? buddylist2.patch
? buddylist_api/handlers
Index: buddylist_api/buddylist_api.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/buddylist2/buddylist_api/Attic/buddylist_api.module,v
retrieving revision 1.1.2.4
diff -u -r1.1.2.4 buddylist_api.module
--- buddylist_api/buddylist_api.module	2 Sep 2008 13:16:04 -0000	1.1.2.4
+++ buddylist_api/buddylist_api.module	18 Sep 2008 11:43:12 -0000
@@ -4,7 +4,7 @@
 /**
  * @file
  * buddylist_api module file
- * 
+ *
  * contains core buddylist_api functions to generate social networks
  */
 
@@ -52,7 +52,7 @@
   }
 
   $sql = "SELECT count(*) FROM {buddylist_relations} WHERE requester_id = %d AND requestee_id = %d AND rtid = %d";
- 
+
   if (db_result(db_query($sql, $requester->uid, $requestee->uid, $type->rtid)) == 0) {
     $relationship = (object)array(
       'requester_id'  => $requester->uid,
@@ -60,7 +60,7 @@
       'rtid'          => $type->rtid,
       'init_id'       => $requester->uid,
     );
-    
+
     if($type->oneway) {
       $relationship->state = 1;
     }
@@ -136,7 +136,7 @@
  *
  * @param $par
  *    desc
- * 
+ *
  * @return
  *    relationship object
  *    or
@@ -146,13 +146,16 @@
   $fields['uid'] = 'requester_id';
   $fields['rtid'] = 'rtid';
   $fields['rid'] = 'rid';
-  
-  $query = "SELECT * FROM {buddylist_relations} WHERE ". $fields[$type] ." = %d";
+
+  $what = $count ? "count(*)" : "*";
+  $query = "SELECT ". $what ." FROM {buddylist_relations} WHERE ". $fields[$type] ." = %d";
 
   $result = db_query($query, $value);
 
-  if($type = 'rid') return db_fetch_object($result);
-  
+  if ($type = 'rid') {
+    return db_fetch_object($result);
+  }
+
   if ($count) {
     return (int)db_result($result);
   }
@@ -161,9 +164,9 @@
   while ($relationship = db_fetch_object($result)) {
     $relationships[$relationship->rtid] = $relationship;
   }
-  
+
   _buddylist_api_invoke('load', $relationships);
-  
+
   return $relationships;
 }
 
@@ -171,25 +174,25 @@
 function buddylist_api_load_relationships_between(&$userA, &$userB, $count = FALSE, $active = TRUE) {
    $what = $count ? "count(*)" : "*";
    $query = "SELECT ". $what ." FROM {buddylist_relations} WHERE requester_id = %d AND requestee_id = %d";
-   
+
    if ($active)
      $query.= ' AND state = 1';
    else
      $query.= ' AND state = 0';
-        
+
    $result = db_query($query, $userA->uid, $userB->uid);
-  
+
    if ($count) {
      return (int)(db_result($result));
    }
    $relationships = array();
-  
+
    while ($relationship = db_fetch_object($result)) {
     $relationships[$relationship->rtid] = $relationship;
    }
-  
+
   _buddylist_api_invoke('load', $relationships);
-  
+
   return $relationships;
 }
 
