2006-01-03 02:02:52 +00:00
< ?
2025-01-29 03:30:48 +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 .
*/
2006-01-03 02:02:52 +00:00
?>
< ?
2025-01-29 03:30:48 +00:00
require ( '../common.inc.php' );
require_once ( '../user.inc.php' );
user_auth_required ( 'committee' , 'admin' );
send_header ( 'Create All Divisional Awards' ,
array ( 'Committee Main' => 'committee_main.php' ,
'Administration' => 'admin/index.php' ,
'Awards Main' => 'admin/awards.php' ));
if ( get_value_from_array ( $_GET , 'sponsors_id' ))
$sponsors_id = $_GET [ 'sponsors_id' ];
else if ( get_value_from_array ( $_POST , 'sponsors_id' ))
$sponsors_id = $_POST [ 'sponsors_id' ];
if ( get_value_from_array ( $_GET , 'award_types_id' ))
$award_types_id = $_GET [ 'award_types_id' ];
else if ( get_value_from_array ( $_POST , 'award_types_id' ))
$award_types_id = $_POST [ 'award_types_id' ];
// first, we can only do this if we dont have any type=divisional awards created yet
$q = $pdo -> prepare ( " SELECT COUNT(id) AS num FROM award_awards WHERE award_types_id='1' AND year=' { $config [ 'FAIRYEAR' ] } ' " );
$q -> execute ();
$r = $q -> fetch ( PDO :: FETCH_OBJ );
if ( $r -> num ) {
echo error ( i18n ( '%1 Divisional awards already exist. There must not be any divisional awards in order to run this wizard' , array ( $r -> num )));
} else {
$q = $pdo -> prepare ( " SELECT * FROM projectdivisions WHERE year=' " . $config [ 'FAIRYEAR' ] . " ' ORDER BY id " );
2024-12-06 20:54:02 -05:00
$q -> execute ();
2025-01-29 03:30:48 +00:00
while ( $r = $q -> fetch ( PDO :: FETCH_OBJ ))
$div [ $r -> id ] = $r -> division ;
2006-01-03 02:02:52 +00:00
2025-01-29 03:30:48 +00:00
$q = $pdo -> prepare ( " SELECT * FROM projectcategories WHERE year=' " . $config [ 'FAIRYEAR' ] . " ' ORDER BY id " );
2024-12-06 20:54:02 -05:00
$q -> execute ();
2025-01-29 03:30:48 +00:00
while ( $r = $q -> fetch ( PDO :: FETCH_OBJ ))
$cat [ $r -> id ] = $r -> category ;
2006-01-03 02:02:52 +00:00
2025-01-29 03:30:48 +00:00
$dkeys = array_keys ( $div );
$ckeys = array_keys ( $cat );
2007-12-20 20:45:18 +00:00
2025-01-29 03:30:48 +00:00
if ( $config [ 'filterdivisionbycategory' ] == 'yes' ) {
$q = $pdo -> prepare ( " SELECT * FROM projectcategoriesdivisions_link WHERE year=' " . $config [ 'FAIRYEAR' ] . " ' ORDER BY projectdivisions_id,projectcategories_id " );
2024-12-06 20:54:02 -05:00
$q -> execute ();
2025-01-29 03:30:48 +00:00
$divcat = array ();
while ( $r = $q -> fetch ( PDO :: FETCH_OBJ )) {
$divcat [] = array ( 'c' => $r -> projectcategories_id , 'd' => $r -> projectdivisions_id );
2007-12-20 20:45:18 +00:00
}
2025-01-29 03:30:48 +00:00
} else {
$divcat = array ();
foreach ( $dkeys AS $d ) {
foreach ( $ckeys AS $c ) {
$divcat [] = array ( 'c' => $c , 'd' => $d );
2007-12-20 20:45:18 +00:00
}
}
2025-01-29 03:30:48 +00:00
}
if ( $_GET [ 'action' ] == 'create' && $_GET [ 'sponsors_id' ]) {
$q = $pdo -> prepare ( " SELECT * FROM award_prizes WHERE year='-1' AND award_awards_id='0' ORDER BY `order` " );
$q -> execute ();
$prizes = array ();
while ( $r = $q -> fetch ( PDO :: FETCH_OBJ )) {
$prizes [] = array (
'cash' => $r -> cash ,
'scholarship' => $r -> scholarship ,
'value' => $r -> value ,
'prize' => $r -> prize ,
'number' => $r -> number ,
'excludefromac' => $r -> excludefromac ,
'trophystudentkeeper' => $r -> trophystudentkeeper ,
'trophystudentreturn' => $r -> trophystudentreturn ,
'trophyschoolkeeper' => $r -> trophyschoolkeeper ,
'trophyschoolreturn' => $r -> trophyschoolreturn ,
'order' => $r -> order
);
}
2007-12-20 20:45:18 +00:00
2025-01-29 03:30:48 +00:00
$ord = 1 ;
echo '<br />' ;
foreach ( $divcat AS $dc ) {
$d_id = $dc [ 'd' ];
$c_id = $dc [ 'c' ];
$d_division = $div [ $d_id ];
$c_category = $cat [ $c_id ];
2006-01-03 02:02:52 +00:00
2025-01-29 03:30:48 +00:00
echo i18n ( 'Creating %1 - %2' , array ( $c_category , $d_division )) . '<br />' ;
2006-01-03 02:02:52 +00:00
2025-01-29 03:30:48 +00:00
$q = $pdo -> prepare ( " INSERT INTO award_awards (sponsors_id,award_types_id,name,criteria,`order`,year) VALUES (
2009-09-09 00:26:12 +00:00
'{$_GET[' sponsors_id ']}' ,
2006-01-03 02:02:52 +00:00
'1' ,
'$c_category - $d_division' ,
2025-01-29 03:30:48 +00:00
'" . i18n(' Best % 1 projects in the % 2 division ', array($c_category, $d_division)) . "' ,
2006-01-03 02:02:52 +00:00
'$ord' ,
'{$config[' FAIRYEAR ']}'
) " );
2025-01-29 03:30:48 +00:00
$q -> execute ();
show_pdo_errors_if_any ( $pdo );
$award_awards_id = $pdo -> lastInsertId ();
2006-01-03 02:02:52 +00:00
2025-01-29 03:30:48 +00:00
$q = $pdo -> prepare ( " INSERT INTO award_awards_projectcategories (award_awards_id,projectcategories_id,year) VALUES (' $award_awards_id ',' $c_id ',' { $config [ 'FAIRYEAR' ] } ') " );
$q -> execute ();
2006-01-03 02:02:52 +00:00
2025-01-29 03:30:48 +00:00
$q = $pdo -> prepare ( " INSERT INTO award_awards_projectdivisions (award_awards_id,projectdivisions_id,year) VALUES (' $award_awards_id ',' $d_id ',' { $config [ 'FAIRYEAR' ] } ') " );
$q -> execute ();
$ord ++ ;
2006-01-03 02:02:52 +00:00
2025-01-29 03:30:48 +00:00
echo ' ' . i18n ( 'Prizes: ' );
foreach ( $prizes AS $prize ) {
$q = $pdo -> prepare ( " INSERT INTO award_prizes (award_awards_id,cash,scholarship,value,prize,number,`order`,excludefromac,trophystudentkeeper,trophystudentreturn,trophyschoolkeeper,trophyschoolreturn,year) VALUES (
2006-01-03 02:02:52 +00:00
'$award_awards_id' ,
'{$prize[' cash ']}' ,
'{$prize[' scholarship ']}' ,
2007-12-20 20:45:18 +00:00
'{$prize[' value ']}' ,
2006-01-03 02:02:52 +00:00
'{$prize[' prize ']}' ,
'{$prize[' number ']}' ,
'{$prize[' order ']}' ,
2007-12-20 20:45:18 +00:00
'{$prize[' excludefromac ']}' ,
'{$prize[' trophystudentkeeper ']}' ,
'{$prize[' trophystudentreturn ']}' ,
'{$prize[' trophyschoolkeeper ']}' ,
'{$prize[' trophyschoolreturn ']}' ,
2006-01-03 02:02:52 +00:00
'{$config[' FAIRYEAR ']}'
) " );
2024-12-06 20:54:02 -05:00
2025-01-29 03:30:48 +00:00
$q -> execute ();
2024-12-06 20:54:02 -05:00
2025-01-29 03:30:48 +00:00
echo $prize [ 'prize' ] . ',' ;
2006-01-03 02:02:52 +00:00
}
2025-01-29 03:30:48 +00:00
echo '<br />' ;
2006-01-03 02:02:52 +00:00
}
2025-01-29 03:30:48 +00:00
echo happy ( i18n ( 'All divisional awards and prizes successfully created' ));
echo '<a href="award_awards.php">' . i18n ( 'Go to awards manager' ) . " </a> \n " ;
} else {
echo '<br />' ;
echo i18n ( 'Please choose the sponsor and create the prizes that will be added to all divisional awards' );
echo '<form method="get" action="award_awardcreatedivisional.php">' ;
echo '<table>' ;
echo '<tr><td>' . i18n ( 'Sponsor' ) . ':</td><td>' ;
$sq = $pdo -> prepare ( 'SELECT id,organization FROM sponsors ORDER BY organization' );
$sq -> execute ();
echo '<select name="sponsors_id">' ;
// only show the "choose a sponsor" option if we are adding,if we are editing, then they must have already chosen one.
echo $firstsponsor ;
while ( $sr = $sq -> fetch ( PDO :: FETCH_OBJ )) {
if ( $sr -> id == $sponsors_id )
$sel = 'selected="selected"' ;
else
$sel = '' ;
echo " <option $sel value= \" $sr->id\ " > " . i18n( $sr->organization ) . '</option>';
}
echo '</select>' ;
echo '</td></tr>' ;
2006-01-03 02:02:52 +00:00
2025-01-29 03:30:48 +00:00
echo '<tr><td>' . i18n ( 'Prizes' ) . '</td><td><a href="award_prizes.php?award_awards_id=-1">Edit prize template for divisional awards</a>' ;
// the 'generic' template prizes for the awards are stored with year =-1 and award_awards_id=0
2006-01-03 02:02:52 +00:00
2025-01-29 03:30:48 +00:00
$q = $pdo -> prepare ( " SELECT * FROM award_prizes WHERE year='-1' AND award_awards_id='0' ORDER BY `order` " );
$q -> execute ();
2006-01-03 02:02:52 +00:00
2025-01-29 03:30:48 +00:00
if ( $q -> rowCount ()) {
2006-01-03 02:02:52 +00:00
/*
2025-01-29 03:30:48 +00:00
* echo " <form method= \" post \" action= \" award_prizes.php \" > " ;
* echo " <input type= \" hidden \" name= \" action \" value= \" reorder \" > " ;
* echo " <input type= \" hidden \" name= \" award_awards_id \" value= \" $award_awards_id\ " > " ;
*/
2006-01-03 02:02:52 +00:00
2025-01-29 03:30:48 +00:00
echo '<table class="summarytable">' ;
echo '<tr>' ;
2006-01-03 02:02:52 +00:00
// echo " <th>".i18n("Order")."</th>";
2025-01-29 03:30:48 +00:00
echo ' <th>' . i18n ( 'Prize Description' ) . '</th>' ;
echo ' <th>' . i18n ( 'Cash Amount' ) . '</th>' ;
echo ' <th>' . i18n ( 'Scholarship Amount' ) . '</th>' ;
echo ' <th>' . i18n ( 'Value' ) . '</th>' ;
echo ' <th>' . i18n ( '# of Prizes' ) . '</th>' ;
// echo " <th>Actions</th>";
echo " </tr> \n " ;
while ( $r = $q -> fetch ( PDO :: FETCH_OBJ )) {
echo " <tr> \n " ;
echo " <td> $r->prize </td> \n " ;
echo ' <td align="right">' ;
if ( $r -> cash )
echo " \$ $r->cash " ;
else
echo ' ' ;
echo ' </td>' ;
echo ' <td align="right">' ;
if ( $r -> scholarship )
echo " \$ $r->scholarship " ;
else
echo ' ' ;
echo ' </td>' ;
echo ' <td align="right">' ;
if ( $r -> value )
echo " \$ $r->value " ;
else
echo ' ' ;
echo ' </td>' ;
echo " <td align= \" center \" > $r->number </td> \n " ;
2006-01-03 02:02:52 +00:00
echo " </tr> \n " ;
}
2025-01-29 03:30:48 +00:00
echo " </table> \n " ;
}
2006-01-03 02:02:52 +00:00
2025-01-29 03:30:48 +00:00
echo '</td></tr>' ;
echo '</table>' ;
2006-01-03 02:02:52 +00:00
2025-01-29 03:30:48 +00:00
echo '<b>' . i18n ( 'We will create the following awards with the prizes listed above' ) . ':</b>' ;
echo '<br />' ;
foreach ( $divcat AS $dc ) {
$d_id = $dc [ 'd' ];
$c_id = $dc [ 'c' ];
$d_division = $div [ $d_id ];
$c_category = $cat [ $c_id ];
2006-01-03 02:02:52 +00:00
2025-01-29 03:30:48 +00:00
echo i18n ( $c_category ) . ' - ' . i18n ( $d_division ) . '<br />' ;
2006-01-03 02:02:52 +00:00
}
2025-01-29 03:30:48 +00:00
echo '<input type="hidden" name="action" value="create">' ;
echo '<input type="submit" value="' . i18n ( 'Create all divisional awards' ) . '">' ;
echo '</form>' ;
2006-01-03 02:02:52 +00:00
}
2025-01-29 03:30:48 +00:00
}
send_footer ();
2006-01-03 02:02:52 +00:00
?>