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
    • NavigationMain
    • 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

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