From d50debde12fd7dc63e0fd97c2c4544dd5b9019da Mon Sep 17 00:00:00 2001 From: dave Date: Thu, 10 Sep 2009 08:29:16 +0000 Subject: [PATCH] - Make the main award table sortable by dragging - Implement new/delete award (still needs some eyecandy) - Update the order tables to recalc the order without fetching it from the server - Only thing left to do is make sure saving eligiblity works. : --- admin/award_awards.php | 1011 +++++++++++++++------------------------- 1 file changed, 369 insertions(+), 642 deletions(-) diff --git a/admin/award_awards.php b/admin/award_awards.php index e146e3e8..f61709d5 100644 --- a/admin/award_awards.php +++ b/admin/award_awards.php @@ -29,48 +29,31 @@ switch($_GET['action']) { case 'awardinfo_load': $id = intval($_GET['id']); - $q=mysql_query("SELECT award_awards.id, - award_awards.name, - award_awards.criteria, - award_awards.description, - award_awards.order, - award_awards.presenter, - award_awards.excludefromac, - award_awards.cwsfaward, - award_awards.self_nominate, - award_awards.schedule_judges, - award_types.id AS award_types_id, - award_types.type, - sponsors.id AS sponsors_id, - sponsors.organization - FROM - award_awards, - award_types, - sponsors - WHERE - award_awards.id='$id' - AND award_awards.sponsors_id=sponsors.id - AND award_awards.award_types_id=award_types.id - "); - echo mysql_error(); - $r = mysql_fetch_assoc($q); - $ret = array(); - $ret['id'] = $r['id']; - $ret['name'] = $r['name']; - $ret['order'] = $r['order']; - $ret['criteria'] = $r['criteria']; - $ret['description'] = $r['description']; - $ret['presenter'] = $r['presenter']; - $ret['award_types_id'] = $r['award_types_id']; - $ret['sponsors_id'] = $r['sponsors_id']; - $ret['excludefromac'] = $r['excludefromac']; - $ret['cwsfaward'] = $r['cwsfaward']; - $ret['self_nominate'] = $r['self_nominate']; - $ret['schedule_judges'] = $r['schedule_judges']; + $q=mysql_query("SELECT * FROM award_awards WHERE id='$id'"); + $ret = mysql_fetch_assoc($q); echo json_encode($ret); exit; - case 'awardinfo_save': + + +case 'award_create': + $q=mysql_query("INSERT INTO award_awards (year,self_nominate,schedule_judges) + VALUES ('{$config['FAIRYEAR']}','yes','yes')"); + $ret = array('id' => mysql_insert_id() ); + echo json_encode($ret); + exit; + + case 'award_delete': $id=intval($_GET['id']); + mysql_query("DELETE FROM award_prizes WHERE award_awards_id='$id'"); + mysql_query("DELETE FROM award_awards_projectcategories WHERE award_awards_id='$id'"); + mysql_query("DELETE FROM award_awards_projectdivisions WHERE award_awards_id='$id'"); + mysql_query("DELETE FROM award_awards WHERE id='$id'"); + exit; + + case 'awardinfo_save': + /* Scrub the data while we save it */ + $id=intval($_GET['id']); + $q = "UPDATE award_awards SET name='".mysql_escape_string(stripslashes($_GET['name']))."', `order`='".intval($_GET['order'])."', @@ -84,39 +67,8 @@ criteria='".mysql_escape_string(stripslashes($_GET['criteria']))."', description='".mysql_escape_string(stripslashes($_GET['description']))."' WHERE id='$id'"; - echo $q; - echo happy(i18n('Settings Saved')); -// mysql_query($q); - /* - //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) - { - mysql_query("INSERT INTO award_awards_projectcategories (award_awards_id,projectcategories_id,year) VALUES ('$id','$cat','".$config['FAIRYEAR']."')"); - } - } - - //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"); - */ + echo happy(i18n('Award Info Saved')); + mysql_query($q); exit; case 'eligibilty_load': @@ -136,14 +88,53 @@ echo json_encode($ret); exit; + case 'eligibility_save': + $id = intval($_GET['id']); + + //now add the new ones + if(!is_array($_GET['categories']) || !is_array($_GET['divisions'])) { + echo error(i18n("Invalid data")); + exit; + } + + //wipe out any old award-category links + mysql_query("DELETE FROM award_awards_projectcategories WHERE award_awards_id='$id'"); + + foreach($_GET['categories'] AS $cat) { + mysql_query("INSERT INTO award_awards_projectcategories (award_awards_id,projectcategories_id,year) + VALUES ('$id','$cat','{$config['FAIRYEAR']}')"); + } + + //wipe out any old award-divisions links + mysql_query("DELETE FROM award_awards_projectdivisions WHERE award_awards_id='$id'"); + + //now add the new ones + foreach($_POST['eligibledivisions'] AS $div) { + mysql_query("INSERT INTO award_awards_projectdivisions (award_awards_id,projectdivisions_id,year) + VALUES ('$id','$div','{$config['FAIRYEAR']}')"); + } + echo happy(i18n("Saved.")); + exit; + case 'prize_order': $order = 0; foreach ($_GET['prizelist'] as $position=>$id) { if($id == '') continue; $order++; - mysql_query("UPDATE `award_prizes` SET `order`='$order' WHERE `id`='$id'"); + mysql_query("UPDATE `award_prizes` SET `order`='$order' WHERE `id`='$id'"); } - echo happy(i18n("Order Updated.")); +// print_r($_GET); +// echo happy(i18n("Order Updated.")); + exit; + + case 'award_order': + $order = 0; + foreach ($_GET['awardlist'] as $position=>$id) { + if($id == '') continue; + $order++; + mysql_query("UPDATE `award_awards` SET `order`='$order' WHERE `id`='$id'"); + } +// echo happy(i18n("Order Updated.")); exit; case 'prizeinfo_load': @@ -196,80 +187,18 @@ exit; } - if($_GET['action']=="edit" || $_GET['action']=="add") { - send_header(($_GET['action']=="edit") ? "Edit Award" : "Add Award", - array('Committee Main' => 'committee_main.php', - 'Administration' => 'admin/index.php', - 'Awards Main' => 'admin/awards.php', - 'Awards Management' => 'admin/award_awards.php') ); - } else { - send_header("Awards Management", - array('Committee Main' => 'committee_main.php', + send_header("Awards Management", + array('Committee Main' => 'committee_main.php', 'Administration' => 'admin/index.php', 'Awards Main' => 'admin/awards.php') ); - } - - - if($_GET['sponsors_id'] && $_GET['sponsors_id']!="all") - $_SESSION['sponsors_id']=$_GET['sponsors_id']; - else if($_GET['sponsors_id']=="all") - unset($_SESSION['sponsors_id']); - - if($_GET['award_types_id'] && $_GET['award_types_id']!="all") - $_SESSION['award_types_id']=$_GET['award_types_id']; - else if($_GET['award_types_id']=="all") - unset($_SESSION['award_types_id']); - -/* - if($_GET['award_sponsors_confirmed'] && $_GET['award_sponsors_confirmed']!="all") - $_SESSION['award_sponsors_confirmed']=$_GET['award_sponsors_confirmed']; - - if($_GET['sponsors_id']=="all") - unset($_SESSION['sponsors_id']); - if($_GET['award_types_id']=="all") - unset($_SESSION['award_types_id']); - if($_GET['award_sponsors_confirmed']=="all") - unset($_SESSION['award_sponsors_confirmed']); -*/ - - $award_types_id=$_SESSION['award_types_id']; - $sponsors_id=$_SESSION['sponsors_id']; - //$award_sponsors_confirmed=$_SESSION['award_sponsors_confirmed']; - - - function popup_begin($name, $title, $width=0, $height=0) - { - echo "
"; - } - function popup_end() - { - echo "
"; - } - - require_once('../htabs.inc.php'); - - ?> @@ -418,18 +341,16 @@ $(document).ready(function() { echo "
"; htabs_begin('editortabs', array('awardinfo' => array('label' =>'Award', - 'title' => 'Award Info', 'callback' => 'update_awardinfo'), 'eligibility' => array('label' =>'Eligibility', - 'title' => 'Eligibility', 'callback' => 'update_eligibility'), 'prizes'=> array('label' => 'Prizes', - 'title' => 'Prizes', 'callback' => 'update_prizeinfo'), ),'awardinfo'); htabs_tab_begin('awardinfo'); ?> +

@@ -451,11 +372,11 @@ htabs_tab_begin('awardinfo'); echo ""; } ?> - - : - - - : + + : + + + : "; @@ -464,33 +385,39 @@ htabs_tab_begin('awardinfo'); while($tr=mysql_fetch_object($tq)) { echo ""; } - echo ""; - echo ""; - - echo "".i18n("Criteria").":\n"; - echo "".i18n("Description").":\n"; - echo ""; - echo "

