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 29 Nov 2006 09:08:19 -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); } } @@ -330,16 +337,13 @@ function invite_user($op, &$edit, &$user if ($registration = db_fetch_object($result)) { $targetrole = variable_get('invite_target_role', '2'); _invite_role_escalate($user); - - /* - ** if they sign up as a different email to the one sent to them, they do - ** not get "joined" properly in the invitee's invite screen. - ** this bit fixes that - */ - $userRegMail = $_POST[edit][mail]; - _invite_set_timestamp($userRegMail, $user->uid, $edit['invite_code']); - - _invite_unblock($user->uid); + /* + ** if they sign up as a different email to the one sent to them, they do + ** not get "joined" properly in the invitee's invite screen. + ** this bit fixes that + */ + _invite_set_timestamp($edit['mail'], $user->uid, $edit['invite_code']); + _invite_unblock($user->uid); } else { watchdog('invite', 'User '.$user->name.' registration code failed', $link = NULL); } @@ -377,12 +381,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 +452,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); @@ -439,15 +461,18 @@ function invite_page(){ function invite_form_validate($form_id, &$edit) { global $user; - if (!_invite_check_invited($edit["email"],$user->uid) || !valid_email_address($edit["email"])) { - form_set_error("invite_email", t('Email address is not valid!')); - } + $x = _invite_check_invited($edit['email'], $user->uid); + if (!valid_email_address($edit['email']) || $x['is_invited']) { + form_set_error("invite_email", t($x['message'])); + } } function invite_form_submit($form_id, $edit) { global $user; // generate code $code = _invite_create_regcode(); + $args = array('inviter' => $user); + module_invoke_all('invite', 'invite', $args); //send email if ($success = _invite_send_invite('mail', $user->name, $edit['email'], $code, $edit['message'])) { //update database @@ -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'); @@ -473,32 +498,29 @@ function invite_delete($email) { */ function _invite_check_invited($email, $uid){ - global $user; - - $already_invited = 1; - - //check if the email has already been used to invite someone - $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"); - $already_invited = 0; - } - } - - $maximum_invites = _invite_check_remaining_invites($user); - if ($maximum_invites > 0) { - //check if the user has exceed their allowed invitations - $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"); - $already_invited = 0; - } - } - - return $already_invited; - + global $user; + + $rtn = array('is_invited' => 0, 'message' => ''); + + if ((int)db_result(db_query('SELECT COUNT(*) AS count FROM {invite} WHERE email = "%s"', $email)) > 0) { + $rtn['message'] = 'The user you are trying to invite has already been invited.'; + $rtn['is_invited']++; + return $rtn; + } + + if ((int)db_result(db_query('SELECT COUNT(*) AS count FROM users WHERE mail = "%s"', $email)) > 0) { + $rtn['message'] = 'The user you are trying to invite has already registered.'; + $rtn['is_invited']++; + return $rtn; + } + + if (_invite_check_remaining_invites($user) > 0 && db_result(db_query("SELECT COUNT(*) from {invite} WHERE uid = %d", $uid)) >= $maximum_invites) { + $rtn['message'] = 'You have exceeded your allowed invitations.'; + $rtn['is_invited']++; + return $rtn; + } + + return $rtn; } function _invite_check_remaining_invites($user) { @@ -551,7 +573,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 +652,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 29 Nov 2006 09:08:19 -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; +}