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