  |
1 | 1 | | <?php |
| |
2 | 2 | | /* |
  |
3 | | - | $Id: shipping.php 422 2006-02-09 13:36:08Z hpdl $ |
| |
| 3 | + | $Id: shipping.php 425 2006-02-14 11:31:42Z hpdl $ |
|
4 | 4 | | |
| |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
|
|
 |
… |
|
14 | 14 | | var $_modules = array(), |
| |
15 | 15 | | $_quotes = array(), |
| |
16 | 16 | | $_shipping_boxes = 1, |
  |
17 | | - | $_shipping_weight = 0; |
| |
| 17 | + | $_shipping_weight = 0, |
| |
| 18 | + | $_keys; |
|
18 | 19 | | |
| |
19 | 20 | | // class constructor |
| |
20 | 21 | | function osC_Shipping($module = '') { |
  |
21 | | - | global $osC_Language; |
| |
| 22 | + | global $osC_Database, $osC_Language; |
|
22 | 23 | | |
| |
23 | 24 | | if (isset($_SESSION['osC_Shipping_data']) === false) { |
| |
24 | 25 | | $_SESSION['osC_Shipping_data'] = array('shipping_boxes' => 1, |
| |
|
|
 |
… |
|
30 | 31 | | $this->_shipping_weight =& $_SESSION['osC_Shipping_data']['shipping_weight']; |
| |
31 | 32 | | $this->_quotes =& $_SESSION['osC_Shipping_data']['quotes']; |
| |
32 | 33 | | |
  |
33 | | - | if (defined('MODULE_SHIPPING_INSTALLED') && (osc_empty(MODULE_SHIPPING_INSTALLED) === false)) { |
| |
34 | | - | $this->_modules = explode(';', MODULE_SHIPPING_INSTALLED); |
| |
| 34 | + | $Qmodules = $osC_Database->query('select code from :table_templates_boxes where modules_group = "shipping"'); |
| |
| 35 | + | $Qmodules->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES); |
| |
| 36 | + | $Qmodules->setCache('modules-shipping'); |
| |
| 37 | + | $Qmodules->execute(); |
|
35 | 38 | | |
  |
| 39 | + | while ($Qmodules->next()) { |
| |
| 40 | + | $this->_modules[] = $Qmodules->value('code'); |
| |
| 41 | + | } |
| |
| 42 | + | |
| |
| 43 | + | $Qmodules->freeResult(); |
| |
| 44 | + | |
| |
| 45 | + | if (empty($this->_modules) === false) { |
|
36 | 46 | | $include_modules = array(); |
| |
37 | 47 | | |
  |
38 | | - | if ( (empty($module) === false) && (in_array(substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($_SERVER['PHP_SELF'], (strrpos($_SERVER['PHP_SELF'], '.')+1)), $this->_modules)) ) { |
| |
39 | | - | $include_modules[] = array('class' => substr($module['id'], 0, strpos($module['id'], '_')), 'file' => substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($_SERVER['PHP_SELF'], (strrpos($_SERVER['PHP_SELF'], '.')+1))); |
| |
| 48 | + | if ((empty($module) === false) && in_array(substr($module['id'], 0, strpos($module['id'], '_')), $this->_modules)) { |
| |
| 49 | + | $include_modules[] = array('class' => 'osC_Shipping_' . substr($module['id'], 0, strpos($module['id'], '_')), |
| |
| 50 | + | 'file' => substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr(basename(__FILE__), (strrpos(basename(__FILE__), '.')+1))); |
|
40 | 51 | | } else { |
| |
41 | 52 | | foreach ($this->_modules as $value) { |
  |
42 | | - | $class = substr($value, 0, strrpos($value, '.')); |
| |
43 | | - | $include_modules[] = array('class' => $class, 'file' => $value); |
| |
| 53 | + | $include_modules[] = array('class' => 'osC_Shipping_' . $value, |
| |
| 54 | + | 'file' => $value . '.' . substr(basename(__FILE__), (strrpos(basename(__FILE__), '.')+1))); |
|
44 | 55 | | } |
| |
45 | 56 | | } |
| |
46 | 57 | | |
| |
|
|
 |
… |
|
49 | 60 | | foreach ($include_modules as $module) { |
| |
50 | 61 | | include('includes/modules/shipping/' . $module['file']); |
| |
51 | 62 | | |
  |
52 | | - | $GLOBALS[$module['class']] = new $module['class']; |
| |
53 | | - | $GLOBALS[$module['class']]->prepare(); |
| |
| 63 | + | $GLOBALS[$module['class']] = new $module['class'](); |
| |
| 64 | + | $GLOBALS[$module['class']]->initialize(); |
|
54 | 65 | | } |
| |
55 | 66 | | } |
| |
56 | 67 | | } |
| |
57 | 68 | | |
  |
58 | | - | function calculateQuotes($method = '', $module = '') { |
| |
| 69 | + | function calculateQuotes() { |
|
59 | 70 | | global $osC_ShoppingCart; |
| |
60 | 71 | | |
| |
61 | 72 | | $this->_quotes = array(); |
| |
|
|
 |
… |
|
76 | 87 | | |
| |
77 | 88 | | $include_quotes = array(); |
| |
78 | 89 | | |
  |
79 | | - | if (defined('MODULE_SHIPPING_FREE_STATUS') && (MODULE_SHIPPING_FREE_STATUS == 'True') && ($GLOBALS['free']->enabled)) { |
| |
| 90 | + | if (defined('MODULE_SHIPPING_FREE_STATUS') && (MODULE_SHIPPING_FREE_STATUS == 'True') && ($GLOBALS['osC_Shipping_free']->enabled)) { |
|
80 | 91 | | $include_quotes[] = 'free'; |
| |
81 | 92 | | } else { |
  |
82 | | - | foreach ($this->_modules as $value) { |
| |
83 | | - | $class = substr($value, 0, strrpos($value, '.')); |
| |
84 | | - | |
| |
85 | | - | if (tep_not_null($module)) { |
| |
86 | | - | if ( ($module == $class) && ($GLOBALS[$class]->enabled) ) { |
| |
87 | | - | $include_quotes[] = $class; |
| |
88 | | - | } |
| |
89 | | - | } elseif ($GLOBALS[$class]->enabled) { |
| |
90 | | - | $include_quotes[] = $class; |
| |
| 93 | + | foreach ($this->_modules as $module) { |
| |
| 94 | + | if ($GLOBALS['osC_Shipping_' . $module]->enabled) { |
| |
| 95 | + | $include_quotes[] = 'osC_Shipping_' . $module; |
|
91 | 96 | | } |
| |
92 | 97 | | } |
| |
93 | 98 | | } |
| |
94 | 99 | | |
| |
95 | 100 | | foreach ($include_quotes as $module) { |
  |
96 | | - | $quotes = $GLOBALS[$module]->quote($method); |
| |
| 101 | + | $quotes = $GLOBALS[$module]->quote(); |
|
97 | 102 | | |
| |
98 | 103 | | if (is_array($quotes)) { |
| |
99 | 104 | | $this->_quotes[] = $quotes; |
| |
|
|
 |
… |
|
116 | 121 | | return $total_quotes; |
| |
117 | 122 | | } |
| |
118 | 123 | | |
  |
119 | | - | function getQuotes($method = '', $module = '') { |
| |
120 | | - | if ( (empty($method) === false) && (empty($module) === false) ) { |
| |
| 124 | + | function getQuotes($module = '') { |
| |
| 125 | + | if (empty($module) === false) { |
| |
| 126 | + | list($module, $method) = explode('_', $module); |
| |
| 127 | + | |
|
121 | 128 | | foreach ($this->_quotes as $quote) { |
| |
122 | 129 | | if ($quote['id'] == $module) { |
| |
123 | 130 | | foreach ($quote['methods'] as $quote_method) { |
| |
|
|
 |
… |
|
140 | 147 | | $rates = array(); |
| |
141 | 148 | | |
| |
142 | 149 | | foreach ($this->_modules as $value) { |
  |
143 | | - | $class = substr($value, 0, strrpos($value, '.')); |
| |
| 150 | + | $class = 'osC_Shipping_' . $value; |
|
144 | 151 | | if ($GLOBALS[$class]->enabled) { |
| |
145 | 152 | | $quotes = $GLOBALS[$class]->quotes; |
| |
146 | 153 | | |
| |
|
|
 |
… |
|
169 | 176 | | return $cheapest; |
| |
170 | 177 | | } |
| |
171 | 178 | | } |
  |
| 179 | + | |
| |
| 180 | + | function hasActive() { |
| |
| 181 | + | static $has_active; |
| |
| 182 | + | |
| |
| 183 | + | if (isset($has_active) === false) { |
| |
| 184 | + | $has_active = false; |
| |
| 185 | + | |
| |
| 186 | + | foreach ($this->_modules as $module) { |
| |
| 187 | + | if ($GLOBALS['osC_Shipping_' . $module]->enabled) { |
| |
| 188 | + | $has_active = true; |
| |
| 189 | + | break; |
| |
| 190 | + | } |
| |
| 191 | + | } |
| |
| 192 | + | } |
| |
| 193 | + | |
| |
| 194 | + | return $has_active; |
| |
| 195 | + | } |
| |
| 196 | + | |
| |
| 197 | + | function hasKeys() { |
| |
| 198 | + | static $has_keys; |
| |
| 199 | + | |
| |
| 200 | + | if (isset($has_keys) === false) { |
| |
| 201 | + | $has_keys = (sizeof($this->getKeys()) > 0) ? true : false; |
| |
| 202 | + | } |
| |
| 203 | + | |
| |
| 204 | + | return $has_keys; |
| |
| 205 | + | } |
| |
| 206 | + | |
| |
| 207 | + | function install() { |
| |
| 208 | + | global $osC_Database, $osC_Language; |
| |
| 209 | + | |
| |
| 210 | + | $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)'); |
| |
| 211 | + | $Qinstall->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES); |
| |
| 212 | + | $Qinstall->bindValue(':title', $this->_title); |
| |
| 213 | + | $Qinstall->bindValue(':code', $this->_code); |
| |
| 214 | + | $Qinstall->bindValue(':author_name', $this->_author_name); |
| |
| 215 | + | $Qinstall->bindValue(':author_www', $this->_author_www); |
| |
| 216 | + | $Qinstall->bindValue(':modules_group', $this->_group); |
| |
| 217 | + | $Qinstall->execute(); |
| |
| 218 | + | |
| |
| 219 | + | foreach ($osC_Language->getAll() as $key => $value) { |
| |
| 220 | + | if (file_exists(dirname(__FILE__) . '/../languages/' . $key . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) { |
| |
| 221 | + | foreach ($osC_Language->extractDefinitions($key . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) { |
| |
| 222 | + | $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'); |
| |
| 223 | + | $Qcheck->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS); |
| |
| 224 | + | $Qcheck->bindValue(':definition_key', $def['key']); |
| |
| 225 | + | $Qcheck->bindValue(':content_group', $def['group']); |
| |
| 226 | + | $Qcheck->bindInt(':languages_id', $value['id']); |
| |
| 227 | + | $Qcheck->execute(); |
| |
| 228 | + | |
| |
| 229 | + | if ($Qcheck->numberOfRows() === 1) { |
| |
| 230 | + | $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'); |
| |
| 231 | + | } else { |
| |
| 232 | + | $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)'); |
| |
| 233 | + | } |
| |
| 234 | + | $Qdef->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS); |
| |
| 235 | + | $Qdef->bindInt(':languages_id', $value['id']); |
| |
| 236 | + | $Qdef->bindValue(':content_group', $def['group']); |
| |
| 237 | + | $Qdef->bindValue(':definition_key', $def['key']); |
| |
| 238 | + | $Qdef->bindValue(':definition_value', $def['value']); |
| |
| 239 | + | $Qdef->execute(); |
| |
| 240 | + | } |
| |
| 241 | + | } |
| |
| 242 | + | } |
| |
| 243 | + | |
| |
| 244 | + | osC_Cache::clear('languages'); |
| |
| 245 | + | } |
| |
| 246 | + | |
| |
| 247 | + | function remove() { |
| |
| 248 | + | global $osC_Database, $osC_Language; |
| |
| 249 | + | |
| |
| 250 | + | $Qdel = $osC_Database->query('delete from :table_templates_boxes where code = :code and modules_group = :modules_group'); |
| |
| 251 | + | $Qdel->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES); |
| |
| 252 | + | $Qdel->bindValue(':code', $this->_code); |
| |
| 253 | + | $Qdel->bindValue(':modules_group', $this->_group); |
| |
| 254 | + | $Qdel->execute(); |
| |
| 255 | + | |
| |
| 256 | + | if ($this->hasKeys()) { |
| |
| 257 | + | $Qdel = $osC_Database->query('delete from :table_configuration where configuration_key in (":configuration_key")'); |
| |
| 258 | + | $Qdel->bindTable(':table_configuration', TABLE_CONFIGURATION); |
| |
| 259 | + | $Qdel->bindRaw(':configuration_key', implode('", "', $this->getKeys())); |
| |
| 260 | + | $Qdel->execute(); |
| |
| 261 | + | } |
| |
| 262 | + | |
| |
| 263 | + | if (file_exists(dirname(__FILE__) . '/../languages/' . $osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) { |
| |
| 264 | + | foreach ($osC_Language->extractDefinitions($osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) { |
| |
| 265 | + | $Qdel = $osC_Database->query('delete from :table_languages_definitions where definition_key = :definition_key and content_group = :content_group'); |
| |
| 266 | + | $Qdel->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS); |
| |
| 267 | + | $Qdel->bindValue(':definition_key', $def['key']); |
| |
| 268 | + | $Qdel->bindValue(':content_group', $def['group']); |
| |
| 269 | + | $Qdel->execute(); |
| |
| 270 | + | } |
| |
| 271 | + | |
| |
| 272 | + | osC_Cache::clear('languages'); |
| |
| 273 | + | } |
| |
| 274 | + | } |
  |
172 | 275 | | } |
| |
173 | 276 | | ?> |