Whitespace fixes (from jshint)
[civicrm-core.git] / CRM / Admin / Form / PreferencesDate.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
32 * $Id$
33 *
34 */
35
36 /**
37 * This class generates form components for Location Type
38 *
39 */
40 class CRM_Admin_Form_PreferencesDate extends CRM_Admin_Form {
41
42 /**
43 * Function to build the form
44 *
45 * @return None
46 * @access public
47 */
48 public function buildQuickForm() {
49
50 parent::buildQuickForm();
51
52 if ($this->_action & CRM_Core_Action::DELETE) {
53 return;
54 }
55
56 $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_PreferencesDate');
57
58 $this->applyFilter('__ALL__', 'trim');
59 $name = &$this->add('text',
60 'name',
61 ts('Name'),
62 $attributes['name'],
63 TRUE
64 );
65 $name->freeze();
66
67 $this->add('text', 'description', ts('Description'), $attributes['description'], FALSE);
68 $this->add('text', 'start', ts('Start Offset'), $attributes['start'], TRUE);
69 $this->add('text', 'end', ts('End Offset'), $attributes['end'], TRUE);
70
71 $formatType = CRM_Core_Dao::getFieldValue('CRM_Core_DAO_PreferencesDate', $this->_id, 'name');
72
73 if ($formatType == 'creditCard') {
74 $this->add('text', 'date_format', ts('Format'), $attributes['date_format'], TRUE);
75 }
76 else {
77 $this->add('select', 'date_format', ts('Format'),
78 array('' => ts('- default input format -')) + CRM_Core_SelectValues::getDatePluginInputFormats()
79 );
80 $this->add('select', 'time_format', ts('Time'),
81 array('' => ts('- none -')) + CRM_Core_SelectValues::getTimeFormats()
82 );
83 }
84 $this->addRule('start', ts('Value must be an integer.'), 'integer');
85 $this->addRule('end', ts('Value must be an integer.'), 'integer');
86
87 // add a form rule
88 $this->addFormRule(array('CRM_Admin_Form_PreferencesDate', 'formRule'));
89 }
90
91 /**
92 * global validation rules for the form
93 *
94 * @param array $fields (referance) posted values of the form
95 *
96 * @return array if errors then list of errors to be posted back to the form,
97 * true otherwise
98 * @static
99 * @access public
100 */
101 static function formRule($fields) {
102 $errors = array();
103
104 if ($fields['name'] == 'activityDateTime' && !$fields['time_format']) {
105 $errors['time_format'] = ts('Time is required for this format.');
106 }
107
108 return empty($errors) ? TRUE : $errors;
109 }
110
111 /**
112 * Function to process the form
113 *
114 * @access public
115 *
116 * @return None
117 */
118 public function postProcess() {
119 if (!($this->_action & CRM_Core_Action::UPDATE)) {
120 CRM_Core_Session::setStatus(ts('Preferences Date Options can only be updated'), ts('Sorry'), 'error');
121 return;
122 }
123
124 // store the submitted values in an array
125 $params = $this->controller->exportValues($this->_name);
126
127 // action is taken depending upon the mode
128 $dao = new CRM_Core_DAO_PreferencesDate();
129 $dao->id = $this->_id;
130 $dao->description = $params['description'];
131 $dao->start = $params['start'];
132 $dao->end = $params['end'];
133 $dao->date_format = $params['date_format'];
134 $dao->time_format = $params['time_format'];
135
136 $dao->save();
137
138 CRM_Core_Session::setStatus(ts("The date type '%1' has been saved.",
139 array(1 => $params['name'])
140 ), ts('Saved'), 'success');
141 }
142 }