award prizes system

This commit is contained in:
james 2005-03-04 03:40:03 +00:00
parent d4b84cd798
commit 2212b9c98d
2 changed files with 289 additions and 60 deletions

View File

@ -40,53 +40,65 @@
if($_POST['save']=="edit" || $_POST['save']=="add")
{
if($_POST['save']=="add")
{
$q=mysql_query("INSERT INTO award_awards (award_sponsors_id,award_types_id,year) VALUES ('".$_POST['award_sponsors_id']."','".$_POST['award_types_id']."','".$config['FAIRYEAR']."')");
$id=mysql_insert_id();
if(!$_POST['award_types_id']) {
echo error(i18n("Award Type is required"));
$_GET['action']=$_POST['save'];
}
else if(!$_POST['award_sponsors_id']) {
echo error(i18n("Award Sponsor is required"));
$_GET['action']=$_POST['save'];
}
else
$id=$_POST['id'];
$exec="UPDATE award_awards SET ".
"name='".mysql_escape_string(stripslashes($_POST['name']))."', ".
"`order`='".mysql_escape_string(stripslashes($_POST['order']))."', ".
"award_sponsors_id='".mysql_escape_string(stripslashes($_POST['award_sponsors_id']))."', ".
"award_types_id='".mysql_escape_string(stripslashes($_POST['award_types_id']))."', ".
"criteria='".mysql_escape_string(stripslashes($_POST['criteria']))."' ".
"WHERE id='$id'";
mysql_query($exec);
echo mysql_error();
//whipe out any old award-category links
mysql_query("DELETE FROM award_awards_projectcategories WHERE award_awards_id='$id'");
//now add the new ones
if(is_array($_POST['eligiblecategories']))
{
foreach($_POST['eligiblecategories'] AS $cat)
if($_POST['save']=="add")
{
mysql_query("INSERT INTO award_awards_projectcategories (award_awards_id,projectcategories_id,year) VALUES ('$id','$cat','".$config['FAIRYEAR']."')");
$q=mysql_query("INSERT INTO award_awards (award_sponsors_id,award_types_id,year) VALUES ('".$_POST['award_sponsors_id']."','".$_POST['award_types_id']."','".$config['FAIRYEAR']."')");
$id=mysql_insert_id();
}
}
else
$id=$_POST['id'];
//whipe out any old award-divisions links
mysql_query("DELETE FROM award_awards_projectdivisions WHERE award_awards_id='$id'");
$exec="UPDATE award_awards SET ".
"name='".mysql_escape_string(stripslashes($_POST['name']))."', ".
"`order`='".mysql_escape_string(stripslashes($_POST['order']))."', ".
"award_sponsors_id='".mysql_escape_string(stripslashes($_POST['award_sponsors_id']))."', ".
"award_types_id='".mysql_escape_string(stripslashes($_POST['award_types_id']))."', ".
"criteria='".mysql_escape_string(stripslashes($_POST['criteria']))."' ".
"WHERE id='$id'";
//now add the new ones
if(is_array($_POST['eligibledivisions']))
{
foreach($_POST['eligibledivisions'] AS $div)
mysql_query($exec);
echo mysql_error();
//whipe out any old award-category links
mysql_query("DELETE FROM award_awards_projectcategories WHERE award_awards_id='$id'");
//now add the new ones
if(is_array($_POST['eligiblecategories']))
{
mysql_query("INSERT INTO award_awards_projectdivisions (award_awards_id,projectdivisions_id,year) VALUES ('$id','$div','".$config['FAIRYEAR']."')");
foreach($_POST['eligiblecategories'] AS $cat)
{
mysql_query("INSERT INTO award_awards_projectcategories (award_awards_id,projectcategories_id,year) VALUES ('$id','$cat','".$config['FAIRYEAR']."')");
}
}
}
if($_POST['save']=="add")
echo happy("Award successfully added");
else
echo happy("Successfully saved changes to award");
//whipe out any old award-divisions links
mysql_query("DELETE FROM award_awards_projectdivisions WHERE award_awards_id='$id'");
//now add the new ones
if(is_array($_POST['eligibledivisions']))
{
foreach($_POST['eligibledivisions'] AS $div)
{
mysql_query("INSERT INTO award_awards_projectdivisions (award_awards_id,projectdivisions_id,year) VALUES ('$id','$div','".$config['FAIRYEAR']."')");
}
}
if($_POST['save']=="add")
echo happy("Award successfully added");
else
echo happy("Successfully saved changes to award");
}
}
if($_POST['action']=="reorder")
@ -107,8 +119,11 @@
echo happy("Award successfully deleted");
}
if($_GET['action']=="edit" || $action=="add")
if($_GET['action']=="edit" || $_GET['action']=="add")
{
//define these here so we dont forget :)
$currentcategories=array();
$currentdivisions=array();
echo "<a href=\"award_awards.php\">&lt;&lt; ".i18n("Back to Awards List")."</a>\n";
if($_GET['action']=="edit")
@ -140,9 +155,29 @@
echo mysql_error();
$r=mysql_fetch_object($q);
$award_awards_id=$r->id;
$award_awards_name=$r->name;
$award_awards_order=$r->order;
$award_awards_criteria=$r->criteria;
$award_types_id=$r->award_types_id;
$award_type=$r->type;
$award_sponsors_id=$r->award_sponsors_id;
$award_sponsor=$r->organization;
//select the current categories that this award is linked to
$ccq=mysql_query("SELECT * FROM award_awards_projectcategories WHERE award_awards_id='$r->id'");
while($ccr=mysql_fetch_object($ccq))
$currentcategories[]=$ccr->projectcategories_id;
//select the current categories that this award is linked to
$cdq=mysql_query("SELECT * FROM award_awards_projectdivisions WHERE award_awards_id='$r->id'");
while($cdr=mysql_fetch_object($cdq))
$currentdivisions[]=$cdr->projectdivisions_id;
}
else if($action=="add")
else if($_GET['action']=="add")
{
echo "<h3>".i18n("Add Award")."</h3>\n";
$buttontext="Add Award";
@ -151,16 +186,26 @@ echo mysql_error();
}
$buttontext=i18n($buttontext);
//if we have POST values, then they should be used instead of the db values
//esp for adding, if there is an error then the POST values will be redisplayed
if($_POST['name']) $award_awards_name=$_POST['name'];
if($_POST['order']) $award_awards_order=$_POST['order'];
if($_POST['criteria']) $award_awards_criteria=$_POST['criteria'];
if($_POST['award_types_id']) $award_types_id=$_POST['award_types_id'];
if($_POST['award_sponsors_id']) $award_sponsors_id=$_POST['award_sponsors_id'];
if($_POST['eligiblecategories']) $currentcategories=$_POST['eligiblecategories'];
if($_POST['eligibledivisions']) $currentdivisions=$_POST['eligibledivisions'];
echo "<form method=\"post\" action=\"award_awards.php\">\n";
echo "<input type=\"hidden\" name=\"award_sponsors_id\" value=\"$award_sponsors_id\">\n";
echo "<input type=\"hidden\" name=\"save\" value=\"".$_GET['action']."\">\n";
if($_GET['action']=="edit")
echo "<input type=\"hidden\" name=\"id\" value=\"".$_GET['edit']."\">\n";
echo "<table>\n";
echo "<tr><td>".i18n("Name")."</td><td><input type=\"text\" name=\"name\" value=\"".htmlspecialchars($r->name)."\" size=\"50\" maxlength=\"128\" /></td></tr>\n";
echo "<tr><td>".i18n("Order")."</td><td><input type=\"text\" name=\"order\" value=\"".htmlspecialchars($r->order)."\" size=\"5\" maxlength=\"5\" />(".i18n("presentation order").")</td></tr>\n";
echo "<tr><td>".i18n("Name")."</td><td><input type=\"text\" name=\"name\" value=\"".htmlspecialchars($award_awards_name)."\" size=\"50\" maxlength=\"128\" /></td></tr>\n";
echo "<tr><td>".i18n("Order")."</td><td><input type=\"text\" name=\"order\" value=\"".htmlspecialchars($award_awards_order)."\" size=\"5\" maxlength=\"5\" />(".i18n("presentation order").")</td></tr>\n";
echo "<tr><td>".i18n("Sponsor")."</td><td>";
$sq=mysql_query("SELECT id,organization FROM award_sponsors ORDER BY organization");
echo "<select name=\"award_sponsors_id\">";
@ -168,7 +213,7 @@ echo mysql_error();
echo $firstsponsor;
while($sr=mysql_fetch_object($sq))
{
if($sr->id == $r->award_sponsors_id)
if($sr->id == $award_sponsors_id)
$sel="selected=\"selected\"";
else
$sel="";
@ -184,7 +229,7 @@ echo mysql_error();
echo $firsttype;
while($tr=mysql_fetch_object($tq))
{
if($tr->id == $r->award_types_id)
if($tr->id == $award_types_id)
$sel="selected=\"selected\"";
else
$sel="";
@ -193,7 +238,7 @@ echo mysql_error();
echo "</select>";
echo "</td></tr>";
echo "<tr><td>".i18n("Criteria")."</td><td><textarea name=\"criteria\" rows=\"8\" cols=\"50\">".htmlspecialchars($r->criteria)."</textarea></td></tr>\n";
echo "<tr><td>".i18n("Criteria")."</td><td><textarea name=\"criteria\" rows=\"8\" cols=\"50\">".htmlspecialchars($award_awards_criteria)."</textarea></td></tr>\n";
echo "<tr><td>".i18n("Eligibility")."</td><td>";
echo "<table>";
@ -203,12 +248,6 @@ echo mysql_error();
echo "</tr>";
echo "<tr><td>";
$currentcategories=array();
//select the current categories that this award is linked to
$ccq=mysql_query("SELECT * FROM award_awards_projectcategories WHERE award_awards_id='$r->id'");
while($ccr=mysql_fetch_object($ccq))
$currentcategories[]=$ccr->projectcategories_id;
//now select all the categories so we can list them all
$cq=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' ORDER BY mingrade");
echo mysql_error();
@ -224,13 +263,6 @@ echo mysql_error();
echo "</td>";
echo "<td>";
$currentdivisions=array();
//select the current categories that this award is linked to
$cdq=mysql_query("SELECT * FROM award_awards_projectdivisions WHERE award_awards_id='$r->id'");
while($cdr=mysql_fetch_object($cdq))
$currentdivisions[]=$cdr->projectdivisions_id;
$dq=mysql_query("SELECT * FROM projectdivisions WHERE year='".$config['FAIRYEAR']."' ORDER BY division");
echo mysql_error();
@ -368,9 +400,9 @@ echo mysql_error();
echo "</td>";
echo " <td align=\"center\">";
echo "<a href=\"award_awards.php?award_awards_id=$award_awards_id&action=edit&edit=$r->id\"><img border=\"0\" src=\"".$config['SFIABDIRECTORY']."/images/16/edit.".$config['icon_extension']."\"></a>";
echo "<a href=\"award_awards.php?action=edit&edit=$r->id\"><img border=\"0\" src=\"".$config['SFIABDIRECTORY']."/images/16/edit.".$config['icon_extension']."\"></a>";
echo "&nbsp;";
echo "<a onclick=\"return confirmClick('Are you sure you want to remove this award?')\" href=\"award_awards.php?award_awards_id=$award_awards_id&action=delete&delete=$r->id\"><img border=0 src=\"".$config['SFIABDIRECTORY']."/images/16/button_cancel.".$config['icon_extension']."\"></a>";
echo "<a onclick=\"return confirmClick('Are you sure you want to remove this award?')\" href=\"award_awards.php?action=delete&delete=$r->id\"><img border=0 src=\"".$config['SFIABDIRECTORY']."/images/16/button_cancel.".$config['icon_extension']."\"></a>";
echo " </td>\n";
echo "</tr>\n";

197
admin/award_prizes.php Normal file
View File

@ -0,0 +1,197 @@
<?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website: http://www.sfiab.ca
Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
Copyright (C) 2005 James Grant <james@lightbox.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation, version 2.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
?>
<?
require("../common.inc.php");
auth_required('admin');
send_header("Administration - Award Prizes");
if($_GET['award_awards_id'])
$award_awards_id=$_GET['award_awards_id'];
else if($_POST['award_awards_id'])
$award_awards_id=$_POST['award_awards_id'];
?>
<?
echo "<a href=\"index.php\">&lt;&lt; ".i18n("Back to Administration")."</a>\n";
echo "<a href=\"awards.php\">&lt;&lt; ".i18n("Back to Awards Main")."</a>\n";
echo "<a href=\"award_awards.php\">&lt;&lt; ".i18n("Back to Awards List")."</a>\n";
if($award_awards_id)
{
$q=mysql_query("SELECT * FROM award_awards WHERE id='".$award_awards_id."'");
$award=mysql_fetch_object($q);
if($_POST['save']=="edit" || $_POST['save']=="add")
{
if($_POST['save']=="add")
{
$q=mysql_query("INSERT INTO award_prizes (award_awards_id,year) VALUES ('$award_awards_id','".$config['FAIRYEAR']."')");
$id=mysql_insert_id();
}
else
$id=$_POST['id'];
$exec="UPDATE award_prizes SET ".
"prize='".mysql_escape_string(stripslashes($_POST['prize']))."', ".
"cash='".mysql_escape_string(stripslashes($_POST['cash']))."', ".
"scholarship='".mysql_escape_string(stripslashes($_POST['scholarship']))."', ".
"number='".mysql_escape_string(stripslashes($_POST['number']))."', ".
"`order`='".mysql_escape_string(stripslashes($_POST['order']))."' ".
"WHERE id='$id'";
mysql_query($exec);
if($_POST['save']=="add")
echo happy("Prize successfully added");
else
echo happy("Successfully saved changes to prize");
}
if($_POST['action']=="reorder")
{
if(is_array($_POST['reorder']))
{
foreach($_POST['reorder'] AS $key=>$val)
{
mysql_query("UPDATE award_prizes SET `order`='$val' WHERE id='$key'");
}
echo happy("Award Prizes successfully reordered");
}
}
if($_GET['action']=="delete" && $_GET['delete'])
{
mysql_query("DELETE FROM award_prizes WHERE id='".$_GET['delete']."'");
echo happy("Contact successfully deleted");
}
if($_GET['action']=="edit" || $action=="add")
{
echo "<a href=\"award_prizes.php?award_awards_id=$award_awards_id\">&lt;&lt; ".i18n("Back to Prizes for %1",array($award->name))."</a>\n";
echo "<br />";
echo "<br />";
if($_GET['action']=="edit")
{
echo "<h3>".i18n("Edit Prize for %1",array($award->name))."</h3>\n";
$buttontext="Save Prize";
$q=mysql_query("SELECT * FROM award_prizes WHERE id='".$_GET['edit']."'");
$r=mysql_fetch_object($q);
}
else if($action=="add")
{
echo "<h3>".i18n("Add Prize for %1",array($award->name))."</h3>\n";
$buttontext="Add Prize";
}
$buttontext=i18n($buttontext);
echo "<form method=\"post\" action=\"award_prizes.php\">\n";
echo "<input type=\"hidden\" name=\"award_awards_id\" value=\"$award_awards_id\">\n";
echo "<input type=\"hidden\" name=\"save\" value=\"".$_GET['action']."\">\n";
if($_GET['action']=="edit")
echo "<input type=\"hidden\" name=\"id\" value=\"".$_GET['edit']."\">\n";
echo "<table>\n";
echo "<tr><td>".i18n("Prize Description")."</td><td></td><td><input type=\"text\" name=\"prize\" value=\"".htmlspecialchars($r->prize)."\" size=\"40\" maxlength=\"128\" /></td></tr>\n";
echo "<tr><td>".i18n("Cash Amount")."</td><td>\$</td><td><input type=\"text\" name=\"cash\" value=\"".htmlspecialchars($r->cash)."\" size=\"10\" maxlength=\"10\" /></td></tr>\n";
echo "<tr><td>".i18n("Scholarship Amount")."</td><td>\$</td><td><input type=\"text\" name=\"scholarship\" value=\"".htmlspecialchars($r->scholarship)."\" size=\"10\" maxlength=\"10\" /></td></tr>\n";
echo "<tr><td>".i18n("Number")."</td><td></td><td><input type=\"text\" name=\"number\" value=\"".htmlspecialchars($r->number)."\" size=\"3\" maxlength=\"5\" /></td></tr>\n";
echo "<tr><td>".i18n("Order")."</td><td></td><td><input type=\"text\" name=\"order\" value=\"".htmlspecialchars($r->order)."\" size=\"3\" maxlength=\"5\" /></td></tr>\n";
echo "<tr><td colspan=\"3\" align=\"center\"><input type=\"submit\" value=\"$buttontext\" /></td></tr>\n";
echo "</table>\n";
echo "</form>\n";
}
else
{
echo "<br />";
echo "<a href=\"award_prizes.php?award_awards_id=$award_awards_id&action=add\">".i18n("Add New Prize to %1",array($award->name))."</a>\n";
echo "<br />";
$q=mysql_query("SELECT * FROM award_prizes WHERE year='".$config['FAIRYEAR']."' AND award_awards_id='$award_awards_id' ORDER BY `order`");
if(mysql_num_rows($q))
{
echo "<form method=\"post\" action=\"award_prizes.php\">";
echo "<input type=\"hidden\" name=\"action\" value=\"reorder\">";
echo "<input type=\"hidden\" name=\"award_awards_id\" value=\"$award_awards_id\">";
echo "<table class=\"summarytable\">";
echo "<tr>";
echo " <th>".i18n("Order")."</th>";
echo " <th>".i18n("Prize Description")."</th>";
echo " <th>".i18n("Cash Amount")."</th>";
echo " <th>".i18n("Scholarship Amount")."</th>";
echo " <th>".i18n("# of Prizes")."</th>";
echo " <th>Actions</th>";
echo "</tr>\n";
while($r=mysql_fetch_object($q))
{
echo "<tr>\n";
echo " <td><input type=\"text\" name=\"reorder[$r->id]\" value=\"$r->order\" size=\"3\" /></td>\n";
echo " <td>$r->prize</td>\n";
echo " <td align=\"right\">";
if($r->cash) echo "\$$r->cash";
else echo "&nbsp;";
echo " </td>";
echo " <td align=\"right\">";
if($r->scholarship) echo "\$$r->scholarship";
else echo "&nbsp;";
echo " </td>";
echo " <td align=\"center\">$r->number</td>\n";
echo " <td align=\"center\">";
echo "<a href=\"award_prizes.php?award_awards_id=$award_awards_id&action=edit&edit=$r->id\"><img border=\"0\" src=\"".$config['SFIABDIRECTORY']."/images/16/edit.".$config['icon_extension']."\"></a>";
echo "&nbsp;";
echo "<a onclick=\"return confirmClick('Are you sure you want to remove this prize?')\" href=\"award_prizes.php?award_awards_id=$award_awards_id&action=delete&delete=$r->id\"><img border=0 src=\"".$config['SFIABDIRECTORY']."/images/16/button_cancel.".$config['icon_extension']."\"></a>";
echo " </td>\n";
echo "</tr>\n";
}
echo "</table>\n";
echo "<input type=\"submit\" value=\"".i18n("Re-order prizes")."\" />";
echo "</form>";
}
}
}
else
{
echo error(i18n("No Award ID specified"));
echo "<a href=\"award_awards.php\">".i18n("Choose an award")."</a>";
}
send_footer();
?>