diff --git a/include/vendor.php b/include/vendor.php index 486ae75..8aa5aae 100644 --- a/include/vendor.php +++ b/include/vendor.php @@ -15,20 +15,25 @@ class Vendor { /** * constructor, fetches the data. */ - function Vendor($iVendorId = null) + function Vendor($iVendorId = null, $oRow = null) { // we are working on an existing vendor if(is_numeric($iVendorId)) { - /* - * We fetch the data related to this vendor. - */ - $sQuery = "SELECT * - FROM vendor - WHERE vendorId = '?'"; - if($hResult = query_parameters($sQuery, $iVendorId)) + if(!$oRow) + { + /* + * We fetch the data related to this vendor. + */ + $sQuery = "SELECT * + FROM vendor + WHERE vendorId = '?'"; + if($hResult = query_parameters($sQuery, $iVendorId)) + $oRow = mysql_fetch_object($hResult); + } + + if($oRow) { - $oRow = mysql_fetch_object($hResult); $this->iVendorId = $iVendorId; $this->sName = $oRow->vendorName; $this->sWebpage = $oRow->vendorURL; @@ -140,14 +145,18 @@ class Vendor { echo "\n"; } - function objectGetEntries($bQueued) + function objectGetEntries($bQueued, $iRows = 0, $iStart = 0) { /* Vendor queueing is not implemented yet */ if($bQueued) return NULL; + if(!$iRows) + $iRows = getNumberOfVendors(); + $hResult = query_parameters("SELECT * FROM vendor - ORDER BY vendorName"); + ORDER BY vendorName LIMIT ?,?", + $iStart, $iRows); if(!$hResult) return FALSE; @@ -168,6 +177,33 @@ class Vendor { echo html_tr($sCells, $sClass); } + function objectGetInstanceFromRow($oRow) + { + return new vendor($oRow->vendorId, $oRow); + } + + function objectOutputTableRow($sClass = "") + { + $aCells = array( + "iVendorId\">". + "$this->sName", + "sWebpage\">$this->sWebpage", + array(sizeof($this->aApplicationsIds), "align=\"right\"")); + + if($this->canEdit()) + { + if(!sizeof($this->aApplicationsIds)) + $sDelete = " [iVendorId\">". + "delete]"; + + $aCells[sizeof($aCells)] = "[iVendorId\">edit]$sDelete"; + } + + echo html_tr($aCells, $sClass); + } + function canEdit() { if($_SESSION['current']->hasPriv("admin")) diff --git a/vendorview.php b/vendorview.php index 05a674d..0671801 100644 --- a/vendorview.php +++ b/vendorview.php @@ -52,25 +52,10 @@ else vendor::objectOutputHeader("color4"); - $c = 1; - while($oRow = mysql_fetch_object($hResult)) + for($c = 0; $oRow = mysql_fetch_object($hResult); $c++) { - if ($c % 2 == 1) { $bgcolor = 'color0'; } else { $bgcolor = 'color1'; } - $oVendor = new Vendor($oRow->vendorId); - echo '