<?php
if (!defined('ADMIN_FILE')) die("Illegal File Access");
function editcategory($gid, $parent) {
	global $prefix, $db, $admin_file;
	head();
	if (isset($gid) && $gid!="") {
		navigationAdmin("<b><a href=\"".$admin_file.".php?op=album\">"._GALCONFIG."</a></b> &gt;&gt; <b><a href=\"".$admin_file.".php?op=album&do=editallcategories\">"._GALEDITALLCATEGORIES."</a></b> &gt;&gt; <b>"._GALEDITCATEGORY."</b>");
		$album_title = "<center><font class=\"option\"><b>"._GALEDITCATEGORY."</b></font></center>";
	} else {
		navigationAdmin("<b><a href=\"".$admin_file.".php?op=album\">"._GALCONFIG."</a></b> &gt;&gt; <b><a href=\"".$admin_file.".php?op=album&do=editallcategories\">"._GALEDITALLCATEGORIES."</a></b> &gt;&gt; <b>"._GALCREATECATEGORY."</b>");
		$album_title = "<center><font class=\"option\"><b>"._GALCREATECATEGORY."</b></font></center>";
	}
	OpenTable();
	echo "$album_title";
	if (isset($gid) && $gid!="") {
		$sql = "SELECT * FROM $prefix"._album_categories." WHERE gallid=$gid";
		$result = $db->sql_query($sql);
		$row = $db->sql_fetchrow($result);
		mysql_free_result($result);
	}
	if (isset($parent) && $parent!="" && $parent!=-1) {
		$sql = "SELECT galloc FROM $prefix"._album_categories." WHERE gallid=$parent";
		$result = $db->sql_query($sql);
		list ($parentloc) = $db->sql_fetchrow($result);
		mysql_free_result($result);
	}
	if (isset($gid) && $gid!="") {
		echo "<form method=\"POST\" action=\"".$admin_file.".php?op=album\">";
	} else {
		echo "<form method=\"POST\" action=\"".$admin_file.".php?op=album\" enctype=\"multipart/form-data\">";
	}
	echo "<input type=\"hidden\" name=\"do\" value=\"editcategory\">";
	if (isset($gid) && $gid!="") {
		echo "<input type=\"hidden\" name=\"type\" value=\"save\">";
	} else {
		echo "<input type=\"hidden\" name=\"type\" value=\"create\">";
	}
	echo "<input type=\"hidden\" name=\"parent\" value=\"$parent\"><input type=\"hidden\" name=\"parentloc\" value=\"$parentloc\"><input type=\"hidden\" name=\"category\" value=\"$gid\">";
	echo "<table border=\"0\" align=\"center\"><tr><td>"._GALCATAEGOYNAME.":</td><td><input type=\"text\" size=\"50\" style=\"width:300px\" name=\"categoryname\" value=\"$row[gallname]\"></td></tr><tr><td>"._GALCATLOC.":</td><td>";
	if (isset($gid) && $gid!="") {
		echo "<input type=\"text\" size=\"50\" style=\"width:300px\" value=\"$row[galloc]\">";
	} else {
		echo "<input type=\"text\" size=\"50\" style=\"width:300px\" name=\"categoryloc\" value=\"$row[galloc]\">";
	}
	echo "</td></tr><tr><td>"._GALCATDESC.":</td><td><textarea name=\"description_cat\" rows=\"5\" cols=\"50\" style=\"width:300px\" wrap=\"virtual\">$row[description]</textarea></td></tr><tr><td>"._GALCATICON.":</td><td>";
	if (isset($gid) && $gid!="") {
		echo "<input type=\"text\" size=\"50\" style=\"width:300px\" name=\"image\" value=\"$row[gallimg]\">";
	} else {
		echo "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"1000000\">";
		echo "<input type=\"file\" size=\"50\" style=\"width:300px\" name=\"userfile\" >";
	}
	echo "</td></tr><tr><td>"._GALCATTHUMB.":</td><td><input type=\"text\" size=\"50\" style=\"width:300px\" name=\"thumbwidth\" value=\"$row[thumbwidth]\"></td></tr><tr><td>"._GALNUMCOLCAT.":</td><td><select name=\"numcol\" style=\"width:300px\">";
	for ($k=1; $k<=3; $k++) {
		if ($k==$row[numcol]) {
			echo "<option selected value=\"$k\">$k</option>";
		} else {
			echo "<option value=\"$k\">$k</option>";
		}
	}
	echo "</select></td></tr><tr><td>"._GALTEMPLATETYPE.":</td><td><select name=\"xtemplate\" style=\"width:300px\">";
	$sel_template[$templateID] = ' selected';
	$tempres = $db->sql_query("SELECT id, title FROM $prefix"._album_template_types." WHERE id>1 AND type=2 ORDER BY title");
	while($row2 = $db->sql_fetchrow($tempres)) {
		$sel = $sel_template[$row2[id]];
		echo "<option value=\"$row2[id]\"$sel>$row2[title]</option>\n";
	}
	echo "</select></td></tr><tr><td>"._GALCATVISIBLE.":</td><td><select name=\"visible\" style=\"width:300px\">";
	$ind = $row[visible];
	$selected[$ind] = "selected";
	echo "<option value=\"0\" $selected[0]>"._GALVISIBLEADMIN."</option><option value=\"1\" $selected[1]>"._GALVISIBLEMEMBER."</option><option value=\"2\" $selected[2]>"._GALVISIBLEPUBLIC."</option></select></td></tr>";
	if (isset($gid) && $gid!="") {
		list($nb) = $db->sql_fetchrow($db->sql_query("SELECT count(*) FROM $prefix"._album_pictures." WHERE gid=$gid"));
		list($sub) = $db->sql_fetchrow($db->sql_query("SELECT count(*) FROM $prefix"._album_categories." WHERE parent=$gid"));
		echo "<tr><td>"._GALCATDETAILS.":</td><td>"._GALCATMEDIACOUNT.": $nb, "._GALSUBCATEGORIES.": $sub</td></tr>";
	}
	echo "</table><br><center><input type=\"submit\" name=\"save\" value=\""._GALSAVECHANGES."\"></center></form>";
	CloseTable();
	foot();
}
?>