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