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