Difference between revisions of "VbzCart/archive/code/files/store.php"

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
< VbzCart‎ | archive‎ | code‎ | files
Jump to navigation Jump to search
(basically working... totally different: is an actual class library now)
 
(3 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
* '''History''':
 
* '''History''':
 
** '''2009-03-07''' Transcribed from working code at vbz.net
 
** '''2009-03-07''' Transcribed from working code at vbz.net
 +
** '''2009-10-06''' Latest code - large chunks working, focus of development no longer on this module
 +
** '''2011-12-18''' long-overdue update
 
* '''To Do''':
 
* '''To Do''':
 
** should be split up into auto-loadable class files, e.g. vbz.title.php, vbz.dept.php, etc.
 
** should be split up into auto-loadable class files, e.g. vbz.title.php, vbz.dept.php, etc.
Line 13: Line 15:
 
  HISTORY:
 
  HISTORY:
 
   2009-07-11 (Wzl) Lots of cleanup; added types and methods needed for shopping cart page
 
   2009-07-11 (Wzl) Lots of cleanup; added types and methods needed for shopping cart page
 +
  2009-10-06 (Wzl) Changed most clsTitle* classes to clsVbzTitle* (conflict with something - w3tpl?)
 +
    Additional changes needed so it would work on Rizzo
 +
  2010-06-12 (Wzl) A little cleanup; clsTopic::Titles()
 +
  2010-06-14 (Wzl) clsVbzTable::GetItem() handles non-numeric IDs by creating new object and passing along ID
 +
  2011-01-18 (Wzl) moved clsTopic(s) to topic.php
 
*/
 
*/
//define('kfpHostAcctRoot','/hsphere/local/home/hypertwi/');
 
//define('kfpMediaWiki',kfpHostAcctRoot.'wiki.vbz.net/');
 
 
define('kEmbeddedPagePrefix','embed:');
 
define('kEmbeddedPagePrefix','embed:');
  
 +
/*
 
if (defined( '__DIR__' )) {
 
if (defined( '__DIR__' )) {
 
   $fpThis = __DIR__;
 
   $fpThis = __DIR__;
Line 23: Line 29:
 
   $fpThis = dirname(__FILE__);
 
   $fpThis = dirname(__FILE__);
 
}
 
}
 +
*/
 
if (!defined('LIBMGR')) {
 
if (!defined('LIBMGR')) {
     require('libmgr.php');
+
     require(KFP_LIB.'/libmgr.php');
 
}
 
}
clsLibMgr::Add('datamgr',$fpThis.'/datamgr.php');
+
clsLibMgr::Add('strings', KFP_LIB.'/strings.php',__FILE__,__LINE__);
clsLibMgr::Load('datamgr');
+
clsLibMgr::Add('string.tplt', KFP_LIB.'/StringTemplate.php',__FILE__,__LINE__);
 +
clsLibMgr::Add('cache' , KFP_LIB.'/cache.php',__FILE__,__LINE__);
 +
clsLibMgr::Add('dtree', KFP_LIB.'/dtree.php',__FILE__,__LINE__);
 +
clsLibMgr::Add('events', KFP_LIB.'/events.php',__FILE__,__LINE__);
 +
clsLibMgr::Add('vbz.data', KFP_LIB_VBZ.'/vbz-data.php',__FILE__,__LINE__);
 +
clsLibMgr::Add('topic', KFP_LIB_VBZ.'/topic.php',__FILE__,__LINE__);
 +
 
 +
clsLibMgr::Load('strings',__FILE__,__LINE__);
 +
clsLibMgr::Load('string.tplt',__FILE__,__LINE__);
 +
clsLibMgr::Load('cache',__FILE__,__LINE__);
 +
clsLibMgr::Load('dtree',__FILE__,__LINE__);
 +
clsLibMgr::Load('events',__FILE__,__LINE__);
 +
clsLibMgr::Load('vbz.data',__FILE__,__LINE__);
 +
clsLibMgr::Load('topic',__FILE__,__LINE__);
  
 
define('EN_PGTYPE_NOTFND',-1); // requested item (supp/dept/title) not found
 
define('EN_PGTYPE_NOTFND',-1); // requested item (supp/dept/title) not found
Line 35: Line 55:
 
define('EN_PGTYPE_TITLE',4); // title page
 
define('EN_PGTYPE_TITLE',4); // title page
 
// table names
 
// table names
// - caching
 
define('ksTbl_cache_tables','data_tables');
 
define('ksTbl_cache_procs','data_procs');
 
define('ksTbl_cache_flow','data_flow');
 
define('ksTbl_cache_log','data_log');
 
 
// - stock
 
// - stock
 
define('ksTbl_stock_places','stk_places');
 
define('ksTbl_stock_places','stk_places');
Line 47: Line 62:
 
define('ksTbl_stock_hist_items','stk_history');
 
define('ksTbl_stock_hist_items','stk_history');
 
define('ksTbl_stock_hist_bins','stk_bin_history');
 
define('ksTbl_stock_hist_bins','stk_bin_history');
 +
// - browsing
 +
define('ksTbl_title_topics','brs_titles_x_topics');
  
 +
global $vbgImgSize;
 
$vbgImgSize = array(
 
$vbgImgSize = array(
 
     'th' => 'thumbnail',
 
     'th' => 'thumbnail',
Line 55: Line 73:
 
     'zoom' => 'detail');
 
     'zoom' => 'detail');
  
// shipping charge adjustment factors by destination zone:
+
// shipping zone data:
 +
global $listShipListDesc,$listItmFactors,$listPkgFactors; // there's got to be a better way to do this...
 
$listShipListDesc['US'] = 'United States';
 
$listShipListDesc['US'] = 'United States';
 
$listShipListDesc['CA'] = 'Canada';
 
$listShipListDesc['CA'] = 'Canada';
 
$listShipListDesc['INT'] = 'International';
 
$listShipListDesc['INT'] = 'International';
 +
// -- shipping charge adjustment factors:
 
$listPkgFactors['US'] = 1.0;
 
$listPkgFactors['US'] = 1.0;
 
$listItmFactors['US'] = 1.0;
 
$listItmFactors['US'] = 1.0;
Line 75: Line 95:
 
$fwpAbsTools = 'http://'.KS_TOOLS_SERVER.$fpTools;
 
$fwpAbsTools = 'http://'.KS_TOOLS_SERVER.$fpTools;
 
$fwpCart = $fwpAbsPages.'/cart/';
 
$fwpCart = $fwpAbsPages.'/cart/';
$strCurServer = $_ENV['SERVER_NAME'];
+
$strCurServer = $_SERVER['SERVER_NAME'];
  
 
// SET UP DEPENDENT VALUES
 
// SET UP DEPENDENT VALUES
Line 86: Line 106:
 
$fwpLogo = $fpTools.'/img/logos/v/';
 
$fwpLogo = $fpTools.'/img/logos/v/';
  
class clsVbzData extends clsDatabase {
+
/*====
   private $objPages;
+
  NOTES:
 +
    2011-02-02 This could use some rewriting. A lot of it is kind of pointless,
 +
      and other parts duplicate RichText objects.
 +
*/
 +
class clsPageOutput {
 +
  public $out;
 +
   private $isOdd;
 +
  public $inTbl;
  
   public function __construct($iSpec) {
+
   function __construct() {
     global $objDataMgr;
+
     $this->out = '';
 
+
     $this->isOdd = false;
     parent::__construct($iSpec);
+
     $this->inTbl = 0;
    $objDataMgr = new clsDataMgr($this,ksTbl_cache_tables,ksTbl_cache_procs,ksTbl_cache_flow,ksTbl_cache_log);
 
     $this->Open();
 
 
   }
 
   }
// generic object-creation function
+
   function Clear() {
   protected function Make($iName) {
+
     $this->out = '';
     if (!isset($this->$iName)) {
 
      $this->$iName = new $iName($this);
 
    }
 
    return $this->$iName;
 
 
   }
 
   }
// table-specific functions
+
   function AddText($iText) {
   public function Pages() {
+
     $this->out .= $iText;
     return $this->Make('clsCatPages');
 
 
   }
 
   }
   public function Suppliers() {
+
   function SectionHdr($iTitle) { // this is specifically duplicated
     return $this->Make('clsSuppliers');
+
     $this->out .= '<p class="hdr-sub">'.$iTitle.'</p>';
 +
    return $this->out;
 
   }
 
   }
   public function Depts() {
+
   function StartTable($iTitle) {
     return $this->Make('clsDepts');
+
     if ($iTitle) {
 +
      $this->SectionHdr($iTitle);
 +
      $this->out .= '<table class=content>';
 +
      $this->inTbl++;
 +
    }
 
   }
 
   }
   public function Titles() {
+
   function RowStart($iClass='') {
     return $this->Make('clsTitles');
+
    if ($iClass) {
 +
      $this->out .= '<tr class="'.$iClass.'">';
 +
     } else {
 +
      $this->out .= '<tr>';
 +
    }
 
   }
 
   }
   public function TitlesExt() {
+
   function RowStop() {
     return $this->Make('clsTitlesExt');
+
     $this->out .= '</tr>';
 +
    $this->isOdd = !$this->isOdd;
 
   }
 
   }
   public function Items() {
+
   function ColAdd($iText) {
     return $this->Make('clsItems');
+
     if ($this->isOdd) {
 +
      $cellOpen = '<td class=catalog-stripe valign=top>';
 +
    } else {
 +
      $cellOpen = '<td class=catalog valign=top>';
 +
    }
 +
    $this->out .= $cellOpen.$iText.'</td>';
 
   }
 
   }
   public function Items_Stock() {
+
   function EndTable() {
     return $this->Make('clsItems_Stock');
+
     if ($this->inTbl) {
 +
      $this->out .= '</table>';
 +
      $this->inTbl--;
 +
    }
 +
    return $this->out;
 
   }
 
   }
   public function ItTyps() {
+
   function ShowImgUnavail() {
     return $this->Make('clsItTyps');
+
     $this->out .= '<table class=border cellpadding="5"><tbody><tr><td><table class="hdr" cellpadding="2"><tbody><tr><td align="center"><span class="page-title">No Images<br>Available<br></span>for this item<br><b>:-(</b></td></tr></tbody></table></td></tr></tbody></table>';
  }
+
     return $this->out;
  public function ItOpts() {
 
    return $this->Make('clsItOpts');
 
  }
 
  public function ShipCosts() {
 
    return $this->Make('clsShipCosts');
 
  }
 
  public function Images() {
 
    return $this->Make('clsImages');
 
  }
 
  public function StkItems() {
 
    return $this->Make('clsStkItems');
 
  }
 
  public function Topics() {
 
    return $this->Make('clsTopics');
 
  }
 
  public function Events() {
 
    return $this->Make('clsEvents');
 
  }
 
  public function LogEvent($iWhere,$iParams,$iDescr,$iCode,$iIsError,$iIsSevere) {
 
     return $this->Events()->LogEvent($iWhere,$iParams,$iDescr,$iCode,$iIsError,$iIsSevere);
 
 
   }
 
   }
 +
}
 +
class clsCacheFile_vbz extends clsCacheFile {
 +
    public function __construct() {
 +
parent::__construct(KFP_CACHE);
 +
    }
 +
}
 +
class clsVbzData extends clsDatabase {
 +
    protected $objPages;
 +
 +
    public function __construct($iSpec) {
 +
parent::__construct($iSpec);
 +
$this->Open();
 +
    }
 +
// cache manager
 +
    protected function CacheMgr_empty() {
 +
return new clsCacheMgr($this);
 +
    }
 +
    public function CacheMgr() {
 +
if (empty($this->objCacheMgr)) {
 +
    $objCache = $this->CacheMgr_empty();
 +
    $objCache->SetTables('cache_tables','cache_queries','cache_flow','cache_log');
 +
    $this->objCacheMgr = $objCache;
 +
}
 +
return $this->objCacheMgr;
 +
    }
 +
// table-specific functions
 +
    public function Pages() {
 +
return $this->Make('clsCatPages');
 +
    }
 +
    public function Suppliers() {
 +
return $this->Make('clsSuppliers');
 +
    }
 +
    public function Depts() {
 +
return $this->Make('clsDepts');
 +
    }
 +
    public function Titles($iID=NULL) {
 +
return $this->Make('clsVbzTitles',$iID);
 +
    }
 +
    public function Items() {
 +
return $this->Make('clsItems');
 +
    }
 +
    public function Items_Stock() {
 +
return $this->Make('clsItems_Stock');
 +
    }
 +
    public function Items_Cat() {
 +
return $this->Make('clsItems_info_Cat');
 +
    }
 +
    public function ItTyps() {
 +
return $this->Make('clsItTyps');
 +
    }
 +
    public function ItOpts() {
 +
return $this->Make('clsItOpts');
 +
    }
 +
    public function ShipCosts() {
 +
return $this->Make('clsShipCosts');
 +
    }
 +
    public function Folders() {
 +
return $this->Make('clsVbzFolders');
 +
    }
 +
    public function Images() {
 +
return $this->Make('clsImages');
 +
    }
 +
    public function StkItems() {
 +
return $this->Make('clsStkItems');
 +
    }
 +
    public function Topics($iID=NULL) {
 +
return $this->Make('clsTopics',$iID);
 +
    }
 +
    public function TitleTopic_Titles() {
 +
return $this->Make('clsTitleTopic_Titles');
 +
    }
 +
    public function TitleTopic_Topics() {
 +
return $this->Make('clsTitleTopic_Topics');
 +
    }
 +
    public function VarsGlobal() {
 +
return $this->Make('clsGlobalVars');
 +
    }
 +
    public function Events() {
 +
return $this->Make('clsEvents');
 +
    }
 +
    public function LogEvent($iWhere,$iParams,$iDescr,$iCode,$iIsError,$iIsSevere) {
 +
return $this->Events()->LogEvent($iWhere,$iParams,$iDescr,$iCode,$iIsError,$iIsSevere);
 +
    }
 
// Page output routines
 
// Page output routines
  public function SectionHdr($iTitle) {
+
     public function Formatter() {
     $out = '<p class=main><big>'.$iTitle.'</big></p>';
+
if (!isset($this->objFmt)) {
    return $out;
+
    $this->objFmt = new clsPageOutput();
  }
+
}
  public function ShowTitles($iHdrText,$iList,$objNoImgSect) {
+
return $this->objFmt;
    $cntImgs = 0;
+
    }
    $outImgs = '';
+
    public function SectionHdr($iTitle) {
    foreach ($iList as $i => $objTitleData) {
+
/*
      $objTitle = $this->Titles()->GetItem($objTitleData->ID);
+
$out = '<p class="hdr-sub">'.$iTitle.'</p>';
      $objImgs = $objTitle->ListImages('th');
+
return $out;
      $currMinPrice = $objTitleData->currMinPrice;
+
*/
      $currMaxPrice = $objTitleData->currMaxPrice;
+
$this->Formatter()->Clear();
      $strPrice = DataCurr($currMinPrice);
+
return $this->Formatter()->SectionHdr($iTitle);
      if ($currMinPrice != $currMaxPrice) {
 
        $strPrice .= '-'.DataCurr($currMaxPrice);
 
      }
 
      assert('is_resource($objImgs->Res)');
 
      if ($objImgs->RowCount()) {
 
        $cntImgs++;
 
$strCatNum = $objTitleData->CatNum;
 
        $strTitleTag = '&quot;'.$objTitle->Name.'&quot; ('.$strCatNum.')';
 
        $strTitleLink = $objTitle->Link();
 
        while ($objImgs->NextRow()) {
 
          $strImgTag = $strTitleTag.' - '.$strPrice;
 
  $qtyStk = $objTitleData->qtyForSale;
 
          if ($qtyStk) {
 
            $strImgTag .= ' - '.$qtyStk.' in stock';
 
          }
 
          $outImgs .= $strTitleLink.'<img class="thumb" src="'.KWP_IMG_MERCH.'/'.$objImgs->Spec.'" title="'.$strImgTag.'"></a>';
 
        }
 
      } else {
 
        if (!$objNoImgSect->inTbl) {
 
          $objNoImgSect->StartTable('titles without images:');
 
          $objNoImgSect->AddText('<tr class=main><th>Cat. #</th><th>Title</th><th>Price<br>Range</th><th>to<br>order</th><th>status</th></tr>');
 
        }
 
        $objNoImgSect->RowStart();
 
        $objNoImgSect->ColAdd('<b>'.$objTitleData->CatNum.'</b>');
 
        $objNoImgSect->ColAdd($objTitle->Name);
 
        $objNoImgSect->ColAdd($strPrice);
 
        $objNoImgSect->ColAdd('<b>[</b>'.$objTitle->Link().'order</a><b>]</b>');
 
        $qtyStk = $objTitleData->qtyForSale;
 
        if ($qtyStk) {
 
          $strStock = '<b>'.$qtyStk.'</b> in stock';
 
          $objNoImgSect->ColAdd($strStock);
 
          if ($objTitleData->cntInPrint == 0) {
 
            $objNoImgSect->ColAdd('OUT OF PRINT!');
 
          }
 
        } else {
 
          $objNoImgSect->ColAdd('<a title="explanation..." href="'.KWP_WIKI.'Available_but_not_in_stock">available, not in stock</a>');
 
// Debugging:
 
//          $objNoImgSect->ColAdd('ID_Title='.$objTitle->ID.' ID_ItTyp='.$objTitle->idItTyp);
 
        }
 
        $objNoImgSect->RowStop();
 
      }
 
 
     }
 
     }
     $out = '';
+
     /*----
    if ($cntImgs) {
+
      NOTES:
      $out .= $this->SectionHdr($iHdrText);
+
2011-02-02 This really should somehow provide a more general service. Right now, it's only used for displaying
      $out .= $outImgs;
+
  department pages -- but topic pages and searches could make use of it as well, if there were some tidy way
 +
  to abstract the collecting of the price and stock data. This will probably necessitate adding hi/low price
 +
  data to _titles and possibly _dept_ittyps (it's already in _title_ittyps).
 +
      HISTORY:
 +
2011-02-02
 +
  * Removed assertion that $objImgs->Res is a resource, because if there are no thumbnails for this title,
 +
    then apparently it isn't, and apparently RowCount() handles this properly.
 +
  * Also fixed references to qtyForSale -- should be qtyInStock.
 +
    */
 +
    public function ShowTitles($iHdrText,$iList,$objNoImgSect) {
 +
$cntImgs = 0;
 +
$outImgs = '';
 +
foreach ($iList as $i => $row) {
 +
    $objTitle = $this->Titles()->GetItem($row['ID']);
 +
    $objImgs = $objTitle->ListImages('th');
 +
    //assert('is_resource($objImgs->Res); /* TYPE='.get_class($objImgs).' SQL='.$objImgs->sqlMake.' */');
 +
    $currMinPrice = $row['currMinPrice'];
 +
    $currMaxPrice = $row['currMaxPrice'];
 +
    $strPrice = DataCurr($currMinPrice);
 +
    if ($currMinPrice != $currMaxPrice) {
 +
      $strPrice .= '-'.DataCurr($currMaxPrice);
 +
    }
 +
    if ($objImgs->RowCount()) {
 +
      $cntImgs++;
 +
      $strCatNum = $objTitle->CatNum();
 +
      $strTitleTag = '&quot;'.$objTitle->Name.'&quot; ('.$strCatNum.')';
 +
      $strTitleLink = $objTitle->Link();
 +
      while ($objImgs->NextRow()) {
 +
$strImgTag = $strTitleTag.' - '.$strPrice;
 +
$qtyStk = $row['qtyInStock'];
 +
if ($qtyStk) {
 +
  $strImgTag .= ' - '.$qtyStk.' in stock';
 +
}
 +
$outImgs .= $strTitleLink.'<img class="thumb" src="'.$objImgs->WebSpec().'" title="'.$strImgTag.'"></a>';
 +
      }
 +
    } else {
 +
if (!$objNoImgSect->inTbl) {
 +
    $objNoImgSect->StartTable('titles without images:');
 +
    $objNoImgSect->AddText('<tr class=main><th>Cat. #</th><th>Title</th><th>Price<br>Range</th><th>to<br>order</th><th>status</th></tr>');
 +
}
 +
$objNoImgSect->RowStart();
 +
$objNoImgSect->ColAdd('<b>'.$objTitle->CatNum().'</b>');
 +
$objNoImgSect->ColAdd($objTitle->Name);
 +
$objNoImgSect->ColAdd($strPrice);
 +
$objNoImgSect->ColAdd('<b>[</b>'.$objTitle->Link().'order</a><b>]</b>');
 +
$qtyStk = $row['qtyInStock'];
 +
if ($qtyStk) {
 +
    $strStock = '<b>'.$qtyStk.'</b> in stock';
 +
    if ($row['cntInPrint'] == 0) {
 +
$strStock .= ' - OUT OF PRINT!';
 +
    }
 +
    $objNoImgSect->ColAdd($strStock);
 +
} else {
 +
    $objNoImgSect->ColAdd('<a title="explanation..." href="'.KWP_HELP_NO_STOCK_BUT_AVAIL.'">available, not in stock</a>');
 +
// Debugging:
 +
//          $objNoImgSect->ColAdd('ID_Title='.$objTitle->ID.' ID_ItTyp='.$objTitle->idItTyp);
 +
}
 +
$objNoImgSect->RowStop();
 +
    }
 +
}
 +
$out = '';
 +
if ($cntImgs) {
 +
    $out .= $this->SectionHdr($iHdrText);
 +
    $out .= $outImgs;
 +
}
 +
return $out;
 
     }
 
     }
    return $out;
 
  }
 
 
}
 
}
  
Line 245: Line 369:
 
   }
 
   }
 
}
 
}
 
 
/* ===================
 
/* ===================
   CLASS: clsPage
+
   CLASS: clsVbzSkin
   PURPOSE: Handles display of different page types
+
   PURPOSE: Abstract skin class
 
*/
 
