(NFC) Update CRM/Badge CRM/Campaign CRM/Case to be up to date with a newer coder
[civicrm-core.git] / CRM / Campaign / Page / Petition / Confirm.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
32 */
33 class CRM_Campaign_Page_Petition_Confirm extends CRM_Core_Page {
34
35 /**
36 * @return string
37 * @throws Exception
38 */
39 public function run() {
40 CRM_Utils_System::addHTMLHead('<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">');
41
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');
47 if (!$petition_id) {
48 $petition_id = CRM_Utils_Request::retrieve('p', 'String');
49 }
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
74 $pparams['id'] = $petition_id;
75 $this->petition = [];
76 CRM_Campaign_BAO_Survey::retrieve($pparams, $this->petition);
77 $this->assign('is_share', CRM_Utils_Array::value('is_share', $this->petition));
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 /**
93 * Confirm email verification.
94 *
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.
101 *
102 * @param int $activity_id
103 * @param int $petition_id
104 *
105 * @return bool
106 * True on success
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
122 CRM_Contact_BAO_GroupContact::addContactsToGroup(
123 [$contact_id],
124 $se->group_id,
125 'Email',
126 'Added',
127 $ce->id
128 );
129
130 $bao = new CRM_Campaign_BAO_Petition();
131 $bao->confirmSignature($activity_id, $contact_id, $petition_id);
132 }
133
134 }