Options

"; - echo ''; - echo ""; - echo ""; - echo ""; - echo ""; - - echo "
"; - echo "".i18n("Exclude this award from the award ceremony script")."
"; - echo "".i18n("This award identifies the students that will be attending the Canada-Wide Science Fair")."
"; - echo "".i18n("Students can self-nominate for this award (this is usually checked for special awards)")."
"; - echo "".i18n("Allow the Automatic Judge Scheduler to assign judges to this award (usually checked)")."
"; - echo "
"; - echo "\n"; - +?> + + : + + : + + +

Options

+ + + + + + + + + +
+
+
+
+
+ +"; - echo "".i18n("Age Categories").":"; +?> +

+ +
: + -
-
+

+
+ + + + + + + + + +

*
@@ -578,451 +515,241 @@ htabs_end(); echo ''; -if($_POST['save']=="edit" || $_POST['save']=="add") +/* Here's all the code for the award list, except for the AJAX queries which are + * at the top of this file */ +?> + - if($_POST['action']=="reorder") - { - if(is_array($_POST['reorder'])) - { - foreach($_POST['reorder'] AS $key=>$val) - { - mysql_query("UPDATE award_awards SET `order`='$val' WHERE id='$key'"); - } - echo happy("Awards successfully reordered"); - } - } +
- if($_GET['action']=="delete" && $_GET['delete']) - { - mysql_query("DELETE FROM award_awards WHERE id='".$_GET['delete']."'"); - echo happy("Award successfully deleted"); - } +id; - $award_awards_name=$r->name; - $award_awards_order=$r->order; - $award_awards_criteria=$r->criteria; - $award_awards_description=$r->description; - $award_types_id=$r->award_types_id; - $award_type=$r->type; - $sponsors_id=$r->sponsors_id; - $award_sponsor=$r->organization; - $award_awards_presenter=$r->presenter; - $award_awards_excludefromac=$r->excludefromac; - $award_awards_cwsfaward=$r->cwsfaward; - $award_awards_self_nominate=$r->self_nominate; - $award_awards_schedule_judges=$r->schedule_judges; +echo "
"; +echo i18n("Filter By:"); +echo "
"; +echo ""; +echo ""; +echo "
"; - //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; +$q=mysql_query("SELECT id,organization FROM sponsors ORDER BY organization"); +echo ""; +echo "
"; - //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($_GET['action']=="add") - { - $buttontext="Add Award"; - $firstsponsor="\n"; - $firsttype="\n"; - /* We want these two on by default for new - * awards */ - $award_awards_self_nominate = 'yes'; - $award_awards_schedule_judges = 'yes'; - } - $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['description']) $award_awards_criteria=$_POST['description']; - if($_POST['award_types_id']) $award_types_id=$_POST['award_types_id']; - if($_POST['sponsors_id']) $sponsors_id=$_POST['sponsors_id']; - if($_POST['eligiblecategories']) $currentcategories=$_POST['eligiblecategories']; - if($_POST['eligibledivisions']) $currentdivisions=$_POST['eligibledivisions']; - if($_POST['presenter']) $award_awards_presenter=$_POST['presenter']; - if($_POST['excludefromac']) $award_awards_excludefromac=$_POST['excludefromac']; - if($_POST['cwsfaward']) $award_awards_cwsfaward=$_POST['cwsfaward']; - if($_POST['self_nominate']) $award_awards_self_nominate=$_POST['self_nominate']; - if($_POST['schedule_judges']) $award_awards_schedule_judges=$_POST['schedule_judges']; - - - echo "\n"; - echo "\n"; - - if($_GET['action']=="edit") - echo "\n"; - - echo "\n"; -// echo "\n"; - echo "\n"; - echo ""; - - echo "\n"; - echo ""; - -// echo "\n"; -// echo "\n"; - echo ""; - - echo ""; - echo ""; - echo ""; - echo ""; - - echo "\n"; - - echo "
".i18n("Name")."
".i18n("Order")."(".i18n("presentation order").")
".i18n("Sponsor").""; - $sq=mysql_query("SELECT id,organization FROM sponsors ORDER BY organization"); - echo ""; - echo "
".i18n("Presenter")."
".i18n("Type").""; - $tq=mysql_query("SELECT id,type FROM award_types WHERE year='{$config['FAIRYEAR']}' ORDER BY type"); - echo ""; - echo "
".i18n("Criteria")."
".i18n("Description")."
".i18n("Eligibility").""; - - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - if(count($currentcategories)==0) $class="class=\"error\""; else $class=""; - echo ""; - if(count($currentdivisions)==0) $class="class=\"error\""; else $class=""; - echo ""; - echo ""; - if(count($currentcategories)==0 || count($currentdivisions)==0) - echo ""; - echo "
".i18n("Age Categories")."".i18n("Divisions")."
"; - - //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(); - while($cr=mysql_fetch_object($cq)) - { - if(in_array($cr->id,$currentcategories)) - $ch="checked=\"checked\""; - else - $ch=""; - - echo "id\" />".i18n($cr->category)."
"; - } - echo "
"; - - $dq=mysql_query("SELECT * FROM projectdivisions WHERE year='".$config['FAIRYEAR']."' ORDER BY division"); - echo mysql_error(); - while($dr=mysql_fetch_object($dq)) - { - if(in_array($dr->id,$currentdivisions)) - $ch="checked=\"checked\""; - else - $ch=""; - echo "id\" />".i18n($dr->division)."
"; - } - - echo "
".i18n("At least one age category and one division must be selected")."
"; - - echo "
"; - if($award_awards_excludefromac==1) $ch="checked=\"checked\""; else $ch=""; - echo "".i18n("Exclude this award from the award ceremony script")."
"; - if($award_awards_cwsfaward==1) $ch="checked=\"checked\""; else $ch=""; - echo "".i18n("This award identifies the students that will be attending the Canada-Wide Science Fair")."
"; - $ch = ($award_awards_self_nominate=='yes') ? "checked=\"checked\"" : ''; - echo "".i18n("Students can self-nominate for this award (this is usually checked for special awards)")."
"; - $ch = ($award_awards_schedule_judges=='yes') ? "checked=\"checked\"" : ''; - echo "".i18n("Allow the Automatic Judge Scheduler to assign judges to this award (usually checked)")."
\n"; - echo "\n"; - } - else - { - - - echo "
"; - echo i18n("Filter By:"); - echo "
"; - echo ""; - echo ""; - echo "
"; - - $q=mysql_query("SELECT id,organization FROM sponsors ORDER BY organization"); - echo ""; - echo "
"; - - $q=mysql_query("SELECT id,type FROM award_types WHERE year='{$config['FAIRYEAR']}' ORDER BY type"); - echo ""; - echo ""; +$q=mysql_query("SELECT id,type FROM award_types WHERE year='{$config['FAIRYEAR']}' ORDER BY type"); +echo ""; +echo ""; /* //FIXME: 'confirmed' no longer exists, we need to lookup their sponsorship record and check the status there, either pending, confirmed or received, dunno if it makes sense to put that here or not.. - echo ""; - */ - echo ""; - echo "
"; - - - - echo "
"; - echo "".i18n("Add New Award")."\n"; - echo "
"; - - if($sponsors_id) $where_asi="AND sponsors_id='$sponsors_id'"; - if($award_types_id) $where_ati="AND award_types_id='$award_types_id'"; -// if($award_sponsors_confirmed) $where_asc="AND award_sponsors.confirmed='$award_sponsors_confirmed'"; - - if(!$orderby) $orderby="order"; - - $q=mysql_query("SELECT - award_awards.id, - award_awards.name, - award_awards.order, - award_awards.award_source_fairs_id, - award_types.type, - sponsors.organization - - FROM - award_awards, - award_types, - sponsors - WHERE - award_awards.year='".$config['FAIRYEAR']."' - $where_asi - $where_ati - $where_asc - AND award_awards.sponsors_id=sponsors.id - AND award_awards.award_types_id=award_types.id - AND award_types.year='".$config['FAIRYEAR']."' - ORDER BY `$orderby`"); - - echo mysql_error(); - - if(mysql_num_rows($q)) - { - echo "
"; - echo ""; - - echo ""; - echo ""; - echo " "; - echo " "; - echo " "; - echo " "; - echo " "; - echo " "; - echo "\n"; - - - $hasexternal=false; - while($r=mysql_fetch_object($q)) - { - if($r->award_source_fairs_id){ $cl="class=\"externalaward\""; $hasexternal=true; } else $cl=""; - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - - $numq=mysql_query("SELECT COUNT(id) AS num FROM award_prizes WHERE award_awards_id='$r->id'"); - $numr=mysql_fetch_object($numq); - $numprizes=$numr->num; - - - echo " "; - - echo " \n"; - echo "\n"; - } - if($hasexternal) - echo ""; - echo "
".i18n("Order")."".i18n("Sponsor")."".i18n("Type")."".i18n("Name")."".i18n("Prizes")."".i18n("Actions")."
id]\" value=\"$r->order\" size=\"3\" />$r->organization$r->typeid});\">$r->name"; - echo "$numprizes  "; - echo "id\">\"view\""; - echo ""; - echo "id\">"; - echo " "; - echo "id\">"; - - echo "
".i18n("Indicates award imported from an external source")."
\n"; - echo ""; - echo "
"; - } - echo "
"; - echo "Edit prizes for the generic prize template"; - - } - - send_footer(); +echo ""; +*/ +echo ""; +echo "
"; + +?> +
+ +

