--- og_user_roles.module.5.x-2.6.orig	2007-11-17 16:57:49.000000000 -0800
+++ og_user_roles.module	2007-12-21 00:44:16.000000000 -0800
@@ -1,5 +1,5 @@
 <?php
-// $Id: og_user_roles.module,v 1.1.2.10 2007/11/11 22:43:16 somebodysysop Exp $
+// $Id: og_user_roles.module,v 1.1.2.3 2007/07/08 19:50:44 somebodysysop Exp $
 
 /**
  * @file
@@ -18,9 +18,13 @@ function og_user_roles_help($section) {
 
 /**
  * Implementation of hook_perm().
+ * 
+ * Modification as per: http://drupal.org/node/192747
+ * Added 'administer og_user_roles'
+ *
  */
 function og_user_roles_perm() {
-  return array('configure member roles', 'create og_subgroups');
+  return array('administer og_user_roles', 'configure member roles', 'create og_subgroups');
 }
 
 /**
@@ -277,7 +281,11 @@ function og_user_roles_menu($may_cache) 
       'description' => t('Allows group administrators to add members into group roles.'),
       'callback' => 'drupal_get_form',
       'callback arguments' => 'og_user_roles_admin_settings',
-      'access' => user_access('administer site configuration'),
+/* 
+ * Modification as per: http://drupal.org/node/192747
+ * was: 'access' => user_access('administer site configuration'),
+ */
+      'access' => user_access('administer og_user_roles'),
       'type' => MENU_NORMAL_ITEM
     );
     $items[] = array(
@@ -817,7 +825,8 @@ function og_user_roles_init() {
       $tid = intval(arg(3));
       $gid = og_user_roles_gid_from_tid($tid);
       // Hijack only if there is a gid value;
-      if (!empty($gid)) {
+      // Modificaton as per http://drupal.org/node/194214
+      if (!empty($gid) && $gid != 0) { 
         $path = 'node/ognodeadd';
         $query = 'type='. $type .'&gids[]='. $gid .'&tid='. $tid;
         drupal_goto($path, $query);
@@ -1372,7 +1381,8 @@ function og_user_roles_all_roles($user) 
     // Modified 2007-08-06 for modr8 "modr8" and "ogmodr8" (our own callback);
     // Modified 2007-09-13 for "galleries";
     // Modified 2007-09-14 for "email";
-    if (arg(0) == 'node' && is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'outline' || arg(2) == 'track' || arg(2) == 'results' || arg(2) == 'access' || arg(2) == 'modr8' || arg(2) == 'ogmodr8' || arg(2) == 'delete' || arg(2) == 'galleries' || arg(2) == 'email')) {
+    // Modified 2007-12-20 for "revisions": http://drupal.org/node/202196
+    if (arg(0) == 'node' && is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'outline' || arg(2) == 'track' || arg(2) == 'results' || arg(2) == 'access' || arg(2) == 'modr8' || arg(2) == 'ogmodr8' || arg(2) == 'delete' || arg(2) == 'galleries' || arg(2) == 'email' || arg(2) == 'revisions')) {
       $location = 2;
       $nid = (int)arg(1);	
       $gid = og_user_roles_getgid($nid, $uid);
@@ -1424,7 +1434,7 @@ function og_user_roles_all_roles($user) 
       $nid = $comment->nid;
       $gid = og_user_roles_getgid($nid, $uid);
     }
-
+
     //                           0      1    2
     // http://www.mysite.com/comment/reply/128#comment_form
     if (arg(0) == 'comment' && arg(1) == 'reply') {
@@ -1485,21 +1495,6 @@ function og_user_roles_all_roles($user) 
       }
     }
 
-    // modr8 view modr8_log
-    //          
-    // http://clients.brixrealtyinc.com/node/ogmodr8?gids[]=12&event=2
-    //
-    // Modification as per: http://drupal.org/node/164092
-    //
-    if (arg(0) == 'node' && arg(1) == 'ogmodr8') {
-      // Modification -- Get the gid from the variable instead of trying to calculate it.
-      if (isset($_REQUEST['gids'])) {
-        $location = 131;
-        $gids = $_GET['gids'];
-        $gid = intval(current($_REQUEST['gids']));
-      }
-    }
-
     // og_user_roles
     //
     // http://doadance.scbbs.com/og/users/72/roles
@@ -1541,7 +1536,7 @@ function og_user_roles_all_roles($user) 
     //
     // http://www.centralavedance.com/og_calendar/2973/2007/07/01
     if (arg(0) == 'og_calendar' && is_numeric(arg(1))) {
-      $location = 7;
+      $location = 67;
       $gid = (int)arg(1);
     }
 
@@ -1553,7 +1548,7 @@ function og_user_roles_all_roles($user) 
     // with arg() values.
 
      if (arg(0) == 'og_forum' && is_numeric(arg(2)) && isset($_REQUEST['edit'])) {
-       $location = 8;
+       $location = 68;
        $edit = $_GET['edit'];
        if ($edit[og_groups][0] > 0) {
          $gid = arg(2);
@@ -1563,7 +1558,7 @@ function og_user_roles_all_roles($user) 
     // http://www.mysite.com/forum/39
     // Modification - 2007-07-04.  In the case where this is a forum
     if (arg(0) == 'forum' && is_numeric(arg(1)) && is_null(arg(2))) {
-      $location = 81;
+      $location = 681;
       $tid = (int)arg(1);
       $gid = og_user_roles_gid_from_tid($tid);
       // If no gid returned, then set $gid = 0
@@ -1591,6 +1586,21 @@ function og_user_roles_all_roles($user) 
       $gid = intval(current($_REQUEST['gids']));
     }
 
+    // modr8 view modr8_log
+    //          
+    // http://clients.brixrealtyinc.com/node/ogmodr8?gids[]=12&event=2
+    //
+    // Modification as per: http://drupal.org/node/164092
+    //
+    if (arg(0) == 'node' && arg(1) == 'ogmodr8') {
+      // Modification -- Get the gid from the variable instead of trying to calculate it.
+      if (isset($_REQUEST['gids'])) {
+        $location = 131;
+        $gids = $_GET['gids'];
+        $gid = intval(current($_REQUEST['gids']));
+      }
+    }
+
     // og create nodes (custom node/20 aliased to node/ognodeadd)
     //          0     1   2           3
     // http://clients.brixrealtyinc.com/node/ognodeadd?type=document&gids[]=12
@@ -1643,6 +1653,14 @@ function og_user_roles_all_roles($user) 
       if ($_SESSION['og_last']) $gid = $_SESSION['og_last']->nid;
 	}
 
+    // Agenda module
+    // http://doadance.scbbs.com/node/agenda/list/279
+    if (arg(0) == 'node' && arg(1) == 'agenda' && arg(2) == 'list' && is_numeric(arg(3)) ) {
+      $location = 17;
+      $nid = (int)arg(3);
+      $gid = og_user_roles_getgid($nid, $uid);
+    }
+
    // Modification. As per: http://drupal.org/node/176390
    // Present a hook for other modules: hook_og_user_roles_gid()  
    if ($results = module_invoke_all('og_user_roles_gid')) {
@@ -2119,14 +2137,14 @@ function og_user_roles_user_manage() {
  * stolen from og_forum (had to in the case where og_user_roles user doesn't have latest
  * version of og_forum module which includes this)
  */
-function og_user_roles_gid_from_tid($tid = 0) {
+function og_user_roles_gid_from_tid($tid = 0) {
   // Modification as per: http://drupal.org/node/172923
   if (module_exists('og_forum')) {
-    $sql = "SELECT nid FROM {og_term} WHERE tid = %d";
-    $gid = db_result(db_query($sql, $tid));
-    return $gid;
-  }
-}
+    $sql = "SELECT nid FROM {og_term} WHERE tid = %d";
+    $gid = db_result(db_query($sql, $tid));
+  }
+  return empty($gid) ? 0 : $gid; // As per http://drupal.org/node/194214
+}
 
 /**
  * using the og_vocab tid, get the group id
@@ -2515,7 +2533,7 @@ function og_user_roles_tac_db_rewrite($q
         // Determine if this is a create or edit content process.
         if ($field == 'tid' && $table == 't') {
 		  if (arg(1) == 'add' || arg(1) == 'ognodeadd' || arg(2) == 'edit') { // this will include edits as well
-			$sql = db_query("SELECT t.tid, d.vid, BIT_OR(t.grant_create) AS grant_create FROM {term_access} t INNER JOIN {term_data} d ON t.tid=d.tid LEFT OUTER JOIN {og_term} ot on ot.tid = t.tid WHERE t.rid in ('".implode("','",$rids)."') AND grant_create = 1 and (ot.nid is null OR ot.nid in (".implode("','",$gid)."))	group by t.tid, d.vid"); // only get create term grants in *this* group ($gid IS an array);
+			$sql = db_query("SELECT t.tid, d.vid, BIT_OR(t.grant_create) AS grant_create FROM {term_access} t INNER JOIN {term_data} d ON t.tid=d.tid LEFT OUTER JOIN {og_term} ot on ot.tid = t.tid WHERE t.rid in ('".implode("','",$rids)."') AND grant_create = 1 and (ot.nid is null OR ot.nid in ('".implode("','",$gid)."'))	group by t.tid, d.vid"); // only get create term grants in *this* group ($gid IS an array);
 		  } else {
 			$sql = db_query("SELECT t.tid, d.vid, BIT_OR(t.grant_$op) AS grant_$op FROM {term_access} t INNER JOIN {term_data} d ON t.tid=d.tid WHERE t.rid in ('".implode("','",$rids)."') AND grant_$op = 1 group by t.tid, d.vid");
 		  }
@@ -2663,11 +2681,14 @@ function og_user_roles_theme() {
     $group_node = node_load($gid);
     $custom_theme = $group_node->og_theme;
   }
-  elseif (arg(0) == 'forum' && is_numeric(arg(1))) {
-    $tid = intval(arg(1));
-    $gid = og_user_roles_gid_from_tid($tid);
-    $group_node = node_load($gid);
-    $custom_theme = $group_node->og_theme;
+  // As per: http://drupal.org/node/194214
+  elseif (arg(0) == 'forum' && is_numeric(arg(1))) {
+    $tid = intval(arg(1));
+    $gid = og_user_roles_gid_from_tid($tid);
+    if (!empty($gid)) {
+      $group_node = node_load($gid);
+      $custom_theme = $group_node->og_theme;
+    }
   }
   elseif (arg(0) == 'og_calendar' && is_numeric(arg(1))) {
     $gid = intval(arg(1));
