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 * This class generates form components for Option Group
40 class CRM_Campaign_Form_SurveyType
extends CRM_Admin_Form
{
44 * The option group name
66 * Set variables up before form is built
72 function preProcess() {
73 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this);
75 if ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::DELETE
)) {
76 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
77 $this->assign('id', $this->_id
);
79 $this->assign('action', $this->_action
);
80 $this->assign('id', $this->_id
);
82 $this->_BAOName
= 'CRM_Core_BAO_OptionValue';
83 $this->_gName
= 'activity_type';
84 $this->_gid
= CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gName
, 'id', 'name');
86 $session = CRM_Core_Session
::singleton();
87 $url = CRM_Utils_System
::url('civicrm/admin/campaign/surveyType', 'reset=1');
88 $session->pushUserContext($url);
90 if ($this->_id
&& in_array($this->_gName
, CRM_Core_OptionGroup
::$_domainIDGroups)) {
91 $domainID = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id
, 'domain_id', 'id');
92 if (CRM_Core_Config
::domainID() != $domainID) {
93 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
99 * Set default values for the form.
100 * the default values are retrieved from the database.
104 * @return array array of default values
106 public function setDefaultValues() {
107 $defaults = parent
::setDefaultValues();
109 if (!isset($defaults['weight']) ||
!$defaults['weight']) {
110 $fieldValues = array('option_group_id' => $this->_gid
);
111 $defaults['weight'] = CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues);
118 * Build the form object
122 public function buildQuickForm() {
123 parent
::buildQuickForm();
124 if ($this->_action
& CRM_Core_Action
::DELETE
) {
128 $this->applyFilter('__ALL__', 'trim');
129 $this->add('text', 'label', ts('Title'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_OptionValue', 'label'), TRUE);
131 $this->addWysiwyg('description',
133 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_OptionValue', 'description')
136 $this->add('checkbox', 'is_active', ts('Enabled?'));
138 if ($this->_action
== CRM_Core_Action
::UPDATE
&&
139 CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_id
, 'is_reserved')
141 $this->freeze(array('label', 'is_active'));
143 $this->add('text', 'weight', ts('Order'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_OptionValue', 'weight'), TRUE);
145 $this->assign('id', $this->_id
);
149 * Process the form submission
154 public function postProcess() {
156 if ($this->_action
& CRM_Core_Action
::DELETE
) {
157 $fieldValues = array('option_group_id' => $this->_gid
);
158 $wt = CRM_Utils_Weight
::delWeight('CRM_Core_DAO_OptionValue', $this->_id
, $fieldValues);
160 if (CRM_Core_BAO_OptionValue
::del($this->_id
)) {
161 CRM_Core_Session
::setStatus(ts('Selected Survey type has been deleted.'), ts('Record Deleted'), 'success');
165 $params = $ids = array();
166 $params = $this->exportValues();
168 // set db value of filter in params if filter is non editable
169 if ($this->_id
&& !array_key_exists('filter', $params)) {
170 $params['filter'] = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id
, 'filter', 'id');
173 $groupParams = array('name' => ($this->_gName
));
174 $params['component_id'] = CRM_Core_Component
::getComponentID('CiviCampaign');
175 $optionValue = CRM_Core_OptionValue
::addOptionValue($params, $groupParams, $this->_action
, $this->_id
);
177 CRM_Core_Session
::setStatus(ts('The Survey type \'%1\' has been saved.', array(1 => $optionValue->label
)), ts('Saved'), 'success');