--- autoassignrole.module	2008-10-13 21:53:42.000000000 +0100
+++ autoassignrole.module	2008-10-16 12:53:54.597000000 +0100
@@ -37,6 +37,7 @@
           'page arguments' => array($r->rid),
           'page callback' => 'autoassignrole_path',
           'access callback' => '_autoassignrole_path_access',
+          'access arguments' => array($r->rid),
           'file' => 'autoassignrole-path.inc',
           'weight' => $r->weight
         );
@@ -71,6 +72,7 @@
           'page arguments' => array($r->rid),
           'page callback' => 'autoassignrole_path',
           'access callback' => '_autoassignrole_path_access',
+          'access arguments' => array($r->rid),
           'file' => 'autoassignrole-path.inc',
           'type' => MENU_LOCAL_TASK,
           'weight' => $r->weight
@@ -117,14 +119,9 @@
   return $items;
 }
  
-function _autoassignrole_path_access() {
-  global $user;
-  if(variable_get('user_register', 1) && $user->uid == 0) {
-    return TRUE;
-  }
-  else {
-    return FALSE;
-  }
+function _autoassignrole_path_access($rid = NULL) {
+    $roles = user_roles(TRUE); // receive all roles
+    return array_key_exists($rid, $roles) ? user_access("access {$roles[$rid]} registration") : TRUE;
 }
 
 /**
@@ -132,7 +129,20 @@
  * @return array
  */
 function autoassignrole_perm() {
-  return array('administer autoassignrole');
+    $perm = array('administer autoassignrole');
+    $result = db_query("SELECT rid FROM {autoassignrole_page}"); // get all used roles by autoassignrole
+    if ($result) {
+	while ($db_role = db_fetch_object($result)) { // get db records...
+	    $db_roles[$db_role->rid] = $db_role->rid; // ...and save them to the array
+	}
+	$roles = user_roles(TRUE); // receive all roles
+	foreach ($db_roles as $role) { // for each used role...
+	    if (array_key_exists($role,$roles)) { // .. check if role exist...
+		$perm[] = "access {$roles[$role]} registration"; // ...and add the new permission
+	    }
+	}
+    }
+    return $perm;
 }
 
 /**
@@ -141,7 +151,7 @@
 function autoassignrole_user($op, &$edit, &$account, $category = NULL) {
   switch ($op) {
     case 'insert':
-      $path = substr(request_uri(),1);
+      $path = drupal_get_path_alias($_GET['q']);
       $page = db_fetch_object(db_query("SELECT rid FROM {autoassignrole_page} WHERE path = '%s'", $path));
       if (_autoassignrole_settings('user_active') == 1) {
         $roles = array();
@@ -387,13 +397,13 @@
       '#default_value' => variable_get('autoassignrole_content_profile_'. $form['#node_type']->type, 0),
       '#options' => $options,
       '#description' => t('The Auto Assign Role module gives you the ability to
-        assign paths a user can register from for a role.  After associating a <a href="@aar">path with a role</a> your selection can  associate this content type with a path.', array('@aar' => url('admin/user/autoassignrole'))),
+        assign paths a user can register from for a role.  After associating a <a href="@aar">path with a role</a> your selection can associate this content type with a path.', array('@aar' => url('admin/user/autoassignrole'))),
     );
     $form['#submit'][] = 'autoassignrole_node_type_form_submit';
   }
   if ($form_id == 'user_register' && module_exists('content')  && module_exists('content_profile')) {
     $profile_types = content_profile_get_types('names', 'registration_use');
-    $path = substr(request_uri(),1);
+    $path = drupal_get_path_alias($_GET['q']);
     if($path != 'user/register') {
       $page = db_fetch_object(db_query("SELECT rid FROM {autoassignrole_page} WHERE path = '%s'", $path));
       if(isset($page->rid)) {
