Index: profile_role.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/profile_role/profile_role.module,v
retrieving revision 1.5
diff -u -r1.5 profile_role.module
--- profile_role.module	15 Feb 2009 03:09:11 -0000	1.5
+++ profile_role.module	30 Jul 2009 05:21:07 -0000
@@ -35,10 +35,9 @@
  * Implementation of hook_menu_alter().
  */
 function profile_role_menu_alter(&$callbacks) {
-  $result = db_query('SELECT DISTINCT(category)
-                      FROM {profile_fields}');
-
-  while ($category = db_result($result)) {
+  $result = db_query('SELECT DISTINCT category
+                      FROM {profile_field}')->fetchCol();
+  foreach ($result AS $category) {
     $key = 'user/%user_category/edit/' . $category;
     $callbacks[$key]['access callback'] = 'profile_role_access_category';
     $callbacks[$key]['access arguments'] = array(1, $category);
@@ -57,67 +56,29 @@
 function profile_role_access_category($user, $category) {
   $category_roles = profile_role_get_roles();
   if (isset($category_roles[$category])) {
-    foreach ($category_roles[$category] as $rid) {
-      if (array_key_exists($rid, $user->roles)) {
-        // User has fields, check if editting user has edit access.
-        return user_edit_access($GLOBALS['user']);
-      }
+    if (array_key_exists($category_roles[$category], $user->roles)) {
+      // User has fields, check if editting user has edit access.
+      return user_edit_access($GLOBALS['user']);
     }
   }
   return FALSE;
 }
 
 /**
- * Restrict the user registration form.
- */
-function profile_role_form_user_register_alter(&$form, $form_state) {
-  if ($form['#action'] == '/user/register') {
-    // No way to determine what role user will be, so leave form alone.
-    return;
-  }
-
-  $roles = isset($form_state['post']['roles']) ? $form_state['post']['roles'] : array();
-  $category_roles = profile_role_get_roles();
-  $result = db_query('SELECT DISTINCT(category)
-                      FROM {profile_fields}');
-  while ($category = db_result($result)) {
-    if (isset($form[$category])) {
-      // Category displayed, check to see if it should.
-      $remove = TRUE;
-
-      if (isset($category_roles[$category])) {
-        foreach ($category_roles[$category] as $rid) {
-          if (array_key_exists($rid, $roles)) {
-            $remove = FALSE;
-          }
-        }
-      }
-
-      if ($remove) {
-        unset($form[$category]);
-      }
-    }
-  }
-
-  // Submit the form so that any additional fields display.
-  $form['account']['roles']['#attributes']['onchange'] = 'submit()';
-}
-
-/**
  * Define profile categories by role.
  */
 function profile_role_restrict_form(&$form_state) {
   $form = array();
   $roles = profile_role_get_roles();
   $result = db_query('SELECT DISTINCT(category)
-                      FROM {profile_fields}');
+                      FROM {profile_field}')->fetchCol();
 
   $form['_categories'] = array(
     '#type' => 'value',
     '#value' => array()
   );
   $i = 0;
-  while ($category = db_result($result)) {
+  foreach ($result as $category) {
     $form[$i] = array(
       '#type' => 'fieldset',
       '#title' => $category,
@@ -147,15 +108,15 @@
  * Save category roles.
  */
 function profile_role_restrict_form_submit($form, &$form_state) {
-  db_query('DELETE FROM {profile_role}');
-
+  db_delete('profile_role')->execute();
+  $insert = db_insert('profile_role');
+  $insert->fields(array('rid', 'category'));
   foreach ($form_state['values']['_categories'] as $key => $category) {
     foreach ($form_state['values'][$key]['roles'] as $rid) {
-      db_query("INSERT INTO {profile_role}
-                VALUES (%d, '%s')", $rid, $category);
+      $insert->values(array($rid, $category));
     }
   }
-
+  $insert->execute();
   drupal_set_message(t('The configuration options have been saved.'));
 }
 
@@ -165,12 +126,7 @@
  * @return array Associative array of roles.
  */
 function profile_role_get_roles() {
-  $result = db_query('SELECT rid, category
-                      FROM {profile_role}');
-  $roles = array();
-  while ($role = db_fetch_object($result)) {
-    $roles[$role->category][] = $role->rid;
-  }
+  $roles = db_query('SELECT category, rid FROM {profile_role}')->fetchAllKeyed();
   return $roles;
 }
 
Index: profile_role.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/profile_role/profile_role.test,v
retrieving revision 1.2
diff -u -r1.2 profile_role.test
--- profile_role.test	4 Dec 2008 06:12:38 -0000	1.2
+++ profile_role.test	30 Jul 2009 05:21:07 -0000
@@ -11,7 +11,7 @@
   /**
    * Implementation of getInfo().
    */
-  function getInfo() {
+  public static function getInfo() {
     return array(
       'name' => t('Profile role'),
       'description' => t('Test the visibility of a field based on its role settings.'),
@@ -22,14 +22,14 @@
   /**
    * Implementation of setUp().
    */
-  function setUp() {
+  public function setUp() {
     parent::setUp('profile', 'profile_role');
   }
 
   /**
    * Test the visibility of a field based on its role settings.
    */
-  function testFieldVisibility() {
+  public function testFieldVisibility() {
     // Create and login user.
     $admin_user = $this->drupalCreateUser(array('administer users'));
     $this->drupalLogin($admin_user);
Index: profile_role.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/profile_role/profile_role.info,v
retrieving revision 1.2
diff -u -r1.2 profile_role.info
--- profile_role.info	30 Jul 2009 04:49:40 -0000	1.2
+++ profile_role.info	30 Jul 2009 05:21:07 -0000
@@ -2,5 +2,8 @@
 name = "Profile role"
 description = "Define profile categories by role."
 package = "Profile"
-core = 6.x
+core = 7.x
 dependencies[] = profile
+files[] = profile_role.install
+files[] = profile_role.module
+files[] = profile_role.test
