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