'birthdays', 'title' => t('Birthdays'), 'access' => user_access('access birthdays'), 'callback' => 'birthdays_page', 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/settings/birthdays', 'title' => t('Birthdays'), 'description' => t('Set user birthday mail and toggle user mail, upcomming birthdays mail and more.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('birthdays_admin_settings'), 'access' => user_access('administer site configuration'), 'type' => MENU_NORMAL_ITEM, ); return $items; } /** * Implementation of hook_form(). */ function birthdays_admin_settings() { // Most date-formats that are useful $dates = array('Y-m-d', 'm/d/Y', 'd/m/Y', 'Y/m/d', 'M j Y', 'j M Y', 'Y M j', 'F j, Y', 'j F, Y', 'Y, F j', 'F j, Y', 'j F Y', 'Y, F j', 'j. F Y'); // Date settings: construct choices for user foreach ($dates as $f) { $datechoices[$f] = format_date(time(), 'custom', $f); } $form['birthdays_use_starsign'] = array( '#type' => 'radios', '#title' => t('Show star signs'), '#default_value' => variable_get('birthdays_use_starsign', 1), '#options' => array(1 => t('Yes'), 0 => t('No')), '#description' => t('Select whether the star signs should be enabled') ); $form['birthdays_date_format'] = array( '#type' => 'select', '#title' => t('Birthday date format'), '#default_value' => variable_get('birthdays_date_format', $dates[1]), '#options' => $datechoices, '#description' => t('The format of the birthday date display.') ); $form['birthdays_profile_category'] = array( '#type' => 'textfield', '#title' => t('Profile category'), '#default_value' => variable_get('birthdays_profile_category', t('My profile')), '#description' => t('In what profile category should the date of birth be placed? Default is on the main profile page, do not change if not sure..') ); $form['birthdays_required'] = array( '#type' => 'radios', '#title' => t('Input required'), '#default_value' => variable_get('birthdays_required', 0), '#options' => array(1 => t('Yes'), 0 => t('No')), '#description' => t('Are users required to fill in their birthday?') ); $form['birthdays_email'] = array( '#type'=>'fieldset', '#title' => t('E-mail user'), '#collapsible' => TRUE, ); $form['birthdays_email']['birthdays_send_user'] = array( '#type' => 'radios', '#title' => t('Send user e-mail on day of birth'), '#default_value' => variable_get('birthdays_send_user', 0), '#options' => array(1 => t('Yes'), 0 => t('No')), '#description' => t('Should users that have their birthday today receive an e-mail?') ); $form['birthdays_email']['birthdays_send_user_subject'] = array( '#type' => 'textfield', '#title' => t('Subject'), '#default_value' => variable_get('birthdays_send_user_subject', t('Happy Birthday!')), ); $form['birthdays_email']['birthdays_send_user_message'] = array( '#type' => 'textarea', '#title' => t('Message'), '#default_value' => variable_get('birthdays_send_user_message', t("Hey %name%,\n\n" . "Happy birthday!\n" . "Hope you have a great day!\n")), '#description' => t('%name% will be replaced for the firstname of the user.') ); $form['birthdays_remind'] = array( '#type' => 'radios', '#title' => t('Send upcoming birthdays'), '#default_value' => variable_get('birthdays_remind', 0), '#options' => array(1 => t('Yes'), 0 => t('No')), '#description' => t('Do you want a dayly e-mail containing all upcoming birthdays (for the next week)?') ); return system_settings_form($form); } /** * Implementation of hook_perm(). */ function birthdays_perm() { return array('access birthdays', 'edit DOB'); } /** * Implementation of hook_cron(). */ function birthdays_cron() { // Perform these actions just once per day if (variable_get('birthdays_last_cron', 0) < (time() - 3600*24)) { _birthdays_message(); variable_set('birthdays_last_cron', time()); } } /** * Implementation of hook_block * - Block lists N upcoming birthdays * - Block lists birthdays in N days * * @param $op the operation that is being requested. This defaults to 'list', which indicates that the method should * return which blocks are available. * @param $delta the specific block to display. This is actually the offset into an array. * @return one of two possibilities. The first is an array of available blocks. The other is an array containing a * */ function birthdays_block($op = 'list', $delta = 0) { $block = array(); if($op == 'list') { $block[0]['info'] = t('Birthdays Block: N birthdays'); $block[1]['info'] = t('Birthdays Block: N days'); } elseif($op == 'configure') { // Configuration settings for block if( $delta == 0 ) { $form["birthday_past"] = array( '#type' => 'textfield', '#title' => t("Number of birthdays"), '#default_value' => variable_get("birthdays_list_number", 6), '#size' => 2, '#maxlength' => 2, '#description' => t("Number of upcoming birthdays to list in block"),); return $form; } if( $delta == 1 ) { $form["birthday_past"] = array( '#type' => 'textfield', '#title' => t("Number of days"), '#default_value' => variable_get("birthdays_days_number", 7), '#size' => 2, '#maxlength' => 2, '#description' => t("Number of days to list the birthdays of in block"),); return $form; } } else { // Render block content if (user_access('access birthdays')) { // Get birthdays based on block-type; if( $delta == 0 ) { $birthdays = _get_upcoming_birthdays(variable_get("birthdays_list_number", 6)); } else if( $delta == 1 ) { $birthdays = _get_upcoming_birthdays_days(variable_get("birthdays_days_number", 7)); } $blockContent = '
| ' . l($user['name'], 'user/' . $user['uid']) . ' | ' . $user['day'] . ' ' . $user['month'] . ' |
';
$link .= '';
return $link;
}
function _get_starsign_dates($starsign) {
switch ($starsign ) {
case t('capricorn'): $ret = array(12,22,1,20); break;
case t('aquarius'): $ret = array(1,20,2,20); break;
case t('pisces'): $ret = array(2,20,3,21); break;
case t('aries'): $ret = array(3,21,4,20); break;
case t('taurus'): $ret = array(4,20,5,21); break;
case t('gemini'): $ret = array(5,21,6,22); break;
case t('cancer'): $ret = array(6,22,7,23); break;
case t('leo'): $ret = array(7,23,8,23); break;
case t('virgo'): $ret = array(8,23,9,23); break;
case t('libra'): $ret = array(9,23,10,23); break;
case t('scorpio'): $ret = array(10,23,11,22); break;
case t('sagittarius'): $ret = array(11,22,12,22); break;
default: $ret = false;
}
return $ret;
}
/**
* Sends e-mail to administrator as reminder and to users on birthday and e-mail users who's birthdays it is
*/
function _birthdays_message() {
if (variable_get('birthdays_remind', true)) {
$users = db_query("SELECT uid, MONTH(birthday) as m, DAY(birthday) as d FROM {dob} WHERE ( (MONTH(birthday) = MONTH(CURDATE())
AND
DAY(birthday) >= DAYOFMONTH(CURDATE())
AND
DAY(birthday) <= (DAY(CURDATE())+%s))
OR
(MONTH(birthday) = MONTH(ADDDATE(CURDATE(),%s))
AND
DAY(birthday) <= DAY(ADDDATE(CURDATE(),%s)))
)
order by m, d",6,6,6);
$message = t("The following users birthdays are coming up in 7 days:");
while ($user = db_fetch_object($users)) {
$account = user_load(array('uid' => $user->uid));
$message .= "\n" . $account->name;
}
if (db_num_rows($users) != 0) {
// Get site e-mail to send reminder to and from
$from = variable_get('site_mail', ini_get('sendmail_from'));
$to = $from;
$subject = t("Upcoming Birthdays");
drupal_mail('birthdays_upcoming_mail', $to, $subject, $message, $from );
watchdog('Birthdays', 'sent birthday overview e-mail', WATCHDOG_NOTICE, ' ');
}
}
if (variable_get('birthdays_send_user', true)) {
$users = db_query("SELECT uid FROM {dob} WHERE DATE_FORMAT(birthday, '%%m%%d') = DATE_FORMAT(NOW(), '%%m%%d')");
while ($user = db_fetch_object($users)) {
$account = user_load(array('uid' => $user->uid));
$message = variable_get('birthdays_send_user_message', "Hey %name%,
Happy birthday!
Hope you have a great day!
Take care,");
$message = str_replace('%name%',$account->name, $message);
$subject = variable_get('birthdays_send_user_subject', 'Happy Birthday!');
$from = variable_get('site_mail', ini_get('sendmail_from'));
if (module_exists('postcard')) {
// If postcard module installed, send postcard
$postcard = array('field_sndr' => $from,
'field_from' => $from,
'field_nid' => 49,
'field_rcpt' => $account->name,
'field_to' => $account->mail,
'field_body' => $message);
$postid = postcard_send($postcard);
watchdog('Birthdays', $account->name . ' sent birthday postcard', WATCHDOG_NOTICE, l('postcard', 'postcard/45/'. $postid));
} else {
// Send e-mail
drupal_mail('birthdays_user_mail', $account->name . '<' . $account->mail . '>', $subject, $message, $from );
watchdog('Birthdays', $account->name . ' sent birthday e-mail', WATCHDOG_NOTICE, ' ');
}
}
}
}
?>