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