Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 27 | */ |
6a488035 TO |
28 | |
29 | /** | |
30 | * | |
31 | * @package CRM | |
ca5cec67 | 32 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
33 | */ |
34 | ||
35 | /** | |
ce064e4f | 36 | * This class generates form components for PDF Page Format Settings. |
6a488035 TO |
37 | */ |
38 | class CRM_Admin_Form_PdfFormats extends CRM_Admin_Form { | |
39 | ||
40 | /** | |
eceb18cc | 41 | * PDF Page Format ID. |
62d3ee27 | 42 | * @var int |
6a488035 | 43 | */ |
e57fc8ca | 44 | public $_id = NULL; |
6a488035 | 45 | |
88aae6d4 A |
46 | /** |
47 | * @var bool | |
48 | */ | |
49 | public $submitOnce = TRUE; | |
50 | ||
6a488035 | 51 | /** |
eceb18cc | 52 | * Build the form object. |
6a488035 TO |
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); | |
be2fb01f | 65 | $this->add('text', 'description', ts('Description'), ['size' => CRM_Utils_Type::HUGE]); |
6a488035 TO |
66 | $this->add('checkbox', 'is_default', ts('Is this PDF Page Format the default?')); |
67 | ||
68 | $this->add('select', 'paper_size', ts('Paper Size'), | |
be2fb01f | 69 | [ |
317fceb4 | 70 | 0 => ts('- default -'), |
be2fb01f CW |
71 | ] + CRM_Core_BAO_PaperSize::getList(TRUE), FALSE, |
72 | ['onChange' => "selectPaper( this.value );"] | |
6a488035 TO |
73 | ); |
74 | ||
4367e964 | 75 | $this->add('static', 'paper_dimensions', ts('Width x Height')); |
6a488035 | 76 | $this->add('select', 'orientation', ts('Orientation'), CRM_Core_BAO_PdfFormat::getPageOrientations(), FALSE, |
be2fb01f | 77 | ['onChange' => "updatePaperDimensions();"] |
6a488035 TO |
78 | ); |
79 | $this->add('select', 'metric', ts('Unit of Measure'), CRM_Core_BAO_PdfFormat::getUnits(), FALSE, | |
be2fb01f | 80 | ['onChange' => "selectMetric( this.value );"] |
6a488035 | 81 | ); |
be2fb01f CW |
82 | $this->add('text', 'margin_left', ts('Left Margin'), ['size' => 8, 'maxlength' => 8], TRUE); |
83 | $this->add('text', 'margin_right', ts('Right Margin'), ['size' => 8, 'maxlength' => 8], TRUE); | |
84 | $this->add('text', 'margin_top', ts('Top Margin'), ['size' => 8, 'maxlength' => 8], TRUE); | |
85 | $this->add('text', 'margin_bottom', ts('Bottom Margin'), ['size' => 8, 'maxlength' => 8], TRUE); | |
f20d2b0d | 86 | $this->add('number', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_BAO_PdfFormat', 'weight'), TRUE); |
6a488035 | 87 | |
be2fb01f | 88 | $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', [ |
0d48f1cc TO |
89 | 'CRM_Core_BAO_PdfFormat', |
90 | $this->_id, | |
91 | ]); | |
6a488035 TO |
92 | $this->addRule('margin_left', ts('Margin must be numeric'), 'numeric'); |
93 | $this->addRule('margin_right', ts('Margin must be numeric'), 'numeric'); | |
94 | $this->addRule('margin_top', ts('Margin must be numeric'), 'numeric'); | |
95 | $this->addRule('margin_bottom', ts('Margin must be numeric'), 'numeric'); | |
96 | $this->addRule('weight', ts('Weight must be integer'), 'integer'); | |
97 | } | |
98 | ||
e0ef6999 EM |
99 | /** |
100 | * @return int | |
101 | */ | |
00be9182 | 102 | public function setDefaultValues() { |
6a488035 TO |
103 | if ($this->_action & CRM_Core_Action::ADD) { |
104 | $defaults['weight'] = CRM_Utils_Array::value('weight', CRM_Core_BAO_PdfFormat::getDefaultValues(), 0); | |
105 | } | |
106 | else { | |
107 | $defaults = $this->_values; | |
108 | } | |
109 | return $defaults; | |
110 | } | |
111 | ||
112 | /** | |
eceb18cc | 113 | * Process the form submission. |
6a488035 TO |
114 | */ |
115 | public function postProcess() { | |
116 | if ($this->_action & CRM_Core_Action::DELETE) { | |
117 | // delete PDF Page Format | |
118 | CRM_Core_BAO_PdfFormat::del($this->_id); | |
119 | CRM_Core_Session::setStatus(ts('Selected PDF Page Format has been deleted.'), ts('Record Deleted'), 'success'); | |
120 | return; | |
121 | } | |
122 | ||
123 | $values = $this->controller->exportValues($this->getName()); | |
124 | $values['is_default'] = isset($values['is_default']); | |
125 | $bao = new CRM_Core_BAO_PdfFormat(); | |
126 | $bao->savePdfFormat($values, $this->_id); | |
127 | ||
903546e6 | 128 | $status = ts('Your new PDF Page Format titled <strong>%1</strong> has been saved.', [1 => $values['name']]); |
6a488035 | 129 | if ($this->_action & CRM_Core_Action::UPDATE) { |
903546e6 | 130 | $status = ts('Your PDF Page Format titled <strong>%1</strong> has been updated.', [1 => $values['name']]); |
6a488035 | 131 | } |
903546e6 | 132 | CRM_Core_Session::setStatus($status, ts('Saved'), 'success'); |
6a488035 | 133 | } |
96025800 | 134 | |
6a488035 | 135 | } |