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