From 2212b9c98d0489419aebed853011a51fc510ec93 Mon Sep 17 00:00:00 2001 From: james Date: Fri, 4 Mar 2005 03:40:03 +0000 Subject: [PATCH] award prizes system --- admin/award_awards.php | 152 ++++++++++++++++++------------- admin/award_prizes.php | 197 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 289 insertions(+), 60 deletions(-) create mode 100644 admin/award_prizes.php diff --git a/admin/award_awards.php b/admin/award_awards.php index e4cb6e8..a960abb 100644 --- a/admin/award_awards.php +++ b/admin/award_awards.php @@ -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 "<< ".i18n("Back to Awards List")."\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 "

".i18n("Add Award")."

\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 "
\n"; - echo "\n"; echo "\n"; if($_GET['action']=="edit") echo "\n"; echo "\n"; - echo "\n"; - echo "\n"; + echo "\n"; + echo "\n"; echo ""; - echo "\n"; + echo "\n"; echo "
".i18n("Name")."name)."\" size=\"50\" maxlength=\"128\" />
".i18n("Order")."order)."\" size=\"5\" maxlength=\"5\" />(".i18n("presentation order").")
".i18n("Name")."
".i18n("Order")."(".i18n("presentation order").")
".i18n("Sponsor").""; $sq=mysql_query("SELECT id,organization FROM award_sponsors ORDER BY organization"); echo ""; echo "
".i18n("Criteria")."
".i18n("Criteria")."
".i18n("Eligibility").""; echo ""; @@ -203,12 +248,6 @@ echo mysql_error(); echo ""; echo ""; echo ""; echo " \n"; echo "\n"; diff --git a/admin/award_prizes.php b/admin/award_prizes.php new file mode 100644 index 0000000..e31c3b8 --- /dev/null +++ b/admin/award_prizes.php @@ -0,0 +1,197 @@ + + Copyright (C) 2005 James Grant + + 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. +*/ +?> + + +<< ".i18n("Back to Administration")."\n"; + echo "<< ".i18n("Back to Awards Main")."\n"; + echo "<< ".i18n("Back to Awards List")."\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 "<< ".i18n("Back to Prizes for %1",array($award->name))."\n"; + echo "
"; + echo "
"; + if($_GET['action']=="edit") + { + echo "

".i18n("Edit Prize for %1",array($award->name))."

\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 "

".i18n("Add Prize for %1",array($award->name))."

\n"; + $buttontext="Add Prize"; + } + $buttontext=i18n($buttontext); + + echo "\n"; + echo "\n"; + echo "\n"; + + if($_GET['action']=="edit") + echo "\n"; + + echo "
"; - $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 ""; - $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 ""; - echo "id\">"; + echo "id\">"; echo " "; - echo "id\">"; + echo "id\">"; echo "
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + + echo "
".i18n("Prize Description")."prize)."\" size=\"40\" maxlength=\"128\" />
".i18n("Cash Amount")."\$cash)."\" size=\"10\" maxlength=\"10\" />
".i18n("Scholarship Amount")."\$scholarship)."\" size=\"10\" maxlength=\"10\" />
".i18n("Number")."number)."\" size=\"3\" maxlength=\"5\" />
".i18n("Order")."order)."\" size=\"3\" maxlength=\"5\" />
\n"; + echo "\n"; + } + else + { + + echo "
"; + echo "".i18n("Add New Prize to %1",array($award->name))."\n"; + echo "
"; + + $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 "
"; + echo ""; + echo ""; + + echo ""; + echo ""; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + echo "\n"; + + + while($r=mysql_fetch_object($q)) + { + echo "\n"; + echo " \n"; + echo " \n"; + echo " "; + echo " "; + echo " \n"; + echo " \n"; + echo "\n"; + } + + echo "
".i18n("Order")."".i18n("Prize Description")."".i18n("Cash Amount")."".i18n("Scholarship Amount")."".i18n("# of Prizes")."Actions
id]\" value=\"$r->order\" size=\"3\" />$r->prize"; + if($r->cash) echo "\$$r->cash"; + else echo " "; + echo " "; + if($r->scholarship) echo "\$$r->scholarship"; + else echo " "; + echo " $r->number"; + echo "id\">"; + echo " "; + echo "id\">"; + + + echo "
\n"; + echo ""; + echo "
"; + } + + } + + + } + else + { + echo error(i18n("No Award ID specified")); + echo "".i18n("Choose an award").""; + } + + send_footer(); + +?>