Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * $Id: PaymentProcessorType.php 9702 2007-05-29 23:57:16Z lobo $ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class generates form components for Location Type | |
38 | * | |
39 | */ | |
40 | class CRM_Admin_Form_PaymentProcessorType extends CRM_Admin_Form { | |
41 | protected $_id = NULL; | |
42 | ||
43 | protected $_fields = NULL; | |
44 | ||
00be9182 | 45 | public function preProcess() { |
6a488035 TO |
46 | parent::preProcess(); |
47 | ||
48 | $this->_fields = array( | |
49 | array( | |
50 | 'name' => 'name', | |
51 | 'label' => ts('Name'), | |
52 | 'required' => TRUE, | |
53 | ), | |
54 | array( | |
55 | 'name' => 'title', | |
56 | 'label' => ts('Title'), | |
57 | 'required' => TRUE, | |
58 | ), | |
59 | array( | |
60 | 'name' => 'billing_mode', | |
61 | 'label' => ts('Billing Mode'), | |
62 | 'required' => TRUE, | |
63 | 'rule' => 'positiveInteger', | |
64 | 'msg' => ts('Enter a positive integer'), | |
65 | ), | |
66 | array( | |
67 | 'name' => 'description', | |
68 | 'label' => ts('Description'), | |
69 | ), | |
70 | array( | |
71 | 'name' => 'user_name_label', | |
72 | 'label' => ts('User Name Label'), | |
73 | ), | |
74 | array( | |
75 | 'name' => 'password_label', | |
76 | 'label' => ts('Password Label'), | |
77 | ), | |
78 | array( | |
79 | 'name' => 'signature_label', | |
80 | 'label' => ts('Signature Label'), | |
81 | ), | |
82 | array( | |
83 | 'name' => 'subject_label', | |
84 | 'label' => ts('Subject Label'), | |
85 | ), | |
86 | array( | |
87 | 'name' => 'class_name', | |
88 | 'label' => ts('PHP class name'), | |
89 | 'required' => TRUE, | |
90 | ), | |
91 | array( | |
92 | 'name' => 'url_site_default', | |
93 | 'label' => ts('Live Site URL'), | |
94 | 'required' => TRUE, | |
95 | 'rule' => 'url', | |
96 | 'msg' => ts('Enter a valid URL'), | |
97 | ), | |
98 | array( | |
99 | 'name' => 'url_api_default', | |
100 | 'label' => ts('Live API URL'), | |
101 | 'required' => FALSE, | |
102 | 'rule' => 'url', | |
103 | 'msg' => ts('Enter a valid URL'), | |
104 | ), | |
105 | array( | |
106 | 'name' => 'url_recur_default', | |
107 | 'label' => ts('Live Recurring Payments URL'), | |
108 | 'required' => TRUE, | |
109 | 'rule' => 'url', | |
110 | 'msg' => ts('Enter a valid URL'), | |
111 | ), | |
112 | array( | |
113 | 'name' => 'url_button_default', | |
114 | 'label' => ts('Live Button URL'), | |
115 | 'rule' => 'url', | |
116 | 'msg' => ts('Enter a valid URL'), | |
117 | ), | |
118 | array( | |
119 | 'name' => 'url_site_test_default', | |
120 | 'label' => ts('Test Site URL'), | |
121 | 'required' => TRUE, | |
122 | 'rule' => 'url', | |
123 | 'msg' => ts('Enter a valid URL'), | |
124 | ), | |
125 | array( | |
126 | 'name' => 'url_api_test_default', | |
127 | 'label' => ts('Test API URL'), | |
128 | 'required' => FALSE, | |
129 | 'rule' => 'url', | |
130 | 'msg' => ts('Enter a valid URL'), | |
131 | ), | |
132 | array( | |
133 | 'name' => 'url_recur_test_default', | |
134 | 'label' => ts('Test Recurring Payments URL'), | |
135 | 'required' => TRUE, | |
136 | 'rule' => 'url', | |
137 | 'msg' => ts('Enter a valid URL'), | |
138 | ), | |
139 | array( | |
140 | 'name' => 'url_button_test_default', | |
141 | 'label' => ts('Test Button URL'), | |
142 | 'rule' => 'url', | |
143 | 'msg' => ts('Enter a valid URL'), | |
144 | ), | |
145 | ); | |
146 | } | |
147 | ||
148 | /** | |
eceb18cc | 149 | * Build the form object. |
6a488035 | 150 | * |
dd244018 EM |
151 | * @param bool $check |
152 | * | |
355ba699 | 153 | * @return void |
6a488035 TO |
154 | */ |
155 | public function buildQuickForm($check = FALSE) { | |
156 | parent::buildQuickForm(); | |
157 | ||
158 | if ($this->_action & CRM_Core_Action::DELETE) { | |
159 | return; | |
160 | } | |
161 | ||
481a74f4 | 162 | $attributes = CRM_Core_DAO::getAttribute('CRM_Financial_DAO_PaymentProcessorType'); |
6a488035 TO |
163 | |
164 | foreach ($this->_fields as $field) { | |
165 | $required = CRM_Utils_Array::value('required', $field, FALSE); | |
166 | $this->add('text', $field['name'], | |
167 | $field['label'], $attributes['name'], $required | |
168 | ); | |
a7488080 | 169 | if (!empty($field['rule'])) { |
6a488035 TO |
170 | $this->addRule($field['name'], $field['msg'], $field['rule']); |
171 | } | |
172 | } | |
173 | ||
174 | // is this processor active ? | |
175 | $this->add('checkbox', 'is_active', ts('Is this Payment Processor Type active?')); | |
176 | $this->add('checkbox', 'is_default', ts('Is this Payment Processor Type the default?')); | |
177 | $this->add('checkbox', 'is_recur', ts('Does this Payment Processor Type support recurring donations?')); | |
178 | } | |
179 | ||
e0ef6999 EM |
180 | /** |
181 | * @return array | |
182 | */ | |
00be9182 | 183 | public function setDefaultValues() { |
6a488035 TO |
184 | $defaults = array(); |
185 | ||
186 | if (!$this->_id) { | |
187 | $defaults['is_active'] = $defaults['is_default'] = 1; | |
188 | $defaults['user_name_label'] = ts('User Name'); | |
189 | $defaults['password_label'] = ts('Password'); | |
190 | $defaults['signature_label'] = ts('Signature'); | |
191 | $defaults['subject_label'] = ts('Subject'); | |
192 | return $defaults; | |
193 | } | |
194 | ||
481a74f4 | 195 | $dao = new CRM_Financial_DAO_PaymentProcessorType(); |
6a488035 TO |
196 | $dao->id = $this->_id; |
197 | ||
198 | if (!$dao->find(TRUE)) { | |
199 | return $defaults; | |
200 | } | |
201 | ||
202 | CRM_Core_DAO::storeValues($dao, $defaults); | |
203 | ||
204 | return $defaults; | |
205 | } | |
206 | ||
207 | /** | |
eceb18cc | 208 | * Process the form submission. |
6a488035 | 209 | * |
6a488035 | 210 | * |
355ba699 | 211 | * @return void |
6a488035 TO |
212 | */ |
213 | public function postProcess() { | |
481a74f4 | 214 | CRM_Utils_System::flushCache('CRM_Financial_DAO_PaymentProcessorType'); |
6a488035 TO |
215 | |
216 | if ($this->_action & CRM_Core_Action::DELETE) { | |
217 | CRM_Financial_BAO_PaymentProcessorType::del($this->_id); | |
218 | return; | |
219 | } | |
220 | ||
221 | $values = $this->controller->exportValues($this->_name); | |
222 | ||
a7488080 | 223 | if (!empty($values['is_default'])) { |
6a488035 TO |
224 | $query = " |
225 | UPDATE civicrm_payment_processor SET is_default = 0"; | |
226 | CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); | |
227 | } | |
228 | ||
481a74f4 | 229 | $dao = new CRM_Financial_DAO_PaymentProcessorType(); |
6a488035 | 230 | |
353ffa53 | 231 | $dao->id = $this->_id; |
6a488035 | 232 | $dao->is_default = CRM_Utils_Array::value('is_default', $values, 0); |
353ffa53 TO |
233 | $dao->is_active = CRM_Utils_Array::value('is_active', $values, 0); |
234 | $dao->is_recur = CRM_Utils_Array::value('is_recur', $values, 0); | |
6a488035 TO |
235 | |
236 | $dao->name = $values['name']; | |
237 | $dao->description = $values['description']; | |
238 | ||
239 | foreach ($this->_fields as $field) { | |
240 | $dao->{$field['name']} = trim($values[$field['name']]); | |
241 | if (empty($dao->{$field['name']})) { | |
242 | $dao->{$field['name']} = 'null'; | |
243 | } | |
244 | } | |
245 | $dao->save(); | |
246 | } | |
96025800 | 247 | |
6a488035 | 248 | } |