*/
class clsPage extends clsVbzData {
+
abstract class clsVbzSkin extends clsVbzData {
// query
+
    /*-----
  protected $strReq; // requested page
+
      USAGE: Normal main entry point -- should be called from index.php
// page definition
+
    */
  protected $strName; // short title: {item name} (goes into html title, prefixed with store name)
+
    public function DoPage() {
  protected $strTitle; // longer, descriptive title: {"item name" by Supplier} (goes at top of page)
+
try {
  protected $strSheet; // name of style sheet to use (without the .css)
+
    $this->DoPreContent();
  protected $strWikiPg; // name of wiki page to embed, if any (blank = suppress embedding)
+
    $this->DoContent();
  protected $strTitleContext; // context of short title, in HTML: {Supplier: Department:} (goes above title, in small print)
+
    $this->DoPostContent();
  protected $strHdrXtra; // any extra stuff (HTML) for the header
+
} catch(exception $e) {
  protected $strSideXtra; // any extra stuff for the sidebar
+
    $this->EmailException($e);
  protected $lstTop; // stuff listed at the top of the sidebar
+
}
// calculated fields
+
    }
  protected $strCalcTitle;
+
    /*----
  protected $strContText;
+
      HISTORY:
// flags set by wiki contents
+
2011-03-31 added Page and Cookie to list of reported variables
  protected $hideImgs;
+
    */
 +
    protected function EmailException(exception $e) {
 +
$msg = $e->getMessage();
 +
$out = 'Description: '.($e->getMessage());
 +
$out .= "\nStack trace:\n".($e->getTraceAsString());
  
  public function __construct($iSpec) {
+
$guest_ip = $_SERVER['REMOTE_ADDR'];
    parent::__construct($iSpec);
+
$guest_browser = $_SERVER['HTTP_USER_AGENT'];
    $this->lstTop = new clsList();
+
$guest_referer = NzArray($_SERVER,'HTTP_REFERER');
  }
+
$guest_page = $_SERVER['REQUEST_URI'];
 +
$guest_cookie = $_SERVER['HTTP_COOKIE'];
  
  public function GetQuery() {
+
$out .= <<<__END__
// ACTION: Retrieves request from URL and parses it
 
    if (isset($_SERVER['PATH_INFO'])) {
 
$strReq = $_SERVER['PATH_INFO'];
 
    } else {
 
$strReq = '';
 
    }
 
    $this->strReq = $strReq;
 
//    $pathinfo = $_SERVER['REQUEST_URI'];
 
    if (strrpos($strReq,'/')+1 < strlen($strReq)) {
 
      $strRedir = KWP_CAT_REL.substr($strReq,1).'/';
 
      header('Location: '.$strRedir);
 
      exit; // retry with new URL
 
    }
 
    $this->ParseQuery();
 
  }
 
  public function ParseQuery() {
 
// This is essentially an abstract function
 
// Define any additional parsing of the query (store member vars etc.)
 
  
//    global $objFactory;
+
Client information:
 +
- IP Addr: $guest_ip
 +
- Browser: $guest_browser
 +
- Page  : $guest_page
 +
- Cookie : $guest_cookie
 +
- Referer: $guest_referer
 +
__END__;
  
//    $strReq = $this->strReq;
+
$subj = 'vbz error from IP '.$guest_ip;
 +
$ok = mail(KS_TEXT_EMAIL_ADDR_ERROR,$subj,$out);
  
 +
echo <<<__END__
 +
<b>Ack!</b> We seem to have a small problem here. (If it was a large problem, you wouldn't be seeing this message.)
 +
The webmaster is being alerted about this.
 +
<br>Meanwhile, you might try reloading the page -- a lot of errors are transient,
 +
which makes them hard to fix, which is why there are more of them than the other kind.
 +
<br><br>
 +
We apologize for the nuisance.
 +
<br><br>
 +
<b>Error Message</b>: $msg
 +
__END__;
  
//   $this->objCatPage = $objFactory->Pages()->GetItem_byKey($strReq);
+
// FUTURE: log the error and whether the email was successful
//print 'REQ='.$strReq.' ABBR='.$this->objCatPage->AB;
+
    }
  }
+
    /*-----
// DIFFERENT TYPES OF PAGES
+
      ACTION: Displays everything *before* the main page contents
  protected function DoNotFound() {
+
    */
//    $this->Setup('','Unknown Title','unknown title in catalog','browse','Tomb of the...');
+
    protected function DoPreContent() {
    $this->strWikiPg = '';
+
$this->ParseInput();
    $this->strTitle = 'Unknown Page';
+
$this->HandleInput();
     $this->strName = 'unknown title in catalog';
+
$this->RenderHdrBlocks();
     $this->strTitleContext = 'Tomb of the...';
+
     }
    $this->strHdrXtra = '';
+
     /*-----
    $this->strSideXtra = '<dt><b>Cat #</b>: '.$this->strReq;
+
      ACTION: Displays everything *after* the main page contents
  }
+
    */
// UTILITY
+
    protected function DoPostContent() {
  protected function AddText($iText) {
+
$this->RenderFtrBlocks();
    $this->strContText .= $iText;
+
    }
  }
 
  
// PAGE COMPONENTS
+
// ABSTRACT section //
// -- HEADER COMPONENTS
+
    /*-----
   protected function DoPreamble() {
+
      ACTION: Displays the main page contents
# Framework
+
    */
     $this->DoHeader();
+
    protected abstract function DoContent();
    $this->DoSidebar();
+
    /*-----
     $this->DoWikiContent();
+
      ACTION: Grab any expected input and interpret it
  }
+
    */
  protected function DoPostamble() {
+
    protected abstract function ParseInput();
    global $didPage,$fltStart;
+
    /*-----
 +
      ACTION: Take the parsed input and do any needed processing (e.g. looking up data)
 +
    */
 +
    protected abstract function HandleInput();
 +
    /*-----
 +
      ACTION: Render any output that appears *before* the main content
 +
    */
 +
    protected abstract function RenderHdrBlocks();
 +
    /*-----
 +
      ACTION: Render any output that appears *after* the main content
 +
    */
 +
    protected abstract function RenderFtrBlocks();
 +
}
 +
/* ===================
 +
  CLASS: clsVbzSkin_Standard
 +
   PURPOSE: Standard skin class
 +
    Will later be replaceable with other skins
 +
*/
 +
abstract class clsVbzSkin_Standard extends clsVbzSkin {
 +
/*
 +
    protected function DoContent() {
 +
    }
 +
     protected function ParseInput() {
 +
    }
 +
    protected function HandleInput() {
 +
    }
 +
*/
 +
    protected function RenderHdrBlocks() {
 +
$this->RenderHtmlStart();
 +
$this->RenderContentHdr();
 +
$this->DoSidebar();
 +
     }
 +
    protected function RenderFtrBlocks() {
 +
$this->RenderContentFtr();
 +
$this->RenderHtmlStop();
 +
    }
 +
    protected function RenderContentFtr() {
 +
global $didPage,$fltStart;
  
    echo '<div style="clear: both;" align=right>';
+
echo '<div style="clear: both;" align=right>';
    $this->DoSepBar();
+
$this->DoSepBar();
    echo '<table width=100%><tr><td align=right><small><i>';
+
echo '<table width=100%><tr><td align=right><small><i>';
    $fltExecTime = microtime(true)-$fltStart;
+
$fltExecTime = microtime(true)-$fltStart;
    $dat = getrusage();
+
$dat = getrusage();
    $fltUserTime = $dat["ru_utime.tv_usec"]/1000000;
+
$fltUserTime = $dat["ru_utime.tv_usec"]/1000000;
    $strServer = $_SERVER['SERVER_SOFTWARE'];
+
$strServer = $_SERVER['SERVER_SOFTWARE'];
    echo $strServer.' .. ';
+
echo $strServer.' .. ';
    echo 'PHP '.phpversion().' .. Generated in <b>'.$fltUserTime.'</b> seconds (script execution '.$fltExecTime.' sec.) .. ';
+
echo 'PHP '.phpversion().' .. Generated in <b>'.$fltUserTime.'</b> seconds (script execution '.$fltExecTime.' sec.) .. ';
    $strWikiPg = $this->strWikiPg;
+
$strWikiPg = $this->strWikiPg;
    if ($strWikiPg) {
+
if ($strWikiPg) {
echo 'wiki: <a href="'.KWP_WIKI.kEmbeddedPagePrefix.$this->strWikiPg.'">'.$strWikiPg.'</a> .. ';
+
    echo 'wiki: <a href="'.KWP_WIKI.kEmbeddedPagePrefix.$this->strWikiPg.'">'.$strWikiPg.'</a> .. ';
 +
}
 +
echo date('Y-m-d H:i:s');
 +
echo '</i></small></td></tr></table>';
 +
echo '</div>';
 +
$didPage = true;
 
     }
 
     }
     echo date('Y-m-d H:i:s');
+
     protected function RenderHtmlStop() {
    echo '</i></small></td></tr></table>';
+
echo "\n</body>\n</html>";
    echo '</div></body></html>';
 
    $didPage = true;
 
  }
 
  private function DoWikiContent() {
 
# WIKI CONTENTS
 
# $txtPage = GetEmbedPage('cat');
 
    if (KF_USE_WIKI) {
 
      $txtWiki = GetWikiPage($this->strWikiPg);
 
      if ($txtWiki) {
 
        if (strpos($txtWiki,'__NOIMG__') != -1) {
 
          $txtWiki = str_replace('__NOIMG__','',$txtWiki);
 
          $this->hideImgs = true;
 
        }
 
      }
 
      if ($txtWiki) {
 
//        print '<span class=main>'.$txtPage.'</span><br>';
 
        echo '<table class=main><tr><td>'.$txtWiki.'</td></tr></table>';
 
      }
 
 
     }
 
     }
  }
 
  protected function DoSidebar() {
 
    global $fpTools,$objDataMgr;
 
  
 +
// NEW METHODS for this class //
 +
    protected function DoSidebar() {
 +
$objCache = $this->CacheMgr();
 
// TO DO: these should be pulled from the [stats] table
 
// TO DO: these should be pulled from the [stats] table
if ($objDataMgr->dtNewest) {
+
/*
     $timeSidebarBuild=$objDataMgr->dtNewest;
+
if ($objCache->dtNewest) {
 +
     $timeSidebarBuild=$objCache->dtNewest;
 
} else {
 
} else {
 
     $timeSidebarBuild = NULL;
 
     $timeSidebarBuild = NULL;
 
}
 
}
 +
*/
 +
    $timeSidebarBuild = NULL;
 
$statsQtyTitlesAvail = 2245;
 
$statsQtyTitlesAvail = 2245;
 
$statsQtyStockPieces = 1395;
 
$statsQtyStockPieces = 1395;
Line 378: Line 531:
 
//---------
 
//---------
  
    echo '<table class=border align=left cellpadding=3 bgcolor="#000000"><tr><td>';
+
echo '<table class=border align=left cellpadding=3 bgcolor="#000000"><tr><td>';
?>
+
echo '<table class=sidebar bgcolor="#ffffff" cellpadding=5><tr><td>';
<table class=sidebar bgcolor="#ffffff" cellpadding=5><tr><td>
+
echo '<table border=0 class=menu-title width="100%"><tr><td class=menu-title><a href="/">Home</a></td></tr></table>';
<table border=0 class=menu-title width="100%"><tr><td class=menu-title><a href="/">Home</a></td></tr></table>
+
echo '<span class=menu-text><dl>';
<span class=menu-text><dl>
 
<?php
 
 
/*
 
/*
 
<span class=menu-text><p style="background: #eeeeee;"><dl>
 
<span class=menu-text><p style="background: #eeeeee;"><dl>
 
*/
 
*/
  echo $this->lstTop->Output('<dt><b>','</b>: ','');
+
echo $this->lstTop->Output('<dt><b>','</b>: ','');
 
//  echo '</p></span></dl>';
 
//  echo '</p></span></dl>';
  echo '</dl>';
+
echo '</dl>';
  if ($this->strSideXtra) {
+
if ($this->strSideXtra) {
    echo '<dl style="background: #eeeeee;">'.$this->strSideXtra.'</dl>';
+
    echo '<dl style="background: #eeeeee;">'.$this->strSideXtra.'</dl>';
  }
+
}
  echo '<form action="/search/">';
+
echo '<form action="/search/">';
  echo 'Search '.$statsQtyTitlesAvail.' items:<br>';
+
echo 'Search '.$statsQtyTitlesAvail.' items:<br>';
 
?>
 
?>
 
<input size=10 name=search><input type=submit value="Go"><br>
 
<input size=10 name=search><input type=submit value="Go"><br>
Line 400: Line 551:
 
</form>
 
</form>
 
<b>Indexes</b>
 
<b>Indexes</b>
<br> ...<a href="/cat/"><b>C</b>atalog <b>H</b>ome</a>
 
 
<?php
 
<?php
 
+
echo '<br> ...<a href="'.KWP_SHOP_SUPP.'" title="list of suppliers and what we carry from each one"><b>S</b>uppliers</a>';
    echo '<br> ...<a href="/stock/" title="'.$statsQtyStockPieces.' pieces, '.$statsQtyStockItems.'. items"><b>S</b>tock</a> ('.$statsQtyStockPieces.')';
 
    echo '<br> ...<a href="/artists/" title="'.$statsQtyArtists.'.artists"><b>A</b>rtists</a> ('.$statsQtyArtists.')';
 
    //print '<br> ...<a href="/topics/" title="'.$statsQtyTopics.'.topics"><b>T</b>opics</a> ('.$statsQtyTopics.')';
 
    echo '<p>';
 
    echo '[[ <a href="'.KWP_WIKI.'" title="vbz wiki homepage"><b>wiki</b></a> ]]<br>';
 
    echo '-- [[ <a href="'.KWP_WIKI.'help" title="help-related pages on the wiki"><b>Help</b></a> ]]<br>';
 
    echo '-- [[ <a href="'.KWP_WIKI.'about" title="about vbz.net (probably more than you want to know)"><b>About</b></a> ]]<br>';
 
    echo '-- [[ <a href="'.KWP_WIKI.'contact" title="contact vbz.net (several different methods)"><b>Contact</b></a> ]]<br>';
 
    echo '<p>';
 
    echo '<a href="/email/" title="web form for sending us email">email form</a><br>';
 
    echo '<a href="/cart/" title="your shopping cart">shopping cart</a><p>';
 
# == END Sidebar B ==
 
 
/*
 
/*
    print '<table class=border width="100%"><tr><td>';
+
echo '<br> ...<a href="/stock/" title="'
    print '<table width="100%"><tr><td valign=top class=menu-status>Updated:</td><td>';
+
  .$statsQtyStockPieces.' pieces, '
    print '<td align=right class=menu-status><b>'.$timeSidebarBuild.'</b>';
+
  .$statsQtyStockItems.'. items"><b>S</b>tock</a> ('.$statsQtyStockPieces.')';
    print '</td></tr></table>';
 
    print '</td></tr></table>';
 
 
*/
 
*/
    echo '</span></td></tr></table></td></tr></table>';
+
echo '<br> ...<a href="'.KWP_SHOP_STOCK.'" title="what\'s currently in stock"><b>S</b>tock</a>';
  }
+
echo '<br> ...<a href="'.KWP_SHOP_TOPICS.'" title="topic master index (topics are like category tags)"><b>T</b>opics</a>';
  private function DoSepBar() {
+
// echo '<br> ...<a href="/artists/" title="'.$statsQtyArtists.'.artists"><b>A</b>rtists</a> ('.$statsQtyArtists.')';
     global $fpTools;
+
echo '<p>';
 +
echo '[[ <a href="'.KWP_WIKI.'" title="vbz wiki homepage"><b>wiki</b></a> ]]<br>';
 +
echo '-- [[ <a href="'.KWP_HELP_HOME.'" title="help main index"><b>Help</b></a> ]]<br>';
 +
echo '-- [[ <a href="'.KWP_HELP_ABOUT.'" title="about vbz.net (probably more than you want to know)"><b>About</b></a> ]]<br>';
 +
echo '-- [[ <a href="'.KWP_HELP_CONTACT.'" title="contact vbz.net (several different methods)"><b>Contact</b></a> ]]<br>';
 +
echo '-- [[ <a href="'.KWP_WIKI.'VBZwiki_talk:Community_portal" title="leave your comments and suggestions"><b>Comments</b></a> ]]<br>';
 +
echo '<p>';
 +
echo '<a href="/email/" title="web form for sending us email">email form</a><br>';
 +
echo '<a href="/cart/" title="your shopping cart">shopping cart</a><p>';
 +
echo '</span></td></tr></table></td></tr></table>';
 +
    }
 +
    protected function DoSepBar() {
 +
      echo $this->Render_HLine();
 +
    }
 +
    public function Render_HLine($iHeight=NULL) {
 +
      global $fpTools;
 +
 
 +
      $htHt = is_null($iHeight)?'':('height='.$iHeight);
 +
      return '<img src="'.$fpTools.'/img/bg/hlines/"'.$htHt.' alt="-----" width="100%">';
 +
    }
 +
     private function ToolbarItem($iURL,$iIcon,$iTitle,$iAlt) {
 +
global $fpTools;
 +
return '<a href="'.$iURL.'"><img border=0 src="'.$fpTools.'/img/icons/'.$iIcon.'.050pxh.png" title="'.$iTitle.'" alt="'.$iAlt.'"></a>';
 +
    }
 +
    protected function DoToolbar() {
 +
global $fpPages,$fwpCart;
  
    echo '<img src="'.$fpTools.'/img/bg/hlines/" alt="-----" width="100%">';
+
echo $this->ToolbarItem($fpPages.'/','home',KS_STORE_NAME.' home page','home page');
  }
+
echo $this->ToolbarItem($fpPages.'/search/','search','search page','search page');
  private function ToolbarItem($iURL,$iIcon,$iTitle,$iAlt) {
+
echo $this->ToolbarItem($fwpCart,'cart','shopping cart','shopping cart');
    global $fpTools;
+
echo $this->ToolbarItem(KWP_HELP_HOME,'help','help!','help');
    return '<a href="'.$iURL.'"><img border=0 src="'.$fpTools.'/img/icons/'.$iIcon.'.050pxh.png" title="'.$iTitle.'" alt="'.$iAlt.'"></a>';
+
    }
  }
 
  protected function DoToolbar() {
 
    global $fpPages,$fwpCart;
 
  
    echo $this->ToolbarItem($fpPages.'/','home',KS_STORE_NAME.' home page','home page');
+
// NEW METHODS for this class //
     echo $this->ToolbarItem($fpPages.'/search/','search','search page','search page');
+
     /*----
     echo $this->ToolbarItem($fwpCart,'cart','shopping cart','shopping cart');
+
      PURPOSE: Renders HTML inside <head></head> section
    echo $this->ToolbarItem(KWP_WIKI.'help','help','help!','help');
+
      HISTORY:
  }
+
2011-01-11 Created
// -- HEADER
+
    */
  protected function DoHeader() {
+
     protected function RenderHtmlHeaderSection() {
    global $fpTools, $fwpLogo;
+
$strTitle = KS_STORE_NAME.' - '.$this->strName;
 +
$out = "\n<title>$strTitle</title>";
  
    $strWikiPg = $this->strWikiPg;
+
$arVars = array('sheet' => $this->strSheet);
    $this->strCalcTitle = KS_STORE_NAME.' - '.$this->strName;
+
$objStrTplt = new clsStringTemplate_array(NULL,NULL,$arVars);
    $htmlHead = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
+
$objStrTplt->MarkedValue(KHT_PAGE_STYLE);
    $htmlHead .= '<html><head><title>'.$this->strCalcTitle.'</title>';
+
$out .= $objStrTplt->Replace();
    if ($this->strSheet) {
+
//$out .= KHT_PAGE_STYLE;
      $htmlHead .= '<link rel="StyleSheet" href="'.$fpTools.'/styles/'.$this->strSheet.'.css">';
+
if (!empty($this->strName)) {
 +
    $ftName = ': '.htmlspecialchars($this->strName);
 +
} else {
 +
    $ftName = '';
 +
}
 +
$strContent = KS_STORE_NAME_META.$ftName;
 +
$out .= "\n<meta name=description content=\"$strContent\">";
 +
return $out;
 
     }
 
     }
# remove any quotes from $pageName:
+
    /*----
     $htmlName = str_replace('"','&quot;',$this->strName);
+
      PURPOSE: Renders HTML up to beginning of BODY.
    if ($htmlName) {
+
      HISTORY:
      $htmlName = ': '.$htmlName;
+
2011-01-11 Extracted everything between <head> and </head> into RenderHtmlHeaderSection()
 +
    */
 +
     protected function RenderHtmlStart() {
 +
//$this->strCalcTitle = KS_STORE_NAME.' - '.$this->strName;
 +
$out = KHT_PAGE_DOCTYPE;
 +
$out .= "\n<html>\n<head>";
 +
$out .= $this->RenderHtmlHeaderSection();
 +
$out .= "\n</head>";
 +
$out .= KHT_PAGE_BODY_TAG;
 +
echo $out;
 
     }
 
     }
     $htmlHead .= '<meta name=description content="'.KS_STORE_NAME_META.$htmlName.'">';
+
     protected function RenderContentHdr() {
    $htmlHead .= '</head>';
+
global $fwpLogo;
    echo $htmlHead;
+
//$strWikiPg = $this->strWikiPg;
?><body
+
 
bgcolor=000044
+
      // begin content header
TEXT=CCFFFF
+
echo '<table width="100%" class=border cellpadding=5><tr><td>';
LINK=33FF33
+
echo '<table width="100%" class=hdr cellpadding=2><tr>';
VLINK=33CCFF
+
      // === LEFT HEADER: Title ===
ALINK=FFCC00
+
echo '<td>';
TOPMARGIN=0
+
echo '<a href="'.KWP_HOME_ABS.'"><img align=left border=0 src="'.$fwpLogo.'" title="'.KS_STORE_NAME.' home" alt="'.KS_SMALL_LOGO_ALT.'"></a>';
LEFTMARGIN=0
+
if ($this->strTitleContext) {
MARGINWIDTH=0
+
  echo '<span class=pretitle><b><a href="/">'.KS_STORE_NAME.'</a></b>: '.$this->strTitleContext.'</span><br>';
MARGINHEIGHT=0
+
}
>
+
echo '<span class=page-title>'.$this->strTitle.'</span></td>';
<?
+
      // === END LEFT HEADER ===
// begin content header
+
 
    echo '<table width="100%" class=border cellpadding=5><tr><td>';
+
      // === RIGHT HEADER: nav icons ===
    echo '<table width="100%" class=hdr cellpadding=2><tr>';
+
echo '<td align=right>';
// === LEFT HEADER: Title ===
+
$this->DoToolbar();
    echo '<td>';
+
echo '</td>';
    echo '<a href="'.KWP_HOME_ABS.'"><img align=left border=0 src="'.$fwpLogo.'" title="'.KS_STORE_NAME.' home" alt="'.KS_SMALL_LOGO_ALT.'"></a>';
+
      // === END RIGHT HEADER ===
    if ($this->strTitleContext) {
+
echo "\n</tr></table>\n</td></tr></table><!-- end html header -->";
      echo '<span class=pretitle><b><a href="/">'.KS_STORE_NAME.'</a></b>: '.$this->strTitleContext.'</span><br>';
 
 
     }
 
     }
     echo '<span class=page-title>'.$this->strTitle.'</span></td>';
+
}
// === END LEFT HEADER ===
+
/* ===================
 +
  CLASS: clsPage
 +
  PURPOSE: Handles display of different page types
 +
  TO DO: These classes (clsPage and descendants) need to be reorganized (they're a mess)
 +
     and also set up so we can create different skins.
 +
*/
 +
abstract class clsPage extends clsVbzSkin_Standard {
 +
// query
 +
    protected $strReq; // requested page
 +
// page definition
 +
    protected $strName; // short title: {item name} (goes into html title, prefixed with store name)
 +
    protected $strTitle; // longer, descriptive title: {"item name" by Supplier} (goes at top of page)
 +
    protected $strSheet; // name of style sheet to use (without the .css)
 +
    protected $strWikiPg; // name of wiki page to embed, if any (blank = suppress embedding)
 +
    protected $strTitleContext; // context of short title, in HTML: {Supplier: Department:} (goes above title, in small print)
 +
    protected $strHdrXtra; // any extra stuff (HTML) for the header
 +
    protected $strSideXtra; // any extra stuff for the sidebar
 +
    protected $lstTop; // stuff listed at the top of the sidebar
 +
// calculated fields
 +
//   protected $strCalcTitle;
 +
    protected $strContText;
 +
// flags set by wiki contents
 +
    protected $hideImgs;
  
// === RIGHT HEADER: nav icons ===
+
    public function __construct($iSpec) {
    echo '<td align=right>';
+
parent::__construct($iSpec);
    $this->DoToolbar();
+
$this->lstTop = new clsList();
    echo '</td>';
+
    }
// === END RIGHT HEADER ===
+
    protected function HandleInput() {
?>
+
$this->strSheet = 'browse'; // default
</tr></table>
+
    }
</td></tr></table>
+
    /*-----
<!-- end html header -->
+
      IMPLEMENTATION: Retrieves request from URL and parses it
<?
+
URL data identifies page, keyed to cat_pages data
  }
+
    */
 +
    protected function ParseInput() {
 +
if (isset($_SERVER['PATH_INFO'])) {
 +
    $strReq = $_SERVER['PATH_INFO'];
 +
} else {
 +
    $strReq = '';
 +
}
 +
$this->strReq = $strReq;
 +
if (strrpos($strReq,'/')+1 < strlen($strReq)) {
 +
    $strRedir = KWP_CAT_REL.substr($strReq,1).'/';
 +
    header('Location: '.$strRedir);
 +
    exit; // retry with new URL
 +
}
 +
    }
 +
// DIFFERENT TYPES OF PAGES
 +
    protected function DoNotFound() {
 +
$this->strWikiPg = '';
 +
$this->strTitle = 'Unknown Page';
 +
$this->strName = 'unknown title in catalog';
 +
$this->strTitleContext = 'Tomb of the...';
 +
$this->strHdrXtra = '';
 +
$this->strSideXtra = '<dt><b>Cat #</b>: '.$this->strReq;
 +
    }
 +
// UTILITY
 +
    protected function AddText($iText) {
 +
$this->strContText .= $iText;
 +
    }
 +
    private function DoWikiContent() {
 +
# WIKI CONTENTS
 +
# $txtPage = GetEmbedPage('cat');
 +
if (KF_USE_WIKI) {
 +
    $txtWiki = GetWikiPage($this->strWikiPg);
 +
    if ($txtWiki) {
 +
if (strpos($txtWiki,'__NOIMG__') != -1) {
 +
    $txtWiki = str_replace('__NOIMG__','',$txtWiki);
 +
    $this->hideImgs = true;
 +
}
 +
    }
 +
    if ($txtWiki) {
 +
echo '<table class=main><tr><td>'.$txtWiki.'</td></tr></table>';
 +
    }
 +
}
 +
    }
 
}
 
}
  
 
class clsPageCat extends clsPage {
 
class clsPageCat extends clsPage {
  private $objCatPage; // object for identifying page to display
+
    private $objCatPage; // object for identifying page to display
 +
    protected function RenderHdrBlocks() {
 +
if ($this->useSkin) {
 +
    parent::RenderHdrBlocks();
 +
}
 +
    }
 +
    protected function RenderFtrBlocks() {
 +
if ($this->useSkin) {
 +
    parent::RenderFtrBlocks();
 +
}
 +
    }
 +
    protected function HandleInput() {
 +
parent::HandleInput();
 +
$strReq = $this->strReq;
 +
$this->objCatPage = $this->Pages()->GetItem_byKey($strReq);
 +
$objPage = $this->objCatPage;
 +
$this->useSkin = TRUE;
  
  public function ParseQuery() {
+
if ($this->strReq) {
    $strReq = $this->strReq;
+
    if (is_object($objPage)) {
    $this->objCatPage = $this->Pages()->GetItem_byKey($strReq);
+
switch ($objPage->Type) {
 
+
case 'S':
//print 'REQ='.$strReq.' ABBR='.$this->objCatPage->AB;
+
  $this->DoCatSupp();
  }
+
  break;
 
+
case 'D':
  public function DoRequest() {
+
  $this->DoCatDept();
    $doRawHTML = FALSE;
+
  break;
    $this->strSheet = 'browse'; // default
+
case 'T':
    if ($this->strReq) {
+
  $this->DoCatTitle();
      if (is_object($this->objCatPage)) {
+
  break;
        switch ($this->objCatPage->Type) {
+
case 'I':
        case 'S':
+
  $this->useSkin = FALSE;
          $this->DoCatSupp();
+
  $this->DoCatImage();
          break;
+
  break;
        case 'D':
+
}
          $this->DoCatDept();
+
    } else {
          break;
+
$this->DoNotFound();
        case 'T':
+
    }
          $this->DoCatTitle();
+
} else {
          break;
+
    $this->DoCatHome();
        case 'I':
+
}
          $doRawHTML = TRUE;
 
          $this->DoCatImage();
 
          break;
 
        }
 
      } else {
 
        $this->DoNotFound();
 
      }
 
    } else {
 
      $this->DoCatHome();
 
 
     }
 
     }
     if ($doRawHTML) {
+
     public function DoContent() {
      echo $this->strContText;
+
  echo $this->strContText;
    } else {
 
      $this->DoPreamble(); // everything before the contents
 
      echo $this->strContText;
 
      $this->DoPostamble(); // everything after the contents
 
 
     }
 
     }
  }
 
 
// SIDEBAR INFO for different types of pages
 
// SIDEBAR INFO for different types of pages
 
   private function DoCatIndicia() {
 
   private function DoCatIndicia() {
Line 570: Line 810:
  
 
   private function DoCatHome() {
 
   private function DoCatHome() {
//    $objSuppTbl = VbzClasses::Suppliers();
 
//    $this->Setup('cat','Catalog Home','Catalog main page','browse','hello and welcome to the...');
 
 
     $this->DoCatIndicia();
 
     $this->DoCatIndicia();
 
     $this->strWikiPg = 'cat';
 
     $this->strWikiPg = 'cat';
Line 580: Line 818:
 
   }
 
   }
 
   private function DoCatSupp() {
 
   private function DoCatSupp() {
    CallEnter($this,__LINE__,'clsPage.DoCatSupp()');
 
 
//    $objSuppTbl = VbzClasses::Suppliers();
 
 
     $objSuppTbl = $this->Suppliers();
 
     $objSuppTbl = $this->Suppliers();
 
     $objSupp = $objSuppTbl->GetItem($this->objCatPage->ID_Row);
 
     $objSupp = $objSuppTbl->GetItem($this->objCatPage->ID_Row);
Line 594: Line 829:
 
     $this->strTitleContext = '<a href="'.KWP_CAT_REL.'">Suppliers</a>: <b>'.$strSuppName.'</b>:';
 
     $this->strTitleContext = '<a href="'.KWP_CAT_REL.'">Suppliers</a>: <b>'.$strSuppName.'</b>:';
 
     $this->AddText($objSupp->DoPage());
 
     $this->AddText($objSupp->DoPage());
 
    CallExit('clsPage.DoCatSupp()');
 
 
   }
 
   }
 
   private function DoCatDept() {
 
   private function DoCatDept() {
Line 627: Line 860:
 
     $objTitleTbl = $this->Titles();
 
     $objTitleTbl = $this->Titles();
  
     $objTitle = $objTitleTbl->GetItem($this->objCatPage->ID_Row);
+
    $idRow = $this->objCatPage->ID_Row;
 +
     $objTitle = $objTitleTbl->GetItem($idRow);
 
     assert('is_object($objTitle)');
 
     assert('is_object($objTitle)');
 
     $objDept = $objTitle->Dept();
 
     $objDept = $objTitle->Dept();
Line 657: Line 891:
 
     $objImage->DoPage();
 
     $objImage->DoPage();
 
     CallExit('clsPage.DoCatImage()');
 
     CallExit('clsPage.DoCatImage()');
  }
 
}
 
 
class clsPageTopic extends clsPage {
 
  public function DoRequest() {
 
    $this->strSheet = 'browse'; // default
 
    $strReq = $this->strReq;
 
    if (is_numeric($strReq)) {
 
      $idTopic = (int)$strReq;
 
      $objTopic = $this->Topics()->GetItem($idTopic);
 
      $this->strWikiPg = 'topic.'.$objTopic->WebName();
 
      $this->strTitle = 'Topic Index';
 
      $this->strName = 'catalog topic index';
 
      $this->AddText($objTopic->DoPage());
 
    } else {
 
      $this->strWikiPg = 'topics';
 
      $this->strTitle = 'Topic Index';
 
      $this->strName = 'catalog topic index';
 
      $this->AddText($this->Topics()->DoIndex());
 
    }
 
    $this->DoPreamble(); // everything before the contents
 
    echo '<span class=main>'.$this->strContText.'</span>';
 
    $this->DoPostamble(); // everything after the contents
 
  }
 
}
 
 
class clsPageOutput {
 
  public $out;
 
  private $isOdd;
 
  public $inTbl;
 
 
  function __construct() {
 
    $this->out = '';
 
    $this->isOdd = false;
 
    $this->inTbl = 0;
 
  }
 
  function Clear() {
 
    $this->out = '';
 
  }
 
  function AddText($iText) {
 
    $this->out .= $iText;
 
  }
 
  function SectionHdr($iTitle) {
 
    $this->out .= '<p class=main><big>'.$iTitle.'</big></p>';
 
    return $this->out;
 
  }
 
  function StartTable($iTitle) {
 
    if ($iTitle) {
 
      $this->SectionHdr($iTitle);
 
      $this->out .= '<table class=content>';
 
      $this->inTbl++;
 
    }
 
  }
 
  function RowStart($iClass='') {
 
    if ($iClass) {
 
      $this->out .= '<tr class="'.$iClass.'">';
 
    } else {
 
      $this->out .= '<tr>';
 
    }
 
  }
 
  function RowStop() {
 
    $this->out .= '</tr>';
 
    $this->isOdd = !$this->isOdd;
 
  }
 
  function ColAdd($iText) {
 
    if ($this->isOdd) {
 
      $cellOpen = '<td class=catalog-stripe valign=top>';
 
    } else {
 
      $cellOpen = '<td class=catalog valign=top>';
 
    }
 
    $this->out .= $cellOpen.$iText.'</td>';
 
  }
 
  function EndTable() {
 
    if ($this->inTbl) {
 
      $this->out .= '</table>';
 
      $this->inTbl--;
 
    }
 
    return $this->out;
 
  }
 
  function ShowImgUnavail() {
 
    $this->out .= '<table class=border cellpadding="5"><tbody><tr><td><table class="hdr" cellpadding="2"><tbody><tr><td align="center"><span class="page-title">No Images<br>Available<br></span>for this item<br><b>:-(</b></td></tr></tbody></table></td></tr></tbody></table>';
 
    return $this->out;
 
 
   }
 
   }
 
}
 
}
Line 745: Line 897:
 
  *** CATALOG DATA CLASSES ***
 
  *** CATALOG DATA CLASSES ***
 
*/
 
*/
class clsVbzTable extends clsTable {
 
  protected function Touch($iCaller) {
 
    global $objDataMgr;
 
 
    $objDataMgr->Update_byName($this->Name(),$iCaller);
 
  }
 
}
 
  
 
class clsCatPages extends clsVbzTable {
 
class clsCatPages extends clsVbzTable {
  public function __construct($iDB) {
+
    public function __construct($iDB) {
    parent::__construct($iDB);
+
parent::__construct($iDB);
      $this->Name('cat_pages');
+
  $this->Name('cat_pages'); // cache
      $this->KeyName('AB');
+
  //$this->Name('qryCat_pages'); // live data
      $this->ClassSng('clsCatPage');
+
  $this->KeyName('AB');
  }
+
  $this->ClassSng('clsCatPage');
/*
+
    }
  protected function _newItem() {
+
     public function GetItem_byKey($iKey) {
     return new clsCatPage($this);
+
CallEnter($this,__LINE__,__CLASS__.'.GetItem_byKey('.$iKey.')');
  }
+
$strKey = trim($iKey,'/');
*/
+
$strKey = str_replace('-','/',$strKey);
  public function GetItem_byKey($iKey) {
+
$sqlCatKey = $this->objDB->SafeParam($strKey);
 
+
// This function is named wrong, and needs to be rewritten anyway
    CallEnter($this,__LINE__,__CLASS__.'.GetItem_byKey('.$iKey.')');
+
// $this->Touch('clsCatPages.GetItem_byKey('.$iKey.')');
    $strKey = trim($iKey,'/');
+
$objItem = $this->GetData('Path="'.$sqlCatKey.'"');
    $strKey = str_replace('-','/',$strKey);
+
    //    $objRec = $this->objDB->Query($sql);
    $sqlCatKey = $this->objDB->SafeParam($strKey);
+
assert('is_object($objItem)');
    $this->Touch('clsCatPages.GetItem_byKey('.$iKey.')');
+
if ($objItem->NextRow()) {
    $objItem = $this->GetData('Path="'.$sqlCatKey.'"');
+
    DumpValue('objItem NumRows',$objItem->hasRows());
//    $objRec = $this->objDB->Query($sql);
+
    CallExit('clsCatPages.GetItem_byKey('.$iKey.') -> Page '.$objItem->AB);
    assert('is_object($objItem)');
+
} else {
    if ($objItem->NextRow()) {
+
    CallExit('clsCatPages.GetItem_byKey('.$iKey.') -> no data');
      DumpValue('objItem NumRows',$objItem->hasRows());
+
}
      CallExit('clsCatPages.GetItem_byKey('.$iKey.') -> Page '.$objItem->AB);
+
return $objItem;
    } else {
 
      CallExit('clsCatPages.GetItem_byKey('.$iKey.') -> no data');
 
 
     }
 
     }
    return $objItem;
 
  }
 
 
}
 
}
  
 
class clsCatPage extends clsDataSet {
 
class clsCatPage extends clsDataSet {
 
// == STATIC SECTION
 
// == STATIC SECTION
//  const cksTblName = 'cat_pages';
 
 
//  const cksIDName = 'AB';
 
//  const cksIDName = 'AB';
  
Line 796: Line 936:
  
 
// ==== DYNAMIC SECTION
 
// ==== DYNAMIC SECTION
  public function __construct($iDB) {
+
    public function __construct($iDB) {
    parent::__construct($iDB);
+
parent::__construct($iDB);
      $this->Name('cat_supp');
+
  $this->Name('cat_supp');
      $this->KeyName('ID');
+
  $this->KeyName('ID');
      $this->ClassSng('clsSupplier');
+
  $this->ClassSng('clsSupplier');
  }
+
  $this->ActionKey('supp');
  public function GetItem_byKey($iKey) {
+
    }
    CallEnter($this,__LINE__,__CLASS__.'.GetItem_byKey('.$iKey.')');
+
    public function GetItem_byKey($iKey) {
    $sqlCatKey = $this->objDB->SafeParam($iKey);
+
CallEnter($this,__LINE__,__CLASS__.'.GetItem_byKey('.$iKey.')');
    $objItem = $this->GetData('CatKey="'.$sqlCatKey.'"');
+
$sqlCatKey = $this->objDB->SafeParam($iKey);
    CallExit(__CLASS__.'.GetItem_byKey('.$iKey.') -> new supplier');
+
$objItem = $this->GetData('CatKey="'.$sqlCatKey.'"');
    return $objItem;
+
CallExit(__CLASS__.'.GetItem_byKey('.$iKey.') -> new supplier');
  }
+
return $objItem;
  public function DoHomePage() {
+
    }
    global $objDataMgr;
+
    /*----
 +
      HISTORY
 +
2010-11-12 disabled automatic cache update
 +
    */
 +
    protected function DataSet_forStore($iClass=NULL) {
 +
//$objCache = $this->objDB->CacheMgr();
 +
//$objCache->Update_byName('_supplier_ittyps','clsSuppliers.DoHomePage()');
 +
$sql = 'SELECT * FROM _supplier_ittyps ORDER BY Name, ItemCount DESC';
 +
$objRows = $this->objDB->DataSet($sql,$iClass);
  
     $objDataMgr->Update_byName('_supplier_ittyps','clsSuppliers.DoHomePage()');
+
return $objRows;
    $sql = 'SELECT * FROM _supplier_ittyps ORDER BY Name, ItemCount DESC';
+
    }
    $objRec = $this->objDB->DataSet($sql);
+
     public function DoHomePage() {
    $out = '';
+
$out = '';
    if ($objRec->hasRows()) {
+
$objRec = $this->DataSet_forStore();
      $objTbl = new clsPageOutput;
+
if ($objRec->hasRows()) {
      $objTbl->StartTable('Suppliers');
+
    $objTbl = new clsPageOutput;
      $strKeyLast = $outCell = '';
+
    $objTbl->StartTable('Suppliers');
      while ($objRec->NextRow()) {
+
    $strKeyLast = $outCell = '';
        $strKey = $objRec->CatKey;
+
    while ($objRec->NextRow()) {
        if ($strKey != $strKeyLast) {
+
$strKey = $objRec->CatKey;
          $strKeyLast = $strKey;
+
if ($strKey != $strKeyLast) {
          $strKeyLink = strtolower($strKey).'/';
+
    $strKeyLast = $strKey;
          if ($outCell) {
+
    $strKeyLink = strtolower($strKey).'/';
            $objTbl->ColAdd($outCell);
+
    if ($outCell) {
            $objTbl->RowStop();
+
$objTbl->ColAdd($outCell);
            $outCell = '';
+
$objTbl->RowStop();
          }
+
$outCell = '';
          $objTbl->RowStart();
+
    }
          $objTbl->ColAdd('<b><a href="'.$strKeyLink.'">'.$objRec->Name.'</a></b>');
+
    $objTbl->RowStart();
          $isFirst = true;
+
    $objTbl->ColAdd('<b><a href="'.$strKeyLink.'">'.$objRec->Name.'</a></b>');
        }
+
    $isFirst = true;
        if ($isFirst) {
+
}
          $isFirst = false;
+
if ($isFirst) {
        } else {
+
    $isFirst = false;
          $outCell .= ', ';
+
} else {
        }
+
    $outCell .= ', ';
$strItType = $objRec->ItemType;
+
}
if ($strItType == '') {
+
$strItType = $objRec->ItemType;
    $strItType = '?id'.$objRec->ID;
+
if ($strItType == '') {
 +
    $strItType = '?id'.$objRec->ID;
 +
}
 +
$outCell .= ' <b>'.$objRec->ItemCount.'</b> '.$strItType;
 +
    }
 +
    $objTbl->ColAdd($outCell);
 +
    $objTbl->RowStop();
 +
    $out .= $objTbl->EndTable();
 
}
 
}
        $outCell .= ' <b>'.$objRec->ItemCount.'</b> '.$strItType;
+
return $out;
      }
 
      $objTbl->ColAdd($outCell);
 
      $objTbl->RowStop();
 
      $out .= $objTbl->EndTable();
 
 
     }
 
     }
    return $out;
 
  }
 
 
}
 
}
  
 
class clsSupplier extends clsDataSet {
 
class clsSupplier extends clsDataSet {
  public function DoPage() {
+
    /*----
     global $objDataMgr;
+
      ACTION: Finds the Item for this Supplier with the given supplier CatNum
 +
      RETURNS: object of type requested by user; defaults to clsItem. NULL if not found.
 +
      DEPRECATED -- use GetItem_bySCatNum()
 +
    */
 +
    public function GetItem_bySuppCatNum($iCatNum,$iClass=NULL) {
 +
return $this->GetItem_bySCatNum($iCatNum);
 +
    }
 +
    /*----
 +
      ACTION: Checks the given catalog number to see if it corresponds to a given item for the current supplier
 +
      INPUT: supplier catalog number
 +
      OUTPUT: item object (if found) or NULL (if not found)
 +
      HISTORY:
 +
2011-01-09 Moved here from VbzAdminSupplier; replaces GetItem_bySuppCatNum()
 +
    */
 +
    public function GetItem_bySCatNum($iSCat) {
 +
$objTblItems = $this->objDB->Items();
 +
 
 +
$sqlFind = '(ID_Supp='.$this->ID.') AND (Supp_CatNum="'.$iSCat.'")';
 +
$objItem = $objTblItems->GetData($sqlFind);
 +
if ($objItem->HasRows()) {
 +
    $objItem->NextRow();
 +
    return $objItem;
 +
} else {
 +
    return NULL;
 +
}
 +
    }
 +
    /*----
 +
      ACTION: Finds the Title for this Supplier with the given CatKey
 +
      RETURNS: object of type requested by user; defaults to clsVbzTitle. NULL if not found.
 +
      HISTORY:
 +
2010-11-07 Created for Title editing page -- need to check for duplicate CatKey before saving.
 +
    */
 +
    public function GetTitle_byCatKey($iCatKey,$iClass='clsVbzTitle') {
 +
$sqlCatKey = $this->objDB->SafeParam($iCatKey);
 +
$sqlFilt = '(ID_Supplier='.$this->ID.') AND (CatKey="'.$sqlCatKey.'")';
 +
$objTitle = $this->objDB->Titles_Cat()->GetData($sqlFilt,$iClass);
 +
if ($objTitle->HasRows()) {
 +
    $objTitle->NextRow();
 +
    return $objTitle;
 +
} else {
 +
    return NULL;
 +
}
 +
    }
 +
    /*----
 +
      ACTION: Searches for Titles whose CatKeys include the given string
 +
      PURPOSE: used during renaming of supplier-recycled catalog numbers, so we can see if that number
 +
has been recycled before and avoid having to repeatedly try new names
 +
      HISTORY:
 +
2010-11-08 Created for title editing page
 +
    */
 +
    public function GetTitles_byCatKey($iCatKey,$iClass='clsVbzTitle') {
 +
$sqlCatKey = $this->objDB->SafeParam($iCatKey);
 +
$sqlFilt = '(ID_Supplier='.$this->ID.') AND (CatKey LIKE "%'.$sqlCatKey.'%")';
 +
$objTitle = $this->objDB->Titles_Cat()->GetData($sqlFilt,$iClass);
 +
if ($objTitle->HasRows()) {
 +
    $objTitle->NextRow();
 +
    return $objTitle;
 +
} else {
 +
    return NULL;
 +
}
 +
    }
 +
    protected function DeptsData_forCount($iClass='clsDept') {
 +
$objTbl = $this->objDB->Depts();
 +
$objRows = $objTbl->GetData('isActive AND (ID_Supplier='.$this->ID.')',$iClass,'Sort');
 +
return $objRows;
 +
    }
 +
    /*----
 +
      USED BY: $this->DeptsPage_forStore()
 +
      RETURNS: array of data for the current supplier
 +
array[rows] = source dataset -- each row is an ItTyp within a Department
 +
array[depts][ID_Dept][ID_ItTyp] = count of items for sale by department and item type
 +
array[supp][ID_ItTyp] = count of items for sale by item type
 +
      HISTORY:
 +
2011-02-02 switched data source from qryItTypsDepts_ItTyps to _dept_ittyps
 +
  Page was not displaying at all. Some additional changes were necessary.
 +
    */
 +
    protected function DeptsData_forStore() {
 +
if (is_null($this->arDeptsData)) {
 +
    //$objRows = $this->objDB->DataSet('SELECT * FROM qryItTypsDepts_ItTyps WHERE ID_Supplier='.$this->ID);
 +
    $objRows = $this->objDB->DataSet('SELECT * FROM _dept_ittyps WHERE ID_Supp='.$this->ID);
 +
    while ($objRows->NextRow()) {
 +
$idItTyp = $objRows->ID_ItTyp;
 +
$intCntForSale = $objRows->cntForSale;
 +
 
 +
if (!isset($arObjs[$idItTyp])) {
 +
    $objItTyp = $this->Engine()->ItTyps()->SpawnItem();
 +
    $arObjs[$idItTyp] = $objItTyp;
 +
 
 +
    $objItTyp->Row['NameSng'] = $objRows->Value('ItTypNameSng');
 +
    $objItTyp->Row['NamePlr'] = $objRows->Value('ItTypNamePlr');
 +
    $objItTyp->Row['cntForSale'] = 0; // initialize the count
 +
}
 +
    // accumulate the list of everything this supplier has:
 +
$idSupp = $objRows->ID_Supplier;
 +
$objItTyp->Row['cntForSale'] += $intCntForSale;
 +
    // accumulate the department listing:
 +
$idDept = $objRows->Value('ID_Dept');
 +
$arDeptCntForSale[$idDept][$idItTyp] = $intCntForSale;
 +
    }
 +
    $arOut['rows'] = $objRows;
 +
    $arOut['depts'] = $arDeptCntForSale;
 +
    $arOut['supp'] = $arObjs;
 +
    $this->arDeptsData = $arOut;
 +
}
 +
return $this->arDeptsData;
 +
    }
 +
    /*----
 +
      ACTION: Generates the item-type-count summary for the Supplier's index page
 +
    */
 +
    public function DoPiece_ItTyp_Summary() {
 +
$arData = $this->DeptsData_forStore();
 +
$arObjs = $arData['supp'];
 +
 
 +
$outRow = '';
 +
foreach ($arObjs as $id=>$obj) {
 +
    $objTyp = $obj;
 +
    $cnt = $objTyp->Value('cntForSale');
 +
    if ($cnt > 0) {
 +
$strType = $objTyp->Name($cnt);
 +
if ($outRow != '') {
 +
    $outRow .= ', ';
 +
}
 +
$outRow .= '<b>'.$cnt.'</b> '.$strType;
 +
    }
 +
}
 +
$out = '<span class=catalog-summary>'.$outRow.'</span>';
 +
return $out;
 +
    }
 +
    /*----
 +
      ACTION: Generates the table of departments and the summary of items available for each
 +
    */
 +
    public function DoPiece_Dept_ItTyps() {
 +
$arData = $this->DeptsData_forStore();
 +
$arObjs = $arData['supp'];
 +
$arDeptCntForSale = $arData['depts'];
 +
 
 +
$out = '<table class=depts>';
 +
$isOdd = FALSE;
 +
$fpSupp = KWP_CAT_REL.strtolower($this->Value('CatKey')).'/';
 +
foreach ($arDeptCntForSale as $idDept=>$arCnts) {
 +
    $isOdd = !$isOdd;
 +
    if ($isOdd) {
 +
$cellOpen = '<td class=catalog-stripe valign=top>';
 +
    } else {
 +
$cellOpen = '<td class=catalog valign=top>';
 +
    }
 +
 
 +
    $outRow = '';
 +
    foreach ($arCnts as $id=>$cnt) {
 +
if ($cnt > 0) {
 +
    $objTyp = $arObjs[$id];
 +
    $strType = $objTyp->Name($cnt);
 +
    if ($outRow != '') {
 +
$outRow .= ', ';
 +
    }
 +
    $outRow .= '<b>'.$cnt.'</b> '.$strType;
 +
}
 +
    }
 +
    if ($outRow != '') {
 +
$objDept = $this->objDB->Depts()->GetItem($idDept);
 +
$strPageKey = $objDept->PageKey();
 +
$strName = $objDept->Name;
 +
 
 +
$out .= '<tr>'.$cellOpen.'<a href="'.$fpSupp.strtolower($strPageKey).'/">'.$strName.'</a></td>';
 +
$out .= $cellOpen.$outRow.'</td></tr>';
 +
    }
 +
}
 +
$out .= '</table>';
 +
return $out;
 +
    }
 +
    protected function DeptsPage_forStore() {
 +
$out = $this->DoPiece_ItTyp_Summary();
 +
$out .= $this->Engine()->SectionHdr('Departments:');
 +
$out .= $this->DoPiece_Dept_ItTyps();
 +
return $out;
 +
    }
 +
    public function DoPage() {
 +
$out = '';
 +
assert('$this->ID');
 +
 
 +
     // first, check how many departments supplier has:
 +
//$objDeptTbl = $this->objDB->Depts();
 +
//$objDepts = $objDeptTbl->GetData('isActive AND (ID_Supplier='.$this->ID.')','clsDept','Sort');
 +
$objDepts = $this->DeptsData_forCount();
 +
$intRows = $objDepts->RowCount();
  
    CallEnter($this,__LINE__,'clsSupplier.DoPage()');
+
if ($intRows == 1) {
     $out = '';
+
     // if there's only one department, display that instead of a department listing
    assert('$this->ID');
+
    $objDepts->NextRow(); // get the first/only dept
// first, check how many departments supplier has:
+
    $out = $objDepts->DoPage();
    $objDeptTbl = $this->objDB->Depts();
+
} else {
    $objDepts = $objDeptTbl->GetData('isActive AND (ID_Supplier='.$this->ID.')','clsDept','Sort');
+
    $out .= $this->DeptsPage_forStore();
 +
}
  
    if ($objDepts->RowCount() == 1) {
+
return $out;
// if there's only one department, display that instead of a department listing
 
      $out = $objDepts->DoPage();
 
    } else {
 
      $objDataMgr->Update_byName('_supplier_ittyps','clsSupplier.DoPage() for '.$this->CatKey);
 
      $sql = 'SELECT * FROM _supplier_ittyps WHERE ID='.$this->ID.' ORDER BY Name, ItemCount DESC';
 
      $objItTyps = $this->objDB->DataSet($sql,'clsItTyp');
 
      $isFirst = true;
 
      $out .= '<span class=catalog-summary>';
 
      while ($objItTyps->NextRow()) {
 
        if ($isFirst) {
 
          $isFirst = false;
 
        } else {
 
          $out .= ', ';
 
        }
 
        $out .= ' <b>'.$objItTyps->ItemCount.'</b> '.$objItTyps->ItemType;
 
      }
 
      $out .= '</span>';
 
      $out .= $objDeptTbl->DoListing_forSupp($this->ID);
 
 
     }
 
     }
  
     CallExit('clsSupplier.DoPage()');
+
     public function ShopLink($iText=NULL) {
    return $out;
+
if (is_null($iText)) {
  }
+
    $strText = $this->Name;
  public function Link() {
+
} else {
    $out = '<a href="'.$this->URL().'">'.$this->Name.'</a>';
+
    $strText = $iText;
    return $out;
+
}
  }
+
$out = '<a href="'.$this->URL().'">'.$strText.'</a>';
  public function URL() {
+
return $out;
    return KWP_CAT_REL.strtolower($this->CatKey).'/';
+
    }
  }
+
    public function Link() { return $this->ShopLink(); }
 +
    public function URL() {
 +
return KWP_CAT_REL.strtolower($this->CatKey).'/';
 +
    }
 
}
 
}
 
class clsDepts extends clsVbzTable {
 
class clsDepts extends clsVbzTable {
  public function __construct($iDB) {
+
    public function __construct($iDB) {
    parent::__construct($iDB);
+
parent::__construct($iDB);
      $this->Name('cat_depts');
+
  $this->Name('cat_depts');
      $this->KeyName('ID');
+
  $this->KeyName('ID');
      $this->ClassSng('clsDept');
+
  $this->ClassSng('clsDept');
  }
+
  $this->ActionKey('dept');
  protected function _newItem() {
+
    }
    CallStep('clsDepts._newItem()');
+
    protected function _newItem() {
    return new clsDept($this);
+
CallStep('clsDepts._newItem()');
  }
+
return new clsDept($this);
  public function DoListing_forSupp($iSuppID) {
+
    }
    CallEnter($this,__LINE__,'clsDepts.DoListing_forSupp('.$iSuppID.')');
+
 
   
+
// THIS FUNCTION IS DEPRECATED
    $out = '<p class=main><big>Departments:</big></p><table class=depts>';
+
/*
    $objDepts = $this->GetData('ID_Supplier='.$iSuppID,'clsDept');
+
    public function DoListing_forSupp($iSuppID) {
    $isFirst = true;
+
CallEnter($this,__LINE__,'clsDepts.DoListing_forSupp('.$iSuppID.')');
 +
 +
//$objRows = $this->objDB->DataSet('SELECT * FROM qryItTypsDepts_ItTyps WHERE ID_Supplier='.$iSuppID);
 +
$objRows = $this->Data_forStore();
 +
while ($objRows->NextRow()) {
 +
      $idItTyp = $objRows->ID_ItTyp;
 +
      $intCntForSale = $objRows->cntForSale;
 +
      $arTypSng[$idItTyp] = $objRows->ItTyp_Sng;
 +
      $arTypPlr[$idItTyp] = $objRows->ItTyp_Plr;
 +
 
 +
// accumulate the list of everything this supplier has:
 +
      $idSupp = $objRows->ID_Supplier;
 +
      if (isset($arSuppCntForSale[$idItTyp])) {
 +
  $arSuppCntForSale[$idItTyp] += $intCntForSale;
 +
      } else {
 +
  $arSuppCntForSale[$idItTyp] = $intCntForSale;
 +
      }
 +
 
 +
// accumulate the department listing:
 +
      $idDept = $objRows->ID_Dept;
 +
      $arDeptCntForSale[$idDept][$idItTyp] = $intCntForSale;
 +
}
 +
 
 +
// Now present the accumulated data:
 +
  // - SUPPLIER:
 +
$outRow = '';
 +
foreach ($arSuppCntForSale as $idType=>$cnt) {
 +
    if ($cnt == 1) {
 +
$strType = $arTypSng[$idType];
 +
    } else {
 +
$strType = $arTypPlr[$idType];
 +
    }
 +
    if ($outRow != '') {
 +
$outRow .= ', ';
 +
    }
 +
    $outRow .= '<b>'.$cnt.'</b> '.$strType;
 +
}
 +
$out = '<span class=catalog-summary>'.$outRow.'</span>';
 +
 
 +
  // - DEPARTMENTS:
 +
$out .= '<p class=main><big>Departments:</big></p><table class=depts>';
 +
$isOdd = FALSE;
 +
foreach ($arDeptCntForSale as $idDept=>$arCnts) {
 +
      $isOdd = !$isOdd;
 +
      if ($isOdd) {
 +
  $cellOpen = '<td class=catalog-stripe valign=top>';
 +
      } else {
 +
  $cellOpen = '<td class=catalog valign=top>';
 +
      }
 +
 
 +
      $objDept = $this->objDB->Depts()->GetItem($idDept);
 +
      $strPageKey = $objDept->PageKey();
 +
      $strName = $objDept->Name;
 +
      $out .= '<tr>'.$cellOpen.'<a href="'.strtolower($strPageKey).'/">'.$strName.'</a></td>';
 +
      $outRow = '';
 +
      foreach ($arCnts as $idType=>$cnt) {
 +
  if ($cnt == 1) {
 +
      $strType = $arTypSng[$idType];
 +
  } else {
 +
      $strType = $arTypPlr[$idType];
 +
  }
 +
  if ($outRow != '') {
 +
      $outRow .= ', ';
 +
  }
 +
  $outRow .= '<b>'.$cnt.'</b> '.$strType;
 +
      }
 +
      $out .= $cellOpen.$outRow.'</td></tr>';
 +
}
 +
$out .= '</table>';
  
    $isOdd = FALSE;
+
CallExit('clsDepts.DoListing_forSupp()');
    while ($objDepts->NextRow()) {
+
return $out;
      $outDept = $objDepts->DoListing();
 
      if ($outDept) { // only show departments with something in them
 
        if ($isOdd) {
 
          $cellOpen = '<td class=catalog-stripe valign=top>';
 
        } else {
 
          $cellOpen = '<td class=catalog valign=top>';
 
        }
 
        $keyDept = $objDepts->PageKey();
 
        $out .= '<tr>'.$cellOpen.'<a href="'.strtolower($keyDept).'/">'.$objDepts->Name.'</a></td>';
 
        $isOdd = !$isOdd;
 
        $out .= $cellOpen.$outDept.'</td></tr>';
 
      }
 
 
     }
 
     }
    $out .= '</table>';
 
    CallExit('clsDepts.DoListing_forSupp()');
 
    return $out;
 
 
/**/
 
/**/
  }
 
 
}
 
}
 
class clsDept extends clsDataSet {
 
class clsDept extends clsDataSet {
 
// object cache
 
// object cache
  private $objSupp;
+
    private $objSupp;
  
  public function Supplier() {
+
    public function SuppObj() {
    if (is_object($this->objSupp)) {
+
if (is_object($this->objSupp)) {
      return $this->objSupp;
+
    return $this->objSupp;
    } else {
+
} else {
      $idSupp = $this->ID_Supplier;
+
    $idSupp = $this->ID_Supplier;
      if ($idSupp) {
+
    if ($idSupp) {
        $this->objSupp = $this->objDB->Suppliers()->GetItem($idSupp);
+
$this->objSupp = $this->objDB->Suppliers()->GetItem($idSupp);
        return $this->objSupp;
+
return $this->objSupp;
      } else {
+
    } else {
        return NULL;
+
return NULL;
      }
+
    }
 +
}
 +
    }
 +
    // DEPRECATED -- use SuppObj()
 +
    public function Supplier() {
 +
return $this->SuppObj();
 +
    }
 +
    public function PageKey() {
 +
if ($this->PageKey) {
 +
    return $this->PageKey;
 +
} else {
 +
    return $this->CatKey;
 +
}
 
     }
 
     }
  }
+
    /*----
  public function PageKey() {
+
      PURPOSE: loads data needed to display catalog views for this department
    if ($this->PageKey) {
+
      HISTORY
      return $this->PageKey;
+
2010-11-12 disabled automatic cache update
    } else {
+
2010-11-16 changed sorting field from cntInPrint to cntForSale
      return $this->CatKey;
+
2011-02-02 using _dept_ittyps now instead of qryItTypsDepts_ItTyps
 +
  Also added "AND (cntForSale)" to WHERE clause -- not listing titles with nothing to sell
 +
    */
 +
    protected function Data_forStore() { // was GetDeptData()
 +
//$objCache = $this->objDB->CacheMgr();
 +
//$objCache->Update_byName('_dept_ittyps','clsDept.DoListing() for ID='.$this->ID);
 +
//$sql = 'SELECT * FROM qryItTypsDepts_ItTyps WHERE (ID_Dept='.$this->ID.') ORDER BY cntForSale DESC';
 +
$sql = 'SELECT * FROM _dept_ittyps WHERE (ID_Dept='.$this->ID.') AND (cntForSale) ORDER BY cntForSale DESC';
 +
$objItTyps = $this->objDB->DataSet($sql,'clsItTyp');
 +
return $objItTyps;
 
     }
 
     }
  }
+
     /*-----
  protected function GetDeptData() {
+
      PURPOSE: Print this department's information as part of department list
     global $objDataMgr;
+
      HISTORY:
 
+
2010-11-16 $cntAvail is now cntForSale, not cntInPrint+qtyInStock
    $objDataMgr->Update_byName('_dept_ittyps','clsDept.DoListing() for ID='.$this->ID);
+
    */
    $sql = 'SELECT * FROM qryItTypsDepts_ItTyps WHERE (ID_Dept='.$this->ID.') ORDER BY cntInPrint DESC';
+
     public function DoListing() {
    $objItTyps = $this->objDB->DataSet($sql,'clsItTyp');
+
assert('$this->ID');
    return $objItTyps;
+
$objItTyps = $this->Data_forStore();
  }
+
$isFirst = true;
  public function DoListing() {
+
$out = '';
// PURPOSE: Print this department's information as part of department list
+
while ($objItTyps->NextRow()) {
 
+
    if ($isFirst) {
     assert('$this->ID');
+
$isFirst = false;
    $objItTyps = $this->GetDeptData();
+
    } else {
    $isFirst = true;
+
$out .= ', ';
    $out = '';
+
    }
    while ($objItTyps->NextRow()) {
+
    $cntInPrint = $objItTyps->cntInPrint;
      if ($isFirst) {
+
    $qtyInStock = $objItTyps->qtyForSale;
        $isFirst = false;
+
    //$cntAvail = $cntInPrint + $qtyInStock;
      } else {
+
    $cntForSale = $objItTyps->cntForSale;
        $out .= ', ';
+
    if ($cntAvail == 1) {
      }
+
$strName = $objItTyps->ItTyp_Sng;
      $cntInPrint = $objItTyps->cntInPrint;
+
    } else {
      $qtyInStock = $objItTyps->qtyForSale;
+
$strName = $objItTyps->ItTyp_Plr;
// TO FIX: This is wrong. Need cntForSale field
+
    }
      $cntAvail = $cntInPrint + $qtyInStock;
+
    $out .= ' <b>'.$cntAvail.'</b> '.$strName;
      if ($cntAvail == 1) {
+
}
        $strName = $objItTyps->ItTyp_Sng;
+
return $out;
      } else {
 
        $strName = $objItTyps->ItTyp_Plr;
 
      }
 
      $out .= ' <b>'.$cntAvail.'</b> '.$strName;
 
 
     }
 
     }
     return $out;
+
     /*----
  }
+
      PURPOSE: Print page for current department
  public function DoPage() {
+
      ACTION:
// PURPOSE: Print page for current department
+
* Iterates through item types available for this department.
// ACTION:
+
* For each item type, prints header and then a list of titles.
// * Iterates through item types available for this department.
+
      HISTORY:
// * For each item type, prints header and then a list of titles.
+
2010-11-?? Started using cached table _title_ittyps instead of qryTitles_ItTyps_Titles
    global $objDataMgr;
+
2010-11-16 $cntAvail is now cntForSale, not cntInPrint+qtyInStock
 
+
2011-02-02 $qtyInStock now set to Row['qtyInStock'], not Row['qtyForSale'] which didn't make sense anyway
     assert('$this->ID');
+
    */
    $out = '';
+
     public function DoPage() {
    $idDept = $this->ID;
+
$out = '';
    $objSection = new clsPageOutput();
+
$idDept = $this->ID;
    $objItTyps = $this->GetDeptData();
+
if (empty($idDept)) {
    $objTitles = new clsTitleExt($this->objDB);
+
    throw new exception('Department object has no ID');
    $objNoImgSect = new clsPageOutput();
+
}
    $cntSections = 0;
+
$objSection = new clsPageOutput();
    while ($objItTyps->NextRow()) {
+
// calculate the list of item types available in this department
      $cntInPrint = $objItTyps->cntInPrint;
+
$objItTyps = $this->Data_forStore();
      $qtyInStock = $objItTyps->qtyForSale;
+
$objTitles = new clsVbzTitle($this->objDB);
// TO FIX: This is wrong. Need cntForSale field
+
$objNoImgSect = new clsPageOutput();
      $cntAvail = $cntInPrint + $qtyInStock;
+
$cntSections = 0;
      if ($cntAvail) {
+
while ($objItTyps->NextRow()) {
        $cntSections++;
+
    $cntInPrint = $objItTyps->Row['cntInPrint'];
        $idItTyp = $objItTyps->ID_ItTyp;
+
    $qtyInStock = $objItTyps->Row['qtyInStock'];
//        $objSection->SectionHdr();
+
    $cntAvail = $objItTyps->Row['cntForSale'];
//        $sql = 'SELECT *, ID_Title AS ID, TitleName AS Name FROM _title_ittyps WHERE ((cntForSale) AND (ID_ItTyp='.$idItTyp.') AND (ID_Dept='.$idDept.'));';
+
    if ($cntAvail) {
        $sql = 'SELECT t.ID_Title AS ID, t.* FROM qryTitles_ItTyps_Titles AS t WHERE (ID_ItTyp='.$idItTyp.') AND (ID_Dept='.$idDept.');';
+
$cntSections++;
//        $objDataMgr->Update_byName('_title_ittyps','clsDept.DoPage() for ID_ItTyp='.$idItTyp.', ID_Dept='.$idDept);
+
$idItTyp = $objItTyps->Row['ID_ItTyp'];
        $objTitles->Query($sql);
+
        $sql = 'SELECT *, ID_Title AS ID, TitleName AS Name, cntInStock FROM _title_ittyps WHERE ((cntForSale) AND (ID_ItTyp='.$idItTyp.') AND (ID_Dept='.$idDept.'));';
//        $idTitle = $objTitles->GetValue('ID_Title');
+
//$sql = 'SELECT t.ID_Title AS ID, t.* FROM qryTitles_ItTyps_Titles AS t WHERE (ID_ItTyp='.$idItTyp.') AND (ID_Dept='.$idDept.');';
//        $objTitles->ID = $idTitle;
+
$objTitles->Query($sql);
 
 
        if ($objTitles->hasRows()) {
+
$arTitles = NULL;
          while ($objTitles->NextRow()) {
+
if ($objTitles->hasRows()) {
    // make a copy with current row's data
+
    while ($objTitles->NextRow()) {
            $objTitle = new clsDataSet(NULL,$objTitles->Res,$objTitles->Row);
+
// add title to display list
    //$objTitle = clone $objTitles;
+
$arTitles[] = $objTitles->Values(); // save it in a list
            $lstTitles[] = $objTitle; // save it in a list
+
    }
          }
+
    assert('is_array($arTitles)');
          assert('is_array($lstTitles)');
 
  
// We've generated the list of titles for this section; now display the section header and titles:
+
  // We've generated the list of titles for this section; now display the section header and titles:
 
+
    $out .= $this->objDB->ShowTitles($objItTyps->Row['ItTypNamePlr'].':',$arTitles,$objNoImgSect);
//          $out .= $objSection->ShowTitles($objItTyps->ItTypNamePlr.':',$lstTitles,$objNoImgSect);
+
} else {
//          $out .= $objSection->ShowTitles($objItTyps->ItTyp_Plr.':',$lstTitles,$objNoImgSect);
+
    echo 'ERROR: No titles found! SQL='.$sql;
          $out .= $this->objDB->ShowTitles($objItTyps->ItTyp_Plr.':',$lstTitles,$objNoImgSect);
+
}
        } else {
+
$objSection->Clear();
  echo 'ERROR: No titles found! SQL='.$sql;
+
    } else {
        }
+
$out .= '<span class=main>Small coding error: this line should never happen.</span>'; // TO DO: log an error
        unset($lstTitles);
+
    }
        $objSection->Clear();
+
}
      } else {
+
if (!$cntSections) {
        $out .= '<span class=main>Small coding error: this line should never happen.</span>'; // TO DO: log an error
+
    $out .= '<span class=main>This department appears to have been emptied of all leftover stock. (Eventually there will be a way to see what items used to be here.)</span>';
      }
+
}
 +
if ($objNoImgSect->inTbl) {
 +
    $objNoImgSect->EndTable();
 +
    $objSection->AddText($objNoImgSect->out);
 +
    $objSection->EndTable();
 +
    $out .= $objSection->out;
 +
}
 +
return $out;
 +
    }
 +
    public function URL_Rel() {
 +
$strURL = $this->Supplier()->URL();
 +
$strKey = $this->PageKey();
 +
if ($strKey) {
 +
    $strURL .= strtolower($strKey).'/';
 +
}
 +
return $strURL;
 +
    }
 +
    public function URL_Abs() {
 +
return KWP_ROOT.$this->URL_Rel();
 
     }
 
     }
     if (!$cntSections) {
+
     public function LinkName() {
        $out .= '<span class=main>This department appears to have been emptied of all leftover stock. (Eventually there will be a way to see what items used to be here.)</span>';
+
$strURL = $this->URL_Rel();
 +
return '<a href="'.$strURL.'">'.$this->Name.'</a>';
 
     }
 
     }
     if ($objNoImgSect->inTbl) {
+
     /*-----
      $objNoImgSect->EndTable();
+
      RETURNS: The string which, when prepended to a Title's CatKey, would form the Title's catalog number
      $objSection->AddText($objNoImgSect->out);
+
    */
      $objSection->EndTable();
+
    public function CatPfx() {
      $out .= $objSection->out;
+
$strFull = strtoupper($this->Supplier()->CatKey);
 +
if ($this->AffectsCatNum()) {
 +
    $strFull .= '-'.strtoupper($this->CatKey);
 +
}
 +
return $strFull.'-';
 
     }
 
     }
     return $out;
+
     /*-----
  }
+
      RETURNS: TRUE if this department affects the catalog number (i.e. if CatKey is non-blank)
  public function LinkName() {
+
     */
     $strURL = $this->Supplier()->URL();
+
     public function AffectsCatNum() {
     if ($this->PageKey) {
+
return ($this->CatKey != '');
      $strURL .= strtolower($this->PageKey).'/';
 
 
     }
 
     }
//    return '<a href="'.KWP_CAT_REL.$strURL.'">'.$this->Name.'</a>';
 
    return '<a href="'.$strURL.'">'.$this->Name.'</a>';
 
  }
 
 
}
 
}
  
class clsTitles extends clsVbzTable {
+
class clsVbzTitles extends clsVbzTable {
  public function __construct($iDB) {
+
    public function __construct($iDB) {
    parent::__construct($iDB);
+
parent::__construct($iDB);
      $this->Name('cat_titles');
+
  $this->Name('cat_titles');
      $this->KeyName('ID');
+
  $this->KeyName('ID');
      $this->ClassSng('clsTitle');
+
  $this->ClassSng('clsVbzTitle');
  }
+
    }
 +
    public function Search_forText_SQL($iFind) {
 +
return '(Name LIKE "%'.$iFind.'%") OR (`Desc` LIKE "%'.$iFind.'%")';
 +
    }
 +
    public function Search_forText($iFind) {
 +
$sqlFilt = $this->Search_forText_SQL($iFind);
 +
$rs = $this->GetData($sqlFilt);
 +
return $rs;
 +
    }
 
/*
 
/*
 
  ACTION: Finds a Title from a CatNum and returns an object for it
 
  ACTION: Finds a Title from a CatNum and returns an object for it
  TO DO: Rename to Get_byCatNum()
+
  TO DO:
 +
    Rename to Get_byCatNum()
 +
    Stop using v_titles
 
*/
 
*/
 +
/* 2010-11-07 Is anything actually using this?
 
   public function GetItem_byCatNum($iCatNum) {
 
   public function GetItem_byCatNum($iCatNum) {
 
     global $objDataMgr;
 
     global $objDataMgr;
Line 1,087: Line 1,504:
 
     $sqlCatNum = $this->objDB->SafeParam($sqlCatNum);
 
     $sqlCatNum = $this->objDB->SafeParam($sqlCatNum);
 
     $sql = 'SELECT * FROM v_titles WHERE CatNum="'.$sqlCatNum.'"';
 
     $sql = 'SELECT * FROM v_titles WHERE CatNum="'.$sqlCatNum.'"';
     $objTitle = new clsTitleExt($this);
+
//    $objTitle = new clsVbzTitleExt($this);
 +
     $objTitle = new clsVbzTitle($this);
 
     // make sure _titles (part of v_titles) is up-to-date
 
     // make sure _titles (part of v_titles) is up-to-date
 
     //$objDataMgr->Update_byName('_titles','GetItem_byCatNum('.$iCatNum.')');
 
     //$objDataMgr->Update_byName('_titles','GetItem_byCatNum('.$iCatNum.')');
Line 1,100: Line 1,518:
 
       $objTitle->dontLoadBasic = true;
 
       $objTitle->dontLoadBasic = true;
 
       $objTitle->Query($sql);
 
       $objTitle->Query($sql);
       CallExit('clsTitles.GetItem_byCatNum() -> ok');
+
       CallExit('clsVbzTitles.GetItem_byCatNum() -> ok');
 
       return $objTitle;
 
       return $objTitle;
 
     } else {
 
     } else {
       CallExit('clsTitles.GetItem_byCatNum() -> NULL');
+
       CallExit('clsVbzTitles.GetItem_byCatNum() -> NULL');
 
       return NULL;
 
       return NULL;
 
     }
 
     }
 
   }
 
   }
 +
*/
 
}
 
}
class clsTitle extends clsDataSet {
+
class clsVbzTitle extends clsDataSet {
// == STATIC SECTION ==
 
