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