aa5005b2f2baef812c22f1774b8044ae6927d68d
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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 name badge layout
40 class CRM_Badge_Form_Layout
extends CRM_Admin_Form
{
43 * Function to build the form
48 public function buildQuickForm() {
49 parent
::buildQuickForm();
51 if ($this->_action
& CRM_Core_Action
::DELETE
) {
55 $config = CRM_Core_Config
::singleton();
56 $resources = CRM_Core_Resources
::singleton();
57 $resources->addSetting(
59 'kcfinderPath' => $config->userFrameworkResourceURL
.'packages' .DIRECTORY_SEPARATOR
62 $resources->addScriptFile('civicrm', 'templates/CRM/Badge/Form/Layout.js');
64 $this->applyFilter('__ALL__', 'trim');
66 $this->add('text', 'title', ts('Title'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_PrintLabel', 'title'), true);
68 $labelStyle = CRM_Core_BAO_LabelFormat
::getList(TRUE, 'name_badge');
69 $this->add('select', 'label_format_name', ts('Label Style'), array('' => ts('- select -')) +
$labelStyle, TRUE);
71 $this->add('text', 'description', ts('Description'),
72 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_PrintLabel', 'title'));
75 $contactTokens = CRM_Core_SelectValues
::contactTokens();
76 $eventTokens = CRM_Core_SelectValues
::eventTokens();
77 $tokens = array_merge($contactTokens, $eventTokens);
80 $fontSizes = CRM_Core_BAO_LabelFormat
::getFontSizes();
81 $fontNames = CRM_Core_BAO_LabelFormat
::getFontNames('name_badge');
82 $textAlignment = CRM_Core_BAO_LabelFormat
::getTextAlignments();
85 for ( $i =1; $i <= $rowCount; $i++
) {
86 $this->add('select', "token[$i]", ts('Token'), array('' => ts('- none -')) +
$tokens);
87 $this->add('select', "font_name[$i]", ts('Font Name'), $fontNames);
88 $this->add('select', "font_size[$i]", ts('Font Size'), $fontSizes);
89 $this->add('select', "text_alignment[$i]", ts('Alignment'), $textAlignment);
92 $this->assign('rowCount', $rowCount);
94 $this->add('checkbox', 'add_barcode', ts('Barcode?'));
95 unset($textAlignment['J']);
96 $this->add('select', "barcode_alignment", ts('Alignment'), $textAlignment);
100 'value' => ts('click here and select a file double clicking on it'),
102 $this->add('text', 'image_1', ts('Image 1'), $attributes + CRM_Core_DAO
::getAttribute('CRM_Core_DAO_PrintLabel', 'title'));
103 $this->add('text', 'image_2', ts('Image 2'), $attributes + CRM_Core_DAO
::getAttribute('CRM_Core_DAO_PrintLabel', 'title'));
105 $this->add('checkbox', 'is_default', ts('Default?'));
106 $this->add('checkbox', 'is_active', ts('Enabled?'));
107 $this->add('checkbox', 'is_reserved', ts('Reserved?'));
111 * This function sets the default values for the form. MobileProvider that in edit/view mode
112 * the default values are retrieved from the database
118 function setDefaultValues() {
119 if (isset($this->_id
) && empty($this->_values
)) {
120 $this->_values
= array();
121 $params = array('id' => $this->_id
);
122 CRM_Badge_BAO_Layout
::retrieve($params, $this->_values
);
125 $defaults = array_merge($this->_values
,
126 CRM_Badge_BAO_Layout
::getDecodedData($this->_values
['data']));
129 if ($this->_action
== CRM_Core_Action
::DELETE
&& isset($defaults['title'])) {
130 $this->assign('delName', $defaults['title']);
133 // its ok if there is no element called is_active
134 $defaults['is_active'] = ($this->_id
) ? CRM_Utils_Array
::value('is_active', $defaults) : 1;
140 * Function to process the form
146 public function postProcess() {
147 if ($this->_action
& CRM_Core_Action
::DELETE
) {
148 CRM_Badge_BAO_Layout
::del($this->_id
);
149 CRM_Core_Session
::setStatus(ts('Selected badge layout has been deleted.'), ts('Record Deleted'), 'success');
153 $params = $data = $this->controller
->exportValues($this->_name
);
155 unset($data['qfKey']);
156 $params['data'] = json_encode($data);
159 $params['id'] = $this->_id
;
162 // store the submitted values in an array
163 CRM_Badge_BAO_Layout
::create($params);
165 CRM_Core_Session
::setStatus(ts("The badge layout '%1' has been saved.",
166 array(1 => $params['title'])
167 ), ts('Saved'), 'success');