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
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • 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
  • SolrRightBottomPage

Exceptions

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