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: function __construct($rawSettings, $id, array $contentTypes) {
53:
54:
55: $this->_type = 'CMS_PIFAFORM';
56: $this->_prefix = 'pifaform';
57: $this->_settingsType = self::SETTINGS_TYPE_XML;
58: $this->_formFields = array(
59: 'pifaform_headline',
60: 'pifaform_idform',
61: 'pifaform_module',
62: 'pifaform_processor',
63: 'pifaform_template_get',
64: 'pifaform_template_post',
65: 'pifaform_mail_client_template',
66: 'pifaform_mail_client_from_email',
67: 'pifaform_mail_client_from_name',
68: 'pifaform_mail_client_subject',
69: 'pifaform_mail_system_template',
70: 'pifaform_mail_system_from_email',
71: 'pifaform_mail_system_from_name',
72: 'pifaform_mail_system_recipient_email',
73: 'pifaform_mail_system_subject'
74: );
75:
76: parent::__construct($rawSettings, $id, $contentTypes);
77:
78:
79:
80:
81: $action = isset($_POST['pifaform_action']) ? $_POST['pifaform_action'] : NULL;
82: $id = isset($_POST['pifaform_id']) ? $_POST['pifaform_id'] : NULL;
83: if ('store' === $action && $this->_id == $id) {
84: $this->_storeSettings();
85: }
86: }
87:
88: 89: 90: 91: 92: 93: 94:
95: public function generateEditCode() {
96:
97:
98: $tplTop = new cTemplate();
99: $tplTop->set('s', 'ICON', 'plugins/form_assistant/images/icon_form.png');
100: $tplTop->set('s', 'ID', $this->_id);
101: $tplTop->set('s', 'PREFIX', $this->_prefix);
102: $tplTop->set('s', 'HEADLINE', Pifa::i18n('form'));
103: $codeTop = $tplTop->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_top.html', true);
104:
105:
106: $tabMenu = array(
107: 'base' => Pifa::i18n('form')
108: );
109:
110:
111: $tplPanel = new cTemplate();
112: $tplPanel->set('s', 'PREFIX', $this->_prefix);
113: $tplPanel->set('d', 'TAB_ID', 'base');
114: $tplPanel->set('d', 'TAB_CLASS', 'base');
115: $tplPanel->set('d', 'TAB_CONTENT', $this->_getPanel());
116: $tplPanel->next();
117: $codePanel = $tplPanel->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_tabs.html', true);
118:
119:
120: $tplBottom = new cTemplate();
121: $tplBottom->set('s', 'PATH_FRONTEND', $this->_cfgClient[$this->_client]['path']['htmlpath']);
122: $tplBottom->set('s', 'ID', $this->_id);
123: $tplBottom->set('s', 'PREFIX', $this->_prefix);
124: $tplBottom->set('s', 'IDARTLANG', $this->_idArtLang);
125: $tplBottom->set('s', 'FIELDS', "'" . implode("','", $this->_formFields) . "'");
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: private function _getSelectMailClientTemplate() {
469:
470:
471: $id = 'pifaform_mail_client_template_' . $this->_id;
472:
473:
474: $label = new cHTMLLabel(Pifa::i18n('template'), $id);
475:
476:
477: $select = new cHTMLSelectElement($id, '', $id);
478: $select->addOptionElement($index = 0, new cHTMLOptionElement(Pifa::i18n('none'), ''));
479:
480:
481: $templates = Pifa::getTemplates('/cms_pifaform_[^\.]+_mail_client\.tpl/');
482:
483:
484: usort($templates, 'cContentTypePifaForm::sortByLabel');
485:
486:
487: foreach ($templates as $template) {
488:
489:
490: $title = $template['label'];
491: $value = $template['value'];
492: $selected = $template['value'] == $this->_settings['pifaform_mail_client_template'];
493:
494:
495: $option = new cHTMLOptionElement($title, $value, $selected);
496:
497:
498: $select->addOptionElement(++$index, $option);
499: }
500:
501:
502: $div = new cHTMLDiv(array(
503: $label,
504: $select
505: ));
506:
507:
508: return $div;
509: }
510:
511: 512: 513: 514: 515:
516: private function _getInputMailClientFromEmail() {
517:
518:
519: $label = Pifa::i18n('sender email');
520: $id = 'pifaform_mail_client_from_email_' . $this->_id;
521: $value = $this->_settings['pifaform_mail_client_from_email'];
522:
523:
524: $div = new cHTMLDiv(array(
525: new cHTMLLabel($label, $id),
526: new cHTMLTextbox($id, $value, '', '', $id)
527: ));
528:
529:
530: return $div;
531: }
532:
533: 534: 535: 536: 537:
538: private function _getInputMailClientFromName() {
539:
540:
541: $label = Pifa::i18n('sender name');
542: $id = 'pifaform_mail_client_from_name_' . $this->_id;
543: $value = $this->_settings['pifaform_mail_client_from_name'];
544:
545:
546: $div = new cHTMLDiv(array(
547: new cHTMLLabel($label, $id),
548: new cHTMLTextbox($id, $value, '', '', $id)
549: ));
550:
551:
552: return $div;
553: }
554:
555: 556: 557: 558: 559:
560: private function _getInputMailClientSubject() {
561:
562:
563: $label = Pifa::i18n('subject');
564: $id = 'pifaform_mail_client_subject_' . $this->_id;
565: $value = $this->_settings['pifaform_mail_client_subject'];
566:
567:
568: $value = str_replace('$', '$', $value);
569:
570:
571: $div = new cHTMLDiv(array(
572: new cHTMLLabel($label, $id),
573: new cHTMLTextbox($id, $value, '', '', $id)
574: ));
575:
576:
577: return $div;
578: }
579:
580: 581: 582: 583: 584:
585: private function _getSelectMailSystemTemplate() {
586:
587:
588: $id = 'pifaform_mail_system_template_' . $this->_id;
589:
590:
591: $label = new cHTMLLabel(Pifa::i18n('template'), $id);
592:
593:
594: $select = new cHTMLSelectElement($id, '', $id);
595: $select->addOptionElement($index = 0, new cHTMLOptionElement(Pifa::i18n('none'), ''));
596:
597:
598: $templates = Pifa::getTemplates('/cms_pifaform_[^\.]+_mail_system\.tpl/');
599:
600:
601: usort($templates, 'cContentTypePifaForm::sortByLabel');
602:
603:
604: foreach ($templates as $template) {
605:
606:
607: $title = $template['label'];
608: $value = $template['value'];
609: $selected = $template['value'] == $this->_settings['pifaform_mail_system_template'];
610:
611:
612: $option = new cHTMLOptionElement($title, $value, $selected);
613:
614:
615: $select->addOptionElement(++$index, $option);
616: }
617:
618:
619: $div = new cHTMLDiv(array(
620: $label,
621: $select
622: ));
623:
624:
625: return $div;
626: }
627:
628: 629: 630: 631: 632:
633: private function _getInputMailSystemFromEmail() {
634:
635:
636: $label = Pifa::i18n('sender email');
637: $id = 'pifaform_mail_system_from_email_' . $this->_id;
638: $value = $this->_settings['pifaform_mail_system_from_email'];
639:
640:
641: $div = new cHTMLDiv(array(
642: new cHTMLLabel($label, $id),
643: new cHTMLTextbox($id, $value, '', '', $id)
644: ));
645:
646:
647: return $div;
648: }
649:
650: 651: 652: 653: 654:
655: private function _getInputMailSystemFromName() {
656:
657:
658: $label = Pifa::i18n('sender name');
659: $id = 'pifaform_mail_system_from_name_' . $this->_id;
660: $value = $this->_settings['pifaform_mail_system_from_name'];
661:
662:
663: $div = new cHTMLDiv(array(
664: new cHTMLLabel($label, $id),
665: new cHTMLTextbox($id, $value, '', '', $id)
666: ));
667:
668:
669: return $div;
670: }
671:
672: 673: 674: 675: 676:
677: private function _getInputMailSystemRecipientEmail() {
678:
679:
680: $label = Pifa::i18n('Recipient email');
681: $id = 'pifaform_mail_system_recipient_email_' . $this->_id;
682: $value = $this->_settings['pifaform_mail_system_recipient_email'];
683:
684:
685: $div = new cHTMLDiv(array(
686: new cHTMLLabel($label, $id),
687: new cHTMLTextbox($id, $value, '', '', $id)
688: ));
689:
690:
691: return $div;
692: }
693:
694: 695: 696: 697: 698:
699: private function _getInputMailSystemSubject() {
700:
701:
702: $label = Pifa::i18n('subject');
703: $id = 'pifaform_mail_system_subject_' . $this->_id;
704: $value = $this->_settings['pifaform_mail_system_subject'];
705:
706:
707: $value = str_replace('$', '$', $value);
708:
709:
710: $div = new cHTMLDiv(array(
711: new cHTMLLabel($label, $id),
712: new cHTMLTextbox($id, $value, '', '', $id)
713: ));
714:
715:
716: return $div;
717: }
718:
719: 720: 721: 722: 723: 724: 725: 726: 727: 728:
729: public function generateViewCode() {
730: $code = '";?' . '><' . '?php $form = new %s(\'%s\', %s, %s); echo $form->buildCode(); ?' . '><' . '?php echo "';
731: $code = sprintf($code, get_class($this), $this->_rawSettings, $this->_id, 'array()');
732:
733: return $code;
734: }
735:
736: 737: 738: 739: 740:
741: public function buildCode() {
742: $out = '';
743: if (0 === cSecurity::toInteger($this->_settings['pifaform_idform'])) {
744:
745: } elseif (0 === cString::getStringLength(trim($this->_settings['pifaform_module']))) {
746:
747: } else {
748: $moduleClass = trim($this->_settings['pifaform_module']);
749: try {
750: $filename = Pifa::fromCamelCase($moduleClass);
751: $filename = "extensions/class.pifa.$filename.php";
752: if (false === file_exists(Pifa::getPath() . $filename)) {
753: $msg = sprintf(Pifa::i18n('MISSING_MODULE_FILE'), $filename);
754: throw new PifaException($msg);
755: }
756: plugin_include(Pifa::getName(), $filename);
757: if (false === class_exists($moduleClass)) {
758: $msg = sprintf(Pifa::i18n('MISSING_MODULE_CLASS'), $moduleClass);
759: throw new PifaException($msg);
760: }
761:
762: $mod = new $moduleClass($this->_settings);
763: $out = $mod->render(true);
764: } catch (Exception $e) {
765: Pifa::logException($e);
766:
767: }
768: }
769:
770:
771:
772:
773: return $out;
774: }
775: }
776: