Index: invite.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/invite/invite.module,v retrieving revision 1.9.2.2 diff -u -r1.9.2.2 invite.module --- invite.module 9 Sep 2006 13:06:48 -0000 1.9.2.2 +++ invite.module 14 Sep 2006 14:22:46 -0000 @@ -232,10 +232,45 @@ 'callback' => 'invite_delete', 'access' => user_access('send invitations'), 'type' => MENU_CALLBACK); + + $items[] = array('path' => 'admin/settings/invite', + 'callback' => 'invite_hook_settings', + 'title' => 'invite', + 'access' => user_access('access administration pages')); } return $items; } +// we use this function name so we can port this easier when hook_settings is deprecated +function invite_hook_settings() { + $form['invite_additional_emails'] = array( + '#type' => 'textfield', + '#title' => t('Number of invitations'), + '#maxlength' => 1, + '#default_value' => variable_get('invite_additional_emails', 1), + '#description' => t('Enter the number of people you would like to allow users to invite on one form submission. Must be numeric and equal to 1 or more.') + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save Settings') + ); + + return drupal_get_form('invite_settings_form', $form); +} + +function invite_settings_form_submit($form_id, $form_values) { + if(!is_numeric($form_values['invite_additional_emails'])) { + form_set_error('invite_additional_emails', t('Please enter a numeric value')); + } + else if ($form_values['invite_additional_emails'] < 1) { + form_set_error('invite_additional_emails', t('Please enter a value greater than or equal to 1')); + } + else { + variable_set('invite_additional_emails', $form_values['invite_additional_emails']); + } +} + /* * Implementation of hook_user * @@ -356,16 +391,26 @@ } //the invitation form - if ($inc < $maximum_invites || $maximum_invites == 0){ - $form['invite_form']['email'] = array( + if ($inc < $maximum_invites || $maximum_invites == 0) { + $form['invite_form']['email'] = array('#tree' => 1); + + $form['invite_form']['email']['email-0'] = array( '#type' => 'textfield', '#title' => t('Email'), - '#default_value' => '', - '#size' => 20, '#maxlength' => 64, + '#size' => 20, '#description' => t('Type the email of the person you would like to invite'), '#required' => TRUE, ); + // add additional email invite fields + for($x=1;$x 'textfield', + '#title' => t('Email'), + '#maxlength' => 64, + '#size' => 20 + ); + } $form['invite_form']['message'] = array( '#type' => 'textarea', '#title' => t('Your message'), @@ -387,19 +432,30 @@ 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!')); + foreach($edit['email'] as $key => $email) { + if ($email) { + if(!valid_email_address($email)) { + form_set_error("email][$key", t('Email address is not valid!')); + } + elseif(!_invite_check_invited($email,$user->uid)) { + form_set_error("email][$key", t('The user you are trying to invite has already been invited')); + } + } } } function invite_form_submit($form_id, $edit) { global $user; - // generate code - $code = _invite_create_regcode(); - //send email - if ($success = _invite_send_invite('mail', $user->name, $edit['email'], $code, $edit['message'])) { - //update database - db_query("INSERT INTO {invite}(email, reg_code, uid, expiry) VALUES ('%s', '%s', %d, %d)",$edit["email"],$code,$user->uid, time()+(variable_get('invite_expiry', 30)*60*60*24)); + foreach($edit['email'] as $email) { + if($email) { + // generate code + $code = _invite_create_regcode(); + //send email + if ($success = _invite_send_invite('mail', $user->name, $email, $code, $edit['message'])) { + //update database + db_query("INSERT INTO {invite}(email, reg_code, uid, expiry) VALUES ('%s', '%s', %d, %d)", $email, $code, $user->uid, time()+(variable_get('invite_expiry', 30)*60*60*24)); + } + } } } @@ -429,7 +485,6 @@ $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; } }