@@ -210,20 +213,21 @@
 function buddylist_api_rtype_load($param = array()) {
   // Get all relationtypes
   $rtypes = buddylist_api_rtypes_load();
-  
+
   // If there are no relationtypes, return null
-  if (!isset($rtypes))
+  if (!isset($rtypes)) {
     return NULL;
-  
+  }
+
   // If param is a number, return that one relationtype
   if (is_numeric($param)) {
     return $rtypes[$param];
   }
-  
+
   // Search through relationtypes and return the first matching
   foreach ($rtypes as $type) {
     $found = TRUE;
-    
+
     foreach($param as $column => $value) {
       $column = strtolower($column);
 
@@ -234,7 +238,7 @@
       else {
         $col_val = $type->$column;
       }
-      
+
       // mismatch, move to the next type
       if ($col_val != $value) {
         $found = FALSE;
@@ -248,26 +252,44 @@
   }
 }
 
+define('BUDDYLIST_API_RELATIONSHIP_TYPE_INACTIVE', 0);
+define('BUDDYLIST_API_RELATIONSHIP_TYPE_ACTIVE', 1);
+
 /**
- * Public API for loading the full list of relationtypes
+ * Public API for loading the full list of relationtypes.
  *
+ * @param $only_actives
+ *   if TRUE, only return those relationship types which are active, otherwise
+ *   return all relationship types.
  * @param $reset
- *    a boolean that forces a reset of the internal static types list
+ *    a boolean that forces a reset of the internal static types list.
  *
  * @return
  *    array of relationtype objects
  */
-function buddylist_api_rtypes_load($reset = NULL) {
-  static $relationtypes_list = array();
-  
-  if ($reset || !sizeof($relationtypes_list)) {
-    $results = db_query("SELECT * FROM {buddylist_relationtypes}");
+function buddylist_api_rtypes_load($rtype_status = NULL, $reset = NULL) {
+  //static $relationtypes_list = array();
+  if (is_null($rtype_status)) {
+    $rtype_status = array();
+  }
+
+  //if ($reset || !sizeof($relationtypes_list)) {
+    if (sizeof($rtype_status) > 0) {
+      $where = ' WHERE';
+      $i = 1;
+      foreach ($rtype_status as $status) {
+        $where .= ' active = %d' . (($i++ < sizeof($rtype_status)) ? ' OR' : '' );
+      }
+    }
+    else {
+      $where = '';
+    }
+    $results = db_query("SELECT * FROM {buddylist_relationtypes}" . $where, $rtype_status);
     while ($relationtype = db_fetch_object($results)) {
+      _buddylist_api_invoke('load_rtype', $relationtype, TRUE);
       $relationtypes_list[$relationtype->rtid] = $relationtype;
     }
-  }
-
-  _buddylist_api_invoke('load', $relationtypes_list, TRUE);
+  //}
 
   return $relationtypes_list;
 }
@@ -279,20 +301,20 @@
  *   A Relationtype object
  */
 function buddylist_api_rtype_save(&$rtype) {
-  _buddylist_api_invoke('presave', $rtype, TRUE);
+  _buddylist_api_invoke('presave_rtype', $rtype, TRUE);
 
   // if a rtid is set, we are in updated process
   // no rtid -> a new relationtype is inserted
   $op = $rtype->rtid ? 'update' : 'insert';
-  
+
   $existing = buddylist_api_rtype_load(array('name' => $rtype->name));
   if ($existing && ($op == 'update' ? $existing->rtid != $rtype->rtid : TRUE)) {
     return FALSE;
   }
-  
+
   drupal_write_record('buddylist_relationtypes', $rtype, ($op == 'update' ? 'rtid' : NULL));
 
-  _buddylist_api_invoke($op, $rtype, TRUE);
+  _buddylist_api_invoke($op .'_rtype', $rtype, TRUE);
 }
 
 /**
@@ -312,8 +334,10 @@
 }
 
 
-function _buddylist_api_invoke($op, $rtype, $is_type = false) {
-   //drupal_set_message("invoke: ".$op);
+function _buddylist_api_invoke($op, &$arg, $is_type = false) {
+  foreach (module_implements('buddylist_' . $op) as $module) {
+    call_user_func($module . '_buddylist_' . $op, $arg, $is_type);
+  }
 }
 
 
@@ -335,4 +359,10 @@
  */
 function buddylist_api_translation() {
   return array();
-}
\ No newline at end of file
+}
+
+function buddylist_api_views_api() {
+  return array(
+    'api' => 2.0,
+  );
+}
Index: buddylist_api/buddylist_api.views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/buddylist2/buddylist_api/Attic/buddylist_api.views.inc,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 buddylist_api.views.inc
--- buddylist_api/buddylist_api.views.inc	2 Sep 2008 13:16:04 -0000	1.1.2.1
+++ buddylist_api/buddylist_api.views.inc	18 Sep 2008 14:15:34 -0000
@@ -3,15 +3,74 @@
 /**
  * @file
  * buddylist_ui.views include file
- * 
+ *
  * contains views functions for buddylist_ui
  */
 
 
 function buddylist_api_views_data() {
   $data = array();
-  
-  
+
+  $data['buddylist_relations'] = array(
+    'table' => array(
+      'group' => t('Buddylist'),
+      // Define the joins:
+      'join' => array(
+        'users' => array(
+          'left_field' => 'uid',
+          'field' => 'requestee_id',
+        ),
+      ),
+    ),
+
+    'requester_id' => array(
+      'filter' => array(
+        'handler' => 'views_handler_filter_user_current',
+        'title' => t('Current User\'s Buddies'),
+        'help' => t('Restrict to the buddies of the currently logged in user'),
+      ),
+    ),
+
+    'state' => array(
+      'filter' => array(
+        'title' => t('Relation State'),
+        'help' => t('Has the relationship been accepted, or is it awaiting confirmation'),
+        'handler' => 'views_handler_filter_buddylist_relation_state',
+      ),
+    ),
+
+  );
+
+  $data['buddylist_relationtypes'] = array(
+    'table' => array(
+      'group' => t('Buddylist'),
+      'join' => array(
+        'users' => array(
+          'left_table' => 'buddylist_relations',
+          'left_field' => 'rtid',
+          'field' => 'rtid',
+        ),
+      ),
+    ),
+    'name' => array(
+      'title' => t('Relation Type'),
+      'help' => t('The type of the relation that links two users.'),
+      'field' => array(
+        'handler' => 'views_handler_field_xss',
+      ),
+      'sort' => array(
+        'handler' => 'views_handler_sort',
+      ),
+
+    ),
+    'rtid' => array(
+      'filter' => array(
+        'handler' => 'views_handler_filter_buddylist_relation_type',
+        'title' => t('Relation Type'),
+        'help' => t('The type of the relation that links two users.'),
+      ),
+    ),
+  );
   return $data;
 }
 
@@ -20,4 +79,20 @@
  $views = array();
  // $views[$view->name] = $view;
  return $views;
-}
\ No newline at end of file
+}
+
+function buddylist_api_views_handlers() {
+  return array(
+    'info' => array(
+      'path' => drupal_get_path('module', 'buddylist_api') . '/handlers',
+    ),
+    'handlers' => array(
+      'views_handler_filter_buddylist_relation_type' => array(
+        'parent' => 'views_handler_filter_in_operator',
+      ),
+      'views_handler_filter_buddylist_relation_state' => array(
+        'parent' => 'views_handler_filter_in_operator',
+      ),
+    ),
+  );
+}
Index: buddylist_ui/buddylist_ui.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/buddylist2/buddylist_ui/Attic/buddylist_ui.admin.inc,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 buddylist_ui.admin.inc
--- buddylist_ui/buddylist_ui.admin.inc	2 Sep 2008 13:16:04 -0000	1.1.2.2
+++ buddylist_ui/buddylist_ui.admin.inc	18 Sep 2008 10:39:29 -0000
@@ -3,7 +3,7 @@
 /**
  * @file
  * buddylist_ui.admin include file
- * 
+ *
  * contains functions for admin area
  */
 
