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