Implement divisions editor, small changes to categories

This commit is contained in:
james 2004-12-20 17:03:48 +00:00
parent d73ea11215
commit 287a19999b
2 changed files with 101 additions and 29 deletions

View File

@ -7,7 +7,8 @@
{
if($_POST['id'] && $_POST['category'] && $_POST['mingrade'] && $_POST['maxgrade'])
{
$q=mysql_query("SELECT id FROM projectcategories WHERE id='".$_POST['id']."'");
$q=mysql_query("SELECT id FROM projectcategories WHERE id='".$_POST['id']."' AND year='".$config['FAIRYEAR']."'");
echo mysql_error();
if(mysql_num_rows($q) && $_POST['saveid']!=$_POST['id'])
{
echo error(i18n("Category ID %1 already exists",array($_POST['id'])));
@ -33,18 +34,19 @@
{
if($_POST['id'] && $_POST['category'] && $_POST['mingrade'] && $_POST['maxgrade'])
{
$q=mysql_query("SELECT id FROM projectcategories WHERE id='".$_POST['id']."'");
$q=mysql_query("SELECT id FROM projectcategories WHERE id='".$_POST['id']."' AND year='".$config['FAIRYEAR']."'");
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 ( ".
mysql_query("INSERT INTO projectcategories (id,category,mingrade,maxgrade,year) VALUES ( ".
"'".$_POST['id']."', ".
"'".mysql_escape_string(stripslashes($_POST['category']))."', ".
"'".$_POST['mingrade']."', ".
"'".$_POST['maxgrade']."')");
"'".$_POST['maxgrade']."', ".
"'".$config['FAIRYEAR']."')");
echo happy(i18n("Category successfully added"));
}
}
@ -81,7 +83,7 @@
if($_GET['action']=="edit")
{
echo "<input type=\"hidden\" name=\"saveid\" value=\"".$_GET['edit']."\">\n";
$q=mysql_query("SELECT * FROM projectcategories WHERE id='".$_GET['edit']."'");
$q=mysql_query("SELECT * FROM projectcategories WHERE id='".$_GET['edit']."' AND year='".$config['FAIRYEAR']."'");
$categoryr=mysql_fetch_object($q);
$buttontext="Save";
}
@ -99,7 +101,7 @@
}
else
{
$q=mysql_query("SELECT * FROM projectcategories ORDER BY mingrade");
$q=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' ORDER BY mingrade");
while($r=mysql_fetch_object($q))
{
echo "<tr>";

View File

@ -1,43 +1,113 @@
<?
require("../common.inc.php");
send_header("Configuration - Categories and Divisions");
send_header("Configuration - Project Divisions");
echo "<a href=\"index.php\">&lt;&lt; ".i18n("Back to Configuration")."</a><br />";
if($_POST['action']=="save")
if($_POST['action']=="edit")
{
if($_POST['id'] && $_POST['division'] )
{
$q=mysql_query("SELECT id FROM projectdivisions WHERE id='".$_POST['id']."' AND year='".$config['FAIRYEAR']."'");
if(mysql_num_rows($q) && $_POST['saveid']!=$_POST['id'])
{
echo error(i18n("Division ID %1 already exists",array($_POST['id'])));
}
else
{
mysql_query("UPDATE projectdivisions SET ".
"id='".$_POST['id']."', ".
"division='".mysql_escape_string(stripslashes($_POST['division']))."' ".
"WHERE id='".$_POST['saveid']."'");
echo happy(i18n("Division successfully saved"));
}
}
else
{
echo error(i18n("All fields are required"));
}
}
if($_POST['action']=="new")
{
if($_POST['id'] && $_POST['division'])
{
$q=mysql_query("SELECT id FROM projectdivisions WHERE id='".$_POST['id']."' AND year='".$config['FAIRYEAR']."'");
if(mysql_num_rows($q))
{
echo error(i18n("Division ID %1 already exists",array($_POST['id'])));
}
else
{
mysql_query("INSERT INTO projectdivisions (id,division,year) VALUES ( ".
"'".$_POST['id']."', ".
"'".mysql_escape_string(stripslashes($_POST['division']))."', ".
"'".$config['FAIRYEAR']."') ");
echo happy(i18n("Division successfully added"));
}
}
else
{
echo error(i18n("All fields are required"));
}
}
if($_GET['action']=="remove" && $_GET['remove'])
{
mysql_query("DELETE FROM projectdivisions WHERE id='".$_GET['remove']."'");
echo happy(i18n("Division successfully removed"));
}
echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">";
echo "<h3>".i18n("Age Categories")."</h3>";
$q=mysql_query("SELECT * FROM projectcategories ORDER BY mingrade");
echo "<h3>".i18n("Divisions")."</h3>";
if(! ($_GET['action']=="edit" || $_GET['action']=="new") )
echo "<a href=\"".$_SERVER['PHP_SELF']."?action=new\">".i18n("Add new division")."</a>\n";
echo "<table class=\"summarytable\">";
echo "<tr>";
echo "<th>".i18n("Category ID")."</th>\n";
echo "<th>".i18n("Category Name")."</th>\n";
echo "<th>".i18n("Minimum Grade")."</th>\n";
echo "<th>".i18n("Maximum Grade")."</th>\n";
echo "<th>".i18n("Division ID")."</th>\n";
echo "<th>".i18n("Division Name")."</th>\n";
echo "<th>".i18n("Actions")."</th>\n";
echo "</tr>";
while($r=mysql_fetch_object($q))
if($_GET['action']=="edit" || $_GET['action']=="new")
{
echo "<tr>";
echo " <td>$r->id</td>";
echo " <td>$r->category</td>";
echo " <td>$r->mingrade</td>";
echo " <td>$r->maxgrade</td>";
echo " <td>";
echo "<a title=\"Edit\" href=\"".$_SERVER['PHP_SELF']."?action=editcat&editcat=$r->id\"><img src=\"".$config['SFIABDIRECTORY']."/images/16/edit.".$config['icon_extension']."\" border=0></a>";
echo "&nbsp; &nbsp;";
echo "<a title=\"Remove\" onClick=\"return confirmClick('Are you sure you want to remove this age category?');\" href=\"".$_SERVER['PHP_SELF']."?module=$module&action=remove&remove=$r->id\"><img src=\"".$config['SFIABDIRECTORY']."/images/16/button_cancel.".$config['icon_extension']."\" border=0></a>";
echo " </td>";
echo "<input type=\"hidden\" name=\"action\" value=\"".$_GET['action']."\">\n";
if($_GET['action']=="edit")
{
echo "<input type=\"hidden\" name=\"saveid\" value=\"".$_GET['edit']."\">\n";
$q=mysql_query("SELECT * FROM projectdivisions WHERE id='".$_GET['edit']."' AND year='".$config['FAIRYEAR']."'");
$divisionr=mysql_fetch_object($q);
$buttontext="Save";
}
else if($_GET['action']=="new")
{
$buttontext="Add";
}
echo "<tr>";
echo " <td><input type=\"text\" size=\"3\" name=\"id\" value=\"$divisionr->id\"></td>";
echo " <td><input type=\"text\" size=\"40\" name=\"division\" value=\"$divisionr->division\"></td>";
echo " <td><input type=\"submit\" value=\"".i18n($buttontext)."\"></td>";
echo "</tr>";
}
else
{
$q=mysql_query("SELECT * FROM projectdivisions WHERE year='".$config['FAIRYEAR']."' ORDER BY division");
while($r=mysql_fetch_object($q))
{
echo "<tr>";
echo " <td>$r->id</td>";
echo " <td>$r->division</td>";
echo " <td>";
echo "<a title=\"Edit\" href=\"".$_SERVER['PHP_SELF']."?action=edit&edit=$r->id\"><img src=\"".$config['SFIABDIRECTORY']."/images/16/edit.".$config['icon_extension']."\" border=0></a>";
echo "&nbsp; &nbsp;";
echo "<a title=\"Remove\" onClick=\"return confirmClick('Are you sure you want to remove this division?');\" href=\"".$_SERVER['PHP_SELF']."?module=$module&action=remove&remove=$r->id\"><img src=\"".$config['SFIABDIRECTORY']."/images/16/button_cancel.".$config['icon_extension']."\" border=0></a>";
echo " </td>";
echo "</tr>";
}
}
echo "</table>";
echo "</form>";
echo "<h3>".i18n("Divisions")."</h3>";
$q=mysql_query("SELECT * FROM projectdivisions ORDER BY division");
send_footer();
?>