Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
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 PDF Page Format Settings | |
39 | * | |
40 | */ | |
41 | class CRM_Admin_Form_PdfFormats extends CRM_Admin_Form { | |
42 | ||
43 | /** | |
44 | * PDF Page Format ID | |
45 | */ | |
46 | protected $_id = NULL; | |
47 | ||
48 | /** | |
49 | * Function to build the form | |
50 | * | |
355ba699 | 51 | * @return void |
6a488035 TO |
52 | * @access public |
53 | */ | |
54 | public function buildQuickForm() { | |
55 | parent::buildQuickForm(); | |
56 | ||
57 | if ($this->_action & CRM_Core_Action::DELETE) { | |
58 | $formatName = CRM_Core_BAO_PdfFormat::getFieldValue('CRM_Core_BAO_PdfFormat', $this->_id, 'name'); | |
59 | $this->assign('formatName', $formatName); | |
60 | return; | |
61 | } | |
62 | ||
63 | $attributes = CRM_Core_DAO::getAttribute('CRM_Core_BAO_PdfFormat'); | |
64 | $this->add('text', 'name', ts('Name'), $attributes['name'], TRUE); | |
65 | $this->add('text', 'description', ts('Description'), array('size' => CRM_Utils_Type::HUGE)); | |
66 | $this->add('checkbox', 'is_default', ts('Is this PDF Page Format the default?')); | |
67 | ||
68 | $this->add('select', 'paper_size', ts('Paper Size'), | |
69 | array( | |
70 | 0 => ts('- default -')) + CRM_Core_BAO_PaperSize::getList(TRUE), FALSE, | |
71 | array('onChange' => "selectPaper( this.value );") | |
72 | ); | |
73 | ||
74 | $this->add('static', 'paper_dimensions', NULL, ts('Width x Height')); | |
75 | $this->add('select', 'orientation', ts('Orientation'), CRM_Core_BAO_PdfFormat::getPageOrientations(), FALSE, | |
76 | array('onChange' => "updatePaperDimensions();") | |
77 | ); | |
78 | $this->add('select', 'metric', ts('Unit of Measure'), CRM_Core_BAO_PdfFormat::getUnits(), FALSE, | |
79 | array('onChange' => "selectMetric( this.value );") | |
80 | ); | |
81 | $this->add('text', 'margin_left', ts('Left Margin'), array('size' => 8, 'maxlength' => 8), TRUE); | |
82 | $this->add('text', 'margin_right', ts('Right Margin'), array('size' => 8, 'maxlength' => 8), TRUE); | |
83 | $this->add('text', 'margin_top', ts('Top Margin'), array('size' => 8, 'maxlength' => 8), TRUE); | |
84 | $this->add('text', 'margin_bottom', ts('Bottom Margin'), array('size' => 8, 'maxlength' => 8), TRUE); | |
85 | $this->add('text', 'weight', ts('Weight'), CRM_Core_DAO::getAttribute('CRM_Core_BAO_PdfFormat', 'weight'), TRUE); | |
86 | ||
87 | $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array('CRM_Core_BAO_PdfFormat', $this->_id)); | |
88 | $this->addRule('margin_left', ts('Margin must be numeric'), 'numeric'); | |
89 | $this->addRule('margin_right', ts('Margin must be numeric'), 'numeric'); | |
90 | $this->addRule('margin_top', ts('Margin must be numeric'), 'numeric'); | |
91 | $this->addRule('margin_bottom', ts('Margin must be numeric'), 'numeric'); | |
92 | $this->addRule('weight', ts('Weight must be integer'), 'integer'); | |
93 | } | |
94 | ||
95 | function setDefaultValues() { | |
96 | if ($this->_action & CRM_Core_Action::ADD) { | |
97 | $defaults['weight'] = CRM_Utils_Array::value('weight', CRM_Core_BAO_PdfFormat::getDefaultValues(), 0); | |
98 | } | |
99 | else { | |
100 | $defaults = $this->_values; | |
101 | } | |
102 | return $defaults; | |
103 | } | |
104 | ||
105 | /** | |
106 | * Function to process the form | |
107 | * | |
108 | * @access public | |
109 | * | |
355ba699 | 110 | * @return void |
6a488035 TO |
111 | */ |
112 | public function postProcess() { | |
113 | if ($this->_action & CRM_Core_Action::DELETE) { | |
114 | // delete PDF Page Format | |
115 | CRM_Core_BAO_PdfFormat::del($this->_id); | |
116 | CRM_Core_Session::setStatus(ts('Selected PDF Page Format has been deleted.'), ts('Record Deleted'), 'success'); | |
117 | return; | |
118 | } | |
119 | ||
120 | $values = $this->controller->exportValues($this->getName()); | |
121 | $values['is_default'] = isset($values['is_default']); | |
122 | $bao = new CRM_Core_BAO_PdfFormat(); | |
123 | $bao->savePdfFormat($values, $this->_id); | |
124 | ||
125 | $status = ts('Your new PDF Page Format titled <strong>%1</strong> has been saved.', array(1 => $values['name']), ts('Saved'), 'success'); | |
126 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
127 | $status = ts('Your PDF Page Format titled <strong>%1</strong> has been updated.', array(1 => $values['name']), ts('Saved'), 'success'); | |
128 | } | |
129 | CRM_Core_Session::setStatus($status); | |
130 | } | |
131 | } |