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
127 * @return array array of default values
129 public function setDefaultValues() {
132 $pageType = CRM_Utils_Request
::retrieve('page_type', 'String', $this);
133 $defaults['page_type'] = !empty($pageType) ?
$pageType : '';
139 * Build the form object
145 public function buildQuickForm() {
146 if ($this->_action
& CRM_Core_Action
::DELETE
) {
147 $this->addButtons(array(
150 'name' => ts('Delete Campaign'),
155 'name' => ts('Cancel'),
162 $status = array('' => ts('- select -')) + CRM_Core_OptionGroup
::values("pcp_status");
164 '' => ts('- select -'),
165 'contribute' => ts('Contribution'),
166 'event' => ts('Event'),
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
192 * Posted values of the form.
195 * @param CRM_Core_Form $form
197 * @return array list of errors to be posted back to the form
200 public static function formRule($fields, $files, $form) {
210 public function postProcess() {
211 if ($this->_action
& CRM_Core_Action
::DELETE
) {
212 CRM_PCP_BAO_PCP
::deleteById($this->_id
);
213 CRM_Core_Session
::setStatus(ts("The Campaign Page '%1' has been deleted.", array(1 => $this->_title
)), ts('Page Deleted'), 'success');
216 $params = $this->controller
->exportValues($this->_name
);
217 $parent = $this->controller
->getParent();
219 if (!empty($params)) {
220 $fields = array('status_id', 'page_id');
221 foreach ($fields as $field) {
222 if (isset($params[$field]) &&
223 !CRM_Utils_System
::isNull($params[$field])
225 $parent->set($field, $params[$field]);
228 $parent->set($field, NULL);