Support Multiple uploads for SFIAB targets

This commit is contained in:
dave 2010-04-18 22:39:55 +00:00
parent 14df5adc39
commit a5a431605a

View File

@ -27,7 +27,7 @@ require_once('curl.inc.php');
user_auth_required('committee', 'admin');
//function get_cwsf_award_winners()
function get_winners($awardid, $catmap_str=NULL, $divmap_str=NULL)
function get_winners($awardid, $fairs_id, $catmap_str=NULL, $divmap_str=NULL)
{
global $config;
@ -65,7 +65,18 @@ function get_winners($awardid, $catmap_str=NULL, $divmap_str=NULL)
'teacheremail'=>'teacheremail');
$awards = array();
if($awardid == -1) {
/* Get all for this fair */
$q=mysql_query("SELECT * FROM award_awards WHERE award_source_fairs_id='$fairs_id' AND year='{$config['FAIRYEAR']}'");
if(mysql_num_rows($q) == 0) {
error_("Can't find award id $awardid");
return false;
}
while($a = mysql_fetch_assoc($q)) {
$awards[] = $a;
}
} else {
/* Get the award */
$q=mysql_query("SELECT * FROM award_awards WHERE id='$awardid' AND year='{$config['FAIRYEAR']}'");
if(mysql_num_rows($q)!=1) {
@ -73,17 +84,26 @@ function get_winners($awardid, $catmap_str=NULL, $divmap_str=NULL)
return false;
}
$award=mysql_fetch_assoc($q);
$awards[] = $award;
}
/* Get the fair for the div/cat mappings */
$q = mysql_query("SELECT * FROM fairs WHERE id='{$award['award_source_fairs_id']}'");
$fair = mysql_fetch_assoc($q);
$catmap = unserialize(($catmap_str != NULL) ? $catmap_str : $fair['catmap']);
$divmap = unserialize(($divmap_str != NULL) ? $divmap_str : $fair['divmap']);
$catmap = unserialize($fair['catmap']);
$divmap = unserialize($fair['divmap']);
$winners=array( 'prizes' => array(),
'award_name' => $award['name'],
foreach($awards as $award) {
$winners=array( 'award_name' => $award['name'],
'external_identifier' => $award['external_identifier'],
'external_postback' => $award['external_postback']);
'year' => $config['FAIRYEAR'],
'prizes' => array());
if($fair['type'] != 'sfiab') {
/* YSC Compatability */
$winners['external_postback'] = $award['external_postback'];
}
/* Get the prizes */
$q=mysql_query("SELECT * FROM award_prizes WHERE award_awards_id='{$award['id']}'");
@ -143,25 +163,46 @@ function get_winners($awardid, $catmap_str=NULL, $divmap_str=NULL)
'identifier'=>$prize['external_identifier'], /* for ysc compatability */
'projects'=>$prizewinners);
}
return $winners;
$all_winners[] = $winners;
}
return $all_winners;
}
switch($_GET['action']) {
case 'award_upload':
$award_awards_id = intval($_GET['id']);
$winners = get_winners($award_awards_id);
$fairs_id = intval($_GET['fairs_id']);
$all_winners = get_winners($award_awards_id, $fairs_id);
/* Get the fair */
$q = mysql_query("SELECT award_source_fairs_id FROM award_awards WHERE id='$award_awards_id'");
$a = mysql_fetch_assoc($q);
$q = mysql_query("SELECT * FROM fairs WHERE id='{$a['award_source_fairs_id']}'");
$q = mysql_query("SELECT * FROM fairs WHERE id='$fairs_id}'");
$fair = mysql_fetch_assoc($q);
echo '<br />';
if($winners == false) {
echo notice(i18n('No winners selected for this award'));
} else {
/* Check that we're going to upload something */
$upload_something = false;
foreach($all_winners as $w) {
foreach($w['prizes'] as $p) {
if(count($p['projects'])) {
$upload_something = true;
break;
}
}
}
if($upload_something == false) {
echo notice(i18n('No winners to be uploaded'));
exit;
}
if($fair['type'] == 'ysc') {
if($award_awards_id == -1) {
echo "Multiple uploads not supported for YSC targets.\n";
exit;
}
/* Pull the single-award out, get_winners() will never
* return more than one award for YSC targets */
$winners = array_shift($all_winners);
$w = array();
foreach($winners['prizes'] as $prize_name=>$prize) {
$w[] = $prize;
@ -175,12 +216,12 @@ case 'award_upload':
);
$url = $winners['external_postback'];
} else {
$req = array('award_upload' => $winners);
$req['award_upload']['year'] = $config['FAIRYEAR'];
$req = array();
$req['awards_upload'] = $all_winners;
$url = ''; /* url is ignored for type = sfiab */
}
echo i18n("Sending %1 winners to %2...", array('<b>'.$winners['award_name'].'</b>',
'<b>'.$fair['name'].'</b>'));
echo i18n("Sending winners to %1...", array('<b>'.$fair['name'].'</b>'));
echo '<br />';
// echo "<pre>"; print_r($req); echo "</pre>";
@ -193,15 +234,14 @@ case 'award_upload':
echo notice("{$fair['name']} server said: <pre>".join("\n", $data['notice'])."</pre>");
else if(is_array($data['message']))
echo notice("{$fair['name']} server said: <pre>".join("\n", $data['message'])."</pre>");
else if($data['message']) {
else if($data['message'])
echo notice("{$fair['name']} server said: <pre>".$data['message']."</pre>");
}
else
echo notice("{$fair['name']} server said: <pre>".htmlspecialchars(print_r($data,true))."</pre>");
echo happy(i18n("Upload completed successfully"));
}
}
exit;
case 'catdiv_load':
$fairs_id = intval($_GET['id']);
$q = mysql_query("SELECT * FROM fairs WHERE id='$fairs_id'");
@ -277,7 +317,8 @@ case 'catdiv_save':
case 'confirm_load':
$award_awards_id = intval($_GET['id']);
$winners = get_winners($award_awards_id);
$fairs_id = intval($_GET['fairs_id']);
$winners = get_winners($award_awards_id, $fairs_id);
print_r($winners);
exit;
@ -340,7 +381,7 @@ function catdiv_load()
}
function award_upload(id)
{
$("#award_upload_status").load("<?=$_SERVER['PHP_SELF']?>?action=award_upload&id="+id);
$("#award_upload_status").load("<?=$_SERVER['PHP_SELF']?>?action=award_upload&id="+id+"&fairs_id="+fairs_id);
}
function catdiv_save()
@ -360,7 +401,7 @@ function catdiv_next()
function confirm_load()
{
$("#confirm_data").load("<?=$_SERVER['PHP_SELF']?>?action=confirm_load&id="+award_awards_id);
$("#confirm_data").load("<?=$_SERVER['PHP_SELF']?>?action=confirm_load&id="+award_awards_id+"&fairs_id="+fairs_id);
}
function confirm_upload()
@ -465,7 +506,6 @@ $(document).ready(function() {
echo "<option value=\"-1\">Loading...</option>";
echo '</select></td></tr>';
}
/* <input type="submit" onClick="catdiv_save();return false;" value="<?=i18n("Save")?>" /></td>*/
?>
</table>
<br />
@ -498,6 +538,7 @@ $(document).ready(function() {
</div></div>
<?
@ -508,6 +549,44 @@ if(!function_exists('curl_init')) {
exit;
}
/* Fairs first */
$q = mysql_query("SELECT fairs.id, fairs.name, fairs.type, COUNT(award_awards.id) as AWARD_COUNT FROM fairs
LEFT JOIN award_awards ON award_awards.award_source_fairs_id=fairs.id
WHERE award_awards.award_source_fairs_id IS NOT NULL
AND award_awards.year='{$config['FAIRYEAR']}'
GROUP BY fairs.id
ORDER BY fairs.name ");
echo mysql_error();
?>
<h4><?=i18n('Upload all winners to a source')?>:</h4>
<table class="tableview"><thead>
<tr><th><?=i18n("Source Name")?></th>
<th><?=i18n("Number of Awards")?></th>
<th><?=i18n("Send All")?></th>
</tr></thead>
<?
while($r=mysql_fetch_object($q)) {
echo "<tr><td>{$r->name}</td>\n";
echo "<td>{$r->AWARD_COUNT}</td>";
echo "<td align=\"center\">";
if($r->type == 'sfiab')
echo "<a href=\"#\" onClick=\"popup_upload({$r->id},-1)\" >".i18n("Send All")."</a>";
else
echo "Not available yet, we're working on it!";
echo "</td></tr>";
}
?>
</table>
<br />
<br />
<?
$q = mysql_query("SELECT award_awards.id, award_awards.name AS awardname,
fairs.name as fairname, award_source_fairs_id,
fairs.type as fairtype, award_awards.external_additional_materials
@ -519,6 +598,7 @@ $q = mysql_query("SELECT award_awards.id, award_awards.name AS awardname,
echo mysql_error();
?>
<h4><?=i18n('Upload individual winners to a source')?>:</h4>
<table class="tableview"><thead>
<tr><th><?=i18n("Award Name")?></th>