CRM-16425 Added CiviCRM Licensing Exception in header
[civicrm-core.git] / CRM / Admin / Form / Preferences / Contribute.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2015
32 * $Id$
33 *
34 */
35
36 /**
37 * This class generates form components for the display preferences
38 *
39 */
40 class CRM_Admin_Form_Preferences_Contribute extends CRM_Admin_Form_Preferences {
41 /**
42 * Process the form submission.
43 *
44 *
45 * @return void
46 */
47 public function preProcess() {
48 $config = CRM_Core_Config::singleton();
49 CRM_Utils_System::setTitle(ts('CiviContribute Component Settings'));
50 $this->_varNames = array(
51 CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME => array(
52 'invoice_prefix' => array(
53 'html_type' => 'text',
54 'title' => ts('Invoice Prefix'),
55 'weight' => 1,
56 'description' => ts('Enter prefix to be display on PDF for invoice'),
57 ),
58 'credit_notes_prefix' => array(
59 'html_type' => 'text',
60 'title' => ts('Credit Notes Prefix'),
61 'weight' => 2,
62 'description' => ts('Enter prefix to be display on PDF for credit notes.'),
63 ),
64 'due_date' => array(
65 'html_type' => 'text',
66 'title' => ts('Due Date'),
67 'weight' => 3,
68 ),
69 'due_date_period' => array(
70 'html_type' => 'select',
71 'title' => ts('For transmission'),
72 'weight' => 4,
73 'description' => ts('Select the interval for due date.'),
74 'option_values' => array(
75 'select' => ts('- select -'),
76 'days' => ts('Days'),
77 'months' => ts('Months'),
78 'years' => ts('Years'),
79 ),
80 ),
81 'notes' => array(
82 'html_type' => 'wysiwyg',
83 'title' => ts('Notes or Standard Terms'),
84 'weight' => 5,
85 'description' => ts('Enter note or message to be displayed on PDF invoice or credit notes '),
86 'attributes' => array('rows' => 2, 'cols' => 40),
87 ),
88 'is_email_pdf' => array(
89 'html_type' => 'checkbox',
90 'title' => ts('Automatically email invoice when user purchases online'),
91 'weight' => 6,
92 ),
93 'tax_term' => array(
94 'html_type' => 'text',
95 'title' => ts('Tax Term'),
96 'weight' => 7,
97 ),
98 'tax_display_settings' => array(
99 'html_type' => 'select',
100 'title' => ts('Tax Display Settings'),
101 'weight' => 8,
102 'option_values' => array(
103 'Do_not_show' => ts('Do not show breakdown, only show total -i.e ' .
104 $config->defaultCurrencySymbol . '120.00'),
105 'Inclusive' => ts('Show [tax term] inclusive price - i.e. ' .
106 $config->defaultCurrencySymbol .
107 '120.00 (includes [tax term] of ' .
108 $config->defaultCurrencySymbol . '20.00)'),
109 'Exclusive' => ts('Show [tax term] exclusive price - i.e. ' .
110 $config->defaultCurrencySymbol . '100.00 + ' .
111 $config->defaultCurrencySymbol . '20.00 [tax term]'),
112 ),
113 ),
114 ),
115 );
116 parent::preProcess();
117 }
118
119 /**
120 * Build the form object.
121 *
122 * @return void
123 */
124 public function buildQuickForm() {
125 $this->add('checkbox', 'invoicing', ts('Enable Tax and Invoicing'));
126 parent::buildQuickForm();
127 }
128
129 /**
130 * Set default values for the form.
131 * default values are retrieved from the database
132 *
133 *
134 * @return void
135 */
136 public function setDefaultValues() {
137 $defaults = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
138 return $defaults;
139 }
140
141 /**
142 * Process the form after the input has been submitted and validated.
143 *
144 *
145 * @return void
146 */
147 public function postProcess() {
148 // store the submitted values in an array
149 $params = $this->controller->exportValues($this->_name);
150 unset($params['qfKey']);
151 unset($params['entryURL']);
152 $setInvoiceSettings = CRM_Core_BAO_Setting::setItem($params, CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
153
154 // to set default value for 'Invoices / Credit Notes' checkbox on display preferences
155 $values = CRM_Core_BAO_Setting::getItem("CiviCRM Preferences");
156 $optionValues = CRM_Core_OptionGroup::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name');
157 $setKey = array_search('Invoices / Credit Notes', $optionValues);
158
159 if (isset($params['invoicing'])) {
160 $value = array($setKey => $optionValues[$setKey]);
161 $setInvoice = CRM_Core_DAO::VALUE_SEPARATOR .
162 implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($value)) .
163 CRM_Core_DAO::VALUE_SEPARATOR;
164 CRM_Core_BAO_Setting::setItem($values['user_dashboard_options'] .
165 $setInvoice, 'CiviCRM Preferences', 'user_dashboard_options');
166 }
167 else {
168 $setting = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($values['user_dashboard_options'], 1, -1));
169 $invoiceKey = array_search($setKey, $setting);
170 unset($setting[$invoiceKey]);
171 $settingName = CRM_Core_DAO::VALUE_SEPARATOR .
172 implode(CRM_Core_DAO::VALUE_SEPARATOR, array_values($setting)) .
173 CRM_Core_DAO::VALUE_SEPARATOR;
174 CRM_Core_BAO_Setting::setItem($settingName, 'CiviCRM Preferences', 'user_dashboard_options');
175 }
176 }
177
178 }