Location: PHPKode > projects > PHPmyCDMouse > phpmycdmouse_031/selectcat.php
<?
/*
   Copyright (C) 2003  by Uwe Thiel, Germany

    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.
*/
	session_start();
	require("./config.inc.php");
	$HideHeader = true;
	require($Header);
#	deletevars();
	$Access = $_SESSION["Access"];
	
	$CatID=intval($_GET["CatID"]);
	$FileID=intval($_GET["FileID"]);
    $Action=$_GET["Action"];
	
	
	if (($Action=="Add") && ($Access[Categories])) {
		if ($_POST["NewCat"]=="") {
			$Message = "<font color=red>Please enter a name for the category</font><br><br>";
		} else {
			$CheckExists = new CD_DB();
			$CheckExistsSQL = "SELECT * FROM Category WHERE UPPER(CategoryName)='".strtoupper($_POST["NewCat"])."' AND ParentID=$CatID";
			$CheckExists->query($CheckExistsSQL);
			if ($CheckExists->next_record()) {
				$Message = "<font color=red>Category <b>".$_POST["NewCat"]."</b> already exists</font><br><br>";
			} else {
				$AddCat = new CD_DB();
				$AddCatSQL = "INSERT INTO Category (CategoryName, ParentID) VALUES ('".$_POST["NewCat"]."', $CatID)";
				$AddCat->query($AddCatSQL);
				$Message = "<font color=blue>Category <b>".$_POST["NewCat"]."</b> Added</font><br><br>";
			}
		}
	}
	
	if ($CatID==0) {
		$CatName = "Main Category Listing";
	} else {
		$GetCurrent = new CD_DB();
		$GetCurrentSQL = "SELECT * FROM Category WHERE CategoryID=$CatID";
		$GetCurrent->query($GetCurrentSQL);
		$GetCurrent->next_record();
		$CatName = $GetCurrent->f("CategoryName");
		$ParentID = $GetCurrent->f("ParentID");
	}
	
	$CatList = new CD_DB();
	$CatListSQL = "SELECT * FROM Category WHERE ParentID=$CatID ORDER BY CategoryName";
	$CatList->query($CatListSQL);
?>
<script language="javascript">
function SetCat(CategoryID, CategoryName) {
	window.opener.document.FileForm.elements["CategoryID[<?=$FileID?>]"].value = CategoryID;
	window.opener.document.FileForm.elements["CategoryName[<?=$FileID?>]"].value = CategoryName;
	window.close();
}
</script>
<h1>Current Category: <?=$CatName?></h1>
<?	if ($CatID!=0) {
?>
<input type=button value="Select Category" onClick="javascript:SetCat(<?=$CatID?>,'<?=$CatName?>');"><br><br>
<?
	}
	if ($ParentID!="") {
?>
<li><a href="<?=$_SERVER["PHP_SELF"]?>?CatID=<?=$ParentID?>&FileID=<?=$FileID?>">Up One Level</a><br><br>
<?	} 
	echo $Message;
?>
<table width=100%>
<tr><td><b>ID</b></td><td><b>Category Name</b></td><td></td></tr>
<?	$Counter = 0;
	while ($CatList->next_record()) {
		$Counter++;
?>
<tr class="FileLine<?=$Counter%2?>"><td><?=$CatList->f("CategoryID")?></td><td><a href="<?=$_SERVER["PHP_SELF"]?>?CatID=<?=$CatList->f("CategoryID")?>&FileID=<?=$FileID?>"><?=$CatList->f("CategoryName")?></a></td><td><input type=button value="Select" onClick="javascript:SetCat(<?=$CatList->f("CategoryID")?>,'<?=$CatList->f("CategoryName")?>')"></td></tr>
<?
	}
	if ($Access[Categories]) {
?>
<form action="<?=$_SERVER["PHP_SELF"]?>?Action=Add&CatID=<?=$CatID?>&FileID=<?=$FileID?>" method="post">
<tr class="RedLine"><td><b>New Category:</b></td><td><input type=text name="NewCat" value=""></td><td><input type=submit value="Add"></td></tr>
<?	} ?>
</table>
</form>
<div align=right valign=bottom><a href="javascript:window.close()">Close</a></div>
</div>
</BODY>
</HTML>
Return current item: PHPmyCDMouse