  const cksTblName = 'cat_titles';
 
  const cksIDName = 'ID';
 
 
 
  public static function GetItem($iID) {
 
    $sql = 'SELECT * FROM '.self::cksTblName.' WHERE '.self::cksIDName.'="'.$iID.'"';
 
    $objItem = new self;
 
    $objItem->Query($sql);
 
    return $objItem;
 
  }
 
 
 
// == DYNAMIC SECTION ==
 
 
// object cache
 
// object cache
  private $objDept;
+
    private $objDept;
 +
    private $objSupp;
 
// options
 
// options
  public $hideImgs;
+
    public $hideImgs;
  
  public function Dept() {
+
    public function Dept() {
    if (is_object($this->objDept)) {
+
$doLoad = FALSE;
      return $this->objDept;
+
if (empty($this->objDept)) {
    } else {
+
    $doLoad = TRUE;
      $idDept = $this->ID_Dept;
+
} else if (is_object($this->objDept)) {
      if ($idDept) {
+
    if ($this->ID_Dept != $this->objDept->ID) {
        $objDept = $this->objDB->Depts()->GetItem($idDept);
+
$doLoad = TRUE;
        $this->objDept = $objDept;
+
    }
        assert('is_object($objDept)');
+
} else {
        return $objDept;
+
    $doLoad = TRUE;
      } else {
+
}
        return NULL;
+
if ($doLoad) {
      }
+
    $idDept = $this->ID_Dept;
 +
    if (empty($idDept)) {
 +
$objDept = NULL;
 +
    } else {
 +
$objDept = $this->objDB->Depts()->GetItem($idDept);
 +
assert('is_object($objDept)');
 +
    }
 +
    $this->objDept = $objDept;
 +
}
 +
return $this->objDept;
 +
    }
 +
    /*----
 +
      RETURNS: ID of this title's supplier
 +
      HISTORY:
 +
2011-09-28 revised to get ID directly from the new ID_Supp field
 +
  instead of having to look up the Dept and get it from there.
 +
    */
 +
    public function Supplier_ID() {
 +
/*
 +
$objDept = $this->Dept();
 +
$idSupp = $objDept->ID_Supplier;
 +
*/
 +
$idSupp = $this->Value('ID_Supp');
 +
return $idSupp;
 +
    }
 +
    // DEPRECATED -- use SuppObj()
 +
    public function Supplier() {
 +
return $this->SuppObj();
 +
    }
 +
    public function SuppObj() {
 +
$doLoad = FALSE;
 +
if (empty($this->objSupp)) {
 +
    $doLoad = TRUE;
 +
} else if (is_object($this->objSupp)) {
 +
    if ($this->ID_Supplier != $this->objSupp->ID) {
 +
$doLoad = TRUE;
 +
    }
 +
} else {
 +
    $doLoad = TRUE;
 +
}
 +
if ($doLoad) {
 +
    $idSupp = $this->Supplier_ID();
 +
    if (empty($idSupp)) {
 +
$objSupp = NULL;
 +
    } else {
 +
$objSupp = $this->objDB->Suppliers()->GetItem($idSupp);
 +
assert('is_object($objSupp)');
 +
    }
 +
    $this->objSupp = $objSupp;
 +
}
 +
return $this->objSupp;
 +
    }
 +
    public function Items() {
 +
$sqlFilt = 'ID_Title='.$this->ID;
 +
$objTbl = $this->objDB->Items();
 +
$objRows = $objTbl->GetData($sqlFilt);
 +
return $objRows;
 +
    }
 +
    public function Topics() {
 +
$objTbl = $this->Engine()->TitleTopic_Topics();
 +
$objRows = $objTbl->GetTitle($this->KeyValue());
 +
return $objRows;
 
     }
 
     }
  }
+
    public function DoPage() {
  public function IsActive() {
+
$idTitle = $this->KeyValue();
      if (is_null($this->DateUnavail)) {
+
assert('$idTitle');
  $out = TRUE;
+
$objSection = new clsPageOutput();
      } else {
 
  $out = ($this->DateUnavail > time());
 
      }
 
      return $out;
 
  }
 
  public function DoPage() {
 
    global $objDataMgr;
 
  
     $idTitle = $this->ID;
+
     // show "small" images
    assert('$idTitle');
+
if (!$this->hideImgs) {
    $objSection = new clsPageOutput();
+
    $objImgs = $this->ListImages('sm');
 +
    if ($objImgs->hasRows()) {
 +
while ($objImgs->NextRow()) {
 +
    $strImgTag = $objImgs->AttrDispl;
 +
    $urlRel = $objImgs->Spec;
 +
    $idImg = $objImgs->ID;
 +
    //$strImg = '<img src="'.KWP_IMG_MERCH.$urlRel.'"';
 +
    $strImg = '<img src="'.$objImgs->WebSpec().'"';
 +
    if ($strImgTag) {
 +
$strImg .= ' title="'.$strImgTag.'"';
 +
    }
 +
    $strImg .= '>';
 +
    $objImgBig = $objImgs->ImgForSize('big');
 +
    if (is_object($objImgBig)) {
 +
if ($objImgBig->FirstRow()) {
 +
    $strImg = $objImgBig->Href().$strImg.'</a>';
 +
}
 +
    }
 +
    $objSection->AddText($strImg);
 +
}
 +
    } else {
 +
      $objSection->ShowImgUnavail();
 +
    }
 +
}
  
// show small-size images
+
// list topics for this title
    if (!$this->hideImgs) {
+
$db = $this->Engine();
      $objImgs = $this->ListImages('sm');
+
$tbl = $db->TitleTopic_Topics();
      if ($objImgs->hasRows()) {
+
$tbl->doBranch(TRUE);
        while ($objImgs->NextRow()) {
+
$rs = $tbl->GetTitle($idTitle);
          $strImgTag = $objImgs->AttrDispl;
+
if ($rs->hasRows()) {
          $urlRel = $objImgs->Spec;
+
    $txt = '<table align=right style="border: solid 1px; background: black;"><tr><td bgcolor=#333333>';
          $idImg = $objImgs->ID;
+
    $txt .= '<b>'.$db->Topics()->IndexLink('Topics').'</b>:';
          $strImg = '<img src="'.KWP_IMG_MERCH.$urlRel.'"';
+
    while ($rs->NextRow()) {
          if ($strImgTag) {
+
$txt .= '<br>- '.$rs->ShopLink();
            $strImg .= ' title="'.$strImgTag.'"';
+
    }
          }
+
    $txt .= '</td></tr></table>';
          $strImg .= '>';
+
    $objSection->AddText($txt);
          $objImgBig = $objImgs->ImgForSize('big');
+
}
          if (is_object($objImgBig)) {
 
            if ($objImgBig->hasRow()) {
 
              $strImg = $objImgBig->Href().$strImg.'</a>';
 
            }
 
          }
 
          $objSection->AddText($strImg);
 
        }
 
      } else {
 
        $objSection->ShowImgUnavail();
 
      }
 
    }
 
  
 
// now list available items as table
 
// now list available items as table
    $sql = 'SELECT * FROM qryTitles_ItTyps_ItTyps WHERE (ID_Title='.$idTitle.') ORDER BY ItTyp_Sort IS NULL, ItTyp_Sort;';
+
//$sql = 'SELECT * FROM qryTitles_ItTyps_ItTyps WHERE (ID_Title='.$idTitle.') ORDER BY ItTyp_Sort IS NULL, ItTyp_Sort;';
    $objTypes = $this->objDB->DataSet($sql);
+
$sql = 'SELECT * FROM _title_ittyps WHERE (ID_Title='.$idTitle.') ORDER BY ItTypSort IS NULL, ItTypSort;';
    if ($objTypes->hasRows()) {
+
$rsTypes = $this->Engine()->DataSet($sql);
      if (KF_CART_ABSOLUTE) {
+
$isItem = FALSE;
        $urlCart = KWP_CART_ABS;
+
if ($rsTypes->hasRows()) {
      } else {
+
    if (KF_CART_ABSOLUTE) {
        $urlCart = KWP_CART_REL;
+
      $urlCart = KWP_CART_ABS;
      }
+
    } else {
      $objSection->AddText('<form method=post action="'.$urlCart.'"><input type=hidden name=from value=browse-multi>');
+
      $urlCart = KWP_CART_REL;
 +
    }
 +
    $objSection->AddText('<form method=post action="'.$urlCart.'"><input type=hidden name=from value=browse-multi>');
 +
 
 +
    $flagDisplayTogether = false; // hard-coded for now
  
      $flagDisplayTogether = false; // hard-coded for now
+
    //$objStk = $this->Engine()->Items_Stock();
 +
    $tblItems = $this->Engine()->Items();
 +
    //$txtTblHdr = '<tr><th align=left>Option</th><th>Status</th><th align=right class=title-price>Price</th><th align=center class=orderQty>Order<br>Qty.</th><th><i>list<br>price</th></tr>';
 +
    $txtTblHdr = $tblItems->Render_TableHdr();
 +
    $txtInStock = $txtOutStock = '';
  
      while ($objTypes->NextRow()) {
+
    while ($rsTypes->NextRow()) {
        $idItTyp = $objTypes->ID_ItTyp;
+
$idItTyp = $rsTypes->Value('ID_ItTyp');
        assert('$idItTyp');
+
assert('$idItTyp');
$sqlFilt = '(ID_Title='.$idTitle.') AND (ID_ItTyp='.$idItTyp.')';
+
$sqlFilt = '(ID_Title='.$idTitle.') AND (ID_ItTyp='.$idItTyp.')';
$sqlSort = 'GrpSort,GrpDescr,ItOpt_Sort';
+
$sqlSort = 'GrpSort,GrpDescr,ItOpt_Sort';
$objStk = $this->objDB->Items_Stock();
+
$rsItems = $tblItems->GetData($sqlFilt,NULL,$sqlSort);
$objItems = $objStk->GetData($sqlFilt,'clsItem',$sqlSort);
+
//$idItType = 0;
        $idItType = 0;
 
  
        $txtLine = '<tr class=typeHdr><td colspan=3><b>'.$objTypes->ItTyp_Plr.'</b>:</td></tr>';
+
$txtLine = '<tr class=typeHdr><td colspan=3><b>'.$rsTypes->Value('ItTypNamePlr').'</b>:</td></tr>';
  
        if ($flagDisplayTogether) {
+
if ($flagDisplayTogether) {
 
// displaying all items in a single listing
 
// displaying all items in a single listing
          $txtBoth .= $txtLine;
+
    $txtBoth .= $txtLine;
        } else {
+
} else {
 
// set flags to determine which stock-status sections to show
 
// set flags to determine which stock-status sections to show
          $cntInStock = $objTypes->cntStkForSale;
+
    $cntInStock = $rsTypes->Value('cntInStock');
          $cntForSale = $objTypes->cntForSale;
+
    $cntForSale = $rsTypes->Value('cntForSale');
          $cntOutStock = $cntForSale - $cntInStock;
+
    $cntOutStock = $cntForSale - $cntInStock;
 
 
  $txtInStock = $txtOutStock = '';
 
          if ($cntInStock > 0) {
 
            $txtInStock .= $txtLine;
 
          }
 
          if ($cntOutStock > 0) {
 
            $txtOutStock .= $txtLine;
 
          }
 
        }
 
  
 +
    if ($cntInStock > 0) {
 +
$txtInStock .= $txtLine;
 +
    }
 +
    if ($cntOutStock > 0) {
 +
$txtOutStock .= $txtLine;
 +
    }
 +
}
 
// iterate through items for this type:
 
// iterate through items for this type:
        $strGrpLast = '';
+
$strGrpLast = '';
        while ($objItems->NextRow()) {
+
while ($rsItems->NextRow()) {
          $strGrp = $objItems->GrpDescr;
+
    $strGrp = $rsItems->Value('GrpDescr');
  $qtyStk = $objItems->qtyForSale;
+
    $qtyStk = $rsItems->Value('QtyIn_Stk');
          if ($strGrp != $strGrpLast) {
+
    if ($strGrp != $strGrpLast) {
            $strGrpLast = $strGrp;
+
$strGrpLast = $strGrp;
            $strGrpCode = $objItems->GrpCode;
+
$strGrpCode = $rsItems->Value('GrpCode');
            $out = '<tr class="group">';
+
$out = '<tr class="group">';
            $out .= '<td colspan=5> &mdash; '.$strGrp;
+
$out .= '<td colspan=5> &mdash; '.$strGrp;
            if ($strGrpCode) {
+
if ($strGrpCode) {
              $out .= ' <font color=#666666>(<font color=#666699>'.$strGrpCode.'</font>)</font>';
+
    $out .= ' <font color=#666666>(<font color=#666699>'.$strGrpCode.'</font>)</font>';
            }
+
}
            $out .= '</td>';
+
$out .= '</td>';
            $out .= '</tr>';
+
$out .= '</tr>';
 
// this should probably be a subroutine...
 
// this should probably be a subroutine...
            if ($flagDisplayTogether) {
+
if ($flagDisplayTogether) {
              $txtBoth .= $out;
+
  $txtBoth .= $out;
            } else {
+
} else {
              if ($qtyStk > 0) {
+
  if ($qtyStk > 0) {
                $txtInStock .= $out;
+
    $txtInStock .= $out;
              } else {
+
  } else {
                $txtOutStock .= $out;
+
    $txtOutStock .= $out;
              }
+
  }
            }
+
}
          }
+
    }
          if ($objItems->isForSale) {
+
//echo '<br>GOT TO #1 - qty='.$qtyStk;
            $txtLine = $objItems->Print_TableRow();
+
    if ($rsItems->Value('isForSale')) {
 +
$isItem = TRUE;
 +
$txtLine = $rsItems->Render_TableRow();
  
            if ($flagDisplayTogether) {
+
if ($flagDisplayTogether) {
              $txtBoth .= $txtLine;
+
    $txtBoth .= $txtLine;
            } else {
+
} else {
              if ($qtyStk > 0) {
+
    if ($qtyStk > 0) {
                $txtInStock .= $txtLine;
+
$txtInStock .= $txtLine;
              } else {
+
    } else {
                $txtOutStock .= $txtLine;
+
$txtOutStock .= $txtLine;
              }
+
    }
            }
+
}
          }
+
    }
        }
+
}
      }
+
    }
  
 
// DO the actual display of the accumulated text
 
// DO the actual display of the accumulated text
 +
    $txtTblOpen = '<table class=main><tbody>';
 +
    $txtTblFtr = '<tr><td colspan="4" align="right"><input value="Add to Cart" type="submit"></td></tr>';
 +
    $txtTblShut = '</tbody></table>';
  
      $txtTblOpen = '<table class=main><tbody>';
+
    if ($flagDisplayTogether) {
      $txtTblHdr = '<tr><th align=left>Option</th><th>Status</th><th align=right class=title-price>Price</th><th align=center class=orderQty>Order<br>Qty.</th><th><i>list<br>price</th></tr>';
+
// Display in-stock and backordered items together
      $txtTblFtr = '<tr><td colspan="4" align="right"><input value="Add to Cart" type="submit"></td></tr>';
+
$objSection->AddText($txtTblOpen);
      $txtTblShut = '</tbody></table>';
+
$objSection->AddText($txtTblHdr);
 +
$objSection->AddText($txtBoth);
 +
$objSection->AddText($txtTblFtr);
 +
$objSection->AddText($txtTblShut);
 +
    } else {
 +
if ($txtInStock != '') {
 +
    $txtClause = Pluralize($cntInStock,'This item is','These items are');
 +
    $objSection->AddText($txtTblOpen);
 +
    $objSection->AddText('<tr class=inStock><td colspan=5>'.$txtClause.' in stock:</td></tr>');
 +
    $objSection->AddText($txtTblHdr);
 +
    $objSection->AddText($txtInStock);
 +
    $objSection->AddText($txtTblFtr);
 +
    $objSection->AddText($txtTblShut);
 +
}
  
      if ($flagDisplayTogether) {
+
if (!empty($txtOutStock)) {
// Display in-stock and backordered items together
+
    if (!empty($txtInStock)) {
        $objSection->AddText($txtTblOpen);
+
$objSection->AddText('<p>');
        $objSection->AddText($txtTblHdr);
+
    }
        $objSection->AddText($txtBoth);
+
    $txtClause = Pluralize($cntOutStock,'This item is','These items are');
        $objSection->AddText($txtTblFtr);
+
    $objSection->AddText($txtTblOpen);
        $objSection->AddText($txtTblShut);
+
    $objSection->AddText('<tr><td colspan=5>'.$txtClause.' <a href="'.KWP_HELP_NO_STOCK_BUT_AVAIL.'"><b>not in stock</b></a>');
 +
    $txtClause = Pluralize($cntOutStock,'it','them');
 +
    $objSection->AddText(', but we can (probably) <a href="'.KWP_HELP_POLICY_SHIP.'">get '.$txtClause.'</a>:</td></tr>');
 +
    $objSection->AddText($txtTblHdr);
 +
    $objSection->AddText($txtOutStock);
 +
    $objSection->AddText($txtTblFtr);
 +
    $objSection->AddText($txtTblShut);
 +
} /**/
 +
    }
 +
    $objSection->AddText('</form>');
 +
}
 +
if (!$isItem) {
 +
    $objSection->SectionHdr('This title is currently unavailable');
 +
}
 +
return $objSection->out."\n<!-- TITLE ID=$idTitle -->\n";
 +
    }
 +
    /*----
 +
      RETURNS: Array containing summary information about this title
 +
    */
 +
    public function Indicia(array $iarAttr=NULL) {
 +
$objItems = $this->Items();
 +
$intActive = 0;
 +
$intRetired = 0;
 +
if ($objItems->HasRows()) {
 +
    while ($objItems->NextRow()) {
 +
if ($objItems->isForSale) {
 +
    $intActive++;
 +
} else {
 +
    $intRetired++;
 +
}
 +
    }
 +
}
 +
// "dark-bg" brings up link colors for a dark background
 +
$arLink = array('class'=>'dark-bg');
 +
// merge in any overrides or additions from iarAttr:
 +
if (is_array($iarAttr)) {
 +
    $arLink = array_merge($arLink,$iarAttr);
 +
}
 +
$htLink = $this->Link($arLink);
 +
$txtCatNum = $this->CatNum();
 +
$txtName = $this->Name;
 +
 
 +
$arOut['cnt.active'] = $intActive;
 +
$arOut['cnt.retired'] = $intRetired;
 +
$arOut['txt.cat.num'] = $txtCatNum;
 +
$arOut['ht.link.open'] = $htLink;
 +
$arOut['ht.cat.line'] = $htLink.$txtCatNum.'</a> '.$txtName;
 +
 
 +
return $arOut;
 +
    }
 +
    /*----
 +
      RETURNS: Array containing summaries of ItTyps in which this Title is available
 +
array['text.!num'] = plaintext version with no numbers (types only)
 +
array['text.cnt'] = plaintext version with line counts
 +
array['html.cnt'] = HTML version with line counts
 +
array['html.qty'] = HTML version with stock quantities
 +
      HISTORY:
 +
2011-01-23 written
 +
    */
 +
    public function Summary_ItTyps($iSep=', ') {
 +
$dsRows = $this->DataSet_ItTyps();
 +
$outTextNoQ = $outTextType = $outTextCnt = $outHTMLCnt = $outHTMLQty = NULL;
 +
if ($dsRows->HasRows()) {
 +
    $isFirst = TRUE;
 +
    while ($dsRows->NextRow()) {
 +
$cntType = $dsRows->Value('cntForSale');
 +
if ($cntType > 0) {
 +
    $qtyStk = $dsRows->Value('qtyInStock');
 +
    $txtSng = $dsRows->Value('ItTypNameSng');
 +
    $txtPlr = $dsRows->Value('ItTypNamePlr');
 +
    $strType = Pluralize($cntType,$txtSng,$txtPlr);
 +
    if ($isFirst) {
 +
$isFirst = FALSE;
 +
    } else {
 +
$outTextType .= $iSep;
 +
$outTextCnt .= $iSep;
 +
$outHTMLCnt .= $iSep;
 +
if (!is_null($outHTMLQty)) {
 +
    $outHTMLQty .= $iSep;
 +
}
 +
    }
 +
    $outTextType .= $txtSng;
 +
    $outTextCnt .= $cntType.' '.$strType;
 +
    $outHTMLCnt .= '<b>'.$cntType.'</b> '.$strType;
 +
    if (!empty($qtyStk)) {
 +
$outHTMLQty .= '<b>'.$qtyStk.'</b> '.Pluralize($qtyStk,$txtSng,$txtPlr);
 +
    }
 +
}
 +
    }
 +
}
 +
$arOut['text.!num'] = $outTextType;
 +
$arOut['text.cnt'] = $outTextCnt;
 +
$arOut['html.cnt'] = $outHTMLCnt;
 +
$arOut['html.qty'] = $outHTMLQty;
 +
return $arOut;
 +
    }
 +
// LATER: change name to DataSet_Images() to clarify that this returns a dataset, not a text list or array
 +
    public function ListImages($iSize) {
 +
$sqlFilt = '(ID_Title='.$this->ID.') AND (Ab_Size="'.$iSize.'") AND isActive';
 +
$objImgs = $this->objDB->Images()->GetData($sqlFilt,'clsImage','AttrSort');
 +
return $objImgs;
 +
    }
 +
    /*----
 +
      RETURNS: dataset of item types for this title
 +
      USES: _title_ittyps (cached table)
 +
      HISTORY:
 +
2011-01-19 written
 +
    */
 +
    public function DataSet_ItTyps() {
 +
$sql = 'SELECT * FROM _title_ittyps WHERE ID_Title='.$this->KeyValue();
 +
$obj = $this->Engine()->DataSet($sql,'clsTitleIttyp');
 +
return $obj;
 +
    }
 +
    /*----
 +
      HISTORY:
 +
2010-10-19 added optimization to fetch answer from CatKey field if it exists.
 +
  This may cause future problems. Remove $iSep field and create individual functions
 +
  if so.
 +
    */
 +
    public function CatNum($iSep='-') {
 +
      if (empty($this->Row['CatNum'])) {
 +
  $objDept = $this->Dept();
 +
  if (is_object($objDept)) {
 +
      $objSupp = $objDept->Supplier();
 +
      $strDeptKey = $objDept->CatKey;
 +
      $strOut = $objSupp->CatKey;
 +
      if ($strDeptKey) {
 +
$strOut .= $iSep.$strDeptKey;
 +
      }
 +
  } else {
 +
      $strOut = '?';
 +
  }
 +
  $strOut .= $iSep.$this->CatKey;
 
       } else {
 
       } else {
        if ($txtInStock != '') {
+
  $strOut = $this->CatNum;
          $txtClause = Pluralize($cntInStock,'This item is','These items are');
 
          $objSection->AddText($txtTblOpen);
 
          $objSection->AddText('<tr class=inStock><td colspan=5>'.$txtClause.' in stock:</td></tr>');
 
          $objSection->AddText($txtTblHdr);
 
          $objSection->AddText($txtInStock);
 
          $objSection->AddText($txtTblFtr);
 
          $objSection->AddText($txtTblShut);
 
        }
 
 
 
        if ($txtOutStock != '') {
 
          if ($txtInStock != '') {
 
            $objSection->AddText('<p>');
 
          }
 
          $txtClause = Pluralize($cntOutStock,'This item is','These items are');
 
          $objSection->AddText($txtTblOpen);
 
          $objSection->AddText('<tr><td colspan=5>'.$txtClause.' <a href="http://wiki.vbz.net/Available_but_not_in_stock"><b>not in stock</b></a>');
 
          $txtClause = Pluralize($cntOutStock,'it','them');
 
          $objSection->AddText(', but we can (probably) <a href="http://wiki.vbz.net/Shipping_Policies">get '.$txtClause.'</a>:</td></tr>');
 
          $objSection->AddText($txtTblHdr);
 
          $objSection->AddText($txtOutStock);
 
          $objSection->AddText($txtTblFtr);
 
          $objSection->AddText($txtTblShut);
 
        } /**/
 
 
       }
 
       }
//      $objSection->AddText('<tr><td colspan="4" align="right"><input value="Add to Cart" type="submit"></td></tr></tbody></table></form>');
+
       return strtoupper($strOut);
       $objSection->AddText('</form>');
 
    } else {
 
      $objSection->SectionHdr('This title is currently unavailable');
 
    }
 
    return $objSection->out;
 
  }
 
  public function ListImages($iSize) {
 
    $sqlFilt = '(ID_Title='.$this->ID.') AND (Ab_Size="'.$iSize.'")';
 
    $objImgs = $this->objDB->Images()->GetData($sqlFilt,'clsImage','AttrSort');
 
    return $objImgs;
 
  }
 
  public function CatNum($iSep='-') {
 
    $objDept = $this->Dept();
 
    $objSupp = $objDept->Supplier();
 
    $strDeptKey = $objDept->CatKey;
 
    $strOut = $objSupp->CatKey;
 
    if ($strDeptKey) {
 
      $strOut .= $iSep.$strDeptKey;
 
 
     }
 
     }
    $strOut .= $iSep.$this->CatKey;
 
    return strtoupper($strOut);
 
  }
 
 
   public function URL_part() {
 
   public function URL_part() {
 
     return strtolower($this->CatNum('/'));
 
     return strtolower($this->CatNum('/'));
 
   }
 
   }
   public function URL() {
+
   public function URL($iBase=KWP_CAT_REL) {
     return KWP_CAT_REL.$this->URL_part();
+
     return $iBase.$this->URL_part();
 
   }
 
   }
   public function Link() {
+
    public function Link(array $iarAttr=NULL) {
     $strURL = $this->URL();
+
$strURL = $this->URL();
 +
$htAttr = ArrayToAttrs($iarAttr);
 +
return '<a'.$htAttr.' href="'.$strURL.'">';
 +
    }
 +
   public function LinkAbs() {
 +
     $strURL = $this->URL(KWP_CAT);
 
     return '<a href="'.$strURL.'">';
 
     return '<a href="'.$strURL.'">';
 
   }
 
   }
Line 1,342: Line 1,932:
 
