Location: PHPKode > projects > SWG Resource Tracker > distro/upload/filter.php
<?php
/*
 *	SWG Resource Tracker
 *	Copyright (C) 2004 Enigma
 *
 *	This program is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU General Public License
 *	as published by the Free Software Foundation; either version 2
 *	of the License, or (at your option) any later version.
 *	
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *	
 *	You should have received a copy of the GNU General Public License
 *	along with this program; if not, write to the Free Software
 *	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

	function printFilterFields()
	{
		foreach ($_REQUEST as $key => $value)
		{
			if (ereg("^filter", $key))
				echo "<input type=\"hidden\" name=\"{$key}\" value=\"{$value}\" />\n";
		}
	}
	
	function printGETQuery()
	{
		$get = "";
		foreach ($_REQUEST as $key => $value)
		{
			if (ereg("^filter[0-9]+", $key))
				$get .= "&amp;{$key}={$value}";
		}
		
		return $get;
	}
	
	function printSQLQuery($values, $prefix="")
	{
		if (count($values) == 0)
			return "";
		
		
		$query = "(";
		for ($i = 0; $i < count($values); $i++)
		{
			$id = $values[$i][0];
			$cat = $values[$i][1];
			
			if ($i > 0)
				$query .= " OR ";
			
			$query .= "{$prefix}`category`=$id";
		}
		
		$query .= ")";
		
		//echo $query . "\n";
		
		return $query;
	}
	
	function getCategoryList($newlist)
	{
		global $prefix;
		
		$categories = array();
		$biglist = array();
		
		//var_dump($_REQUEST);
		
		foreach ($_REQUEST as $key => $value)
		{
			if (ereg("^swgfilter([0-9]{1,3})cat", $key, $regs))
			{
				$keyNum = $regs[1];
				
				$key1 = "swgfilter{$keyNum}cat";
				$key2 = "swgfilter{$keyNum}id";
				$categories[] = array('cat' => $_REQUEST[$key1],'id' => $_REQUEST[$key2]);
			}
		}
		
		$categories[] = $newlist;
		
		//var_dump($categories);
		
		for ($i = 0; $i < count($categories); $i++)
		{
			global $list;
			$list = array();
			
			fetchList($categories[$i]['cat'] + 1, $categories[$i]['id']);
			
			//var_dump($list);
			
			$biglist = array_merge($biglist, $list);
			
		}
		
		$biglist[] = array($categories[0]['id'], $categories[0]['cat'], "");
		
		//var_dump($biglist);
		return $biglist;
	}
	
	//Create an array of all the final categories within one larger one
	function fetchList($cat, $class)
	{
		global $DB, $list;
		
		if ($cat > 6)
		{
			$id = $class;
			
			$query = "SELECT * FROM `category6` WHERE id=$id";
			$DB->query($query);
			$result = $DB->fetchall();
			
			//var_dump($result);
			
			$category = $result[0]['category'];
			$name = $result[0]['name'];
			
			$list[] = array($id, 6, $name);
			
			return;
		}
			
		
		$query = "SELECT * FROM `category$cat` WHERE category=$class";
		
		$DB->query($query);
		$result = $DB->fetchall();
		
		if (count($result) == 0) // It's already at the end
		{
			//$list[] = array($class, $cat - 1, "");
		}
		
		
		for ($i = 0; $i < count($result); $i++)
		{
			$id = $result[$i]['id'];
			$category = $result[$i]['category'];
			$name = $result[$i]['name'];
			
			if ($cat < 6)
			{
				$query = "SELECT * FROM `category" . ($cat + 1) . "` WHERE category=$id";
				$DB->query($query);
				
				$count = $DB->rowCount();
			}
			//echo "0";
			
			//Terminating case.  If category is at end of tier, create just it and make it able to display contents
			if (($count == 0 && $cat < 6) || $cat == 6)
			{
					
					$list[] = array($id, $cat, $name);
			}
			else //Fetch all of the sub-categories for this category
			{
				//$list[] = array($id, $category, $name);
				fetchList($cat + 1, $id);
			}
		}
	}
?>
Return current item: SWG Resource Tracker