@@ -12,15 +12,15 @@
  */
 function buddylist_ui_admin_overview() {
   $form = array();
-  
+
   //active relationtypes
   $form['active'] = array('#value' => '<h2>'. t('Active relationtypes'). '</h2>');
-  $form['active_table'] = buddylist_ui_admin_get_rtypes(1);
-  
+  $form['active_table'] = buddylist_ui_admin_get_rtypes(BUDDYLIST_API_RELATIONSHIP_TYPE_ACTIVE);
+
   //inactive relationtypes
   $form['inactive'] = array('#value' => '<h2>'. t('Inactive relationtypes'). '</h2>');
-  $form['inactive_table'] = buddylist_ui_admin_get_rtypes(0);
-  
+  $form['inactive_table'] = buddylist_ui_admin_get_rtypes(BUDDYLIST_API_RELATIONSHIP_TYPE_INACTIVE);
+
   return $form;
 }
 
@@ -31,32 +31,32 @@
   // load all types
   $rtypes = buddylist_api_rtypes_load();
   $final_types = array();
-  
+
   foreach($rtypes as $rtype) {
     // only add to table if the state matches
     if ($rtype->active == $active_state) {
       $path = 'admin/buddylist/rtypes/'. $rtype->rtid;
-      $id = $rtype->rtid;     
-      
-      $ops = array();  
+      $id = $rtype->rtid;
+
+      $ops = array();
       $ops[] = l(t('edit'), $path .'/edit');
       $ops[] = l(t('delete'), $path .'/delete');
-      
+
       $final_types[$id] = (array)$rtype;
-      $final_types[$id]['oneway'] = ($final_types[$id]['oneway'] == 1) ? t('Yes') : t('No'); 
-      $final_types[$id]['backrelation'] = ($final_types[$id]['backrelation'] == 1) ? t('Yes') : t('No');    
+      $final_types[$id]['oneway'] = ($final_types[$id]['oneway'] == 1) ? t('Yes') : t('No');
+      $final_types[$id]['backrelation'] = ($final_types[$id]['backrelation'] == 1) ? t('Yes') : t('No');
       $final_types[$id][] = implode(' ', $ops);
-      
+
       // do not show if its active
-      unset($final_types[$id]['active']); 
+      unset($final_types[$id]['active']);
     }
   }
-  
+
   // no relationtypes found
   if (!count($final_types)) {
     return array('#value' => '<p>'. t('None') .'</p>');
   }
- 
+
   $header = array(t('Relation ID'), t('Machine Readable Name'), t('Name'), t('Oneway'), t('Free Backrelation'), t('Operations'));
   return array('#value' => theme('table', $header, $final_types));
 }
@@ -64,9 +64,9 @@
 /**
  * Returns the form for editing/adding a rtype
  */
-function buddylist_ui_admin_form_edit(&$form_state, $rtype = NULL) { 
+function buddylist_ui_admin_form_edit(&$form_state, $rtype = NULL) {
   $form = array();
-  
+
   $form['name'] = array(
     '#type'           => 'textfield',
     '#title'          => t('Name'),
@@ -74,19 +74,19 @@
     '#default_value'  => $rtype->name,
     '#description'    => t("Example: buddy, friend, colleague."),
     '#required'       => TRUE,
-  );  
+  );
   $form['oneway'] = array(
     '#type'           => 'checkbox',
     '#title'          => t('This is a oneway relationship'),
     '#default_value'  => $rtype->oneway,
     '#description'    => t('Check this if this relationship should only go one way (Example: Fan, Subscriber)'),
-  );  
+  );
   $form['backrelation'] = array(
     '#type'           => 'checkbox',
     '#title'          => t('Free Backrealation'),
     '#default_value'  => $rtype->backrelation,
     '#description'    => t('...'),
-  ); 
+  );
   $form['active'] = array(
     '#type'           => 'checkbox',
     '#title'          => t('Relationtype is active'),
@@ -97,35 +97,35 @@
     '#type'           => 'submit',
     '#value'          => 'Save',
   );
-  
+
   // extra for edit process
   if($rtype != NULL ) {
     $form['rtid'] = array(
       '#type'           => 'hidden',
-      '#default_value'  => $rtype->rtid, 
-    );    
+      '#default_value'  => $rtype->rtid,
+    );
   }
-  
+
   return $form;
 }
 
 /**
  * Submit function for edit/delete a relationtype
  */
