commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / CRM / Admin / Form / LocationType.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2015
32 * $Id$
33 *
34 */
35
36 /**
37 * This class generates form components for Location Type
38 *
39 */
40 class CRM_Admin_Form_LocationType extends CRM_Admin_Form {
41
42 /**
43 * Build the form object.
44 *
45 * @return void
46 */
47 public function buildQuickForm() {
48 parent::buildQuickForm();
49 $this->setPageTitle(ts('Location Type'));
50
51 if ($this->_action & CRM_Core_Action::DELETE) {
52 return;
53 }
54
55 $this->applyFilter('__ALL__', 'trim');
56 $this->add('text',
57 'name',
58 ts('Name'),
59 CRM_Core_DAO::getAttribute('CRM_Core_DAO_LocationType', 'name'),
60 TRUE
61 );
62 $this->addRule('name',
63 ts('Name already exists in Database.'),
64 'objectExists',
65 array('CRM_Core_DAO_LocationType', $this->_id)
66 );
67 $this->addRule('name',
68 ts('Name can only consist of alpha-numeric characters'),
69 'variable'
70 );
71
72 $this->add('text', 'display_name', ts('Display Name'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_LocationType', 'display_name'), TRUE);
73 $this->add('text', 'vcard_name', ts('vCard Name'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_LocationType', 'vcard_name'));
74
75 $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_LocationType', 'description'));
76
77 $this->add('checkbox', 'is_active', ts('Enabled?'));
78 $this->add('checkbox', 'is_default', ts('Default?'));
79
80 if ($this->_action & CRM_Core_Action::UPDATE) {
81 if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_LocationType', $this->_id, 'is_reserved')) {
82 $this->freeze(array('name', 'description', 'is_active'));
83 }
84 if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_LocationType', $this->_id, 'is_default')) {
85 $this->freeze(array('is_default'));
86 }
87 }
88 }
89
90 /**
91 * Process the form submission.
92 *
93 *
94 * @return void
95 */
96 public function postProcess() {
97 CRM_Utils_System::flushCache('CRM_Core_DAO_LocationType');
98
99 if ($this->_action & CRM_Core_Action::DELETE) {
100 CRM_Core_BAO_LocationType::del($this->_id);
101 CRM_Core_Session::setStatus(ts('Selected Location type has been deleted.'), ts('Record Deleted'), 'success');
102 return;
103 }
104
105 // store the submitted values in an array
106 $params = $this->exportValues();
107 $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
108 $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
109
110 // action is taken depending upon the mode
111 $locationType = new CRM_Core_DAO_LocationType();
112 $locationType->name = $params['name'];
113 $locationType->display_name = $params['display_name'];
114 $locationType->vcard_name = $params['vcard_name'];
115 $locationType->description = $params['description'];
116 $locationType->is_active = $params['is_active'];
117 $locationType->is_default = $params['is_default'];
118
119 if ($params['is_default']) {
120 $query = "UPDATE civicrm_location_type SET is_default = 0";
121 CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
122 }
123
124 if ($this->_action & CRM_Core_Action::UPDATE) {
125 $locationType->id = $this->_id;
126 }
127
128 $locationType->save();
129
130 CRM_Core_Session::setStatus(ts("The location type '%1' has been saved.",
131 array(1 => $locationType->name)
132 ), ts('Saved'), 'success');
133 }
134
135 }