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: plugin_include(Pifa::getName(), 'extensions/class.pifa.default_form_processor.php');
17:
18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28:
29: class MailedFormProcessor extends DefaultFormProcessor {
30: const MAIL_MODE_CLIENT = 'client';
31: const MAIL_MODE_SYSTEM = 'system';
32:
33: 34: 35: 36: 37: 38: 39: 40:
41: protected function _processStoredData() {
42:
43:
44: $errors = array();
45:
46:
47: try {
48: $mailOptions = $this->_getMailOptions(self::MAIL_MODE_CLIENT);
49:
50:
51: if ($mailOptions !== false) {
52: $this->getForm()->toMailRecipient($mailOptions);
53: }
54: } catch (PifaMailException $e) {
55: $errors[] = mi18n("PIFA_CLIENT_MAIL") . ": " . $e->getMessage();
56: }
57:
58:
59: try {
60: $mailOptions = $this->_getMailOptions(self::MAIL_MODE_SYSTEM);
61:
62:
63: if ($mailOptions !== false) {
64: $this->getForm()->toMailRecipient($mailOptions);
65: }
66: } catch (PifaMailException $e) {
67: $errors[] = mi18n("PIFA_SYSTEM_MAIL") . ": " . $e->getMessage();
68: }
69:
70:
71: if (0 < count($errors)) {
72: throw new PifaMailException(implode('<br>', $errors));
73: }
74: }
75:
76: 77: 78: 79: 80: 81:
82: protected function _getMailOptions($mode) {
83: if ($mode != self::MAIL_MODE_CLIENT && $mode != self::MAIL_MODE_SYSTEM) {
84: return false;
85: }
86:
87: $bodyTemplate = $this->getModule()->getSetting('pifaform_mail_' . $mode . '_template');
88: if ($bodyTemplate == '') {
89: return false;
90: }
91:
92:
93: $values = $this->getForm()->getValues();
94:
95:
96: $tpl = cSmartyFrontend::getInstance(true);
97: $tpl->assign('values', $values);
98: $subject = $tpl->fetch('eval:' . $this->getModule()->getSetting('pifaform_mail_' . $mode . '_subject'));
99:
100:
101: $tpl = cSmartyFrontend::getInstance(true);
102: $tpl->assign('values', $values);
103: $body = $tpl->fetchGeneral($bodyTemplate);
104:
105: if ($mode == self::MAIL_MODE_CLIENT) {
106: $mailTo = $values['email'];
107: } else {
108: $mailTo = $this->getModule()->getSetting('pifaform_mail_system_recipient_email');
109: }
110:
111: if (cRegistry::getLanguageId() != 0) {
112: $language = cRegistry::getLanguage();
113: $encoding = $language->getField('encoding');
114: if ($encoding == '') {
115: $encoding = 'UTF-8';
116: }
117: }
118:
119: $mailOptions = array(
120: 'from' => $this->getModule()->getSetting('pifaform_mail_' . $mode . '_from_email'),
121: 'fromName' => $this->getModule()->getSetting('pifaform_mail_' . $mode . '_from_name'),
122: 'to' => $mailTo,
123: 'subject' => $subject,
124: 'body' => $body,
125: 'charSet' => $encoding
126: );
127:
128:
129:
130: if ($mode == self::MAIL_MODE_SYSTEM) {
131: $mailOptions['attachmentNames'] = $this->_getAttachmentNames();
132: $mailOptions['attachmentStrings'] = $this->_getAttachmentStrings();
133: }
134:
135: return $mailOptions;
136: }
137:
138: 139: 140: 141: 142: 143:
144: protected function _getAttachmentNames() {
145:
146:
147:
148: $attachmentNames = array();
149: if (0 < count($this->getForm()->getFiles())) {
150: $tableName = $this->getForm()->get('data_table');
151: $lastInsertedId = $this->getForm()->getLastInsertedId();
152: $cfg = cRegistry::getConfig();
153: $destPath = $cfg['path']['contenido_cache'] . 'form_assistant/';
154: foreach ($this->getForm()->getFiles() as $column => $file) {
155: if (!is_array($file)) {
156: continue;
157: }
158: $destName = $tableName . '_' . $lastInsertedId . '_' . $column;
159: $destName = preg_replace('/[^a-z0-9_]+/i', '_', $destName);
160: $attachmentNames[$column] = $destPath . $destName;
161: }
162: }
163:
164: return $attachmentNames;
165: }
166:
167: 168: 169: 170: 171: 172:
173: protected function _getAttachmentStrings() {
174: return array();
175: }
176: }
177:
178: ?>