Index: modules/invite/invite.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/invite/invite.module,v
retrieving revision 1.4.2.3
diff -u -r1.4.2.3 invite.module
--- modules/invite/invite.module	20 Mar 2006 15:17:58 -0000	1.4.2.3
+++ modules/invite/invite.module	6 May 2006 02:26:23 -0000
@@ -158,6 +158,11 @@
                  'callback' => 'invite_page',
                    'access' => user_access('send invitations'),
                      'type' => MENU_SUGGESTED_ITEM);
+
+    $items[] = array('path' => 'invite/delete', 
+                 'callback' => 'invite_delete',
+                   'access' => user_access('send invitations'),
+                     'type' => MENU_CALLBACK);
   }
   return $items;
 }
@@ -234,104 +239,104 @@
 
 function invite_page(){
   global $user;
+  //this displays all invites for a user, and counts how many invites they have left to give
+  $form['invitations'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Your invitations'),
+  );
+
+  $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 ? "Joined" : "Pending"),$invite->timestamp ? "delete" : l("delete",'invite/delete/'.urlencode($invite->email)));
+    $inc++;
+  }
+  
+  if (count($items) > 0) {
+    $headers = array(t('Email'), t('Status'), '');
+    $table = theme('table', $headers, $items);
+  }
+  else {
+  	$table = t('You have not sent any invitations yet.');
+  }
+  $form['invitations']['table'] = array(
+    '#type' => 'markup',
+    '#value' => $table,
+  );
+  
+  $form['invite_form'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Invite a friend'),
+  );      
+  
+  $maximum_invites = _invite_check_remaining_invites($user);
+  if ($maximum_invites > 0) {
+    $invites_left =  $maximum_invites - $inc;
+    $form['invite_form']['remaining_invites'] = array(
+      '#type' => 'markup',
+      '#value' => t('You have %invites invites left', array('%invites' => $invites_left)),
+    );
+  }
   
-  // collect post data
-  $edit = $_POST['edit'];
-  $op = $_POST['op'] ? $_POST['op'] : arg(1);
+  //the invitation form
+  if ($inc < $maximum_invites  || $maximum_invites == 0){
+    $form['invite_form']['email'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Email'),
+      '#default_value' => '',
+      '#size' => 20,
+      '#maxlength' => 64,
+      '#description' => t('Type the email of the person you would like to invite'),
+      '#required' => TRUE,
+    );
+    $form['invite_form']['message'] = array(
+      '#type' => 'textarea',
+      '#title' => t('Your message'),
+      '#default_value' => '',
+      '#required' => FALSE,
+      '#description' => t('This message will be added to the mail sent to the person you are inviting.'),
+    );        
+    $form['invite_form']['submit'] = array(
+      '#type' => 'submit',
+      '#value' => t('Submit'),
+    );
+  } else {
+    drupal_set_message(t('Maximum number (%max) of invitations reached', array('%max' => $maximum_invites)));
+  }
 
-  switch ($op){
-    case t('Submit'):
-  //parse the form
-     // validate the form
-     if ( _invite_check_invited($edit["email"], $user->uid) && valid_email_address($edit["email"])){
-       // 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));  
-       }
-     } else {
-       form_set_error("invite_email", t('Email address is not valid!'));
-     }
-    case "delete":
-       //delete an invite from the table
-       if ($email = arg(2)){ 
-         db_query("DELETE from {invite} WHERE email = '%s'",$email);
-         drupal_set_message("Invitation to $email has been deleted");
-         $args = array('email' => $email);
-         module_invoke_all('invite', 'cancel', $args);
-         drupal_goto('invite');
-       }
-    default:
-      //this displays all invites for a user, and counts how many invites they have left to give
-      $form['invitations'] = array(
-        '#type' => 'fieldset',
-        '#title' => t('Your invitations'),
-      );
-
-      $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 ? "Joined" : "Pending"),$invite->timestamp ? "delete" : l("delete",'invite/delete/'.$invite->email));
-        $inc++;
-      }
-      
-      if (count($items) > 0) {
-        $headers = array(t('Email'), t('Status'), '');
-        $table = theme('table', $headers, $items);
-      }
-      else {
-      	$table = t('You have not sent any invitations yet.');
-      }
-      $form['invitations']['table'] = array(
-        '#type' => 'markup',
-        '#value' => $table,
-      );
-      
-      $form['invite_form'] = array(
-        '#type' => 'fieldset',
-        '#title' => t('Invite a friend'),
-      );      
-      
-      $maximum_invites = _invite_check_remaining_invites($user);
-      if ($maximum_invites > 0) {
-        $invites_left =  $maximum_invites - $inc;
-        $form['invite_form']['remaining_invites'] = array(
-          '#type' => 'markup',
-          '#value' => t('You have %invites invites left', array('%invites' => $invites_left)),
-        );
-      }
-      
-      //the invitation form
-      if ($inc < $maximum_invites  || $maximum_invites == 0){
-        $form['invite_form']['email'] = array(
-          '#type' => 'textfield',
-          '#title' => t('Email'),
-          '#default_value' => '',
-          '#size' => 20,
-          '#maxlength' => 64,
-          '#description' => t('Type the email of the person you would like to invite'),
-          '#required' => TRUE,
-        );
-        $form['invite_form']['message'] = array(
-          '#type' => 'textarea',
-          '#title' => t('Your message'),
-          '#default_value' => '',
-          '#required' => FALSE,
-          '#description' => t('This message will be added to the mail sent to the person you are inviting.'),
-        );        
-        $form['invite_form']['submit'] = array(
-          '#type' => 'submit',
-          '#value' => t('Submit'),
-        );
-      } else {
-        drupal_set_message(t('Maximum number (%max) of invitations reached', array('%max' => $maximum_invites)));
-      }
+  $output .= drupal_get_form('invite_form', $form);
+  return $output;
+}
 
-      $output .= drupal_get_form('invite_form', $form);
-      return $output;
-    } 
+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!'));
+  }
+}
+
+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));  
+  }
+}
+
+
+function invite_delete($email) {
+  global $user;
+  $email = urldecode($email);
+  if ($email){
+    db_query("DELETE from {invite} WHERE email = '%s'",$email);
+    drupal_set_message("Invitation to $email has been deleted");
+    $args = array('email' => $email);
+    module_invoke_all('invite', 'cancel', $args);
+    drupal_goto('invite');
+  }
 }
 
 /*
