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