Index: database/database.mysql =================================================================== RCS file: /cvs/drupal/drupal/database/database.mysql,v retrieving revision 1.177 diff -u -r1.177 database.mysql --- database/database.mysql 12 Apr 2005 18:52:47 -0000 1.177 +++ database/database.mysql 13 Apr 2005 17:37:39 -0000 @@ -114,6 +114,19 @@ ) TYPE=MyISAM; -- +-- Table structure for table block_visibility +-- + +CREATE TABLE block_visibility ( + module varchar(64) NOT NULL default '', + delta varchar(32) NOT NULL default '', + rid int(10) NOT NULL default '1', + visible tinyint(1) NOT NULL default '1', + PRIMARY KEY (module,delta,rid), + KEY visible (visible) +) TYPE=MyISAM; + +-- -- Table structure for table 'blocks' -- @@ -804,6 +817,8 @@ REPLACE blocks SET module = 'user', delta = '0', status = '1'; REPLACE blocks SET module = 'user', delta = '1', status = '1'; +INSERT INTO block_visibility (module, delta, rid, visible) SELECT b.module, b.delta, r.rid, '1' FROM blocks b LEFT JOIN role r ON 1 = 1; + INSERT INTO sequences (name, id) VALUES ('menu_mid', 1); INSERT INTO node_access VALUES (0, 0, 'all', 1, 0, 0); Index: database/database.pgsql =================================================================== RCS file: /cvs/drupal/drupal/database/database.pgsql,v retrieving revision 1.113 diff -u -r1.113 database.pgsql --- database/database.pgsql 12 Apr 2005 18:52:47 -0000 1.113 +++ database/database.pgsql 13 Apr 2005 17:37:39 -0000 @@ -112,6 +112,19 @@ ); -- +-- Table structure for table block_visibility +-- + +CREATE TABLE block_visibility ( + module varchar(64) NOT NULL default '', + delta varchar(32) NOT NULL default '', + rid integer NOT NULL default '1', + visible smallint NOT NULL default '1', + PRIMARY KEY (module,delta,rid), + UNIQUE (visible) +); + +-- -- Table structure for blocks -- @@ -803,6 +816,8 @@ INSERT INTO blocks(module,delta,status) VALUES('user', 0, 1); INSERT INTO blocks(module,delta,status) VALUES('user', 1, 1); +INSERT INTO block_visibility (module, delta, rid, visible) SELECT b.module, b.delta, r.rid, '1' FROM blocks b LEFT JOIN role r ON 1 = 1; + INSERT INTO node_access VALUES (0, 0, 'all', 1, 0, 0); INSERT INTO filter_formats (name, roles, cache) VALUES ('Filtered HTML',',1,2,',1); Index: database/updates.inc =================================================================== RCS file: /cvs/drupal/drupal/database/updates.inc,v retrieving revision 1.105 diff -u -r1.105 updates.inc --- database/updates.inc 12 Apr 2005 18:52:47 -0000 1.105 +++ database/updates.inc 13 Apr 2005 23:28:38 -0000 @@ -107,7 +107,8 @@ "2005-03-21" => "update_128", "2005-04-08: first update since Drupal 4.6.0 release" => "update_129", "2005-04-10" => "update_130", - "2005-04-11" => "update_131" + "2005-04-11" => "update_131", + "2005-04-13" => "update_132" ); function update_32() { @@ -2391,4 +2392,14 @@ return $ret; } + +function update_132() { + $ret = array(); + $ret[] = update_sql("INSERT INTO {block_visibility} (module, delta, rid, visible) SELECT b.module, b.delta, r.rid, '1' FROM {blocks} b LEFT JOIN {role} r ON 1 = 1"); + $ret[] = update_sql("DELETE FROM {sequences} WHERE name = 'boxes'"); + $ret[] = update_sql("INSERT INTO {sequences} (name, id) SELECT 'boxes', MAX(bid) FROM {boxes}"); + + return $ret; +} + ?> Index: modules/block.module =================================================================== RCS file: /cvs/drupal/drupal/modules/block.module,v retrieving revision 1.163 diff -u -r1.163 block.module --- modules/block.module 12 Apr 2005 18:52:47 -0000 1.163 +++ modules/block.module 13 Apr 2005 23:24:40 -0000 @@ -178,6 +178,28 @@ } /** + * Save the role for the given ($module, $delta) tuple. + * + */ + +function _block_roles_save($module, $delta, $edit) { + // Update the role visibilities, if line (module, delta, rid) doesn't exist for a given rid, we insert it. + // This query will display a list of rid with it's status : + // It could be 0 or 1 so the line in block visibility for this given (module, delta, rid) exists so we just update it. + // If it's NULL, it means the line doesn't exists and we need to insert it. + $roles[] = array(); + $result = db_query("SELECT r.rid, v.visible FROM {role} r LEFT JOIN {blocks} b ON 1 = 1 LEFT OUTER JOIN {block_visibility} v ON v.module = b.module AND v.delta = b.delta AND r.rid = v.rid WHERE b.module = '%s' AND b.delta = '%s'", $module, $delta); + while ($role = db_fetch_object($result)) { + if (is_null($role->visible)) { + db_query("INSERT INTO {block_visibility} (module, delta, rid, visible) VALUES ('%s', '%s', %d, %d)", $module, $delta, $role->rid, in_array($role->rid,$edit['roles']) ? 1 : 0 ); + } + else { + db_query("UPDATE {block_visibility} SET visible = %d WHERE module = '%s' AND delta = '%s' and rid = %d", in_array($role->rid, $edit['roles']) ? 1 : 0 , $module, $delta, $role->rid); + } + } +} + +/** * Prepare the main block administration form. */ function block_admin_display() { @@ -262,8 +284,10 @@ 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); module_invoke($module, 'block', 'save', $delta, $edit); + _block_roles_save($module, $delta, $edit); drupal_set_message('The block configuration has been saved.'); cache_clear_all(); drupal_goto('admin/block'); @@ -291,10 +315,19 @@ $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 'blog' for the blog page and 'blog/*' for every personal blog. '<front>' 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); + $roles = db_query("SELECT rid FROM {block_visibility} WHERE module = '%s' and delta = '%s' and visible = '1'", $module, $delta); + + $edit['roles'] = array(); + while ($role = db_fetch_object($roles)) { + $edit['roles'][] = $role->rid; + } + $group_4 = form_checkboxes(t('Restrict block to Roles'), 'roles', $edit['roles'], user_roles(0), t('The block receives the combined permissions of all of the selected roles.
If there\'s no role selected, the block will be invisible.'), 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('Roles specific visibility settings'), $group_4); $form .= form_submit(t('Save block')); @@ -336,6 +369,7 @@ if ($_POST['edit']['confirm']) { db_query('DELETE FROM {boxes} WHERE bid = %d', $bid); + db_query("DELETE FROM {block_visibility} WHERE module = 'block' AND delta = %d", $bid); drupal_set_message(t('The block %name has been deleted.', array('%name' => theme('placeholder', $info)))); cache_clear_all(); drupal_goto('admin/block'); @@ -356,7 +390,9 @@ $output .= filter_form('format', $edit['format']); $output .= form_textarea(t('Block body'), 'body', $edit['body'], 70, 10, t('The content of the block as shown to the user.')); $output .= form_textfield(t('Block description'), 'info', $edit['info'], 50, 64, t('A brief description of your block. Used on the block overview page.', array('%overview' => url('admin/block')))); - + if (!$edit) { + $output .= form_checkboxes(t('Restrict block to Roles'), 'roles', array_keys(user_roles(0)), user_roles(0), t('The block receives the combined permissions of all of the selected roles.
If there\'s no role selected, the block will be invisible.'), NULL, FALSE); + } return $output; } @@ -373,9 +409,13 @@ form_set_error('title', t('Please ensure each block description is unique.')); return false; } - db_query("INSERT INTO {boxes} (title, body, info, format) VALUES ('%s', '%s', '%s', %d)", $edit['title'], $edit['body'], $edit['info'], $edit['format']); - } + $delta = db_next_id('boxes'); + db_query("INSERT INTO {boxes} (bid, title, body, info, format) VALUES (%d, '%s', '%s', '%s', %d)", $delta, $edit['title'], $edit['body'], $edit['info'], $edit['format']); + _block_rehash(); + _block_roles_save('block', $delta, $edit); + } return true; + } } /** @@ -458,7 +498,7 @@ if (!isset($blocks[$region])) { $blocks[$region] = array(); - $result = db_query("SELECT * FROM {blocks} WHERE status = 1 AND region IN ('%s') ORDER BY weight, module", $regions[$region]); + $result = db_query("SELECT DISTINCT b.module, b.delta, b.status, b.weight, b.region, b.custom, b.throttle, b.visibility, b.pages, b.types FROM {blocks} b LEFT OUTER JOIN {block_visibility} v ON b.module = v.module AND b.delta = v.delta WHERE status = 1 AND b.region IN (%s) AND v.rid in (%s) and v.visible = 1 ORDER BY b.weight, b.module", $regions[$region], implode(',', array_flip($user->roles))); while ($block = db_fetch_array($result)) { // Use the user's block visibility setting, if necessary if ($block['custom'] != 0) {