--- nodeprofile.module	2008-04-20 17:57:14.000000000 -0300
+++ nodeprofile.module_	2008-07-08 17:53:50.000000000 -0300
@@ -80,20 +80,24 @@ function nodeprofile_admin_settings($typ
     '#description' => t('If selected this node profile\'s form will be shown on the user register page. ') . 
       t('Note that this will bypass the node creation permission settings, so this will work for your users regardless if they have access to edit or create their nodeprofile later!'),
   );
-  if (module_exists('rolesignup')) {
+  if (module_exists('autoassignrole') && (variable_get('AUTOASSIGNROLE_ROLE_USER_ACTIVE', '0') != 0)) {
     // List roles having Role Signup's "register for role" permission
-    if ($roles = user_roles(TRUE, 'register for role')) {
+    if($roles = _autoassignrole_intersect()) {
       $form['integration']['register_roles'] = array(
         '#type' => 'checkboxes',
         '#title' => t('Roles allowed to see this node profile during user registration'),
         '#default_value' => nodeprofile_get_settings('register_roles', $type),
         '#options' => $roles,
-        '#description' => t('If the <em>Show this node profile during user registration</em> option has been enabled, you may select what roles will see it. If no role is selected, all users will see this node profile. Note that this feature relies on the Role Signup module.'),
+        '#description' => t('If the <em>Show this node profile during user registration</em> option has been enabled, you may select what roles will see it. If no role is selected, all users will see this node profile. Note that this feature relies on the Auto Assign Role module.'),
       );
-    }
+    } else {
+      $form['integration']['register_roles'] = array(
+        '#title' => t('No roles have been selected yet. Please first choose roles in admin/user/autoassignrole, User Role Assignment settings.'),
+      );
+    };
   }
   else {
-    $form['integration']['#description'] .= '<br />'. t('The !rolesignup module is currently not installed. If installed, it would allow you show this node profile only to users who register for specific roles.', array('!rolesignup' => l(t('Role Signup'), 'http://drupal.org/project/rolesignup')));
+    $form['integration']['#description'] .= '<br />'. t('The !autoassignrole module is currently not installed or do not has the User Role Assignment settings enabled. If installed, it would allow you show this node profile only to users who register for specific roles.', array('!autoassignrole' => l(t('Auto Assign Role'), 'http://drupal.org/project/autoassignrole')));    
   }
   $form['weight'] = array(
     '#type' => 'weight',
@@ -270,7 +274,7 @@ function nodeprofile_form_alter($form_id
       $form['workflow']['nodefamily_max']['#disabled'] = TRUE;
     }
   }
-  else if (module_exists('rolesignup') && $form_id == 'user_admin_perm') {
+  else if (module_exists('autoassignrole') && $form_id == 'user_admin_perm') {
     $form['#submit']['nodeprofile_user_admin_perm_submit'] = array();
   }
 }
@@ -278,14 +282,14 @@ function nodeprofile_form_alter($form_id
 /**
  * Submit handler for the access control administration page.
  *
- * This is needed for Role Signup integration. This function clears up old
+ * This is needed for Auto Assign Role integration. This function clears up old
  * settings when some roles are no longer enabled for signup. This ensures that
  * we get the expected behavior when no specific role is enabled for
  * registration in the nodeprofile settings.
  */
 function nodeprofile_user_admin_perm_submit($form_id, $form_values) {
   $settings = nodeprofile_get_settings();
-  $user_roles = user_roles(TRUE, 'register for role');
+  $user_roles = _autoassignrole_intersect();
   if (isset($settings['register_roles'])) {
     foreach (array_filter($settings['register_roles']) as $type => $type_settings) {
       foreach ($type_settings as $role_id => $status) {
@@ -328,7 +332,7 @@ function nodeprofile_user($op, &$edit, &
       $data = array();
       if ($settings = nodeprofile_get_settings('user_edit')) {
         foreach ($settings as $type => $value) {
-          if (!empty($value) && node_access('create', $type)) {
+          if (!empty($value) && node_access('create', $type) && _nodeprofile_verify_user_role($type, $account->uid)) {
             $data[] = array(
                'name' => $type,
                'title' => check_plain(node_get_types('name', $type)),
@@ -387,7 +391,7 @@ function nodeprofile_user($op, &$edit, &
             );
             $fields[$title]['weight'] = nodeprofile_get_settings('weight', $type);
           }
-          else if ($account->uid == $user->uid && nodeprofile_get_settings('add_link', $type) && user_access('create '. $type .' content')) {
+          else if ($account->uid == $user->uid && nodeprofile_get_settings('add_link', $type) && user_access('create '. $type .' content') && _nodeprofile_verify_user_role($type, $account->uid)) {
             $fields[$type_name]['profile']['value'] = theme('nodeprofile_display_add_link', $type, $type_name);
             $fields[$type_name]['weight'] = nodeprofile_get_settings('weight', $type);
           }
@@ -514,14 +518,8 @@ function nodeprofile_get_register_form()
   foreach (nodeprofile_get_types('names') as $type => $type_name) {
     if (nodeprofile_get_settings('register', $type)) {
       // If a role has been selected for registration.
-      if (module_exists('rolesignup') && isset($_SESSION['role'])) {
-        // Find roles relevant to Role Signup that have settings for the current type.
-        if ($register_roles = nodeprofile_get_settings('register_roles', $type)) {
-          $user_roles = user_roles(TRUE, 'register for role');
-          if (!isset($user_roles[$_SESSION['role']]) || !isset($register_roles[$_SESSION['role']])) {
-            continue; // Do not show the current type.
-          }
-        }
+      if (!_nodeprofile_verify_autorole($type)) {
+        continue; // Do not show the current type.
       }
       $form[$type] = array(
         '#type' => 'fieldset',
@@ -794,3 +792,57 @@ function nodeprofile_show_profiles($uid)
   }
   return $fields;
 }
+
+/**
+ * Functions for compatibility with Autoassignrole Module. Mods by Marcelo IH aka Vuds.
+ * 
+ * Function _nodeprofile_verify_user_role()
+ * Purpose: Verify if the node profile type is in the list of permitted User Role Assignment of Auto Assign Role Module for registered users.
+ * Input: The node profile form type and the uid of this user.
+ * Output: Returns boolean TRUE if this a form a registered user may apply or FALSE if not.      
+ */
+   
+function _nodeprofile_verify_user_role($type, $user_id){
+  if (module_exists('autoassignrole') && (variable_get('AUTOASSIGNROLE_ROLE_USER_ACTIVE', '0') != 0)) {
+    // Get the permitted roles for this user
+    $autoassignrole_user_roles = array();
+    $result = db_query("SELECT rid FROM {users_roles} WHERE uid = %d", $user_id);
+    while ($role = db_fetch_object($result)) {
+      $autoassignrole_user_roles[] = $role->rid;
+    }
+    //Compare the permitted user roles with the permitted profiles and return TRUE if OK 
+    if (($register_roles = nodeprofile_get_settings('register_roles', $type)) && isset($autoassignrole_user_roles)) {
+      foreach($autoassignrole_user_roles as $value) {
+        if (in_array($value, $register_roles)) {
+          return TRUE;
+        }
+      }
+      return FALSE;
+    }
+  }
+  return TRUE;
+}
+
+/**
+ * Function _nodeprofile_verify_autorole()
+ * Purpose: Verify if the node profile type is in the list of permitted Automatic Role Assignment of Auto Assign Role Module for new users.
+ * Input: The node profile form type.
+ * Output: Returns boolean TRUE if this a form a new user may apply or FALSE if not.      
+ */
+function _nodeprofile_verify_autorole($type){
+  if (module_exists('autoassignrole') && (variable_get('AUTOASSIGNROLE_ROLE_ACTIVE', '0') != 0)) {
+    // Get the assigned roles for the new user registration
+    $autoassignrole_roles = array();
+    $autoassignrole_roles = variable_get('AUTOASSIGNROLE_ROLE', '');
+    //Compare the user roles with the permitted profiles and return TRUE if OK 
+    if (($register_roles = nodeprofile_get_settings('register_roles', $type)) && isset($autoassignrole_roles)) {
+      foreach($autoassignrole_roles as $value) {
+        if (in_array($value, $register_roles)) {
+          return TRUE;
+        }
+      }
+      return FALSE;
+    }
+  }
+  return TRUE;
+}
\ No newline at end of file
