INFRA-132 - Put space after flow-control (if/switch/for/foreach/while)
[civicrm-core.git] / CRM / Mailing / Form / Upload.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2014
32 * $Id$
33 *
34 */
35
36 /**
37 * This file is used to build the form configuring mailing details
38 */
39 class CRM_Mailing_Form_Upload extends CRM_Core_Form {
40
41 public $_mailingID;
42
43 public function preProcess() {
44 $this->_mailingID = $this->get('mailing_id');
45 if (CRM_Core_Permission::check('administer CiviCRM')) {
46 $this->assign('isAdmin', 1);
47 }
48
49 //when user come from search context.
50 $ssID = $this->get('ssID');
51 $this->assign('ssid', $ssID);
52 $this->_searchBasedMailing = CRM_Contact_Form_Search::isSearchContext($this->get('context'));
53 if (CRM_Contact_Form_Search::isSearchContext($this->get('context')) && !$ssID){
54 $params = array();
55 $result = CRM_Core_BAO_PrevNextCache::getSelectedContacts();
56 $this->assign("value", $result);
57 }
58 }
59 /**
60 * Set default values for the form.
61 * the default values are retrieved from the database
62 *
63 *
64 * @return void
65 */
66 public function setDefaultValues() {
67 $mailingID = CRM_Utils_Request::retrieve('mid', 'Integer', $this, FALSE, NULL);
68
69 //need to differentiate new/reuse mailing, CRM-2873
70 $reuseMailing = FALSE;
71 if ($mailingID) {
72 $reuseMailing = TRUE;
73 }
74 else {
75 $mailingID = $this->_mailingID;
76 }
77
78 $count = $this->get('count');
79 $this->assign('count', $count);
80
81 $this->set('skipTextFile', FALSE);
82 $this->set('skipHtmlFile', FALSE);
83
84 $defaults = array();
85
86 $htmlMessage = NULL;
87 if ($mailingID) {
88 $dao = new CRM_Mailing_DAO_Mailing();
89 $dao->id = $mailingID;
90 $dao->find(TRUE);
91 $dao->storeValues($dao, $defaults);
92
93 //we don't want to retrieve template details once it is
94 //set in session
95 $templateId = $this->get('template');
96 $this->assign('templateSelected', $templateId ? $templateId : 0);
97 if (isset($defaults['msg_template_id']) && !$templateId) {
98 $defaults['template'] = $defaults['msg_template_id'];
99 $messageTemplate = new CRM_Core_DAO_MessageTemplate();
100 $messageTemplate->id = $defaults['msg_template_id'];
101 $messageTemplate->selectAdd();
102 $messageTemplate->selectAdd('msg_text, msg_html');
103 $messageTemplate->find(TRUE);
104
105 $defaults['text_message'] = $messageTemplate->msg_text;
106 $htmlMessage = $messageTemplate->msg_html;
107 }
108
109 if (isset($defaults['body_text'])) {
110 $defaults['text_message'] = $defaults['body_text'];
111 $this->set('textFile', $defaults['body_text']);
112 $this->set('skipTextFile', TRUE);
113 }
114
115 if (isset($defaults['body_html'])) {
116 $htmlMessage = $defaults['body_html'];
117 $this->set('htmlFile', $defaults['body_html']);
118 $this->set('skipHtmlFile', TRUE);
119 }
120
121 //set default from email address.
122 if (!empty($defaults['from_name']) && !empty($defaults['from_email'])) {
123 $defaults['from_email_address'] = array_search('"' . $defaults['from_name'] . '" <' . $defaults['from_email'] . '>',
124 CRM_Core_OptionGroup::values('from_email_address')
125 );
126 }
127 else {
128 //get the default from email address.
129 $defaultAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1');
130 foreach ($defaultAddress as $id => $value) {
131 $defaults['from_email_address'] = $id;
132 }
133 }
134
135 if (!empty($defaults['replyto_email'])) {
136 $replyToEmail = CRM_Core_OptionGroup::values('from_email_address');
137 foreach ($replyToEmail as $value) {
138 if (strstr($value, $defaults['replyto_email'])) {
139 $replyToEmailAddress = $value;
140 break;
141 }
142 }
143 $replyToEmailAddress = explode('<', $replyToEmailAddress);
144 if (count($replyToEmailAddress) > 1) {
145 $replyToEmailAddress = $replyToEmailAddress[0] . '<' . $replyToEmailAddress[1];
146 }
147 $defaults['reply_to_address'] = array_search($replyToEmailAddress, $replyToEmail);
148 }
149 }
150
151 //fix for CRM-2873
152 if (!$reuseMailing) {
153 $textFilePath = $this->get('textFilePath');
154 if ($textFilePath &&
155 file_exists($textFilePath)
156 ) {
157 $defaults['text_message'] = file_get_contents($textFilePath);
158 if (strlen($defaults['text_message']) > 0) {
159 $this->set('skipTextFile', TRUE);
160 }
161 }
162
163 $htmlFilePath = $this->get('htmlFilePath');
164 if ($htmlFilePath &&
165 file_exists($htmlFilePath)
166 ) {
167 $defaults['html_message'] = file_get_contents($htmlFilePath);
168 if (strlen($defaults['html_message']) > 0) {
169 $htmlMessage = $defaults['html_message'];
170 $this->set('skipHtmlFile', TRUE);
171 }
172 }
173 }
174
175 if ($this->get('html_message')) {
176 $htmlMessage = $this->get('html_message');
177 }
178
179 $htmlMessage = str_replace(array("\n", "\r"), ' ', $htmlMessage);
180 $htmlMessage = str_replace("'", "\'", $htmlMessage);
181 $this->assign('message_html', $htmlMessage);
182
183 $defaults['upload_type'] = 1;
184 if (isset($defaults['body_html'])) {
185 $defaults['html_message'] = $defaults['body_html'];
186 }
187
188 //CRM-4678 setdefault to default component when composing new mailing.
189 if (!$reuseMailing) {
190 $componentFields = array(
191 'header_id' => 'Header',
192 'footer_id' => 'Footer',
193 );
194 foreach ($componentFields as $componentVar => $componentType) {
195 $defaults[$componentVar] = CRM_Mailing_PseudoConstant::defaultComponent($componentType, '');
196 }
197 }
198
199 return $defaults;
200 }
201
202 /**
203 * Build the form object
204 *
205 * @return void
206 */
207 public function buildQuickForm() {
208 $session = CRM_Core_Session::singleton();
209 $config = CRM_Core_Config::singleton();
210 $options = array();
211 $tempVar = FALSE;
212
213 // this seems so hacky, not sure what we are doing here and why. Need to investigate and fix
214 $session->getVars($options,
215 "CRM_Mailing_Controller_Send_{$this->controller->_key}"
216 );
217
218 $fromEmailAddress = CRM_Core_OptionGroup::values('from_email_address');
219 if (empty($fromEmailAddress)) {
220 //redirect user to enter from email address.
221 $url = CRM_Utils_System::url('civicrm/admin/options/from_email_address', 'action=add&reset=1');
222 $status = ts("There is no valid from email address present. You can add here <a href='%1'>Add From Email Address.</a>", array(1 => $url));
223 $session->setStatus($status, ts('Notice'));
224 }
225 else {
226 foreach ($fromEmailAddress as $key => $email) {
227 $fromEmailAddress[$key] = htmlspecialchars($fromEmailAddress[$key]);
228 }
229 }
230
231 $this->add('select', 'from_email_address',
232 ts('From Email Address'), array(
233 '' => '- select -') + $fromEmailAddress, TRUE
234 );
235
236 //Added code to add custom field as Reply-To on form when it is enabled from Mailer settings
237 if (isset($config->replyTo) && !empty($config->replyTo) && empty($options['override_verp'])) {
238 $this->add('select', 'reply_to_address', ts('Reply-To'),
239 array('' => '- select -') + $fromEmailAddress
240 );
241 }
242 elseif (!empty($options['override_verp'])) {
243 $trackReplies = TRUE;
244 $this->assign('trackReplies', $trackReplies);
245 }
246
247 $this->add('text', 'subject', ts('Mailing Subject'),
248 CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'subject'), TRUE
249 );
250
251 $attributes = array('onclick' => "showHideUpload();");
252 $options = array(ts('Upload Content'), ts('Compose On-screen'));
253
254 $this->addRadio('upload_type', ts('I want to'), $options, $attributes, "&nbsp;&nbsp;");
255
256 CRM_Mailing_BAO_Mailing::commonCompose($this);
257
258 $this->addElement('file', 'textFile', ts('Upload TEXT Message'), 'size=30 maxlength=60');
259 $this->addUploadElement('textFile');
260 $this->setMaxFileSize(1024 * 1024);
261 $this->addRule('textFile', ts('File size should be less than 1 MByte'), 'maxfilesize', 1024 * 1024);
262 $this->addRule('textFile', ts('File must be in UTF-8 encoding'), 'utf8File');
263
264 $this->addElement('file', 'htmlFile', ts('Upload HTML Message'), 'size=30 maxlength=60');
265 $this->addUploadElement('htmlFile');
266 $this->setMaxFileSize(1024 * 1024);
267 $this->addRule('htmlFile',
268 ts('File size should be less than %1 MByte(s)',
269 array(1 => 1)
270 ),
271 'maxfilesize',
272 1024 * 1024
273 );
274 $this->addRule('htmlFile', ts('File must be in UTF-8 encoding'), 'utf8File');
275
276 //fix upload files when context is search. CRM-3711
277 $ssID = $this->get('ssID');
278 if ($this->_searchBasedMailing && $ssID) {
279 $this->set('uploadNames', array('textFile', 'htmlFile'));
280 }
281
282 CRM_Core_BAO_File::buildAttachment($this,
283 'civicrm_mailing',
284 $this->_mailingID
285 );
286
287 $this->add('select', 'header_id', ts('Mailing Header'),
288 array('' => ts('- none -')) + CRM_Mailing_PseudoConstant::component('Header')
289 );
290
291 $this->add('select', 'footer_id', ts('Mailing Footer'),
292 array('' => ts('- none -')) + CRM_Mailing_PseudoConstant::component('Footer')
293 );
294
295 $this->addFormRule(array('CRM_Mailing_Form_Upload', 'formRule'), $this);
296
297 $buttons = array(
298 array(
299 'type' => 'back',
300 'name' => ts('<< Previous'),
301 ),
302 array(
303 'type' => 'upload',
304 'name' => ts('Next >>'),
305 'spacing' => '&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;',
306 'isDefault' => TRUE,
307 ),
308 array(
309 'type' => 'upload',
310 'name' => ts('Save & Continue Later'),
311 'subName' => 'save',
312 ),
313 array(
314 'type' => 'cancel',
315 'name' => ts('Cancel'),
316 ),
317 );
318 $this->addButtons($buttons);
319 }
320
321 public function postProcess() {
322 $params = $ids = array();
323 $uploadParams = array('header_id', 'footer_id', 'subject', 'from_name', 'from_email');
324 $fileType = array('textFile', 'htmlFile');
325
326 $formValues = $this->controller->exportValues($this->_name);
327
328 foreach ($uploadParams as $key) {
329 if (!empty($formValues[$key]) ||
330 in_array($key, array('header_id', 'footer_id'))
331 ) {
332 $params[$key] = $formValues[$key];
333 $this->set($key, $formValues[$key]);
334 }
335 }
336
337 if (!$formValues['upload_type']) {
338 foreach ($fileType as $key) {
339 $contents = NULL;
340 if (isset($formValues[$key]) &&
341 !empty($formValues[$key])
342 ) {
343 $contents = file_get_contents($formValues[$key]['name']);
344 $this->set($key, $formValues[$key]['name']);
345 }
346 if ($contents) {
347 $params['body_' . substr($key, 0, 4)] = $contents;
348 }
349 else {
350 $params['body_' . substr($key, 0, 4)] = 'NULL';
351 }
352 }
353 }
354 else {
355 $text_message = $formValues['text_message'];
356 $params['body_text'] = $text_message;
357 $this->set('textFile', $params['body_text']);
358 $this->set('text_message', $params['body_text']);
359 $html_message = $formValues['html_message'];
360
361 // dojo editor does some html conversion when tokens are
362 // inserted as links. Hence token replacement fails.
363 // this is hack to revert html conversion for { to %7B and
364 // } to %7D by dojo editor
365 $html_message = str_replace('%7B', '{', str_replace('%7D', '}', $html_message));
366
367 $params['body_html'] = $html_message;
368 $this->set('htmlFile', $params['body_html']);
369 $this->set('html_message', $params['body_html']);
370 }
371
372 $params['name'] = $this->get('name');
373
374 $session = CRM_Core_Session::singleton();
375 $params['contact_id'] = $session->get('userID');
376 $composeFields = array(
377 'template', 'saveTemplate',
378 'updateTemplate', 'saveTemplateName',
379 );
380 $msgTemplate = NULL;
381 //mail template is composed
382 if ($formValues['upload_type']) {
383 $composeParams = array();
384
385 foreach ($composeFields as $key) {
386 if (!empty($formValues[$key])) {
387 $composeParams[$key] = $formValues[$key];
388 $this->set($key, $formValues[$key]);
389 }
390 }
391
392 if (!empty($composeParams['updateTemplate'])) {
393 $templateParams = array(
394 'msg_text' => $text_message,
395 'msg_html' => $html_message,
396 'msg_subject' => $params['subject'],
397 'is_active' => TRUE,
398 );
399
400 $templateParams['id'] = $formValues['template'];
401
402 $msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
403 }
404
405 if (!empty($composeParams['saveTemplate'])) {
406 $templateParams = array(
407 'msg_text' => $text_message,
408 'msg_html' => $html_message,
409 'msg_subject' => $params['subject'],
410 'is_active' => TRUE,
411 );
412
413 $templateParams['msg_title'] = $composeParams['saveTemplateName'];
414
415 $msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
416 }
417
418 if (isset($msgTemplate->id)) {
419 $params['msg_template_id'] = $msgTemplate->id;
420 }
421 else {
422 $params['msg_template_id'] = CRM_Utils_Array::value('template', $formValues);
423 }
424 $this->set('template', $params['msg_template_id']);
425 }
426
427 CRM_Core_BAO_File::formatAttachment($formValues,
428 $params,
429 'civicrm_mailing',
430 $this->_mailingID
431 );
432 $ids['mailing_id'] = $this->_mailingID;
433
434 //handle mailing from name & address.
435 $fromEmailAddress = CRM_Utils_Array::value($formValues['from_email_address'],
436 CRM_Core_OptionGroup::values('from_email_address')
437 );
438
439 //get the from email address
440 $params['from_email'] = CRM_Utils_Mail::pluckEmailFromHeader($fromEmailAddress);
441
442 //get the from Name
443 $params['from_name'] = CRM_Utils_Array::value(1, explode('"', $fromEmailAddress));
444
445 //Add Reply-To to headers
446 if (!empty($formValues['reply_to_address'])) {
447 $replyToEmail = CRM_Core_OptionGroup::values('from_email_address');
448 $params['replyto_email'] = CRM_Utils_Array::value($formValues['reply_to_address'], $replyToEmail);
449 }
450
451 /* Build the mailing object */
452
453 CRM_Mailing_BAO_Mailing::create($params, $ids);
454
455 if (isset($this->_submitValues['_qf_Upload_upload_save']) &&
456 $this->_submitValues['_qf_Upload_upload_save'] == 'Save & Continue Later'
457 ) {
458 //when user perform mailing from search context
459 //redirect it to search result CRM-3711.
460 $ssID = $this->get('ssID');
461 if ($ssID && $this->_searchBasedMailing) {
462 if ($this->_action == CRM_Core_Action::BASIC) {
463 $fragment = 'search';
464 }
465 elseif ($this->_action == CRM_Core_Action::PROFILE) {
466 $fragment = 'search/builder';
467 }
468 elseif ($this->_action == CRM_Core_Action::ADVANCED) {
469 $fragment = 'search/advanced';
470 }
471 else {
472 $fragment = 'search/custom';
473 }
474
475 $context = $this->get('context');
476 if (!CRM_Contact_Form_Search::isSearchContext($context)) {
477 $context = 'search';
478 }
479 $urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}";
480 $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
481 if (CRM_Utils_Rule::qfKey($qfKey)) {
482 $urlParams .= "&qfKey=$qfKey";
483 }
484
485 $session = CRM_Core_Session::singleton();
486 $draftURL = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
487 $status = ts("You can continue later by clicking the 'Continue' action to resume working on it.<br />From <a href='%1'>Draft and Unscheduled Mailings</a>.", array(1 => $draftURL));
488 CRM_Core_Session::setStatus($status, ts('Mailing Saved'), 'success');
489
490 // Redirect user to search.
491 $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams);
492 }
493 else {
494 $status = ts("Click the 'Continue' action to resume working on it.");
495 $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
496 }
497 CRM_Core_Session::setStatus($status, ts('Mailing Saved'), 'success');
498 return $this->controller->setDestination($url);
499 }
500 }
501
502 /**
503 * Validation
504 *
505 * @param array $params
506 * (ref.) an assoc array of name/value pairs.
507 *
508 * @param $files
509 * @param $self
510 *
511 * @return mixed true or array of errors
512 * @static
513 */
514 public static function formRule($params, $files, $self) {
515 if (!empty($_POST['_qf_Import_refresh'])) {
516 return TRUE;
517 }
518 $errors = array();
519 $template = CRM_Core_Smarty::singleton();
520
521 if (isset($params['html_message'])) {
522 $htmlMessage = str_replace(array("\n", "\r"), ' ', $params['html_message']);
523 $htmlMessage = str_replace("'", "\'", $htmlMessage);
524 $template->assign('htmlContent', $htmlMessage);
525 }
526
527 $domain = CRM_Core_BAO_Domain::getDomain();
528
529 $mailing = new CRM_Mailing_BAO_Mailing();
530 $mailing->id = $self->_mailingID;
531 $mailing->find(TRUE);
532
533 $session = CRM_Core_Session::singleton();
534 $values = array(
535 'contact_id' => $session->get('userID'),
536 'version' => 3,
537 );
538 require_once 'api/api.php';
539 $contact = civicrm_api('contact', 'get', $values);
540
541 //CRM-4524
542 $contact = reset($contact['values']);
543
544 $verp = array_flip(array('optOut', 'reply', 'unsubscribe', 'resubscribe', 'owner'));
545 foreach ($verp as $key => $value) {
546 $verp[$key]++;
547 }
548
549 $urls = array_flip(array('forward', 'optOutUrl', 'unsubscribeUrl', 'resubscribeUrl'));
550 foreach ($urls as $key => $value) {
551 $urls[$key]++;
552 }
553
554 // set $header and $footer
555 foreach (array(
556 'header', 'footer') as $part) {
557 $$part = array();
558 if ($params["{$part}_id"]) {
559 //echo "found<p>";
560 $component = new CRM_Mailing_BAO_Component();
561 $component->id = $params["{$part}_id"];
562 $component->find(TRUE);
563 ${$part}['textFile'] = $component->body_text;
564 ${$part}['htmlFile'] = $component->body_html;
565 $component->free();
566 }
567 else {
568 ${$part}['htmlFile'] = ${$part}['textFile'] = '';
569 }
570 }
571
572 $skipTextFile = $self->get('skipTextFile');
573 $skipHtmlFile = $self->get('skipHtmlFile');
574
575 if (!$params['upload_type']) {
576 if ((!isset($files['textFile']) || !file_exists($files['textFile']['tmp_name'])) &&
577 (!isset($files['htmlFile']) || !file_exists($files['htmlFile']['tmp_name']))
578 ) {
579 if (!($skipTextFile || $skipHtmlFile)) {
580 $errors['textFile'] = ts('Please provide either a Text or HTML formatted message - or both.');
581 }
582 }
583 }
584 else {
585 if (empty($params['text_message']) && empty($params['html_message'])) {
586 $errors['html_message'] = ts('Please provide either a Text or HTML formatted message - or both.');
587 }
588 if (!empty($params['saveTemplate']) && empty($params['saveTemplateName'])) {
589 $errors['saveTemplateName'] = ts('Please provide a Template Name.');
590 }
591 }
592
593 foreach (array(
594 'text', 'html') as $file) {
595 if (!$params['upload_type'] && !file_exists(CRM_Utils_Array::value('tmp_name', $files[$file . 'File']))) {
596 continue;
597 }
598 if ($params['upload_type'] && !$params[$file . '_message']) {
599 continue;
600 }
601
602 if (!$params['upload_type']) {
603 $str = file_get_contents($files[$file . 'File']['tmp_name']);
604 $name = $files[$file . 'File']['name'];
605 }
606 else {
607 $str = $params[$file . '_message'];
608 $str = ($file == 'html') ? str_replace('%7B', '{', str_replace('%7D', '}', $str)) : $str;
609 $name = $file . ' message';
610 }
611
612 /* append header/footer */
613
614 $str = $header[$file . 'File'] . $str . $footer[$file . 'File'];
615
616 $dataErrors = array();
617
618 /* First look for missing tokens */
619
620 if (!CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'disable_mandatory_tokens_check')) {
621 $err = CRM_Utils_Token::requiredTokens($str);
622 if ($err !== TRUE) {
623 foreach ($err as $token => $desc) {
624 $dataErrors[] = '<li>' . ts('This message is missing a required token - {%1}: %2',
625 array(1 => $token, 2 => $desc)
626 ) . '</li>';
627 }
628 }
629 }
630
631 /* Do a full token replacement on a dummy verp, the current
632 * contact and domain, and the first organization. */
633
634 // here we make a dummy mailing object so that we
635 // can retrieve the tokens that we need to replace
636 // so that we do get an invalid token error
637 // this is qute hacky and I hope that there might
638 // be a suggestion from someone on how to
639 // make it a bit more elegant
640
641 $dummy_mail = new CRM_Mailing_BAO_Mailing();
642 $mess = "body_{$file}";
643 $dummy_mail->$mess = $str;
644 $tokens = $dummy_mail->getTokens();
645
646 $str = CRM_Utils_Token::replaceSubscribeInviteTokens($str);
647 $str = CRM_Utils_Token::replaceDomainTokens($str, $domain, NULL, $tokens[$file]);
648 $str = CRM_Utils_Token::replaceMailingTokens($str, $mailing, NULL, $tokens[$file]);
649 $str = CRM_Utils_Token::replaceOrgTokens($str, $org);
650 $str = CRM_Utils_Token::replaceActionTokens($str, $verp, $urls, NULL, $tokens[$file]);
651 $str = CRM_Utils_Token::replaceContactTokens($str, $contact, NULL, $tokens[$file]);
652
653 $unmatched = CRM_Utils_Token::unmatchedTokens($str);
654
655 if (!empty($unmatched) && 0) {
656 foreach ($unmatched as $token) {
657 $dataErrors[] = '<li>' . ts('Invalid token code') . ' {' . $token . '}</li>';
658 }
659 }
660 if (!empty($dataErrors)) {
661 $errors[$file . 'File'] = ts('The following errors were detected in %1:', array(
662 1 => $name)) . ' <ul>' . implode('', $dataErrors) . '</ul><br /><a href="' . CRM_Utils_System::docURL2('Sample CiviMail Messages', TRUE, NULL, NULL, NULL, "wiki") . '" target="_blank">' . ts('More information on required tokens...') . '</a>';
663 }
664 }
665
666 $templateName = CRM_Core_BAO_MessageTemplate::getMessageTemplates();
667 if (!empty($params['saveTemplate']) && in_array(CRM_Utils_Array::value('saveTemplateName', $params), $templateName)
668 ) {
669 $errors['saveTemplate'] = ts('Duplicate Template Name.');
670 }
671 return empty($errors) ? TRUE : $errors;
672 }
673
674 /**
675 * Display Name of the form
676 *
677 *
678 * @return string
679 */
680 public function getTitle() {
681 return ts('Mailing Content');
682 }
683 }