Index: modules/block/block.module =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.module,v retrieving revision 1.234 diff -u -F^f -r1.234 block.module --- modules/block/block.module 8 Nov 2006 19:49:13 -0000 1.234 +++ modules/block/block.module 19 Nov 2006 16:57:48 -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); } @@ -404,7 +407,9 @@ function block_admin_configure($module = // 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']))); + if (isset($info[$delta])) { + drupal_set_title(t("'%name' block", array('%name' => $info[$delta]['info']))); + } // Standard block configurations. $form['user_vis_settings'] = array( @@ -512,21 +517,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 +578,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 +604,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 +613,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 -F^f -r1.40 system.install --- modules/system/system.install 8 Nov 2006 19:24:11 -0000 1.40 +++ modules/system/system.install 19 Nov 2006 16:57:52 -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', @@ -3069,7 +3069,7 @@ function system_update_182() { } /** - * @defgroup updates-4.7-to-x.x System updates from 4.7 to x.x + * @defgroup updates-4.7-to-x.x System updates from 4.7 to 5 * @{ */ @@ -3375,7 +3375,20 @@ function system_update_1014() { return array(); } +function system_update_1015() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $max = (int)db_result(db_query('SELECT MAX(bid) FROM {boxes}')); + $ret[] = update_sql('ALTER TABLE {boxes} CHANGE COLUMN bid bid tinyint NOT NULL'); + $ret[] = update_sql("REPLACE INTO {sequences} VALUES ('{boxes}_bid', $max)"); + break; + } + return $ret; +} + /** - * @} End of "defgroup updates-4.7-to-x.x" + * @} End of "defgroup updates-4.7-to-5" * The next series of updates should start at 2000. */