     return $this->Link().$this->Name.'</a>';
 
     return $this->Link().$this->Name.'</a>';
 
   }
 
   }
 +
/* 2010-11-06 if this is needed, use a method in SpecialVbzAdmin
 
   public function LinkName_wt() {
 
   public function LinkName_wt() {
 
// TO DO: make this more configurable
 
// TO DO: make this more configurable
Line 1,347: Line 1,938:
 
     return $out;
 
     return $out;
 
   }
 
   }
 +
*/
 
}
 
}
// extended Title data from v_titles
 
class clsTitlesExt extends clsTitles {
 
  public function __construct($iDB) {
 
    parent::__construct($iDB);
 
      $this->Name('v_titles');
 
      $this->KeyName('ID');
 
  }
 
  protected function _newItem() {
 
    CallStep('clsTitlesExt._newItem()');
 
    return new clsTitleExt($this);
 
  }
 
}
 
// this encapsulates [_titles] instead of [titles]
 
class clsTitleExt extends clsTitle {
 
/*
 
  public $CatNum;
 
  public $CatWeb;
 
  public $curMinPrice;
 
  public $curMaxPrice;
 
  public $idItTyp;
 
  public $qtyInStock;
 
*/
 
// action flags
 
  public $dontLoadBasic;
 
/*
 
  protected function LoadResults() {
 
    CallEnter($this,__LINE__,'clsTitleExt.LoadResults()');
 
    if (!$this->dontLoadBasic) {
 
      parent::LoadResults();
 
    }
 
  
    $this->CatNum = $this->GetValue('CatNum');
+
/*====
    $this->CatWeb = $this->GetValue('CatWeb');
+
  PURPOSE: TITLE/ITTYP hybrid
    $this->currMinPrice = $this->GetValue('currMinPrice');
+
   TABLE: _title_ittyps
    $this->currMaxPrice = $this->GetValue('currMaxPrice');
 
    $this->idItTyp = $this->GetValue('ID_ItTyp');
 
    $this->qtyInStock = $this->GetValue('qtyInStock');
 
 
 
    CallExit('clsTitle.LoadResults()');
 
   }
 
 
*/
 
*/
  public function Link() {
 
    $out = '<a class="thumb" href="'.$this->URL().'">';
 
    return $out;
 
  }
 
  public function URL() {
 
    return KWP_CAT_REL.$this->CatWeb.'/';
 
  }
 
}
 
/* -------------------- *\
 
    TITLE/ITTYP hybrid
 
\* -------------------- */
 
 
class clsTitleIttyp extends clsDataSet {
 
class clsTitleIttyp extends clsDataSet {
/*
 
  public $ID_ItTyp;
 
  //public $ID_Dept;
 
  public $cntForSale;
 
  public $cntInPrint;
 
  public $cntInStock;
 
  public $qtyInStock;
 
  public $ItTypSng;
 
  public $ItTypPlr;
 
*/
 
 
// object cache
 
// object cache
 
   private $objIttyp;
 
   private $objIttyp;
  
/*
 
  protected function LoadResults() {
 
    CallEnter($this,__LINE__,'clsTitleIttyp.LoadResults()');
 
    $idItTyp = $this->GetValue('ID_ItTyp');
 
    if ($idItTyp != $this->ID_ItTyp) {
 
      $this->ID_ItTyp = $this->GetValue('ID_ItTyp');
 
      $this->objIttyp = NULL;
 
    }
 
    $this->ID_Title = $this->GetValue('ID_Title');
 
    //$this->ID_Dept = $this->GetValue('ID_Dept');
 
    $this->cntForSale = $this->GetValue('cntForSale');
 
    $this->cntInPrint = $this->GetValue('cntInPrint');
 
    $this->cntInStock = $this->GetValue('cntInStock');
 
    $this->qtyInStock = $this->GetValue('qtyInStock');
 
    $this->ItTypSng = $this->GetValue('ItTyp_Sng');
 
    $this->ItTypPlr = $this->GetValue('ItTyp_Plr');
 
    if ($this->ID_ItTyp) { } else {
 
      echo 'ERROR: ID_ItTyp has no value! data = ';
 
      DumpArray($this->Row,TRUE);
 
    }
 
    CallExit('clsTitleIttyp.LoadResults()');
 
  }
 
*/
 
 
   public function Ittyp() {
 
   public function Ittyp() {
 
     if (is_null($this->objIttyp)) {
 
     if (is_null($this->objIttyp)) {
Line 1,449: Line 1,961:
 
class clsItems extends clsVbzTable {
 
class clsItems extends clsVbzTable {
  
  public function __construct($iDB) {
+
    public function __construct($iDB) {
    parent::__construct($iDB);
+
parent::__construct($iDB);
      $this->Name('cat_items');
+
  $this->Name('cat_items');
      $this->KeyName('ID');
+
  $this->KeyName('ID');
      $this->ClassSng('clsItem');
+
  $this->ClassSng('clsItem');
  }
+
    }
/*
+
    /*----
ACTION: Finds the Item with the given CatNum, and returns a clsItem object
+
      ACTION: Finds the Item with the given CatNum, and returns a clsItem object
*/
+
    */
  public function Get_byCatNum($iCatNum) {
+
    public function Get_byCatNum($iCatNum) {
      $sqlCatNum = $this->objDB->SafeParam($iCatNum);
+
$sqlCatNum = $this->objDB->SafeParam(strtoupper($iCatNum));
      $objItem = $this->GetData('CatNum="'.$sqlCatNum.'"');
+
$objItem = $this->GetData('CatNum="'.$sqlCatNum.'"');
      if ($objItem->HasRows()) {
+
if ($objItem->HasRows()) {
  $objItem->NextRow();
+
    $objItem->NextRow();
  return $objItem;
+
    return $objItem;
      } else {
+
} else {
  return NULL;
+
    return NULL;
       }
+
}
  }
+
    }
 +
    public function Search_byCatNum($iCatNum) {
 +
$sqlCatNum = $this->objDB->SafeParam(strtoupper($iCatNum));
 +
$objItem = $this->GetData('CatNum LIKE "%'.$sqlCatNum.'%"');
 +
if ($objItem->HasRows()) {
 +
    return $objItem;
 +
} else {
 +
    return NULL;
 +
}
 +
    }
 +
    /*----
 +
       RETURNS: Table header for list of available items on catalog Title pages
 +
      HISTORY:
 +
2011-01-24 created/corrected from code in Title page-display function
 +
    */
 +
    public function Render_TableHdr() {
 +
return '<tr>'
 +
  .'<th align=left>Option</th>'
 +
  .'<th>Status</th>'
 +
  .'<th align=center><i>List<br>Price</th>'
 +
  .'<th align=center class=title-price>Our<br>Price</th>'
 +
  .'<th align=center class=orderQty>Order<br>Qty.</th>'
 +
  .'</tr>';
 +
    }
 
}
 
}
 
/* ===============
 
/* ===============
 
  CLASS: clsItem
 
  CLASS: clsItem
  NOTE: "in stock" always refers to stock for sale, not stock which has already been purchased
+
  NOTES:
 +
  * "in stock" always refers to stock for sale, not stock which has already been purchased
 +
  * 2009-12-03: The above note does not clarify anything.
 +
  * Four methods were moved here from clsShopCartLine in shop.php: ItemSpecs(), ItemDesc(), ItemDesc_ht(), ItemDesc_wt()
 +
    They are used for displaying a full description of an item, in both shop.php and SpecialVbzAdmin
 
*/
 
*/
 
class clsItem extends clsDataSet {
 
class clsItem extends clsDataSet {
 
// object cache
 
// object cache
  private $objTitle;
+
    private $objTitle;
 +
    private $objItTyp;
 +
    private $objItOpt;
 +
 
 +
    public function CatNum() {
 +
return $this->Value('CatNum');
 +
    }
 +
    public function DescSpecs(array $iSpecs=NULL) {
 +
if (is_null($iSpecs)) {
 +
    $this->objTitle = $this->Title();
 +
    $this->objItTyp = $this->ItTyp();
 +
    $this->objItOpt = $this->ItOpt();
 +
 
 +
    $out['tname'] = $this->objTitle->Name;
 +
    $out['ittyp'] = $this->objItTyp->Name($this->Qty);
 +
    $out['itopt'] = $this->objItOpt->Descr;
 +
    return $out;
 +
} else {
 +
    return $iSpecs;
 +
}
 +
    }
 +
    public function DescLong(array $iSpecs=NULL) { // plaintext
 +
if (is_null($this->Value('Descr'))) {
 +
    $sp = $this->DescSpecs($iSpecs);
 +
 
 +
    $strItOpt = $sp['itopt'];
 +
 
 +
    $out = '"'.$sp['tname'].'" ('.$sp['ittyp'];
 +
    if (!is_null($strItOpt)) {
 +
$out .= ' - '.$strItOpt;
 +
    }
 +
    $out .= ')';
 +
} else {
 +
    $out = $this->Value('Descr');
 +
}
 +
 
 +
return $out;
 +
    }
 +
    public function DescLong_ht(array $iSpecs=NULL) { // as HTML
 +
$sp = $this->DescSpecs($iSpecs);
 +
 
 +
$htTitleName = '<i>'.$this->Title()->LinkName().'</i>';
 +
$strItOpt = $sp['itopt'];
 +
 
 +
$out = $htTitleName.' ('.$sp['ittyp'];
 +
if (!is_null($strItOpt)) {
 +
    $out .= ' - '.$strItOpt;
 +
}
 +
$out .= ')';
  
  public function Print_TableRow() {
+
return $out;
/*
 
  ASSUMES:
 
      This item is ForSale, so isForSale = true and (qtyForSale>0 || isInPrint) = true
 
      This item's data was generated by clsItems_Stock
 
  TO DO: create a separate clsItem_Stock class and move this method there.
 
*/
 
    $qtyInStock = $this->qtyForSale;
 
    if ($qtyInStock) {
 
      $strClass = 'inStock';
 
      $strStock = $qtyInStock.' in stock';
 
    } else {
 
      $strClass = 'noStock';
 
 
     }
 
     }
     $out = '<tr class='.$strClass.'><!-- ID='.$this->ID.' -->';
+
     /*-----
    $out .= '<td>&emsp;'.$this->ItOpt_Descr;
+
      ASSUMES:
    if ($this->isInPrint) {
+
  This item is ForSale, so isForSale = true and (qtyForSale>0 || isInPrint) = true
      if ($qtyInStock) {
+
      HISTORY:
        $strStatus = $strStock.'; more available';
+
  2011-01-24 Renamed Print_TableRow() -> Render_TableRow; corrected to match header
      } else {
+
    */
        $strStatus = '<a title="explanation..." href="'.KWP_WIKI.'Available_but_not_in_stock">available, not in stock</a>';
+
    public function Render_TableRow() {
      }
+
$arStat = $this->AvailStatus();
    } else {
+
$strCls = $arStat['cls'];
      $strStatus = '<b>'.$strStock.'</b> - <i>out of print!</i>';
+
 
 +
$out = '<tr class='.$strCls.'><!-- ID='.$this->ID.' -->';
 +
$out .= '<td>&emsp;'.$this->Value('ItOpt_Descr').'</td>';
 +
$out .= '<td>'.$arStat['html'].'</td>';
 +
$out .= '<td align=right><i>'.DataCurr($this->Value('PriceList')).'</i></td>';
 +
$out .= '<td align=right>'.DataCurr($this->Value('PriceSell')).'</td>';
 +
$out .= '<td>'.'<input size=3 name="qty-'.$this->Value('CatNum').'"></td>';
 +
$out .= '</tr>';
 +
return $out;
 
     }
 
     }
     $out .= '<td>'.$strStatus.'</td>';
+
     /*----
    $out .= '<td>'.DataCurr($this->PriceSell).'</td>';
+
      ACTION: Returns an array with human-friendly text about the item's availability status
    $out .= '<td>'.'<input size=3 name="qty-'.$this->CatNum.'"></td>';
+
      RETURNS:
    if ($this->PriceList) {
+
array['html']: status text, in HTML format
      $out .= '<td><i>'.DataCurr($this->PriceList).'</i></td>';
+
array['cls']: class to use for displaying item row in a table
 +
      USED BY: Render_TableRow()
 +
      NOTE: This probably does not actually need to be a separate method; I thought I could reuse it to generate
 +
status for titles, but that doesn't make sense. Maybe it will be easier to adapt, though, as a separate method.
 +
      HISTORY:
 +
2010-11-16 Modified truth table for in-print status so that if isInPrint=FALSE, then status always shows
 +
  "out of print" even if isCurrent=FALSE. What happens when a supplier has been discontinued? Maybe we need to
 +
  check that separately. Wait for an example to come up, for easier debugging.
 +
2011-01-24 Corrected to use cat_items fields
 +
    */
 +
    private function AvailStatus() {
 +
//echo 'SQL=['.$this->sqlMake.']';
 +
//echo '<pre>'.print_r($this->Row,TRUE).'</pre>';
 +
      $qtyInStock = $this->Value('QtyIn_Stk');
 +
if ($qtyInStock) {
 +
    $strCls = 'inStock';
 +
    $strStk = $qtyInStock.' in stock';
 +
} else {
 +
    $strCls = 'noStock';
 +
    $strStk = 'none in stock';
 +
}
 +
$isInPrint = $this->Value('isInPrint');
 +
if ($isInPrint) {
 +
    if ($this->Value('isCurrent')) {
 +
    if ($qtyInStock) {
 +
$txt = $strStk.'; more available';
 +
    } else {
 +
$txt = '<a title="explanation..." href="'.KWP_HELP_NO_STOCK_BUT_AVAIL.'">available, not in stock</a>';
 +
    }
 +
    } else {
 +
if ($qtyInStock) {
 +
    $txt = $strStk.'; in-print status uncertain';
 +
} else {
 +
    $txt = $strStk.'; availability uncertain';
 +
}
 +
    }
 +
} else {
 +
    if (is_null($isInPrint)) {
 +
$txt = '<b>'.$strStk.'</b> - <i>possibly out of print</i>';
 +
    } else {
 +
$txt = '<b>'.$strStk.'</b> - <i>out of print!</i>';
 +
    }
 +
}
 +
$arOut['html'] = $txt;
 +
$arOut['cls'] = $strCls;
 +
return $arOut;
 
     }
 
     }
    $out .= '</tr>';
+
 
    return $out;
 
  }
 
 
   public function Title() {
 
   public function Title() {
    $doLoad = TRUE;
+
      $doLoad = TRUE;
    if (is_object($this->objTitle)) {
+
      if (is_object($this->objTitle)) {
      if ($this->objTitle->ID == $this->ID_Title) {
+
  if ($this->objTitle->ID == $this->ID_Title) {
        $doLoad = FALSE;
+
      $doLoad = FALSE;
 +
  }
 +
      }
 +
      if ($doLoad) {
 +
  $this->objTitle = $this->objDB->Titles()->GetItem($this->ID_Title);
 
       }
 
       }
    }
+
      return $this->objTitle;
    if ($doLoad) {
+
  }
       $this->objTitle = $this->objDB->Titles()->GetItem($this->ID_Title);
+
  public function Supplier() {
    }
+
       return $this->Title()->Supplier();
    return $this->objTitle;
 
 
   }
 
   }
 
   public function ItTyp() {
 
   public function ItTyp() {
    $doLoad = TRUE;
+
      $doLoad = TRUE;
    if (is_object($this->objItTyp)) {
+
      if (is_object($this->objItTyp)) {
      if ($this->objItTyp->ID == $this->ID_ItTyp) {
+
  if ($this->objItTyp->ID == $this->ID_ItTyp) {
        $doLoad = FALSE;
+
      $doLoad = FALSE;
 +
  }
 +
      }
 +
      if ($doLoad) {
 +
  $this->objItTyp = $this->objDB->ItTyps()->GetItem($this->ID_ItTyp);
 
       }
 
       }
    }
+
       return $this->objItTyp;
    if ($doLoad) {
 
       $this->objItTyp = $this->objDB->ItTyps()->GetItem($this->ID_ItTyp);
 
    }
 
    return $this->objItTyp;
 
 
   }
 
   }
 
   public function ItOpt() {
 
   public function ItOpt() {
Line 1,547: Line 2,176:
 
     return $this->objItOpt;
 
     return $this->objItOpt;
 
   }
 
   }
  public function ShCost() {
+
    // DEPRECATED - use ShipCostObj()
     $doLoad = TRUE;
+
    public function ShCost() {
    if (is_object($this->objShCost)) {
+
return $this->ShipCostObj();
      if ($this->objShCost->ID == $this->ID_ShipCost) {
+
    }
        $doLoad = FALSE;
+
     /*----
       }
+
      HISTORY:
 +
2010-10-19 created from contents of ShCost()
 +
    */
 +
    public function ShipCostObj() {
 +
$doLoad = FALSE;
 +
if (empty($this->objShCost)) {
 +
    $doLoad = TRUE;
 +
} elseif ($this->objShCost->ID != $this->ID_ShipCost) {
 +
    $doLoad = TRUE;
 +
}
 +
if ($doLoad) {
 +
    $this->objShCost = $this->objDB->ShipCosts()->GetItem($this->ID_ShipCost);
 +
}
 +
return $this->objShCost;
 +
    }
 +
    /*----
 +
      RETURNS: The item's per-item shipping price for the given shipping zone
 +
      FUTURE: Rename to ShPerItm_forZone()
 +
    */
 +
    public function ShipPriceItem($iZone) {
 +
global $listItmFactors;
 +
 
 +
$fltZoneFactor = $listItmFactors[$iZone];
 +
$objSh = $this->ShipCostObj();
 +
return $objSh->PerItem * $fltZoneFactor;
 +
    }
 +
    /*----
 +
      RETURNS: The item's per-package shipping price for the given shipping zone
 +
      FUTURE: Rename to ShPerPkg_forZone()
 +
    */
 +
    public function ShipPricePkg($iZone) {
 +
global $listPkgFactors;
 +
 
 +
$fltZoneFactor = $listPkgFactors[$iZone];
 +
return $this->ShipCostObj()->PerPkg * $fltZoneFactor;
 +
    }
 +
    /*----
 +
       RETURNS: The item's per-item shipping price, with no zone calculations
 +
      FUTURE: need to handle shipping zone more gracefully and rigorously
 +
This function is currently only used in the admin area, so does not need
 +
to be infallible.
 +
    */
 +
    public function ShPerItm() {
 +
return $this->ShipCostObj()->Value('PerItem');
 +
    }
 +
    /*----
 +
      RETURNS: The item's per-package shipping price, with no zone calculations
 +
      FUTURE: need to handle shipping zone more gracefully and rigorously
 +
This function is currently only used in the admin area, so does not need
 +
to be infallible.
 +
    */
 +
    public function ShPerPkg() {
 +
return $this->ShipCostObj()->Value('PerPkg');
 
     }
 
     }
     if ($doLoad) {
+
}
      $this->objShCost = $this->objDB->ShipCosts()->GetItem($this->ID_ShipCost);
+
/*====
 +
  PURPOSE: clsItems with additional catalog information
 +
*/
 +
class clsItems_info_Cat extends clsItems {
 +
     public function __construct($iDB) {
 +
parent::__construct($iDB);
 +
  $this->Name('qryCat_Items');
 +
  //$this->ClassSng('clsItem_info_Cat');
 
     }
 
     }
    return $this->objShCost;
 
  }
 
  public function ShipPriceItem($iZone) {
 
      global $listItmFactors;
 
      $this->ShCost(); // get the shipping cost object
 
      $fltZoneFactor = $listItmFactors[$iZone];
 
      return $this->objShCost->PerItem * $fltZoneFactor;
 
  }
 
  public function ShipPricePkg($iZone) {
 
      global $listPkgFactors;
 
      $this->ShCost(); // get the shipping cost object
 
      $fltZoneFactor = $listPkgFactors[$iZone];
 
      return $this->objShCost->PerPkg * $fltZoneFactor;
 
  }
 
 
}
 
}
 
 
/* -------------------- *\
 
/* -------------------- *\
 
     ITEM TYPE classes
 
     ITEM TYPE classes
 
\* -------------------- */
 
\* -------------------- */
 
class clsItTyps extends clsVbzTable {
 
class clsItTyps extends clsVbzTable {
  public function __construct($iDB) {
+
    public function __construct($iDB) {
    parent::__construct($iDB);
+
parent::__construct($iDB);
      $this->Name('cat_ittyps');
+
  $this->Name('cat_ittyps');
      $this->KeyName('ID');
+
  $this->KeyName('ID');
      $this->ClassSng('clsItTyp');
+
  $this->ClassSng('clsItTyp');
  }
+
    }
 +
    // BOILERPLATE - cache
 +
    protected $objCache;
 +
    protected function Cache() {
 +
if (!isset($this->objCache)) {
 +
    $this->objCache = new clsCache_Table($this);
 +
}
 +
return $this->objCache;
 +
    }
 +
    public function GetItem_Cached($iID=NULL,$iClass=NULL) {
 +
return $this->Cache()->GetItem($iID,$iClass);
 +
    }
 +
/*
 +
    public function GetData_Cached($iWhere=NULL,$iClass=NULL,$iSort=NULL) {
 +
return $this->Cache()->GetData($iWhere,$iClass,$iSort);
 +
    }
 +
*/
 +
    /*----
 +
      FUTURE:
 +
* This method really belongs with Admin functions, since it will never be used in the standalone store
 +
* If table ever grows to a significant size, we might end up changing the filtering criteron.
 +
      HISTORY:
 +
2010-11-21 Adapted from clsFolders.
 +
    */
 +
    public function DropDown($iName=NULL,$iDefault=NULL,$iChoose=NULL) {
 +
$strName = is_null($iName)?($this->Table->ActionKey()):$iName;
 +
$arRows = $this->Cache()->GetData_array('isType',NULL,'Sort, NameSng');
 +
$out = $this->DropDown_for_array($arRows,$strName,$iDefault,$iChoose);
 +
return $out;
 +
    }
 +
    /*----
 +
      ACTION: same as clsItTyp::DropDown_for_rows, but takes an array
 +
      HISTORY:
 +
2011-02-11 wrote
 +
    */
 +
    public function DropDown_for_array(array $iRows,$iName=NULL,$iDefault=NULL,$iChoose=NULL) {
 +
$strName = is_null($iName)?($this->Table->ActionKey()):$iName;
 +
$objRow = $this->SpawnItem();
 +
foreach($iRows as $key => $row) {
 +
    $objRow->Values($row);
 +
    $arList[$key] = $objRow->Name();
 +
}
 +
return DropDown_arr($strName,$arList,$iDefault,$iChoose);
 +
    }
 
}
 
}
class clsItTyp extends clsDataSet {
+
/*====
  public function Name($iCount=-1) {
+
  CLASS: Item Type (singular)
    if ($iCount == -1) {
+
*/
      $iCount = $this->cntInPrint;
+
class clsItTyp extends clsDataSet_bare {
 +
    /*----
 +
      HISTORY:
 +
2011-02-02 removed the IsNew() check because sometimes we want to use this
 +
  on data which has not been associated with an ID
 +
    */
 +
    public function Name($iCount=NULL) {
 +
if (is_null($iCount)) {
 +
    if (isset($this->Row['cntInPrint'])) {
 +
$iCount = $this->Row['cntInPrint'];
 +
    } else {
 +
$iCount = 1; // default: use singular
 +
    }
 +
}
 +
if ($iCount == 1) {
 +
    $out = array_key_exists('NameSng',$this->Row)?$this->Row['NameSng']:NULL;
 +
} else {
 +
    $out = array_key_exists('NamePlr',$this->Row)?$this->Row['NamePlr']:NULL;
 +
}
 +
return $out;
 
     }
 
     }
     if ($iCount == 1) {
+
     /*----
      return $this->NameSng;
+
      ACTION: Shows a drop-down selection box contining the rows in the current dataset
    } else {
+
      FUTURE:
      return $this->NamePlr;
+
* This method really belongs with Admin functions, since it will never be used in the standalone store
 +
    */
 +
    public function DropDown_for_rows($iName=NULL,$iDefault=NULL,$iChoose=NULL) {
 +
$strName = is_null($iName)?($this->Table->ActionKey()):$iName;
 +
if ($this->HasRows()) {
 +
    $out = '<select name="'.$strName.'">';
 +
    if (!is_null($iChoose)) {
 +
$out .= '<option>'.$iChoose.'</option>';
 +
    }
 +
    while ($this->NextRow()) {
 +
$id = $this->Row['ID'];
 +
if ($id == $iDefault) {
 +
    $htSelect = " selected";
 +
} else {
 +
    $htSelect = '';
 +
}
 +
$out .= '<option'.$htSelect.' value="'.$id.'">'.$this->Name().'</option>';
 +
    }
 +
    $out .= '</select>';
 +
} else {
 +
    $out = 'No item types found.';
 +
}
 +
return $out;
 
     }
 
     }
  }
 
 
}
 
}
 
/* -------------------- *\
 
/* -------------------- *\
Line 1,606: Line 2,362:
 
       $this->ClassSng('clsItOpt');
 
       $this->ClassSng('clsItOpt');
 
   }
 
   }
 +
    // ==BOILERPLATE - cache
 +
    protected $objCache;
 +
    protected function Cache() {
 +
if (!isset($this->objCache)) {
 +
    $this->objCache = new clsCache_Table($this);
 +
}
 +
return $this->objCache;
 +
    }
 +
    public function GetItem_Cached($iID=NULL,$iClass=NULL) {
 +
return $this->Cache()->GetItem($iID,$iClass);
 +
    }
 +
    // ==/BOILERPLATE
 +
    /*----
 +
      FUTURE:
 +
* This method really belongs with Admin functions, since it will never be used in the standalone store
 +
* If table ever grows to a significant size, we might end up changing the filtering criteron.
 +
* Actually, this should be a boilerplate function with a helper class. The only change from clsItTyps
 +
  is the GetData filter and sorting.
 +
      HISTORY:
 +
2010-11-21 Adapted from clsItTyps
 +
    */
 +
    public function DropDown($iName=NULL,$iDefault=NULL,$iChoose=NULL) {
 +
$strName = is_null($iName)?($this->Table->ActionKey()):$iName;
 +
$arRows = $this->Cache()->GetData_array(NULL,NULL,'Sort');
 +
$out = $this->DropDown_for_array($arRows,$strName,$iDefault,$iChoose);
 +
return $out;
 +
    }
 +
    /*----
 +
      ACTION: same as clsItTyp::DropDown_for_rows, but takes an array
 +
      HISTORY:
 +
2011-02-11 wrote
 +
    */
 +
    public function DropDown_for_array(array $iRows,$iName=NULL,$iDefault=NULL,$iChoose=NULL) {
 +
$strName = is_null($iName)?($this->Table->ActionKey()):$iName;
 +
$objRow = $this->SpawnItem();
 +
foreach($iRows as $key => $row) {
 +
    $objRow->Values($row);
 +
    $arList[$key] = $objRow->ChoiceLine();
 +
}
 +
return DropDown_arr($strName,$arList,$iDefault,$iChoose);
 +
    }
 
}
 
}
 
