--- donation-6.x-1.x.module 2009-03-14 21:00:35.000000000 +0000 +++ donation.module 2009-07-10 08:29:54.000000000 +0100 @@ -33,6 +33,7 @@ define ('DONATION_MEMO_DEFAULT_TEXT', define ('DONATION_PAGE_TITLE', 'donation_page_title'); define ('DONATION_DEFAULT_PAGE_TITLE', t('Donate')); define ('DONATION_DEFAULT_EMAIL', t('webmaster@localhost')); +define ('DONATION_UPDATE_DONATIONS_THERMOMETER', 'donation_update_donations_thermometer'); /** * Implementation of hook_perm(). @@ -230,6 +231,20 @@ function donation_settings() { '#description' => t('This text will be displayed to the user after they come back from Paypal.'), ); + $form['integration'] = array( + '#type' => 'fieldset', + '#title' => t('Integration'), + '#collapsible' => TRUE, + '#collapsed' => FALSE, + ); + + $form['integration'][DONATION_UPDATE_DONATIONS_THERMOMETER] = array('#type' => 'checkbox', + '#title' => t('Update Donations Thermometer Amount'), + '#default_value' => variable_get(DONATION_UPDATE_DONATIONS_THERMOMETER, 0), + '#disabled' => !module_exists('donations_thermometer') ? TRUE : FALSE, + '#description' => t('When enabled the Donations Thermometer Amount is automatically updated with the total of donations.'), + ); + return system_settings_form($form); } @@ -356,6 +371,7 @@ function donation_edit_submit($form, &$f $form_state['values']['currency'], $form_state['values']['status']); drupal_set_message(t('The donation has been added.')); + donation_update_donation_thermometer_amount(); break; case 'edit': @@ -371,6 +387,7 @@ function donation_edit_submit($form, &$f $form_state['values']['status'], $form_state['values']['did']); drupal_set_message(t('The donation has been updated.')); + donation_update_donation_thermometer_amount(); } break; @@ -378,6 +395,7 @@ function donation_edit_submit($form, &$f if ($form_state['values']['did']) { db_query("DELETE FROM {donations} WHERE did = %d", $form_state['values']['did']); drupal_set_message(t('The donation has been deleted.')); + donation_update_donation_thermometer_amount(); } break; } @@ -437,6 +455,7 @@ function donation_import_submit($form, & } drupal_set_message(t('The donations have been imported.')); + donation_update_donation_thermometer_amount(); drupal_goto('admin/build/donations'); } @@ -538,6 +557,7 @@ function donation_ipn() { $amount, $currency, variable_get(DONATION_STATE, DONATION_PUBLIC)); + donation_update_donation_thermometer_amount(); watchdog('donation', 'Donation from @name (@mail) amount of @amount @currency.', array( '@name' => $name, '@mail' => $payer_email, @@ -614,3 +634,23 @@ function donation_form_build() { return $form; } +/** + * Return the total amount of the donations + */ + +function donation_total() { + $sql = 'SELECT SUM(d.Amount) FROM {donations} d WHERE d.status=1'; + $result = db_result(db_query($sql)); + $result = check_plain(sprintf('%.2f',$result)); + return $result; +} + +/** + * If enabled update the donations_thermometer_amount + */ + +function donation_update_donation_thermometer_amount() { + if (variable_get(DONATION_UPDATE_DONATIONS_THERMOMETER, 0) == 1) { + variable_set('donations_thermometer_amount', donation_total()); + } +} \ No newline at end of file