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