diff --git a/admin/award_awards.php b/admin/award_awards.php index 04a64be..7a1a471 100644 --- a/admin/award_awards.php +++ b/admin/award_awards.php @@ -34,8 +34,7 @@ echo json_encode($ret); exit; - -case 'award_create': + 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() ); @@ -193,6 +192,42 @@ case 'award_create': // echo "DELETE FROM award_prizes WHERE id='$id'"; echo happy(i18n("Prize deleted")); exit; + + case 'feeder_load': + $id = intval($_GET['id']); + $ret = array(); + /* Prepare two lists of fair IDs, for which fairs can upload and download this award */ + $q=mysql_query("SELECT * FROM fairs_awards_link WHERE award_awards_id='$id'"); + while($r=mysql_fetch_assoc($q)) { + if($r['download_award'] == 'yes') $ret['dl'][] = $r['fairs_id']; + if($r['upload_winners'] == 'yes') $ret['ul'][] = $r['fairs_id']; + } + echo json_encode($ret); + exit; + + case 'feeder_save': + print_r($_POST); + $id = intval($_POST['award_awards_id']); + $dl = is_array($_POST['feeder_dl']) ? $_POST['feeder_dl'] : array(); + $ul = is_array($_POST['feeder_ul']) ? $_POST['feeder_ul'] : array(); + + /* Prepare a fair-wise list */ + $data = array(); + foreach($dl AS $fairs_id) $data[$fairs_id]['dl'] = true; + foreach($ul AS $fairs_id) $data[$fairs_id]['ul'] = true; + + /* Now save each one */ + mysql_query("DELETE FROM fairs_awards_link WHERE award_awards_id='$id'"); + echo mysql_error(); + foreach($data as $fairs_id=>$f) { + $dl = ($f['dl'] == true) ? 'yes' : 'no'; + $ul = ($f['ul'] == true) ? 'yes' : 'no'; + mysql_query("INSERT INTO fairs_awards_link (award_awards_id,fairs_id,download_award,upload_winners) + VALUES ('$id','$fairs_id','$dl','$ul')"); + echo mysql_error(); + } + alert(happy, "Saved"); + exit; } send_header("Awards Management", @@ -230,7 +265,7 @@ function update_awardinfo() function awardinfo_save() { - $("#awardinfo_info").post("$_SERVER['PHP_SELF']?>?action=awardinfo_save", $("#awardinfo").serialize()); + $("#awardinfo_info").load("$_SERVER['PHP_SELF']?>?action=awardinfo_save", $("#awardinfo").serializeArray()); return 0; } @@ -308,13 +343,13 @@ function edit_prize(id) function eligibility_save() { - $("#eligibility_info").post("$_SERVER['PHP_SELF']?>?action=eligibility_save", $("#eligibility").serialize()); + $("#eligibility_info").load("$_SERVER['PHP_SELF']?>?action=eligibility_save", $("#eligibility").serializeArray()); return 0; } function prize_save() { - $("#prizeinfo_info").post("$_SERVER['PHP_SELF']?>?action=prize_save", $("#prizeinfo").serialize()); + $("#prizeinfo_info").load("$_SERVER['PHP_SELF']?>?action=prize_save", $("#prizeinfo").serializeArray()); update_prizeinfo(); return 0; } @@ -345,6 +380,24 @@ function prize_create() }); } +function update_feeder() +{ + var id = award_id; + $.getJSON("=$_SERVER['PHP_SELF']?>?action=feeder_load&id="+id, + function(json) { + $("#feeder_id").val(id); + $("[name=feeder_dl\\[\\]]").val(json.dl); + $("[name=feeder_ul\\[\\]]").val(json.ul); + }); + +} + +function feeder_save() +{ + $("#feeder_info").load("$_SERVER['PHP_SELF']?>?action=feeder_save", $("#feeder_form").serializeArray()); + return 0; +} + /* Setup the popup window */ $(document).ready(function() { @@ -365,7 +418,10 @@ $(document).ready(function() { break; case 'editor_tab_prizes': update_prizeinfo(); - break; + break; + case 'editor_tab_feeder': + update_feeder(); + break; } }, selected: -1, @@ -384,6 +440,7 @@ $(document).ready(function() {
=("Select which feeder fairs can download this award and upload winners.")?>
+ +