Add a 'per_fair' option to the awards, so an award can be treated as a

separate award for each feeder fair, allowing the maximum prize
assignments from each fair.
This commit is contained in:
dave 2010-01-27 20:24:17 +00:00
parent 7fc721b96f
commit 7d611e531f
3 changed files with 72 additions and 65 deletions

View File

@ -209,19 +209,62 @@
case 'feeder_load':
$id = intval($_GET['id']);
$ret = array('ul'=>array(), 'dl'=>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'");
$ul = array();
$dl = array();
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'];
if($r['upload_winners'] == 'yes') $ul[$r['fairs_id']] = true;
if($r['download_award'] == 'yes') $dl[$r['fairs_id']] = true;
}
$q = mysql_query("SELECT * FROM award_awards WHERE id='$id'");
$a = mysql_fetch_assoc($q);
$ret['identifier'] = $a['external_identifier'];
$ret['additional_materials'] = $a['external_additional_materials'];
$ret['register_winners'] = $a['external_register_winners'];
echo json_encode($ret);
?>
<h4><?=i18n("Feeder Fairs")?></h4>
<form id="feeder_form">
<input type="hidden" id="feeder_id" name="award_awards_id" value="<?=$a['id']?>"/>
<? $ch = $a['per_fair'] == 'yes' ? 'checked="checked"' : ''; ?>
<p><input type="checkbox" name="per_fair" value="yes" <?=$ch?> />
<?=i18n("Treat this award as a separate award for each feeder fair (instead of as a single award across the whole system). This will allow winners to be assigned to prizes for each feeder fair. If disabled, only a single group if winners will be permitted across all feeder fairs.")?></p>
<? $ch = (count($ul) || count($dl)) ? 'checked="checked"' : ''; ?>
<p><input type="checkbox" id="feeder_enable" name="enable" value="yes" <?=$ch?> />
<?=i18n("Allow feeder fairs to download this award.")?></p>
<div id="feeder_en">
<table class="editor">
<tr><td><?=i18n('Unique Name')?>:</td>
<td><input type="text" name="identifier" value="<?=$a['external_identifier']?>" size="40" maxlength="128" /></td></tr>
<? $ch = $a['external_additional_materials'] ? 'checked="checked"' : ''; ?>
<tr><td><input type="checkbox" name="register_winners" value="1" <?=$ch?> /></td>
<td><?=i18n("Winners uploaded by a feeder fair should be registered as participants at this fair (both download award and upload winners should be turned on below)")?></td></tr>
<? $ch = $a['external_register_winners'] ? 'checked="checked"' : ''; ?>
<tr><td><input type="checkbox" name="additional_materials" value="1" <?=$ch?> /></td>
<td><?=i18n("There is additional material for this award (e.g. forms, instructions). If a feeder fair assigns a winner to this award, they will be told they need to contact this fair to get the additional material.")?></td></tr>
</table>
<p><?=i18n("Select which feeder fairs can download this award and upload winners.")?></p>
<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>";
$ch = $dl[$r['id']] == true ? 'checked="checked"' : '';
echo "<td style=\"text-align:center\"><input type=\"checkbox\" name=\"feeder_dl[]\" value=\"{$r['id']} $ch \"></td>";
$ch = $ul[$r['id']] == true ? 'checked="checked"' : '';
echo "<td style=\"text-align:center\"><input type=\"checkbox\" name=\"feeder_ul[]\" value=\"{$r['id']} $ch \"></td>";
echo '</tr>';
}
?>
</table>
</div>
<br />
<button id="feeder_save"><?=i18n("Save")?></button>
</form>
<?
exit;
case 'feeder_save':
@ -247,11 +290,14 @@
echo mysql_error();
}
$ident=mysql_escape_string(stripslashes($_POST['identifier']));
$per_fair = $_POST['per_fair'] == 'yes' ? 'yes' : 'no';
$mat = intval($_POST['additional_materials']);
$w = intval($_POST['register_winners']);
mysql_query("UPDATE award_awards SET external_identifier='$ident',
external_additional_materials='$mat',
external_register_winners='$w' WHERE id='$id'");
external_register_winners='$w',
per_fair='$per_fair'
WHERE id='$id'");
happy_("Feeder Fair information saved");
exit;
@ -479,19 +525,18 @@ function update_feeder()
{
if(award_tab_update['feeder'] == award_id) return;
award_tab_update['feeder'] = award_id;
$.getJSON("<?=$_SERVER['PHP_SELF']?>?action=feeder_load&id="+award_id,
function(json) {
$("#feeder_id").val(award_id);
$("#feeder_identifier").val(json.identifier);
$("#feeder_additional_materials").val([json.additional_materials]);
$("#feeder_register_winners").val([json.register_winners]);
$("[name=feeder_dl\\[\\]]").val(json.dl);
$("[name=feeder_ul\\[\\]]").val(json.ul);
if(json.dl.length == 0 && json.ul.length == 0)
$('#feeder_enable').val([]);
else
$('#feeder_enable').val(['yes']);
$("#editor_tab_feeder").load("<?=$_SERVER['PHP_SELF']?>?action=feeder_load&id="+award_id, '',
function(responseText, textStatus, XMLHttpRequest) {
/* Register buttons and handlers */
$("#feeder_enable").change(function() {
update_feeder_enable();
});
$("#feeder_save").click(function() {
$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=feeder_save", $("#feeder_form").serializeArray());
return false;
});
update_feeder_enable();
});
}
@ -500,20 +545,13 @@ function update_feeder_enable()
{
var checked = $('#feeder_enable:checkbox').is(':checked');
if(checked==true) {
$('#feeder_form *').removeAttr('disabled');
$('#feeder_en *').removeAttr('disabled');
} else {
$("#feeder_form *").attr('disabled', 'disabled');
$("#feeder_en *").attr('disabled', 'disabled');
$('#feeder_enable').removeAttr('disabled');
}
}
function feeder_save()
{
$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=feeder_save", $("#feeder_form").serializeArray());
return false;
}
/* Setup the popup window */
$(document).ready(function() {
$("#popup_editor").dialog({
@ -733,41 +771,7 @@ $(document).ready(function() {
</div>
<? /* Next Tab */ ?>
<div id="editor_tab_feeder">
<h4><?=i18n("Feeder Fairs")?></h4>
<form id="feeder_form">
<input type="hidden" id="feeder_id" name="award_awards_id" value=""/>
<p><input type="checkbox" id="feeder_enable" name="enable" value="yes" onchange="update_feeder_enable()" />
<?=i18n("Allow feeder fairs to download this award.")?></p>
<table class="editor">
<tr><td><?=i18n('Unique Name')?>:</td>
<td><input type="text" id="feeder_identifier" name="identifier" value="" size="40" maxlength="128" /></td></tr>
<tr><td><input type="checkbox" id="feeder_register_winners" name="register_winners" value="1" /></td>
<td><?=i18n("Winners uploaded by a feeder fair should be registered as participants at this fair (both download award and upload winners should be turned on below)")?></td></tr>
<tr><td><input type="checkbox" id="feeder_additional_materials" name="additional_materials" value="1" /></td>
<td><?=i18n("There is additional material for this award (e.g. forms, instructions). If a feeder fair assigns a winner to this award, they will be told they need to contact this fair to get the additional material.")?></td></tr>
</table>
<p><?=i18n("Select which feeder fairs can download this award and upload winners.")?></p>
<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>
<br />
<input type="submit" onClick="feeder_save();return false;" value="<?=i18n("Save")?>" />
</form>
</div>
<div id="editor_tab_feeder"></div>
<? /* End tabs, end popup */ ?>
</div></div>

View File

@ -1 +1 @@
156
157

3
db/db.update.157.sql Normal file
View File

@ -0,0 +1,3 @@
ALTER TABLE `award_awards` ADD `per_fair` ENUM( 'no', 'yes' ) NOT NULL ;