2005-02-06 17:49:48 +00:00
|
|
|
<?php
|
|
|
|
|
/**********************************/
|
|
|
|
|
/* this class represents a vendor */
|
|
|
|
|
/**********************************/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Vendor class for handling vendors.
|
|
|
|
|
*/
|
|
|
|
|
class Vendor {
|
|
|
|
|
var $iVendorId;
|
|
|
|
|
var $sName;
|
|
|
|
|
var $sWebpage;
|
2007-04-23 23:32:30 +00:00
|
|
|
var $sQueued;
|
2005-02-06 17:49:48 +00:00
|
|
|
var $aApplicationsIds; // an array that contains the appId of every application linked to this vendor
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* constructor, fetches the data.
|
|
|
|
|
*/
|
2007-02-01 02:07:24 +00:00
|
|
|
function Vendor($iVendorId = null, $oRow = null)
|
2005-02-06 17:49:48 +00:00
|
|
|
{
|
|
|
|
|
// we are working on an existing vendor
|
2005-03-23 23:56:38 +00:00
|
|
|
if(is_numeric($iVendorId))
|
2005-02-06 17:49:48 +00:00
|
|
|
{
|
2007-02-01 02:07:24 +00:00
|
|
|
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)
|
2005-02-06 17:49:48 +00:00
|
|
|
{
|
2005-02-09 02:21:41 +00:00
|
|
|
$this->iVendorId = $iVendorId;
|
|
|
|
|
$this->sName = $oRow->vendorName;
|
|
|
|
|
$this->sWebpage = $oRow->vendorURL;
|
2007-04-23 23:32:30 +00:00
|
|
|
$this->sQueued = $oRow->queued;
|
2005-02-06 17:49:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We fetch applicationsIds.
|
|
|
|
|
*/
|
|
|
|
|
$sQuery = "SELECT appId
|
|
|
|
|
FROM appFamily
|
2006-06-27 19:16:27 +00:00
|
|
|
WHERE vendorId = '?'";
|
|
|
|
|
if($hResult = query_parameters($sQuery, $iVendorId))
|
2005-02-06 17:49:48 +00:00
|
|
|
{
|
|
|
|
|
while($oRow = mysql_fetch_object($hResult))
|
|
|
|
|
{
|
|
|
|
|
$this->aApplicationsIds[] = $oRow->appId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new vendor.
|
|
|
|
|
*/
|
2007-01-28 23:28:14 +00:00
|
|
|
function create()
|
2005-02-06 17:49:48 +00:00
|
|
|
{
|
2007-04-22 00:57:41 +00:00
|
|
|
$hResult = query_parameters("INSERT INTO vendor (vendorName, vendorURL, queued) ".
|
|
|
|
|
"VALUES ('?', '?', '?')",
|
|
|
|
|
$this->sName, $this->sWebpage,
|
|
|
|
|
$this->mustBeQueued() ? "true" : "false");
|
2006-06-24 04:20:32 +00:00
|
|
|
if($hResult)
|
2005-02-06 17:49:48 +00:00
|
|
|
{
|
|
|
|
|
$this->iVendorId = mysql_insert_id();
|
|
|
|
|
$this->vendor($this->iVendorId);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
2006-06-24 04:20:32 +00:00
|
|
|
{
|
|
|
|
|
addmsg("Error while creating a new vendor.", "red");
|
2005-02-06 17:49:48 +00:00
|
|
|
return false;
|
2006-06-24 04:20:32 +00:00
|
|
|
}
|
2005-02-06 17:49:48 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-22 00:57:41 +00:00
|
|
|
/**
|
|
|
|
|
* Un-queue vendor
|
|
|
|
|
* Returns TRUE or FALSE
|
|
|
|
|
*/
|
|
|
|
|
function unQueue()
|
|
|
|
|
{
|
|
|
|
|
if(!$this->canEdit())
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
$hResult = query_parameters("UPDATE vendor SET queued = '?' WHERE vendorId = '?'",
|
|
|
|
|
'false', $this->iVendorId);
|
|
|
|
|
|
|
|
|
|
if(!$hResult)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2005-02-06 17:49:48 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update vendor.
|
|
|
|
|
* Returns true on success and false on failure.
|
|
|
|
|
*/
|
2007-01-28 23:28:14 +00:00
|
|
|
function update()
|
2005-02-06 17:49:48 +00:00
|
|
|
{
|
2005-02-07 23:54:29 +00:00
|
|
|
if(!$this->iVendorId)
|
2007-01-28 23:28:14 +00:00
|
|
|
return $this->create();
|
2005-02-07 23:54:29 +00:00
|
|
|
|
2007-01-28 23:28:14 +00:00
|
|
|
if($this->sName)
|
2005-02-06 17:49:48 +00:00
|
|
|
{
|
2006-06-27 19:16:27 +00:00
|
|
|
if (!query_parameters("UPDATE vendor SET vendorName = '?' WHERE vendorId = '?'",
|
2007-01-28 23:28:14 +00:00
|
|
|
$this->sName, $this->iVendorId))
|
2005-02-06 17:49:48 +00:00
|
|
|
return false;
|
|
|
|
|
$this->sName = $sName;
|
2007-01-28 23:28:14 +00:00
|
|
|
}
|
2005-02-06 17:49:48 +00:00
|
|
|
|
2007-01-28 23:28:14 +00:00
|
|
|
if($this->sWebpage)
|
2005-02-06 17:49:48 +00:00
|
|
|
{
|
2006-06-27 19:16:27 +00:00
|
|
|
if (!query_parameters("UPDATE vendor SET vendorURL = '?' WHERE vendorId = '?'",
|
2007-01-28 23:28:14 +00:00
|
|
|
$this->sWebpage, $this->iVendorId))
|
2005-02-06 17:49:48 +00:00
|
|
|
return false;
|
|
|
|
|
$this->sWebpage = $sWebpage;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-01-28 23:28:14 +00:00
|
|
|
/**
|
2005-02-06 17:49:48 +00:00
|
|
|
* Deletes the vendor from the database.
|
|
|
|
|
*/
|
|
|
|
|
function delete($bSilent=false)
|
|
|
|
|
{
|
2005-02-07 23:54:29 +00:00
|
|
|
if(sizeof($this->aApplicationsIds)>0)
|
|
|
|
|
{
|
|
|
|
|
addmsg("The vendor has not been deleted because there are still applications linked to it.", "red");
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
$sQuery = "DELETE FROM vendor
|
2006-06-27 19:16:27 +00:00
|
|
|
WHERE vendorId = '?'
|
2005-02-07 23:54:29 +00:00
|
|
|
LIMIT 1";
|
2007-01-28 23:28:14 +00:00
|
|
|
if(query_parameters($sQuery, $this->iVendorId))
|
|
|
|
|
{
|
|
|
|
|
addmsg("The vendor has been deleted.", "green");
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
2005-02-07 23:54:29 +00:00
|
|
|
}
|
2005-02-06 17:49:48 +00:00
|
|
|
}
|
2005-10-25 00:47:32 +00:00
|
|
|
|
2007-01-17 03:18:49 +00:00
|
|
|
function outputEditor()
|
2005-10-25 00:47:32 +00:00
|
|
|
{
|
|
|
|
|
echo "<table width='100%' border=0 cellpadding=2 cellspacing=0>\n";
|
|
|
|
|
|
|
|
|
|
// Name
|
2007-05-02 01:08:22 +00:00
|
|
|
echo html_tr(array(
|
|
|
|
|
array("<b>Vendor Name:</b>", 'align=right class="color0"'),
|
|
|
|
|
array('<input type=text name="sVendorName" value="'.$this->sName.'" size="60">', 'class="color0"')
|
|
|
|
|
));
|
2005-10-25 00:47:32 +00:00
|
|
|
// Url
|
2007-05-02 01:08:22 +00:00
|
|
|
echo html_tr(array(
|
|
|
|
|
array("<b>Vendor URL:</b>", 'align=right class="color0"'),
|
|
|
|
|
array('<input type=text name="sVendorWebpage" value="'.$this->sWebpage.'" size="60">', 'class="color0"')
|
|
|
|
|
));
|
2005-10-25 00:47:32 +00:00
|
|
|
|
|
|
|
|
echo '<input type="hidden" name="iVendorId" value="'.$this->iVendorId.'">',"\n";
|
|
|
|
|
|
|
|
|
|
echo "</table>\n";
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-24 18:30:16 +00:00
|
|
|
function objectGetEntries($bQueued, $bRejected, $iRows = 0, $iStart = 0)
|
2007-01-31 02:24:54 +00:00
|
|
|
{
|
|
|
|
|
/* Vendor queueing is not implemented yet */
|
|
|
|
|
if($bQueued)
|
2007-03-24 18:30:16 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* Not implemented */
|
|
|
|
|
if($bRejected)
|
|
|
|
|
return FALSE;
|
2007-01-31 02:24:54 +00:00
|
|
|
|
2007-02-01 02:07:24 +00:00
|
|
|
if(!$iRows)
|
2007-03-25 04:21:34 +00:00
|
|
|
$iRows = Vendor::objectGetEntriesCount($bQueued, $bRejected);
|
2007-02-01 02:07:24 +00:00
|
|
|
|
2007-01-31 02:24:54 +00:00
|
|
|
$hResult = query_parameters("SELECT * FROM vendor
|
2007-02-01 02:07:24 +00:00
|
|
|
ORDER BY vendorName LIMIT ?,?",
|
|
|
|
|
$iStart, $iRows);
|
2007-01-31 02:24:54 +00:00
|
|
|
|
|
|
|
|
if(!$hResult)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
return $hResult;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-17 21:04:43 +00:00
|
|
|
function objectGetHeader()
|
2007-01-31 02:24:54 +00:00
|
|
|
{
|
2007-03-17 21:04:43 +00:00
|
|
|
$aCells = array(
|
2007-01-31 02:24:54 +00:00
|
|
|
"Name",
|
|
|
|
|
"Website",
|
|
|
|
|
array("Linked apps", "align=\"right\""));
|
|
|
|
|
|
2007-03-17 21:04:43 +00:00
|
|
|
return $aCells;
|
2007-01-31 02:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
2007-02-01 02:07:24 +00:00
|
|
|
function objectGetInstanceFromRow($oRow)
|
|
|
|
|
{
|
|
|
|
|
return new vendor($oRow->vendorId, $oRow);
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-13 21:08:39 +00:00
|
|
|
/* arg1 = OM object, arg2 = CSS style, arg3 = text for edit link */
|
|
|
|
|
function objectOutputTableRow($oObject, $sClass = "", $sEditLinkLabel)
|
2007-02-01 02:07:24 +00:00
|
|
|
{
|
|
|
|
|
$aCells = array(
|
2007-02-03 19:03:42 +00:00
|
|
|
"<a href=\"".$oObject->makeUrl("view", $this->iVendorId,
|
|
|
|
|
"View Vendor")."\">$this->sName</a>",
|
2007-02-01 02:07:24 +00:00
|
|
|
"<a href=\"$this->sWebpage\">$this->sWebpage</a>",
|
|
|
|
|
array(sizeof($this->aApplicationsIds), "align=\"right\""));
|
|
|
|
|
|
|
|
|
|
if($this->canEdit())
|
|
|
|
|
{
|
|
|
|
|
if(!sizeof($this->aApplicationsIds))
|
2007-03-13 21:08:39 +00:00
|
|
|
$shDeleteLink = " [<a href=\"".$oObject->makeUrl("delete",
|
2007-02-03 19:03:42 +00:00
|
|
|
$this->iVendorId, "View Vendors")."\">".
|
2007-02-01 02:07:24 +00:00
|
|
|
"delete</a>]";
|
|
|
|
|
|
2007-02-03 19:03:42 +00:00
|
|
|
$aCells[sizeof($aCells)] = "[<a href=\"".$oObject->makeUrl("edit",
|
2007-03-13 21:08:39 +00:00
|
|
|
$this->iVendorId, "Edit Vendor")."\">$sEditLinkLabel</a>]$shDeleteLink";
|
2007-02-01 02:07:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo html_tr($aCells, $sClass);
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-28 23:28:14 +00:00
|
|
|
function canEdit()
|
|
|
|
|
{
|
|
|
|
|
if($_SESSION['current']->hasPriv("admin"))
|
|
|
|
|
return TRUE;
|
|
|
|
|
else
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-22 00:39:53 +00:00
|
|
|
function mustBeQueued()
|
|
|
|
|
{
|
|
|
|
|
if($_SESSION['current']->hasPriv("admin"))
|
|
|
|
|
return FALSE;
|
|
|
|
|
else
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-31 02:16:54 +00:00
|
|
|
function getOutputEditorValues($aClean)
|
2007-01-28 23:28:14 +00:00
|
|
|
{
|
|
|
|
|
$this->sName = $aClean['sVendorName'];
|
|
|
|
|
$this->sWebpage = $aClean['sVendorWebpage'];
|
|
|
|
|
}
|
2007-01-31 02:16:54 +00:00
|
|
|
|
|
|
|
|
function display()
|
|
|
|
|
{
|
|
|
|
|
echo 'Vendor Name: '.$this->sName,"\n";
|
|
|
|
|
if($this->canEdit())
|
|
|
|
|
{
|
2007-02-03 19:03:42 +00:00
|
|
|
echo "[<a href=\"".$_SERVER['PHP_SELF']."?sClass=vendor&sAction=edit&".
|
|
|
|
|
"iId=$this->iVendorId&sTitle=Edit%20Vendor\">edit</a>]";
|
2007-01-31 02:16:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo '<br />',"\n";
|
|
|
|
|
if ($this->sWebpage)
|
|
|
|
|
echo 'Vendor URL: <a href="'.$this->sWebpage.'">'.
|
|
|
|
|
$this->sWebpage.'</a> <br />',"\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($this->aApplicationsIds)
|
|
|
|
|
{
|
|
|
|
|
echo '<br />Applications by '.$this->sName.'<br /><ol>',"\n";
|
|
|
|
|
foreach($this->aApplicationsIds as $iAppId)
|
|
|
|
|
{
|
|
|
|
|
$oApp = new Application($iAppId);
|
2007-04-01 01:21:58 +00:00
|
|
|
echo '<li>'.$oApp->objectMakeLink().'</li>',"\n";
|
2007-01-31 02:16:54 +00:00
|
|
|
}
|
|
|
|
|
echo '</ol>',"\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-03-13 20:59:45 +00:00
|
|
|
|
|
|
|
|
/* Make a URL for viewing the specified vendor */
|
|
|
|
|
function objectMakeUrl()
|
|
|
|
|
{
|
|
|
|
|
$oManager = new objectManager("vendor", "View Vendor");
|
|
|
|
|
return $oManager->makeUrl("view", $this->iVendorId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Make a HTML link for viewing the specified vendor */
|
|
|
|
|
function objectMakeLink()
|
|
|
|
|
{
|
|
|
|
|
return "<a href=\"".$this->objectMakeUrl()."\">$this->sName</a>";
|
|
|
|
|
}
|
2005-10-25 00:47:32 +00:00
|
|
|
|
2007-03-25 03:59:58 +00:00
|
|
|
function objectGetEntriesCount($bQueued, $bRejected)
|
2005-10-25 00:47:32 +00:00
|
|
|
{
|
2007-03-25 03:59:58 +00:00
|
|
|
/* Not implemented */
|
|
|
|
|
if($bQueued)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* Not implemented */
|
|
|
|
|
if($bRejected)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
$hResult = query_parameters("SELECT COUNT(vendorId) as count FROM vendor");
|
|
|
|
|
|
|
|
|
|
if(!$hResult)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if(!$oRow = mysql_fetch_object($hResult))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
return $oRow->count;
|
2005-10-25 00:47:32 +00:00
|
|
|
}
|
2007-04-29 23:00:01 +00:00
|
|
|
|
|
|
|
|
function allowAnonymousSubmissions()
|
|
|
|
|
{
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2005-02-06 17:49:48 +00:00
|
|
|
}
|
2007-03-25 03:59:58 +00:00
|
|
|
|
2005-02-06 17:49:48 +00:00
|
|
|
?>
|