Overview

Packages

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