require("../common.inc.php");
send_header("Configuration - Categories and Divisions");
echo "<< ".i18n("Back to Configuration")."
";
if($_POST['action']=="edit")
{
if($_POST['id'] && $_POST['category'] && $_POST['mingrade'] && $_POST['maxgrade'])
{
$q=mysql_query("SELECT id FROM projectcategories WHERE id='".$_POST['id']."'");
if(mysql_num_rows($q) && $_POST['saveid']!=$_POST['id'])
{
echo error(i18n("Category ID %1 already exists",array($_POST['id'])));
}
else
{
mysql_query("UPDATE projectcategories SET ".
"id='".$_POST['id']."', ".
"category='".mysql_escape_string(stripslashes($_POST['category']))."', ".
"mingrade='".$_POST['mingrade']."', ".
"maxgrade='".$_POST['maxgrade']."' ".
"WHERE id='".$_POST['saveid']."'");
echo happy(i18n("Category successfully saved"));
}
}
else
{
echo error(i18n("All fields are required"));
}
}
if($_POST['action']=="new")
{
if($_POST['id'] && $_POST['category'] && $_POST['mingrade'] && $_POST['maxgrade'])
{
$q=mysql_query("SELECT id FROM projectcategories WHERE id='".$_POST['id']."'");
if(mysql_num_rows($q))
{
echo error(i18n("Category ID %1 already exists",array($_POST['id'])));
}
else
{
mysql_query("INSERT INTO projectcategories (id,category,mingrade,maxgrade) VALUES ( ".
"'".$_POST['id']."', ".
"'".mysql_escape_string(stripslashes($_POST['category']))."', ".
"'".$_POST['mingrade']."', ".
"'".$_POST['maxgrade']."')");
echo happy(i18n("Category successfully added"));
}
}
else
{
echo error(i18n("All fields are required"));
}
}
if($_GET['action']=="remove" && $_GET['remove'])
{
mysql_query("DELETE FROM projectcategories WHERE id='".$_GET['remove']."'");
echo happy(i18n("Category successfully removed"));
}
echo "