Index: multiblock.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/multiblock/multiblock.module,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 multiblock.module
--- multiblock.module	18 May 2008 00:39:13 -0000	1.1.2.1
+++ multiblock.module	18 May 2008 23:55:15 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: multiblock.module,v 1.1.2.1 2008/05/18 00:39:13 andrewlevine Exp $
+// $Id: multiblock.module,v 1.1 2008/02/29 20:26:31 andrewlevine Exp $
 
 /**
  * Implementation of hook_menu().
@@ -16,15 +16,14 @@
         'type' => MENU_NORMAL_ITEM,
     );
     $items[] = array(
-      'path' => 'multiblock/delete',
+      'path' => 'admin/build/multiblock/delete',
       'title' => t('Delete Block Instance'),
-      'callback' => 'multiblock_delete',
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('multiblock_delete_form'),
       'access' => user_access('administer blocks'),
       'type' => MENU_CALLBACK,
     );
   }
-  else {
-  }
   return $items;
 }
 
@@ -34,18 +33,48 @@
 function multiblock_block($op = 'list', $delta = 0, $edit = array()) {
   if ($op == 'list') {
     // Get all of the block instances that exist.
-    $result = db_query("SELECT delta, title FROM {multiblock}");
+    return multiblock_get_block_list();
+  }
+  // Any op besides list we want to dispatch the call to its respective module.
+  else if ($op == 'view' || $op == 'configure' || $op == 'save') {
+    return multiblock_call_block($delta, $op, $edit);
+  }
+}
+
+/**
+ * Fetch a given block from the multiblock database table.
+ * 
+ * @param $delta
+ *   Optional. Retreive a single block based on this delta. If none specified,
+ *   all multiblock instances are returned.
+ * @param $reset
+ *   Optional. Boolean value to reset the interal cache of this function.
+ */
+function multiblock_get_block($delta = NULL, $reset = FALSE) {
+  static $blocks;
+
+  if (!isset($blocks) || $reset) {
     $blocks = array();
+    $result = db_query("SELECT * FROM {multiblock}");
     // Escape the titles and return an array of them keyed by their NEW deltas.
     while ($row = db_fetch_object($result)) {
-      $blocks[$row->delta] = array( 'info' => check_plain($row->title), );
+      $blocks[$row->delta] = $row;
     }
-    return $blocks;
   }
-  // Any op besides list we want to dispatch the call to its respective module.
-  else if ($op == 'view' || $op == 'configure' || $op == 'save') {
-    return multiblock_call_block($delta, $op, $edit);
+
+  return is_numeric($delta) ? $blocks[$delta] : $blocks;
+}
+
+/**
+ * Retreive a list of blocks provided by this module.
+ */
+function multiblock_get_block_list() {
+  $blocks = multiblock_get_block();
+  $list = array();
+  foreach ($blocks as $block) {
+    $list[$block->delta] = array('info' => check_plain($block->title));
   }
+  return $list;
 }
 
 /**
@@ -82,12 +111,7 @@
   $form = drupal_get_form('multiblock_add_block', $blocks);
  
   // Get an array of existing blocks.
-  $result = db_query('SELECT * FROM {multiblock} ORDER BY title'); 
-  $multiblocks = array();
-  while ($multiblock = db_fetch_object($result)) {
-    $multiblocks[] = $multiblock;
-  }
-  
+  $multiblocks = multiblock_get_block();
   return theme('multiblock_general', $form, $multiblocks);
 }
 
@@ -127,23 +151,44 @@
   return $form;
 }
 
+function multiblock_delete_form($delta) {
+  $block = multiblock_get_block($delta);
+
+  if (empty($block)) {
+    drupal_set_message(t('The multiblock with the delta @delta was not found.', array('@delta' => $delta)), 'error');
+    return array();
+  }
+
+  $form['delta'] = array('#type' => 'value', '#value' => $delta);
+  return confirm_form($form,
+    t('Delete the block instance %title?', array('%title' => $block->title)),
+    'admin/build/multiblock',
+    t('This will delete the instance of the block %title.', array('%title' => $block->title)),
+    t('Delete'), t('Cancel'));
+}
+
+function multiblock_delete_form_submit($form_id, $form_values) {
+  if (multiblock_delete($form_values['delta'])) {
+    drupal_set_message(t('Block successfully deleted!'));
+  }
+  else {
+    drupal_set_message(t('There was a problem deleting the block'));
+  }
+  return 'admin/build/multiblock';
+}
+
 /**
- * Callback that deletes the block instance with a delta of arg(2)
- * and redirects the user back to the "Manage Block Instances" form.
+ * Delete a multiblock instance.
  */
-function multiblock_delete() {
-  $multiblock_delta = arg(2);
-  $result = db_query('DELETE FROM {multiblock} WHERE delta=%d', (int)$multiblock_delta);
-  // If we actually deleted something.
+function multiblock_delete($multiblock_delta) {
+  $result = db_query('DELETE FROM {multiblock} WHERE delta = %d', (int)$multiblock_delta);
   if (ctype_digit($multiblock_delta) && db_affected_rows() == 1) {
-    drupal_set_message(t('Block successfully deleted!'));
     _block_rehash();
+    return TRUE;
   }
   else {
-    drupal_set_message(t('There was a problem deleting the block'));
+    return FALSE;
   }
-  drupal_goto('admin/build/multiblock');
-  exit;
 }
 
 /**
@@ -215,7 +260,7 @@
   $header = array(t('Title'), t('Original Block Title'), t('Original Module'), t('Original Delta'), t('Action'));
   
   foreach ($multiblocks as $row) {
-    $delete_link = l(t('Delete'), 'multiblock/delete/'. $row->delta);
+    $delete_link = l(t('Delete'), 'admin/build/multiblock/delete/'. $row->delta);
     $title = multiblock_get_block_title($row->module, $row->orig_delta);
     $rows[] = array(check_plain($row->title), $title, $row->module, $row->orig_delta, $delete_link);
   }
@@ -223,4 +268,4 @@
   $output .= '<p><h3>'. t('Manage Instances') .'</h3>'. theme('table', $header, $rows) .'</p>';
   
   return $output;
-}
+}
\ No newline at end of file
