Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
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 | ||
36 | /** | |
37 | * Administer Personal Campaign Pages - Search form | |
38 | */ | |
39 | class CRM_PCP_Form_PCP extends CRM_Core_Form { | |
40 | ||
41 | public $_context; | |
42 | ||
43 | /** | |
44 | * Function to set variables up before form is built | |
45 | * | |
46 | * @param null | |
47 | * | |
48 | * @return void | |
49 | * @access public | |
50 | */ | |
51 | public function preProcess() { | |
52 | if ($this->_action & CRM_Core_Action::DELETE) { | |
53 | //check permission for action. | |
54 | if (!CRM_Core_Permission::checkActionPermission('CiviEvent', $this->_action)) { | |
55 | CRM_Core_Error::fatal(ts('You do not have permission to access this page')); | |
56 | } | |
57 | ||
58 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); | |
59 | $this->_title = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $this->_id, 'title'); | |
60 | $this->assign('title', $this->_title); | |
61 | parent::preProcess(); | |
62 | } | |
63 | ||
64 | if (!$this->_action) { | |
65 | $this->_action = CRM_Utils_Array::value('action', $_GET); | |
66 | $this->_id = CRM_Utils_Array::value('id', $_GET); | |
67 | } | |
68 | else { | |
69 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); | |
70 | } | |
71 | ||
72 | //give the context. | |
73 | if (!isset($this->_context)) { | |
74 | $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); | |
75 | } | |
76 | ||
77 | $this->assign('context', $this->_context); | |
78 | ||
79 | ||
80 | $session = CRM_Core_Session::singleton(); | |
81 | $context = $session->popUserContext(); | |
82 | $userID = $session->get('userID'); | |
83 | ||
84 | //do not allow destructive actions without permissions | |
85 | $permission = FALSE; | |
86 | if (CRM_Core_Permission::check('administer CiviCRM') || | |
87 | ($userID && (CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', | |
88 | $this->_id, | |
89 | 'contact_id' | |
90 | ) == $userID)) | |
91 | ) { | |
92 | $permission = TRUE; | |
93 | } | |
94 | if ($permission && $this->_id) { | |
95 | ||
96 | $this->_title = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $this->_id, 'title'); | |
97 | switch ($this->_action) { | |
98 | case CRM_Core_Action::DELETE: | |
99 | case 'delete': | |
100 | CRM_PCP_BAO_PCP::deleteById($this->_id); | |
101 | CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been deleted.", array(1 => $this->_title)), ts('Page Deleted'), 'success'); | |
102 | break; | |
103 | ||
104 | case CRM_Core_Action::DISABLE: | |
105 | case 'disable': | |
106 | CRM_PCP_BAO_PCP::setDisable($this->_id, '0'); | |
107 | CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been disabled.", array(1 => $this->_title)), ts('Page Disabled'), 'success'); | |
108 | break; | |
109 | ||
110 | case CRM_Core_Action::ENABLE: | |
111 | case 'enable': | |
112 | CRM_PCP_BAO_PCP::setDisable($this->_id, '1'); | |
113 | CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been enabled.", array(1 => $this->_title)), ts('Page Enabled'), 'success'); | |
114 | break; | |
115 | } | |
116 | ||
117 | if ($context) { | |
118 | CRM_Utils_System::redirect($context); | |
119 | } | |
120 | } | |
121 | } | |
122 | ||
123 | /** | |
124 | * This function sets the default values for the form. Note that in edit/view mode | |
125 | * the default values are retrieved from the database | |
126 | * | |
127 | * @param null | |
128 | * | |
129 | * @return array array of default values | |
130 | * @access public | |
131 | */ | |
132 | function setDefaultValues() { | |
133 | $defaults = array(); | |
134 | ||
135 | $pageType = CRM_Utils_Request::retrieve('page_type', 'String', $this); | |
136 | $defaults['page_type'] = !empty($pageType) ? $pageType : ''; | |
137 | ||
138 | return $defaults; | |
139 | } | |
140 | ||
141 | /** | |
142 | * Function to actually build the form | |
143 | * | |
144 | * @param null | |
145 | * | |
146 | * @return void | |
147 | * @access public | |
148 | */ | |
149 | public function buildQuickForm() { | |
150 | if ($this->_action & CRM_Core_Action::DELETE) { | |
151 | $this->addButtons(array( | |
152 | array( | |
153 | 'type' => 'next', | |
154 | 'name' => ts('Delete Campaign'), | |
155 | 'isDefault' => TRUE, | |
156 | ), | |
157 | array( | |
158 | 'type' => 'cancel', | |
159 | 'name' => ts('Cancel'), | |
160 | ), | |
161 | ) | |
162 | ); | |
163 | } | |
164 | else { | |
165 | ||
166 | $status = array('' => ts('- select -')) + CRM_PCP_PseudoConstant::pcpStatus(); | |
167 | $types = array('' => ts('- select -')) + CRM_PCP_PseudoConstant::pcpType(); | |
168 | $contribPages = array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage(); | |
169 | $eventPages = array('' => ts('- select -')) + CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )"); | |
170 | ||
171 | $this->addElement('select', 'status_id', ts('Status'), $status); | |
172 | $this->addElement('select', 'page_type', ts('Source Type'), $types); | |
173 | $this->addElement('select', 'page_id', ts('Contribution Page'), $contribPages); | |
174 | $this->addElement('select', 'event_id', ts('Event Page'), $eventPages); | |
175 | $this->addButtons(array( | |
176 | array( | |
177 | 'type' => 'refresh', | |
178 | 'name' => ts('Search'), | |
179 | 'spacing' => ' ', | |
180 | 'isDefault' => TRUE, | |
181 | ), | |
182 | ) | |
183 | ); | |
184 | parent::buildQuickForm(); | |
185 | } | |
186 | } | |
187 | ||
188 | /** | |
189 | * global validation rules for the form | |
190 | * | |
191 | * @param array $fields posted values of the form | |
192 | * | |
193 | * @return array list of errors to be posted back to the form | |
194 | * @static | |
195 | * @access public | |
196 | */ | |
197 | static function formRule($fields, $files, $form) {} | |
198 | ||
199 | /** | |
200 | * Process the form | |
201 | * | |
202 | * @param null | |
203 | * | |
204 | * @return void | |
205 | * @access public | |
206 | */ | |
207 | public function postProcess() { | |
208 | if ($this->_action & CRM_Core_Action::DELETE) { | |
209 | CRM_PCP_BAO_PCP::deleteById($this->_id); | |
210 | CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been deleted.", array(1 => $this->_title)), ts('Page Deleted'), 'success'); | |
211 | } | |
212 | else { | |
213 | $params = $this->controller->exportValues($this->_name); | |
214 | $parent = $this->controller->getParent(); | |
215 | ||
216 | if (!empty($params)) { | |
217 | $fields = array('status_id', 'page_id'); | |
218 | foreach ($fields as $field) { | |
219 | if (isset($params[$field]) && | |
220 | !CRM_Utils_System::isNull($params[$field]) | |
221 | ) { | |
222 | $parent->set($field, $params[$field]); | |
223 | } | |
224 | else { | |
225 | $parent->set($field, NULL); | |
226 | } | |
227 | } | |
228 | } | |
229 | } | |
230 | } | |
231 | } | |
232 |