+ +" /> + +if($sponsors_id) $where_asi="AND sponsors_id='$sponsors_id'"; +if($award_types_id) $where_ati="AND award_types_id='$award_types_id'"; +// if($award_sponsors_confirmed) $where_asc="AND award_sponsors.confirmed='$award_sponsors_confirmed'"; + +if(!$orderby) $orderby="order"; + +$q=mysql_query("SELECT + award_awards.id, + award_awards.name, + award_awards.order, + award_awards.award_source_fairs_id, + award_types.type, + sponsors.organization + FROM + award_awards, + award_types, + sponsors + WHERE + award_awards.year='{$config['FAIRYEAR']}' + $where_asi + $where_ati + $where_asc + AND award_awards.sponsors_id=sponsors.id + AND award_awards.award_types_id=award_types.id + AND award_types.year='{$config['FAIRYEAR']}' + ORDER BY `$orderby`"); + +echo mysql_error(); + +if(mysql_num_rows($q)) + { + echo ""; + echo ""; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + echo "\n"; + + + $hasexternal=false; + while($r=mysql_fetch_object($q)) { + $cl = ($r->award_source_fairs_id) ? externalaward : ''; + $eh = "style=\"cursor:pointer;\" onclick=\"popup_editor({$r->id});\""; + echo "id}\" >\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + + $numq=mysql_query("SELECT COUNT(id) AS num FROM award_prizes WHERE award_awards_id='{$r->id}'"); + $numr=mysql_fetch_assoc($numq); + echo " "; + + echo " \n"; + echo "\n"; + } + if($hasexternal) + echo ""; + echo "
".i18n("Order")."".i18n("Sponsor")."".i18n("Type")."".i18n("Name")."".i18n("Prizes")."".i18n("Actions")."
id}\" class=\"drag_handle\" style=\"cursor:move; text-align:right;\">{$r->order}{$r->organization}{$r->type}{$r->name}{$numr['num']}"; + echo ""; + echo " "; + echo "id});\" href=\"#\" >"; + + echo "
".i18n("Indicates award imported from an external source")."
\n"; + echo ""; + } + echo "
"; + echo "Edit prizes for the generic prize template"; + + +send_footer(); ?>