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.15.2.3
diff -u -p -r1.1.2.15.2.3 og_user_roles.module
--- og_user_roles.module	20 Dec 2008 02:25:19 -0000	1.1.2.15.2.3
+++ og_user_roles.module	29 Dec 2008 16:33:16 -0000
@@ -18,10 +18,10 @@ function og_user_roles_help($path, $arg)
 
 /**
  * Implementation of hook_perm().
- * 
- * Modification as per: http://drupal.org/node/192747
- * Added 'administer og_user_roles'
- *
+ * 
+ * Modification as per: http://drupal.org/node/192747
+ * Added 'administer og_user_roles'
+ *
  */
 function og_user_roles_perm() {
   return array('administer og_user_roles', 'configure member roles', 'create og_subgroups', 'manage registration codes', 'use registration codes', 'no oguseredit');
@@ -59,10 +59,10 @@ function og_user_roles_admin_settings() 
   }
 
   // If no assignable roles, advise user to add some.
-  // Modification as per: http://drupal.org/node/167373 
+  // Modification as per: http://drupal.org/node/167373 
   if (!count($roles)) {
     $form['og_user_roles'] = array(					  
-      '#value' => '<p>'. t('No assignable roles were found. Please create at least one role under !roles.', array('!roles' => l(t('Administer >> User management >> Roles'), 'admin/user/roles'))) .'</p>',
+      '#value' => '<p>'. t('No assignable roles were found. Please create at least one role under !roles.', array('!roles' => l(t('Administer >> User management >> Roles'), 'admin/user/roles'))) .'</p>',
     );
     return $form;
   }
@@ -107,7 +107,7 @@ function og_user_roles_admin_settings() 
     '#default_value' => variable_get('og_user_roles_assign_regcode_gid', 0),
     '#description' => t('Do you wish to allow Group Admins to define "Registration Codes" to allow users to subscribe to their groups without admin approval? The Group Admin will be able to define the Registration Codes on <b>edit</b> (not creation) of the group node.  Group Admin must have <b>manage registration codes</b> permission.'),
   );
-
+
   $form['og_user_roles_approval'] = array(
     '#type' => 'fieldset',
     '#title' => t('Allow group admins to approve new signups.'),
@@ -121,7 +121,7 @@ function og_user_roles_admin_settings() 
     '#default_value' => variable_get('og_user_roles_approval_default', 0),
     '#description' => t('<strong>If your site requires administrator approval for signups</strong>: When a user registers and elects to subscribe to a group (group is on registration form), then the admin of the group will receive an email notification of the pending signup and be allowed to approve it.  Note that this requires that the group admin have a group role which includes the <strong>administer users</strong> permission.'),
   );
-
+
   $form['og_user_roles_default'] = array(
     '#type' => 'fieldset',
     '#title' => t('Default Non-Group Role for new users.'),
@@ -176,7 +176,7 @@ function og_user_roles_admin_settings() 
     '#default_value' => variable_get('og_user_roles_assign_basicgrouprole_gid', 0),
     '#description' => t('Do you wish to allow Group Admins to define a specific "basic group role" for <b>every new subscriber to their group</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\' admin(s).  The Group Admin will be able to define the default group role on <b>edit</b> (not creation) of the group node.  Group Admin must have <b>configure member roles</b> permission.'),
   );
-
+
   $form['og_user_roles_founder'] = array(
     '#type' => 'fieldset',
     '#title' => t('Default Founder Role for users who create groups.'),
@@ -218,7 +218,7 @@ function og_user_roles_admin_settings() 
     '#default_value' => variable_get('og_user_roles_admingrouprole_value', 0),
     '#description' => t('Select the role you wish to use as the "group administrator role" for every new group administrator.'),
   );
-
+
   $form['og_user_roles_notify'] = array(
     '#type' => 'fieldset',
     '#title' => t('Default Group Admin Notification for new subscribers.'),
@@ -253,21 +253,21 @@ function og_user_roles_admin_settings() 
     '#type' => 'fieldset',
     '#title' => t('TAC / OG Access Control Integration.'),
   );
-
-  // Check to see if taxonomy_access is installed. 
-  $taxonomy_access = "not installed";
-  $disabled = 1;
-  if (module_exists("taxonomy_access")) {
-    $disabled = 0;
-	$taxonomy_access = 'installed';
-  }
-
+
+  // Check to see if taxonomy_access is installed. 
+  $taxonomy_access = "not installed";
+  $disabled = 1;
+  if (module_exists("taxonomy_access")) {
+    $disabled = 0;
+	$taxonomy_access = 'installed';
+  }
+
   $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?  Note that this feature requires that you install the ' . l("Taxonomy Access Control Module", "http://www.drupal.org/project/taxonomy_access") . '.  The <b>taxonomy_access.module</b> is currently <b>' . $taxonomy_access . '</b>.  Details here: ' . l("How to Make OG and TAC Work Together: Step 2", "http://groups.drupal.org/node/3700")),
-    '#disabled' => $disabled,
+    '#disabled' => $disabled,
   );
 
   if (module_exists('og_subgroups')) {
@@ -292,7 +292,7 @@ function og_user_roles_admin_settings() 
       '#description' => t('Select the group type you wish to use for subgroup creation.'),
     );
   }
-
+
   $form['og_user_roles_clear_cache'] = array(
     '#type' => 'fieldset',
     '#title' => t('Clear the cache?'),
@@ -307,7 +307,7 @@ function og_user_roles_admin_settings() 
     '#default_value' => variable_get('og_user_roles_clear_cache_value', 0),
     '#description' => t($description),
   );						 
-
+
   $form['og_user_roles_test'] = array(
     '#type' => 'fieldset',
     '#title' => t('Test/Debug.'),
@@ -320,52 +320,52 @@ function og_user_roles_admin_settings() 
     '#default_value' => variable_get('og_user_roles_test_default', 0),
     '#description' => t('Every time user_access() is called, it will call og_user_all_roles() which adds group roles to $user->roles.  Do you wish to see the output from this function? (Note that this feature is for testing/debug purposes, and could create a very large output file.  This feature also requires that the table og_user_test already exist. Details here: ' . l("OG User Roles: Test", "http://drupal.org/node/164038")),
   );
-
-  $form['og_user_roles_menu_options'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Group Menu Options.'),
-    '#description' => t('Give group admins control of the display of OGUR and default OG create links in the groups menu.'),
-    '#collapsible' => TRUE,
+
+  $form['og_user_roles_menu_options'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Group Menu Options.'),
+    '#description' => t('Give group admins control of the display of OGUR and default OG create links in the groups menu.'),
+    '#collapsible' => TRUE,
     '#collapsed' => TRUE,
-   );
-  $form['og_user_roles_menu_options']['og_user_roles_menu_options_enabled'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Enable menu control?'),
-    '#default_value' => variable_get('og_user_roles_menu_options_enabled', 1),
-    '#description' => t("This will add two form elements, inside a field set, to the OG node's edit page, enabling this feature."),
-   );
-
-  $form['og_user_roles_logo'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Group Logo Attributes.'),
-    '#description' => t('Group admins can upload a logo for their group. Here you enter the maximum width and height attributes for Group Logos.'),
-    '#collapsible' => TRUE,
+   );
+  $form['og_user_roles_menu_options']['og_user_roles_menu_options_enabled'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Enable menu control?'),
+    '#default_value' => variable_get('og_user_roles_menu_options_enabled', 1),
+    '#description' => t("This will add two form elements, inside a field set, to the OG node's edit page, enabling this feature."),
+   );
+
+  $form['og_user_roles_logo'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Group Logo Attributes.'),
+    '#description' => t('Group admins can upload a logo for their group. Here you enter the maximum width and height attributes for Group Logos.'),
+    '#collapsible' => TRUE,
     '#collapsed' => TRUE,
-    );
-  $form['og_user_roles_logo']['og_user_roles_logo_enabled'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Enable group logo?'),
-    '#default_value' => variable_get('og_user_roles_logo_enabled', 1),
-    '#description' => t("This will add a text box onto the OG node's edit page, enabling this feature."),
-   );
-  $form['og_user_roles_logo']['og_user_roles_logo_width'] = array(
-    '#type' => 'textfield',
-    '#size' => 10,
-    '#title' => t('Maximum width for display of group logo?'),
-    '#default_value' => variable_get('og_user_roles_logo_width', '135'),
-    '#description' => t('Enter the maximum pixel (px) width at which group logos will be displayed'),
-    );
-  $form['og_user_roles_logo']['og_user_roles_logo_height'] = array(
-    '#type' => 'textfield',
-    '#size' => 10,
-    '#title' => t('Maximum height for display of group logo?'),
-    '#default_value' => variable_get('og_user_roles_logo_height', '113'),
-    '#description' => t('Enter the maximum pixel (px) height at which group logos will be displayed'),
-    );
-
+    );
+  $form['og_user_roles_logo']['og_user_roles_logo_enabled'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Enable group logo?'),
+    '#default_value' => variable_get('og_user_roles_logo_enabled', 1),
+    '#description' => t("This will add a text box onto the OG node's edit page, enabling this feature."),
+   );
+  $form['og_user_roles_logo']['og_user_roles_logo_width'] = array(
+    '#type' => 'textfield',
+    '#size' => 10,
+    '#title' => t('Maximum width for display of group logo?'),
+    '#default_value' => variable_get('og_user_roles_logo_width', '135'),
+    '#description' => t('Enter the maximum pixel (px) width at which group logos will be displayed'),
+    );
+  $form['og_user_roles_logo']['og_user_roles_logo_height'] = array(
+    '#type' => 'textfield',
+    '#size' => 10,
+    '#title' => t('Maximum height for display of group logo?'),
+    '#default_value' => variable_get('og_user_roles_logo_height', '113'),
+    '#description' => t('Enter the maximum pixel (px) height at which group logos will be displayed'),
+    );
+
   $form['og_user_roles_counter'] = array(
     '#type' => 'textfield',
-    '#size' => 10,
+    '#size' => 10,
     '#title' => t('Counter for <b>og_users_roles</b> table'),
     '#default_value' => variable_get('og_user_roles_counter', 0),
     '#description' => t('This is the counter for the <b>og_users_roles</b> table. You do not need to set this.  It will update itself.  It should NOT be set lower than the number of records currently in the table.'),
@@ -373,7 +373,7 @@ function og_user_roles_admin_settings() 
 
   return system_settings_form($form);
 }
-
+
 /**
  * Implementation of hook_theme()
  */
@@ -384,65 +384,65 @@ function og_user_roles_theme() {
     ),
   );
 }
