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