<?php
/*
  $Id: order_total.php,v 1.4 2003/02/11 00:04:53 hpdl Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

  class order_total {
    var $modules;

// class constructor
    function order_total() {
      global $language;

      if (defined('MODULE_ORDER_TOTAL_INSTALLED') && tep_not_null(MODULE_ORDER_TOTAL_INSTALLED)) {
        $this->modules = explode(';', MODULE_ORDER_TOTAL_INSTALLED);

        reset($this->modules);
        while (list(, $value) = each($this->modules)) {
          include(DIR_WS_LANGUAGES . $language . '/modules/order_total/' . $value);
          include(DIR_WS_MODULES . 'order_total/' . $value);

          $class = substr($value, 0, strrpos($value, '.'));
          $GLOBALS[$class] = new $class;
        }
      }
    }

    function process() {
      $order_total_array = array();
      if (is_array($this->modules)) {
        reset($this->modules);
        while (list(, $value) = each($this->modules)) {
          $class = substr($value, 0, strrpos($value, '.'));
          if ($GLOBALS[$class]->enabled) {
            $GLOBALS[$class]->process();

            for ($i=0, $n=sizeof($GLOBALS[$class]->output); $i<$n; $i++) {
//echo "<br>code=".$GLOBALS[$class]->code;
//echo "<br>ddd=".$GLOBALS[$class]->output[$i]['title'];
//echo "<br>lll===".MODULE_SHIPPING_ITEM_TEXT_WAY;
              if (tep_not_null($GLOBALS[$class]->output[$i]['title']) && tep_not_null($GLOBALS[$class]->output[$i]['text'])) {
                $order_total_array[] = array('code' => $GLOBALS[$class]->code,
                                             'title' => $GLOBALS[$class]->output[$i]['title'],
                                             'text' => $GLOBALS[$class]->output[$i]['text'],
                                             'value' => $GLOBALS[$class]->output[$i]['value'],
                                             'sort_order' => $GLOBALS[$class]->sort_order);
              }
            }
          }
        }
      }

      return $order_total_array;
    }

    function output($couponcode='') {
      $output_string = '';
      if (is_array($this->modules)) {
        reset($this->modules);
        while (list(, $value) = each($this->modules)) {
          $class = substr($value, 0, strrpos($value, '.'));
          if ($GLOBALS[$class]->enabled) {
            $size = sizeof($GLOBALS[$class]->output);
            for ($i=0; $i<$size; $i++) {
						if ($GLOBALS[$class]->code=="ot_shipping")
						{
									  $output_string .= '              <tr>' . "\n" .
														'                <td align="right" class="main">' . MODULE_SHIPPING_ITEM_TEXT_TITLE . ':</td>' . "\n" .
														'                <td align="right" class="main">' . $GLOBALS[$class]->output[$i]['text'] . '</td>' . "\n" .
														'              </tr>';
						}
						else
						if ($GLOBALS[$class]->code=="ot_discount_coupon")
						{
									  $output_string .= '              <tr>' . "\n" .
														'                <td align="right" class="main">' . str_replace( '[code]', $couponcode, MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY) . ':</td>' . "\n" .
														'                <td align="right" class="main">' . $GLOBALS[$class]->output[$i]['text'] . '</td>' . "\n" .
														'              </tr>';
						}
						else
						if ($GLOBALS[$class]->code=="ot_total")
						{
									  $output_string .= '              <tr>' . "\n" .
														'                <td align="right" class="main"><b>' . MODULE_ORDER_TOTAL_TOTAL_TITLE . ':</b></td>' . "\n" .
														'                <td align="right" class="main">' . $GLOBALS[$class]->output[$i]['text'] . '</td>' . "\n" .
														'              </tr>';
						}
						else
						{
									  $output_string .= '              <tr>' . "\n" .
														'                <td align="right" class="main">' . $GLOBALS[$class]->output[$i]['title'] . '</td>' . "\n" .
														'                <td align="right" class="main">' . $GLOBALS[$class]->output[$i]['text'] . '</td>' . "\n" .
														'              </tr>';
						}
            }
          }
        }
      }

      return $output_string;
    }
  }
?>