-
+
 /**
  * Generate multinode access UI form.
  */
 function og_user_roles_multinode() {
-  global $user;
-  if (isset($uid)) {
-    $account = user_load(array('uid' => $uid));
-  } else {
-    $account = $user;
-    $uid = $user->uid; 
-  }
-     
-  // Get whatever is stored in multinode table.
-  $existing = array();
+  global $user;
+  if (isset($uid)) {
+    $account = user_load(array('uid' => $uid));
+  } else {
+    $account = $user;
+    $uid = $user->uid; 
+  }
+     
+  // Get whatever is stored in multinode table.
+  $existing = array();
   $result = db_query("SELECT * FROM {multinode_access}");
   while ($row = db_fetch_object($result)) {
     $existing[$row->realm] = $row;
   }
-
-  // Get all rule realms from node_access table.
-  $result = db_query("SELECT DISTINCT realm FROM {node_access}");
-   while ($row = db_fetch_object($result)) {
-    $rules[] = $row->realm;
-   }    
-
-  // Get all rule realms from modules.  User doing this should have grants in all modules affected.
-  $op = 'view';
-  $mrules = node_access_grants($op, $account);
-  foreach ($mrules as $realm => $grants) {
-    $rules[] = $realm;
-  }
-  
-  // Get only unique values
-  $rules = array_unique($rules);
-    
-  // Sort the rule realms
-  asort($rules);
-
+
+  // Get all rule realms from node_access table.
+  $result = db_query("SELECT DISTINCT realm FROM {node_access}");
+   while ($row = db_fetch_object($result)) {
+    $rules[] = $row->realm;
+   }    
+
+  // Get all rule realms from modules.  User doing this should have grants in all modules affected.
+  $op = 'view';
+  $mrules = node_access_grants($op, $account);
+  foreach ($mrules as $realm => $grants) {
+    $rules[] = $realm;
+  }
+  
+  // Get only unique values
+  $rules = array_unique($rules);
+    
+  // Sort the rule realms
+  asort($rules);
+
   $form = array('#tree' => TRUE);
-  foreach ($rules as $realm) {
-    $form[$realm]['checkbox'] = array('#type' => 'checkbox', '#default_value' => (isset($existing[$realm]->realm) ? 1 : 0)); 
-    $form[$realm]['realm'] = array('#type' => 'textfield', '#size' => 25, '#disabled' => TRUE, '#value' => check_plain($realm), '#default_value' => $realm); 
-    $form[$realm]['group'] = array('#type' => 'textfield', '#size' => 5, '#default_value' => (isset($existing[$realm]->groupname) ? $existing[$realm]->groupname : '') ); 
-    $form[$realm]['logic'] = array('#type' => 'select', '#default_value' => (isset($existing[$realm]->logic) ? $existing[$realm]->logic : 'AND'), '#options' => array('AND' => 'AND', 'OR' => 'OR') ); 
-    $form[$realm]['weight'] = array('#type' => 'select', '#default_value' => (isset($existing[$realm]->weight) ? $existing[$realm]->weight : '0'), '#options' => array('0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9') ); 
-    $form[$realm]['check'] = array('#type' => 'select', '#default_value' => (isset($existing[$realm]->checkstatus) ? $existing[$realm]->checkstatus : '0'), '#options' => array('0' => '0', '1' => '1') ); 
-  }
-
+  foreach ($rules as $realm) {
+    $form[$realm]['checkbox'] = array('#type' => 'checkbox', '#default_value' => (isset($existing[$realm]->realm) ? 1 : 0)); 
+    $form[$realm]['realm'] = array('#type' => 'textfield', '#size' => 25, '#disabled' => TRUE, '#value' => check_plain($realm), '#default_value' => $realm); 
+    $form[$realm]['group'] = array('#type' => 'textfield', '#size' => 5, '#default_value' => (isset($existing[$realm]->groupname) ? $existing[$realm]->groupname : '') ); 
+    $form[$realm]['logic'] = array('#type' => 'select', '#default_value' => (isset($existing[$realm]->logic) ? $existing[$realm]->logic : 'AND'), '#options' => array('AND' => 'AND', 'OR' => 'OR') ); 
+    $form[$realm]['weight'] = array('#type' => 'select', '#default_value' => (isset($existing[$realm]->weight) ? $existing[$realm]->weight : '0'), '#options' => array('0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9') ); 
+    $form[$realm]['check'] = array('#type' => 'select', '#default_value' => (isset($existing[$realm]->checkstatus) ? $existing[$realm]->checkstatus : '0'), '#options' => array('0' => '0', '1' => '1') ); 
+  }
+
   $form['submit'] = array('#type' => 'submit', '#value' => t('Save changes'));
-
+
   $form['#theme'] = 'og_user_roles_multinode';
-
-  return $form;
-
-}
-
+
+  return $form;
+
+}
+
 /**
- * Theme function to render the table for the og_user_roles_multinode 
+ * Theme function to render the table for the og_user_roles_multinode 
  * Multinode access UI
  */
 function theme_og_user_roles_multinode($form) {
@@ -460,31 +460,31 @@ function theme_og_user_roles_multinode($
   }
 
   $output .= theme('table', $header, $rows, array('id' => 'og-roles-multinode-table'));
-
-  // This is an OGUR restriction: Do not show "submit" button if 
-  // TAC/OG Integration not turned on.
-  if (variable_get('og_user_roles_tac_og_value', 0) == 1) {
-    $output .= drupal_render($form['submit']);
-  } else {
+
+  // This is an OGUR restriction: Do not show "submit" button if 
+  // TAC/OG Integration not turned on.
+  if (variable_get('og_user_roles_tac_og_value', 0) == 1) {
+    $output .= drupal_render($form['submit']);
+  } else {
     $output .= '<div id="comments">'. t('<strong>TAC/OG Integration is OFF</strong>.') ."</div>\n";
   }
-
+
   $output .= "</div>\n";
   $output .= drupal_render($form);
   return $output;
 }
-
+
 /**
  * Process multinode form submission.
  */
 function og_user_roles_multinode_submit($form, &$form_state) {
-  // Erase all existing settings
-  db_query ("DELETE FROM {multinode_access}");
-
-  // Insert new settings
+  // Erase all existing settings
+  db_query ("DELETE FROM {multinode_access}");
+
+  // Insert new settings
   foreach ($form_state['values'] as $block) {
-    if ($block['checkbox'] == 1) {
-      db_query("INSERT INTO {multinode_access} (realm, groupname, logic, weight, checkstatus) VALUES ('%s','%s','%s','%s',%d)", $block['realm'], $block['group'], $block['logic'], $block['weight'], $block['check']);
+    if ($block['checkbox'] == 1) {
+      db_query("INSERT INTO {multinode_access} (realm, groupname, logic, weight, checkstatus) VALUES ('%s','%s','%s','%s',%d)", $block['realm'], $block['group'], $block['logic'], $block['weight'], $block['check']);
 	}
   }
   drupal_set_message(t('The multinode access settings have been updated.'));
@@ -495,8 +495,8 @@ function og_user_roles_multinode_submit(
  * Implementation of hook_menu().
  */
 function og_user_roles_menu() {
-  global $user;
-    
+  global $user;
+    
   $items = array();
 
     $items['admin/og/og_user_roles'] = array(
@@ -504,8 +504,8 @@ function og_user_roles_menu() {
       'description' => 'Allows group administrators to add members into group roles.   Also edit multinode access configuration.',
       'page callback' => 'drupal_get_form',
       'page arguments' => array('og_user_roles_admin_settings'),
-      'access callback' => 'user_access',
-      'access arguments' => array('administer og_user_roles'),
+      'access callback' => 'user_access',
+      'access arguments' => array('administer og_user_roles'),
     );
     $items['admin/og/og_user_roles/settings'] = array(
       'title' => t('General'),
@@ -516,8 +516,8 @@ function og_user_roles_menu() {
       'title' => t('Configure multinode UI'),
       'page callback' => 'drupal_get_form',
       'page arguments' => array('og_user_roles_multinode'),
-      'access callback' => 'user_access',
-      'access arguments' => array('administer site configuration'),
+      'access callback' => 'user_access',
+      'access arguments' => array('administer site configuration'),
       'weight' => 10,
       'type' => MENU_LOCAL_TASK,
      );  
@@ -539,20 +539,20 @@ function og_user_roles_menu() {
       'access callback' => 'user_is_logged_in',
       'type' => MENU_CALLBACK
     );
-    $items['oguseredit/%'] = array(
-      'title' => 'Edit user',
-      'page callback' => 'og_user_roles_oguseredit',
-      'page arguments' => array(1),
-      'access callback' => 'user_is_logged_in',
-      'type' => MENU_CALLBACK
-    );
-    $items['ogusermanage/%'] = array(
-      'title' => 'Manage users',
-	  'page callback' => 'og_user_roles_user_manage',
-      'page arguments' => array(1),
-      'access callback' => 'user_is_logged_in',
-      'type' => MENU_CALLBACK
-    );
+    $items['oguseredit/%'] = array(
+      'title' => 'Edit user',
+      'page callback' => 'og_user_roles_oguseredit',
+      'page arguments' => array(1),
+      'access callback' => 'user_is_logged_in',
+      'type' => MENU_CALLBACK
+    );
+    $items['ogusermanage/%'] = array(
+      'title' => 'Manage users',
+	  'page callback' => 'og_user_roles_user_manage',
+      'page arguments' => array(1),
+      'access callback' => 'user_is_logged_in',
+      'type' => MENU_CALLBACK
+    );
     $items['og/regcode'] = array(
       'title' => 'Enter registration code',
       'page callback' => 'drupal_get_form',
@@ -562,21 +562,21 @@ function og_user_roles_menu() {
       'weight' => 10,
       'type' => MENU_LOCAL_TASK,
      );  
-    //
-	// Not sure if putting $user->uid in array will work here
-	//
+    //
+	// Not sure if putting $user->uid in array will work here
+	//
     $items['oglogo'] = array(
       'title' => 'Group Logo',
       'page callback' => 'og_user_roles_oglogo',
-      'callback arguments' => array($user->uid),
+      'callback arguments' => array($user->uid),
       'access callback' => 'user_access',
-      'access arguments' => array('access print'),
+      'access arguments' => array('access print'),
       'type' => MENU_CALLBACK
     );
-
-    // modr8 modification - using my own access callback
+
+    // modr8 modification - using my own access callback
     if (module_exists('modr8')) {
-      $items['node/%/ogmodr8'] = array(
+      $items['node/%/ogmodr8'] = array(
         'title' => 'Moderate',
         'page callback' => 'og_user_roles_modr8_page',
         'page arguments' => array(1),
@@ -584,10 +584,10 @@ function og_user_roles_menu() {
         'access arguments' => array(1, 'moderate content'),
         'weight' => 5,
         'type' => MENU_LOCAL_TASK);
-    }
-
+    }
+
     // Add another tab to the group subscribers page for admins to
-    // configure member roles
+    // configure member roles
 	// Modified og_user_roles_allowed to apply user_access('configure member roles')
     $items['og/users/%/roles'] = array(
       'title' => 'Configure member roles',
@@ -598,9 +598,9 @@ function og_user_roles_menu() {
       'weight' => 5,
       'type' => MENU_LOCAL_TASK
     );
-
+
     // Add another tab to the group subscribers page for admins to
-    // manage users
+    // manage users
     $items['og/users/%/manage'] = array(
       'title' => 'Manage users',
       'page callback' => 'og_user_roles_user_manage',
@@ -618,7 +618,7 @@ function og_user_roles_menu() {
  * Menu callback; displays members and role selection
  */
 function og_user_roles_page($gid) {
-
+
   $output = '';
   $node = node_load($gid);
   // Get roles associated with this group. We rebuild the associative
@@ -634,16 +634,16 @@ function og_user_roles_page($gid) {
   if (is_array($roles)) {
     // Retrieve list of all group users
     $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);
+    $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);
+    $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.'));
   }
 
   drupal_set_title(t('Subscribers') .': '. l($node->title, "node/$node->nid"));
-  
+  
   return $output;
 }
 
@@ -655,14 +655,14 @@ function og_user_roles_modr8_page($nid) 
   
 //  $count_sql = db_rewrite_sql('SELECT COUNT(*) FROM {node} n WHERE n.status = 1 AND n.moderate = 1 AND n.nid = '.$nid);
 //  $page_sql = db_rewrite_sql('SELECT n.nid FROM {node} n WHERE n.status = 1 AND n.moderate = 1 AND n.nid = '.$nid.' ORDER BY n.changed DESC');
-  $is_published = '';
-  if (!user_access('administer nodes')) {
-    // Users who don't have the 'administer nodes' permission can only see published nodes.
-    $is_published = 'n.status = 1 AND ';
-  }
-
-  $count_sql = db_rewrite_sql('SELECT COUNT(*) FROM {node} n WHERE '. $is_published .' n.moderate = 1 AND n.nid = '.$nid);
-  $page_sql = db_rewrite_sql('SELECT n.nid FROM {node} n WHERE '. $is_published .' n.moderate = 1 AND n.nid = '.$nid.' ORDER BY n.changed DESC');
+  $is_published = '';
+  if (!user_access('administer nodes')) {
+    // Users who don't have the 'administer nodes' permission can only see published nodes.
+    $is_published = 'n.status = 1 AND ';
+  }
+
+  $count_sql = db_rewrite_sql('SELECT COUNT(*) FROM {node} n WHERE '. $is_published .' n.moderate = 1 AND n.nid = '.$nid);
+  $page_sql = db_rewrite_sql('SELECT n.nid FROM {node} n WHERE '. $is_published .' n.moderate = 1 AND n.nid = '.$nid.' ORDER BY n.changed DESC');
   $result = pager_query($page_sql, variable_get('modr8_nodes_per_page', 10), 0, $count_sql);
   
   $output = '';
@@ -677,19 +677,19 @@ function og_user_roles_modr8_page($nid) 
   }
   return $output;
 }
-
+
 /**
  * Form for user roles page.
  */
 function og_user_roles_page_form($form_values, $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('query' => "destination=og/users/$gid")) .')';
 
     $form['user_roles']['roles'][$account->uid] = array(
@@ -723,10 +723,10 @@ function og_user_roles_page_form_submit(
       $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) {
 	    $ogr_id = variable_get('og_user_roles_counter', 0) + 1;
-        variable_set('og_user_roles_counter', $ogr_id);
+        variable_set('og_user_roles_counter', $ogr_id);
         db_query("INSERT INTO {og_users_roles} (uid, rid, gid, ogr_id) VALUES (%d, %d, %d, %d)", $uid, $rid, $gid, $ogr_id);
-        $args['rid'] = $rid;
-        $args['ogr_id'] = $ogr_id;
+        $args['rid'] = $rid;
+        $args['ogr_id'] = $ogr_id;
         module_invoke_all('og', 'user update', $gid, $uid, $args);
       }
       elseif (!$checked && $exists) {
@@ -813,13 +813,13 @@ function og_user_roles_is_allowed($nid) 
  *
  * @param $uid the user ID
  * @param $rid the role ID
- * @param $gid node ID of the group for the user in this role
- *
- * There is no return parameter, but "hook_og()" is invoked with args:
+ * @param $gid node ID of the group for the user in this role
+ *
+ * There is no return parameter, but "hook_og()" is invoked with args:
  * 'rid' (role ID) and 'ogr_id' (og_users_roles table ID for the newly created record).
  */
 function og_user_roles_role_join($uid, $rid, $gid) {
-  // Modification.  http://drupal.org/node/174773
+  // Modification.  http://drupal.org/node/174773
   // Check to see if this user doesn't already have this role in this group;
   // If not, then assign it.
   $sql = "SELECT COUNT(*) FROM {og_users_roles} WHERE uid = %d AND rid = %d and gid = %d";
@@ -828,13 +828,13 @@ function og_user_roles_role_join($uid, $
 
   if ($output == 0) {
     $ogr_id = variable_get('og_user_roles_counter', 0) + 1;
-    variable_set('og_user_roles_counter', $ogr_id);
+    variable_set('og_user_roles_counter', $ogr_id);
     db_query("INSERT INTO {og_users_roles} (uid, rid, gid, ogr_id) VALUES (%d, %d, %d, %d)", $uid, $rid, $gid, $ogr_id);
-    $args['rid'] = $rid;
-    $args['ogr_id'] = $ogr_id;
+    $args['rid'] = $rid;
+    $args['ogr_id'] = $ogr_id;
     module_invoke_all('og', 'user update', $gid, $uid, $args);
-  }
-}
+  }
+}
 
 /**
  * Remove all roles for a user in a group table.
@@ -842,27 +842,27 @@ function og_user_roles_role_join($uid, $
 function og_user_roles_role_leave($uid, $gid) {
   db_query("DELETE FROM {og_users_roles} WHERE uid = %d AND gid = %d", $uid, $gid);
 }
-
+
 /**
  * Remove all roles for a group node that has been deleted.
  */
 function og_user_roles_role_remove($gid) {
   db_query("DELETE FROM {og_users_roles} WHERE gid = %d", $gid);
 }
-
+
 /**
  * Remove this role from this user in this group.
  */
 function og_user_roles_role_delete($uid, $rid, $gid) {
   db_query("DELETE FROM {og_users_roles} WHERE uid = %d AND gid = %d AND rid = %d", $uid, $gid, $rid);
 }
-
+
 /**
  * Remove og_user_roles variables for a group node that has been deleted.
  */
 function og_user_roles_variable_remove($gid) {
-  if (variable_get('og_user_roles_basicgrouprole_value_' . $gid, 0)) variable_del('og_user_roles_basicgrouprole_value_' . $gid);  
-  if (variable_get('og_user_roles_assign_basicgrouprole_' . $gid, 0)) variable_del('og_user_roles_assign_basicgrouprole_' . $gid);  
+  if (variable_get('og_user_roles_basicgrouprole_value_' . $gid, 0)) variable_del('og_user_roles_basicgrouprole_value_' . $gid);  
+  if (variable_get('og_user_roles_assign_basicgrouprole_' . $gid, 0)) variable_del('og_user_roles_assign_basicgrouprole_' . $gid);  
 }
 
 /**
@@ -937,9 +937,9 @@ function og_user_roles_views_tables() {
       'right' => array(
         'field' => 'uid'
       ),
-      'extra' => array(
-        'gid' => '***CURRENT_GID***'
-      ),
+      'extra' => array(
+        'gid' => '***CURRENT_GID***'
+      ),
     ),
     'filters' => array(
       'rid' => array(
@@ -1018,10 +1018,10 @@ function views_handler_filter_group() {
   $list = array();
   $list = og_get_types('group');
 
-// Modification as per: http://drupal.org/node/184357
-  $group_types = implode("','", $list);
+// Modification as per: http://drupal.org/node/184357
+  $group_types = implode("','", $list);
   $vids = array();
-  $result = db_query("SELECT n.nid, n.title FROM {node} n WHERE n.type IN ('".$group_types."') ORDER BY n.title");
+  $result = db_query("SELECT n.nid, n.title FROM {node} n WHERE n.type IN ('".$group_types."') ORDER BY n.title");
   while ($obj = db_fetch_object($result)) {
     $vids[$obj->nid] = $obj->title;
   }
@@ -1030,7 +1030,7 @@ function views_handler_filter_group() {
 }
 
 /**
- * Based on og_handler_filter_picg
+ * Based on og_handler_filter_picg
  * Should restrict queries that use og_users_roles table to the current group. 
  *
  * @return void
@@ -1039,31 +1039,31 @@ function og_user_roles_handler_filter($o
   $query->ensure_table('og_users_roles');
   $query->add_where("og_users_roles.gid = ***CURRENT_GID***");
 }
-
-/**
- * views_handler
- * Create list of roles for this group type
-*/
-function og_user_roles_filter_role() {
-  $node = og_get_group_context();
-  $roles = array();
-  if ($node->type) {
-    $group = $node->type;
-  } else {
-    $group = 'group';
-  }
-  // 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_{$group}", array());
-  $all_roles = user_roles();
-  foreach ($role_ids as $rid => $checked) {
-    if ($checked != 0) {
-      $roles[$rid] = $all_roles[$rid];
-    }
-  }
-  return $roles;
+
+/**
+ * views_handler
+ * Create list of roles for this group type
+*/
+function og_user_roles_filter_role() {
+  $node = og_get_group_context();
+  $roles = array();
+  if ($node->type) {
+    $group = $node->type;
+  } else {
+    $group = 'group';
+  }
+  // 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_{$group}", array());
+  $all_roles = user_roles();
+  foreach ($role_ids as $rid => $checked) {
+    if ($checked != 0) {
+      $roles[$rid] = $all_roles[$rid];
+    }
+  }
+  return $roles;
 } 
-
+
 /*
  * Implementation of hook_boot() (was hook_init()).
  *
@@ -1072,20 +1072,20 @@ function og_user_roles_filter_role() {
  */
 function og_user_roles_boot() {
   global $user;
-
-  // Let's try getting og roles here, just to see what happens
-  // Added here as per hook_init() suggestion: http://api.drupal.org/api/function/hook_init/5
-  // Don't call og_user_roles_all_roles unless this user is logged in
+
+  // Let's try getting og roles here, just to see what happens
+  // Added here as per hook_init() suggestion: http://api.drupal.org/api/function/hook_init/5
+  // Don't call og_user_roles_all_roles unless this user is logged in
   if ($user->uid > 0) {
     $roles = og_user_roles_all_roles($user); // This returns normal $user->roles and includes OG roles if any
-    $user->roles = $roles;
-    if (variable_get('og_user_roles_clear_cache_value', 0) == 1) {
-	  cache_clear_all($user->uid, 'cache_menu', TRUE);
-	  // Clear the user_access $perm cache
-	  user_access('', NULL, TRUE);
+    $user->roles = $roles;
+    if (variable_get('og_user_roles_clear_cache_value', 0) == 1) {
+	  cache_clear_all($user->uid, 'cache_menu', TRUE);
+	  // Clear the user_access $perm cache
+	  user_access('', NULL, TRUE);
 	}
-  }
-
+  }
+
   // 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) {
@@ -1093,47 +1093,47 @@ function og_user_roles_boot() {
     if ((!function_exists('arg') || !function_exists('node_load')) && $user->uid > 0) {
       drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);  // http://drupal.org/node/273068
     }
-    // Modification as per: http://drupal.org/node/183860
-	// Further modification: changed og_user_roles_theme() to og_user_roles_determine_context()
-    og_user_roles_determine_context();
-
-    /** 
-     * Modules exempted from ognodeadd:
-	 * Originally for ad module: http://drupal.org/node/183081
-	 * Added minutes module: http://drupal.org/node/184102
-	 */
-    $exempted = array('ad','minutes');
-
-    $orig_query = $_SERVER['QUERY_STRING'];
-	// Get rid of Create Content 'node/add?gids[]'
-      $pattern = '/q\=.*node\/add\&gids\[\]\=(\d+)/i';
-      $orig_query = preg_replace($pattern, "", $orig_query);
-	// Get rid of Create Content 'node/ognodeadd&gids[]'
-      $pattern = '/q\=.*node\/ognodeadd\&gids\[\]\=(\d+)/i';
-      $orig_query = preg_replace($pattern, "", $orig_query);
-	// Get rid of Create Content 'node/ognodeadd&type='
-      $pattern = '/q\=.*node\/ognodeadd\&type\=(\w+)/i';
-      $orig_query = preg_replace($pattern, "", $orig_query);
-	// Get rid of 'node/add followed by &'
-      $pattern = '/q\=.*node\/add\/[^\&]+\&/i';
-      $orig_query = preg_replace($pattern, "", $orig_query);
-	// Get rid of 'node/add followed which ends the line'
-      $pattern = '/q\=.*node\/add\/[^\&]+$/i';
-      $orig_query = preg_replace($pattern, "", $orig_query);
-	// Get rid of 'gids[]='
-      $pattern = '/.*gids\[\]\=(\d+)[\&]?/i';
-      $orig_query = preg_replace($pattern, "", $orig_query);
-	// Get rid of 'node/ognodeadd'
-      $pattern = '/q\=.*node\/ognodeadd/i';
-      $orig_query = preg_replace($pattern, "", $orig_query);
-	// Get rid of '&' if it starts a line
-      $pattern = '/^\&/i';
-      $orig_query = preg_replace($pattern, "", $orig_query);
-//    drupal_set_message($orig_query);
-
+    // Modification as per: http://drupal.org/node/183860
+	// Further modification: changed og_user_roles_theme() to og_user_roles_determine_context()
+    og_user_roles_determine_context();
+
+    /** 
+     * Modules exempted from ognodeadd:
+	 * Originally for ad module: http://drupal.org/node/183081
+	 * Added minutes module: http://drupal.org/node/184102
+	 */
+    $exempted = array('ad','minutes');
+
+    $orig_query = $_SERVER['QUERY_STRING'];
+	// Get rid of Create Content 'node/add?gids[]'
+      $pattern = '/q\=.*node\/add\&gids\[\]\=(\d+)/i';
+      $orig_query = preg_replace($pattern, "", $orig_query);
+	// Get rid of Create Content 'node/ognodeadd&gids[]'
+      $pattern = '/q\=.*node\/ognodeadd\&gids\[\]\=(\d+)/i';
+      $orig_query = preg_replace($pattern, "", $orig_query);
+	// Get rid of Create Content 'node/ognodeadd&type='
+      $pattern = '/q\=.*node\/ognodeadd\&type\=(\w+)/i';
+      $orig_query = preg_replace($pattern, "", $orig_query);
+	// Get rid of 'node/add followed by &'
+      $pattern = '/q\=.*node\/add\/[^\&]+\&/i';
+      $orig_query = preg_replace($pattern, "", $orig_query);
+	// Get rid of 'node/add followed which ends the line'
+      $pattern = '/q\=.*node\/add\/[^\&]+$/i';
+      $orig_query = preg_replace($pattern, "", $orig_query);
+	// Get rid of 'gids[]='
+      $pattern = '/.*gids\[\]\=(\d+)[\&]?/i';
+      $orig_query = preg_replace($pattern, "", $orig_query);
+	// Get rid of 'node/ognodeadd'
+      $pattern = '/q\=.*node\/ognodeadd/i';
+      $orig_query = preg_replace($pattern, "", $orig_query);
+	// Get rid of '&' if it starts a line
+      $pattern = '/^\&/i';
+      $orig_query = preg_replace($pattern, "", $orig_query);
+//    drupal_set_message($orig_query);
+
     // If this is a group node/add, re-direct to ognodeadd
     if (arg(0) == 'node' && arg(1) == 'add' && isset($_REQUEST['gids']) && (!in_array(arg(2), $exempted)) ) {
-      
+      
       $gids = $_GET['gids'];
       $gid = intval(current($_REQUEST['gids']));
       $type = arg(2);
@@ -1150,25 +1150,25 @@ function og_user_roles_boot() {
         $query = 'type='. $type .'&gids[]='. $gid .'&tid='. intval(arg(3));
       }
 
-      // Modification to make it work with module "Relativity"
-      // http://drupal.org/node/166253
-      if (module_exists('relativity')) {
-      if (arg(3) == 'parent' && is_numeric(arg(4))) {
-          $query .= '&parent_node='.arg(4);
-        }
-        elseif (!empty($_GET['parent_node'])) {
-        $query .= '&parent_node='.$_GET['parent_node'];
-        }
-      }
-
-      // Modification for book module - http://drupal.org/node/180243
-	  // this: http://www.scbbs.com/node/add/book/parent/225&gids[]=29
-	  // becomes this: http://www.scbbs.com/node/ognodeadd/0/parent/225?type=book&gids[]=29
-      if (module_exists('book') && $type == 'book' && arg(3) == 'parent' && is_numeric(arg(4))) {
-        $path .= '/book/parent/'. arg(4);
-      }
-
-      if ($orig_query) $query = $query . '&' . $orig_query;
+      // Modification to make it work with module "Relativity"
+      // http://drupal.org/node/166253
+      if (module_exists('relativity')) {
+      if (arg(3) == 'parent' && is_numeric(arg(4))) {
+          $query .= '&parent_node='.arg(4);
+        }
+        elseif (!empty($_GET['parent_node'])) {
+        $query .= '&parent_node='.$_GET['parent_node'];
+        }
+      }
+
+      // Modification for book module - http://drupal.org/node/180243
+	  // this: http://www.scbbs.com/node/add/book/parent/225&gids[]=29
+	  // becomes this: http://www.scbbs.com/node/ognodeadd/0/parent/225?type=book&gids[]=29
+      if (module_exists('book') && $type == 'book' && arg(3) == 'parent' && is_numeric(arg(4))) {
+        $path .= '/book/parent/'. arg(4);
+      }
+
+      if ($orig_query) $query = $query . '&' . $orig_query;
       drupal_goto($path, $query);
     }
 
@@ -1179,30 +1179,30 @@ function og_user_roles_boot() {
       $tid = intval(arg(3));
       $gid = og_user_roles_gid_from_tid($tid);
       // Hijack only if there is a gid value;
-      // Modificaton as per http://drupal.org/node/194214
+      // Modificaton as per http://drupal.org/node/194214
       if (!empty($gid) && $gid != 0) { 
         $path = 'node/ognodeadd';
         $query = 'type='. $type .'&gids[]='. $gid .'&tid='. $tid;
-        if ($orig_query) $query = $query . '&' . $orig_query;
+        if ($orig_query) $query = $query . '&' . $orig_query;
         drupal_goto($path, $query);
       }
     }
-
-    // Modification as per: http://drupal.org/node/174959
-    // If this is a non-group node/add, but og_last session cookie is set
-    // then re-direct to ognodeadd
+
+    // Modification as per: http://drupal.org/node/174959
+    // If this is a non-group node/add, but og_last session cookie is set
+    // then re-direct to ognodeadd
 	// But, make sure you don't redirect for omitted nodes.
     if (arg(0) == 'node' && arg(1) == 'add' && $_SESSION['og_last'] && (!is_null(arg(2)))  && (!in_array(arg(2), $exempted)) ) {
-
-      $gid = $_SESSION['og_last']->nid;
-
+
+      $gid = $_SESSION['og_last']->nid;
+
       $type = arg(2);
       $path = 'node/ognodeadd';
-
-      // Modification as per: http://drupal.org/node/178610
-	  // Need to make sure this node $type supports adding a group item
-      $og_audience_required = variable_get('og_audience_required', FALSE);
-      $og_omitted = variable_get('og_omitted', array());
+
+      // Modification as per: http://drupal.org/node/178610
+	  // Need to make sure this node $type supports adding a group item
+      $og_audience_required = variable_get('og_audience_required', FALSE);
+      $og_omitted = variable_get('og_omitted', array());
       if ($og_audience_required && (!in_array($type, $og_omitted)) ) {
         if ($type == 'og_user_roles_subgroup') {
           $type = variable_get('og_user_roles_create_subgroup_value', ''); // change OG Subgroups type to 'group'
@@ -1210,201 +1210,201 @@ function og_user_roles_boot() {
 
         $query = 'type='. $type .'&gids[]='. $gid;
 
-        // Modification to make it work with module "Relativity"
-        // http://drupal.org/node/166253
-        if (module_exists('relativity')) {
-          if (arg(3) == 'parent' && is_numeric(arg(4))) {
-            $query .= '&parent_node='.arg(4);
-          }
-          elseif (!empty($_GET['parent_node'])) {
-          $query .= '&parent_node='.$_GET['parent_node'];
-          }
-        }
-
-        // Modification for book module - http://drupal.org/node/180243
-  	    // this: http://www.scbbs.com/node/add/book/parent/225&gids[]=29
-	    // becomes this: http://www.scbbs.com/node/ognodeadd/0/parent/225?type=book&gids[]=29
-        if (module_exists('book') && $type == 'book' && arg(3) == 'parent' && is_numeric(arg(4))) {
-          $path .= '/book/parent/'. arg(4);
-        }
-
-        if ($orig_query) $query = $query . '&' . $orig_query;
+        // Modification to make it work with module "Relativity"
+        // http://drupal.org/node/166253
+        if (module_exists('relativity')) {
+          if (arg(3) == 'parent' && is_numeric(arg(4))) {
+            $query .= '&parent_node='.arg(4);
+          }
+          elseif (!empty($_GET['parent_node'])) {
+          $query .= '&parent_node='.$_GET['parent_node'];
+          }
+        }
+
+        // Modification for book module - http://drupal.org/node/180243
+  	    // this: http://www.scbbs.com/node/add/book/parent/225&gids[]=29
+	    // becomes this: http://www.scbbs.com/node/ognodeadd/0/parent/225?type=book&gids[]=29
+        if (module_exists('book') && $type == 'book' && arg(3) == 'parent' && is_numeric(arg(4))) {
+          $path .= '/book/parent/'. arg(4);
+        }
+
+        if ($orig_query) $query = $query . '&' . $orig_query;
         drupal_goto($path, $query);
-      }
+      }
     }
-
-    // Modification for og_vocab: http://drupal.org/node/162649
-    // This allows a group role with "administer taxonomy" permission to edit
-    // og_vocab terms.  If this is an og_vocab term edit:
-    //   a. Get the group and tid
-    //   b. re-direct to destination
+
+    // Modification for og_vocab: http://drupal.org/node/162649
+    // This allows a group role with "administer taxonomy" permission to edit
+    // og_vocab terms.  If this is an og_vocab term edit:
+    //   a. Get the group and tid
+    //   b. re-direct to destination
 	//   c. from destination, redirect to ogtermedit
-    if (module_exists('og_vocab')) {
-	  if (arg(0) == 'admin' && arg(1) == 'content' && arg(2) == 'taxonomy' && arg(3) == 'edit' && arg(4) == 'term' && is_numeric(arg(5)) && isset($_REQUEST['destination'])) {
+    if (module_exists('og_vocab')) {
+	  if (arg(0) == 'admin' && arg(1) == 'content' && arg(2) == 'taxonomy' && arg(3) == 'edit' && arg(4) == 'term' && is_numeric(arg(5)) && isset($_REQUEST['destination'])) {
         $destination = $_GET['destination'];
         $tid = arg(5);
-        $gid = og_user_roles_gid_from_og_vocab_tid($tid);
+        $gid = og_user_roles_gid_from_og_vocab_tid($tid);
 
         $query = '&gids[]='. $gid .'&tid='. $tid . '&newdestination=' . $destination;
-
+
         // Re-direct to destination if $gid > 0
-        if ($gid > 0) {
-          drupal_goto($destination, $query);
+        if ($gid > 0) {
+          drupal_goto($destination, $query);
 		}
-      }
-      // This is the destination path for og_vocab term edit redirection above
-	  if (arg(0) == 'node'  && is_numeric(arg(1)) && arg(2) == 'og' && arg(3) == 'vocab' && arg(4) == 'terms' && is_numeric(arg(5)) && isset($_REQUEST['gids'])  && isset($_REQUEST['tid']) ) {
-        $destination = $_GET['newdestination'];       
+      }
+      // This is the destination path for og_vocab term edit redirection above
+	  if (arg(0) == 'node'  && is_numeric(arg(1)) && arg(2) == 'og' && arg(3) == 'vocab' && arg(4) == 'terms' && is_numeric(arg(5)) && isset($_REQUEST['gids'])  && isset($_REQUEST['tid']) ) {
+        $destination = $_GET['newdestination'];       
         $tid = $_GET['tid'];
         $gids = $_GET['gids'];
         $gid = intval(current($_REQUEST['gids']));
         $path = 'node/ogtermedit';
-
+
         $query = 'gids[]='. $gid .'&tid='. $tid . '&destination=' . $destination;
-
+
         // Re-direct to ogtermedit
         drupal_goto($path, $query);
-      }
+      }
     }
-    // Modification for modr8: http://drupal.org/node/162649
-    // This allows a group role with "moderate content" permission to view
-	// the modr8_log for events related to nodes he has access to.
-    if (module_exists('modr8')) {
-	  if (arg(0) == 'admin' && arg(1) == 'logs' && arg(2) == 'modr8' && arg(3) == 'event' && is_numeric(arg(4)) ) {
+    // Modification for modr8: http://drupal.org/node/162649
+    // This allows a group role with "moderate content" permission to view
+	// the modr8_log for events related to nodes he has access to.
+    if (module_exists('modr8')) {
+	  if (arg(0) == 'admin' && arg(1) == 'logs' && arg(2) == 'modr8' && arg(3) == 'event' && is_numeric(arg(4)) ) {
         $event = arg(4);
-        $gid = og_user_roles_gid_from_modr8_event($event);
+        $gid = og_user_roles_gid_from_modr8_event($event);
         $path = 'node/ogmodr8';
         $query = 'gids[]='. $gid .'&event='. $event;
         // Re-direct to destination if $gid > 0
-        if ($gid > 0) {
-          drupal_goto($path, $query);
+        if ($gid > 0) {
+          drupal_goto($path, $query);
 		}
-      }
-	}
-    // Modification for ad module: http://drupal.org/node/183081
-    // Add groupID if we are in group context.
-    if (module_exists('ad')) {
-	  if (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'ad' && (arg(3) == 'image' || arg(3) == 'text') && $_SESSION['og_last'] && (!isset($_REQUEST['gids'])) ) {
-//        $gid = $_SESSION['og_last']->nid;
+      }
+	}
+    // Modification for ad module: http://drupal.org/node/183081
+    // Add groupID if we are in group context.
+    if (module_exists('ad')) {
+	  if (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'ad' && (arg(3) == 'image' || arg(3) == 'text') && $_SESSION['og_last'] && (!isset($_REQUEST['gids'])) ) {
+//        $gid = $_SESSION['og_last']->nid;
 //        $uri_request_id = request_uri();
-//        $this_url = parse_url($uri_request_id);
-//        $this_path = $this_url[path];
-//        $this_path = ltrim($this_path, "\/");
+//        $this_url = parse_url($uri_request_id);
+//        $this_path = $this_url[path];
+//        $this_path = ltrim($this_path, "\/");
 //        $path = $this_path;
-
-        $gid = $_SESSION['og_last']->nid;
-        $uri_request_id = request_uri();
-        $this_url = parse_url($uri_request_id);
-        $this_path = $this_url[path];
-        $base_path_len = strlen(base_path());
-        $this_path2 = substr($this_path, $base_path_len);
-        $path = $this_path2;
-
+
+        $gid = $_SESSION['og_last']->nid;
+        $uri_request_id = request_uri();
+        $this_url = parse_url($uri_request_id);
+        $this_path = $this_url[path];
+        $base_path_len = strlen(base_path());
+        $this_path2 = substr($this_path, $base_path_len);
+        $path = $this_path2;
+
         $query = 'gids[]='. $gid;
         // Only add if $gid > 0
-        if ($gid > 0) {
-          drupal_goto($path, $query);
+        if ($gid > 0) {
+          drupal_goto($path, $query);
 		}
-      }
-	}
-    // Modification for minutes module: http://drupal.org/node/184102
-    // Add groupID if we are in group context.
-    if (module_exists('minutes')) {
-	  if (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'minutes' && is_numeric(arg(3)) && $_SESSION['og_last'] && (!isset($_REQUEST['gids'])) ) {
-//        $gid = $_SESSION['og_last']->nid;
+      }
+	}
+    // Modification for minutes module: http://drupal.org/node/184102
+    // Add groupID if we are in group context.
+    if (module_exists('minutes')) {
+	  if (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'minutes' && is_numeric(arg(3)) && $_SESSION['og_last'] && (!isset($_REQUEST['gids'])) ) {
+//        $gid = $_SESSION['og_last']->nid;
 //        $uri_request_id = request_uri();
-//        $this_url = parse_url($uri_request_id);
-//        $this_path = $this_url[path];
-//        $this_path = ltrim($this_path, "\/");
+//        $this_url = parse_url($uri_request_id);
+//        $this_path = $this_url[path];
+//        $this_path = ltrim($this_path, "\/");
 //        $path = $this_path;
-
-        $gid = $_SESSION['og_last']->nid;
-        $uri_request_id = request_uri();
-        $this_url = parse_url($uri_request_id);
-        $this_path = $this_url[path];
-        $base_path_len = strlen(base_path());
-        $this_path2 = substr($this_path, $base_path_len);
-        $path = $this_path2;
-
+
+        $gid = $_SESSION['og_last']->nid;
+        $uri_request_id = request_uri();
+        $this_url = parse_url($uri_request_id);
+        $this_path = $this_url[path];
+        $base_path_len = strlen(base_path());
+        $this_path2 = substr($this_path, $base_path_len);
+        $path = $this_path2;
+
         $query = 'gids[]='. $gid;
         // Only add if $gid > 0
-        if ($gid > 0) {
-          drupal_goto($path, $query);
+        if ($gid > 0) {
+          drupal_goto($path, $query);
 		}
-      }
-	}
+      }
+	}
     // Modification user edit
-    // If this is going to http://clients.brixrealtyinc.com/user/76
-    // But the referrer is http://clients.brixrealtyinc.com/oguseredit/76/edit?gids[]=47
-    // Then redirect back to referrer.
-	// As a result of http://drupal.org/node/176662 this can only be done if the
+    // If this is going to http://clients.brixrealtyinc.com/user/76
+    // But the referrer is http://clients.brixrealtyinc.com/oguseredit/76/edit?gids[]=47
+    // Then redirect back to referrer.
+	// As a result of http://drupal.org/node/176662 this can only be done if the
 	// "Allow group admins to approve users" setting is checked on.
     if (variable_get('og_user_roles_approval_default', 0) === 1 && ((!user_access('access administration pages')) && (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) != 1) || (arg(0) == 'admin' && arg(1) == 'user' && arg(2) == 'user'))) {
-      $ref = $_SERVER["HTTP_REFERER"];
-      $ref_url = parse_url($ref);
-      $ref_path = $ref_url[path];
-      $ref_query = $ref_url[query];
-      $ref_arg = explode('/', $ref_path);
-
-      drupal_set_message('ref_query = ' . $ref_query);
-
+      $ref = $_SERVER["HTTP_REFERER"];
+      $ref_url = parse_url($ref);
+      $ref_path = $ref_url[path];
+      $ref_query = $ref_url[query];
+      $ref_arg = explode('/', $ref_path);
+
+      drupal_set_message('ref_query = ' . $ref_query);
+
       // Hijack only if the referrer contains oguseredit;
       if ($ref_arg[1] == 'oguseredit' && arg(2) != 'user') {
-        // If user clicks delete from user edit screen. Gets you to the
-		// "delete" confirmation.
-        if (arg(2) == 'delete') {
+        // If user clicks delete from user edit screen. Gets you to the
+		// "delete" confirmation.
+        if (arg(2) == 'delete') {
           $temp = substr($ref_path, 1);
-          $path = str_replace("/edit", "/delete", $temp);
+          $path = str_replace("/edit", "/delete", $temp);
           $query = $ref_query;
-          drupal_goto($path, $query);
-		}
-        // If user clicks "submit" from user edit screen - just takes you back
-		// to the same edit screen.
+          drupal_goto($path, $query);
+		}
+        // If user clicks "submit" from user edit screen - just takes you back
+		// to the same edit screen.
         if ($ref_arg[3] == 'edit') {
           $path = substr($ref_path, 1);
           $query = $ref_query;
-          drupal_goto($path, $query);
+          drupal_goto($path, $query);
 		}
-        // If user clicks "delete" or "cancel" from delete confirmation screen.
-		// Takes you to group home page.
+        // If user clicks "delete" or "cancel" from delete confirmation screen.
+		// Takes you to group home page.
         if ($ref_arg[3] == 'delete') {
-          parse_str($ref_query);
+          parse_str($ref_query);
           $gid = $gids[0];
           $path = 'node/' . $gid;
-          drupal_goto($path);
+          drupal_goto($path);
 		}
       }
     }
     // If this is a group relativity or book module node/add, re-direct to ognodeadd
     if (arg(0) == 'node' && arg(1) == 'add'  && is_numeric(arg(4)) && (!in_array(arg(2), $exempted)) ) {
-      
+      
       $type = arg(2);
       $path = 'node/ognodeadd';
-
-      // Get the gid for this parent
+
+      // Get the gid for this parent
       $nid = (int)arg(4);
       $gid = og_user_roles_getgid($nid, $user->uid);
 
       $query = 'type='. $type .'&gids[]='. $gid;
 
-      // Modification to make it work with module "Relativity"
-      // http://drupal.org/node/166253
-      // http://drupal.org/node/227978
-      if (module_exists('relativity')) {
-        if (arg(3) == 'parent') {
-          $query .= '&parent_node='.arg(4);
-        }
-        elseif (!empty($_GET['parent_node'])) {
-          $query .= '&parent_node='.$_GET['parent_node'];
-        }
-      }
-      // Book module as per: http://drupal.org/node/228386
-      if (module_exists('book') && $type == 'book' && arg(3) == 'parent' && is_numeric(arg(4))) {
-        $path .= '/book/parent/'. arg(4);
-      }
+      // Modification to make it work with module "Relativity"
+      // http://drupal.org/node/166253
+      // http://drupal.org/node/227978
+      if (module_exists('relativity')) {
+        if (arg(3) == 'parent') {
+          $query .= '&parent_node='.arg(4);
+        }
+        elseif (!empty($_GET['parent_node'])) {
+          $query .= '&parent_node='.$_GET['parent_node'];
+        }
+      }
+      // Book module as per: http://drupal.org/node/228386
+      if (module_exists('book') && $type == 'book' && arg(3) == 'parent' && is_numeric(arg(4))) {
+        $path .= '/book/parent/'. arg(4);
+      }
        $query = 'type='. $type .'&gids[]='. $gid .'&tid='. $tid;
        drupal_goto($path, $query);
-    }
+    }
   }
 }
 
@@ -1416,44 +1416,44 @@ function og_user_roles_boot() {
  */
 function og_user_roles_user($op, &$edit, &$user, $category = NULL) {
 
-  if ($op == 'insert') {
-    // Registration Code 
+  if ($op == 'insert') {
+    // Registration Code 
     if (isset($edit['og_user_roles_regcode']) && variable_get('og_user_roles_assign_regcode_gid', 0) == 1) { //only present during registration
-      $gid = og_user_roles_gid_from_regcode($edit['og_user_roles_regcode']);
-      if ($gid > 0) {
-        $node = node_load($gid);
+      $gid = og_user_roles_gid_from_regcode($edit['og_user_roles_regcode']);
+      if ($gid > 0) {
+        $node = node_load($gid);
         $title = $node->title;
         $return = og_save_subscription($gid, $user->uid, array('is_active' => 1)); // as per http://drupal.org/node/156224
-        drupal_set_message(t('Subscription request to ' . l($title, 'node/'. $gid) . ' approved.'));	
-        // Delete this registration code if 'delete_regcode' is set
-        if (variable_get('og_user_roles_delete_regcode_' . $gid, 0) == 1) og_user_roles_delete_regcode($gid, $edit['og_user_roles_regcode']);
-        // Places all new registration code group subscribers into default regcode role.
-        if (variable_get('og_user_roles_assign_regcoderole_' . $gid, 0)) { // check to see if this variable exists
+        drupal_set_message(t('Subscription request to ' . l($title, 'node/'. $gid) . ' approved.'));	
+        // Delete this registration code if 'delete_regcode' is set
+        if (variable_get('og_user_roles_delete_regcode_' . $gid, 0) == 1) og_user_roles_delete_regcode($gid, $edit['og_user_roles_regcode']);
+        // Places all new registration code group subscribers into default regcode role.
+        if (variable_get('og_user_roles_assign_regcoderole_' . $gid, 0)) { // check to see if this variable exists
           if (variable_get('og_user_roles_assign_regcode_gid', 0) == 1 && variable_get('og_user_roles_assign_regcoderole_' . $gid, 0) == 1 ) {
             $rid = variable_get('og_user_roles_regcoderole_value_' . $gid, 0);
             og_user_roles_role_join($user->uid, $rid, $gid); // assign user to group role in that group
           }
-        }
-      }
+        }
+      }
     }
-
-    // If site requires admin approval and group admins are allowed to approve users
-	// Variable "user_register" values: 0 = Admin Only, 1 = No Admin Approval, 2 = Admin Approval
-    if (variable_get('og_user_roles_approval_default', 0) == 1 && (variable_get('user_register', 1) == 2 || ($user->status == 0))) {
+
+    // If site requires admin approval and group admins are allowed to approve users
+	// Variable "user_register" values: 0 = Admin Only, 1 = No Admin Approval, 2 = Admin Approval
+    if (variable_get('og_user_roles_approval_default', 0) == 1 && (variable_get('user_register', 1) == 2 || ($user->status == 0))) {
        watchdog('new_user: status', 'user->status = ' . $user->status, WATCHDOG_NOTICE);
       if (is_array($edit['og_register'])) {
         $sender = variable_get('site_mail', '');
-        $edit_test1 = $edit['og_register'];
+        $edit_test1 = $edit['og_register'];
         foreach (array_keys(array_filter($edit['og_register'])) as $gid) {
           watchdog('new_user: gid', 'gid = ' . $gid, WATCHDOG_NOTICE);
           $node = node_load($gid);
           $group = check_plain($node->title);
           $subject = t('User @user pending account approval. Subscription request to : @group', array('@user' => $user->name, '@group' => $group));
-		  if (variable_get('og_user_roles_approval_default', 0) == 1) {
-            $view_user = "oguseredit/$user->uid";
-		  }else{
-            $view_user = "user/$user->uid";
-		  }
+		  if (variable_get('og_user_roles_approval_default', 0) == 1) {
+            $view_user = "oguseredit/$user->uid";
+		  }else{
+            $view_user = "user/$user->uid";
+		  }
           $message = "The registration application for user " . l($user->name, $view_user, array('query' => "gids[]=$gid", 'absolute' => TRUE)) . " is pending approval.  You are the administrator for at least one of the groups to which this user has also applied to subscribe : " . l($group, "node/$gid", array('absolute' => TRUE)) . ".<p>You can click " . l("here", "$view_user/edit", array('query' => "gids[]=$gid", 'absolute' => TRUE)) . " to Activate, Block or Delete the user. (Don't forget to first log into group for which you are admin.)";
           $result = db_query("SELECT uid FROM {og_uid} WHERE is_admin = 1 AND nid = %d", $gid);
 
@@ -1463,10 +1463,10 @@ function og_user_roles_user($op, &$edit,
             $recipient = $recipient_user->mail;
             if (module_exists('mimemail')) mimemail($sender, $recipient, $subject, $message);
           } // end while
-        }
-	  }
+        }
+	  }
 	}
-
+
     // If site admin opted to create a default role
     if (variable_get('og_user_roles_assign_default', 0) == 1) {
       // Check to see if this user doesn't already have this role;
@@ -1479,21 +1479,21 @@ function og_user_roles_user($op, &$edit,
       if ($output == 0) {
         db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $user->uid, $rid);
       }
-    }
+    }
   }
 
-  if ($op == 'validate') {
-    // Registration Code
+  if ($op == 'validate') {
+    // Registration Code
     if (isset($edit['og_user_roles_regcode'])) { //only present during registration
       if (variable_get('og_user_roles_assign_regcode_gid', 0) == 1 && $edit['og_user_roles_regcode'] != '') {
-        $gid = og_user_roles_gid_from_regcode($edit['og_user_roles_regcode']);
+        $gid = og_user_roles_gid_from_regcode($edit['og_user_roles_regcode']);
         if ($gid == 0) {
           form_set_error('og_user_roles_regcode', "Not a valid group registration code.  If you do not have a registration code, please make sure the Group registration code box is empty.");
         }
       }
     }
-  }
-
+  }
+
   // 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') {
@@ -1532,50 +1532,50 @@ function og_user_roles_og($op, $nid, $ui
       }
 
       // --- Modification - 2007-09-20 - as per: http://drupal.org/node/177016
-      // Places all new group subscribers into default role.
-      // Same as above, except these settings are set by Group Admin in the
+      // Places all new group subscribers into default role.
+      // Same as above, except these settings are set by Group Admin in the
       // group node.  So, the variables are set by group.
-	  if (variable_get('og_user_roles_assign_basicgrouprole_' . $nid, 0)) { // check to see if this variable exists
+	  if (variable_get('og_user_roles_assign_basicgrouprole_' . $nid, 0)) { // check to see if this variable exists
         if (variable_get('og_user_roles_assign_basicgrouprole_gid', 0) == 1 && variable_get('og_user_roles_assign_basicgrouprole_' . $nid, 0) == 1 ) {
           $rid = variable_get('og_user_roles_basicgrouprole_value_' . $nid, 0);
           og_user_roles_role_join($uid, $rid, $nid); // assign user to group role in that group
         }
-      }
-
+      }
+
       // --- Modification - 2008-01-10 - as per: http://drupal.org/node/197489
-      // Places all new group administrators into default group administrator role.
-      $admin = $args['is_admin'];
+      // Places all new group administrators into default group administrator role.
+      $admin = $args['is_admin'];
       if (variable_get('og_user_roles_assign_admingrouprole', 0) == 1 && $admin == 1) {
         $rid = variable_get('og_user_roles_admingrouprole_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);
-      // --- Modification - 2008-05-20 - as per: http://drupal.org/node/259956
-      $node = db_fetch_object(db_query("SELECT type, title FROM {node} WHERE nid=%d", $nid));
+      // --- Modification - 2008-05-20 - as per: http://drupal.org/node/259956
+      $node = db_fetch_object(db_query("SELECT type, title FROM {node} WHERE nid=%d", $nid));
 
       // --- Modification - 2008-03-10 - as per: http://drupal.org/node/229715
-      // Places all new group subscribers into default role per group type.
-      $type = $node->type;
-	  if (variable_get('og_user_roles_assign_typegrouprole_' . $type, 0)) {
-	    if (variable_get('og_user_roles_assign_typegrouprole_' . $type, 0) == 1) {
+      // Places all new group subscribers into default role per group type.
+      $type = $node->type;
+	  if (variable_get('og_user_roles_assign_typegrouprole_' . $type, 0)) {
+	    if (variable_get('og_user_roles_assign_typegrouprole_' . $type, 0) == 1) {
           $rid = variable_get('og_user_roles_typegrouprole_value_' . $type, 0);
           og_user_roles_role_join($uid, $rid, $nid); // assign user to group role in that group
-        }
-      }
-
+        }
+      }
+
       // Send notification of new og subscription to administrators of group;
       if (variable_get('og_user_roles_notify_default', 0) == 1 && module_exists('mimemail')) {
         $group = check_plain($node->title);
         $sender = variable_get('site_mail', '');
         $subject = t('User @user added to group: @group', array('@user' => $user->name, '@group' => $group));
-        if (variable_get('og_user_roles_approval_default', 0) == 1) {
-          $view_user = "oguseredit/$user->uid";
-		}else{
-          $view_user = "user/$user->uid";
-		}
-        // http://www.scbbs.com/node/135/219#comment-219
+        if (variable_get('og_user_roles_approval_default', 0) == 1) {
+          $view_user = "oguseredit/$user->uid";
+		}else{
+          $view_user = "user/$user->uid";
+		}
+        // http://www.scbbs.com/node/135/219#comment-219
         $message = "User " . l($user->name, $view_user, array('query' => "gids[]=$nid", 'absolute' => TRUE)) . " added to group: " . l($group, "node/$nid", array('absolute' => TRUE));
         $result = db_query("SELECT uid FROM {og_uid} WHERE is_admin = 1 AND nid = %d", $nid);
 
@@ -1584,25 +1584,25 @@ function og_user_roles_og($op, $nid, $ui
           $recipient_user = user_load(array('uid' => $recipient_uid));
           $recipient = $recipient_user->mail;
           mimemail($sender, $recipient, $subject, $message);
-          // drupal_mail('og_user_roles_new_subscription', $recipient, $subject, $message, $sender);
+          // drupal_mail('og_user_roles_new_subscription', $recipient, $subject, $message, $sender);
         } // end while
       } // end if
       break;
 
     case 'user update':
       // --- Modification - 2008-01-10 - as per: http://drupal.org/node/197489
-      // Places all new group administrators into default group administrator role.
-      $admin = $args['is_admin'];
+      // Places all new group administrators into default group administrator role.
+      $admin = $args['is_admin'];
       if (variable_get('og_user_roles_assign_admingrouprole', 0) == 1 && $admin === 0) {
         $rid = variable_get('og_user_roles_admingrouprole_value', 0);
         og_user_roles_role_delete($uid, $rid, $nid); // delete this admin role for this user in this group (if it exists)
-      }
+      }
       if (variable_get('og_user_roles_assign_admingrouprole', 0) == 1 && $admin === 1) {
         $rid = variable_get('og_user_roles_admingrouprole_value', 0);
         og_user_roles_role_join($uid, $rid, $nid); // assign user to group role in that group
       }
       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);
@@ -1634,7 +1634,7 @@ function og_user_roles_node_info() {
  */
 function og_user_roles_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
   global $user;
-
+
   switch ($op) {
     case 'access':
       break;
@@ -1665,16 +1665,16 @@ function og_user_roles_nodeapi(&$node, $
         $subgroup = $node->nid;
         $sql = 'INSERT INTO {og_ancestry} (nid,group_nid,is_public) VALUES (%d,%d,0)';
         db_query($sql, $subgroup, $gid);
-        if (module_exists('og_subgroups')) db_query('INSERT INTO {og_subgroups} (gid, parent) VALUES (%d, %d)', $subgroup, $gid);
+        if (module_exists('og_subgroups')) db_query('INSERT INTO {og_subgroups} (gid, parent) VALUES (%d, %d)', $subgroup, $gid);
       }
 
       break;
-
+
     case 'update':
 
-      // Modification. 2007-09-24 as per: http://drupal.org/node/178257
-      // If this is a group node, put the group creator into a group role upon creation
-	  // OR when the group node is updated.  If user already is in that role in the group,
+      // Modification. 2007-09-24 as per: http://drupal.org/node/178257
+      // If this is a group node, put the group creator into a group role upon creation
+	  // OR when the group node is updated.  If user already is in that role in the group,
 	  // the og_user_roles_role_join command will ignore the request.
       if (variable_get('og_user_roles_assign_founder', 0) == 1) {
         // If this is a group node
@@ -1688,145 +1688,145 @@ function og_user_roles_nodeapi(&$node, $
       }
 
       break;
-
+
     case 'validate':
-      // Check to see if this user can post into other groups
-      $uid = $user->uid;
-      if ($node->type) {
-        $type = $node->type;
-      } elseif (arg(1) == 'add') {
-        $type = arg(2);
-      } elseif (arg(1) == 'ognodeadd') {
-        $type = $_GET['type'];
-      }
+      // Check to see if this user can post into other groups
+      $uid = $user->uid;
+      if ($node->type) {
+        $type = $node->type;
+      } elseif (arg(1) == 'add') {
+        $type = arg(2);
+      } elseif (arg(1) == 'ognodeadd') {
+        $type = $_GET['type'];
+      }
       // Check to see if this is a group post;
-      // Do we have group context?
-      if ($group_node = og_get_group_context()) {
-        // If this is a node that can be posted into groups
-        if (og_is_group_post_type($type)) {
-	      // Does this node have groups?
-          if ($node->og_groups) {
-		    foreach ($node->og_groups as $gid) {
-              if ((arg(1) == 'add' || arg(1) == 'ognodeadd') && $gid > 0) {
-			    $access = FALSE;
-                // Get the module
-                $module = node_get_types('module', $type);
+      // Do we have group context?
+      if ($group_node = og_get_group_context()) {
+        // If this is a node that can be posted into groups
+        if (og_is_group_post_type($type)) {
+	      // Does this node have groups?
+          if ($node->og_groups) {
+		    foreach ($node->og_groups as $gid) {
+              if ((arg(1) == 'add' || arg(1) == 'ognodeadd') && $gid > 0) {
+			    $access = FALSE;
+                // Get the module
+                $module = node_get_types('module', $type);
 				// Get all permissions for this module
-                $perms = module_invoke($module, 'perm');
+                $perms = module_invoke($module, 'perm');
 				// Look for the 'create' permission
-				foreach ($perms as $string) {
-				  // If this is a create permission
-				  if (preg_match('/create/', $string) || preg_match('/edit own blog/', $string)) {
-				    // See if the user has this permission in this group
-                    if (og_user_roles_user_access($string, $gid, $uid) === TRUE) {
-		              $access = TRUE;
+				foreach ($perms as $string) {
+				  // If this is a create permission
+				  if (preg_match('/create/', $string) || preg_match('/edit own blog/', $string)) {
+				    // See if the user has this permission in this group
+                    if (og_user_roles_user_access($string, $gid, $uid) === TRUE) {
+		              $access = TRUE;
                     }
-				  }
+				  }
 				}
                 if ($access === FALSE) {
-                  $temp_node = node_load($gid);
-				  $group_name = $temp_node->title;
-                  form_set_error('og_groups', t('You do not have permission to post this content type (' . $type . ') into Group: <strong>' . $group_name . '</strong> (' . $gid . ')'));
+                  $temp_node = node_load($gid);
+				  $group_name = $temp_node->title;
+                  form_set_error('og_groups', t('You do not have permission to post this content type (' . $type . ') into Group: <strong>' . $group_name . '</strong> (' . $gid . ')'));
                 }
               }
               if ((arg(2) == 'edit' || arg(2) == 'delete') && $gid > 0) {
-			    $access = FALSE;
+			    $access = FALSE;
                 $module = node_get_types('module', $type);
                 $perms = module_invoke($module, 'perm');
-				foreach ($perms as $string) {
-				  // If this is an edit string
-				  if (preg_match('/edit/', $string) || preg_match('/manage/', $string)) {
-                    if (og_user_roles_user_access($string, $gid, $uid) === TRUE) {
-		              $access = TRUE;
+				foreach ($perms as $string) {
+				  // If this is an edit string
+				  if (preg_match('/edit/', $string) || preg_match('/manage/', $string)) {
+                    if (og_user_roles_user_access($string, $gid, $uid) === TRUE) {
+		              $access = TRUE;
                     }
-				  }
+				  }
 				}
                 if ($access === FALSE) {
-                  $temp_node = node_load($gid);
-				  $group_name = $temp_node->title;
-                  form_set_error('og_groups', t('You do not have permission to edit or delete this content type (' . $type . ') in Group: <strong>' . $group_name . '</strong> (' . $gid . ')'));
+                  $temp_node = node_load($gid);
+				  $group_name = $temp_node->title;
+                  form_set_error('og_groups', t('You do not have permission to edit or delete this content type (' . $type . ') in Group: <strong>' . $group_name . '</strong> (' . $gid . ')'));
                 }
               }
-            }
-          }
-        }
-      }
+            }
+          }
+        }
+      }
       // Check to see if this is a group post, and if so, if public posts are allowed;
-      // Do we have group context?
-	  if ($group_node = og_get_group_context()) {
-	   // Get the group node id
-	   $gid = $group_node->nid;
-
-	   // If this is a group node
-	   if (in_array($node->type, og_get_types('group'))) {
-	   }
-
-	   // Check the nopublic variable for this group
-        if (variable_get('og_user_roles_assign_nopublic_' . $gid, 0) == 1) { 
-	      // Check public status of this post
-	      if ($node->og_public) { 
-	        form_set_error('og_public', t('No public posts allowed in this group.  You may NOT check the <strong>Public</strong> box on this post.'));
-	      }
-		  // Check forum status of this post
-		  if (module_exists('og_forum')) {
-		    if ($node->type == 'forum') {
-              // Get the forum vocabulary ID
+      // Do we have group context?
+	  if ($group_node = og_get_group_context()) {
+	   // Get the group node id
+	   $gid = $group_node->nid;
+
+	   // If this is a group node
+	   if (in_array($node->type, og_get_types('group'))) {
+	   }
+
+	   // Check the nopublic variable for this group
+        if (variable_get('og_user_roles_assign_nopublic_' . $gid, 0) == 1) { 
+	      // Check public status of this post
+	      if ($node->og_public) { 
+	        form_set_error('og_public', t('No public posts allowed in this group.  You may NOT check the <strong>Public</strong> box on this post.'));
+	      }
+		  // Check forum status of this post
+		  if (module_exists('og_forum')) {
+		    if ($node->type == 'forum') {
+              // Get the forum vocabulary ID
               $vid = og_forum_get_vid(); // http://drupal.org/node/346717
-              $ok = FALSE;
-   			  // Get all forums for this group
-     		  $sql = "SELECT tid FROM {og_term} WHERE nid = %d";
-              $forums = array();
-              $result = db_query($sql, $gid);
-              while ($nid = db_fetch_array($result)){
-                $forums[] = $nid['tid'];
-              }
-              // Get the forum containers only for this group
-		   	  $containers = variable_get('forum_containers', array());
-			  $my_containers = array_intersect($containers, $forums);
-			  // Get the list of names for forum containers for this group
-			  $names = "";
-              foreach ($my_containers as $item) {
-                $temp = taxonomy_get_term($item);
-                $names .= $temp->name . "  ";
-              }
-              // Get the vocabulary terms for this node
-              foreach ($node->taxonomy as $term) {
-                // Check to make sure this term is in the forum vocabulary
-                if (db_result(db_query('SELECT COUNT(*) FROM {term_data} WHERE tid = %d AND vid = %d', $term, $vid))) {
-                  // Make sure this term is in the same group
-                  if ($gid == og_user_roles_gid_from_tid($term)) {
-                    $tid = $term;
-        		    $ok = TRUE;
-                  }
-                }
-              }
-			  // Check the gid of this tid against this gid
-			  if (!$ok) {
-                form_set_error('tid', t('You have selected the wrong <strong>Forum</strong> for this post.  You may only select a forum from the <strong>Forums</strong> pull-down menu that is in the same group as this post.  Please try again. Group ('.$gid.') Term ('.$term.') Suggested container(s): %names', array('%names' => $names)));
-			  }
-		    }
-		  }
-		}
-	  }
+              $ok = FALSE;
+   			  // Get all forums for this group
+     		  $sql = "SELECT tid FROM {og_term} WHERE nid = %d";
+              $forums = array();
+              $result = db_query($sql, $gid);
+              while ($nid = db_fetch_array($result)){
+                $forums[] = $nid['tid'];
+              }
+              // Get the forum containers only for this group
+		   	  $containers = variable_get('forum_containers', array());
+			  $my_containers = array_intersect($containers, $forums);
+			  // Get the list of names for forum containers for this group
+			  $names = "";
+              foreach ($my_containers as $item) {
+                $temp = taxonomy_get_term($item);
+                $names .= $temp->name . "  ";
+              }
+              // Get the vocabulary terms for this node
+              foreach ($node->taxonomy as $term) {
+                // Check to make sure this term is in the forum vocabulary
+                if (db_result(db_query('SELECT COUNT(*) FROM {term_data} WHERE tid = %d AND vid = %d', $term, $vid))) {
+                  // Make sure this term is in the same group
+                  if ($gid == og_user_roles_gid_from_tid($term)) {
+                    $tid = $term;
+        		    $ok = TRUE;
+                  }
+                }
+              }
+			  // Check the gid of this tid against this gid
+			  if (!$ok) {
+                form_set_error('tid', t('You have selected the wrong <strong>Forum</strong> for this post.  You may only select a forum from the <strong>Forums</strong> pull-down menu that is in the same group as this post.  Please try again. Group ('.$gid.') Term ('.$term.') Suggested container(s): %names', array('%names' => $names)));
+			  }
+		    }
+		  }
+		}
+	  }
       break;
-
+
     case 'delete':
       // Remove og_users_roles and variables related to group node if it is deleted;
         // If this is a group node
         if (og_is_group_type($node->type)) {
-           og_user_roles_role_remove($node->nid);
-           og_user_roles_variable_remove($node->nid);
-		   if (module_exists('og_subgroups')) db_query('DELETE FROM {og_subgroups} WHERE gid = %d', $node->nid);
-        }
+           og_user_roles_role_remove($node->nid);
+           og_user_roles_variable_remove($node->nid);
+		   if (module_exists('og_subgroups')) db_query('DELETE FROM {og_subgroups} WHERE gid = %d', $node->nid);
+        }
       break;
-
+
   } // end switch
 } // end og_user_roles_nodeapi function
 
 /**
- * Use this function to determine whether a user has a given privilege
+ * Use this function to determine whether a user has a given privilege
  * in a particular group.
- *
+ *
  * @param $string
  *   The permission, such as "administer nodes", being checked for.
  * @param $gid
@@ -1838,27 +1838,27 @@ function og_user_roles_nodeapi(&$node, $
  *   boolean TRUE if the current user has the requested permission.
  */
 function og_user_roles_user_access($string, $gid, $uid) {
-  $roles = array();
-  $perms = "";
-
+  $roles = array();
+  $perms = "";
+
   // User #1 has all privileges:
   if ($uid == 1) {
     return TRUE;
   }
-
+
   if ($uid) {
     $roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
   }
   else {
     $roles[DRUPAL_ANONYMOUS_RID] = 'anonymous user';
   }
-  // Get the normal roles
+  // Get the normal roles
   $result = db_query('SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = %d', $uid);
   while ($role = db_fetch_object($result)) {
     $roles[$role->rid] = $role->name;
   }
-  // Get the group roles
-  $result = db_query('SELECT r.rid, r.name FROM {role} r INNER JOIN {og_users_roles} ogr ON r.rid = ogr.rid INNER JOIN {og_uid} ogu ON ogu.uid = ogr.uid AND ogu.nid = ogr.gid WHERE ogr.uid = %d AND ogr.gid = %d AND ogu.is_active = 1', $uid, $gid);
+  // Get the group roles
+  $result = db_query('SELECT r.rid, r.name FROM {role} r INNER JOIN {og_users_roles} ogr ON r.rid = ogr.rid INNER JOIN {og_uid} ogu ON ogu.uid = ogr.uid AND ogu.nid = ogr.gid WHERE ogr.uid = %d AND ogr.gid = %d AND ogu.is_active = 1', $uid, $gid);
   while ($role = db_fetch_object($result)) {
     $roles[$role->rid] = $role->name;
   }
@@ -1869,7 +1869,7 @@ function og_user_roles_user_access($stri
     $perms .= "$row->perm, ";
   }
   return strpos($perms, "$string, ") !== FALSE;
-}
+}
 
 /**
  * Returns all groups so long as this is not a group itself.
@@ -1901,10 +1901,10 @@ function og_user_roles_get_groups_result
  * of group and non-group roles for this user.
  */
 function og_user_roles_all_roles($user) {
-
+
   drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); // added as per this issue: http://drupal.org/node/149469
 //  drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH); // added as per this issue: http://drupal.org/node/149469
-
+
   // This will be the process to get BOTH the group and non-group roles for a user
   $uid = $user->uid;
   $gid = 0;
@@ -1914,13 +1914,13 @@ function og_user_roles_all_roles($user) 
   $uri_request_id = request_uri();
   $arg = explode('/', $uri_request_id);
   $ogroles = array();
-  $x1 = 0;
+  $x1 = 0;
   // Need to use the referrer to get OG group in some cases;
-  $ref = $_SERVER['HTTP_REFERER'];
-  $ref_url = parse_url($ref);
-  $ref_path = $ref_url['path'];
-  $ref_query = $ref_url['query'];
-  $ref_arg = explode('/', $ref_path);
+  $ref = $_SERVER['HTTP_REFERER'];
+  $ref_url = parse_url($ref);
+  $ref_path = $ref_url['path'];
+  $ref_query = $ref_url['query'];
+  $ref_arg = explode('/', $ref_path);
 
   //
   // This will by default add the anonymous user role (no need since we merge user->roles)
@@ -1928,17 +1928,17 @@ function og_user_roles_all_roles($user) 
   // We get the groupID
   //
 
-  drupal_load('module', 'og');
-//  require_once("modules/og/og.module");
-
+  drupal_load('module', 'og');
+//  require_once("modules/og/og.module");
+
   $group_node = og_get_group_context();
   $gid02 = $group_node->nid;
   $gid = $gid02;
   if ($gid02 === NULL) {
     $gid = 0;
-  }else{
+  }else{
     $_SESSION['og_last'] = $group_node;
-    $_SESSION['og_user_role'] = $gid;
+    $_SESSION['og_user_role'] = $gid;
   }
 
   //
@@ -1952,49 +1952,49 @@ function og_user_roles_all_roles($user) 
       $gid = og_user_roles_getgid($nid, $uid);
     }
 
-    // Translate pages using i18n translation module as per: http://drupal.org/node/203395
-	if (arg(0) == 'node' && arg(1) == 'add' && isset($_REQUEST['translation']))	{
-	  $nid = intval($_REQUEST['translation']);
-	  $gid = og_user_roles_getgid($nid, $uid);
-	  if ($gid) {
-	    // Troubleshooting
-	    // drupal_set_message('recognized translation node add, gid = '.$gid);	  
-	    $_GET['gids'] = array($gid); // inject gid
-	  }
-	}
-	
-	// http://doadance.scbbs.com/node/79/edit
-	// http://doadance.scbbs.com/node/79/outline
-	// http://doadance.scbbs.com/node/79/track
-	// http://doadance.scbbs.com/node/79/modr8
-	// http://doadance.scbbs.com/node/79/ogmodr8
-
-    // Modified 2007-07-05 for webform "results";
-    // Modified 2007-07-23 for content_access "access";
-    // Modified 2007-08-06 for modr8 "modr8" and "ogmodr8" (our own callback);
-    // Modified 2007-09-13 for "galleries";
-    // Modified 2007-09-14 for "email";
-    // Modified 2007-12-20 for "revisions": http://drupal.org/node/202196
-    // Modified 2008-01-10 for "workflow": http://drupal.org/node/208363
-    // Modified 2008-03-21 for "feedapi": http://drupal.org/node/237258
-    if (arg(0) == 'node' && is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'outline' || arg(2) == 'track' || arg(2) == 'results' || arg(2) == 'access' || arg(2) == 'modr8' || arg(2) == 'ogmodr8' || arg(2) == 'delete' || arg(2) == 'galleries' || arg(2) == 'email' || arg(2) == 'revisions' || arg(2) == 'signups' || arg(2) == 'agenda' || arg(2) == 'workflow' || arg(2) == 'votes' || arg(2) == 'refresh' || arg(2) == 'purge')) {
-      $location = 2;
-      $nid = (int)arg(1);	
-      $gid = og_user_roles_getgid($nid, $uid);
-    }
-
+    // Translate pages using i18n translation module as per: http://drupal.org/node/203395
+	if (arg(0) == 'node' && arg(1) == 'add' && isset($_REQUEST['translation']))	{
+	  $nid = intval($_REQUEST['translation']);
+	  $gid = og_user_roles_getgid($nid, $uid);
+	  if ($gid) {
+	    // Troubleshooting
+	    // drupal_set_message('recognized translation node add, gid = '.$gid);	  
+	    $_GET['gids'] = array($gid); // inject gid
+	  }
+	}
+	
+	// http://doadance.scbbs.com/node/79/edit
+	// http://doadance.scbbs.com/node/79/outline
+	// http://doadance.scbbs.com/node/79/track
+	// http://doadance.scbbs.com/node/79/modr8
+	// http://doadance.scbbs.com/node/79/ogmodr8
+
+    // Modified 2007-07-05 for webform "results";
+    // Modified 2007-07-23 for content_access "access";
+    // Modified 2007-08-06 for modr8 "modr8" and "ogmodr8" (our own callback);
+    // Modified 2007-09-13 for "galleries";
+    // Modified 2007-09-14 for "email";
+    // Modified 2007-12-20 for "revisions": http://drupal.org/node/202196
+    // Modified 2008-01-10 for "workflow": http://drupal.org/node/208363
+    // Modified 2008-03-21 for "feedapi": http://drupal.org/node/237258
+    if (arg(0) == 'node' && is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'outline' || arg(2) == 'track' || arg(2) == 'results' || arg(2) == 'access' || arg(2) == 'modr8' || arg(2) == 'ogmodr8' || arg(2) == 'delete' || arg(2) == 'galleries' || arg(2) == 'email' || arg(2) == 'revisions' || arg(2) == 'signups' || arg(2) == 'agenda' || arg(2) == 'workflow' || arg(2) == 'votes' || arg(2) == 'refresh' || arg(2) == 'purge')) {
+      $location = 2;
+      $nid = (int)arg(1);	
+      $gid = og_user_roles_getgid($nid, $uid);
+    }
+
     // poll.module
-    if (arg(0) == 'poll' && is_numeric(arg(2)) && (arg(1) == 'cancel')) {
-      $location = 20;
-      $nid = (int)arg(2);	
-      $gid = og_user_roles_getgid($nid, $uid);
-    }
-
-    // Edit users (og_user_roles_approval)
-	//
-	// This will get a group context if the current user and the
-	// user he is trying to access both belong to at least the same
-	// group that is also the last group set by OG in "og_last" session
+    if (arg(0) == 'poll' && is_numeric(arg(2)) && (arg(1) == 'cancel')) {
+      $location = 20;
+      $nid = (int)arg(2);	
+      $gid = og_user_roles_getgid($nid, $uid);
+    }
+
+    // Edit users (og_user_roles_approval)
+	//
+	// This will get a group context if the current user and the
+	// user he is trying to access both belong to at least the same
+	// group that is also the last group set by OG in "og_last" session
 	// (which logically should be the current group);
     //
     // http://doadance.scbbs.com/oguseredit/72?gids[]=47
@@ -2007,50 +2007,50 @@ function og_user_roles_all_roles($user) 
         $gid = intval(current($_REQUEST['gids']));
       }
     }
-
-    // print.module (printer friendly)
-    //
+
+    // print.module (printer friendly)
+    //
     // http://www.mysite.com/print/14
     if (arg(0) == 'print' && is_numeric(arg(1))) {
-      header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
-      header('Cache-Control: no-store, no-cache, must-revalidate');
-      header('Cache-Control: post-check=0, pre-check=0', FALSE);
-      header('Pragma: no-cache'); 
-
-      cache_clear_all();
-
+      header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
+      header('Cache-Control: no-store, no-cache, must-revalidate');
+      header('Cache-Control: post-check=0, pre-check=0', FALSE);
+      header('Pragma: no-cache'); 
+
+      cache_clear_all();
+
       $location = 201;
       $nid = (int)arg(1);
       $gid = og_user_roles_getgid($nid, $uid);
-      // Set group context.
+      // Set group context.
       $group_node = node_load($gid);
       og_set_group_context($group_node);
     }
-
-    // oglogo (printer friendly)
-    //
+
+    // oglogo (printer friendly)
+    //
     // http://www.mysite.com/oglogo
     if (arg(0) == 'oglogo') {
-      if ($_SESSION['og_last']) {
+      if ($_SESSION['og_last']) {
         $location = 202;
-        $gid = $_SESSION['og_last']->nid;
+        $gid = $_SESSION['og_last']->nid;
         // Set group context.
         $group_node = node_load($gid);
         og_set_group_context($group_node);
-	  }
+	  }
     }
-
-    // Manage users (og_user_roles_approval)
-	//
-	// This will get a group context from og_last session
-	// and list all users in the group if the user listing
-	// is admin for the group and has the 'administer users' permission.
+
+    // Manage users (og_user_roles_approval)
+	//
+	// This will get a group context from og_last session
+	// and list all users in the group if the user listing
+	// is admin for the group and has the 'administer users' permission.
     //
     // http://doadance.scbbs.com/ogusermanage/47
     if (arg(0) == 'ogusermanage' AND is_numeric(arg(1))) {
       $gid = (int)arg(1);
     }
-
+
     //                           0    1    2
     // http://www.mysite.com/comment/edit/14
     if (arg(0) == 'comment' && is_numeric(arg(2)) && arg(1) == 'edit') {
@@ -2058,7 +2058,7 @@ function og_user_roles_all_roles($user) 
       $comment = _comment_load(arg(2));
       $nid = $comment->nid;
       $gid = og_user_roles_getgid($nid, $uid);
-      // Set group context.
+      // Set group context.
       $group_node = node_load($gid);
       og_set_group_context($group_node);
     }
@@ -2071,7 +2071,7 @@ function og_user_roles_all_roles($user) 
       $nid = $comment->nid;
       $gid = og_user_roles_getgid($nid, $uid);
     }
-
+
     //                           0      1    2
     // http://www.mysite.com/comment/reply/128#comment_form
     if (arg(0) == 'comment' && arg(1) == 'reply') {
@@ -2119,7 +2119,7 @@ function og_user_roles_all_roles($user) 
       $group_node = node_load($gid);
       og_set_group_context($group_node);
     }
-
+
     // og_vocab
     //
     // http://doadance.scbbs.com/node/29/og/vocab
@@ -2127,7 +2127,7 @@ function og_user_roles_all_roles($user) 
       $location = 61;
       $gid = (int)arg(1);
     }
-
+
     // og_vocab 
     //   
     // http://clients.brixrealtyinc.com/node/ogtermedit?destination=node%2F29%2Fog%2Fvocab%2Fterms%2F26&gids[]=29&tid=116
@@ -2142,7 +2142,7 @@ function og_user_roles_all_roles($user) 
         $gid = intval(current($_REQUEST['gids']));
       }
     }
-
+
     // og_user_roles
     //
     // http://doadance.scbbs.com/og/users/72/roles
@@ -2235,7 +2235,7 @@ function og_user_roles_all_roles($user) 
     }
 
     // modr8 view modr8_log
-    //          
+    //          
     // http://clients.brixrealtyinc.com/node/ogmodr8?gids[]=12&event=2
     //
     // Modification as per: http://drupal.org/node/164092
@@ -2248,7 +2248,7 @@ function og_user_roles_all_roles($user) 
         $gid = intval(current($_REQUEST['gids']));
       }
     }
-
+
     // og create nodes (custom node/20 aliased to node/ognodeadd)
     //          0     1   2           3
     // http://clients.brixrealtyinc.com/node/ognodeadd?type=document&gids[]=12
@@ -2266,71 +2266,71 @@ function og_user_roles_all_roles($user) 
         $gid = intval(current($_REQUEST['gids']));
       }
     }
-    
-	// File upload: http://www.scbbs.com/node/135/225#comment-225
-	if ((arg(0) == 'upload' && arg(1) == 'js') || (arg(0) == 'filemanager' && arg(1) == 'active')) {
+    
+	// File upload: http://www.scbbs.com/node/135/225#comment-225
+	if ((arg(0) == 'upload' && arg(1) == 'js') || (arg(0) == 'filemanager' && arg(1) == 'active')) {
       $location = 14;
-      // First, try and get gid from the session cookie
-      if ($_SESSION['og_last']) $gid = $_SESSION['og_last']->nid;
-	  // If gid is still = 0, then try getting it from referrer 
-	  if ($gid == 0 || is_null($gid)) {
-		if ($ref_arg[1] == 'node' && is_numeric($ref_arg[2]) && $ref_arg[3] == 'edit') {
+      // First, try and get gid from the session cookie
+      if ($_SESSION['og_last']) $gid = $_SESSION['og_last']->nid;
+	  // If gid is still = 0, then try getting it from referrer 
+	  if ($gid == 0 || is_null($gid)) {
+		if ($ref_arg[1] == 'node' && is_numeric($ref_arg[2]) && $ref_arg[3] == 'edit') {
           $nid = (int)$ref_arg[2];
-          $gid = og_user_roles_getgid($nid, $uid);
+          $gid = og_user_roles_getgid($nid, $uid);
 		  // Set group context.
           $group_node = node_load($gid);
           og_set_group_context($group_node);
-   		}
-		if ($ref_arg[1] == 'node' && $ref_arg[2] == 'ognodeadd') {
-          parse_str($ref_query);
+   		}
+		if ($ref_arg[1] == 'node' && $ref_arg[2] == 'ognodeadd') {
+          parse_str($ref_query);
           $gid = $gids[0];
-          // Set group context.
+          // Set group context.
           $group_node = node_load($gid);
           og_set_group_context($group_node);
-   		}		
-	  }
-	}
-	// File upload: Using wysiwygpro editor
-	if (arg(0) == 'modules' && arg(1) == 'wysiwygPro') {
+   		}		
+	  }
+	}
+	// File upload: Using wysiwygpro editor
+	if (arg(0) == 'modules' && arg(1) == 'wysiwygPro') {
       $location = 140;
-      // First, try and get gid from the session cookie
-      if ($_SESSION['og_user_role']) {
-          $gid = $_SESSION['og_user_role'];
+      // First, try and get gid from the session cookie
+      if ($_SESSION['og_user_role']) {
+          $gid = $_SESSION['og_user_role'];
 		  // Set group context.
           $group_node = node_load($gid);
           og_set_group_context($group_node);
-      }
-	}
-    // File download
-	if (arg(0) == 'system' && arg(1) == 'files') {
+      }
+	}
+    // File download
+	if (arg(0) == 'system' && arg(1) == 'files') {
       $location = 15;
-      if ($_SESSION['og_last']) $gid = $_SESSION['og_last']->nid;
-	}
-    // File download using FileManger and Attachment modules
-	if (arg(0) == 'filemanager' && arg(1) == 'active') {
+      if ($_SESSION['og_last']) $gid = $_SESSION['og_last']->nid;
+	}
+    // File download using FileManger and Attachment modules
+	if (arg(0) == 'filemanager' && arg(1) == 'active') {
       $location = 16;
-      if ($_SESSION['og_last']) $gid = $_SESSION['og_last']->nid;
-	}
-
-    // IMCE 
-	if (arg(0) == 'imce' && (arg(1) == 'browse' || arg(1) == 'upload')) {
+      if ($_SESSION['og_last']) $gid = $_SESSION['og_last']->nid;
+	}
+
+    // IMCE 
+	if (arg(0) == 'imce' && (arg(1) == 'browse' || arg(1) == 'upload')) {
       $location = 160;
-      if ($_SESSION['og_last']) {
-        $gid = $_SESSION['og_last']->nid;
+      if ($_SESSION['og_last']) {
+        $gid = $_SESSION['og_last']->nid;
         // Set group context.
         $group_node = node_load($gid);
         og_set_group_context($group_node);
-	  }
-	}
-
-    // Listing by taxonomy terms
-	if (arg(0) == 'taxonomy' && arg(1) == 'term') {
+	  }
+	}
+
+    // Listing by taxonomy terms
+	if (arg(0) == 'taxonomy' && arg(1) == 'term') {
       $location = 161;
-      if ($_SESSION['og_last']) $gid = $_SESSION['og_last']->nid;
-	}
-
-    // Files
-	if (arg(0) == 'files' || arg(1) == 'files') {
+      if ($_SESSION['og_last']) $gid = $_SESSION['og_last']->nid;
+	}
+
+    // Files
+	if (arg(0) == 'files' || arg(1) == 'files') {
       $location = 162;
       // Modification -- Get the gid from the variable instead of trying to calculate it.
       if (isset($_REQUEST['gids'])) {
@@ -2338,74 +2338,74 @@ function og_user_roles_all_roles($user) 
         $gids = $_GET['gids'];
         $gid = intval(current($_REQUEST['gids']));
         $group_node = node_load($gid);
-        og_set_group_context($group_node);
-      } elseif ($_SESSION['og_last']) {
+        og_set_group_context($group_node);
+      } elseif ($_SESSION['og_last']) {
         $location = 1622;
-        $gid = $_SESSION['og_last']->nid;
+        $gid = $_SESSION['og_last']->nid;
         $group_node = node_load($gid);
-        og_set_group_context($group_node);
-	  } else {
-	    // Need to get the file name;
+        og_set_group_context($group_node);
+	  } else {
+	    // Need to get the file name;
         $location = 1623;
-        $path = $_SERVER['REQUEST_URI'];
-        $basename = basename($path);        
-		$basename = urldecode($basename);
-        $basename = preg_replace("/\+/", " ", $basename);
-		// Now, get the node associated with this file;
-		// 6.x has different file structure
-//        $file = db_fetch_object(db_query("SELECT u.nid FROM {files} f INNER JOIN {upload} u ON f.fid = u.fid where f.filepath like '%s'", '%' . $basename));
-        $file = db_fetch_object(db_query("SELECT u.nid FROM {files} f INNER JOIN {upload} u ON f.fid = u.fid where f.filepath like '%s'", '%' . '/' . $basename));
+        $path = $_SERVER['REQUEST_URI'];
+        $basename = basename($path);        
+		$basename = urldecode($basename);
+        $basename = preg_replace("/\+/", " ", $basename);
+		// Now, get the node associated with this file;
+		// 6.x has different file structure
+//        $file = db_fetch_object(db_query("SELECT u.nid FROM {files} f INNER JOIN {upload} u ON f.fid = u.fid where f.filepath like '%s'", '%' . $basename));
+        $file = db_fetch_object(db_query("SELECT u.nid FROM {files} f INNER JOIN {upload} u ON f.fid = u.fid where f.filepath like '%s'", '%' . '/' . $basename));
 		$nid = $file->nid;
-        $gid = og_user_roles_getgid($nid, $uid);
+        $gid = og_user_roles_getgid($nid, $uid);
         $group_node = node_load($gid);
-        og_set_group_context($group_node);
+        og_set_group_context($group_node);
 	  }
-	}
-
-    // Agenda module
+	}
+
+    // Agenda module
     // http://doadance.scbbs.com/node/agenda/list/279
     if (arg(0) == 'node' && arg(1) == 'agenda' && arg(2) == 'list' && is_numeric(arg(3)) ) {
       $location = 17;
       $nid = (int)arg(3);
       $gid = og_user_roles_getgid($nid, $uid);
     }
-
-    // Modification as per: http://drupal.org/node/204080
-    // Galleries (view part: The view urls can have 'subdirs' so we may need to check until the nth arg)
-    if (module_exists("og_galleries")) {
-      $og_gal_parts=split('/',og_galleries_get_url());
-      if (!empty($og_gal_parts)) {
-        $is_og_gal_url=TRUE;
-        $arg_num=0;
-        foreach ($og_gal_parts as $value) {
-          if ($value != arg($arg_num++)) {
-            $is_og_gal_url=FALSE;
-          }
-        }
-        if ($is_og_gal_url && is_numeric(arg($arg_num))) {
-         $location = 18;
-         $gid = (int)arg($arg_num);
-        }
-      }
-    } 
-
-    // Book module
-	// As per: http://drupal.org/node/228386
+
+    // Modification as per: http://drupal.org/node/204080
+    // Galleries (view part: The view urls can have 'subdirs' so we may need to check until the nth arg)
+    if (module_exists("og_galleries")) {
+      $og_gal_parts=split('/',og_galleries_get_url());
+      if (!empty($og_gal_parts)) {
+        $is_og_gal_url=TRUE;
+        $arg_num=0;
+        foreach ($og_gal_parts as $value) {
+          if ($value != arg($arg_num++)) {
+            $is_og_gal_url=FALSE;
+          }
+        }
+        if ($is_og_gal_url && is_numeric(arg($arg_num))) {
+         $location = 18;
+         $gid = (int)arg($arg_num);
+        }
+      }
+    } 
+
+    // Book module
+	// As per: http://drupal.org/node/228386
     // http://doadance.scbbs.com/book/export/html/279
     if (arg(0) == 'book' && arg(1) == 'export' && arg(2) == 'html' && is_numeric(arg(3)) ) {
       $location = 19;
       $nid = (int)arg(3);
       $gid = og_user_roles_getgid($nid, $uid);
     }
-
-   // Modification. As per: http://drupal.org/node/176390
-   // Present a hook for other modules: hook_og_user_roles_gid()  
-   if ($results = module_invoke_all('og_user_roles_gid')) {
-     foreach ($results as $result) {
-       if ($result) $gid = $result;
-     }
-   }
-
+
+   // Modification. As per: http://drupal.org/node/176390
+   // Present a hook for other modules: hook_og_user_roles_gid()  
+   if ($results = module_invoke_all('og_user_roles_gid')) {
+     foreach ($results as $result) {
+       if ($result) $gid = $result;
+     }
+   }
+
   } // end $gid if
 
   //
@@ -2413,18 +2413,18 @@ function og_user_roles_all_roles($user) 
   //
   if (empty($gid)) {
     $gid = 0; // This prevents us from getting error on non-group node/add
-  }else{
-    $_SESSION['og_last']->nid = $gid;
-    $_SESSION['og_user_role'] = $gid;
+  }else{
+    $_SESSION['og_last']->nid = $gid;
+    $_SESSION['og_user_role'] = $gid;
   }
 
-/*
- * Modification as per http://drupal.org/node/189227
- * Makes sure use is "active" (not in moderation) before any of these group roles are added.
- * Was: $query = 'SELECT r.rid, r.name FROM {role} r INNER JOIN {og_users_roles} ogr ON r.rid = ogr.rid WHERE ogr.uid = %d AND ogr.gid = %d';
+/*
+ * Modification as per http://drupal.org/node/189227
+ * Makes sure use is "active" (not in moderation) before any of these group roles are added.
+ * Was: $query = 'SELECT r.rid, r.name FROM {role} r INNER JOIN {og_users_roles} ogr ON r.rid = ogr.rid WHERE ogr.uid = %d AND ogr.gid = %d';
  */
-
-  $query = 'SELECT r.rid, r.name FROM {role} r INNER JOIN {og_users_roles} ogr ON r.rid = ogr.rid INNER JOIN {og_uid} ogu ON ogu.uid = ogr.uid AND ogu.nid = ogr.gid WHERE ogr.uid = %d AND ogr.gid = %d AND ogu.is_active = 1';
+
+  $query = 'SELECT r.rid, r.name FROM {role} r INNER JOIN {og_users_roles} ogr ON r.rid = ogr.rid INNER JOIN {og_uid} ogu ON ogu.uid = ogr.uid AND ogu.nid = ogr.gid WHERE ogr.uid = %d AND ogr.gid = %d AND ogu.is_active = 1';
   $results = db_query($query, $uid, $gid);
 
   //
@@ -2454,15 +2454,15 @@ function og_user_roles_all_roles($user) 
   }
 
   // Write the test data: http://drupal.org/node/164038
-  if (variable_get('og_user_roles_test_default', 0) == 1) {
-    if (is_array($d)) {
-      $d1 = 'Roles Returned: ('. implode(',', $d) .')';
-	} else {
-	  $d1 = '';
+  if (variable_get('og_user_roles_test_default', 0) == 1) {
+    if (is_array($d)) {
+      $d1 = 'Roles Returned: ('. implode(',', $d) .')';
+	} else {
+	  $d1 = '';
 	}
-    og_user_roles_write_test($user, $location, $gid02, $gid, $uri_request_id, $d1, $ref);
+    og_user_roles_write_test($user, $location, $gid02, $gid, $uri_request_id, $d1, $ref);
   }
-
+
   // $d is either the merged results, or just $user->roles;
 
   return $d;
@@ -2473,7 +2473,7 @@ function og_user_roles_all_roles($user) 
  */
 function og_user_roles_getgid($nid, $uid) {
   $gid = 0;
-
+
   // If $gid still equals 0 then try searching og table
   // See if this is a group itself
   if ($gid == 0) {
@@ -2482,57 +2482,57 @@ function og_user_roles_getgid($nid, $uid
       $gid = $t->nid;
     }
   }
-
-  // See if our user is a member of this node's group.
-  //
+
+  // See if our user is a member of this node's group.
+  //
   if ($gid == 0) {
     $result = db_query("SELECT oga.group_nid from {og_ancestry} oga INNER JOIN {og_uid} ogu ON ogu.nid = oga.group_nid WHERE oga.nid = %d AND ogu.uid = %d", $nid, $uid);
     while ($t = db_fetch_object($result)) {
       $gid = $t->group_nid;
     }
   }
-
-  // If this user is not a member of this group (fails test above), and this is a public node, 
-  // then we just need to find the first group it belongs to.
-  //
-  // select og_ancestry.group_nid FROM og_ancestry WHERE og_ancestry.nid = 130 AND og_ancestry.is_public = 1
-  //
+
+  // If this user is not a member of this group (fails test above), and this is a public node, 
+  // then we just need to find the first group it belongs to.
+  //
+  // select og_ancestry.group_nid FROM og_ancestry WHERE og_ancestry.nid = 130 AND og_ancestry.is_public = 1
+  //
   if ($gid == 0) {
     $result = db_query("SELECT oga.group_nid FROM {og_ancestry} oga WHERE oga.nid = %d AND oga.is_public = 1", $nid);
     while ($t = db_fetch_object($result)) {
       $gid = $t->group_nid;
     }
   }
-
-/** 
- * If $gid still equals 0 then try searching node_access table
- * Modified as per: http://drupal.org/node/347277
- */
-  if ($gid == 0) {
-    $result = db_query("SELECT na.gid from {node_access} na INNER JOIN {og_uid} ogu ON na.gid = ogu.nid WHERE na.realm = 'og_subscriber' AND ogu.uid = %d AND (na.nid = %d)", $uid, $nid, $nid); // modified to check for either the node ID in node_access
-    while ($t = db_fetch_object($result)) {
-      $gid = $t->gid;
-    }
-  } 
-
-  if ($gid == 0) {
-    $result = db_query("SELECT na.gid from {node_access} na INNER JOIN {og_uid} ogu ON na.gid = ogu.nid WHERE na.realm = 'og_subscriber' AND ogu.uid = %d AND (na.gid = %d)", $uid, $nid, $nid); // modified to check for group ID in node_access
-    while ($t = db_fetch_object($result)) {
-      $gid = $t->gid;
-    }
-  } 
-
-/** 
- * Old code. Query too slow:
- * 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 = 2 AND (node_access.nid = 194 OR node_access.gid = 194)
- * 
- */
+
+/** 
+ * If $gid still equals 0 then try searching node_access table
+ * Modified as per: http://drupal.org/node/347277
+ */
+  if ($gid == 0) {
+    $result = db_query("SELECT na.gid from {node_access} na INNER JOIN {og_uid} ogu ON na.gid = ogu.nid WHERE na.realm = 'og_subscriber' AND ogu.uid = %d AND (na.nid = %d)", $uid, $nid, $nid); // modified to check for either the node ID in node_access
+    while ($t = db_fetch_object($result)) {
+      $gid = $t->gid;
+    }
+  } 
+
+  if ($gid == 0) {
+    $result = db_query("SELECT na.gid from {node_access} na INNER JOIN {og_uid} ogu ON na.gid = ogu.nid WHERE na.realm = 'og_subscriber' AND ogu.uid = %d AND (na.gid = %d)", $uid, $nid, $nid); // modified to check for group ID in node_access
+    while ($t = db_fetch_object($result)) {
+      $gid = $t->gid;
+    }
+  } 
+
+/** 
+ * Old code. Query too slow:
+ * 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 = 2 AND (node_access.nid = 194 OR node_access.gid = 194)
+ * 
+ */
 //  if ($gid == 0) {
 //    $result = db_query("SELECT na.gid from {node_access} na INNER JOIN {og_uid} ogu ON na.gid = ogu.nid WHERE na.realm = 'og_subscriber' AND ogu.uid = %d AND (na.nid = %d OR na.gid = %d)", $uid, $nid, $nid); // 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
@@ -2542,40 +2542,40 @@ function og_user_roles_getgid($nid, $uid
       $gid = $t->nid;
     }
   }
-
-  // As per: http://drupal.org/node/167180
+
+  // As per: http://drupal.org/node/167180
   // If gid still not found
   if ($gid == 0) {
-    $node = db_fetch_object(db_query('SELECT nid, type FROM {node} WHERE nid = %d', $nid));
-    if (og_is_group_type($node->type)) {
-      $gid = $node->nid;
-    } elseif (is_array($groups = og_get_node_groups($node))) {
-      $last_id = 0;
-      foreach ($groups as $id => $group) {
-        if ($group) {
-          // Need some way to determine the group to select in case of
-		  // multiple groups.  Going to try using og_last session cookie.
-		  // Just not sure if session will be set for current group by now.
-		  if ($id == $_SESSION['og_last']->nid) $gid = $id;
-		  $last_id = $id;
-		}
-      }
-	  // If there was no session with og_last session cookie, then set gid to last
-	  // id located in groups.  Roll of the dice until we can find something more
-	  // certain.
-	  if ($gid == 0) $gid = $last_id;
-    }
-  }
+    $node = db_fetch_object(db_query('SELECT nid, type FROM {node} WHERE nid = %d', $nid));
+    if (og_is_group_type($node->type)) {
+      $gid = $node->nid;
+    } elseif (is_array($groups = og_get_node_groups($node))) {
+      $last_id = 0;
+      foreach ($groups as $id => $group) {
+        if ($group) {
+          // Need some way to determine the group to select in case of
+		  // multiple groups.  Going to try using og_last session cookie.
+		  // Just not sure if session will be set for current group by now.
+		  if ($id == $_SESSION['og_last']->nid) $gid = $id;
+		  $last_id = $id;
+		}
+      }
+	  // If there was no session with og_last session cookie, then set gid to last
+	  // id located in groups.  Roll of the dice until we can find something more
+	  // certain.
+	  if ($gid == 0) $gid = $last_id;
+    }
+  }
   
   return $gid;
-
+
 } // end getgid()
 
 /**
  * Check if table exist.
  */
 function og_user_roles_table_exists($table) {
-  //  return db_num_rows(db_query("SHOW TABLES LIKE '{". db_escape_table($table) ."}'"));
+  //  return db_num_rows(db_query("SHOW TABLES LIKE '{". db_escape_table($table) ."}'"));
   // http://drupal.org/node/114774#db-num-rows (db_num_rows removed)
   return db_result(db_query("SHOW TABLES LIKE '{". db_escape_table($table) ."}'"));
 }
@@ -2600,13 +2600,13 @@ function og_user_roles_write_test($user,
   $test_perm = $d;
 
   if (og_user_roles_table_exists('{og_user_test}')) {
-    $test_query = "INSERT INTO og_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 ."')";
+    $test_query = "INSERT INTO og_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);
-  } else {
-    drupal_install_schema('og_user_test');
+  } else {
+    drupal_install_schema('og_user_test');
   }
 }
-
+
 
 /**
  * Create content
@@ -2614,8 +2614,8 @@ function og_user_roles_write_test($user,
  */
 function og_user_roles_ognodeadd() {
   global $user;
-
-  require('modules/node/node.pages.inc'); 
+
+  require('modules/node/node.pages.inc'); 
 
   $roles = og_user_roles_all_roles($user); // This returns normal $user->roles and includes OG roles if any
 
@@ -2640,54 +2640,54 @@ function og_user_roles_ognodeadd() {
     $access = module_invoke($module, 'access', 'create', $type, $user);
 
     if ($access === TRUE) {
-      
-    // Working on this issue: http://drupal.org/node/183096
-      $content_type = node_get_types('type', str_replace('-', '_', $type));
-      $output = '<p>'. filter_xss_admin($content_type->help) .'</p>';
+      
+    // Working on this issue: http://drupal.org/node/183096
+      $content_type = node_get_types('type', str_replace('-', '_', $type));
+      $output = '<p>'. filter_xss_admin($content_type->help) .'</p>';
       $output .= node_add($type);
     }
-
+
     else {
-
-      $output = 'Access denied.';
-	  
-	  // Old = type, message, severity, link
-	  // New = type, message, variables, severity, link
+
+      $output = 'Access denied.';
+	  
+	  // Old = type, message, severity, link
+	  // New = type, message, variables, severity, link
 
       watchdog('access denied', 'User can not create this node type:<b> '.$type.'</b>', $variables = array() , WATCHDOG_WARNING, 'node/ognodeadd?type='. $type .'&gids[]='. $gids[0]);
     }
-
-  }else{
-
-    /**
-     * Modification: Creates an overview page with the allowed node types for this user and group
-     * when there is no type in the url query. This page is similar to generic node/add page
-     * Taken and modified from node_add() function in node core module and og_og_create_links() in og module
-     * If no (valid) node type has been provided, display a node type overview.
-	 * http://drupal.org/node/203875
-	 */
-    $exempt = array_merge(og_get_types('group'), variable_get('og_omitted', array()));
-    foreach (node_get_types() as $type) {
-      // we used to check for node_access(create) but then node admins would get a false positive and see node types that they could not create
-      if (!in_array($type->type, $exempt) && module_invoke(node_get_types('module', $type), 'access', 'create', $type)) {
-        // Why is this needed?
-        // $type_url_str = str_replace('_', '-', $type->type);
-        $type_url_str = $type->type;
-        $title = t('Add a new @s.', array('@s' => $type->name));
-        $out = '<dt>'. l(drupal_ucfirst($type->name), "node/add/$type_url_str", array('attributes' => array('title' => $title), 'query' => 'gids[]='. $gids[0])) .'</dt>';
-        $out .= '<dd>'. filter_xss_admin($type->description) .'</dd>';
-        $item[$type->type] = $out;
-      }
-    }
-
-    if (isset($item)) {
-      uksort($item, 'strnatcasecmp');
-      $output = t('Choose the appropriate item from the list:') .'<dl>'. implode('', $item) .'</dl>';
-    }
-    else {
-      $output = t('No content types available.');
-    }
-  }
+
+  }else{
+
+    /**
+     * Modification: Creates an overview page with the allowed node types for this user and group
+     * when there is no type in the url query. This page is similar to generic node/add page
+     * Taken and modified from node_add() function in node core module and og_og_create_links() in og module
+     * If no (valid) node type has been provided, display a node type overview.
+	 * http://drupal.org/node/203875
+	 */
+    $exempt = array_merge(og_get_types('group'), variable_get('og_omitted', array()));
+    foreach (node_get_types() as $type) {
+      // we used to check for node_access(create) but then node admins would get a false positive and see node types that they could not create
+      if (!in_array($type->type, $exempt) && module_invoke(node_get_types('module', $type), 'access', 'create', $type)) {
+        // Why is this needed?
+        // $type_url_str = str_replace('_', '-', $type->type);
+        $type_url_str = $type->type;
+        $title = t('Add a new @s.', array('@s' => $type->name));
+        $out = '<dt>'. l(drupal_ucfirst($type->name), "node/add/$type_url_str", array('attributes' => array('title' => $title), 'query' => 'gids[]='. $gids[0])) .'</dt>';
+        $out .= '<dd>'. filter_xss_admin($type->description) .'</dd>';
+        $item[$type->type] = $out;
+      }
+    }
+
+    if (isset($item)) {
+      uksort($item, 'strnatcasecmp');
+      $output = t('Choose the appropriate item from the list:') .'<dl>'. implode('', $item) .'</dl>';
+    }
+    else {
+      $output = t('No content types available.');
+    }
+  }
 
   return $output;
 }
@@ -2698,7 +2698,7 @@ function og_user_roles_ognodeadd() {
  */
 function og_user_roles_ogtermedit() {
   require_once drupal_get_path('module', 'taxonomy'). '/taxonomy.admin.inc';
-
+
   global $user;
 
   $roles = og_user_roles_all_roles($user); // This returns normal $user->roles and includes OG roles if any
@@ -2709,7 +2709,7 @@ function og_user_roles_ogtermedit() {
      $group_node = node_load($gids[0]);
      og_set_group_context($group_node);
   }
-
+
   $tid = $_GET['tid'];
 
   $access = user_access('administer taxonomy');
@@ -2723,7 +2723,7 @@ function og_user_roles_ogtermedit() {
 
   return $output;
 }
-
+
 /**
  * View the modr8 log
  * Format: http://www.scbbs.com/node/ogmodr8?gids[]=29&event=2
@@ -2732,7 +2732,7 @@ function og_user_roles_ogmodr8() {
   global $user;
   // Need this in order to not get "undefined function" on "modr8_log_event" call below
   require_once drupal_get_path('module', 'modr8'). '/modr8_admin.inc';
-
+
   $roles = og_user_roles_all_roles($user); // This returns normal $user->roles and includes OG roles if any
 
   $user->roles = $roles;
@@ -2741,7 +2741,7 @@ function og_user_roles_ogmodr8() {
      $group_node = node_load($gids[0]);
      og_set_group_context($group_node);
   }
-
+
   $event = $_GET['event'];
 
   $access = user_access('moderate content');
@@ -2755,21 +2755,21 @@ function og_user_roles_ogmodr8() {
 
   return $output;
 }
-
+
 /**
  * Edit user
  * Format: http://www.scbbs.com/oguseredit/76?gids[]=47
  * Format: http://www.scbbs.com/oguseredit/76/edit?gids[]=47
  */
 function og_user_roles_oguseredit($uid = 0) {
-
+
   require_once drupal_get_path('module', 'user'). '/user.pages.inc';
-
+
   global $user;
 
   $roles = og_user_roles_all_roles($user); // This returns normal $user->roles and includes OG roles if any
 
-  $user->roles = $roles;
+  $user->roles = $roles;
   $gids = $_GET['gids'];
   if ($gids) {
      $group_node = node_load($gids[0]);
@@ -2777,371 +2777,371 @@ function og_user_roles_oguseredit($uid =
      og_set_group_context($group_node);
   }
 
-  $account = user_load(array('uid' => $uid));
-  $in_this_group = 'no';
-  $oguseredit = 'yes';
-
-  if (user_access('no oguseredit', $account)) $oguseredit = 'no';
-
- /**
-  * This checks all groups the user is a member of to see if any one has given the
-  * 'no oguseredit' permission.	 If one group has given him a role with this
-  * permission, then his profile cannot be edited using oguseredit.
-  */
-  $user_gids = array_keys($account->og_groups);
-  if ($user_gids) {
-    foreach ($user_gids as $user_gid) {
-      if (og_user_roles_user_access('no oguseredit', $user_gid, $uid) === TRUE) $oguseredit = 'no'; 
-    }
-  }
-
-  if (array_keys($account->og_groups)) {
-    if (array_key_exists($gid, $account->og_groups)) $in_this_group = 'yes';
-  }
-
-  $access = user_access('administer users');
-
-  if ($access === TRUE && $uid != 1 && $in_this_group == 'yes' && $oguseredit == 'yes') {
-    
-    if (arg(2) == 'edit') $output = drupal_get_form('user_profile_form', $account);
-    if (arg(2) == 'delete') $output = drupal_get_form('user_confirm_delete', $account);
+  $account = user_load(array('uid' => $uid));
+  $in_this_group = 'no';
+  $oguseredit = 'yes';
+
+  if (user_access('no oguseredit', $account)) $oguseredit = 'no';
+
+ /**
+  * This checks all groups the user is a member of to see if any one has given the
+  * 'no oguseredit' permission.	 If one group has given him a role with this
+  * permission, then his profile cannot be edited using oguseredit.
+  */
+  $user_gids = array_keys($account->og_groups);
+  if ($user_gids) {
+    foreach ($user_gids as $user_gid) {
+      if (og_user_roles_user_access('no oguseredit', $user_gid, $uid) === TRUE) $oguseredit = 'no'; 
+    }
+  }
+
+  if (array_keys($account->og_groups)) {
+    if (array_key_exists($gid, $account->og_groups)) $in_this_group = 'yes';
+  }
+
+  $access = user_access('administer users');
+
+  if ($access === TRUE && $uid != 1 && $in_this_group == 'yes' && $oguseredit == 'yes') {
+    
+    if (arg(2) == 'edit') $output = drupal_get_form('user_profile_form', $account);
+    if (arg(2) == 'delete') $output = drupal_get_form('user_confirm_delete', $account);
     if (is_null(arg(2))) $output = user_view($account);
   } else {
-    if ($oguseredit == 'no') drupal_set_message('This user account may not be edited using oguseredit.');
-    if ($in_this_group == 'no') drupal_set_message('This user is not a member of the current group.');
+    if ($oguseredit == 'no') drupal_set_message('This user account may not be edited using oguseredit.');
+    if ($in_this_group == 'no') drupal_set_message('This user is not a member of the current group.');
     $output = 'Access denied.';
     watchdog('access denied', 'oguseredit/'. $uid, WATCHDOG_WARNING);
   }
 
   return $output;
 }
-
-/**
- * Manage users from OG User Roles
- * ogusermanage
- */
-function og_user_roles_user_manage($gid) {
-  global $user;
+
+/**
+ * Manage users from OG User Roles
+ * ogusermanage
+ */
+function og_user_roles_user_manage($gid) {
+  global $user;
   $roles = og_user_roles_all_roles($user); // This returns normal $user->roles and includes OG roles if any
 
-  $user->roles = $roles;
-  $gids = array_keys($user->og_groups);
-
-  $this_gid = $gid;
-  if ($this_gid) {
+  $user->roles = $roles;
+  $gids = array_keys($user->og_groups);
+
+  $this_gid = $gid;
+  if ($this_gid) {
     $group_node = node_load($this_gid);
-    og_set_group_context($group_node);
+    og_set_group_context($group_node);
+  }
+
+  // Get the admin status for this user in this group;
+  $is_admin = 0;
+  if ($subscriptions = og_get_subscriptions($user->uid)) {
+    foreach ($subscriptions as $key => $val) {
+      // Debug
+      // print "key = " . $key . " is_admin = " . $val['is_admin'];
+      if ($key == $this_gid) {
+        $is_admin = $val['is_admin'];
+      }
+    }
   }
-
-  // Get the admin status for this user in this group;
-  $is_admin = 0;
-  if ($subscriptions = og_get_subscriptions($user->uid)) {
-    foreach ($subscriptions as $key => $val) {
-      // Debug
-      // print "key = " . $key . " is_admin = " . $val['is_admin'];
-      if ($key == $this_gid) {
-        $is_admin = $val['is_admin'];
-      }
-    }
-  }
-
+
   $items = db_query("SELECT uid FROM {users} ORDER BY name");
-  $output = "";
-
+  $output = "";
+
   while ($item = db_fetch_object($items)) {
-	$uid = $item->uid;
+	$uid = $item->uid;
     $account = user_load(array('uid' => $uid));
-    $account_gids = array_keys($account->og_groups);
-	$common_gids = array_intersect($gids, $account_gids);
-    if ($common_gids) {
-      foreach ($common_gids as $common) {
-        if ($common == $this_gid && $is_admin == 1 && user_access('administer users') && $uid != 1) {
- 	        $output .= "<li>" . l($account->name, 'oguseredit/' . $uid, array('attributes' => $attributes = array(), 'query' => 'gids[]=' . $this_gid)) . " | " . l('(edit)', 'oguseredit/' . $uid . '/edit', array('attributes' => $attributes = array(), 'query' => 'gids[]=' . $this_gid . '&destination=og/users/'.$this_gid.'/manage')) . " | " . l('(delete)', 'oguseredit/' . $uid . '/delete', array('attributes' => $attributes = array(), 'query' => 'gids[]=' . $this_gid . '&destination=og/users/'.$this_gid.'/manage')) . "</li>";
-         }
-      }
-    }
-  } // end while
-
+    $account_gids = array_keys($account->og_groups);
+	$common_gids = array_intersect($gids, $account_gids);
+    if ($common_gids) {
+      foreach ($common_gids as $common) {
+        if ($common == $this_gid && $is_admin == 1 && user_access('administer users') && $uid != 1) {
+ 	        $output .= "<li>" . l($account->name, 'oguseredit/' . $uid, array('attributes' => $attributes = array(), 'query' => 'gids[]=' . $this_gid)) . " | " . l('(edit)', 'oguseredit/' . $uid . '/edit', array('attributes' => $attributes = array(), 'query' => 'gids[]=' . $this_gid . '&destination=og/users/'.$this_gid.'/manage')) . " | " . l('(delete)', 'oguseredit/' . $uid . '/delete', array('attributes' => $attributes = array(), 'query' => 'gids[]=' . $this_gid . '&destination=og/users/'.$this_gid.'/manage')) . "</li>";
+         }
+      }
+    }
+  } // end while
+
   if ($output == "") $output = "<b>No users have been located for this group or you are not an admin user for this group!</b>";
-
-  return $output;
-}
-
-/**
- * Return group logo
- * oglogo
- */
-function og_user_roles_oglogo($uid) {
-
-  header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
-  header('Cache-Control: no-store, no-cache, must-revalidate');
-  header('Cache-Control: post-check=0, pre-check=0', FALSE);
-  header('Pragma: no-cache'); 
- 
-  cache_clear_all();
-
-  if (empty($uid)) {
-    global $user;
-  } else {
-    $user = user_load(array('uid' => $uid));
-  }
-
-  $location = "5";
-  $test_function = 'og_user_roles_oglogo';
-
-  $addr = $_SERVER['REMOTE_ADDR'];
-
-  $ref = $_SERVER["HTTP_REFERER"];
-  $ref_url = parse_url($ref);
-  $ref_path = $ref_url[path];
-  $ref_query = $ref_url[query];
-  $ref_arg = explode('/', $ref_path);
-
+
+  return $output;
+}
+
+/**
+ * Return group logo
+ * oglogo
+ */
+function og_user_roles_oglogo($uid) {
+
+  header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
+  header('Cache-Control: no-store, no-cache, must-revalidate');
+  header('Cache-Control: post-check=0, pre-check=0', FALSE);
+  header('Pragma: no-cache'); 
+ 
+  cache_clear_all();
+
+  if (empty($uid)) {
+    global $user;
+  } else {
+    $user = user_load(array('uid' => $uid));
+  }
+
+  $location = "5";
+  $test_function = 'og_user_roles_oglogo';
+
+  $addr = $_SERVER['REMOTE_ADDR'];
+
+  $ref = $_SERVER["HTTP_REFERER"];
+  $ref_url = parse_url($ref);
+  $ref_path = $ref_url[path];
+  $ref_query = $ref_url[query];
+  $ref_arg = explode('/', $ref_path);
+
   $group_node = og_get_group_context();
   $gid02 = $group_node->nid;
   $gid = $gid02;
-
+
   $uri_request_id = request_uri();
   $arg = explode('/', $uri_request_id);
-
-  if ($group_node = og_get_group_context()) {
-    $location .= "A";
-    $gid = $group_node->nid;
-    $logo = variable_get('og_user_roles_logo_' . $gid, '');
-    $_SESSION['oglogo'] = $logo;
-    variable_set('oglogo_' . $addr, $logo);
-  }
-
-  if ($ref_arg[1] == 'print' && is_numeric($ref_arg[2])) {
-    $location .= "B";
+
+  if ($group_node = og_get_group_context()) {
+    $location .= "A";
+    $gid = $group_node->nid;
+    $logo = variable_get('og_user_roles_logo_' . $gid, '');
+    $_SESSION['oglogo'] = $logo;
+    variable_set('oglogo_' . $addr, $logo);
+  }
+
+  if ($ref_arg[1] == 'print' && is_numeric($ref_arg[2])) {
+    $location .= "B";
     $nid = (int)$ref_arg[2];
-    $gid = og_user_roles_getgid($nid, $uid);
-    $logo = variable_get('og_user_roles_logo_' . $gid, '');
-    $_SESSION['oglogo'] = $logo;
-    variable_set('oglogo_' . $addr, $logo);
-  }
-
-  if (arg(0) == 'print' && arg(2) == 'og' && is_numeric(arg(3))) {
-    $location .= "C";
+    $gid = og_user_roles_getgid($nid, $uid);
+    $logo = variable_get('og_user_roles_logo_' . $gid, '');
+    $_SESSION['oglogo'] = $logo;
+    variable_set('oglogo_' . $addr, $logo);
+  }
+
+  if (arg(0) == 'print' && arg(2) == 'og' && is_numeric(arg(3))) {
+    $location .= "C";
     $nid = (int)arg(3);
-    $gid = og_user_roles_getgid($nid, $uid);
-    $logo = variable_get('og_user_roles_logo_' . $gid, '');
-    $_SESSION['oglogo'] = $logo;
-    variable_set('oglogo_' . $addr, $logo);
-  }
-
-  if ($ref_arg[1] == 'print' && is_numeric($ref_arg[4])) {
-    $location .= "D";
+    $gid = og_user_roles_getgid($nid, $uid);
+    $logo = variable_get('og_user_roles_logo_' . $gid, '');
+    $_SESSION['oglogo'] = $logo;
+    variable_set('oglogo_' . $addr, $logo);
+  }
+
+  if ($ref_arg[1] == 'print' && is_numeric($ref_arg[4])) {
+    $location .= "D";
     $nid = (int)$ref_arg[4];
-    $gid = og_user_roles_getgid($nid, $uid);
-    $logo = variable_get('og_user_roles_logo_' . $gid, '');
-    $_SESSION['oglogo'] = $logo;
-    variable_set('oglogo_' . $addr, $logo);
-  }
-
-
-//  if (empty($logo) && $_SESSION['oglogo']) {
-//    $location .= "E";
-//    $logo = $_SESSION['oglogo'];
-//  }
-
-//  if (empty($logo) && $_SESSION['og_last']->nid) {
-//    $location .= "F";
+    $gid = og_user_roles_getgid($nid, $uid);
+    $logo = variable_get('og_user_roles_logo_' . $gid, '');
+    $_SESSION['oglogo'] = $logo;
+    variable_set('oglogo_' . $addr, $logo);
+  }
+
+
+//  if (empty($logo) && $_SESSION['oglogo']) {
+//    $location .= "E";
+//    $logo = $_SESSION['oglogo'];
+//  }
+
+//  if (empty($logo) && $_SESSION['og_last']->nid) {
+//    $location .= "F";
 //    $nid = $_SESSION['og_last']->nid;
-//    $gid = og_user_roles_getgid($nid, $uid);
-//    $logo = variable_get('og_user_roles_logo_' . $gid, '');
-//  }
-
-// IE Print Problem: If we found $logo above, use this to locate it.
-// Problem is:  How do we not use this if logo is legitimately not found for group
-// after this user has found one that does exist?
-//
-  if (empty($logo) && empty($ref) && empty($gid) && $user->uid == 0) {
-    $location .= "G";
-    $logo = variable_get('oglogo_' . $addr, '');
-  }
-
-  $d = 'Session variables: (';
-  $d .= 'oglogo = ' . $_SESSION['oglogo'];
-  $d .= ' | og_last = ' . $_SESSION['og_last'];
-  $d .= ' | og_user_role = ' . $_SESSION['og_user_role'];
-  $d .= ' | gid = ' . $gid;
-  $d .= ' | remote_addr = ' . $addr;
-  $d .= ' | logo = ' . $logo;
-  $d .= ')';
-
-  if (empty($logo))  {
-    $location .= "H";
-    $logo = theme_get_setting('logo_path');
-  }
-
+//    $gid = og_user_roles_getgid($nid, $uid);
+//    $logo = variable_get('og_user_roles_logo_' . $gid, '');
+//  }
+
+// IE Print Problem: If we found $logo above, use this to locate it.
+// Problem is:  How do we not use this if logo is legitimately not found for group
+// after this user has found one that does exist?
+//
+  if (empty($logo) && empty($ref) && empty($gid) && $user->uid == 0) {
+    $location .= "G";
+    $logo = variable_get('oglogo_' . $addr, '');
+  }
+
+  $d = 'Session variables: (';
+  $d .= 'oglogo = ' . $_SESSION['oglogo'];
+  $d .= ' | og_last = ' . $_SESSION['og_last'];
+  $d .= ' | og_user_role = ' . $_SESSION['og_user_role'];
+  $d .= ' | gid = ' . $gid;
+  $d .= ' | remote_addr = ' . $addr;
+  $d .= ' | logo = ' . $logo;
+  $d .= ')';
+
+  if (empty($logo))  {
+    $location .= "H";
+    $logo = theme_get_setting('logo_path');
+  }
+
   // Write the test data: http://drupal.org/node/164038
-  if (variable_get('og_user_roles_test_default', 0) == 1) {
-    og_user_roles_write_test($user, $location, $gid02, $gid, $uri_request_id, $d, $ref, $test_function);
+  if (variable_get('og_user_roles_test_default', 0) == 1) {
+    og_user_roles_write_test($user, $location, $gid02, $gid, $uri_request_id, $d, $ref, $test_function);
+  }
+
+  if (empty($logo)) $logo = theme_get_setting('logo_path');
+
+  // Return image information
+  $info = image_get_info($logo);
+
+  // If file is not an image file (or is unsupported) then return an error
+  if (!$info['mime_type']) {
+    $text = "Unsupported Filetype: (" . $location . ")";
+    og_user_roles_oglogo_display_error($text);
+    return;
+  }
+
+  // Display headers so browser knows we're outputting an image
+  $headers = array('Content-Type: '.$info['mime_type']);
+  foreach ($headers as $header) {
+    header($header);
   }
-
-  if (empty($logo)) $logo = theme_get_setting('logo_path');
-
-  // Return image information
-  $info = image_get_info($logo);
-
-  // If file is not an image file (or is unsupported) then return an error
-  if (!$info['mime_type']) {
-    $text = "Unsupported Filetype: (" . $location . ")";
-    og_user_roles_oglogo_display_error($text);
-    return;
-  }
-
-  // Display headers so browser knows we're outputting an image
-  $headers = array('Content-Type: '.$info['mime_type']);
-  foreach ($headers as $header) {
-    header($header);
-  }
-
-  // Output image
-  $im = @readfile($logo);
-
-  // If there's been a problem, report it
-  if (!$im) og_user_roles_oglogo_display_error();
-
-}
-
-/**
- * Return group logo path from group gid
- */
-function og_user_roles_oglogo_gid($gid) {
-
-  $logo = variable_get('og_user_roles_logo_' . $gid, '');
-
-  return $logo;
-}
-
-function og_user_roles_oglogo_display_error($text = "Error Creating Logo") {
-  $im = imagecreate(181, 20);
-  $bg = imagecolorallocate($im, 255, 255, 255);
-  $textcolor = imagecolorallocate($im, 255, 0, 0);
-  imagestring($im, 5, 2, 1, $text, $textcolor);
-  header("Content-type: image/png");
-  imagepng($im);
-  imagedestroy($im);
-} // og_user_roles_oglogo_display_error
-
+
+  // Output image
+  $im = @readfile($logo);
+
+  // If there's been a problem, report it
+  if (!$im) og_user_roles_oglogo_display_error();
+
+}
+
+/**
+ * Return group logo path from group gid
+ */
+function og_user_roles_oglogo_gid($gid) {
+
+  $logo = variable_get('og_user_roles_logo_' . $gid, '');
+
+  return $logo;
+}
+
+function og_user_roles_oglogo_display_error($text = "Error Creating Logo") {
+  $im = imagecreate(181, 20);
+  $bg = imagecolorallocate($im, 255, 255, 255);
+  $textcolor = imagecolorallocate($im, 255, 0, 0);
+  imagestring($im, 5, 2, 1, $text, $textcolor);
+  header("Content-type: image/png");
+  imagepng($im);
+  imagedestroy($im);
+} // og_user_roles_oglogo_display_error
+
 /**
  * using the og_forum tid, get the group id
  * stolen from og_forum (had to in the case where og_user_roles user doesn't have latest
  * version of og_forum module which includes this)
  */
-function og_user_roles_gid_from_tid($tid = 0) {
-  // Modification as per: http://drupal.org/node/172923
-  if (module_exists('og_forum')) {
-    $sql = "SELECT nid FROM {og_term} WHERE tid = %d";
-    $gid = db_result(db_query($sql, $tid));
-  }
-  return empty($gid) ? 0 : $gid; // As per http://drupal.org/node/194214
-}
-
+function og_user_roles_gid_from_tid($tid = 0) {
+  // Modification as per: http://drupal.org/node/172923
+  if (module_exists('og_forum')) {
+    $sql = "SELECT nid FROM {og_term} WHERE tid = %d";
+    $gid = db_result(db_query($sql, $tid));
+  }
+  return empty($gid) ? 0 : $gid; // As per http://drupal.org/node/194214
+}
+
 /**
  * using the og_vocab tid, get the group id
  */
 function og_user_roles_gid_from_og_vocab_tid($tid = 0) {
-  $gid = 0;
+  $gid = 0;
   $result = db_query("SELECT ogv.nid FROM {og_vocab} ogv INNER JOIN {vocabulary} v ON v.vid = ogv.vid INNER JOIN {term_data} td ON td.vid = v.vid WHERE td.tid = %d", $tid); // Get the group node of this term, if it is a group term
   while ($t = db_fetch_object($result)) {
     $gid = $t->nid;
   }
   return $gid;
 }
-
+
 /**
  * using the modr8 event log, get the group id
  */
 function og_user_roles_gid_from_modr8_event($event = 0) {
-  $gid = 0;
+  $gid = 0;
   $result = db_query("SELECT o.group_nid FROM {modr8_log} m INNER JOIN {og_ancestry} o ON o.nid = m.nid WHERE m.modid = %d", $event); // Get the group this node belongs to.
   while ($t = db_fetch_object($result)) {
     $gid = $t->group_nid;
   }
   return $gid;
 }
-
-/**
- * Get gid from session og_last or referrer
- */
-function og_user_roles_gid_from_referrer() {
-
-  $gid = 0;
-
+
+/**
+ * Get gid from session og_last or referrer
+ */
+function og_user_roles_gid_from_referrer() {
+
+  $gid = 0;
+
   // Need to use the referrer to get OG group in some cases;
-  $ref = $_SERVER["HTTP_REFERER"];
-  $ref_url = parse_url($ref);
-  $ref_path = $ref_url[path];
-  $ref_query = $ref_url[query];
-  $ref_arg = explode('/', $ref_path);
-
-  // First, try and get gid from the session cookie
-  if ($_SESSION['og_last']) $gid = $_SESSION['og_last']->nid;
-  // If gid is still = 0, then try getting it from referrer 
-  if ($gid == 0 || is_null($gid)) {
-    if ($ref_arg[1] == 'node' && is_numeric($ref_arg[2]) && $ref_arg[3] == 'edit') {
+  $ref = $_SERVER["HTTP_REFERER"];
+  $ref_url = parse_url($ref);
+  $ref_path = $ref_url[path];
+  $ref_query = $ref_url[query];
+  $ref_arg = explode('/', $ref_path);
+
+  // First, try and get gid from the session cookie
+  if ($_SESSION['og_last']) $gid = $_SESSION['og_last']->nid;
+  // If gid is still = 0, then try getting it from referrer 
+  if ($gid == 0 || is_null($gid)) {
+    if ($ref_arg[1] == 'node' && is_numeric($ref_arg[2]) && $ref_arg[3] == 'edit') {
       $nid = (int)$ref_arg[2];
-      $gid = og_user_roles_getgid($nid, $uid);
-    }
-	if ($ref_arg[1] == 'node' && $ref_arg[2] == 'ognodeadd') {
-      parse_str($ref_query);
+      $gid = og_user_roles_getgid($nid, $uid);
+    }
+	if ($ref_arg[1] == 'node' && $ref_arg[2] == 'ognodeadd') {
+      parse_str($ref_query);
       $gid = $gids[0];
-    }		
-  }
-
-  return $gid;
-}
-
-/**
- * Get gid from registration code
- */
-function og_user_roles_gid_from_regcode($regcode) {
-  $gid = 0;
-  // Get the list of OG groups
+    }		
+  }
+
+  return $gid;
+}
+
+/**
+ * Get gid from registration code
+ */
+function og_user_roles_gid_from_regcode($regcode) {
+  $gid = 0;
+  // Get the list of OG groups
   $groups = og_all_groups_options();
-  foreach ($groups as $group => $title) {
-    // Only process groups that are allowed to have registration codes
-    if (variable_get('og_user_roles_assign_regcode_' . $group, 0) == 1) {
-      // Get the array of codes for this group.
-      $group_array = explode(',', variable_get('og_user_roles_regcode_value_' . $group, ''));
-      if (in_array($regcode, $group_array)) {
-        $gid = $group;
-      }
-    }
-  }
-  return $gid;
-}
-
-
-/**
- * Created to check a view before I execute it.  Needed for OG Home Pages with multiple
- * embedded views because if one has no ndoes, then the entire page won't print.
- * Don't want that, so created this utility to check before the view is rendered.
- */
-function og_user_roles_checkview($viewname, $args) {
-  $view = views_get_view($viewname);
-  $items = views_build_view('items', $view, $args, 4, 5);
-  if ($items['items']) {
-    $result = 1;
-  } else {
-    $result = 0;
-  }
-  return $result;
-}
-
-/**
- * Implementation of hook_form_alter
- * Adds ability to set default group role for new members for an individual
- * group.
- */
-function og_user_roles_form_alter(&$form, $form_state, $form_id) {
-  // If this is a registration form, put the Group Register box on it if appropriate.
-  // Anonymous users need 'use registration codes' permission
-  // 'Allow Registration Codes' in OGUR settings must be checked on.
-  if ($form_id == 'user_register') {
+  foreach ($groups as $group => $title) {
+    // Only process groups that are allowed to have registration codes
+    if (variable_get('og_user_roles_assign_regcode_' . $group, 0) == 1) {
+      // Get the array of codes for this group.
+      $group_array = explode(',', variable_get('og_user_roles_regcode_value_' . $group, ''));
+      if (in_array($regcode, $group_array)) {
+        $gid = $group;
+      }
+    }
+  }
+  return $gid;
+}
+
+
+/**
+ * Created to check a view before I execute it.  Needed for OG Home Pages with multiple
+ * embedded views because if one has no ndoes, then the entire page won't print.
+ * Don't want that, so created this utility to check before the view is rendered.
+ */
+function og_user_roles_checkview($viewname, $args) {
+  $view = views_get_view($viewname);
+  $items = views_build_view('items', $view, $args, 4, 5);
+  if ($items['items']) {
+    $result = 1;
+  } else {
+    $result = 0;
+  }
+  return $result;
+}
+
+/**
+ * Implementation of hook_form_alter
+ * Adds ability to set default group role for new members for an individual
+ * group.
+ */
+function og_user_roles_form_alter(&$form, $form_state, $form_id) {
+  // If this is a registration form, put the Group Register box on it if appropriate.
+  // Anonymous users need 'use registration codes' permission
+  // 'Allow Registration Codes' in OGUR settings must be checked on.
+  if ($form_id == 'user_register' && user_access('use registration codes')) {
     if (!isset($form['og_register'])) {
       $form['og_register'] = array('#type' => 'fieldset', '#title' => t('Groups'));
     }
@@ -3152,17 +3152,17 @@ function og_user_roles_form_alter(&$form
       '#description' => t('If you received a group registration code, enter it here.'),
     );
   }
-  $roles = array();
-  // If this is a group node edit (use og_last to determine if this is a group node) and
-  // the user has the 'configure member roles' permission, and we allow group admins
-  // to set default group roles, then print the 'basicgrouprole' form on the
-  // group edit form.
-  if (arg(0) == 'node' && ($_SESSION['og_last']->nid == arg(1)) && arg(2) == 'edit' && user_access('configure member roles') && variable_get('og_user_roles_assign_basicgrouprole_gid', 0) == 1) {
-    $gid = arg(1);
-
-    // First, we need to get a list of all og-enabled node types
-    $group_types = og_get_types('group');
-    foreach ($group_types as $type) {
+  $roles = array();
+  // If this is a group node edit (use og_last to determine if this is a group node) and
+  // the user has the 'configure member roles' permission, and we allow group admins
+  // to set default group roles, then print the 'basicgrouprole' form on the
+  // group edit form.
+  if (arg(0) == 'node' && ($_SESSION['og_last']->nid == arg(1)) && arg(2) == 'edit' && user_access('configure member roles') && variable_get('og_user_roles_assign_basicgrouprole_gid', 0) == 1) {
+    $gid = arg(1);
+
+    // First, we need to get a list of all og-enabled node types
+    $group_types = og_get_types('group');
+    foreach ($group_types as $type) {
       // Get list of assignable group roles for this group type
       $role_ids = variable_get("og_user_roles_roles_{$type}", array());
       $all_roles = user_roles();
@@ -3171,40 +3171,40 @@ function og_user_roles_form_alter(&$form
           $roles[$rid] = $all_roles[$rid];
         }
       }
-      // If the form loaded is this type then we can move on
-      if ($type != '' && $form_id == $type . "_node_form")  {
-        $form['og_user_roles_basicgrouprole_gid'] = array(
-          '#type' => 'fieldset',
-          '#title' => t('Default Basic Group Role for new subscribers to this group.'),
-          '#description' => t('Allows you to select a group role to automatically assign to users who join this group. The role is specific to this group. That is, the user will only have the privileges of the role while he is visiting this group.  You must have the <b>configure member roles</b> permission to use this setting.'),
-          '#collapsible' => TRUE,
+      // If the form loaded is this type then we can move on
+      if ($type != '' && $form_id == $type . "_node_form")  {
+        $form['og_user_roles_basicgrouprole_gid'] = array(
+          '#type' => 'fieldset',
+          '#title' => t('Default Basic Group Role for new subscribers to this group.'),
+          '#description' => t('Allows you to select a group role to automatically assign to users who join this group. The role is specific to this group. That is, the user will only have the privileges of the role while he is visiting this group.  You must have the <b>configure member roles</b> permission to use this setting.'),
+          '#collapsible' => TRUE,
           '#collapsed' => TRUE,
-          );
-        $form['og_user_roles_basicgrouprole_gid']['og_user_roles_assign_basicgrouprole_' . $gid] = array(
-          '#type' => 'checkbox',
-          '#title' => t('Set default basic group (group limited) role for users who join this group?'),
-          '#default_value' => variable_get('og_user_roles_assign_basicgrouprole_' . $gid, 0),
-          '#description' => t('Do you wish to automatically assign a specific "basic group role" to <b>every new subscriber to this group</b> at the time he subscribes to this group? The role is limited to this group. This role assignment can be be removed by the groups\' admin(s)'),
-          );
-        $form['og_user_roles_basicgrouprole_gid']['og_user_roles_basicgrouprole_value_' . $gid] = array(
-          '#type' => 'select',
-          '#title' => t('Role to use as a basic group role'),
-          '#options' => $roles,
-          '#default_value' => variable_get('og_user_roles_basicgrouprole_value_' . $gid, 0),
-          '#description' => t('Select the role you wish to use as the "basic group role" for every new subscriber to this group.'),
-          );      
-         $form['#submit'][] = 'og_user_roles_basicgrouprole_form_submit';          
-      }
-    }
-  }
-
-  // If this is a group node edit (use og_last to determine if this is a group node) 
-  if (arg(0) == 'node' && ($_SESSION['og_last']->nid == arg(1)) && arg(2) == 'edit' ) {
-    $gid = arg(1);
-
-    // First, we need to get a list of all og-enabled node types
-    $group_types = og_get_types('group');
-    foreach ($group_types as $type) {
+          );
+        $form['og_user_roles_basicgrouprole_gid']['og_user_roles_assign_basicgrouprole_' . $gid] = array(
+          '#type' => 'checkbox',
+          '#title' => t('Set default basic group (group limited) role for users who join this group?'),
+          '#default_value' => variable_get('og_user_roles_assign_basicgrouprole_' . $gid, 0),
+          '#description' => t('Do you wish to automatically assign a specific "basic group role" to <b>every new subscriber to this group</b> at the time he subscribes to this group? The role is limited to this group. This role assignment can be be removed by the groups\' admin(s)'),
+          );
+        $form['og_user_roles_basicgrouprole_gid']['og_user_roles_basicgrouprole_value_' . $gid] = array(
+          '#type' => 'select',
+          '#title' => t('Role to use as a basic group role'),
+          '#options' => $roles,
+          '#default_value' => variable_get('og_user_roles_basicgrouprole_value_' . $gid, 0),
+          '#description' => t('Select the role you wish to use as the "basic group role" for every new subscriber to this group.'),
+          );      
+         $form['#submit'][] = 'og_user_roles_basicgrouprole_form_submit';          
+      }
+    }
+  }
+
+  // If this is a group node edit (use og_last to determine if this is a group node) 
+  if (arg(0) == 'node' && ($_SESSION['og_last']->nid == arg(1)) && arg(2) == 'edit' ) {
+    $gid = arg(1);
+
+    // First, we need to get a list of all og-enabled node types
+    $group_types = og_get_types('group');
+    foreach ($group_types as $type) {
       // Get list of assignable group roles for this group type
       $role_ids = variable_get("og_user_roles_roles_{$type}", array());
       $all_roles = user_roles();
@@ -3213,240 +3213,240 @@ function og_user_roles_form_alter(&$form
           $roles[$rid] = $all_roles[$rid];
         }
       }
-      
-      // If the form loaded is this type then we can move on
-      if ($type != '' && $form_id == $type . "_node_form")  {
-
-        // Group Logo Location
-
-        if(variable_get('og_user_roles_logo_enabled', '1') ) {
-          $form['og_user_roles_logo'] = array(
-            '#type' => 'fieldset',
-            '#title' => t('Group Logo location.'),
-            '#description' => t('Allows you to supply location of logo to be used with this group. You can provide either the URL to the file if it is available on a remote website, or the relative file path if it is available locally (i.e., on this server). You can use <strong>File attachments</strong> to upload the file to this server.'),
-            '#collapsible' => TRUE,
+      
+      // If the form loaded is this type then we can move on
+      if ($type != '' && $form_id == $type . "_node_form")  {
+
+        // Group Logo Location
+
+        if(variable_get('og_user_roles_logo_enabled', '1') ) {
+          $form['og_user_roles_logo'] = array(
+            '#type' => 'fieldset',
+            '#title' => t('Group Logo location.'),
+            '#description' => t('Allows you to supply location of logo to be used with this group. You can provide either the URL to the file if it is available on a remote website, or the relative file path if it is available locally (i.e., on this server). You can use <strong>File attachments</strong> to upload the file to this server.'),
+            '#collapsible' => TRUE,
             '#collapsed' => TRUE,
-            );
-          $form['og_user_roles_logo']['og_user_roles_logo_' . $gid] = array(
-            '#type' => 'textfield',
-            '#title' => t('Location of group logo?'),
-            '#default_value' => variable_get('og_user_roles_logo_' . $gid, ''),
-            '#description' => t('Enter either the local file path or the remote URL for the image to be used as the logo for this group. Enter one of the following formats: <strong>http://www.yoursite.com/yourlogo.gif</strong> (for remote file) or <strong>files/yourlogo.gif</strong> (for local file). You can attach the file you wish to use to this group using <strong>File attachments</strong> section below, then supply local path here once the file is uploaded (attached).  Your logo image must not exceed these size dimensions: Width (in pixels): <strong>' . variable_get('og_user_roles_logo_width', '135') . 'px</strong> Height (in pixels): <strong>' . variable_get('og_user_roles_logo_height', '113') . 'px</strong>'),
-            );
-          $form['#validate'][] = 'og_user_roles_logo_form_validate';          
-          $form['#submit'][] = 'og_user_roles_logo_form_submit';          
-		}
-
-        // Add the code to display 'Create content' link and/or remove 'create_' links.
-
-        if (variable_get('og_user_roles_menu_options_enabled', 1)) {
-          $form['og_user_roles_links_gid'] = array(
-            '#type' => 'fieldset',
-            '#title' => t('Control group menu content links.'),
-            '#collapsible' => TRUE,
+            );
+          $form['og_user_roles_logo']['og_user_roles_logo_' . $gid] = array(
+            '#type' => 'textfield',
+            '#title' => t('Location of group logo?'),
+            '#default_value' => variable_get('og_user_roles_logo_' . $gid, ''),
+            '#description' => t('Enter either the local file path or the remote URL for the image to be used as the logo for this group. Enter one of the following formats: <strong>http://www.yoursite.com/yourlogo.gif</strong> (for remote file) or <strong>files/yourlogo.gif</strong> (for local file). You can attach the file you wish to use to this group using <strong>File attachments</strong> section below, then supply local path here once the file is uploaded (attached).  Your logo image must not exceed these size dimensions: Width (in pixels): <strong>' . variable_get('og_user_roles_logo_width', '135') . 'px</strong> Height (in pixels): <strong>' . variable_get('og_user_roles_logo_height', '113') . 'px</strong>'),
+            );
+          $form['#validate'][] = 'og_user_roles_logo_form_validate';          
+          $form['#submit'][] = 'og_user_roles_logo_form_submit';          
+		}
+
+        // Add the code to display 'Create content' link and/or remove 'create_' links.
+
+        if (variable_get('og_user_roles_menu_options_enabled', 1)) {
+          $form['og_user_roles_links_gid'] = array(
+            '#type' => 'fieldset',
+            '#title' => t('Control group menu content links.'),
+            '#collapsible' => TRUE,
             '#collapsed' => TRUE,
-            );
-          $form['og_user_roles_links_gid']['og_user_roles_links_content_' . $gid] = array(
-            '#type' => 'checkbox',
-            '#title' => t('Display the <strong>Create content</strong> link?'),
-            '#default_value' => variable_get('og_user_roles_links_content_' . $gid, 0),
-            '#description' => t('Do you wish to display the OGUR <strong>Create content</strong> link on this group\'s menu?'),
-            );
-          $form['og_user_roles_links_gid']['og_user_roles_links_remove_' . $gid] = array(
-            '#type' => 'checkbox',
-            '#title' => t('Remove the default <strong>Create</strong> links?'),
-            '#default_value' => variable_get('og_user_roles_links_remove_' . $gid, 0),
-            '#description' => t('Do you wish to remove the default OG <strong>Create</strong> content links on this group\'s menu?'),
-            );
-          $form['#submit'][] = 'og_user_roles_links_form_submit';          
-		}
-
-        // Add the code to disallow public posts to the
-        // group edit form.
-
-          $form['og_user_roles_nopublic_gid'] = array(
-            '#type' => 'fieldset',
-            '#title' => t('Disallow public posts in this group.'),
-            '#description' => t('Allows you to prevent any <strong>Public</strong> posts from this group.  That is, no post made in this group may have the <strong>Public</strong> box checked.  In addition, if OG Forums is installed and this is a group <strong>Forum topic</strong> post, then the forum group selected in the <strong>Forums</strong> pull-down menu on the edit form must match this group, or the post will be rejected.'),
-            '#collapsible' => TRUE,
+            );
+          $form['og_user_roles_links_gid']['og_user_roles_links_content_' . $gid] = array(
+            '#type' => 'checkbox',
+            '#title' => t('Display the <strong>Create content</strong> link?'),
+            '#default_value' => variable_get('og_user_roles_links_content_' . $gid, 0),
+            '#description' => t('Do you wish to display the OGUR <strong>Create content</strong> link on this group\'s menu?'),
+            );
+          $form['og_user_roles_links_gid']['og_user_roles_links_remove_' . $gid] = array(
+            '#type' => 'checkbox',
+            '#title' => t('Remove the default <strong>Create</strong> links?'),
+            '#default_value' => variable_get('og_user_roles_links_remove_' . $gid, 0),
+            '#description' => t('Do you wish to remove the default OG <strong>Create</strong> content links on this group\'s menu?'),
+            );
+          $form['#submit'][] = 'og_user_roles_links_form_submit';          
+		}
+
+        // Add the code to disallow public posts to the
+        // group edit form.
+
+          $form['og_user_roles_nopublic_gid'] = array(
+            '#type' => 'fieldset',
+            '#title' => t('Disallow public posts in this group.'),
+            '#description' => t('Allows you to prevent any <strong>Public</strong> posts from this group.  That is, no post made in this group may have the <strong>Public</strong> box checked.  In addition, if OG Forums is installed and this is a group <strong>Forum topic</strong> post, then the forum group selected in the <strong>Forums</strong> pull-down menu on the edit form must match this group, or the post will be rejected.'),
+            '#collapsible' => TRUE,
             '#collapsed' => TRUE,
-            );
-          $form['og_user_roles_nopublic_gid']['og_user_roles_assign_nopublic_' . $gid] = array(
-            '#type' => 'checkbox',
-            '#title' => t('Do not allow public posts in this group?'),
-            '#default_value' => variable_get('og_user_roles_assign_nopublic_' . $gid, 0),
-            '#description' => t('Do you wish to disallow public postings from this group?'),
-            );
-          $form['#submit'][] = 'og_user_roles_nopublic_form_submit';          
-
-        // If the user has the 'manage registration codes' permission, and we allow group admins
-        // to set registration codes, then print the 'regcode' form on the
-        // group edit form.
-        if (user_access('manage registration codes') && variable_get('og_user_roles_assign_regcode_gid', 0) == 1) {
-
-          $form['og_user_roles_regcode_gid'] = array(
-            '#type' => 'fieldset',
-            '#title' => t('Registration code for new subscribers to this group.'),
-            '#description' => t('Allows you to enter registration codes that can be used for new users to automatically subscribe to this group and bypass moderation. This will only work if this group is in <b>moderation</b> status.  You must have the <b>manage registration codes</b> permission to use this setting.'),
-            '#collapsible' => TRUE,
+            );
+          $form['og_user_roles_nopublic_gid']['og_user_roles_assign_nopublic_' . $gid] = array(
+            '#type' => 'checkbox',
+            '#title' => t('Do not allow public posts in this group?'),
+            '#default_value' => variable_get('og_user_roles_assign_nopublic_' . $gid, 0),
+            '#description' => t('Do you wish to disallow public postings from this group?'),
+            );
+          $form['#submit'][] = 'og_user_roles_nopublic_form_submit';          
+
+        // If the user has the 'manage registration codes' permission, and we allow group admins
+        // to set registration codes, then print the 'regcode' form on the
+        // group edit form.
+        if (user_access('manage registration codes') && variable_get('og_user_roles_assign_regcode_gid', 0) == 1) {
+
+          $form['og_user_roles_regcode_gid'] = array(
+            '#type' => 'fieldset',
+            '#title' => t('Registration code for new subscribers to this group.'),
+            '#description' => t('Allows you to enter registration codes that can be used for new users to automatically subscribe to this group and bypass moderation. This will only work if this group is in <b>moderation</b> status.  You must have the <b>manage registration codes</b> permission to use this setting.'),
+            '#collapsible' => TRUE,
             '#collapsed' => TRUE,
-            );
-          $form['og_user_roles_regcode_gid']['og_user_roles_assign_regcode_' . $gid] = array(
-            '#type' => 'checkbox',
-            '#title' => t('Set registration codes to allow users to join this group?'),
-            '#default_value' => variable_get('og_user_roles_assign_regcode_' . $gid, 0),
-            '#description' => t('Do you wish to enter registration codes that will allow new subscribers to bypass admin approval and join this group?'),
-            );
-          $form['og_user_roles_regcode_gid']['og_user_roles_delete_regcode_' . $gid] = array(
-            '#type' => 'checkbox',
-            '#title' => t('Delete registration code after it is used?'),
-            '#default_value' => variable_get('og_user_roles_delete_regcode_' . $gid, 0),
-            '#description' => t('Do you want to delete each individual registration code after it is used to successfully subscribe a user to the group?'),
-            );
-          $form['og_user_roles_regcode_gid']['og_user_roles_regcode_value_' . $gid] = array(
+            );
+          $form['og_user_roles_regcode_gid']['og_user_roles_assign_regcode_' . $gid] = array(
+            '#type' => 'checkbox',
+            '#title' => t('Set registration codes to allow users to join this group?'),
+            '#default_value' => variable_get('og_user_roles_assign_regcode_' . $gid, 0),
+            '#description' => t('Do you wish to enter registration codes that will allow new subscribers to bypass admin approval and join this group?'),
+            );
+          $form['og_user_roles_regcode_gid']['og_user_roles_delete_regcode_' . $gid] = array(
+            '#type' => 'checkbox',
+            '#title' => t('Delete registration code after it is used?'),
+            '#default_value' => variable_get('og_user_roles_delete_regcode_' . $gid, 0),
+            '#description' => t('Do you want to delete each individual registration code after it is used to successfully subscribe a user to the group?'),
+            );
+          $form['og_user_roles_regcode_gid']['og_user_roles_regcode_value_' . $gid] = array(
             '#type' => 'textarea',
             '#title' => t('Registration codes for allowing users to subscribe to this group without admin approval'),
-            '#default_value' => variable_get('og_user_roles_regcode_value_' . $gid, ''),
+            '#default_value' => variable_get('og_user_roles_regcode_value_' . $gid, ''),
             '#cols' => 50,
             '#rows' => 2,
             '#description' => t('Specify here the registration codes which will allow users who enter them to subscribe to this moderated group without being manually approved by the group administrator. Structure your entries like this:
               <p><strong>Code1,Code2,Code3<br /></strong></p>
               <p>Each registration code separated by a comma. No spaces.'),
             );
-      	  // They only see this if they can configure user roles
-          if (user_access('configure member roles')) {
-            $form['og_user_roles_regcode_gid']['og_user_roles_assign_regcoderole_' . $gid] = array(
-              '#type' => 'checkbox',
-              '#title' => t('Set default basic group (group limited) role for users who join this group using this registration code?'),
-              '#default_value' => variable_get('og_user_roles_assign_regcoderole_' . $gid, 0),
-              '#description' => t('Do you wish to automatically assign a specific "registration code group role" to new subscribers to this group <b>who use this registration code to subscribe</b> to this group? The role is limited to this group. This role assignment can be be removed by the groups\' admin(s)'),
-              );
-            $form['og_user_roles_regcode_gid']['og_user_roles_regcoderole_value_' . $gid] = array(
-              '#type' => 'select',
-              '#title' => t('Role to assign'),
-              '#options' => $roles,
-              '#default_value' => variable_get('og_user_roles_regcoderole_value_' . $gid, 0),
-              '#description' => t('Select the role you wish to use as the "registration code group role" for every new subscriber who subscribes to this group using one of the registration codes above.'),
-              );      
-          }
-          $form['#validate'][] = 'og_user_roles_regcode_form_validate';          
-          $form['#submit'][] = 'og_user_roles_regcode_form_submit';          
-        }
-	  }
-    }
-  }
-
-  // If this is a role deletion function
-  if (arg(0) == 'admin' && arg(1) == 'user' && arg(2) == 'roles' && arg(3) == 'edit' && is_numeric(arg(4))) {
-    $rid = arg(4);
-    // If the form loaded is this type then we want to run it by our submit function
-	// which will test to see if it is a delete operation
-    if ($form_id == "user_admin_role")  {
-      $form['#submit'][] = 'og_user_roles_role_submit';          
-    }
-  }
-
-}
-
-function og_user_roles_basicgrouprole_form_submit($form, &$form_state) {
-  $gid = arg(1);
-  variable_set('og_user_roles_assign_basicgrouprole_' . $gid, $form_state['values']['og_user_roles_assign_basicgrouprole_' . $gid]);
-  variable_set('og_user_roles_basicgrouprole_value_' . $gid, $form_state['values']['og_user_roles_basicgrouprole_value_' . $gid]);
-}
-function og_user_roles_logo_form_submit($form, &$form_state) {
-  $gid = arg(1);
-  variable_set('og_user_roles_logo_' . $gid, $form_state['values']['og_user_roles_logo_' . $gid]);
-}
-/*
- * Here we want to make sure that the submitted logo does not exceed size restrictions.
- */
+      	  // They only see this if they can configure user roles
+          if (user_access('configure member roles')) {
+            $form['og_user_roles_regcode_gid']['og_user_roles_assign_regcoderole_' . $gid] = array(
+              '#type' => 'checkbox',
+              '#title' => t('Set default basic group (group limited) role for users who join this group using this registration code?'),
+              '#default_value' => variable_get('og_user_roles_assign_regcoderole_' . $gid, 0),
+              '#description' => t('Do you wish to automatically assign a specific "registration code group role" to new subscribers to this group <b>who use this registration code to subscribe</b> to this group? The role is limited to this group. This role assignment can be be removed by the groups\' admin(s)'),
+              );
+            $form['og_user_roles_regcode_gid']['og_user_roles_regcoderole_value_' . $gid] = array(
+              '#type' => 'select',
+              '#title' => t('Role to assign'),
+              '#options' => $roles,
+              '#default_value' => variable_get('og_user_roles_regcoderole_value_' . $gid, 0),
+              '#description' => t('Select the role you wish to use as the "registration code group role" for every new subscriber who subscribes to this group using one of the registration codes above.'),
+              );      
+          }
+          $form['#validate'][] = 'og_user_roles_regcode_form_validate';          
+          $form['#submit'][] = 'og_user_roles_regcode_form_submit';          
+        }
+	  }
+    }
+  }
+
+  // If this is a role deletion function
+  if (arg(0) == 'admin' && arg(1) == 'user' && arg(2) == 'roles' && arg(3) == 'edit' && is_numeric(arg(4))) {
+    $rid = arg(4);
+    // If the form loaded is this type then we want to run it by our submit function
+	// which will test to see if it is a delete operation
+    if ($form_id == "user_admin_role")  {
+      $form['#submit'][] = 'og_user_roles_role_submit';          
+    }
+  }
+
+}
+
+function og_user_roles_basicgrouprole_form_submit($form, &$form_state) {
+  $gid = arg(1);
+  variable_set('og_user_roles_assign_basicgrouprole_' . $gid, $form_state['values']['og_user_roles_assign_basicgrouprole_' . $gid]);
+  variable_set('og_user_roles_basicgrouprole_value_' . $gid, $form_state['values']['og_user_roles_basicgrouprole_value_' . $gid]);
+}
+function og_user_roles_logo_form_submit($form, &$form_state) {
+  $gid = arg(1);
+  variable_set('og_user_roles_logo_' . $gid, $form_state['values']['og_user_roles_logo_' . $gid]);
+}
+/*
+ * Here we want to make sure that the submitted logo does not exceed size restrictions.
+ */
 function og_user_roles_logo_form_validate($form, &$form_state) {
-  $gid = arg(1);
-  if ($form_state['values']['og_user_roles_logo_' . $gid]) {
-    $width = variable_get('og_user_roles_logo_width', '135');
-    $height = variable_get('og_user_roles_logo_height', '113');
-    $image = image_get_info($form_state['values']['og_user_roles_logo_' . $gid]);
-	$img_width = $image['width'];
-	$img_height = $image['height'];
-	if ($img_width > $width || $img_height > $height) {
-       form_set_error('og_user_roles_logo_' . $gid, "Your submitted group logo image exceeds maximim image dimension limits.");
-	}
-  }
-}
-function og_user_roles_links_form_submit($form, &$form_state) {
-  $gid = arg(1);
-  variable_set('og_user_roles_links_content_' . $gid, $form_state['values']['og_user_roles_links_content_' . $gid]);
-  variable_set('og_user_roles_links_remove_' . $gid, $form_state['values']['og_user_roles_links_remove_' . $gid]);
-}
-function og_user_roles_nopublic_form_submit($form, &$form_state) {
-  $gid = arg(1);
-  variable_set('og_user_roles_assign_nopublic_' . $gid, $form_state['values']['og_user_roles_assign_nopublic_' . $gid]);
-}
-function og_user_roles_regcode_form_submit($form, &$form_state) {
-  $gid = arg(1);
-  variable_set('og_user_roles_assign_regcode_' . $gid, $form_state['values']['og_user_roles_assign_regcode_' . $gid]);
-  variable_set('og_user_roles_delete_regcode_' . $gid, $form_state['values']['og_user_roles_delete_regcode_' . $gid]);
-  variable_set('og_user_roles_regcode_value_' . $gid, $form_state['values']['og_user_roles_regcode_value_' . $gid]);
-  variable_set('og_user_roles_assign_regcoderole_' . $gid, $form_state['values']['og_user_roles_assign_regcoderole_' . $gid]);
-  variable_set('og_user_roles_regcoderole_value_' . $gid, $form_state['values']['og_user_roles_regcoderole_value_' . $gid]);
-}
-/*
- * Here we want to make sure that the submitted regcode value is not duplicated in another group.
- */
+  $gid = arg(1);
+  if ($form_state['values']['og_user_roles_logo_' . $gid]) {
+    $width = variable_get('og_user_roles_logo_width', '135');
+    $height = variable_get('og_user_roles_logo_height', '113');
+    $image = image_get_info($form_state['values']['og_user_roles_logo_' . $gid]);
+	$img_width = $image['width'];
+	$img_height = $image['height'];
+	if ($img_width > $width || $img_height > $height) {
+       form_set_error('og_user_roles_logo_' . $gid, "Your submitted group logo image exceeds maximim image dimension limits.");
+	}
+  }
+}
+function og_user_roles_links_form_submit($form, &$form_state) {
+  $gid = arg(1);
+  variable_set('og_user_roles_links_content_' . $gid, $form_state['values']['og_user_roles_links_content_' . $gid]);
+  variable_set('og_user_roles_links_remove_' . $gid, $form_state['values']['og_user_roles_links_remove_' . $gid]);
+}
+function og_user_roles_nopublic_form_submit($form, &$form_state) {
+  $gid = arg(1);
+  variable_set('og_user_roles_assign_nopublic_' . $gid, $form_state['values']['og_user_roles_assign_nopublic_' . $gid]);
+}
+function og_user_roles_regcode_form_submit($form, &$form_state) {
+  $gid = arg(1);
+  variable_set('og_user_roles_assign_regcode_' . $gid, $form_state['values']['og_user_roles_assign_regcode_' . $gid]);
+  variable_set('og_user_roles_delete_regcode_' . $gid, $form_state['values']['og_user_roles_delete_regcode_' . $gid]);
+  variable_set('og_user_roles_regcode_value_' . $gid, $form_state['values']['og_user_roles_regcode_value_' . $gid]);
+  variable_set('og_user_roles_assign_regcoderole_' . $gid, $form_state['values']['og_user_roles_assign_regcoderole_' . $gid]);
+  variable_set('og_user_roles_regcoderole_value_' . $gid, $form_state['values']['og_user_roles_regcoderole_value_' . $gid]);
+}
+/*
+ * Here we want to make sure that the submitted regcode value is not duplicated in another group.
+ */
 function og_user_roles_regcode_form_validate($form, &$form_state) {
-  $gid = arg(1);
-  // No need to go through any of this if the 'Allow Group Admins to set Registration Codes' is not set
-  if (variable_get('og_user_roles_assign_regcode_gid', 0) == 1) {
-    // If this group allows for registration codes to be set
-    if ($form_state['values']['og_user_roles_assign_regcode_' . $gid] == 1) {
-      // If this value is blank, return error
+  $gid = arg(1);
+  // No need to go through any of this if the 'Allow Group Admins to set Registration Codes' is not set
+  if (variable_get('og_user_roles_assign_regcode_gid', 0) == 1) {
+    // If this group allows for registration codes to be set
+    if ($form_state['values']['og_user_roles_assign_regcode_' . $gid] == 1) {
+      // If this value is blank, return error
       $regcode_array = explode(',', $form_state['values']['og_user_roles_regcode_value_' . $gid]);
       if (empty($regcode_array[0])) {
         form_set_error('og_user_roles_regcode_value_' . $gid, "No valid registration code entered.");
-      }
-      // Get the list of OG groups
+      }
+      // Get the list of OG groups
       $groups = og_all_groups_options();
-      foreach ($groups as $group => $title) {
+      foreach ($groups as $group => $title) {
 	    // Get all groups except current one.
-        if ($group != $gid) {
-          // Only process groups that are allowed to have registration codes
-          if (variable_get('og_user_roles_assign_regcode_' . $group, 0) == 1) {
-	   	    // Get the array of codes for this group.
-            $group_array = explode(',', variable_get('og_user_roles_regcode_value_' . $group, ''));
-            // Check to see this array as any elements which are duplicated
-            if ($duplicated = array_intersect($regcode_array, $group_array)) {
-              // If there are duplicates, then display the group in which they are duplicated ONLY if this is a site admin
+        if ($group != $gid) {
+          // Only process groups that are allowed to have registration codes
+          if (variable_get('og_user_roles_assign_regcode_' . $group, 0) == 1) {
+	   	    // Get the array of codes for this group.
+            $group_array = explode(',', variable_get('og_user_roles_regcode_value_' . $group, ''));
+            // Check to see this array as any elements which are duplicated
+            if ($duplicated = array_intersect($regcode_array, $group_array)) {
+              // If there are duplicates, then display the group in which they are duplicated ONLY if this is a site admin
               if (user_access('administer nodes')) {
-                form_set_error('og_user_roles_regcode_value_' . $gid, "Registration codes <b>" . implode(', ', $duplicated) . "</b> duplicated in group " . l($title, 'node/' . $group));
-			  } else {
-                form_set_error('og_user_roles_regcode_value_' . $gid, "Registration codes <b>" . implode(', ', $duplicated) . "</b> duplicated.");
+                form_set_error('og_user_roles_regcode_value_' . $gid, "Registration codes <b>" . implode(', ', $duplicated) . "</b> duplicated in group " . l($title, 'node/' . $group));
+			  } else {
+                form_set_error('og_user_roles_regcode_value_' . $gid, "Registration codes <b>" . implode(', ', $duplicated) . "</b> duplicated.");
 			  }
-            }
-    	  }
-	    }
-      }
-    }
-  }
-}
-function og_user_roles_role_submit($form, &$form_state) {
-  // If this is a delete role operation (Admin->User Management->Roles->Edit Role)
-  $op = $form_state['clicked_button']['#value'];
-  if ($op == t('Delete role')) {
-    // Remove from og_users_roles table all rows with this rid:
-    db_query('DELETE FROM {og_users_roles} WHERE rid = %d', $form_state['values']['rid']);
-  }
-}
-
+            }
+    	  }
+	    }
+      }
+    }
+  }
+}
+function og_user_roles_role_submit($form, &$form_state) {
+  // If this is a delete role operation (Admin->User Management->Roles->Edit Role)
+  $op = $form_state['clicked_button']['#value'];
+  if ($op == t('Delete role')) {
+    // Remove from og_users_roles table all rows with this rid:
+    db_query('DELETE FROM {og_users_roles} WHERE rid = %d', $form_state['values']['rid']);
+  }
+}
+
 /**
- * This is what is in OG.  og_user_roles_theme() was returning error, so decided to 
- * try this.
+ * This is what is in OG.  og_user_roles_theme() was returning error, so decided to 
+ * try this.
  */
 function og_user_roles_determine_context() {
   global $custom_theme;
   $group_node = NULL; // a node object containing the 'active' group for this request
 
   $type = $_GET['type'];
-
+
   if (arg(0) == 'og' && is_numeric(arg(2))) {
     $group_node = og_set_theme(arg(2));
   }
@@ -3462,133 +3462,133 @@ function og_user_roles_determine_context
     $group_node = node_load($gid);
     $custom_theme = $group_node->og_theme;
   }
-  // As per: http://drupal.org/node/194214
-  elseif (arg(0) == 'forum' && is_numeric(arg(1))) {
-    $tid = intval(arg(1));
-    $gid = og_user_roles_gid_from_tid($tid);
-    if (!empty($gid)) {
-      $group_node = node_load($gid);
-      $custom_theme = $group_node->og_theme;
-    }
-  }
+  // As per: http://drupal.org/node/194214
+  elseif (arg(0) == 'forum' && is_numeric(arg(1))) {
+    $tid = intval(arg(1));
+    $gid = og_user_roles_gid_from_tid($tid);
+    if (!empty($gid)) {
+      $group_node = node_load($gid);
+      $custom_theme = $group_node->og_theme;
+    }
+  }
   elseif (arg(0) == 'og_calendar' && is_numeric(arg(1))) {
     $gid = intval(arg(1));
     $group_node = node_load($gid);
     $custom_theme = $group_node->og_theme;
-  }
+  }
   elseif (arg(0) == 'comment' && is_numeric(arg(2))) {
-    if (arg(1) == 'edit') {
+    if (arg(1) == 'edit') {
       $comment = _comment_load(arg(2));
       $nid = $comment->nid;
       $gid = og_user_roles_getgid($nid, $uid);
       $group_node = og_set_theme($gid);
-    } else {
+    } else {
       $group_node = og_set_theme(arg(2));
-    }
+    }
   }
   elseif (arg(0) == 'user' && arg(1) == 'register' && isset($_REQUEST['gids'])) {
     $gid = intval(current($_REQUEST['gids']));
     $group_node = node_load($gid);
     $custom_theme = $group_node->og_theme;
-  }
+  }
 
   og_set_group_context($group_node);
 }
-
-/**
- * hook_og_create_links
- *
- * Modification as per: http://drupal.org/node/203875
- * $group is an object containing the group node
- */
-function og_user_roles_og_create_links($group) {
-  if (variable_get('og_user_roles_links_content_' . $group->nid, 0) == 1) {
-    $links[] = l(t('Create content'), "node/ognodeadd", array('title' => t('Add new content in this group.'), 'query' => 'gids[]=' . $group->nid));
-    return $links;
-  }
-}
-
-/**
- * hook_og_link_alter
- *
- * Modification as per: http://drupal.org/node/2517905
- * Optionally remove create_ links.
- */
-function og_user_roles_og_links_alter(&$links, $group_node) {
-  if (variable_get('og_user_roles_links_remove_' . $group_node->nid, 0) == 1) {
-    foreach($links as $key => $value) {
-      if(substr($key,0,7) == 'create_') {
-        unset($links["$key"]);
-      }
-    }
-  }
-}
-
-
-/**
- * hook_block
- *
- */
-function og_user_roles_block($op = 'list', $delta = 0, $edit = array()) {
-  global $user;
-
-  if ($op == 'list') {
-    $blocks[0] = array('info' => t('Register Codes'),
-      'weight' => 0, 'enabled' => 1, 'region' => 'left');
-    $blocks[1] = array('info' => t('Group Logo'),
-      'weight' => 0, 'enabled' => 0);
-    return $blocks;
-  }
-  else if ($op == 'view') {
-    switch($delta) {
-      case 0:
-        if ($node = og_get_group_context()) {
-          $subscription = og_user_roles_og_status($node);
+
+/**
+ * hook_og_create_links
+ *
+ * Modification as per: http://drupal.org/node/203875
+ * $group is an object containing the group node
+ */
+function og_user_roles_og_create_links($group) {
+  if (variable_get('og_user_roles_links_content_' . $group->nid, 0) == 1) {
+    $links[] = l(t('Create content'), "node/ognodeadd", array('title' => t('Add new content in this group.'), 'query' => 'gids[]=' . $group->nid));
+    return $links;
+  }
+}
+
+/**
+ * hook_og_link_alter
+ *
+ * Modification as per: http://drupal.org/node/2517905
+ * Optionally remove create_ links.
+ */
+function og_user_roles_og_links_alter(&$links, $group_node) {
+  if (variable_get('og_user_roles_links_remove_' . $group_node->nid, 0) == 1) {
+    foreach($links as $key => $value) {
+      if(substr($key,0,7) == 'create_') {
+        unset($links["$key"]);
+      }
+    }
+  }
+}
+
+
+/**
+ * hook_block
+ *
+ */
+function og_user_roles_block($op = 'list', $delta = 0, $edit = array()) {
+  global $user;
+
+  if ($op == 'list') {
+    $blocks[0] = array('info' => t('Register Codes'),
+      'weight' => 0, 'enabled' => 1, 'region' => 'left');
+    $blocks[1] = array('info' => t('Group Logo'),
+      'weight' => 0, 'enabled' => 0);
+    return $blocks;
+  }
+  else if ($op == 'view') {
+    switch($delta) {
+      case 0:
+        if ($node = og_get_group_context()) {
+          $subscription = og_user_roles_og_status($node);
           if ($subscription == 'none') {
-            if ($user->uid) {
+            if ($user->uid) {
               if (variable_get('og_user_roles_assign_regcode_gid', 0) == 1 && variable_get('og_user_roles_assign_regcode_' . $node->nid, 0) == 1 ) {
-                $block = array('subject' => t('Register Codes'), 'content' => l('Enter your registration code', 'og/regcode'));
-              }
-            }
-		  }
+                $block = array('subject' => t('Register Codes'), 'content' => l('Enter your registration code', 'og/regcode'));
+              }
+            }
+		  }
 		}
-        break;
-      case 1:
-        if ($node = og_get_group_context()) {
-          if ($logo = variable_get('og_user_roles_logo_' . $node->nid, '')) {
-//		    $width = variable_get('og_user_roles_logo_width', '135');
-//		    $height = variable_get('og_user_roles_logo_height', '113');
-//		    $attributes = array('width' => $width, 'height' => $height);
-		    $attributes = array();
-            $imglink = theme_image($logo, $alt = $node->title, $title = $node->title, $attributes, $getsize = FALSE);
-// Modification as per: http://drupal.org/node/287571
-//            $output = "<a href='" . base_path() . "node/" . $node->nid . "'>" . $imglink . "</a>";
-            $output = "<a href='" . url('node/'.$node->nid) . "'>" . $imglink . "</a>";
-            $block = array('content' => $output);
-		  }
+        break;
+      case 1:
+        if ($node = og_get_group_context()) {
+          if ($logo = variable_get('og_user_roles_logo_' . $node->nid, '')) {
+//		    $width = variable_get('og_user_roles_logo_width', '135');
+//		    $height = variable_get('og_user_roles_logo_height', '113');
+//		    $attributes = array('width' => $width, 'height' => $height);
+		    $attributes = array();
+            $imglink = theme_image($logo, $alt = $node->title, $title = $node->title, $attributes, $getsize = FALSE);
+// Modification as per: http://drupal.org/node/287571
+//            $output = "<a href='" . base_path() . "node/" . $node->nid . "'>" . $imglink . "</a>";
+            $output = "<a href='" . url('node/'.$node->nid) . "'>" . $imglink . "</a>";
+            $block = array('content' => $output);
+		  }
 		}
-        break;
-    }
-    return $block;
-  }
-}
-
-/**
- * hook_og_block_details
- * 
- * Trying to get this to work to put "Enter registration code" link in group menu
- * if in moderation.
- */
-function og_user_roles_og_block_details($group) {
-  if ($group->og_selective == OG_MODERATED && variable_get('og_user_roles_assign_regcode_gid', 0) == 1 && variable_get('og_user_roles_assign_regcode_' . $group->nid, '') == 1) {
-    $links[] = l(t('Enter registration code'), "og/regcode", array('attributes' => array('title' => t('Subscribe to this group using a registration code.'))));
-  }  
-  $oldblock = og_og_block_details($group);
+        break;
+    }
+    return $block;
+  }
+}
+
+/**
+ * hook_og_block_details
+ * 
+ * Trying to get this to work to put "Enter registration code" link in group menu
+ * if in moderation.
+ */
+function og_user_roles_og_block_details($group) {
+  if ($group->og_selective == OG_MODERATED && variable_get('og_user_roles_assign_regcode_gid', 0) == 1 && variable_get('og_user_roles_assign_regcode_' . $group->nid, '') == 1) {
+    $links[] = l(t('Enter registration code'), "og/regcode", array('attributes' => array('title' => t('Subscribe to this group using a registration code.'))));
+  }  
+  $oldblock = og_og_block_details($group);
   $block['content'] = $oldblock['content'] . theme('item_list', $links);
-  $block['subject'] = $oldblock['subject'];
+  $block['subject'] = $oldblock['subject'];
   return $block;
-}
-
+}
+
 /**
  *  Menu callback function to register with a code.
  *
@@ -3596,17 +3596,17 @@ function og_user_roles_og_block_details(
 function og_user_roles_register() {
   global $user;
 
-  if ($user->uid) {
-    drupal_set_message(t('If you have received a registration code for access to a group, enter it here.'));
-  } else {
-    drupal_set_message(l('You must register/login use registration codes.', 'user/login'));
+  if ($user->uid) {
+    drupal_set_message(t('If you have received a registration code for access to a group, enter it here.'));
+  } else {
+    drupal_set_message(l('You must register/login use registration codes.', 'user/login'));
   }
-
+
   $form['og_user_roles_regcode'] = array(
     '#type' => 'textfield',
     '#title' => t('Group registration code'),
     '#required' => TRUE,
-    '#size' => 25,
+    '#size' => 25,
 	'#access' => $user->uid,
   );
    
@@ -3617,8 +3617,8 @@ function og_user_roles_register() {
 }
 
 function og_user_roles_register_validate($form, &$form_state) {
-  global $user;
-  $gid = og_user_roles_gid_from_regcode($form_state['values']['og_user_roles_regcode']);
+  global $user;
+  $gid = og_user_roles_gid_from_regcode($form_state['values']['og_user_roles_regcode']);
   if ($gid == 0) {
     form_set_error('og_user_roles_regcode', "Not a valid group registration code.");
   }
@@ -3634,54 +3634,54 @@ function og_user_roles_register_submit($
   global $user;
   
   if ($user->uid) {
-    $gid = og_user_roles_gid_from_regcode($form_state['values']['og_user_roles_regcode']);
-	if ($gid > 0) {
-	  $node = node_load($gid);
+    $gid = og_user_roles_gid_from_regcode($form_state['values']['og_user_roles_regcode']);
+	if ($gid > 0) {
+	  $node = node_load($gid);
 	  $title = $node->title;
       $return = og_save_subscription($gid, $user->uid, array('is_active' => 1)); // as per http://drupal.org/node/156224
-      drupal_set_message(t('Subscription request to ' . l($title, 'node/'. $gid) . ' approved.'));	
-      // Delete this registration code if 'delete_regcode' is set
-      if (variable_get('og_user_roles_delete_regcode_' . $gid, 0) == 1) og_user_roles_delete_regcode($gid, $form_state['values']['og_user_roles_regcode']);
-      // Places all new registration code group subscribers into default regcode role.
-      if (variable_get('og_user_roles_assign_regcoderole_' . $gid, 0)) { // check to see if this variable exists
+      drupal_set_message(t('Subscription request to ' . l($title, 'node/'. $gid) . ' approved.'));	
+      // Delete this registration code if 'delete_regcode' is set
+      if (variable_get('og_user_roles_delete_regcode_' . $gid, 0) == 1) og_user_roles_delete_regcode($gid, $form_state['values']['og_user_roles_regcode']);
+      // Places all new registration code group subscribers into default regcode role.
+      if (variable_get('og_user_roles_assign_regcoderole_' . $gid, 0)) { // check to see if this variable exists
         if (variable_get('og_user_roles_assign_regcode_gid', 0) == 1 && variable_get('og_user_roles_assign_regcoderole_' . $gid, 0) == 1 ) {
           $rid = variable_get('og_user_roles_regcoderole_value_' . $gid, 0);
           og_user_roles_role_join($user->uid, $rid, $gid); // assign user to group role in that group
         }
-      }
-	}
+      }
+	}
   } else {
     drupal_access_denied();
   }
-
+
+}
+
+function og_user_roles_delete_regcode($gid, $regcode) {
+  // Get the array of registration codes for this $gid
+  $group_array = explode(',', variable_get('og_user_roles_regcode_value_' . $gid, ''));
+  // Create new array that contains all codes for this one.
+  foreach ($group_array as $item) {
+    if ($item != $regcode) {
+      $new_array[] = $item;    
+    }
+  }
+  // Implode the new array
+  $new = implode(",", $new_array);
+  // Write the new value.
+  variable_set('og_user_roles_regcode_value_' . $gid, $new);  
 }
-
-function og_user_roles_delete_regcode($gid, $regcode) {
-  // Get the array of registration codes for this $gid
-  $group_array = explode(',', variable_get('og_user_roles_regcode_value_' . $gid, ''));
-  // Create new array that contains all codes for this one.
-  foreach ($group_array as $item) {
-    if ($item != $regcode) {
-      $new_array[] = $item;    
-    }
-  }
-  // Implode the new array
-  $new = implode(",", $new_array);
-  // Write the new value.
-  variable_set('og_user_roles_regcode_value_' . $gid, $new);  
-}
-
+
 /**
  * Determine the subscription status of this user in this group
- *
- * @param
+ *
+ * @param
  *   Group node
  * @return status
  *   The status of subscriber containing 'active' or 'requested' or 'none'
  */
  function og_user_roles_og_status($node) {
   global $user;
-  $subscription = 'none';
+  $subscription = 'none';
   $result = db_query('select * from {og_uid} where nid = %d', $node->nid);
   while ($row = db_fetch_object($result)) {
     if ($row->uid == $user->uid) {
@@ -3694,14 +3694,14 @@ function og_user_roles_delete_regcode($g
   }
   return $subscription;
 }
-
+
 /**
- * Access callback
- * Determine access to modr8 page
+ * Access callback
+ * Determine access to modr8 page
  * Coded as per "Create your own access": http://drupal.org/node/109157
- *
- * @param
- *   node id
+ *
+ * @param
+ *   node id
  *   user access
  * @return status
  *   Boolean true or false
@@ -3710,7 +3710,7 @@ function og_user_roles_delete_regcode($g
   $node = node_load($nid);
   return $node->moderate && user_access($access);
  }
-
+
 /*
  * Implementation of hook_node_grants
  */
@@ -3722,35 +3722,35 @@ function og_user_roles_node_grants($acco
   }
   return !empty($array['ogr_access']) ? $array : NULL;
 }
-
-/*
- * Implementation of hook_node_access_records
- */
-function og_user_roles_node_access_records($node) {
-
-  $grants = array();
-
-  if (variable_get('og_user_roles_tac_og_value', 0) == 1) {
-
-    // we need to explicitly label public nodes it seems. OG doesn't label nodes
-    // of types it doesn't apply to, or the "implicitly public" nodes created by
-    // leaving all the audience checkboxes blank.
-    // From: http://drupal.org/node/234087#comment-788876
-
-    if (og_is_omitted_type($node->type) || (is_array($node->og_groups) && count($node->og_groups) === 0) || (!is_array($node->og_groups) && !og_is_group_type($node->type))) {
-      $grants[] = array (
-        'realm' => 'og_public',
-        'gid' => 0,
-        'grant_view' => 1,
-        'grant_update' => 0,
-        'grant_delete' => 0 );
-    }
-    
-	// This creates all ogr grants
-    
-    $where = "WHERE ta.rid = ogr.rid AND n.nid = ".$node->nid;
+
+/*
+ * Implementation of hook_node_access_records
+ */
+function og_user_roles_node_access_records($node) {
+
+  $grants = array();
+
+  if (variable_get('og_user_roles_tac_og_value', 0) == 1) {
+
+    // we need to explicitly label public nodes it seems. OG doesn't label nodes
+    // of types it doesn't apply to, or the "implicitly public" nodes created by
+    // leaving all the audience checkboxes blank.
+    // From: http://drupal.org/node/234087#comment-788876
+
+    if (og_is_omitted_type($node->type) || (is_array($node->og_groups) && count($node->og_groups) === 0) || (!is_array($node->og_groups) && !og_is_group_type($node->type))) {
+      $grants[] = array (
+        'realm' => 'og_public',
+        'gid' => 0,
+        'grant_view' => 1,
+        'grant_update' => 0,
+        'grant_delete' => 0 );
+    }
+    
+	// This creates all ogr grants
+    
+    $where = "WHERE ta.rid = ogr.rid AND n.nid = ".$node->nid;
     $result = db_query("SELECT n.nid, ta.rid, ogr.ogr_id, BIT_OR(ta.grant_view) AS grant_view, BIT_OR(ta.grant_update) AS grant_update, BIT_OR(ta.grant_delete) AS grant_delete FROM {term_node} n INNER JOIN {term_access} ta ON n.tid = ta.tid INNER JOIN {og_ancestry} oa ON n.nid = oa.nid INNER JOIN {og_users_roles} ogr ON oa.group_nid = ogr.gid $where GROUP BY n.nid, ta.rid");
-    
+    
     while($row = db_fetch_object($result)) {
       if ($row) {
         $grant_view = ($row->grant_view == 1) ? 1 : 0;
@@ -3767,89 +3767,89 @@ function og_user_roles_node_access_recor
         );
       }
     }
-
-    return $grants;
-  }
-}
-
+
+    return $grants;
+  }
+}
+
 /**
  * Implementation of hook_cron().
  */
-function og_user_roles_cron() {
-
-  // Insert nodes into all groups.
+function og_user_roles_cron() {
+
+  // Insert nodes into all groups.
   $nodelist = variable_get('og_user_roles_all_groups_nodes', '');
 
   if (!empty($nodelist)) {
     $nodelist_array = explode(',', $nodelist);
-    $result = db_query("SELECT nid FROM {og}");
- 
-    while ($row = db_fetch_object($result)) {
+    $result = db_query("SELECT nid FROM {og}");
+ 
+    while ($row = db_fetch_object($result)) {
       foreach ($nodelist_array as $nodelist_item) {
-        print "<br>nodelist_item : " . $nodelist_item; 
-        $count = db_result(db_query("SELECT COUNT(nid) FROM {og_ancestry} WHERE nid = %d AND group_nid = %d", $nodelist_item, $row->nid));
-        // Insert if it doesn't already belong.
-        if ($count == 0) {
+        print "<br>nodelist_item : " . $nodelist_item; 
+        $count = db_result(db_query("SELECT COUNT(nid) FROM {og_ancestry} WHERE nid = %d AND group_nid = %d", $nodelist_item, $row->nid));
+        // Insert if it doesn't already belong.
+        if ($count == 0) {
           db_query('INSERT INTO {og_ancestry} (nid,group_nid,is_public) VALUES (%d,%d,0)', $nodelist_item, $row->nid);
           watchdog('og_user_roles', t('Inserted nid: %nid into group: %gid.', array('%nid' => $nodelist_item, '%gid' => $row->nid)));
-	    }
+	    }
       } // end foreach
-    }
-  }
-
-}
-
+    }
+  }
+
+}
+
 /**
  * Get the OG roles a user has in a group
- *
- * @param
+ *
+ * @param
  *   User ID
- * @param
+ * @param
  *   Group ID
  * @return array
  *   An array containing the [roleID => roleName] that the user has in this group
  */
  function og_user_roles_get_og_roles($uid, $gid) {
-
-  $roles = array();
-  // Get the group roles
-  $result = db_query('SELECT r.rid, r.name FROM {role} r INNER JOIN {og_users_roles} ogr ON r.rid = ogr.rid INNER JOIN {og_uid} ogu ON ogu.uid = ogr.uid AND ogu.nid = ogr.gid WHERE ogr.uid = %d AND ogr.gid = %d AND ogu.is_active = 1', $uid, $gid);
+
+  $roles = array();
+  // Get the group roles
+  $result = db_query('SELECT r.rid, r.name FROM {role} r INNER JOIN {og_users_roles} ogr ON r.rid = ogr.rid INNER JOIN {og_uid} ogu ON ogu.uid = ogr.uid AND ogu.nid = ogr.gid WHERE ogr.uid = %d AND ogr.gid = %d AND ogu.is_active = 1', $uid, $gid);
   while ($role = db_fetch_object($result)) {
     $roles[$role->rid] = $role->name;
   }
-  return $roles;
-}   
-
+  return $roles;
+}   
+
 /**
  * Implementation of hook_mail_alter().
  */