class clsItOpt extends clsDataSet {
 
class clsItOpt extends clsDataSet {
 +
    /*----
 +
      RETURNS: Approximately as much description as will fit nicely into a choice line for a drop-down or selection box
 +
    */
 +
    public function ChoiceLine() {
 +
return $this->Value('CatKey');
 +
    }
 
}
 
}
 
/* -------------------- *\
 
/* -------------------- *\
Line 1,619: Line 2,422:
 
       $this->ClassSng('clsShipCost');
 
       $this->ClassSng('clsShipCost');
 
   }
 
   }
 +
    // ==BOILERPLATE - cache
 +
    protected $objCache;
 +
    protected function Cache() {
 +
if (!isset($this->objCache)) {
 +
    $this->objCache = new clsCache_Table($this);
 +
}
 +
return $this->objCache;
 +
    }
 +
    public function GetItem_Cached($iID=NULL,$iClass=NULL) {
 +
return $this->Cache()->GetItem($iID,$iClass);
 +
    }
 +
    // ==/BOILERPLATE
 +
    /*----
 +
      FUTURE:
 +
* This method really belongs with Admin functions, since it will never be used in the standalone store
 +
* If table ever grows to a significant size, we might end up changing the filtering criteron.
 +
* Actually, this should be a boilerplate function with a helper class. The only change from clsItTyps
 +
  is the GetData filter and sorting.
 +
      HISTORY:
 +
2010-11-21 Adapted from clsItTyps
 +
    */
 +
    public function DropDown($iName=NULL,$iDefault=NULL,$iChoose=NULL) {
 +
$strName = is_null($iName)?($this->Table->ActionKey()):$iName;
 +
$arRows = $this->Cache()->GetData_array(NULL,NULL,'Sort');
 +
$out = $this->DropDown_for_array($arRows,$strName,$iDefault,$iChoose);
 +
return $out;
 +
    }
 +
    /*----
 +
      ACTION: same as clsItTyp::DropDown_for_rows, but takes an array
 +
      HISTORY:
 +
2011-02-11 wrote
 +
    */
 +
    public function DropDown_for_array(array $iRows,$iName=NULL,$iDefault=NULL,$iChoose=NULL) {
 +
$strName = is_null($iName)?($this->Table->ActionKey()):$iName;
 +
$objRow = $this->SpawnItem();
 +
foreach($iRows as $key => $row) {
 +
    $objRow->Values($row);
 +
    $arList[$key] = $objRow->ChoiceLine();
 +
}
 +
return DropDown_arr($strName,$arList,$iDefault,$iChoose);
 +
    }
 
}
 
}
 
class clsShipCost extends clsDataSet {
 
class clsShipCost extends clsDataSet {
 +
    /*----
 +
      RETURNS: Approximately as much description as will fit nicely into a choice line for a drop-down or selection box
 +
    */
 +
    public function ChoiceLine() {
 +
return $this->Value('Descr');
 +
    }
 
}
 
}
 
/* -------------------- *\
 
/* -------------------- *\
 
     STOCK ITEM classes
 
     STOCK ITEM classes
 
\* -------------------- */
 
\* -------------------- */
// TO DO: explain the difference between clsItems_Stock and clsStkItems
+
/*====
 +
  CLASS PAIR: Items_Stock
 +
  PURPOSE: items with stock information (from a query or cache)
 +
    Similar to clsItem, but with different fields
 +
  HISTORY:
 +
    2011-01-24 disabled -- use cat_items (has all necessary fields cached)
 +
*/
 +
/*
 
class clsItems_Stock extends clsItems {
 
class clsItems_Stock extends clsItems {
  public function __construct($iDB) {
+
    public function __construct($iDB) {
    parent::__construct($iDB);
+
parent::__construct($iDB);
      $this->Name('qryCat_Items_Stock');
+
  $this->Name('qryCat_Items_Stock');
      $this->KeyName('ID');
+
  //$this->Name('_title_ittyps'); // WRONG! This GROUPS the data, no Items.
  }
+
  $this->KeyName('ID');
 +
  $this->ClassSng('clsItem_Stock');
 +
    }
 +
    public function Render_TableHdr() {
 +
return '<tr>'
 +
  .'<th align=left>Option</th>'
 +
  .'<th>Status</th>'
 +
  .'<th align=right class=title-price>Price</th>'
 +
  .'<th align=center class=orderQty>Order<br>Qty.</th>'
 +
  .'<th><i>list<br>price</th>'
 +
  .'</tr>';
 +
    }
 
}
 
}
 +
*/
 +
//class clsItem_Stock extends clsItem {
 +
    /*-----
 +
      ASSUMES:
 +
  This item is ForSale, so isForSale = true and (qtyForSale>0 || isInPrint) = true
 +
  This item's data was generated by clsItems_Stock
 +
      TO DO: create a separate clsItem_Stock class and move this method there.
 +
      TO DO: this method isn't named or structured canonically; consider refactoring. Whatever that means.
 +
      HISTORY:
 +
  2011-01-24 moved from clsItem to clsItem_Stock
 +
    */
 +
/*
 +
    public function Render_TableRow() {
 +
$arStat = $this->AvailStatus();
 +
$strCls = $arStat['cls'];
  
 +
$out = '<tr class='.$strCls.'><!-- ID='.$this->ID.' -->';
 +
$out .= '<td>&emsp;'.$this->ItOpt_Descr.'</td>';
 +
$out .= '<td>'.$arStat['html'].'</td>';
 +
$out .= '<td>'.DataCurr($this->PriceSell).'</td>';
 +
$out .= '<td>'.'<input size=3 name="qty-'.$this->CatNum.'"></td>';
 +
if ($this->PriceList) {
 +
    $out .= '<td><i>'.DataCurr($this->PriceList).'</i></td>';
 +
}
 +
$out .= '</tr>';
 +
return $out;
 +
    }
 +
*/
 +
    /*----
 +
      ACTION: Returns an array with human-friendly text about the item's availability status
 +
      RETURNS:
 +
array['html']: status text, in HTML format
 +
array['cls']: class to use for displaying item row in a table
 +
      USED BY: Print_TableRow()
 +
      NOTE: This probably does not actually need to be a separate method; I thought I could reuse it to generate
 +
status for titles, but that doesn't make sense. Maybe it will be easier to adapt, though, as a separate method.
 +
      HISTORY:
 +
2010-11-16 Modified truth table for in-print status so that if isInPrint=FALSE, then status always shows
 +
  "out of print" even if isCurrent=FALSE. What happens when a supplier has been discontinued? Maybe we need to
 +
  check that separately. Wait for an example to come up, for easier debugging.
 +
2011-01-24 Adapted from clsItem (was it being used there, for real?) to clsItem_Stock
 +
    */
 +
/*
 +
    private function AvailStatus() {
 +
//echo 'SQL=['.$this->sqlMake.']';
 +
//echo '<pre>'.print_r($this->Row,TRUE).'</pre>';
 +
      $qtyInStock = $this->Value('qtyForSale');
 +
if ($qtyInStock) {
 +
    $strCls = 'inStock';
 +
    $strStk = $qtyInStock.' in stock';
 +
} else {
 +
    $strCls = 'noStock';
 +
    $strStk = 'none in stock';
 +
}
 +
if ($this->Value('isInPrint')) {
 +
    if ($this->Value('isCurrent')) {
 +
    if ($qtyInStock) {
 +
$txt = $strStk.'; more available';
 +
    } else {
 +
$txt = '<a title="explanation..." href="'.KWP_HELP_NO_STOCK_BUT_AVAIL.'">available, not in stock</a>';
 +
    }
 +
    } else {
 +
if ($qtyInStock) {
 +
    $txt = $strStk.'; in-print status uncertain';
 +
} else {
 +
    $txt = $strStk.'; availability uncertain';
 +
}
 +
    }
 +
} else {
 +
    $txt = '<b>'.$strStk.'</b> - <i>out of print!</i>';
 +
}
 +
$arOut['html'] = $txt;
 +
$arOut['cls'] = $strCls;
 +
return $arOut;
 +
    }
 +
}
 +
*/
 
class clsStkItems extends clsVbzTable {
 
class clsStkItems extends clsVbzTable {
  public function __construct($iDB) {
+
    public function __construct($iDB) {
    parent::__construct($iDB);
+
parent::__construct($iDB);
      $this->Name('stk_items');
+
  $this->Name('stk_items');
      $this->KeyName('ID');
+
  $this->KeyName('ID');
  }
+
    }
  public function QtyInStock_forItem($iItemID) {
+
    /*-----
    $sql = 'SELECT SUM(s.Qty) AS Qty FROM stk_items AS s LEFT JOIN stk_bins AS sb ON s.ID_Bin=sb.ID WHERE (s.ID_Item='.$iItemID.') AND (s.WhenRemoved IS NULL) AND (sb.WhenVoided IS NULL) AND (sb.isForSale) GROUP BY s.ID_Item';
+
      RETURNS: Recordset containing list of stock for the given item (qtys, bin, bin name, place, place name, notes)
// ** TO DO: maybe this can use a view or one of the calculated tables now?
+
    */
 +
    public function List_forItem($iItemID) {
 +
$sql = 'SELECT '
 +
  .'ID, QtyForSale, QtyForShip, QtyExisting, ID_Bin, ID_Place, BinCode, WhName, Notes '
 +
  .'FROM qryStk_lines_remaining WHERE (ID_Item='.$iItemID.');';
 +
$objStock = $this->objDB->DataSet($sql,$this->ClassSng());
 +
$objStock->Table = $this;
 +
return $objStock;
 +
    }
 +
/* (2010-06-15) This doesn't seem to be used anywhere, and possibly does not work.
 +
    public function QtyInStock_forItem($iItemID) {
 +
$sql = 'SELECT SUM(s.Qty) AS Qty FROM stk_items AS s LEFT JOIN stk_bins AS sb ON s.ID_Bin=sb.ID WHERE (s.ID_Item='.$iItemID.') AND (s.WhenRemoved IS NULL) AND (sb.WhenVoided IS NULL) AND (sb.isForSale) GROUP BY s.ID_Item';
  
    $objStock = new clsDataItem($this);
+
$objStock = new clsDataItem($this);
    $objStock->Query($sql);
+
$objStock->Query($sql);
    if ($objStock->NextRow()) {
+
if ($objStock->NextRow()) {
      assert('is_resource($objStock->Res)');
+
    assert('is_resource($objStock->Res)');
      if ($objStock->RowCount()) {
+
    if ($objStock->RowCount()) {
        assert('$objStock->RowCount() == 1');
+
assert('$objStock->RowCount() == 1');
        return $objStock->Qty;
+
return $objStock->Qty;
      }
+
    }
    } else {
+
} else {
      return NULL;
+
    return NULL;
 +
}
 
     }
 
     }
  }
+
*/
 
}
 
}
 
/* -------------------- *\
 
/* -------------------- *\
 
     IMAGE classes
 
     IMAGE classes
 
\* -------------------- */
 
\* -------------------- */
 +
class clsVbzFolders extends clsVbzTable {
 +
    public function __construct($iDB) {
 +
parent::__construct($iDB);
 +
  $this->Name('cat_folders');
 +
  $this->KeyName('ID');
 +
  $this->ClassSng('clsVbzFolder');
 +
    }
 +
    /*----
 +
      FUTURE:
 +
* This method really belongs with Admin functions, since it will never be used in the standalone store
 +
* If table ever grows to a significant size, we might end up changing the filtering criteron.
 +
    */
 +
    public function DropDown($iName,$iDefault=NULL) {
 +
$dsRows = $this->GetData('Descr IS NOT NULL');
 +
return $dsRows->DropDown_for_rows($iName,$iDefault);
 +
    }
 +
    /*----
 +
      PURPOSE: Finds the folder record which matches as much of the given URL as possible
 +
      RETURNS: object for that folder, or NULL if no match found
 +
      ASSUMES: folder list is not empty
 +
      TO DO:
 +
does not yet handle adding new folders
 +
does not recursively check subfolders for improved match
 +
      HISTORY:
 +
2011-01-30 created -- subfolders not implemented yet because no data to test with
 +
    */
 +
    public function FindBest($iURL) {
 +
if (strlen($iURL) > 0) {
 +
    $slURL = strlen($iURL);
 +
    $rs = $this->GetData('ID_Parent IS NULL'); // start with root folders
 +
    $arrBest = NULL;
 +
    $slBest = 0;
 +
    while ($rs->NextRow()) {
 +
$fp = $rs->Value('PathPart');
 +
$pos = strpos($iURL,$fp); // does the folder appear in the URL?
 +
if ($pos === 0) {
 +
    $slFldr = strlen($fp);
 +
    if ($slFldr > $slBest) {
 +
$arrBest = $rs->Values();
 +
$slBest = $slFldr;
 +
    }
 +
}
 +
    }
 +
    if (is_array($arrBest)) {
 +
$rsFldr = $this->SpawnItem();
 +
$rsFldr->Values($arrBest);
 +
return $rsFldr;
 +
    }
 +
}
 +
return NULL;
 +
    }
 +
}
 +
class clsVbzFolder extends clsDataSet {
 +
    public function Spec() {
 +
$out = '';
 +
if (!is_null($this->ID_Parent)) {
 +
    $out = $this->ParentObj()->Spec();
 +
}
 +
$out .= $this->PathPart;
 +
return $out;
 +
    }
 +
    protected function ParentObj() {
 +
return $this->Table->GetItem($this->ID_Parent);
 +
    }
 +
    /*----
 +
      ACTION: Shows a drop-down selection box contining the rows in the current dataset
 +
      FUTURE:
 +
* This method really belongs with Admin functions, since it will never be used in the standalone store
 +
    */
 +
    public function DropDown_for_rows($iName,$iDefault=NULL) {
 +
if ($this->HasRows()) {
 +
    $out = '<select name="'.$iName.'">';
 +
    while ($this->NextRow()) {
 +
if ($this->ID == $iDefault) {
 +
    $htSelect = " selected";
 +
} else {
 +
    $htSelect = '';
 +
}
 +
$out .= '<option'.$htSelect.' value="'.$this->ID.'">'.$this->Spec().'</option>';
 +
    }
 +
    $out .= '</select>';
 +
} else {
 +
    $out = 'No shipments matching filter';
 +
}
 +
return $out;
 +
    }
 +
    /*----
 +
      RETURNS: The rest of the URL after this folder's PathPart is removed from the beginning
 +
      USED BY: bulk image entry admin routine
 +
    */
 +
    public function Remainder($iSpec) {
 +
$fsFldr = $this->Value('PathPart');
 +
$slFldr = strlen($fsFldr);
 +
$fsRest = substr($iSpec,$slFldr);
 +
return $fsRest;
 +
    }
 +
}
 
class clsImages extends clsVbzTable {
 
class clsImages extends clsVbzTable {
  public function __construct($iDB) {
+
    public function __construct($iDB) {
    parent::__construct($iDB);
+
parent::__construct($iDB);
      $this->Name('cat_images');
+
  $this->Name('cat_images');
      $this->KeyName('ID');
+
  $this->KeyName('ID');
      $this->ClassSng('clsImage');
+
  $this->ClassSng('clsImage');
  }
+
    }
 +
    public function Update(array $iSet,$iWhere) {
 +
$iSet['WhenEdited'] = 'NOW()';
 +
parent::Update($iSet,$iWhere);
 +
$this->Touch(__METHOD__.' WHERE='.$iWhere);
 +
    }
 +
    public function Insert(array $iData) {
 +
$iData['WhenAdded'] = 'NOW()';
 +
parent::Insert($iData);
 +
$this->Touch(__METHOD__);
 +
    }
 +
    public function Thumbnails($iTitle,array $iarAttr=NULL) {
 +
$sqlFilt = '(ID_Title='.$iTitle.') AND (Ab_Size="th") AND isActive';
 +
$objTbl = $this->objDB->Images();
 +
$objRows = $objTbl->GetData($sqlFilt,NULL,'AttrSort');
 +
return $objRows->Images_HTML($iarAttr);
 +
    }
 
}
 
}
class clsImage extends clsDataSet {
+
class clsImage extends clsVbzRecs {
// == STATIC SECTION ==
 
  const cksTblName = 'cat_images';
 
 
 
// == DYNAMIC SECTION ==
 
 
// object cache
 
// object cache
  private $objTitle;
+
    protected $objTitle;
  
  public function ImgForSize($iSize) {
+
    /*----
// ACTION: Get the image with the same title and attribute but with the given size
+
      HISTORY:
     if ($this->AttrFldr) {
+
2010-11-16 Modified to use new cat_folders data via ID_Folder
      $sqlAttr = '="'.$this->AttrFldr.'"';
+
    */
    } else {
+
    public function WebSpec() {
      $sqlAttr = ' IS NULL';
+
//return KWP_IMG_MERCH.$this->Spec;
 +
return $this->FolderPath().$this->Spec;
 +
    }
 +
    /*----
 +
      HISTORY:
 +
2010-11-16 Created
 +
    */
 +
    public function FolderObj() {
 +
return $this->objDB->Folders()->GetItem($this->ID_Folder);
 +
    }
 +
    /*----
 +
      HISTORY:
 +
2010-11-16 Created
 +
    */
 +
    public function FolderPath() {
 +
return $this->FolderObj()->Spec();
 +
    }
 +
    /*-----
 +
      ACTION: Generate the HTML code to display all images in the current dataset
 +
    */
 +
    public function Images_HTML(array $iarAttr=NULL) {
 +
if ($this->HasRows()) {
 +
    $out = '';
 +
    while ($this->NextRow()) {
 +
$out .= $this->Image_HTML($iarAttr);
 +
    }
 +
    return $out;
 +
} else {
 +
    return NULL;
 +
}
 +
    }
 +
    /*-----
 +
      ACTION: Generate the HTML code to display an image for the current row
 +
    */
 +
    public function Image_HTML(array $iarAttr=NULL) {
 +
$htDispl = $this->AttrDispl;
 +
if (!empty($htDispl)) {
 +
    nzApp($iarAttr['title'],' - '.$htDispl);
 +
}
 +
$iarAttr['src'] = $this->WebSpec();
 +
$htAttr = ArrayToAttrs($iarAttr);
 +
return '<img'.$htAttr.'>';
 +
    }
 +
    /*-----
 +
      ACTION: Get the image with the same title and attribute but with the given size
 +
     */
 +
    public function ImgForSize($iSize) {
 +
if ($this->AttrFldr) {
 +
    $sqlAttr = '="'.$this->AttrFldr.'"';
 +
} else {
 +
    $sqlAttr = ' IS NULL';
 +
}
 +
$sqlFilt = '(ID_Title='.$this->ID_Title.') AND (AttrFldr'.$sqlAttr.') AND (Ab_Size="'.$iSize.'")';
 +
$objImgOut = $this->objDB->Images()->GetData($sqlFilt);
 +
return $objImgOut;
 
     }
 
     }
     $sqlFilt = '(ID_Title='.$this->ID_Title.') AND (AttrFldr'.$sqlAttr.') AND (Ab_Size="'.$iSize.'")';
+
     public function Title() {
    $objImgOut = $this->objDB->Images()->GetData($sqlFilt);
+
      if (!is_object($this->objTitle)) {
    return $objImgOut;
+
  $this->objTitle = $this->objDB->Titles()->GetItem($this->ID_Title);
  }
+
      }
  public function Title() {
+
      return $this->objTitle;
    if (!is_object($this->objTitle)) {
 
$this->objTitle = $this->objDB->Titles()->GetItem($this->ID_Title);
 
 
     }
 
     }
     return $this->objTitle;
+
     /*-----
  }
+
      ACTION: outputs a standalone page for larger image sizes - does not use skin
  public function DoPage() {
+
    */
    global $vbgImgSize;
+
    public function DoPage() {
 +
global $vbgImgSize;
 +
 
 +
$objTitle = $this->Title();
 +
$strCatNum = $objTitle->CatNum();
 +
$strTitle = $objTitle->Name;
 +
$htTitleHref = $objTitle->Link();
 +
$htmlTitle = KS_STORE_NAME.' - '.$strCatNum.' &ldquo;'.$strTitle.'&rdquo;';
 +
echo '<html><head><title>'.$htmlTitle.'</title></head>';
 +
echo "\n<body"
 +
    ."\n bgcolor=000044"
 +
    ."\n TEXT=CCFFFF"
 +
    ."\n LINK=33FF33"
 +
    ."\n VLINK=33CCFF"
 +
    ."\n ALINK=FFCC00"
 +
    ."\n TOPMARGIN=0"
 +
    ."\n LEFTMARGIN=0"
 +
    ."\n MARGINWIDTH=0"
 +
    ."\n MARGINHEIGHT=0"
 +
    .'>';
 +
echo '<center>';
 +
echo '<big>'.$htTitleHref.$strTitle.'</a></big><br><small>'.$strCatNum.' - title ID #'.$this->ID_Title.'</small>';
  
    $objTitle = $this->Title();
 
    $strCatNum = $objTitle->CatNum();
 
    $strTitle = $objTitle->Name;
 
    $htmlTitle = KS_STORE_NAME.' - '.$strCatNum.' &ldquo;'.$strTitle.'&rdquo;';
 
    echo '<html><head><title>'.$htmlTitle.'</title></head>';
 
    echo '<body
 
bgcolor=000044
 
TEXT=CCFFFF
 
LINK=33FF33
 
VLINK=33CCFF
 
ALINK=FFCC00
 
TOPMARGIN=0
 
LEFTMARGIN=0
 
MARGINWIDTH=0
 
MARGINHEIGHT=0
 
>';
 
    echo '<center>';
 
    echo '<big>'.$strTitle.'</big><br><small>'.$strCatNum.' - title ID #'.$this->ID_Title.'</small>';
 
    echo '<table border=1><tr><td><table>';
 
 
// show list of available image sizes (except th and sm)
 
// show list of available image sizes (except th and sm)
 
+
$objImgs = $this->ListImages_sameAttr();
    $objImgs = $this->ListImages_sameAttr();
+
$strSizes = NULL;
    $strOut = NULL;
+
if ($objImgs->hasRows()) {
    if ($objImgs->hasRows()) {
+
    $strImgCount = 0;
      $strImgCount = 0;
+
    while ($objImgs->NextRow()) {
      while ($objImgs->NextRow()) {
+
$strImgType = $objImgs->Ab_Size;
        $strImgType = $objImgs->Ab_Size;
+
if (!empty($strImgType)) {
        if (($strImgType != 'th') && ($strImgType != 'sm')) {
+
    if (($strImgType != 'th') && ($strImgType != 'sm')) {
          $strImgCount++;
+
$strImgCount++;
  $strDesc = $vbgImgSize[$strImgType];
+
$strDesc = $vbgImgSize[$strImgType];
  if ($objImgs->ID == $this->ID) {
+
if ($objImgs->ID == $this->ID) {
      $strImgTag = '<b>'.$strDesc.'</b>';
+
    $strImgTag = '<b>'.$strDesc.'</b>';
  } else {
+
} else {
      $strImgTag = $objImgs->Href(TRUE).$strDesc.'</a>';
+
    $strImgTag = $objImgs->Href(TRUE).$strDesc.'</a>';
  }
+
}
          if ($strOut) {
+
if (!empty($strSizes)) {
            $strOut .= ' .. ';
+
    $strSizes .= ' .. ';
          }
+
}
          $strOut .= $strImgTag;
+
$strSizes .= $strImgTag;
        }
+
    }
      }
+
}
      if ($strImgCount > 1) {
+
    }
echo '<tr><td><font color=#aaaaaa>sizes</font> :</td><td align=center>'.$strOut.'</td><td>: <font color=#aaaaaa>sizes</font></td></tr>';
+
    if ($strImgCount > 1) {
      }
+
$ftSizes = '<tr>'
    }
+
  .'<td><font color=#aaaaaa>sizes</font> :</td>'
    $strOut = NULL;
+
  .'<td align=center>'.$strSizes.'</td>'
 +
  .'<td>: <font color=#aaaaaa>sizes</font></td>'
 +
  .'</tr>';
 +
    } else {
 +
$ftSizes = NULL;
 +
    }
 +
}
  
 
// show list of available images for this title at this size
 
// show list of available images for this title at this size
    $objImgs = $this->ListImages_sameSize();
+
$strAttrs = NULL;
    if ($objImgs->NextRow()) {
+
$objImgs = $this->ListImages_sameSize();
      $strImgCount = 0;
+
//echo 'test';
      $strOut .= '';
+
if ($objImgs->NextRow()) {
      if ($objImgs->hasRows()) {
+
    $intImgs = 0;
        while ($objImgs->NextRow()) {
+
    if ($objImgs->hasRows()) {
          $strImgFldr = $objImgs->AttrFldr;
+
$idx = 0;
          $strImgDescr = $objImgs->AttrDispl;
+
while ($objImgs->NextRow()) {
          $strImgCount++;
+
$idx++;
          if ($strOut) {
+
    $strImgFldr = $objImgs->AttrFldr;
            $strOut .= ' .. ';
+
    $strImgDescr = $objImgs->AttrDispl.'('.$idx.')';
          }
+
    $intImgs++;
          if ($objImgs->ID == $this->ID) {
+
    if (!empty($out)) {
            $strOut .= '<b>'.$strImgDescr.'</b>';
+
$strAttrs .= ' .. ';
          } else {
+
    }
            $strOut .= $objImgs->Href(TRUE).$strImgDescr.'</a>';
+
    if ($objImgs->ID == $this->ID) {
          }
+
$strAttrs .= '<b>'.$strImgDescr.'</b>';
        }
+
    } else {
        if ($strImgCount > 1) {
+
$strAttrs .= $objImgs->Href(TRUE).$strImgDescr.'</a>';
          echo '<tr><td><font color=#aaaaaa>views</font> :</td><td align=center>'.$strOut.'</td><td>: <font color=#aaaaaa>views</font></td></tr>';
+
    }
        }
+
}
      }
+
if ($intImgs > 1) {
 +
    $ftAttrs = '<tr>'
 +
      .'<td><font color=#aaaaaa>views</font> :</td>'
 +
      .'<td align=center>'.$strAttrs.'</td>'
 +
      .'<td>: <font color=#aaaaaa>views</font></td>'
 +
      .'</tr>';
 +
} else {
 +
    $ftAttrs = NULL;
 +
}
 +
    }
 +
}
 +
if ((!empty($ftSizes)) || (!empty($ftAttrs))) {
 +
    echo '<table border=1><tr><td><table>';
 +
    echo $ftSizes.$ftAttrs;
 +
    echo '</table></td></tr></table>';
 +
} else {
 +
    echo '<br>';
 +
}
 +
echo $htTitleHref.'ordering page</a><br>';
 +
echo $this->Image_HTML();
 +
echo "\n</body>\n</html>";
 
     }
 
     }
    echo '</table></td></tr></table>';
 
