Merge pull request #13241 from seamuslee001/561_schedule_reminders
[civicrm-core.git] / CRM / Campaign / Page / Petition / Confirm.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
6b83d5bd 31 * @copyright CiviCRM LLC (c) 2004-2019
6a488035
TO
32 */
33class CRM_Campaign_Page_Petition_Confirm extends CRM_Core_Page {
30c4e065
EM
34 /**
35 * @return string
36 * @throws Exception
37 */
00be9182 38 public function run() {
ad03f101 39 CRM_Utils_System::addHTMLHead('<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">');
94880218 40
a3d827a7
CW
41 $contact_id = CRM_Utils_Request::retrieve('cid', 'Integer');
42 $subscribe_id = CRM_Utils_Request::retrieve('sid', 'Integer');
43 $hash = CRM_Utils_Request::retrieve('h', 'String');
44 $activity_id = CRM_Utils_Request::retrieve('a', 'String');
45 $petition_id = CRM_Utils_Request::retrieve('pid', 'String');
11e23469 46 if (!$petition_id) {
a3d827a7 47 $petition_id = CRM_Utils_Request::retrieve('p', 'String');
11e23469 48 }
6a488035
TO
49
50 if (!$contact_id ||
51 !$subscribe_id ||
52 !$hash
53 ) {
54 CRM_Core_Error::fatal(ts("Missing input parameters"));
55 }
56
57 $result = $this->confirm($contact_id, $subscribe_id, $hash, $activity_id, $petition_id);
58 if ($result === FALSE) {
59 $this->assign('success', $result);
60 }
61 else {
62 $this->assign('success', TRUE);
63 // $this->assign( 'group' , $result );
64 }
65
66 list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contact_id);
67 $this->assign('display_name', $displayName);
68 $this->assign('email', $email);
69 $this->assign('petition_id', $petition_id);
70
71 $this->assign('survey_id', $petition_id);
72
353ffa53 73 $pparams['id'] = $petition_id;
6a488035
TO
74 $this->petition = array();
75 CRM_Campaign_BAO_Survey::retrieve($pparams, $this->petition);
ebd6c880 76 $this->assign('is_share', CRM_Utils_Array::value('is_share', $this->petition));
6a488035
TO
77 $this->assign('thankyou_title', CRM_Utils_Array::value('thankyou_title', $this->petition));
78 $this->assign('thankyou_text', CRM_Utils_Array::value('thankyou_text', $this->petition));
79 CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->petition));
80
81 // send thank you email
82 $params['contactId'] = $contact_id;
83 $params['email-Primary'] = $email;
84 $params['sid'] = $petition_id;
85 $params['activityId'] = $activity_id;
86 CRM_Campaign_BAO_Petition::sendEmail($params, CRM_Campaign_Form_Petition_Signature::EMAIL_THANK);
87
88 return parent::run();
89 }
90
91 /**
fe482240 92 * Confirm email verification.
6a488035 93 *
7aaf6db0
TO
94 * @param int $contact_id
95 * The id of the contact.
96 * @param int $subscribe_id
97 * The id of the subscription event.
98 * @param string $hash
99 * The hash.
6c8f6e67 100 *
100fef9d
CW
101 * @param int $activity_id
102 * @param int $petition_id
6a488035 103 *
389bcebf 104 * @return bool
a6c01b45 105 * True on success
6a488035
TO
106 */
107 public static function confirm($contact_id, $subscribe_id, $hash, $activity_id, $petition_id) {
108 $se = CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash);
109
110 if (!$se) {
111 return FALSE;
112 }
113
114 $transaction = new CRM_Core_Transaction();
115
116 $ce = new CRM_Mailing_Event_BAO_Confirm();
117 $ce->event_subscribe_id = $se->id;
118 $ce->time_stamp = date('YmdHis');
119 $ce->save();
120
c49a2977
CW
121 CRM_Contact_BAO_GroupContact::addContactsToGroup(
122 array($contact_id),
123 $se->group_id,
124 'Email',
125 'Added',
126 $ce->id
6a488035
TO
127 );
128
129 $bao = new CRM_Campaign_BAO_Petition();
130 $bao->confirmSignature($activity_id, $contact_id, $petition_id);
131 }
96025800 132
6a488035 133}