? code_clean_up.patch
Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og_user_roles/README.txt,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 README.txt
--- README.txt	19 Jun 2007 18:18:18 -0000	1.1.2.2
+++ README.txt	5 Jul 2007 08:48:04 -0000
@@ -9,14 +9,14 @@ the group type is allowed to configure r
 admin for the group.
 
 For example, if you created a "trusted user" role, and a new node type
-called "official group," you could allow administrators of only official 
+called "official group," you could allow administrators of only official
 groups to add selected other group members of to the "trusted user" role.
 
 Furthermore, unlike the original og_roles module, this module will restrict
 the role you select for the user to the group.  So, if you have a role called
 "contributor", and you assign that role to a user and group using this module,
 the user will only have the role "contributor" in the specified group, and will
-not have it in any other group unless you specifically add the role to the 
+not have it in any other group unless you specifically add the role to the
 user in that group.
 
 REQUIREMENTS
@@ -33,36 +33,35 @@ INSTALLATION
 - If you are currently running the "OG Roles" module, please uninstall it.  It
   is incompatible with the "OG User Roles" module.
 
-- Enable the module from administer >> modules.  This should create new table 
-  "og_users_roles".  If it doesn't then use the og_users_roles.sql file found 
+- Enable the module from administer >> modules.  This should create new table
+  "og_users_roles".  If it doesn't then use the og_users_roles.sql file found
   in the distribution directory to create it manually.
 
-- Go to administer >> user management >> access control and assign 
-  "configure member roles" to the roles you wish to be able to assign group 
+- Go to administer >> user management >> access control and assign
+  "configure member roles" to the roles you wish to be able to assign group
   roles to users.
 
 - This module uses multi column checkbox settings for display of user roles.
   This saves space, particulary when your group has lots of users.
   To activate, you will need to drop the following code into the style.css
   file of your active theme(s):
-  
-      .checkbox-columns .form-item {
-      font-size:75%;
-      width: 12em;
-      margin-right: 1px;
-      float: left;
-      display: inline;
-    }
-
-    .checkbox-columns-clear .form-item {
-     font-size:75%;
-     width: 12em;
-      margin-right: 1px;
-      clear: left;
-      float: left;
-      display: inline;
-    }
- 
+
+.checkbox-columns .form-item {
+  font-size:75%;
+  width: 12em;
+  margin-right: 1px;
+  float: left;
+  display: inline;
+}
+.checkbox-columns-clear .form-item {
+  font-size:75%;
+  width: 12em;
+  margin-right: 1px;
+  clear: left;
+  float: left;
+  display: inline;
+}
+
 
 SETTINGS
 --------
@@ -71,131 +70,131 @@ Only users with role ('administer site c
 - Go to administer >> Organic groups user roles:
 
   Assignable roles
-  
-  	Check the box next to each role you wish group admins to be able to 
-	manage.  Make sure you have assigned the appropriate privileges to 
-	roles selected here. Note that because these will be assignable by 
-	non-site admins, you should be conservative in what permissions you 
-	give (maybe 'create' permissions on a special node type, etc.)
-
-	Again, whatever roles you select here, when they are assigned to
-	a user in a group, that user will only have the permissions of that
-	role while he is within the context of the group in which he is
-	assigned the role.  When he is outside of that group's context,
-	he will no longer have this role.
+
+    Check the box next to each role you wish group admins to be able to
+  manage.  Make sure you have assigned the appropriate privileges to
+  roles selected here. Note that because these will be assignable by
+  non-site admins, you should be conservative in what permissions you
+  give (maybe 'create' permissions on a special node type, etc.)
+
+  Again, whatever roles you select here, when they are assigned to
+  a user in a group, that user will only have the permissions of that
+  role while he is within the context of the group in which he is
+  assigned the role.  When he is outside of that group's context,
+  he will no longer have this role.
 
   Default Non-Group Role for new users
 
-	If you wish to assign a default site-wide role to every new user that
-	signs up to your web-site, place a check in:
-	
-		"Set default global (site-wide) role for new signups?"
-	
-	and, select the role to which you want all new signups assigned from
-	the pulldown menu:
-	
-		"Selectable roles:"
+  If you wish to assign a default site-wide role to every new user that
+  signs up to your web-site, place a check in:
+
+    "Set default global (site-wide) role for new signups?"
+
+  and, select the role to which you want all new signups assigned from
+  the pulldown menu:
+
+    "Selectable roles:"
 
   Default Basic Group Role for new group subscribers
 
-	If you wish to assign a default group specific role to every new subscriber 
-	to groups on your your web-site, place a check in:
-	
-		"Set default basic group (group limited) role for users who join groups?"
-	
-	and, select the role to which you want all new group subscribers assigned from
-	the pulldown menu:
-	
-		"Selectable roles:"
+  If you wish to assign a default group specific role to every new subscriber
+  to groups on your your web-site, place a check in:
+
+    "Set default basic group (group limited) role for users who join groups?"
+
+  and, select the role to which you want all new group subscribers assigned from
+  the pulldown menu:
+
+    "Selectable roles:"
 
   Default Founder Role for users who create groups
 
-	If you wish to assign a default group specific role to a user who creates
-	a group, then place a check in:
-	
-		"Set default group founder (group limited) role for users who create groups?"
-	
-	and, select the group role to which you want the group "founder" user 
-	assigned from the pulldown:
-	
-		"Role to use as founder role:"
+  If you wish to assign a default group specific role to a user who creates
+  a group, then place a check in:
+
+    "Set default group founder (group limited) role for users who create groups?"
+
+  and, select the group role to which you want the group "founder" user
+  assigned from the pulldown:
+
+    "Role to use as founder role:"
 
   Default Group Admin Notification for new subscribers
 
-	If you wish to automatically send an email notification to the group 
-	administrator when a new subscriber is added to a group, then place
-	a check in:
+  If you wish to automatically send an email notification to the group
+  administrator when a new subscriber is added to a group, then place
+  a check in:
 
-		"Send email notification to group admin when new subscriber 
-		is added to group?"
+    "Send email notification to group admin when new subscriber
+    is added to group?"
 
-	Note that this feature requires mimemail.
+  Note that this feature requires mimemail.
 
   Nodes to automatically place into all available groups
 
-	If you wish to have certain nodes automatically placed into all 
-	available groups each time they are modified, place the comma
-	separated node id numbers into this box:
+  If you wish to have certain nodes automatically placed into all
+  available groups each time they are modified, place the comma
+  separated node id numbers into this box:
 
-		"Nodes to automatically place into all available groups"
+    "Nodes to automatically place into all available groups"
 
-	Note: This is really a specialized customization for my own site.
-	Use it only if you need it.
+  Note: This is really a specialized customization for my own site.
+  Use it only if you need it.
 
   TAC / OG Access Control Integration
 
-	This is a very specialized feature that you should leave unchecked
-	by default. We have been working on an access control project
-	which allows TAC and OG to work in unison.  Basic details of this
-	project are here: http://groups.drupal.org/node/3700
+  This is a very specialized feature that you should leave unchecked
+  by default. We have been working on an access control project
+  which allows TAC and OG to work in unison.  Basic details of this
+  project are here: http://groups.drupal.org/node/3700
 
-	In order to use this feature, you will need a number of patches
-	installed: http://groups.drupal.org/node/4026
+  In order to use this feature, you will need a number of patches
+  installed: http://groups.drupal.org/node/4026
 
-	Again, unless you understand this project and know what you are
-	doing, please leave this unchecked.
+  Again, unless you understand this project and know what you are
+  doing, please leave this unchecked.
 
   Create Subgroups
-  
-  	Allows you to select a group type to use for displaying a 
-  	"Create Subgroup" link on your group menus. Users will need to 
-  	have the "create og_subgroups" permission in order to access this 
-  	link on their group menus. Note that this functionality requires 
-  	the og_subgroups.module
-	
-	To use this, you must first have og_subgroups.module installed.
-	Next, you place a check in this checkbox:
-
-		Create link to "Create Subgroup" in group menu?
-
-	Finally, you select the group type to use for creating subgroups
-	from this pulldown menu:
-	
-		Group type to use for subgroup creation:	
 
-	Don't forget to click on "Save configuration" button to save your choices.
+    Allows you to select a group type to use for displaying a
+    "Create Subgroup" link on your group menus. Users will need to
+    have the "create og_subgroups" permission in order to access this
+    link on their group menus. Note that this functionality requires
+    the og_subgroups.module
+
+  To use this, you must first have og_subgroups.module installed.
+  Next, you place a check in this checkbox:
+
+    Create link to "Create Subgroup" in group menu?
+
+  Finally, you select the group type to use for creating subgroups
+  from this pulldown menu:
+
+    Group type to use for subgroup creation:
+
+  Don't forget to click on "Save configuration" button to save your choices.
 
 USAGE
 -----
 - As a group manager or administrator, go to the Group Home Page. In the
   group navigation menu you should see an link titled:
-  
-  	"# subscribers".  
-  	
+
+    "# subscribers".
+
   Click on this link.  You should next see a menu tab which says:
-  
-  	"Configure member roles"
-  	
+
+    "Configure member roles"
+
   Click on this tab.  You should next see the list of subscribers for this
   group.  Next to each subscriber should be a list of the assignable
-  roles you selected in "SETTINGS" step above. 
-  
-  Check on each role that each user in the group should have, then don't 
+  roles you selected in "SETTINGS" step above.
+
+  Check on each role that each user in the group should have, then don't
   forget to click on the "Save Changes" button at the bottom of the page.
 
   Each user will now have the privileges of the role(s) you have checked
   for him while he is within the context of this group.
-  
+
 NOTES
 -----
 - Please note that these roles and their permissions will only take effect within
@@ -204,44 +203,44 @@ NOTES
 
 - Group Admin.  When a user who is not the group creator is assigned to be a
   "Group Admin" for the group, we have noticed that the "Add subscribers" tab
-  does not appear for this user when "og user roles" is installed.  
+  does not appear for this user when "og user roles" is installed.
   The fix for this is to:
 
-	a.	Create a "GroupAdmin" role in "access control", and give this role the 
-		"edit group content" permission.  
-	b.	Go into "configure member roles" for the group, and give the Group Admin
-		user the "GroupAdmin" role in this group.
+  a.  Create a "GroupAdmin" role in "access control", and give this role the
+    "edit group content" permission.
+  b.  Go into "configure member roles" for the group, and give the Group Admin
+    user the "GroupAdmin" role in this group.
 
 - Noted incompatibility with Auto Assign module.  http://drupal.org/node/149483
   Can't use both modules to assign the same role to users on signup.
 
 - comment 'Done - note to others' by Ricco
 
-	I followed the instructions, and all went smooth as silk. To save others
-	time, here are some notes;
+  I followed the instructions, and all went smooth as silk. To save others
+  time, here are some notes;
 
-	*) you must have the og_forum module installed first. I hadn't, you can
-	find it here; http://drupal.org/project/og_forum [1]
+  *) you must have the og_forum module installed first. I hadn't, you can
+  find it here; http://drupal.org/project/og_forum [1]
 
-	*) it seems that you must disable the og_roles module before you try to
-	enable the og_user_roles module. I hadn't and when I tried to enable the
-	module, i got the happy message;
+  *) it seems that you must disable the og_roles module before you try to
+  enable the og_user_roles module. I hadn't and when I tried to enable the
+  module, i got the happy message;
 
 
-	Fatal error: Cannot redeclare _user_roles() (previously declared in
-	/...mypathinfo.../modules/og_roles/og_roles.module:199) in
-	/...mypathinfo.../modules/og_user_roles/og_user_roles.module on line 244
+  Fatal error: Cannot redeclare _user_roles() (previously declared in
+  /...mypathinfo.../modules/og_roles/og_roles.module:199) in
+  /...mypathinfo.../modules/og_user_roles/og_user_roles.module on line 244
 
 
-	that seems to lock me up for a few seconds... and would not let me even
-	view my site... so use FTP and delete the og_user module (bring it down
-	to your site of course first for backup) and then refresh your browser,
-	and you can get back in, and continue.
+  that seems to lock me up for a few seconds... and would not let me even
+  view my site... so use FTP and delete the og_user module (bring it down
+  to your site of course first for backup) and then refresh your browser,
+  and you can get back in, and continue.
 
 
 CREDITS
 -------
-The original og_roles module was Authored and maintained by Farsheed Hamidi-Toosi and Angela Byron 
+The original og_roles module was Authored and maintained by Farsheed Hamidi-Toosi and Angela Byron
 of CivicSpace Labs Sponsored by Raven Brooks of BuyBlue.org
 
 This version was modified from their original version.
