2005-05-04 21:23:00 +00:00
< ?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website : http :// www . sfiab . ca
Copyright ( C ) 2005 Sci - Tech Ontario Inc < info @ scitechontario . org >
Copyright ( C ) 2005 James Grant < james @ lightbox . org >
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 .
*/
?>
< ?
require ( " ../common.inc.php " );
2007-11-21 17:02:09 +00:00
require_once ( " ../user.inc.php " );
2005-05-11 04:13:27 +00:00
require ( " ../projects.inc.php " );
2007-11-18 23:50:23 +00:00
user_auth_required ( 'committee' , 'admin' );
2005-05-04 21:23:00 +00:00
2009-09-09 00:26:12 +00:00
if ( $_GET [ 'sponsors_id' ]) $sponsors_id = $_GET [ 'sponsors_id' ];
else if ( $_POST [ 'sponsors_id' ]) $sponsors_id = $_POST [ 'sponsors_id' ];
2005-05-04 21:23:00 +00:00
if ( $_GET [ 'award_types_id' ]) $award_types_id = $_GET [ 'award_types_id' ];
else if ( $_POST [ 'award_types_id' ]) $award_types_id = $_POST [ 'award_types_id' ];
2007-11-18 23:50:23 +00:00
if ( $_GET [ 'edit' ]) $edit = intval ( $_GET [ 'edit' ]);
if ( $_POST [ 'edit' ]) $edit = intval ( $_POST [ 'edit' ]);
2005-05-04 21:23:00 +00:00
if ( $_GET [ 'action' ]) $action = $_GET [ 'action' ];
if ( $_POST [ 'action' ]) $action = $_POST [ 'action' ];
if ( $action == " addwinner " )
{
if ( $_POST [ 'winner' ])
{
//first check how many we are allowed to have
$q = mysql_query ( " SELECT number FROM award_prizes WHERE id=' " . $_POST [ 'prize_id' ] . " ' " );
echo mysql_Error ();
$r = mysql_fetch_object ( $q );
$number = $r -> number ;
$q = mysql_query ( " SELECT COUNT(*) AS count FROM winners WHERE awards_prizes_id=' " . $_POST [ 'prize_id' ] . " ' " );
echo mysql_Error ();
$r = mysql_fetch_object ( $q );
$count = $r -> count ;
if ( $count < $number )
{
mysql_query ( " INSERT INTO winners (awards_prizes_id,projects_id,year) VALUES (' " . $_POST [ 'prize_id' ] . " ',' " . $_POST [ 'winner' ] . " ',' " . $config [ 'FAIRYEAR' ] . " ') " );
2007-11-18 23:50:23 +00:00
$notice = 'added' ;
2005-05-04 21:23:00 +00:00
}
else
{
2007-11-18 23:50:23 +00:00
$notice = 'nomore' ;
$notice_data = array ( $number );
2005-05-04 21:23:00 +00:00
}
}
2007-11-18 23:50:23 +00:00
$action = " edit " ;
2005-05-04 21:23:00 +00:00
}
if ( $action == " delete " )
{
if ( $_GET [ 'prize_id' ] && $_GET [ 'project_id' ])
{
mysql_query ( " DELETE FROM winners WHERE awards_prizes_id=' " . $_GET [ 'prize_id' ] . " ' AND projects_id=' " . $_GET [ 'project_id' ] . " ' " );
2007-11-18 23:50:23 +00:00
$notice = 'removed' ;
2005-05-04 21:23:00 +00:00
}
$action = " edit " ;
}
if ( $action == " edit " && $edit )
{
2007-11-18 23:50:23 +00:00
send_header ( " Choose Projects " ,
array ( 'Committee Main' => 'committee_main.php' ,
'Administration' => 'admin/index.php' ,
2008-08-22 20:50:38 +00:00
'Enter Winning Projects' => 'admin/winners.php' ),
" enter_winning_projects "
2007-11-18 23:50:23 +00:00
);
switch ( $notice ) {
case 'removed' :
echo happy ( i18n ( " Winning project removed " ));
break ;
case 'nomore' :
echo error ( i18n ( " This prize cannot accept any more winners. Maximum: %1 " , $notice_data ));
break ;
case 'added' :
echo happy ( i18n ( " Winning project added " ));
break ;
}
2005-05-04 21:23:00 +00:00
$q = mysql_query ( " SELECT
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 ,
award_types . type
FROM
award_awards ,
award_types
WHERE
award_awards . year = '".$config[' FAIRYEAR ']."'
AND award_awards . award_types_id = award_types . id
AND award_awards . id = '$edit'
" );
echo mysql_error ();
if ( $r = mysql_fetch_object ( $q ))
{
echo " <br /> " ;
2005-05-06 20:02:20 +00:00
//get the projets that are eligible for the award, given the award ID ($r->id)
2007-04-03 20:10:00 +00:00
if ( $r -> type == " Special " && ! $_GET [ 'eligible' ])
2005-05-12 19:06:12 +00:00
{
$projects = getProjectsNominatedForSpecialAward ( $r -> id );
}
else
$projects = getProjectsEligibleForAward ( $r -> id );
2005-05-04 21:23:00 +00:00
$winq = mysql_query ( " SELECT
winners . projects_id
FROM
winners , award_prizes , award_awards
WHERE
award_awards . id = '$r->id'
AND award_prizes . award_awards_id = award_awards . id
AND winners . awards_prizes_id = award_prizes . id
ORDER BY
projects_id
" );
echo mysql_error ();
$alreadywinners = array ();
while ( $winr = mysql_fetch_object ( $winq ))
{
$alreadywinners [] = $winr -> projects_id ;
}
//print_r($alreadywinners);
/*
echo " projects: " ;
echo nl2br ( print_r ( $projects , true ));
echo " <br /> " ;
*/
// echo "<img border=\"0\" src=\"".$config['SFIABDIRECTORY']."/images/16/edit.".$config['icon_extension']."\">";
2007-01-30 07:45:12 +00:00
echo " <b> { $r -> type } - { $r -> name } </b><br /> " ;
echo " { $r -> criteria } <br /> " ;
2005-05-04 21:23:00 +00:00
$pq = mysql_query ( " SELECT
award_prizes . prize ,
award_prizes . number ,
award_prizes . id ,
award_prizes . cash ,
award_prizes . scholarship ,
winners . projects_id ,
projects . projectnumber ,
projects . title
FROM
award_prizes
LEFT JOIN winners ON winners . awards_prizes_id = award_prizes . id
LEFT JOIN projects ON projects . id = winners . projects_id
WHERE
award_awards_id = '$r->id'
AND award_prizes . year = '".$config[' FAIRYEAR ']."'
ORDER BY
`order` " );
echo mysql_error ();
$prevprizeid =- 1 ;
while ( $pr = mysql_fetch_object ( $pq ))
{
if ( $prevprizeid != $pr -> id )
{
echo " <hr> " ;
echo " " ;
echo " " ;
echo " <b> " ;
echo " $pr->prize " ;
if ( $pr -> cash || $pr -> scholarship )
{
echo " ( " ;
if ( $pr -> cash && $pr -> scholarship )
echo " \$ $pr->cash cash / \$ $pr->scholarship scholarship " ;
else if ( $pr -> cash )
echo " \$ $pr->cash cash " ;
else if ( $pr -> scholarship )
echo " \$ $pr->scholarship scholarship " ;
echo " ) " ;
}
$cq = mysql_query ( " SELECT COUNT(*) AS count FROM winners WHERE awards_prizes_id=' $pr->id ' " );
echo mysql_Error ();
$cr = mysql_fetch_object ( $cq );
$count = $cr -> count ;
if ( $count < $pr -> number ) $color = " red " ; else $color = " green " ;
echo " <font color= \" $color\ " > [ " . $count . " / " . $pr->number . " ] </ font > " ;
echo " </b> " ;
$prevprizeid = $pr -> id ;
if ( $count < $pr -> number )
{
echo " <form method= \" post \" action= \" winners.php \" > " ;
echo " <input type= \" hidden \" name= \" action \" value= \" addwinner \" > " ;
echo " <input type= \" hidden \" name= \" prize_id \" value= \" $pr->id\ " > " ;
echo " <input type= \" hidden \" name= \" edit \" value= \" $edit\ " > " ;
echo " <select name= \" winner \" > " ;
echo " <option value= \" \" > " . i18n ( " Choose a project " ) . " </option> \n " ;
foreach ( $projects AS $proj )
{
if ( ! in_array ( $proj [ 'id' ], $alreadywinners ))
echo " <option value= \" " . $proj [ 'id' ] . " \" >( " . $proj [ 'projectnumber' ] . " ) " . $proj [ 'title' ] . " </option> " ;
}
echo " </select> " ;
echo " <input type= \" submit \" value= \" " . i18n ( " Add " ) . " \" > " ;
echo " </form> " ;
2007-04-03 20:10:00 +00:00
echo " <a href= \" winners.php?action= $action &edit= $edit &eligible=true \" >Show All Eligible</a> " ;
echo " <br /> " ;
2005-05-04 21:23:00 +00:00
}
else
echo " <br /> " ;
}
if ( $pr -> projectnumber )
{
echo " " ;
echo " " ;
echo " " ;
echo " " ;
echo " <a onclick= \" return confirmClick('Are you sure you want to remove this project from this prize?') \" href= \" winners.php?action=delete&edit= $edit &prize_id= $pr->id &project_id= $pr->projects_id\ " >< img border = 0 src = \ " " . $config [ 'SFIABDIRECTORY' ] . " /images/16/button_cancel. " . $config [ 'icon_extension' ] . " \" ></a> " ;
echo " ( $pr->projectnumber ) $pr->title " ;
echo " <br /> " ;
}
}
}
}
else
{
2007-11-18 23:50:23 +00:00
send_header ( " Enter Winning Projects " ,
array ( 'Committee Main' => 'committee_main.php' ,
2008-08-22 20:50:38 +00:00
'Administration' => 'admin/index.php' ),
" enter_winning_projects "
2007-11-18 23:50:23 +00:00
);
switch ( $notice ) {
case 'removed' :
echo happy ( i18n ( " Winning project removed " ));
break ;
case 'nomore' :
echo error ( i18n ( " This prize cannot accept any more winners. Maximum: %1 " , $notice_data ));
break ;
case 'added' :
echo happy ( i18n ( " Winning project added " ));
break ;
}
2005-05-04 21:23:00 +00:00
$q = mysql_query ( " SELECT
award_awards . id ,
award_awards . name ,
award_awards . order AS awards_order ,
2007-10-29 19:13:52 +00:00
award_types . type ,
2009-09-09 00:26:12 +00:00
sponsors . organization
2005-05-04 21:23:00 +00:00
FROM
award_awards ,
2007-10-29 19:13:52 +00:00
award_types ,
2009-09-09 00:26:12 +00:00
sponsors
2005-05-04 21:23:00 +00:00
WHERE
award_awards . year = '".$config[' FAIRYEAR ']."'
AND award_awards . award_types_id = award_types . id
2006-03-04 05:22:26 +00:00
AND award_types . year = '".$config[' FAIRYEAR ']."'
2009-09-09 00:26:12 +00:00
AND award_awards . sponsors_id = sponsors . id
2005-05-04 21:23:00 +00:00
ORDER BY awards_order " );
echo mysql_error ();
if ( mysql_num_rows ( $q ))
{
echo " <br /> " ;
echo i18n ( " Choose an award to assign winners " );
echo " <br /> " ;
echo " <br /> " ;
while ( $r = mysql_fetch_object ( $q ))
{
echo " <a href= \" winners.php?action=edit&edit= $r->id\ " > " ;
// echo "<img border=\"0\" src=\"".$config['SFIABDIRECTORY']."/images/16/edit.".$config['icon_extension']."\">";
echo " $r->type - \n " ;
echo " $r->name \n " ;
echo " </a> " ;
2007-10-29 19:13:52 +00:00
echo " <span style= \" font-size: 0.8em; font-style: italic; \" >( " . $r -> organization . " )</span><br /> " ;
2005-05-04 21:23:00 +00:00
$pq = mysql_query ( " SELECT
award_prizes . prize ,
award_prizes . number ,
award_prizes . id ,
award_prizes . cash ,
award_prizes . scholarship ,
winners . projects_id ,
projects . projectnumber ,
projects . title
FROM
award_prizes
LEFT JOIN winners ON winners . awards_prizes_id = award_prizes . id
LEFT JOIN projects ON projects . id = winners . projects_id
WHERE
award_awards_id = '$r->id'
AND award_prizes . year = '".$config[' FAIRYEAR ']."'
ORDER BY
`order` " );
echo mysql_error ();
$prevprizeid =- 1 ;
while ( $pr = mysql_fetch_object ( $pq ))
{
if ( $prevprizeid != $pr -> id )
{
echo " " ;
echo " " ;
echo " <b> " ;
echo " $pr->prize " ;
if ( $pr -> cash || $pr -> scholarship )
{
echo " ( " ;
if ( $pr -> cash && $pr -> scholarship )
echo " \$ $pr->cash cash / \$ $pr->scholarship scholarship " ;
else if ( $pr -> cash )
echo " \$ $pr->cash cash " ;
else if ( $pr -> scholarship )
echo " \$ $pr->scholarship scholarship " ;
echo " ) " ;
}
$cq = mysql_query ( " SELECT COUNT(*) AS count FROM winners WHERE awards_prizes_id=' $pr->id ' " );
echo mysql_Error ();
$cr = mysql_fetch_object ( $cq );
$count = $cr -> count ;
if ( $count < $pr -> number ) $color = " red " ; else $color = " green " ;
echo " <font color= \" $color\ " > [ " . $count . " / " . $pr->number . " ] </ font > " ;
echo " </b> " ;
echo " <br /> " ;
$prevprizeid = $pr -> id ;
}
if ( $pr -> projectnumber )
{
echo " " ;
echo " " ;
echo " " ;
echo " " ;
echo " ( $pr->projectnumber ) $pr->title " ;
echo " <br /> " ;
}
else
{
/*
echo " " ;
echo " " ;
echo " " ;
echo " " ;
echo " <font color= \" red \" >No winner(s) specified</font> " ;
*/
}
}
echo " <br /> " ;
}
}
}
send_footer ();
?>