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