-function og_user_roles_mail_alter(&$message) {
-
-  $mailkey = $message['mail_id'];
-  $to = $message['to'];
-  $subject = $message['subject'];
-  $body = $message['body'];
-  $from = $message['from'];
-  $headers = $message['headers'];
-
-  if ($mailkey == 'og_mail') {
-    // Get unsubscribe url
-      $unsubscribe_url = $headers['List-Unsubscribe'];
-    // Take out the "<" and ">" characters	
-      $url = preg_replace('/[\<|\>]/', '', $unsubscribe_url);
-	// Get the group number (i.e., http://www.less-paper.org/og/manage/16 will yield "16")
-      $gid = basename($url);
-    // Get the logo path 
-      $logo = og_user_roles_oglogo_gid($gid);
-	// Construct the url to the logo
-      $parsed_url = parse_url($url);
-      $logo_url = $parsed_url['scheme'] . '://' . $parsed_url['host'] . '/' . $logo;
-
-    $body = preg_replace('/\!group_logo_url/', '<img src=' . $logo_url . ' />', $body);
-  }
-
-}
-
+function og_user_roles_mail_alter(&$message) {
+
+  $mailkey = $message['mail_id'];
+  $to = $message['to'];
+  $subject = $message['subject'];
+  $body = $message['body'];
+  $from = $message['from'];
+  $headers = $message['headers'];
+
+  if ($mailkey == 'og_mail') {
+    // Get unsubscribe url
+      $unsubscribe_url = $headers['List-Unsubscribe'];
+    // Take out the "<" and ">" characters	
+      $url = preg_replace('/[\<|\>]/', '', $unsubscribe_url);
+	// Get the group number (i.e., http://www.less-paper.org/og/manage/16 will yield "16")
+      $gid = basename($url);
+    // Get the logo path 
+      $logo = og_user_roles_oglogo_gid($gid);
+	// Construct the url to the logo
+      $parsed_url = parse_url($url);
+      $logo_url = $parsed_url['scheme'] . '://' . $parsed_url['host'] . '/' . $logo;
+
+    $body = preg_replace('/\!group_logo_url/', '<img src=' . $logo_url . ' />', $body);
+  }
+
+}
+
 function og_user_roles_readme() {
   global $base_path;
   // this link has to work when clean urls are disabled and drupal in subdir.
@@ -3857,9 +3857,9 @@ function og_user_roles_readme() {
   $link = "<a href=\"$base_path$href\">". t('README file'). '</a>';
   return $link;
 }
-
+
 function og_user_roles_list_users_sql($min_is_active = 1, $min_is_admin = 0, $orderby='u.name ASC') {
   return "SELECT u.uid, u.name, u.mail, u.picture, ou.* FROM {og_uid} ou INNER JOIN {users} u ON ou.uid = u.uid WHERE ou.nid = %d AND u.status > 0 AND ou.is_active >= $min_is_active AND ou.is_admin >= $min_is_admin ORDER BY $orderby";
 }
-
+
 ?>
\ No newline at end of file
