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
|
|
|
/***************************************************/
|
|
|
|
|
|
2004-03-15 16:22:00 +00:00
|
|
|
class Category {
|
|
|
|
|
|
|
|
|
|
var $name;
|
|
|
|
|
var $id;
|
|
|
|
|
var $subcat;
|
|
|
|
|
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
/**
|
2004-03-15 16:22:00 +00:00
|
|
|
* the special name "ROOT" is the top category
|
|
|
|
|
*/
|
|
|
|
|
function Category($id = 0)
|
|
|
|
|
{
|
2005-02-06 17:49:48 +00:00
|
|
|
$this->id = $id;
|
2004-12-12 03:51:51 +00:00
|
|
|
$this->load($id);
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-06 17:49:48 +00:00
|
|
|
/**
|
|
|
|
|
* Deletes the category from the database.
|
|
|
|
|
* and request the deletion of linked elements.
|
|
|
|
|
*/
|
|
|
|
|
function delete()
|
|
|
|
|
{
|
|
|
|
|
$r = query_appdb("SELECT appId FROM appFamily WHERE catId = ".$this->id,"Failed to delete category ".$this->id);
|
|
|
|
|
if($r)
|
|
|
|
|
{
|
|
|
|
|
while($ob = mysql_fetch_object($r))
|
|
|
|
|
{
|
|
|
|
|
$oApp = new Application($ob->appId);
|
|
|
|
|
$oApp->delete();
|
|
|
|
|
}
|
|
|
|
|
$r = query_appdb("DELETE FROM appCategory WHERE catId = $catId","Failed to delete category $catId");
|
|
|
|
|
if($r)
|
|
|
|
|
addmsg("Category $catId deleted.", "green");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
/**
|
2004-03-15 16:22:00 +00:00
|
|
|
* load the category data into this class
|
|
|
|
|
*/
|
|
|
|
|
function load($id)
|
|
|
|
|
{
|
2004-12-12 03:51:51 +00:00
|
|
|
$this->id = $id;
|
|
|
|
|
|
|
|
|
|
if($id == 0)
|
|
|
|
|
{
|
|
|
|
|
$this->name = "ROOT";
|
|
|
|
|
} else
|
|
|
|
|
{
|
2005-01-11 00:26:05 +00:00
|
|
|
$result = query_appdb("SELECT * FROM appCategory WHERE catId = $id");
|
2004-12-12 03:51:51 +00:00
|
|
|
if(!$result)
|
|
|
|
|
{
|
|
|
|
|
// category not found!
|
|
|
|
|
errorpage("Internal Error: Category not found!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$ob = mysql_fetch_object($result);
|
|
|
|
|
$this->name = $ob->catName;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-11 00:26:05 +00:00
|
|
|
$result = query_appdb("SELECT catId, catName, catDescription FROM ".
|
2004-12-12 03:51:51 +00:00
|
|
|
"appCategory WHERE catParent = $this->id " .
|
|
|
|
|
"ORDER BY catName");
|
|
|
|
|
if(mysql_num_rows($result) == 0)
|
|
|
|
|
return; // no sub categories
|
|
|
|
|
|
|
|
|
|
$this->subcat = array();
|
|
|
|
|
while($row = mysql_fetch_object($result))
|
|
|
|
|
{
|
|
|
|
|
// ignore NONAME categories
|
|
|
|
|
if($row->catName == "NONAME")
|
|
|
|
|
continue;
|
|
|
|
|
$this->subcat[$row->catId] = array($row->catName, $row->catDescription);
|
|
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
/**
|
2004-03-15 16:22:00 +00:00
|
|
|
* resolve the category id by name
|
|
|
|
|
*/
|
|
|
|
|
function getCategoryId($name)
|
|
|
|
|
{
|
2004-12-12 03:51:51 +00:00
|
|
|
if($name == "ROOT")
|
|
|
|
|
return 0;
|
|
|
|
|
|
2005-01-11 00:26:05 +00:00
|
|
|
$result = query_appdb("SELECT catId FROM appCategory WHERE ".
|
2004-12-12 03:51:51 +00:00
|
|
|
"catName = '$name'");
|
|
|
|
|
if(!$result)
|
|
|
|
|
return -1;
|
|
|
|
|
if(mysql_num_rows($result) != 1)
|
|
|
|
|
return -1;
|
|
|
|
|
$row = mysql_fetch_object($result);
|
|
|
|
|
return $row->catId;
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
/**
|
2004-03-15 16:22:00 +00:00
|
|
|
* returns the list of sub categories
|
|
|
|
|
*
|
|
|
|
|
* category list has the following format:
|
|
|
|
|
*
|
|
|
|
|
* { { catId => { catName, catDescription } }, ... }
|
|
|
|
|
*/
|
|
|
|
|
function getCategoryList()
|
|
|
|
|
{
|
2004-12-12 03:51:51 +00:00
|
|
|
return $this->subcat;
|
2004-03-15 16:22:00 +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()
|
|
|
|
|
{
|
2004-12-12 03:51:51 +00:00
|
|
|
$path = array();
|
|
|
|
|
$id = $this->id;
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
2005-01-11 00:26:05 +00:00
|
|
|
$result = query_appdb("SELECT catName, catId, catParent FROM appCategory WHERE catId = $id");
|
2004-12-12 03:51:51 +00:00
|
|
|
if(!$result || mysql_num_rows($result) != 1)
|
|
|
|
|
break;
|
|
|
|
|
$cat = mysql_fetch_object($result);
|
|
|
|
|
$path[] = array($cat->catId, $cat->catName);
|
|
|
|
|
$id = $cat->catParent;
|
|
|
|
|
}
|
|
|
|
|
$path[] = array(0, "ROOT");
|
|
|
|
|
return array_reverse($path);
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
/**
|
2004-03-15 16:22:00 +00:00
|
|
|
* returns a list of applications in the specified category
|
|
|
|
|
*/
|
|
|
|
|
function getAppList($id)
|
|
|
|
|
{
|
2005-01-11 00:26:05 +00:00
|
|
|
$result = query_appdb("SELECT appId, appName, description FROM ".
|
2004-12-12 03:51:51 +00:00
|
|
|
"appFamily WHERE catId = $id ".
|
|
|
|
|
"ORDER BY appName");
|
|
|
|
|
if(!$result || mysql_num_rows($result) == 0)
|
|
|
|
|
return array();
|
|
|
|
|
|
|
|
|
|
$list = array();
|
2004-03-15 16:22:00 +00:00
|
|
|
while($row = mysql_fetch_object($result))
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
|
|
|
|
if($row->appName == "NONAME")
|
|
|
|
|
continue;
|
|
|
|
|
$list[$row->appId] = array($row->appName, $row->description);
|
|
|
|
|
}
|
|
|
|
|
return $list;
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
/**
|
2004-03-15 16:22:00 +00:00
|
|
|
* returns the number of apps in the specified category
|
|
|
|
|
*/
|
|
|
|
|
function getAppCount($id, $recurse = 1)
|
|
|
|
|
{
|
2004-12-12 03:51:51 +00:00
|
|
|
$total = 0;
|
|
|
|
|
|
2005-01-11 00:26:05 +00:00
|
|
|
$result = query_appdb("SELECT appId FROM appFamily WHERE catId = $id");
|
2004-12-12 03:51:51 +00:00
|
|
|
if($result)
|
|
|
|
|
$total += mysql_num_rows($result);
|
|
|
|
|
|
|
|
|
|
if($recurse)
|
|
|
|
|
{
|
2005-01-11 00:26:05 +00:00
|
|
|
$result = query_appdb("SELECT catId FROM appCategory WHERE catParent = $id");
|
2004-12-12 03:51:51 +00:00
|
|
|
if($result)
|
|
|
|
|
{
|
|
|
|
|
while($ob = mysql_fetch_object($result))
|
|
|
|
|
$total += $this->getAppCount($ob->catId, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $total;
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* create the Category: line at the top of appdb pages$
|
|
|
|
|
*/
|
2004-12-25 20:11:13 +00:00
|
|
|
function make_cat_path($path, $appId = '', $versionId = '')
|
2004-03-15 16:22:00 +00:00
|
|
|
{
|
|
|
|
|
$str = "";
|
|
|
|
|
$catCount = 0;
|
|
|
|
|
while(list($idx, list($id, $name)) = each($path))
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
|
|
|
|
if($name == "ROOT")
|
|
|
|
|
$catname = "Main";
|
|
|
|
|
else
|
|
|
|
|
$catname = $name;
|
|
|
|
|
|
|
|
|
|
if ($catCount > 0) $str .= " > ";
|
|
|
|
|
$str .= html_ahref($catname,"appbrowse.php?catId=$id");
|
|
|
|
|
$catCount++;
|
|
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
|
2004-12-25 20:11:13 +00:00
|
|
|
if(!empty($appId))
|
|
|
|
|
{
|
|
|
|
|
if(!empty($versionId))
|
2005-02-02 00:35:49 +00:00
|
|
|
{
|
2005-02-04 02:59:05 +00:00
|
|
|
$str .= " > ".html_ahref(lookup_app_name($appId),"appview.php?appId=$appId");
|
|
|
|
|
$str .= " > ".lookup_version_name($versionId);
|
2005-02-02 00:35:49 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2005-02-04 02:59:05 +00:00
|
|
|
$str .= " > ".lookup_app_name($appId);
|
2005-02-02 00:35:49 +00:00
|
|
|
}
|
2004-12-25 20:11:13 +00:00
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
|
|
|
|
|
return $str;
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-06 17:49:48 +00:00
|
|
|
function lookupCategoryName($catId)
|
2005-01-08 18:28:32 +00:00
|
|
|
{
|
|
|
|
|
$sResult = query_appdb("SELECT * FROM appCategory ".
|
|
|
|
|
"WHERE catId = ".$catId);
|
|
|
|
|
if(!$sResult || mysql_num_rows($sResult) != 1)
|
|
|
|
|
return "Unknown category";
|
|
|
|
|
|
|
|
|
|
$ob = mysql_fetch_object($sResult);
|
|
|
|
|
return $ob->catName;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-15 16:22:00 +00:00
|
|
|
?>
|