<?php if (!defined('MAX_PATH')) { exit; } ?>



    <br />
    <table border='0' cellpadding='0' cellspacing='0' width='100%'>
    <tr>
        <td colspan='2' align='center'>
            <div id='displayDbError' style='display:block'>
        <?php
            if ($displayError == true) {
            	include 'install-messages.html';
            }
        ?>
            </div>
        </td>
    </tr>
    <tr>
        <td valign='top'>
        <img class="install-icon" src='<?php echo $imgPath; ?>images/install-database.png'></td>
        <td width='100%' valign='top'>
        <br>
        <span class='tab-s'><?php echo $strDbSetupTitle; ?></span><br><img src='<?php echo $imgPath; ?>images/break-el.gif' width='100%' height='1' vspace='8'><span class='install'><?php echo ($_COOKIE['oat'] == OA_UPGRADE_UPGRADE) ? $strDbUpgradeIntro : $strDbSetupIntro; ?></span>
        </td>
    </tr>
    </table>
    <br />
    <br />
    <script type='text/javascript'>

    function showLoaders(f) {
        noerrors = max_formValidate(f);
        if (noerrors == true) {
            var errObj = new getObj('displayDbError');
            var pgsqlWarn  = new getObj('pgSqlWarning');
            errObj.style.display='none';
            pgsqlWarn.style.display = 'none';
            showLoader();
        }
        return(noerrors);
    }

    function switchDbTypes() {
        var dbType     = new getObj('aConfig[database][type]');
        var portObj    = new getObj('aConfig[database][port]');
        var TblTypeObj = new getObj('aConfig[table][type]');
        var pgsqlWarn  = new getObj('pgSqlWarning');
        if (dbType.obj.value == 'mysql') {
            portObj.obj.value = 3306;
            if (!portObj.obj.disabled) {
                TblTypeObj.obj.disabled = false;
            }
            pgsqlWarn.style.display = 'none';
        } else if (dbType.obj.value == 'pgsql') {
            portObj.obj.value = 5432;
            TblTypeObj.obj.disabled = 'disabled';
            pgsqlWarn.style.display = 'block';
        }
        toggleSocketInput();
    }
    </script>

<div id="pgSqlWarning" class="sysmessage sysinfoerror" style="display:none;">Please understand that support for PostgreSQL is currently experimental. Proceed with caution!</div>

<?php OA_GUI_getHtmlForDbLoader("Processing..."); ?>

<form name="frmOpenads" id="frmOpenads" method="POST" action="install.php" onSubmit='return showLoaders(this);' style="margin:0; padding:0;">

