Index: block.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/block.module,v
retrieving revision 1.144
diff -u -F^f -r1.144 block.module
--- block.module	15 Nov 2004 11:26:04 -0000	1.144
+++ block.module	17 Nov 2004 03:27:51 -0000
@@ -78,6 +78,10 @@ function block_menu($may_cache) {
       'access' => user_access('administer blocks'),
       'callback' => 'block_box_add',
       'type' => MENU_LOCAL_TASK);
+    $items[] = array('path' => 'admin/block/regions', 'title' => t('regions'),
+      'access' => user_access('administer blocks'),
+      'callback' => 'block_box_regions',
+      'type' => MENU_LOCAL_TASK);
   }
 
   return $items;
@@ -204,9 +208,11 @@ function block_admin_display() {
       $operation = '';
     }
 
-    $row = array($block['info'], array('data' => form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][status', 1, $block['status']), 'align' => 'center'), form_weight(NULL, $block['module'] .']['. $block['delta'] .'][weight', $block['weight']), form_radios(NULL, $block['module'] .']['. $block['delta'] .'][region', $block['region'], array(t('left'), t('right'))));
+    $block_regions  = _block_regionarray();
 
     $row = array($block['info'], array('data' => form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][status', 1, $block['status']), 'align' => 'center'), form_weight(NULL, $block['module'] .']['. $block['delta'] .'][weight', $block['weight']), form_radios(NULL, $block['module'] .']['. $block['delta'] .'][region', $block['region'], array(t('left'), t('right'))));
+
+    $row = array($block['info'], array('data' => form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][status', 1, $block['status']), 'align' => 'center'), form_weight(NULL, $block['module'] .']['. $block['delta'] .'][weight', $block['weight']), form_select(NULL, $block['module'] .']['. $block['delta'] .'][region', $block['region'], $block_regions));
     if (module_exist('throttle')) {
       $row[] = array('data' => form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][throttle', 1, $block['throttle']), 'align' => 'center');
     }
@@ -335,6 +341,48 @@ function block_box_save($edit, $delta = 
   }
 }
 
+
+/**
+ * Menu callback; handles region setup.
+ */
+function block_box_regions() {
+  $edit = $_POST['edit'];
+  $op = $_POST['op'];
+
+  switch ($op) {
+    case t('Save regions'):
+      variable_set('block_regions', $edit['regions']);
+      drupal_set_message(t('Region settings have been changed.'));
+      drupal_goto('admin/block/regions');
+
+    default:
+      $regions = variable_get('block_regions','');
+      $form =  form_textarea(t('Regions'), 'regions', $regions, 50, 10, t('List of regions, one per line.'));
+      $form .= form_submit(t('Save regions'));
+      $output .= form($form);
+
+      if (function_exists('theme_block_regions')) {
+        $diff = array_diff(_block_regionarray(), theme_block_regions());
+        if (count($diff)>0) {
+          form_set_error('Theme-region problem', t('The selected theme & configured blocks have different regions. Please make sure they are identical.'));
+        }
+      }
+  }
+
+  print theme('page', $output);
+}
+
+//internal function
+function _block_regionarray() {
+  $regions = array(t('left'), t('right'));
+  if ($regionsource = explode("\n",trim(variable_get('block_regions','')))) {
+    foreach($regionsource as $regionlabel) {
+      array_push($regions, trim($regionlabel));
+    }
+  }
+  return $regions;
+}
+
 /**
  * Menu callback; displays the block overview page.
  */
@@ -400,9 +448,20 @@ function block_list($region) {
   global $user, $base_url;
   static $blocks = array();
 
+  //calculate regionid
+  $block_regions = _block_regionarray();
+
+  if (in_array($region, $block_regions)) {
+    $regionid = array_search($region, $block_regions);
+  }
+  else {
+    $regionid = '-1';
+  }
+
+
   if (!isset($blocks[$region])) {
     $blocks[$region] = array();
-    $result = db_query('SELECT * FROM {blocks} WHERE status = 1 '. ($region != 'all' ? 'AND region = %d ' : '') .'ORDER BY weight, module', $region == 'left' ? 0 : 1);
+    $result = db_query('SELECT * FROM {blocks} WHERE status = 1 '. ($region != 'all' ? 'AND region = '.$regionid.' ' : '') .'ORDER BY weight, module');
 
     while ($result && ($block = db_fetch_array($result))) {
       // Use the user's block visibility setting, if necessary
