1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19: 20:
21: class DefaultFormModule extends PifaAbstractFormModule {
22:
23: 24: 25: 26: 27: 28: 29: 30:
31: protected function doGet(array $values = array(), array $errors = array()) {
32:
33:
34: $this->setTemplateName($this->getSetting('pifaform_template_get'));
35:
36:
37: $pifaForm = new PifaForm($this->getIdform());
38:
39:
40: if (true !== $pifaForm->isLoaded()) {
41: $msg = Pifa::i18n('FORM_LOAD_ERROR');
42: throw new PifaException($msg);
43: }
44:
45:
46: $pifaForm->setValues($values);
47:
48:
49: $pifaForm->setErrors($errors);
50:
51: $actionPath = cUri::getInstance()->build(array(
52: 'idart' => cRegistry::getArticleId(),
53: 'lang' => cRegistry::getLanguageId()
54: ), true);
55:
56: if (Pifa::isHttps()) {
57: $actionPath = str_replace('http://', 'https://', $actionPath);
58: }
59:
60:
61: $this->getTpl()->assign('form', $pifaForm->toHtml(array(
62: 'action' => $actionPath
63: )));
64: }
65:
66: 67: 68: 69: 70:
71: protected function doPost() {
72:
73:
74: $this->setTemplateName($this->getSetting('pifaform_template_post'));
75:
76: try {
77:
78:
79: $processorClass = $this->getSetting('pifaform_processor');
80:
81:
82: $filename = Pifa::fromCamelCase($processorClass);
83: $filename = "extensions/class.pifa.$filename.php";
84: if (false === file_exists(Pifa::getPath() . $filename)) {
85: $msg = Pifa::i18n('MISSING_PROCESSOR_FILE');
86: $msg = sprintf($msg, $filename);
87: throw new PifaException($msg);
88: }
89: plugin_include(Pifa::getName(), $filename);
90: if (false === class_exists($processorClass)) {
91: $msg = Pifa::i18n('MISSING_PROCESSOR_CLASS');
92: $msg = sprintf($msg, $processorClass);
93: throw new PifaException($msg);
94: }
95:
96:
97:
98:
99: $postProcessor = new $processorClass($this);
100: $postProcessor->process();
101:
102:
103: $this->getTpl()->assign('reply', array(
104: 'headline' => mi18n("REPLY_HEADLINE"),
105: 'text' => mi18n("REPLY_TEXT")
106: ));
107: } catch (PifaValidationException $e) {
108:
109:
110: $this->doGet($postProcessor->getForm()->getValues(), $e->getErrors());
111:
112:
113:
114: cRegistry::setAppVar('pifaFormValidity', 'invalid');
115: } catch (PifaException $e) {
116:
117: $this->doGet($postProcessor->getForm()->getValues());
118:
119: Pifa::displayException($e);
120: } catch (Exception $e) {
121:
122: Pifa::logException($e);
123: Pifa::displayException($e);
124: }
125: }
126: }
127: