From 5d9824a5a6cd6ea4eb10ba86c9cc4c57a486ab35 Mon Sep 17 00:00:00 2001 From: james Date: Fri, 16 Oct 2009 15:22:54 +0000 Subject: [PATCH] Rework the donors search/landing page so it shows top 10 donors if no search is performed yet Fix a few typo's and make the fundingselection/proposalsubmissiondate save properly --- admin/donors.php | 29 +++++++---- admin/donors_search.php | 110 ++++++++++++++++++++++++---------------- 2 files changed, 85 insertions(+), 54 deletions(-) diff --git a/admin/donors.php b/admin/donors.php index bc832e5..1b775af 100644 --- a/admin/donors.php +++ b/admin/donors.php @@ -65,9 +65,11 @@ switch($_GET['action']) { "notes='".mysql_escape_string(stripslashes($_POST['notes']))."', ". "donationpolicyurl='".mysql_escape_string(stripslashes($_POST['donationpolicyurl']))."', ". "fundingselectiondate='".mysql_escape_string(stripslashes($_POST['fundingselectiondate']))."', ". + "proposalsubmissiondate='".mysql_escape_string(stripslashes($_POST['proposalsubmissiondate']))."', ". "waiveraccepted='".mysql_escape_string(stripslashes($_POST['waiveraccepted']))."' ". "WHERE id='$id'"; mysql_query($exec); + echo mysql_error(); //FIXME accept the logo //"logo='".mysql_escape_string(stripslashes($_POST['logo']))."', ". @@ -132,7 +134,7 @@ switch($_GET['action']) { echo ""; echo ""; echo " \n"; - echo " \n"; + echo " \n"; echo " \n"; echo " \n"; echo ""; @@ -157,7 +159,7 @@ switch($_GET['action']) { echo "
".i18n("Date")."".i18n("Goal")."".i18n("Purpose")."".i18n("Appeal")."".i18n("Value")."
"; echo ""; echo " \n"; - echo " \n"; + echo " \n"; echo " \n"; echo " \n"; echo ""; @@ -841,9 +843,9 @@ $(document).ready(function() { }); $("#organizationinfo_fundingselectiondate").datepicker({ dateFormat: 'yy-mm-dd'}); + $("#organizationinfo_proposalsubmissiondate").datepicker({ dateFormat: 'yy-mm-dd'}); //, showOn: 'button', buttonText: "" }); open_search(); - }); @@ -871,6 +873,7 @@ function open_editor(id) { $("#organizationinfo_website").val(""); $("#organizationinfo_donationpolicyurl").val(""); $("#organizationinfo_fundingselectiondate").val(""); + $("#organizationinfo_proposalsubmissiondate").val(""); $("#organizationinfo_notes").val(""); $("#organizationinfo_save_button").attr('disabled','disabled'); @@ -889,8 +892,7 @@ function open_editor(id) { function open_search() { $("#donor_editor").hide(); $("#searchbrowse").show(); - - + donorsearch(false); } function update_organizationinfo() { @@ -919,6 +921,7 @@ function update_organizationinfo() $("#organizationinfo_website").val(json.website); $("#organizationinfo_donationpolicyurl").val(json.donationpolicyurl); $("#organizationinfo_fundingselectiondate").val(json.fundingselectiondate); + $("#organizationinfo_proposalsubmissiondate").val(json.proposalsubmissiondate); $("#organizationinfo_notes").val(json.notes); // For some reason, with checkboxes, these have to be arrays $("[name=waiveraccepted]").val([json.waiveraccepted]); @@ -1011,10 +1014,13 @@ function activityinfo_save() { return false; } -function donorsearch() { +function donorsearch(realsearch) { $("#searchresults").show(); - $("#searchresults").load("donors_search.php", $("#searchform").serializeArray()); - return false; + if(realsearch) + $("#searchresults").load("donors_search.php", $("#searchform").serializeArray()); + else + $("#searchresults").load("donors_search.php"); //, $("#searchform").serializeArray()); + return false; } var searchtimer; @@ -1125,8 +1131,8 @@ echo "
"; - - + + ";
".i18n("Date")."".i18n("Goal")."".i18n("Purpose")."".i18n("Appeal")."".i18n("Value")."
"; - echo ""; - echo " "; -// echo " "; -// echo " "; - echo " "; -// echo " "; - echo "\n"; + $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 "
Organization# of Sponsorships# of Awards# of ContactsAction
"; + 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"; - - $numq=mysql_query("SELECT COUNT(id) AS num FROM award_awards WHERE year='".$config['FAIRYEAR']."' AND sponsors_id='$r->id'"); - $numr=mysql_fetch_object($numq); - $numawards=$numr->num; - - $numq=mysql_query("SELECT COUNT(id) AS num FROM fundraising_donations WHERE fiscalyear='".$config['FISCALYEAR']."' AND sponsors_id='$r->id'"); - $numr=mysql_fetch_object($numq); - $numsponsorships=$numr->num; - - $numq=mysql_query("SELECT uid,MAX(year),firstname,lastname,deleted FROM users,users_sponsor WHERE types LIKE '%sponsor%' AND sponsors_id='$r->id' AND users_sponsor.users_id=users.id AND users.deleted='no' GROUP BY uid ORDER BY firstname"); -// $numq=mysql_query("SELECT DISTINCT(uid) FROM users_sponsor, users WHERE sponsors_id='$r->id' AND users_sponsor.users_id=users.id AND users.deleted='no'"); - $numcontacts=mysql_num_rows($numq); -// $numr=mysql_fetch_object($numq); -// $numcontacts=$numr->num; - - -/* - echo " "; - - echo " "; - */ - - echo " "; + $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 "
Donor/SponsorTotal $ this yearTotal $ last year% change
$r->organization"; - echo "$numsponsorships  "; - echo "id\">\"view\""; - echo ""; - echo "$numawards  "; - echo "id\">\"view\""; - echo ""; - echo "$numcontacts  "; -// echo "id\">\"view\""; - echo "{$r['name']}"; + echo format_money($r['thisyeartotal']); + echo ""; + echo format_money($r['lastyeartotal']); + echo ""; + echo $r['change'].$sign; + echo "
\n";