Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright (C) 2011 Marty Wright | | |
7 | | Licensed to CiviCRM under the Academic Free License version 3.0. | | |
8 | +--------------------------------------------------------------------+ | |
9 | | This file is a part of CiviCRM. | | |
10 | | | | |
11 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
12 | | under the terms of the GNU Affero General Public License | | |
13 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
14 | | | | |
15 | | CiviCRM is distributed in the hope that it will be useful, but | | |
16 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
17 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
18 | | See the GNU Affero General Public License for more details. | | |
19 | | | | |
20 | | You should have received a copy of the GNU Affero General Public | | |
21 | | License and the CiviCRM Licensing Exception along | | |
22 | | with this program; if not, contact CiviCRM LLC | | |
23 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
24 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
25 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
26 | +--------------------------------------------------------------------+ | |
27 | */ | |
28 | ||
29 | /** | |
30 | * | |
31 | * @package CRM | |
32 | * @copyright CiviCRM LLC (c) 2004-2013 | |
33 | * $Id$ | |
34 | * | |
35 | */ | |
36 | ||
37 | /** | |
38 | * This class generates form components for Label Format Settings | |
39 | * | |
40 | */ | |
41 | class CRM_Admin_Form_LabelFormats extends CRM_Admin_Form { | |
42 | ||
43 | /** | |
44 | * Label Format ID | |
45 | */ | |
46 | protected $_id = NULL; | |
47 | ||
48 | /** | |
49 | * Function to build the form | |
50 | * | |
51 | * @return None | |
52 | * @access public | |
53 | */ | |
54 | public function buildQuickForm() { | |
55 | parent::buildQuickForm(); | |
56 | ||
57 | if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::COPY)) { | |
58 | $formatName = CRM_Core_BAO_LabelFormat::getFieldValue('CRM_Core_BAO_LabelFormat', $this->_id, 'label'); | |
59 | $this->assign('formatName', $formatName); | |
60 | return; | |
61 | } | |
62 | ||
63 | $disabled = array(); | |
64 | $required = TRUE; | |
65 | $is_reserved = $this->_id ? CRM_Core_BAO_LabelFormat::getFieldValue('CRM_Core_BAO_LabelFormat', $this->_id, 'is_reserved') : FALSE; | |
66 | if ($is_reserved) { | |
67 | $disabled['disabled'] = 'disabled'; | |
68 | $required = FALSE; | |
69 | } | |
70 | ||
71 | $attributes = CRM_Core_DAO::getAttribute('CRM_Core_BAO_LabelFormat'); | |
72 | $this->add('text', 'label', ts('Name'), $attributes['label'] + $disabled, $required); | |
73 | $this->add('text', 'description', ts('Description'), array('size' => CRM_Utils_Type::HUGE)); | |
74 | $this->add('checkbox', 'is_default', ts('Is this Label Format the default?')); | |
75 | $this->add('select', 'paper_size', ts('Sheet Size'), | |
76 | array( | |
77 | 0 => ts('- default -')) + CRM_Core_BAO_PaperSize::getList(TRUE), FALSE, | |
78 | array( | |
79 | 'onChange' => "selectPaper( this.value );") + $disabled | |
80 | ); | |
81 | $this->add('static', 'paper_dimensions', NULL, ts('Sheet Size (w x h)')); | |
82 | $this->add('select', 'orientation', ts('Orientation'), CRM_Core_BAO_LabelFormat::getPageOrientations(), FALSE, | |
83 | array( | |
84 | 'onChange' => "updatePaperDimensions();") + $disabled | |
85 | ); | |
86 | $this->add('select', 'font_name', ts('Font Name'), CRM_Core_BAO_LabelFormat::getFontNames()); | |
87 | $this->add('select', 'font_size', ts('Font Size'), CRM_Core_BAO_LabelFormat::getFontSizes()); | |
88 | $this->add('static', 'font_style', ts('Font Style')); | |
89 | $this->add('checkbox', 'bold', ts('Bold')); | |
90 | $this->add('checkbox', 'italic', ts('Italic')); | |
91 | $this->add('select', 'metric', ts('Unit of Measure'), CRM_Core_BAO_LabelFormat::getUnits(), FALSE, | |
92 | array('onChange' => "selectMetric( this.value );") | |
93 | ); | |
94 | $this->add('text', 'width', ts('Label Width'), array('size' => 8, 'maxlength' => 8) + $disabled, $required); | |
95 | $this->add('text', 'height', ts('Label Height'), array('size' => 8, 'maxlength' => 8) + $disabled, $required); | |
96 | $this->add('text', 'NX', ts('Labels Per Row'), array('size' => 3, 'maxlength' => 3) + $disabled, $required); | |
97 | $this->add('text', 'NY', ts('Labels Per Column'), array('size' => 3, 'maxlength' => 3) + $disabled, $required); | |
98 | $this->add('text', 'tMargin', ts('Top Margin'), array('size' => 8, 'maxlength' => 8) + $disabled, $required); | |
99 | $this->add('text', 'lMargin', ts('Left Margin'), array('size' => 8, 'maxlength' => 8) + $disabled, $required); | |
100 | $this->add('text', 'SpaceX', ts('Horizontal Spacing'), array('size' => 8, 'maxlength' => 8) + $disabled, $required); | |
101 | $this->add('text', 'SpaceY', ts('Vertical Spacing'), array('size' => 8, 'maxlength' => 8) + $disabled, $required); | |
102 | $this->add('text', 'lPadding', ts('Left Padding'), array('size' => 8, 'maxlength' => 8), $required); | |
103 | $this->add('text', 'tPadding', ts('Top Padding'), array('size' => 8, 'maxlength' => 8), $required); | |
104 | $this->add('text', 'weight', ts('Weight'), CRM_Core_DAO::getAttribute('CRM_Core_BAO_LabelFormat', 'weight'), TRUE); | |
105 | ||
106 | $this->addRule('label', ts('Name already exists in Database.'), 'objectExists', array('CRM_Core_BAO_LabelFormat', $this->_id)); | |
107 | $this->addRule('NX', ts('Must be an integer'), 'integer'); | |
108 | $this->addRule('NY', ts('Must be an integer'), 'integer'); | |
109 | $this->addRule('tMargin', ts('Must be numeric'), 'numeric'); | |
110 | $this->addRule('lMargin', ts('Must be numeric'), 'numeric'); | |
111 | $this->addRule('SpaceX', ts('Must be numeric'), 'numeric'); | |
112 | $this->addRule('SpaceY', ts('Must be numeric'), 'numeric'); | |
113 | $this->addRule('lPadding', ts('Must be numeric'), 'numeric'); | |
114 | $this->addRule('tPadding', ts('Must be numeric'), 'numeric'); | |
115 | $this->addRule('width', ts('Must be numeric'), 'numeric'); | |
116 | $this->addRule('height', ts('Must be numeric'), 'numeric'); | |
117 | $this->addRule('weight', ts('Weight must be integer'), 'integer'); | |
118 | } | |
119 | ||
120 | function setDefaultValues() { | |
121 | if ($this->_action & CRM_Core_Action::ADD) { | |
122 | $defaults['weight'] = CRM_Utils_Array::value('weight', CRM_Core_BAO_LabelFormat::getDefaultValues(), 0); | |
123 | } | |
124 | else { | |
125 | $defaults = $this->_values; | |
126 | // Convert field names that are illegal PHP/SMARTY variable names | |
127 | $defaults['paper_size'] = $defaults['paper-size']; | |
128 | unset($defaults['paper-size']); | |
129 | $defaults['font_name'] = $defaults['font-name']; | |
130 | unset($defaults['font-name']); | |
131 | $defaults['font_size'] = $defaults['font-size']; | |
132 | unset($defaults['font-size']); | |
133 | ||
134 | $defaults['bold'] = (stripos($defaults['font-style'], 'B') !== FALSE); | |
135 | $defaults['italic'] = (stripos($defaults['font-style'], 'I') !== FALSE); | |
136 | unset($defaults['font-style']); | |
137 | } | |
138 | return $defaults; | |
139 | } | |
140 | ||
141 | /** | |
142 | * Function to process the form | |
143 | * | |
144 | * @access public | |
145 | * | |
146 | * @return None | |
147 | */ | |
148 | public function postProcess() { | |
149 | if ($this->_action & CRM_Core_Action::DELETE) { | |
150 | // delete Label Format | |
151 | CRM_Core_BAO_LabelFormat::del($this->_id); | |
152 | CRM_Core_Session::setStatus(ts('Selected Label Format has been deleted.'), ts('Record Deleted'), 'success'); | |
153 | return; | |
154 | } | |
155 | if ($this->_action & CRM_Core_Action::COPY) { | |
156 | // make a copy of the Label Format | |
157 | $labelFormat = CRM_Core_BAO_LabelFormat::getById($this->_id); | |
158 | $list = CRM_Core_BAO_LabelFormat::getList(TRUE); | |
159 | $count = 1; | |
160 | $prefix = ts('Copy of '); | |
161 | while (in_array($prefix . $labelFormat['label'], $list)) { | |
162 | $prefix = ts('Copy') . ' (' . ++$count . ') ' . ts('of '); | |
163 | } | |
164 | $labelFormat['label'] = $prefix . $labelFormat['label']; | |
165 | $labelFormat['grouping'] = CRM_Core_BAO_LabelFormat::customGroupName(); | |
166 | $labelFormat['is_default'] = 0; | |
167 | $labelFormat['is_reserved'] = 0; | |
168 | $bao = new CRM_Core_BAO_LabelFormat(); | |
169 | $bao->saveLabelFormat($labelFormat); | |
170 | CRM_Core_Session::setStatus($labelFormat['label'] . ts(' has been created.'), ts('Saved'), 'success'); | |
171 | return; | |
172 | } | |
173 | ||
174 | $values = $this->controller->exportValues($this->getName()); | |
175 | $values['is_default'] = isset($values['is_default']); | |
176 | ||
177 | // Restore field names that were converted because they are illegal PHP/SMARTY variable names | |
178 | if (isset($values['paper_size'])) { | |
179 | $values['paper-size'] = $values['paper_size']; | |
180 | unset($values['paper_size']); | |
181 | } | |
182 | if (isset($values['font_name'])) { | |
183 | $values['font-name'] = $values['font_name']; | |
184 | unset($values['font_name']); | |
185 | } | |
186 | if (isset($values['font_size'])) { | |
187 | $values['font-size'] = $values['font_size']; | |
188 | unset($values['font_size']); | |
189 | } | |
190 | ||
191 | $style = ''; | |
192 | if (isset($values['bold'])) { | |
193 | $style .= 'B'; | |
194 | } | |
195 | if (isset($values['italic'])) { | |
196 | $style .= 'I'; | |
197 | } | |
198 | $values['font-style'] = $style; | |
199 | ||
200 | $bao = new CRM_Core_BAO_LabelFormat(); | |
201 | $bao->saveLabelFormat($values, $this->_id); | |
202 | ||
203 | $status = ts('Your new Label Format titled <strong>%1</strong> has been saved.', array(1 => $values['label'])); | |
204 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
205 | $status = ts('Your Label Format titled <strong>%1</strong> has been updated.', array(1 => $values['label'])); | |
206 | } | |
207 | CRM_Core_Session::setStatus($status, ts('Saved'), 'success'); | |
208 | } | |
209 | } |