[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/includes/classes/ -> pad_multiple_dropdowns.php (source)

   1  <?php
   2  /*

   3        QT Pro Version 4.1

   4    

   5        pad_multiple_dropdowns.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        Modifications made:

  23            11/2004 - Created

  24            12/2004 - Fix _draw_out_of_stock_message_js to add semicolon to end of js stock array

  25            03/2005 - Remove '&' for pass by reference from parameters to call of

  26                      _build_attributes_combinations.  Only needed on method definition and causes

  27                      error messages on some php versions/configurations

  28    

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

  30    

  31        QT Pro Product Attributes Display Plugin

  32    

  33        pad_multiple_dropdowns.php - Display stocked product attributes first as one dropdown for each attribute.

  34    

  35        Class Name: pad_multiple_dropdowns

  36    

  37        This class generates the HTML to display product attributes.  First, product attributes that

  38        stock is tracked for are displayed, each attribute in its own dropdown list.  Then attributes that

  39        stock is not tracked for are displayed, each attribute in its own dropdown list.

  40        

  41        Methods overidden or added:

  42    

  43          _draw_stocked_attributes            draw attributes that stock is tracked for

  44          _draw_out_of_stock_message_js       draw Javascript to display out of stock message for out of

  45                                              stock attribute combinations

  46  */
  47    require_once (DIR_WS_CLASSES . 'pad_base.php');
  48  
  49    class pad_multiple_dropdowns extends pad_base {
  50  
  51  
  52  /*

  53      Method: _draw_stocked_attributes

  54    

  55      draw dropdown lists for attributes that stock is tracked for

  56  

  57    

  58      Parameters:

  59    

  60        none

  61    

  62      Returns:

  63    

  64        string:         HTML to display dropdown lists for attributes that stock is tracked for

  65    

  66  */
  67      function _draw_stocked_attributes() {
  68        global $languages_id;
  69        
  70        $out='';
  71        
  72        $attributes = $this->_build_attributes_array(true, false);
  73        if (sizeof($attributes)>0) {
  74          for($o=0; $o<sizeof($attributes); $o++) {
  75            $s=sizeof($attributes[$o]['ovals']);
  76            for ($a=0; $a<$s; $a++) {
  77              $attribute_stock_query = tep_db_query("select products_stock_quantity from " . TABLE_PRODUCTS_STOCK . " where products_id = '" . (int)$this->products_id . "' AND products_stock_attributes REGEXP '(^|,)" . (int)$attributes[$o]['oid'] . "-" . (int)$attributes[$o]['ovals'][$a]['id'] . "(,|$)' AND products_stock_quantity > 0");
  78              $out_of_stock=(tep_db_num_rows($attribute_stock_query)==0);
  79              if ($out_of_stock && ($this->show_out_of_stock == 'True')) {
  80                switch ($this->mark_out_of_stock) {
  81                  case 'Left':   $attributes[$o]['ovals'][$a]['text']=TEXT_OUT_OF_STOCK.' - '.$attributes[$o]['ovals'][$a]['text'];
  82                                 break;
  83                  case 'Right':  $attributes[$o]['ovals'][$a]['text'].=' - '.TEXT_OUT_OF_STOCK;
  84                                 break;
  85                }
  86              }
  87              elseif ($out_of_stock && ($this->show_out_of_stock != 'True')) {
  88                unset($attributes[$o]['ovals'][$a]);
  89              }
  90            }
  91            $out.='<tr><td align="right" class=main><b>'.$attributes[$o]['oname'].":</b></td><td class=main>".tep_draw_pull_down_menu('id['.$attributes[$o]['oid'].']',array_values($attributes[$o]['ovals']),$attributes[$o]['default'], "onchange=\"stkmsg(this.form);\"")."</td></tr>\n";
  92          }        
  93          $out.=$this->_draw_out_of_stock_message_js($attributes);
  94          
  95          return $out;
  96        }
  97      }
  98  
  99  
 100  /*

 101      Method: _draw_out_of_stock_message_js

 102    

 103      draw Javascript to display out of stock message for out of stock attribute combinations

 104  

 105    

 106      Parameters:

 107    

 108        $attributes     array   Array of attributes for the product.  Format is as returned by

 109                                _build_attributes_array.

 110    

 111      Returns:

 112    

 113        string:         Javascript to display out of stock message for out of stock attribute combinations

 114    

 115  */
 116      function _draw_out_of_stock_message_js($attributes) {
 117        $out='';
 118        
 119        $out.="<tr><td>&nbsp</td><td><span id=\"oosmsg\" class=errorBox></span>\n";
 120    
 121        if (($this->out_of_stock_msgline == 'True' | $this->no_add_out_of_stock == 'True')) {
 122          $out.="<SCRIPT LANGUAGE=\"JavaScript\"><!--\n";
 123          $combinations = array();
 124          $selected_combination = 0;
 125          $this->_build_attributes_combinations($attributes, false, 'None', $combinations, $selected_combination);
 126          
 127          $out.="  function chkstk(frm) {\n";
 128        
 129          // build javascript array of in stock combinations

 130          $out.="    var stk=".$this->_draw_js_stock_array($combinations).";\n";
 131          $out.="    var instk=false;\n";
 132        
 133          // build javascript if statement to test level by level for existance  

 134          $out.='    ';
 135          for ($i=0; $i<sizeof($attributes); $i++) {
 136            $out.='if (stk';
 137            for ($j=0; $j<=$i; $j++) {
 138              $out.="[frm['id[".$attributes[$j]['oid']."]'].value]";
 139            }
 140            $out.=') ';
 141          }
 142          
 143          $out.="instk=true;\n";
 144          $out.="  return instk;\n";
 145          $out.="  }\n";
 146  
 147          if ($this->out_of_stock_msgline == 'True') {
 148            // set/reset out of stock message based on selection

 149            $out.="  function stkmsg(frm) {\n";
 150            $out.="    var instk=chkstk(frm);\n";
 151            $out.="    var span=document.getElementById(\"oosmsg\");\n";
 152            $out.="    while (span.childNodes[0])\n";
 153            $out.="      span.removeChild(span.childNodes[0]);\n";
 154            $out.="    if (!instk)\n";
 155            $out.="      span.appendChild(document.createTextNode(\"".TEXT_OUT_OF_STOCK_MESSAGE."\"));\n";
 156            $out.="    else\n";
 157            $out.="      span.appendChild(document.createTextNode(\" \"));\n";
 158            $out.="  }\n";
 159            //initialize out of stock message

 160            $out.="  stkmsg(document.cart_quantity);\n";
 161          }
 162        
 163          if ($this->no_add_out_of_stock == 'True') {
 164            // js to not allow add to cart if selection is out of stock

 165            $out.="  function chksel() {\n";
 166            $out.="    var instk=chkstk(document.cart_quantity);\n";
 167            $out.="    if (!instk) alert('".TEXT_OUT_OF_STOCK_MESSAGE."');\n";
 168            $out.="    return instk;\n";
 169            $out.="  }\n";
 170            $out.="  document.cart_quantity.onsubmit=chksel;\n";
 171          }
 172          $out.="//--></SCRIPT>\n";
 173        }
 174        $out.="</td></tr>\n";
 175        
 176        return $out;
 177      }
 178  
 179    }
 180  ?>


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