<?php
    echo form_fieldset(lang('db_db'), array(
        'class' => 'bordertop'
    ));

        $hostname = element('hostname', $new_db_settings);
        $username = element('username', $new_db_settings);
        $password = element('password', $new_db_settings);
        $port = element('port', $new_db_settings);
        $database = element('database', $new_db_settings);

        if ($hostname && $database) {
            $formstyle = 'disabled';
        } else {
            $formstyle = 'enabled';
        }
        
        $localhost = (PHP_OS=='Darwin') ? '127.0.0.1' : 'localhost';

        echo '<p class="formstyle">';
            echo form_label('<span class="label1">'.lang('db_server').' <small>*</small>:</span>', 'server');
            echo form_input(array(
                'name' => 'server',
                'size' => '50',
                'style' => 'width:300px;',
                'class' => 'required',
                'value' => set_value('server', ($hostname) ? $hostname : $localhost),
                $formstyle => $formstyle,
                'required' => 'required',
            ));
        echo '</p>';
        
        if (!is_numeric($port)) {
            $port = 3306;
        }
        echo '<p class="formstyle">';
            echo form_label('<span class="label1">'.lang('db_port').' <small>*</small>:</span>', 'port');
            echo form_input(array(
                'name' => 'port',
                'size' => '30',
                'style' => 'width:100px;',
                'class' => 'required',
                'value' => set_value('port', $port),
                $formstyle => true,
            ));
        echo '</p>';
        
        if (!$username || !$password):
            $username = 'root';
            $password = '';
            echo '<p class="formstyle">';
                echo form_label('<span class="label1">'.lang('db_username').' <small>*</small>:</span>', 'username');
                echo form_input(array(
                    'name' => 'username',
                    'size' => '50',
                    'style' => 'width:300px;',
                    'class' => 'required',
                    'value' => set_value('username', $username),
                    'enabled' => 'enabled',
                    'required' => 'required',
                ));
            echo '</p>';

            echo '<p class="formstyle">';
                echo form_label('<span class="label1">'.lang('db_password').':</span>', 'password');
                echo form_password(array(
                    'name' => 'password',
                    'size' => '50',
                    'style' => 'width:300px;',
                    'value' => set_value('password', $password),
                    'enabled' => 'enabled',
                ));
            echo '</p>';
        endif;

        echo '<hr>';
        echo '<p class="formstyle">';
        echo form_label('<span class="label1">'.lang('db_us_username').' <small>*</small>:</span>', 'username');
        echo form_input(array(
            'name' => 'us_username',
            'size' => '50',
            'style' => 'width:300px;',
            'class' => 'required',
            'value' => set_value('us_username', $us_username),
            'enabled' => 'enabled',
            'required' => 'required',
        ));
        echo '</p>';

        echo '<p class="formstyle">';
            echo form_label('<span class="label1">'.lang('db_name').'<small>*</small>:</span>', 'database');
            echo form_input(array(
                'name' => 'database',
                'size' => '50',
                'style' => 'width:300px;',
                'class' => 'required',
                'value' => set_value('database', ($database) ? $database : 'untermstrich'),
                $formstyle => $formstyle,
                'required' => 'required',
            ));
        echo '</p>';

    echo form_fieldset_close();
