3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
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 * This class generates form components for Location Type
40 class CRM_Admin_Form_LocationType
extends CRM_Admin_Form
{
43 * Function to build the form
48 public function buildQuickForm() {
50 parent
::buildQuickForm();
52 if ($this->_action
& CRM_Core_Action
::DELETE
) {
56 $this->applyFilter('__ALL__', 'trim');
60 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_LocationType', 'name'),
63 $this->addRule('name',
64 ts('Name already exists in Database.'),
66 array('CRM_Core_DAO_LocationType', $this->_id
)
68 $this->addRule('name',
69 ts('Name can only consist of alpha-numeric characters'),
73 $this->add('text', 'display_name', ts('Display Name'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_LocationType', 'display_name'));
74 $this->add('text', 'vcard_name', ts('vCard Name'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_LocationType', 'vcard_name'));
76 $this->add('text', 'description', ts('Description'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_LocationType', 'description'));
78 $this->add('checkbox', 'is_active', ts('Enabled?'));
79 $this->add('checkbox', 'is_default', ts('Default?'));
80 if ($this->_action
== CRM_Core_Action
::UPDATE
&& CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_LocationType', $this->_id
, 'is_reserved')) {
81 $this->freeze(array('name', 'description', 'is_active'));
86 * Function to process the form
92 public function postProcess() {
93 CRM_Utils_System
::flushCache('CRM_Core_DAO_LocationType');
95 if ($this->_action
& CRM_Core_Action
::DELETE
) {
96 CRM_Core_BAO_LocationType
::del($this->_id
);
97 CRM_Core_Session
::setStatus(ts('Selected Location type has been deleted.'), ts('Record Deleted'), 'success');
101 // store the submitted values in an array
102 $params = $this->exportValues();
103 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
104 $params['is_default'] = CRM_Utils_Array
::value('is_default', $params, FALSE);
106 // action is taken depending upon the mode
107 $locationType = new CRM_Core_DAO_LocationType();
108 $locationType->name
= $params['name'];
109 $locationType->display_name
= $params['display_name'];
110 $locationType->vcard_name
= $params['vcard_name'];
111 $locationType->description
= $params['description'];
112 $locationType->is_active
= $params['is_active'];
113 $locationType->is_default
= $params['is_default'];
115 if ($params['is_default']) {
116 $query = "UPDATE civicrm_location_type SET is_default = 0";
117 CRM_Core_DAO
::executeQuery($query, CRM_Core_DAO
::$_nullArray);
120 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
121 $locationType->id
= $this->_id
;
124 $locationType->save();
126 CRM_Core_Session
::setStatus(ts("The location type '%1' has been saved.",
127 array(1 => $locationType->name
)
128 ), ts('Saved'), 'success');