18 require_once SQ_PACKAGES_PATH.
'/cms/form/form_action/form_action.inc';
19 require_once SQ_ATTRIBUTES_PATH.
'/email_format/email_format.inc';
21 require_once SQ_FUDGE_PATH.
'/general/general.inc';
46 parent::__construct();
58 if (!isset($settings[
'email_format'])) {
59 $email_settings = serialize(Array());
61 $email_settings = $settings[
'email_format'];
66 $xml = simplexml_load_string(
'<email_format with_asset_finder="1" show_inc_attachments="1" />');
67 $email_format->setEditParams($xml);
69 $email_format->paint($prefix);
81 if (!isset($settings[
'email_format'])) {
82 $email_settings = serialize(Array());
84 $email_settings = $settings[
'email_format'];
89 $xml = simplexml_load_string(
'<email_format with_asset_finder="1" show_inc_attachments="1" />');
90 $email_format->setEditParams($xml);
92 $email_format->name =
'current action\'s settings';
93 $email_format->process($prefix);
95 $settings[
'email_format'] = $email_format->value;
97 return $email_format->validateValue($email_format->value);
109 if (!isset($settings[
'email_format'])) {
110 $email_settings = Array();
112 $email_settings = unserialize($settings[
'email_format']);
114 self::_fillEmailFormatDefaults($email_settings);
116 ?><table
class=
"no-borders">
123 <td
class=
"sq-backend-table-cell" style=
"vertical-align: top"><p><strong>To:</strong></p></td>
124 <td
class=
"sq-backend-table-cell" style=
"vertical-align: top"><p><?php
127 $all_keywords = TRUE;
130 for (; ($i < 6) && !empty($email_settings[
'to']); $i++) {
131 $this_email = array_shift($email_settings[
'to']);
132 $to_array[] = htmlspecialchars($this_email);
133 if (!preg_match(
'/%.*%/', $this_email)) {
134 $all_keywords = FALSE;
140 for (; ($i < 6) && !empty($email_settings[
'to_assetids']); $i++) {
141 $to_array[] = get_asset_tag_line(array_shift($email_settings[
'to_assetids']));
142 $all_keywords = FALSE;
146 echo implode(
', ', $to_array);
147 $extra_recipients = count($email_settings[
'to']) + count($email_settings[
'to_assetids']);
148 if ($extra_recipients > 0) {
149 ?>, <em>plus <?php echo $extra_recipients ?> more recipients</em><?php
152 ?><br/><em>Note: All of your recipients are based on the results of keywords (
for instance, submitted responses). If these are left blank in a submission,
this email may not send.</em><?php
155 ?><span
class=
"sq-backend-warning">No recipients specified.</span> This email cannot send without at least one recipient.<?php
160 <td
class=
"sq-backend-table-cell" style=
"vertical-align: top"><p><strong>From:</strong></p></td>
161 <td
class=
"sq-backend-table-cell" style=
"vertical-align: top"><p><?php
162 if (!empty($email_settings[
'from'])) {
163 echo htmlspecialchars($email_settings[
'from']);
165 ?><span
class=
"sq-backend-warning">No
"From:" address specified.</span> The system
's default email address (<?php echo SQ_CONF_DEFAULT_EMAIL ?>) will be used.<?php
170 <td class="sq-backend-table-cell" style="vertical-align: top"><p><strong>Subject:</strong></p></td>
171 <td class="sq-backend-table-cell" style="vertical-align: top"><p><?php
172 if (!empty($email_settings['subject
'])) {
173 echo htmlspecialchars($email_settings['subject
']);
175 ?><span class="sq-backend-warning">No subject specified.</span> Although an email can send without a subject, it is recommended you add one.<?php
179 <td class="sq-backend-table-cell" style="vertical-align: top"><p><strong>HTML Body:</strong></p></td>
180 <td class="sq-backend-table-cell" style="vertical-align: top"><p><?php
181 if (!empty($email_settings['html_format
'])) {
182 echo ellipsisize(strip_tags(preg_replace('/\\n/
', ' ', $email_settings['html_format
'])), 512);
184 ?><span class="sq-backend-warning">The HTML body is empty.</span><?php
188 <td class="sq-backend-table-cell" style="vertical-align: top"><p><strong>Text Body:</strong></p></td>
189 <td class="sq-backend-table-cell" style="vertical-align: top"><p><?php
190 if (!empty($email_settings['text_format
'])) {
191 echo ellipsisize(preg_replace('/\\n/
', ' ', $email_settings['text_format
']), 512);
193 ?><span class="sq-backend-warning">The text-only body is empty.</span><?php
197 <td class="sq-backend-table-cell" style="vertical-align: top"><p><strong>Uploads:</strong></p></td>
198 <td class="sq-backend-table-cell" style="vertical-align: top"><p>File uploads are <strong><?php echo $email_settings['inc_attachments
'] ? 'attached
' : 'not attached
' ?></strong>.</p></td>
204 }//end paintSummary()
211 public static function execute(Form $form, $settings)
213 $email_settings = $settings['email_format
'];
215 // Set up email format and let it be the final judge
216 $email_format = new Asset_Attribute_Email_Format(0, $email_settings);
217 $xml = simplexml_load_string('<email_format with_asset_finder=
"1" show_inc_attachments=
"1" />
');
218 $email_format->setEditParams($xml);
220 $form->sendEmail($email_format);
230 public static function isValid(Form $form, $settings)
232 if (!isset($settings['email_format
'])) {
233 $email_settings = Array();
235 $email_settings = unserialize($settings['email_format
']);
237 self::_fillEmailFormatDefaults($email_settings);
239 // No-one to send it to!
240 if (empty($email_settings['to
']) && empty($email_settings['to_assetids
'])) {
244 // Nothing in either body!
245 if (empty($email_settings['text_format
']) && empty($email_settings['html_format
'])) {
249 // Set up email format and let it be the final judge
250 $email_format = new Asset_Attribute_Email_Format(0, serialize($email_settings));
251 $xml = simplexml_load_string('<email_format with_asset_finder=
"1" show_inc_attachments=
"1" />
');
252 $email_format->setEditParams($xml);
254 return $email_format->validateValue($email_settings);
266 private static function _fillEmailFormatDefaults(&$email_format) {
267 if (!isset($email_format['to
'])) {
268 $email_format['to
'] = Array();
271 if (!isset($email_format['to_assetids
'])) {
272 $email_format['to_assetids
'] = Array();
275 if (!isset($email_format['from
'])) {
276 $email_format['from
'] = '';
279 if (!isset($email_format['subject
'])) {
280 $email_format['subject
'] = '';
283 if (!isset($email_format['html_format
'])) {
284 $email_format['html_format
'] = '';
287 if (!isset($email_format['text_format
'])) {
288 $email_format['text_format
'] = '';
291 if (!isset($email_format['inc_attachments
'])) {
292 $email_format['inc_attachments
'] = Array();
295 if (!isset($email_format['attachments
'])) {
296 $email_format['attachments
'] = Array();
300 }//end _fillDefaultValues()