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	31 Jul 2009 00:06:28 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: profile_role.module,v 1.5 2009/02/15 03:09:11 boombatower Exp $
+// $Id: profile_role.module,v 1.4 2009/01/23 20:11:43 boombatower Exp $
 /**
  * @file
  * Define profile categories by role.
@@ -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,28 @@
 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 (count(array_intersect($category_roles[$category], array_keys($user->roles))) > 0) {
+      // 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,14 +107,18 @@
  * 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,10 +129,10 @@
  * @return array Associative array of roles.
  */
 function profile_role_get_roles() {
-  $result = db_query('SELECT rid, category
+  $result = db_query('SELECT category, rid
                       FROM {profile_role}');
   $roles = array();
-  while ($role = db_fetch_object($result)) {
+  foreach ($result as $role) {
     $roles[$role->category][] = $role->rid;
   }
   return $roles;
Index: CHANGELOG.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/profile_role/CHANGELOG.txt,v
retrieving revision 1.8
diff -u -r1.8 CHANGELOG.txt
--- CHANGELOG.txt	30 Jul 2009 04:49:40 -0000	1.8
+++ CHANGELOG.txt	31 Jul 2009 00:06:28 -0000
@@ -1,5 +1,10 @@
 // $Id: CHANGELOG.txt,v 1.8 2009/07/30 04:49:40 boombatower Exp $
 
+Profile role 7.x-1.0, xxxx-xx-xx (development version)
+--------------------------------
+- Changes
+   * #531840 by tutumlum: D7 version.
+
 Profile role 6.x-1.3, xxxx-xx-xx (development version)
 --------------------------------
 - Changes
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	31 Jul 2009 00:06:28 -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