Index: og_user_roles.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og_user_roles/og_user_roles.info,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 og_user_roles.info
--- og_user_roles.info	19 Jun 2007 18:18:18 -0000	1.1.2.2
+++ og_user_roles.info	5 Jul 2007 08:48:04 -0000
@@ -1,9 +1,5 @@
 ; $Id: og_user_roles.info,v 1.1.2.2 2007/06/19 18:18:18 somebodysysop Exp $
 name = "OG User Roles"
-description = "Allows group administrators to add members into Drupal system roles which are restricted to the group.  NOT same as OG Roles module."
-dependencies = og og_forum 
+description = "Allows group administrators to add members into Drupal system roles which are restricted to the group.  NOT same as OG Roles."
+dependencies = og
 package = "Organic groups"
-
-; Information added by drupal.org packaging script on 2007-02-10 (this was added to original og_roles)
-project = "og_user_roles"
-
Index: og_user_roles.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og_user_roles/og_user_roles.install,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 og_user_roles.install
--- og_user_roles.install	10 Jun 2007 22:42:44 -0000	1.1.2.1
+++ og_user_roles.install	5 Jul 2007 08:48:04 -0000
@@ -5,14 +5,14 @@ function og_user_roles_install() {
   switch ($GLOBALS['db_type']) {
     case 'mysql':
     case 'mysqli':
-  
+
       db_query("CREATE TABLE {og_users_roles} (
         uid int(10) unsigned NOT NULL DEFAULT '0',
         rid int(10) unsigned NOT NULL DEFAULT '0',
         gid int(10) unsigned NOT NULL DEFAULT '0',
         PRIMARY KEY  (uid, rid, gid)
       ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
-      
+
     break;
     case 'pgsql':
 
@@ -20,13 +20,12 @@ function og_user_roles_install() {
         uid int(10) unsigned NOT NULL DEFAULT '0',
         rid int(10) unsigned NOT NULL DEFAULT '0',
         gid int(10) unsigned NOT NULL DEFAULT '0',
-        PRIMARY KEY  (uid, rid, gid)
+        PRIMARY KEY  (uid, rid, gid)
+
       );");
-      
+
       break;
   }
-
+
   drupal_set_message(t('og_user_roles module enabled. Please see the included readme.txt file for further installation instructions.'));
 }
-
-
Index: og_user_roles.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og_user_roles/og_user_roles.module,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 og_user_roles.module
--- og_user_roles.module	19 Jun 2007 18:18:18 -0000	1.1.2.2
+++ og_user_roles.module	5 Jul 2007 08:48:05 -0000
@@ -11,132 +11,34 @@
  */
 function og_user_roles_help($section) {
   switch ($section) {
-    case 'admin/og_settings/og_user_roles':
+    case 'admin/og/og_user_roles':
       return '<p>'.t('Allows group administrators to add members into Drupal system roles limited by group.').'</p>';
   }
 }
-
+
 /**
  * Implementation of hook_perm().
  */
 function og_user_roles_perm() {
-  return array(
-    'configure member roles',  
-	'create og_subgroups',
-  );
+  return array('configure member roles', 'create og_subgroups');
 }
-
+
 /**
  * Implementation of hook_access().
  */
 function og_user_roles_access($op, $node) {
-
   global $user;
-
-  if ($op == 'create') {
-    return user_access('create og_subgroups');
-  }
-}
-
-/**
- * Implementation of hook_menu().
- */
-function og_user_roles_menu($may_cache) {
-  global $user;    
 
-  $items = array();
+  if ($op == 'create') {
+    return user_access('create og_subgroups');
+  }
 
-  if (!$may_cache) {    
-
-    $access = $user->uid; // login is required
-    $items[] = array('path' => 'node/ognodeadd', 'type' => MENU_CALLBACK, 'callback' => 'og_user_roles_ognodeadd', 'access' => $access, 'title' => t('Create content'));
-
-    if (! user_access('administer site configuration')) {
-      $user = user_load(array('uid' => $user->uid));       
-
-// Original Code
-//
-// This code causes a "configure member roles" tab to appear for each group the user has
-// admin access to.  Problem is, it appears on "My Groups" page: http://clients.brixrealtyinc.com/og/my
-//
-//      foreach ($user->og_groups as $key => $sub) {
-//        if (og_user_roles_is_allowed($key)) {
-//          $node = node_load(array('nid' => $key));
-	        // Add another tab to the group subscribers page for admins to 
-	        // configure member roles
-//	        $items[] = array(
-//	          'path' => "og/users/$key/roles",
-//	          'callback' => 'og_user_roles_page',
-//	          'title' => t('configure member roles'),
-//	          'callback arguments' => array($key),
-//	          'type' => MENU_LOCAL_TASK,
-//	          'access' => node_access('update', $node),
-//	          'weight' => 5,
-//	        );
-//        }
-//      } // end foreach
-
-// Modification 
-//
-//	This prevents this tab from appearing on "My Groups" page: http://clients.brixrealtyinc.com/og/my
-// 
-//
-      foreach ($user->og_groups as $key => $sub) {
-		  if (arg(0) == 'og' && arg(1) == 'users' && arg(2) == $key) {
-			$key = arg(2);
-    	    if (og_user_roles_is_allowed($key)) {
-	          $node = node_load(array('nid' => $key));
-	    	    // Add another tab to the group subscribers page for admins to 
-		        // configure member roles
-		        $items[] = array(
-	    	      'path' => "og/users/$key/roles",
-		          'callback' => 'og_user_roles_page',
-		          'title' => t('Configure member roles'),
-	        	  'callback arguments' => array($key),
-	    	      'type' => MENU_LOCAL_TASK,
-//		          'access' => node_access('update', $node),
-		          'access' => user_access('configure member roles'),
-		          'weight' => 5,
-	        	);
-        	} // end if
-      	} // end if
-      } // end foreach
-//
-// end modification
-
-    }       
-    else {
-    	// site admin only      
-		  $items[] = array(
-		    'path' => 'admin/og/og_user_roles',
-		    'title' => t('Organic groups user roles'),
-		    'description' => t('Allows group administrators to add members into group roles.'),
-		    'callback' => 'drupal_get_form',
-		    'callback arguments' => 'og_user_roles_settings',
-		    'access' => user_access('administer site configuration'), 
-		    );
-		    
-		    // site admin only, admin will see og_user_roles page on each group page
-		    if ((arg(0) == 'og') && (arg(1) == 'users') && ($gid = arg(2)) && is_numeric($gid) && (og_user_roles_is_allowed($gid))) {		            
-			    $items[] = array(
-				    'path' => "og/users/$gid/roles", 
-			      'callback' => 'og_user_roles_page', 
-		        'title' => t('Configure member roles'), 
-		        'callback arguments' => array($gid), 
-		        'type' => MENU_LOCAL_TASK, 'weight' => 5, 
-		        'access' => user_access('administer site configuration')
-			    );
-		    }
-    }
-  } // end if
-
-  return $items;
 }
 
 /**
  * Implementation of hook_settings().
  */
-function og_user_roles_settings() {
+function og_user_roles_admin_settings() {
 
   // Get list of all og-enabled node types
   $group_types = variable_get('og_node_types', array('og'));
@@ -155,7 +57,7 @@ function og_user_roles_settings() {
   // If no assignable roles, advise user to add some.
   if (!count($roles)) {
     $form['og_user_roles'] = array(
-	  '#value' => '<p>'. t('No assignable roles were found. Please create at least one role under <a href="%access">administer >> access >> roles</a>.', array('%access' => url('admin/access/roles'))) .'</p>',
+    '#value' => '<p>'. t('No assignable roles were found. Please create at least one role under <a href="%access">administer >> access >> roles</a>.', array('%access' => url('admin/access/roles'))) .'</p>',
     );
     return $form;
   }
@@ -164,10 +66,8 @@ function og_user_roles_settings() {
   foreach ($types as $type => $name) {
     $form["og_user_roles_$type"] = array(
       '#type' => 'fieldset',
-//      '#title' => t('%type_name role options', array('%type_name' => theme('placeholder', $name))),
       '#title' => t('%type_name role options', array('%type_name' => $name)),
     );
-
     $form["og_user_roles_$type"]["og_user_roles_roles_$type"] = array(
       '#type' => 'checkboxes',
       '#title' => t('Assignable roles'),
@@ -175,142 +75,177 @@ function og_user_roles_settings() {
       '#default_value' => variable_get("og_user_roles_roles_$type", array()),
     );
   }
-
-    $form["og_user_roles_default"] = array(
+
+    $form['og_user_roles_default'] = array(
       '#type' => 'fieldset',
       '#title' => t('Default Non-Group Role for new users.'),
-   	  '#description' => t('Allows you to select a role to automatically assign to all new signups to your site.'),
+      '#description' => t('Allows you to select a role to automatically assign to all new signups to your site.'),
     );
-
-    $form["og_user_roles_default"]["og_user_roles_assign_default"] = array(
+    $form['og_user_roles_default']['og_user_roles_assign_default'] = array(
       '#type' => 'checkbox',
       '#title' => t('Set default global (site-wide) role for new signups?'),
-      '#default_value' => variable_get("og_user_roles_assign_default", 0),
-   	  '#description' => t('Do you wish to automatically assign all new signups to your web site to a specific role (that is NOT group specific) upon registration?'),
+      '#default_value' => variable_get('og_user_roles_assign_default', 0),
+      '#description' => t('Do you wish to automatically assign all new signups to your web site to a specific role (that is NOT group specific) upon registration?'),
     );
-    $form["og_user_roles_default"]["og_user_roles_default_value"] = array(
+    $form['og_user_roles_default']['og_user_roles_default_value'] = array(
       '#type' => 'select',
       '#title' => t('Selectable roles'),
       '#options' => $roles,
-      '#default_value' => variable_get("og_user_roles_default_value", 0),
+      '#default_value' => variable_get('og_user_roles_default_value', 0),
     );
-
-
-    // ---- Modification - 2007-06-18 - as per: http://drupal.org/node/152442
-    // Added basic group role option for user roles
-    // - bibo
-    $form["og_user_roles_basicgrouprole"] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Default Basic Group Role for new group subscribers.'),
-         '#description' => t('Allows you to select a group role to automatically assign to users who join a group on your site. The role is specific to the group(s) to which the user is subscribing.  That is, the user will only have the privileges of the role in the group he is subscribed to.'),
-    );
-
-    $form["og_user_roles_basicgrouprole"]["og_user_roles_assign_basicgrouprole"] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Set default basic group (group limited) role for users who join groups?'),
-      '#default_value' => variable_get("og_user_roles_assign_basicgrouprole", 0),
-         '#description' => t('Do you wish to automatically assign a specific "basic group role" to <b>every new group subscriber</b> at the time he subscribes to the group? The role is limited to the group that he is subscribed to. This role assignment can be be removed by the groups\' admins'),
-    );
-    $form["og_user_roles_basicgrouprole"]["og_user_roles_basicgrouprole_value"] = array(
-      '#type' => 'select',
-      '#title' => t('Role to use as a basic group role'),
-      '#options' => $roles,
-      '#default_value' => variable_get("og_user_roles_basicgrouprole_value", 0),
-         '#description' => t('Select the role you wish to use as the "basic group role" for every new groupmember.'),
-    );
-    //
-    // --- end of modification
-
-    $form["og_user_roles_founder"] = array(
+
+    $form['og_user_roles_basicgrouprole'] = array(
       '#type' => 'fieldset',
-      '#title' => t('Default Founder Role for users who create groups.'),
-   	  '#description' => t('Allows you to select a group role to automatically assign to users who create groups on your site. The role is specific to the group(s) this user creates.  That is, the user will only have the privileges of the role in the group that he creates.'),
+      '#title' => t('Default Basic Group Role for new group subscribers.'),
+      '#description' => t('Allows you to select a group role to automatically assign to users who join a group on your site. The role is specific to the group(s) to which the user is subscribing.  That is, the user will only have the privileges of the role in the group he is subscribed to.'),
+    );
+    $form['og_user_roles_basicgrouprole']['og_user_roles_assign_basicgrouprole'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Set default basic group (group limited) role for users who join groups?'),
+      '#default_value' => variable_get('og_user_roles_assign_basicgrouprole', 0),
+      '#description' => t('Do you wish to automatically assign a specific "basic group role" to <b>every new group subscriber</b> at the time he subscribes to the group? The role is limited to the group that he is subscribed to. This role assignment can be be removed by the groups\' admins'),
+    );
+    $form['og_user_roles_basicgrouprole']['og_user_roles_basicgrouprole_value'] = array(
+      '#type' => 'select',
+      '#title' => t('Role to use as a basic group role'),
+      '#options' => $roles,
+      '#default_value' => variable_get('og_user_roles_basicgrouprole_value', 0),
+      '#description' => t('Select the role you wish to use as the "basic group role" for every new groupmember.'),
     );
 
-    $form["og_user_roles_founder"]["og_user_roles_assign_founder"] = array(
+    $form['og_user_roles_founder'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Default Founder Role for users who create groups.'),
+      '#description' => t('Allows you to select a group role to automatically assign to users who create groups on your site. The role is specific to the group(s) this user creates.  That is, the user will only have the privileges of the role in the group that he creates.'),
+    );
+    $form['og_user_roles_founder']['og_user_roles_assign_founder'] = array(
       '#type' => 'checkbox',
       '#title' => t('Set default group founder (group limited) role for users who create groups?'),
-      '#default_value' => variable_get("og_user_roles_assign_founder", 0),
-   	  '#description' => t('Do you wish to automatically assign a user who creates a group (e.g. "founder") to a group specific role that is limited to the group that he creates?'),
+      '#default_value' => variable_get('og_user_roles_assign_founder', 0),
+      '#description' => t('Do you wish to automatically assign a user who creates a group (e.g. "founder") to a group specific role that is limited to the group that he creates?'),
     );
-    $form["og_user_roles_founder"]["og_user_roles_founder_value"] = array(
+    $form['og_user_roles_founder']['og_user_roles_founder_value'] = array(
       '#type' => 'select',
       '#title' => t('Role to use as founder role'),
       '#options' => $roles,
-      '#default_value' => variable_get("og_user_roles_founder_value", 0),
-   	  '#description' => t('Select the role you wish to use as the "founder" role.'),
+      '#default_value' => variable_get('og_user_roles_founder_value', 0),
+      '#description' => t('Select the role you wish to use as the "founder" role.'),
     );
-
-    $form["og_user_roles_notify"] = array(
+
+    $form['og_user_roles_notify'] = array(
       '#type' => 'fieldset',
       '#title' => t('Default Group Admin Notification for new subscribers.'),
     );
-    $form["og_user_roles_notify"]["og_user_roles_notify_default"] = array(
+    $form['og_user_roles_notify']['og_user_roles_notify_default'] = array(
       '#type' => 'checkbox',
       '#title' => t('Send email notification to group admin when new subscriber is added to group?'),
-      '#default_value' => variable_get("og_user_roles_notify_default", 0),
-   	  '#description' => t('Do you wish to automatically send an email notification to the group administrator when a new subscriber is added to a group? (Note that this feature requires mimemail to be installed)'),
+      '#default_value' => variable_get('og_user_roles_notify_default', 0),
+      '#description' => t('Do you wish to automatically send an email notification to the group administrator when a new subscriber is added to a group? (Note that this feature requires mimemail to be installed)'),
     );
 
-    $form["og_user_roles_all_groups"] = array(
+    $form['og_user_roles_all_groups'] = array(
       '#type' => 'fieldset',
       '#title' => t('Nodes to automatically place into all available groups.'),
     );
-
-  	$form['og_user_roles_all_groups']['og_user_roles_all_groups_nodes'] = array(
-    	'#type' => 'textarea',
-	    '#title' => t('Nodes to automatically place into all available groups'),
-    	'#default_value' => variable_get('og_user_roles_all_groups_nodes', ''),
-	    '#cols' => 50,
-    	'#rows' => 2,
-	    '#description' => t('Specify here the node IDs of nodes which you want placed into all groups, each
-	    	separated by a comma. Structure your entries like this:
-	      	<p><strong>63,20<br /></strong></p>
-    	  	<p>Each node ID separated by a comma.'),
-  		);
-
-    $form["og_user_roles_tac_og_default"] = array(
+    $form['og_user_roles_all_groups']['og_user_roles_all_groups_nodes'] = array(
+      '#type' => 'textarea',
+      '#title' => t('Nodes to automatically place into all available groups'),
+      '#default_value' => variable_get('og_user_roles_all_groups_nodes', ''),
+      '#cols' => 50,
+      '#rows' => 2,
+      '#description' => t('Specify here the node IDs of nodes which you want placed into all groups, each separated by a comma. Structure your entries like this:
+          <p><strong>63,20<br /></strong></p>
+          <p>Each node ID separated by a comma.'),
+      );
+
+    $form['og_user_roles_tac_og_default'] = array(
       '#type' => 'fieldset',
       '#title' => t('TAC / OG Access Control Integration.'),
     );
-    $form["og_user_roles_tac_og_default"]["og_user_roles_tac_og_value"] = array(
+    $form['og_user_roles_tac_og_default']['og_user_roles_tac_og_value'] = array(
       '#type' => 'checkbox',
       '#title' => t('Integrate TAC and OG Access Control?'),
-      '#default_value' => variable_get("og_user_roles_tac_og_value", 0),
-   	  '#description' => t('Do you have Taxonomy Access installed and do you wish to make its access control work with Organic Groups?  Details here: http://groups.drupal.org/node/3700'),
-    );
-
-    $form["og_user_roles_subgroup"] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Create Subgroups.'),
-   	  '#description' => t('Allows you to select a group type to use for displaying a "Create Subgroup" link on your group menus. Users will need to have the "create og_subgroups" permission in order to access this link on their group menus.
-   	  Note that this functionality requires the og_subgroups.module'),
+      '#default_value' => variable_get('og_user_roles_tac_og_value', 0),
+      '#description' => t('Do you have Taxonomy Access installed and do you wish to make its access control work with Organic Groups?  Details here: http://groups.drupal.org/node/3700'),
     );
-    $form["og_user_roles_subgroup"]["og_user_roles_create_subgroup"] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Create link to "Create Subgroup" in group menu?'),
-      '#default_value' => variable_get("og_user_roles_create_subgroup", 0),
-   	  '#description' => t('Do you wish to have a "Create Subgroup" link appear on the group menu (if the user has the appropriate permissions)?'),
+
+    if (module_exists('og_subgroups')) {
+      $form['og_user_roles_subgroup'] = array(
+        '#type' => 'fieldset',
+        '#title' => t('Create Subgroups.'),
+        '#description' => t('Allows you to select a group type to use for displaying a "Create Subgroup" link on your group menus. Users will need to have the "create og_subgroups" permission in order to access this link on their group menus. Note that this functionality requires the og_subgroups.module'),
+      );
+      $form['og_user_roles_subgroup']['og_user_roles_create_subgroup'] = array(
+        '#type' => 'checkbox',
+        '#title' => t('Create link to "Create Subgroup" in group menu?'),
+        '#default_value' => variable_get('og_user_roles_create_subgroup', 0),
+        '#description' => t('Do you wish to have a "Create Subgroup" link appear on the group menu (if the user has the appropriate permissions)?'),
+      );
+      $form['og_user_roles_subgroup']['og_user_roles_create_subgroup_value'] = array(
+        '#type' => 'select',
+        '#title' => t('Group type to use for subgroup creation'),
+        '#options' => $group_types,
+        '#default_value' => variable_get('og_user_roles_create_subgroup_value', ''),
+        '#description' => t('Select the group type you wish to use for subgroup creation.'),
+      );
+    }
+
+  return system_settings_form($form);
+}
+
+/**
+ * Implementation of hook_menu().
+ */
+function og_user_roles_menu($may_cache) {
+  global $user;
+
+  $items = array();
+
+  if ($may_cache) {
+    $items[] = array(
+      'path' => 'admin/og/og_user_roles',
+      'title' => t('Organic groups user roles'),
+      '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'),
+      'type' => MENU_NORMAL_ITEM
     );
-    $form["og_user_roles_subgroup"]["og_user_roles_create_subgroup_value"] = array(
-      '#type' => 'select',
-      '#title' => t('Group type to use for subgroup creation'),
-      '#options' => $group_types,
-      '#default_value' => variable_get("og_user_roles_create_subgroup_value", ''),
-   	  '#description' => t('Select the group type you wish to use for subgroup creation.'),
+    $items[] = array(
+      'path' => 'node/ognodeadd',
+      'title' => t('Create content'),
+      'callback' => 'og_user_roles_ognodeadd',
+      'access' => $user->uid,
+      'type' => MENU_CALLBACK,
     );
-
-
-  return system_settings_form($form);
+  }
+  else {
+    // Add another tab to the group subscribers page for admins to
+    // configure member roles
+    $gid = arg(2);
+    if (og_user_roles_is_allowed($gid)) {
+      $access = user_access('configure member roles') || user_access('administer site configuration');
+      $items[] = array(
+        'path' => "og/users/$gid/roles",
+        'title' => t('Configure member roles'),
+        'callback' => 'og_user_roles_page',
+        'callback arguments' => array($gid),
+        'access' => user_access('configure member roles'),
+        'weight' => 5,
+        'type' => MENU_LOCAL_TASK,
+      );
+    }
+  }
+
+  return $items;
 }
 
 /**
  * Menu callback; displays members and role selection
  */
 function og_user_roles_page($gid) {
-  $output = '';  
+  $output = '';
   $node = node_load(array('nid' => $gid));
-  
   // Get roles associated with this group. We rebuild the associative
   // array because the settings form only passes RID and we need the name.
   $role_ids = variable_get("og_user_roles_roles_{$node->type}", array());
@@ -323,99 +258,67 @@ function og_user_roles_page($gid) {
 
   if (is_array($roles)) {
     // Retrieve list of all group users
-    $sql = og_list_users_sql(0);   
-    $result = pager_query($sql, 100, 0, NULL, $gid);    
-    $output .= theme('pager',NULL, 100);     
-    $output .= drupal_get_form('og_user_roles_page_form',$gid,$roles,$result);
-  } 
+    $sql = og_list_users_sql(0, 0, 'ou.is_admin DESC, ou.is_active ASC, u.name ASC');
+    $result = pager_query($sql, 100, 0, NULL, $gid);
+    $output .= theme('pager', NULL, 100);
+    $output .= drupal_get_form('og_user_roles_page_form', $gid, $roles, $result);
+  }
   else {
     drupal_set_message(t('No roles have been assigned as group roles yet.'));
   }
-  print theme('page', $output);
+
+  drupal_set_title(t('Subscribers'). ': '. l($node->title, "node/$node->nid"));
+
+  return $output;
 }
 
 /**
  * Form
  */
-function og_user_roles_page_form($gid,$roles,$result) {   
-    $form['user_roles'] = array('#tree' => TRUE); // Make sure form array isn't flattened
-    while ($account = db_fetch_object($result)) {
-      $form['user_roles']['users'][$account->uid] = array(
-        '#type'=>'value',
-        '#value' => $account->uid
-      );
-//
-// Original form
-//
-//      $form['user_roles']['roles'][$account->uid] = array(
-//        '#type' => 'checkboxes',
-//        '#options' => $roles,
-//        '#default_value' => _user_roles($account->uid, $roles),
-//      );
-//
-	//
-	// Modification
-	//
-	//      $form['user_roles']['roles'][$account->uid] = array(
-	//			'#type' => 'select',
-	//			'#multiple' => TRUE,
-	//			'#required' => FALSE,
-	//			'#size' => 2,
-	//	        '#options' => $roles,
-	//	        '#default_value' => _user_roles($account->uid, $roles),
-	//		);
-	//
-	// end modification for pulldown select
-	//
-
-//
-// Multi column checkbox form - as per http://drupal.org/node/41936
-// Also "unsubscribe" link added: 
-//
-//  $link = l($account->name, "user/$account->uid") . l(" (unsubscribe)", "og/unsubscribe/$gid/$account->uid", array(), "destination=og/users/$gid");
-// Modified - 2007-06-18 - Changed "unsubscribe" link as per: http://drupal.org/node/152442
-//
-  $link = l($account->name, "user/$account->uid") . l(t(" (unsubscribe)"), "og/unsubscribe/$gid/$account->uid", array(), "destination=og/users/$gid");
-  $form['user_roles']['roles'][$account->uid] = array(
-    '#type' => 'checkbox_columns',
-	'#title' => $link,
-    '#default_value' => _og_user_roles($account->uid, $roles),
-    '#columns' => 4,
-    '#options' => $roles,
-    '#suffix' => '<br style="clear:both;"/>',
-  );
-
-
-    }
-    // Output form to screen
-    $form['submit'] = array('#type' => 'submit', '#value' => t('Save changes'));
-    return $form;
+function og_user_roles_page_form($gid, $roles, $result) {
+  $form['user_roles'] = array('#tree' => TRUE); // Make sure form array isn't flattened
+
+  while ($account = db_fetch_object($result)) {
+    $form['user_roles']['users'][$account->uid] = array(
+      '#type' => 'value',
+      '#value' => $account->uid
+    );
+
+    $title = theme('username', $account) .' ('. l(t('unsubscribe'), "og/unsubscribe/$gid/$account->uid", array(), "destination=og/users/$gid") .')';
+
+    $form['user_roles']['roles'][$account->uid] = array(
+      '#type' => 'checkbox_columns',
+      '#title' => $title,
+      '#default_value' => _og_user_roles($account->uid, $roles),
+      '#columns' => 4,
+      '#options' => $roles,
+      '#suffix' => '<br style="clear: both;" />',
+    );
+  }
+
+  $form['submit'] = array('#type' => 'submit', '#value' => t('Save changes'));
+
+  return $form;
 }
 
 /**
  * Process the form submission
  */
 function og_user_roles_page_form_submit($form_id, $form_values) {
-
-	//
-	// Modification
-	// Added this to get gid 
-	//
-		if ( is_numeric(arg(2)) ) {
-			$gid = (int)arg(2);
-		}
-
+
+  // Added this to get gid
+  if (is_numeric(arg(2))) {
+    $gid = (int)arg(2);
+  }
+
   foreach ($form_values['user_roles']['roles'] as $uid => $roles) {
     foreach ($roles as $rid => $checked) {
-      $exists = db_result(db_query("SELECT * FROM {og_users_roles} WHERE uid = %d AND rid = %d AND gid = %d", $uid, $rid, $gid)); // modification
-//    $exists = db_result(db_query("SELECT * FROM {users_roles} WHERE uid = %d AND rid = %d", $uid, $rid)); // replaced
+      $exists = db_result(db_query("SELECT * FROM {og_users_roles} WHERE uid = %d AND rid = %d AND gid = %d", $uid, $rid, $gid));
       if ($checked && !$exists) {
-        db_query("INSERT INTO {og_users_roles} (uid, rid, gid) VALUES (%d, %d, %d)", $uid, $rid, $gid);  // modification
-//      db_query("INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)", $uid, $rid);  // replaced
+        db_query("INSERT INTO {og_users_roles} (uid, rid, gid) VALUES (%d, %d, %d)", $uid, $rid, $gid);
       }
       elseif (!$checked && $exists) {
-        db_query("DELETE FROM {og_users_roles} WHERE uid = %d AND rid = %d AND gid = %d", $uid, $rid, $gid);  // modification
-//      db_query("DELETE FROM {users_roles} WHERE uid = %d AND rid = %d", $uid, $rid);  // replaced
+        db_query("DELETE FROM {og_users_roles} WHERE uid = %d AND rid = %d AND gid = %d", $uid, $rid, $gid);
       }
     }
   }
@@ -429,24 +332,20 @@ function og_user_roles_page_form_submit(
 /**
  * This checks to see what roles a current user has against a given set of roles.
  */
-function _og_user_roles($uid, $roles = array()) { 
-
-	//
-	// Modification
-	// Added this to get gid 
-	//
-		if ( is_numeric(arg(2)) ) {
-			$gid = (int)arg(2);
-		}
-
+function _og_user_roles($uid, $roles = array()) {
+
+  // Added this to get gid
+  if (is_numeric(arg(2))) {
+    $gid = (int)arg(2);
+  }
+
   $roles_output = array();
   if (is_array($roles)) {
     foreach ($roles as $rid => $role) {
-      $result = db_result(db_query("SELECT * FROM {og_users_roles} WHERE uid = %d AND rid = %d AND gid = %d", $uid, $rid, $gid)); // modification
-//    $result = db_result(db_query("SELECT * FROM {users_roles} WHERE uid = %d AND rid = %d", $uid, $rid));  // replaced
+      $result = db_result(db_query("SELECT * FROM {og_users_roles} WHERE uid = %d AND rid = %d AND gid = %d", $uid, $rid, $gid));
       if ($result) {
         $roles_output[$rid] = $rid;
-      } 
+      }
     }
   }
 
@@ -457,26 +356,23 @@ function _og_user_roles($uid, $roles = a
 /**
  * Theme function to render the table for the og_user_roles form.
  */
-function theme_og_user_roles_page_form($form) {  
+function theme_og_user_roles_page_form($form) {
   $output .= "\n" . '<div id="og-roles-form">' . "\n";
   $output .= '<div id="desc">' . t('Here you can assign group roles to members.  This will give that member permission of that role.  It will apply to all posts of this group type.') . "</div>\n";
-//  $header[] = array('data' => t('Users'));
   $header[] = array('data' => t('Roles'), 'colspan' => 2);
   $rows = array();
-  
+
   $i = 0;
   foreach ($form['user_roles']['users'] as $user_form) {
     $uid = $user_form['#value'];
 
     if ($uid) {
-//      $rows[$i][] = theme('username', user_load(array('uid'=> $uid)));
       $rows[$i][] = drupal_render($form['user_roles']['roles'][$uid]);
-      
       $i++;
     }
   }
 
-  $output .= theme_table($header, $rows, $attributes = array('id' => 'og-roles-table'), $caption = NULL);  
+  $output .= theme('table', $header, $rows, array('id' => 'og-roles-table'));
   $output .= drupal_render($form['submit']);
   $output .= "</div>\n";
   $output .= drupal_render($form);
@@ -492,7 +388,7 @@ function theme_og_user_roles_page_form($
  *   TRUE if this group type allows roles to be assigned, otherwise FALSE
  */
 function og_user_roles_is_allowed($nid) {
-  $node = node_load(array('nid'=>$nid));
+  $node = node_load(array('nid' => $nid));
   if (in_array($node->type, variable_get('og_node_types', array('og'))) && variable_get("og_user_roles_roles_$node->type", NULL)) {
     return TRUE;
   }
@@ -500,68 +396,86 @@ function og_user_roles_is_allowed($nid) 
     return FALSE;
   }
 }
-
-//
-// Modification
-// Added the following two functions to add and remove roles.
-//
+
 /**
  * Add role to og_users_roles table.
  */
-function og_user_roles_role_join($uid, $rid, $gid) {
-	db_query("INSERT INTO {og_users_roles} (rid, uid, gid) VALUES ('%d','%d','%d')", $rid, $uid, $gid);
-}
+function og_user_roles_role_join($uid, $rid, $gid) {
+  db_query("INSERT INTO {og_users_roles} (rid, uid, gid) VALUES ('%d','%d','%d')", $rid, $uid, $gid);
+}
+
 /**
  * Remove all roles for a user in a group table.
  */
-function og_user_roles_role_leave($uid, $gid) {
-	db_query("DELETE FROM {og_users_roles} WHERE uid = %d AND gid = %d", $uid, $gid);
-}
-//
-// Modification
-// Added the following functions from this snippet: http://drupal.org/node/41936
-// Creates multiple checkbox columns
-//
-function expand_checkbox_columns($element) {
-  $value = is_array($element['#value']) ? $element['#value'] : array();
-  $element['#type'] = 'checkboxes';
-  $element['#tree'] = TRUE;
-  if (count($element['#options']) > 0) {
-    if (!isset($element['#default_value']) || $element['#default_value'] == 0) {
-      $element['#default_value'] = array();
-    }
-    foreach ($element['#options'] as $key => $choice) {
-      $class = ($column % $element['#columns']) && $column ? 'checkbox-columns' : 'checkbox-columns-clear';
-      if (!isset($element[$key])) {
-        $element[$key] = array('#type' => 'checkbox', '#processed' => TRUE, '#title' => $choice, '#default_value' => in_array($key, $value), '#attributes' => $element['#attributes'], '#prefix' => '<div class="' . $class . '">', '#suffix' => '</div>', '#return_value' => $choice);
-      }
-      $column++;
-    }
-  }
-  return $element;
-}
-//
-// Modification
-// Added the following functions from this snippet: http://drupal.org/node/41936
-// To let Drupal know about the new "expand_checkbox_columns".
-//
-function og_user_roles_elements() {
-  $type['checkbox_columns'] = array('#input' => TRUE, '#process' => array('expand_checkbox_columns' => array()), '#tree' => TRUE);
-  return $type;
-}
-
+function og_user_roles_role_leave($uid, $gid) {
+  db_query("DELETE FROM {og_users_roles} WHERE uid = %d AND gid = %d", $uid, $gid);
+}
+
+//
+// Modification
+// Added the following functions from this snippet: http://drupal.org/node/41936
+// Creates multiple checkbox columns
+//
+function expand_checkbox_columns($element) {
+
+  $value = is_array($element['#value']) ? $element['#value'] : array();
+
+  $element['#type'] = 'checkboxes';
+
+  $element['#tree'] = TRUE;
+
+  if (count($element['#options']) > 0) {
+    if (!isset($element['#default_value']) || $element['#default_value'] == 0) {
+      $element['#default_value'] = array();
+    }
+
+    foreach ($element['#options'] as $key => $choice) {
+      $class = ($column % $element['#columns']) && $column ? 'checkbox-columns' : 'checkbox-columns-clear';
+      if (!isset($element[$key])) {
+        $element[$key] = array(
+          '#type' => 'checkbox',
+          '#processed' => TRUE,
+          '#title' => $choice,
+          '#default_value' => in_array($key, $value),
+          '#attributes' => $element['#attributes'],
+          '#prefix' => '<div class="' . $class . '">',
+          '#suffix' => '</div>',
+          '#return_value' => $choice
+        );
+      }
+      $column++;
+    }
+  }
+
+  return $element;
+
+}
+
+/**
+ * Added the following functions from this snippet: http://drupal.org/node/41936
+ * To let Drupal know about the new "expand_checkbox_columns".
+ */
+function og_user_roles_elements() {
+  $type['checkbox_columns'] = array(
+    '#input' => TRUE,
+    '#process' => array('expand_checkbox_columns' => array()),
+    '#tree' => TRUE
+  );
+
+  return $type;
+}
+
 /**
  * @ingroup views
  */
 
 /**
  * Implementation of hook_views_tables():
- * Present fields and filters for user data.
+ * Present fields and filters for user data.
  * Requires that usernode be installed.
  */
-
 function og_user_roles_views_tables() {
-
+
   $tables['og_users_roles'] = array(
     'name' => 'og_users_roles',
     'provider' => 'internal', // won't show up in external list.
@@ -592,7 +506,7 @@ function og_user_roles_views_tables() {
       ),
     ),
   );
-
+
   $tables['og_users_uid'] = array(
     'name' => 'og_uid',
     'provider' => 'internal', // won't show up in external list.
@@ -616,7 +530,7 @@ function og_user_roles_views_tables() {
       ),
     ),
   );
-
+
   $tables['og_non_group_roles'] = array(
     'name' => 'users_roles',
     'provider' => 'internal', // won't show up in external list.
@@ -642,290 +556,242 @@ function og_user_roles_views_tables() {
 
   return $tables;
 }
-
-
+
 /*
  * Create a list of group names and IDs.
  */
-function views_handler_filter_group() {
-  $list = array();
-  $list = variable_get('og_node_types', array('og'));  
-  $groupTypes = implode(",", $list);
+function views_handler_filter_group() {
+  $list = array();
+  $list = variable_get('og_node_types', array('og'));
+
+  $group_types = implode(',', $list);
   $vids = array();
-  $result = db_query("SELECT n.nid, n.title FROM {node} n WHERE n.type IN ('". $groupTypes ."') ORDER BY n.title");
+  $result = db_query("SELECT n.nid, n.title FROM {node} n WHERE n.type IN (%s) ORDER BY n.title", $group_types);
   while ($obj = db_fetch_object($result)) {
     $vids[$obj->nid] = $obj->title;
   }
+
   return $vids;
 }
-
+
+
 /*
- * Implementation of hook_init.
- * 
- * Got the idea of re-directing if this is a add group node request
- * from here: http://drupal.org/project/globalredirect
+ * Implementation of hook_init.
  *
+ * Got the idea of re-directing if this is a add group node request
+ * from here: http://drupal.org/project/globalredirect
  */
-
-function og_user_roles_init ()
-{
-	global $user;
-
-	// Looking for this format: http://www.scbbs.com/node/add/link?gids[]=29
-
-	// We only need to process this if the user is logged in
-	if ($user->uid > 0) {
-
-		// Bootstrap if arg() doesn't exist
-	    if (!function_exists('arg') && $user->uid > 0){
-			drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH); // added as per this issue: http://drupal.org/node/149469
-	    }
-
-		// If this is a group node/add, re-direct to ognodeadd
-		if (arg(0) == 'node' && arg(1) == 'add' && isset($_REQUEST['gids'])) {
-			$gids = $_GET['gids'];
-		    $gid = intval(current($_REQUEST['gids']));
-
-			$type = arg(2);
-
-			$path = 'node/ognodeadd';
-			if ($type == 'og_user_roles_subgroup') $type = variable_get("og_user_roles_create_subgroup_value", ''); // change OG Subgroups type to 'group'
-
-			$query = 'type=' . $type . '&gids[]=' . $gid;
-			drupal_goto($path, $query);
-		}
-	}
-}
-
+function og_user_roles_init() {
+  global $user;
+  // Looking for this format: http://www.scbbs.com/node/add/link?gids[]=29
+  // We only need to process this if the user is logged in
+
+  if ($user->uid > 0) {
+    // Bootstrap if arg() doesn't exist
+    if (!function_exists('arg') && $user->uid > 0) {
+      drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH); // added as per this issue: http://drupal.org/node/149469
+    }
+    // If this is a group node/add, re-direct to ognodeadd
+    if (arg(0) == 'node' && arg(1) == 'add' && isset($_REQUEST['gids'])) {
+      $gids = $_GET['gids'];
+      $gid = intval(current($_REQUEST['gids']));
+      $type = arg(2);
+      $path = 'node/ognodeadd';
+
+      if ($type == 'og_user_roles_subgroup') {
+        $type = variable_get('og_user_roles_create_subgroup_value', ''); // change OG Subgroups type to 'group'
+      }
+      $query = 'type=' . $type . '&gids[]=' . $gid;
+
+      drupal_goto($path, $query);
+    }
+  }
+}
+
 /*
- * Implementation of hook_user.
- * Put new users in default role if applicable.
- *
- * Got this code from here: http://drupal.org/node/28379#comment-132430
+ * Implementation of hook_user.
+ * Put new users in default role if applicable.
  *
+ * Got this code from here: http://drupal.org/node/28379#comment-132430
  */
-
-function og_user_roles_user ($op, &$edit, &$user, $category=null)
-{
-	// If the user opted to create a default role
-
-	if (variable_get("og_user_roles_assign_default", 0) == 1) {
-
-		$rid = variable_get("og_user_roles_default_value", 0);
-
-    	// special case for new users
-	    if ($op == "insert")
-    	{
-/*
- * Modification as per: http://drupal.org/node/149483
- */
-		// Check to see if this user doesn't already have this role;
-		// If not, then assign it.
-
-			$sql = "SELECT COUNT(*) FROM {users_roles} WHERE uid = %d AND rid = %d";
-		    $result = db_query($sql, $user->uid, $rid);
-		    $output = (db_result($result));
-			if ($output == 0) db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $user->uid, $rid);
-    	}
-
-	} // end if
-	
-	// Add the group roles to $user->roles if this is a group
-	// This should only be effective until the next global $user call
-
-    if ($op == "load") {
-		$roles = og_user_roles_all_roles($user); // This returns normal $user->roles and includes OG roles if any
-		$user->roles = $roles;
-	} // end $op load
-
-	// Remove user info from og_users_roles table
-
-    if ($op == "delete") {
-        db_query("DELETE FROM {og_users_roles} WHERE uid = %d", $user->uid);  // delete all records for this user
-	} // end $op delete
-
-}
-
-/**
- * implementation of hook_og();
- *
- * @param $op string, 'user insert', 'user update', 'user delete'
- * @param $nid node ID of the group 
- * @param $uid the user ID
- * @param $args associative array containing details about the subscription
- */
-function og_user_roles_og($op, $nid, $uid, $args = array()) {
-    switch ($op) {
-      case 'user insert':
-		
-        // --- Modification - 2007-06-18 - as per: http://drupal.org/node/152442
-        // Adding every user to a basic group restricted role, that all users in the group should have.
-        // I don't know a better way, so I'll do it like this. This is based on the creating of a founder role,
-        // just that every user in the group should automagically get this role.
-        // -Bibo
-	        if (variable_get("og_user_roles_assign_basicgrouprole", 0) == 1) {
-    	        $rid = variable_get("og_user_roles_basicgrouprole_value", 0);
-        	    og_user_roles_role_join($uid, $rid, $nid); // assign user to group role in that group
-	        }
-        //--- end of modification
-
-		global $base_url;
-		$user = user_load(array('uid' => $uid));
-		$username = $user->name;
-		$node = node_load($nid);
-
-		// Send notification of new og subscription to administrators of group;
-
-		if (variable_get("og_user_roles_notify_default", 0) == 1) {
-			$group = $node->title;
-			$sender = variable_get('site_mail', '');
-			$subject = 'User ' . $username . ' added to group: ' . $group;
-			$message = "User <a href='" . $base_url . "/user/" . $uid . "'>" . $username . "</a> added to group: <a href='" . $base_url . "/node/" . $nid . "'>" . $group . "</a>";
-
-            // Get the group admin(s)
-
-//  			$result = db_query("SELECT uid FROM og_uid WHERE is_admin = 1 AND nid = " . $nid);
-  			$result = db_query("SELECT uid FROM {og_uid} WHERE is_admin = 1 AND nid = %d", $nid); // FIXED TABLE PREFIX
-  			while ($obj = db_fetch_object($result)) {
-    			$recipient_uid = $obj->uid;
-				$recipient_user = user_load(array('uid' => $recipient_uid));
-				$recipient = $recipient_user->mail;
-				mimemail($sender, $recipient, $subject, $message);
-  			} // end while
-		} // end if
-
-       	break;
-
-      case 'user delete':
-
-		// Remove all roles for this user in this group if he is being unsubscribed;
-
-			og_user_roles_role_leave($uid, $nid);
-       	
-       	break;
-
-    } // end switch
-}
-
-/**
- * Implementation of hook_node_info().
- */
-function og_user_roles_node_info() {
-	
-	// If og_subgroups is installed AND og_user_roles_create_subgroup checkbox is checked;
-
-	if (module_exists('og_subgroups') && variable_get("og_user_roles_create_subgroup", 0) == 1) {
-	  return array(
-	    'og_user_roles_subgroup' => array(
-    	  'name'        => t('Subgroup'),
-	      'module'      => 'og_user_roles',
-    	  'description' => t('Create a basic subgroup.'),
-	      'help'        => t('Create a basic subgroup.'),
-    	  'body_label'  => t('Description'),
-	    ),
-	  );
-	} // end if
-}
-
-/**
- * Implementation of hook_load().
- *
- * Doesn't seem to work.
-*/
-//function og_user_roles_load($node) {
- // watchdog test
-// 	watchdog("hook_load", "og_user_roles : type = " . $node->type);
-  	
-//  	return $node;
-//} 
-
+function og_user_roles_user($op, &$edit, &$user, $category = NULL) {
+
+  // If the user opted to create a default role
+  if ($op == 'insert' && variable_get('og_user_roles_assign_default', 0) == 1) {
+    // Check to see if this user doesn't already have this role;
+    // If not, then assign it.
+    $rid = variable_get('og_user_roles_default_value', 0);
+    $sql = "SELECT COUNT(*) FROM {users_roles} WHERE uid = %d AND rid = %d";
+    $result = db_query($sql, $user->uid, $rid);
+    $output = (db_result($result));
+
+    if ($output == 0) {
+      db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $user->uid, $rid);
+    }
+  }
+
+  // Add the group roles to $user->roles if this is a group
+  // This should only be effective until the next global $user call
+  if ($op == 'load') {
+    $roles = og_user_roles_all_roles($user); // This returns normal $user->roles and includes OG roles if any
+    $user->roles = $roles;
+  } // end $op load
+
+  // Remove user info from og_users_roles table
+  if ($op == 'delete') {
+    db_query("DELETE FROM {og_users_roles} WHERE uid = %d", $user->uid);  // delete all records for this user
+  } // end $op delete
+}
+
 /**
- * Implementation of hook_nodeapi().
+ * implementation of hook_og();
  *
+ * @param $op string, 'user insert', 'user update', 'user delete'
+ * @param $nid node ID of the group
+ * @param $uid the user ID
+ * @param $args associative array containing details about the subscription
+ */
+function og_user_roles_og($op, $nid, $uid, $args = array()) {
+
+  switch ($op) {
+    case 'user insert':
+      global $base_url;
+
+      if (variable_get('og_user_roles_assign_basicgrouprole', 0) == 1) {
+        $rid = variable_get('og_user_roles_basicgrouprole_value', 0);
+        og_user_roles_role_join($uid, $rid, $nid); // assign user to group role in that group
+      }
+
+      $user = user_load(array('uid' => $uid));
+      $node = node_load($nid);
+
+      // Send notification of new og subscription to administrators of group;
+      if (variable_get('og_user_roles_notify_default', 0) == 1) {
+        $group = check_plain($node->title);
+        $sender = variable_get('site_mail', '');
+        $subject = t('User @user added to group: @group', array('@user' => $user->name, '@group' => $group));
+        $message = t('User @user added to group: @group.', array('@user' => theme('username', $user), '@group' => l($group, "node/$nid")));
+        $result = db_query("SELECT uid FROM {og_uid} WHERE is_admin = 1 AND nid = %d", $nid); // FIXED TABLE PREFIX
+
+        while ($obj = db_fetch_object($result)) {
+          $recipient_uid = $obj->uid;
+          $recipient_user = user_load(array('uid' => $recipient_uid));
+          $recipient = $recipient_user->mail;
+          mimemail($sender, $recipient, $subject, $message);
+        } // end while
+      } // end if
+      break;
+
+    case 'user delete':
+      // Remove all roles for this user in this group if he is being unsubscribed;
+      og_user_roles_role_leave($uid, $nid);
+      break;
+  } // end switch
+}
+
+/**
+ * Implementation of hook_node_info().
+ */
+function og_user_roles_node_info() {
+  // If og_subgroups is installed AND og_user_roles_create_subgroup checkbox is checked;
+  if (module_exists('og_subgroups') && variable_get("og_user_roles_create_subgroup", 0) == 1) {
+
+    return array(
+      'og_user_roles_subgroup' => array(
+        'name'        => t('Subgroup'),
+        'module'      => 'og_user_roles',
+        'description' => t('Create a basic subgroup.'),
+        'help'        => t('Create a basic subgroup.'),
+        'body_label'  => t('Description'),
+      ),
+    );
+  } // end if
+}
+
+/**
+ * Implementation of hook_nodeapi().
 */
 function og_user_roles_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
   switch ($op) {
-
-	case 'access':
-//
-// This access check is used for TAC and OG permissions integration;
-//
-		if (variable_get("og_user_roles_tac_og_value", 0) == 1) {
-
-			$access = FALSE;
-			$og_access = og_user_roles_og_access_check($teaser, $node);
-			$tac_access = og_user_roles_taxonomy_access_check($teaser, $node);
-
-			if ($og_access === TRUE && $tac_access == FALSE) $access = FALSE;
-			if ($og_access === FALSE) $access = FALSE;
-			if ($og_access === TRUE && $tac_access == TRUE) $access = TRUE;
-		
-			return $access;
-		}
-			 
-	break;
-
+    case 'access':
+      // This access check is used for TAC and OG permissions integration;
+      if (variable_get("og_user_roles_tac_og_value", 0) == 1) {
+        $access = FALSE;
+
+        $og_access = og_user_roles_og_access_check($teaser, $node);
+        $tac_access = og_user_roles_taxonomy_access_check($teaser, $node);
+
+        if ($og_access === TRUE && $tac_access == FALSE) {
+          $access = FALSE;
+        }
+        if ($og_access === FALSE) {
+          $access = FALSE;
+        }
+
+        if ($og_access === TRUE && $tac_access == TRUE) {
+          $access = TRUE;
+        }
+
+        return $access;
+      }
+      break;
+
     case 'submit':
-	//
-	// Put appropriate nodes into all groups upon node submission;
-	//
-		// Get list of nodes to put into all groups;
-
-		$nodelist = variable_get('og_user_roles_all_groups_nodes', '');
-		if (!empty($nodelist)) {
-			$nodelistArray = explode(",", $nodelist);
-			foreach ($nodelistArray as $nodelistItem) {
-				if ($node->nid == $nodelistItem) {
-		    	  if ($grps = og_user_roles_get_groups($node)) {
-	    	    	$node->og_groups = array_keys($grps);
-		    	    $node->og_groups_names = array_values($grps);
-        
-	    		    $public = db_result(db_query_range("SELECT is_public FROM {og_ancestry} WHERE nid = %d", $node->nid, 0, 1));
-    	    		$node->og_public = $public ? TRUE : FALSE;
-			      } // end $grps if
-				} // end $node->nid if
-			} // end foreach
-		} // end $nodelist if
-
-
+      // Put appropriate nodes into all groups upon node submission;
+
+      // Get list of nodes to put into all groups;
+      $nodelist = variable_get('og_user_roles_all_groups_nodes', '');
+
+      if (!empty($nodelist)) {
+        $nodelist_array = explode(",", $nodelist);
+
+        foreach ($nodelist_array as $nodelist_item) {
+          if ($node->nid == $nodelist_item) {
+              if ($grps = og_user_roles_get_groups($node)) {
+                $node->og_groups = array_keys($grps);
+                $node->og_groups_names = array_values($grps);
+                $public = db_result(db_query_range("SELECT is_public FROM {og_ancestry} WHERE nid = %d", $node->nid, 0, 1));
+                $node->og_public = $public ? TRUE : FALSE;
+              } // end $grps if
+          } // end $node->nid if
+        } // end foreach
+
+      } // end $nodelist if
+
       break;
-
+
     case 'insert':
-
-		// If this is a group node, put the group creator into a group role upon creation;
-
-		if (variable_get("og_user_roles_assign_founder", 0) == 1) {
-
-			$rid = variable_get("og_user_roles_founder_value", 0);
-
-			// If this is a group node
-			if (og_is_group_type($node->type)) {
-				// Get the requisite data
-				$uid = $node->uid; // user ID
-				$gid = $node->nid; // group ID
-				og_user_roles_role_join($uid, $rid, $gid); // assign user to group role in that group
-			}
-		}
-
-		// Create a subgroup record for this group
-
-		// 'ognodeadd' is my node add callback, so I know if this node is a group and 
-		// here, then we need to process it node as a subgroup
-
-		if ($node->type == variable_get('og_user_roles_create_subgroup_value', '') && arg(1) == 'ognodeadd') { 
-
-			$gids = $_GET['gids'];
-			$gid = $gids[0];
-			$subgroup = $node->nid;
-			$sql = 'INSERT INTO {og_ancestry} (nid,group_nid,is_public) VALUES (%d,%d,0)';
-			db_query($sql, $subgroup, $gid);		
-		}
-      
+
+      // If this is a group node, put the group creator into a group role upon creation;
+      if (variable_get("og_user_roles_assign_founder", 0) == 1) {
+        // If this is a group node
+
+        if (og_is_group_type($node->type)) {
+          // Get the requisite data
+          $uid = $node->uid; // user ID
+          $rid = variable_get("og_user_roles_founder_value", 0);
+          $gid = $node->nid; // group ID
+          og_user_roles_role_join($uid, $rid, $gid); // assign user to group role in that group
+        }
+
+      }
+      // Create a subgroup record for this group
+      // 'ognodeadd' is my node add callback, so I know if this node is a group and
+
+      // here, then we need to process it node as a subgroup
+      if ($node->type == variable_get('og_user_roles_create_subgroup_value', '') && arg(1) == 'ognodeadd') {
+        $gids = $_GET['gids'];
+        $gid = $gids[0];
+        $subgroup = $node->nid;
+        $sql = 'INSERT INTO {og_ancestry} (nid,group_nid,is_public) VALUES (%d,%d,0)';
+        db_query($sql, $subgroup, $gid);
+      }
+
       break;
-
   } // end switch
 } // end og_user_roles_nodeapi function
-
+
+
 // returns all groups so long as this is not a group itself
 function og_user_roles_get_groups($node) {
   $groups = array();
@@ -934,6 +800,7 @@ function og_user_roles_get_groups($node)
     while ($row = db_fetch_object($result)) {
       $groups[$row->group_nid] = $row->title;
     }
+
     return $groups;
   }
 }
@@ -941,455 +808,457 @@ function og_user_roles_get_groups($node)
 // just the query for the get_node_groups function.
 function og_user_roles_get_groups_result() {
   $sql = "SELECT oga.group_nid, n.title FROM {og_ancestry} oga INNER JOIN {node} n ON oga.group_nid = n.nid";
-  // we use rewrite_sql() in order to avoid disclosing completely private groups (once we support those properly)
-//  return db_query(db_rewrite_sql($sql, 'oga', 'group_nid'), $nid);
-  	return db_query(db_rewrite_sql($sql, 'oga', 'group_nid'), '');
-}
-
-//
-// My OG Roles Modifications
-//
-//
-// Modification - Added this function
-//
-// This function returns an array of role keys and names, like $user->roles
-// However, it returns site roles as well as group roles
-//
-function og_user_roles_all_roles_array($user) {
-
-	$roles = og_user_roles_all_roles($user);
-
-	return $roles;
-}
-
-// This function takes the global $user (or $account) value and returns a list
-// of group and non-group roles for this user
-
-function og_user_roles_all_roles($user) {
-
-	// This will be the process to get BOTH the group and non-group roles for a user
-
-		$uid = $user->uid;
-		$gid = 0;
-		$gids = array();
-		$nodeID = 0;
-		$location = 0;
-
-		$uri_request_id = $_SERVER['REQUEST_URI'];
-		$arg = explode("/", $uri_request_id);
-
-		$ogroles = array();
-		$x1 = 0;
-	//
-	// This will by default add the anonymous user role (no need since we merge user->roles)
-	//
-	// We get the groupID
-	//
-  		$group_node = og_get_group_context();
-		$gid02 = $group_node->nid;
-		$gid = $gid02;
-		if ($gid02 === null) $gid = 0;
-	// 
-	// If the above doesn't get the groupID, then we start trying stuff
-	//
-		if ($gid == 0) {
-
-		// http://doadance.scbbs.com/drupal03/node/79
-
-			if (arg(0) == 'node' && is_numeric(arg(1)) && is_null(arg(2))) {
-				$location = 1;
-			  $nodeID = (int)arg(1);	
-			  $gid = getgid($nodeID, $uid);
-			}
-
-		// http://doadance.scbbs.com/node/79/edit
-		// http://doadance.scbbs.com/node/79/outline
-		// http://doadance.scbbs.com/node/79/track
-
-			if (arg(0) == 'node' && is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'outline' || arg(2) == 'track' ) ) {
-				$location = 2;
-			  $nodeID = (int)arg(1);	
-			  $gid = getgid($nodeID, $uid);
-			}
-		//                           0    1    2
-		// http://www.mysite.com/comment/edit/14				
-		//
-			if (arg(0) == 'comment' && is_numeric(arg(2)) && arg(1) == 'edit' ) {
-				$location = 3;
-			  $comment = _comment_load(arg(2));
-			  $nodeID = $comment->nid;
-		   	  $gid = getgid($nodeID, $uid);	  	
-			}
-		//                           0      1    2
-		// http://www.mysite.com/comment/reply/128#comment_form				
-		//
-			if (arg(0) == 'comment' && arg(1) == 'reply' ) {
-				$location = 4;
-  	       	  $subsections = explode("#", arg(2));
-			  $nodeID = (int)$subsections[0];	
-		   	  $gid = getgid($nodeID, $uid);	  	
-			}
-				
-		// og_term access
-		//                        0    1    2    3
-		// http://www.mysite.com/node/add/forum/121				
-		//
-			if (arg(0) == 'node' && is_numeric(arg(3)) && arg(1) == 'add' ) {
-				$location = 5;
-			  $nodeID = (int)arg(3);	
-			  $gid = getgid($nodeID, $uid);
-			}
-
-		// Here we get the gid directly
-		//
-		// http://doadance.scbbs.com/node/79/view/tree
-		// http://doadance.scbbs.com/node/79/view/members
-		// http://doadance.scbbs.com/node/79/view
-
-			if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'view' ) {
-   				$location = 2;
-			  $gid = (int)arg(1);	
-			}
-
-		// Here we get the gid directly
-		//
-		// http://doadance.scbbs.com/og/users/72
-		// http://doadance.scbbs.com/og/manage/72
-
-			if (arg(0) == 'og' && is_numeric(arg(2)) && is_null(arg(3))) {
-				$location = 6;
-			  $gid = (int)arg(2);	
-			}
-				
-		// og_user_roles
-		//
-		// http://doadance.scbbs.com/og/users/72/roles
-		// http://doadance.scbbs.com/og/users/72/add
-
-			if (arg(0) == 'og' && arg(1) == 'users' && is_numeric(arg(2)) && is_null(arg(4))) {
-				$location = 6;
-			  $gid = (int)arg(2);	
-			}
-
-		// og unsubscribe
-		// og_user_roles
-		//
-		// This is sort of a catch all for "og" and gid in this order
-		// og/<whatever>/<gid>
-		//
-		// http://doadance.scbbs.com/og/unsubscribe/72
-		// http://doadance.scbbs.com/og/users/72/add
-
-			if (arg(0) == 'og' && is_numeric(arg(2))) {
-				$location = 6;
-			  $gid = (int)arg(2);	
-			}
-
-		// og_forum
-		//
-		// http://doadance.scbbs.com/og_forum/manage/72
-
-			if (arg(0) == 'og_forum' && arg(1) == 'manage' && is_numeric(arg(2)) && is_null(arg(3))) {
-				$location = 6;
-			  $gid = (int)arg(2);	
-			}
-
-		// http://doadance.scbbs.com/og_forum/manage/edit/72
-		// http://doadance.scbbs.com/og_forum/manage/add/72
-
-			if (arg(0) == 'og_forum' && arg(1) == 'manage' && is_numeric(arg(3))) {
-				$location = 6;
-			  $gid = (int)arg(3);	
-			}
-
-		// og_calendar
-		//
-		// http://doadance.scbbs.com/og_calendar/72
-
-			if (arg(0) == 'og_calendar' && is_numeric(arg(1)) && is_null(arg(2))) {
-				$location = 7;
-			  $gid = (int)arg(1);	
-			}
-				
-		// og_forum
-		//				 0	         1	  2			  3	
-		// http://www.mysite.com/og_forum/39/72?edit[og_groups][]=72
-		// http://www.mysite.com/og_forum/37/71?sort=asc&order=Replies&edit[og_groups][0]=71
-
-			if ($arg[1] == 'og_forum' && strpos($arg[3], 'og_groups') !== false && (!is_null($arg[3])) ) {
-				$location = 8;
-				$subsections = explode("=", $arg[3]);
-				foreach ($subsections as $subsection) {
-					if (is_numeric($subsection)) {
-			  			$gid = (int)$subsection;
-					}
-				}
-			}
-
-		// og create nodes (version 5.1)
-		//				  0		  1	  2			      3
-		// http://sbn.scbbs.com/node/add/forum?gids[]=72
-		// http://sbn.scbbs.com/node/add/simplenews?gids[]=72
-		// http://sbn.scbbs.com/node/add/webform?gids[]=72
-		// http://sbn.scbbs.com/node/add/video?gids[]=72
-		// http://sbn.scbbs.com/node/add/page?gids[]=72
-		// http://sbn.scbbs.com/node/add/blog?gids[]=72
-		// http://sbn.scbbs.com/node/add/event?gids[]=72
-		// http://sbn.scbbs.com/node/add/poll?gids[]=72
-		// http://sbn.scbbs.com/node/add/flexinode-3?gids[]=72
-
-			if ($arg[1] == 'node' && strpos($arg[3], 'gids') !== false && (!is_null($arg[3])) ) {
-				$location = 10 . "(" . arg(0) . "|" . arg(1) . "|" . arg(2) . ")";
-				$subsections = explode("=", $arg[3]);
-	  			$gid = (int)$subsections[1];
-			}
-
-		// og create nodes (custom node/20 aliased to node/ognodeadd)
-		//				  0		  1	  2			      3
-		// http://clients.brixrealtyinc.com/node/ognodeadd?type=document&gids[]=12
-		//
-			if ($arg[1] == 'node') {
-			  if (strpos($arg[2], 'ognodeadd') !== false ) {
-			     if (strpos($arg[2], 'gids') !== false ) {
-					$location = 13;
-					$subsections = explode("=", $arg[2]);
-					$gid = (int)$subsections[2];
-			      }
-			  }
-			}
-
-		} // end $gid if
-	//
-	// Now, using $uid and $gid we find out what roles this user has in this group;
-	//
-		if (empty($gid)) $gid = 0; // This prevents us from getting error on non-group node/add
-//	  	$query = 'SELECT role.rid, role.name FROM role INNER JOIN og_users_roles ON role.rid = og_users_roles.rid WHERE og_users_roles.uid = ' . $uid . ' AND og_users_roles.gid = ' . $gid;
-//	  	$results = db_query($query);
-	  	$query = 'SELECT {role}.rid, {role}.name FROM {role} INNER JOIN {og_users_roles} ON {role}.rid = {og_users_roles}.rid WHERE {og_users_roles}.uid = %d AND {og_users_roles}.gid = %d'; // FIXED TABLE PREFIX
-	  	$results = db_query($query, $uid, $gid);
-	//
-	// Create an array of these roles;
-	//
-  		while ( $row = db_fetch_array($results) ) {
-			$x1 = $row["rid"];
-    		$ogroles[$x1] = $row["name"];
-		}
-	//
-	// First, we need to create an array of $user->roles
-	//
-		$c = $user->roles;
-	//
-	// Next, we add the $user->roles array to the $ogroles array, if there is an ogroles array;
-	//		
-		if ($x1 > 0) {
-			$d = array();
-			$d = $c + $ogroles;
-			$d = array_unique($d);
-		} else {
-			$d = $c;
-		}
-
-	// Write the test data
-
-		og_user_roles_write_test($user, $location, $gid02, $gid, $uri_request_id, $d, $query);
-//
-// $d is either the merged results, or just $user->roles;
-//
-		return $d;
-
-} // end og_user_roles_all_roles()
-
-function getgid($nodeID, $uid) {
-
-	// This will return a $gid based upon the $nodeID and $uid supplied
-
-		$gid = 0;
-
-//		$result = db_query("select node_access.gid from node_access INNER JOIN og_uid ON node_access.gid = og_uid.nid WHERE node_access.realm = 'og_subscriber' AND og_uid.uid = $uid AND (node_access.nid = $nodeID OR node_access.gid = $nodeID)"); // modified to check for either the node or group ID in node_access
-		$result = db_query("select {node_access}.gid from {node_access} INNER JOIN {og_uid} ON {node_access}.gid = {og_uid}.nid WHERE {node_access}.realm = 'og_subscriber' AND {og_uid}.uid = %d AND ({node_access}.nid = %d OR {node_access}.gid = %d)", $uid, $nodeID, $nodeID); // FIXED TABLE PREFIX - modified to check for either the node or group ID in node_access
-		while($t = db_fetch_object($result)) {
-    		$gid = $t->gid;
-		}
-
-		// If $gid still equals 0 then try searching og_term table (if it exists)
-		// og forums will typically be listed here
-
-		if ($gid == 0) {
-			if (user_table_exists('{og_term}')) {
-//				$result = db_query("select og_term.nid from og_term INNER JOIN og_uid ON og_term.nid = og_uid.nid WHERE og_term.tid = $nodeID AND og_uid.uid = $uid");
-				$result = db_query("select {og_term}.nid from {og_term} INNER JOIN {og_uid} ON {og_term}.nid = {og_uid}.nid WHERE {og_term}.tid = %d AND {og_uid}.uid = %d", $nodeID, $uid); // FIXED TABLE PREFIX
-				while($t = db_fetch_object($result)) {
-    				$gid = $t->nid;
-				}
-			}
-		}
-
-		return $gid;
-
-} // end getgid()
-//
-// Modification - Added this function
-//
-function user_table_exists($table) {
-  return db_num_rows(db_query("SHOW TABLES LIKE '{" . db_escape_table($table) . "}'"));
-}
-
-function og_user_roles_write_test($user, $location, $gid02, $gid, $uri_request_id, $d, $query) {
-//
-// See what is found in user_all_roles
-//
-   	$testStatus = "";
-	$testDate = format_date(time(), 'custom', 'Y-m-d h:i:s a');
-	$testUser = $user->uid;
-	$testFunction = "og_user_roles_all_roles";
-	$testSubFunction = $location;
-	$testString = "group context: " . $gid02;
-	$testUserName = $user->name;
-	$testGroup = $gid;
-	$testURI = $uri_request_id;
-	$testAArg0 = arg(0);
-	$testAArg1 = arg(1);
-	$testAArg2 = arg(2);
-	$testAArg3 = arg(3);
-    $testPerm = "Roles Returned: (" . implode(",", $d) . ") <br>dbQuery = " . $query;
-	if (user_table_exists('{user_test}')) {
-		$testQuery = "insert into user_test (testStatus, testDate, testUser, testUserName, testGroup, testFunction, testSubFunction, testString, testURI, testAArg0, testAArg1, testAArg2, testAArg3, testPerm) values ('" . $testStatus . "','" . $testDate . "','" . $testUser . "','" . $testUserName . "','" . $testGroup . "','" . $testFunction . "','" . $testSubFunction . "','" . $testString . "','" . $testURI . "','" . $testAArg0 . "','" . $testAArg1 . "','" . $testAArg2 . "','" . $testAArg3 . "','" . $testPerm . "')";
-		db_query($testQuery);
-	}
-}
-
+  $result = db_query(db_rewrite_sql($sql, 'oga', 'group_nid'), '');
+
+  return $result;
+}
+
+
+//
+// My OG Roles Modifications
+//
+//
+// Modification - Added this function
+//
+// This function returns an array of role keys and names, like $user->roles
+// However, it returns site roles as well as group roles
+//
+function og_user_roles_all_roles_array($user) {
+  $roles = og_user_roles_all_roles($user);
+  return $roles;
+}
+
+// This function takes the global $user (or $account) value and returns a list
+// of group and non-group roles for this user
+function og_user_roles_all_roles($user) {
+  // This will be the process to get BOTH the group and non-group roles for a user
+  $uid = $user->uid;
+  $gid = 0;
+  $gids = array();
+  $nid = 0;
+  $location = 0;
+  $uri_request_id = $_SERVER['REQUEST_URI'];
+  $arg = explode("/", $uri_request_id);
+  $ogroles = array();
+  $x1 = 0;
+
+  //
+  // This will by default add the anonymous user role (no need since we merge user->roles)
+  //
+  // We get the groupID
+  //
+
+  $group_node = og_get_group_context();
+  $gid02 = $group_node->nid;
+  $gid = $gid02;
+  if ($gid02 === NULL) {
+    $gid = 0;
+  }
+
+  //
+  // If the above doesn't get the groupID, then we start trying stuff
+  //
+  if ($gid == 0) {
+    // http://doadance.scbbs.com/drupal03/node/79
+    if (arg(0) == 'node' && is_numeric(arg(1)) && is_null(arg(2))) {
+      $location = 1;
+      $nid = (int)arg(1);
+      $gid = getgid($nid, $uid);
+    }
+
+    // http://doadance.scbbs.com/node/79/edit
+    // http://doadance.scbbs.com/node/79/outline
+    // http://doadance.scbbs.com/node/79/track
+    if (arg(0) == 'node' && is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'outline' || arg(2) == 'track')) {
+        $location = 2;
+        $nid = (int)arg(1);
+        $gid = getgid($nid, $uid);
+      }
+
+    //                           0    1    2
+    // http://www.mysite.com/comment/edit/14
+    //
+    if (arg(0) == 'comment' && is_numeric(arg(2)) && arg(1) == 'edit') {
+      $location = 3;
+      $comment = _comment_load(arg(2));
+      $nid = $comment->nid;
+      $gid = getgid($nid, $uid);
+    }
+
+    //                           0      1    2
+    // http://www.mysite.com/comment/reply/128#comment_form
+    //
+    if (arg(0) == 'comment' && arg(1) == 'reply') {
+      $location = 4;
+      $subsections = explode("#", arg(2));
+      $nid = (int)$subsections[0];
+      $gid = getgid($nid, $uid);
+    }
+
+    // og_term access
+    //                        0    1    2    3
+    // http://www.mysite.com/node/add/forum/121
+    //
+    if (arg(0) == 'node' && is_numeric(arg(3)) && arg(1) == 'add') {
+      $location = 5;
+      $nid = (int)arg(3);
+      $gid = getgid($nid, $uid);
+    }
+
+    // Here we get the gid directly
+    //
+    // http://doadance.scbbs.com/node/79/view/tree
+    // http://doadance.scbbs.com/node/79/view/members
+    // http://doadance.scbbs.com/node/79/view
+    if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'view') {
+      $location = 2;
+      $gid = (int)arg(1);
+    }
+
+    // Here we get the gid directly
+    //
+    // http://doadance.scbbs.com/og/users/72
+    // http://doadance.scbbs.com/og/manage/72
+    if (arg(0) == 'og' && is_numeric(arg(2)) && is_null(arg(3))) {
+      $location = 6;
+      $gid = (int)arg(2);
+    }
+
+    // og_user_roles
+    //
+    // http://doadance.scbbs.com/og/users/72/roles
+    // http://doadance.scbbs.com/og/users/72/add
+    if (arg(0) == 'og' && arg(1) == 'users' && is_numeric(arg(2)) && is_null(arg(4))) {
+      $location = 6;
+      $gid = (int)arg(2);
+    }
+
+    // og unsubscribe
+    // og_user_roles
+    //
+    // This is sort of a catch all for "og" and gid in this order
+    // og/<whatever>/<gid>
+    //
+    // http://doadance.scbbs.com/og/unsubscribe/72
+    // http://doadance.scbbs.com/og/users/72/add
+    if (arg(0) == 'og' && is_numeric(arg(2))) {
+      $location = 6;
+      $gid = (int)arg(2);
+    }
+
+    // og_forum
+    //
+    // http://doadance.scbbs.com/og_forum/manage/72
+    if (arg(0) == 'og_forum' && arg(1) == 'manage' && is_numeric(arg(2)) && is_null(arg(3))) {
+      $location = 6;
+      $gid = (int)arg(2);
+    }
+
+    // http://doadance.scbbs.com/og_forum/manage/edit/72
+    // http://doadance.scbbs.com/og_forum/manage/add/72
+    if (arg(0) == 'og_forum' && arg(1) == 'manage' && is_numeric(arg(3))) {
+      $location = 6;
+      $gid = (int)arg(3);
+    }
+
+    // og_calendar
+    //
+    // http://doadance.scbbs.com/og_calendar/72
+    if (arg(0) == 'og_calendar' && is_numeric(arg(1)) && is_null(arg(2))) {
+      $location = 7;
+      $gid = (int)arg(1);
+    }
+
+    // og_forum
+    //         0           1    2       3
+    // http://www.mysite.com/og_forum/39/72?edit[og_groups][]=72
+    // http://www.mysite.com/og_forum/37/71?sort=asc&order=Replies&edit[og_groups][0]=71
+    if ($arg[1] == 'og_forum' && strpos($arg[3], 'og_groups') !== FALSE && (!is_null($arg[3]))) {
+      $location = 8;
+      $subsections = explode("=", $arg[3]);
+      foreach ($subsections as $subsection) {
+        if (is_numeric($subsection)) {
+          $gid = (int)$subsection;
+        }
+      }
+    }
+
+    // og create nodes (version 5.1)
+    //          0     1   2           3
+    // http://sbn.scbbs.com/node/add/forum?gids[]=72
+    // http://sbn.scbbs.com/node/add/simplenews?gids[]=72
+    // http://sbn.scbbs.com/node/add/webform?gids[]=72
+    // http://sbn.scbbs.com/node/add/video?gids[]=72
+    // http://sbn.scbbs.com/node/add/page?gids[]=72
+    // http://sbn.scbbs.com/node/add/blog?gids[]=72
+    // http://sbn.scbbs.com/node/add/event?gids[]=72
+    // http://sbn.scbbs.com/node/add/poll?gids[]=72
+    // http://sbn.scbbs.com/node/add/flexinode-3?gids[]=72
+    if ($arg[1] == 'node' && strpos($arg[3], 'gids') !== FALSE && (!is_null($arg[3]))) {
+      $location = 10 .'('. arg(0) .'|'. arg(1) .'|'. arg(2) .')';
+      $subsections = explode('=', $arg[3]);
+      $gid = (int)$subsections[1];
+    }
+
+    // og create nodes (custom node/20 aliased to node/ognodeadd)
+    //          0     1   2           3
+    // http://clients.brixrealtyinc.com/node/ognodeadd?type=document&gids[]=12
+    //
+    if ($arg[1] == 'node') {
+      if (strpos($arg[2], 'ognodeadd') !== FALSE) {
+        if (strpos($arg[2], 'gids') !== FALSE) {
+          $location = 13;
+          $subsections = explode('=', $arg[2]);
+          $gid = (int)$subsections[2];
+        }
+      }
+    }
+  } // end $gid if
+
+  //
+  // Now, using $uid and $gid we find out what roles this user has in this group;
+  //
+  if (empty($gid)) {
+    $gid = 0; // This prevents us from getting error on non-group node/add
+  }
+
+  $query = 'SELECT {role}.rid, {role}.name FROM {role} INNER JOIN {og_users_roles} ON {role}.rid = {og_users_roles}.rid WHERE {og_users_roles}.uid = %d AND {og_users_roles}.gid = %d'; // FIXED TABLE PREFIX
+  $results = db_query($query, $uid, $gid);
+
+  //
+  // Create an array of these roles;
+  //
+
+  while ($row = db_fetch_array($results)) {
+    $x1 = $row["rid"];
+    $ogroles[$x1] = $row["name"];
+  }
+
+  //
+  // First, we need to create an array of $user->roles
+  //
+  $c = $user->roles;
+
+  //
+  // Next, we add the $user->roles array to the $ogroles array, if there is an ogroles array;
+  //
+  if ($x1 > 0) {
+    $d = array();
+    $d = $c + $ogroles;
+    $d = array_unique($d);
+  }
+  else {
+    $d = $c;
+  }
+
+  // Write the test data
+  og_user_roles_write_test($user, $location, $gid02, $gid, $uri_request_id, $d, $query);
+
+//
+// $d is either the merged results, or just $user->roles;
+//
+
+  return $d;
+} // end og_user_roles_all_roles()
+
+function getgid($nid, $uid) {
+  // This will return a $gid based upon the $nid and $uid supplied
+  $gid = 0;
+  $result = db_query("select {node_access}.gid from {node_access} INNER JOIN {og_uid} ON {node_access}.gid = {og_uid}.nid WHERE {node_access}.realm = 'og_subscriber' AND {og_uid}.uid = %d AND ({node_access}.nid = %d OR {node_access}.gid = %d)", $uid, $nid, $nid); // FIXED TABLE PREFIX - modified to check for either the node or group ID in node_access
+  while ($t = db_fetch_object($result)) {
+    $gid = $t->gid;
+  }
+
+  // If $gid still equals 0 then try searching og_term table (if it exists)
+  // og forums will typically be listed here
+  if ($gid == 0) {
+    if (user_table_exists('{og_term}')) {
+      $result = db_query("select {og_term}.nid from {og_term} INNER JOIN {og_uid} ON {og_term}.nid = {og_uid}.nid WHERE {og_term}.tid = %d AND {og_uid}.uid = %d", $nid, $uid); // FIXED TABLE PREFIX
+      while ($t = db_fetch_object($result)) {
+        $gid = $t->nid;
+      }
+    }
+  }
+
+  return $gid;
+} // end getgid()
+
+//
+// Modification - Added this function
+//
+function user_table_exists($table) {
+  return db_num_rows(db_query("SHOW TABLES LIKE '{" . db_escape_table($table) . "}'"));
+}
+
+function og_user_roles_write_test($user, $location, $gid02, $gid, $uri_request_id, $d, $query) {
+  //
+  // See what is found in user_all_roles
+  //
+  $test_status = '';
+  $test_date = format_date(time(), 'custom', 'Y-m-d h:i:s a');
+  $test_user = $user->uid;
+  $test_function = 'og_user_roles_all_roles';
+  $test_subfunction = $location;
+  $test_string = 'group context: '. $gid02;
+  $test_username = $user->name;
+  $test_group = $gid;
+  $test_uri = $uri_request_id;
+  $test_aarg0 = arg(0);
+  $test_aarg1 = arg(1);
+  $test_aarg2 = arg(2);
+  $test_aarg3 = arg(3);
+  $test_perm = 'Roles Returned: ('. implode(",", $d) .') <br />dbQuery = '. $query;
+
+  if (user_table_exists('{user_test}')) {
+    $test_query = "INSERT INTO user_test (testStatus, testDate, testUser, testUserName, testGroup, testFunction, testSubFunction, testString, testURI, testAArg0, testAArg1, testAArg2, testAArg3, testPerm) values ('" . $test_status . "','" . $test_date . "','" . $test_user . "','" . $test_username . "','" . $test_group . "','" . $test_function . "','" . $test_subfunction . "','" . $test_string . "','" . $test_uri . "','" . $test_aarg0 . "','" . $test_aarg1 . "','" . $test_aarg2 . "','" . $test_aarg3 . "','" . $test_perm . "')";
+    db_query($test_query);
+  }
+}
+
 /**
  * Called by og_user_roles_nodeapi('access')
  * To check og access permissions
  *
-*/
+ */
 function og_user_roles_og_access_check($op, $node = NULL) {
   global $user;
-  $uid = $user->uid;
-
-  if ($op != 'create' && $node->nid && $node->status) {
-
-      if (isset($user) && is_array($user->og_groups)) {
-		$gids = array_keys($user->og_groups);
-      } 
-      else {
-        $gids[] = 0;
-      }
-
-
-      if (isset($user) && is_array($user->roles)) {
-        $rids = array_keys($user->roles);
-      } 
-      else {
-        $rids[] = 1;
-      }
-
-	//
-	// if this node has groups or is a group, then use group sql, else use non-group sql
-	//	
-
-	$groups = $node->og_groups;
-
-	if ($groups || $node->type == 'group') {
-
-	    $sql = "
-    	SELECT COUNT(*) FROM {node_access} na 
-			LEFT OUTER JOIN {og_uid} ogu on ogu.nid = na.nid 
-			LEFT OUTER JOIN {og} ogm on ogm.nid = na.nid 
-	    	WHERE (na.nid = 0 OR na.nid = %d) 
-    		AND ((na.realm = 'og_public' and na.gid = 0) 
-    		OR (na.realm = 'og_subscriber' AND na.gid in ('".implode("','",$gids)."')) 
-			OR (ogm.nid > 0 and (na.nid in ('".implode("','",$gids)."')) or ogm.directory = 1 ) 
-	    	OR (na.realm = 'term_access' AND na.nid in ('".implode("','",$gids)."')) ) 
-    		AND (na.grant_$op >= 1 OR (ogu.is_admin = 1 AND ogu.uid = ".$uid.") )
-    		";
-	} else {
-	    $sql = "
-    	SELECT COUNT(*) FROM {node_access} na 
-    		WHERE (na.nid = 0 OR na.nid = %d) 
-	    	AND (na.realm = 'term_access' AND na.gid in ('".implode("','",$rids)."')) 
-    		AND na.grant_$op >= 1
-    		";
-	}
-
-    $result = db_query($sql, $node->nid);
-    $output = (db_result($result));
-    if ($output == 0) return FALSE;
-    if ($output > 0) return TRUE;
-  }
-}
-
+  $uid = $user->uid;
+  if ($op != 'create' && $node->nid && $node->status) {
+    if (isset($user) && is_array($user->og_groups)) {
+      $gids = array_keys($user->og_groups);
+    }
+    else {
+      $gids[] = 0;
+    }
+
+    if (isset($user) && is_array($user->roles)) {
+      $rids = array_keys($user->roles);
+    }
+    else {
+      $rids[] = 1;
+    }
+
+    //
+    // if this node has groups or is a group, then use group sql, else use non-group sql
+    //
+    $groups = $node->og_groups;
+    if ($groups || $node->type == 'group') {
+      $sql = "
+        SELECT COUNT(*) FROM {node_access} na
+        LEFT OUTER JOIN {og_uid} ogu on ogu.nid = na.nid
+        LEFT OUTER JOIN {og} ogm on ogm.nid = na.nid
+        WHERE (na.nid = 0 OR na.nid = %d)
+        AND ((na.realm = 'og_public' and na.gid = 0)
+        OR (na.realm = 'og_subscriber' AND na.gid in (%s))
+        OR (ogm.nid > 0 and (na.nid in (%s)) or ogm.directory = 1)
+        OR (na.realm = 'term_access' AND na.nid in (%s)))
+        AND (na.grant_$op >= 1 OR (ogu.is_admin = 1 AND ogu.uid = %d))
+        ";
+      $group_ids = implode(',', $gids);
+      $result = db_query($sql, $node->nid, $group_ids, $group_ids, $group_ids, $uid);
+    }
+    else {
+      $sql = "
+        SELECT COUNT(*) FROM {node_access} na
+        WHERE (na.nid = 0 OR na.nid = %d)
+        AND (na.realm = 'term_access' AND na.gid in (%s))
+        AND na.grant_$op >= 1
+        ";
+      $result = db_query($sql, $node->nid, implode(',', $rids));
+    }
+
+    $output = (db_result($result));
+
+    if ($output == 0) {
+      return FALSE;
+    }
+    if ($output > 0) {
+      return TRUE;
+    }
+  }
+}
+
 /**
- * Called by og_user_roles_nodeapi('access')
+ * Called by og_user_roles_nodeapi('access')
  * To check taxonomy_access access permissions
  *
-*/
-function og_user_roles_taxonomy_access_check($op, $node = NULL) {
-  global $user;
-  $uid = $user->uid;
-
-  if ($op != 'create' && $node->nid && $node->status) {
-	// 	Discovered that I needed to continue using user->roles to get non-group roles.
-	//	will get group roles using og_users_roles and og_ancestry
-	//
+ */
+function og_user_roles_taxonomy_access_check($op, $node = NULL) {
+  global $user;
+
+  $uid = $user->uid;
+
+  if ($op != 'create' && $node->nid && $node->status) {
+  //  Discovered that I needed to continue using user->roles to get non-group roles.
+  //  will get group roles using og_users_roles and og_ancestry
+
     if (isset($user) && is_array($user->roles)) {
       $rids = array_keys($user->roles);
-    } 
+    }
     else {
       $rids[] = 1;
     }
-
-    $sql = "SELECT COUNT(*) FROM {node_access} na";
-    $sql .= " LEFT OUTER JOIN {og_users_roles} ogr ON ogr.rid = na.gid";
-    $sql .= " LEFT OUTER JOIN {og_ancestry} oga ON oga.nid = na.nid";
-	$sql .= " LEFT OUTER JOIN {og_uid} ogu on ogu.nid = na.nid";
-    $sql .= " WHERE (na.nid = 0 OR na.nid = %d) AND ((na.realm = 'term_access' AND na.gid in ('".implode("','",$rids)."')) OR (ogr.uid = " . $uid . " AND na.realm = 'term_access' AND oga.group_nid = ogr.gid) )";
-    $sql .= " AND (na.grant_$op >= 1 OR (ogu.is_admin = 1 AND ogu.uid = ".$uid.") )";
-    $result = db_query($sql, $node->nid);
-    $output = (db_result($result));
-    if ($output == 0) return FALSE;
-    if ($output > 0) return TRUE;
-  }
-}
-
+
+    $sql = "SELECT COUNT(*) FROM {node_access} na";
+    $sql .= " LEFT OUTER JOIN {og_users_roles} ogr ON ogr.rid = na.gid";
+    $sql .= " LEFT OUTER JOIN {og_ancestry} oga ON oga.nid = na.nid";
+    $sql .= " LEFT OUTER JOIN {og_uid} ogu on ogu.nid = na.nid";
+    $sql .= " WHERE (na.nid = 0 OR na.nid = %d) AND ((na.realm = 'term_access' AND na.gid in (%s)) OR (ogr.uid = %d AND na.realm = 'term_access' AND oga.group_nid = ogr.gid))";
+    $sql .= " AND (na.grant_$op >= 1 OR (ogu.is_admin = 1 AND ogu.uid = %d))";
+
+    $result = db_query($sql, $node->nid, implode(',', $rids), $uid, $uid);
+    $output = (db_result($result));
+
+    if ($output == 0) {
+      return FALSE;
+    }
+    if ($output > 0) {
+      return TRUE;
+    }
+  }
+}
+
 /**
- * Create content
+ * Create content
  *
- * Format: http://www.scbbs.com/node/ognodeadd?type=link&gids[]=29
+ * Format: http://www.scbbs.com/node/ognodeadd?type=link&gids[]=29
  *
-*/
-function og_user_roles_ognodeadd() {
-	global $user;
-	$roles = og_user_roles_all_roles($user); // This returns normal $user->roles and includes OG roles if any
-	$user->roles = $roles;
-
-	$gids = $_GET['gids'];
-
-	$typeFound = 'no';
-
-	if ($gids) {
-	   $group_node = node_load($gids[0]);
-	   og_set_group_context($group_node);
-	}
-
-	$type = $_GET['type'];
-
-	if ($type) { 
-		//
-		// Got this from node.module (node_access)
-  		// No matter the type, this should return us the create permission.
-		//
-  		$module = node_get_types('module', $type);
-  		if ($module == 'node') {
-    		$module = 'node_content'; // Avoid function name collisions.
-  		}
-  		$access = module_invoke($module, 'access', 'create', $type);
-	   	if ($access === TRUE) {
-	     	$output = node_add($type);
-	   	} else {
-			$output = "Access denied.";
-			watchdog("access denied", "node/ognodeadd?type=" . $type . "&gids[]=" . $gids[0], WATCHDOG_WARNING);
-		}
-	}
-	return $output;
+ */
+function og_user_roles_ognodeadd() {
+  global $user;
+
+  $roles = og_user_roles_all_roles($user); // This returns normal $user->roles and includes OG roles if any
+
+  $user->roles = $roles;
+  $gids = $_GET['gids'];
+  if ($gids) {
+     $group_node = node_load($gids[0]);
+     og_set_group_context($group_node);
+  }
+
+  $type = $_GET['type'];
+
+  if ($type) {
+    //
+    // Got this from node.module (node_access)
+    // No matter the type, this should return us the create permission.
+    //
+    $module = node_get_types('module', $type);
+
+    if ($module == 'node') {
+      $module = 'node_content'; // Avoid function name collisions.
+    }
+
+    $access = module_invoke($module, 'access', 'create', $type);
+
+    if ($access === TRUE) {
+      $output = node_add($type);
+    }
+    else {
+      $output = 'Access denied.';
+      watchdog('access denied', 'node/ognodeadd?type='. $type .'&gids[]='. $gids[0], WATCHDOG_WARNING);
+    }
+  }
+
+  return $output;
 }
\ No newline at end of file
