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_INFO, 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:
687: $tpl->assign('trans', array(
688: 'legend' => Pifa::i18n('fields'),
689: 'pleaseSaveFirst' => Pifa::i18n('please save first'),
690: 'dialogTitle' => Pifa::i18n('edit field'),
691: 'edit' => Pifa::i18n('EDIT'),
692: 'delete' => Pifa::i18n('DELETE'),
693: 'obligatory' => Pifa::i18n('OBLIGATORY')
694: ));
695:
696:
697: $tpl->assign('ajaxParams', implode('&', array(
698: 'area=form_ajax',
699: 'frame=4',
700: 'contenido=' . cRegistry::getBackendSessionId()
701: )));
702: if (cRegistry::getPerm()->have_perm_area_action('form_ajax', PifaAjaxHandler::GET_FIELD_FORM)) {
703: $tpl->assign('dragParams', implode('&', array(
704: 'area=form_ajax',
705: 'frame=4',
706: 'contenido=' . cRegistry::getBackendSessionId(),
707: 'action=' . PifaAjaxHandler::GET_FIELD_FORM,
708: 'idform=' . $idform
709: )));
710: }
711: if (cRegistry::getPerm()->have_perm_area_action('form_ajax', PifaAjaxHandler::REORDER_FIELDS)) {
712: $tpl->assign('sortParams', implode('&', array(
713: 'area=form_ajax',
714: 'frame=4',
715: 'contenido=' . cRegistry::getBackendSessionId(),
716: 'action=' . PifaAjaxHandler::REORDER_FIELDS,
717: 'idform=' . $this->_pifaForm->get('idform')
718: )));
719: }
720:
721:
722: $tpl->assign('idform', $idform);
723: $tpl->assign('idfield', $idfield);
724:
725: $tpl->assign('fields', $fields);
726: $tpl->assign('fieldTypes', PifaField::getFieldTypeNames());
727:
728:
729: $tpl->assign('editField', $editField);
730: $tpl->assign('deleteField', $deleteField);
731:
732: $tpl->assign('partialFieldRow', $cfg['templates']['pifa_ajax_field_row']);
733:
734: $out = $tpl->fetch($cfg['templates']['pifa_right_bottom_fields']);
735:
736: return $out;
737: }
738:
739: }
740:
741: 742: 743: 744: 745:
746: class PifaRightBottomFormDataPage extends cGuiPage {
747:
748: 749: 750: 751: 752:
753: const SHOW_DATA = 'pifa_show_data';
754:
755: 756: 757: 758: 759:
760: private $_pifaForm = NULL;
761:
762: 763: 764: 765: 766: 767: 768: 769: 770:
771: public function __construct() {
772:
773: 774: 775: 776:
777: global $action;
778:
779: 780: 781: 782:
783: global $idform;
784:
785: 786: 787: 788:
789: global $idfield;
790:
791: parent::__construct('right_bottom', Pifa::getName());
792:
793: $this->addStyle('smoothness/jquery-ui-1.8.20.custom.css');
794: $this->addStyle('right_bottom.css');
795: $this->addScript('form_assistant.js');
796: $this->addScript('right_bottom.js');
797:
798:
799: $this->_pifaForm = new PifaForm();
800:
801:
802: $idform = cSecurity::toInteger($idform);
803: if (0 < $idform) {
804: if (false === $this->_pifaForm->loadByPrimaryKey($idform)) {
805: $msg = Pifa::i18n('FORM_LOAD_ERROR');
806: throw new PifaException($msg);
807: }
808: }
809:
810:
811: $this->set('s', 'I18N', json_encode(array(
812: 'cancel' => Pifa::i18n('CANCEL'),
813: 'save' => Pifa::i18n('SAVE')
814: )));
815:
816:
817: try {
818: $this->_dispatch($action);
819: } catch (PifaException $e) {
820: $cGuiNotification = new cGuiNotification();
821: $notification = $cGuiNotification->returnNotification(cGuiNotification::LEVEL_ERROR, $e->getMessage());
822: $this->set('s', 'notification', $notification);
823: $this->set('s', 'content', '');
824: }
825: }
826:
827: 828: 829: 830: 831: 832: 833: 834:
835: protected function _dispatch($action, $notification = '') {
836: global $area;
837:
838:
839: if (!cRegistry::getPerm()->have_perm_area_action($area, $action)) {
840: $msg = Pifa::i18n('NO_PERMISSIONS');
841: throw new PifaIllegalStateException($msg);
842: }
843:
844: if (NULL === $action) {
845: $this->set('s', 'notification', Pifa::i18n('please select a form'));
846: $this->set('s', 'content', '');
847: return;
848: }
849:
850:
851: switch ($action) {
852:
853: case self::SHOW_DATA:
854: $this->set('s', 'notification', $notification);
855: try {
856: $this->set('s', 'content', $this->_showData());
857: } catch (SmartyCompilerException $e) {
858: $this->set('s', 'content', Pifa::notifyException($e));
859: }
860: break;
861:
862: default:
863: $msg = Pifa::i18n('UNKNOWN_ACTION');
864: throw new PifaException($msg);
865: }
866: }
867:
868: 869:
870: private function _showData() {
871: $cfg = cRegistry::getConfig();
872:
873: $tpl = cSmartyBackend::getInstance(true);
874:
875:
876: $tpl->assign('trans', array(
877: 'legend' => Pifa::i18n('data'),
878: 'pleaseSaveFirst' => Pifa::i18n('please save first'),
879: 'export' => Pifa::i18n('download data as CSV')
880: ));
881:
882: $tpl->assign('form', $this->_pifaForm);
883: $tpl->assign('getFileUrl', 'main.php?' . implode('&', array(
884: 'area=form_ajax',
885: 'frame=4',
886: 'contenido=' . cRegistry::getBackendSessionId(),
887: 'action=' . PifaAjaxHandler::GET_FILE
888: )));
889:
890: try {
891: $tpl->assign('fields', $this->_pifaForm->getFields());
892: } catch (Exception $e) {
893: $tpl->assign('fields', Pifa::notifyException($e));
894: }
895:
896: $tpl->assign('withTimestamp', (bool) $this->_pifaForm->get('with_timestamp'));
897:
898: try {
899: $data = $this->_pifaForm->getData();
900: $tpl->assign('data', $data);
901: if (!empty($data) && cRegistry::getPerm()->have_perm_area_action('form_ajax', PifaAjaxHandler::EXPORT_DATA)) {
902: $tpl->assign('exportUrl', 'main.php?' . implode('&', array(
903: 'area=form_ajax',
904: 'frame=4',
905: 'contenido=' . cRegistry::getBackendSessionId(),
906: 'action=' . PifaAjaxHandler::EXPORT_DATA,
907: 'idform=' . $this->_pifaForm->get('idform')
908: )));
909: }
910: } catch (Exception $e) {
911: $tpl->assign('data', Pifa::notifyException($e));
912: }
913:
914: $out = $tpl->fetch($cfg['templates']['pifa_right_bottom_data']);
915:
916: return $out;
917: }
918:
919: }
920:
921: 922: 923: 924: 925: 926:
927: class PifaRightBottomFormExportPage extends cGuiPage {
928:
929: 930: 931: 932: 933:
934: const EXPORT_FORM = 'pifa_export_form';
935:
936: 937: 938: 939: 940:
941: private $_pifaForm = NULL;
942:
943: 944: 945: 946: 947: 948: 949: 950:
951: public function __construct() {
952:
953: 954: 955: 956:
957: global $action;
958:
959: 960: 961: 962:
963: global $idform;
964:
965: parent::__construct('right_bottom', Pifa::getName());
966:
967: $this->addStyle('smoothness/jquery-ui-1.8.20.custom.css');
968: $this->addStyle('right_bottom.css');
969: $this->addScript('form_assistant.js');
970: $this->addScript('right_bottom.js');
971:
972:
973: $this->_pifaForm = new PifaForm();
974:
975:
976: $idform = cSecurity::toInteger($idform);
977: if (0 < $idform) {
978: if (false === $this->_pifaForm->loadByPrimaryKey($idform)) {
979: $msg = Pifa::i18n('FORM_LOAD_ERROR');
980: throw new PifaException($msg);
981: }
982: }
983:
984:
985: try {
986: $this->_dispatch($action);
987: } catch (PifaException $e) {
988: $cGuiNotification = new cGuiNotification();
989: $notification = $cGuiNotification->returnNotification(cGuiNotification::LEVEL_ERROR, $e->getMessage());
990: $this->set('s', 'notification', $notification);
991: $this->set('s', 'content', '');
992: }
993: }
994:
995: 996: 997: 998: 999: 1000: 1001: 1002:
1003: protected function _dispatch($action, $notification = '') {
1004:
1005:
1006: switch ($action) {
1007:
1008: case self::EXPORT_FORM:
1009:
1010:
1011: if (!cRegistry::getPerm()->have_perm_area_action('form_ajax', $action)) {
1012: $msg = Pifa::i18n('NO_PERMISSIONS');
1013: throw new PifaIllegalStateException($msg);
1014: }
1015:
1016: $this->set('s', 'notification', $notification);
1017: try {
1018: $this->set('s', 'content', $this->_exportForm());
1019: } catch (SmartyCompilerException $e) {
1020: $this->set('s', 'content', Pifa::notifyException($e));
1021: }
1022: break;
1023:
1024: default:
1025: $msg = Pifa::i18n('UNKNOWN_ACTION');
1026: throw new PifaException($msg);
1027: }
1028: }
1029:
1030: 1031:
1032: private function _exportForm() {
1033: $cfg = cRegistry::getConfig();
1034:
1035: $tpl = cSmartyBackend::getInstance(true);
1036:
1037:
1038: $tpl->assign('trans', array(
1039: 'legend' => Pifa::i18n('pifa_export_form'),
1040: 'withData' => Pifa::i18n('WITH_DATA'),
1041: 'export' => Pifa::i18n('EXPORT')
1042: ));
1043:
1044: $tpl->assign('formAction', 'main.php?' . implode('&', array(
1045: 'area=form_ajax',
1046: 'frame=4',
1047: 'contenido=' . cRegistry::getBackendSessionId(),
1048: 'action=' . PifaAjaxHandler::EXPORT_FORM,
1049: 'idform=' . $this->_pifaForm->get('idform')
1050: )));
1051:
1052: $tpl->assign('idform', $this->_pifaForm->get('idform'));
1053:
1054: $out = $tpl->fetch($cfg['templates']['pifa_right_bottom_export']);
1055:
1056: return $out;
1057: }
1058:
1059: }
1060:
1061: 1062: 1063: 1064: 1065: 1066:
1067: class PifaRightBottomFormImportPage extends cGuiPage {
1068:
1069: 1070: 1071: 1072: 1073:
1074: const IMPORT_FORM = 'pifa_import_form';
1075:
1076: 1077: 1078: 1079:
1080: public function __construct() {
1081:
1082: 1083: 1084: 1085:
1086: global $action;
1087:
1088: parent::__construct('right_bottom', Pifa::getName());
1089:
1090: $this->addStyle('smoothness/jquery-ui-1.8.20.custom.css');
1091: $this->addStyle('right_bottom.css');
1092: $this->addScript('form_assistant.js');
1093: $this->addScript('right_bottom.js');
1094:
1095:
1096: try {
1097: $this->_dispatch($action);
1098: } catch (PifaException $e) {
1099: $cGuiNotification = new cGuiNotification();
1100: $notification = $cGuiNotification->returnNotification(cGuiNotification::LEVEL_ERROR, $e->getMessage());
1101: $this->set('s', 'notification', $notification);
1102: $this->set('s', 'content', '');
1103: }
1104: }
1105:
1106: 1107: 1108: 1109: 1110: 1111: 1112: 1113:
1114: protected function _dispatch($action, $notification = '') {
1115: global $area;
1116:
1117:
1118: if (!cRegistry::getPerm()->have_perm_area_action($area, $action)) {
1119: $msg = Pifa::i18n('NO_PERMISSIONS');
1120: throw new PifaIllegalStateException($msg);
1121: }
1122:
1123:
1124: switch ($action) {
1125:
1126: case self::IMPORT_FORM:
1127: $this->set('s', 'notification', $notification);
1128: try {
1129:
1130: switch (strtoupper($_SERVER['REQUEST_METHOD'])) {
1131: case 'GET':
1132: $this->set('s', 'content', $this->_importFormGet());
1133: break;
1134:
1135: case 'POST':
1136: $this->set('s', 'content', $this->_importFormPost());
1137: break;
1138: }
1139:
1140: $this->setReload();
1141: } catch (SmartyCompilerException $e) {
1142: $this->set('s', 'content', Pifa::notifyException($e));
1143: }
1144: break;
1145:
1146: default:
1147: $msg = Pifa::i18n('UNKNOWN_ACTION');
1148: throw new PifaException($msg);
1149: }
1150: }
1151:
1152: 1153: 1154: 1155: 1156: 1157: 1158: 1159: 1160: 1161:
1162: private function _importFormGet($showTableNameField = false) {
1163: $cfg = cRegistry::getConfig();
1164:
1165: $tpl = cSmartyBackend::getInstance(true);
1166:
1167:
1168: $tpl->assign('trans', array(
1169: 'legend' => Pifa::i18n('pifa_import_form'),
1170: 'xml' => Pifa::i18n('XML'),
1171: 'used_table_name_error' => Pifa::i18n('USED_TABLE_NAME_ERROR'),
1172: 'table_name' => Pifa::i18n('data table'),
1173: 'export' => Pifa::i18n('IMPORT')
1174: ));
1175:
1176: $tpl->assign('formAction', 'main.php?' . implode('&', array(
1177: 'area=form_import',
1178: 'frame=4',
1179: 'contenido=' . cRegistry::getBackendSessionId(),
1180: 'action=' . self::IMPORT_FORM
1181: )));
1182:
1183: $tpl->assign('showTableNameField', $showTableNameField);
1184:
1185: $out = $tpl->fetch($cfg['templates']['pifa_right_bottom_import']);
1186:
1187: return $out;
1188: }
1189:
1190: 1191: 1192: 1193: 1194: 1195: 1196: 1197: 1198: 1199:
1200: private function _importFormPost() {
1201: $cGuiNotification = new cGuiNotification();
1202:
1203:
1204: $xml = file_get_contents($_FILES['xml']['tmp_name']);
1205: $tableName = isset($_POST['table_name'])? $_POST['table_name'] : NULL;
1206:
1207:
1208: if (false === $xml) {
1209: $note = Pifa::i18n('READ_XML_ERROR');
1210: return $cGuiNotification->returnNotification(cGuiNotification::LEVEL_ERROR, $note);
1211: }
1212:
1213: try {
1214:
1215:
1216: $pifaImporter = new PifaImporter();
1217: $pifaImporter->setTableName($tableName);
1218: $pifaImporter->import($xml);
1219:
1220:
1221: $note = Pifa::i18n('IMPORT_SUCCESS');
1222: $out = $cGuiNotification->returnNotification(cGuiNotification::LEVEL_INFO, $note);
1223: } catch (PifaDatabaseException $e) {
1224: $out = $this->_importFormGet(true);
1225: }
1226:
1227: return $out;
1228: }
1229:
1230: }
1231: