  |
1 | 1 | | <?php |
| |
2 | 2 | | /* |
  |
3 | | - | $Id: payment.php 410 2006-01-26 09:17:09Z hpdl $ |
| |
| 3 | + | $Id: payment.php 443 2006-02-19 23:01:01Z hpdl $ |
|
4 | 4 | | |
| |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
|
|
 |
… |
|
10 | 10 | | Released under the GNU General Public License |
| |
11 | 11 | | */ |
| |
12 | 12 | | |
  |
13 | | - | class payment { |
| |
14 | | - | var $modules, $selected_module; |
| |
| 13 | + | class osC_Payment { |
| |
| 14 | + | var $selected_module; |
|
15 | 15 | | |
  |
| 16 | + | var $_modules = array(), |
| |
| 17 | + | $_group = 'payment'; |
| |
| 18 | + | |
|
16 | 19 | | // class constructor |
  |
17 | | - | function payment($module = '') { |
| |
18 | | - | global $osC_Language; |
| |
| 20 | + | function osC_Payment($module = '') { |
| |
| 21 | + | global $osC_Database, $osC_Language; |
|
19 | 22 | | |
  |
20 | | - | if (defined('MODULE_PAYMENT_INSTALLED') && tep_not_null(MODULE_PAYMENT_INSTALLED)) { |
| |
21 | | - | $this->modules = explode(';', MODULE_PAYMENT_INSTALLED); |
| |
| 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(); |
|
22 | 27 | | |
  |
23 | | - | $include_modules = array(); |
| |
| 28 | + | while ($Qmodules->next()) { |
| |
| 29 | + | $this->_modules[] = $Qmodules->value('code'); |
| |
| 30 | + | } |
|
24 | 31 | | |
  |
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; |
| |
| 32 | + | $Qmodules->freeResult(); |
|
27 | 33 | | |
  |
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 | | - | } |
| |
| 34 | + | if (empty($this->_modules) === false) { |
| |
| 35 | + | if ((empty($module) === false) && in_array($module, $this->_modules)) { |
| |
| 36 | + | $this->_modules = array($module); |
| |
| 37 | + | $this->selected_module = 'osC_Payment_' . $module; |
|
35 | 38 | | } |
| |
36 | 39 | | |
| |
37 | 40 | | $osC_Language->load('modules-payment'); |
| |
38 | 41 | | |
  |
39 | | - | for ($i=0, $n=sizeof($include_modules); $i<$n; $i++) { |
| |
40 | | - | include('includes/modules/payment/' . $include_modules[$i]['file']); |
| |
| 42 | + | foreach ($this->_modules as $modules) { |
| |
| 43 | + | include('includes/modules/payment/' . $modules . '.' . substr(basename(__FILE__), (strrpos(basename(__FILE__), '.')+1))); |
|
41 | 44 | | |
  |
42 | | - | $GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class']; |
| |
43 | | - | } |
| |
| 45 | + | $module_class = 'osC_Payment_' . $modules; |
|
44 | 46 | | |
  |
45 | | - | // if there is only one payment method, select it as default because in |
| |
46 | | - | // checkout_confirmation.php the $payment variable is being assigned the |
| |
47 | | - | // $_POST['payment_mod_sel'] value which will be empty (no radio button selection possible) |
| |
48 | | - | if ( (tep_count_payment_modules() == 1) && (!isset($GLOBALS[$_SESSION['payment']]) || (isset($GLOBALS[$_SESSION['payment']]) && !is_object($GLOBALS[$_SESSION['payment']]))) ) { |
| |
49 | | - | $_SESSION['payment'] = $include_modules[0]['class']; |
| |
| 47 | + | $GLOBALS[$module_class] = new $module_class(); |
|
50 | 48 | | } |
| |
51 | 49 | | |
  |
52 | | - | if ( (tep_not_null($module)) && (in_array($module, $this->modules)) && (isset($GLOBALS[$module]->form_action_url)) ) { |
| |
53 | | - | $this->form_action_url = $GLOBALS[$module]->form_action_url; |
| |
| 50 | + | usort($this->_modules, array('osC_Payment', '_usortModules')); |
| |
| 51 | + | |
| |
| 52 | + | if ( (tep_not_null($module)) && (in_array($module, $this->_modules)) && (isset($GLOBALS['osC_Payment_' . $module]->form_action_url)) ) { |
| |
| 53 | + | $this->form_action_url = $GLOBALS['osC_Payment_' . $module]->form_action_url; |
|
54 | 54 | | } |
| |
55 | 55 | | } |
| |
56 | 56 | | } |
| |
57 | 57 | | |
| |
58 | 58 | | // class methods |
  |
| 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 | + | |
|
59 | 79 | | /* The following method is needed in the checkout_confirmation.php page |
| |
60 | 80 | | due to a chicken and egg problem with the payment class and order class. |
| |
61 | 81 | | The payment modules needs the order destination data for the dynamic status |
| |
|
|
 |
… |
|
65 | 85 | | section. This should be looked into again post 2.2. |
| |
66 | 86 | | */ |
| |
67 | 87 | | function update_status() { |
  |
68 | | - | if (is_array($this->modules)) { |
| |
| 88 | + | if (is_array($this->_modules)) { |
|
69 | 89 | | if (isset($GLOBALS[$this->selected_module]) && is_object($GLOBALS[$this->selected_module])) { |
| |
70 | 90 | | if (method_exists($GLOBALS[$this->selected_module], 'update_status')) { |
| |
71 | 91 | | $GLOBALS[$this->selected_module]->update_status(); |
| |
|
|
 |
… |
|
78 | 98 | | global $osC_Language; |
| |
79 | 99 | | |
| |
80 | 100 | | $js = ''; |
  |
81 | | - | if (is_array($this->modules)) { |
| |
| 101 | + | if (is_array($this->_modules)) { |
|
82 | 102 | | $js = '<script type="text/javascript"><!-- ' . "\n" . |
| |
83 | 103 | | 'function check_form() {' . "\n" . |
| |
84 | 104 | | ' var error = 0;' . "\n" . |
| |
|
|
 |
… |
|
96 | 116 | | ' payment_value = document.checkout_payment.payment.value;' . "\n" . |
| |
97 | 117 | | ' }' . "\n\n"; |
| |
98 | 118 | | |
  |
99 | | - | reset($this->modules); |
| |
100 | | - | while (list(, $value) = each($this->modules)) { |
| |
101 | | - | $class = substr($value, 0, strrpos($value, '.')); |
| |
102 | | - | if ($GLOBALS[$class]->enabled) { |
| |
103 | | - | $js .= $GLOBALS[$class]->javascript_validation(); |
| |
| 119 | + | foreach ($this->_modules as $module) { |
| |
| 120 | + | if ($GLOBALS['osC_Payment_' . $module]->getStatus() === true) { |
| |
| 121 | + | $js .= $GLOBALS['osC_Payment_' . $module]->javascript_validation(); |
|
104 | 122 | | } |
| |
105 | 123 | | } |
| |
106 | 124 | | |
| |
|
|
 |
… |
|
124 | 142 | | function selection() { |
| |
125 | 143 | | $selection_array = array(); |
| |
126 | 144 | | |
  |
127 | | - | if (is_array($this->modules)) { |
| |
128 | | - | reset($this->modules); |
| |
129 | | - | while (list(, $value) = each($this->modules)) { |
| |
130 | | - | $class = substr($value, 0, strrpos($value, '.')); |
| |
131 | | - | if ($GLOBALS[$class]->enabled) { |
| |
132 | | - | $selection = $GLOBALS[$class]->selection(); |
| |
133 | | - | if (is_array($selection)) $selection_array[] = $selection; |
| |
134 | | - | } |
| |
| 145 | + | foreach ($this->_modules as $module) { |
| |
| 146 | + | if ($GLOBALS['osC_Payment_' . $module]->getStatus() === true) { |
| |
| 147 | + | $selection = $GLOBALS['osC_Payment_' . $module]->selection(); |
| |
| 148 | + | if (is_array($selection)) $selection_array[] = $selection; |
|
135 | 149 | | } |
| |
136 | 150 | | } |
| |
137 | 151 | | |
| |
138 | 152 | | return $selection_array; |
| |
139 | 153 | | } |
| |
140 | 154 | | |
| |
141 | 155 | | function pre_confirmation_check() { |
  |
142 | | - | if (is_array($this->modules)) { |
| |
143 | | - | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { |
| |
| 156 | + | if (is_array($this->_modules)) { |
| |
| 157 | + | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) { |
|
144 | 158 | | $GLOBALS[$this->selected_module]->pre_confirmation_check(); |
| |
145 | 159 | | } |
| |
146 | 160 | | } |
| |
147 | 161 | | } |
| |
148 | 162 | | |
| |
149 | 163 | | function confirmation() { |
  |
150 | | - | if (is_array($this->modules)) { |
| |
151 | | - | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { |
| |
| 164 | + | if (is_array($this->_modules)) { |
| |
| 165 | + | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) { |
|
152 | 166 | | return $GLOBALS[$this->selected_module]->confirmation(); |
| |
153 | 167 | | } |
| |
154 | 168 | | } |
| |
155 | 169 | | } |
| |
156 | 170 | | |
| |
157 | 171 | | function process_button() { |
  |
158 | | - | if (is_array($this->modules)) { |
| |
159 | | - | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { |
| |
| 172 | + | if (is_array($this->_modules)) { |
| |
| 173 | + | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) { |
|
160 | 174 | | return $GLOBALS[$this->selected_module]->process_button(); |
| |
161 | 175 | | } |
| |
162 | 176 | | } |
| |
163 | 177 | | } |
| |
164 | 178 | | |
| |
165 | 179 | | function before_process() { |
  |
166 | | - | if (is_array($this->modules)) { |
| |
167 | | - | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { |
| |
| 180 | + | if (is_array($this->_modules)) { |
| |
| 181 | + | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) { |
|
168 | 182 | | return $GLOBALS[$this->selected_module]->before_process(); |
| |
169 | 183 | | } |
| |
170 | 184 | | } |
| |
171 | 185 | | } |
| |
172 | 186 | | |
| |
173 | 187 | | function after_process() { |
  |
174 | | - | if (is_array($this->modules)) { |
| |
175 | | - | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { |
| |
| 188 | + | if (is_array($this->_modules)) { |
| |
| 189 | + | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) { |
|
176 | 190 | | return $GLOBALS[$this->selected_module]->after_process(); |
| |
177 | 191 | | } |
| |
178 | 192 | | } |
| |
179 | 193 | | } |
| |
180 | 194 | | |
| |
181 | 195 | | function get_error() { |
  |
182 | | - | if (is_array($this->modules)) { |
| |
183 | | - | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { |
| |
| 196 | + | if (is_array($this->_modules)) { |
| |
| 197 | + | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) { |
|
184 | 198 | | return $GLOBALS[$this->selected_module]->get_error(); |
| |
185 | 199 | | } |
| |
186 | 200 | | } |
| |
187 | 201 | | } |
  |
| 202 | + | |
| |
| 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 | + | |
| |
| 219 | + | function hasActive() { |
| |
| 220 | + | static $has_active; |
| |
| 221 | + | |
| |
| 222 | + | if (isset($has_active) === false) { |
| |
| 223 | + | $has_active = false; |
| |
| 224 | + | |
| |
| 225 | + | foreach ($this->_modules as $module) { |
| |
| 226 | + | if ($GLOBALS['osC_Payment_' . $module]->getStatus() === true) { |
| |
| 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 | + | |
| |
| 242 | + | foreach ($this->_modules as $module) { |
| |
| 243 | + | if ($GLOBALS['osC_Payment_' . $module]->getStatus() === true) { |
| |
| 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) { |
| |
| 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()); |
| |
| 334 | + | } |
| |
| 335 | + | |
| |
| 336 | + | return ($GLOBALS['osC_Payment_' . $a]->getSortOrder() < $GLOBALS['osC_Payment_' . $b]->getSortOrder()) ? -1 : 1; |
| |
| 337 | + | } |
  |
188 | 338 | | } |
| |
189 | 339 | | ?> |