Index: database/database.mysql =================================================================== RCS file: /cvs/drupal/drupal/database/database.mysql,v retrieving revision 1.176 diff -u -r1.176 database.mysql --- database/database.mysql 11 Apr 2005 19:05:50 -0000 1.176 +++ database/database.mysql 11 Apr 2005 23:05:13 -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' -- @@ -805,6 +818,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.112 diff -u -r1.112 database.pgsql --- database/database.pgsql 11 Apr 2005 19:05:50 -0000 1.112 +++ database/database.pgsql 11 Apr 2005 23:07:13 -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 -- @@ -804,6 +817,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.104 diff -u -r1.104 updates.inc --- database/updates.inc 11 Apr 2005 19:05:51 -0000 1.104 +++ database/updates.inc 11 Apr 2005 23:31:14 -0000 @@ -106,7 +106,8 @@ "2005-03-18" => "update_127", "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-10" => "update_130", + "2005-04-11" => "update_131" ); function update_32() { @@ -2376,4 +2377,11 @@ return $ret; } +function update_131() { + $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"); + + return $ret; +} + ?> Index: modules/block.module =================================================================== RCS file: /cvs/drupal/drupal/modules/block.module,v retrieving revision 1.162 diff -u -r1.162 block.module --- modules/block.module 4 Apr 2005 12:27:05 -0000 1.162 +++ modules/block.module 11 Apr 2005 23:41:32 -0000 @@ -262,6 +262,21 @@ else { $types = ''; } + + // 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); + } + } 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); drupal_set_message('The block configuration has been saved.'); @@ -291,10 +306,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')); @@ -335,6 +359,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'); @@ -452,7 +477,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) {