Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace:

Diff

422
 
425
 
425
 
shipping.php
_> 11 <?php
  22 /*
<> 3 -  $Id: shipping.php 422 2006-02-09 13:36:08Z hpdl $
   3+  $Id: shipping.php 425 2006-02-14 11:31:42Z hpdl $
44 
  55   osCommerce, Open Source E-Commerce Solutions
  66   http://www.oscommerce.com
     
 !
1414     var $_modules = array(),
  1515         $_quotes = array(),
  1616         $_shipping_boxes = 1,
<> 17 -        $_shipping_weight = 0;
   17+        $_shipping_weight = 0,
   18+        $_keys;
1819 
  1920 // class constructor
  2021     function osC_Shipping($module = '') {
<> 21 -      global $osC_Language;
   22+      global $osC_Database, $osC_Language;
2223 
  2324       if (isset($_SESSION['osC_Shipping_data']) === false) {
  2425         $_SESSION['osC_Shipping_data'] = array('shipping_boxes' => 1,
     
 !
3031       $this->_shipping_weight =& $_SESSION['osC_Shipping_data']['shipping_weight'];
  3132       $this->_quotes =& $_SESSION['osC_Shipping_data']['quotes'];
  3233 
<> 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();
3538 
<>  39+      while ($Qmodules->next()) {
   40+        $this->_modules[] = $Qmodules->value('code');
   41+      }
   42+
   43+      $Qmodules->freeResult();
   44+
   45+      if (empty($this->_modules) === false) {
3646         $include_modules = array();
  3747 
<> 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)));
4051         } else {
  4152           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)));
4455           }
  4556         }
  4657 
     
 !
4960         foreach ($include_modules as $module) {
  5061           include('includes/modules/shipping/' . $module['file']);
  5162 
<> 52 -          $GLOBALS[$module['class']] = new $module['class'];
  53 -          $GLOBALS[$module['class']]->prepare();
   63+          $GLOBALS[$module['class']] = new $module['class']();
   64+          $GLOBALS[$module['class']]->initialize();
5465         }
  5566       }
  5667     }
  5768 
<> 58 -    function calculateQuotes($method = '', $module = '') {
   69+    function calculateQuotes() {
5970       global $osC_ShoppingCart;
  6071 
  6172       $this->_quotes = array();
     
 !
7687 
  7788         $include_quotes = array();
  7889 
<> 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)) {
8091           $include_quotes[] = 'free';
  8192         } 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;
9196             }
  9297           }
  9398         }
  9499 
  95100         foreach ($include_quotes as $module) {
<> 96 -          $quotes = $GLOBALS[$module]->quote($method);
   101+          $quotes = $GLOBALS[$module]->quote();
97102 
  98103           if (is_array($quotes)) {
  99104             $this->_quotes[] = $quotes;
     
 !
116121       return $total_quotes;
  117122     }
  118123 
<> 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+
121128         foreach ($this->_quotes as $quote) {
  122129           if ($quote['id'] == $module) {
  123130             foreach ($quote['methods'] as $quote_method) {
     
 !
140147         $rates = array();
  141148 
  142149         foreach ($this->_modules as $value) {
<> 143 -          $class = substr($value, 0, strrpos($value, '.'));
   150+          $class = 'osC_Shipping_' . $value;
144151           if ($GLOBALS[$class]->enabled) {
  145152             $quotes = $GLOBALS[$class]->quotes;
  146153 
     
 !
169176         return $cheapest;
  170177       }
  171178     }
<>  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+    }
<_ 172275   }
  173276 ?>