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
  • PifaExternalOptionsDatasourceInterface
  • PifaField
  • PifaFieldCollection
  • PifaForm
  • PifaFormCollection
  • PifaLeftBottomPage
  • PifaRightBottomFormDataPage
  • PifaRightBottomFormFieldsPage
  • 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:  * Creates a page to be displayed in the left bottom frame.
 18:  *
 19:  * @author marcus.gnass
 20:  */
 21: class PifaLeftBottomPage extends cGuiPage {
 22: 
 23:     /**
 24:      *
 25:      * @throws PifaIllegalStateException
 26:      */
 27:     public function __construct() {
 28: 
 29:         /**
 30:          *
 31:          * @param string $action to be performed
 32:          */
 33:         global $action;
 34: 
 35:         /**
 36:          *
 37:          * @param int $idform id of form to be edited
 38:          */
 39:         global $idform;
 40: 
 41:         parent::__construct('left_bottom', Pifa::getName());
 42: 
 43:         $this->addScript('left_bottom.js');
 44: 
 45:         $this->set('s', 'menu', $this->_getMenu());
 46: 
 47:         // add translations to template
 48:         $this->set('s', 'I18N', json_encode(array(
 49:             'confirm_delete_form' => Pifa::i18n('CONFIRM_DELETE_FORM')
 50:         )));
 51:     }
 52: 
 53:     /**
 54:      * Get menu with all forms of current client in current language.
 55:      */
 56:     private function _getMenu() {
 57:         global $area;
 58: 
 59:         $cfg = cRegistry::getConfig();
 60:         $client = cRegistry::getClientId();
 61:         $lang = cRegistry::getLanguageId();
 62: 
 63:         // get all forms of current client in current language
 64:         $forms = PifaFormCollection::getByClientAndLang($client, $lang);
 65:         if (false === $forms) {
 66:             return '<!-- no forms for current client/language -->';
 67:         }
 68: 
 69:         // $formIcon = Pifa::getUrl() . 'images/icon_form.png';
 70: 
 71:         // create menu
 72:         $menu = new cGuiMenu();
 73:         while (false !== $form = $forms->next()) {
 74: 
 75:             $idform = $form->get('idform');
 76:             $formName = $form->get('name');
 77: 
 78:             $menu->setTitle($idform, $formName);
 79: 
 80:             // create link to show/edit the form
 81:             $link = new cHTMLLink();
 82:             $link->setMultiLink($area, '', $area, PifaRightBottomFormPage::SHOW_FORM);
 83:             $link->setCustom('idform', $idform);
 84:             $menu->setLink($idform, $link);
 85: 
 86:             // create link to delete the form
 87:             if (cRegistry::getPerm()->have_perm_area_action('form', PifaRightBottomFormPage::DELETE_FORM)) {
 88:                 $link = new cHTMLLink();
 89:                 $link->setMultiLink($area, PifaRightBottomFormPage::DELETE_FORM, $area, PifaRightBottomFormPage::DELETE_FORM);
 90:                 $link->setCustom('idform', $idform);
 91:                 $link->setClass('pifa-icon-delete-form');
 92:                 $deleteForm = Pifa::i18n('DELETE_FORM');
 93:                 $link->setAlt($deleteForm);
 94:                 $link->setContent('<img src="' . $cfg['path']['images'] . 'delete.gif" title="' . $deleteForm . '" alt="' . $deleteForm . '">');
 95:                 // $menu->setLink($idform, $link);
 96:                 $menu->setActions($idform, 'delete', $link);
 97:             } else {
 98:                 $menu->setActions($idform, 'delete', '<img src="' . $cfg['path']['images'] . 'delete_inact.gif" title="' . $deleteForm . '" alt="' . $deleteForm . '">');
 99:             }
100:         }
101: 
102:         return $menu->render(false);
103:     }
104: }
105: 
106: /**
107:  * Creates a page to be displayed in the right bottom frame.
108:  *
109:  * @author marcus.gnass
110:  */
111: class PifaRightBottomFormPage extends cGuiPage {
112: 
113:     /**
114:      *
115:      * @var string
116:      */
117:     const SHOW_FORM = 'pifa_show_form';
118: 
119:     /**
120:      *
121:      * @var string
122:      */
123:     const STORE_FORM = 'pifa_store_form';
124: 
125:     /**
126:      *
127:      * @var string
128:      */
129:     const DELETE_FORM = 'pifa_delete_form';
130: 
131:     /**
132:      * model for a single PIFA form
133:      *
134:      * @var PifaForm
135:      */
136:     private $_pifaForm = NULL;
137: 
138:     /**
139:      * Creates and aggregates a model for a collection of PIFA forms
140:      * and another for a single PIFA form.
141:      *
142:      * If an ID for an item is given this is loaded from database
143:      * and its values are stored in the appropriate model.
144:      *
145:      * @throws PifaException
146:      */
147:     public function __construct() {
148: 
149:         /**
150:          *
151:          * @param string $action to be performed
152:          */
153:         global $action;
154: 
155:         /**
156:          *
157:          * @param int $idform id of form to be edited
158:          */
159:         global $idform;
160: 
161:         /**
162:          *
163:          * @param int $idfield id of field to be edited
164:          */
165:         global $idfield;
166: 
167:         parent::__construct('right_bottom', Pifa::getName());
168: 
169:         $this->addStyle('smoothness/jquery-ui-1.8.20.custom.css');
170:         $this->addStyle('right_bottom.css');
171:         $this->addScript('right_bottom.js');
172: 
173:         // create models
174:         $this->_pifaForm = new PifaForm();
175: 
176:         // load models
177:         $idform = cSecurity::toInteger($idform);
178:         if (0 < $idform) {
179:             if (false === $this->_pifaForm->loadByPrimaryKey($idform)) {
180:                 $msg = Pifa::i18n('FORM_LOAD_ERROR');
181:                 throw new PifaException($msg);
182:             }
183:         }
184: 
185:         // add translations to template
186:         $this->set('s', 'I18N', json_encode(array(
187:             'cancel' => Pifa::i18n('CANCEL'),
188:             'save' => Pifa::i18n('SAVE')
189:         )));
190: 
191:         // dispatch action
192:         try {
193:             $this->_dispatch($action);
194:         } catch (PifaException $e) {
195:             $cGuiNotification = new cGuiNotification();
196:             $notification = $cGuiNotification->returnNotification(cGuiNotification::LEVEL_ERROR, $e->getMessage());
197:             $this->set('s', 'notification', $notification);
198:             $this->set('s', 'content', '');
199:         }
200:     }
201: 
202:     /**
203:      * Dispatches the given action.
204:      *
205:      * @param string $action to be executed
206:      * @param string $notification
207:      * @throws PifaException if the given action is unknown
208:      */
209:     protected function _dispatch($action, $notification = '') {
210:         global $area;
211: 
212:         // check for permission
213:         if (!cRegistry::getPerm()->have_perm_area_action($area, $action)) {
214:             $msg = Pifa::i18n('NO_PERMISSIONS');
215:             throw new PifaIllegalStateException($msg);
216:         }
217: 
218:         if (NULL === $action) {
219:             $cGuiNotification = new cGuiNotification();
220:             $notification = $cGuiNotification->returnNotification(cGuiNotification::LEVEL_INFO, Pifa::i18n('please select a form'));
221:             $this->set('s', 'notification', $notification);
222:             $this->set('s', 'content', '');
223:             return;
224:         }
225: 
226:         // dispatch actions
227:         switch ($action) {
228:             case PifaRightBottomFormPage::SHOW_FORM:
229:                 $this->set('s', 'notification', $notification);
230:                 try {
231:                     $this->set('s', 'content', $this->_showForm());
232:                 } catch (SmartyCompilerException $e) {
233:                     $this->set('s', 'content', Pifa::notifyException($e));
234:                 }
235:                 break;
236: 
237:             case PifaRightBottomFormPage::STORE_FORM:
238:                 $notification = '';
239:                 try {
240:                     $this->_storeForm();
241:                     $this->setReload();
242:                     // reload right_top after saving of form
243:                     $idform = $this->_pifaForm->get('idform');
244:                     $url = "main.php?area=form&frame=3&idform=$idform&action=" . PifaRightBottomFormPage::SHOW_FORM;
245:                     $url = cRegistry::getSession()->url($url);
246:                     $this->addScript("<script type=\"text/javascript\">
247:                         parent.parent.frames['right'].frames['right_top'].location.href = '$url';
248:                         </script>");
249:                 } catch (Exception $e) {
250:                     $notification = Pifa::notifyException($e);
251:                 }
252:                 $this->_dispatch(PifaRightBottomFormPage::SHOW_FORM, $notification);
253:                 break;
254: 
255:             case PifaRightBottomFormPage::DELETE_FORM:
256:                 $notification = '';
257:                 try {
258:                     $this->_deleteForm();
259:                     $cGuiNotification = new cGuiNotification();
260:                     $this->set('s', 'notification', $cGuiNotification->returnNotification(cGuiNotification::LEVEL_INFO, Pifa::i18n('FORM_DELETED')));
261:                     $this->set('s', 'content', '');
262:                     $this->setReload();
263:                 } catch (Exception $e) {
264:                     $notification = Pifa::notifyException($e);
265:                 }
266:                 break;
267: 
268:             default:
269:                 $msg = Pifa::i18n('UNKNOWN_ACTION');
270:                 throw new PifaException($msg);
271:         }
272:     }
273: 
274:     /**
275:      * Build and return form for PIFA forms.
276:      *
277:      * @return string
278:      */
279:     private function _showForm() {
280:         global $area;
281: 
282:         $cfg = cRegistry::getConfig();
283: 
284:         // get form action
285:         $formAction = '';
286:         if (cRegistry::getPerm()->have_perm_area_action('form', self::STORE_FORM)) {
287:             $formAction = new cHTMLLink();
288:             $formAction->setCLink($area, 4, PifaRightBottomFormPage::STORE_FORM);
289:             $formAction = $formAction->getHref();
290:         }
291: 
292:         // get current or default values for form
293:         if (!is_null($this->_pifaForm) && $this->_pifaForm->isLoaded()) {
294:             $idform = $this->_pifaForm->get('idform');
295:             $nameValue = $this->_pifaForm->get('name');
296:             $dataTableValue = $this->_pifaForm->get('data_table');
297:             $methodValue = $this->_pifaForm->get('method');
298:             $withTimestampValue = (bool) $this->_pifaForm->get('with_timestamp');
299:         } else {
300:             $idform = NULL;
301: 
302:             // read item data from form
303:             $nameValue = empty($_POST['name']) ? '':$_POST['name'];
304:             $nameValue = cSecurity::unescapeDB($nameValue);
305:             $nameValue = cSecurity::toString($nameValue);
306:             $nameValue = trim($nameValue);
307: 
308:             $dataTableValue = empty($_POST['data_table']) ? '':$_POST['data_table'];
309:             $dataTableValue = trim($dataTableValue);
310:             $dataTableValue = strtolower($dataTableValue);
311:             $dataTableValue = preg_replace('/[^a-z0-9_]/', '_', $dataTableValue);
312: 
313:             $methodValue = '';
314:             $withTimestampValue = true;
315:         }
316: 
317:         $tpl = Contenido_SmartyWrapper::getInstance(true);
318:         $tpl->assign('formAction', $formAction);
319:         $tpl->assign('idform', $idform);
320:         $tpl->assign('nameValue', $nameValue);
321:         $tpl->assign('dataTableValue', $dataTableValue);
322:         $tpl->assign('methodValue', strtoupper($methodValue));
323:         $tpl->assign('withTimestampValue', $withTimestampValue);
324:         $tpl->assign('hasWithTimestamp', Pifa::TIMESTAMP_BYFORM === Pifa::getTimestampSetting());
325:         $tpl->assign('trans', array(
326:             'legend' => Pifa::i18n('form'),
327:             'name' => Pifa::i18n('form name'),
328:             'dataTable' => Pifa::i18n('data table'),
329:             'method' => Pifa::i18n('method'),
330:             'withTimestamp' => Pifa::i18n('with timestamp'),
331:             'pleaseChoose' => Pifa::i18n('please choose'),
332:             'saveForm' => Pifa::i18n('save form')
333:         ));
334: 
335:         $out = $tpl->fetch($cfg['templates']['pifa_right_bottom_form']);
336: 
337:         return $out;
338:     }
339: 
340:     /**
341:      * Handles a POST request of the first form, showing a forms details.
342:      *
343:      * @throws PifaException
344:      */
345:     private function _storeForm() {
346: 
347:         // determine if item is loaded
348:         $isLoaded = $this->_pifaForm->isLoaded();
349: 
350:         // read item data from form
351:         $name = $_POST['name'];
352:         $name = cSecurity::unescapeDB($name);
353:         $name = cSecurity::toString($name);
354:         $name = trim($name);
355: 
356:         $dataTable = $_POST['data_table'];
357:         $dataTable = trim($dataTable);
358:         $dataTable = strtolower($dataTable);
359:         $dataTable = preg_replace('/[^a-z0-9_]/', '_', $dataTable);
360: 
361:         $method = $_POST['method'];
362:         $method = trim($method);
363:         $method = strtoupper($method);
364: 
365:         switch (Pifa::getTimestampSetting()) {
366:             case Pifa::TIMESTAMP_NEVER:
367:                 $withTimestamp = false;
368:                 break;
369:             case Pifa::TIMESTAMP_BYFORM:
370:                 $withTimestamp = 'on' === $_POST['with_timestamp'];
371:                 break;
372:             case Pifa::TIMESTAMP_ALWAYS:
373:                 $withTimestamp = true;
374:                 break;
375:         }
376: 
377:         // validate item data
378:         if (0 === strlen($name)) {
379:             $msg = Pifa::i18n('EMPTY_FORMNAME_ERROR');
380:             throw new PifaException($msg);
381:         }
382:         if (0 === strlen($dataTable)) {
383:             $msg = Pifa::i18n('EMPTY_DATETABLENAME_ERROR');
384:             throw new PifaException($msg);
385:         }
386:         if (!in_array($method, array(
387:             'GET',
388:             'POST'
389:         ))) {
390:             $msg = Pifa::i18n('FORM_METHOD_ERROR');
391:             throw new PifaException($msg);
392:         }
393: 
394:         if ($isLoaded) {
395:             // remember old table values
396:             $oldDataTable = $this->_pifaForm->get('data_table');
397:             $oldWithTimestamp = (bool) $this->_pifaForm->get('with_timestamp');
398:         } else {
399:             // create new item for given client & language
400:             $pifaFormCollection = new PifaFormCollection();
401:             $this->_pifaForm = $pifaFormCollection->createNewItem(array(
402:                 'idclient' => cRegistry::getClientId(),
403:                 'idlang' => cRegistry::getLanguageId()
404:             ));
405:         }
406: 
407:         // set item data
408:         // Never, really never, call Item->set() if the value doesn't differ
409:         // from the previous one. Otherwise the genericDb thinks that the item
410:         // is modified and tries to store it resulting in a return value of
411:         // false!
412:         if ($name !== $this->_pifaForm->get('name')) {
413:             $this->_pifaForm->set('name', $name);
414:         }
415:         if ($dataTable !== $this->_pifaForm->get('data_table')) {
416:             $this->_pifaForm->set('data_table', $dataTable);
417:         }
418:         if (0 !== strcasecmp($method, $this->_pifaForm->get('method'))) {
419:             $this->_pifaForm->set('method', $method);
420:         }
421:         if ($withTimestamp !== (bool) $this->_pifaForm->get('with_timestamp')) {
422:             $this->_pifaForm->set('with_timestamp', $withTimestamp);
423:         }
424: 
425:         // store item
426:         if (false === $this->_pifaForm->store()) {
427:             $msg = Pifa::i18n('FORM_STORE_ERROR');
428:             $msg = sprintf($msg, $this->_pifaForm->getLastError());
429:             throw new PifaException($msg);
430:         }
431: 
432:         if ($isLoaded) {
433:             // optionally alter data table
434:             // HINT: passing the old values is correct!
435:             // The new values have already been stored inside the pifaForm
436:             // object!
437:             $this->_pifaForm->alterTable($oldDataTable, $oldWithTimestamp);
438:         } else {
439:             // create table
440:             $this->_pifaForm->createTable($withTimestamp);
441:         }
442:     }
443: 
444:     /**
445:      */
446:     private function _deleteForm() {
447:         $this->_pifaForm->delete();
448:         $this->_pifaForm = NULL;
449:     }
450: }
451: 
452: /**
453:  * Creates a page to be displayed in the right bottom frame.
454:  *
455:  * @author marcus.gnass
456:  */
457: class PifaRightBottomFormFieldsPage extends cGuiPage {
458: 
459:     /**
460:      *
461:      * @var string
462:      */
463:     const SHOW_FIELDS = 'pifa_show_fields';
464: 
465:     /**
466:      * model for a single PIFA form
467:      *
468:      * @var PifaForm
469:      */
470:     private $_pifaForm = NULL;
471: 
472:     /**
473:      * Creates and aggregates a model for a collection of PIFA forms
474:      * and another for a single PIFA form.
475:      *
476:      * If an ID for an item is given this is loaded from database
477:      * and its values are stored in the appropriate model.
478:      *
479:      * @throws PifaException
480:      */
481:     public function __construct() {
482: 
483:         /**
484:          *
485:          * @param string $action to be performed
486:          */
487:         global $action;
488: 
489:         /**
490:          *
491:          * @param int $idform id of form to be edited
492:          */
493:         global $idform;
494: 
495:         /**
496:          *
497:          * @param int $idfield id of field to be edited
498:          */
499:         global $idfield;
500: 
501:         parent::__construct('right_bottom', Pifa::getName());
502: 
503:         $this->addStyle('smoothness/jquery-ui-1.8.20.custom.css');
504:         $this->addStyle('right_bottom.css');
505:         $this->addScript('right_bottom.js');
506: 
507:         // create models
508:         $this->_pifaForm = new PifaForm();
509: 
510:         // load models
511:         $idform = cSecurity::toInteger($idform);
512:         if (0 < $idform) {
513:             $ret = $this->_pifaForm->loadByPrimaryKey($idform);
514:             if (false === $ret) {
515:                 $msg = Pifa::i18n('FORM_LOAD_ERROR');
516:                 throw new PifaException($msg);
517:             }
518:         }
519: 
520:         // add translations to template
521:         $this->set('s', 'I18N', json_encode(array(
522:             'cancel' => Pifa::i18n('CANCEL'),
523:             'save' => Pifa::i18n('SAVE'),
524:             'confirm_delete_field' => Pifa::i18n('CONFIRM_DELETE_FIELD')
525:         )));
526: 
527:         // dispatch action
528:         try {
529:             $this->_dispatch($action);
530:         } catch (PifaException $e) {
531:             $cGuiNotification = new cGuiNotification();
532:             $notification = $cGuiNotification->returnNotification(cGuiNotification::LEVEL_ERROR, $e->getMessage());
533:             $this->set('s', 'notification', $notification);
534:             $this->set('s', 'content', '');
535:         }
536:     }
537: 
538:     /**
539:      * Dispatches the given action.
540:      *
541:      * @param string $action to be executed
542:      * @param string $notification
543:      * @throws PifaException if the given action is unknown
544:      */
545:     protected function _dispatch($action, $notification = '') {
546:         global $area;
547: 
548:         // check for permission
549:         if (!cRegistry::getPerm()->have_perm_area_action($area, $action)) {
550:             $msg = Pifa::i18n('NO_PERMISSIONS');
551:             throw new PifaIllegalStateException($msg);
552:         }
553: 
554:         if (NULL === $action) {
555:             $this->set('s', 'notification', Pifa::i18n('please select a form'));
556:             $this->set('s', 'content', '');
557:             return;
558:         }
559: 
560:         // dispatch actions
561:         switch ($action) {
562: 
563:             case PifaRightBottomFormFieldsPage::SHOW_FIELDS:
564:                 $this->set('s', 'notification', $notification);
565:                 try {
566:                     $this->set('s', 'content', $this->_showFields());
567:                 } catch (SmartyCompilerException $e) {
568:                     $this->set('s', 'content', Pifa::notifyException($e));
569:                 }
570:                 break;
571: 
572:             default:
573:                 $msg = Pifa::i18n('UNKNOWN_ACTION');
574:                 throw new PifaException($msg);
575:         }
576:     }
577: 
578:     /**
579:      */
580:     private function _showFields() {
581:         global $area;
582: 
583:         $cfg = cRegistry::getConfig();
584: 
585:         $idform = $idfield = NULL;
586:         $fieldTypes = $fields = NULL;
587:         $editField = $deleteField = NULL;
588:         if ($this->_pifaForm->isLoaded()) {
589: 
590:             $idform = $this->_pifaForm->get('idform');
591:             $idfield = $_GET['idfield'];
592: 
593:             $fieldTypes = $this->_getFieldTypes();
594:             $fields = $this->_pifaForm->getFields();
595: 
596:             if (cRegistry::getPerm()->have_perm_area_action('form_ajax', PifaAjaxHandler::GET_FIELD_FORM)) {
597:                 $editField = new cHTMLLink();
598:                 $editField->setCLink('form_ajax', 4, PifaAjaxHandler::GET_FIELD_FORM);
599:                 $editField->setCustom('idform', $idform);
600:                 $editField = $editField->getHref();
601:             }
602: 
603:             if (cRegistry::getPerm()->have_perm_area_action('form_ajax', PifaAjaxHandler::DELETE_FIELD)) {
604:                 $deleteField = new cHTMLLink();
605:                 $deleteField->setCLink('form_ajax', 4, PifaAjaxHandler::DELETE_FIELD);
606:                 $deleteField->setCustom('idform', $idform);
607:                 $deleteField = $deleteField->getHref();
608:             }
609:         }
610: 
611:         // get and fill template
612:         $tpl = Contenido_SmartyWrapper::getInstance(true);
613: 
614:         // translations
615:         $tpl->assign('trans', array(
616:             'legend' => Pifa::i18n('fields'),
617:             'pleaseSaveFirst' => Pifa::i18n('please save first'),
618:             'dialogTitle' => Pifa::i18n('edit field'),
619:             'edit' => Pifa::i18n('EDIT'),
620:             'delete' => Pifa::i18n('DELETE'),
621:             'obligatory' => Pifa::i18n('OBLIGATORY')
622:         ));
623: 
624:         // params
625:         $tpl->assign('ajaxParams', implode('&', array(
626:             'area=form_ajax',
627:             'frame=4',
628:             'contenido=' . cRegistry::getBackendSessionId()
629:         )));
630:         if (cRegistry::getPerm()->have_perm_area_action('form_ajax', PifaAjaxHandler::GET_FIELD_FORM)) {
631:             $tpl->assign('dragParams', implode('&', array(
632:                 'area=form_ajax',
633:                 'frame=4',
634:                 'contenido=' . cRegistry::getBackendSessionId(),
635:                 'action=' . PifaAjaxHandler::GET_FIELD_FORM,
636:                 'idform=' . $idform
637:             )));
638:         }
639:         if (cRegistry::getPerm()->have_perm_area_action('form_ajax', PifaAjaxHandler::REORDER_FIELDS)) {
640:             $tpl->assign('sortParams', implode('&', array(
641:                 'area=form_ajax',
642:                 'frame=4',
643:                 'contenido=' . cRegistry::getBackendSessionId(),
644:                 'action=' . PifaAjaxHandler::REORDER_FIELDS,
645:                 'idform=' . $this->_pifaForm->get('idform')
646:             )));
647:         }
648: 
649:         // data
650:         $tpl->assign('idform', $idform);
651:         $tpl->assign('idfield', $idfield);
652: 
653:         $tpl->assign('fields', $fields);
654:         // $tpl->assign('fieldTypes', PifaField::getFieldTypeIds());
655:         $tpl->assign('fieldTypes', PifaField::getFieldTypeNames());
656: 
657:         // for partial
658:         $tpl->assign('editField', $editField);
659:         $tpl->assign('deleteField', $deleteField);
660:         // define path to partial template for displaying a single field row
661:         $tpl->assign('partialFieldRow', $cfg['templates']['pifa_ajax_field_row']);
662: 
663:         $out = $tpl->fetch($cfg['templates']['pifa_right_bottom_fields']);
664: 
665:         return $out;
666:     }
667: 
668:     /**
669:      * Returns a multidimensional array with available field types.
670:      * This array contains values for the label and icon of the field type.
671:      *
672:      * @return array
673:      */
674:     private function _getFieldTypes() {
675:         $fieldTypes = array();
676:         foreach (PifaField::getFieldTypeIds() as $fieldTypeId) {
677:             $fieldTypes[$fieldTypeId] = array();
678:             $fieldTypes[$fieldTypeId]['id'] = $fieldTypeId;
679:             $fieldTypes[$fieldTypeId]['label'] = PifaField::getFieldTypeName($fieldTypeId);
680:             // icon is not used atm
681:             $fieldTypes[$fieldTypeId]['icon'] = PifaField::getFieldTypeIcon($fieldTypeId);
682:         }
683: 
684:         return $fieldTypes;
685:     }
686: }
687: 
688: /**
689:  * Creates a page to be displayed in the right bottom frame.
690:  *
691:  * @author marcus.gnass
692:  */
693: class PifaRightBottomFormDataPage extends cGuiPage {
694: 
695:     /**
696:      *
697:      * @var string
698:      */
699:     const SHOW_DATA = 'pifa_show_data';
700: 
701:     /**
702:      * model for a single PIFA form
703:      *
704:      * @var PifaForm
705:      */
706:     private $_pifaForm = NULL;
707: 
708:     /**
709:      * Creates and aggregates a model for a collection of PIFA forms
710:      * and another for a single PIFA form.
711:      *
712:      * If an ID for an item is given this is loaded from database
713:      * and its values are stored in the appropriate model.
714:      *
715:      * @throws PifaException
716:      */
717:     public function __construct() {
718: 
719:         /**
720:          *
721:          * @param string $action to be performed
722:          */
723:         global $action;
724: 
725:         /**
726:          *
727:          * @param int $idform id of form to be edited
728:          */
729:         global $idform;
730: 
731:         /**
732:          *
733:          * @param int $idfield id of field to be edited
734:          */
735:         global $idfield;
736: 
737:         parent::__construct('right_bottom', Pifa::getName());
738: 
739:         $this->addStyle('smoothness/jquery-ui-1.8.20.custom.css');
740:         $this->addStyle('right_bottom.css');
741:         $this->addScript('right_bottom.js');
742: 
743:         // create models
744:         $this->_pifaForm = new PifaForm();
745: 
746:         // load models
747:         $idform = cSecurity::toInteger($idform);
748:         if (0 < $idform) {
749:             if (false === $this->_pifaForm->loadByPrimaryKey($idform)) {
750:                 $msg = Pifa::i18n('FORM_LOAD_ERROR');
751:                 throw new PifaException($msg);
752:             }
753:         }
754: 
755:         // add translations to template
756:         $this->set('s', 'I18N', json_encode(array(
757:             'cancel' => Pifa::i18n('CANCEL'),
758:             'save' => Pifa::i18n('SAVE')
759:         )));
760: 
761:         // dispatch action
762:         try {
763:             $this->_dispatch($action);
764:         } catch (PifaException $e) {
765:             $cGuiNotification = new cGuiNotification();
766:             $notification = $cGuiNotification->returnNotification(cGuiNotification::LEVEL_ERROR, $e->getMessage());
767:             $this->set('s', 'notification', $notification);
768:             $this->set('s', 'content', '');
769:         }
770:     }
771: 
772:     /**
773:      * Dispatches the given action.
774:      *
775:      * @param string $action to be executed
776:      * @param string $notification
777:      * @throws PifaException if the given action is unknown
778:      */
779:     protected function _dispatch($action, $notification = '') {
780:         global $area;
781: 
782:         // check for permission
783:         if (!cRegistry::getPerm()->have_perm_area_action($area, $action)) {
784:             $msg = Pifa::i18n('NO_PERMISSIONS');
785:             throw new PifaIllegalStateException($msg);
786:         }
787: 
788:         if (NULL === $action) {
789:             $this->set('s', 'notification', Pifa::i18n('please select a form'));
790:             $this->set('s', 'content', '');
791:             return;
792:         }
793: 
794:         // dispatch actions
795:         switch ($action) {
796: 
797:             case PifaRightBottomFormDataPage::SHOW_DATA:
798:                 $this->set('s', 'notification', $notification);
799:                 try {
800:                     $this->set('s', 'content', $this->_showData());
801:                 } catch (SmartyCompilerException $e) {
802:                     $this->set('s', 'content', Pifa::notifyException($e));
803:                 }
804:                 break;
805: 
806:             default:
807:                 $msg = Pifa::i18n('UNKNOWN_ACTION');
808:                 throw new PifaException($msg);
809:         }
810:     }
811: 
812:     /**
813:      */
814:     private function _showData() {
815:         $cfg = cRegistry::getConfig();
816: 
817:         $tpl = Contenido_SmartyWrapper::getInstance(true);
818: 
819:         // translations
820:         $tpl->assign('trans', array(
821:             'legend' => Pifa::i18n('data'),
822:             'pleaseSaveFirst' => Pifa::i18n('please save first'),
823:             'export' => Pifa::i18n('download data as CSV')
824:         ));
825: 
826:         if (cRegistry::getPerm()->have_perm_area_action('form_ajax', PifaAjaxHandler::EXPORT_DATA)) {
827:             $tpl->assign('exportUrl', 'main.php?' . implode('&', array(
828:                 'area=form_ajax',
829:                 'frame=4',
830:                 'contenido=' . cRegistry::getBackendSessionId(),
831:                 'action=' . PifaAjaxHandler::EXPORT_DATA,
832:                 'idform=' . $this->_pifaForm->get('idform')
833:             )));
834:         }
835:         $tpl->assign('form', $this->_pifaForm);
836:         $tpl->assign('getFileUrl', 'main.php?' . implode('&', array(
837:             'area=form_ajax',
838:             'frame=4',
839:             'contenido=' . cRegistry::getBackendSessionId(),
840:             'action=' . PifaAjaxHandler::GET_FILE
841:         )));
842: 
843:         try {
844:             $tpl->assign('fields', $this->_pifaForm->getFields());
845:         } catch (Exception $e) {
846:             $tpl->assign('fields', Pifa::notifyException($e));
847:         }
848: 
849:         $tpl->assign('withTimestamp', (bool) $this->_pifaForm->get('with_timestamp'));
850: 
851:         try {
852:             $tpl->assign('data', $this->_pifaForm->getData());
853:         } catch (Exception $e) {
854:             $tpl->assign('data', Pifa::notifyException($e));
855:         }
856: 
857:         $out = $tpl->fetch($cfg['templates']['pifa_right_bottom_data']);
858: 
859:         return $out;
860:     }
861: }
862: 
CMS CONTENIDO 4.9.1 API documentation generated by ApiGen 2.8.0