    echo $objTitle->Link().'ordering page</a><br>';
 
    echo $this->ImgSrc();
 
    echo '</body></html>';
 
  }
 
 
   public function ListImages_sameAttr() {
 
   public function ListImages_sameAttr() {
 +
    $sqlFilt = 'isActive AND (ID_Title='.$this->ID_Title.')';
 
     if ($this->AttrFldr) {
 
     if ($this->AttrFldr) {
       $sqlFilt = '(ID_Title='.$this->ID_Title.') AND (AttrFldr="'.$this->AttrFldr.'")';
+
       $sqlFilt .= ' AND (AttrFldr="'.$this->AttrFldr.'")';
    } else {
 
      $sqlFilt = '(ID_Title='.$this->ID_Title.')';
 
 
     }
 
     }
 
     $objImgOut = $this->objDB->Images()->GetData($sqlFilt);
 
     $objImgOut = $this->objDB->Images()->GetData($sqlFilt);
Line 1,782: Line 2,921:
 
     return $objImgOut;
 
     return $objImgOut;
 
   }
 
   }
  public function ListImages_sameSize() {
+
    public function ListImages_sameSize() {
    $sqlFilt = '(ID_Title='.$this->ID_Title.') AND (Ab_Size="'.$this->Ab_Size.'")';
+
$sqlFilt = 'isActive AND (ID_Title='.$this->ID_Title.') AND (Ab_Size="'.$this->Ab_Size.'")';
    $objImgOut = $this->objDB->Images()->GetData($sqlFilt);
+
//echo 'SQL: '.$sqlFilt;
    return $objImgOut;
+
$objImgOut = $this->objDB->Images()->GetData($sqlFilt);
  }
+
return $objImgOut;
  public function Href($iAbs=false) {
 
    $strFldrRel = $this->AttrFldr;
 
    if ($strFldrRel) {
 
      $strFldrRel .= '-';
 
 
     }
 
     }
     $strFldrRel .= $this->Ab_Size;
+
     public function Href($iAbs=false) {
 +
$strFldrRel = $this->AttrFldr;
 +
if ($strFldrRel) {
 +
    $strFldrRel .= '-';
 +
}
 +
$strFldrRel .= $this->Ab_Size;
  
    if ($iAbs) {
+
if ($iAbs) {
      $strFldr = $this->Title()->URL().'/'.$strFldrRel;
+
    $strFldr = $this->Title()->URL().'/'.$strFldrRel;
    } else {
+
} else {
      $strFldr = $strFldrRel;
+
    $strFldr = $strFldrRel;
 +
}
 +
return '<a href="'.$strFldr.'/">';
 
     }
 
     }
 +
}
  
    return '<a href="'.$strFldr.'/">';
+
/* ======================
  }
+
GLOBAL VARIABLES CLASS
  public function ImgSrc() {
+
*/
     return '<img src="'.KWP_IMG_MERCH.$this->Spec.'">';
+
class clsGlobalVars extends clsTable {
  }
+
     const TableName='var_global';
}
+
    private $strOld;
  
/* ------------------ *\
+
     public function __construct($iDB) {
     CATALOG BROWSING
+
parent::__construct($iDB);
\* ------------------ */
+
  $this->Name(self::TableName);
class clsTopics extends clsVbzTable {
+
  $this->KeyName('Name');
  public function __construct($iDB) {
+
//   $this->ClassSng('clsGlobalVar');
    parent::__construct($iDB);
+
    }
      $this->Name('brs_topics');
+
    public function Exists($iName) {
      $this->KeyName('ID');
+
$sqlFilt = 'Name="'.$iName.'"';
      $this->ClassSng('clsTopic');
+
$objRow = $this->GetData($sqlFilt);
  }
+
if ($objRow->hasRows()) {
  public function DoIndex() {
+
    $objRow->NextRow();
     global $objDataMgr;
+
    $this->strOld = $objRow->Value;
 +
    return TRUE;
 +
} else {
 +
    unset($this->strOld);
 +
    return FALSE;
 +
}
 +
    }
 +
    private function GetVar($iName) {
 +
if ($this->Exists($iName)) {
 +
    return $this->strOld;
 +
} else {
 +
    return NULL;
 +
}
 +
     }
 +
    private function SetVar($iName, $iValue) {
 +
$strWhere = __METHOD__; // should return class::function
 +
$sqlVal = SQLValue($iValue);
 +
$sqlName = SQLValue($iName);
  
    CallEnter($this,__LINE__,'clsTopics.DoIndex()');
+
if ($this->Exists($iName)) {
    $objSection = new clsPageOutput();
+
    $this->objDB->LogEvent($strWhere,
 +
      '|name='.$iName.'|old='.$this->strOld.'|new='.$sqlVal,
 +
      'global updated: '.$iName,
 +
      'VAR-U',FALSE,FALSE);
  
    $objTopics = $this->GetData('ID_Parent IS NULL',NULL,'Sort,Name,NameTree');
+
    $arUpd = array(
    while ($objTopics->NextRow()) {
+
      'Value' => $sqlVal,
      if ($isFirst) {
+
      'WhenUpdated' => 'NOW()'
        $isFirst = false;
+
      );
        $objSection->SectionHdr('Root Topics');
+
    $this->Update($arUpd,'Name='.$sqlName);
      } else {
+
} else {
        $objSection->AddText($objTopics->Name.'<br>');
+
    $this->objDB->LogEvent($strWhere,
      }
+
      '|name='.$iName.'|val='.$sqlVal,
 +
      'global added: '.$iName,
 +
      'VAR-I',FALSE,FALSE);
 +
    $arIns = array(
 +
      'Name' => $sqlName,
 +
      'Value' => $sqlVal,
 +
      'WhenCreated' => 'NOW()'
 +
      );
 +
    $this->Insert($arIns);
 +
}
 +
    }
 +
    public function Val($iName,$iValue=NULL) {
 +
if (is_null($iValue)) {
 +
    return $this->GetVar($iName);
 +
} else {
 +
    return $this->SetVar($iName,$iValue);
 +
}
 
     }
 
     }
 
    CallExit('clsTopic.DoIndex()');
 
    return $objSection->out;
 
  }
 
}
 
class clsTopic extends clsDataSet {
 
 
/*
 
/*
  public $ID_Parent;
+
    public function __set($iName, $iValue) {
  public $Name;
+
$this->SetVar($iName,$iValue);
  public $NameTree;
+
     }
  public $NameFull;
+
     public function __get($iName) {
  public $Variants;
+
return $this->GetVar($iName);
  public $Mispeled;
+
     }
 
 
  protected function LoadResults() {
 
    CallEnter($this,__LINE__,'clsTopic.LoadResults()');
 
    $this->ID = $this->GetValue('ID');
 
    $this->ID_Parent = $this->GetValue('ID_Parent');
 
     $this->Name = $this->GetValue('Name');
 
     $this->NameTree = $this->GetValue('NameTree');
 
    $this->NameFull = $this->GetValue('NameFull');
 
    $this->Variants = $this->GetValue('Variants');
 
    $this->Mispeled = $this->GetValue('Mispeled');
 
    assert('$this->ID');
 
     CallExit('clsTopic.LoadResults()');
 
  }
 
 
*/
 
*/
 
  public function DoPage() {
 
    global $objDataMgr;
 
 
    CallEnter($this,__LINE__,'clsTopic.DoPage()');
 
    assert('$this->ID');
 
    $objSection = new clsPageOutput();
 
 
    $objTitles = $this->objDB->DataSet('SELECT * FROM brs_titles_x_topics WHERE ID_Topic='.$this->ID);
 
    while ($objTitles->NextRow()) {
 
      if ($isFirst) {
 
        $isFirst = false;
 
        $objSection->SectionHdr('Titles');
 
      } else {
 
        $objSection->AddText($objTitles->Name.'<br>');
 
      }
 
    }
 
 
    CallExit('clsTopic.DoPage()');
 
    return $out;
 
  }
 
  public function WebName() {
 
    return sprintf(KS_FMT_TOPICID,$this->ID);
 
  }
 
}
 
 
/* ------------------ *\
 
    EVENT LOGGING
 
\* ------------------ */
 
class clsEvents extends clsVbzTable {
 
  public function __construct($iDB) {
 
    assert('is_object($iDB)');
 
    parent::__construct($iDB);
 
      $this->Name('event_log');
 
      $this->KeyName('ID');
 
  }
 
 
  public function LogEvent($iWhere,$iParams,$iDescr,$iCode,$iIsError,$iIsSevere) {
 
    global $sql, $vgUserName;
 
 
    $sql = 'INSERT INTO `'.$this->Name().'` (EvWhen,EvWhere,Params,Descr,Code,VbzUser,SysUser,Machine,isError,isSevere)'.
 
'VALUES(NOW(),"'.$iWhere.'","'.$iParams.'","'.$iDescr.'",'.SQLValue($iCode).','.SQLValue($vgUserName).
 
',NULL,"'.
 
$_ENV['REMOTE_ADDR'].'",'.
 
($iIsError?'TRUE':'FALSE').','.
 
($iIsSevere?'TRUE':'FALSE').');';
 
    $this->objDB->Exec($sql); 
 
  }
 
 
}
 
}
 
 
/* ==================== *\
 
/* ==================== *\
 
     UTILITY FUNCTIONS
 
     UTILITY FUNCTIONS
Line 1,918: Line 3,029:
 
}
 
}
 
function DataCurr($iCurr,$iPfx='$') {
 
function DataCurr($iCurr,$iPfx='$') {
  $out = $iPfx.sprintf("%01.2f",$iCurr);
+
    if (is_null($iCurr)) {
  return $out;
+
return NULL;
 +
    } else {
 +
$out = $iPfx.sprintf("%01.2f",$iCurr);
 +
return $out;
 +
    }
 
}
 
}
 
function DataDate($iDate) {
 
function DataDate($iDate) {
Line 1,948: Line 3,063:
 
}
 
}
 
function IsEmail($iAddr) {
 
function IsEmail($iAddr) {
     $ok = preg_match('/.{1}.*[\@].{1}.*[\.][a-z]{2}.*/i', $iAddr );
+
     $ok = preg_match('/^[0-9,a-z,\-,\.]{1,}@([0-9,a-z,\-][\.]{0,1}){2,}$/i', $iAddr );
 
     return $ok;
 
     return $ok;
 +
}
 +
function ArrayToAttrs(array $iarAttr=NULL) {
 +
    $htAttr = '';
 +
    if (is_array($iarAttr)) {
 +
foreach ($iarAttr as $key => $val) {
 +
    $htAttr .= ' '.$key.'="'.$val.'"';
 +
}
 +
    }
 +
    return $htAttr;
 
}
 
}
  

Latest revision as of 02:09, 19 December 2014

About

  • Purpose: Classes for displaying different types of catalog display pages
  • History:
    • 2009-03-07 Transcribed from working code at vbz.net
    • 2009-10-06 Latest code - large chunks working, focus of development no longer on this module
    • 2011-12-18 long-overdue update
  • To Do:
    • should be split up into auto-loadable class files, e.g. vbz.title.php, vbz.dept.php, etc.
    • "clsFactory" should be eliminated in favor of static functions for each class

Code - store.php

