Quick Search:

View

Revision:

Diff

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