Index: block.module
===================================================================
RCS file: /home/dww/drupal/.cvs_repo/drupal/modules/block.module,v
retrieving revision 1.1.1.1
diff -u -F^f -r1.1.1.1 block.module
--- block.module	28 Jan 2006 10:32:42 -0000	1.1.1.1
+++ block.module	13 Feb 2006 10:36:08 -0000
@@ -153,15 +153,16 @@ function _block_rehash($order_by = array
           $block['custom'] = $old_blocks[$module][$delta]->custom;
           $block['throttle'] = $old_blocks[$module][$delta]->throttle;
           $block['types'] = $old_blocks[$module][$delta]->types;
+          $block['roles'] = $old_blocks[$module][$delta]->roles;
         }
         else {
           $block['status'] = $block['weight'] = $block['region'] = $block['custom'] = 0;
-          $block['pages'] = $block['types'] = '';
+          $block['pages'] = $block['types'] = $block['roles'] = '';
         }
 
         // reinsert blocks into table
-        db_query("INSERT INTO {blocks} (module, delta, status, weight, region, visibility, pages, custom, throttle, types) VALUES ('%s', '%s', %d, %d, %d, %d, '%s', %d, %d, '%s')",
-          $block['module'], $block['delta'], $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle'], $block['types']);
+        db_query("INSERT INTO {blocks} (module, delta, status, weight, region, visibility, pages, custom, throttle, types, roles) VALUES ('%s', '%s', %d, %d, %d, %d, '%s', %d, %d, '%s', '%s')",
+          $block['module'], $block['delta'], $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle'], $block['types'], $block['roles'] );
 
         $blocks[] = $block;
 
@@ -262,7 +263,13 @@ function block_admin_configure($module =
       else {
         $types = '';
       }
-      db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d, types = '%s' WHERE module = '%s' AND delta = '%s'", $edit['visibility'], $edit['pages'], $edit['custom'], $types, $module, $delta);
+      if ($edit['roles']) {
+        $roles = implode(',', $edit['roles']);
+      }
+      else {
+        $roles = '';
+      }
+      db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d, types = '%s', roles = '%s' WHERE module = '%s' AND delta = '%s'", $edit['visibility'], $edit['pages'], $edit['custom'], $types, $roles, $module, $delta);
       module_invoke($module, 'block', 'save', $delta, $edit);
       drupal_set_message(t('The block configuration has been saved.'));
       cache_clear_all();
@@ -271,7 +278,7 @@ function block_admin_configure($module =
     default:
       // Always evaluates to TRUE, but a validation step may be added later.
       if (!$edit) {
-        $edit = db_fetch_array(db_query("SELECT pages, visibility, custom, types FROM {blocks} WHERE module = '%s' AND delta = '%s'", $module, $delta));
+        $edit = db_fetch_array(db_query("SELECT pages, visibility, custom, types, roles FROM {blocks} WHERE module = '%s' AND delta = '%s'", $module, $delta));
       }
 
       // Module-specific block configurations.
@@ -282,6 +289,12 @@ function block_admin_configure($module =
       foreach (node_list() as $type) {
         $content_types[$type] = node_invoke($type, 'node_name');
       }
+      // get all the user roles to include as checkboxes
+      $role_query = db_query("SELECT rid, name FROM {role}");
+      while ($role = db_fetch_object($role_query)) {
+        $user_roles[$role->rid] = $role->name;
+      }
+
       // Get the block subject for the page title.
       $info = module_invoke($module, 'block', 'list');
       drupal_set_title(t("'%name' block", array('%name' => $info[$delta]['info'])));
@@ -291,11 +304,12 @@ function block_admin_configure($module =
       $group_2 = form_radios(t('Show block on specific pages'), 'visibility', $edit['visibility'], array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')));
       $group_2 .= form_textarea(t('Pages'), 'pages', $edit['pages'], 40, 5, t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '<em>blog</em>' for the blog page and '<em>blog/*</em>' for every personal blog. '<em>&lt;front&gt;</em>' is the front page."));
       $group_3 = form_checkboxes(t('Restrict block to specific content types'), 'types', explode(',', $edit['types']), $content_types, t('Selecting one or more content types will cause this block to only be shown on pages of the selected types. This feature works alone or in conjunction with page specific visibility settings. For example, you can specify that a block only appear on book pages in the \'FAQ\' path.'), NULL, FALSE);
+      $group_4 = form_checkboxes(t('Restrict block to specific user roles'), 'roles', explode(',', $edit['roles']), $user_roles, t('Selecting one or more user roles will cause this block to only be shown to users belonging to the selected roles. This feature works alone or in conjunction with page specific visibility settings.'), NULL, FALSE);
 
       $form .= form_group(t('User specific visibility settings'), $group_1);
       $form .= form_group(t('Page specific visibility settings'), $group_2);
       $form .= form_group(t('Content specific visibility settings'), $group_3);
-
+      $form .= form_group(t('Role specific visibility settings'), $group_4);
 
       $form .= form_submit(t('Save block'));
 
@@ -494,8 +508,23 @@ function block_list($region, $regions = 
       else {
         $type_match = TRUE;
       }
+      // Match the user's role if necessary
+      $role_match = FALSE;
+      if ($block['roles'] != '') {
+        $roles = explode(',', $block['roles']);
+        //Match on any one selected role
+        foreach ($roles as $role) {
+          if ($user->roles[$role]) {
+            $role_match = TRUE;
+            break;
+          }
+        }
+      }
+      else {
+        $role_match = TRUE;
+      }
 
-      if ($enabled && $page_match && $type_match) {
+      if ($enabled && $page_match && $type_match && $role_match) {
         // Check the current throttle status and see if block should be displayed
         // based on server load.
         if (!($block['throttle'] && (module_invoke('throttle', 'status') > 0))) {
