Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
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_Page_Petition_Confirm extends CRM_Core_Page { | |
36 | function run() { | |
37 | $contact_id = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject); | |
38 | $subscribe_id = CRM_Utils_Request::retrieve('sid', 'Integer', CRM_Core_DAO::$_nullObject); | |
39 | $hash = CRM_Utils_Request::retrieve('h', 'String', CRM_Core_DAO::$_nullObject); | |
40 | $activity_id = CRM_Utils_Request::retrieve('a', 'String', CRM_Core_DAO::$_nullObject); | |
41 | $petition_id = CRM_Utils_Request::retrieve('p', 'String', CRM_Core_DAO::$_nullObject); | |
42 | ||
43 | if (!$contact_id || | |
44 | !$subscribe_id || | |
45 | !$hash | |
46 | ) { | |
47 | CRM_Core_Error::fatal(ts("Missing input parameters")); | |
48 | } | |
49 | ||
50 | $result = $this->confirm($contact_id, $subscribe_id, $hash, $activity_id, $petition_id); | |
51 | if ($result === FALSE) { | |
52 | $this->assign('success', $result); | |
53 | } | |
54 | else { | |
55 | $this->assign('success', TRUE); | |
56 | // $this->assign( 'group' , $result ); | |
57 | } | |
58 | ||
59 | list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contact_id); | |
60 | $this->assign('display_name', $displayName); | |
61 | $this->assign('email', $email); | |
62 | $this->assign('petition_id', $petition_id); | |
63 | ||
64 | $this->assign('survey_id', $petition_id); | |
65 | ||
66 | $pparams['id'] = $petition_id; | |
67 | $this->petition = array(); | |
68 | CRM_Campaign_BAO_Survey::retrieve($pparams, $this->petition); | |
ebd6c880 | 69 | $this->assign('is_share', CRM_Utils_Array::value('is_share', $this->petition)); |
6a488035 TO |
70 | $this->assign('thankyou_title', CRM_Utils_Array::value('thankyou_title', $this->petition)); |
71 | $this->assign('thankyou_text', CRM_Utils_Array::value('thankyou_text', $this->petition)); | |
72 | CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->petition)); | |
73 | ||
74 | // send thank you email | |
75 | $params['contactId'] = $contact_id; | |
76 | $params['email-Primary'] = $email; | |
77 | $params['sid'] = $petition_id; | |
78 | $params['activityId'] = $activity_id; | |
79 | CRM_Campaign_BAO_Petition::sendEmail($params, CRM_Campaign_Form_Petition_Signature::EMAIL_THANK); | |
80 | ||
81 | return parent::run(); | |
82 | } | |
83 | ||
84 | /** | |
85 | * Confirm email verification | |
86 | * | |
87 | * @param int $contact_id The id of the contact | |
88 | * @param int $subscribe_id The id of the subscription event | |
89 | * @param string $hash The hash | |
90 | * | |
91 | * @return boolean True on success | |
92 | * @access public | |
93 | * @static | |
94 | */ | |
95 | public static function confirm($contact_id, $subscribe_id, $hash, $activity_id, $petition_id) { | |
96 | $se = CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash); | |
97 | ||
98 | if (!$se) { | |
99 | return FALSE; | |
100 | } | |
101 | ||
102 | $transaction = new CRM_Core_Transaction(); | |
103 | ||
104 | $ce = new CRM_Mailing_Event_BAO_Confirm(); | |
105 | $ce->event_subscribe_id = $se->id; | |
106 | $ce->time_stamp = date('YmdHis'); | |
107 | $ce->save(); | |
108 | ||
109 | ||
110 | CRM_Contact_BAO_GroupContact::updateGroupMembershipStatus($contact_id, $se->group_id, | |
111 | 'Email', $ce->id | |
112 | ); | |
113 | ||
114 | $bao = new CRM_Campaign_BAO_Petition(); | |
115 | $bao->confirmSignature($activity_id, $contact_id, $petition_id); | |
116 | } | |
117 | } | |
118 |