Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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-2013 | |
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 | ||
45 | function preProcess() { | |
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 | /** | |
149 | * Function to build the form | |
150 | * | |
151 | * @return None | |
152 | * @access public | |
153 | */ | |
154 | public function buildQuickForm($check = FALSE) { | |
155 | parent::buildQuickForm(); | |
156 | ||
157 | if ($this->_action & CRM_Core_Action::DELETE) { | |
158 | return; | |
159 | } | |
160 | ||
161 | $attributes = CRM_Core_DAO::getAttribute( 'CRM_Financial_DAO_PaymentProcessorType' ); | |
162 | ||
163 | foreach ($this->_fields as $field) { | |
164 | $required = CRM_Utils_Array::value('required', $field, FALSE); | |
165 | $this->add('text', $field['name'], | |
166 | $field['label'], $attributes['name'], $required | |
167 | ); | |
168 | if (CRM_Utils_Array::value('rule', $field)) { | |
169 | $this->addRule($field['name'], $field['msg'], $field['rule']); | |
170 | } | |
171 | } | |
172 | ||
173 | // is this processor active ? | |
174 | $this->add('checkbox', 'is_active', ts('Is this Payment Processor Type active?')); | |
175 | $this->add('checkbox', 'is_default', ts('Is this Payment Processor Type the default?')); | |
176 | $this->add('checkbox', 'is_recur', ts('Does this Payment Processor Type support recurring donations?')); | |
177 | } | |
178 | ||
179 | function setDefaultValues() { | |
180 | $defaults = array(); | |
181 | ||
182 | if (!$this->_id) { | |
183 | $defaults['is_active'] = $defaults['is_default'] = 1; | |
184 | $defaults['user_name_label'] = ts('User Name'); | |
185 | $defaults['password_label'] = ts('Password'); | |
186 | $defaults['signature_label'] = ts('Signature'); | |
187 | $defaults['subject_label'] = ts('Subject'); | |
188 | return $defaults; | |
189 | } | |
190 | ||
191 | $dao = new CRM_Financial_DAO_PaymentProcessorType( ); | |
192 | $dao->id = $this->_id; | |
193 | ||
194 | if (!$dao->find(TRUE)) { | |
195 | return $defaults; | |
196 | } | |
197 | ||
198 | CRM_Core_DAO::storeValues($dao, $defaults); | |
199 | ||
200 | return $defaults; | |
201 | } | |
202 | ||
203 | /** | |
204 | * Function to process the form | |
205 | * | |
206 | * @access public | |
207 | * | |
208 | * @return None | |
209 | */ | |
210 | public function postProcess() { | |
211 | CRM_Utils_System::flushCache( 'CRM_Financial_DAO_PaymentProcessorType' ); | |
212 | ||
213 | if ($this->_action & CRM_Core_Action::DELETE) { | |
214 | CRM_Financial_BAO_PaymentProcessorType::del($this->_id); | |
215 | return; | |
216 | } | |
217 | ||
218 | $values = $this->controller->exportValues($this->_name); | |
219 | ||
220 | if (CRM_Utils_Array::value('is_default', $values)) { | |
221 | $query = " | |
222 | UPDATE civicrm_payment_processor SET is_default = 0"; | |
223 | CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); | |
224 | } | |
225 | ||
226 | $dao = new CRM_Financial_DAO_PaymentProcessorType( ); | |
227 | ||
228 | $dao->id = $this->_id; | |
229 | $dao->is_default = CRM_Utils_Array::value('is_default', $values, 0); | |
230 | $dao->is_active = CRM_Utils_Array::value('is_active', $values, 0); | |
231 | $dao->is_recur = CRM_Utils_Array::value('is_recur', $values, 0); | |
232 | ||
233 | $dao->name = $values['name']; | |
234 | $dao->description = $values['description']; | |
235 | ||
236 | foreach ($this->_fields as $field) { | |
237 | $dao->{$field['name']} = trim($values[$field['name']]); | |
238 | if (empty($dao->{$field['name']})) { | |
239 | $dao->{$field['name']} = 'null'; | |
240 | } | |
241 | } | |
242 | $dao->save(); | |
243 | } | |
244 | } | |
245 |