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