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