Index: invite.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/invite/invite.info,v
retrieving revision 1.1.2.5.2.1
diff -u -p -r1.1.2.5.2.1 invite.info
--- invite.info	10 Jul 2008 10:18:06 -0000	1.1.2.5.2.1
+++ invite.info	24 Jul 2008 22:34:24 -0000
@@ -1,5 +1,6 @@
 ; $Id: invite.info,v 1.1.2.5.2.1 2008/07/10 10:18:06 smk Exp $
 name = Invite
 description = "Allow your users to send and track invitations to join your site."
-dependencies = token
+dependencies[] = token
 package = Invite
+core = 6.x
\ No newline at end of file
Index: invite.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/invite/invite.install,v
retrieving revision 1.3.2.26.2.7
diff -u -p -r1.3.2.26.2.7 invite.install
--- invite.install	10 Jul 2008 10:18:06 -0000	1.3.2.26.2.7
+++ invite.install	24 Jul 2008 22:34:24 -0000
@@ -5,6 +5,117 @@
  * Install the initial schema.
  */
 function invite_install() {
+  drupal_install_schema('invite');
+}
+
+function invite_schema() {
+  $schema = array();
+  
+  $schema['invite'] = array(
+    'description' => t('Lists invitations that have been made.'),
+    'fields' => array(
+      'reg_code' => array(
+        'description' => 'registration code?',
+        'type' => 'varchar',
+        'length' => 8,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'email' => array(
+        'description' => t('Email Address'),
+        'type' => 'varchar',
+        'length' => 100,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'uid' => array(
+        'description' => t('User who invited'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'invitee' => array(
+        'description' => t('?'),
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'created' => array(
+        'description' => t('?'),
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'expiry' => array(
+        'description' => t('?'),
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'joined' => array(
+        'description' => t('?'),
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'canceled' => array(
+        'description' => t('?'),
+        'type' => 'int',
+        'size' => 'tiny',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'resent' => array(
+        'description' => t('?'),
+        'type' => 'int',
+        'size' => 'small',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'data' => array(
+        'description' => t('?'),
+        'type' => 'text',
+        'not null' => TRUE,
+        'default' => '',
+      ),
+    ),
+    'unique keys' => array(
+      'reg_code' => array('reg_code'),
+    ),
+    'indexes' => array(
+      'email' => array('email'),
+      'uid'   => array('uid'),
+    ),
+  );
+  
+  $schema['invite_notifications'] = array(
+    'description' => t('Stores notifications of invitees'),
+    'fields' => array(
+      'uid' => array(
+        'description' => t('User who invited'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'invitee' => array(
+        'description' => t('?'),
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+    ),
+    'unique keys' => array(
+      'uid_invitee' => array('uid', 'invitee'),
+    )
+  );
+  
+  return $schema;
+}
+
+/*
+function invite_old_install() {
   switch ($GLOBALS['db_type']) {
     case 'mysql':
     case 'mysqli':
@@ -23,14 +134,14 @@ function invite_install() {
           UNIQUE (reg_code),
           KEY (email),
           KEY (uid)
-        ) /*!40100 DEFAULT CHARACTER SET utf8 */;"
+        ) / *!40100 DEFAULT CHARACTER SET utf8 * /;"
       );
       db_query("
         CREATE TABLE {invite_notifications} (
           uid int(10) NOT NULL default '0',
           invitee int(10) NOT NULL default '0',
           UNIQUE (uid, invitee)
-        ) /*!40100 DEFAULT CHARACTER SET utf8 */;"
+        ) / *!40100 DEFAULT CHARACTER SET utf8 * /;"
       );
       break;
 
@@ -61,14 +172,14 @@ function invite_install() {
       );
       break;
   }
-}
+} */
 
 /**
  * Implementation of hook_uninstall().
  */
 function invite_uninstall() {
   // Drop database table
-  db_query('DROP TABLE {invite}');
+  drupal_uninstall_schema('invite');
 
   // Delete variables
   $sql = "DELETE from {variable} WHERE name LIKE '%s%%'";
@@ -120,13 +231,20 @@ function _invite_add_permission($rid, $p
 
 function invite_update_1() {
   $ret = array();
-  switch ($GLOBALS['db_type']) {
+  /*switch ($GLOBALS['db_type']) {
     case 'mysql':
     case 'mysqli':
       $ret[] = update_sql("ALTER TABLE {invite} CHANGE reg_code reg_code VARCHAR(64) UNIQUE NOT NULL");
       $ret[] = update_sql("ALTER TABLE {invite} ADD INDEX reg_code_idx (reg_code)");
       break;
-  }
+  }*/
+  db_change_field($ret, 'invite', 'reg_code', 'reg_code', array('type' => 'varchar', 'length' => 64, 'not null' => TRUE), 
+    array('unique keys' => array(
+        'reg_code' => array('reg_code'),
+      ), 'indexes' => array(
+        'reg_code' => array('reg_code'),
+      ),
+    ));
   return $ret;
 }
 
@@ -135,7 +253,7 @@ function invite_update_1() {
  */
 function invite_update_2() {
   $ret = array();
-  switch ($GLOBALS['db_type']) {
+  /*switch ($GLOBALS['db_type']) {
     case 'mysql':
     case 'mysqli':
       $ret[] = update_sql("ALTER TABLE {invite} DROP INDEX reg_code_idx");
@@ -145,7 +263,9 @@ function invite_update_2() {
       $ret[] = update_sql("DROP INDEX reg_code_idx");
       $ret[] = update_sql("CREATE INDEX {invite}_uid_idx ON {invite} (uid)");
       break;
-  }
+  }*/
+  db_drop_index($ret, 'invite', 'reg_code');
+  db_add_index($ret, 'invite', 'uid', array('uid'));
   return $ret;
 }
 
@@ -155,13 +275,14 @@ function invite_update_2() {
 function invite_update_3() {
   $ret = array();
   $result = db_query("SELECT DISTINCT i.uid FROM {invite} i LEFT JOIN {users} u ON i.uid = u.uid WHERE u.uid IS NULL");
-  $count = db_num_rows($result);
+  $count = 0;
   $sql = "DELETE FROM {invite} WHERE uid = %d";
   if (!variable_get('invite_allow_join_delete', 0)) {
     $sql .= " AND timestamp != 0";
   }
   while ($inviter = db_fetch_object($result)) {
     db_query($sql, $inviter->uid);
+    $count++;
   }
   $ret[] = array(
     'query' => strtr('%count orphaned invites have been deleted.', array('%count' => $count)),
@@ -175,7 +296,7 @@ function invite_update_3() {
  */
 function invite_update_4() {
   $ret = array();
-  switch ($GLOBALS['db_type']) {
+  /*switch ($GLOBALS['db_type']) {
     case 'mysql':
     case 'mysqli':
       $ret[] = update_sql("ALTER TABLE {invite} CHANGE received received tinyint(3) unsigned NOT NULL default '0'");
@@ -183,7 +304,8 @@ function invite_update_4() {
     case 'pgsql':
       db_change_column($ret, 'invite', 'received', 'received', 'SMALLINT', array('not null' => TRUE));
       break;
-  }
+  }*/
+  db_change_field($ret, 'invite', 'received', 'received', array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0));
   // Prevent displaying a whole bunch of messages for old invites
   $ret[] = update_sql("UPDATE {invite} SET received = 1 WHERE mid <> 0");
   return $ret;
@@ -194,7 +316,7 @@ function invite_update_4() {
  */
 function invite_update_5() {
   $ret = array();
-  switch ($GLOBALS['db_type']) {
+  /*switch ($GLOBALS['db_type']) {
     case 'mysql':
     case 'mysqli':
       $ret[] = update_sql("ALTER TABLE {invite} ADD COLUMN message TEXT NOT NULL default ''");
@@ -202,7 +324,8 @@ function invite_update_5() {
     case 'pgsql':
       db_add_column($ret, 'invite', 'message', 'TEXT', array('not null' => TRUE, 'default' => "''"));
       break;
-  }
+  }*/
+  db_add_field($ret, 'invite', 'message', array('type' => 'text', 'not null' => TRUE, 'default' => ''));
   return $ret;
 }
 
@@ -213,9 +336,10 @@ function invite_update_6() {
   $ret = array();
   if (variable_get('invite_allow_join_delete', 0)) {
     $result = db_query("SELECT i.mid FROM {invite} i LEFT JOIN {users} u ON i.mid = u.uid WHERE u.uid IS NULL");
-    $count = db_num_rows($result);
+    $count = 0;
     while ($invitee = db_fetch_object($result)) {
       db_query("DELETE FROM {invite} WHERE mid = %d", $invitee->mid);
+      $count++;
     }
     $ret[] = array(
       'query' => strtr('%count orphaned invites have been deleted.', array('%count' => $count)),
@@ -237,7 +361,7 @@ function invite_update_7() {
     'query' => 'The message tokens for the invite module have been successfully updated.',
     'success' => TRUE
   );
-  drupal_set_message(strtr('Please note that invite now depends on the %token module.', array('%token' => l('token', 'http://drupal.org/project/token', array('target' => '_blank'), NULL, NULL, TRUE))), 'error');
+  drupal_set_message(strtr('Please note that invite now depends on the %token module.', array('%token' => l('token', 'http://drupal.org/project/token', array('attributes' => array('target' => '_blank'), 'absolute' => TRUE)))), 'error');
   return $ret;
 }
 
@@ -247,6 +371,7 @@ function invite_update_7() {
 function invite_update_8() {
   $ret = array();
 
+  /*
   // Add column data first
   switch ($GLOBALS['db_type']) {
     case 'mysql':
@@ -270,7 +395,20 @@ function invite_update_8() {
   }
 
   // Finally drop column message
-  $ret[] = update_sql("ALTER TABLE {invite} DROP message");
+  $ret[] = update_sql("ALTER TABLE {invite} DROP message");*/
+  
+  db_change_field($ret, 'invite', 'message', 'data', array('type' => 'text', 'not null' => TRUE, 'default' => ''));
+  
+  // Convert existing messages
+  $result = db_query("SELECT reg_code, data FROM {invite} WHERE data <> ''");
+  while ($row = db_fetch_object($result)) {
+    if (substr($row->message, 0, 2) == 'a:') {
+      // Already serialized
+      continue;
+    }
+    $data = array('subject' => NULL, 'message' => $row->data);
+    db_query("UPDATE {invite} SET data = '%s' WHERE reg_code = '%s'", serialize($data), $row->reg_code);
+  }
 
   return $ret;
 }
@@ -376,7 +514,7 @@ function invite_update_12() {
  */
 function invite_update_200() {
   $ret = array();
-  switch ($GLOBALS['db_type']) {
+  /*switch ($GLOBALS['db_type']) {
     case 'mysql':
     case 'mysqli':
       $ret[] = update_sql("ALTER TABLE {invite} DROP PRIMARY KEY, ADD INDEX email (email)");
@@ -395,7 +533,14 @@ function invite_update_200() {
       db_add_column($ret, 'invite', 'canceled', 'SMALLINT', array('default' => 0, 'not null' => TRUE));
       db_add_column($ret, 'invite', 'resent', 'SMALLINT', array('default' => 0, 'not null' => TRUE));
       break;
-  }
+  }*/
+  db_drop_primary_key($ret, 'invite'); // drop primary key.
+  db_add_index($ret, 'invite', 'email', array('email'));
+  db_change_field($ret, 'invite', 'mid', 'invitee', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
+  db_change_field($ret, 'invite', 'timestamp', 'joined', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
+  db_add_field($ret, 'invite', 'created', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
+  db_add_field($ret, 'invite', 'cancelled', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0));
+  db_add_field($ret, 'invite', 'resent', array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0));
   return $ret;
 }
 
@@ -404,7 +549,7 @@ function invite_update_200() {
  */
 function invite_update_201() {
   $ret = array();
-  switch ($GLOBALS['db_type']) {
+  /*switch ($GLOBALS['db_type']) {
     case 'mysql':
     case 'mysqli':
       $ret[] = update_sql("
@@ -412,7 +557,7 @@ function invite_update_201() {
           uid int(10) NOT NULL default '0',
           invitee int(10) NOT NULL default '0',
           KEY (uid)
-        ) /*!40100 DEFAULT CHARACTER SET utf8 */;"
+        ) *!40100 DEFAULT CHARACTER SET utf8 *;"
       );
       break;
     case 'pgsql':
@@ -424,11 +569,33 @@ function invite_update_201() {
       );
       $ret[] = update_sql("CREATE INDEX {invite_notifications}_uid_idx ON {invite_notifications}(uid)");
       break;
-  }
+  }*/
+  db_create_table($ret, 'invite_notifications', array(
+    'description' => t('Stores notifications of invitees'),
+    'fields' => array(
+      'uid' => array(
+        'description' => t('User who invited'),
+        'type' => 'int',
+        //'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'invitee' => array(
+        'description' => t('?'),
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+    ),
+    'indexes' => array(
+      'uid' => array('uid'),
+    )
+  ));
   // Convert old data
   db_query("INSERT INTO {invite_notifications} (uid, invitee) SELECT uid, invitee FROM {invite} WHERE joined != 0 AND received = 0");
   // Drop old column
-  $ret[] = update_sql("ALTER TABLE {invite} DROP received");
+  //$ret[] = update_sql("ALTER TABLE {invite} DROP received");
+  db_drop_field($ret, 'invite', 'received');
   return $ret;
 }
 
@@ -437,7 +604,7 @@ function invite_update_201() {
  */
 function invite_update_202() {
   $ret = array();
-  switch ($GLOBALS['db_type']) {
+  /*switch ($GLOBALS['db_type']) {
     case 'mysql':
     case 'mysqli':
       $ret[] = update_sql("ALTER TABLE {invite_notifications} DROP INDEX uid,  ADD UNIQUE uid_invitee (uid, invitee)");
@@ -448,5 +615,29 @@ function invite_update_202() {
       $ret[] = update_sql("CREATE UNIQUE INDEX {invite_notifications}_uid_invitee_key ON {invite_notifications}(uid, invitee)");
       break;
   }
+  return $ret;*/
+  db_drop_index($ret, 'invite_notifications', 'uid');
+  db_add_unique_key($ret, 'invite_notifications', 'uid_invitee', array('uid', 'invitee'));
+}
+
+/**
+ * normalize things for Drupal 6.
+ * 
+ * a) Change uid field to be an unsigned int, as per user module.
+ *
+ * @return unknown
+ */
+function invite_update_6000() {
+  $ret = array();
+  db_drop_index($ret, 'invite', 'uid');
+  db_change_field($ret, 'invite', 'uid', 'uid', array('type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0), array('indexes' => array('uid' => array('uid'))));
+  db_drop_index($ret, 'invite_notifications', 'uid_invitee');
+  db_change_field($ret, 'invite_notifications', 'uid', 'uid', array('type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0), array('unique keys' => array('uid_invitee' => array('uid', 'invitee'))));
   return $ret;
 }
Index: invite.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/invite/invite.module,v
retrieving revision 1.10.2.93.2.26
diff -u -p -r1.10.2.93.2.26 invite.module
--- invite.module	12 Jul 2008 21:40:13 -0000	1.10.2.93.2.26
+++ invite.module	24 Jul 2008 22:34:24 -0000
@@ -27,9 +27,12 @@ require_once drupal_get_path('module', '
  *
  * Returns appropriate help text for all three invite status pages.
  */
-function invite_help($section) {
-  if (arg(0) == 'user' && is_numeric(arg(1)) && arg(2) == 'invites') {
+function invite_help($path, $arg) {
+  /*if ($arg[0] == 'user' && is_numeric($arg[1]) && $arg[2] == 'invites') {
     return _invite_user_help($section, arg(1));
+  }*/
+  if (strpos($path, 'user/%user/invites') === 0) {
+    return _invite_user_help($path, $arg[1]);
   }
   else if ($section == 'admin/help#invite') {
     return _invite_module_help();
@@ -44,16 +47,16 @@ function invite_help($section) {
  * @param $uid
  *   A user profile id.
  */
-function _invite_user_help($section, $uid) {
-  switch ($section) {
-    case "user/$uid/invites":
-    case "user/$uid/invites/accepted":
+function _invite_user_help($path, $uid) {
+  switch ($path) {
+    case "user/%user/invites":
+    case "user/%user/invites/accepted":
       $output = '<p>'. t("The invitations shown on this page have been used to join the site. Clicking on an e-mail address takes you to the user's profile page.");
       break;
-    case "user/$uid/invites/pending":
+    case "user/%user/invites/pending":
       $output = '<p>'. t("The invitations shown on this page haven't been accepted yet.");
       break;
-    case "user/$uid/invites/expired":
+    case "user/%user/invites/expired":
       $output = '<p>'. t('The invitations shown on this page have not been used to register on the site within the expiration period of @count days.', array('@count' => variable_get('invite_expiry', 30)));
       break;
     default:
@@ -89,140 +92,172 @@ function invite_perm() {
 }
 
 /**
+ * Implements hook_init().
+ *
+ */
+function invite_init() {
+  // Notify current user about newly joined invitees.
+  if (!empty($user->invite_sent) && !module_invoke('throttle', 'status')) {
+    invite_notify($user->uid);
+  }
+}
+
+/**
  * Implementation of hook_menu().
  */
-function invite_menu($may_cache) {
+function invite_menu() {
   global $user;
   $items = array();
 
-  $send_access = user_access('send invitations');
-  $track_access = user_access('track invitations');
-  $admin_access = user_access('administer site configuration');
-
-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'admin/user/invite',
-      'title' => t('Invites'),
-      'callback' => 'invite_admin_overview',
-      'access' => $admin_access,
-      'type' => MENU_NORMAL_ITEM,
-    );
-    $items[] = array(
-      'path' => 'admin/user/invite/list',
-      'title' => t('Inviters'),
-      'access' => $admin_access,
-      'type' => MENU_DEFAULT_LOCAL_TASK,
-      'weight' => -5,
-    );
-    $items[] = array(
-      'path' => 'admin/user/invite/settings',
-      'title' => t('Settings'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => 'invite_settings',
-      'access' => $admin_access,
-      'type' => MENU_LOCAL_TASK,
-      'weight' => 5,
-    );
-    $items[] = array(
-      'path' => 'invite',
-      'title' => variable_get('invite_page_title', t('Invite a friend')),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('invite_form', 'page', array()),
-      'access' => $send_access,
-      'type' => MENU_NORMAL_ITEM,
-    );
-    $items[] = array(
-      'path' => 'invite/accept',
-      'callback' => 'invite_controller',
-      'access' => TRUE,
-      'type' => MENU_CALLBACK,
-    );
-    $items[] = array(
-      'path' => 'invite/withdraw',
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('invite_cancel'),
-      'access' => $track_access,
-      'type' => MENU_CALLBACK,
-    );
-  }
-  else {
-    // Notify current user about newly joined invitees.
-    if (!empty($user->invite_sent) && !module_invoke('throttle', 'status')) {
-      invite_notify($user->uid);
-    }
+  $send_access = array('send invitations');
+  $track_access = array('track invitations');
+  $admin_access = array('administer site configuration');
 
-    if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) == $user->uid) {
-      $items[] = array(
-        'path' => 'user/'. arg(1) .'/invites',
-        'title' => t('Track invitations'),
-        'callback' => 'invite_user_overview',
-        'access' => $track_access,
-        'type' => MENU_LOCAL_TASK,
-      );
-      $items[] = array(
-        'path' => 'user/'. arg(1) .'/invites/accepted',
-        'title' => t('Accepted'),
-        'callback' => 'invite_user_overview',
-        'callback arguments' => array('accepted'),
-        'access' => $track_access,
-        'type' => MENU_DEFAULT_LOCAL_TASK,
-        'weight' => -5,
-      );
-      $items[] = array(
-        'path' => 'user/'. arg(1) .'/invites/pending',
-        'title' => t('Pending'),
-        'callback' => 'invite_user_overview',
-        'callback arguments' => array('pending'),
-        'access' => $track_access,
-        'type' => MENU_LOCAL_TASK,
-      );
-      $items[] = array(
-        'path' => 'user/'. arg(1) .'/invites/expired',
-        'title' => t('Expired'),
-        'callback' => 'invite_user_overview',
-        'callback arguments' => array('expired'),
-        'access' => $track_access,
-        'type' => MENU_LOCAL_TASK,
-        'weight' => 5,
-      );
-      $items[] = array(
-        'path' => 'user/'. arg(1) .'/invites/new',
-        'title' => t('New invitation'),
-        'callback' => 'drupal_get_form',
-        'callback arguments' => array('invite_form', 'page', array()),
-        'access' => $send_access,
-        'type' => MENU_LOCAL_TASK,
-        'weight' => 10,
-      );
-    }
-    else if (arg(2) == 'invite' && arg(3) == 'details' && arg(4)) {
-      if ($account = user_load(array('uid' => arg(4)))) {
-        $items[] = array(
-          'path' => 'admin/user/invite/details/'. arg(4),
-          'title' => t('Invitees of @name', array('@name' => $account->name)),
-          'callback' => 'invite_admin_details',
-          'callback arguments' => array(arg(4)),
-          'access' => $admin_access,
-          'type' => MENU_LOCAL_TASK,
-        );
-      }
-    }
-    else if (arg(0) == 'invite' && arg(1) == 'resend' && arg(2)) {
-      $items[] = array(
-        'path' => 'invite/resend/'. arg(2),
-        'title' => t('Resend invitation'),
-        'callback' => 'invite_resend',
-        'callback arguments' => array(arg(2)),
-        'access' => $send_access,
-        'type' => MENU_CALLBACK,
-      );
-    }
-  }
+
+  $items['admin/user/invite'] = array(
+    'title' => 'Invites',
+    'page callback' => 'invite_admin_overview',
+    'access arguments' => $admin_access,
+    'type' => MENU_NORMAL_ITEM,
+  );
+  $items['admin/user/invite/list'] = array(
+    'title' => 'Inviters',
+    'access arguments' => $admin_access,
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+    'weight' => -5,
+  );
+  $items['admin/user/invite/settings'] = array(
+    'title' => 'Settings',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('invite_settings'),
+    'access arguments' => $admin_access,
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 5,
+  );
+  $items['invite'] = array(
+    'title callback' => 'invite_path_title',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('invite_form', 'page', array()),
+    'access arguments' => $send_access,
+    'type' => MENU_NORMAL_ITEM,
+  );
+  $items['invite/accept'] = array(
+    'path' => 'invite/accept',
+    'page callback' => 'invite_controller',
+    'access callback' => 'invite_accept_public',
+    'type' => MENU_CALLBACK,
+  );
+  $items['invite/withdraw'] = array(
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('invite_cancel'),
+    'access arguments' => $track_access,
+    'type' => MENU_CALLBACK,
+  );
+
+  $items['user/%user/invites'] = array(
+    'title' => 'Track invitations',
+    'page callback' => 'invite_user_overview',
+    'access callback' => 'invite_access_callback',
+    'access arguments' => array('track invitations', 1),
+    'type' => MENU_LOCAL_TASK,
+  );
+  $items['user/%user/invites/accepted'] = array(
+    'title' => 'Accepted',
+    'page callback' => 'invite_user_overview',
+    'page arguments' => array('accepted'),
+    'access callback' => 'invite_access_callback',
+    'access arguments' => array('track invitations', 1),
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+    'weight' => -5,
+  );
+  $items['user/%user/invites/pending'] = array(
+    'title' => 'Pending',
+    'page callback' => 'invite_user_overview',
+    'page arguments' => array('pending'),
+    'access callback' => 'invite_access_callback',
+    'access arguments' => array('track invitations', 1),
+    'type' => MENU_LOCAL_TASK,
+  );
+  $items['user/%user/invites/expired'] = array(
+    'title' => 'Expired',
+    'page callback' => 'invite_user_overview',
+    'page arguments' => array('expired'),
+    'access callback' => 'invite_access_callback',
+    'access arguments' => array('track invitations', 1),
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 5,
+  );
+  $items['user/%user/invites/new'] = array(
+    'title' => 'New invitation',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('invite_form', 'page', array()),
+    'access callback' => 'invite_access_callback',
+    'access arguments' => array('send invitations', 1),
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 10,
+  );
+
+  $items['admin/user/invite/details/%user'] = array(
+    'title callback' => 'invite_details_usertitle',
+    'title arguments' => array(4),
+    'page callback' => 'invite_admin_details',
+    'page arguments' => array(4),
+    'access arguments' => $admin_access,
+    'type' => MENU_LOCAL_TASK,
+  );
+        
+  // Invite Resend path - wildcard is an invite code.
+  $items['invite/resend/%'] = array(
+    'title' => 'Resend invitation',
+    'page callback' => 'invite_resend',
+    'page arguments' => array(arg(2)),
+    'access arguments' => $send_access,
+    'type' => MENU_CALLBACK,
+  );
 
   return $items;
 }
 
 /**
+ * Menu Access helper function that allows us to easily mark menu items as publicly accessible.
+ *
+ * @return unknown
+ */
+function invite_accept_public() {
+  return TRUE;
+}
+
+/**
+ * Menu Access helper function that ensures that the user/%user/invites links are only visible if you have permission and it's your account.
+ *
+ * @param unknown_type $permission
+ * @param unknown_type $account
+ * @return unknown
+ */
+function invite_access_callback($permission, $account) {
+  global $user;
+  
+  return ($account->uid == $user->uid && user_access($permission));
+}
+
+function invite_path_title() {
+  return variable_get('invite_page_title', t('Invite a friend'));
+}
+
+/**
+ * Menu Title helper function - sets the title of admin/user/invite/details/%user page.
+ *
+ * @param unknown_type $account
+ * @return unknown
+ */
+function invite_details_usertitle($account) {
+  if ($account) {
+    return t('Invitees of @name', array('@name' => $account->name));
+  }
+  return '';
+}
+
+/**
  * Displays a notification message when an invited user has registered.
  *
  * @param $uid
@@ -262,7 +297,7 @@ function invite_controller() {
 /**
  * Implementation of hook_form_alter().
  */
-function invite_form_alter($form_id, &$form) {
+function invite_form_alter(&$form, $form_state, $form_id) {
   switch ($form_id) {
     case 'user_admin_settings':
       // Add new registration mode.
@@ -312,7 +347,7 @@ function invite_form_alter($form_id, &$f
       // Remove temptation for non members to try and register.
       if (variable_get('user_register', 1) === '1-inviteonly') {
         $new_items = array();
-        $new_items[] = l(t('Request new password'), 'user/password', array('title' => t('Request new password via e-mail.')));
+        $new_items[] = l(t('Request new password'), 'user/password', array('attributes' => array('title' => t('Request new password via e-mail.'))));
         $form['links']['#value'] = theme('item_list', $new_items);
       }
       break;
@@ -500,7 +535,7 @@ function invite_delete($uid) {
  */
 function invite_block($op = 'list', $delta = 0, $edit = array()) {
   if ($op == 'list') {
-    $blocks[0] = array('info' => t('Invite a friend'));
+    $blocks[0] = array('info' => t('Invite a friend'), 'cache' => BLOCK_CACHE_PER_ROLE);
     return $blocks;
   }
   else if ($op == 'view') {
@@ -528,7 +563,7 @@ function invite_block($op = 'list', $del
  * @return
  *   A form definition.
  */
-function invite_form($op = 'page', $edit = array()) {
+function invite_form(&$form_state, $op = 'page', $edit = array()) {
   global $user;
 
   if (!is_array($edit)) {
@@ -806,6 +841,27 @@ function invite_block_form($remaining_in
 }
 
 /**
+ * Implements hook_theme().
+ *
+ * @return unknown
+ */
+function invite_theme() {
+  return array(
+    'invite_form' => array(
+      'arguments' => array('form' => array()),
+    ),
+    'invite_user_overview' => array(
+      'arguments' => array('rows' => array()),
+      'file' => 'invite_admin.inc',
+    ),
+    'invite_token_help' => array(
+      'arguments' => array('type' => '', 'prefix' => '', 'suffix' => ''),
+      'file' => 'invite_token.inc',
+    ),
+  );
+}
+
+/**
  * Theme function for the invite form.
  *
  * @ingroup themeable
@@ -852,15 +908,16 @@ function theme_invite_form($form) {
  * Filters out e-mails that are already registered or have been invited before.
  * Checks the invite limit of the user and the max. number of invites per turn.
  */
-function invite_form_validate($form_id, &$edit) {
+function invite_form_validate($form, &$form_state) {
   global $user;
 
-  $emails = _invite_get_emails($edit['email']);
+  $emails = _invite_get_emails($form_state['values']['email']);
 
-  if (!$edit['resent']) {
+  if (!$form_state['values']['resent']) {
     if (count($emails) > 0) {
+      $email_placeholder = db_placeholders($emails, 'varchar');
       // Filter out already registered users, but pass validation.
-      $failed_emails = _invite_validate_emails("SELECT mail AS email FROM {users} WHERE mail IN (%s)", $emails);
+      $failed_emails = _invite_validate_emails("SELECT mail AS email FROM {users} WHERE mail IN (". $email_placeholder .")", $emails);
       if (count($failed_emails)) {
         $error = format_plural(count($failed_emails), 'The following recipient is already a member:', 'The following recipients are already members:') .'<br />';
         foreach ($failed_emails as $key => $email) {
@@ -872,7 +929,7 @@ function invite_form_validate($form_id, 
       }
 
       // Filter out already invited users, but pass validation.
-      $failed_emails = _invite_validate_emails("SELECT email FROM {invite} WHERE email IN (%s) AND uid = %d AND canceled = 0", $emails, $user->uid);
+      $failed_emails = _invite_validate_emails("SELECT email FROM {invite} WHERE email IN (". $email_placeholder .") AND uid = %d AND canceled = 0", $emails, $user->uid);
       if (count($failed_emails)) {
         $error = format_plural(count($failed_emails), 'You did already invite the following recipient:', 'You did already invite the following recipients:') .'<br />';
         $error .= implode(', ', array_map('check_plain', $failed_emails));
@@ -887,8 +944,8 @@ function invite_form_validate($form_id, 
       }
 
       // Check invite limit, fail to let the user choose which ones to send.
-      if (isset($edit['remaining_invites']) && count($emails) > $edit['remaining_invites']) {
-        form_set_error('email', format_plural($edit['remaining_invites'], 'You have only 1 invite left.', 'You have only @count invites left.'));
+      if (isset($form_state['values']['remaining_invites']) && count($emails) > $form_state['values']['remaining_invites']) {
+        form_set_error('email', format_plural($form_state['values']['remaining_invites'], 'You have only 1 invite left.', 'You have only @count invites left.'));
         return;
       }
 
@@ -901,7 +958,9 @@ function invite_form_validate($form_id, 
   }
 
   // Save valid emails.
-  form_set_value(array('#parents' => array('valid_emails')), $emails);
+  //form_set_value(array('#parents' => array('valid_emails')), $emails);
+  //form_set_value(array('#parents' => array('valid_emails')), $emails, $form_state);
+  $form_state['values']['valid_emails'] = $emails;
 }
 
 /**
@@ -941,7 +1000,8 @@ function _invite_get_emails($string) {
     $_SESSION['invite_failed_emails'] = serialize($failed_emails);
   }
 
-  return $valid_emails;
+  //drupal_set_message(dprint_r($valid_emails, TRUE));
+  //return $valid_emails;
 }
 
 /**
@@ -959,11 +1019,11 @@ function _invite_get_emails($string) {
  */
 function _invite_validate_emails($sql, &$emails) {
   $failed_emails = array();
-  $args = func_get_args();
-  array_shift($args);
-  array_shift($args);
-  array_unshift($args, "'". implode("','", array_map('db_escape_string', $emails)) ."'");
-  $result = db_query(vsprintf($sql, $args));
+  //$args = func_get_args();
+  //array_shift($args);
+  //array_shift($args);
+  //array_unshift($args, "'". implode("','", array_map('db_escape_string', $emails)) ."'");
+  $result = db_query($sql, $emails);
   while ($row = db_fetch_object($result)) {
     $failed_emails[] = $row->email;
   }
@@ -975,8 +1035,11 @@ function _invite_validate_emails($sql, &
 /**
  * Forms API callback; process submitted form data.
  */
-function invite_form_submit($form_id, $edit) {
+function invite_form_submit($form, &$form_state) {
   global $user;
+  
+  // Set this now, so other things can change it later - 
+  $form_state['redirect'] = 'invite';
 
   $failed_emails = array();
   $num_failed = $num_succeeded = 0;
@@ -987,16 +1050,16 @@ function invite_form_submit($form_id, $e
     $num_failed = count($failed_emails);
   }
 
-  $subject = isset($edit['subject']) ? trim($edit['subject']) : invite_get_subject();
-  $message = isset($edit['message']) ? trim($edit['message']) : NULL;
+  $subject = isset($form_state['values']['subject']) ? trim($form_state['values']['subject']) : invite_get_subject();
+  $message = isset($form_state['values']['message']) ? trim($form_state['values']['message']) : NULL;
 
-  foreach ($edit['valid_emails'] as $email) {
+  foreach ($form_state['values']['valid_emails'] as $email) {
     // Create the invite object.
-    $code = $edit['reg_code'] ? $edit['reg_code'] : invite_generate_code();
+    $code = $form_state['values']['reg_code'] ? $form_state['values']['reg_code'] : invite_generate_code();
     $invite = _invite_substitutions(array(
       'email' => $email,
       'code'  => $code,
-      'resent'  => $edit['resent'],
+      'resent'  => $form_state['values']['resent'],
       'data'  => array('subject' => $subject, 'message' => $message),
     ));
 
@@ -1009,7 +1072,7 @@ function invite_form_submit($form_id, $e
       invite_save($invite);
 
       // Notify other modules.
-      if (!$edit['resent']) {
+      if (!$form_state['values']['resent']) {
         $args = array('inviter' => $invite->inviter, 'email' => $invite->email, 'code' => $invite->code);
         module_invoke_all('invite', 'invite', $args);
       }
@@ -1027,9 +1090,9 @@ function invite_form_submit($form_id, $e
   }
 
   if ($num_succeeded) {
-    if (isset($edit['remaining_invites'])) {
+    if (isset($form_state['values']['remaining_invites'])) {
       // Update user property if user is limited.
-      user_save($user, array('invites' => $edit['remaining_invites'] - $num_succeeded));
+      user_save($user, array('invites' => $form_state['values']['remaining_invites'] - $num_succeeded));
     }
     $message = format_plural($num_succeeded, 'Your invitation has been successfully sent. You will be notified when the invitee joins the site.', '@count invitations have been successfully sent. You will be notified when any invitee joins the site.');
     drupal_set_message($message);
@@ -1040,10 +1103,8 @@ function invite_form_submit($form_id, $e
   }
   else if (user_access('track invitations') && $user->uid) {
     // Everything went well: redirect to pending invites page.
-    return "user/$user->uid/invites/pending";
+    $form_state['redirect'] = "user/$user->uid/invites/pending";
   }
-
-  return 'invite';
 }
 
 /**
@@ -1122,16 +1183,31 @@ function invite_send_invite($recipient, 
     $headers['Reply-To'] = $reply_to;
   }
 
-  if (!($success = drupal_mail('invite-mail', $recipient, $subject, wordwrap($body, 72), $from, $headers))) {
-    static $error_shown = FALSE;
-    if (!$error_shown) {
-      drupal_set_message(t('Problems occurred while sending the invitation(s). Please contact the site administrator.'), 'error');
-      $error_shown = TRUE;
-    }
-    watchdog('invite', t('Failed sending invitation. To: @email From: @from', array('@email' => '<'. $recipient .'>', '@from' => '<'. $from .'>')));
-  }
+  $params = array('headers' => $headers, 'body' => $body, 'subject' => $subject);
+  $language = user_preferred_language($user);
+  
+  $message = drupal_mail('invite', 'invite-mail', $recipient, $language, $params, $from);
+  
+  drupal_set_message(dprint_r($message, TRUE));
+  return TRUE; // for testing, we override.
 
-  return $success;
+  return $message['result'];
+}
+
+/**
+ * Implements hook_invite().
+ *
+ * @param unknown_type $key
+ * @param unknown_type $message
+ * @param unknown_type $params
+ */
+function invite_mail($key, &$message, $params) {
+  if ($key == 'invite-mail') {
+    $message['subject'] = $subject;
+    $message['body'][] = $params['body'];
+    $message['headers'] = array_merge($message['headers'], $params['headers']);
+
+  }
 }
 
 /**
@@ -1194,7 +1270,7 @@ function invite_cancel($origin, $code) {
     }
   }
   else {
-    watchdog('invite', t('Detected malicious attempt to delete an invitation.'), WATCHDOG_WARNING, l(t('view'), 'user/'. $user->uid));
+    watchdog('invite', 'Detected malicious attempt to delete an invitation.', array(), WATCHDOG_WARNING, l(t('view'), 'user/'. $user->uid));
     drupal_access_denied();
   }
 
@@ -1204,8 +1280,8 @@ function invite_cancel($origin, $code) {
 /**
  * Submit handler to delete an invitation.
  */
-function invite_cancel_submit($form_id, $form_values) {
-  $invite = $form_values['invite'];
+function invite_cancel_submit($form, $form_state) {
+  $invite = $form_state['values']['invite'];
 
   db_query("UPDATE {invite} SET canceled = 1 WHERE reg_code = '%s'", $invite->reg_code);
   drupal_set_message(t('Invitation to %email has been withdrawn.', array('%email' => $invite->email)));
@@ -1267,12 +1343,12 @@ function invite_admin_overview() {
 /**
  * Menu callback; return a list of invites by a user.
  *
- * @param $uid
- *   A user id.
+ * @param $account
+ *   A user object.
  */
-function invite_admin_details($uid) {
+function invite_admin_details($account) {
   require_once drupal_get_path('module', 'invite') .'/invite_admin.inc';
-  return _invite_admin_details($uid);
+  return _invite_admin_details($account);
 }
 
 /**
@@ -1281,9 +1357,9 @@ function invite_admin_details($uid) {
  * @return
  *   A form definition array.
  */
-function invite_settings() {
+function invite_settings(&$form_state) {
   require_once drupal_get_path('module', 'invite') .'/invite_admin.inc';
-  return _invite_settings();
+  return _invite_settings($form_state);
 }
 
 /**
Index: invite_admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/invite/Attic/invite_admin.inc,v
retrieving revision 1.1.2.4
diff -u -p -r1.1.2.4 invite_admin.inc
--- invite_admin.inc	10 Jul 2008 10:27:28 -0000	1.1.2.4
+++ invite_admin.inc	24 Jul 2008 22:34:24 -0000
@@ -7,7 +7,7 @@
 function _invite_settings() {
   $roles = user_roles(0, 'send invitations');
   if (count($roles) == 0) {
-    drupal_set_message(t('Please enable the <em>send invitations</em> permission for at least one role. This can be done on the <a href="!admin-user-access">Access control page</a>.', array('!admin-user-access' => url('admin/user/access'))));
+    drupal_set_message(t('Please enable the <em>send invitations</em> permission for at least one role. This can be done on the <a href="!admin-user-access">Permissions page</a>.', array('!admin-user-access' => url('admin/user/permissions'))));
   }
   $target_roles = user_roles(1);
 
@@ -40,7 +40,7 @@ function _invite_settings() {
   $form['role'] = array(
     '#type' => 'fieldset',
     '#title' => t('Role settings'),
-    '#description' => t('Note: Permission related settings can be found at the <a href="!admin-user-access">Access control page</a>.', array('!admin-user-access' => url('admin/user/access'))),
+    //'#description' => t('Note: Permission related settings can be found at the <a href="!admin-user-access">Permissions page</a>.', array('!admin-user-access' => url('admin/user/permissions'))),
     '#collapsible' => TRUE,
     '#collapsed' => TRUE,
   );
@@ -200,7 +200,7 @@ function _invite_admin_overview() {
     $cells[] = invite_count($row->uid, 'expired');
     $remaining = invite_get_remaining_invites($row);
     $cells[] = ($remaining == INVITE_UNLIMITED) ? '&infin;' : $remaining;
-    $cells[] = l(t('details'), "admin/user/invite/details/$row->uid", array(), $query);
+    $cells[] = l(t('details'), "admin/user/invite/details/$row->uid", array('query' => $query));
     $rows[] = $cells;
   }
   
@@ -239,20 +239,21 @@ function invite_admin_filter_form() {
   return $form;
 }
 
-function invite_admin_filter_form_submit($form_id, $form_values) {
-  if ($form_values['filter']) {
-    $_SESSION[INVITE_ADMIN_SESSION] = $form_values['filter'];
+function invite_admin_filter_form_submit($form, &$form_state) {
+  if ($form_state['values']['filter']) {
+    $_SESSION[INVITE_ADMIN_SESSION] = $form_state['values']['filter'];
   }
 }
 
 /**
  * Return a list of invites by a user.
  *
- * @param $uid
- *   A user id.
+ * @param $account
+ *   A user object.
  */
-function _invite_admin_details($uid) {
+function _invite_admin_details($account) {
   $now = time();
+  $uid = $account->uid;
   $status_sort = '';
   if ($_GET['order'] == t('Status')) {
     $sort = db_escape_string($_GET['sort']);
Index: invite_cancel_account.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/invite/invite_cancel_account.info,v
retrieving revision 1.1.2.1.2.1
diff -u -p -r1.1.2.1.2.1 invite_cancel_account.info
--- invite_cancel_account.info	10 Jul 2008 10:27:28 -0000	1.1.2.1.2.1
+++ invite_cancel_account.info	24 Jul 2008 22:34:24 -0000
@@ -1,5 +1,6 @@
 ; $Id: invite_cancel_account.info,v 1.1.2.1.2.1 2008/07/10 10:27:28 smk Exp $
 name = Cancel User Accounts
 description = "Allows your users to terminate user accounts by withdrawing their invitation. WARNING - This module is put into effect when you enable it."
-dependencies = invite
+dependencies[] = invite
 package = Invite
+core = 6.x
Index: invite_stats.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/invite/invite_stats.info,v
retrieving revision 1.1.2.2.2.1
diff -u -p -r1.1.2.2.2.1 invite_stats.info
--- invite_stats.info	10 Jul 2008 10:27:28 -0000	1.1.2.2.2.1
+++ invite_stats.info	24 Jul 2008 22:34:24 -0000
@@ -1,5 +1,6 @@
 ; $Id: invite_stats.info,v 1.1.2.2.2.1 2008/07/10 10:27:28 smk Exp $
 name = Invite Statistics
 description = "Displays some statistics about sent invitations."
-dependencies = invite
+dependencies[] = invite
 package = Invite
+core = 6.x
Index: invite_stats.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/invite/invite_stats.module,v
retrieving revision 1.1.2.1.2.5
diff -u -p -r1.1.2.1.2.5 invite_stats.module
--- invite_stats.module	10 Jul 2008 10:27:28 -0000	1.1.2.1.2.5
+++ invite_stats.module	24 Jul 2008 22:34:24 -0000
@@ -121,7 +121,11 @@ function invite_stats_display_user_rank(
   $user_invite_stats_count = db_result(db_query("SELECT COUNT(*) FROM {invite} WHERE uid = %d AND joined <> 0", $uid));
 
   // Calculate user's rank.
-  $rank = 1 + db_num_rows(db_query("SELECT DISTINCT COUNT(uid) FROM {invite} WHERE joined <> 0 GROUP BY uid HAVING COUNT(uid) > %d", $user_invite_stats_count));
+  $result = db_query("SELECT DISTINCT COUNT(uid) FROM {invite} WHERE joined <> 0 GROUP BY uid HAVING COUNT(uid) > %d", $user_invite_stats_count);
+  $rank = 1;
+  while ($row = db_fetch_array($result)) {
+    $rank++;
+  }
 
   // Fetch users with more invites.
   $i = 0;
@@ -158,6 +162,14 @@ function invite_stats_display_user_rank(
   return theme('invite_stats_ranking', $inviters, $rank);
 }
 
+function invite_stats_theme() {
+  return array(
+    'invite_stats_ranking' => array(
+      'arguments' => array('inviters' => NULL, 'rank' => 1),
+    ),
+  );
+}
+
 /**
  * Theme the Top inviters/user rank block.
  *
Index: invite_token.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/invite/invite_token.inc,v
retrieving revision 1.1.2.1.2.3
diff -u -p -r1.1.2.1.2.3 invite_token.inc
--- invite_token.inc	10 Jul 2008 10:28:44 -0000	1.1.2.1.2.3
+++ invite_token.inc	24 Jul 2008 22:34:24 -0000
@@ -12,7 +12,7 @@ function invite_token_values($type = 'al
     $values['invite-mail']        = $object->email;
     $values['invite-message']     = check_plain($object->data['message']);
     $values['invite-message-raw'] = $object->data['message'];
-    $values['join-link']          = url('invite/accept/'. $object->code, NULL, NULL, TRUE);
+    $values['join-link']          = url('invite/accept/'. $object->code, array('absolute' => TRUE));
   }
   return $values;
 }
@@ -56,7 +56,7 @@ function theme_invite_token_help($type =
   $headers = array(t('Token'), t('Replacement value'));
   $rows = array();
   foreach ($full_list as $key => $category) {
-    $rows[] = array(array('data' => drupal_ucfirst($key) . ' ' . t('tokens'), 'class' => 'region', 'colspan' => 2));
+    $rows[] = array(array('data' => drupal_ucfirst($key) .' '. t('tokens'), 'class' => 'region', 'colspan' => 2));
     foreach ($category as $token => $description) {
       $row = array();
       $row[] = $prefix . $token . $suffix;
