2004-12-12 03:51:51 +00:00
|
|
|
<?php
|
|
|
|
|
/***************************************************/
|
2004-03-15 16:22:00 +00:00
|
|
|
/* this class represents a category + its children */
|
2004-12-12 03:51:51 +00:00
|
|
|
/***************************************************/
|
|
|
|
|
|
2005-02-09 02:20:21 +00:00
|
|
|
/**
|
|
|
|
|
* Category class for handling categories.
|
|
|
|
|
*/
|
2004-03-15 16:22:00 +00:00
|
|
|
class Category {
|
2005-02-09 02:20:21 +00:00
|
|
|
var $iCatId;
|
|
|
|
|
var $iParentId;
|
|
|
|
|
var $sName;
|
|
|
|
|
var $sDescription;
|
|
|
|
|
var $aApplicationsIds; // an array that contains the appId of every application linked to this category
|
|
|
|
|
var $aSubcatsIds; // an array that contains the appId of every application linked to this category
|
2004-03-15 16:22:00 +00:00
|
|
|
|
|
|
|
|
|
2005-02-06 17:49:48 +00:00
|
|
|
/**
|
2005-02-09 02:20:21 +00:00
|
|
|
* constructor, fetches the data.
|
2005-02-06 17:49:48 +00:00
|
|
|
*/
|
2005-02-09 02:20:21 +00:00
|
|
|
function Category($iCatId = null)
|
2005-02-06 17:49:48 +00:00
|
|
|
{
|
2006-07-07 16:24:33 +00:00
|
|
|
// we are working on an existing category
|
2005-02-09 02:20:21 +00:00
|
|
|
if($iCatId=="0" || $iCatId)
|
2005-02-06 17:49:48 +00:00
|
|
|
{
|
2005-02-09 02:20:21 +00:00
|
|
|
/*
|
|
|
|
|
* We fetch the data related to this vendor.
|
|
|
|
|
*/
|
|
|
|
|
$sQuery = "SELECT *
|
|
|
|
|
FROM appCategory
|
2006-06-27 19:16:27 +00:00
|
|
|
WHERE catId = '?' ORDER BY catName;";
|
|
|
|
|
if($hResult = query_parameters($sQuery, $iCatId))
|
2005-02-06 17:49:48 +00:00
|
|
|
{
|
2007-08-03 23:27:25 +00:00
|
|
|
$oRow = query_fetch_object($hResult);
|
2006-11-25 17:24:44 +00:00
|
|
|
if($oRow)
|
|
|
|
|
{
|
|
|
|
|
$this->iCatId = $iCatId;
|
|
|
|
|
$this->iParentId = $oRow->catParent;
|
|
|
|
|
$this->sName = $oRow->catName;
|
|
|
|
|
$this->sDescription = $oRow->catDescription;
|
|
|
|
|
}
|
2005-02-09 02:20:21 +00:00
|
|
|
}
|
2004-12-12 03:51:51 +00:00
|
|
|
|
2005-02-09 02:20:21 +00:00
|
|
|
/*
|
|
|
|
|
* We fetch applicationsIds.
|
|
|
|
|
*/
|
|
|
|
|
$sQuery = "SELECT appId
|
|
|
|
|
FROM appFamily
|
2006-06-27 19:16:27 +00:00
|
|
|
WHERE catId = '?'
|
2007-12-12 22:25:01 +01:00
|
|
|
AND state = 'accepted' ORDER BY appName";
|
2006-06-27 19:16:27 +00:00
|
|
|
if($hResult = query_parameters($sQuery, $iCatId))
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
2007-08-03 23:27:25 +00:00
|
|
|
while($oRow = query_fetch_object($hResult))
|
2005-02-09 02:20:21 +00:00
|
|
|
{
|
|
|
|
|
$this->aApplicationsIds[] = $oRow->appId;
|
|
|
|
|
}
|
2004-12-12 03:51:51 +00:00
|
|
|
}
|
|
|
|
|
|
2005-02-09 02:20:21 +00:00
|
|
|
/*
|
|
|
|
|
* We fetch subcatIds.
|
|
|
|
|
*/
|
|
|
|
|
$sQuery = "SELECT catId
|
|
|
|
|
FROM appCategory
|
2006-06-27 19:16:27 +00:00
|
|
|
WHERE catParent = '?' ORDER BY catName;";
|
|
|
|
|
if($hResult = query_parameters($sQuery, $iCatId))
|
2005-02-09 02:20:21 +00:00
|
|
|
{
|
2007-08-03 23:27:25 +00:00
|
|
|
while($oRow = query_fetch_object($hResult))
|
2005-02-09 02:20:21 +00:00
|
|
|
{
|
|
|
|
|
$this->aSubcatsIds[] = $oRow->catId;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-12-12 03:51:51 +00:00
|
|
|
}
|
2005-02-09 02:20:21 +00:00
|
|
|
}
|
2004-12-12 03:51:51 +00:00
|
|
|
|
|
|
|
|
|
2005-02-09 02:20:21 +00:00
|
|
|
/**
|
|
|
|
|
* Creates a new category.
|
|
|
|
|
*/
|
2007-11-24 02:16:28 +01:00
|
|
|
function create()
|
2005-02-09 02:20:21 +00:00
|
|
|
{
|
2006-06-24 04:20:32 +00:00
|
|
|
$hResult = query_parameters("INSERT INTO appCategory (catName, catDescription, catParent) ".
|
|
|
|
|
"VALUES('?', '?', '?')",
|
2007-11-24 02:16:28 +01:00
|
|
|
$this->sName, $this->sDescription, $this->iParentId);
|
2006-06-24 04:20:32 +00:00
|
|
|
if($hResult)
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
2007-08-03 23:27:25 +00:00
|
|
|
$this->iCatId = query_appdb_insert_id();
|
2005-02-09 02:20:21 +00:00
|
|
|
$this->category($this->iCatId);
|
|
|
|
|
return true;
|
2004-12-12 03:51:51 +00:00
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
|
2007-11-24 02:16:28 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
/**
|
2005-02-09 02:20:21 +00:00
|
|
|
* Update category.
|
|
|
|
|
* Returns true on success and false on failure.
|
2004-03-15 16:22:00 +00:00
|
|
|
*/
|
2007-11-24 02:16:28 +01:00
|
|
|
function update()
|
2004-03-15 16:22:00 +00:00
|
|
|
{
|
2007-11-24 02:16:28 +01:00
|
|
|
if(!query_parameters("UPDATE appCategory SET catName = '?', catDescription = '?', catParent = '?' WHERE catId = '?'",
|
|
|
|
|
$this->sName, $this->sDescription, $this->iParentId, $this->iCatId))
|
|
|
|
|
return false;
|
2005-02-09 02:20:21 +00:00
|
|
|
|
|
|
|
|
return true;
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-09 02:20:21 +00:00
|
|
|
/**
|
|
|
|
|
* Deletes the category from the database.
|
2004-03-15 16:22:00 +00:00
|
|
|
*/
|
2007-11-24 02:16:28 +01:00
|
|
|
function delete()
|
2004-03-15 16:22:00 +00:00
|
|
|
{
|
2007-11-24 02:16:28 +01:00
|
|
|
if(!$this->canEdit())
|
2005-10-26 02:09:49 +00:00
|
|
|
return false;
|
|
|
|
|
|
2005-02-09 02:20:21 +00:00
|
|
|
if(sizeof($this->aApplicationsIds)>0)
|
2007-11-24 02:16:28 +01:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
$sQuery = "DELETE FROM appCategory
|
|
|
|
|
WHERE catId = '?'
|
|
|
|
|
LIMIT 1";
|
|
|
|
|
query_parameters($sQuery, $this->iCatId);
|
2005-10-26 02:09:49 +00:00
|
|
|
|
|
|
|
|
return true;
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
2007-11-24 02:16:28 +01:00
|
|
|
function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction)
|
|
|
|
|
{
|
|
|
|
|
return new mailOptions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function objectGetChildren()
|
|
|
|
|
{
|
|
|
|
|
/* We don't have any (or we do, sort of, but we don't use them for anything at the moment) */
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function objectGetMail($sAction, $bMailSubmitter, $bParentAction)
|
|
|
|
|
{
|
|
|
|
|
/* We don't send notification mails */
|
|
|
|
|
return array(null, null, null);
|
|
|
|
|
}
|
2005-02-09 02:20:21 +00:00
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
/**
|
2004-03-15 16:22:00 +00:00
|
|
|
* returns a path like:
|
|
|
|
|
*
|
|
|
|
|
* { ROOT, Games, Simulation }
|
|
|
|
|
*/
|
|
|
|
|
function getCategoryPath()
|
|
|
|
|
{
|
2006-06-30 16:33:02 +00:00
|
|
|
$aPath = array();
|
2005-02-09 02:20:21 +00:00
|
|
|
$iCatId = $this->iCatId;
|
2006-07-11 18:53:06 +00:00
|
|
|
|
|
|
|
|
/* loop, working up through categories until we have no parent */
|
2005-02-09 02:20:21 +00:00
|
|
|
while($iCatId != 0)
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
2006-06-30 16:33:02 +00:00
|
|
|
$hResult = query_parameters("SELECT catName, catId, catParent FROM appCategory WHERE catId = '?'",
|
2006-06-27 19:16:27 +00:00
|
|
|
$iCatId);
|
2007-08-03 23:27:25 +00:00
|
|
|
if(!$hResult || query_num_rows($hResult) != 1)
|
2004-12-12 03:51:51 +00:00
|
|
|
break;
|
2007-08-03 23:27:25 +00:00
|
|
|
$oCatRow = query_fetch_object($hResult);
|
2006-06-30 16:33:02 +00:00
|
|
|
$aPath[] = array($oCatRow->catId, $oCatRow->catName);
|
|
|
|
|
$iCatId = $oCatRow->catParent;
|
2004-12-12 03:51:51 +00:00
|
|
|
}
|
2006-06-30 16:33:02 +00:00
|
|
|
$aPath[] = array(0, "ROOT");
|
|
|
|
|
return array_reverse($aPath);
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
2005-05-11 02:26:11 +00:00
|
|
|
|
|
|
|
|
/* return the total number of applications in this category */
|
|
|
|
|
function getApplicationCount($depth = null)
|
|
|
|
|
{
|
|
|
|
|
$MAX_DEPTH = 5;
|
|
|
|
|
|
|
|
|
|
if($depth)
|
|
|
|
|
$depth++;
|
|
|
|
|
else
|
|
|
|
|
$depth = 0;
|
|
|
|
|
|
|
|
|
|
/* if we've reached our max depth, just return 0 and stop recursing */
|
|
|
|
|
if($depth >= $MAX_DEPTH)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
$totalApps = 0;
|
|
|
|
|
|
|
|
|
|
/* add on all apps in each category this category includes */
|
|
|
|
|
if($this->aSubcatsIds)
|
|
|
|
|
{
|
|
|
|
|
while(list($i, $iSubcatId) = each($this->aSubcatsIds))
|
|
|
|
|
{
|
|
|
|
|
$subCat = new Category($iSubcatId);
|
|
|
|
|
$totalApps += $subCat->getApplicationCount($depth);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$totalApps += sizeof($this->aApplicationsIds); /* add on the apps at this category level */
|
|
|
|
|
|
|
|
|
|
return $totalApps;
|
|
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
|
2006-07-11 18:53:06 +00:00
|
|
|
/**
|
|
|
|
|
* create the Category: line at the top of appdb pages$
|
|
|
|
|
*/
|
|
|
|
|
function make_cat_path($path, $appId = '', $versionId = '')
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
2006-07-11 18:53:06 +00:00
|
|
|
$str = "";
|
|
|
|
|
$catCount = 0;
|
|
|
|
|
while(list($iCatIdx, list($iCatId, $name)) = each($path))
|
|
|
|
|
{
|
|
|
|
|
if($name == "ROOT")
|
|
|
|
|
$catname = "Main";
|
|
|
|
|
else
|
|
|
|
|
$catname = $name;
|
2004-12-12 03:51:51 +00:00
|
|
|
|
2006-07-11 18:53:06 +00:00
|
|
|
if ($catCount > 0) $str .= " > ";
|
|
|
|
|
$str .= html_ahref($catname,"appbrowse.php?catId=$iCatId");
|
|
|
|
|
$catCount++;
|
|
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
|
2006-07-11 18:53:06 +00:00
|
|
|
if(!empty($appId))
|
2005-02-02 00:35:49 +00:00
|
|
|
{
|
2006-07-11 18:53:06 +00:00
|
|
|
$oApp = new Application($appId);
|
|
|
|
|
if(!empty($versionId))
|
|
|
|
|
{
|
|
|
|
|
$oVersion = new Version($versionId);
|
2007-04-01 00:09:05 +00:00
|
|
|
$str .= " > ".$oApp->objectMakeLink();
|
2006-07-11 18:53:06 +00:00
|
|
|
$str .= " > ".$oVersion->sName;
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
$str .= " > ".$oApp->sName;
|
|
|
|
|
}
|
2005-02-02 00:35:49 +00:00
|
|
|
}
|
2006-07-11 18:53:06 +00:00
|
|
|
|
|
|
|
|
return $str;
|
2004-12-25 20:11:13 +00:00
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
|
2007-11-24 02:16:28 +01:00
|
|
|
function objectGetId()
|
|
|
|
|
{
|
|
|
|
|
return $this->iCatId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function objectGetSubmitterId()
|
|
|
|
|
{
|
|
|
|
|
/* We don't log that */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function outputEditor()
|
|
|
|
|
{
|
|
|
|
|
$sQuery = "SELECT catId, catName FROM appCategory WHERE catId!='?'";
|
|
|
|
|
$hResult = query_parameters($sQuery, $this->iCatId);
|
|
|
|
|
|
|
|
|
|
/* Add the virtual 'Main' category */
|
|
|
|
|
$aCatIds = array(0);
|
|
|
|
|
$aCatNames = array('Main');
|
|
|
|
|
|
|
|
|
|
/* Add the rest from the database */
|
|
|
|
|
while($oRow = query_fetch_object($hResult))
|
|
|
|
|
{
|
|
|
|
|
$aCatIds[] = $oRow->catId;
|
|
|
|
|
$aCatNames[] = $oRow->catName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo "<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"2\">
|
|
|
|
|
<tr>
|
|
|
|
|
<td width=\"15%\" class=\"box-label\"><b>Category name</b></td>
|
|
|
|
|
<td class=\"box-body\">
|
2008-02-23 12:06:24 +11:00
|
|
|
<input type=\"text\" size=\"50\" name=\"sName\" value=\"".$this->sName."\">
|
2007-11-24 02:16:28 +01:00
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td width=\"15%\" class=\"box-label\"><b>Description</b></td>
|
|
|
|
|
<td class=\"box-body\">
|
2008-02-23 12:06:24 +11:00
|
|
|
<input type=\"text\" size=\"50\" name=\"sDescription\" value=\"".$this->sDescription."\">
|
2007-11-24 02:16:28 +01:00
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td width=\"15%\" class=\"box-label\"><b>Parent</b></td>
|
|
|
|
|
<td class=\"box-body\">
|
|
|
|
|
".html_select("iParentId",$aCatIds,$this->iParentId, $aCatNames)."
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function allowAnonymousSubmissions()
|
|
|
|
|
{
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getOutputEditorValues($aClean)
|
|
|
|
|
{
|
|
|
|
|
$this->sName = $aClean['sName'];
|
|
|
|
|
$this->iParentId = $aClean['iParentId'];
|
|
|
|
|
$this->sDescription = $aClean['sDescription'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function mustBeQueued()
|
|
|
|
|
{
|
|
|
|
|
return $_SESSION['current']->hasPriv('admin');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function canEdit()
|
|
|
|
|
{
|
|
|
|
|
return $_SESSION['current']->hasPriv('admin');
|
|
|
|
|
}
|
|
|
|
|
|
2006-07-11 18:53:06 +00:00
|
|
|
/**
|
|
|
|
|
* display the full path of the Category we are looking at
|
|
|
|
|
*/
|
|
|
|
|
function display($appId, $versionId = '')
|
|
|
|
|
{
|
|
|
|
|
$sCatFullPath = Category::make_cat_path($this->getCategoryPath(), $appId, $versionId);
|
|
|
|
|
echo html_frame_start("",'98%','',2);
|
2008-02-23 12:06:24 +11:00
|
|
|
echo "<p><b>Category: ". $sCatFullPath ."</b><br>\n";
|
2006-07-11 18:53:06 +00:00
|
|
|
echo html_frame_end();
|
|
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
2006-07-11 18:53:06 +00:00
|
|
|
|
2004-03-15 16:22:00 +00:00
|
|
|
?>
|