quickfix for crash if civigrant not enabled and have admin rights
[civicrm-core.git] / CRM / Mailing / Page / Common.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17 class CRM_Mailing_Page_Common extends CRM_Core_Page {
18 protected $_type = NULL;
19
20 /**
21 * Run page.
22 *
23 * This includes assigning smarty variables and other page processing.
24 *
25 * @return string
26 * @throws Exception
27 */
28 public function run() {
29 $job_id = CRM_Utils_Request::retrieve('jid', 'Integer');
30 $queue_id = CRM_Utils_Request::retrieve('qid', 'Integer');
31 $hash = CRM_Utils_Request::retrieve('h', 'String');
32
33 if (!$job_id ||
34 !$queue_id ||
35 !$hash
36 ) {
37 throw new CRM_Core_Exception(ts("Missing input parameters"));
38 }
39
40 // verify that the three numbers above match
41 $q = CRM_Mailing_Event_BAO_Queue::verify($job_id, $queue_id, $hash);
42 if (!$q) {
43 throw new CRM_Core_Exception(ts("There was an error in your request"));
44 }
45
46 $cancel = CRM_Utils_Request::retrieve("_qf_{$this->_type}_cancel", 'String');
47 if ($cancel) {
48 $config = CRM_Core_Config::singleton();
49 CRM_Utils_System::redirect($config->userFrameworkBaseURL);
50 }
51
52 $confirm = CRM_Utils_Request::retrieve('confirm', 'Boolean');
53
54 list($displayName, $email) = CRM_Mailing_Event_BAO_Queue::getContactInfo($queue_id);
55 $this->assign('display_name', $displayName);
56 $this->assign('email', $email);
57 $this->assign('confirm', $confirm);
58
59 $groups = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_mailing($job_id, $queue_id, $hash, TRUE);
60 $this->assign('groups', $groups);
61 $groupExist = NULL;
62 foreach ($groups as $key => $value) {
63 if ($value) {
64 $groupExist = TRUE;
65 }
66 }
67 $this->assign('groupExist', $groupExist);
68
69 if ($confirm) {
70 if ($this->_type == 'unsubscribe') {
71 $groups = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_mailing($job_id, $queue_id, $hash);
72 if (count($groups)) {
73 CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue_id, $groups, FALSE, $job_id);
74 }
75 else {
76 // should we indicate an error, or just ignore?
77 }
78 }
79 elseif ($this->_type == 'resubscribe') {
80 $groups = CRM_Mailing_Event_BAO_Resubscribe::resub_to_mailing($job_id, $queue_id, $hash);
81 if (count($groups)) {
82 CRM_Mailing_Event_BAO_Resubscribe::send_resub_response($queue_id, $groups, $job_id);
83 }
84 else {
85 // should we indicate an error, or just ignore?
86 }
87 }
88 else {
89 if (CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_domain($job_id, $queue_id, $hash)) {
90 CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue_id, NULL, TRUE, $job_id);
91 }
92 else {
93 // should we indicate an error, or just ignore?
94 }
95 }
96 }
97 else {
98 $confirmURL = CRM_Utils_System::url("civicrm/mailing/{$this->_type}",
99 "reset=1&jid={$job_id}&qid={$queue_id}&h={$hash}&confirm=1"
100 );
101 $this->assign('confirmURL', $confirmURL);
102 // push context for further process CRM-4431
103 $session = CRM_Core_Session::singleton();
104 $session->pushUserContext($confirmURL);
105 }
106
107 return parent::run();
108 }
109
110 }