INFRA-132 - CRM/Member - Convert single-line @param to multi-line
[civicrm-core.git] / CRM / PCP / Form / PCP.php
CommitLineData
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 */
39class 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
78
79 $session = CRM_Core_Session::singleton();
80 $context = $session->popUserContext();
81 $userID = $session->get('userID');
82
83 //do not allow destructive actions without permissions
84 $permission = FALSE;
85 if (CRM_Core_Permission::check('administer CiviCRM') ||
86 ($userID && (CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP',
87 $this->_id,
88 'contact_id'
89 ) == $userID))
90 ) {
91 $permission = TRUE;
92 }
93 if ($permission && $this->_id) {
94
95 $this->_title = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $this->_id, 'title');
96 switch ($this->_action) {
97 case CRM_Core_Action::DELETE:
98 case 'delete':
99 CRM_PCP_BAO_PCP::deleteById($this->_id);
100 CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been deleted.", array(1 => $this->_title)), ts('Page Deleted'), 'success');
101 break;
102
103 case CRM_Core_Action::DISABLE:
104 case 'disable':
105 CRM_PCP_BAO_PCP::setDisable($this->_id, '0');
106 CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been disabled.", array(1 => $this->_title)), ts('Page Disabled'), 'success');
107 break;
108
109 case CRM_Core_Action::ENABLE:
110 case 'enable':
111 CRM_PCP_BAO_PCP::setDisable($this->_id, '1');
112 CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been enabled.", array(1 => $this->_title)), ts('Page Enabled'), 'success');
113 break;
114 }
115
116 if ($context) {
117 CRM_Utils_System::redirect($context);
118 }
119 }
120 }
121
122 /**
c490a46a 123 * Set default values for the form. Note that in edit/view mode
6a488035
TO
124 * the default values are retrieved from the database
125 *
126 * @param null
127 *
128 * @return array 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
TO
169 $contribPages = array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage();
170 $eventPages = array('' => ts('- select -')) + CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
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' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
181 'isDefault' => TRUE,
182 ),
183 )
184 );
185 parent::buildQuickForm();
186 }
187 }
188
189 /**
100fef9d 190 * Global validation rules for the form
6a488035
TO
191 *
192 * @param array $fields posted values of the form
193 *
da6b46f4 194 * @param $files
c490a46a 195 * @param CRM_Core_Form $form
da6b46f4 196 *
6a488035
TO
197 * @return array list of errors to be posted back to the form
198 * @static
6a488035 199 */
00be9182 200 public static function formRule($fields, $files, $form) {}
6a488035
TO
201
202 /**
203 * Process the form
204 *
205 * @param null
206 *
207 * @return void
6a488035
TO
208 */
209 public function postProcess() {
210 if ($this->_action & CRM_Core_Action::DELETE) {
211 CRM_PCP_BAO_PCP::deleteById($this->_id);
212 CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been deleted.", array(1 => $this->_title)), ts('Page Deleted'), 'success');
213 }
214 else {
215 $params = $this->controller->exportValues($this->_name);
216 $parent = $this->controller->getParent();
217
218 if (!empty($params)) {
219 $fields = array('status_id', 'page_id');
220 foreach ($fields as $field) {
221 if (isset($params[$field]) &&
222 !CRM_Utils_System::isNull($params[$field])
223 ) {
224 $parent->set($field, $params[$field]);
225 }
226 else {
227 $parent->set($field, NULL);
228 }
229 }
230 }
231 }
232 }
233}