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