Merge pull request #3112 from freeform/CRM-14568
[civicrm-core.git] / CRM / Campaign / BAO / Petition.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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 class CRM_Campaign_BAO_Petition extends CRM_Campaign_BAO_Survey {
36 function __construct() {
37 parent::__construct();
38 // expire cookie in one day
39 $this->cookieExpire = (1 * 60 * 60 * 24);
40 }
41
42 /**
43 * Function to get Petition Details for dashboard.
44 *
45 * @static
46 */
47 static function getPetitionSummary($params = array(), $onlyCount = FALSE) {
48 //build the limit and order clause.
49 $limitClause = $orderByClause = $lookupTableJoins = NULL;
50 if (!$onlyCount) {
51 $sortParams = array(
52 'sort' => 'created_date',
53 'offset' => 0,
54 'rowCount' => 10,
55 'sortOrder' => 'desc',
56 );
57 foreach ($sortParams as $name => $default) {
58 if (!empty($params[$name])) {
59 $sortParams[$name] = $params[$name];
60 }
61 }
62
63 //need to lookup tables.
64 $orderOnPetitionTable = TRUE;
65 if ($sortParams['sort'] == 'campaign') {
66 $orderOnPetitionTable = FALSE;
67 $lookupTableJoins = '
68 LEFT JOIN civicrm_campaign campaign ON ( campaign.id = petition.campaign_id )';
69 $orderByClause = "ORDER BY campaign.title {$sortParams['sortOrder']}";
70 }
71 elseif ($sortParams['sort'] == 'activity_type') {
72 $orderOnPetitionTable = FALSE;
73 $lookupTableJoins = "
74 LEFT JOIN civicrm_option_value activity_type ON ( activity_type.value = petition.activity_type_id
75 OR petition.activity_type_id IS NULL )
76 INNER JOIN civicrm_option_group grp ON ( activity_type.option_group_id = grp.id AND grp.name = 'activity_type' )";
77 $orderByClause = "ORDER BY activity_type.label {$sortParams['sortOrder']}";
78 }
79 elseif ($sortParams['sort'] == 'isActive') {
80 $sortParams['sort'] = 'is_active';
81 }
82 if ($orderOnPetitionTable) {
83 $orderByClause = "ORDER BY petition.{$sortParams['sort']} {$sortParams['sortOrder']}";
84 }
85 $limitClause = "LIMIT {$sortParams['offset']}, {$sortParams['rowCount']}";
86 }
87
88 //build the where clause.
89 $queryParams = $where = array();
90
91 //we only have activity type as a
92 //difference between survey and petition.
93 $petitionTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'petition', 'name');
94 if ($petitionTypeID) {
95 $where[] = "( petition.activity_type_id = %1 )";
96 $queryParams[1] = array($petitionTypeID, 'Positive');
97 }
98 if (!empty($params['title'])) {
99 $where[] = "( petition.title LIKE %2 )";
100 $queryParams[2] = array('%' . trim($params['title']) . '%', 'String');
101 }
102 if (!empty($params['campaign_id'])) {
103 $where[] = '( petition.campaign_id = %3 )';
104 $queryParams[3] = array($params['campaign_id'], 'Positive');
105 }
106 $whereClause = NULL;
107 if (!empty($where)) {
108 $whereClause = ' WHERE ' . implode(" \nAND ", $where);
109 }
110
111 $selectClause = '
112 SELECT petition.id as id,
113 petition.title as title,
114 petition.is_active as is_active,
115 petition.result_id as result_id,
116 petition.is_default as is_default,
117 petition.campaign_id as campaign_id,
118 petition.activity_type_id as activity_type_id';
119
120 if ($onlyCount) {
121 $selectClause = 'SELECT COUNT(*)';
122 }
123 $fromClause = 'FROM civicrm_survey petition';
124
125 $query = "{$selectClause} {$fromClause} {$whereClause} {$orderByClause} {$limitClause}";
126
127 if ($onlyCount) {
128 return (int) CRM_Core_DAO::singleValueQuery($query, $queryParams);
129 }
130
131 $petitions = array();
132 $properties = array(
133 'id',
134 'title',
135 'campaign_id',
136 'is_active',
137 'is_default',
138 'result_id',
139 'activity_type_id',
140 );
141
142 $petition = CRM_Core_DAO::executeQuery($query, $queryParams);
143 while ($petition->fetch()) {
144 foreach ($properties as $property) {
145 $petitions[$petition->id][$property] = $petition->$property;
146 }
147 }
148
149 return $petitions;
150 }
151
152 /**
153 * Get the petition count.
154 *
155 * @static
156 */
157 static function getPetitionCount() {
158 $whereClause = 'WHERE ( 1 )';
159 $queryParams = array();
160 $petitionTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'petition', 'name');
161 if ($petitionTypeID) {
162 $whereClause = "WHERE ( petition.activity_type_id = %1 )";
163 $queryParams[1] = array($petitionTypeID, 'Positive');
164 }
165 $query = "SELECT COUNT(*) FROM civicrm_survey petition {$whereClause}";
166
167 return (int) CRM_Core_DAO::singleValueQuery($query, $queryParams);
168 }
169
170 /**
171 * takes an associative array and creates a petition signature activity
172 *
173 * @param array $params (reference ) an assoc array of name/value pairs
174 *
175 * @return object CRM_Campaign_BAO_Petition
176 * @access public
177 * @static
178 */
179 function createSignature(&$params) {
180 if (empty($params)) {
181 return;
182 }
183
184 if (!isset($params['sid'])) {
185 $statusMsg = ts('No survey sid parameter. Cannot process signature.');
186 CRM_Core_Session::setStatus($statusMsg, ts('Sorry'), 'error');
187 return;
188 }
189
190 if (isset($params['contactId'])) {
191
192 // add signature as activity with survey id as source id
193 // get the activity type id associated with this survey
194 $surveyInfo = CRM_Campaign_BAO_Petition::getSurveyInfo($params['sid']);
195
196 // create activity
197 // 1-Schedule, 2-Completed
198
199 $activityParams = array(
200 'source_contact_id' => $params['contactId'],
201 'target_contact_id' => $params['contactId'],
202 'source_record_id' => $params['sid'],
203 'subject' => $surveyInfo['title'],
204 'activity_type_id' => $surveyInfo['activity_type_id'],
205 'activity_date_time' => date("YmdHis"),
206 'status_id' => $params['statusId'],
207 'activity_campaign_id' => $params['activity_campaign_id'],
208 );
209
210 //activity creation
211 // *** check for activity using source id - if already signed
212 $activity = CRM_Activity_BAO_Activity::create($activityParams);
213
214 // save activity custom data
215 if (!empty($params['custom']) &&
216 is_array($params['custom'])
217 ) {
218 CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_activity', $activity->id);
219 }
220
221 // set permanent cookie to indicate this petition already signed on the computer
222 setcookie('signed_' . $params['sid'], $activity->id, time() + $this->cookieExpire, '/');
223 }
224
225 return $activity;
226 }
227
228 function confirmSignature($activity_id, $contact_id, $petition_id) {
229 // change activity status to completed (status_id = 2)
230 // I wonder why do we need contact_id when we have activity_id anyway? [chastell]
231 $sql = 'UPDATE civicrm_activity SET status_id = 2 WHERE id = %1';
232 $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
233 $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
234 $params = array(
235 1 => array($activity_id, 'Integer'),
236 2 => array($contact_id, 'Integer'),
237 3 => array($sourceID, 'Integer')
238 );
239 CRM_Core_DAO::executeQuery($sql, $params);
240
241 $sql = 'UPDATE civicrm_activity_contact SET contact_id = %2 WHERE activity_id = %1 AND record_type_id = %3';
242 CRM_Core_DAO::executeQuery($sql, $params);
243 // remove 'Unconfirmed' tag for this contact
244 $tag_name = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
245 'tag_unconfirmed',
246 NULL,
247 'Unconfirmed'
248 );
249
250 $sql = "
251 DELETE FROM civicrm_entity_tag
252 WHERE entity_table = 'civicrm_contact'
253 AND entity_id = %1
254 AND tag_id = ( SELECT id FROM civicrm_tag WHERE name = %2 )";
255 $params = array(
256 1 => array($contact_id, 'Integer'),
257 2 => array($tag_name, 'String'),
258 );
259 CRM_Core_DAO::executeQuery($sql, $params);
260
261 // set permanent cookie to indicate this users email address now confirmed
262 setcookie("confirmed_{$petition_id}",
263 $activity_id,
264 time() + $this->cookieExpire,
265 '/'
266 );
267
268 return TRUE;
269 }
270
271 /**
272 * Function to get Petition Signature Total
273 *
274 * @param $surveyId
275 *
276 * @return array
277 * @internal param bool $all
278 * @internal param int $id
279 * @static
280 */
281 static function getPetitionSignatureTotalbyCountry($surveyId) {
282 $countries = array();
283 $sql = "
284 SELECT count(civicrm_address.country_id) as total,
285 IFNULL(country_id,'') as country_id,IFNULL(iso_code,'') as country_iso, IFNULL(civicrm_country.name,'') as country
286 FROM ( civicrm_activity a, civicrm_survey, civicrm_contact )
287 LEFT JOIN civicrm_address ON civicrm_address.contact_id = civicrm_contact.id AND civicrm_address.is_primary = 1
288 LEFT JOIN civicrm_country ON civicrm_address.country_id = civicrm_country.id
289 LEFT JOIN civicrm_activity_contact ac ON ( ac.activity_id = a.id AND ac.record_type_id = %2 )
290 WHERE
291 ac.contact_id = civicrm_contact.id AND
292 a.activity_type_id = civicrm_survey.activity_type_id AND
293 civicrm_survey.id = %1 AND
294 a.source_record_id = %1 ";
295
296 $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
297 $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
298 $params = array(
299 1 => array($surveyId, 'Integer'),
300 2 => array($sourceID, 'Integer')
301 );
302 $sql .= " GROUP BY civicrm_address.country_id";
303 $fields = array('total', 'country_id', 'country_iso', 'country');
304
305 $dao = CRM_Core_DAO::executeQuery($sql, $params);
306 while ($dao->fetch()) {
307 $row = array();
308 foreach ($fields as $field) {
309 $row[$field] = $dao->$field;
310 }
311 $countries[] = $row;
312 }
313 return $countries;
314 }
315
316 /**
317 * Function to get Petition Signature Total
318 *
319 * @param $surveyId
320 *
321 * @return array
322 * @internal param bool $all
323 * @internal param int $id
324 * @static
325 */
326 static function getPetitionSignatureTotal($surveyId) {
327 $surveyInfo = CRM_Campaign_BAO_Petition::getSurveyInfo((int) $surveyId);
328 //$activityTypeID = $surveyInfo['activity_type_id'];
329 $sql = "
330 SELECT
331 status_id,count(id) as total
332 FROM civicrm_activity
333 WHERE
334 source_record_id = " . (int) $surveyId . " AND activity_type_id = " . (int) $surveyInfo['activity_type_id'] . " GROUP BY status_id";
335
336 $statusTotal = array();
337 $total = 0;
338 $dao = CRM_Core_DAO::executeQuery($sql);
339 while ($dao->fetch()) {
340 $total += $dao->total;
341 $statusTotal['status'][$dao->status_id] = $dao->total;
342 }
343 $statusTotal['count'] = $total;
344 return $statusTotal;
345 }
346
347
348 public static function getSurveyInfo($surveyId = NULL) {
349 $surveyInfo = array();
350
351 $sql = "
352 SELECT activity_type_id,
353 campaign_id,
354 s.title,
355 ov.label AS activity_type
356 FROM civicrm_survey s, civicrm_option_value ov, civicrm_option_group og
357 WHERE s.id = " . (int) $surveyId . "
358 AND s.activity_type_id = ov.value
359 AND ov.option_group_id = og.id
360 AND og.name = 'activity_type'";
361
362 $dao = CRM_Core_DAO::executeQuery($sql);
363 while ($dao->fetch()) {
364 //$survey['campaign_id'] = $dao->campaign_id;
365 //$survey['campaign_name'] = $dao->campaign_name;
366 $surveyInfo['activity_type'] = $dao->activity_type;
367 $surveyInfo['activity_type_id'] = $dao->activity_type_id;
368 $surveyInfo['title'] = $dao->title;
369 }
370
371 return $surveyInfo;
372 }
373
374 /**
375 * Function to get Petition Signature Details
376 *
377 * @param $surveyId
378 * @param null $status_id
379 *
380 * @return array
381 * @internal param bool $all
382 * @internal param int $id
383 * @static
384 */
385 static function getPetitionSignature($surveyId, $status_id = NULL) {
386
387 // sql injection protection
388 $surveyId = (int) $surveyId;
389 $signature = array();
390
391 $sql = "
392 SELECT a.id,
393 a.source_record_id as survey_id,
394 a.activity_date_time,
395 a.status_id,
396 civicrm_contact.id as contact_id,
397 civicrm_contact.contact_type,civicrm_contact.contact_sub_type,image_URL,
398 first_name,last_name,sort_name,
399 employer_id,organization_name,
400 household_name,
401 IFNULL(gender_id,'') AS gender_id,
402 IFNULL(state_province_id,'') AS state_province_id,
403 IFNULL(country_id,'') as country_id,IFNULL(iso_code,'') as country_iso, IFNULL(civicrm_country.name,'') as country
404 FROM (civicrm_activity a, civicrm_survey, civicrm_contact )
405 LEFT JOIN civicrm_activity_contact ac ON ( ac.activity_id = a.id AND ac.record_type_id = %3 )
406 LEFT JOIN civicrm_address ON civicrm_address.contact_id = civicrm_contact.id AND civicrm_address.is_primary = 1
407 LEFT JOIN civicrm_country ON civicrm_address.country_id = civicrm_country.id
408 WHERE
409 ac.contact_id = civicrm_contact.id AND
410 a.activity_type_id = civicrm_survey.activity_type_id AND
411 civicrm_survey.id = %1 AND
412 a.source_record_id = %1 ";
413
414 $params = array(1 => array($surveyId, 'Integer'));
415
416 if ($status_id) {
417 $sql .= " AND status_id = %2";
418 $params[2] = array($status_id, 'Integer');
419 }
420 $sql .= " ORDER BY a.activity_date_time";
421
422 $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
423 $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
424 $params[3] = array($sourceID, 'Integer');
425
426 $fields = array(
427 'id',
428 'survey_id',
429 'contact_id',
430 'activity_date_time',
431 'activity_type_id',
432 'status_id',
433 'first_name',
434 'last_name',
435 'sort_name',
436 'gender_id',
437 'country_id',
438 'state_province_id',
439 'country_iso',
440 'country',
441 );
442
443 $dao = CRM_Core_DAO::executeQuery($sql, $params);
444 while ($dao->fetch()) {
445 $row = array();
446 foreach ($fields as $field) {
447 $row[$field] = $dao->$field;
448 }
449 $signature[] = $row;
450 }
451 return $signature;
452 }
453
454 /**
455 * This function returns all entities assigned to a specific tag
456 *
457 * @param object $tag an object of a tag.
458 *
459 * @return array $contactIds array of contact ids
460 * @access public
461 */
462 function getEntitiesByTag($tag) {
463 $contactIds = array();
464 $entityTagDAO = new CRM_Core_DAO_EntityTag();
465 $entityTagDAO->tag_id = $tag['id'];
466 $entityTagDAO->find();
467
468 while ($entityTagDAO->fetch()) {
469 $contactIds[] = $entityTagDAO->entity_id;
470 }
471 return $contactIds;
472 }
473
474 /**
475 * Function to check if contact has signed this petition
476 *
477 * @param int $surveyId
478 * @param int $contactId
479 *
480 * @return array
481 * @static
482 */
483 static function checkSignature($surveyId, $contactId) {
484
485 $surveyInfo = CRM_Campaign_BAO_Petition::getSurveyInfo($surveyId);
486 $signature = array();
487 $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
488 $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
489
490 $sql = "
491 SELECT a.id AS id,
492 a.source_record_id AS source_record_id,
493 ac.contact_id AS source_contact_id,
494 a.activity_date_time AS activity_date_time,
495 a.activity_type_id AS activity_type_id,
496 a.status_id AS status_id,
497 %1 AS survey_title
498 FROM civicrm_activity a
499 INNER JOIN civicrm_activity_contact ac ON (ac.activity_id = a.id AND ac.record_type_id = %5)
500 WHERE a.source_record_id = %2
501 AND a.activity_type_id = %3
502 AND ac.contact_id = %4
503 ";
504 $params = array(
505 1 => array($surveyInfo['title'], 'String'),
506 2 => array($surveyId, 'Integer'),
507 3 => array($surveyInfo['activity_type_id'], 'Integer'),
508 4 => array($contactId, 'Integer'),
509 5 => array($sourceID, 'Integer')
510 );
511
512 $dao = CRM_Core_DAO::executeQuery($sql, $params);
513 while ($dao->fetch()) {
514 $signature[$dao->id]['id'] = $dao->id;
515 $signature[$dao->id]['source_record_id'] = $dao->source_record_id;
516 $signature[$dao->id]['source_contact_id'] = CRM_Contact_BAO_Contact::displayName($dao->source_contact_id);
517 $signature[$dao->id]['activity_date_time'] = $dao->activity_date_time;
518 $signature[$dao->id]['activity_type_id'] = $dao->activity_type_id;
519 $signature[$dao->id]['status_id'] = $dao->status_id;
520 $signature[$dao->id]['survey_title'] = $dao->survey_title;
521 $signature[$dao->id]['contactId'] = $dao->source_contact_id;
522 }
523
524 return $signature;
525 }
526
527 /**
528 * takes an associative array and sends a thank you or email verification email
529 *
530 * @param array $params (reference ) an assoc array of name/value pairs
531 *
532 * @param $sendEmailMode
533 *
534 * @throws Exception
535 * @return void
536 @access public
537 * @static
538 */
539 public static function sendEmail($params, $sendEmailMode) {
540
541 /* sendEmailMode
542 * CRM_Campaign_Form_Petition_Signature::EMAIL_THANK
543 * connected user via login/pwd - thank you
544 * or dedupe contact matched who doesn't have a tag CIVICRM_TAG_UNCONFIRMED - thank you
545 * or login using fb connect - thank you + click to add msg to fb wall
546 *
547 * CRM_Campaign_Form_Petition_Signature::EMAIL_CONFIRM
548 * send a confirmation request email
549 */
550
551 // check if the group defined by CIVICRM_PETITION_CONTACTS exists, else create it
552 $petitionGroupName = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
553 'petition_contacts',
554 NULL,
555 'Petition Contacts'
556 );
557
558 $dao = new CRM_Contact_DAO_Group();
559 $dao->title = $petitionGroupName;
560 if (!$dao->find(TRUE)) {
561 $dao->is_active = 1;
562 $dao->visibility = 'User and User Admin Only';
563 $dao->save();
564 }
565 $group_id = $dao->id;
566
567 // get petition info
568 $petitionParams['id'] = $params['sid'];
569 $petitionInfo = array();
570 CRM_Campaign_BAO_Survey::retrieve($petitionParams, $petitionInfo);
571 if (empty($petitionInfo)) {
572 CRM_Core_Error::fatal('Petition doesn\'t exist.');
573 }
574
575 //get the default domain email address.
576 list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
577
578 $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
579
580 $toName = CRM_Contact_BAO_Contact::displayName($params['contactId']);
581
582 $replyTo = "do-not-reply@$emailDomain";
583
584 // set additional general message template params (custom tokens to use in email msg templates)
585 // tokens then available in msg template as {$petition.title}, etc
586 $petitionTokens['title'] = $petitionInfo['title'];
587 $petitionTokens['petitionId'] = $params['sid'];
588 $tplParams['petition'] = $petitionTokens;
589
590 switch ($sendEmailMode) {
591 case CRM_Campaign_Form_Petition_Signature::EMAIL_THANK:
592
593 // add this contact to the CIVICRM_PETITION_CONTACTS group
594 // Cannot pass parameter 1 by reference
595 $p = array($params['contactId']);
596 CRM_Contact_BAO_GroupContact::addContactsToGroup($p, $group_id, 'API');
597
598 if ($params['email-Primary']) {
599 CRM_Core_BAO_MessageTemplate::sendTemplate(
600 array(
601 'groupName' => 'msg_tpl_workflow_petition',
602 'valueName' => 'petition_sign',
603 'contactId' => $params['contactId'],
604 'tplParams' => $tplParams,
605 'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>",
606 'toName' => $toName,
607 'toEmail' => $params['email-Primary'],
608 'replyTo' => $replyTo,
609 'petitionId' => $params['sid'],
610 'petitionTitle' => $petitionInfo['title'],
611 )
612 );
613 }
614 break;
615
616 case CRM_Campaign_Form_Petition_Signature::EMAIL_CONFIRM:
617 // create mailing event subscription record for this contact
618 // this will allow using a hash key to confirm email address by sending a url link
619 $se = CRM_Mailing_Event_BAO_Subscribe::subscribe($group_id,
620 $params['email-Primary'],
621 $params['contactId'],
622 'profile'
623 );
624
625 // require_once 'CRM/Core/BAO/Domain.php';
626 // $domain = CRM_Core_BAO_Domain::getDomain();
627 $config = CRM_Core_Config::singleton();
628 $localpart = CRM_Core_BAO_MailSettings::defaultLocalpart();
629
630 $replyTo = implode($config->verpSeparator,
631 array(
632 $localpart . 'c',
633 $se->contact_id,
634 $se->id,
635 $se->hash,
636 )
637 ) . "@$emailDomain";
638
639
640 $confirmUrl = CRM_Utils_System::url('civicrm/petition/confirm',
641 "reset=1&cid={$se->contact_id}&sid={$se->id}&h={$se->hash}&a={$params['activityId']}&p={$params['sid']}",
642 TRUE
643 );
644 $confirmUrlPlainText = CRM_Utils_System::url('civicrm/petition/confirm',
645 "reset=1&cid={$se->contact_id}&sid={$se->id}&h={$se->hash}&a={$params['activityId']}&p={$params['sid']}",
646 TRUE,
647 NULL,
648 FALSE
649 );
650
651 // set email specific message template params and assign to tplParams
652 $petitionTokens['confirmUrl'] = $confirmUrl;
653 $petitionTokens['confirmUrlPlainText'] = $confirmUrlPlainText;
654 $tplParams['petition'] = $petitionTokens;
655
656 if ($params['email-Primary']) {
657 CRM_Core_BAO_MessageTemplate::sendTemplate(
658 array(
659 'groupName' => 'msg_tpl_workflow_petition',
660 'valueName' => 'petition_confirmation_needed',
661 'contactId' => $params['contactId'],
662 'tplParams' => $tplParams,
663 'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>",
664 'toName' => $toName,
665 'toEmail' => $params['email-Primary'],
666 'replyTo' => $replyTo,
667 'petitionId' => $params['sid'],
668 'petitionTitle' => $petitionInfo['title'],
669 'confirmUrl' => $confirmUrl,
670 )
671 );
672 }
673 break;
674 }
675 }
676 }
677