| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: donation.module,v 1.3 2009/03/14 21:00:35 kbahey Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 33 |
define ('DONATION_PAGE_TITLE', 'donation_page_title'); |
define ('DONATION_PAGE_TITLE', 'donation_page_title'); |
| 34 |
define ('DONATION_DEFAULT_PAGE_TITLE', t('Donate')); |
define ('DONATION_DEFAULT_PAGE_TITLE', t('Donate')); |
| 35 |
define ('DONATION_DEFAULT_EMAIL', t('webmaster@localhost')); |
define ('DONATION_DEFAULT_EMAIL', t('webmaster@localhost')); |
| 36 |
|
define ('DONATION_UPDATE_DONATIONS_THERMOMETER', 'donation_update_donations_thermometer'); |
| 37 |
|
|
| 38 |
/** |
/** |
| 39 |
* Implementation of hook_perm(). |
* Implementation of hook_perm(). |
| 231 |
'#description' => t('This text will be displayed to the user after they come back from Paypal.'), |
'#description' => t('This text will be displayed to the user after they come back from Paypal.'), |
| 232 |
); |
); |
| 233 |
|
|
| 234 |
|
$form['integration'] = array( |
| 235 |
|
'#type' => 'fieldset', |
| 236 |
|
'#title' => t('Integration'), |
| 237 |
|
'#collapsible' => TRUE, |
| 238 |
|
'#collapsed' => FALSE, |
| 239 |
|
); |
| 240 |
|
|
| 241 |
|
$form['integration'][DONATION_UPDATE_DONATIONS_THERMOMETER] = array('#type' => 'checkbox', |
| 242 |
|
'#title' => t('Update Donations Thermometer Amount'), |
| 243 |
|
'#default_value' => variable_get(DONATION_UPDATE_DONATIONS_THERMOMETER, 0), |
| 244 |
|
'#disabled' => !module_exists('donations_thermometer') ? TRUE : FALSE, |
| 245 |
|
'#description' => t('When enabled the Donations Thermometer Amount is automatically updated with the total of donations.'), |
| 246 |
|
); |
| 247 |
|
|
| 248 |
return system_settings_form($form); |
return system_settings_form($form); |
| 249 |
} |
} |
| 250 |
|
|
| 371 |
$form_state['values']['currency'], |
$form_state['values']['currency'], |
| 372 |
$form_state['values']['status']); |
$form_state['values']['status']); |
| 373 |
drupal_set_message(t('The donation has been added.')); |
drupal_set_message(t('The donation has been added.')); |
| 374 |
|
donation_update_donation_thermometer_amount(); |
| 375 |
break; |
break; |
| 376 |
|
|
| 377 |
case 'edit': |
case 'edit': |
| 387 |
$form_state['values']['status'], |
$form_state['values']['status'], |
| 388 |
$form_state['values']['did']); |
$form_state['values']['did']); |
| 389 |
drupal_set_message(t('The donation has been updated.')); |
drupal_set_message(t('The donation has been updated.')); |
| 390 |
|
donation_update_donation_thermometer_amount(); |
| 391 |
} |
} |
| 392 |
break; |
break; |
| 393 |
|
|
| 395 |
if ($form_state['values']['did']) { |
if ($form_state['values']['did']) { |
| 396 |
db_query("DELETE FROM {donations} WHERE did = %d", $form_state['values']['did']); |
db_query("DELETE FROM {donations} WHERE did = %d", $form_state['values']['did']); |
| 397 |
drupal_set_message(t('The donation has been deleted.')); |
drupal_set_message(t('The donation has been deleted.')); |
| 398 |
|
donation_update_donation_thermometer_amount(); |
| 399 |
} |
} |
| 400 |
break; |
break; |
| 401 |
} |
} |
| 455 |
} |
} |
| 456 |
|
|
| 457 |
drupal_set_message(t('The donations have been imported.')); |
drupal_set_message(t('The donations have been imported.')); |
| 458 |
|
donation_update_donation_thermometer_amount(); |
| 459 |
drupal_goto('admin/build/donations'); |
drupal_goto('admin/build/donations'); |
| 460 |
} |
} |
| 461 |
|
|
| 557 |
$amount, |
$amount, |
| 558 |
$currency, |
$currency, |
| 559 |
variable_get(DONATION_STATE, DONATION_PUBLIC)); |
variable_get(DONATION_STATE, DONATION_PUBLIC)); |
| 560 |
|
donation_update_donation_thermometer_amount(); |
| 561 |
watchdog('donation', 'Donation from @name (@mail) amount of @amount @currency.', array( |
watchdog('donation', 'Donation from @name (@mail) amount of @amount @currency.', array( |
| 562 |
'@name' => $name, |
'@name' => $name, |
| 563 |
'@mail' => $payer_email, |
'@mail' => $payer_email, |
| 634 |
return $form; |
return $form; |
| 635 |
} |
} |
| 636 |
|
|
| 637 |
|
/** |
| 638 |
|
* Return the total amount of the donations |
| 639 |
|
*/ |
| 640 |
|
|
| 641 |
|
function donation_total() { |
| 642 |
|
$sql = 'SELECT SUM(d.Amount) FROM {donations} d WHERE d.status=1'; |
| 643 |
|
$result = db_result(db_query($sql)); |
| 644 |
|
$result = check_plain(sprintf('%.2f',$result)); |
| 645 |
|
return $result; |
| 646 |
|
} |
| 647 |
|
|
| 648 |
|
/** |
| 649 |
|
* If enabled update the donations_thermometer_amount |
| 650 |
|
*/ |
| 651 |
|
|
| 652 |
|
function donation_update_donation_thermometer_amount() { |
| 653 |
|
if (variable_get(DONATION_UPDATE_DONATIONS_THERMOMETER, 0) == 1) { |
| 654 |
|
variable_set('donations_thermometer_amount', donation_total()); |
| 655 |
|
} |
| 656 |
|
} |