Merge pull request #2842 from totten/master-api-rollback-soft-errors
[civicrm-core.git] / CRM / Campaign / Page / Petition / Confirm.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
32 * $Id$
33 *
34 */
35 class CRM_Campaign_Page_Petition_Confirm extends CRM_Core_Page {
36 /**
37 * @return string
38 * @throws Exception
39 */
40 function run() {
41 $contact_id = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject);
42 $subscribe_id = CRM_Utils_Request::retrieve('sid', 'Integer', CRM_Core_DAO::$_nullObject);
43 $hash = CRM_Utils_Request::retrieve('h', 'String', CRM_Core_DAO::$_nullObject);
44 $activity_id = CRM_Utils_Request::retrieve('a', 'String', CRM_Core_DAO::$_nullObject);
45 $petition_id = CRM_Utils_Request::retrieve('p', 'String', CRM_Core_DAO::$_nullObject);
46
47 if (!$contact_id ||
48 !$subscribe_id ||
49 !$hash
50 ) {
51 CRM_Core_Error::fatal(ts("Missing input parameters"));
52 }
53
54 $result = $this->confirm($contact_id, $subscribe_id, $hash, $activity_id, $petition_id);
55 if ($result === FALSE) {
56 $this->assign('success', $result);
57 }
58 else {
59 $this->assign('success', TRUE);
60 // $this->assign( 'group' , $result );
61 }
62
63 list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contact_id);
64 $this->assign('display_name', $displayName);
65 $this->assign('email', $email);
66 $this->assign('petition_id', $petition_id);
67
68 $this->assign('survey_id', $petition_id);
69
70 $pparams['id'] = $petition_id;
71 $this->petition = array();
72 CRM_Campaign_BAO_Survey::retrieve($pparams, $this->petition);
73 $this->assign('is_share', CRM_Utils_Array::value('is_share', $this->petition));
74 $this->assign('thankyou_title', CRM_Utils_Array::value('thankyou_title', $this->petition));
75 $this->assign('thankyou_text', CRM_Utils_Array::value('thankyou_text', $this->petition));
76 CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->petition));
77
78 // send thank you email
79 $params['contactId'] = $contact_id;
80 $params['email-Primary'] = $email;
81 $params['sid'] = $petition_id;
82 $params['activityId'] = $activity_id;
83 CRM_Campaign_BAO_Petition::sendEmail($params, CRM_Campaign_Form_Petition_Signature::EMAIL_THANK);
84
85 return parent::run();
86 }
87
88 /**
89 * Confirm email verification
90 *
91 * @param int $contact_id The id of the contact
92 * @param int $subscribe_id The id of the subscription event
93 * @param string $hash The hash
94 *
95 * @param $activity_id
96 * @param $petition_id
97 *
98 * @return boolean True on success
99 * @access public
100 * @static
101 */
102 public static function confirm($contact_id, $subscribe_id, $hash, $activity_id, $petition_id) {
103 $se = CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash);
104
105 if (!$se) {
106 return FALSE;
107 }
108
109 $transaction = new CRM_Core_Transaction();
110
111 $ce = new CRM_Mailing_Event_BAO_Confirm();
112 $ce->event_subscribe_id = $se->id;
113 $ce->time_stamp = date('YmdHis');
114 $ce->save();
115
116 CRM_Contact_BAO_GroupContact::addContactsToGroup(
117 array($contact_id),
118 $se->group_id,
119 'Email',
120 'Added',
121 $ce->id
122 );
123
124 $bao = new CRM_Campaign_BAO_Petition();
125 $bao->confirmSignature($activity_id, $contact_id, $petition_id);
126 }
127 }
128