Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SIWECOS
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cContentTypePifaForm
  • DefaultFormModule
  • DefaultFormProcessor
  • ExampleOptionsDatasource
  • MailedFormProcessor
  • Pifa
  • PifaAbstractFormModule
  • PifaAbstractFormProcessor
  • PifaAjaxHandler
  • PifaExporter
  • PifaExternalOptionsDatasourceInterface
  • PifaField
  • PifaFieldCollection
  • PifaForm
  • PifaFormCollection
  • PifaImporter
  • PifaLeftBottomPage
  • PifaRightBottomFormDataPage
  • PifaRightBottomFormExportPage
  • PifaRightBottomFormFieldsPage
  • PifaRightBottomFormImportPage
  • PifaRightBottomFormPage

Exceptions

  • PifaDatabaseException
  • PifaException
  • PifaIllegalStateException
  • PifaMailException
  • PifaNotImplementedException
  • PifaNotYetStoredException
  • PifaValidationException
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
   1: <?php
   2: 
   3: /**
   4:  * This file contains several page classes.
   5:  *
   6:  * @package Plugin
   7:  * @subpackage FormAssistant
   8:  * @author Marcus Gnaß <marcus.gnass@4fb.de>
   9:  * @copyright four for business AG
  10:  * @link http://www.4fb.de
  11:  */
  12: 
  13: // assert CONTENIDO framework
  14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
  15: 
  16: /**
  17:  * Page to be displayed in the left bottom frame.
  18:  * It provides a navigation for all forms defined for the current client and the
  19:  * current language.
  20:  *
  21:  * @author Marcus Gnaß <marcus.gnass@4fb.de>
  22:  */
  23: class PifaLeftBottomPage extends cGuiPage {
  24: 
  25:     /**
  26:      * id of the PIFA content type
  27:      *
  28:      * @var int
  29:      */
  30:     protected $typeId;
  31: 
  32:     /**
  33:      * Create an instance.
  34:      *
  35:      * @throws cDbException
  36:      * @throws cException
  37:      */
  38:     public function __construct() {
  39: 
  40:         /**
  41:          * @param string $action to be performed
  42:          */
  43:         global $action;
  44: 
  45:         /**
  46:          * @param int $idform id of form to be edited
  47:          */
  48:         global $idform;
  49: 
  50:         parent::__construct('left_bottom', Pifa::getName());
  51: 
  52:         // get the id of the content type
  53:         $typeCollection = new cApiTypeCollection();
  54:         $typeCollection->select('type = "CMS_PIFAFORM"');
  55:         $type = $typeCollection->next();
  56:         $this->typeId = $type->get('idtype');
  57: 
  58:         $this->addScript('form_assistant.js');
  59:         $this->addScript('left_bottom.js');
  60: 
  61:         $this->set('s', 'dialog_title', Pifa::i18n('INUSE_DIALOG_TITLE'));
  62:         $this->set('s', 'menu', $this->_getMenu());
  63: 
  64:         // add translations to template
  65:         $this->set('s', 'I18N', json_encode(['confirm_delete_form' => Pifa::i18n('CONFIRM_DELETE_FORM')]));
  66:     }
  67: 
  68:     /**
  69:      * Get menu with all forms of current client in current language.
  70:      *
  71:      * @return string
  72:      * @throws cDbException
  73:      * @throws cException
  74:      * @throws cInvalidArgumentException
  75:      */
  76:     private function _getMenu() {
  77:         global $area;
  78: 
  79:         $cfg = cRegistry::getConfig();
  80:         $client = cRegistry::getClientId();
  81:         $lang = cRegistry::getLanguageId();
  82: 
  83:         // get all forms of current client in current language
  84:         $forms = PifaFormCollection::getByClientAndLang($client, $lang);
  85:         if (false === $forms) {
  86:             return '<!-- no forms for current client/language -->';
  87:         }
  88: 
  89:         // $formIcon = Pifa::getUrl() . 'images/icon_form.png';
  90: 
  91:         // collect usage information from the content table
  92:         $contentCollection = new cApiContentCollection();
  93:         // select all entries about the pifa content type
  94:         $formContent = $contentCollection->getFieldsByWhereClause(array(
  95:             'idartlang',
  96:             'value',
  97:         ), 'idtype = "' . $this->typeId . '"');
  98:         // get the idform and the related cApiArticleLanguage object and save them in an array
  99:         $assignedForms = array();
 100:         foreach ($formContent as $formRow) {
 101:             // read settings
 102:             $formRow['value'] = conHtmlEntityDecode($formRow['value']);
 103:             $formRow['value'] = utf8_encode($formRow['value']);
 104:             $settings = cXmlBase::xmlStringToArray($formRow['value']);
 105:             // if it was successful append the array of articles using this form
 106:             if ($settings['idform'] != '') {
 107:                 if (is_array($assignedForms[$settings['idform']])) {
 108:                     $assignedForms[$settings['idform']][] = new cApiArticleLanguage($formRow['idartlang']);
 109:                 } else {
 110:                     $assignedForms[$settings['idform']] = array(
 111:                         new cApiArticleLanguage($formRow['idartlang']),
 112:                     );
 113:                 }
 114:             }
 115:         }
 116: 
 117:         // create menu
 118:         $menu = new cGuiMenu();
 119:         while (false !== $form = $forms->next()) {
 120: 
 121:             $idform = $form->get('idform');
 122:             $formName = $form->get('name');
 123: 
 124:             $menu->setTitle($idform, $formName);
 125: 
 126:             // create link to show/edit the form
 127:             $link = new cHTMLLink();
 128:             $link->setMultiLink($area, '', $area, PifaRightBottomFormPage::SHOW_FORM);
 129:             $link->setCustom('idform', $idform);
 130:             $link->setAttribute('title', 'idform: ' . $idform);
 131:             $menu->setLink($idform, $link);
 132: 
 133:             // if this is true, then the form is in use
 134:             if (isset($assignedForms[$idform])) {
 135:                 // create a link for the action
 136:                 $link = new cHTMLLink();
 137:                 // set the class and the dialog text
 138:                 $link->setClass('in_use_link');
 139:                 $dialogText = Pifa::i18n("FOLLOWING_LIST_USES_FORM") . "<br><br>";
 140:                 /** @var cApiArticleLanguage $article */
 141:                 foreach ($assignedForms[$idform] as $article) {
 142:                     $dialogText .= '<b>' . $article->get('title') . '</b> - (' . $article->get('idart') . ')<br>';
 143:                 }
 144:                 $link->setAttribute("data-dialog-text", $dialogText);
 145:                 $link->setLink('javascript://');
 146: 
 147:                 $image = new cHTMLImage();
 148:                 $image->setSrc($cfg['path']['images'] . 'exclamation.gif');
 149:                 $link->setContent($image->render());
 150: 
 151:                 $menu->setActions($idform, 'inuse', $link);
 152:             }
 153: 
 154:             // create link to delete the form
 155:             $deleteForm = Pifa::i18n('DELETE_FORM');
 156:             if (cRegistry::getPerm()->have_perm_area_action('form', PifaRightBottomFormPage::DELETE_FORM)) {
 157:                 $link = new cHTMLLink();
 158:                 $link->setMultiLink($area, PifaRightBottomFormPage::DELETE_FORM, $area, PifaRightBottomFormPage::DELETE_FORM);
 159:                 $link->setCustom('idform', $idform);
 160:                 $link->setClass('pifa-icon-delete-form');
 161:                 $link->setAlt($deleteForm);
 162:                 $link->setContent('<img src="' . $cfg['path']['images'] . 'delete.gif" title="' . $deleteForm . '" alt="' . $deleteForm . '">');
 163:                 // $menu->setLink($idform, $link);
 164:                 $menu->setActions($idform, 'delete', $link);
 165:             } else {
 166:                 $menu->setActions($idform, 'delete', '<img src="' . $cfg['path']['images'] . 'delete_inact.gif" title="' . $deleteForm . '" alt="' . $deleteForm . '">');
 167:             }
 168:         }
 169: 
 170:         return $menu->render(false);
 171:     }
 172: 
 173: }
 174: 
 175: /**
 176:  * Page for area "form" to be displayed in the right bottom frame.
 177:  *
 178:  * @author Marcus Gnaß <marcus.gnass@4fb.de>
 179:  */
 180: class PifaRightBottomFormPage extends cGuiPage {
 181: 
 182:     /**
 183:      * Action constant.
 184:      *
 185:      * @var string
 186:      */
 187:     const SHOW_FORM = 'pifa_show_form';
 188: 
 189:     /**
 190:      * Action constant.
 191:      *
 192:      * @var string
 193:      */
 194:     const STORE_FORM = 'pifa_store_form';
 195: 
 196:     /**
 197:      * Action constant.
 198:      *
 199:      * @var string
 200:      */
 201:     const DELETE_FORM = 'pifa_delete_form';
 202: 
 203:     /**
 204:      * model for a single PIFA form
 205:      *
 206:      * @var PifaForm
 207:      */
 208:     private $_pifaForm = NULL;
 209: 
 210:     /**
 211:      * Creates and aggregates a model for a collection of PIFA forms
 212:      * and another for a single PIFA form.
 213:      *
 214:      * If an ID for an item is given this is loaded from database
 215:      * and its values are stored in the appropriate model.
 216:      *
 217:      * @throws PifaException if form could not be loaded
 218:      * @throws cDbException
 219:      * @throws cException
 220:      */
 221:     public function __construct() {
 222: 
 223:         /**
 224:          * @param string $action to be performed
 225:          */
 226:         global $action;
 227: 
 228:         /**
 229:          * @param int $idform id of form to be edited
 230:          */
 231:         global $idform;
 232: 
 233:         /**
 234:          * @param int $idfield id of field to be edited
 235:          */
 236:         global $idfield;
 237: 
 238:         parent::__construct('right_bottom', Pifa::getName());
 239: 
 240:         $this->addStyle('smoothness/jquery-ui-1.8.20.custom.css');
 241:         $this->addStyle('right_bottom.css');
 242:         $this->addScript('form_assistant.js');
 243:         $this->addScript('right_bottom.js');
 244: 
 245:         // create models
 246:         $this->_pifaForm = new PifaForm();
 247: 
 248:         // load models
 249:         $idform = cSecurity::toInteger($idform);
 250:         if (0 < $idform) {
 251:             if (false === $this->_pifaForm->loadByPrimaryKey($idform)) {
 252:                 $msg = Pifa::i18n('FORM_LOAD_ERROR');
 253:                 throw new PifaException($msg);
 254:             }
 255:         }
 256: 
 257:         // add translations to template
 258:         $this->set('s', 'I18N', json_encode(array(
 259:             'cancel' => Pifa::i18n('CANCEL'),
 260:             'save' => Pifa::i18n('SAVE'),
 261:         )));
 262: 
 263:         // dispatch action
 264:         try {
 265:             $this->_dispatch($action);
 266:         } catch (PifaException $e) {
 267:             $cGuiNotification = new cGuiNotification();
 268:             $notification = $cGuiNotification->returnNotification(cGuiNotification::LEVEL_ERROR, $e->getMessage());
 269:             $this->set('s', 'notification', $notification);
 270:             $this->set('s', 'content', '');
 271:         }
 272:     }
 273: 
 274:     /**
 275:      * Dispatches the given action.
 276:      *
 277:      * @param string $action to be executed
 278:      * @param string $notification
 279:      *
 280:      * @throws PifaException if the given action is unknown
 281:      * @throws PifaIllegalStateException if permissions are missing
 282:      * @throws cDbException
 283:      * @throws cException
 284:      */
 285:     protected function _dispatch($action, $notification = '') {
 286:         global $area;
 287: 
 288:         // check for permission
 289:         if (!cRegistry::getPerm()->have_perm_area_action($area, $action)) {
 290:             $msg = Pifa::i18n('NO_PERMISSIONS');
 291:             throw new PifaIllegalStateException($msg);
 292:         }
 293: 
 294:         if (NULL === $action) {
 295:             $cGuiNotification = new cGuiNotification();
 296:             $notification = $cGuiNotification->returnNotification(cGuiNotification::LEVEL_INFO, Pifa::i18n('please select a form'));
 297:             $this->set('s', 'notification', $notification);
 298:             $this->set('s', 'content', '');
 299:             return;
 300:         }
 301: 
 302:         // dispatch actions
 303:         switch ($action) {
 304:             case self::SHOW_FORM:
 305:                 $this->set('s', 'notification', $notification);
 306:                 try {
 307:                     $this->set('s', 'content', $this->_showForm());
 308:                 } catch (SmartyCompilerException $e) {
 309:                     $this->set('s', 'content', Pifa::notifyException($e));
 310:                 }
 311:                 break;
 312: 
 313:             case self::STORE_FORM:
 314:                 $notification = '';
 315:                 try {
 316:                     $this->_storeForm();
 317:                     $this->setReload();
 318:                     // reload right_top after saving of form
 319:                     $idform = $this->_pifaForm->get('idform');
 320:                     $url = "main.php?area=form&frame=3&idform=$idform&action=" . PifaRightBottomFormPage::SHOW_FORM;
 321:                     $url = cRegistry::getSession()->url($url);
 322:                     $this->addScript("<script type=\"text/javascript\">
 323:                         Con.getFrame('right_top').location.href = '$url';
 324:                         </script>");
 325:                 } catch (Exception $e) {
 326:                     $notification = Pifa::notifyException($e);
 327:                 }
 328:                 $this->_dispatch(self::SHOW_FORM, $notification);
 329:                 break;
 330: 
 331:             case self::DELETE_FORM:
 332:                 $notification = '';
 333:                 try {
 334:                     $this->_deleteForm();
 335:                     $cGuiNotification = new cGuiNotification();
 336:                     $this->set('s', 'notification', $cGuiNotification->returnNotification(cGuiNotification::LEVEL_OK, Pifa::i18n('FORM_DELETED')));
 337:                     $this->set('s', 'content', '');
 338:                     $this->setReload();
 339:                 } catch (Exception $e) {
 340:                     $notification = Pifa::notifyException($e);
 341:                 }
 342:                 break;
 343: 
 344:             default:
 345:                 $msg = Pifa::i18n('UNKNOWN_ACTION');
 346:                 throw new PifaException($msg);
 347:         }
 348:     }
 349: 
 350:     /**
 351:      * Build and return form for PIFA forms.
 352:      *
 353:      * @return string
 354:      * @throws cDbException
 355:      * @throws cException
 356:      */
 357:     private function _showForm() {
 358:         global $area;
 359: 
 360:         $cfg = cRegistry::getConfig();
 361: 
 362:         // get form action
 363:         $formAction = '';
 364:         if (cRegistry::getPerm()->have_perm_area_action('form', self::STORE_FORM)) {
 365:             $formAction = new cHTMLLink();
 366:             $formAction->setCLink($area, 4, self::STORE_FORM);
 367:             $formAction = $formAction->getHref();
 368:         }
 369: 
 370:         // get current or default values for form
 371:         if (!is_null($this->_pifaForm) && $this->_pifaForm->isLoaded()) {
 372:             $idform = $this->_pifaForm->get('idform');
 373:             $nameValue = $this->_pifaForm->get('name');
 374:             $dataTableValue = $this->_pifaForm->get('data_table');
 375:             $methodValue = $this->_pifaForm->get('method');
 376:             $withTimestampValue = (bool) $this->_pifaForm->get('with_timestamp');
 377:         } else {
 378:             $idform = NULL;
 379: 
 380:             // read item data from form
 381:             $nameValue = empty($_POST['name'])? '' : $_POST['name'];
 382:             $nameValue = cSecurity::unescapeDB($nameValue);
 383:             $nameValue = cSecurity::toString($nameValue);
 384:             $nameValue = trim($nameValue);
 385: 
 386:             $dataTableValue = empty($_POST['data_table'])? '' : $_POST['data_table'];
 387:             $dataTableValue = trim($dataTableValue);
 388:             $dataTableValue = cString::toLowerCase($dataTableValue);
 389:             $dataTableValue = preg_replace('/[^a-z0-9_]/', '_', $dataTableValue);
 390: 
 391:             $methodValue = '';
 392:             $withTimestampValue = true;
 393:         }
 394: 
 395:         $tpl = cSmartyBackend::getInstance(true);
 396:         $tpl->assign('formAction', $formAction);
 397:         $tpl->assign('idform', $idform);
 398:         $tpl->assign('nameValue', $nameValue);
 399:         $tpl->assign('dataTableValue', $dataTableValue);
 400:         $tpl->assign('methodValue', cString::toUpperCase($methodValue));
 401:         $tpl->assign('withTimestampValue', $withTimestampValue);
 402:         $tpl->assign('hasWithTimestamp', Pifa::TIMESTAMP_BYFORM === Pifa::getTimestampSetting());
 403:         $tpl->assign('trans', array(
 404:             'legend' => Pifa::i18n('form'),
 405:             'name' => Pifa::i18n('form name'),
 406:             'dataTable' => Pifa::i18n('data table'),
 407:             'method' => Pifa::i18n('method'),
 408:             'withTimestamp' => Pifa::i18n('with timestamp'),
 409:             'pleaseChoose' => Pifa::i18n('please choose'),
 410:             'saveForm' => Pifa::i18n('save form'),
 411:         ));
 412: 
 413:         $out = $tpl->fetch($cfg['templates']['pifa_right_bottom_form']);
 414: 
 415:         return $out;
 416:     }
 417: 
 418:     /**
 419:      * Handles a POST request of the first form, showing a forms details.
 420:      *
 421:      * @throws PifaException
 422:      */
 423:     private function _storeForm() {
 424: 
 425:         // determine if item is loaded
 426:         $isLoaded = $this->_pifaForm->isLoaded();
 427: 
 428:         // read item data from form
 429:         $name = $_POST['name'];
 430:         $name = cSecurity::unescapeDB($name);
 431:         $name = cSecurity::toString($name);
 432:         $name = trim($name);
 433: 
 434:         $dataTable = $_POST['data_table'];
 435:         $dataTable = trim($dataTable);
 436:         $dataTable = cString::toLowerCase($dataTable);
 437:         $dataTable = preg_replace('/[^a-z0-9_]/', '_', $dataTable);
 438: 
 439:         $method = $_POST['method'];
 440:         $method = trim($method);
 441:         $method = cString::toUpperCase($method);
 442: 
 443:         switch (Pifa::getTimestampSetting()) {
 444:             case Pifa::TIMESTAMP_NEVER:
 445:                 $withTimestamp = false;
 446:                 break;
 447:             case Pifa::TIMESTAMP_BYFORM:
 448:                 $withTimestamp = 'on' === $_POST['with_timestamp'];
 449:                 break;
 450:             case Pifa::TIMESTAMP_ALWAYS:
 451:             default:
 452:                 $withTimestamp = true;
 453:                 break;
 454:         }
 455: 
 456:         // validate item data
 457:         if (0 === cString::getStringLength($name)) {
 458:             $msg = Pifa::i18n('EMPTY_FORMNAME_ERROR');
 459:             throw new PifaException($msg);
 460:         }
 461:         if (0 === cString::getStringLength($dataTable)) {
 462:             $msg = Pifa::i18n('EMPTY_DATETABLENAME_ERROR');
 463:             throw new PifaException($msg);
 464:         }
 465:         if (!in_array($method, array(
 466:             'GET',
 467:             'POST',
 468:         ))) {
 469:             $msg = Pifa::i18n('FORM_METHOD_ERROR');
 470:             throw new PifaException($msg);
 471:         }
 472: 
 473:         if ($isLoaded) {
 474:             // remember old table values
 475:             $oldDataTable = $this->_pifaForm->get('data_table');
 476:             $oldWithTimestamp = (bool) $this->_pifaForm->get('with_timestamp');
 477:         } else {
 478:             // create new item for given client & language
 479:             $pifaFormCollection = new PifaFormCollection();
 480:             $this->_pifaForm = $pifaFormCollection->createNewItem(array(
 481:                 'idclient' => cRegistry::getClientId(),
 482:                 'idlang' => cRegistry::getLanguageId(),
 483:             ));
 484:         }
 485: 
 486:         // set item data
 487:         // Never, really never, call Item->set() if the value doesn't differ
 488:         // from the previous one. Otherwise the genericDb thinks that the item
 489:         // is modified and tries to store it resulting in a return value of
 490:         // false!
 491:         if ($name !== $this->_pifaForm->get('name')) {
 492:             $this->_pifaForm->set('name', $name);
 493:         }
 494:         if ($dataTable !== $this->_pifaForm->get('data_table')) {
 495:             $this->_pifaForm->set('data_table', $dataTable);
 496:         }
 497:         if (0 !== strcasecmp($method, $this->_pifaForm->get('method'))) {
 498:             $this->_pifaForm->set('method', $method);
 499:         }
 500:         if ($withTimestamp !== (bool) $this->_pifaForm->get('with_timestamp')) {
 501:             $this->_pifaForm->set('with_timestamp', $withTimestamp);
 502:         }
 503: 
 504:         if ($isLoaded) {
 505:             // optionally alter data table
 506:             // HINT: passing the old values is correct!
 507:             // The new values have already been stored inside the pifaForm
 508:             // object!
 509:             $this->_pifaForm->alterTable($oldDataTable, $oldWithTimestamp);
 510:         } else {
 511:             // create table
 512:             $this->_pifaForm->createTable($withTimestamp);
 513:         }
 514: 
 515:         // store item
 516:         if (false === $this->_pifaForm->store()) {
 517:             $msg = Pifa::i18n('FORM_STORE_ERROR');
 518:             $msg = sprintf($msg, $this->_pifaForm->getLastError());
 519:             throw new PifaException($msg);
 520:         }
 521:     }
 522: 
 523:     /**
 524:      */
 525:     private function _deleteForm() {
 526:         $this->_pifaForm->delete();
 527:         $this->_pifaForm = NULL;
 528:     }
 529: 
 530: }
 531: 
 532: /**
 533:  * Page for area "form_fields" to be displayed in the right bottom frame.
 534:  *
 535:  * @author Marcus Gnaß <marcus.gnass@4fb.de>
 536:  */
 537: class PifaRightBottomFormFieldsPage extends cGuiPage {
 538: 
 539:     /**
 540:      * Action constant.
 541:      *
 542:      * @var string
 543:      */
 544:     const SHOW_FIELDS = 'pifa_show_fields';
 545: 
 546:     /**
 547:      * model for a single PIFA form
 548:      *
 549:      * @var PifaForm
 550:      */
 551:     private $_pifaForm = NULL;
 552: 
 553:     /**
 554:      * Creates and aggregates a model for a collection of PIFA forms
 555:      * and another for a single PIFA form.
 556:      *
 557:      * If an ID for an item is given this is loaded from database
 558:      * and its values are stored in the appropriate model.
 559:      *
 560:      * @throws PifaException if form could not be loaded
 561:      * @throws cDbException
 562:      * @throws cException
 563:      */
 564:     public function __construct() {
 565: 
 566:         /**
 567:          * @param string $action to be performed
 568:          */
 569:         global $action;
 570: 
 571:         /**
 572:          * @param int $idform id of form to be edited
 573:          */
 574:         global $idform;
 575: 
 576:         /**
 577:          * @param int $idfield id of field to be edited
 578:          */
 579:         global $idfield;
 580: 
 581:         parent::__construct('right_bottom', Pifa::getName());
 582: 
 583:         $this->addStyle('smoothness/jquery-ui-1.8.20.custom.css');
 584:         $this->addStyle('right_bottom.css');
 585:         $this->addScript('form_assistant.js');
 586:         $this->addScript('right_bottom.js');
 587: 
 588:         // create models
 589:         $this->_pifaForm = new PifaForm();
 590: 
 591:         // load models
 592:         $idform = cSecurity::toInteger($idform);
 593:         if (0 < $idform) {
 594:             $ret = $this->_pifaForm->loadByPrimaryKey($idform);
 595:             if (false === $ret) {
 596:                 $msg = Pifa::i18n('FORM_LOAD_ERROR');
 597:                 throw new PifaException($msg);
 598:             }
 599:         }
 600: 
 601:         // add translations to template
 602:         $this->set('s', 'I18N', json_encode(array(
 603:             'cancel' => Pifa::i18n('CANCEL'),
 604:             'save' => Pifa::i18n('SAVE'),
 605:             'confirm_delete_field' => Pifa::i18n('CONFIRM_DELETE_FIELD'),
 606:         )));
 607: 
 608:         // dispatch action
 609:         try {
 610:             $this->_dispatch($action);
 611:         } catch (PifaException $e) {
 612:             $cGuiNotification = new cGuiNotification();
 613:             $notification = $cGuiNotification->returnNotification(cGuiNotification::LEVEL_ERROR, $e->getMessage());
 614:             $this->set('s', 'notification', $notification);
 615:             $this->set('s', 'content', '');
 616:         }
 617:     }
 618: 
 619:     /**
 620:      * Dispatches the given action.
 621:      *
 622:      * @param string $action to be executed
 623:      * @param string $notification
 624:      *
 625:      * @throws PifaException if the given action is unknown
 626:      * @throws PifaIllegalStateException if permissions are missing
 627:      * @throws cDbException
 628:      * @throws cException
 629:      */
 630:     protected function _dispatch($action, $notification = '') {
 631:         global $area;
 632: 
 633:         // check for permission
 634:         if (!cRegistry::getPerm()->have_perm_area_action($area, $action)) {
 635:             $msg = Pifa::i18n('NO_PERMISSIONS');
 636:             throw new PifaIllegalStateException($msg);
 637:         }
 638: 
 639:         if (NULL === $action) {
 640:             $this->set('s', 'notification', Pifa::i18n('please select a form'));
 641:             $this->set('s', 'content', '');
 642:             return;
 643:         }
 644: 
 645:         // dispatch actions
 646:         switch ($action) {
 647: 
 648:             case self::SHOW_FIELDS:
 649:                 $this->set('s', 'notification', $notification);
 650:                 try {
 651:                     $this->set('s', 'content', $this->_showFields());
 652:                 } catch (SmartyCompilerException $e) {
 653:                     $this->set('s', 'content', Pifa::notifyException($e));
 654:                 }
 655:                 break;
 656: 
 657:             default:
 658:                 $msg = Pifa::i18n('UNKNOWN_ACTION');
 659:                 throw new PifaException($msg);
 660:         }
 661:     }
 662: 
 663:     /**
 664:      * @return mixed|string
 665:      * @throws cDbException
 666:      * @throws cException
 667:      */
 668:     private function _showFields() {
 669:         global $area;
 670: 
 671:         $cfg = cRegistry::getConfig();
 672: 
 673:         $idform = $idfield = NULL;
 674:         $fields = NULL;
 675:         $editField = $deleteField = NULL;
 676:         if ($this->_pifaForm->isLoaded()) {
 677: 
 678:             $idform = $this->_pifaForm->get('idform');
 679:             $idfield = $_GET['idfield'];
 680: 
 681:             $fields = $this->_pifaForm->getFields();
 682: 
 683:             if (cRegistry::getPerm()->have_perm_area_action('form_ajax', PifaAjaxHandler::GET_FIELD_FORM)) {
 684:                 $editField = new cHTMLLink();
 685:                 $editField->setCLink('form_ajax', 4, PifaAjaxHandler::GET_FIELD_FORM);
 686:                 $editField->setCustom('idform', $idform);
 687:                 $editField = $editField->getHref();
 688:             }
 689: 
 690:             if (cRegistry::getPerm()->have_perm_area_action('form_ajax', PifaAjaxHandler::DELETE_FIELD)) {
 691:                 $deleteField = new cHTMLLink();
 692:                 $deleteField->setCLink('form_ajax', 4, PifaAjaxHandler::DELETE_FIELD);
 693:                 $deleteField->setCustom('idform', $idform);
 694:                 $deleteField = $deleteField->getHref();
 695:             }
 696:         }
 697: 
 698:         // get and fill template
 699:         $tpl = cSmartyBackend::getInstance(true);
 700: 
 701:         $columnNames = array();
 702:         $includesCaptcha = false;
 703: 
 704:         /** @var PifaField $field */
 705:         foreach ($this->_pifaForm->getFields() as $field) {
 706:             $columnNames[] = $field->get('column_name');
 707:             if ((int) $field->get('field_type') === PifaField::CAPTCHA) {
 708:                 $includesCaptcha = true;
 709:             }
 710:         }
 711: 
 712:         $cGuiNotification = new cGuiNotification();
 713: 
 714:         // check for required email column at this form
 715:         if (!in_array('email', $columnNames)) {
 716:             $email_notification = $cGuiNotification->returnNotification(
 717:                 cGuiNotification::LEVEL_WARNING,
 718:                 Pifa::i18n('Currently there is no field called "email" in this form. Sending mails - if configured - to the user which entered the form data may not work!')
 719:             );
 720:             $tpl->assign('email_notification', $email_notification);
 721:         }
 722: 
 723:         // check for captcha usage
 724:         if ($includesCaptcha && (cString::getStringLength(getEffectiveSetting('pifa-recaptcha', 'sitekey', '')) === 0 || cString::getStringLength(getEffectiveSetting('pifa-recaptcha', 'secret', '')) === 0)) {
 725:             $captcha_notification = $cGuiNotification->returnNotification(
 726:                 cGuiNotification::LEVEL_WARNING,
 727:                 Pifa::i18n('This form is configured with a captcha, but its settings were not defined.') . "<br>" .
 728:                 Pifa::i18n('The captcha will not work until you provide the missing information.') . "<br>" .
 729:                 Pifa::i18n('Please save the "sitekey" and the "secret" in the client settings for the type "pifa-recaptcha". You will get this data from https://www.google.com/recaptcha.')
 730:             );
 731:             $tpl->assign('captcha_notification', $captcha_notification);
 732:         }
 733: 
 734:         // translations
 735:         $tpl->assign('trans', array(
 736:             'legend' => Pifa::i18n('fields'),
 737:             'pleaseSaveFirst' => Pifa::i18n('please save first'),
 738:             'dialogTitle' => Pifa::i18n('edit field'),
 739:             'edit' => Pifa::i18n('EDIT'),
 740:             'delete' => Pifa::i18n('DELETE'),
 741:             'obligatory' => Pifa::i18n('OBLIGATORY'),
 742:         ));
 743: 
 744:         // params
 745:         $tpl->assign('ajaxParams', implode('&', array(
 746:             'area=form_ajax',
 747:             'frame=4',
 748:             'contenido=' . cRegistry::getBackendSessionId(),
 749:         )));
 750:         if (cRegistry::getPerm()->have_perm_area_action('form_ajax', PifaAjaxHandler::GET_FIELD_FORM)) {
 751:             $tpl->assign('dragParams', implode('&', array(
 752:                 'area=form_ajax',
 753:                 'frame=4',
 754:                 'contenido=' . cRegistry::getBackendSessionId(),
 755:                 'action=' . PifaAjaxHandler::GET_FIELD_FORM,
 756:                 'idform=' . $idform,
 757:             )));
 758:         }
 759:         if (cRegistry::getPerm()->have_perm_area_action('form_ajax', PifaAjaxHandler::REORDER_FIELDS)) {
 760:             $tpl->assign('sortParams', implode('&', array(
 761:                 'area=form_ajax',
 762:                 'frame=4',
 763:                 'contenido=' . cRegistry::getBackendSessionId(),
 764:                 'action=' . PifaAjaxHandler::REORDER_FIELDS,
 765:                 'idform=' . $this->_pifaForm->get('idform'),
 766:             )));
 767:         }
 768: 
 769:         // data
 770:         $tpl->assign('idform', $idform);
 771:         $tpl->assign('idfield', $idfield);
 772: 
 773:         $tpl->assign('fields', $fields);
 774:         $tpl->assign('fieldTypes', PifaField::getFieldTypeNames());
 775: 
 776:         // for partial
 777:         $tpl->assign('editField', $editField);
 778:         $tpl->assign('deleteField', $deleteField);
 779:         // define path to partial template for displaying a single field row
 780:         $tpl->assign('partialFieldRow', $cfg['templates']['pifa_ajax_field_row']);
 781: 
 782:         $out = $tpl->fetch($cfg['templates']['pifa_right_bottom_fields']);
 783: 
 784:         return $out;
 785:     }
 786: 
 787: }
 788: 
 789: /**
 790:  * Page for area "form_data" to be displayed in the right bottom frame.
 791:  *
 792:  * @author Marcus Gnaß <marcus.gnass@4fb.de>
 793:  */
 794: class PifaRightBottomFormDataPage extends cGuiPage {
 795: 
 796:     /**
 797:      * Action constant.
 798:      *
 799:      * @var string
 800:      */
 801:     const SHOW_DATA = 'pifa_show_data';
 802: 
 803:     /**
 804:      * model for a single PIFA form
 805:      *
 806:      * @var PifaForm
 807:      */
 808:     private $_pifaForm = NULL;
 809: 
 810:     /**
 811:      * Creates and aggregates a model for a collection of PIFA forms
 812:      * and another for a single PIFA form.
 813:      *
 814:      * If an ID for an item is given this is loaded from database
 815:      * and its values are stored in the appropriate model.
 816:      *
 817:      * @throws PifaException if form could not be loaded
 818:      * @throws cDbException
 819:      * @throws cException
 820:      */
 821:     public function __construct() {
 822: 
 823:         /**
 824:          * @param string $action to be performed
 825:          */
 826:         global $action;
 827: 
 828:         /**
 829:          * @param int $idform id of form to be edited
 830:          */
 831:         global $idform;
 832: 
 833:         /**
 834:          * @param int $idfield id of field to be edited
 835:          */
 836:         global $idfield;
 837: 
 838:         parent::__construct('right_bottom', Pifa::getName());
 839: 
 840:         $this->addStyle('smoothness/jquery-ui-1.8.20.custom.css');
 841:         $this->addStyle('right_bottom.css');
 842:         $this->addScript('form_assistant.js');
 843:         $this->addScript('right_bottom.js');
 844: 
 845:         // create models
 846:         $this->_pifaForm = new PifaForm();
 847: 
 848:         // load models
 849:         $idform = cSecurity::toInteger($idform);
 850:         if (0 < $idform) {
 851:             if (false === $this->_pifaForm->loadByPrimaryKey($idform)) {
 852:                 $msg = Pifa::i18n('FORM_LOAD_ERROR');
 853:                 throw new PifaException($msg);
 854:             }
 855:         }
 856: 
 857:         // add translations to template
 858:         $this->set('s', 'I18N', json_encode(array(
 859:             'cancel' => Pifa::i18n('CANCEL'),
 860:             'save' => Pifa::i18n('SAVE'),
 861:         )));
 862: 
 863:         // dispatch action
 864:         try {
 865:             $this->_dispatch($action);
 866:         } catch (PifaException $e) {
 867:             $cGuiNotification = new cGuiNotification();
 868:             $notification = $cGuiNotification->returnNotification(cGuiNotification::LEVEL_ERROR, $e->getMessage());
 869:             $this->set('s', 'notification', $notification);
 870:             $this->set('s', 'content', '');
 871:         }
 872:     }
 873: 
 874:     /**
 875:      * Dispatches the given action.
 876:      *
 877:      * @param string $action to be executed
 878:      * @param string $notification
 879:      *
 880:      * @throws PifaException if the given action is unknown
 881:      * @throws PifaIllegalStateException if permissions are missing
 882:      * @throws cDbException
 883:      * @throws cException
 884:      */
 885:     protected function _dispatch($action, $notification = '') {
 886:         global $area;
 887: 
 888:         // check for permission
 889:         if (!cRegistry::getPerm()->have_perm_area_action($area, $action)) {
 890:             $msg = Pifa::i18n('NO_PERMISSIONS');
 891:             throw new PifaIllegalStateException($msg);
 892:         }
 893: 
 894:         if (NULL === $action) {
 895:             $this->set('s', 'notification', Pifa::i18n('please select a form'));
 896:             $this->set('s', 'content', '');
 897:             return;
 898:         }
 899: 
 900:         // dispatch actions
 901:         switch ($action) {
 902: 
 903:             case self::SHOW_DATA:
 904:                 $this->set('s', 'notification', $notification);
 905:                 try {
 906:                     $this->set('s', 'content', $this->_showData());
 907:                 } catch (SmartyCompilerException $e) {
 908:                     $this->set('s', 'content', Pifa::notifyException($e));
 909:                 }
 910:                 break;
 911: 
 912:             default:
 913:                 $msg = Pifa::i18n('UNKNOWN_ACTION');
 914:                 throw new PifaException($msg);
 915:         }
 916:     }
 917: 
 918:     /**
 919:      * @return mixed|string
 920:      * @throws cException
 921:      */
 922:     private function _showData() {
 923:         $cfg = cRegistry::getConfig();
 924: 
 925:         $tpl = cSmartyBackend::getInstance(true);
 926: 
 927:         // translations
 928:         $tpl->assign('trans', array(
 929:             'legend' => Pifa::i18n('data'),
 930:             'nodata' => Pifa::i18n('NODATA'),
 931:             'pleaseSaveFirst' => Pifa::i18n('please save first'),
 932:             'export' => Pifa::i18n('download data as CSV'),
 933:             'delete' => Pifa::i18n('Delete'),
 934:         ));
 935: 
 936:         $tpl->assign('form', $this->_pifaForm);
 937:         $tpl->assign('getFileUrl', 'main.php?' . implode('&', array(
 938:             'area=form_ajax',
 939:             'frame=4',
 940:             'contenido=' . cRegistry::getBackendSessionId(),
 941:             'action=' . PifaAjaxHandler::GET_FILE,
 942:         )));
 943: 
 944:         try {
 945:             $tpl->assign('fields', $this->_pifaForm->getFields());
 946:         } catch (Exception $e) {
 947:             $tpl->assign('fields', Pifa::notifyException($e));
 948:         }
 949: 
 950:         $tpl->assign('withTimestamp', (bool) $this->_pifaForm->get('with_timestamp'));
 951: 
 952: 
 953:         try {
 954:             $hasPermExportData = cRegistry::getPerm()->have_perm_area_action('form_ajax', PifaAjaxHandler::EXPORT_DATA);
 955:             $hasPermDeleteData = cRegistry::getPerm()->have_perm_area_action('form_ajax', PifaAjaxHandler::DELETE_DATA);
 956:         } catch (Exception $e) {
 957:             $hasPermExportData = false;
 958:             $hasPermDeleteData = false;
 959:         }
 960: 
 961:         // export data
 962:         $data = $this->_pifaForm->getData();
 963:         $tpl->assign('data', $data);
 964: 
 965:         if (!empty($data) && $hasPermExportData) {
 966:             $tpl->assign('exportUrl', 'main.php?' . http_build_query(array(
 967:                 'area' => 'form_ajax',
 968:                 'frame' => '4',
 969:                 'contenido' => cRegistry::getBackendSessionId(),
 970:                 'action' => PifaAjaxHandler::EXPORT_DATA,
 971:                 'idform' => $this->_pifaForm->get('idform')
 972:             )));
 973:         }
 974: 
 975:         // delete data
 976:         if (!empty($data) && $hasPermDeleteData) {
 977:             $tpl->assign('deleteUrl', 'main.php?' . http_build_query([
 978:                 'area' => 'form_ajax',
 979:                 'frame' => '4',
 980:                 'contenido' => cRegistry::getBackendSessionId(),
 981:                 'action' => PifaAjaxHandler::DELETE_DATA,
 982:                 'idform' => $this->_pifaForm->get('idform')
 983:             ]));
 984:         }
 985: 
 986:         // Mass deletion of form data
 987:         $lnkDel = new cHTMLLink('javascript://');
 988:         $lnkDel->setClass('flip_mark');
 989:         $lnkDel->setContent(Pifa::i18n('Check all'));
 990:         $tpl->assign('lnkDel', $lnkDel->render());
 991: 
 992:         $out = $tpl->fetch($cfg['templates']['pifa_right_bottom_data']);
 993: 
 994:         return $out;
 995:     }
 996: 
 997: }
 998: 
 999: /**
1000:  * Page for area "form_export" to be displayed in the right bottom frame.
1001:  * This page allows for exporting a form as XML.
1002:  *
1003:  * @author Marcus Gnaß <marcus.gnass@4fb.de>
1004:  */
1005: class PifaRightBottomFormExportPage extends cGuiPage {
1006: 
1007:     /**
1008:      * Action constant.
1009:      *
1010:      * @var string
1011:      */
1012:     const EXPORT_FORM = 'pifa_export_form';
1013: 
1014:     /**
1015:      * model for a single PIFA form
1016:      *
1017:      * @var PifaForm
1018:      */
1019:     private $_pifaForm = NULL;
1020: 
1021:     /**
1022:      * Creates and aggregates a model for a single PIFA form.
1023:      *
1024:      * If an ID for an item is given this is loaded from database
1025:      * and its values are stored in the appropriate model.
1026:      *
1027:      * @throws PifaException if form could not be loaded
1028:      * @throws cDbException
1029:      * @throws cException
1030:      */
1031:     public function __construct() {
1032: 
1033:         /**
1034:          * @param string $action to be performed
1035:          */
1036:         global $action;
1037: 
1038:         /**
1039:          * @param int $idform id of form to be edited
1040:          */
1041:         global $idform;
1042: 
1043:         parent::__construct('right_bottom', Pifa::getName());
1044: 
1045:         $this->addStyle('smoothness/jquery-ui-1.8.20.custom.css');
1046:         $this->addStyle('right_bottom.css');
1047:         $this->addScript('form_assistant.js');
1048:         $this->addScript('right_bottom.js');
1049: 
1050:         // add translations to template
1051:         $this->set('s', 'I18N', json_encode(array(
1052:             'cancel' => Pifa::i18n('CANCEL'),
1053:             'save' => Pifa::i18n('SAVE'),
1054:         )));
1055: 
1056:         // create models
1057:         $this->_pifaForm = new PifaForm();
1058: 
1059:         // load models
1060:         $idform = cSecurity::toInteger($idform);
1061:         if (0 < $idform) {
1062:             if (false === $this->_pifaForm->loadByPrimaryKey($idform)) {
1063:                 $msg = Pifa::i18n('FORM_LOAD_ERROR');
1064:                 throw new PifaException($msg);
1065:             }
1066:         }
1067: 
1068:         // dispatch action
1069:         try {
1070:             $this->_dispatch($action);
1071:         } catch (PifaException $e) {
1072:             $cGuiNotification = new cGuiNotification();
1073:             $notification = $cGuiNotification->returnNotification(cGuiNotification::LEVEL_ERROR, $e->getMessage());
1074:             $this->set('s', 'notification', $notification);
1075:             $this->set('s', 'content', '');
1076:         }
1077:     }
1078: 
1079:     /**
1080:      * Dispatches the given action.
1081:      *
1082:      * @param string $action to be executed
1083:      * @param string $notification
1084:      *
1085:      * @throws PifaException if the given action is unknown
1086:      * @throws PifaIllegalStateException if permissions are missing
1087:      * @throws cDbException
1088:      * @throws cException
1089:      */
1090:     protected function _dispatch($action, $notification = '') {
1091: 
1092:         // dispatch actions
1093:         switch ($action) {
1094: 
1095:             case self::EXPORT_FORM:
1096: 
1097:                 // check for permission
1098:                 if (!cRegistry::getPerm()->have_perm_area_action('form_ajax', $action)) {
1099:                     $msg = Pifa::i18n('NO_PERMISSIONS');
1100:                     throw new PifaIllegalStateException($msg);
1101:                 }
1102: 
1103:                 $this->set('s', 'notification', $notification);
1104:                 try {
1105:                     $this->set('s', 'content', $this->_exportForm());
1106:                 } catch (SmartyCompilerException $e) {
1107:                     $this->set('s', 'content', Pifa::notifyException($e));
1108:                 }
1109:                 break;
1110: 
1111:             default:
1112:                 $msg = Pifa::i18n('UNKNOWN_ACTION');
1113:                 throw new PifaException($msg);
1114:         }
1115:     }
1116: 
1117:     /**
1118:      * @return mixed|string
1119:      * @throws cException
1120:      */
1121:     private function _exportForm() {
1122:         $cfg = cRegistry::getConfig();
1123: 
1124:         $tpl = cSmartyBackend::getInstance(true);
1125: 
1126:         // translations
1127:         $tpl->assign('trans', array(
1128:             'legend' => Pifa::i18n('pifa_export_form'),
1129:             'withData' => Pifa::i18n('WITH_DATA'),
1130:             'export' => Pifa::i18n('EXPORT'),
1131:         ));
1132: 
1133:         $tpl->assign('formAction', 'main.php?' . implode('&', array(
1134:             'area=form_ajax',
1135:             'frame=4',
1136:             'contenido=' . cRegistry::getBackendSessionId(),
1137:             'action=' . PifaAjaxHandler::EXPORT_FORM,
1138:             'idform=' . $this->_pifaForm->get('idform'),
1139:         )));
1140: 
1141:         $tpl->assign('idform', $this->_pifaForm->get('idform'));
1142: 
1143:         $out = $tpl->fetch($cfg['templates']['pifa_right_bottom_export']);
1144: 
1145:         return $out;
1146:     }
1147: 
1148: }
1149: 
1150: /**
1151:  * Page for area "form_import" to be displayed in the right bottom frame.
1152:  * This page allows for importing a form that is available as XML.
1153:  *
1154:  * @author Marcus Gnaß <marcus.gnass@4fb.de>
1155:  */
1156: class PifaRightBottomFormImportPage extends cGuiPage {
1157: 
1158:     /**
1159:      * Action constant.
1160:      *
1161:      * @var string
1162:      */
1163:     const IMPORT_FORM = 'pifa_import_form';
1164: 
1165:     /**
1166:      * PifaRightBottomFormImportPage constructor.
1167:      * Dispatches the current action and displays a notification.
1168:      *
1169:      * @throws cDbException
1170:      * @throws cException
1171:      */
1172:     public function __construct() {
1173: 
1174:         /**
1175:          * @param string $action to be performed
1176:          */
1177:         global $action;
1178: 
1179:         parent::__construct('right_bottom', Pifa::getName());
1180: 
1181:         $this->addStyle('smoothness/jquery-ui-1.8.20.custom.css');
1182:         $this->addStyle('right_bottom.css');
1183:         $this->addScript('form_assistant.js');
1184:         $this->addScript('right_bottom.js');
1185: 
1186:         // add translations to template
1187:         $this->set('s', 'I18N', json_encode(array(
1188:             'cancel' => Pifa::i18n('CANCEL'),
1189:             'save' => Pifa::i18n('SAVE'),
1190:         )));
1191: 
1192:         // dispatch action
1193:         try {
1194:             $this->_dispatch($action);
1195:         } catch (PifaException $e) {
1196:             $cGuiNotification = new cGuiNotification();
1197:             $notification = $cGuiNotification->returnNotification(cGuiNotification::LEVEL_ERROR, $e->getMessage());
1198:             $this->set('s', 'notification', $notification);
1199:             $this->set('s', 'content', '');
1200:         }
1201:     }
1202: 
1203:     /**
1204:      * Dispatches the given action.
1205:      *
1206:      * @param string $action to be executed
1207:      * @param string $notification
1208:      *
1209:      * @throws PifaException if the given action is unknown
1210:      * @throws PifaIllegalStateException if permissions are missing
1211:      * @throws cDbException
1212:      * @throws cException
1213:      */
1214:     protected function _dispatch($action, $notification = '') {
1215:         global $area;
1216: 
1217:         // check for permission
1218:         if (!cRegistry::getPerm()->have_perm_area_action($area, $action)) {
1219:             $msg = Pifa::i18n('NO_PERMISSIONS');
1220:             throw new PifaIllegalStateException($msg);
1221:         }
1222: 
1223:         // dispatch actions
1224:         switch ($action) {
1225: 
1226:             case self::IMPORT_FORM:
1227:                 $this->set('s', 'notification', $notification);
1228:                 try {
1229: 
1230:                     switch (cString::toUpperCase($_SERVER['REQUEST_METHOD'])) {
1231:                         case 'GET':
1232:                             $this->set('s', 'content', $this->_importFormGet());
1233:                             break;
1234: 
1235:                         case 'POST':
1236:                             $this->set('s', 'content', $this->_importFormPost());
1237:                             break;
1238:                     }
1239: 
1240:                     $this->setReload();
1241:                 } catch (SmartyCompilerException $e) {
1242:                     $this->set('s', 'content', Pifa::notifyException($e));
1243:                 }
1244:                 break;
1245: 
1246:             default:
1247:                 $msg = Pifa::i18n('UNKNOWN_ACTION');
1248:                 throw new PifaException($msg);
1249:         }
1250:     }
1251: 
1252:     /**
1253:      * Handles the GET & POST request for the form_import area.
1254:      * On a GET request a form is displayed that allows for uploading an XML
1255:      * export file and an additional checkbox to select if gathered data should
1256:      * be imported too.
1257:      * On a POST request the import of the uploaded file is performed via
1258:      * PifaImporter. Eventually a notification is displayed.
1259:      *
1260:      * @param bool $showTableNameField
1261:      *
1262:      * @return string
1263:      * @throws cException
1264:      */
1265:     private function _importFormGet($showTableNameField = false) {
1266:         $cfg = cRegistry::getConfig();
1267: 
1268:         $tpl = cSmartyBackend::getInstance(true);
1269: 
1270:         // translations
1271:         $tpl->assign('trans', array(
1272:             'legend' => Pifa::i18n('pifa_import_form'),
1273:             'xml' => Pifa::i18n('XML'),
1274:             'used_table_name_error' => Pifa::i18n('USED_TABLE_NAME_ERROR'),
1275:             'table_name' => Pifa::i18n('data table'),
1276:             'export' => Pifa::i18n('IMPORT'),
1277:         ));
1278: 
1279:         $tpl->assign('formAction', 'main.php?' . implode('&', array(
1280:             'area=form_import',
1281:             'frame=4',
1282:             'contenido=' . cRegistry::getBackendSessionId(),
1283:             'action=' . self::IMPORT_FORM,
1284:         )));
1285: 
1286:         $tpl->assign('showTableNameField', $showTableNameField);
1287: 
1288:         $out = $tpl->fetch($cfg['templates']['pifa_right_bottom_import']);
1289: 
1290:         return $out;
1291:     }
1292: 
1293:     /**
1294:      * Handles the GET & POST request for the form_import area.
1295:      * On a GET request a form is displayed that allows for uploading an XML
1296:      * export file and an additional checkbox to select if gathered data should
1297:      * be imported too.
1298:      * On a POST request the import of the uploaded file is performed via
1299:      * PifaImporter. Eventually a notification is displayed.
1300:      *
1301:      * @return string
1302:      * @throws cException
1303:      */
1304:     private function _importFormPost() {
1305:         $cGuiNotification = new cGuiNotification();
1306: 
1307:         // read XML from file
1308:         $xml = file_get_contents($_FILES['xml']['tmp_name']);
1309:         $tableName = isset($_POST['table_name'])? $_POST['table_name'] : NULL;
1310: 
1311:         // check read operation
1312:         if (false === $xml) {
1313:             $note = Pifa::i18n('READ_XML_ERROR');
1314:             return $cGuiNotification->returnNotification(cGuiNotification::LEVEL_ERROR, $note);
1315:         }
1316: 
1317:         try {
1318: 
1319:             // perform import process
1320:             $pifaImporter = new PifaImporter();
1321:             $pifaImporter->setTableName($tableName);
1322:             $pifaImporter->import($xml);
1323: 
1324:             // display success message
1325:             $note = Pifa::i18n('IMPORT_SUCCESS');
1326:             $out = $cGuiNotification->returnNotification(cGuiNotification::LEVEL_OK, $note);
1327:         } catch (PifaDatabaseException $e) {
1328:             $out = $this->_importFormGet(true);
1329:         }
1330: 
1331:         return $out;
1332:     }
1333: 
1334: }
1335: 
CMS CONTENIDO 4.10.1 API documentation generated by ApiGen 2.8.0