--- og_user_roles.module.070605.orig	2007-06-05 16:24:54.000000000 -0700
+++ og_user_roles.module	2007-06-06 12:24:49.000000000 -0700
@@ -350,7 +350,7 @@ function og_user_roles_page_form($gid,$r
   $form['user_roles']['roles'][$account->uid] = array(
     '#type' => 'checkbox_columns',
 	'#title' => $link,
-    '#default_value' => _user_roles($account->uid, $roles),
+    '#default_value' => _og_user_roles($account->uid, $roles),
     '#columns' => 4,
     '#options' => $roles,
     '#suffix' => '<br style="clear:both;"/>',
@@ -400,7 +400,7 @@ function og_user_roles_page_form_submit(
 /**
  * This checks to see what roles a current user has against a given set of roles.
  */
-function _user_roles($uid, $roles = array()) { 
+function _og_user_roles($uid, $roles = array()) { 
 
 	//
 	// Modification
@@ -640,19 +640,31 @@ function views_handler_filter_group() {
 
 function og_user_roles_init ()
 {
+	global $user;
+
 	// Looking for this format: http://www.scbbs.com/node/add/link?gids[]=29
 
-	if (arg(0) == 'node' && arg(1) == 'add' && isset($_REQUEST['gids'])) {
-		$gids = $_GET['gids'];
-	    $gid = intval(current($_REQUEST['gids']));
+	// We only need to process this if the user is logged in
+	if ($user->uid > 0) {
+
+		// Bootstrap if arg() doesn't exist
+	    if (!function_exists('arg') && $user->uid > 0){
+			drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH); // added as per this issue: http://drupal.org/node/149469
+	    }
+
+		// If this is a group node/add, re-direct to ognodeadd
+		if (arg(0) == 'node' && arg(1) == 'add' && isset($_REQUEST['gids'])) {
+			$gids = $_GET['gids'];
+		    $gid = intval(current($_REQUEST['gids']));
 
-		$type = arg(2);
+			$type = arg(2);
 
-		$path = 'node/ognodeadd';
-		if ($type == 'og_user_roles_subgroup') $type = variable_get("og_user_roles_create_subgroup_value", ''); // change OG Subgroups type to 'group'
+			$path = 'node/ognodeadd';
+			if ($type == 'og_user_roles_subgroup') $type = variable_get("og_user_roles_create_subgroup_value", ''); // change OG Subgroups type to 'group'
 
-		$query = 'type=' . $type . '&gids[]=' . $gid;
-		drupal_goto($path, $query);
+			$query = 'type=' . $type . '&gids[]=' . $gid;
+			drupal_goto($path, $query);
+		}
 	}
 }
 
@@ -675,7 +687,16 @@ function og_user_roles_user ($op, &$edit
     	// special case for new users
 	    if ($op == "insert")
     	{
-	      db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $user->uid, $rid); // 
+/*
+ * Modification as per: http://drupal.org/node/149483
+ */
+		// Check to see if this user doesn't already have this role;
+		// If not, then assign it.
+
+			$sql = "SELECT COUNT(*) FROM {users_roles} WHERE uid = %d AND rid = %d";
+		    $result = db_query($sql, $user->uid, $rid);
+		    $output = (db_result($result));
+			if ($output == 0) db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $user->uid, $rid);
     	}
 
 	} // end if
