[ Index ]
 

Code source de osCommerce 2.2ms2-060817

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/extras/orders/ -> update.php (source)

   1  <?php
   2  /*
   3    $Id: update.php,v 1.1 2002/04/08 01:15:19 hpdl Exp $
   4  
   5    osCommerce, Open Source E-Commerce Solutions
   6    http://www.oscommerce.com
   7  
   8    Copyright (c) 2002 osCommerce
   9  
  10    Released under the GNU General Public License
  11  */
  12  
  13    if (!$HTTP_POST_VARS['DB_SERVER']) {
  14  ?>
  15  <html>
  16  <head>
  17  <title>osCommerce 2.2-CVS Orders Update Script</title>
  18  <style type=text/css><!--
  19    TD, P, BODY {
  20      font-family: Verdana, Arial, sans-serif;
  21      font-size: 14px;
  22      color: #000000;
  23    }
  24  //--></style>
  25  </head>
  26  <body>
  27  <p>
  28  <b>osCommerce 2.2-CVS Orders Update Script</b>
  29  <p>
  30  This script updates inserts the order total information into the new
  31  orders_total table, which takes advantage of the new order_total modules.
  32  <p>
  33  <form name="database" action="update.php" method="post">
  34  <table border="0" cellspacing="2" cellpadding="2">
  35    <tr>
  36      <td colspan="2"><b>Database Server Information</b></td>
  37    </tr>
  38    <tr>
  39      <td>Server:</td>
  40      <td><input type="text" name="DB_SERVER"> <small>(eg, 192.168.0.1)</small></td>
  41    </tr>
  42    <tr>
  43      <td>Username:</td>
  44      <td><input type="text" name="DB_SERVER_USERNAME"> <small>(eg, root)</small></td>
  45    </tr>
  46    <tr>
  47      <td>Password:</td>
  48      <td><input type="text" name="DB_SERVER_PASSWORD"> <small>(eg, bee)</small></td>
  49    </tr>
  50    <tr>
  51      <td>Database:</td>
  52      <td><input type="text" name="DB_DATABASE"> <small>(eg, catalog)</small></td>
  53    </tr>
  54    <tr>
  55      <td colspan="2">&nbsp;</td>
  56    </tr>
  57    <tr>
  58      <td valign="top">orders_total Table:</td>
  59      <td><input type="text" name="OT_TABLE" value="orders_total"> <small>(eg, orders_total)</small><br><small>This table is dropped, created, then filled</small></td>
  60    </tr>
  61    <tr>
  62      <td colspan="2">&nbsp;</td>
  63    </tr>
  64    <tr>
  65      <td colspan="2"><input type="checkbox" name="DISPLAY_PRICES_WITH_TAX"> <b>Display Prices With Tax Included</b><br><small>Should the tax be added to the SubTotal? (the tax amount is still displayed)</small></td>
  66    </tr>
  67    <tr>
  68      <td colspan="2"><input type="checkbox" name="DISPLAY_MULTIPLE_TAXES"> <b>Display Multiple Tax Groups</b><br><small>If more than one tax rate is used, display the individual values, or as one global tax value?</small></td>
  69    </tr>
  70    <tr>
  71      <td colspan="2"><input type="checkbox" name="DISPLAY_SHIPPING"> <b>Display No/Free Shipping Charges</b><br><small>Display the shipping value if it equals $0.00?</small></td>
  72    </tr>
  73    <tr>
  74      <td colspan="2">&nbsp;</td>
  75    </tr>
  76    <tr>
  77      <td>Sub-Total Text:</td>
  78      <td><input type="text" name="OT_SUBTOTAL" value="Sub-Total:"> <small>(eg, Sub-Total:)</small></td>
  79    </tr>
  80    <tr>
  81      <td>Tax Text:</td>
  82      <td><input type="text" name="OT_TAX" value="Tax:"> <small>(eg, Tax:)</small></td>
  83    </tr>
  84    <tr>
  85      <td>Multiple Tax Groups Text:</td>
  86      <td><input type="text" name="OT_TAX_MULTIPLE" value="Tax (%s):"> <small>(eg, Tax (16%):)</small></td>
  87    </tr>
  88    <tr>
  89      <td>Shipping Text:</td>
  90      <td><input type="text" name="OT_SHIPPING" value="Shipping:"> <small>(eg, Shipping:)</small></td>
  91    </tr>
  92    <tr>
  93      <td>Total Text:</td>
  94      <td><input type="text" name="OT_TOTAL" value="Total:"> <small>(eg, Total:)</small></td>
  95    </tr>
  96    <tr>
  97      <td colspan="2">&nbsp;</td>
  98    </tr>
  99    <tr>
 100      <td>&nbsp;</td>
 101      <td><input type="submit" value="Submit"></td>
 102    </tr>
 103  </table>
 104  </form>
 105  </body>
 106  </html>
 107  <?php
 108      exit;
 109    }
 110  
 111    function tep_db_connect($link = 'db_link') {
 112      global $HTTP_POST_VARS, $$link;
 113  
 114      $$link = mysql_connect($HTTP_POST_VARS['DB_SERVER'], $HTTP_POST_VARS['DB_SERVER_USERNAME'], $HTTP_POST_VARS['DB_SERVER_PASSWORD']);
 115  
 116      if ($$link) mysql_select_db($HTTP_POST_VARS['DB_DATABASE']);
 117  
 118      return $$link;
 119    }
 120  
 121    function tep_db_error($query, $errno, $error) { 
 122      die('<font color="#000000"><b>' . $errno . ' - ' . $error . '<br><br>' . $query . '<br><br><small><font color="#ff0000">[TEP STOP]</font></small><br><br></b></font>');
 123    }
 124  
 125    function tep_db_query($query, $link = 'db_link') {
 126      global $$link;
 127  
 128      $result = mysql_query($query, $$link) or tep_db_error($query, mysql_errno(), mysql_error());
 129  
 130      return $result;
 131    }
 132  
 133    function tep_db_fetch_array($db_query) {
 134      return mysql_fetch_array($db_query, MYSQL_ASSOC);
 135    }
 136  
 137    function tep_db_num_rows($db_query) {
 138      return mysql_num_rows($db_query);
 139    }
 140  
 141    function tep_currency_format($number, $calculate_currency_value = true, $currency_code = DEFAULT_CURRENCY, $value = '') {
 142      $currency_query = tep_db_query("select symbol_left, symbol_right, decimal_point, thousands_point, decimal_places, value from currencies where code = '" . $currency_code . "'");
 143      $currency = tep_db_fetch_array($currency_query);
 144  
 145      if ($calculate_currency_value == true) {
 146        if (strlen($currency_code) == 3) {
 147          if ($value) {
 148            $rate = $value;
 149          } else {
 150            $rate = $currency['value'];
 151          }
 152        } else {
 153          $rate = 1;
 154        }
 155        $number2currency = $currency['symbol_left'] . number_format(($number * $rate), $currency['decimal_places'], $currency['decimal_point'], $currency['thousands_point']) . $currency['symbol_right'];
 156      } else {
 157        $number2currency = $currency['symbol_left'] . number_format($number, $currency['decimal_places'], $currency['decimal_point'], $currency['thousands_point']) . $currency['symbol_right'];
 158      }
 159  
 160      return $number2currency;
 161    }
 162  
 163    function tep_display_tax_value($value, $padding = TAX_DECIMAL_PLACES) {
 164      if (strpos($value, '.')) {
 165        $loop = true;
 166        while ($loop) {
 167          if (substr($value, -1) == '0') {
 168            $value = substr($value, 0, -1);
 169          } else {
 170            $loop = false;
 171            if (substr($value, -1) == '.') {
 172              $value = substr($value, 0, -1);
 173            }
 174          }
 175        }
 176      }
 177  
 178      if ($padding > 0) {
 179        if ($decimal_pos = strpos($value, '.')) {
 180          $decimals = strlen(substr($value, ($decimal_pos+1)));
 181          for ($i=$decimals; $i<$padding; $i++) {
 182            $value .= '0';
 183          }
 184        } else {
 185          $value .= '.';
 186          for ($i=0; $i<$padding; $i++) {
 187            $value .= '0';
 188          }
 189        }
 190      }
 191  
 192      return $value;
 193    }
 194  
 195    tep_db_connect() or die('Unable to connect to database server!');
 196  
 197    if (strlen($HTTP_POST_VARS['OT_TABLE']) > 0) {
 198      tep_db_query("drop table if exists " . $HTTP_POST_VARS['OT_TABLE']);
 199      tep_db_query("create table " . $HTTP_POST_VARS['OT_TABLE'] . " ( orders_total_id int unsigned not null auto_increment, orders_id int not null, title varchar(255) not null, text varchar(255) not null, value decimal(8,2) not null, class varchar(32) not null, sort_order int not null, primary key (orders_total_id), key idx_orders_total_orders_id (orders_id))");
 200    }
 201  
 202    $i = 0;
 203    $orders_query = tep_db_query("select orders_id, shipping_method, shipping_cost, currency, currency_value from orders");
 204    while ($orders = tep_db_fetch_array($orders_query)) {
 205      $o = array();
 206      $total_cost = 0;
 207  
 208      $o['id'] = $orders['orders_id'];
 209      $o['shipping_method'] = $orders['shipping_method'];
 210      $o['shipping_cost'] = $orders['shipping_cost'];
 211      $o['currency'] = $orders['currency'];
 212      $o['currency_value'] = $orders['currency_value'];
 213      $o['tax'] = 0;
 214  
 215      $orders_products_query = tep_db_query("select final_price, products_tax, products_quantity from orders_products where orders_id = '" . $orders['orders_id'] . "'");
 216      while ($orders_products = tep_db_fetch_array($orders_products_query)) {
 217        $o['products'][$i]['final_price'] = $orders_products['final_price'];
 218        $o['products'][$i]['qty'] = $orders_products['products_quantity'];
 219  
 220        $o['products'][$i]['tax_groups']["{$orders_products['products_tax']}"] += $orders_products['products_tax']/100 * ($orders_products['final_price'] * $orders_products['products_quantity']);
 221        $o['tax'] += $orders_products['products_tax']/100 * ($orders_products['final_price'] * $orders_products['products_quantity']);
 222  
 223        $total_cost += ($o['products'][$i]['final_price'] * $o['products'][$i]['qty']);
 224      }
 225  
 226      if ($HTTP_POST_VARS['DISPLAY_PRICES_WITH_TAX'] == 'on') {
 227        $subtotal_text = tep_currency_format($total_cost + $o['tax'], true, $o['currency'], $o['currency_value']);
 228        $subtotal_value = $total_cost + $o['tax'];
 229      } else {
 230        $subtotal_text = tep_currency_format($total_cost, true, $o['currency'], $o['currency_value']);
 231        $subtotal_value = $total_cost;
 232      }
 233  
 234      tep_db_query("insert into " . $HTTP_POST_VARS['OT_TABLE'] . " (orders_total_id, orders_id, title, text, value, class, sort_order) values ('', '" . $o['id'] . "', '" . $HTTP_POST_VARS['OT_SUBTOTAL'] . "', '" . $subtotal_text . "', '" . $subtotal_value . "', 'ot_subtotal', '1')");
 235  
 236      if ($HTTP_POST_VARS['DISPLAY_MULTIPLE_TAXES'] == 'on') {
 237        @reset($o['products'][$i]['tax_groups']);
 238        while (@list($key, $value) = each($o['products'][$i]['tax_groups'])) {
 239          $tax_text = tep_currency_format($value, true, $o['currency'], $o['currency_value']);
 240          $tax_value = $value;
 241          tep_db_query("insert into " . $HTTP_POST_VARS['OT_TABLE'] . " (orders_total_id, orders_id, title, text, value, class, sort_order) values ('', '" . $o['id'] . "', '" . sprintf($HTTP_POST_VARS['OT_TAX_MULTIPLE'], tep_display_tax_value($key) . '%') . "', '" . $tax_text . "', '" . $tax_value . "', 'ot_tax', '2')");
 242        }
 243      } else {
 244        $tax_text = tep_currency_format($o['tax'], true, $o['currency'], $o['currency_value']);
 245        $tax_value = $o['tax'];
 246        tep_db_query("insert into " . $HTTP_POST_VARS['OT_TABLE'] . " (orders_total_id, orders_id, title, text, value, class, sort_order) values ('', '" . $o['id'] . "', '" . $HTTP_POST_VARS['OT_TAX'] . "', '" . $tax_text . "', '" . $tax_value . "', 'ot_tax', '2')");
 247      }
 248  
 249      if (strlen($o['shipping_method']) < 1) {
 250        $o['shipping_method'] = $HTTP_POST_VARS['OT_SHIPPING'];
 251      } else {
 252        $o['shipping_method'] .= ':';
 253      }
 254      if ($HTTP_POST_VARS['DISPLAY_SHIPPING'] == 'on') {
 255        $shipping_text = tep_currency_format($o['shipping_cost'], true, $o['currency'], $o['currency_value']);
 256        $shipping_value = $o['shipping_cost'];
 257        tep_db_query("insert into " . $HTTP_POST_VARS['OT_TABLE'] . " (orders_total_id, orders_id, title, text, value, class, sort_order) values ('', '" . $o['id'] . "', '" . $o['shipping_method'] . "', '" . $shipping_text . "', '" . $shipping_value . "', 'ot_shipping', '3')");
 258      } elseif ($o['shipping_cost'] > 0) {
 259        $shipping_text = tep_currency_format($o['shipping_cost'], true, $o['currency'], $o['currency_value']);
 260        $shipping_value = $o['shipping_cost'];
 261        tep_db_query("insert into " . $HTTP_POST_VARS['OT_TABLE'] . " (orders_total_id, orders_id, title, text, value, class, sort_order) values ('', '" . $o['id'] . "', '" . $o['shipping_method'] . "', '" . $shipping_text . "', '" . $shipping_value . "', 'ot_shipping', '3')");
 262      }
 263  
 264      $total_text = tep_currency_format($total_cost + $o['tax'] + $o['shipping_cost'], true, $o['currency'], $o['currency_value']);
 265      $total_value = $total_cost + $o['tax'] + $o['shipping_cost'];
 266      tep_db_query("insert into " . $HTTP_POST_VARS['OT_TABLE'] . " (orders_total_id, orders_id, title, text, value, class, sort_order) values ('', '" . $o['id'] . "', '" . $HTTP_POST_VARS['OT_TOTAL'] . "', '" . $total_text . "', '" . $total_value . "', 'ot_total', '4')");
 267  
 268      $i++;
 269    }
 270  ?>
 271  Done!


Généré le : Mon Nov 26 19:48:25 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics