? vt-D6-235503-3.patch
Index: volunteer_timeslots.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/volunteer_timeslots/volunteer_timeslots.info,v
retrieving revision 1.4
diff -u -p -r1.4 volunteer_timeslots.info
--- volunteer_timeslots.info	13 Jul 2007 00:51:37 -0000	1.4
+++ volunteer_timeslots.info	7 Jun 2008 01:46:51 -0000
@@ -1,6 +1,7 @@
 ; $Id: volunteer_timeslots.info,v 1.4 2007/07/13 00:51:37 pwolanin Exp $
 name = Volunteer timeslots
 description = Enables creation of events where users can sign up to volunteer in a time slot.
-dependencies = event
+dependencies[] = event
 package = Event
+core = 6.x
 
Index: volunteer_timeslots.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/volunteer_timeslots/volunteer_timeslots.install,v
retrieving revision 1.5
diff -u -p -r1.5 volunteer_timeslots.install
--- volunteer_timeslots.install	13 Jul 2007 01:11:26 -0000	1.5
+++ volunteer_timeslots.install	7 Jun 2008 01:46:51 -0000
@@ -2,9 +2,77 @@
 // $Id: volunteer_timeslots.install,v 1.5 2007/07/13 01:11:26 pwolanin Exp $
 
 /**
+ * @file
+ * Install file for Event with Volunteer Timeslots
+ */
+
+/**
  * Implementation of hook_install().
  */
 function volunteer_timeslots_install() {
+  drupal_install_schema('volunteer_timeslots');
+  variable_set('event_nodeapi_volunteer_timeslots', 'all');
+  variable_set('node_options_volunteer_timeslots', array('status', 'revision'));
+}
+
+/**
+ * Implementation of hook_schema().
+ */
+function volunteer_timeslots_schema() {
+  $schema['volunteer_timeslots'] = array(
+    'description' => t('The timeslots data.'),
+    'fields' => array(
+      'nid' => array(
+        'description' => t('The primary identifier for a node.'),
+        'type' => 'serial',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'vid' => array(
+        'description' => t('The current {node_revisions}.vid version identifier.'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'timeslot_length' => array(
+        'description' => t('The length of each timeslot (seconds).'),
+        'type' => 'int',
+        'unsigned' => FALSE,
+        'not null' => TRUE,
+        'default' => 1,
+      ),
+      'num_volunteers' => array(
+        'description' => t('The number of volunteers in each timeslot.'),
+        'type' => 'int',
+        'unsigned' => FALSE,
+        'not null' => TRUE,
+        'default' => 1,
+      ),
+      'timeslots_organizers' => array(
+        'description' => t('The organizers of this event.'),
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'title' => array(
+        'description' => t('The title of this node, always treated a non-markup plain text.'),
+        'type' => 'text',
+        'size' => 'big',
+        'not null' => TRUE,
+      ),
+    ),
+    'unique keys' => array(
+      'vid'     => array('vid')
+      ),
+    'primary key' => array('nid', 'vid'),
+  );
+
+  return $schema;
+}
+
+/*
   switch ($GLOBALS['db_type']) {
     case 'mysql':
     case 'mysqli':
@@ -17,7 +85,7 @@ function volunteer_timeslots_install() {
         timeslot_data longtext NOT NULL,
         PRIMARY KEY (nid, vid),
         KEY vid (vid)
-      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
+      ) ");
       break;
     case 'pgsql':
       db_query("CREATE TABLE {volunteer_timeslots} (
@@ -32,13 +100,12 @@ function volunteer_timeslots_install() {
       )");
       break;
   }
-  variable_set('event_nodeapi_volunteer_timeslots', 'all');
-  variable_set('node_options_volunteer_timeslots', array('status', 'revision'));
 }
+*/
 
 function volunteer_timeslots_uninstall() {
   db_query("DELETE FROM {node_type} WHERE module = 'volunteer_timeslots'");
-  db_query("DROP TABLE {volunteer_timeslots}");
+  drupal_uninstall_schema('volunteer_timeslots');
   variable_del('event_nodeapi_volunteer_timeslots');
   variable_del('node_options_volunteer_timeslots');
   variable_del('volunteer_timeslots_profile_fields');
Index: volunteer_timeslots.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/volunteer_timeslots/volunteer_timeslots.module,v
retrieving revision 1.19
diff -u -p -r1.19 volunteer_timeslots.module
--- volunteer_timeslots.module	17 Feb 2007 02:55:23 -0000	1.19
+++ volunteer_timeslots.module	7 Jun 2008 01:46:51 -0000
@@ -9,8 +9,8 @@
 /**
  * Implementation of hook_help().
  */
-function volunteer_timeslots_help($section) {
-  switch ($section) {
+function volunteer_timeslots_help($path, $arg) {
+  switch ($path) {
     case 'admin/settings/volunteer_timeslots':
       return t('A node type representing an event with timeslots where users can sign up to volunteer');
   }
@@ -32,19 +32,28 @@ function volunteer_timeslots_node_info()
 function volunteer_timeslots_perm() {
   return array('create volunteer events', 'edit own volunteer events', 'administer volunteer events');
 }
-      
+
+function hook_theme() {
+  return array(
+    'timeslots_roster_form' => array(
+      'arguments' => array('form' => NULL),
+    ),
+  );
+}
+
+
 /**
 * menu callback to settings page.
 */
 function volunteer_timeslots_settings() {
-  
+
   $form['volunteer_timeslots_organizer_updates'] = array(
     '#type' => 'checkbox',
     '#title' => t("Allow each event's organizer(s) to edit the event"),
     '#default_value' => variable_get('volunteer_timeslots_organizer_updates', TRUE),
     '#description' => t('If set, every user designated as an organizer of a volunteer event can edit that node.'),
   );
-  
+
   $form['volunteer_timeslots_author_manages'] = array(
     '#type' => 'checkbox',
     '#title' => t("Allow each event's author to manage (add and remove) volunteers for the event"),
@@ -55,7 +64,7 @@ function volunteer_timeslots_settings() 
   $hours = array(
     -100 => t('never'),
     6*60 => t('!s hours', array('!s' => '6')),
-    12*60 => t('!s hours', array('!s' => '12')), 
+    12*60 => t('!s hours', array('!s' => '12')),
     18*60 => t('!s hours', array('!s' => '18')),
     24*60 => t('!s hours', array('!s' => '24')),
     36*60 => t('!s hours', array('!s' => '36')),
@@ -63,19 +72,19 @@ function volunteer_timeslots_settings() 
     72*60 => t('!s hours', array('!s' => '72')),
   );
   $form['volunteer_timeslots_remind_time'] = array(
-    '#type' => 'select', 
-    '#title' => t('Number of hours in advance to send event reminder e-mails'), 
+    '#type' => 'select',
+    '#title' => t('Number of hours in advance to send event reminder e-mails'),
     '#default_value' => variable_get('volunteer_timeslots_remind_time', 36*60),
-    '#options' => $hours,      
+    '#options' => $hours,
     '#description' => t('This sets the maximum possible time before an event that the reminder e-mail will be sent. The actual time the e-mail is set depnds upon when and how often cron.php is executed on your system. Choose %s to disable automatic e-mail reminders', array('%s' => t('never'))),
   );
-  if (module_exists('profile')) { 
-    $result = db_query('SELECT * FROM {profile_fields} WHERE visibility != %d ORDER BY category, weight', PROFILE_HIDDEN);
+  if (module_exists('profile')) {
+    $result = db_query('SELECT * FROM {profile_fields} WHERE visibility <> %d ORDER BY category, weight', PROFILE_HIDDEN);
     while ($field = db_fetch_object($result)) {
       $options[$field->name] = $field->title;
     }
-    $form['volunteer_timeslots_profile_fields'] = array (
-      '#type' => 'checkboxes', 
+    $form['volunteer_timeslots_profile_fields'] = array(
+      '#type' => 'checkboxes',
       '#title' => t('User profile fields to include in the volunteer list for organizers'),
       '#default_value' => variable_get('volunteer_timeslots_profile_fields', array()),
       '#options' => $options,
@@ -83,8 +92,8 @@ function volunteer_timeslots_settings() 
     $form['array_filter'] = array('#type' => 'value', '#value' => TRUE);
   }
   else {
-    $form['volunteer_timeslots_profile_note'] = array (
-      '#value' => '<p>'. t('Note: if you enable the profile module, you will be able to select profile fields to show in the volunteer roster.').'</p>',);    
+    $form['volunteer_timeslots_profile_note'] = array(
+      '#value' => '<p>'. t('Note: if you enable the profile module, you will be able to select profile fields to show in the volunteer roster.') .'</p>',);
   }
   return system_settings_form($form);
 }
@@ -94,22 +103,26 @@ function volunteer_timeslots_settings() 
 /**
  * Implementation of hook_access().
  */
-function volunteer_timeslots_access($op, $node) {
+function volunteer_timeslots_access($op, $node, $account = NULL) {
   global $user;
 
+  if (empty($account)) {
+    $account = $user;
+  }
+
   if ($op == 'create') {
     return user_access('create volunteer events');
   }
-  $delete_perm = (user_access('administer volunteer events') || 
-                 (user_access('edit own volunteer events') && ($user->uid == $node->uid)));
+  $delete_perm = (user_access('administer volunteer events') ||
+                 (user_access('edit own volunteer events') && ($account->uid == $account->uid)));
   if ($op == 'delete') {
     if ($delete_perm) {
       return TRUE;
     }
   }
   if ($op == 'update') { //note- check against $node->validated work-around allows organizers to remove themselves from the list of organizers
-    if ($delete_perm || 
-       (variable_get('volunteer_timeslots_organizer_updates', TRUE) && (in_array($user->uid, $node->timeslots_organizers) || $node->validated))) {
+    if ($delete_perm ||
+       (variable_get('volunteer_timeslots_organizer_updates', TRUE) && (in_array($account->uid, $node->timeslots_organizers) || $node->validated))) {
       return TRUE;
     }
   }
@@ -118,32 +131,32 @@ function volunteer_timeslots_access($op,
 /**
  * Implementation of hook_menu().
  */
-function volunteer_timeslots_menu($may_cache) {
+function volunteer_timeslots_menu() {
   $items = array();
 
-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'admin/settings/volunteer_timeslots',
-      'title' => t('Event with volunteer timeslots'),
-      'description' => t('Configure the volunteer timeslots.'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => 'volunteer_timeslots_settings',
-      'access' => user_access('administer site configuration'),
-    ); 
-    $items[] = array(
-      'path' => 'multiuser/autocomplete', 
-      'title' => t('multiuser autocomplete'),
-      'callback' => 'multiuser_autocomplete', 
-      'access' => user_access('access user profiles'), 
-      'type' => MENU_CALLBACK,
-    );
-  }
-  else {
-    drupal_add_css(drupal_get_path('module', 'volunteer_timeslots') .'/volunteer_timeslots.css', 'module');
-  }
+  $items['admin/settings/volunteer_timeslots'] = array(
+    'title' => 'Event with volunteer timeslots',
+    'description' => 'Configure the volunteer timeslots.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => 'volunteer_timeslots_settings',
+    'access arguments' => array('administer site configuration'),
+  );
+  $items['multiuser/autocomplete'] = array(
+    'title' => 'multiuser autocomplete',
+    'page callback' => 'multiuser_autocomplete',
+    'access arguments' => array('access user profiles'),
+    'type' => MENU_CALLBACK,
+  );
 
   return $items;
 }
+/**
+ * Implementation of hook_init().
+ */
+function volunteer_timeslots_init() {
+  drupal_add_css(drupal_get_path('module', 'volunteer_timeslots') .'/volunteer_timeslots.css', 'module');
+
+}
 
 function multiuser_autocomplete($string) {
   // The user enters a comma-separated list of usernames. We only autocomplete the last one.
@@ -163,63 +176,63 @@ function multiuser_autocomplete($string)
   }
 }
 
-function timeslots_node_form_validate($form_id, $form_values, $form) {
-  $names = explode(',', $form_values['timeslots_organizers']);
-  foreach($names as $n) { // username validation
+function timeslots_node_form_validate($form, &$form_state) {
+  $names = explode(',', $form_state['values']['timeslots_organizers']);
+  foreach ($names as $n) { // username validation
     $n = trim($n);
     if (!user_load(array('name' => $n, 'status' => 1))) {
-      form_set_error('timeslots_organizers', t('The username %name does not exist or is blocked.', array ('%name' => $n)));
-    }  
+      form_set_error('timeslots_organizers', t('The username %name does not exist or is blocked.', array('%name' => $n)));
+    }
   }
 }
- 
+
 /**
  * Implementation of hook_form().
  */
 function volunteer_timeslots_form(&$node) {
   global $user;
   $form['title'] = array(
-    '#type' => 'textfield', 
-    '#title' => t('Title'), 
-    '#required' => TRUE, 
-    '#default_value' => $node->title, 
+    '#type' => 'textfield',
+    '#title' => t('Title'),
+    '#required' => TRUE,
+    '#default_value' => $node->title,
     '#weight' => -25,
     '#description' => t('A brief title for your event for the calendar listing.'),
   );
   if (variable_get('event_nodeapi_volunteer_timeslots', 'never') == 'never') {
     $form['message'] = array(
        '#value' => t("You must have the event module enabled and make sure the type '%type' to selected to appear in the events calendar.", array( '%type' => t('Event with volunteer timeslots'))),
-    );    
+    );
   }
   else {
-    $form['#validate']['timeslots_node_form_validate'] = array();
+    $form['#validate'][] = 'timeslots_node_form_validate';
     $form['timeslots'] = array(
       '#type' => 'fieldset',
       '#title' => t('Set up the timeslots for volunteers and the organizer for this event'),
-      '#collapsible' => TRUE, 
+      '#collapsible' => TRUE,
       '#collapsed' => FALSE,
       '#weight' => -10,
     );
     if (!isset($node->timeslot_data)) {
       $node->timeslot_data = array();
     }
-    
+
     if (!empty($node->timeslots_organizers)) {
       $names = array();
       foreach ($node->timeslots_organizers as $uid) {
         $account = user_load(array('uid' => $uid));
         $names[] = $account->name;
       }
-      $org_names = implode(', ',$names);
+      $org_names = implode(', ', $names);
     }
     else {
       $org_names = '';
     }
-    
-    $form['timeslots']['timeslots_organizers'] = array( 
+
+    $form['timeslots']['timeslots_organizers'] = array(
       '#type' => 'textfield',
       '#maxlength' => 255,
-      '#autocomplete_path' => 'multiuser/autocomplete', 
+      '#autocomplete_path' => 'multiuser/autocomplete',
       '#title' => t('@s username of the event organizer', array('@s' => variable_get('site_name', 'local'))),
       '#default_value' => $org_names,
       '#description' => t("For example: %name. To specify multiple organizers, separate each username with a comma.", array('%name' => $user->name)),
@@ -227,17 +240,17 @@ function volunteer_timeslots_form(&$node
     );
     $period = drupal_map_assoc(array(60*15, 60*30, 60*45, 60*60, 60*90, 60*120, 60*150, 60*180, 60*180, 60*240, 60*300, 60*360, 60*420, 60*480), 'format_interval');
     $form['timeslots']['timeslot_length'] = array(
-      '#type' => 'select', 
-      '#title' => t('Length of each time slot'), 
+      '#type' => 'select',
+      '#title' => t('Length of each time slot'),
       '#default_value' => isset($node->timeslot_length) ? $node->timeslot_length : 60*60,
       '#options' => $period,
     );
-    $numbers = drupal_map_assoc(array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,20));
+    $numbers = drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 20));
     $form['timeslots']['num_volunteers'] = array(
-      '#type' => 'select', 
-      '#title' => t('Number of volunteers in each time slot'), 
+      '#type' => 'select',
+      '#title' => t('Number of volunteers in each time slot'),
       '#default_value' => isset($node->num_volunteers) ? $node->num_volunteers : 1,
-      '#options' => $numbers,      
+      '#options' => $numbers,
       '#description' => t('The volunteer form will have this number of volunteer spots in each time slot.'),
     );
     $form['timeslot_data']  = array(
@@ -248,7 +261,7 @@ function volunteer_timeslots_form(&$node
       $form['administer'] = array(
         '#type' => 'fieldset',
         '#title' => t('Administer volunteers'),
-        '#collapsible' => TRUE, 
+        '#collapsible' => TRUE,
         '#collapsed' => TRUE,
         '#weight' => -9,
       );
@@ -259,10 +272,10 @@ function volunteer_timeslots_form(&$node
     }
   }
   $form['body_filter']['body'] = array(
-    '#type' => 'textarea', 
-    '#title' => t('volunteer event description'), 
-    '#default_value' => $node->body, 
-    '#rows' => 10, 
+    '#type' => 'textarea',
+    '#title' => t('volunteer event description'),
+    '#default_value' => $node->body,
+    '#rows' => 10,
     '#required' => TRUE
   );
   $form['body_filter']['format'] = filter_form($node->format);
@@ -290,21 +303,23 @@ function volunteer_timeslots_view(&$node
   $node = node_prepare($node, $teaser);
 
   if (!$teaser) {
-    $admin = (user_access('administer volunteer events') || 
-             (($user->uid == $node->uid) && variable_get('volunteer_timeslots_author_manages', TRUE)) || 
+    $admin = (user_access('administer volunteer events') ||
+             (($user->uid == $node->uid) && variable_get('volunteer_timeslots_author_manages', TRUE)) ||
               in_array($user->uid, $node->timeslots_organizers)); //user is allowed to remove/add volunteers
     $node->content['timeslots_signup_form'] = array(
       '#value' => drupal_get_form('_timeslots_signup_form', $node, $admin),
-      '#weight' => 10,);
-    
+      '#weight' => 10,
+    );
+
     if ($admin) {
       $node->content['timeslots_roster_form'] = array(
         '#value' => drupal_get_form('_timeslots_roster_form', $node),
-        '#weight' => 20,);     
+        '#weight' => 20,
+      );
     }
-    
+
   }
-  
+
   return $node;
 }
 
@@ -317,17 +332,17 @@ function _timeslots_roster_form($node) {
   if (!count($node->timeslot_data[0]['all_volunteers'])) {
     return array();
   }
-  
+
   $form = array(
     '#theme' => 'timeslots_roster_form',
     '#tree' => TRUE,
   );
-  
+
   $form['nid'] = array('#type' => 'value', '#value' => $node->nid);
-  
+
   $header = array("Username");
   if ($profile = module_exists('profile')) {
-    $fields = variable_get('volunteer_timeslots_profile_fields', array());  
+    $fields = variable_get('volunteer_timeslots_profile_fields', array());
   }
   foreach ($node->timeslot_data[0]['all_volunteers'] as $uid) {
     if ($account = user_load(array('uid' => $uid))) {
@@ -345,10 +360,10 @@ function _timeslots_roster_form($node) {
     }
   }
   if ($profile) {
-    $result = db_query("SELECT * FROM {profile_fields} p WHERE p.name in ('". implode("','", $fields). "') ORDER BY p.category, p.weight");
+    $result = db_query("SELECT * FROM {profile_fields} p WHERE p.name in ('". implode("','", $fields) ."') ORDER BY p.category, p.weight");
 
     while ($pf = db_fetch_object($result)) {
-      $header[] = $pf->title; 
+      $header[] = $pf->title;
     }
   }
   $header[] = t('Notes');
@@ -358,11 +373,11 @@ function _timeslots_roster_form($node) {
     '#value' => $header,
     );
   $form['submit'] = array(
-    '#type' => 'submit', 
+    '#type' => 'submit',
     '#value' => t('Update notes'),
     '#attributes' => array('class' => 'volunteer-timeslots'),
   );
-  return $form;  
+  return $form;
 }
 
 function theme_timeslots_roster_form($form) {
@@ -372,24 +387,24 @@ function theme_timeslots_roster_form($fo
     foreach (element_children($form['info'][$uid]) as $profile_field) {
       $items[] = drupal_render($form['info'][$uid][$profile_field]);
     }
-    $items[] = array('data'=> drupal_render($form['notes'][$uid]));
+    $items[] = array('data' => drupal_render($form['notes'][$uid]));
     $rows[] = $items;
   }
-  
+
   $output = theme('table', $form['header']['#value'], $rows, array('class' => 'volunteer-timeslots'), t('Volunteer roster'));
   return $output. drupal_render($form);
 }
 
 
-function _timeslots_roster_form_submit($form_id, $form_values) {
-  $node = node_load($form_values['nid']);
-  if ($form_values['notes'] == $node->timeslot_data[0]['notes']) {
+function _timeslots_roster_form_submit($form, &$form_state) {
+  $node = node_load($form_state['values']['nid']);
+  if ($form_state['values']['notes'] == $node->timeslot_data[0]['notes']) {
     drupal_set_message(t('No changes were made.'));
     return;
   }
-  
+
   $node->timeslot_data[0]['notes'] = array(); //clear old notes
-  foreach ($form_values['notes'] as $uid => $note) {
+  foreach ($form_state['values']['notes'] as $uid => $note) {
     $node->timeslot_data[0]['notes'][$uid] = $note;
   }
   $node->revision = TRUE;
@@ -404,25 +419,25 @@ function _timeslots_signup_form($node, $
     '#tree' => TRUE,
   );
   $none = theme('placeholder', t('volunteer needed'));
-  
+
   $form['nid'] = array('#type' => 'value', '#value' => $node->nid);
-  
-  $access = user_access('access user profiles'); 
-  
+
+  $access = user_access('access user profiles');
+
   if (count($node->timeslot_data[0]['all_volunteers'])) {
-    $result = db_query("SELECT * FROM {users} WHERE uid in (". implode(',', $node->timeslot_data[0]['all_volunteers']). ")");    
+    $result = db_query("SELECT * FROM {users} WHERE uid in (". implode(',', $node->timeslot_data[0]['all_volunteers']). ")");
     while ($account = db_fetch_object($result)) {
-      $users[$account->uid] = $account; 
+      $users[$account->uid] = $account;
     }
   }
   $box = FALSE; //flag to see if we have any checkbox elements in the form
   $openings = array();
   $form['num_slots'] = array( '#type' => 'value', '#value' => count($node->timeslot_data));
   foreach ($node->timeslot_data as $slot => $data) {
-    $form['timeslot'][$slot]['start_time'] = array( 
+    $form['timeslot'][$slot]['start_time'] = array(
       '#value' => format_date($data['start_time'], 'custom', 'g:i a', $node->start_offset),
     );
-    $form['timeslot'][$slot]['end_time'] = array( 
+    $form['timeslot'][$slot]['end_time'] = array(
       '#value' => format_date($data['end_time'], 'custom', 'g:i a', $node->start_offset),
     );
     if (count($data['volunteers']) < $node->num_volunteers) {
@@ -441,7 +456,7 @@ function _timeslots_signup_form($node, $
       $box = TRUE;
     }
     else {
-      $form['timeslot'][$slot]['box'] = array( '#value' => '', ); 
+      $form['timeslot'][$slot]['box'] = array( '#value' => '', );
     }
     for ($i = 0; $i < $node->num_volunteers; $i++) {
       $set = isset($data['volunteers'][$i]);
@@ -454,11 +469,11 @@ function _timeslots_signup_form($node, $
       else {
         $name = $users[$data['volunteers'][$i]]->name;
       }
-      $form['timeslot'][$slot]['name'][$i] = array( 
+      $form['timeslot'][$slot]['name'][$i] = array(
         '#value' => $name,
       );
       if ($set && $admin) {
-        $form['timeslot'][$slot]['remove'][$i] = array( 
+        $form['timeslot'][$slot]['remove'][$i] = array(
           '#type' => 'checkbox',
           '#return_value' => $users[$data['volunteers'][$i]]->uid,
         );
@@ -472,31 +487,31 @@ function _timeslots_signup_form($node, $
     '#value' => t('The event ends %time.', array( '%time' => format_date($node->event_end, 'custom', 'D, g:i a', $node->end_offset))),
   );
   $form['box'] = array(
-    '#type' => 'value', 
+    '#type' => 'value',
     '#value' => $box,
   );
   $form['admin'] = array(
-    '#type' => 'value', 
+    '#type' => 'value',
     '#value' => $admin,
   );
   if ($admin) {
     if (count($openings)) {
-       $form['add_volunteer'] = array( 
+       $form['add_volunteer'] = array(
         '#type' => 'fieldset',
         '#title' => t('Add a volunteer to the schedule'),
-        '#collapsible' => TRUE, 
+        '#collapsible' => TRUE,
         '#collapsed' => TRUE,
         '#prefix' => '<div class="volunteer-timeslots">',
         '#suffix' => '</div>',
         );
-      $form['add_volunteer']['name'] = array( 
+      $form['add_volunteer']['name'] = array(
         '#type' => 'textfield',
         '#maxlength' => 60,
-        '#autocomplete_path' => 'user/autocomplete', 
+        '#autocomplete_path' => 'user/autocomplete',
 
         '#description' => t("Enter a %s username. For example: %name.", array('%s' => variable_get('site_name', 'local'), '%name' => $user->name)),
       );
-      $form['add_volunteer']['slot'] = array( 
+      $form['add_volunteer']['slot'] = array(
         '#type' => 'select',
         '#options' => $openings,
         '#description' => t("The time slot to add the volunteer"),
@@ -505,18 +520,18 @@ function _timeslots_signup_form($node, $
     else {
       $form['no_openings'] = array(
         '#value' => t('There are no open slots in the schedule.'),
-      );      
+      );
     }
   }
   if ($box || $admin) {
-    $form['send_me'] = array( 
+    $form['send_me'] = array(
       '#type' => 'checkbox',
       '#title' => t("Send me a copy of this event's information"),
       '#default_value' => !$admin, //checked by default except for admins/organizers
       '#attributes' => array('class' => 'volunteer-timeslots'),
     );
     $form['submit'] = array(
-      '#type' => 'submit', 
+      '#type' => 'submit',
       '#value' => t('Submit'),
       '#attributes' => array('class' => 'volunteer-timeslots'),
     );
@@ -527,19 +542,19 @@ function _timeslots_signup_form($node, $
   return $form;
 }
 
-function _timeslots_signup_form_validate($form_id, $form_values, $form) {
+function _timeslots_signup_form_validate($form, &$form_state) {
 
-  $node = node_load($form_values['nid']);
-  if (!empty($form_values['add_volunteer']['name'])) {
-    $name = trim($form_values['add_volunteer']['name']);
+  $node = node_load($form_state['values']['nid']);
+  if (!empty($form_state['values']['add_volunteer']['name'])) {
+    $name = trim($form_state['values']['add_volunteer']['name']);
     if (!empty($name)) {
       if (!($account = user_load(array('name' => $name)))) {
-        form_set_error("add_volunteer][name", t('The username %name does not exist.', array ('%name' => theme('placeholder', $name))));
+        form_set_error("add_volunteer][name", t('The username %name does not exist.', array('%name' => theme('placeholder', $name))));
       }
       else {
         global $user;
-        $slot = $form_values['add_volunteer']['slot'];
-        if ($form_values['timeslot'][$slot]['box'] && !$form_values['timeslot'][$slot]['was_checked']) {
+        $slot = $form_state['values']['add_volunteer']['slot'];
+        if ($form_state['values']['timeslot'][$slot]['box'] && !$form_state['values']['timeslot'][$slot]['was_checked']) {
           if ((count($node->timeslot_data[$slot]['volunteers']) >= ($node->num_volunteers - 1)) &&
               ($account->uid != $user->uid)) {
             form_set_error('add_volunteer', t('Error: you cannot add both yourself and another volunteer to that time slot'));
@@ -549,29 +564,29 @@ function _timeslots_signup_form_validate
     }
   }
   else { // does this work???
-    if ($form_values['timeslot'][$slot]['box'] && !$form_values['timeslot'][$slot]['was_checked']) {
+    if ($form_state['values']['timeslot'][$slot]['box'] && !$form_state['values']['timeslot'][$slot]['was_checked']) {
       if (count($node->timeslot_data[$slot]['volunteers']) >= $node->num_volunteers) {
         form_set_error('', t('Sorry: That time slot has been filled.'));
       }
-    }    
+    }
   }
 }
 
 function theme_timeslots_signup_form($form) {
-  
+
   $header = array(t('Time slot'));
   if ($form['box']['#value']) {
     $header[] = t('Sign up for this slot');
   }
   else {
-   $header[] = ''; 
+   $header[] = '';
   }
   $header[] = t('Volunteers');
   if ($form['admin']['#value']) {
     $header[] = t('Remove');
   }
   else {
-   $header[] = ''; 
+   $header[] = '';
   }
   $rows = array();
   for ($slot = 0; $slot < $form['num_slots']['#value']; $slot++) {
@@ -582,7 +597,7 @@ function theme_timeslots_signup_form($fo
           $arow[] = drupal_render($form['timeslot'][$slot]['box']);
         }
         else {
-          $arow[] = ''; 
+          $arow[] = '';
         }
         $arow[] = drupal_render($form['timeslot'][$slot]['name'][0]);
         $arow[] = drupal_render($form['timeslot'][$slot]['remove'][0]);
@@ -600,17 +615,17 @@ function theme_timeslots_signup_form($fo
   return $output . drupal_render($form);
 }
 
-function _timeslots_signup_form_submit($form_id, $form_values) {
+function _timeslots_signup_form_submit($form, &$form_state) {
   global $user;
-  $node = node_load($form_values['nid']);
-  
+  $node = node_load($form_state['values']['nid']);
+
   $changed = array();
   $remove = array();
-  foreach($form_values['timeslot'] as $slot => $data) {
+  foreach ($form_state['values']['timeslot'] as $slot => $data) {
     if (isset($data['box']) && ($data['box'] != $data['was_checked'])) {
       $changed[$slot] = TRUE;
     }
-    if ($form_values['admin']) {
+    if ($form_state['values']['admin']) {
       foreach ($data['remove'] as $uid) {
         if ($uid > 0) {
           $remove[$slot] = TRUE;
@@ -618,13 +633,13 @@ function _timeslots_signup_form_submit($
       }
     }
   }
-  if (!count($changed) && !count($remove) && empty($form_values['add_volunteer']['name'])) {
+  if (!count($changed) && !count($remove) && empty($form_state['values']['add_volunteer']['name'])) {
     drupal_set_message(t('No changes were made.'));
     return;
   }
   $all_volunteers = array();
-  
-  foreach($form_values['timeslot'] as $slot => $data) {
+
+  foreach ($form_state['values']['timeslot'] as $slot => $data) {
     $vol = $node->timeslot_data[$slot]['volunteers'];
     if (isset($changed[$slot])) {
       if ($data['box']) {
@@ -648,8 +663,8 @@ function _timeslots_signup_form_submit($
         }
       }
     }
-    if (isset($form_values['add_volunteer']['name']) && $form_values['add_volunteer']['slot'] == $slot) {
-      $name = trim($form_values['add_volunteer']['name']);
+    if (isset($form_state['values']['add_volunteer']['name']) && $form_state['values']['add_volunteer']['slot'] == $slot) {
+      $name = trim($form_state['values']['add_volunteer']['name']);
       if (!empty($name)) {
         $account = user_load(array('name' => $name));
         $vol[] = $account->uid;
@@ -662,8 +677,8 @@ function _timeslots_signup_form_submit($
   $node->revision = TRUE;
   node_save($node);
   drupal_set_message(t('Your changes to the schedule were made.'));
-  if ($form_values['send_me']) {
-    volunteer_timeslots_reminder_mail($node, $user->uid, "Information about the event:");
+  if ($form_state['values']['send_me']) {
+    drupal_mail('volunteer_timeslots_reminder', 'send_me',  $user->mail, user_preferred_language($user), array('node' => $node, 'uid' => $user->uid, 'opening' => "Information about the event:"));
     drupal_set_message(t('Information about the event was sent to your e-mail address.'));
   }
 }
@@ -671,13 +686,13 @@ function _timeslots_signup_form_submit($
 /**
  * Implementation of hook_nodeapi().
  *
- * hook_nodeapi is implemented instead of hook_submit so that event module has 
+ * hook_nodeapi is implemented instead of hook_submit so that event module has
  * a chance to act first and properly process the event's start and end times.
  */
 function volunteer_timeslots_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
 
-  if($node->type == 'volunteer_timeslots') {
-    if ($op == 'submit') {
+  if ($node->type == 'volunteer_timeslots') {
+    if ($op == 'presave') {
       //insure a rational end time- at least one time slot after the event start.
       if ($node->event_end <= $node->event_start) {
         $node->event_end = $node->event_start + $node->timeslot_length;
@@ -685,11 +700,11 @@ function volunteer_timeslots_nodeapi(&$n
       $start = $node->event_start;
       $end = $node->event_end;
       $num_slots = ceil(($end - $start)/$node->timeslot_length);
-      
+
       if ($node->clear_volunteers) {
-        unset($node->timeslot_data); 
+        unset($node->timeslot_data);
       }
-      
+
       $data[0]['all_volunteers'] = array();
       for ($i=0; $i<$num_slots; $i++) {
         $data[$i]['start_time'] = $start + $i* $node->timeslot_length;
@@ -701,7 +716,7 @@ function volunteer_timeslots_nodeapi(&$n
         }
         if (count($node->timeslot_data[$i]['volunteers'])) {
           $data[$i]['volunteers'] = $node->timeslot_data[$i]['volunteers'];
-          $data[0]['all_volunteers'] = array_merge($data[0]['all_volunteers'], $node->timeslot_data[$i]['volunteers']); 
+          $data[0]['all_volunteers'] = array_merge($data[0]['all_volunteers'], $node->timeslot_data[$i]['volunteers']);
         }
         else {
           $data[$i]['volunteers'] = array();
@@ -709,13 +724,13 @@ function volunteer_timeslots_nodeapi(&$n
       }
       $data[0]['all_volunteers'] = array_unique($data[0]['all_volunteers']);
       foreach ($data[0]['all_volunteers'] as $uid) {
-        $data[0]['notes'][$uid] = $node->timeslot_data[0]['notes'][$uid]; 
+        $data[0]['notes'][$uid] = $node->timeslot_data[0]['notes'][$uid];
       }
       $node->timeslot_data = $data;
       //$node->revision = TRUE;
       $names = explode(',', $node->timeslots_organizers);
       $organizers = array();
-      foreach($names as $n) {
+      foreach ($names as $n) {
         // validation has already been done in _validate, convert to uid values
         if ($account = user_load(array('name' => trim($n)))) {
           $organizers[] = $account->uid;
@@ -730,10 +745,10 @@ function volunteer_timeslots_nodeapi(&$n
  * Implementation of hook_insert().
  */
 function volunteer_timeslots_insert(&$node) {
-  db_query("INSERT INTO {volunteer_timeslots} (nid, vid, timeslot_length, num_volunteers, timeslots_organizers, timeslot_data) VALUES (%d, %d, %d, %d, '%s', '%s')", 
+  db_query("INSERT INTO {volunteer_timeslots} (nid, vid, timeslot_length, num_volunteers, timeslots_organizers, timeslot_data) VALUES (%d, %d, %d, %d, '%s', '%s')",
             $node->nid, $node->vid, $node->timeslot_length, $node->num_volunteers, implode(',', $node->timeslots_organizers), serialize($node->timeslot_data));
 }
- 
+
 function _volunteer_timeslots_data_insert(&$node) {
 }
 
@@ -745,7 +760,7 @@ function volunteer_timeslots_update(&$no
     volunteer_timeslots_insert($node);
   }
   else {
-    db_query("UPDATE {volunteer_timeslots} SET timeslot_length = %d, num_volunteers = %d, timeslots_organizers = '%s', timeslot_data = '%s' WHERE vid = %d", 
+    db_query("UPDATE {volunteer_timeslots} SET timeslot_length = %d, num_volunteers = %d, timeslots_organizers = '%s', timeslot_data = '%s' WHERE vid = %d",
              $node->timeslot_length, $node->num_volunteers, implode(',', $node->timeslots_organizers), serialize($node->timeslot_data), $node->vid);
   }
 }
@@ -759,13 +774,13 @@ function volunteer_timeslots_delete(&$no
 
 
 function volunteer_timeslots_link($type, $node = NULL,  $teaser = FALSE) {
-  $links = array(); 
+  $links = array();
   global $user;
-  
+
   if ($type == 'node' && $node->type == 'volunteer_timeslots' && !$user->uid) {
     $destination = "destination=". drupal_urlencode("node/". $node->nid);
     if (variable_get('user_register', 1)) {
-      $links['volunteer_timeslots_login'] = array( 
+      $links['volunteer_timeslots_login'] = array(
         'title' => t('<a href="!login">Login</a> or <a href="!register">register</a> to volunteer', array('!login' => url('user/login', $destination), '!register' => check_url(url('user/register', $destination)))),
         'html' => TRUE,
       );
@@ -773,11 +788,11 @@ function volunteer_timeslots_link($type,
     else {
       $links['volunteer_timeslots_login_register'] = array(
         'title' => t('<a href="!login">Login</a> to volunteer', array('!login' => check_url(url('user/login', $destination)))),
-        'html' => TRUE,     
+        'html' => TRUE,
       );
     }
   }
-  
+
   return $links;
 }
 
@@ -789,7 +804,7 @@ function volunteer_timeslots_cron() {
   if (($remind_time = variable_get('volunteer_timeslots_remind_time', 36*60)) < 0) {
     return;
   }
-  
+
   $check_time = time() - (30 * 60 * 60);
   $result = db_query('SELECT vt.* FROM {volunteer_timeslots} vt INNER JOIN {node} n ON n.vid = vt.vid INNER JOIN {event} e ON n.nid = e.nid WHERE n.status = 1 AND n.moderate = 0 AND e.event_start >= %d ORDER BY event_start', $check_time);
 
@@ -798,24 +813,28 @@ function volunteer_timeslots_cron() {
     $minutesleft = (int)(($node->event_start - time()) / 60);
     if (($minutesleft < $remind_time) && ($minutesleft > 0) && !variable_get($node->nid. '_timeslots_reminder_sent', FALSE)) {
       foreach ($node->timeslot_data[0]['all_volunteers'] as $uid) {
-        volunteer_timeslots_reminder_mail($node, $uid);
+        drupal_mail('volunteer_timeslots_reminder', 'remind',  '', user_preferred_language($user), array('node' => $node, 'uid' => $uid));
       }
       $account = user_load(array('uid' => $node->timeslots_organizers[0], 'status' => 1));
-      watchdog('mail', t('Volunteer timeslots: reminder e-mails about %url were sent on behalf of %name-from.', array('%name-from' => l($account->name,'user/'. $account->uid), '%url' => l('node/'.$node->nid,'node/'.$node->nid))));
+      watchdog('mail', 'Volunteer timeslots: reminder e-mails about %url were sent on behalf of %name-from.', array('%name-from' => l($account->name,'user/'. $account->uid), '%url' => l('node/'.$node->nid,'node/'.$node->nid)));
       variable_set($node->nid. '_timeslots_reminder_sent', TRUE);
     }
     elseif ($minutesleft < 0) {
       variable_del($node->nid. '_timeslots_reminder_sent');
-    }    
+    }
   }
 }
 
 /**
  * Send an e-mail with information or a reminder
  */
-function volunteer_timeslots_reminder_mail($node, $uid, $opening = "Reminder- you have volunteered for a time slot at:") {
+function volunteer_timeslots_reminder_mail($key, &$message, $params) {
   static $organizer = array();
   static $text = array();
+
+  $node = $params['node'];
+  $uid = $params['uid'];
+  $opening = empty($params['opening']) ? "Reminder- you have volunteered for a time slot at:" : $params['opening'];
   
   if (empty($organizer[$node->nid])) {
     $organizer[$node->nid] = user_load(array('uid' => $node->timeslots_organizers[0], 'status' => 1));
@@ -824,13 +843,13 @@ function volunteer_timeslots_reminder_ma
       $organizer[$node->nid]->mail = variable_get('site_mail', ini_get('sendmail_from'));
     }
   }
-  
-  $account = user_load(array('uid' => $uid, 'status' => 1)); 
+
+  $account = user_load(array('uid' => $uid, 'status' => 1));
   if (empty($account)) {
     watchdog('user', t("Volunteer timeslots: the user ID '%s' for node/%n could not be loaded.", array('%s' => $uid, '%n' => $node->nid)), WATCHDOG_ERROR);
     return;
   }
-  
+
   // Compose the body:
   if (empty($text[$node->nid])) {
     switch (variable_get('event_timezone_display', 'event')) {
@@ -845,7 +864,7 @@ function volunteer_timeslots_reminder_ma
         $start_offset = variable_get('date_default_timezone', 0);
         break;
     }
-    $start_format = format_date($node->event_start, 'small', '', $start_offset);  
+    $start_format = format_date($node->event_start, 'small', '', $start_offset);
     $message[] = t($opening. ' @title', array('@title' => $node->title));
     $message[] = t('This is scheduled for @event_start. To see which time slot you volunteered for, go to !url', array('@event_start' => $start_format, '!url' => url("node/".$node->nid, NULL, NULL, TRUE)));
     $message[] = vt_mail_output(check_markup($node->body, $node->format, FALSE));
@@ -857,21 +876,18 @@ function volunteer_timeslots_reminder_ma
   }
 
   // Prepare all fields:
-  $to = $account->mail;
-  $from = $organizer[$node->nid]->mail;
+  $message['to'] = $account->mail;
+  $message['from'] = $organizer[$node->nid]->mail;
 
   // Format the subject:
-  $subject = '['. variable_get('site_name', 'drupal') .'] '. t('Event volunteer information');
+  $message['subject'] = '['. variable_get('site_name', 'drupal') .'] '. t('Event volunteer information');
 
   // Prepare the body:
-  $body = $account->name.",\n\n". $text[$node->nid];
-
-  // Send the e-mail:
-  drupal_mail('volunteer_timeslots_reminder', $to, $subject, $body, $from);
+  $message['body'] = $account->name .",\n\n". $text[$node->nid];
 }
 
 // takes filtered HTML as input and transforms for email
-// modified from og.module 
+// modified from og.module
 function vt_mail_output($body, $html = TRUE) {
 
   if ($html) {
