Quick Search:

View

Revision:

Diff

Diff from 434 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/oscommerce/includes/classes/payment.php

Annotated File View

hpdl
1
1 <?php
2 /*
hpdl
143
3   $Id: payment.php 434 2006-02-15 20:49:45Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
404
8   Copyright (c) 2006 osCommerce
hpdl
1
9
10   Released under the GNU General Public License
11 */
12
hpdl
421
13   class osC_Payment {
hpdl
434
14     var $selected_module;
hpdl
1
15
hpdl
434
16     var $_modules = array(),
17         $_group = 'payment';
hpdl
432
18
hpdl
1
19 // class constructor
hpdl
421
20     function osC_Payment($module = '') {
hpdl
431
21       global $osC_Database, $osC_Language;
hpdl
377
22
hpdl
431
23       $Qmodules = $osC_Database->query('select code from :table_templates_boxes where modules_group = "payment"');
24       $Qmodules->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
25       $Qmodules->setCache('modules-payment');
26       $Qmodules->execute();
hpdl
1
27
hpdl
431
28       while ($Qmodules->next()) {
hpdl
434
29         $this->_modules[] = $Qmodules->value('code');
hpdl
431
30       }
hpdl
1
31
hpdl
431
32       $Qmodules->freeResult();
hpdl
1
33
hpdl
434
34       if (empty($this->_modules) === false) {
35         if ((empty($module) === false) && in_array($module, $this->_modules)) {
36           $this->_modules = array($module);
hpdl
431
37           $this->selected_module = 'osC_Payment_' . $module;
hpdl
1
38         }
39
hpdl
404
40         $osC_Language->load('modules-payment');
41
hpdl
434
42         foreach ($this->_modules as $modules) {
hpdl
431
43           include('includes/modules/payment/' . $modules . '.' . substr(basename(__FILE__), (strrpos(basename(__FILE__), '.')+1)));
hpdl
1
44
hpdl
431
45           $module_class = 'osC_Payment_' . $modules;
hpdl
1
46
hpdl
431
47           $GLOBALS[$module_class] = new $module_class();
hpdl
1
48         }
49
hpdl
434
50         usort($this->_modules, array('osC_Payment', '_usortModules'));
hpdl
431
51
hpdl
434
52         if ( (tep_not_null($module)) && (in_array($module, $this->_modules)) && (isset($GLOBALS['osC_Payment_' . $module]->form_action_url)) ) {
hpdl
431
53           $this->form_action_url = $GLOBALS['osC_Payment_' . $module]->form_action_url;
hpdl
1
54         }
55       }
56     }
57
58 // class methods
hpdl
432
59     function getCode() {
60       return $this->_code;
61     }
62
63     function getTitle() {
64       return $this->_title;
65     }
66
67     function getDescription() {
68       return $this->_description;
69     }
70
71     function getStatus() {
72       return $this->_status;
73     }
74
75     function getSortOrder() {
76       return $this->_sort_order;
77     }
78
hpdl
1
79 /* The following method is needed in the checkout_confirmation.php page
80    due to a chicken and egg problem with the payment class and order class.
81    The payment modules needs the order destination data for the dynamic status
82    feature, and the order class needs the payment module title.
83    The following method is a work-around to implementing the method in all
84    payment modules available which would break the modules in the contributions
85    section. This should be looked into again post 2.2.
86 */
87     function update_status() {
hpdl
434
88       if (is_array($this->_modules)) {
hpdl
1
89         if (isset($GLOBALS[$this->selected_module]) && is_object($GLOBALS[$this->selected_module])) {
90           if (method_exists($GLOBALS[$this->selected_module], 'update_status')) {
91             $GLOBALS[$this->selected_module]->update_status();
92           }
93         }
94       }
95     }
96
97     function javascript_validation() {
hpdl
387
98       global $osC_Language;
99
hpdl
1
100       $js = '';
hpdl
434
101       if (is_array($this->_modules)) {
hpdl
241
102         $js = '<script type="text/javascript"><!-- ' . "\n" .
hpdl
1
103               'function check_form() {' . "\n" .
104               '  var error = 0;' . "\n" .
hpdl
387
105               '  var error_message = "' . $osC_Language->get('js_error') . '";' . "\n" .
hpdl
1
106               '  var payment_value = null;' . "\n" .
107               '  if (document.checkout_payment.payment.length) {' . "\n" .
108               '    for (var i=0; i<document.checkout_payment.payment.length; i++) {' . "\n" .
109               '      if (document.checkout_payment.payment[i].checked) {' . "\n" .
110               '        payment_value = document.checkout_payment.payment[i].value;' . "\n" .
111               '      }' . "\n" .
112               '    }' . "\n" .
113               '  } else if (document.checkout_payment.payment.checked) {' . "\n" .
114               '    payment_value = document.checkout_payment.payment.value;' . "\n" .
115               '  } else if (document.checkout_payment.payment.value) {' . "\n" .
116               '    payment_value = document.checkout_payment.payment.value;' . "\n" .
117               '  }' . "\n\n";
118
hpdl
434
119         foreach ($this->_modules as $module) {
hpdl
432
120           if ($GLOBALS['osC_Payment_' . $module]->getStatus() === true) {
hpdl
431
121             $js .= $GLOBALS['osC_Payment_' . $module]->javascript_validation();
hpdl
1
122           }
123         }
124
125         $js .= "\n" . '  if (payment_value == null) {' . "\n" .
hpdl
390
126                '    error_message = error_message + "' . $osC_Language->get('js_no_payment_module_selected') . '\n";' . "\n" .
hpdl
1
127                '    error = 1;' . "\n" .
128                '  }' . "\n\n" .
129                '  if (error == 1) {' . "\n" .
130                '    alert(error_message);' . "\n" .
131                '    return false;' . "\n" .
132                '  } else {' . "\n" .
133                '    return true;' . "\n" .
134                '  }' . "\n" .
135                '}' . "\n" .
136                '//--></script>' . "\n";
137       }
138
139       return $js;
140     }
141
142     function selection() {
143       $selection_array = array();
144
hpdl
434
145       foreach ($this->_modules as $module) {
hpdl
432
146         if ($GLOBALS['osC_Payment_' . $module]->getStatus() === true) {
hpdl
431
147           $selection = $GLOBALS['osC_Payment_' . $module]->selection();
148           if (is_array($selection)) $selection_array[] = $selection;
hpdl
1
149         }
150       }
151
152       return $selection_array;
153     }
154
155     function pre_confirmation_check() {
hpdl
434
156       if (is_array($this->_modules)) {
hpdl
432
157         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) {
hpdl
1
158           $GLOBALS[$this->selected_module]->pre_confirmation_check();
159         }
160       }
161     }
162
163     function confirmation() {
hpdl
434
164       if (is_array($this->_modules)) {
hpdl
432
165         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) {
hpdl
1
166           return $GLOBALS[$this->selected_module]->confirmation();
167         }
168       }
169     }
170
171     function process_button() {
hpdl
434
172       if (is_array($this->_modules)) {
hpdl
432
173         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) {
hpdl
1
174           return $GLOBALS[$this->selected_module]->process_button();
175         }
176       }
177     }
178
179     function before_process() {
hpdl
434
180       if (is_array($this->_modules)) {
hpdl
432
181         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) {
hpdl
1
182           return $GLOBALS[$this->selected_module]->before_process();
183         }
184       }
185     }
186
187     function after_process() {
hpdl
434
188       if (is_array($this->_modules)) {
hpdl
432
189         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) {
hpdl
1
190           return $GLOBALS[$this->selected_module]->after_process();
191         }
192       }
193     }
194
195     function get_error() {
hpdl
434
196       if (is_array($this->_modules)) {
hpdl
432
197         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) {
hpdl
1
198           return $GLOBALS[$this->selected_module]->get_error();
199         }
200       }
201     }
hpdl
431
202
hpdl
434
203     function hasActionURL() {
204       if (is_array($this->_modules)) {
205         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) {
206           if (isset($GLOBALS[$this->selected_module]->form_action_url) && (empty($GLOBALS[$this->selected_module]->form_action_url) === false)) {
207             return true;
208           }
209         }
210       }
211
212       return false;
213     }
214
215     function getActionURL() {
216       return $GLOBALS[$this->selected_module]->form_action_url;
217     }
218
hpdl
431
219     function hasActive() {
220       static $has_active;
221
222       if (isset($has_active) === false) {
223         $has_active = false;
224
hpdl
434
225         foreach ($this->_modules as $module) {
hpdl
432
226           if ($GLOBALS['osC_Payment_' . $module]->getStatus() === true) {
hpdl
431
227             $has_active = true;
228             break;
229           }
230         }
231       }
232
233       return $has_active;
234     }
235
236     function numberOfActive() {
237       static $active;
238
239       if (isset($active) === false) {
240         $active = 0;
241
hpdl
434
242         foreach ($this->_modules as $module) {
hpdl
432
243           if ($GLOBALS['osC_Payment_' . $module]->getStatus() === true) {
hpdl
431
244             $active++;
245           }
246         }
247       }
248
249       return $active;
250     }
251
252     function hasKeys() {
253       static $has_keys;
254
255       if (isset($has_keys) === false) {
256         $has_keys = (sizeof($this->getKeys()) > 0) ? true : false;
257       }
258
259       return $has_keys;
260     }
261
262     function install() {
263       global $osC_Database, $osC_Language;
264
265       $Qinstall = $osC_Database->query('insert into :table_templates_boxes (title, code, author_name, author_www, modules_group) values (:title, :code, :author_name, :author_www, :modules_group)');
266       $Qinstall->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
267       $Qinstall->bindValue(':title', $this->_title);
268       $Qinstall->bindValue(':code', $this->_code);
269       $Qinstall->bindValue(':author_name', $this->_author_name);
270       $Qinstall->bindValue(':author_www', $this->_author_www);
271       $Qinstall->bindValue(':modules_group', $this->_group);
272       $Qinstall->execute();
273
274       foreach ($osC_Language->getAll() as $key => $value) {
275         if (file_exists(dirname(__FILE__) . '/../languages/' . $key . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) {
276           foreach ($osC_Language->extractDefinitions($key . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) {
277             $Qcheck = $osC_Database->query('select id from :table_languages_definitions where definition_key = :definition_key and content_group = :content_group and languages_id = :languages_id limit 1');
278             $Qcheck->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
279             $Qcheck->bindValue(':definition_key', $def['key']);
280             $Qcheck->bindValue(':content_group', $def['group']);
281             $Qcheck->bindInt(':languages_id', $value['id']);
282             $Qcheck->execute();
283
284             if ($Qcheck->numberOfRows() === 1) {
285               $Qdef = $osC_Database->query('update :table_languages_definitions set definition_value = :definition_value where definition_key = :definition_key and content_group = :content_group and languages_id = :languages_id');
286             } else {
287               $Qdef = $osC_Database->query('insert into :table_languages_definitions (languages_id, content_group, definition_key, definition_value) values (:languages_id, :content_group, :definition_key, :definition_value)');
288             }
289             $Qdef->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
290             $Qdef->bindInt(':languages_id', $value['id']);
291             $Qdef->bindValue(':content_group', $def['group']);
292             $Qdef->bindValue(':definition_key', $def['key']);
293             $Qdef->bindValue(':definition_value', $def['value']);
294             $Qdef->execute();
295           }
296         }
297       }
298
299       osC_Cache::clear('languages');
300     }
301
302     function remove() {
303       global $osC_Database, $osC_Language;
304
305       $Qdel = $osC_Database->query('delete from :table_templates_boxes where code = :code and modules_group = :modules_group');
306       $Qdel->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
307       $Qdel->bindValue(':code', $this->_code);
308       $Qdel->bindValue(':modules_group', $this->_group);
309       $Qdel->execute();
310
311       if ($this->hasKeys()) {
312         $Qdel = $osC_Database->query('delete from :table_configuration where configuration_key in (":configuration_key")');
313         $Qdel->bindTable(':table_configuration', TABLE_CONFIGURATION);
314         $Qdel->bindRaw(':configuration_key', implode('", "', $this->getKeys()));
315         $Qdel->execute();
316       }
317
318       if (file_exists(dirname(__FILE__) . '/../languages/' . $osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) {
319         foreach ($osC_Language->extractDefinitions($osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) {
320           $Qdel = $osC_Database->query('delete from :table_languages_definitions where definition_key = :definition_key and content_group = :content_group');
321           $Qdel->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
322           $Qdel->bindValue(':definition_key', $def['key']);
323           $Qdel->bindValue(':content_group', $def['group']);
324           $Qdel->execute();
325         }
326
327         osC_Cache::clear('languages');
328       }
329     }
330
331     function _usortModules($a, $b) {
hpdl
432
332       if ($GLOBALS['osC_Payment_' . $a]->getSortOrder() == $GLOBALS['osC_Payment_' . $b]->getSortOrder()) {
333         return strnatcasecmp($GLOBALS['osC_Payment_' . $a]->getTitle(), $GLOBALS['osC_Payment_' . $a]->getTitle());
hpdl
431
334       }
335
hpdl
432
336       return ($GLOBALS['osC_Payment_' . $a]->getSortOrder() < $GLOBALS['osC_Payment_' . $b]->getSortOrder()) ? -1 : 1;
hpdl
431
337     }
hpdl
1
338   }
339 ?>