- replaced tons of tabs with spaces

- replaced <? with <?php for compatibility sake (see TODO and CODING_STANDARD to know more)
- improved overall code lisibility
This commit is contained in:
Jonathan Ernst
2004-12-12 03:51:51 +00:00
committed by WineHQ
parent 7270e4cabc
commit d3d9e853d9
73 changed files with 1156 additions and 1219 deletions

View File

@@ -1,6 +1,8 @@
<?
<?php
/***************************************************/
/* this class represents a category + its children */
/***************************************************/
class Category {
var $name;
@@ -8,76 +10,76 @@ class Category {
var $subcat;
/*
/**
* the special name "ROOT" is the top category
*/
function Category($id = 0)
{
$this->load($id);
$this->load($id);
}
/*
/**
* load the category data into this class
*/
function load($id)
{
$this->id = $id;
if($id == 0)
{
$this->name = "ROOT";
}
else
{
$result = mysql_query("SELECT * FROM appCategory WHERE catId = $id");
if(!$result) {
// category not found!
errorpage("Internal Error: Category not found!");
return;
}
$this->id = $id;
$ob = mysql_fetch_object($result);
$this->name = $ob->catName;
}
if($id == 0)
{
$this->name = "ROOT";
} else
{
$result = mysql_query("SELECT * FROM appCategory WHERE catId = $id");
if(!$result)
{
// category not found!
errorpage("Internal Error: Category not found!");
return;
}
$result = mysql_query("SELECT catId, catName, catDescription FROM ".
"appCategory WHERE catParent = $this->id " .
"ORDER BY catName");
if(mysql_num_rows($result) == 0)
return; // no sub categories
$ob = mysql_fetch_object($result);
$this->name = $ob->catName;
}
$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);
}
$result = mysql_query("SELECT catId, catName, catDescription FROM ".
"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);
}
}
/*
/**
* resolve the category id by name
*/
function getCategoryId($name)
{
if($name == "ROOT")
return 0;
if($name == "ROOT")
return 0;
$result = mysql_query("SELECT catId FROM appCategory WHERE ".
"catName = '$name'");
if(!$result)
return -1;
if(mysql_num_rows($result) != 1)
return -1;
$row = mysql_fetch_object($result);
return $row->catId;
$result = mysql_query("SELECT catId FROM appCategory WHERE ".
"catName = '$name'");
if(!$result)
return -1;
if(mysql_num_rows($result) != 1)
return -1;
$row = mysql_fetch_object($result);
return $row->catId;
}
/*
/**
* returns the list of sub categories
*
* category list has the following format:
@@ -86,83 +88,84 @@ class Category {
*/
function getCategoryList()
{
return $this->subcat;
return $this->subcat;
}
/*
/**
* returns a path like:
*
* { ROOT, Games, Simulation }
*/
function getCategoryPath()
{
$path = array();
$id = $this->id;
while(1)
{
$result = mysql_query("SELECT catName, catId, catParent FROM appCategory WHERE catId = $id");
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);
$path = array();
$id = $this->id;
while(1)
{
$result = mysql_query("SELECT catName, catId, catParent FROM appCategory WHERE catId = $id");
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);
}
/*
/**
* returns a list of applications in the specified category
*/
function getAppList($id)
{
$result = mysql_query("SELECT appId, appName, description FROM ".
"appFamily WHERE catId = $id ".
"ORDER BY appName");
if(!$result || mysql_num_rows($result) == 0)
return array();
$list = array();
$result = mysql_query("SELECT appId, appName, description FROM ".
"appFamily WHERE catId = $id ".
"ORDER BY appName");
if(!$result || mysql_num_rows($result) == 0)
return array();
$list = array();
while($row = mysql_fetch_object($result))
{
if($row->appName == "NONAME")
continue;
$list[$row->appId] = array($row->appName, $row->description);
}
return $list;
{
if($row->appName == "NONAME")
continue;
$list[$row->appId] = array($row->appName, $row->description);
}
return $list;
}
/*
/**
* returns the number of apps in the specified category
*/
function getAppCount($id, $recurse = 1)
{
$total = 0;
$total = 0;
$result = mysql_query("SELECT appId FROM appFamily WHERE catId = $id");
if($result)
$total += mysql_num_rows($result);
$result = mysql_query("SELECT appId FROM appFamily WHERE catId = $id");
if($result)
$total += mysql_num_rows($result);
if($recurse)
{
$result = mysql_query("SELECT catId FROM appCategory WHERE catParent = $id");
if($result)
{
while($ob = mysql_fetch_object($result))
$total += $this->getAppCount($ob->catId, 1);
}
}
return $total;
if($recurse)
{
$result = mysql_query("SELECT catId FROM appCategory WHERE catParent = $id");
if($result)
{
while($ob = mysql_fetch_object($result))
$total += $this->getAppCount($ob->catId, 1);
}
}
return $total;
}
};
function appIdToName($appId)
{
$result = mysql_query("SELECT appName FROM appFamily WHERE appId = $appId");
if(!$result || !mysql_num_rows($result))
return "<unknown>"; // shouldn't normally happen
return "<unknown>"; // shouldn't normally happen
$ob = mysql_fetch_object($result);
return $ob->appName;
}
@@ -176,31 +179,30 @@ function versionIdToName($versionId)
return $ob->versionName;
}
// create the Category: line at the top of appdb pages
/**
* create the Category: line at the top of appdb pages$
*/
function make_cat_path($path)
{
global $appId;
global $versionId;
$str = "";
$catCount = 0;
while(list($idx, list($id, $name)) = each($path))
{
if($name == "ROOT")
$catname = "Main";
else
$catname = $name;
{
if($name == "ROOT")
$catname = "Main";
else
$catname = $name;
if ($catCount > 0) { $str .= " &gt; "; }
$str .= html_ahref($catname,"appbrowse.php?catId=$id");
$catCount++;
}
if ($catCount > 0) $str .= " &gt; ";
$str .= html_ahref($catname,"appbrowse.php?catId=$id");
$catCount++;
}
if($appId)
$str .= " &gt; ".html_ahref(appIdToName($appId),"appview.php?appId=$appId");
if($_REQUEST['appId'])
$str .= " &gt; ".html_ahref(appIdToName($_REQUEST['appId']),"appview.php?appId=".$_REQUEST['appId']);
if($versionId)
$str .= " &gt; ".html_ahref(versionIdToName($versionId),"appview.php?appId=$appId&versionId=$versionId");
if($_REQUEST['versionId'])
$str .= " &gt; ".html_ahref(versionIdToName($_REQUEST['versionId']),"appview.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']);
return $str;
}