<?php
$formUrl = $this->url(array('controller'=>'sql','action'=>'create.database'));
?>
<div id="content">
<h2><?php echo $this->lang->L_CREATE_DATABASE;?></h2>
<?php echo $this->sqlHeadNavi(); ?>
<h4><?php echo $this->lang->L_CREATE_DATABASE;?>:</h4>
    <form method="post" action="<?php echo $formUrl;?>">
        <table class="bdr" summary="create new database">
            <tr class="row-odd">
                <td><?php echo $this->lang->L_DB_NAME; ?>:</td>
                <td><input type="text" class="text" id="dbName" name="newDbInfo[dbName]" value="<?php echo (isset($this->dbCreated) && !$this->dbCreated) ? $this->out($this->newDbInfo['dbName']) : ''; ?>"/></td>
            </tr>
            <tr class="row-even">
                <td><?php echo $this->lang->L_DEFAULT_CHARSET;?>:</td>
                <td><select class="select" id="dbCharset" name="newDbInfo[dbCharset]"><?php foreach ($this->charsets as $charset) { ?>
                    <option value="<?php echo $this->out($charset); ?>"<?php echo ($charset == $this->newDbInfo['dbCharset']) ? ' selected="selected"' : ''; ?>><?php echo $this->out($charset); ?></option>
                <?php } ?></select></td>
            </tr>
            <tr class="row-odd">
                <td><?php echo $this->lang->L_DEFAULT_COLLATION_NAME;?>:</td>
                <td><select class="select" id="dbCollation" name="newDbInfo[dbCollation]"><?php foreach ($this->collations[$this->newDbInfo['dbCharset']] as $collation) { ?>
                    <option value="<?php echo $this->out($collation); ?>"<?php echo ($collation == $this->newDbInfo['dbCollation']) ? ' selected="selected"' : ''; ?>><?php echo $this->out($collation); ?></option>
                <?php } ?></select></td>
            </tr>
            <tr class="row-even">
                <td>&nbsp;</td>
                <td class="buttonBar">
                    <button type="submit" class="Formbutton"><?php echo $this->getIcon('Database', '', 16); echo $this->lang->L_CREATE_DATABASE; ?></button>
                </td>
            </tr>
        </table>
    </form>
</div>
<?php $this->jQuery()->onLoadCaptureStart(); ?>
var dbCollations = <?php echo json_encode($this->collations); ?>;
var dbDefaultCollations = <?php echo json_encode($this->defaultCollations); ?>;
$('#dbCharset').bind('change', function() {
    var newOpts = '';
    var curCharset = $(this).val();
    $(dbCollations[curCharset]).each(function(id, v) {
        var selected = '';
        if (v == dbDefaultCollations[curCharset]) {
            selected = ' selected="selected"';
        }
        newOpts += '<option value="' + v +'"' + selected + '>' + v + '</option>';
        $('#dbCollation').html(newOpts);
    });
});
$(document).ready(function() {
    $('#dbName').focus();
});
<?php
$this->jQuery()->onLoadCaptureEnd();

if (isset($this->dbCreated)) {
    if ($this->dbCreated) {
        $this->popUpMessage()->addMessage(
            'dialogDbCreation',
            'L_CREATE_DATABASE',
            array('L_DATABASE_CREATED_SUCCESS', $this->newDbInfo['dbName']),
            array(
                'modal' => 'true',
                'autoOpen' => 'true',
                'buttons' => array(
                    'L_OK' => 'function(){$(this).dialog("close"); }',
                )
            )
        );
    } else {
        $this->popUpMessage()->addMessage(
            'dialogDbCreation',
            'L_CREATE_DATABASE',
            array(
                'L_DATABASE_CREATED_FAILED',
                '<span class="error">(' . $this->errorInfo['code'] . ') '
                . $this->errorInfo['message'] .'</span>'
            ),
            array(
                'modal' => 'true',
                'autoOpen' => 'true',
                'buttons' => array(
                    'L_OK' => 'function(){$(this).dialog("close"); }',
                )
            )
        );
    }
}
?>