<?php
if ($errTz) {
?>
<div id="errTz" class="sysmessage sysinfowarning">
<p>As of this version OpenX stores dates in UTC time rather than in server time.</p>
<p>
    If you want historical statistics to be displayed with the correct timezone, upgrade your data manually.  Learn more <a target="help" href="http://www.openx.org/en/docs/2.8/adminguide/Upgrade+Time+Zones">here</a>.
    Your statistics values will remain accurate even if you leave your data untouched.
</p>
<p>
<input type="checkbox" name="noTzAlert" id="noTzAlert" value="1" />
<label for="noTzAlert">Do not display timezone warnings in the future</label>
<p>
</div>

<?php
}

    // Disable the form items if user is upgrading
    // Change $inputType so that disabled selects are text fields, so that the correct value can be displayed
    if ($_COOKIE['oat'] == OA_UPGRADE_UPGRADE) {
        $disableForm = true;
        $inputType   = 'text';
    } else {
        $disableForm = false;
        $inputType   = 'select';
    }

    //  get default socket
        if (empty($aDatabase['database']['socket']) && $aDatabase['database']['type'] == 'mysql') {
        $aDatabase['database']['socket'] = str_replace("'", '', ini_get('mysql.default_socket'));
    }

    $options->show(array (
        array (
            'text'  => $strDatabaseSettings,
            'items' => array (
                array (
                    'type'      => $inputType,
                    'name'      => 'aConfig[database][type]',
                    'text'      => $strDbType,
                    'disabled'  => $disableForm,
                    'onchange'  => 'switchDbTypes(this);',
                    'value'     => $aDatabase['database']['type'],
                    'items'     => getSupportedDbTypes()
                ),
                array (
                    'type'      => 'break'
                ),
                array (
                    'type'    => 'checkbox',
                    'name'    => 'aConfig[database][localsocket]',
                    'text'    => $strDbLocal,
                    'onclick' => 'toggleSocketInput(this);',
                    'disabled'=> $disableForm,
                    'req'     => false,
                    'value'   => ($aDatabase['database']['localsocket'] || $aDatabase['database']['protocol'] == 'unix'),
                ),
                array (
                    'type'      => 'break'
                ),
                array (
                    'type'    => 'text',
                    'name'    => 'aConfig[database][socket]',
                    'text'    => $strDbSocket,
                    'disabled'=> $disableForm,
                    'req'     => false,
                    'value'   => $aDatabase['database']['socket']
                ),

                array (
                    'type'      => 'break'
                ),
                array (
                    'type'      => 'text',
                    'name'      => 'aConfig[database][host]',
                    'text'      => $strDbHost,
                    'disabled'  => $disableForm,
                    'req'       => true,
                    'value'     => $aDatabase['database']['host']
                ),
                array (
                    'type'    => 'break'
                ),
                array (
                    'type'      => 'text',
                    'name'      => 'aConfig[database][port]',
                    'text'      => $strDbPort,
                    'disabled'  => $disableForm,
                    'req'       => true,
                    'value'     => $aDatabase['database']['port']
                ),
                array (
                    'type'      => 'break'
                ),
                array (
                    'type'      => 'text',
                    'name'      => 'aConfig[database][username]',
                    'text'      => $strDbUser,
                    'disabled'  => $disableForm,
                    'req'       => true,
                    'autooff'   => true,
                    'value'     => $aDatabase['database']['username']
                ),
                array (
                    'type'      => 'break'
                ),
                array (
                    'type'      => 'password',
                    'name'      => 'aConfig[database][password]',
                    'text'      => $strDbPassword,
                    'disabled'  => $disableForm,
                    'req'       => false,
                    'autooff'   => true,
                    'value'     => $aDatabase['database']['password']
                ),
                array (
                    'type'      => 'break'
                ),
                array (
                    'type'      => 'text',
                    'name'      => 'aConfig[database][name]',
                    'hint'      => $strDbNameHint,
                    'text'      => $strDbName,
                    'disabled'  => $disableForm,
                    'req'       => true,
                    'value'     => stripslashes($aDatabase['database']['name']),
                    'decode'    => true,
                )
            )
        ),
        array (
            'text'  => $strAdvancedSettings,
            'items' => array (
                array (
                    'type'      => $inputType,
                    'name'      => 'aConfig[table][type]',
                    'text'      => $strTablesType,
                    'disabled'  => $disableForm,
                    'value'     => $aDatabase['table']['type'],
                    'items'     => getSupportedTableTypes()
                ),
                array (
                    'type'      => 'break'
                ),
                array (
                    'type'      => 'text',
                    'name'      => 'aConfig[table][prefix]',
                    'text'      => $strTablesPrefix,
                    'disabled'  => $disableForm,
                    'req'       => false,
                    'maxlength' => '7',
                    'value'     => stripslashes($aDatabase['table']['prefix']),
                    'decode'    => true,
                )
            )
        )
    ), $errormessage, 0, $imgPath);
?>
                <script type='text/javascript'>
                    switchDbTypes();
                    toggleSocketInput();
                </script>
                <input type="submit" class="button" id="btn_upgrade" name="btn_upgrade" value="<?php echo ($displayError ? $strBtnRetry : $strBtnContinue); ?>" tabindex="<?php echo ($tabindex++); ?>" <?php echo $disableButton; ?>>
                <input type="hidden" name="dirPage" id="dirPage" value="" />
</form>

<form name="frmOpenads2" id="frmOpenads2" method="POST" action="install.php" style="margin:0; padding:0;">
                <input type="submit" class="button floatleft" id="btn_syscheck" name="btn_syscheck" value="<?php echo $strBtnGoBack; ?>" tabindex="<?php echo ($tabindex++); ?>" />
</form>
<form>