-function buddylist_ui_admin_form_edit_submit($form, &$form_state) { 
+function buddylist_ui_admin_form_edit_submit($form, &$form_state) {
   $res = new stdClass();
   foreach(array('name', 'oneway', 'backrelation', 'active', 'rtid') as $key) {
     $res->{$key} = $form_state['values'][$key];
   }
-  
+
   if(is_numeric($res->rtid))
     drupal_set_message(t('Relation type has been updated'));
   else {
     drupal_set_message(t('Relation type has been saved'));
   }
-  
+
   buddylist_api_rtype_save($res);
-  
+
   $form_state['redirect'] = 'admin/buddylist/rtypes';
 }
 
@@ -133,13 +133,13 @@
 /**
  * Returns the form for deleting a rtype
  */
-function buddylist_ui_admin_form_delete(&$form_state, $rtid = NULL) { 
+function buddylist_ui_admin_form_delete(&$form_state, $rtid = NULL) {
   if ($rtid) {
     $form['rtid'] = array(
       '#type'   => 'value',
       '#value'  => (int)$rtid->rtid,
     );
-    
+
     return confirm_form(
       $form,
       t('Are you sure you want to delete %name?', array('%name' => $rtid->name)),
@@ -162,4 +162,4 @@
   buddylist_api_rtype_delete($rtype);
   drupal_set_message(t('Relationship has been deleted.'));
   $form_state['redirect'] = 'admin/buddylist/rtypes';
-}
\ No newline at end of file
+}
Index: buddylist_ui/buddylist_ui.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/buddylist2/buddylist_ui/Attic/buddylist_ui.module,v
retrieving revision 1.6.2.4
diff -u -r1.6.2.4 buddylist_ui.module
--- buddylist_ui/buddylist_ui.module	2 Sep 2008 13:16:04 -0000	1.6.2.4
+++ buddylist_ui/buddylist_ui.module	18 Sep 2008 13:32:13 -0000
@@ -4,7 +4,7 @@
 /**
  * @file
  * buddylist_ui module file
- * 
+ *
  * contains core buddylist_ui functions to generate social networks
  */
 
@@ -13,14 +13,14 @@
 
 /**
  * HOOKS
- */ 
+ */
 
 /**
  * Implementation of hook_menu().
  */
 function buddylist_ui_menu() {
   $items = array();
-  
+
   /*
    * Buddy action links
    */
@@ -64,7 +64,7 @@
     'page arguments' => array('buddylist_ui_accept_request_form', 2, 3),
     'type' => MENU_CALLBACK,
   );
-  
+
   /*
    * Admin Items
    */
@@ -127,26 +127,26 @@
  * Implementation of hook_user()
  */
 function buddylist_ui_user($op, &$edit, &$account, $category = NULL) {
-  
+
   switch($op) {
-    case 'view': 
+    case 'view':
       global $user;
       $viewer =&$user;
-   
+
       if ($account->uid == $viewer->uid) {
         break;
       }
-   
+
       $output = array();
-    
+
       if ($actions = buddylist_ui_actions($viewer, $account)) {
         $output['actions'] = array(
           '#title'      => t('Buddylist actions'),
           '#type'       => 'user_profile_item',
           '#value'      => theme('item_list', $actions),
         );
-      }  
-      
+      }
+
       if ($relations = buddylist_ui_relations($viewer, $account)) {
         $output['relation'] = array(
           '#title'      => t('Your relations to this user'),
@@ -161,7 +161,7 @@
           '#type'       => 'user_profile_item',
           '#value'      => theme('item_list', $pending),
         );
-      }  
+      }
 
       if(sizeof($output)) {
         $account->content['buddylist_ui'] = array(
@@ -170,20 +170,20 @@
         );
         $account->content['buddylist_ui'] = array_merge($account->content['buddylist_ui'], $output);
       }
-    break;  
+    break;
   }
 }
 
 function buddylist_ui_pending_relations(&$viewer, &$viewed) {
-  $relations = buddylist_api_load_relationships_between($viewer, $viewed, FALSE, FALSE); 
+  $relations = buddylist_api_load_relationships_between($viewer, $viewed, FALSE, FALSE);
   $output = array();
-  
+
   foreach($relations as $relation) {
     $rtype = buddylist_api_rtype_load($relation->rtid);
 
     if ($viewer->uid == $relation->init_id)
       $output[] = $rtype->name .': '. l(t('Cancel Request'), 'buddylist/cancel/'. $viewed->uid .'/'. $relation->rid, array('query' => drupal_get_destination()));
-    else 
+    else
       $output[] = $rtype->name .': '. l(t('Accept Request'), 'buddylist/accept/'. $viewed->uid .'/'. $relation->rid, array('query' => drupal_get_destination())) .' | '. l(t('Deny Request'), 'buddylist/deny/'. $viewed->uid .'/'. $relation->rid, array('query' => drupal_get_destination()));
   }
 
@@ -193,7 +193,7 @@
 function buddylist_ui_relations(&$viewer, &$viewed) {
   $relations = buddylist_api_load_relationships_between($viewer, $viewed);
   $output = array();
-  
+
   foreach($relations as $relation) {
     $rtype = buddylist_api_rtype_load($relation->rtid);
     $output[] = $rtype->name .': '. l(t('Delete'), 'buddylist/delete/'. $viewed->uid .'/'. $relation->rid, array('query' => drupal_get_destination()));
@@ -202,13 +202,13 @@
   return $output;
 }
 
-function buddylist_ui_actions(&$viewer, &$viewed) {  
-  $output = array();   
+function buddylist_ui_actions(&$viewer, &$viewed) {
+  $output = array();
 
-  $count_rtypes = sizeof(buddylist_api_rtypes_load());
+  $count_rtypes = sizeof(buddylist_api_rtypes_load(array(BUDDYLIST_API_RELATIONSHIP_TYPE_ACTIVE)));
   if(buddylist_api_load_relationships_between($viewer, $viewed, TRUE) < $count_rtypes)
     $output[] = l(t('Add a relation'), 'buddylist/add/'. $viewed->uid, array('query' => drupal_get_destination()));
- 
+
   return $output;
 }
 
@@ -273,25 +273,22 @@
 
 function buddylist_ui_add_form($form_state, $account) {
   global $user;
-  $count_rtypes = sizeof(buddylist_api_rtypes_load());
+  $active_rtypes = buddylist_api_rtypes_load(array(BUDDYLIST_API_RELATIONSHIP_TYPE_ACTIVE));
+  $count_rtypes = sizeof($active_rtypes);
 
   if ($user->uid == $account->uid) {
     drupal_set_message(t('Cannot add yourself to buddylist'));
-  } elseif (buddylist_api_load_relationships_between($user, $account, TRUE) == $count_rtypes) {
-    drupal_set_message(t('You have allready all possible buddy connections with this user'));
+  } elseif (buddylist_api_load_relationships_between($user, $account, TRUE) >= $count_rtypes) {
+    drupal_set_message(t('You have already all possible buddy connections with this user'));
   } else {
-	  $current_relationships = buddylist_api_load_relationships_between($user, $account);	
+	  $current_relationships = array_keys(buddylist_api_load_relationships_between($user, $account));
+
+      foreach ($active_rtypes as $rtype) {
+        if (!in_array($rtype->rtid, $current_relationships)) {
+          $relationships[$rtype->rtid] = $rtype->name;
+        }
+      }
 
-	  $results = db_query(
-	    "SELECT * FROM {buddylist_relationtypes}" . ($current_relationships ? " WHERE rtid NOT IN (%s) ORDER BY name" : ''),
-	    implode(',', array_keys($current_relationships))
-	  );
-	    
-	  $relationships = array();
-	  while($result = db_fetch_object($results)) {
-	    $relationships[$result->rtid] = $result->name;
-	  }
-	
 	  $form['rtid'] = array(
 	    '#title'          => t('Relationship'),
 	    '#type'           => 'select',
@@ -306,9 +303,9 @@
 	    '#type'   => 'value',
 	    '#value'  => $account
 	  );
-	
-      $output = confirm_form($form, t('Add user to your buddylist?'), $_GET['destination'], NULL, t('Add'), t('Cancel'));
-      
+
+      $output = confirm_form($form, t('Add user to your buddylist?'), $_GET['destination'], '', t('Add'), t('Cancel'));
+
 	  return $output;
   }
 }
@@ -320,7 +317,7 @@
   $requester          = $form_state['values']['requester'];
   $requestee          = $form_state['values']['requestee'];
   $relationship_type  = buddylist_api_rtype_load($form_state['values']['rtid']);
- 
+
   $relationship = buddylist_api_request_relationship($requester, $requestee, $relationship_type);
 
   if ($relationship === FALSE) {
@@ -339,11 +336,11 @@
 
 function buddylist_ui_delete_form($form_state, $account, $relationship) {
   global $user;
-  
+
   if (buddylist_api_load_relationships_between($user, $account, TRUE) == 0) {
     drupal_set_message(t('You have no relationships to this user'));
   } else {
-      
+
       $form['rid'] = array(
 	    '#type' => 'value',
         '#value' => $relationship->rid,
@@ -367,11 +364,11 @@
 
 function buddylist_ui_cancel_request_form($form_state, $account, $relationship) {
   global $user;
-  
+
   if (buddylist_api_load_relationships_between($user, $account, TRUE, FALSE ) == 0) {
     drupal_set_message(t('You have no pending relationship with this user'));
   } else {
-      
+
       $form['rid'] = array(
 	    '#type' => 'value',
         '#value' => $relationship->rid,
@@ -381,7 +378,7 @@
         '#value' => $user
       );
       $rtype = buddylist_api_rtype_load($relationship->rtid);
-      $output = confirm_form($form, t('Remove relation-request %relation to %username?', array('%relation' => $rtype->name, '%username' => $account->name)), $_GET['destination'], NULL, t('Delete'), t('Cancel'));
+      $output = confirm_form($form, t('Remove relation-request %relation to %username?', array('%relation' => $rtype->name, '%username' => $account->name)), $_GET['destination'], '', t('Remove'), t('Cancel'));
       return $output;
   }
 }
@@ -395,11 +392,11 @@
 
 function buddylist_ui_deny_request_form($form_state, $account, $relationship) {
   global $user;
-  
+
   if (buddylist_api_load_relationships_between($account, $user, TRUE, FALSE ) == 0) {
     drupal_set_message(t('You have no pending relationship with this user'));
   } else {
-      
+
       $form['rid'] = array(
 	    '#type' => 'value',
         '#value' => $relationship->rid,
@@ -423,11 +420,11 @@
 
 function buddylist_ui_accept_request_form($form_state, $account, $relationship) {
   global $user;
-  
+
   if (buddylist_api_load_relationships_between($account, $user, TRUE, FALSE ) == 0) {
     drupal_set_message(t('You have no pending relationship with this user'));
   } else {
-      
+
       $form['rid'] = array(
 	    '#type' => 'value',
         '#value' => $relationship->rid,
@@ -436,24 +433,24 @@
         '#type' => 'value',
         '#value' => $user
       );
-            
+
       $rtype = buddylist_api_rtype_load($relationship->rtid);
-      
-      drupal_set_message(print_r($rtype, TRUE));
-      
+
+      //drupal_set_message(print_r($rtype, TRUE));
+
       if($rtype->backrelation) {
-        $current_relationships = buddylist_api_load_relationships_between($user, $account);	
+        $current_relationships = buddylist_api_load_relationships_between($user, $account);
 
 	    $results = db_query(
 	      "SELECT * FROM {buddylist_relationtypes}" . ($current_relationships ? " WHERE rtid NOT IN (%s) AND oneway = 0 ORDER BY name" : ' WHERE oneway = 0'),
 	      implode(',', array_keys($current_relationships))
 	    );
-	    
+
 	    $relationships = array();
 	    while($result = db_fetch_object($results)) {
 	      $relationships[$result->rtid] = $result->name;
 	    }
-        
+
         $form['rtid'] = array(
 	      '#title'          => t('Relationship'),
 	      '#type'           => 'select',
@@ -461,7 +458,7 @@
 	      '#default_value'  => $form_state['rtid'],
 	    );
       }
-      
+
       $output = confirm_form($form, t('Accept relation-request %relation from %username?', array('%relation' => $rtype->name, '%username' => $account->name)), $_GET['destination'], NULL, t('Accept'), t('Cancel'));
       return $output;
   }
@@ -473,4 +470,4 @@
   buddylist_api_save_relationship($relation, 'accept');
 
   $form_state['redirect'] = $_GET['destination'];
-}
\ No newline at end of file
+}
--- buddylist_api/handlers/views_handler_filter_buddylist_relation_state.inc
+++ buddylist_api/handlers/views_handler_filter_buddylist_relation_state.inc
@@ -0,0 +1,14 @@
+<?php
+/**
+ * Filter by relation type
+ */
+class views_handler_filter_buddylist_relation_state extends views_handler_filter_in_operator {
+  function get_value_options() {
+    if (!isset($this->value_options)) {
+      $this->value_title = t('Relation state');
+      $options[0] = t('Not Confirmed');
+      $options[1] = t('Accepted');
+      $this->value_options = $options;
+    }
+  }
+}

--- buddylist_api/handlers/views_handler_filter_buddylist_relation_type.inc
+++ buddylist_api/handlers/views_handler_filter_buddylist_relation_type.inc
@@ -0,0 +1,16 @@
+<?php
+/**
+ * Filter by relation type
+ */
+class views_handler_filter_buddylist_relation_type extends views_handler_filter_in_operator {
+  function get_value_options() {
+    if (!isset($this->value_options)) {
+      $this->value_title = t('Relation type');
+      $types = buddylist_api_rtypes_load();
+      foreach ($types as $type => $info) {
+        $options[$info->rtid] = $info->name;
+      }
+      $this->value_options = $options;
+    }
+  }
+}

