Index: modules/block/block.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.module,v
retrieving revision 1.234
diff -u -p -r1.234 block.module
--- modules/block/block.module	8 Nov 2006 19:49:13 -0000	1.234
+++ modules/block/block.module	19 Nov 2006 10:16:07 -0000
@@ -88,7 +88,7 @@ function block_menu($may_cache) {
     $items[] = array('path' => 'admin/build/block/add', 'title' => t('Add block'),
       'access' => user_access('administer blocks'),
       'callback' => 'drupal_get_form',
-      'callback arguments' => array('block_box_form'),
+      'callback arguments' => array('block_add_block_form'),
       'type' => MENU_LOCAL_TASK);
     $default = variable_get('theme_default', 'garland');
     foreach (list_themes() as $key => $theme) {
@@ -131,7 +131,10 @@ function block_block($op = 'list', $delt
       return $blocks;
 
     case 'configure':
-      $box = block_box_get($delta);
+      $box = array('format' => FILTER_FORMAT_DEFAULT);
+      if ($delta) {
+        $box = block_box_get($delta);
+      }
       if (filter_access($box['format'])) {
         return block_box_form($box);
       }
@@ -512,21 +515,45 @@ function block_admin_configure_submit($f
   }
 }
 
-function block_box_form_validate($form_id, $form_values) {
+/**
+ * Menu callback: display the custom block addition form.
+ */
+function block_add_block_form() {
+  $form = block_admin_configure('block', NULL);
+  return $form;
+}
+
+function block_add_block_form_validate($form_id, $form_values) {
   if (empty($form_values['info']) || db_num_rows(db_query("SELECT info FROM {boxes} WHERE info = '%s'", $form_values['info']))) {
     form_set_error('info', t('Please ensure that each block description is unique.'));
   }
 }
 
-function block_box_form_submit($form_id, $form_values) {
-  if (!form_get_errors()) {
-    if (block_box_save($form_values)) {
-      drupal_set_message(t('The block has been created.'));
-      return 'admin/build/block';
+/**
+ * Save the new custom block.
+ */
+function block_add_block_form_submit($form_id, $form_values) {
+  $delta = db_next_id('{boxes}_bid');
+
+  foreach (list_themes() as $key => $theme) {
+    if ($theme->status) {
+      db_query("INSERT INTO {blocks} (visibility, pages, custom, title, module, theme, status, weight, delta) VALUES(%d, '%s', %d, '%s', '%s', '%s', %d, %d, %d)", $form_values['visibility'], trim($form_values['pages']), $form_values['custom'], $form_values['title'], $form_values['module'], $theme->name, 0, 0, $delta);
     }
   }
+
+  foreach (array_filter($form_values['roles']) as $rid) {
+    db_query("INSERT INTO {blocks_roles} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_values['module'], $delta);
+  }
+
+  db_query("INSERT INTO {boxes} (bid, body, info, format) VALUES  (%d, '%s', '%s', %d)", $delta, $form_values['body'], $form_values['info'], $form_values['format']);
+
+  drupal_set_message(t('The block has been created.'));
+  cache_clear_all();
+
+  return 'admin/build/block';
 }
 
+
 /**
  * Menu callback; confirm deletion of custom blocks.
  */
@@ -549,6 +576,9 @@ function block_box_delete_submit($form_i
   return 'admin/build/block';
 };
 
+/**
+ * Define the custom block form.
+ */
 function block_box_form($edit = array()) {
   $form['info'] = array(
     '#type' => 'textfield',
@@ -572,7 +602,6 @@ function block_box_form($edit = array())
     $edit['format'] = FILTER_FORMAT_DEFAULT;
   }
   $form['body_filter']['format'] = filter_form($edit['format'], -16);
-  $form['submit'] = array('#type' => 'submit', '#value' => t('Save block'));
 
   return $form;
 }
@@ -582,12 +611,8 @@ function block_box_save($edit, $delta = 
     $edit['format'] = FILTER_FORMAT_DEFAULT;
   }
 
-  if (isset($delta)) {
-    db_query("UPDATE {boxes} SET body = '%s', info = '%s', format = %d WHERE bid = %d", $edit['body'], $edit['info'], $edit['format'], $delta);
-  }
-  else {
-    db_query("INSERT INTO {boxes} (body, info, format) VALUES  ('%s', '%s', %d)", $edit['body'], $edit['info'], $edit['format']);
-  }
+  db_query("UPDATE {boxes} SET body = '%s', info = '%s', format = %d WHERE bid = %d", $edit['body'], $edit['info'], $edit['format'], $delta);
+
   return TRUE;
 }
 
Index: modules/system/system.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.install,v
retrieving revision 1.40
diff -u -p -r1.40 system.install
--- modules/system/system.install	8 Nov 2006 19:24:11 -0000	1.40
+++ modules/system/system.install	18 Nov 2006 23:15:08 -0000
@@ -153,7 +153,7 @@ function system_install() {
       ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 
       db_query("CREATE TABLE {boxes} (
-        bid tinyint NOT NULL auto_increment,
+        bid tinyint NOT NULL,
         body longtext,
         info varchar(128) NOT NULL default '',
         format int NOT NULL default '0',
@@ -615,7 +615,7 @@ function system_install() {
       )");
 
       db_query("CREATE TABLE {boxes} (
-        bid serial,
+        bid int NOT NULL,
         title varchar(64) NOT NULL default '',
         body text,
         info varchar(128) NOT NULL default '',
@@ -3375,6 +3375,21 @@ function system_update_1014() {
   return array();
 }
 
+function system_update_1015() {
+  $ret = array();
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql('ALTER TABLE {boxes} CHANGE COLUMN bid bid tinyint NOT NULL');
+      break;
+    case 'pgsql':
+      $ret[] = update_sql('ALTER TABLE {boxes} ALTER COLUMN bid TYPE int');
+      $ret[] = update_sql('ALTER TABLE {boxes} ALTER COLUMN bid SET NOT NULL');
+      break;
+  }
+  return $ret;
+}
+
 /**
  * @} End of "defgroup updates-4.7-to-x.x"
  * The next series of updates should start at 2000.
