3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * Administer Personal Campaign Pages - Search form
39 class CRM_PCP_Form_PCP
extends CRM_Core_Form
{
44 * Set variables up before form is built
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
)) {
54 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
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
);
63 if (!$this->_action
) {
64 $this->_action
= CRM_Utils_Array
::value('action', $_GET);
65 $this->_id
= CRM_Utils_Array
::value('id', $_GET);
68 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
72 if (!isset($this->_context
)) {
73 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this);
76 $this->assign('context', $this->_context
);
78 $session = CRM_Core_Session
::singleton();
79 $context = $session->popUserContext();
80 $userID = $session->get('userID');
82 //do not allow destructive actions without permissions
84 if (CRM_Core_Permission
::check('administer CiviCRM') ||
85 ($userID && (CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP',
92 if ($permission && $this->_id
) {
94 $this->_title
= CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP', $this->_id
, 'title');
95 switch ($this->_action
) {
96 case CRM_Core_Action
::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');
102 case CRM_Core_Action
::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');
108 case CRM_Core_Action
::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');
116 CRM_Utils_System
::redirect($context);
122 * Set default values for the form. Note that in edit/view mode
123 * the default values are retrieved from the database
128 * array of default values
130 public function setDefaultValues() {
133 $pageType = CRM_Utils_Request
::retrieve('page_type', 'String', $this);
134 $defaults['page_type'] = !empty($pageType) ?
$pageType : '';
140 * Build the form object
146 public function buildQuickForm() {
147 if ($this->_action
& CRM_Core_Action
::DELETE
) {
148 $this->addButtons(array(
151 'name' => ts('Delete Campaign'),
156 'name' => ts('Cancel'),
163 $status = array('' => ts('- select -')) + CRM_Core_OptionGroup
::values("pcp_status");
165 '' => ts('- select -'),
166 'contribute' => ts('Contribution'),
167 'event' => ts('Event'),
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 )");
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(
179 'name' => ts('Search'),
180 'spacing' => ' ',
185 parent
::buildQuickForm();
190 * Global validation rules for the form
192 * @param array $fields
193 * Posted values of the form.
196 * @param CRM_Core_Form $form
199 * list of errors to be posted back to the form
202 public static function formRule($fields, $files, $form) {
212 public function postProcess() {
213 if ($this->_action
& CRM_Core_Action
::DELETE
) {
214 CRM_PCP_BAO_PCP
::deleteById($this->_id
);
215 CRM_Core_Session
::setStatus(ts("The Campaign Page '%1' has been deleted.", array(1 => $this->_title
)), ts('Page Deleted'), 'success');
218 $params = $this->controller
->exportValues($this->_name
);
219 $parent = $this->controller
->getParent();
221 if (!empty($params)) {
222 $fields = array('status_id', 'page_id');
223 foreach ($fields as $field) {
224 if (isset($params[$field]) &&
225 !CRM_Utils_System
::isNull($params[$field])
227 $parent->set($field, $params[$field]);
230 $parent->set($field, NULL);