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