Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Campaign_Page_Petition_Confirm extends CRM_Core_Page { | |
30c4e065 EM |
36 | /** |
37 | * @return string | |
38 | * @throws Exception | |
39 | */ | |
6a488035 | 40 | function run() { |
ad03f101 JP |
41 | CRM_Utils_System::addHTMLHead('<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">'); |
42 | ||
6a488035 TO |
43 | $contact_id = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject); |
44 | $subscribe_id = CRM_Utils_Request::retrieve('sid', 'Integer', CRM_Core_DAO::$_nullObject); | |
45 | $hash = CRM_Utils_Request::retrieve('h', 'String', CRM_Core_DAO::$_nullObject); | |
46 | $activity_id = CRM_Utils_Request::retrieve('a', 'String', CRM_Core_DAO::$_nullObject); | |
18d62c87 | 47 | $petition_id = CRM_Utils_Request::retrieve('pid', 'String', CRM_Core_DAO::$_nullObject); |
11e23469 | 48 | if (!$petition_id) { |
49 | $petition_id = CRM_Utils_Request::retrieve('p', 'String', CRM_Core_DAO::$_nullObject); | |
50 | } | |
6a488035 TO |
51 | |
52 | if (!$contact_id || | |
53 | !$subscribe_id || | |
54 | !$hash | |
55 | ) { | |
56 | CRM_Core_Error::fatal(ts("Missing input parameters")); | |
57 | } | |
58 | ||
59 | $result = $this->confirm($contact_id, $subscribe_id, $hash, $activity_id, $petition_id); | |
60 | if ($result === FALSE) { | |
61 | $this->assign('success', $result); | |
62 | } | |
63 | else { | |
64 | $this->assign('success', TRUE); | |
65 | // $this->assign( 'group' , $result ); | |
66 | } | |
67 | ||
68 | list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contact_id); | |
69 | $this->assign('display_name', $displayName); | |
70 | $this->assign('email', $email); | |
71 | $this->assign('petition_id', $petition_id); | |
72 | ||
73 | $this->assign('survey_id', $petition_id); | |
74 | ||
75 | $pparams['id'] = $petition_id; | |
76 | $this->petition = array(); | |
77 | CRM_Campaign_BAO_Survey::retrieve($pparams, $this->petition); | |
ebd6c880 | 78 | $this->assign('is_share', CRM_Utils_Array::value('is_share', $this->petition)); |
6a488035 TO |
79 | $this->assign('thankyou_title', CRM_Utils_Array::value('thankyou_title', $this->petition)); |
80 | $this->assign('thankyou_text', CRM_Utils_Array::value('thankyou_text', $this->petition)); | |
81 | CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->petition)); | |
82 | ||
83 | // send thank you email | |
84 | $params['contactId'] = $contact_id; | |
85 | $params['email-Primary'] = $email; | |
86 | $params['sid'] = $petition_id; | |
87 | $params['activityId'] = $activity_id; | |
88 | CRM_Campaign_BAO_Petition::sendEmail($params, CRM_Campaign_Form_Petition_Signature::EMAIL_THANK); | |
89 | ||
90 | return parent::run(); | |
91 | } | |
92 | ||
93 | /** | |
94 | * Confirm email verification | |
95 | * | |
6c8f6e67 EM |
96 | * @param int $contact_id The id of the contact |
97 | * @param int $subscribe_id The id of the subscription event | |
98 | * @param string $hash The hash | |
99 | * | |
100fef9d CW |
100 | * @param int $activity_id |
101 | * @param int $petition_id | |
6a488035 TO |
102 | * |
103 | * @return boolean True on success | |
104 | * @access public | |
105 | * @static | |
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 | } | |
132 | } | |
133 |