Copyright (C) 2008 James Grant 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. */ ?> \n"; //$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=""; if($_POST['search']) $sql.=" AND organization LIKE '%".mysql_real_escape_string($_POST['search'])."%' "; 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"; // echo "query=$query"; $q=mysql_query($query); $thisyear=$config['FISCALYEAR']; $lastyear=$config['FISCALYEAR']-1; $rows=array(); while($r=mysql_fetch_object($q)) { $cq=mysql_query("SELECT SUM(value) AS total FROM fundraising_donations WHERE sponsors_id='$r->id' AND status='received' AND fiscalyear='$thisyear'"); $cr=mysql_fetch_object($cq); $thisyeartotal=$cr->total; $cq=mysql_query("SELECT SUM(value) AS total FROM fundraising_donations WHERE sponsors_id='$r->id' AND status='received' AND fiscalyear='$lastyear'"); $cr=mysql_fetch_object($cq); $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); } if($_POST['limit']) { $limit=$_POST['limit']; } else { $limit=10; echo "

".i18n("Top 10 donors this year")."

"; } echo ""; echo ""; echo ""; echo " "; echo " "; echo " "; echo " "; echo ""; echo "\n"; $x=0; foreach($rows AS $r) { echo "\n"; $eh="style=\"cursor:pointer;\" onclick=\"open_editor({$r['id']});\""; echo " \n"; echo " \n"; echo " \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 " \n"; echo "\n"; $x++; if($x==$limit) break; } echo "
".i18n("Donor/Sponsor")."".i18n("Total $ this year")."".i18n("Total $ last year")."".i18n("% change")."
{$r['name']}"; echo format_money($r['thisyeartotal']); echo ""; echo format_money($r['lastyeartotal']); echo ""; echo $r['change'].$sign; echo "
\n"; ?>