2005-05-04 21:23:00 +00:00
< ?
2025-01-29 03:30:48 +00:00
/*
* This file is part of the Science - ation project
* Science - ation Website : https :// science - ation . ca
*
* This file was part of the 'Science Fair In A Box' project
*
*
* Copyright ( C ) 2005 Sci - Tech Ontario Inc < info @ scitechontario . org >
* Copyright ( C ) 2005 James Grant < james @ lightbox . org >
* Copyright ( C ) 2024 AlgoLibre Inc . < science - ation @ algolibre . io >
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation , version 2.
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; see the file COPYING . If not , write to
* the Free Software Foundation , Inc . , 59 Temple Place - Suite 330 ,
* Boston , MA 02111 - 1307 , USA .
*/
2005-05-04 21:23:00 +00:00
?>
< ?
2025-01-29 03:30:48 +00:00
require_once ( '../common.inc.php' );
require_once ( '../user.inc.php' );
require_once ( '../projects.inc.php' );
require_once ( '../fair_additional_materials.inc.php' );
2010-01-28 19:05:35 +00:00
2025-01-29 03:30:48 +00:00
$auth_type = user_auth_required ( array ( 'fair' , 'committee' ), 'admin' );
2010-01-27 20:24:19 +00:00
2025-01-29 03:30:48 +00:00
$award_awards_id = intval ( get_value_from_array ( $_GET , 'award_awards_id' ));
$action = get_value_from_array ( $_GET , 'action' );
2010-01-27 20:24:19 +00:00
/* Load fairs */
$fairs = array ();
2025-01-29 03:30:48 +00:00
$q = $pdo -> prepare ( " SELECT * FROM fairs WHERE type='feeder' ORDER BY name " );
2024-11-27 10:47:41 -05:00
$q -> execute ();
2025-01-29 03:30:48 +00:00
while (( $f = $q -> fetch ( PDO :: FETCH_ASSOC ))) {
2010-01-27 20:24:19 +00:00
$fairs [ $f [ 'id' ]] = $f ;
}
2005-05-04 21:23:00 +00:00
2025-01-29 03:30:48 +00:00
switch ( $action ) {
case 'addwinner' :
$prize_id = intval ( $_GET [ 'prize_id' ]);
$projects_id = intval ( $_GET [ 'projects_id' ]);
2005-05-04 21:23:00 +00:00
2025-01-29 03:30:48 +00:00
if ( ! $prize_id || ! $projects_id ) {
error_ ( 'Illegal Assignment' );
exit ;
}
2005-05-04 21:23:00 +00:00
2025-01-29 03:30:48 +00:00
// first check how many we are allowed to have
$q = $pdo -> prepare ( " SELECT number FROM award_prizes WHERE id=' $prize_id ' " );
$q -> execute ();
show_pdo_errors_if_any ( $pdo );
$r = $q -> fetch ( PDO :: FETCH_ASSOC );
$number = $r [ 'number' ];
2005-05-04 21:23:00 +00:00
2025-01-29 03:30:48 +00:00
/* Get the award info */
$q = $pdo -> prepare ( " SELECT * FROM award_awards WHERE id=' $award_awards_id ' " );
$q -> execute ();
show_pdo_errors_if_any ( $pdo );
$a = $q -> fetch ( PDO :: FETCH_ASSOC );
2010-01-27 20:24:19 +00:00
2025-01-29 03:30:48 +00:00
/* Get the project */
$q = $pdo -> prepare ( " SELECT fairs_id FROM projects WHERE id=' $projects_id ' " );
$q -> execute ();
show_pdo_errors_if_any ( $pdo );
$p = $q -> fetch ( PDO :: FETCH_ASSOC );
$fairs_id = $p [ 'fairs_id' ];
/*
* Quick sanity check don ' t let a fair user do an assignment for someone not
* in their fair
*/
if ( $auth_type == 'fair' && $fairs_id != $_SESSION [ 'fairs_id' ]) {
error_ ( 'Illegal Assignemnt' );
exit ;
}
2005-05-04 21:23:00 +00:00
2025-01-29 03:30:48 +00:00
if ( $a [ 'per_fair' ] == 'yes' ) {
/* Count is the number of this fair already assigned */
$q = $pdo -> prepare ( " SELECT COUNT(*) AS count FROM winners
2010-01-27 20:24:19 +00:00
LEFT JOIN projects ON winners . projects_id = projects . id
WHERE
projects . fairs_id = '$fairs_id'
awards_prizes_id = '$prize_id' " );
2025-01-29 03:30:48 +00:00
$q -> execute ();
show_pdo_errors_if_any ( $pdo );
$r = $q -> fetch ( PDO :: FETCH_ASSOC );
$count = $r [ 'count' ];
} else {
/* Count is the total number assigned */
$q = $pdo -> prepare ( " SELECT COUNT(*) AS count FROM winners WHERE awards_prizes_id=' $prize_id ' " );
$q -> execute ();
show_pdo_errors_if_any ( $pdo );
$r = $q -> fetch ( PDO :: FETCH_ASSOC );
$count = $r [ 'count' ];
}
2005-05-04 21:23:00 +00:00
2025-01-29 03:30:48 +00:00
if ( $count < $number ) {
$stmt = $pdo -> prepare ( " INSERT INTO winners (awards_prizes_id,projects_id,year) VALUES (' $prize_id ',' $projects_id ',' { $config [ 'FAIRYEAR' ] } ') " );
$stmt -> execute ();
happy_ ( 'Winning project added' );
} else {
error_ ( 'This prize cannot accept any more winners. Maximum: %1' , $number );
}
2005-05-04 21:23:00 +00:00
2025-01-29 03:30:48 +00:00
exit ;
2010-01-27 20:24:19 +00:00
2025-01-29 03:30:48 +00:00
case 'deletewinner' :
$prize_id = intval ( $_GET [ 'prize_id' ]);
$projects_id = intval ( $_GET [ 'projects_id' ]);
2010-01-27 20:24:19 +00:00
2025-01-29 03:30:48 +00:00
if ( $prize_id && $projects_id ) {
$stmt = $pdo -> prepare ( " DELETE FROM winners WHERE awards_prizes_id=' $prize_id ' AND projects_id=' $projects_id ' " );
$stmt -> execute ();
happy_ ( 'Winning project removed' );
}
exit ;
case 'award_load' :
$fairs_id = intval ( $_GET [ 'fairs_id' ]);
/* Load the award */
$q = $pdo -> prepare ( " SELECT
2010-01-27 20:24:19 +00:00
award_awards . id ,
award_awards . name ,
award_awards . criteria ,
award_awards . order AS awards_order ,
award_awards . per_fair ,
2010-01-28 19:05:35 +00:00
award_awards . external_additional_materials ,
2010-01-31 22:07:14 +00:00
award_awards . award_source_fairs_id ,
2010-01-27 20:24:19 +00:00
award_types . type
FROM
award_awards ,
award_types
WHERE
award_awards . year = '{$config[' FAIRYEAR ']}'
2025-01-29 03:30:48 +00:00
AND \taward_awards . award_types_id = award_types . id
AND \taward_types . year = award_awards . year
AND \taward_awards . id = '$award_awards_id'
2010-01-27 20:24:19 +00:00
" );
2025-01-29 03:30:48 +00:00
$q -> execute ();
2005-05-04 21:23:00 +00:00
2025-01-29 03:30:48 +00:00
show_pdo_errors_if_any ( $pdo );
2010-01-27 20:24:19 +00:00
2025-01-29 03:30:48 +00:00
if ( $q -> rowCount () != 1 ) {
echo i18n ( " Invalid award to load $award_awards_id " );
exit ;
}
$r = $q -> fetch ( PDO :: FETCH_ASSOC );
print_award ( $r , $fairs_id );
2010-01-27 20:24:19 +00:00
exit ;
2007-11-18 23:50:23 +00:00
2025-01-29 03:30:48 +00:00
case 'edit_load' :
$fairs_id = intval ( $_GET [ 'fairs_id' ]);
/* Force the fair user to only edit their fair */
// if($auth_type == 'fair') $fairs_id = $_SESSION['fairs_id'];
2010-01-27 20:24:19 +00:00
2025-01-29 03:30:48 +00:00
/* Load the award */
$q = $pdo -> prepare ( " SELECT
2005-05-04 21:23:00 +00:00
award_awards . id ,
award_awards . name ,
2007-01-30 07:45:12 +00:00
award_awards . criteria ,
2005-05-04 21:23:00 +00:00
award_awards . order AS awards_order ,
2010-01-27 20:24:19 +00:00
award_awards . per_fair ,
2010-01-28 19:05:35 +00:00
award_awards . external_additional_materials ,
2010-01-31 22:07:14 +00:00
award_awards . award_source_fairs_id ,
2005-05-04 21:23:00 +00:00
award_types . type
FROM
2010-01-27 20:24:19 +00:00
award_awards ,
2005-05-04 21:23:00 +00:00
award_types
WHERE
2010-01-27 20:24:19 +00:00
award_awards . year = '{$config[' FAIRYEAR ']}'
2025-01-29 03:30:48 +00:00
AND \taward_awards . award_types_id = award_types . id
AND \taward_types . year = award_awards . year
AND \taward_awards . id = '$award_awards_id'
2005-05-04 21:23:00 +00:00
" );
2025-01-29 03:30:48 +00:00
$q -> execute ();
2010-01-27 20:24:19 +00:00
2025-01-29 03:30:48 +00:00
show_pdo_errors_if_any ( $pdo );
2005-05-04 21:23:00 +00:00
2025-01-29 03:30:48 +00:00
if ( $q -> rowCount () != 1 ) {
echo i18n ( " Invalid award to edit $award_awards_id " );
exit ;
}
2010-01-27 20:24:19 +00:00
2025-01-29 03:30:48 +00:00
$r = $q -> fetch ( PDO :: FETCH_ASSOC );
2010-01-27 20:24:19 +00:00
2025-01-29 03:30:48 +00:00
$editor_data = array ();
2010-01-27 20:24:19 +00:00
2025-01-29 03:30:48 +00:00
/* Load projects */
if ( $r [ 'type' ] == 'Special' ) {
$editor_data [ 'projects_nominated' ] = getProjectsNominatedForSpecialAward ( $r [ 'id' ]);
$editor_data [ 'disable_nominated' ] = false ;
} else {
$editor_data [ 'projects_nominated' ] = array ();
$editor_data [ 'disable_nominated' ] = true ;
}
$editor_data [ 'projects_eligible' ] = getProjectsEligibleForAward ( $r [ 'id' ]);
2010-01-28 19:05:35 +00:00
2025-01-29 03:30:48 +00:00
/* Print the award header */
echo '<br />' ;
if ( $fairs_id )
echo '<h4>' . i18n ( 'Winners from' ) . " : { $fairs [ $fairs_id ][ 'name' ] } </h4> " ;
echo " <b> { $r [ 'type' ] } - { $r [ 'name' ] } </b><br /> " ;
echo " { $r [ 'criteria' ] } <br /> " ;
2010-01-28 19:05:35 +00:00
2025-01-29 03:30:48 +00:00
/* Print the award with editor */
print_award ( $r , $fairs_id , true , $editor_data );
2010-01-28 19:05:35 +00:00
exit ;
2025-01-29 03:30:48 +00:00
case 'additional_materials' :
$fairs_id = intval ( $_GET [ 'fairs_id' ]);
$q = $pdo -> prepare ( " SELECT * FROM award_awards WHERE id=' $award_awards_id ' " );
$q -> execute ();
if ( $fairs_id == 0 ) {
echo " Unsupported Action: Can't get additional materials for fairs_id=0. Edit the project and set it's fair to anything except 'Local/Unspecified'. " ;
exit ;
}
$a = $q -> fetch ( PDO :: FETCH_ASSOC );
$q = $pdo -> prepare ( " SELECT * FROM fairs WHERE id=' $fairs_id ' " );
$q -> execute ();
$fair = $q -> fetch ( PDO :: FETCH_ASSOC );
$pdf = fair_additional_materials ( $fair , $a , $config [ 'FAIRYEAR' ]);
foreach ( $pdf [ 'header' ] as $h )
header ( $h );
echo $pdf [ 'data' ];
exit ;
2010-01-27 20:24:19 +00:00
}
2025-01-29 03:30:48 +00:00
if ( $auth_type == 'fair' ) {
send_header ( 'Enter Winning Projects' ,
2010-01-27 20:24:19 +00:00
array ( 'Science Fair Main' => 'fair_main.php' ),
2025-01-29 03:30:48 +00:00
'enter_winning_projects' );
2010-01-27 20:24:19 +00:00
} else {
2025-01-29 03:30:48 +00:00
send_header ( 'Enter Winning Projects' ,
2010-01-27 20:24:19 +00:00
array ( 'Committee Main' => 'committee_main.php' ,
'Administration' => 'admin/index.php' ),
2025-01-29 03:30:48 +00:00
'enter_winning_projects' );
2010-01-27 20:24:19 +00:00
}
?>
< div id = " winner_editor " title = " Edit Winners " style = " display: none " >
< div id = " winner_content " ></ div >
</ div >
< script language = " javascript " type = " text/javascript " >
var award_awards_id = 0 ;
var fairs_id = 0 ;
function update_winner_content ()
{
2025-01-29 03:30:48 +00:00
$ ( " #winner_content " ) . load ( " <?= $_SERVER['PHP_SELF'] ?>?action=edit_load&award_awards_id= " + award_awards_id + " &fairs_id= " + fairs_id ,{},
2010-01-27 20:24:19 +00:00
function ( responseText , textStatus , XMLHttpRequest ) {
/* Attach to save button */
$ ( " #project_save " ) . click ( function () {
var id = award_awards_id ;
$ ( " #debug " ) . load ( " project_editor.php?action=save&award_awards_id= " + id , $ ( " #project_form " ) . serializeArray ());
});
2005-05-12 19:06:12 +00:00
}
2010-01-27 20:24:19 +00:00
);
}
function popup_editor ( id , fid )
{
var w = ( document . documentElement . clientWidth * 0.9 );
var h = ( document . documentElement . clientHeight * 0.9 );
award_awards_id = id ;
fairs_id = fid ;
/* Show the dialog */
$ ( '#winner_editor' ) . dialog ( 'option' , 'width' , w );
$ ( '#winner_editor' ) . dialog ( 'option' , 'height' , h );
$ ( " #winner_editor " ) . dialog ( 'open' );
update_winner_content ();
return true ;
}
function delete_winner ( prize_id , projects_id )
{
2025-01-29 03:30:48 +00:00
var conf = confirm ( " <?= i18n('Are you sure you want to remove this project from this prize?') ?> " );
2010-01-27 20:24:19 +00:00
if ( conf == false ) return false ;
2025-01-29 03:30:48 +00:00
$ ( " #debug " ) . load ( " <?= $_SERVER['PHP_SELF'] ?>?action=deletewinner&award_awards_id= " + award_awards_id + " &prize_id= " + prize_id + " &projects_id= " + projects_id ,{},
2010-01-27 20:24:19 +00:00
function ( responseText , textStatus , XMLHttpRequest ) {
update_winner_content ();
2005-05-04 21:23:00 +00:00
}
2010-01-27 20:24:19 +00:00
);
}
2005-05-04 21:23:00 +00:00
2010-01-27 20:24:19 +00:00
function add_winner ( prize_id )
{
var projects_id ;
if ( $ ( " #nom_ " + prize_id ) . hasClass ( 'text-link-selected' )) {
projects_id = $ ( " #projects_select_ " + prize_id + " _nom " ) . val ();
} else {
projects_id = $ ( " #projects_select_ " + prize_id + " _eli " ) . val ();
}
2025-01-29 03:30:48 +00:00
$ ( " #debug " ) . load ( " <?= $_SERVER['PHP_SELF'] ?>?action=addwinner&award_awards_id= " + award_awards_id + " &prize_id= " + prize_id + " &projects_id= " + projects_id ,{},
2010-01-27 20:24:19 +00:00
function ( responseText , textStatus , XMLHttpRequest ) {
update_winner_content ();
}
);
}
2005-05-04 21:23:00 +00:00
2010-01-27 20:24:19 +00:00
function unlist_winner ( projects_id )
{
$ ( " .projects_select option[value=' " + projects_id + " '] " ) . remove ();
}
2005-05-04 21:23:00 +00:00
2010-01-27 20:24:19 +00:00
function set_nom ( prize_id )
{
/* Don't try anything if this is already selected */
if ( $ ( " #nom_ " + prize_id ) . hasClass ( 'text-link-selected' )) return false ;
/* If nominated link is disabled, set all-eligible instead */
if ( $ ( " #nom_ " + prize_id ) . hasClass ( 'text-link-disabled' )) return set_eli ( prize_id );
/* Populate List */
$ ( " #projects_select_ " + prize_id + " _eli " ) . css ( 'display' , 'none' );
$ ( " #projects_select_ " + prize_id + " _nom " ) . css ( 'display' , 'inline' );
/* This was brilliant , but we need to filter select boxes by fairs_id in some cases ,
* so keeping a master copy and duplicating it just didn ' t work : (
* Actually , we can do this now , but the code works the other way , so i ' m not going
* to change it back . : p */
/* $ ( " #projects_select_ " + prize_id ) . val ( '' );
$ ( " #projects_select_ " + prize_id ) . html ( '' );
$ ( " #projects_nominated > option " ) . clone () . appendTo ( " #projects_select_ " + prize_id ); */
/* Swap selected styles */
$ ( " #nom_ " + prize_id ) . addClass ( 'text-link-selected' );
$ ( " #eli_ " + prize_id ) . removeClass ( 'text-link-selected' );
}
2005-05-04 21:23:00 +00:00
2010-01-27 20:24:19 +00:00
function set_eli ( prize_id )
{
/* Don't try anything if this is already selected */
if ( $ ( " #eli_ " + prize_id ) . hasClass ( 'text-link-selected' )) {
return false ;
2005-05-04 21:23:00 +00:00
}
2010-01-27 20:24:19 +00:00
/* Populate List */
$ ( " #projects_select_ " + prize_id + " _eli " ) . css ( 'display' , 'inline' );
$ ( " #projects_select_ " + prize_id + " _nom " ) . css ( 'display' , 'none' );
/* Swap selected styles */
$ ( " #nom_ " + prize_id ) . removeClass ( 'text-link-selected' );
$ ( " #eli_ " + prize_id ) . addClass ( 'text-link-selected' );
2005-05-04 21:23:00 +00:00
}
2010-01-27 20:24:19 +00:00
$ ( document ) . ready ( function () {
$ ( " #winner_editor " ) . dialog ({
bgiframe : true , autoOpen : false ,
modal : true , resizable : false ,
draggable : false ,
buttons : {
2025-01-29 03:30:48 +00:00
/* " <?= i18n('Cancel') ?> " : function () {
2010-01-27 20:24:19 +00:00
$ ( this ) . dialog ( " close " );
},
2025-01-29 03:30:48 +00:00
" <?= i18n('Save') ?> " : function () {
2010-01-27 20:24:19 +00:00
save_report ();
$ ( this ) . dialog ( " close " ); */
2025-01-29 03:30:48 +00:00
" <?= i18n('Close') ?> " : function () {
2010-01-27 20:24:19 +00:00
// save_report();
$ ( this ) . dialog ( " close " );
}
},
close : function () {
/* Reload the row after the dialog close in case the info has changed */
2025-01-29 03:30:48 +00:00
$ ( " #winner_list_ " + award_awards_id + " _ " + fairs_id ) . load ( " <?= $_SERVER['PHP_SELF'] ?>?action=award_load&award_awards_id= " + award_awards_id + " &fairs_id= " + fairs_id );
2010-01-27 20:24:19 +00:00
}
});
});
</ script >
< ?
$fair_join = '' ;
$fair_where = '' ;
2025-01-29 03:30:48 +00:00
if ( $auth_type == 'fair' ) {
/*
* Join to fairs_award_link , and only list awards that are set
* as " upload winners " for this fair
*/
2010-01-27 20:24:19 +00:00
$fair_join = 'LEFT JOIN fairs_awards_link ON fairs_awards_link.award_awards_id=award_awards.id' ;
$fair_where = " AND fairs_awards_link.upload_winners='yes'
AND fairs_awards_link . fairs_id = '{$_SESSION[' fairs_id ']}' " ;
}
2024-11-27 10:47:41 -05:00
$q = $pdo -> prepare ( " SELECT
2010-01-27 20:24:19 +00:00
award_awards . id ,
award_awards . name ,
award_awards . order AS awards_order ,
award_awards . per_fair ,
2010-01-28 19:05:35 +00:00
award_awards . external_additional_materials ,
2010-01-31 22:07:14 +00:00
award_awards . award_source_fairs_id ,
2010-01-27 20:24:19 +00:00
award_types . type ,
sponsors . organization
FROM
award_awards $fair_join ,
award_types ,
sponsors
WHERE
award_awards . year = '{$config[' FAIRYEAR ']}'
2025-01-29 03:30:48 +00:00
AND \taward_awards . award_types_id = award_types . id
AND \taward_types . year = '{$config[' FAIRYEAR ']}'
AND \taward_awards . sponsors_id = sponsors . id
2010-01-27 20:24:19 +00:00
$fair_where
ORDER BY awards_order " );
2025-01-02 10:54:18 -05:00
$q -> execute ();
2010-01-27 20:24:19 +00:00
2025-01-02 10:54:18 -05:00
show_pdo_errors_if_any ( $pdo );
2010-01-27 20:24:19 +00:00
2025-01-29 03:30:48 +00:00
if ( $q -> rowCount () == 0 ) {
2010-01-27 20:24:19 +00:00
echo i18n ( 'No awards to display.' );
send_footer ();
exit ;
}
2025-01-29 03:30:48 +00:00
echo '<br />' ;
echo i18n ( 'Choose an award to assign winners' );
echo '<br />' ;
echo '<br />' ;
2010-01-27 20:24:19 +00:00
$fairs_id = ( $auth_type == 'fair' ) ? $_SESSION [ 'fairs_id' ] : 0 ;
2025-01-29 03:30:48 +00:00
while ( $r = $q -> fetch ( PDO :: FETCH_ASSOC )) {
if ( $r [ 'per_fair' ] == 'yes' && $auth_type != 'fair' ) {
?> <?= $r['type'] ?> - <?= $r['name'] ?>
< span style = " font-size: 0.8em; font-style: italic; " > ( < ? = $r [ 'organization' ] ?> )</span><br />
2010-01-27 20:24:19 +00:00
< ?
2025-01-29 03:30:48 +00:00
foreach ( $fairs as $fid => $f ) {
?> <a title="<?= i18n('Edit winners for this award') ?>" href="#" onClick="popup_editor(<?= $r['id'] ?>,<?= $f['id'] ?>);return false;">
< ? = $f [ 'name' ] ?> </a><br />
< div id = " winner_list_<?= $r['id'] ?>_<?= $fid ?> " >
2010-01-27 20:24:19 +00:00
2025-01-29 03:30:48 +00:00
< ?
print_award ( $r , $f [ 'id' ]);
echo '</div>' ;
2010-01-27 20:24:19 +00:00
}
} else {
2025-01-29 03:30:48 +00:00
?> <a title="<?= i18n('Edit winners for this award') ?>" href="#" onClick="popup_editor(<?= $r['id'] ?>,<?= $fairs_id ?>);return false;">
< ? = $r [ 'type' ] ?> - <?= $r['name'] ?></a>
< span style = " font-size: 0.8em; font-style: italic; " > ( < ? = $r [ 'organization' ] ?> )</span><br />
< div id = " winner_list_<?= $r['id'] ?>_<?= $fairs_id ?> " >
< ?
print_award ( $r , $fairs_id );
echo '</div>' ;
2010-01-27 20:24:19 +00:00
}
echo '<br />' ;
}
2025-01-29 03:30:48 +00:00
function print_award ( & $r , $fairs_id , $editor = false , $editor_data = array ())
2005-05-04 21:23:00 +00:00
{
2010-01-27 20:24:19 +00:00
global $config , $auth_type ;
2025-01-05 16:04:50 -05:00
global $pdo ;
2010-01-27 20:24:19 +00:00
2025-01-29 03:30:48 +00:00
// echo "fair=$fairs_id";
2010-01-27 20:24:19 +00:00
2025-01-29 03:30:48 +00:00
/*
* Setup the winner filter , we don ' t want to restrict this
* to a specific fair for the 'fair' user
*/
2010-01-27 20:24:19 +00:00
$fairs_where = '' ;
2025-01-29 03:30:48 +00:00
if ( $r [ 'per_fair' ] == 'yes' ) {
if ( $fairs_id == 0 ) {
2010-01-27 20:24:19 +00:00
echo " blank fairs_id for per-fair award. bug. \n " ;
exit ;
}
/* For per-fair awards, filter the results */
$fairs_where = " AND projects.fairs_id=' $fairs_id ' " ;
2007-11-18 23:50:23 +00:00
}
2005-05-04 21:23:00 +00:00
2010-01-27 20:24:19 +00:00
/* Force the 'fair' user to only edit their own fair */
2025-01-29 03:30:48 +00:00
if ( $auth_type == 'fair' )
$fairs_id = $_SESSION [ 'fairs_id' ];
2010-01-27 20:24:19 +00:00
/* Load prizes for this award */
2025-01-29 03:30:48 +00:00
$q = $pdo -> prepare ( " SELECT
2010-01-27 20:24:19 +00:00
award_prizes . prize ,
award_prizes . number ,
award_prizes . id ,
award_prizes . cash ,
award_prizes . scholarship
2005-05-04 21:23:00 +00:00
FROM
2010-01-27 20:24:19 +00:00
award_prizes
2005-05-04 21:23:00 +00:00
WHERE
2010-01-27 20:24:19 +00:00
award_awards_id = '{$r[' id ']}'
AND award_prizes . year = '{$config[' FAIRYEAR ']}'
ORDER BY
`order` " );
2024-12-08 02:42:00 -05:00
$q -> execute ();
2025-01-02 10:54:18 -05:00
show_pdo_errors_if_any ( $pdo );
2010-01-27 20:24:19 +00:00
2025-01-29 03:30:48 +00:00
echo '<table width="100%"><tr><td>' ;
$has_winners = false ;
while ( $pr = $q -> fetch ( PDO :: FETCH_OBJ )) {
if ( $editor == true ) {
2010-01-27 20:24:19 +00:00
echo '<br /><hr />' ;
}
echo " <b> { $pr -> prize } " ;
2025-01-29 03:30:48 +00:00
if ( $pr -> cash || $pr -> scholarship ) {
echo ' (' ;
if ( $pr -> cash && $pr -> scholarship )
2010-01-27 20:24:19 +00:00
echo " \$ { $pr -> cash } cash / \$ { $pr -> scholarship } scholarship " ;
2025-01-29 03:30:48 +00:00
else if ( $pr -> cash )
2010-01-27 20:24:19 +00:00
echo " \$ { $pr -> cash } cash " ;
2025-01-29 03:30:48 +00:00
else if ( $pr -> scholarship )
2010-01-27 20:24:19 +00:00
echo " \$ { $pr -> scholarship } scholarship " ;
2025-01-29 03:30:48 +00:00
echo ')' ;
2010-01-27 20:24:19 +00:00
}
/* Load winners for this prize */
2025-01-29 03:30:48 +00:00
$cq = $pdo -> prepare ( " SELECT winners.projects_id,
2010-01-27 20:24:19 +00:00
projects . projectnumber ,
projects . title ,
projects . fairs_id
FROM
winners
LEFT JOIN projects ON projects . id = winners . projects_id
WHERE
winners . awards_prizes_id = '{$pr->id}'
$fairs_where " );
2024-12-08 02:42:00 -05:00
$cq -> execute ();
2025-01-02 10:54:18 -05:00
show_pdo_errors_if_any ( $pdo );
2024-12-08 02:42:00 -05:00
$count = $cq -> rowCount ();
2025-01-29 03:30:48 +00:00
// echo "winners=$count";
2010-01-27 20:24:19 +00:00
2025-01-29 03:30:48 +00:00
/* Print count */
2010-01-27 20:24:19 +00:00
$colour = ( $count < $pr -> number ) ? 'red' : 'green' ;
echo " <font color= \" $colour\ " > [ $count / { $pr -> number }] </ font > " ;
2025-01-29 03:30:48 +00:00
echo '</b>' ;
echo '<br />' ;
2010-01-27 20:24:19 +00:00
/* List current winners for this prize */
$winners = array ();
2025-01-29 03:30:48 +00:00
while ( $w = $cq -> fetch ( PDO :: FETCH_ASSOC )) {
if ( $w [ 'projectnumber' ]) {
echo ' ' ;
if ( $editor == true ) {
2010-01-27 20:24:19 +00:00
/* Print the delete X before the project */
2025-01-29 03:30:48 +00:00
if ( $auth_type == 'fair' && $w [ 'fairs_id' ] != $fairs_id ) {
2010-01-27 20:24:19 +00:00
/* show a blank so everything lines up */
echo ' ' ;
} else {
echo " <a onclick= \" delete_winner( { $pr -> id } , { $w [ 'projects_id' ] } );return false; \" href= \" # \" > " ;
echo " <img style= \" vertical-align:middle \" border=0 src= \" { $config [ 'SFIABDIRECTORY' ] } /images/16/button_cancel. { $config [ 'icon_extension' ] } \" ></a> " ;
echo ' ' ;
}
$winners [] = $w [ 'projects_id' ];
2005-05-04 21:23:00 +00:00
}
2010-02-10 05:36:15 +00:00
$has_winners = true ;
2010-01-27 20:24:19 +00:00
echo " ( { $w [ 'projectnumber' ] } ) { $w [ 'title' ] } " ;
2025-01-29 03:30:48 +00:00
echo '<br />' ;
2010-01-27 20:24:19 +00:00
} else {
2025-01-29 03:30:48 +00:00
/* echo " " ;
echo " <font color= \" red \" >No winner(s) specified</font> " ; */
2005-05-04 21:23:00 +00:00
}
}
2010-01-27 20:24:19 +00:00
/* Unlist all the winners we just printed from ALL lists */
2025-01-29 03:30:48 +00:00
if ( $editor == true ) {
echo '<script language="javascript" type="text/javascript">' ;
foreach ( $winners as $w )
echo " unlist_winner( $w ); " ;
echo '</script>' ;
2010-01-27 20:24:19 +00:00
}
/* Print the select box if we need it */
2025-01-29 03:30:48 +00:00
if ( $editor == true && $count < $pr -> number ) {
2010-01-27 20:24:19 +00:00
$n_nom = 0 ;
$n_eli = 0 ;
2025-01-29 03:30:48 +00:00
?>
2010-01-27 20:24:19 +00:00
< br />
2025-01-29 03:30:48 +00:00
< form id = " winner_<?= $pr->id ?> " >
2010-01-27 20:24:19 +00:00
& nbsp ; & nbsp ; & nbsp ;
2025-01-29 03:30:48 +00:00
< select id = " projects_select_<?= $pr->id ?>_nom " class = " projects_select " style = " display:none " >
< option value = " " >< ? = i18n ( 'Choose a project' ) ?> </option>
< ?
foreach ( $editor_data [ 'projects_nominated' ] as $p ) {
if ( $fairs_id != 0 && $p [ 'fairs_id' ] != $fairs_id )
continue ;
2014-04-05 14:02:46 +00:00
echo " <option value= \" { $p [ 'id' ] } \" > { $p [ 'projectnumber' ] } { $p [ 'title' ] } </option> " ;
2010-01-27 20:24:19 +00:00
$n_nom ++ ;
}
2025-01-29 03:30:48 +00:00
?> </select>
< select id = " projects_select_<?= $pr->id ?>_eli " class = " projects_select " style = " display:none " >
< option value = " " >< ? = i18n ( 'Choose a project' ) ?> </option>
< ?
foreach ( $editor_data [ 'projects_eligible' ] as $p ) {
if ( $fairs_id != 0 && $p [ 'fairs_id' ] != $fairs_id )
continue ;
2014-04-05 14:02:46 +00:00
echo " <option value= \" { $p [ 'id' ] } \" > { $p [ 'projectnumber' ] } { $p [ 'title' ] } </option> " ;
2010-01-27 20:24:19 +00:00
$n_eli ++ ;
print_r ( $p );
}
2025-01-29 03:30:48 +00:00
?> </select>
< button id = " " onClick = " add_winner(<?= $pr->id ?>); return false; " >< ? = i18n ( 'Add' ) ?> </button>
2010-01-27 20:24:19 +00:00
< br />& nbsp ; & nbsp ; & nbsp ;
2025-01-29 03:30:48 +00:00
< ? = i18n ( 'List' ) ?> :
2010-01-27 20:24:19 +00:00
< ?
2025-01-29 03:30:48 +00:00
if ( $editor_data [ 'disable_nominated' ] == true )
$n_nom = 'N/A' ;
$nom = i18n ( 'All Nominated' ) . " ( $n_nom ) " ;
$el = i18n ( 'All Eligible' ) . " ( $n_eli ) " ;
2010-01-27 20:24:19 +00:00
$cl = ( $editor_data [ 'disable_nominated' ] == true ) ? 'text-link-disabled' : '' ;
2025-01-29 03:30:48 +00:00
?>
< span id = " nom_<?= $pr->id ?> " class = " text-link <?= $cl ?> " onClick = " set_nom(<?= $pr->id ?>);return false; " >< ? = $nom ?>
</ span > - < span id = " eli_<?= $pr->id ?> " class = " text-link " onClick = " set_eli(<?= $pr->id ?>);return false; " >< ? = $el ?> </span>
2010-01-27 20:24:19 +00:00
</ form >
< script language = " javascript " type = " text/javascript " >
2025-01-29 03:30:48 +00:00
< ? /*
* Start with the nominated list , unless there are none , do
* the eligible list by default in that case
*/
if ( $n_nom > 0 )
echo " set_nom( { $pr -> id } ); " ;
else
echo " set_eli( { $pr -> id } ); " ;
?> </script>
2010-01-27 20:24:19 +00:00
< ?
}
2005-05-04 21:23:00 +00:00
}
2025-01-29 03:30:48 +00:00
echo '</td><td align="right">' ;
if ( $r [ 'external_additional_materials' ] == 1 && $editor == false && $r [ 'award_source_fairs_id' ] == NULL ) {
2010-02-10 05:36:15 +00:00
$d = 'disabled="disabled"' ;
$a = '' ;
2025-01-29 03:30:48 +00:00
if ( $has_winners == true ) {
2010-02-10 05:36:16 +00:00
echo " <a href= \" { $_SERVER [ 'PHP_SELF' ] } ?action=additional_materials&award_awards_id= { $r [ 'id' ] } &fairs_id= { $fairs_id } \" > " ;
2010-02-10 05:36:15 +00:00
$d = '' ;
$a = '</a>' ;
}
2025-01-29 03:30:48 +00:00
echo " <button $d title= \" " . i18n ( 'Download additional material (currently only a nomination form)' ) . '">' . i18n ( 'Download Additional Materials' ) . " </button> $a <br/> " ;
2010-02-10 05:36:15 +00:00
}
2025-01-29 03:30:48 +00:00
echo '</td></tr></table>' ;
2005-05-04 21:23:00 +00:00
}
2010-01-27 20:24:19 +00:00
send_footer ();
2005-05-04 21:23:00 +00:00
?>