3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
37 * Administer Personal Campaign Pages - Search form
39 class CRM_PCP_Form_PCP
extends CRM_Core_Form
{
44 * Function to set variables up before form is built
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
)) {
55 CRM_Core_Error
::fatal(ts('You do not have permission to access this page'));
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
);
64 if (!$this->_action
) {
65 $this->_action
= CRM_Utils_Array
::value('action', $_GET);
66 $this->_id
= CRM_Utils_Array
::value('id', $_GET);
69 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
73 if (!isset($this->_context
)) {
74 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this);
77 $this->assign('context', $this->_context
);
80 $session = CRM_Core_Session
::singleton();
81 $context = $session->popUserContext();
82 $userID = $session->get('userID');
84 //do not allow destructive actions without permissions
86 if (CRM_Core_Permission
::check('administer CiviCRM') ||
87 ($userID && (CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP',
94 if ($permission && $this->_id
) {
96 $this->_title
= CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP', $this->_id
, 'title');
97 switch ($this->_action
) {
98 case CRM_Core_Action
::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');
104 case CRM_Core_Action
::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');
110 case CRM_Core_Action
::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');
118 CRM_Utils_System
::redirect($context);
124 * This function sets the default values for the form. Note that in edit/view mode
125 * the default values are retrieved from the database
129 * @return array array of default values
132 function setDefaultValues() {
135 $pageType = CRM_Utils_Request
::retrieve('page_type', 'String', $this);
136 $defaults['page_type'] = !empty($pageType) ?
$pageType : '';
142 * Function to actually build the form
149 public function buildQuickForm() {
150 if ($this->_action
& CRM_Core_Action
::DELETE
) {
151 $this->addButtons(array(
154 'name' => ts('Delete Campaign'),
159 'name' => ts('Cancel'),
166 $status = array('' => ts('- select -')) + CRM_PCP_PseudoConstant
::pcpStatus();
167 $types = array('' => ts('- select -')) + CRM_PCP_PseudoConstant
::pcpType();
168 $contribPages = array('' => ts('- select -')) + CRM_Contribute_PseudoConstant
::contributionPage();
169 $eventPages = array('' => ts('- select -')) + CRM_Event_PseudoConstant
::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
171 $this->addElement('select', 'status_id', ts('Status'), $status);
172 $this->addElement('select', 'page_type', ts('Source Type'), $types);
173 $this->addElement('select', 'page_id', ts('Contribution Page'), $contribPages);
174 $this->addElement('select', 'event_id', ts('Event Page'), $eventPages);
175 $this->addButtons(array(
178 'name' => ts('Search'),
179 'spacing' => ' ',
184 parent
::buildQuickForm();
189 * global validation rules for the form
191 * @param array $fields posted values of the form
193 * @return array list of errors to be posted back to the form
197 static function formRule($fields, $files, $form) {}
207 public function postProcess() {
208 if ($this->_action
& CRM_Core_Action
::DELETE
) {
209 CRM_PCP_BAO_PCP
::deleteById($this->_id
);
210 CRM_Core_Session
::setStatus(ts("The Campaign Page '%1' has been deleted.", array(1 => $this->_title
)), ts('Page Deleted'), 'success');
213 $params = $this->controller
->exportValues($this->_name
);
214 $parent = $this->controller
->getParent();
216 if (!empty($params)) {
217 $fields = array('status_id', 'page_id');
218 foreach ($fields as $field) {
219 if (isset($params[$field]) &&
220 !CRM_Utils_System
::isNull($params[$field])
222 $parent->set($field, $params[$field]);
225 $parent->set($field, NULL);