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