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