2009-09-30 22:38:38 +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 ) 2008 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 " );
require_once ( " ../user.inc.php " );
user_auth_required ( 'committee' , 'admin' );
2009-10-06 21:00:12 +00:00
echo " <br /> \n " ;
2009-09-30 22:38:38 +00:00
//$q=mysql_query("SELECT * FROM award_sponsors WHERE year='".$config['FAIRYEAR']."' ORDER BY organization");
//we want to show all years, infact that year field probably shouldnt even be there.
$sql = " " ;
2024-12-07 01:54:02 +00:00
if ( $_POST [ 'search' ]) $sql .= " AND organization LIKE '% " . $_POST [ 'search' ] . " %' " ;
2009-09-30 22:38:38 +00:00
if ( count ( $_POST [ 'donortype' ])) {
$sql .= " AND (0 " ;
foreach ( $_POST [ 'donortype' ] AS $d ) {
$sql .= " OR donortype=' $d ' " ;
}
$sql .= " ) " ;
}
$query = " SELECT * FROM sponsors WHERE 1 $sql ORDER BY organization " ;
2009-10-06 21:00:12 +00:00
// echo "query=$query";
2024-12-07 01:54:02 +00:00
$q = $pdo -> prepare ( $query );
$q -> execute ();
2009-09-30 22:38:38 +00:00
2009-10-16 15:22:54 +00:00
$thisyear = $config [ 'FISCALYEAR' ];
$lastyear = $config [ 'FISCALYEAR' ] - 1 ;
$rows = array ();
2009-09-30 22:38:38 +00:00
2024-12-07 01:54:02 +00:00
while ( $r = $q -> fetch ( PDO :: FETCH_OBJ ))
2009-09-30 22:38:38 +00:00
{
2024-12-07 01:54:02 +00:00
$cq = $pdo -> prepare ( " SELECT SUM(value) AS total FROM fundraising_donations WHERE sponsors_id=' $r->id ' AND status='received' AND fiscalyear=' $thisyear ' " );
$cq -> execute ();
$cr = $cq -> fetch ( PDO :: FETCH_OBJ );
2009-10-16 15:22:54 +00:00
$thisyeartotal = $cr -> total ;
2024-12-07 01:54:02 +00:00
$cq = $pdo -> prepare ( " SELECT SUM(value) AS total FROM fundraising_donations WHERE sponsors_id=' $r->id ' AND status='received' AND fiscalyear=' $lastyear ' " );
$cq -> execute ();
$cr = $cq -> fetch ( PDO :: FETCH_OBJ );
2009-10-16 15:22:54 +00:00
$lastyeartotal = $cr -> total ;
if ( $lastyeartotal )
$change = round (( $thisyeartotal - $lastyeartotal ) / $lastyeartotal * 100 );
else
$change = " N/A " ;
$rows [] = array ( " id " => $r -> id , " name " => $r -> organization , " thisyeartotal " => $thisyeartotal , " lastyeartotal " => $lastyeartotal , " change " => $change );
}
$thisyearsort = array ();
if ( ! $_POST [ 'order' ]) {
//if order is not given, lets order by donation amount this year
foreach ( $rows AS $key => $val ) {
$thisyearsort [ $key ] = $val [ 'thisyeartotal' ];
}
array_multisort ( $thisyearsort , SORT_DESC , $rows );
}
2009-09-30 22:38:38 +00:00
2009-10-16 15:22:54 +00:00
if ( $_POST [ 'limit' ]) {
$limit = $_POST [ 'limit' ];
}
else {
$limit = 10 ;
echo " <h4> " . i18n ( " Top 10 donors this year " ) . " </h4> " ;
}
2009-09-30 22:38:38 +00:00
2009-10-16 15:22:54 +00:00
echo " <table class= \" tableview \" > " ;
2010-03-31 18:44:42 +00:00
echo " <thead> " ;
2009-10-16 15:22:54 +00:00
echo " <tr> " ;
2009-10-22 16:46:32 +00:00
echo " <th> " . i18n ( " Donor/Sponsor " ) . " </th> " ;
echo " <th> " . i18n ( " Total $ this year " ) . " </th> " ;
echo " <th> " . i18n ( " Total $ last year " ) . " </th> " ;
echo " <th> " . i18n ( " % change " ) . " </th> " ;
2010-03-31 18:44:42 +00:00
echo " </tr> " ;
echo " </thead> \n " ;
2009-09-30 22:38:38 +00:00
2009-10-16 15:22:54 +00:00
$x = 0 ;
foreach ( $rows AS $r ) {
echo " <tr> \n " ;
$eh = " style= \" cursor:pointer; \" onclick= \" open_editor( { $r [ 'id' ] } ); \" " ;
echo " <td $eh > { $r [ 'name' ] } </td> \n " ;
echo " <td style= \" text-align: right; \" > " ;
echo format_money ( $r [ 'thisyeartotal' ]);
echo " </td> \n " ;
echo " <td style= \" text-align: right; \" > " ;
echo format_money ( $r [ 'lastyeartotal' ]);
echo " </td> \n " ;
if ( is_numeric ( $r [ 'change' ])) {
$n = $r [ 'change' ] / 2 + 50 ;
if ( $n < 0 ) $n = 0 ;
if ( $n > 100 ) $n = 100 ;
$col = " color: " . colour_to_percent ( $n );
$sign = " % " ;
}
else {
$col = " " ; $sign = " " ; }
echo " <td style= \" text-align: center; $col\ " > " ;
echo $r [ 'change' ] . $sign ;
echo " </td> \n " ;
2009-09-30 22:38:38 +00:00
echo " </tr> \n " ;
2009-10-16 15:22:54 +00:00
$x ++ ;
if ( $x == $limit )
break ;
2009-09-30 22:38:38 +00:00
}
echo " </table> \n " ;
2010-03-31 18:44:42 +00:00
2009-09-30 22:38:38 +00:00
?>