require("../common.inc.php");
send_header("Configuration - Project Sub-Divisions");
echo "<< ".i18n("Back to Configuration")."
";
if($_POST['action']=="edit")
{
if($_POST['id'] && $_POST['projectdivisions_id'] && $_POST['subdivision'] )
{
$q=mysql_query("SELECT id FROM projectsubdivisions WHERE id='".$_POST['id']."' AND year='".$config['FAIRYEAR']."'");
if(mysql_num_rows($q) && $_POST['saveid']!=$_POST['id'])
{
echo error(i18n("Sub-Division ID %1 already exists",array($_POST['id'])));
}
else
{
mysql_query("UPDATE projectsubdivisions SET ".
"id='".$_POST['id']."', ".
"projectdivisions_id='".$_POST['projectdivisions_id']."', ".
"subdivision='".mysql_escape_string(stripslashes($_POST['subdivision']))."' ".
"WHERE id='".$_POST['saveid']."'");
echo happy(i18n("Sub-Division successfully saved"));
}
}
else
{
echo error(i18n("All fields are required"));
}
}
if($_POST['action']=="new")
{
if($_POST['projectdivisions_id'] && $_POST['subdivision'])
{
if(!$_POST['id'])
{
$idq=mysql_query("SELECT MAX(id) AS id FROM projectsubdivisions");
$idr=mysql_fetch_object($idq);
$newid=$idr->id+1;
}
else
$newid=$_POST['id'];
$q=mysql_query("SELECT id FROM projectsubdivisions WHERE id='$newid' AND year='".$config['FAIRYEAR']."'");
if(mysql_num_rows($q))
{
echo error(i18n("Sub-Division ID %1 already exists",array($newid)));
}
else
{
mysql_query("INSERT INTO projectsubdivisions (id,projectdivisions_id,subdivision,year) VALUES ( ".
"'$newid', ".
"'".$_POST['projectdivisions_id']."', ".
"'".mysql_escape_string(stripslashes($_POST['subdivision']))."', ".
"'".$config['FAIRYEAR']."') ");
echo happy(i18n("Sub-Division successfully added"));
}
}
else
{
echo error(i18n("All fields except ID are required"));
}
}
if($_GET['action']=="remove" && $_GET['remove'])
{
mysql_query("DELETE FROM projectsubdivisions WHERE id='".$_GET['remove']."'");
echo happy(i18n("Sub-Division successfully removed"));
}
echo "