[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/admin/ -> stock.php (source)

   1  <?php
   2  /*

   3        QT Pro Version 4.1

   4    

   5        stock.php

   6    

   7        Contribution extension to:

   8          osCMax Power E-Commerce

   9          http://oscdox.com

  10       

  11        Copyright 2006 osCMax2004, 2005 Ralph Day

  12        Released under the GNU General Public License

  13    

  14        Based on prior works released under the GNU General Public License:

  15          QT Pro prior versions

  16            Ralph Day, October 2004

  17            Tom Wojcik aka TomThumb 2004/07/03 based on work by Michael Coffman aka coffman

  18            FREEZEHELL - 08/11/2003 [email protected] Copyright 2006 osCMax2003 IBWO

  19            Joseph Shain, January 2003

  20          osCommerce MS2

  21            Copyright 2006 osCMax

  22            

  23        Modifications made:

  24          11/2004 - Add input validation

  25                    clean up register globals off problems

  26                    use table name constant for products_stock instead of hard coded table name

  27          03/2005 - Change $_SERVER to $HTTP_SERVER_VARS for compatibility with older php versions

  28          

  29  *******************************************************************************************

  30    

  31        QT Pro Stock Add/Update

  32    

  33        This is a page to that is linked from the osCommerce admin categories page when an

  34        item is selected.  It displays a products attributes stock and allows it to be updated.

  35  

  36  *******************************************************************************************

  37  

  38  $Id: stock.php 14 2006-07-28 17:42:07Z user $

  39  

  40    Enhancement module for osCMax Power E-Commerce

  41    http://oscdox.com

  42    

  43    Credit goes to original QTPRO developer.

  44    Attributes Inventory - FREEZEHELL - 08/11/2003 [email protected]

  45    Copyright 2006 osCMax2003 IBWO

  46  

  47    Released under the GNU General Public License

  48  */
  49    require ('includes/application_top.php');
  50  
  51    if ($HTTP_SERVER_VARS['REQUEST_METHOD']=="GET") {
  52      $VARS=$_GET;
  53    } else {
  54      $VARS=$_POST;
  55    }
  56    if ($VARS['action']=="Add") {
  57      $inputok = true;
  58      if (!(is_numeric($VARS['product_id']) and ($VARS['product_id']==(int)$VARS['product_id']))) $inputok = false;
  59      while(list($v1,$v2)=each($VARS)) {
  60        if (preg_match("/^option(\d+)$/",$v1,$m1)) {
  61          if (is_numeric($v2) and ($v2==(int)$v2)) $val_array[]=$m1[1]."-".$v2;
  62          else $inputok = false;
  63        }
  64      }
  65      if (!(is_numeric($VARS['quantity']) and ($VARS['quantity']==(int)$VARS['quantity']))) $inputok = false;
  66  
  67      if (($inputok)) {
  68        sort($val_array, SORT_NUMERIC);
  69        $val=join(",",$val_array);
  70        $q=tep_db_query("select products_stock_id as stock_id from " . TABLE_PRODUCTS_STOCK . " where products_id=" . (int)$VARS['product_id'] . " and products_stock_attributes='" . $val . "' order by products_stock_attributes");
  71        if (tep_db_num_rows($q)>0) {
  72          $stock_item=tep_db_fetch_array($q);
  73          $stock_id=$stock_item[stock_id];
  74          if ($VARS['quantity']=intval($VARS['quantity'])) {
  75            tep_db_query("update " . TABLE_PRODUCTS_STOCK . " set products_stock_quantity=" . (int)$VARS['quantity'] . " where products_stock_id=$stock_id");
  76          } else {
  77            tep_db_query("delete from " . TABLE_PRODUCTS_STOCK . " where products_stock_id=$stock_id");
  78          }
  79        } else {
  80          tep_db_query("insert into " . TABLE_PRODUCTS_STOCK . " values (0," . (int)$VARS['product_id'] . ",'$val'," . (int)$VARS['quantity'] . ")");
  81        }
  82        $q=tep_db_query("select sum(products_stock_quantity) as summa from " . TABLE_PRODUCTS_STOCK . " where products_id=" . (int)$VARS['product_id'] . " and products_stock_quantity>0");
  83        $list=tep_db_fetch_array($q);
  84        $summa= (empty($list[summa])) ? 0 : $list[summa];
  85        tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity=$summa where products_id=" . (int)$VARS['product_id']);
  86        if (($summa<1) && (STOCK_ALLOW_CHECKOUT == 'false')) {
  87          tep_db_query("update " . TABLE_PRODUCTS . " set products_status='0' where products_id=" . (int)$VARS['product_id']);
  88        }
  89      }
  90    }
  91    if ($VARS['action']=="Update") {
  92      tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity=" . (int)$VARS['quantity'] . " where products_id=" . (int)$VARS['product_id']);
  93      if (($VARS['quantity']<1) && (STOCK_ALLOW_CHECKOUT == 'false')) {
  94        tep_db_query("update " . TABLE_PRODUCTS . " set products_status='0' where products_id=" . (int)$VARS['product_id']);
  95      }
  96    }
  97    if ($VARS['action']=="Apply to all") {
  98  
  99    }
 100    $q=tep_db_query($sql="select products_name,products_options_name as _option,products_attributes.options_id as _option_id,products_options_values_name as _value,products_attributes.options_values_id as _value_id from ".
 101                    "products_description, products_attributes,products_options,products_options_values where ".
 102                    "products_attributes.products_id=products_description.products_id and ".
 103                    "products_attributes.products_id=" . (int)$VARS['product_id'] . " and ".
 104                    "products_attributes.options_id=products_options.products_options_id and ".
 105                    "products_attributes.options_values_id=products_options_values.products_options_values_id and ".
 106                    "products_description.language_id=" . (int)$languages_id . " and ".
 107                    "products_options_values.language_id=" . (int)$languages_id . " and products_options.products_options_track_stock=1 and ".
 108                    "products_options.language_id=" . (int)$languages_id . " order by products_attributes.options_id, products_attributes.options_values_id");
 109   //list($product_name,$option_name,$option_id,$value,$value_id)

 110    if (tep_db_num_rows($q)>0) {
 111      $flag=1;
 112      while($list=tep_db_fetch_array($q)) {
 113        $options[$list[_option_id]][]=array($list[_value],$list[_value_id]);
 114        $option_names[$list[_option_id]]=$list[_option];
 115        $product_name=$list[products_name];
 116      }
 117    } else {
 118      $flag=0;
 119      $q=tep_db_query("select products_quantity,products_name from " . TABLE_PRODUCTS . " p,products_description pd where pd.products_id=" . (int)$VARS['product_id'] . " and p.products_id=" . (int)$VARS['product_id']);
 120      $list=tep_db_fetch_array($q);
 121      $db_quantity=$list[products_quantity];
 122      $product_name=stripslashes($list[products_name]);
 123    }
 124  ?>
 125  <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
 126  <html <?php echo HTML_PARAMS; ?>>
 127  <head>
 128  <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
 129  <title><?php echo TITLE; ?></title>
 130  <link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
 131  </head>
 132  <body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
 133  <!-- header //-->
 134  <?php require (DIR_WS_INCLUDES . 'header.php'); ?>
 135  <!-- header_eof //-->
 136  
 137  <!-- body //-->
 138  <table border="0" width="100%" cellspacing="2" cellpadding="2">
 139    <tr>
 140      <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
 141  <!-- left_navigation //-->
 142  <?php require (DIR_WS_INCLUDES . 'column_left.php'); ?>
 143  <!-- left_navigation_eof //-->
 144      </table></td>
 145  <!-- body_text //-->
 146      <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
 147        <tr>
 148          <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
 149            <tr>
 150              <td class="pageHeading"><?php echo PRODUCTS_STOCK.": $product_name"; ?></td>
 151              <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
 152            </tr>
 153          </table></td>
 154        </tr>
 155        <tr>
 156          <td><form action="<?php echo $PHP_SELF;?>" method=get>
 157          <table border="0" width="100%" cellspacing="0" cellpadding="0">
 158            <tr>
 159              <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
 160                <tr class="dataTableHeadingRow">
 161  <?php
 162    $title_num=1;
 163    if ($flag) {
 164      while(list($k,$v)=each($options)) {
 165        echo "<td class=\"dataTableHeadingContent\">&nbsp;&nbsp;$option_names[$k]</td>";
 166        $title[$title_num]=$k;
 167      }
 168      echo "<td class=\"dataTableHeadingContent\"><span class=smalltext>Quantity</span></td><td width=\"100%\">&nbsp;</td>";
 169      echo "</tr>";
 170      $q=tep_db_query("select * from " . TABLE_PRODUCTS_STOCK . " where products_id=" . $VARS['product_id'] . " order by products_stock_attributes");
 171      while($rec=tep_db_fetch_array($q)) {
 172        $val_array=explode(",",$rec[products_stock_attributes]);
 173        echo "<tr>";
 174        foreach($val_array as $val) {
 175          if (preg_match("/^(\d+)-(\d+)$/",$val,$m1)) {
 176            echo "<td class=smalltext>&nbsp;&nbsp;&nbsp;".tep_values_name($m1[2])."</td>";
 177          } else {
 178            echo "<td>&nbsp;</td>";
 179          }
 180        }
 181        for($i=0;$i<sizeof($options)-sizeof($val_array);$i++) {
 182          echo "<td>&nbsp;</td>";
 183        }
 184        echo "<td class=smalltext>&nbsp;&nbsp;&nbsp;&nbsp;$rec[products_stock_quantity]</td><td>&nbsp;</td></tr>";
 185      }
 186      echo "<tr>";
 187      reset($options);
 188      $i=0;
 189      while(list($k,$v)=each($options)) {
 190        echo "<td class=dataTableHeadingRow><select name=option$k>";
 191        foreach($v as $v1) {
 192          echo "<option value=".$v1[1].">".$v1[0];
 193        }
 194        echo "</select></td>";
 195        $i++;
 196      }
 197    } else {
 198      $i=1;
 199      echo "<td class=dataTableHeadingContent>Quantity</td>";
 200    }
 201    echo "<td class=dataTableHeadingRow><input type=text name=quantity size=4 value=\"" . $db_quantity . "\"><input type=hidden name=product_id value=\"" . $VARS['product_id'] . "\">&nbsp;</td><td width=\"100%\" class=dataTableHeadingRow>&nbsp;<input type=submit name=action value=" . ($flag?"Add":"Update") . ">&nbsp;</td><td width=\"100%\" class=dataTableHeadingRow>&nbsp;</td>";
 202  ?>
 203                </tr>
 204              </table></td>
 205            </tr>
 206          </table>
 207          </form></td>
 208        </tr>
 209  <tr><td><br>
 210  <?php  echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, '', 'NONSSL') . '" class="menuBoxContentLink">Back to Products Category</a> &nbsp;&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_STATS_LOW_STOCK_ATTRIB, '', 'NONSSL') . '" class="menuBoxContentLink">Back to Low Stock Report for Attributes</a>';?>
 211  </td></tr>
 212      </table></td>
 213  <!-- body_text_eof //-->
 214    </tr>
 215  </table>
 216  <!-- body_eof //-->
 217  
 218  <!-- footer //-->
 219  <?php require (DIR_WS_INCLUDES . 'footer.php'); ?>
 220  <!-- footer_eof //-->
 221  <br>
 222  </body>
 223  </html>
 224  <?php require (DIR_WS_INCLUDES . 'application_bottom.php'); ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7