Having a thermometer to track donation progress would be great. Perhaps a future release could include a built-in block?

To kick off, here is a snippet I wrote to make your own block:

<?php
$goal=50000; // your total fundraising goal
$width=170;  //width of the thermometer in pixels

$sql = "SELECT  d.uid, d.datepaid, d.mc_gross, d.mc_currency FROM {lm_paypal_donations} d";
$result = db_query_range($sql, $uid, 0, 9999); 
$total=0;
$total=0;
while ($donation = db_fetch_object($result)) { 
	if ($donation->mc_currency == 'USD') {
		$total += ($donation->mc_gross)/1.35;  //preform inaccurate currency conversion to Euros
	} else  {
		$total += $donation->mc_gross;
	}
	$count+=1;
}

$o="<table cellpadding=0 cellspacing=0 border=2px><tr>";

$o.='<td width='.round($total/$goal*$width,0).'px bgcolor=#00FF00 align="right">';
if ($total/$goal > 0.5) $o.=round($total/$goal*100,1)."%&nbsp;"; 
$o.='</td><td width='.round((1-$total/$goal)*$width,0).'px bgcolor=#FFFFFF>&nbsp;';
if ($total/$goal < 0.5) $o.=round($total/$goal*100,1)."%";
$o.="</td></tr></table><br>";

print $o;

print $count . ' donations, with <strong>'. round($total,2) . ' &euro;</strong> raised towards our goal of '.$goal.' &euro;';

?>

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

goodluck4287’s picture

Can you please assist me with how to use this. I am relatively new to the Drupal scene, I know a little PHP, so I understand a lot of the code. As far as inputting it into a block, I have done that and created it, now what?

Can you please contact me through drupal or on aim at l i n k i n p a r k g t r g u y without the spaces of course. (A little less porn spam for me). Thank you so much, and I will of course give credit where it is due on the site.

goodluck4287’s picture

Ok got that part up, now I need to hold true and try to get that currency changed to $, change the amount, and how do I link it to Paypal. I also need to set up the databases in sql. Do you have an sql config file set up that you can share?

toemaz’s picture

Version: master » 6.x-2.x-dev
Status: Active » Needs review

I started from a the original snippet and created a contrib module for D6: lm_paypal_meter
Find it attached.

toemaz’s picture

FileSize
1.8 KB

Attaching it again (perhaps a chrome issue)

toemaz’s picture

FileSize
1.88 KB

Forgot to use hook_theme. Better now.

Cyberflyer’s picture

Do I need to be running lm_PayPal 2.x to use this module?

toemaz’s picture

I run the 6.x-1.0 and it works perfect as you will see at http://musescore.org/donate

Junro’s picture

Code is perfect :) Thanks

toemaz’s picture

@Junro @Cyberflyer

Can you both confirm that you are running it successfully in production? Don't forget to add your lm_paypal release version.
Than I can add this as RTBC.

Junro’s picture

I'm using 6.x-1.x-dev in production site.

toemaz’s picture

Status: Needs review » Reviewed & tested by the community

To the lm_paypal module maintainers: should this be committed in the contrib directory or do you think this should get it's own project? Keep in mind it's pretty small module so not a lot of maintenance work.

toemaz’s picture

Find patch attached

lyricnz’s picture

Status: Reviewed & tested by the community » Needs work

(If you upload a new patch, please set status back to needs-review, rather than RTBC)

PS: The patch contains code unrelated to this feature-request (role/user_save)

Also, using round($total,2) results in output like

28 donations received, $773.8 raised. Our goal is $1500 for this year

(as currently seen on http://musescore.org/donate - posted above). Suggest sprintf('%2d') or something like that? Also, HTML output should include quotes around attributes:

 $o = "<table cellpadding=0 cellspacing=0 border=2px><tr>";

needs quotes.

greenpaisley’s picture

Can this be used for multiple PayPal donation buttons?

I have a website with several grants that need funding. All are listed with their own PayPal donation buttons. I would like a progress meter under each one.

Thanks for your time!

John Franklin’s picture

The user_save() bit is patched in #137494: Other Modules not notifed of role changes.

In theme_lm_paypal_meter_display(), $goal may be zero (0) if a target hasn't been set yet. This causes a handful of Warning: Division by zero errors.

Any chance of a 6.x-1.x or 2.x release any time soon? It has been over 2 years since the last one.

John Franklin’s picture

Version: 6.x-2.x-dev » 6.x-1.x-dev
Status: Needs work » Needs review
FileSize
4.37 KB

Patch re-rolled. Includes:

  • no user_save() patch
  • sprintf("%0.2f", $value) for donation amounts
  • Don't show thermometer if goal is unset.
John Franklin’s picture

This submodule should depend on lm_paypal_donations, not lm_paypal.

John Franklin’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev

I'm going to add this to the 6.x-2.x branch. The 1.x branch is going to be bug-fixes only.

bloodyred’s picture

Files already patched or in a zip form would be nice for this that don't have shell access

John Franklin’s picture

Version: 6.x-2.x-dev » 7.x-1.x-dev
Status: Needs review » Patch (to be ported)

Committed. Thanks for the patch.