<php><?php /*

FILE: store.php
PURPOSE: vbz class library - should eventually be subdivided
HISTORY:
 2009-07-11 (Wzl) Lots of cleanup; added types and methods needed for shopping cart page
 2009-10-06 (Wzl) Changed most clsTitle* classes to clsVbzTitle* (conflict with something - w3tpl?)
   Additional changes needed so it would work on Rizzo
 2010-06-12 (Wzl) A little cleanup; clsTopic::Titles()
 2010-06-14 (Wzl) clsVbzTable::GetItem() handles non-numeric IDs by creating new object and passing along ID
 2011-01-18 (Wzl) moved clsTopic(s) to topic.php
  • /

define('kEmbeddedPagePrefix','embed:');

/* if (defined( '__DIR__' )) {

 $fpThis = __DIR__;

} else {

 $fpThis = dirname(__FILE__);

}

  • /

if (!defined('LIBMGR')) {

   require(KFP_LIB.'/libmgr.php');

} clsLibMgr::Add('strings', KFP_LIB.'/strings.php',__FILE__,__LINE__); clsLibMgr::Add('string.tplt', KFP_LIB.'/StringTemplate.php',__FILE__,__LINE__); clsLibMgr::Add('cache' , KFP_LIB.'/cache.php',__FILE__,__LINE__); clsLibMgr::Add('dtree', KFP_LIB.'/dtree.php',__FILE__,__LINE__); clsLibMgr::Add('events', KFP_LIB.'/events.php',__FILE__,__LINE__); clsLibMgr::Add('vbz.data', KFP_LIB_VBZ.'/vbz-data.php',__FILE__,__LINE__); clsLibMgr::Add('topic', KFP_LIB_VBZ.'/topic.php',__FILE__,__LINE__);

clsLibMgr::Load('strings',__FILE__,__LINE__); clsLibMgr::Load('string.tplt',__FILE__,__LINE__); clsLibMgr::Load('cache',__FILE__,__LINE__); clsLibMgr::Load('dtree',__FILE__,__LINE__); clsLibMgr::Load('events',__FILE__,__LINE__); clsLibMgr::Load('vbz.data',__FILE__,__LINE__); clsLibMgr::Load('topic',__FILE__,__LINE__);

define('EN_PGTYPE_NOTFND',-1); // requested item (supp/dept/title) not found define('EN_PGTYPE_HOME',1); // catalog home page define('EN_PGTYPE_SUPP',2); // supplier page define('EN_PGTYPE_DEPT',3); // department page, or possibly title for keyless dept define('EN_PGTYPE_TITLE',4); // title page // table names // - stock define('ksTbl_stock_places','stk_places'); define('ksTbl_stock_bins','stk_bins'); define('ksQry_stock_bins_wInfo','qryStk_Bins_w_info'); define('ksTbl_stock_items','stk_items'); define('ksTbl_stock_hist_items','stk_history'); define('ksTbl_stock_hist_bins','stk_bin_history'); // - browsing define('ksTbl_title_topics','brs_titles_x_topics');

global $vbgImgSize; $vbgImgSize = array(

   'th'	=> 'thumbnail',
   'sm'	=> 'small',
   'big' 	=> 'large',
   'huge'	=> 'huge',
   'zoom'	=> 'detail');

// shipping zone data: global $listShipListDesc,$listItmFactors,$listPkgFactors; // there's got to be a better way to do this... $listShipListDesc['US'] = 'United States'; $listShipListDesc['CA'] = 'Canada'; $listShipListDesc['INT'] = 'International'; // -- shipping charge adjustment factors: $listPkgFactors['US'] = 1.0; $listItmFactors['US'] = 1.0; $listPkgFactors['CA'] = 2.0; $listItmFactors['CA'] = 2.0; $listPkgFactors['INT'] = 4.0; $listItmFactors['INT'] = 4.0; // The above is just until we have something more exact and dynamic

$intCallDepth = 0;

// CALCULATED GLOBALS $fpTools = '/tools'; $fpPages = ; $fwpAbsPages = 'http://'.KS_PAGE_SERVER.$fpPages; $fwpAbsTools = 'http://'.KS_TOOLS_SERVER.$fpTools; $fwpCart = $fwpAbsPages.'/cart/'; $strCurServer = $_SERVER['SERVER_NAME'];

// SET UP DEPENDENT VALUES /* if ($strCurServer != KS_TOOLS_SERVER) {

 $fpTools = $fwpAbsTools;
 $fpPages = $fwpAbsPages;

}

  • /

$fwpLogo = $fpTools.'/img/logos/v/';

/*====

 NOTES:
   2011-02-02 This could use some rewriting. A lot of it is kind of pointless,
     and other parts duplicate RichText objects.
  • /

class clsPageOutput {

 public $out;
 private $isOdd;
 public $inTbl;
 function __construct() {
   $this->out = ;
   $this->isOdd = false;
   $this->inTbl = 0;
 }
 function Clear() {
   $this->out = ;
 }
 function AddText($iText) {
   $this->out .= $iText;
 }
 function SectionHdr($iTitle) {	// this is specifically duplicated

$this->out .= '

'.$iTitle.'

';

   return $this->out;
 }
 function StartTable($iTitle) {
   if ($iTitle) {
     $this->SectionHdr($iTitle);

$this->out .= '

'; $this->inTbl++; } } function RowStart($iClass=) { if ($iClass) { $this->out .= ''; } else { $this->out .= ''; } } function RowStop() { $this->out .= ''; $this->isOdd = !$this->isOdd; } function ColAdd($iText) { if ($this->isOdd) { $cellOpen = ''; } function EndTable() { if ($this->inTbl) { $this->out .= '
';
   } else {
$cellOpen = '
';
   }
$this->out .= $cellOpen.$iText.'

';

     $this->inTbl--;
   }
   return $this->out;
 }
 function ShowImgUnavail() {

$this->out .= '

<tbody></tbody>
<tbody></tbody>
No Images
Available
for this item
:-(

';

   return $this->out;
 }

} class clsCacheFile_vbz extends clsCacheFile {

   public function __construct() {

parent::__construct(KFP_CACHE);

   }

} class clsVbzData extends clsDatabase {

   protected $objPages;
   public function __construct($iSpec) {

parent::__construct($iSpec); $this->Open();

   }

// cache manager

   protected function CacheMgr_empty() {

return new clsCacheMgr($this);

   }
   public function CacheMgr() {

if (empty($this->objCacheMgr)) { $objCache = $this->CacheMgr_empty(); $objCache->SetTables('cache_tables','cache_queries','cache_flow','cache_log'); $this->objCacheMgr = $objCache; } return $this->objCacheMgr;

   }

// table-specific functions

   public function Pages() {

return $this->Make('clsCatPages');

   }
   public function Suppliers() {

return $this->Make('clsSuppliers');

   }
   public function Depts() {

return $this->Make('clsDepts');

   }
   public function Titles($iID=NULL) {

return $this->Make('clsVbzTitles',$iID);

   }
   public function Items() {

return $this->Make('clsItems');

   }
   public function Items_Stock() {

return $this->Make('clsItems_Stock');

   }
   public function Items_Cat() {

return $this->Make('clsItems_info_Cat');

   }
   public function ItTyps() {

return $this->Make('clsItTyps');

   }
   public function ItOpts() {

return $this->Make('clsItOpts');

   }
   public function ShipCosts() {

return $this->Make('clsShipCosts');

   }
   public function Folders() {

return $this->Make('clsVbzFolders');

   }
   public function Images() {

return $this->Make('clsImages');

   }
   public function StkItems() {

return $this->Make('clsStkItems');

   }
   public function Topics($iID=NULL) {

return $this->Make('clsTopics',$iID);

   }
   public function TitleTopic_Titles() {

return $this->Make('clsTitleTopic_Titles');

   }
   public function TitleTopic_Topics() {

return $this->Make('clsTitleTopic_Topics');

   }
   public function VarsGlobal() {

return $this->Make('clsGlobalVars');

   }
   public function Events() {

return $this->Make('clsEvents');

   }
   public function LogEvent($iWhere,$iParams,$iDescr,$iCode,$iIsError,$iIsSevere) {

return $this->Events()->LogEvent($iWhere,$iParams,$iDescr,$iCode,$iIsError,$iIsSevere);

   }

// Page output routines

   public function Formatter() {

if (!isset($this->objFmt)) { $this->objFmt = new clsPageOutput(); } return $this->objFmt;

   }
   public function SectionHdr($iTitle) {

/*

$out = '

'.$iTitle.'

';

return $out;

  • /

$this->Formatter()->Clear(); return $this->Formatter()->SectionHdr($iTitle);

   }
   /*----
     NOTES:

2011-02-02 This really should somehow provide a more general service. Right now, it's only used for displaying department pages -- but topic pages and searches could make use of it as well, if there were some tidy way to abstract the collecting of the price and stock data. This will probably necessitate adding hi/low price data to _titles and possibly _dept_ittyps (it's already in _title_ittyps).

     HISTORY:

2011-02-02 * Removed assertion that $objImgs->Res is a resource, because if there are no thumbnails for this title, then apparently it isn't, and apparently RowCount() handles this properly. * Also fixed references to qtyForSale -- should be qtyInStock.

   */
   public function ShowTitles($iHdrText,$iList,$objNoImgSect) {

$cntImgs = 0; $outImgs = ; foreach ($iList as $i => $row) { $objTitle = $this->Titles()->GetItem($row['ID']); $objImgs = $objTitle->ListImages('th'); //assert('is_resource($objImgs->Res); /* TYPE='.get_class($objImgs).' SQL='.$objImgs->sqlMake.' */'); $currMinPrice = $row['currMinPrice']; $currMaxPrice = $row['currMaxPrice']; $strPrice = DataCurr($currMinPrice); if ($currMinPrice != $currMaxPrice) { $strPrice .= '-'.DataCurr($currMaxPrice); } if ($objImgs->RowCount()) { $cntImgs++; $strCatNum = $objTitle->CatNum(); $strTitleTag = '"'.$objTitle->Name.'" ('.$strCatNum.')'; $strTitleLink = $objTitle->Link(); while ($objImgs->NextRow()) { $strImgTag = $strTitleTag.' - '.$strPrice; $qtyStk = $row['qtyInStock']; if ($qtyStk) { $strImgTag .= ' - '.$qtyStk.' in stock'; } $outImgs .= $strTitleLink.'<img class="thumb" src="'.$objImgs->WebSpec().'" title="'.$strImgTag.'"></a>'; } } else { if (!$objNoImgSect->inTbl) { $objNoImgSect->StartTable('titles without images:');

$objNoImgSect->AddText('Cat. #TitlePrice
Rangeto
orderstatus');

} $objNoImgSect->RowStart(); $objNoImgSect->ColAdd(''.$objTitle->CatNum().''); $objNoImgSect->ColAdd($objTitle->Name); $objNoImgSect->ColAdd($strPrice); $objNoImgSect->ColAdd('['.$objTitle->Link().'order</a>]'); $qtyStk = $row['qtyInStock']; if ($qtyStk) { $strStock = ''.$qtyStk.' in stock'; if ($row['cntInPrint'] == 0) { $strStock .= ' - OUT OF PRINT!'; } $objNoImgSect->ColAdd($strStock); } else { $objNoImgSect->ColAdd('<a title="explanation..." href="'.KWP_HELP_NO_STOCK_BUT_AVAIL.'">available, not in stock</a>'); // Debugging: // $objNoImgSect->ColAdd('ID_Title='.$objTitle->ID.' ID_ItTyp='.$objTitle->idItTyp); } $objNoImgSect->RowStop(); } } $out = ; if ($cntImgs) { $out .= $this->SectionHdr($iHdrText); $out .= $outImgs; } return $out;

   }

}

class clsList {

 public $List;
 public function Add($iName, $iValue=NULL) {
   $objItem = new clsListItem($iName,$iValue);
   $this->List[] = $objItem;
   return $objItem;
 }
 public function Output($iPfx, $iSep, $iSfx) {
   $out = NULL;
   if (is_array($this->List)) {
     foreach ($this->List as $objItem) {
       if (is_null($objItem->value)) {
         $out .= $iPfx.$iSep.$objItem->name.$iSfx;
       } else {
         $out .= $iPfx.$objItem->name.$iSep.$objItem->value.$iSfx;
       }
     }
   }
   return $out;
 }

} class clsListItem {

 public $name;
 public $value;
 public function __construct($iName, $iValue=NULL) {
   $this->name = $iName;
   $this->value = $iValue;
 }

} /* ===================

 CLASS: clsVbzSkin
 PURPOSE: Abstract skin class
  • /

abstract class clsVbzSkin extends clsVbzData {

   /*-----
     USAGE: Normal main entry point -- should be called from index.php
   */
   public function DoPage() {

try { $this->DoPreContent(); $this->DoContent(); $this->DoPostContent(); } catch(exception $e) { $this->EmailException($e); }

   }
   /*----
     HISTORY:

2011-03-31 added Page and Cookie to list of reported variables

   */
   protected function EmailException(exception $e) {

$msg = $e->getMessage(); $out = 'Description: '.($e->getMessage()); $out .= "\nStack trace:\n".($e->getTraceAsString());

$guest_ip = $_SERVER['REMOTE_ADDR']; $guest_browser = $_SERVER['HTTP_USER_AGENT']; $guest_referer = NzArray($_SERVER,'HTTP_REFERER'); $guest_page = $_SERVER['REQUEST_URI']; $guest_cookie = $_SERVER['HTTP_COOKIE'];

$out .= <<<__END__

Client information:

- IP Addr: $guest_ip
- Browser: $guest_browser
- Page   : $guest_page
- Cookie : $guest_cookie
- Referer: $guest_referer

__END__;

$subj = 'vbz error from IP '.$guest_ip; $ok = mail(KS_TEXT_EMAIL_ADDR_ERROR,$subj,$out);

echo <<<__END__ Ack! We seem to have a small problem here. (If it was a large problem, you wouldn't be seeing this message.) The webmaster is being alerted about this.
Meanwhile, you might try reloading the page -- a lot of errors are transient, which makes them hard to fix, which is why there are more of them than the other kind.

We apologize for the nuisance.

Error Message: $msg __END__;

// FUTURE: log the error and whether the email was successful

   }
   /*-----
     ACTION: Displays everything *before* the main page contents
   */
   protected function DoPreContent() {

$this->ParseInput(); $this->HandleInput(); $this->RenderHdrBlocks();

   }
   /*-----
     ACTION: Displays everything *after* the main page contents
   */
   protected function DoPostContent() {

$this->RenderFtrBlocks();

   }

// ABSTRACT section //

   /*-----
     ACTION: Displays the main page contents
   */
   protected abstract function DoContent();
   /*-----
     ACTION: Grab any expected input and interpret it
   */
   protected abstract function ParseInput();
   /*-----
     ACTION: Take the parsed input and do any needed processing (e.g. looking up data)
   */
   protected abstract function HandleInput();
   /*-----
     ACTION: Render any output that appears *before* the main content
   */
   protected abstract function RenderHdrBlocks();
   /*-----
     ACTION: Render any output that appears *after* the main content
   */
   protected abstract function RenderFtrBlocks();

} /* ===================

 CLASS: clsVbzSkin_Standard
 PURPOSE: Standard skin class
   Will later be replaceable with other skins
  • /

abstract class clsVbzSkin_Standard extends clsVbzSkin { /*

   protected function DoContent() {
   }
   protected function ParseInput() {
   }
   protected function HandleInput() {
   }
  • /
   protected function RenderHdrBlocks() {

$this->RenderHtmlStart(); $this->RenderContentHdr(); $this->DoSidebar();

   }
   protected function RenderFtrBlocks() {

$this->RenderContentFtr(); $this->RenderHtmlStop();

   }
   protected function RenderContentFtr() {

global $didPage,$fltStart;

echo '

';

$this->DoSepBar();

echo '
';

$fltExecTime = microtime(true)-$fltStart; $dat = getrusage(); $fltUserTime = $dat["ru_utime.tv_usec"]/1000000; $strServer = $_SERVER['SERVER_SOFTWARE']; echo $strServer.' .. '; echo 'PHP '.phpversion().' .. Generated in '.$fltUserTime.' seconds (script execution '.$fltExecTime.' sec.) .. '; $strWikiPg = $this->strWikiPg; if ($strWikiPg) { echo 'wiki: <a href="'.KWP_WIKI.kEmbeddedPagePrefix.$this->strWikiPg.'">'.$strWikiPg.'</a> .. '; } echo date('Y-m-d H:i:s');

echo '
'; echo '

';

$didPage = true;

   }
   protected function RenderHtmlStop() {

echo "\n</body>\n</html>";

   }

// NEW METHODS for this class //

   protected function DoSidebar() {

$objCache = $this->CacheMgr(); // TO DO: these should be pulled from the [stats] table /* if ($objCache->dtNewest) {

   $timeSidebarBuild=$objCache->dtNewest;

} else {

   $timeSidebarBuild = NULL;

}

  • /
   $timeSidebarBuild = NULL;

$statsQtyTitlesAvail = 2245; $statsQtyStockPieces = 1395; $statsQtyStockItems = 753; $statsQtyArtists = 136; $statsQtyTopics = 1048; //---------

echo '

'; echo '

';

   }
   protected function DoSepBar() {
     echo $this->Render_HLine();
   }
   public function Render_HLine($iHeight=NULL) {
     global $fpTools;
     $htHt = is_null($iHeight)?:('height='.$iHeight);
     return '<img src="'.$fpTools.'/img/bg/hlines/"'.$htHt.' alt="-----" width="100%">';
   }
   private function ToolbarItem($iURL,$iIcon,$iTitle,$iAlt) {

global $fpTools; return '<a href="'.$iURL.'"><img border=0 src="'.$fpTools.'/img/icons/'.$iIcon.'.050pxh.png" title="'.$iTitle.'" alt="'.$iAlt.'"></a>';

   }
   protected function DoToolbar() {

global $fpPages,$fwpCart;

echo $this->ToolbarItem($fpPages.'/','home',KS_STORE_NAME.' home page','home page'); echo $this->ToolbarItem($fpPages.'/search/','search','search page','search page'); echo $this->ToolbarItem($fwpCart,'cart','shopping cart','shopping cart'); echo $this->ToolbarItem(KWP_HELP_HOME,'help','help!','help');

   }

// NEW METHODS for this class //

   /*----
     PURPOSE: Renders HTML inside <head></head> section
     HISTORY:

2011-01-11 Created

   */
   protected function RenderHtmlHeaderSection() {

$strTitle = KS_STORE_NAME.' - '.$this->strName; $out = "\n<title>$strTitle</title>";

$arVars = array('sheet' => $this->strSheet); $objStrTplt = new clsStringTemplate_array(NULL,NULL,$arVars); $objStrTplt->MarkedValue(KHT_PAGE_STYLE); $out .= $objStrTplt->Replace(); //$out .= KHT_PAGE_STYLE; if (!empty($this->strName)) { $ftName = ': '.htmlspecialchars($this->strName); } else { $ftName = ; } $strContent = KS_STORE_NAME_META.$ftName; $out .= "\n<meta name=description content=\"$strContent\">"; return $out;

   }
   /*----
     PURPOSE: Renders HTML up to beginning of BODY.
     HISTORY:

2011-01-11 Extracted everything between <head> and </head> into RenderHtmlHeaderSection()

   */
   protected function RenderHtmlStart() {

//$this->strCalcTitle = KS_STORE_NAME.' - '.$this->strName; $out = KHT_PAGE_DOCTYPE; $out .= "\n\n"; $out .= $this->RenderHtmlHeaderSection(); $out .= "\n"; $out .= KHT_PAGE_BODY_TAG; echo $out; } protected function RenderContentHdr() { global $fwpLogo; //$strWikiPg = $this->strWikiPg; // begin content header echo '

'; echo ''; // === LEFT HEADER: Title === echo ''; // === END LEFT HEADER === // === RIGHT HEADER: nav icons === echo ''; // === END RIGHT HEADER === echo "\n
'; echo ''.KS_SMALL_LOGO_ALT.''; if ($this->strTitleContext) { echo ''.KS_STORE_NAME.': '.$this->strTitleContext.'
'; } echo ''.$this->strTitle.'
'; $this->DoToolbar(); echo '
\n

"; } } /* =================== CLASS: clsPage PURPOSE: Handles display of different page types TO DO: These classes (clsPage and descendants) need to be reorganized (they're a mess) and also set up so we can create different skins. */ abstract class clsPage extends clsVbzSkin_Standard { // query protected $strReq; // requested page // page definition protected $strName; // short title: {item name} (goes into html title, prefixed with store name) protected $strTitle; // longer, descriptive title: {"item name" by Supplier} (goes at top of page) protected $strSheet; // name of style sheet to use (without the .css) protected $strWikiPg; // name of wiki page to embed, if any (blank = suppress embedding) protected $strTitleContext; // context of short title, in HTML: {Supplier: Department:} (goes above title, in small print) protected $strHdrXtra; // any extra stuff (HTML) for the header protected $strSideXtra; // any extra stuff for the sidebar protected $lstTop; // stuff listed at the top of the sidebar // calculated fields // protected $strCalcTitle; protected $strContText; // flags set by wiki contents protected $hideImgs; public function __construct($iSpec) { parent::__construct($iSpec); $this->lstTop = new clsList(); } protected function HandleInput() { $this->strSheet = 'browse'; // default } /*----- IMPLEMENTATION: Retrieves request from URL and parses it URL data identifies page, keyed to cat_pages data */ protected function ParseInput() { if (isset($_SERVER['PATH_INFO'])) { $strReq = $_SERVER['PATH_INFO']; } else { $strReq = ''; } $this->strReq = $strReq; if (strrpos($strReq,'/')+1 < strlen($strReq)) { $strRedir = KWP_CAT_REL.substr($strReq,1).'/'; header('Location: '.$strRedir); exit; // retry with new URL } } // DIFFERENT TYPES OF PAGES protected function DoNotFound() { $this->strWikiPg = ''; $this->strTitle = 'Unknown Page'; $this->strName = 'unknown title in catalog'; $this->strTitleContext = 'Tomb of the...'; $this->strHdrXtra = ''; $this->strSideXtra = '

Cat #: '.$this->strReq; } // UTILITY protected function AddText($iText) { $this->strContText .= $iText; } private function DoWikiContent() { # WIKI CONTENTS # $txtPage = GetEmbedPage('cat'); if (KF_USE_WIKI) { $txtWiki = GetWikiPage($this->strWikiPg); if ($txtWiki) { if (strpos($txtWiki,'__NOIMG__') != -1) { $txtWiki = str_replace('__NOIMG__','',$txtWiki); $this->hideImgs = true; } } if ($txtWiki) { echo '
'.$txtWiki.'
'; } } } } class clsPageCat extends clsPage { private $objCatPage; // object for identifying page to display protected function RenderHdrBlocks() { if ($this->useSkin) { parent::RenderHdrBlocks(); } } protected function RenderFtrBlocks() { if ($this->useSkin) { parent::RenderFtrBlocks(); } } protected function HandleInput() { parent::HandleInput(); $strReq = $this->strReq; $this->objCatPage = $this->Pages()->GetItem_byKey($strReq); $objPage = $this->objCatPage; $this->useSkin = TRUE; if ($this->strReq) { if (is_object($objPage)) { switch ($objPage->Type) { case 'S': $this->DoCatSupp(); break; case 'D': $this->DoCatDept(); break; case 'T': $this->DoCatTitle(); break; case 'I': $this->useSkin = FALSE; $this->DoCatImage(); break; } } else { $this->DoNotFound(); } } else { $this->DoCatHome(); } } public function DoContent() { echo $this->strContText; } // SIDEBAR INFO for different types of pages private function DoCatIndicia() { $this->lstTop->Add('Section','by supplier'); } private function DoSuppIndicia($iSupp,$isFinal=true) { $this->DoCatIndicia(); if ($isFinal) { $this->lstTop->Add('Supplier',$iSupp->Name); $this->lstTop->Add('more info'); } else { $this->lstTop->Add('Supplier',$iSupp->Link()); } } private function DoDeptIndicia($iDept,$isFinal=true) { $this->DoSuppIndicia($iDept->Supplier(),false); if ($isFinal) { $this->lstTop->Add('Dept.',$iDept->Name); } else { $this->lstTop->Add('Dept.',$iDept->LinkName()); } } private function DoTitleIndicia($iTitle) { $this->DoDeptIndicia($iTitle->Dept(),false); $this->lstTop->Add('Title',$iTitle->Name); $this->lstTop->Add(' - catalog #',$iTitle->CatNum()); } private function DoCatHome() { $this->DoCatIndicia(); $this->strWikiPg = 'cat'; $this->strTitle = 'Catalog Home'; $this->strName = 'Catalog main page'; $this->strTitleContext = 'hello and welcome to the...'; $this->AddText($this->Suppliers()->DoHomePage()); } private function DoCatSupp() { $objSuppTbl = $this->Suppliers(); $objSupp = $objSuppTbl->GetItem($this->objCatPage->ID_Row); assert('is_object($objSupp)'); $strSuppName = $objSupp->Name; $this->DoSuppIndicia($objSupp); $this->strWikiPg = 'supp:'.strtoupper($objSupp->CatKey); $this->strTitle = $strSuppName; $this->strName = 'listing for '.$strSuppName; $this->strTitleContext = 'Suppliers: '.$strSuppName.':'; $this->AddText($objSupp->DoPage()); } private function DoCatDept() { CallEnter($this,__LINE__,'clsPage.DoCatDept()'); // $objDeptTbl = VbzClasses::Depts(); $objDeptTbl = $this->Depts(); $objDept = $objDeptTbl->GetItem($this->objCatPage->ID_Row); assert('is_object($objDept)'); $objSupp = $objDept->Supplier(); assert('is_object($objSupp)'); $strDeptName = $objDept->Name; $strSuppName = $objSupp->Name; $strDeptLink = $objDept->LinkName(); $strSuppLink = $objSupp->Link(); $this->DoDeptIndicia($objDept); $this->strWikiPg = 'dept:'.strtoupper($objDept->PageKey); $this->strTitle = $strSuppName; $this->strName = $strDeptName.' dept. of '.$strSuppName; $this->strTitleContext = 'items supplied by '.$strSuppLink.'\'s '.$strDeptName.' department:'; $this->AddText($objDept->DoPage()); CallExit('clsPage.DoCatDept()'); } private function DoCatTitle() { CallEnter($this,__LINE__,'clsPage.DoCatTitle()'); $strPageKey = $this->objCatPage->Path; // $objTitleTbl = VbzClasses::Titles(); $objTitleTbl = $this->Titles(); $idRow = $this->objCatPage->ID_Row; $objTitle = $objTitleTbl->GetItem($idRow); assert('is_object($objTitle)'); $objDept = $objTitle->Dept(); assert('is_object($objDept)'); $objSupp = $objDept->Supplier(); assert('is_object($objSupp)'); $strTitleName = $objTitle->Name; $this->DoTitleIndicia($objTitle); // $this->strAbbr = 'title:'.strtoupper($strCatNum); $this->strWikiPg = 'title:'.$objTitle->CatNum(); //print 'ABBR='.$this->strAbbr; $this->strTitle = $strTitleName; $this->strName = $strPageKey.' "'.$strTitleName.'" from '.$objSupp->Name; $this->strTitleContext = 'items supplied by '.$objSupp->Link().'\'s '. $objDept->LinkName().' department:'; $objTitle->hideImgs = $this->hideImgs; $this->AddText($objTitle->DoPage()); CallExit('clsPage.DoCatTitle()'); } private function DoCatImage() { CallEnter($this,__LINE__,'clsPage.DoCatImage()'); // $objImageTbl = VbzClasses::Images(); $objImageTbl = $this->Images(); $objImage = $objImageTbl->GetItem($this->objCatPage->ID_Row); $objImage->DoPage(); CallExit('clsPage.DoCatImage()'); } } /* =========================== *** CATALOG DATA CLASSES *** */ class clsCatPages extends clsVbzTable { public function __construct($iDB) { parent::__construct($iDB); $this->Name('cat_pages'); // cache //$this->Name('qryCat_pages'); // live data $this->KeyName('AB'); $this->ClassSng('clsCatPage'); } public function GetItem_byKey($iKey) { CallEnter($this,__LINE__,__CLASS__.'.GetItem_byKey('.$iKey.')'); $strKey = trim($iKey,'/'); $strKey = str_replace('-','/',$strKey); $sqlCatKey = $this->objDB->SafeParam($strKey); // This function is named wrong, and needs to be rewritten anyway // $this->Touch('clsCatPages.GetItem_byKey('.$iKey.')'); $objItem = $this->GetData('Path="'.$sqlCatKey.'"'); // $objRec = $this->objDB->Query($sql); assert('is_object($objItem)'); if ($objItem->NextRow()) { DumpValue('objItem NumRows',$objItem->hasRows()); CallExit('clsCatPages.GetItem_byKey('.$iKey.') -> Page '.$objItem->AB); } else { CallExit('clsCatPages.GetItem_byKey('.$iKey.') -> no data'); } return $objItem; } } class clsCatPage extends clsDataSet { // == STATIC SECTION // const cksIDName = 'AB'; } class clsSuppliers extends clsVbzTable { // ==== STATIC SECTION // ==== DYNAMIC SECTION public function __construct($iDB) { parent::__construct($iDB); $this->Name('cat_supp'); $this->KeyName('ID'); $this->ClassSng('clsSupplier'); $this->ActionKey('supp'); } public function GetItem_byKey($iKey) { CallEnter($this,__LINE__,__CLASS__.'.GetItem_byKey('.$iKey.')'); $sqlCatKey = $this->objDB->SafeParam($iKey); $objItem = $this->GetData('CatKey="'.$sqlCatKey.'"'); CallExit(__CLASS__.'.GetItem_byKey('.$iKey.') -> new supplier'); return $objItem; } /*---- HISTORY 2010-11-12 disabled automatic cache update */ protected function DataSet_forStore($iClass=NULL) { //$objCache = $this->objDB->CacheMgr(); //$objCache->Update_byName('_supplier_ittyps','clsSuppliers.DoHomePage()'); $sql = 'SELECT * FROM _supplier_ittyps ORDER BY Name, ItemCount DESC'; $objRows = $this->objDB->DataSet($sql,$iClass); return $objRows; } public function DoHomePage() { $out = ''; $objRec = $this->DataSet_forStore(); if ($objRec->hasRows()) { $objTbl = new clsPageOutput; $objTbl->StartTable('Suppliers'); $strKeyLast = $outCell = ''; while ($objRec->NextRow()) { $strKey = $objRec->CatKey; if ($strKey != $strKeyLast) { $strKeyLast = $strKey; $strKeyLink = strtolower($strKey).'/'; if ($outCell) { $objTbl->ColAdd($outCell); $objTbl->RowStop(); $outCell = ''; } $objTbl->RowStart(); $objTbl->ColAdd(''.$objRec->Name.''); $isFirst = true; } if ($isFirst) { $isFirst = false; } else { $outCell .= ', '; } $strItType = $objRec->ItemType; if ($strItType == '') { $strItType = '?id'.$objRec->ID; } $outCell .= ' '.$objRec->ItemCount.' '.$strItType; } $objTbl->ColAdd($outCell); $objTbl->RowStop(); $out .= $objTbl->EndTable(); } return $out; } } class clsSupplier extends clsDataSet { /*---- ACTION: Finds the Item for this Supplier with the given supplier CatNum RETURNS: object of type requested by user; defaults to clsItem. NULL if not found. DEPRECATED -- use GetItem_bySCatNum() */ public function GetItem_bySuppCatNum($iCatNum,$iClass=NULL) { return $this->GetItem_bySCatNum($iCatNum); } /*---- ACTION: Checks the given catalog number to see if it corresponds to a given item for the current supplier INPUT: supplier catalog number OUTPUT: item object (if found) or NULL (if not found) HISTORY: 2011-01-09 Moved here from VbzAdminSupplier; replaces GetItem_bySuppCatNum() */ public function GetItem_bySCatNum($iSCat) { $objTblItems = $this->objDB->Items(); $sqlFind = '(ID_Supp='.$this->ID.') AND (Supp_CatNum="'.$iSCat.'")'; $objItem = $objTblItems->GetData($sqlFind); if ($objItem->HasRows()) { $objItem->NextRow(); return $objItem; } else { return NULL; } } /*---- ACTION: Finds the Title for this Supplier with the given CatKey RETURNS: object of type requested by user; defaults to clsVbzTitle. NULL if not found. HISTORY: 2010-11-07 Created for Title editing page -- need to check for duplicate CatKey before saving. */ public function GetTitle_byCatKey($iCatKey,$iClass='clsVbzTitle') { $sqlCatKey = $this->objDB->SafeParam($iCatKey); $sqlFilt = '(ID_Supplier='.$this->ID.') AND (CatKey="'.$sqlCatKey.'")'; $objTitle = $this->objDB->Titles_Cat()->GetData($sqlFilt,$iClass); if ($objTitle->HasRows()) { $objTitle->NextRow(); return $objTitle; } else { return NULL; } } /*---- ACTION: Searches for Titles whose CatKeys include the given string PURPOSE: used during renaming of supplier-recycled catalog numbers, so we can see if that number has been recycled before and avoid having to repeatedly try new names HISTORY: 2010-11-08 Created for title editing page */ public function GetTitles_byCatKey($iCatKey,$iClass='clsVbzTitle') { $sqlCatKey = $this->objDB->SafeParam($iCatKey); $sqlFilt = '(ID_Supplier='.$this->ID.') AND (CatKey LIKE "%'.$sqlCatKey.'%")'; $objTitle = $this->objDB->Titles_Cat()->GetData($sqlFilt,$iClass); if ($objTitle->HasRows()) { $objTitle->NextRow(); return $objTitle; } else { return NULL; } } protected function DeptsData_forCount($iClass='clsDept') { $objTbl = $this->objDB->Depts(); $objRows = $objTbl->GetData('isActive AND (ID_Supplier='.$this->ID.')',$iClass,'Sort'); return $objRows; } /*---- USED BY: $this->DeptsPage_forStore() RETURNS: array of data for the current supplier array[rows] = source dataset -- each row is an ItTyp within a Department array[depts][ID_Dept][ID_ItTyp] = count of items for sale by department and item type array[supp][ID_ItTyp] = count of items for sale by item type HISTORY: 2011-02-02 switched data source from qryItTypsDepts_ItTyps to _dept_ittyps Page was not displaying at all. Some additional changes were necessary. */ protected function DeptsData_forStore() { if (is_null($this->arDeptsData)) { //$objRows = $this->objDB->DataSet('SELECT * FROM qryItTypsDepts_ItTyps WHERE ID_Supplier='.$this->ID); $objRows = $this->objDB->DataSet('SELECT * FROM _dept_ittyps WHERE ID_Supp='.$this->ID); while ($objRows->NextRow()) { $idItTyp = $objRows->ID_ItTyp; $intCntForSale = $objRows->cntForSale; if (!isset($arObjs[$idItTyp])) { $objItTyp = $this->Engine()->ItTyps()->SpawnItem(); $arObjs[$idItTyp] = $objItTyp; $objItTyp->Row['NameSng'] = $objRows->Value('ItTypNameSng'); $objItTyp->Row['NamePlr'] = $objRows->Value('ItTypNamePlr'); $objItTyp->Row['cntForSale'] = 0; // initialize the count } // accumulate the list of everything this supplier has: $idSupp = $objRows->ID_Supplier; $objItTyp->Row['cntForSale'] += $intCntForSale; // accumulate the department listing: $idDept = $objRows->Value('ID_Dept'); $arDeptCntForSale[$idDept][$idItTyp] = $intCntForSale; } $arOut['rows'] = $objRows; $arOut['depts'] = $arDeptCntForSale; $arOut['supp'] = $arObjs; $this->arDeptsData = $arOut; } return $this->arDeptsData; } /*---- ACTION: Generates the item-type-count summary for the Supplier's index page */ public function DoPiece_ItTyp_Summary() { $arData = $this->DeptsData_forStore(); $arObjs = $arData['supp']; $outRow = ''; foreach ($arObjs as $id=>$obj) { $objTyp = $obj; $cnt = $objTyp->Value('cntForSale'); if ($cnt > 0) { $strType = $objTyp->Name($cnt); if ($outRow != '') { $outRow .= ', '; } $outRow .= ''.$cnt.' '.$strType; } } $out = ''.$outRow.''; return $out; } /*---- ACTION: Generates the table of departments and the summary of items available for each */ public function DoPiece_Dept_ItTyps() { $arData = $this->DeptsData_forStore(); $arObjs = $arData['supp']; $arDeptCntForSale = $arData['depts']; $out = ''; $isOdd = FALSE; $fpSupp = KWP_CAT_REL.strtolower($this->Value('CatKey')).'/'; foreach ($arDeptCntForSale as $idDept=>$arCnts) { $isOdd = !$isOdd; if ($isOdd) { $cellOpen = ''.$cellOpen.''.$strName.''; $out .= $cellOpen.$outRow.''; } } $out .= '
'; } else { $cellOpen = ''; } $outRow = ''; foreach ($arCnts as $id=>$cnt) { if ($cnt > 0) { $objTyp = $arObjs[$id]; $strType = $objTyp->Name($cnt); if ($outRow != '') { $outRow .= ', '; } $outRow .= ''.$cnt.' '.$strType; } } if ($outRow != '') { $objDept = $this->objDB->Depts()->GetItem($idDept); $strPageKey = $objDept->PageKey(); $strName = $objDept->Name; $out .= '
'; return $out; } protected function DeptsPage_forStore() { $out = $this->DoPiece_ItTyp_Summary(); $out .= $this->Engine()->SectionHdr('Departments:'); $out .= $this->DoPiece_Dept_ItTyps(); return $out; } public function DoPage() { $out = ''; assert('$this->ID'); // first, check how many departments supplier has: //$objDeptTbl = $this->objDB->Depts(); //$objDepts = $objDeptTbl->GetData('isActive AND (ID_Supplier='.$this->ID.')','clsDept','Sort'); $objDepts = $this->DeptsData_forCount(); $intRows = $objDepts->RowCount(); if ($intRows == 1) { // if there's only one department, display that instead of a department listing $objDepts->NextRow(); // get the first/only dept $out = $objDepts->DoPage(); } else { $out .= $this->DeptsPage_forStore(); } return $out; } public function ShopLink($iText=NULL) { if (is_null($iText)) { $strText = $this->Name; } else { $strText = $iText; } $out = ''.$strText.''; return $out; } public function Link() { return $this->ShopLink(); } public function URL() { return KWP_CAT_REL.strtolower($this->CatKey).'/'; } } class clsDepts extends clsVbzTable { public function __construct($iDB) { parent::__construct($iDB); $this->Name('cat_depts'); $this->KeyName('ID'); $this->ClassSng('clsDept'); $this->ActionKey('dept'); } protected function _newItem() { CallStep('clsDepts._newItem()'); return new clsDept($this); } // THIS FUNCTION IS DEPRECATED /* public function DoListing_forSupp($iSuppID) { CallEnter($this,__LINE__,'clsDepts.DoListing_forSupp('.$iSuppID.')'); //$objRows = $this->objDB->DataSet('SELECT * FROM qryItTypsDepts_ItTyps WHERE ID_Supplier='.$iSuppID); $objRows = $this->Data_forStore(); while ($objRows->NextRow()) { $idItTyp = $objRows->ID_ItTyp; $intCntForSale = $objRows->cntForSale; $arTypSng[$idItTyp] = $objRows->ItTyp_Sng; $arTypPlr[$idItTyp] = $objRows->ItTyp_Plr; // accumulate the list of everything this supplier has: $idSupp = $objRows->ID_Supplier; if (isset($arSuppCntForSale[$idItTyp])) { $arSuppCntForSale[$idItTyp] += $intCntForSale; } else { $arSuppCntForSale[$idItTyp] = $intCntForSale; } // accumulate the department listing: $idDept = $objRows->ID_Dept; $arDeptCntForSale[$idDept][$idItTyp] = $intCntForSale; } // Now present the accumulated data: // - SUPPLIER: $outRow = ''; foreach ($arSuppCntForSale as $idType=>$cnt) { if ($cnt == 1) { $strType = $arTypSng[$idType]; } else { $strType = $arTypPlr[$idType]; } if ($outRow != '') { $outRow .= ', '; } $outRow .= ''.$cnt.' '.$strType; } $out = ''.$outRow.''; // - DEPARTMENTS: $out .= '

Departments:

'; $isOdd = FALSE; foreach ($arDeptCntForSale as $idDept=>$arCnts) { $isOdd = !$isOdd; if ($isOdd) { $cellOpen = ''.$cellOpen.''.$strName.''; $outRow = ''; foreach ($arCnts as $idType=>$cnt) { if ($cnt == 1) { $strType = $arTypSng[$idType]; } else { $strType = $arTypPlr[$idType]; } if ($outRow != '') { $outRow .= ', '; } $outRow .= ''.$cnt.' '.$strType; } $out .= $cellOpen.$outRow.''; } $out .= '
'; } else { $cellOpen = ''; } $objDept = $this->objDB->Depts()->GetItem($idDept); $strPageKey = $objDept->PageKey(); $strName = $objDept->Name; $out .= '
'; CallExit('clsDepts.DoListing_forSupp()'); return $out; } /**/ } class clsDept extends clsDataSet { // object cache private $objSupp; public function SuppObj() { if (is_object($this->objSupp)) { return $this->objSupp; } else { $idSupp = $this->ID_Supplier; if ($idSupp) { $this->objSupp = $this->objDB->Suppliers()->GetItem($idSupp); return $this->objSupp; } else { return NULL; } } } // DEPRECATED -- use SuppObj() public function Supplier() { return $this->SuppObj(); } public function PageKey() { if ($this->PageKey) { return $this->PageKey; } else { return $this->CatKey; } } /*---- PURPOSE: loads data needed to display catalog views for this department HISTORY 2010-11-12 disabled automatic cache update 2010-11-16 changed sorting field from cntInPrint to cntForSale 2011-02-02 using _dept_ittyps now instead of qryItTypsDepts_ItTyps Also added "AND (cntForSale)" to WHERE clause -- not listing titles with nothing to sell */ protected function Data_forStore() { // was GetDeptData() //$objCache = $this->objDB->CacheMgr(); //$objCache->Update_byName('_dept_ittyps','clsDept.DoListing() for ID='.$this->ID); //$sql = 'SELECT * FROM qryItTypsDepts_ItTyps WHERE (ID_Dept='.$this->ID.') ORDER BY cntForSale DESC'; $sql = 'SELECT * FROM _dept_ittyps WHERE (ID_Dept='.$this->ID.') AND (cntForSale) ORDER BY cntForSale DESC'; $objItTyps = $this->objDB->DataSet($sql,'clsItTyp'); return $objItTyps; } /*----- PURPOSE: Print this department's information as part of department list HISTORY: 2010-11-16 $cntAvail is now cntForSale, not cntInPrint+qtyInStock */ public function DoListing() { assert('$this->ID'); $objItTyps = $this->Data_forStore(); $isFirst = true; $out = ''; while ($objItTyps->NextRow()) { if ($isFirst) { $isFirst = false; } else { $out .= ', '; } $cntInPrint = $objItTyps->cntInPrint; $qtyInStock = $objItTyps->qtyForSale; //$cntAvail = $cntInPrint + $qtyInStock; $cntForSale = $objItTyps->cntForSale; if ($cntAvail == 1) { $strName = $objItTyps->ItTyp_Sng; } else { $strName = $objItTyps->ItTyp_Plr; } $out .= ' '.$cntAvail.' '.$strName; } return $out; } /*---- PURPOSE: Print page for current department ACTION: * Iterates through item types available for this department. * For each item type, prints header and then a list of titles. HISTORY: 2010-11-?? Started using cached table _title_ittyps instead of qryTitles_ItTyps_Titles 2010-11-16 $cntAvail is now cntForSale, not cntInPrint+qtyInStock 2011-02-02 $qtyInStock now set to Row['qtyInStock'], not Row['qtyForSale'] which didn't make sense anyway */ public function DoPage() { $out = ''; $idDept = $this->ID; if (empty($idDept)) { throw new exception('Department object has no ID'); } $objSection = new clsPageOutput(); // calculate the list of item types available in this department $objItTyps = $this->Data_forStore(); $objTitles = new clsVbzTitle($this->objDB); $objNoImgSect = new clsPageOutput(); $cntSections = 0; while ($objItTyps->NextRow()) { $cntInPrint = $objItTyps->Row['cntInPrint']; $qtyInStock = $objItTyps->Row['qtyInStock']; $cntAvail = $objItTyps->Row['cntForSale']; if ($cntAvail) { $cntSections++; $idItTyp = $objItTyps->Row['ID_ItTyp']; $sql = 'SELECT *, ID_Title AS ID, TitleName AS Name, cntInStock FROM _title_ittyps WHERE ((cntForSale) AND (ID_ItTyp='.$idItTyp.') AND (ID_Dept='.$idDept.'));'; //$sql = 'SELECT t.ID_Title AS ID, t.* FROM qryTitles_ItTyps_Titles AS t WHERE (ID_ItTyp='.$idItTyp.') AND (ID_Dept='.$idDept.');'; $objTitles->Query($sql); $arTitles = NULL; if ($objTitles->hasRows()) { while ($objTitles->NextRow()) { // add title to display list $arTitles[] = $objTitles->Values(); // save it in a list } assert('is_array($arTitles)'); // We've generated the list of titles for this section; now display the section header and titles: $out .= $this->objDB->ShowTitles($objItTyps->Row['ItTypNamePlr'].':',$arTitles,$objNoImgSect); } else { echo 'ERROR: No titles found! SQL='.$sql; } $objSection->Clear(); } else { $out .= 'Small coding error: this line should never happen.'; // TO DO: log an error } } if (!$cntSections) { $out .= 'This department appears to have been emptied of all leftover stock. (Eventually there will be a way to see what items used to be here.)'; } if ($objNoImgSect->inTbl) { $objNoImgSect->EndTable(); $objSection->AddText($objNoImgSect->out); $objSection->EndTable(); $out .= $objSection->out; } return $out; } public function URL_Rel() { $strURL = $this->Supplier()->URL(); $strKey = $this->PageKey(); if ($strKey) { $strURL .= strtolower($strKey).'/'; } return $strURL; } public function URL_Abs() { return KWP_ROOT.$this->URL_Rel(); } public function LinkName() { $strURL = $this->URL_Rel(); return ''.$this->Name.''; } /*----- RETURNS: The string which, when prepended to a Title's CatKey, would form the Title's catalog number */ public function CatPfx() { $strFull = strtoupper($this->Supplier()->CatKey); if ($this->AffectsCatNum()) { $strFull .= '-'.strtoupper($this->CatKey); } return $strFull.'-'; } /*----- RETURNS: TRUE if this department affects the catalog number (i.e. if CatKey is non-blank) */ public function AffectsCatNum() { return ($this->CatKey != ''); } } class clsVbzTitles extends clsVbzTable { public function __construct($iDB) { parent::__construct($iDB); $this->Name('cat_titles'); $this->KeyName('ID'); $this->ClassSng('clsVbzTitle'); } public function Search_forText_SQL($iFind) { return '(Name LIKE "%'.$iFind.'%") OR (`Desc` LIKE "%'.$iFind.'%")'; } public function Search_forText($iFind) { $sqlFilt = $this->Search_forText_SQL($iFind); $rs = $this->GetData($sqlFilt); return $rs; } /* ACTION: Finds a Title from a CatNum and returns an object for it TO DO: Rename to Get_byCatNum() Stop using v_titles */ /* 2010-11-07 Is anything actually using this? public function GetItem_byCatNum($iCatNum) { global $objDataMgr; CallEnter($this,__LINE__,__CLASS__.'.GetItem_byCatNum('.$iCatNum.')'); assert('is_object($this->objDB)'); $sqlCatNum = strtoupper(str_replace('.','-',$iCatNum)); $sqlCatNum = $this->objDB->SafeParam($sqlCatNum); $sql = 'SELECT * FROM v_titles WHERE CatNum="'.$sqlCatNum.'"'; // $objTitle = new clsVbzTitleExt($this); $objTitle = new clsVbzTitle($this); // make sure _titles (part of v_titles) is up-to-date //$objDataMgr->Update_byName('_titles','GetItem_byCatNum('.$iCatNum.')'); $objDataMgr->Update_byName('_depts','GetItem_byCatNum('.$iCatNum.')'); // get data from v_titles $objTitle->Query($sql); $idTitle = $objTitle->ID; assert('is_resource($objTitle->Res)'); if ($objTitle->RowCount()) { assert('$idTitle'); $sql = 'SELECT * FROM titles WHERE ID='.$idTitle; $objTitle->dontLoadBasic = true; $objTitle->Query($sql); CallExit('clsVbzTitles.GetItem_byCatNum() -> ok'); return $objTitle; } else { CallExit('clsVbzTitles.GetItem_byCatNum() -> NULL'); return NULL; } } */ } class clsVbzTitle extends clsDataSet { // object cache private $objDept; private $objSupp; // options public $hideImgs; public function Dept() { $doLoad = FALSE; if (empty($this->objDept)) { $doLoad = TRUE; } else if (is_object($this->objDept)) { if ($this->ID_Dept != $this->objDept->ID) { $doLoad = TRUE; } } else { $doLoad = TRUE; } if ($doLoad) { $idDept = $this->ID_Dept; if (empty($idDept)) { $objDept = NULL; } else { $objDept = $this->objDB->Depts()->GetItem($idDept); assert('is_object($objDept)'); } $this->objDept = $objDept; } return $this->objDept; } /*---- RETURNS: ID of this title's supplier HISTORY: 2011-09-28 revised to get ID directly from the new ID_Supp field instead of having to look up the Dept and get it from there. */ public function Supplier_ID() { /* $objDept = $this->Dept(); $idSupp = $objDept->ID_Supplier; */ $idSupp = $this->Value('ID_Supp'); return $idSupp; } // DEPRECATED -- use SuppObj() public function Supplier() { return $this->SuppObj(); } public function SuppObj() { $doLoad = FALSE; if (empty($this->objSupp)) { $doLoad = TRUE; } else if (is_object($this->objSupp)) { if ($this->ID_Supplier != $this->objSupp->ID) { $doLoad = TRUE; } } else { $doLoad = TRUE; } if ($doLoad) { $idSupp = $this->Supplier_ID(); if (empty($idSupp)) { $objSupp = NULL; } else { $objSupp = $this->objDB->Suppliers()->GetItem($idSupp); assert('is_object($objSupp)'); } $this->objSupp = $objSupp; } return $this->objSupp; } public function Items() { $sqlFilt = 'ID_Title='.$this->ID; $objTbl = $this->objDB->Items(); $objRows = $objTbl->GetData($sqlFilt); return $objRows; } public function Topics() { $objTbl = $this->Engine()->TitleTopic_Topics(); $objRows = $objTbl->GetTitle($this->KeyValue()); return $objRows; } public function DoPage() { $idTitle = $this->KeyValue(); assert('$idTitle'); $objSection = new clsPageOutput(); // show "small" images if (!$this->hideImgs) { $objImgs = $this->ListImages('sm'); if ($objImgs->hasRows()) { while ($objImgs->NextRow()) { $strImgTag = $objImgs->AttrDispl; $urlRel = $objImgs->Spec; $idImg = $objImgs->ID; //$strImg = 'WebSpec().'"'; if ($strImgTag) { $strImg .= ' title="'.$strImgTag.'"'; } $strImg .= '>'; $objImgBig = $objImgs->ImgForSize('big'); if (is_object($objImgBig)) { if ($objImgBig->FirstRow()) { $strImg = $objImgBig->Href().$strImg.''; } } $objSection->AddText($strImg); } } else { $objSection->ShowImgUnavail(); } } // list topics for this title $db = $this->Engine(); $tbl = $db->TitleTopic_Topics(); $tbl->doBranch(TRUE); $rs = $tbl->GetTitle($idTitle); if ($rs->hasRows()) { $txt = '
'; $txt .= ''.$db->Topics()->IndexLink('Topics').':'; while ($rs->NextRow()) { $txt .= '
- '.$rs->ShopLink(); } $txt .= '
'; $objSection->AddText($txt); } // now list available items as table //$sql = 'SELECT * FROM qryTitles_ItTyps_ItTyps WHERE (ID_Title='.$idTitle.') ORDER BY ItTyp_Sort IS NULL, ItTyp_Sort;'; $sql = 'SELECT * FROM _title_ittyps WHERE (ID_Title='.$idTitle.') ORDER BY ItTypSort IS NULL, ItTypSort;'; $rsTypes = $this->Engine()->DataSet($sql); $isItem = FALSE; if ($rsTypes->hasRows()) { if (KF_CART_ABSOLUTE) { $urlCart = KWP_CART_ABS; } else { $urlCart = KWP_CART_REL; } $objSection->AddText('
'); $flagDisplayTogether = false; // hard-coded for now //$objStk = $this->Engine()->Items_Stock(); $tblItems = $this->Engine()->Items(); //$txtTblHdr = 'OptionStatusPriceOrder
Qty.list
price'; $txtTblHdr = $tblItems->Render_TableHdr(); $txtInStock = $txtOutStock = ''; while ($rsTypes->NextRow()) { $idItTyp = $rsTypes->Value('ID_ItTyp'); assert('$idItTyp'); $sqlFilt = '(ID_Title='.$idTitle.') AND (ID_ItTyp='.$idItTyp.')'; $sqlSort = 'GrpSort,GrpDescr,ItOpt_Sort'; $rsItems = $tblItems->GetData($sqlFilt,NULL,$sqlSort); //$idItType = 0; $txtLine = ''.$rsTypes->Value('ItTypNamePlr').':'; if ($flagDisplayTogether) { // displaying all items in a single listing $txtBoth .= $txtLine; } else { // set flags to determine which stock-status sections to show $cntInStock = $rsTypes->Value('cntInStock'); $cntForSale = $rsTypes->Value('cntForSale'); $cntOutStock = $cntForSale - $cntInStock; if ($cntInStock > 0) { $txtInStock .= $txtLine; } if ($cntOutStock > 0) { $txtOutStock .= $txtLine; } } // iterate through items for this type: $strGrpLast = ''; while ($rsItems->NextRow()) { $strGrp = $rsItems->Value('GrpDescr'); $qtyStk = $rsItems->Value('QtyIn_Stk'); if ($strGrp != $strGrpLast) { $strGrpLast = $strGrp; $strGrpCode = $rsItems->Value('GrpCode'); $out = ''; $out .= ' — '.$strGrp; if ($strGrpCode) { $out .= ' ('.$strGrpCode.')'; } $out .= ''; $out .= ''; // this should probably be a subroutine... if ($flagDisplayTogether) { $txtBoth .= $out; } else { if ($qtyStk > 0) { $txtInStock .= $out; } else { $txtOutStock .= $out; } } } //echo '
GOT TO #1 - qty='.$qtyStk; if ($rsItems->Value('isForSale')) { $isItem = TRUE; $txtLine = $rsItems->Render_TableRow(); if ($flagDisplayTogether) { $txtBoth .= $txtLine; } else { if ($qtyStk > 0) { $txtInStock .= $txtLine; } else { $txtOutStock .= $txtLine; } } } } } // DO the actual display of the accumulated text $txtTblOpen = ''; $txtTblFtr = ''; $txtTblShut = '
'; if ($flagDisplayTogether) { // Display in-stock and backordered items together $objSection->AddText($txtTblOpen); $objSection->AddText($txtTblHdr); $objSection->AddText($txtBoth); $objSection->AddText($txtTblFtr); $objSection->AddText($txtTblShut); } else { if ($txtInStock != '') { $txtClause = Pluralize($cntInStock,'This item is','These items are'); $objSection->AddText($txtTblOpen); $objSection->AddText(''.$txtClause.' in stock:'); $objSection->AddText($txtTblHdr); $objSection->AddText($txtInStock); $objSection->AddText($txtTblFtr); $objSection->AddText($txtTblShut); } if (!empty($txtOutStock)) { if (!empty($txtInStock)) { $objSection->AddText('

'); } $txtClause = Pluralize($cntOutStock,'This item is','These items are'); $objSection->AddText($txtTblOpen); $objSection->AddText(''.$txtClause.' not in stock'); $txtClause = Pluralize($cntOutStock,'it','them'); $objSection->AddText(', but we can (probably) get '.$txtClause.':'); $objSection->AddText($txtTblHdr); $objSection->AddText($txtOutStock); $objSection->AddText($txtTblFtr); $objSection->AddText($txtTblShut); } /**/ } $objSection->AddText('

'); } if (!$isItem) { $objSection->SectionHdr('This title is currently unavailable'); } return $objSection->out."\n\n"; } /*---- RETURNS: Array containing summary information about this title */ public function Indicia(array $iarAttr=NULL) { $objItems = $this->Items(); $intActive = 0; $intRetired = 0; if ($objItems->HasRows()) { while ($objItems->NextRow()) { if ($objItems->isForSale) { $intActive++; } else { $intRetired++; } } } // "dark-bg" brings up link colors for a dark background $arLink = array('class'=>'dark-bg'); // merge in any overrides or additions from iarAttr: if (is_array($iarAttr)) { $arLink = array_merge($arLink,$iarAttr); } $htLink = $this->Link($arLink); $txtCatNum = $this->CatNum(); $txtName = $this->Name; $arOut['cnt.active'] = $intActive; $arOut['cnt.retired'] = $intRetired; $arOut['txt.cat.num'] = $txtCatNum; $arOut['ht.link.open'] = $htLink; $arOut['ht.cat.line'] = $htLink.$txtCatNum.' '.$txtName; return $arOut; } /*---- RETURNS: Array containing summaries of ItTyps in which this Title is available array['text.!num'] = plaintext version with no numbers (types only) array['text.cnt'] = plaintext version with line counts array['html.cnt'] = HTML version with line counts array['html.qty'] = HTML version with stock quantities HISTORY: 2011-01-23 written */ public function Summary_ItTyps($iSep=', ') { $dsRows = $this->DataSet_ItTyps(); $outTextNoQ = $outTextType = $outTextCnt = $outHTMLCnt = $outHTMLQty = NULL; if ($dsRows->HasRows()) { $isFirst = TRUE; while ($dsRows->NextRow()) { $cntType = $dsRows->Value('cntForSale'); if ($cntType > 0) { $qtyStk = $dsRows->Value('qtyInStock'); $txtSng = $dsRows->Value('ItTypNameSng'); $txtPlr = $dsRows->Value('ItTypNamePlr'); $strType = Pluralize($cntType,$txtSng,$txtPlr); if ($isFirst) { $isFirst = FALSE; } else { $outTextType .= $iSep; $outTextCnt .= $iSep; $outHTMLCnt .= $iSep; if (!is_null($outHTMLQty)) { $outHTMLQty .= $iSep; } } $outTextType .= $txtSng; $outTextCnt .= $cntType.' '.$strType; $outHTMLCnt .= ''.$cntType.' '.$strType; if (!empty($qtyStk)) { $outHTMLQty .= ''.$qtyStk.' '.Pluralize($qtyStk,$txtSng,$txtPlr); } } } } $arOut['text.!num'] = $outTextType; $arOut['text.cnt'] = $outTextCnt; $arOut['html.cnt'] = $outHTMLCnt; $arOut['html.qty'] = $outHTMLQty; return $arOut; } // LATER: change name to DataSet_Images() to clarify that this returns a dataset, not a text list or array public function ListImages($iSize) { $sqlFilt = '(ID_Title='.$this->ID.') AND (Ab_Size="'.$iSize.'") AND isActive'; $objImgs = $this->objDB->Images()->GetData($sqlFilt,'clsImage','AttrSort'); return $objImgs; } /*---- RETURNS: dataset of item types for this title USES: _title_ittyps (cached table) HISTORY: 2011-01-19 written */ public function DataSet_ItTyps() { $sql = 'SELECT * FROM _title_ittyps WHERE ID_Title='.$this->KeyValue(); $obj = $this->Engine()->DataSet($sql,'clsTitleIttyp'); return $obj; } /*---- HISTORY: 2010-10-19 added optimization to fetch answer from CatKey field if it exists. This may cause future problems. Remove $iSep field and create individual functions if so. */ public function CatNum($iSep='-') { if (empty($this->Row['CatNum'])) { $objDept = $this->Dept(); if (is_object($objDept)) { $objSupp = $objDept->Supplier(); $strDeptKey = $objDept->CatKey; $strOut = $objSupp->CatKey; if ($strDeptKey) { $strOut .= $iSep.$strDeptKey; } } else { $strOut = '?'; } $strOut .= $iSep.$this->CatKey; } else { $strOut = $this->CatNum; } return strtoupper($strOut); } public function URL_part() { return strtolower($this->CatNum('/')); } public function URL($iBase=KWP_CAT_REL) { return $iBase.$this->URL_part(); } public function Link(array $iarAttr=NULL) { $strURL = $this->URL(); $htAttr = ArrayToAttrs($iarAttr); return ''; } public function LinkAbs() { $strURL = $this->URL(KWP_CAT); return ''; } public function LinkName() { return $this->Link().$this->Name.''; } /* 2010-11-06 if this is needed, use a method in SpecialVbzAdmin public function LinkName_wt() { // TO DO: make this more configurable $out = '[[vbznet:cat/'.$this->URL_part().'|'.$this->Name.']]'; return $out; } */ } /*==== PURPOSE: TITLE/ITTYP hybrid TABLE: _title_ittyps */ class clsTitleIttyp extends clsDataSet { // object cache private $objIttyp; public function Ittyp() { if (is_null($this->objIttyp)) { $this->objIttyp = VbzClasses::ItTyps()->GetItem($this->ID_ItTyp); } return $this->objIttyp; } } /* -------------------- *\ ITEM classes \* -------------------- */ class clsItems extends clsVbzTable { public function __construct($iDB) { parent::__construct($iDB); $this->Name('cat_items'); $this->KeyName('ID'); $this->ClassSng('clsItem'); } /*---- ACTION: Finds the Item with the given CatNum, and returns a clsItem object */ public function Get_byCatNum($iCatNum) { $sqlCatNum = $this->objDB->SafeParam(strtoupper($iCatNum)); $objItem = $this->GetData('CatNum="'.$sqlCatNum.'"'); if ($objItem->HasRows()) { $objItem->NextRow(); return $objItem; } else { return NULL; } } public function Search_byCatNum($iCatNum) { $sqlCatNum = $this->objDB->SafeParam(strtoupper($iCatNum)); $objItem = $this->GetData('CatNum LIKE "%'.$sqlCatNum.'%"'); if ($objItem->HasRows()) { return $objItem; } else { return NULL; } } /*---- RETURNS: Table header for list of available items on catalog Title pages HISTORY: 2011-01-24 created/corrected from code in Title page-display function */ public function Render_TableHdr() { return '' .'Option' .'Status' .'List
Price' .'Our
Price' .'Order
Qty.' .''; } } /* =============== CLASS: clsItem NOTES: * "in stock" always refers to stock for sale, not stock which has already been purchased * 2009-12-03: The above note does not clarify anything. * Four methods were moved here from clsShopCartLine in shop.php: ItemSpecs(), ItemDesc(), ItemDesc_ht(), ItemDesc_wt() They are used for displaying a full description of an item, in both shop.php and SpecialVbzAdmin */ class clsItem extends clsDataSet { // object cache private $objTitle; private $objItTyp; private $objItOpt; public function CatNum() { return $this->Value('CatNum'); } public function DescSpecs(array $iSpecs=NULL) { if (is_null($iSpecs)) { $this->objTitle = $this->Title(); $this->objItTyp = $this->ItTyp(); $this->objItOpt = $this->ItOpt(); $out['tname'] = $this->objTitle->Name; $out['ittyp'] = $this->objItTyp->Name($this->Qty); $out['itopt'] = $this->objItOpt->Descr; return $out; } else { return $iSpecs; } } public function DescLong(array $iSpecs=NULL) { // plaintext if (is_null($this->Value('Descr'))) { $sp = $this->DescSpecs($iSpecs); $strItOpt = $sp['itopt']; $out = '"'.$sp['tname'].'" ('.$sp['ittyp']; if (!is_null($strItOpt)) { $out .= ' - '.$strItOpt; } $out .= ')'; } else { $out = $this->Value('Descr'); } return $out; } public function DescLong_ht(array $iSpecs=NULL) { // as HTML $sp = $this->DescSpecs($iSpecs); $htTitleName = ''.$this->Title()->LinkName().''; $strItOpt = $sp['itopt']; $out = $htTitleName.' ('.$sp['ittyp']; if (!is_null($strItOpt)) { $out .= ' - '.$strItOpt; } $out .= ')'; return $out; } /*----- ASSUMES: This item is ForSale, so isForSale = true and (qtyForSale>0 || isInPrint) = true HISTORY: 2011-01-24 Renamed Print_TableRow() -> Render_TableRow; corrected to match header */ public function Render_TableRow() { $arStat = $this->AvailStatus(); $strCls = $arStat['cls']; $out = ''; $out .= ' '.$this->Value('ItOpt_Descr').''; $out .= ''.$arStat['html'].''; $out .= ''.DataCurr($this->Value('PriceList')).''; $out .= ''.DataCurr($this->Value('PriceSell')).''; $out .= ''.''; $out .= ''; return $out; } /*---- ACTION: Returns an array with human-friendly text about the item's availability status RETURNS: array['html']: status text, in HTML format array['cls']: class to use for displaying item row in a table USED BY: Render_TableRow() NOTE: This probably does not actually need to be a separate method; I thought I could reuse it to generate status for titles, but that doesn't make sense. Maybe it will be easier to adapt, though, as a separate method. HISTORY: 2010-11-16 Modified truth table for in-print status so that if isInPrint=FALSE, then status always shows "out of print" even if isCurrent=FALSE. What happens when a supplier has been discontinued? Maybe we need to check that separately. Wait for an example to come up, for easier debugging. 2011-01-24 Corrected to use cat_items fields */ private function AvailStatus() { //echo 'SQL=['.$this->sqlMake.']'; //echo '
'.print_r($this->Row,TRUE).'
'; $qtyInStock = $this->Value('QtyIn_Stk'); if ($qtyInStock) { $strCls = 'inStock'; $strStk = $qtyInStock.' in stock'; } else { $strCls = 'noStock'; $strStk = 'none in stock'; } $isInPrint = $this->Value('isInPrint'); if ($isInPrint) { if ($this->Value('isCurrent')) { if ($qtyInStock) { $txt = $strStk.'; more available'; } else { $txt = 'available, not in stock'; } } else { if ($qtyInStock) { $txt = $strStk.'; in-print status uncertain'; } else { $txt = $strStk.'; availability uncertain'; } } } else { if (is_null($isInPrint)) { $txt = ''.$strStk.' - possibly out of print'; } else { $txt = ''.$strStk.' - out of print!'; } } $arOut['html'] = $txt; $arOut['cls'] = $strCls; return $arOut; } public function Title() { $doLoad = TRUE; if (is_object($this->objTitle)) { if ($this->objTitle->ID == $this->ID_Title) { $doLoad = FALSE; } } if ($doLoad) { $this->objTitle = $this->objDB->Titles()->GetItem($this->ID_Title); } return $this->objTitle; } public function Supplier() { return $this->Title()->Supplier(); } public function ItTyp() { $doLoad = TRUE; if (is_object($this->objItTyp)) { if ($this->objItTyp->ID == $this->ID_ItTyp) { $doLoad = FALSE; } } if ($doLoad) { $this->objItTyp = $this->objDB->ItTyps()->GetItem($this->ID_ItTyp); } return $this->objItTyp; } public function ItOpt() { $doLoad = TRUE; if (is_object($this->objItOpt)) { if ($this->objItOpt->ID == $this->ID_ItOpt) { $doLoad = FALSE; } } if ($doLoad) { $this->objItOpt = $this->objDB->ItOpts()->GetItem($this->ID_ItOpt); } return $this->objItOpt; } // DEPRECATED - use ShipCostObj() public function ShCost() { return $this->ShipCostObj(); } /*---- HISTORY: 2010-10-19 created from contents of ShCost() */ public function ShipCostObj() { $doLoad = FALSE; if (empty($this->objShCost)) { $doLoad = TRUE; } elseif ($this->objShCost->ID != $this->ID_ShipCost) { $doLoad = TRUE; } if ($doLoad) { $this->objShCost = $this->objDB->ShipCosts()->GetItem($this->ID_ShipCost); } return $this->objShCost; } /*---- RETURNS: The item's per-item shipping price for the given shipping zone FUTURE: Rename to ShPerItm_forZone() */ public function ShipPriceItem($iZone) { global $listItmFactors; $fltZoneFactor = $listItmFactors[$iZone]; $objSh = $this->ShipCostObj(); return $objSh->PerItem * $fltZoneFactor; } /*---- RETURNS: The item's per-package shipping price for the given shipping zone FUTURE: Rename to ShPerPkg_forZone() */ public function ShipPricePkg($iZone) { global $listPkgFactors; $fltZoneFactor = $listPkgFactors[$iZone]; return $this->ShipCostObj()->PerPkg * $fltZoneFactor; } /*---- RETURNS: The item's per-item shipping price, with no zone calculations FUTURE: need to handle shipping zone more gracefully and rigorously This function is currently only used in the admin area, so does not need to be infallible. */ public function ShPerItm() { return $this->ShipCostObj()->Value('PerItem'); } /*---- RETURNS: The item's per-package shipping price, with no zone calculations FUTURE: need to handle shipping zone more gracefully and rigorously This function is currently only used in the admin area, so does not need to be infallible. */ public function ShPerPkg() { return $this->ShipCostObj()->Value('PerPkg'); } } /*==== PURPOSE: clsItems with additional catalog information */ class clsItems_info_Cat extends clsItems { public function __construct($iDB) { parent::__construct($iDB); $this->Name('qryCat_Items'); //$this->ClassSng('clsItem_info_Cat'); } } /* -------------------- *\ ITEM TYPE classes \* -------------------- */ class clsItTyps extends clsVbzTable { public function __construct($iDB) { parent::__construct($iDB); $this->Name('cat_ittyps'); $this->KeyName('ID'); $this->ClassSng('clsItTyp'); } // BOILERPLATE - cache protected $objCache; protected function Cache() { if (!isset($this->objCache)) { $this->objCache = new clsCache_Table($this); } return $this->objCache; } public function GetItem_Cached($iID=NULL,$iClass=NULL) { return $this->Cache()->GetItem($iID,$iClass); } /* public function GetData_Cached($iWhere=NULL,$iClass=NULL,$iSort=NULL) { return $this->Cache()->GetData($iWhere,$iClass,$iSort); } */ /*---- FUTURE: * This method really belongs with Admin functions, since it will never be used in the standalone store * If table ever grows to a significant size, we might end up changing the filtering criteron. HISTORY: 2010-11-21 Adapted from clsFolders. */ public function DropDown($iName=NULL,$iDefault=NULL,$iChoose=NULL) { $strName = is_null($iName)?($this->Table->ActionKey()):$iName; $arRows = $this->Cache()->GetData_array('isType',NULL,'Sort, NameSng'); $out = $this->DropDown_for_array($arRows,$strName,$iDefault,$iChoose); return $out; } /*---- ACTION: same as clsItTyp::DropDown_for_rows, but takes an array HISTORY: 2011-02-11 wrote */ public function DropDown_for_array(array $iRows,$iName=NULL,$iDefault=NULL,$iChoose=NULL) { $strName = is_null($iName)?($this->Table->ActionKey()):$iName; $objRow = $this->SpawnItem(); foreach($iRows as $key => $row) { $objRow->Values($row); $arList[$key] = $objRow->Name(); } return DropDown_arr($strName,$arList,$iDefault,$iChoose); } } /*==== CLASS: Item Type (singular) */ class clsItTyp extends clsDataSet_bare { /*---- HISTORY: 2011-02-02 removed the IsNew() check because sometimes we want to use this on data which has not been associated with an ID */ public function Name($iCount=NULL) { if (is_null($iCount)) { if (isset($this->Row['cntInPrint'])) { $iCount = $this->Row['cntInPrint']; } else { $iCount = 1; // default: use singular } } if ($iCount == 1) { $out = array_key_exists('NameSng',$this->Row)?$this->Row['NameSng']:NULL; } else { $out = array_key_exists('NamePlr',$this->Row)?$this->Row['NamePlr']:NULL; } return $out; } /*---- ACTION: Shows a drop-down selection box contining the rows in the current dataset FUTURE: * This method really belongs with Admin functions, since it will never be used in the standalone store */ public function DropDown_for_rows($iName=NULL,$iDefault=NULL,$iChoose=NULL) { $strName = is_null($iName)?($this->Table->ActionKey()):$iName; if ($this->HasRows()) { $out = ''; } else { $out = 'No item types found.'; } return $out; } } /* -------------------- *\ ITEM OPTION classes \* -------------------- */ class clsItOpts extends clsVbzTable { public function __construct($iDB) { parent::__construct($iDB); $this->Name('cat_ioptns'); $this->KeyName('ID'); $this->ClassSng('clsItOpt'); } // ==BOILERPLATE - cache protected $objCache; protected function Cache() { if (!isset($this->objCache)) { $this->objCache = new clsCache_Table($this); } return $this->objCache; } public function GetItem_Cached($iID=NULL,$iClass=NULL) { return $this->Cache()->GetItem($iID,$iClass); } // ==/BOILERPLATE /*---- FUTURE: * This method really belongs with Admin functions, since it will never be used in the standalone store * If table ever grows to a significant size, we might end up changing the filtering criteron. * Actually, this should be a boilerplate function with a helper class. The only change from clsItTyps is the GetData filter and sorting. HISTORY: 2010-11-21 Adapted from clsItTyps */ public function DropDown($iName=NULL,$iDefault=NULL,$iChoose=NULL) { $strName = is_null($iName)?($this->Table->ActionKey()):$iName; $arRows = $this->Cache()->GetData_array(NULL,NULL,'Sort'); $out = $this->DropDown_for_array($arRows,$strName,$iDefault,$iChoose); return $out; } /*---- ACTION: same as clsItTyp::DropDown_for_rows, but takes an array HISTORY: 2011-02-11 wrote */ public function DropDown_for_array(array $iRows,$iName=NULL,$iDefault=NULL,$iChoose=NULL) { $strName = is_null($iName)?($this->Table->ActionKey()):$iName; $objRow = $this->SpawnItem(); foreach($iRows as $key => $row) { $objRow->Values($row); $arList[$key] = $objRow->ChoiceLine(); } return DropDown_arr($strName,$arList,$iDefault,$iChoose); } } class clsItOpt extends clsDataSet { /*---- RETURNS: Approximately as much description as will fit nicely into a choice line for a drop-down or selection box */ public function ChoiceLine() { return $this->Value('CatKey'); } } /* -------------------- *\ SHIP COST classes \* -------------------- */ class clsShipCosts extends clsVbzTable { public function __construct($iDB) { parent::__construct($iDB); $this->Name('cat_ship_cost'); $this->KeyName('ID'); $this->ClassSng('clsShipCost'); } // ==BOILERPLATE - cache protected $objCache; protected function Cache() { if (!isset($this->objCache)) { $this->objCache = new clsCache_Table($this); } return $this->objCache; } public function GetItem_Cached($iID=NULL,$iClass=NULL) { return $this->Cache()->GetItem($iID,$iClass); } // ==/BOILERPLATE /*---- FUTURE: * This method really belongs with Admin functions, since it will never be used in the standalone store * If table ever grows to a significant size, we might end up changing the filtering criteron. * Actually, this should be a boilerplate function with a helper class. The only change from clsItTyps is the GetData filter and sorting. HISTORY: 2010-11-21 Adapted from clsItTyps */ public function DropDown($iName=NULL,$iDefault=NULL,$iChoose=NULL) { $strName = is_null($iName)?($this->Table->ActionKey()):$iName; $arRows = $this->Cache()->GetData_array(NULL,NULL,'Sort'); $out = $this->DropDown_for_array($arRows,$strName,$iDefault,$iChoose); return $out; } /*---- ACTION: same as clsItTyp::DropDown_for_rows, but takes an array HISTORY: 2011-02-11 wrote */ public function DropDown_for_array(array $iRows,$iName=NULL,$iDefault=NULL,$iChoose=NULL) { $strName = is_null($iName)?($this->Table->ActionKey()):$iName; $objRow = $this->SpawnItem(); foreach($iRows as $key => $row) { $objRow->Values($row); $arList[$key] = $objRow->ChoiceLine(); } return DropDown_arr($strName,$arList,$iDefault,$iChoose); } } class clsShipCost extends clsDataSet { /*---- RETURNS: Approximately as much description as will fit nicely into a choice line for a drop-down or selection box */ public function ChoiceLine() { return $this->Value('Descr'); } } /* -------------------- *\ STOCK ITEM classes \* -------------------- */ /*==== CLASS PAIR: Items_Stock PURPOSE: items with stock information (from a query or cache) Similar to clsItem, but with different fields HISTORY: 2011-01-24 disabled -- use cat_items (has all necessary fields cached) */ /* class clsItems_Stock extends clsItems { public function __construct($iDB) { parent::__construct($iDB); $this->Name('qryCat_Items_Stock'); //$this->Name('_title_ittyps'); // WRONG! This GROUPS the data, no Items. $this->KeyName('ID'); $this->ClassSng('clsItem_Stock'); } public function Render_TableHdr() { return '' .'Option' .'Status' .'Price' .'Order
Qty.' .'list
price' .''; } } */ //class clsItem_Stock extends clsItem { /*----- ASSUMES: This item is ForSale, so isForSale = true and (qtyForSale>0 || isInPrint) = true This item's data was generated by clsItems_Stock TO DO: create a separate clsItem_Stock class and move this method there. TO DO: this method isn't named or structured canonically; consider refactoring. Whatever that means. HISTORY: 2011-01-24 moved from clsItem to clsItem_Stock */ /* public function Render_TableRow() { $arStat = $this->AvailStatus(); $strCls = $arStat['cls']; $out = ''; $out .= ' '.$this->ItOpt_Descr.''; $out .= ''.$arStat['html'].''; $out .= ''.DataCurr($this->PriceSell).''; $out .= ''.''; if ($this->PriceList) { $out .= ''.DataCurr($this->PriceList).''; } $out .= ''; return $out; } */ /*---- ACTION: Returns an array with human-friendly text about the item's availability status RETURNS: array['html']: status text, in HTML format array['cls']: class to use for displaying item row in a table USED BY: Print_TableRow() NOTE: This probably does not actually need to be a separate method; I thought I could reuse it to generate status for titles, but that doesn't make sense. Maybe it will be easier to adapt, though, as a separate method. HISTORY: 2010-11-16 Modified truth table for in-print status so that if isInPrint=FALSE, then status always shows "out of print" even if isCurrent=FALSE. What happens when a supplier has been discontinued? Maybe we need to check that separately. Wait for an example to come up, for easier debugging. 2011-01-24 Adapted from clsItem (was it being used there, for real?) to clsItem_Stock */ /* private function AvailStatus() { //echo 'SQL=['.$this->sqlMake.']'; //echo '
'.print_r($this->Row,TRUE).'
'; $qtyInStock = $this->Value('qtyForSale'); if ($qtyInStock) { $strCls = 'inStock'; $strStk = $qtyInStock.' in stock'; } else { $strCls = 'noStock'; $strStk = 'none in stock'; } if ($this->Value('isInPrint')) { if ($this->Value('isCurrent')) { if ($qtyInStock) { $txt = $strStk.'; more available'; } else { $txt = 'available, not in stock'; } } else { if ($qtyInStock) { $txt = $strStk.'; in-print status uncertain'; } else { $txt = $strStk.'; availability uncertain'; } } } else { $txt = ''.$strStk.' - out of print!'; } $arOut['html'] = $txt; $arOut['cls'] = $strCls; return $arOut; } } */ class clsStkItems extends clsVbzTable { public function __construct($iDB) { parent::__construct($iDB); $this->Name('stk_items'); $this->KeyName('ID'); } /*----- RETURNS: Recordset containing list of stock for the given item (qtys, bin, bin name, place, place name, notes) */ public function List_forItem($iItemID) { $sql = 'SELECT ' .'ID, QtyForSale, QtyForShip, QtyExisting, ID_Bin, ID_Place, BinCode, WhName, Notes ' .'FROM qryStk_lines_remaining WHERE (ID_Item='.$iItemID.');'; $objStock = $this->objDB->DataSet($sql,$this->ClassSng()); $objStock->Table = $this; return $objStock; } /* (2010-06-15) This doesn't seem to be used anywhere, and possibly does not work. public function QtyInStock_forItem($iItemID) { $sql = 'SELECT SUM(s.Qty) AS Qty FROM stk_items AS s LEFT JOIN stk_bins AS sb ON s.ID_Bin=sb.ID WHERE (s.ID_Item='.$iItemID.') AND (s.WhenRemoved IS NULL) AND (sb.WhenVoided IS NULL) AND (sb.isForSale) GROUP BY s.ID_Item'; $objStock = new clsDataItem($this); $objStock->Query($sql); if ($objStock->NextRow()) { assert('is_resource($objStock->Res)'); if ($objStock->RowCount()) { assert('$objStock->RowCount() == 1'); return $objStock->Qty; } } else { return NULL; } } */ } /* -------------------- *\ IMAGE classes \* -------------------- */ class clsVbzFolders extends clsVbzTable { public function __construct($iDB) { parent::__construct($iDB); $this->Name('cat_folders'); $this->KeyName('ID'); $this->ClassSng('clsVbzFolder'); } /*---- FUTURE: * This method really belongs with Admin functions, since it will never be used in the standalone store * If table ever grows to a significant size, we might end up changing the filtering criteron. */ public function DropDown($iName,$iDefault=NULL) { $dsRows = $this->GetData('Descr IS NOT NULL'); return $dsRows->DropDown_for_rows($iName,$iDefault); } /*---- PURPOSE: Finds the folder record which matches as much of the given URL as possible RETURNS: object for that folder, or NULL if no match found ASSUMES: folder list is not empty TO DO: does not yet handle adding new folders does not recursively check subfolders for improved match HISTORY: 2011-01-30 created -- subfolders not implemented yet because no data to test with */ public function FindBest($iURL) { if (strlen($iURL) > 0) { $slURL = strlen($iURL); $rs = $this->GetData('ID_Parent IS NULL'); // start with root folders $arrBest = NULL; $slBest = 0; while ($rs->NextRow()) { $fp = $rs->Value('PathPart'); $pos = strpos($iURL,$fp); // does the folder appear in the URL? if ($pos === 0) { $slFldr = strlen($fp); if ($slFldr > $slBest) { $arrBest = $rs->Values(); $slBest = $slFldr; } } } if (is_array($arrBest)) { $rsFldr = $this->SpawnItem(); $rsFldr->Values($arrBest); return $rsFldr; } } return NULL; } } class clsVbzFolder extends clsDataSet { public function Spec() { $out = ''; if (!is_null($this->ID_Parent)) { $out = $this->ParentObj()->Spec(); } $out .= $this->PathPart; return $out; } protected function ParentObj() { return $this->Table->GetItem($this->ID_Parent); } /*---- ACTION: Shows a drop-down selection box contining the rows in the current dataset FUTURE: * This method really belongs with Admin functions, since it will never be used in the standalone store */ public function DropDown_for_rows($iName,$iDefault=NULL) { if ($this->HasRows()) { $out = ''; } else { $out = 'No shipments matching filter'; } return $out; } /*---- RETURNS: The rest of the URL after this folder's PathPart is removed from the beginning USED BY: bulk image entry admin routine */ public function Remainder($iSpec) { $fsFldr = $this->Value('PathPart'); $slFldr = strlen($fsFldr); $fsRest = substr($iSpec,$slFldr); return $fsRest; } } class clsImages extends clsVbzTable { public function __construct($iDB) { parent::__construct($iDB); $this->Name('cat_images'); $this->KeyName('ID'); $this->ClassSng('clsImage'); } public function Update(array $iSet,$iWhere) { $iSet['WhenEdited'] = 'NOW()'; parent::Update($iSet,$iWhere); $this->Touch(__METHOD__.' WHERE='.$iWhere); } public function Insert(array $iData) { $iData['WhenAdded'] = 'NOW()'; parent::Insert($iData); $this->Touch(__METHOD__); } public function Thumbnails($iTitle,array $iarAttr=NULL) { $sqlFilt = '(ID_Title='.$iTitle.') AND (Ab_Size="th") AND isActive'; $objTbl = $this->objDB->Images(); $objRows = $objTbl->GetData($sqlFilt,NULL,'AttrSort'); return $objRows->Images_HTML($iarAttr); } } class clsImage extends clsVbzRecs { // object cache protected $objTitle; /*---- HISTORY: 2010-11-16 Modified to use new cat_folders data via ID_Folder */ public function WebSpec() { //return KWP_IMG_MERCH.$this->Spec; return $this->FolderPath().$this->Spec; } /*---- HISTORY: 2010-11-16 Created */ public function FolderObj() { return $this->objDB->Folders()->GetItem($this->ID_Folder); } /*---- HISTORY: 2010-11-16 Created */ public function FolderPath() { return $this->FolderObj()->Spec(); } /*----- ACTION: Generate the HTML code to display all images in the current dataset */ public function Images_HTML(array $iarAttr=NULL) { if ($this->HasRows()) { $out = ''; while ($this->NextRow()) { $out .= $this->Image_HTML($iarAttr); } return $out; } else { return NULL; } } /*----- ACTION: Generate the HTML code to display an image for the current row */ public function Image_HTML(array $iarAttr=NULL) { $htDispl = $this->AttrDispl; if (!empty($htDispl)) { nzApp($iarAttr['title'],' - '.$htDispl); } $iarAttr['src'] = $this->WebSpec(); $htAttr = ArrayToAttrs($iarAttr); return ''; } /*----- ACTION: Get the image with the same title and attribute but with the given size */ public function ImgForSize($iSize) { if ($this->AttrFldr) { $sqlAttr = '="'.$this->AttrFldr.'"'; } else { $sqlAttr = ' IS NULL'; } $sqlFilt = '(ID_Title='.$this->ID_Title.') AND (AttrFldr'.$sqlAttr.') AND (Ab_Size="'.$iSize.'")'; $objImgOut = $this->objDB->Images()->GetData($sqlFilt); return $objImgOut; } public function Title() { if (!is_object($this->objTitle)) { $this->objTitle = $this->objDB->Titles()->GetItem($this->ID_Title); } return $this->objTitle; } /*----- ACTION: outputs a standalone page for larger image sizes - does not use skin */ public function DoPage() { global $vbgImgSize; $objTitle = $this->Title(); $strCatNum = $objTitle->CatNum(); $strTitle = $objTitle->Name; $htTitleHref = $objTitle->Link(); $htmlTitle = KS_STORE_NAME.' - '.$strCatNum.' “'.$strTitle.'”'; echo ''.$htmlTitle.''; echo "\n'; echo '
'; echo ''.$htTitleHref.$strTitle.'
'.$strCatNum.' - title ID #'.$this->ID_Title.''; // show list of available image sizes (except th and sm) $objImgs = $this->ListImages_sameAttr(); $strSizes = NULL; if ($objImgs->hasRows()) { $strImgCount = 0; while ($objImgs->NextRow()) { $strImgType = $objImgs->Ab_Size; if (!empty($strImgType)) { if (($strImgType != 'th') && ($strImgType != 'sm')) { $strImgCount++; $strDesc = $vbgImgSize[$strImgType]; if ($objImgs->ID == $this->ID) { $strImgTag = ''.$strDesc.''; } else { $strImgTag = $objImgs->Href(TRUE).$strDesc.''; } if (!empty($strSizes)) { $strSizes .= ' .. '; } $strSizes .= $strImgTag; } } } if ($strImgCount > 1) { $ftSizes = '' .'sizes :' .''.$strSizes.'' .': sizes' .''; } else { $ftSizes = NULL; } } // show list of available images for this title at this size $strAttrs = NULL; $objImgs = $this->ListImages_sameSize(); //echo 'test'; if ($objImgs->NextRow()) { $intImgs = 0; if ($objImgs->hasRows()) { $idx = 0; while ($objImgs->NextRow()) { $idx++; $strImgFldr = $objImgs->AttrFldr; $strImgDescr = $objImgs->AttrDispl.'('.$idx.')'; $intImgs++; if (!empty($out)) { $strAttrs .= ' .. '; } if ($objImgs->ID == $this->ID) { $strAttrs .= ''.$strImgDescr.''; } else { $strAttrs .= $objImgs->Href(TRUE).$strImgDescr.''; } } if ($intImgs > 1) { $ftAttrs = '' .'views :' .''.$strAttrs.'' .': views' .''; } else { $ftAttrs = NULL; } } } if ((!empty($ftSizes)) || (!empty($ftAttrs))) { echo '
'; echo $ftSizes.$ftAttrs; echo '
'; } else { echo '
'; } echo $htTitleHref.'ordering page
'; echo $this->Image_HTML(); echo "\n\n";

   }
 public function ListImages_sameAttr() {
   $sqlFilt = 'isActive AND (ID_Title='.$this->ID_Title.')';
   if ($this->AttrFldr) {
     $sqlFilt .= ' AND (AttrFldr="'.$this->AttrFldr.'")';
   }
   $objImgOut = $this->objDB->Images()->GetData($sqlFilt);
   return $objImgOut;
 }
   public function ListImages_sameSize() {

$sqlFilt = 'isActive AND (ID_Title='.$this->ID_Title.') AND (Ab_Size="'.$this->Ab_Size.'")'; //echo 'SQL: '.$sqlFilt; $objImgOut = $this->objDB->Images()->GetData($sqlFilt); return $objImgOut;

   }
   public function Href($iAbs=false) {

$strFldrRel = $this->AttrFldr; if ($strFldrRel) { $strFldrRel .= '-'; } $strFldrRel .= $this->Ab_Size;

if ($iAbs) { $strFldr = $this->Title()->URL().'/'.$strFldrRel; } else { $strFldr = $strFldrRel; } return '<a href="'.$strFldr.'/">';

   }

}

/* ======================

GLOBAL VARIABLES CLASS
  • /

class clsGlobalVars extends clsTable {

   const TableName='var_global';
   private $strOld;
   public function __construct($iDB) {

parent::__construct($iDB); $this->Name(self::TableName); $this->KeyName('Name'); // $this->ClassSng('clsGlobalVar');

   }
   public function Exists($iName) {

$sqlFilt = 'Name="'.$iName.'"'; $objRow = $this->GetData($sqlFilt); if ($objRow->hasRows()) { $objRow->NextRow(); $this->strOld = $objRow->Value; return TRUE; } else { unset($this->strOld); return FALSE; }

   }
   private function GetVar($iName) {

if ($this->Exists($iName)) { return $this->strOld; } else { return NULL; }

   }
   private function SetVar($iName, $iValue) {

$strWhere = __METHOD__; // should return class::function $sqlVal = SQLValue($iValue); $sqlName = SQLValue($iName);

if ($this->Exists($iName)) { $this->objDB->LogEvent($strWhere, '|name='.$iName.'|old='.$this->strOld.'|new='.$sqlVal, 'global updated: '.$iName, 'VAR-U',FALSE,FALSE);

$arUpd = array( 'Value' => $sqlVal, 'WhenUpdated' => 'NOW()' ); $this->Update($arUpd,'Name='.$sqlName); } else { $this->objDB->LogEvent($strWhere, '|name='.$iName.'|val='.$sqlVal, 'global added: '.$iName, 'VAR-I',FALSE,FALSE); $arIns = array( 'Name' => $sqlName, 'Value' => $sqlVal, 'WhenCreated' => 'NOW()' ); $this->Insert($arIns); }

   }
   public function Val($iName,$iValue=NULL) {

if (is_null($iValue)) { return $this->GetVar($iName); } else { return $this->SetVar($iName,$iValue); }

   }

/*

   public function __set($iName, $iValue) {

$this->SetVar($iName,$iValue);

   }
   public function __get($iName) {

return $this->GetVar($iName);

   }
  • /

} /* ==================== *\

   UTILITY FUNCTIONS

\* ==================== */

function DataCents($iCents,$iPfx='$') {

 $out = $iPfx.sprintf("%01.2f",$iCents/100);
 return $out;

} function DataCurr($iCurr,$iPfx='$') {

   if (is_null($iCurr)) {

return NULL;

   } else {

$out = $iPfx.sprintf("%01.2f",$iCurr); return $out;

   }

} function DataDate($iDate) {

   if (is_string($iDate)) {
     $objDate = new DateTime($iDate);

// if ($iDate == 0) { // $out = ; // } else { // $out = date('Y-m-d',$iDate);

     $out = $objDate->format('Y-m-d');
   } else {
     $out = ;
   }
   return $out;

} function DataDateTime($iDate) {

   if (is_string($iDate)) {

if ($iDate == ) { $out = '-'; } else { $objDate = new DateTime($iDate); $out = $objDate->format('Y-m-d H:i'); }

   } else {
     $out = ;
   }
   return $out;

} function IsEmail($iAddr) {

   $ok = preg_match('/^[0-9,a-z,\-,\.]{1,}@([0-9,a-z,\-][\.]{0,1}){2,}$/i', $iAddr );
   return $ok;

} function ArrayToAttrs(array $iarAttr=NULL) {

   $htAttr = ;
   if (is_array($iarAttr)) {

foreach ($iarAttr as $key => $val) { $htAttr .= ' '.$key.'="'.$val.'"'; }

   }
   return $htAttr;

}

/* ==================== *\

   MISSING FUNCTIONS

\* ==================== */ if (!function_exists('http_redirect')) {

   function http_redirect($iURL) {

header('Status: 301 Moved Permanently',TRUE); header('Location: '.$iURL,TRUE);

   }

} </php>