Location: PHPKode > projects > Poddy > src/maintainance/list_cat.php
<html>
<head>
<title>List Categories</title>
</head>
<body>
<a href="index.php">Zum Hauptmen├╝</a>
<a href="list_cat.php">Zur Category-Liste</a>
<hr/>

<?php
require_once("../config.php");
require_once("lib/db_utils.php");
require_once("lib/path_utils.php");
require_once("lib/img_utils.php");
require_once("lib/guid_utils.php");
require_once("lib/sql_utils.php");
require_once("lib/xml.php");

$id = $_REQUEST["id"];
if (!empty($id)) { 
	$sql = "select * from category where id='".$id."'";
	$category = db_single_query($sql);
}

		
if ($_REQUEST["action"] == "create") {
	$newid = create_guid();
	if (empty($category)) {
		$root_line = $newid;
	} else {
		$root_line = $category["root_line"].",".$newid;	
	}
	
	$sql = "insert into category(id, parent_id, name_de, name_en, root_line) values('".$newid."', '".$id."', '".$_REQUEST["name_de"]."', '".$_REQUEST["name_en"]."', '".$root_line."')";
	echo $sql."<br/>";
	db_query($sql);
}
if ($_REQUEST["action"] == "update" && !empty($category)) {
	$sql = "select * from category where id = '".$category["parent_id"]."'";
	$prow = db_single_query($sql);

	if (empty($prow)) {
		$root_line = $category["id"];
	} else {
		$root_line = $prow["root_line"].",".$category["id"];	
	}

	$sql = "update category set name_de='".$_REQUEST["name_de"]."', name_en='".$_REQUEST["name_en"]."', root_line = '".$root_line."' where id='".$id."'";
	echo $sql."<br/>";
	db_query($sql);
}
if ($_REQUEST["action"] == "delete" && !empty($_REQUEST["id"])) {
	$sql = "select * from category where id = '".$id."'";
	$rs = db_query($sql);
	if ($row = db_next_row($rs)) {
		$sql = "update category set parent_id='".$row["parent_id"]."' where parent_id='".$row["id"]."'";
		echo $sql."<br/>";
		db_query($sql);
		if (empty($row["parent_id"])) {
			$sql = "delete from podcast_category where category_id='".$row["id"]."'";
		} else {
			$sql = "update podcast_category set category_id='".$row["parent_id"]."' where category_id='".$row["id"]."'";
		}
		echo $sql."<br/>";
		db_query($sql);
		
		
		$sql = "delete from category where id = '".$row["id"]."'";
		echo $sql."<br/>";
		db_query($sql);
	}
}

if (!empty($id)) { 
	$sql = "select * from category where id='".$id."'";
	$category = db_single_query($sql);
}

if ($_REQUEST["action"] == "icon" && !empty($_REQUEST["id"])) {
	if (is_uploaded_file($_FILES['uploadfile']['tmp_name'])) {
		$url = $_FILES['uploadfile']['tmp_name'];
	} else if (!empty($_REQUEST["uploadurl"])) {
		$url = $_REQUEST["uploadurl"];
	}
	if (!empty($url)) {
		$base = get_cat_icon_path_base($category);
		$base_big = get_cat_icon_path_big_base($category);
		
		makeThumbnail(str_replace(" ", "%20", $url), FS_BASE_ICONS.$base, 32, true);
		makeThumbnail(str_replace(" ", "%20", $url), FS_BASE_ICONS.$base_big, 96, true);
		$category["has_icon"] = 1;
		$sql = "update category set has_icon=1 where id='".$category["id"]."'";
		echo $sql;
		db_query($sql);
	}
}


$sql = "select * from category";

if (empty($id)) {
	$sql .= " where parent_id = ''";
} else {
	$sql .= " where parent_id = '".$id."'";
}

$cats = array();
$rs = db_query($sql);
while ($row = db_next_row($rs)) {
	$cats[] = $row;
}

$pods = array();
if (!empty($id)) {
	$sql = "select p.* from podcast p, podcast_category pc where p.id = pc.podcast_id and pc.category_id='".$id."' order by p.title asc";
	$rs = db_query($sql);
	while ($row = db_next_row($rs)) {
		$pods[] = $row;
	}
}

if (!empty($id)) { 
	echo get_category_path_html($id, "list_cat.php?id=");
}

echo "<table border='1'><tr><th>Name (de)</th><th>Name (en)</th><th>Icon</th><th>&nbsp;</th></tr>";
foreach ($cats as $cat) {
	echo "<tr>";
	echo "<td><a href='list_cat.php?id=".$cat["id"]."'>".$cat["name_de"]."</a></td>";
	echo "<td>".$cat["name_en"]."</td>";
	echo "<td><img src='".URL_BASE_ICONS.get_cat_icon_path($cat)."'/></td>";
	echo "<td><a href='list_cat.php?action=delete&id=".$cat["id"]."'>Del</a></td>";
	echo "</tr>";
}
echo "</table>";
?>

<hr/>

<form action="list_cat.php"><input type="hidden" name="action" value="create"/>
<input type="hidden" name="id" value="<? echo $id; ?>"/>
Name (de):<input type="text" size="25" name="name_de"/> <br/>
Name (en):<input type="text" size="25" name="name_en"/> <br/>
<input type="submit" value="Neue Kategorie hier anlegen"/>
</form>

<?php 
	if (!empty($id)) { 
?>
<hr/>

<form action="list_cat.php">
<input type="hidden" name="id" value="<? echo $id; ?>"/>
<input type="hidden" name="action" value="update"/>
Name (de):<input type="text" size="25" name="name_de" value="<?php echo $category["name_de"] ?>"/> <br/>
Name (en):<input type="text" size="25" name="name_en" value="<?php echo $category["name_en"] ?>"/> <br/>
<input type="submit" value="Speichern"/>
</form>

<hr/>
<form action="list_cat.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="id" value="<? echo $id; ?>"/>
<input type="hidden" name="action" value="icon"/>
<table>
<tr><td>Icon:</td><td><input name="uploadfile" type="file" size="40" /></td></tr>
<tr><td>oder URL:</td><td><input name="uploadurl" type="text" size="40" value="<? echo $_REQUEST["uploadurl"]; ?>"/></td></tr>
<tr><td colspan="2"><input type="submit" value="Laden"/></td></tr>
</table></form>

<img src="<?php echo URL_BASE_ICONS.get_cat_icon_path($category); ?>">

<hr/>
<?php } 

if (!empty($pods)) {
	foreach ($pods as $pod) {
		echo "<a href='edit_pod.php?id=".$pod["id"]."'>".$pod["title"]."</a><br/>";
	}
}
?>

</body>
</html>
Return current item: Poddy