Quick Search:

View

Revision:

Diff

Diff from 390 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 390 2006-01-20 06:04:32Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
8   Copyright (c) 2003 osCommerce
9
10   Released under the GNU General Public License
11 */
12
13   class payment {
14     var $modules, $selected_module;
15
16 // class constructor
17     function payment($module = '') {
hpdl
377
18       global $osC_Language;
19
hpdl
1
20       if (defined('MODULE_PAYMENT_INSTALLED') && tep_not_null(MODULE_PAYMENT_INSTALLED)) {
21         $this->modules = explode(';', MODULE_PAYMENT_INSTALLED);
22
23         $include_modules = array();
24
25         if ( (tep_not_null($module)) && (in_array($module . '.' . substr($_SERVER['PHP_SELF'], (strrpos($_SERVER['PHP_SELF'], '.')+1)), $this->modules)) ) {
26           $this->selected_module = $module;
27
28           $include_modules[] = array('class' => $module, 'file' => $module . '.php');
29         } else {
30           reset($this->modules);
31           while (list(, $value) = each($this->modules)) {
32             $class = substr($value, 0, strrpos($value, '.'));
33             $include_modules[] = array('class' => $class, 'file' => $value);
34           }
35         }
36
37         for ($i=0, $n=sizeof($include_modules); $i<$n; $i++) {
hpdl
377
38           include('includes/languages/' . $osC_Language->getDirectory() . '/modules/payment/' . $include_modules[$i]['file']);
hpdl
273
39           include('includes/modules/payment/' . $include_modules[$i]['file']);
hpdl
1
40
41           $GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class'];
42         }
43
44 // if there is only one payment method, select it as default because in
45 // checkout_confirmation.php the $payment variable is being assigned the
hpdl
143
46 // $_POST['payment_mod_sel'] value which will be empty (no radio button selection possible)
hpdl
199
47         if ( (tep_count_payment_modules() == 1) && (!isset($GLOBALS[$_SESSION['payment']]) || (isset($GLOBALS[$_SESSION['payment']]) && !is_object($GLOBALS[$_SESSION['payment']]))) ) {
48           $_SESSION['payment'] = $include_modules[0]['class'];
hpdl
1
49         }
50
51         if ( (tep_not_null($module)) && (in_array($module, $this->modules)) && (isset($GLOBALS[$module]->form_action_url)) ) {
52           $this->form_action_url = $GLOBALS[$module]->form_action_url;
53         }
54       }
55     }
56
57 // class methods
58 /* The following method is needed in the checkout_confirmation.php page
59    due to a chicken and egg problem with the payment class and order class.
60    The payment modules needs the order destination data for the dynamic status
61    feature, and the order class needs the payment module title.
62    The following method is a work-around to implementing the method in all
63    payment modules available which would break the modules in the contributions
64    section. This should be looked into again post 2.2.
65 */
66     function update_status() {
67       if (is_array($this->modules)) {
68         if (isset($GLOBALS[$this->selected_module]) && is_object($GLOBALS[$this->selected_module])) {
69           if (method_exists($GLOBALS[$this->selected_module], 'update_status')) {
70             $GLOBALS[$this->selected_module]->update_status();
71           }
72         }
73       }
74     }
75
76     function javascript_validation() {
hpdl
387
77       global $osC_Language;
78
hpdl
1
79       $js = '';
80       if (is_array($this->modules)) {
hpdl
241
81         $js = '<script type="text/javascript"><!-- ' . "\n" .
hpdl
1
82               'function check_form() {' . "\n" .
83               '  var error = 0;' . "\n" .
hpdl
387
84               '  var error_message = "' . $osC_Language->get('js_error') . '";' . "\n" .
hpdl
1
85               '  var payment_value = null;' . "\n" .
86               '  if (document.checkout_payment.payment.length) {' . "\n" .
87               '    for (var i=0; i<document.checkout_payment.payment.length; i++) {' . "\n" .
88               '      if (document.checkout_payment.payment[i].checked) {' . "\n" .
89               '        payment_value = document.checkout_payment.payment[i].value;' . "\n" .
90               '      }' . "\n" .
91               '    }' . "\n" .
92               '  } else if (document.checkout_payment.payment.checked) {' . "\n" .
93               '    payment_value = document.checkout_payment.payment.value;' . "\n" .
94               '  } else if (document.checkout_payment.payment.value) {' . "\n" .
95               '    payment_value = document.checkout_payment.payment.value;' . "\n" .
96               '  }' . "\n\n";
97
98         reset($this->modules);
99         while (list(, $value) = each($this->modules)) {
100           $class = substr($value, 0, strrpos($value, '.'));
101           if ($GLOBALS[$class]->enabled) {
102             $js .= $GLOBALS[$class]->javascript_validation();
103           }
104         }
105
106         $js .= "\n" . '  if (payment_value == null) {' . "\n" .
hpdl
390
107                '    error_message = error_message + "' . $osC_Language->get('js_no_payment_module_selected') . '\n";' . "\n" .
hpdl
1
108                '    error = 1;' . "\n" .
109                '  }' . "\n\n" .
110                '  if (error == 1) {' . "\n" .
111                '    alert(error_message);' . "\n" .
112                '    return false;' . "\n" .
113                '  } else {' . "\n" .
114                '    return true;' . "\n" .
115                '  }' . "\n" .
116                '}' . "\n" .
117                '//--></script>' . "\n";
118       }
119
120       return $js;
121     }
122
123     function selection() {
124       $selection_array = array();
125
126       if (is_array($this->modules)) {
127         reset($this->modules);
128         while (list(, $value) = each($this->modules)) {
129           $class = substr($value, 0, strrpos($value, '.'));
130           if ($GLOBALS[$class]->enabled) {
131             $selection = $GLOBALS[$class]->selection();
132             if (is_array($selection)) $selection_array[] = $selection;
133           }
134         }
135       }
136
137       return $selection_array;
138     }
139
140     function pre_confirmation_check() {
141       if (is_array($this->modules)) {
142         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
143           $GLOBALS[$this->selected_module]->pre_confirmation_check();
144         }
145       }
146     }
147
148     function confirmation() {
149       if (is_array($this->modules)) {
150         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
151           return $GLOBALS[$this->selected_module]->confirmation();
152         }
153       }
154     }
155
156     function process_button() {
157       if (is_array($this->modules)) {
158         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
159           return $GLOBALS[$this->selected_module]->process_button();
160         }
161       }
162     }
163
164     function before_process() {
165       if (is_array($this->modules)) {
166         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
167           return $GLOBALS[$this->selected_module]->before_process();
168         }
169       }
170     }
171
172     function after_process() {
173       if (is_array($this->modules)) {
174         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
175           return $GLOBALS[$this->selected_module]->after_process();
176         }
177       }
178     }
179
180     function get_error() {
181       if (is_array($this->modules)) {
182         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
183           return $GLOBALS[$this->selected_module]->get_error();
184         }
185       }
186     }
187   }
188 ?>