iVendorId = $oRow->vendorId;
$this->sName = $oRow->vendorName;
$this->sWebpage = $oRow->vendorURL;
$this->sQueued = $oRow->queued;
}
/*
* We fetch applicationsIds.
*/
$sQuery = "SELECT appId
FROM appFamily
WHERE vendorId = '?'";
if($hResult = query_parameters($sQuery, $this->iVendorId))
{
while($oRow = query_fetch_object($hResult))
{
$this->aApplicationsIds[] = $oRow->appId;
}
}
}
/**
* Creates a new vendor.
*
* NOTE: If creating a vendor with the same name as an existing vendor
* we retrieve the existing vendors information and return true,
* even though we didn't create the vendor, this makes it easier
* for the user of the vendor class.
*/
function create()
{
/* Check for duplicates */
$hResult = query_parameters("SELECT * FROM vendor WHERE vendorName = '?'",
$this->sName);
if($hResult && $oRow = query_fetch_object($hResult))
{
if(query_num_rows($hResult))
{
$this->vendor($oRow->vendorId);
/* Even though we did not create a new vendor, the caller is provided
with an id and can proceed as normal, so we return TRUE */
return TRUE;
}
}
$hResult = query_parameters("INSERT INTO vendor (vendorName, vendorURL, queued) ".
"VALUES ('?', '?', '?')",
$this->sName, $this->sWebpage,
$this->mustBeQueued() ? "true" : "false");
if($hResult)
{
$this->iVendorId = query_appdb_insert_id();
$this->vendor($this->iVendorId);
return true;
}
else
{
addmsg("Error while creating a new vendor.", "red");
return false;
}
}
/**
* 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;
}
/**
* Update vendor.
* Returns true on success and false on failure.
*/
function update()
{
if(!$this->iVendorId)
return $this->create();
if($this->sName)
{
if (!query_parameters("UPDATE vendor SET vendorName = '?' WHERE vendorId = '?'",
$this->sName, $this->iVendorId))
return false;
$this->sName = $sName;
}
if($this->sWebpage)
{
if (!query_parameters("UPDATE vendor SET vendorURL = '?' WHERE vendorId = '?'",
$this->sWebpage, $this->iVendorId))
return false;
$this->sWebpage = $sWebpage;
}
return true;
}
/**
* Deletes the vendor from the database.
*/
function delete($bSilent=false)
{
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
WHERE vendorId = '?'
LIMIT 1";
if(query_parameters($sQuery, $this->iVendorId))
{
addmsg("The vendor has been deleted.", "green");
return TRUE;
}
return FALSE;
}
return false;
}
function outputEditor()
{
$oTable = new Table();
$oTable->SetWidth("100%");
$oTable->SetBorder(0);
$oTable->SetCellPadding(2);
$oTable->SetCellSpacing(0);
// name
$oTableRow = new TableRow();
$oTableCell = new TableCell("Vendor Name:");
$oTableCell->SetAlign("right");
$oTableCell->SetClass("color0");
$oTableCell->SetBold(true);
$oTableRow->AddCell($oTableCell);
$oTableCell = new TableCell('');
$oTableCell->SetClass("color0");
$oTableRow->AddCell($oTableCell);
$oTable->AddRow($oTableRow);
// Url
$oTableRow = new TableRow();
$oTableCell = new TableCell("Vendor URL:");
$oTableCell->SetAlign("right");
$oTableCell->SetClass("color0");
$oTableCell->SetBold(true);
$oTableRow->AddCell($oTableCell);
$oTableCell = new TableCell('');
$oTableCell->SetClass("color0");
$oTableRow->AddCell($oTableCell);
$oTable->AddRow($oTableRow);
echo $oTable->GetString();
echo '',"\n";
}
function objectGetEntries($bQueued, $bRejected, $iRows = 0, $iStart = 0)
{
/* Vendor queueing is not implemented yet */
if($bQueued)
return FALSE;
/* Not implemented */
if($bRejected)
return FALSE;
if(!$iRows)
$iRows = Vendor::objectGetEntriesCount($bQueued, $bRejected);
$hResult = query_parameters("SELECT * FROM vendor
ORDER BY vendorName LIMIT ?,?",
$iStart, $iRows);
if(!$hResult)
return FALSE;
return $hResult;
}
function objectGetHeader()
{
$oTableRow = new TableRow();
$oTableRow->AddTextCell("Name");
$oTableRow->AddTextCell("Website");
$oTableCell = new TableCell("Linked apps");
$oTableCell->SetAlign("right");
$oTableRow->AddCell($oTableCell);
return $oTableRow;
}
// returns an OMTableRow instance
function objectGetTableRow()
{
$bDeleteLink = sizeof($this->aApplicationsIds) ? FALSE : TRUE;
// create the html table row
$oTableRow = new TableRow();
$oTableRow->AddTextCell($this->objectMakeLink());
$oTableCell = new TableCell($this->sWebpage);
$oTableCell->SetCellLink($this->sWebpage);
$oTableRow->AddCell($oTableCell);
$oTableCell = new TableCell(sizeof($this->aApplicationsIds));
$oTableCell->SetAlign("right");
$oTableRow->AddCell($oTableCell);
// create the object manager specific row
$oOMTableRow = new OMTableRow($oTableRow);
$oOMTableRow->SetRowHasDeleteLink($bDeleteLink);
return $oOMTableRow;
}
function canEdit()
{
if($_SESSION['current']->hasPriv("admin"))
return TRUE;
else
return FALSE;
}
function mustBeQueued()
{
if($_SESSION['current']->hasPriv("admin"))
return FALSE;
else
return TRUE;
}
function getOutputEditorValues($aClean)
{
$this->sName = $aClean['sVendorName'];
$this->sWebpage = $aClean['sVendorWebpage'];
}
function display()
{
echo 'Vendor Name: '.$this->sName,"\n";
if($this->canEdit())
{
echo "[iVendorId&sTitle=Edit%20Vendor\">edit]";
}
echo '
',"\n";
if ($this->sWebpage)
{
echo 'Vendor URL: '.
$this->sWebpage.'
',"\n";
}
if($this->aApplicationsIds)
{
echo '
Applications by '.$this->sName.'