1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: cInclude('includes', 'functions.con.php');
18: cInclude('includes', 'functions.upl.php');
19:
20: 21: 22: 23: 24: 25: 26: 27: 28: 29:
30: class cContentTypePifaForm extends cContentTypeAbstractTabbed {
31:
32: 33: 34: 35: 36: 37: 38: 39:
40: public static function sortByLabel($a, $b) {
41: return ($a['label'] == $b['label']) ? 0 : (($a['label'] < $b['label']) ? -1 : 1);
42: }
43:
44: 45: 46: 47: 48: 49: 50: 51: 52: 53:
54: function __construct($rawSettings, $id, array $contentTypes) {
55:
56:
57: $this->_type = 'CMS_PIFAFORM';
58: $this->_prefix = 'pifaform';
59: $this->_settingsType = self::SETTINGS_TYPE_XML;
60: $this->_formFields = array(
61: 'pifaform_idform',
62: 'pifaform_module',
63: 'pifaform_processor',
64: 'pifaform_template_get',
65: 'pifaform_template_post',
66: 'pifaform_mail_client_template',
67: 'pifaform_mail_client_from_email',
68: 'pifaform_mail_client_from_name',
69: 'pifaform_mail_client_subject',
70: 'pifaform_mail_system_template',
71: 'pifaform_mail_system_from_email',
72: 'pifaform_mail_system_from_name',
73: 'pifaform_mail_system_recipient_email',
74: 'pifaform_mail_system_subject'
75: );
76:
77:
78: $rawSettings = conHtmlEntityDecode($rawSettings);
79: $rawSettings = utf8_encode($rawSettings);
80:
81: parent::__construct($rawSettings, $id, $contentTypes);
82:
83:
84:
85:
86: $action = isset($_POST['pifaform_action']) ? $_POST['pifaform_action'] : NULL;
87: $id = isset($_POST['pifaform_id']) ? $_POST['pifaform_id'] : NULL;
88: if ('store' === $action && $this->_id == $id) {
89: $this->_storeSettings();
90: }
91: }
92:
93: 94: 95: 96: 97:
98: public function generateEditCode() {
99:
100:
101: $tplTop = new cTemplate();
102: $tplTop->set('s', 'PATH_BACKEND', $this->_cfg['path']['contenido_fullhtml']);
103: $tplTop->set('s', 'ICON', 'plugins/form_assistant/images/icon_form.png');
104: $tplTop->set('s', 'ID', $this->_id);
105: $tplTop->set('s', 'PREFIX', $this->_prefix);
106: $tplTop->set('s', 'HEADLINE', Pifa::i18n('form'));
107: $codeTop = $tplTop->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_top.html', true);
108:
109:
110: $tabMenu = array(
111: 'base' => Pifa::i18n('form')
112: );
113:
114:
115: $tplPanel = new cTemplate();
116: $tplPanel->set('s', 'PREFIX', $this->_prefix);
117: $tplPanel->set('d', 'TAB_ID', 'base');
118: $tplPanel->set('d', 'TAB_CLASS', 'base');
119: $tplPanel->set('d', 'TAB_CONTENT', $this->_getPanel());
120: $tplPanel->next();
121: $codePanel = $tplPanel->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_tabs.html', true);
122:
123:
124: $tplBottom = new cTemplate();
125: $tplBottom->set('s', 'PATH_BACKEND', $this->_cfg['path']['contenido_fullhtml']);
126: $tplBottom->set('s', 'PATH_FRONTEND', $this->_cfgClient[$this->_client]['path']['htmlpath']);
127: $tplBottom->set('s', 'ID', $this->_id);
128: $tplBottom->set('s', 'PREFIX', $this->_prefix);
129: $tplBottom->set('s', 'IDARTLANG', $this->_idArtLang);
130: $tplBottom->set('s', 'CONTENIDO', $_REQUEST['contenido']);
131: $tplBottom->set('s', 'FIELDS', "'" . implode("','", $this->_formFields) . "'");
132:
133:
134: $tplBottom->set('s', 'SETTINGS', json_encode(str_replace('$', '$', $this->_settings)));
135: $tplBottom->set('s', 'JS_CLASS_SCRIPT', Pifa::getUrl() . 'scripts/cmsPifaform.js');
136: $tplBottom->set('s', 'JS_CLASS_NAME', get_class($this));
137:
138: $codeBottom = $tplBottom->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_bottom.html', true);
139:
140:
141: $code = $this->_encodeForOutput($codeTop);
142:
143: $code .= $this->_encodeForOutput($codePanel);
144: $code .= $this->_generateActionCode();
145: $code .= $this->_encodeForOutput($codeBottom);
146: $code .= $this->generateViewCode();
147:
148: return $code;
149: }
150:
151: 152: 153: 154: 155:
156: private function _getPanel() {
157: $wrapper = new cHTMLDiv(array(
158:
159:
160: $this->_getSelectForm(),
161:
162:
163: new cHTMLFieldset(array(
164: new cHTMLLegend(Pifa::i18n('classes & templates')),
165: $this->_getSelectModule(),
166: $this->_getSelectProcessor(),
167: $this->_getSelectTemplateGet(),
168: $this->_getSelectTemplatePost()
169: )),
170:
171:
172: new cHTMLFieldset(array(
173: new cHTMLLegend(Pifa::i18n('client mail')),
174: $this->_getSelectMailClientTemplate(),
175: $this->_getInputMailClientFromEmail(),
176: $this->_getInputMailClientFromName(),
177: $this->_getInputMailClientSubject()
178: )),
179:
180:
181: new cHTMLFieldset(array(
182: new cHTMLLegend(Pifa::i18n('system mail')),
183: $this->_getSelectMailSystemTemplate(),
184: $this->_getInputMailSystemFromEmail(),
185: $this->_getInputMailSystemFromName(),
186: $this->_getInputMailSystemRecipientEmail(),
187: $this->_getInputMailSystemSubject()
188: ))
189: ), $this->_prefix . '_panel_base', $this->_prefix . '_panel_base_' . $this->_id);
190: $wrapper->setStyle('clear:both');
191:
192: return $wrapper->render();
193: }
194:
195: 196: 197: 198: 199: 200:
201: private function _getSelectForm() {
202:
203:
204: $id = 'pifaform_idform_' . $this->_id;
205:
206:
207: $label = new cHTMLLabel(Pifa::i18n('form'), $id);
208:
209:
210: $select = new cHTMLSelectElement($id, '', $id);
211: $select->addOptionElement($index = 0, new cHTMLOptionElement(Pifa::i18n('none'), ''));
212:
213:
214: $idclient = cRegistry::getClientId();
215: $forms = PifaFormCollection::getByClient($idclient);
216: if (false === $forms) {
217: return $select;
218: }
219:
220:
221: while (false !== $form = $forms->next()) {
222:
223:
224: $title = $form->get('name');
225: $value = $form->get('idform');
226: $selected = $form->get('idform') == $this->_settings['pifaform_idform'];
227:
228:
229: $option = new cHTMLOptionElement($title, $value, $selected);
230:
231:
232: $select->addOptionElement(++$index, $option);
233: }
234:
235:
236: $div = new cHTMLDiv(array(
237: $label,
238: $select
239: ));
240:
241:
242: return $div;
243: }
244:
245: 246: 247: 248: 249: 250:
251: private function _getSelectModule() {
252:
253:
254: $id = 'pifaform_module_' . $this->_id;
255:
256:
257: $label = new cHTMLLabel(Pifa::i18n('module'), $id);
258:
259:
260: $select = new cHTMLSelectElement($id, '', $id);
261: $select->addOptionElement($index = 0, new cHTMLOptionElement(Pifa::i18n('none'), ''));
262:
263:
264: $modules = Pifa::getExtensionClasses('PifaAbstractFormModule');
265:
266:
267: usort($modules, 'cContentTypePifaForm::sortByLabel');
268:
269:
270: foreach ($modules as $module) {
271:
272:
273: $title = $module['label'];
274: $value = $module['value'];
275: $selected = $module['value'] == $this->_settings['pifaform_module'];
276:
277:
278: $option = new cHTMLOptionElement($title, $value, $selected);
279:
280:
281: $select->addOptionElement(++$index, $option);
282: }
283:
284:
285: $div = new cHTMLDiv(array(
286: $label,
287: $select
288: ));
289:
290:
291: return $div;
292: }
293:
294: 295: 296: 297: 298: 299:
300: private function _getSelectProcessor() {
301:
302:
303: $id = 'pifaform_processor_' . $this->_id;
304:
305:
306: $label = new cHTMLLabel(Pifa::i18n('processor'), $id);
307:
308:
309: $select = new cHTMLSelectElement($id, '', $id);
310: $select->addOptionElement($index = 0, new cHTMLOptionElement(Pifa::i18n('none'), ''));
311:
312:
313: $processors = Pifa::getExtensionClasses('PifaAbstractFormProcessor');
314:
315:
316: usort($processors, 'cContentTypePifaForm::sortByLabel');
317:
318:
319: foreach ($processors as $processor) {
320:
321:
322: $title = $processor['label'];
323: $value = $processor['value'];
324: $selected = $processor['value'] == $this->_settings['pifaform_processor'];
325:
326:
327: $option = new cHTMLOptionElement($title, $value, $selected);
328:
329:
330: $select->addOptionElement(++$index, $option);
331: }
332:
333:
334: $div = new cHTMLDiv(array(
335: $label,
336: $select
337: ));
338:
339:
340: return $div;
341: }
342:
343: 344: 345: 346: 347: 348:
349: private function _getSelectTemplateGet() {
350:
351:
352: $id = 'pifaform_template_get_' . $this->_id;
353:
354:
355: $label = new cHTMLLabel(Pifa::i18n('template') . ' – ' . Pifa::i18n('GET'), $id);
356:
357:
358: $select = new cHTMLSelectElement($id, '', $id);
359: $select->addOptionElement($index = 0, new cHTMLOptionElement(Pifa::i18n('none'), ''));
360:
361:
362: $templates = Pifa::getTemplates('/cms_pifaform_[^\.]+_get\.tpl/');
363:
364:
365: usort($templates, 'cContentTypePifaForm::sortByLabel');
366:
367:
368: foreach ($templates as $template) {
369:
370:
371: $title = $template['label'];
372: $value = $template['value'];
373: $selected = $template['value'] == $this->_settings['pifaform_template_get'];
374:
375:
376: $option = new cHTMLOptionElement($title, $value, $selected);
377:
378:
379: $select->addOptionElement(++$index, $option);
380: }
381:
382:
383: $div = new cHTMLDiv(array(
384: $label,
385: $select
386: ));
387:
388:
389: return $div;
390: }
391:
392: 393: 394: 395: 396: 397:
398: private function _getSelectTemplatePost() {
399:
400:
401: $id = 'pifaform_template_post_' . $this->_id;
402:
403:
404: $label = new cHTMLLabel(Pifa::i18n('template') . ' – ' . Pifa::i18n('POST'), $id);
405:
406:
407: $select = new cHTMLSelectElement($id, '', $id);
408: $select->addOptionElement($index = 0, new cHTMLOptionElement(Pifa::i18n('none'), ''));
409:
410:
411: $templates = Pifa::getTemplates('/cms_pifaform_[^\.]+_post\.tpl/');
412:
413:
414: usort($templates, 'cContentTypePifaForm::sortByLabel');
415:
416:
417: foreach ($templates as $template) {
418:
419:
420: $title = $template['label'];
421: $value = $template['value'];
422: $selected = $template['value'] == $this->_settings['pifaform_template_post'];
423:
424:
425: $option = new cHTMLOptionElement($title, $value, $selected);
426:
427:
428: $select->addOptionElement(++$index, $option);
429: }
430:
431:
432: $div = new cHTMLDiv(array(
433: $label,
434: $select
435: ));
436:
437:
438: return $div;
439: }
440:
441: 442: 443: 444: 445: 446: 447:
448: private function _getSelectMailClientTemplate() {
449:
450:
451: $id = 'pifaform_mail_client_template_' . $this->_id;
452:
453:
454: $label = new cHTMLLabel(Pifa::i18n('template'), $id);
455:
456:
457: $select = new cHTMLSelectElement($id, '', $id);
458: $select->addOptionElement($index = 0, new cHTMLOptionElement(Pifa::i18n('none'), ''));
459:
460:
461: $templates = Pifa::getTemplates('/cms_pifaform_[^\.]+_mail_client\.tpl/');
462:
463:
464: usort($templates, 'cContentTypePifaForm::sortByLabel');
465:
466:
467: foreach ($templates as $template) {
468:
469:
470: $title = $template['label'];
471: $value = $template['value'];
472: $selected = $template['value'] == $this->_settings['pifaform_mail_client_template'];
473:
474:
475: $option = new cHTMLOptionElement($title, $value, $selected);
476:
477:
478: $select->addOptionElement(++$index, $option);
479: }
480:
481:
482: $div = new cHTMLDiv(array(
483: $label,
484: $select
485: ));
486:
487:
488: return $div;
489: }
490:
491: 492: 493: 494: 495:
496: private function _getInputMailClientFromEmail() {
497:
498:
499: $label = Pifa::i18n('sender email');
500: $id = 'pifaform_mail_client_from_email_' . $this->_id;
501: $value = $this->_settings['pifaform_mail_client_from_email'];
502:
503:
504: $div = new cHTMLDiv(array(
505: new cHTMLLabel($label, $id),
506: new cHTMLTextbox($id, $value, '', '', $id)
507: ));
508:
509:
510: return $div;
511: }
512:
513: 514: 515: 516: 517:
518: private function _getInputMailClientFromName() {
519:
520:
521: $label = Pifa::i18n('sender name');
522: $id = 'pifaform_mail_client_from_name_' . $this->_id;
523: $value = $this->_settings['pifaform_mail_client_from_name'];
524:
525:
526: $div = new cHTMLDiv(array(
527: new cHTMLLabel($label, $id),
528: new cHTMLTextbox($id, $value, '', '', $id)
529: ));
530:
531:
532: return $div;
533: }
534:
535: 536: 537: 538: 539:
540: private function _getInputMailClientSubject() {
541:
542:
543: $label = Pifa::i18n('subject');
544: $id = 'pifaform_mail_client_subject_' . $this->_id;
545: $value = $this->_settings['pifaform_mail_client_subject'];
546:
547:
548: $value = str_replace('$', '$', $value);
549:
550:
551: $div = new cHTMLDiv(array(
552: new cHTMLLabel($label, $id),
553: new cHTMLTextbox($id, $value, '', '', $id)
554: ));
555:
556:
557: return $div;
558: }
559:
560: 561: 562: 563: 564: 565:
566: private function _getSelectMailSystemTemplate() {
567:
568:
569: $id = 'pifaform_mail_system_template_' . $this->_id;
570:
571:
572: $label = new cHTMLLabel(Pifa::i18n('template'), $id);
573:
574:
575: $select = new cHTMLSelectElement($id, '', $id);
576: $select->addOptionElement($index = 0, new cHTMLOptionElement(Pifa::i18n('none'), ''));
577:
578:
579: $templates = Pifa::getTemplates('/cms_pifaform_[^\.]+_mail_system\.tpl/');
580:
581:
582: usort($templates, 'cContentTypePifaForm::sortByLabel');
583:
584:
585: foreach ($templates as $template) {
586:
587:
588: $title = $template['label'];
589: $value = $template['value'];
590: $selected = $template['value'] == $this->_settings['pifaform_mail_system_template'];
591:
592:
593: $option = new cHTMLOptionElement($title, $value, $selected);
594:
595:
596: $select->addOptionElement(++$index, $option);
597: }
598:
599:
600: $div = new cHTMLDiv(array(
601: $label,
602: $select
603: ));
604:
605:
606: return $div;
607: }
608:
609: 610: 611: 612: 613:
614: private function _getInputMailSystemFromEmail() {
615:
616:
617: $label = Pifa::i18n('sender email');
618: $id = 'pifaform_mail_system_from_email_' . $this->_id;
619: $value = $this->_settings['pifaform_mail_system_from_email'];
620:
621:
622: $div = new cHTMLDiv(array(
623: new cHTMLLabel($label, $id),
624: new cHTMLTextbox($id, $value, '', '', $id)
625: ));
626:
627:
628: return $div;
629: }
630:
631: 632: 633: 634: 635:
636: private function _getInputMailSystemFromName() {
637:
638:
639: $label = Pifa::i18n('sender name');
640: $id = 'pifaform_mail_system_from_name_' . $this->_id;
641: $value = $this->_settings['pifaform_mail_system_from_name'];
642:
643:
644: $div = new cHTMLDiv(array(
645: new cHTMLLabel($label, $id),
646: new cHTMLTextbox($id, $value, '', '', $id)
647: ));
648:
649:
650: return $div;
651: }
652:
653: 654: 655: 656: 657: 658:
659: private function _getInputMailSystemRecipientEmail() {
660:
661:
662: $label = Pifa::i18n('recipient email');
663: $id = 'pifaform_mail_system_recipient_email_' . $this->_id;
664: $value = $this->_settings['pifaform_mail_system_recipient_email'];
665:
666:
667: $div = new cHTMLDiv(array(
668: new cHTMLLabel($label, $id),
669: new cHTMLTextbox($id, $value, '', '', $id)
670: ));
671:
672:
673: return $div;
674: }
675:
676: 677: 678: 679: 680:
681: private function _getInputMailSystemSubject() {
682:
683:
684: $label = Pifa::i18n('subject');
685: $id = 'pifaform_mail_system_subject_' . $this->_id;
686: $value = $this->_settings['pifaform_mail_system_subject'];
687:
688:
689: $value = str_replace('$', '$', $value);
690:
691:
692: $div = new cHTMLDiv(array(
693: new cHTMLLabel($label, $id),
694: new cHTMLTextbox($id, $value, '', '', $id)
695: ));
696:
697:
698: return $div;
699: }
700:
701: 702: 703: 704: 705: 706: 707: 708: 709: 710:
711: public function generateViewCode() {
712: $code = '";?' . '><' . '?php $form = new %s(\'%s\', %s, %s); echo $form->buildCode(); ?' . '><' . '?php echo "';
713: $code = sprintf($code, get_class($this), $this->_rawSettings, $this->_id, 'array()');
714:
715: return $code;
716: }
717:
718: 719: 720: 721: 722: 723:
724: public function buildCode() {
725: $out = '';
726: if (0 === cSecurity::toInteger($this->_settings['pifaform_idform'])) {
727:
728: } else if (0 === strlen(trim($this->_settings['pifaform_module']))) {
729:
730: } else {
731: $moduleClass = trim($this->_settings['pifaform_module']);
732: try {
733: $filename = Pifa::fromCamelCase($moduleClass);
734: $filename = "extensions/class.pifa.$filename.php";
735: if (false === file_exists(Pifa::getPath() . $filename)) {
736: $msg = sprintf(Pifa::i18n('MISSING_MODULE_FILE'), $filename);
737: throw new PifaException($msg);
738: }
739: plugin_include(Pifa::getName(), $filename);
740: if (false === class_exists($moduleClass)) {
741: $msg = sprintf(Pifa::i18n('MISSING_MODULE_CLASS'), $moduleClass);
742: throw new PifaException($msg);
743: }
744: $mod = new $moduleClass($this->_settings);
745: $out = $mod->render(true);
746: } catch (Exception $e) {
747: Pifa::logException($e);
748:
749: }
750: }
751:
752:
753:
754:
755: return $out;
756: }
757: }
758: