- Database update for feeder fair award info

- Load/Save feeder fair awards in the award editor
- Fix all the POSTs in the award editor.   .load automatically does a POST if
  the data is an array, so we need to call .serializeArray() when we want a
  post to happen.
This commit is contained in:
dave 2009-09-13 07:08:12 +00:00
parent 60146110b2
commit e9d3d4ce03
3 changed files with 103 additions and 8 deletions

View File

@ -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() {
<ul><li><a href="#editor_tab_awardinfo"><span><?=i18n('Award Info')?></span></a></li>
<li><a href="#editor_tab_eligibility"><span><?=i18n('Eligibility')?></span></a></li>
<li><a href="#editor_tab_prizes"><span><?=i18n('Prizes')?></span></a></li>
<li><a href="#editor_tab_feeder"><span><?=i18n('Feeder Fairs')?></span></a></li>
</ul>
<div id="editor_tab_awardinfo">
@ -546,10 +603,38 @@ $(document).ready(function() {
<input type="submit" id="prizeinfo_save" onClick="prize_save();" value="<?=i18n("Save Prize")?>" disabled="disabled" />
</div>
</div>
<? /* Next Tab */ ?>
<div id="editor_tab_feeder">
<div id="feeder_info"></div>
<h4><?=i18n("Feeder Fairs")?></h4>
<p><?=("Select which feeder fairs can download this award and upload winners.")?></p>
<form id="feeder_form">
<input type="hidden" id="feeder_id" name="award_awards_id" value=""/>
<table class="tableview">
<tr><th><?=i18n("Fair")?></th>
<th style="width: 5em"><?=i18n("Download Award")?></th>
<th style="width: 5em"><?=i18n("Upload Winners")?></th>
</tr>
<?
$q = mysql_query("SELECT * FROM fairs WHERE type='feeder'");
while($r = mysql_fetch_assoc($q)) {
echo "<tr><td style=\"padding-left:1em;padding-right:1em\">{$r['name']}</td>";
echo "<td style=\"text-align:center\"><input type=\"checkbox\" id=\"feeder_dl_{$r['id']}\" name=\"feeder_dl[]\" value=\"{$r['id']}\"></td>";
echo "<td style=\"text-align:center\"><input type=\"checkbox\" id=\"feeder_ul_{$r['id']}\" name=\"feeder_ul[]\" value=\"{$r['id']}\"></td>";
echo '</tr>';
}
?>
</table>
</form>
<br />
<input type="submit" onClick="feeder_save();" value="<?=i18n("Save")?>" />
</div>
<? /* End tabs, end popup */ ?>
</div></div>
<?
/* Here's all the code for the award list, except for the AJAX queries which are
* at the top of this file */

View File

@ -1 +1 @@
131
132

10
db/db.update.132.sql Normal file
View File

@ -0,0 +1,10 @@
ALTER TABLE `fairs` DROP `award_awards_ids` ;
CREATE TABLE `fairs_awards_link` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`fairs_id` INT NOT NULL ,
`award_awards_id` INT NOT NULL ,
`download_award` ENUM( 'no', 'yes' ) NOT NULL ,
`upload_winners` ENUM( 'no', 'yes' ) NOT NULL
) ENGINE = MYISAM ;