Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace:

Diff

410
 
443
 
443
 
payment.php
_> 11 <?php
  22 /*
<> 3 -  $Id: payment.php 410 2006-01-26 09:17:09Z hpdl $
   3+  $Id: payment.php 443 2006-02-19 23:01:01Z hpdl $
44 
  55   osCommerce, Open Source E-Commerce Solutions
  66   http://www.oscommerce.com
     
 !
1010   Released under the GNU General Public License
  1111 */
  1212 
<> 13 -  class payment {
  14 -    var $modules, $selected_module;
   13+  class osC_Payment {
   14+    var $selected_module;
1515 
<>  16+    var $_modules = array(),
   17+        $_group = 'payment';
   18+
1619 // class constructor
<> 17 -    function payment($module = '') {
  18 -      global $osC_Language;
   20+    function osC_Payment($module = '') {
   21+      global $osC_Database, $osC_Language;
1922 
<> 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();
2227 
<> 23 -        $include_modules = array();
   28+      while ($Qmodules->next()) {
   29+        $this->_modules[] = $Qmodules->value('code');
   30+      }
2431 
<> 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();
2733 
<> 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;
3538         }
  3639 
  3740         $osC_Language->load('modules-payment');
  3841 
<> 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)));
4144 
<> 42 -          $GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class'];
  43 -        }
   45+          $module_class = 'osC_Payment_' . $modules;
4446 
<> 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();
5048         }
  5149 
<> 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;
5454         }
  5555       }
  5656     }
  5757 
  5858 // 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+
5979 /* The following method is needed in the checkout_confirmation.php page
  6080    due to a chicken and egg problem with the payment class and order class.
  6181    The payment modules needs the order destination data for the dynamic status
     
 !
6585    section. This should be looked into again post 2.2.
  6686 */
  6787     function update_status() {
<> 68 -      if (is_array($this->modules)) {
   88+      if (is_array($this->_modules)) {
6989         if (isset($GLOBALS[$this->selected_module]) && is_object($GLOBALS[$this->selected_module])) {
  7090           if (method_exists($GLOBALS[$this->selected_module], 'update_status')) {
  7191             $GLOBALS[$this->selected_module]->update_status();
     
 !
7898       global $osC_Language;
  7999 
  80100       $js = '';
<> 81 -      if (is_array($this->modules)) {
   101+      if (is_array($this->_modules)) {
82102         $js = '<script type="text/javascript"><!-- ' . "\n" .
  83103               'function check_form() {' . "\n" .
  84104               '  var error = 0;' . "\n" .
     
 !
96116               '    payment_value = document.checkout_payment.payment.value;' . "\n" .
  97117               '  }' . "\n\n";
  98118 
<> 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();
104122           }
  105123         }
  106124 
     
 !
124142     function selection() {
  125143       $selection_array = array();
  126144 
<> 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;
135149         }
  136150       }
  137151 
  138152       return $selection_array;
  139153     }
  140154 
  141155     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) ) {
144158           $GLOBALS[$this->selected_module]->pre_confirmation_check();
  145159         }
  146160       }
  147161     }
  148162 
  149163     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) ) {
152166           return $GLOBALS[$this->selected_module]->confirmation();
  153167         }
  154168       }
  155169     }
  156170 
  157171     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) ) {
160174           return $GLOBALS[$this->selected_module]->process_button();
  161175         }
  162176       }
  163177     }
  164178 
  165179     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) ) {
168182           return $GLOBALS[$this->selected_module]->before_process();
  169183         }
  170184       }
  171185     }
  172186 
  173187     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) ) {
176190           return $GLOBALS[$this->selected_module]->after_process();
  177191         }
  178192       }
  179193     }
  180194 
  181195     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) ) {
184198           return $GLOBALS[$this->selected_module]->get_error();
  185199         }
  186200       }
  187201     }
<>  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+    }
<_ 188338   }
  189339 ?>