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