Update Copywrite year to be 2019
[civicrm-core.git] / CRM / Admin / Form / PdfFormats.php
CommitLineData
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
6b83d5bd 32 * @copyright CiviCRM LLC (c) 2004-2019
6a488035
TO
33 */
34
35/**
ce064e4f 36 * This class generates form components for PDF Page Format Settings.
6a488035
TO
37 */
38class CRM_Admin_Form_PdfFormats extends CRM_Admin_Form {
39
40 /**
eceb18cc 41 * PDF Page Format ID.
6a488035
TO
42 */
43 protected $_id = NULL;
44
45 /**
eceb18cc 46 * Build the form object.
6a488035
TO
47 */
48 public function buildQuickForm() {
49 parent::buildQuickForm();
50
51 if ($this->_action & CRM_Core_Action::DELETE) {
52 $formatName = CRM_Core_BAO_PdfFormat::getFieldValue('CRM_Core_BAO_PdfFormat', $this->_id, 'name');
53 $this->assign('formatName', $formatName);
54 return;
55 }
56
57 $attributes = CRM_Core_DAO::getAttribute('CRM_Core_BAO_PdfFormat');
58 $this->add('text', 'name', ts('Name'), $attributes['name'], TRUE);
59 $this->add('text', 'description', ts('Description'), array('size' => CRM_Utils_Type::HUGE));
60 $this->add('checkbox', 'is_default', ts('Is this PDF Page Format the default?'));
61
62 $this->add('select', 'paper_size', ts('Paper Size'),
63 array(
317fceb4 64 0 => ts('- default -'),
353ffa53 65 ) + CRM_Core_BAO_PaperSize::getList(TRUE), FALSE,
6a488035
TO
66 array('onChange' => "selectPaper( this.value );")
67 );
68
69 $this->add('static', 'paper_dimensions', NULL, ts('Width x Height'));
70 $this->add('select', 'orientation', ts('Orientation'), CRM_Core_BAO_PdfFormat::getPageOrientations(), FALSE,
71 array('onChange' => "updatePaperDimensions();")
72 );
73 $this->add('select', 'metric', ts('Unit of Measure'), CRM_Core_BAO_PdfFormat::getUnits(), FALSE,
74 array('onChange' => "selectMetric( this.value );")
75 );
76 $this->add('text', 'margin_left', ts('Left Margin'), array('size' => 8, 'maxlength' => 8), TRUE);
77 $this->add('text', 'margin_right', ts('Right Margin'), array('size' => 8, 'maxlength' => 8), TRUE);
78 $this->add('text', 'margin_top', ts('Top Margin'), array('size' => 8, 'maxlength' => 8), TRUE);
79 $this->add('text', 'margin_bottom', ts('Bottom Margin'), array('size' => 8, 'maxlength' => 8), TRUE);
7ecddde4 80 $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_BAO_PdfFormat', 'weight'), TRUE);
6a488035 81
353ffa53
TO
82 $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array(
83 'CRM_Core_BAO_PdfFormat',
317fceb4 84 $this->_id,
353ffa53 85 ));
6a488035
TO
86 $this->addRule('margin_left', ts('Margin must be numeric'), 'numeric');
87 $this->addRule('margin_right', ts('Margin must be numeric'), 'numeric');
88 $this->addRule('margin_top', ts('Margin must be numeric'), 'numeric');
89 $this->addRule('margin_bottom', ts('Margin must be numeric'), 'numeric');
90 $this->addRule('weight', ts('Weight must be integer'), 'integer');
91 }
92
e0ef6999
EM
93 /**
94 * @return int
95 */
00be9182 96 public function setDefaultValues() {
6a488035
TO
97 if ($this->_action & CRM_Core_Action::ADD) {
98 $defaults['weight'] = CRM_Utils_Array::value('weight', CRM_Core_BAO_PdfFormat::getDefaultValues(), 0);
99 }
100 else {
101 $defaults = $this->_values;
102 }
103 return $defaults;
104 }
105
106 /**
eceb18cc 107 * Process the form submission.
6a488035
TO
108 */
109 public function postProcess() {
110 if ($this->_action & CRM_Core_Action::DELETE) {
111 // delete PDF Page Format
112 CRM_Core_BAO_PdfFormat::del($this->_id);
113 CRM_Core_Session::setStatus(ts('Selected PDF Page Format has been deleted.'), ts('Record Deleted'), 'success');
114 return;
115 }
116
117 $values = $this->controller->exportValues($this->getName());
118 $values['is_default'] = isset($values['is_default']);
119 $bao = new CRM_Core_BAO_PdfFormat();
120 $bao->savePdfFormat($values, $this->_id);
121
122 $status = ts('Your new PDF Page Format titled <strong>%1</strong> has been saved.', array(1 => $values['name']), ts('Saved'), 'success');
123 if ($this->_action & CRM_Core_Action::UPDATE) {
124 $status = ts('Your PDF Page Format titled <strong>%1</strong> has been updated.', array(1 => $values['name']), ts('Saved'), 'success');
125 }
126 CRM_Core_Session::setStatus($status);
127 }
96025800 128
6a488035 129}