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 "