Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace:

Diff

421
 
431
 
431
 
payment.php
_> 11 <?php
  22 /*
<> 3 -  $Id: payment.php 421 2006-02-08 17:53:17Z hpdl $
   3+  $Id: payment.php 431 2006-02-15 05:57:09Z hpdl $
44 
  55   osCommerce, Open Source E-Commerce Solutions
  66   http://www.oscommerce.com
     
 !
1515 
  1616 // class constructor
  1717     function osC_Payment($module = '') {
<> 18 -      global $osC_Language;
   18+      global $osC_Database, $osC_Language;
1919 
<> 20 -      if (defined('MODULE_PAYMENT_INSTALLED') && tep_not_null(MODULE_PAYMENT_INSTALLED)) {
  21 -        $this->modules = explode(';', MODULE_PAYMENT_INSTALLED);
   20+      $Qmodules = $osC_Database->query('select code from :table_templates_boxes where modules_group = "payment"');
   21+      $Qmodules->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
   22+      $Qmodules->setCache('modules-payment');
   23+      $Qmodules->execute();
2224 
<> 23 -        $include_modules = array();
   25+      while ($Qmodules->next()) {
   26+        $this->modules[] = $Qmodules->value('code');
   27+      }
2428 
<> 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;
   29+      $Qmodules->freeResult();
2730 
<> 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 -          }
   31+      if (empty($this->modules) === false) {
   32+        if ((empty($module) === false) && in_array($module, $this->modules)) {
   33+          $this->modules = array($module);
   34+          $this->selected_module = 'osC_Payment_' . $module;
3535         }
  3636 
  3737         $osC_Language->load('modules-payment');
  3838 
<> 39 -        for ($i=0, $n=sizeof($include_modules); $i<$n; $i++) {
  40 -          include('includes/modules/payment/' . $include_modules[$i]['file']);
   39+        foreach ($this->modules as $modules) {
   40+          include('includes/modules/payment/' . $modules . '.' . substr(basename(__FILE__), (strrpos(basename(__FILE__), '.')+1)));
4141 
<> 42 -          $GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class'];
  43 -        }
   42+          $module_class = 'osC_Payment_' . $modules;
4443 
<> 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'];
   44+          $GLOBALS[$module_class] = new $module_class();
5045         }
  5146 
<> 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;
   47+        usort($this->modules, array('osC_Payment', '_usortModules'));
   48+
   49+        if ( (tep_not_null($module)) && (in_array($module, $this->modules)) && (isset($GLOBALS['osC_Payment_' . $module]->form_action_url)) ) {
   50+          $this->form_action_url = $GLOBALS['osC_Payment_' . $module]->form_action_url;
5451         }
  5552       }
  5653     }
     
 !
9693               '    payment_value = document.checkout_payment.payment.value;' . "\n" .
  9794               '  }' . "\n\n";
  9895 
<> 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();
   96+        foreach ($this->modules as $module) {
   97+          if ($GLOBALS['osC_Payment_' . $module]->enabled) {
   98+            $js .= $GLOBALS['osC_Payment_' . $module]->javascript_validation();
10499           }
  105100         }
  106101 
     
 !
124119     function selection() {
  125120       $selection_array = array();
  126121 
<> 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 -          }
   122+      foreach ($this->modules as $module) {
   123+        if ($GLOBALS['osC_Payment_' . $module]->enabled) {
   124+          $selection = $GLOBALS['osC_Payment_' . $module]->selection();
   125+          if (is_array($selection)) $selection_array[] = $selection;
135126         }
  136127       }
  137128 
     
 !
185176         }
  186177       }
  187178     }
<>  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_Payment_' . $module]->enabled) {
   188+            $has_active = true;
   189+            break;
   190+          }
   191+        }
   192+      }
   193+
   194+      return $has_active;
   195+    }
   196+
   197+    function numberOfActive() {
   198+      static $active;
   199+
   200+      if (isset($active) === false) {
   201+        $active = 0;
   202+
   203+        foreach ($this->modules as $module) {
   204+          if ($GLOBALS['osC_Payment_' . $module]->enabled) {
   205+            $active++;
   206+          }
   207+        }
   208+      }
   209+
   210+      return $active;
   211+    }
   212+
   213+    function hasKeys() {
   214+      static $has_keys;
   215+
   216+      if (isset($has_keys) === false) {
   217+        $has_keys = (sizeof($this->getKeys()) > 0) ? true : false;
   218+      }
   219+
   220+      return $has_keys;
   221+    }
   222+
   223+    function install() {
   224+      global $osC_Database, $osC_Language;
   225+
   226+      $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)');
   227+      $Qinstall->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
   228+      $Qinstall->bindValue(':title', $this->_title);
   229+      $Qinstall->bindValue(':code', $this->_code);
   230+      $Qinstall->bindValue(':author_name', $this->_author_name);
   231+      $Qinstall->bindValue(':author_www', $this->_author_www);
   232+      $Qinstall->bindValue(':modules_group', $this->_group);
   233+      $Qinstall->execute();
   234+
   235+      foreach ($osC_Language->getAll() as $key => $value) {
   236+        if (file_exists(dirname(__FILE__) . '/../languages/' . $key . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) {
   237+          foreach ($osC_Language->extractDefinitions($key . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) {
   238+            $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');
   239+            $Qcheck->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
   240+            $Qcheck->bindValue(':definition_key', $def['key']);
   241+            $Qcheck->bindValue(':content_group', $def['group']);
   242+            $Qcheck->bindInt(':languages_id', $value['id']);
   243+            $Qcheck->execute();
   244+
   245+            if ($Qcheck->numberOfRows() === 1) {
   246+              $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');
   247+            } else {
   248+              $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)');
   249+            }
   250+            $Qdef->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
   251+            $Qdef->bindInt(':languages_id', $value['id']);
   252+            $Qdef->bindValue(':content_group', $def['group']);
   253+            $Qdef->bindValue(':definition_key', $def['key']);
   254+            $Qdef->bindValue(':definition_value', $def['value']);
   255+            $Qdef->execute();
   256+          }
   257+        }
   258+      }
   259+
   260+      osC_Cache::clear('languages');
   261+    }
   262+
   263+    function remove() {
   264+      global $osC_Database, $osC_Language;
   265+
   266+      $Qdel = $osC_Database->query('delete from :table_templates_boxes where code = :code and modules_group = :modules_group');
   267+      $Qdel->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
   268+      $Qdel->bindValue(':code', $this->_code);
   269+      $Qdel->bindValue(':modules_group', $this->_group);
   270+      $Qdel->execute();
   271+
   272+      if ($this->hasKeys()) {
   273+        $Qdel = $osC_Database->query('delete from :table_configuration where configuration_key in (":configuration_key")');
   274+        $Qdel->bindTable(':table_configuration', TABLE_CONFIGURATION);
   275+        $Qdel->bindRaw(':configuration_key', implode('", "', $this->getKeys()));
   276+        $Qdel->execute();
   277+      }
   278+
   279+      if (file_exists(dirname(__FILE__) . '/../languages/' . $osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) {
   280+        foreach ($osC_Language->extractDefinitions($osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) {
   281+          $Qdel = $osC_Database->query('delete from :table_languages_definitions where definition_key = :definition_key and content_group = :content_group');
   282+          $Qdel->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
   283+          $Qdel->bindValue(':definition_key', $def['key']);
   284+          $Qdel->bindValue(':content_group', $def['group']);
   285+          $Qdel->execute();
   286+        }
   287+
   288+        osC_Cache::clear('languages');
   289+      }
   290+    }
   291+
   292+    function _usortModules($a, $b) {
   293+      if ($GLOBALS['osC_Payment_' . $a]->sort_order == $GLOBALS['osC_Payment_' . $b]->sort_order) {
   294+        return strnatcasecmp($GLOBALS['osC_Payment_' . $a]->title, $GLOBALS['osC_Payment_' . $a]->title);
   295+      }
   296+
   297+      return ($GLOBALS['osC_Payment_' . $a]->sort_order < $GLOBALS['osC_Payment_' . $b]->sort_order) ? -1 : 1;
   298+    }
<_ 188299   }
  189300 ?>