Commit | Line | Data |
---|---|---|
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 | */ | |
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 | /** | |
100fef9d | 44 | * Set variables up before form is built |
6a488035 TO |
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)) { | |
0499b0ad | 55 | CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); |
6a488035 TO |
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 | /** | |
c490a46a | 124 | * Set default values for the form. Note that in edit/view mode |
6a488035 TO |
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 | /** | |
c490a46a | 142 | * Build the form object |
6a488035 TO |
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 | ||
2158332a CW |
166 | $status = array('' => ts('- select -')) + CRM_Core_OptionGroup::values("pcp_status"); |
167 | $types = array( | |
168 | '' => ts('- select -'), | |
169 | 'contribute' => ts('Contribution'), | |
170 | 'event' => ts('Event'), | |
171 | ); | |
6a488035 TO |
172 | $contribPages = array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage(); |
173 | $eventPages = array('' => ts('- select -')) + CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )"); | |
174 | ||
175 | $this->addElement('select', 'status_id', ts('Status'), $status); | |
176 | $this->addElement('select', 'page_type', ts('Source Type'), $types); | |
177 | $this->addElement('select', 'page_id', ts('Contribution Page'), $contribPages); | |
178 | $this->addElement('select', 'event_id', ts('Event Page'), $eventPages); | |
179 | $this->addButtons(array( | |
180 | array( | |
181 | 'type' => 'refresh', | |
182 | 'name' => ts('Search'), | |
183 | 'spacing' => ' ', | |
184 | 'isDefault' => TRUE, | |
185 | ), | |
186 | ) | |
187 | ); | |
188 | parent::buildQuickForm(); | |
189 | } | |
190 | } | |
191 | ||
192 | /** | |
100fef9d | 193 | * Global validation rules for the form |
6a488035 TO |
194 | * |
195 | * @param array $fields posted values of the form | |
196 | * | |
da6b46f4 | 197 | * @param $files |
c490a46a | 198 | * @param CRM_Core_Form $form |
da6b46f4 | 199 | * |
6a488035 TO |
200 | * @return array list of errors to be posted back to the form |
201 | * @static | |
202 | * @access public | |
203 | */ | |
204 | static function formRule($fields, $files, $form) {} | |
205 | ||
206 | /** | |
207 | * Process the form | |
208 | * | |
209 | * @param null | |
210 | * | |
211 | * @return void | |
212 | * @access public | |
213 | */ | |
214 | public function postProcess() { | |
215 | if ($this->_action & CRM_Core_Action::DELETE) { | |
216 | CRM_PCP_BAO_PCP::deleteById($this->_id); | |
217 | CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been deleted.", array(1 => $this->_title)), ts('Page Deleted'), 'success'); | |
218 | } | |
219 | else { | |
220 | $params = $this->controller->exportValues($this->_name); | |
221 | $parent = $this->controller->getParent(); | |
222 | ||
223 | if (!empty($params)) { | |
224 | $fields = array('status_id', 'page_id'); | |
225 | foreach ($fields as $field) { | |
226 | if (isset($params[$field]) && | |
227 | !CRM_Utils_System::isNull($params[$field]) | |
228 | ) { | |
229 | $parent->set($field, $params[$field]); | |
230 | } | |
231 | else { | |
232 | $parent->set($field, NULL); | |
233 | } | |
234 | } | |
235 | } | |
236 | } | |
237 | } | |
238 | } | |
239 |