• Donate now.
  • This page lists all donors.

  • ')); define ('DONATION_DONATE_MESSAGE', 'donation_donate_message'); define ('DONATION_DONATE_MESSAGE_DEFAULT_TEXT', t('Please make a donation.')); define ('DONATION_CURRENCY_TEXT', 'donation_currency_text'); define ('DONATION_CURRENCY_DEFAULT_TEXT', t('We accept payments in these currencies.')); define ('DONATION_AMOUNT_TEXT', 'donation_amount_text'); define ('DONATION_AMOUNT_DEFAULT_TEXT', t('Enter the amount you wish to donate.')); define ('DONATION_SUBMIT_TEXT', 'donation_submit_text'); define ('DONATION_SUBMIT_DEFAULT_TEXT', t('Proceed to paypal.com for payment')); define ('DONATION_MEMO_TEXT', 'donation_memo_text'); define ('DONATION_MEMO_DEFAULT_TEXT', t('Website Donation')); 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'); define ('DONATION_CONTENT_TYPE', 'donations_content_type'); define ('DONATION_CONTENT_TYPE_DEFAULT', 'donation_target'); define ('DONATION_TARGET_TEXT', 'donations_content_type_text'); define ('DONATION_TARGET_DEFAULT_TEXT', 'Please choose the project you want to support'); define ('DONATION_GENERIC_TEXT', 'donations_generic_text'); define ('DONATION_GENERIC_DEFAULT_TEXT', 'Make a generic donation'); /** * Implementation of hook_perm(). */ function donation_perm() { return array('administer donations'); } /** * Implementation of hook_menu(). */ function donation_menu() { $items = array(); $access = array('administer site configuration'); $items['ipn/donation'] = array( 'page callback' => 'donation_ipn', 'type' => MENU_CALLBACK, 'access callback' => TRUE, ); $items['donation/thanks'] = array( 'title' => variable_get(DONATION_THANKS_TITLE, DONATION_THANKS_DEFAULT_TITLE), 'page callback' => 'donation_thanks', 'type' => MENU_CALLBACK, 'access callback' => TRUE, ); $items['admin/settings/donations'] = array( 'title' => 'Donations', 'page callback' => 'drupal_get_form', 'page arguments' => array('donation_settings'), 'description' => 'Administer donations', 'access arguments' => $access, ); $items['admin/build/donations'] = array( 'title' => 'Donations', 'access arguments' => $access, 'page callback' => 'donation_admin', 'description' => 'Manages donations to your site via Paypal', ); $items['admin/build/donations/list'] = array( 'title' => 'List', 'access arguments' => $access, 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items['admin/build/donations/add'] = array( 'title' => 'Add donation', 'access arguments' => $access, 'page callback' => 'drupal_get_form', 'page arguments' => array('donation_edit', 'add'), 'type' => MENU_LOCAL_TASK, ); $items['admin/build/donations/edit'] = array( 'title' => 'Edit donation', 'access arguments' => $access, 'page callback' => 'drupal_get_form', 'page arguments' => array('donation_edit', 'edit'), 'type' => MENU_CALLBACK, ); $items['admin/build/donations/delete'] = array( 'title' => 'Delete donation', 'access arguments' => $access, 'page callback' => 'drupal_get_form', 'page arguments' => array('donation_edit', 'delete'), 'type' => MENU_CALLBACK, ); $items['admin/build/donations/import'] = array( 'title' => 'Import', 'access arguments' => $access, 'page callback' => 'drupal_get_form', 'page arguments' => array('donation_import'), 'type' => MENU_CALLBACK, ); $items['donate'] = array( 'title' => variable_get(DONATION_PAGE_TITLE, DONATION_DEFAULT_PAGE_TITLE), 'page callback' => 'drupal_get_form', 'page arguments' => array('donation_form_build'), 'type' => MENU_CALLBACK, 'access callback' => TRUE, ); $items['donate/%'] = array( 'title' => variable_get(DONATION_PAGE_TITLE, DONATION_DEFAULT_PAGE_TITLE), 'page callback' => 'drupal_get_form', 'page arguments' => array('donation_form_build', 1), 'type' => MENU_CALLBACK, 'access callback' => TRUE, ); $items['hiddendonations'] = array( 'title' => 'Donations', 'page callback' => 'donation_public_page', 'type' => MENU_CALLBACK, 'access callback' => TRUE, ); return $items; } /** * Implementation of hook_settings(). */ function donation_settings() { $form['general'] = array( '#type' => 'fieldset', '#title' => t('General Settings'), '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form['general'][DONATION_EMAIL] = array( '#type' => 'textfield', '#title' => t('Donations email address'), '#default_value' => variable_get(DONATION_EMAIL, DONATION_DEFAULT_EMAIL), '#description' => t('Only donations to this email address are considered by this module.'), ); $form['general'][DONATION_STATE] = array( '#type' => 'select', '#title' => t('Default donation state'), '#default_value' => variable_get(DONATION_STATE, DONATION_PUBLIC), '#options' => array( DONATION_PUBLIC => t('Public'), DONATION_HIDDEN => t('Hidden') ), '#description' => t('Select whether donations will be public or private for this site.'), ); $form['general'][DONATION_MEMO_TEXT] = array( '#type' => 'textfield', '#title' => t('Text for the PayPal memo field'), '#default_value' => variable_get(DONATION_MEMO_TEXT, DONATION_MEMO_DEFAULT_TEXT), '#description' => t('This text will be sent to PayPal in the memo field.'), '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form['donate_page'] = array( '#type' => 'fieldset', '#title' => t('Donate Page'), '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form['donate_page'][DONATION_PAGE_TITLE] = array( '#type' => 'textfield', '#title' => t('Title for the donate page'), '#default_value' => variable_get(DONATION_PAGE_TITLE, DONATION_DEFAULT_PAGE_TITLE), '#description' => t('This text will be used as the Title for the donate page.'), ); $form['donate_page'][DONATION_DONATE_MESSAGE] = array( '#type' => 'textarea', '#title' => t('Introductory text for the donate page'), '#default_value' => variable_get(DONATION_DONATE_MESSAGE, DONATION_DONATE_MESSAGE_DEFAULT_TEXT), '#description' => t('This text will be displayed to the user after they come back from Paypal.'), ); $form['donate_page'][DONATION_CURRENCY_TEXT] = array( '#type' => 'textfield', '#title' => t('Description text for the currency field'), '#default_value' => variable_get(DONATION_CURRENCY_TEXT, DONATION_CURRENCY_DEFAULT_TEXT), '#description' => t('This text will be displayed as the description for the currency field on the donate page.'), ); $form['donate_page'][DONATION_AMOUNT_TEXT] = array( '#type' => 'textfield', '#title' => t('Description text for the amount field'), '#default_value' => variable_get(DONATION_AMOUNT_TEXT, DONATION_AMOUNT_DEFAULT_TEXT), '#description' => t('This text will be displayed as the description for the amount field on the donate page.'), ); $form['donate_page'][DONATION_SUBMIT_TEXT] = array( '#type' => 'textfield', '#title' => t('Text for the Submit button'), '#default_value' => variable_get(DONATION_SUBMIT_TEXT, DONATION_SUBMIT_DEFAULT_TEXT), '#description' => t('This text will be displayed on the Submit button of the donate page.'), ); $form['misc'] = array( '#type' => 'fieldset', '#title' => t('Miscellaneous'), '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form['misc'][DONATION_DONORS_TEXT] = array( '#type' => 'textarea', '#title' => t('Text for the donors list page'), '#default_value' => variable_get(DONATION_DONORS_TEXT, DONATION_DONORS_DEFAULT_TEXT), '#description' => t('This text will be displayed at the top of the donors list page.'), ); $form['misc'][DONATION_THANKS_TITLE] = array( '#type' => 'textfield', '#title' => t('Title for the donations thank you page'), '#default_value' => variable_get(DONATION_THANKS_TITLE, DONATION_THANKS_DEFAULT_TITLE), '#description' => t('This text will be the Title of the page the user sees after they come back from Paypal.'), ); $form['misc'][DONATION_THANKS_TEXT] = array( '#type' => 'textarea', '#title' => t('Text for the donations thank you page'), '#default_value' => variable_get(DONATION_THANKS_TEXT, DONATION_THANKS_DEFAULT_TEXT), '#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. This requires the !mod module.', array('!mod' => 'donations thermometer')), ); return system_settings_form($form); } /** * FAPI definition for the donation edit form. * * @ingroup forms * @see donation_edit_submit() */ function donation_edit(&$form_state, $mode) { $timestamp = format_date(time(), 'custom', 'Y-m-d H:i O'); switch ($mode) { case 'edit': case 'delete': $did = (int)arg(4); if ($did) { $result = db_query('SELECT * FROM {donations} WHERE did = %d', $did); $donation = db_fetch_object($result); $timestamp = format_date($donation->timestamp, 'custom', 'Y-m-d H:i O'); $uid = $donation->uid; } } $form['timestamp'] = array( '#type' => 'textfield', '#title' => t('Date'), '#default_value' => $timestamp, '#size' => 30, '#maxlength' => 30, '#description' => 'Format: Y-M-D H:M Z', ); $form['uid'] = array( '#type' => 'textfield', '#title' => t('User ID'), '#default_value' => $uid, '#description' => t('If the user is registered on this site, enter his/her the Drupal uid.'), ); $form['name'] = array( '#type' => 'textfield', '#title' => t('Name of donor'), '#default_value' => $donation->name, '#size' => 60, '#maxlength' => 60, '#description' => t('The name of the person or the company who donated money.'), ); $form['mail'] = array( '#type' => 'textfield', '#title' => t('E-mail address of donor'), '#default_value' => $donation->mail, '#size' => 60, '#maxlength' => 60, '#description' => t('The e-mail address of the person or the company who donated money.'), ); $form['amount'] = array( '#type' => 'textfield', '#title' => t('Amount'), '#default_value' => $donation->amount, '#size' => 12, '#maxlength' => 12, '#description' => t('The amount of money donated, after subtracting transfer fees.'), ); $form['currency'] = array( '#type' => 'select', '#title' => t('Currency'), '#default_value' => $donation->currency, '#options' => simple_paypal_get_currencies(), ); $form['status'] = array( '#type' => 'select', '#title' => t('Status'), '#default_value' => $donation->status, '#options' => array( DONATION_PUBLIC => t('Public'), DONATION_HIDDEN => t('Hidden') ), ); if ($mode == 'delete') { $form['delete'] = array( '#type' => 'submit', '#value' => t('Delete'), ); } else { $form['add'] = array( '#type' => 'submit', '#value' => t('Save'), ); } $form['mode'] = array( '#type' => 'hidden', '#value' => $mode, ); $form['did'] = array( '#type' => 'hidden', '#value' => $did, ); return ($form); } /** * Submit handler for donation edit form */ function donation_edit_submit($form, &$form_state) { $mode = $form_state['values']['mode']; if ($form_state['values']['delete'] == t('Delete')) { $mode = 'delete'; } switch ($mode) { case 'add': db_query("INSERT INTO {donations} (timestamp, uid, name, mail, amount, currency, status) VALUES (%d, %d, '%s', '%s', '%s', '%s', %d)", strtotime($form_state['values']['timestamp']), $form_state['values']['uid'], $form_state['values']['name'], $form_state['values']['mail'], $form_state['values']['amount'], $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': if ($form_state['values']['did']) { db_query("UPDATE {donations} SET timestamp = %d, uid = %d, name = '%s', mail = '%s', amount = %f, currency = '%s', status = %d WHERE did = %d", strtotime($form_state['values']['timestamp']), $form_state['values']['uid'], $form_state['values']['name'], $form_state['values']['mail'], $form_state['values']['amount'], $form_state['values']['currency'], $form_state['values']['status'], $form_state['values']['did']); drupal_set_message(t('The donation has been updated.')); donation_update_donation_thermometer_amount(); } break; case 'delete': 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; } drupal_goto('admin/build/donations'); } /** * FAPI definition for the donation import form. * * @ingroup forms * @see donate_form_edit_submit() */ function donation_import($form = NULL) { $form = array( '#value' => t('Paypal lets you export your payment history to a CSV file. Copy/paste the contents of the file (or parts thereof) in the form below to mass import your Paypal history into Drupal. Note that the import routine does not check for duplicate entries.'), ); $form['data'] = array( '#type' => 'textarea', '#title' => t('Data'), '#default_value' => NULL, '#cols' => 70, '#rows' => 30, ); $form['import'] = array( '#type' => 'submit', '#value' => t('Import donations'), ); return $form; } function donation_import_submit($form, &$form_state) { $lines = explode("\n", $form_state['values']['data']); foreach ($lines as $line) { list($date, $time, $timezone, $name, $type, $status, $currency, $gross, $fee, $net, $from_email, $to_email, $tid, $cp_status, $shipping_address, $address_status, $item_title, $item_id, $sh_amount, $insurance_amount, $sales_tax, $opt_1_name, $opt_1_value, $opt_2_name, $opt_2_value, $auction_site, $buyer_id, $item_url, $closing_date, $escrow_id, $invoice_id, $ref_txn_id, $invoice_number, $custom_number, $receipt_id, $contact_phone_number ) = explode('","', $line); if ($to_email == variable_get(DONATION_EMAIL, DONATION_DEFAULT_EMAIL) && $name && $net) { // We need to swap the day and month in Paypal's date format: list($month, $day, $year) = explode('/', substr($date, 1), 3); $uid = donation_resolve_uid($mail); db_query("INSERT INTO {donations} (timestamp, uid, name, mail, amount, currency, status) VALUES (%d, %d, '%s', '%s', '%s', '%s', %d)", strtotime("$month/$day/$year $time $timezone"), // date + time + timezone $uid, $name, $from_email, (float)str_replace(',', '', $net), // net amount (gross - fee), commas stripped $currency, variable_get(DONATION_STATE, DONATION_PUBLIC)); } } drupal_set_message(t('The donations have been imported.')); donation_update_donation_thermometer_amount(); drupal_goto('admin/build/donations'); } function donation_resolve_uid($mail) { return (int)db_result(db_query("SELECT uid FROM {users} WHERE mail = '%s'", $mail)); } function donation_admin() { $rows = array(); $header = array( array('data' => t('Date'), 'field' => 'timestamp', 'sort' => 'desc'), array('data' => t('Name'), 'field' => 'name'), array('data' => t('Amount'), 'field' => 'amount'), array('data' => t('Status'), 'field' => 'status'), array('data' => t('Operations'), 'colspan' => '2') ); $sql = 'SELECT d.* FROM {donations} d'. tablesort_sql($header); $result = pager_query($sql, DONATION_PAGER, 0, NULL); while ($donation = db_fetch_object($result)) { $rows[] = array(format_date($donation->timestamp, 'small'), ($donation->uid ? theme('username', $donation) : check_plain($donation->name)), simple_paypal_format_amount($donation->amount, $donation->currency), ($donation->status == DONATION_PUBLIC ? t('public') : t('hidden')), "mail\">". t('mail') ."", l(t('edit'), "admin/build/donations/edit/$donation->did"), l(t('delete'), "admin/build/donations/delete/$donation->did"), ); } $output = theme('table', $header, $rows); $output .= theme('pager', NULL, DONATION_PAGER, 0); print theme('page', $output); } function donation_get_list($nid = NULL) { $html = ''; $rows = array(); $header = array( array('data' => t('Name'), 'field' => 'name'), array('data' => t('Amount'), 'field' => 'amount'), array('data' => t('Date'), 'field' => 'timestamp', 'sort' => 'desc'), ); if (!$nid) { $sql = 'SELECT d.* FROM {donations} d WHERE d.status = %d'. tablesort_sql($header); $result = pager_query($sql, DONATION_PAGER, 0, NULL, DONATION_PUBLIC); } else { $sql = 'SELECT d.* FROM {donations} d WHERE d.status = %d AND d.nid = %d'. tablesort_sql($header); $result = pager_query($sql, DONATION_PAGER, 0, NULL, DONATION_PUBLIC, $nid); } while ($donation = db_fetch_object($result)) { if ($donation->uid) { $user = user_load(array('uid' => $donation->uid)); $name = theme('username', $user); } else { $name = $donation->name; } $rows[] = array( $name, simple_paypal_format_amount($donation->amount, $donation->currency), t('%time ago', array('%time' => format_interval(time() - $donation->timestamp, 1)))); } $html .= theme('table', $header, $rows); $html .= theme('pager', NULL, DONATION_PAGER, 0); return $html; } function donation_public_page() { $output = variable_get(DONATION_DONORS_TEXT, DONATION_DONORS_DEFAULT_TEXT); $output .= theme('table', $header, $rows); $output .= donation_get_list(); print theme('page', $output); } function donation_thanks() { print theme('page', variable_get(DONATION_THANKS_TEXT, DONATION_THANKS_DEFAULT_TEXT)); } function donation_ipn() { // Verify that the request came from Paypal, and not from some intrusion if (!simple_paypal_ipn_verify($_POST)) { // curl verification failed watchdog('donation', 'curl verification failed'); return; } $receiver = $_POST['business']; if ($receiver == '') { $receiver = $_POST['receiver_email']; } if ($receiver != variable_get(DONATION_EMAIL, DONATION_DEFAULT_EMAIL)) { // Payment is not for the email address configured watchdog('donation', 'Donation was not considered: Payment is not for the email address configured'); return; } // Format the fields $name = check_plain($_POST['first_name'] .' '. $_POST['last_name'] . ($_POST['payer_business_name'] ? ' ('. $_POST['payer_business_name'] .')' : '')); $amount = check_plain((float)$_POST['mc_gross'] - (float)$_POST['mc_fee']); $fee = check_plain($_POST['mc_fee']); $timestamp = check_plain(strtotime($_POST['payment_date'])); $payer_email = check_plain($_POST['payer_email']); $currency = check_plain($_POST['mc_currency']); $uid = check_plain($_POST['custom']); $uid = $uid ? $uid : donation_resolve_uid($mail); $memo = check_plain($_POST['item_name']); $nid = 0; $pattern = '/\[PROJECT:(.*)\]/'; preg_match($pattern, $memo, $matches); if (count($matches) > 0) { $memo = trim(str_replace($matches[0], '', $zeichenkette)); $nid = $matches[1]; } // Record the donation in the database db_query("INSERT INTO {donations} (timestamp, uid, name, mail, amount, fee, currency, status, donor_memo, nid) VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', %d, '%s', '%d')", $timestamp, $uid, $name, $payer_email, $amount, $fee, $currency, variable_get(DONATION_STATE, DONATION_PUBLIC), $memo, $nid); $did = db_last_insert_id('donations', 'did'); $res = db_query('SELECT * FROM {donations} WHERE did=%d', $did); $donation = db_fetch_object($res); donation_update_donation_thermometer_amount(); watchdog('donation', 'Donation from @name (@mail) amount of @amount @currency.', array( '@name' => $name, '@mail' => $payer_email, '@amount' => $amount, '@currency' => $currency, )); module_invoke_all('donation_received', $donation); } /** * Output this function in a PHP node when you want a form which points to Paypal. */ function donation_form() { return drupal_get_form('donation_form_build'); } function donation_form_build($form_data, $nid = null) { global $user; $memo_text = variable_get(DONATION_MEMO_TEXT, DONATION_MEMO_DEFAULT_TEXT); $donation_message = t(variable_get(DONATION_DONATE_MESSAGE, DONATION_DONATE_MESSAGE_DEFAULT_TEXT)); if ($nid != null) { $res = db_query('SELECT nid, title FROM {node} WHERE type=\'%s\' AND nid=%d', variable_get(DONATION_CONTENT_TYPE, DONATION_CONTENT_TYPE_DEFAULT), $nid); if ($node = db_fetch_object($res)) { $memo_text .= ' [PROJECT:' . $node->nid . ']'; $donation_message .= '

    ' . t('Target') . ': ' . $node->title; } else { $nid = null; } } if ($nid==null) { $memo = variable_get(DONATION_MEMO_TEXT, DONATION_MEMO_DEFAULT_TEXT); $targets = array($memo => variable_get(DONATION_GENERIC_TEXT, DONATION_GENERIC_DEFAULT_TEXT)); $res = db_query('SELECT nid, title FROM {node} WHERE type=\'%s\'', variable_get(DONATION_CONTENT_TYPE, DONATION_CONTENT_TYPE_DEFAULT)); while ($node = db_fetch_object($res)) { $targets[$memo . ' [PROJECT:' . $node->nid . ']'] = $node->title; } } $form['#action'] = simple_paypal_get_url(); $form['pre'] = array( '#value' => $donation_message); $form['business'] = array( '#type' => 'hidden', '#name' => 'business', '#value' => variable_get(DONATION_EMAIL, DONATION_DEFAULT_EMAIL)); $form['cmd'] = array( '#type' => 'hidden', '#value' => '_xclick', '#name' => 'cmd'); if ((count($targets) > 1) && ($nid == null)){ $form['item_name'] = array( '#type' => 'select', '#name' => 'item_name', '#options' => $targets, '#description' => t(variable_get(DONATION_TARGET_TEXT, DONATION_TARGET_DEFAULT_TEXT)) ); } else { $form['item_name'] = array( '#type' => 'hidden', '#value' => $memo_text, '#name' => 'item_name' ); } $form['no_shipping'] = array( '#type' => 'hidden', '#value' => 1, '#name' => 'no_shipping'); $form['return'] = array( '#type' => 'hidden', '#value' => url('donation/thanks', array('absolute' => TRUE)), '#name' => 'return'); $form['currency_code'] = array( '#type' => 'select', '#title' => t('Currency'), '#options' => simple_paypal_get_currencies(), '#name' => 'currency_code', '#description' => t(variable_get(DONATION_CURRENCY_TEXT, DONATION_CURRENCY_DEFAULT_TEXT)), ); $form['amount'] = array( '#type' => 'textfield', '#title' => t('Amount'), '#description' => t(variable_get(DONATION_AMOUNT_TEXT, DONATION_AMOUNT_DEFAULT_TEXT)), '#size' => 40, '#required' => TRUE, '#maxlength' => 255, '#name' => 'amount', '#value' => '10.00', ); $form['notify_url'] = array( '#type' => 'hidden', '#value' => url('ipn/donation', array('absolute' => TRUE)), '#name' => 'notify_url', ); $form['custom'] = array( '#type' => 'hidden', '#value' => $user->uid, '#name' => 'custom', ); $form['submit'] = array( '#type' => 'submit', '#value' => t(variable_get(DONATION_SUBMIT_TEXT, DONATION_SUBMIT_DEFAULT_TEXT)), '#name' => 'submit', ); 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()); } }