Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-07-07-15-48-59
[civicrm-core.git] / CRM / Mailing / Page / Common.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06b69b18 4 | CiviCRM version 4.5 |
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 */
35class CRM_Mailing_Page_Common extends CRM_Core_Page {
36 protected $_type = NULL;
37
e0ef6999
EM
38 /**
39 * @return string
40 * @throws Exception
41 */
6a488035
TO
42 function run() {
43 $job_id = CRM_Utils_Request::retrieve('jid', 'Integer', CRM_Core_DAO::$_nullObject);
44 $queue_id = CRM_Utils_Request::retrieve('qid', 'Integer', CRM_Core_DAO::$_nullObject);
45 $hash = CRM_Utils_Request::retrieve('h', 'String', CRM_Core_DAO::$_nullObject);
46
47 if (!$job_id ||
48 !$queue_id ||
49 !$hash
50 ) {
51 CRM_Core_Error::fatal(ts("Missing input parameters"));
52 }
53
54
55 // verify that the three numbers above match
56 $q = CRM_Mailing_Event_BAO_Queue::verify($job_id, $queue_id, $hash);
57 if (!$q) {
58 CRM_Core_Error::fatal(ts("There was an error in your request"));
59 }
60
61 $cancel = CRM_Utils_Request::retrieve("_qf_{$this->_type}_cancel", 'String', CRM_Core_DAO::$_nullObject,
62 FALSE, NULL, $_REQUEST
63 );
64 if ($cancel) {
65 $config = CRM_Core_Config::singleton();
66 CRM_Utils_System::redirect($config->userFrameworkBaseURL);
67 }
68
69 $confirm = CRM_Utils_Request::retrieve('confirm', 'Boolean', CRM_Core_DAO::$_nullObject,
70 FALSE, NULL, $_REQUEST
71 );
72
73 list($displayName, $email) = CRM_Mailing_Event_BAO_Queue::getContactInfo($queue_id);
74 $this->assign('display_name', $displayName);
75 $this->assign('email', $email);
76 $this->assign('confirm', $confirm);
77
78 $groups = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_mailing($job_id, $queue_id, $hash, TRUE);
79 $this->assign('groups', $groups);
80 $groupExist = NULL;
81 foreach ($groups as $key => $value) {
82 if ($value) {
83 $groupExist = TRUE;
84 }
85 }
86 $this->assign('groupExist', $groupExist);
87
88 if ($confirm) {
89 if ($this->_type == 'unsubscribe') {
90 $groups = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_mailing($job_id, $queue_id, $hash);
91 if (count($groups)) {
92 CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue_id, $groups, FALSE, $job_id);
93 }
94 else {
95 // should we indicate an error, or just ignore?
96 }
97 }
98 elseif ($this->_type == 'resubscribe') {
99 $groups = CRM_Mailing_Event_BAO_Resubscribe::resub_to_mailing($job_id, $queue_id, $hash);
100 if (count($groups)) {
101 CRM_Mailing_Event_BAO_Resubscribe::send_resub_response($queue_id, $groups, FALSE, $job_id);
102 }
103 else {
104 // should we indicate an error, or just ignore?
105 }
106 }
107 else {
108 if (CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_domain($job_id, $queue_id, $hash)) {
109 CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue_id, NULL, TRUE, $job_id);
110 }
111 else {
112 // should we indicate an error, or just ignore?
113 }
114 }
115 }
116 else {
117 $confirmURL = CRM_Utils_System::url("civicrm/mailing/{$this->_type}",
118 "reset=1&jid={$job_id}&qid={$queue_id}&h={$hash}&confirm=1"
119 );
120 $this->assign('confirmURL', $confirmURL);
121 //push context for further process CRM-4431
122 $session = CRM_Core_Session::singleton();
123 $session->pushUserContext($confirmURL);
124 }
125
126 return parent::run();
127 }
128}
129