Index: invite.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/invite/invite.module,v retrieving revision 1.9.2.4 diff -u -p -r1.9.2.4 invite.module --- invite.module 19 Nov 2006 10:26:53 -0000 1.9.2.4 +++ invite.module 28 Nov 2006 01:22:33 -0000 @@ -1,4 +1,5 @@ $multiple = FALSE, '#required' => $required = TRUE, ); + $form['user_settings']['invite_allow_join_delete'] = array( + '#type' => 'checkbox', + '#title' => t('Allow deletion of joined users'), + '#default_value' => variable_get('invite_allow_join_delete', 0), + '#description' => t('After an invitee has registered, this option allows a site administrator the option to delete the invitations marked as joined. Useful for users who delete their account to be re-invited or for users who change their email address') + ); $form['user_roles'] = array( '#type' => 'fieldset', @@ -267,7 +274,7 @@ function invite_form_alter($form_id, &$f if ((!$user_admin) && $invite_only) { if (!$valid_invite) { // Redirect to the standard login form if in invite only mode and a valid invite is not present - drupal_set_message('Sorry, new user registration by invite only.'); + drupal_set_message(t('Sorry, new user registration by invite only.')); drupal_goto('user/'); } @@ -306,7 +313,7 @@ function invite_register_submit($form_id return user_register_submit($form_id, $form_values); } else { // Do some watchdog stuff - drupal_set_message('You have not been invited to join this site'); + drupal_set_message(t('You have not been invited to join this site.')); watchdog('invite', 'Uninvited user registration attempt', $link = NULL); } } @@ -377,12 +384,30 @@ function invite_page(){ $inc = 0; $result = db_query("SELECT * from {invite} WHERE uid = %d",$user->uid); while ($invite = db_fetch_object($result)){ - $items[] = array($invite->email, (($invite->expiry + (variable_get('invite_expiry', '30')* 24 * 60 * 60))< time()) ? "Expired" :($invite->timestamp ? t('Joined') : t('Pending')),$invite->timestamp ? "delete" : l("delete",'invite/delete/'.urlencode($invite->email))); + $expiry = $invite->expiry + (variable_get('invite_expiry', '30') * 24 * 60 * 60); + if (!$invite->timestamp) { + $email_cell = $invite->email; + if ($expiry < time()) { + $status_cell = t('Expired'); + $action_cell = l("Delete invitation",'invite/delete/'.urlencode($invite->email)); + } + else { + $status_cell = t('Pending'); + $action_cell = l("Delete invitation",'invite/delete/'.urlencode($invite->email)); + } + } + else { + $account = user_load(array('mail' => $invite->email)); + $email_cell = isset($account->uid) ? l($invite->email, 'user/'.$account->uid) : "{$invite->email}"; + $status_cell = t('Joined'); + $action_cell = (variable_get('invite_allow_join_delete', 0) && isset($account->uid)) ? l("Delete invitation",'invite/delete/'.urlencode($invite->email)) : ' '; + } + $items[] = array($email_cell, $status_cell, $action_cell); $inc++; } if (count($items) > 0) { - $headers = array(t('Email'), t('Status'), ''); + $headers = array(t('Email'), t('Status'), ' '); $table = theme('table', $headers, $items, array('id' => 'invite_table')); } else { @@ -430,7 +455,7 @@ function invite_page(){ '#value' => t('Submit'), ); } else { - drupal_set_message(t('Maximum number (%max) of invitations reached', array('%max' => $maximum_invites))); + drupal_set_message(t('Maximum number (%max) of invitations reached.', array('%max' => $maximum_invites))); } $output .= drupal_get_form('invite_form', $form); @@ -461,7 +486,7 @@ function invite_delete($email) { $email = urldecode($email); if ($email){ db_query("DELETE from {invite} WHERE email = '%s'",$email); - drupal_set_message("Invitation to $email has been deleted"); + drupal_set_message(t('Invitation to %email has been deleted.', array('%email' => $email))); $args = array('email' => $email); module_invoke_all('invite', 'cancel', $args); drupal_goto('invite'); @@ -481,7 +506,7 @@ function _invite_check_invited($email, $ $result = db_query('SELECT * FROM {invite}'); while ($t = db_fetch_object($result)) { if ($t->email == $email){ - drupal_set_message("The user you are trying to invite has already been invited"); + drupal_set_message(t('The user you are trying to invite has already been invited')); $already_invited = 0; } } @@ -492,7 +517,7 @@ function _invite_check_invited($email, $ $result = db_query("SELECT COUNT(*) from {invite} WHERE uid = %d", $uid); if (db_result($result) >= $maximum_invites){ - drupal_set_message("You have exceeded your allowed invitations"); + drupal_set_message(t('You have exceeded your allowed invitations')); $already_invited = 0; } } @@ -551,7 +576,11 @@ function _invite_check_msgs($uid){ } function _invite_create_regcode(){ - return substr(md5(rand()), 0, 8); + do { + $reg_code = substr(md5((string)rand(). date('YmdHis', time())), 0, 8); + $r = db_query('SELECT COUNT(*) FROM {invite} WHERE reg_code = "%s"', $reg_code); + } while ((int)db_result($result) > 0); + return $reg_code; } function _invite_send_invite($op, $user_name = "[username]", $email ="[recipient-email]", $code = "registration-code", $message = '[your message]'){ global $base_url, $user; @@ -626,7 +655,7 @@ _MAIL_; function _invite_unblock($uid) { - if (ctype_digit($uid)) { + if (is_numeric($uid)) { db_query("UPDATE {users} SET status = 1 WHERE uid = %d", $uid); return TRUE; } Index: invite.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/invite/invite.install,v retrieving revision 1.2.2.2 diff -u -p -r1.2.2.2 invite.install --- invite.install 9 Sep 2006 13:06:48 -0000 1.2.2.2 +++ invite.install 28 Nov 2006 01:22:33 -0000 @@ -8,10 +8,10 @@ function invite_install() { switch ($GLOBALS['db_type']) { case 'mysql': case 'mysqli': - $result = db_query(" + $result1 = db_query(" CREATE TABLE {invite} ( email varchar(64) NOT NULL default '', - reg_code varchar(64) NOT NULL default '', + reg_code varchar(64) UNIQUE NOT NULL, uid int(10) unsigned NOT NULL default '0', mid int(11) unsigned NOT NULL default '0', expiry int(11) NOT NULL default '0', @@ -20,8 +20,9 @@ function invite_install() { PRIMARY KEY (email) ) /*!40100 DEFAULT CHARACTER SET utf8 */;" ); + $result2 = db_query("CREATE INDEX reg_code_idx ON {invite} (reg_code)"); - if ($result) { + if ($result1 && $result2) { drupal_set_message(t('The database schema for the invite module has been successfully updated')); } else { @@ -30,3 +31,14 @@ function invite_install() { break; } } + +function invite_update_1() { + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $items[] = update_sql("ALTER TABLE {invite} CHANGE reg_code reg_code VARCHAR(64) UNIQUE NOT NULL"); + db_query("CREATE INDEX reg_code_idx ON {invite} (reg_code)"); + break; + } + return $items; +}