public function ajax_add_block($handler_vars)
{
Utils::check_request_method(array('POST'));
$this->setup_admin_theme('');
$title = $_POST['title'];
$type = $_POST['type'];
if (!isset($_POST['title'])) {
$this->theme->blocks = Plugins::filter('block_list', array());
$this->theme->block_instances = DB::get_results('SELECT b.* FROM {blocks} b ORDER BY b.title ASC', array(), 'Block');
$this->theme->active_theme = Themes::get_active_data(true);
$this->display('block_instances');
} elseif ($title == '') {
$this->theme->blocks = Plugins::filter('block_list', array());
$this->theme->block_instances = DB::get_results('SELECT b.* FROM {blocks} b ORDER BY b.title ASC', array(), 'Block');
$this->theme->active_theme = Themes::get_active_data(true);
$this->display('block_instances');
$msg = json_encode(_t('A new block must first have a name.'));
echo '<script type="text/javascript">
//alert(' . $msg . ');
human_msg.display_msg(' . $msg . ');
</script>';
} else {
$block = new Block(array('title' => $title, 'type' => $type));
$block->insert();
$this->prepare_block_list();
$this->theme->active_theme = Themes::get_active_data(true);
$this->display('block_instances');
$msg = json_encode(_t('Added new block "%1s" of type "%2s".', array($title, $type)));
echo '<script type="text/javascript">
human_msg.display_msg(' . $msg . ');
spinner.stop();
</script>';
}
}