Index: modules/block.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/block.module,v
retrieving revision 1.186
diff -u -F^f -r1.186 block.module
--- modules/block.module	3 Nov 2005 15:39:37 -0000	1.186
+++ modules/block.module	4 Nov 2005 05:56:03 -0000
@@ -312,81 +312,88 @@ function block_box_get($bid) {
  * Menu callback; displays the block configuration form.
  */
 function block_admin_configure($module = NULL, $delta = 0) {
-  $edit = $_POST['edit'];
-  $op = $_POST['op'];
 
-  switch ($op) {
-    case t('Save block'):
-      db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d WHERE module = '%s' AND delta = '%s'", $edit['visibility'], $edit['pages'], $edit['custom'], $module, $delta);
-      module_invoke($module, 'block', 'save', $delta, $edit);
-      drupal_set_message(t('The block configuration has been saved.'));
-      cache_clear_all();
-      drupal_goto('admin/block');
+  $form['module'] = array('#type' => 'value', '#value' => $module);
+  $form['delta'] = array('#type' => 'value', '#value' => $delta);
 
-    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 FROM {blocks} WHERE module = '%s' AND delta = '%s'", $module, $delta));
-      }
+  $edit = db_fetch_array(db_query("SELECT pages, visibility, custom FROM {blocks} WHERE module = '%s' AND delta = '%s'", $module, $delta));
 
-      // Module-specific block configurations.
-      if ($settings = module_invoke($module, 'block', 'configure', $delta)) {
-          $form['block_settings'] = array('#type' => 'fieldset',
-            '#title' => t('Block specific settings'),
-            '#collapsible' => true,
-            '#collapsed' => false,
-            '#weight' => 0);
+  // Module-specific block configurations.
+  if ($settings = module_invoke($module, 'block', 'configure', $delta)) {
+    $form['block_settings'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Block specific settings'),
+      '#collapsible' => true,
+      '#collapsed' => false,
+      '#weight' => 0
+    );
 
-          foreach ($settings as $k => $v) {
-            $form['block_settings'][$k] = $v;
-          }
-      }
+    foreach ($settings as $k => $v) {
+      $form['block_settings'][$k] = $v;
+    }
+  }
 
-      // 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'])));
-
-      // Standard block configurations.
-
-      $form['user_vis_settings'] = array('#type' => 'fieldset',
-        '#title' => t('User specific visibility settings'),
-        '#collapsible' => true,
-        '#collapsed' => false,
-        '#weight' => 0);
-
-      $form['user_vis_settings']['custom'] = array(
-        '#type' => 'radios',
-        '#title' => t('Custom visibility settings'),
-        '#default_value' => $edit['custom'],
-        '#options' => array(t('Users cannot control whether or not they see this block.'), t('Show this block by default, but let individual users hide it.'), t('Hide this block by default but let individual users show it.'), t('Allow individual users to customize the visibility of this block in their account settings.')),
-        '#default_value' => $edit['custom']);
-
-
-      $form['page_vis_settings'] = array('#type' => 'fieldset',
-        '#title' => t('Page specific visibility settings'),
-        '#collapsible' => true,
-        '#collapsed' => false,
-        '#weight' => 0);
-
-
-      $form['page_vis_settings']['visibility'] = array(
-        '#type' => 'radios',
-        '#title' => t('Show block on specific pages'),
-        '#default_value' => $edit['visibility'],
-        '#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'), t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).')),
-        '#default_value' => $edit['visibility']);
-
-      $form['page_vis_settings']['pages'] = array(
-        '#type' => 'textarea',
-        '#title' => t('Pages'),
-        '#default_value' => $edit['pages'],
-        '#cols' => 60,
-        '#rows' => 5,
-        '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '%blog' for the blog page and %blog1 for every personal blog. %front is the front page. If the PHP-mode is chosen, enter PHP code between %php.  Note that executing incorrect PHP-code can break your Drupal site.", array('%blog' => theme('placeholder', 'blog'), '%blog1' =>  theme('placeholder', 'blog/*'), '%front' => theme('placeholder', '<front>'), '%php' => theme('placeholder', '<?php ?>'))));
+  // 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'])));
+
+  // Standard block configurations.
+
+  $form['user_vis_settings'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('User specific visibility settings'),
+    '#collapsible' => true,
+    '#collapsed' => false,
+    '#weight' => 0
+  );
+  $form['user_vis_settings']['custom'] = array(
+    '#type' => 'radios',
+    '#title' => t('Custom visibility settings'),
+    '#options' => array(t('Users cannot control whether or not they see this block.'), t('Show this block by default, but let individual users hide it.'), t('Hide this block by default but let individual users show it.'), t('Allow individual users to customize the visibility of this block in their account settings.')),
+    '#default_value' => $edit['custom']
+  );
+  $form['page_vis_settings'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Page specific visibility settings'),
+    '#collapsible' => true,
+    '#collapsed' => false,
+    '#weight' => 0
+  );
+  $form['page_vis_settings']['visibility'] = array(
+    '#type' => 'radios',
+    '#title' => t('Show block on specific pages'),
+    '#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'), t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).')),
+    '#default_value' => $edit['visibility']
+  );
+  $form['page_vis_settings']['pages'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Pages'),
+    '#default_value' => $edit['pages'],
+    '#cols' => 60,
+    '#rows' => 5,
+    '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '%blog' for the blog page and %blog1 for every personal blog. %front is the front page. If the PHP-mode is chosen, enter PHP code between %php.  Note that executing incorrect PHP-code can break your Drupal site.", array('%blog' => theme('placeholder', 'blog'), '%blog1' =>  theme('placeholder', 'blog/*'), '%front' => theme('placeholder', '<front>'), '%php' => theme('placeholder', '<?php ?>')))
+  );
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save block')
+  );
 
-      $form['submit'] = array('#type' => 'submit', '#value' => t('Save block'));
+  return drupal_get_form('block_admin_configure', $form);
+}
 
-      return drupal_get_form('block_config', $form);
+function block_admin_configure_validate($form_id, $values) {
+  if (empty($values['info']) || db_num_rows(db_query("SELECT bid FROM {boxes} WHERE bid != %d AND info = '%s'", $values['delta'], $values['info']))) {
+    form_set_error('info', t('Please ensure that each block description is unique.'));
+  }
+}
+
+function block_admin_configure_execute($form_id, $values) {
+  if (!form_get_errors()) {
+    db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d WHERE module = '%s' AND delta = '%s'", $values['visibility'], $values['pages'], $values['custom'], $values['module'], $values['delta']);
+    module_invoke($values['module'], 'block', 'save', $values['delta'], $values);
+    drupal_set_message(t('The block configuration has been saved.'));
+    cache_clear_all();
+    drupal_goto('admin/block');
   }
 }
 
@@ -394,22 +401,25 @@ function block_admin_configure($module =
  * Menu callback; displays the block creation form.
  */
 function block_box_add() {
-  $edit = $_POST['edit'];
-  $op = $_POST['op'];
+  $form = block_box_form();
+  $form['submit'] = array('#type' => 'submit', '#value' => t('Save block'));
 
-  switch ($op) {
-    case t('Save block'):
-      if (block_box_save($edit)) {
-        drupal_set_message(t('The block has been created.'));
-        drupal_goto('admin/block');
-      }
-      // deliberate no break
-    default:
-      $form = block_box_form($edit);
-      $form['submit'] = array('#type' => 'submit', '#value' => t('Save block'));
+  return drupal_get_form('block_box_add', $form);
+}
+
+function block_box_add_validate($form_id, $values) {
+  if (empty($values['info']) || db_num_rows(db_query("SELECT info FROM {boxes} WHERE info = '%s'", $values['info']))) {
+    form_set_error('info', t('Please ensure that each block description is unique.'));
   }
+}
 
-  return drupal_get_form('block_box_add', $form);
+function block_box_add_execute($form_id, $values) {
+  if (!form_get_errors()) {
+    if (block_box_save($values)) {
+      drupal_set_message(t('The block has been created.'));
+      drupal_goto('admin/block');
+    }
+  }
 }
 
 /**
@@ -453,10 +463,6 @@ function block_box_save($edit, $delta = 
     db_query("UPDATE {boxes} SET title = '%s', body = '%s', info = '%s', format = %d WHERE bid = %d", $edit['title'], $edit['body'], $edit['info'], $edit['format'], $delta);
   }
   else {
-    if (empty($edit['info']) || db_num_rows(db_query("SELECT info FROM {boxes} WHERE info = '%s'", $edit['info']))) {
-      form_set_error('info', t('Please ensure that 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']);
   }
   return true;
