<?php

    // set to defaults if undefined
    if (!isset($config->host)) {
        $config->host = 'localhost';
    }
    if (!isset($config->type)) {
        $config->type = 'mysql';
    }
    if (!isset($config->sybasequoting)) {
        $config->sybasequoting = 0;
    }
    if (!isset($config->name)) {
        $config->name = '';
    }
    if (!isset($config->user)) {
        $config->user = '';
    }
    if (!isset($config->pass)) {
        $config->pass = '';
    }
    if (!isset($config->table)) {
        $config->table = '';
    }
    if (!isset($config->fielduser)) {
        $config->fielduser = '';
    }
    if (!isset($config->fieldpass)) {
        $config->fieldpass = '';
    }
    if (!isset($config->passtype)) {
        $config->passtype = 'plaintext';
    }
    if (!isset($config->changepasswordurl)) {
        $config->changepasswordurl = '';
    }
    if (empty($config->extencoding)) {
        $config->extencoding = 'utf-8';
    }
    if (empty($config->debugauthdb)) {
        $config->debugauthdb = 0;
    }
    if (!isset($config->setupsql)) {
        $config->setupsql = '';
    }
    if (!isset($config->removeuser)) {
        $config->removeuser = 0;
    }

    $yesno = array( get_string('no'), get_string('yes') );

?>
<table cellspacing="0" cellpadding="5" border="0">

<tr valign="top" class="required">
    <td align="right"><label for="host"><?php print_string("auth_dbhost_key", "auth") ?></label></td>
    <td>
        <input id="host" name="host" type="text" size="30" value="<?php echo $config->host?>" />
        <?php

        if (isset($err["host"])) {
            formerr($err["host"]);
        }

        ?>
    </td>
    <td><?php print_string("auth_dbhost", "auth") ?></td>
</tr>

<tr valign="top" class="required">
    <td align="right"><label for="menutype"><?php print_string("auth_dbtype_key", "auth") ?></label></td>
    <td>
    <?php  $dbtypes = array("access","ado_access", "ado", "ado_mssql", "borland_ibase", "csv", "db2", "fbsql", "firebird", "ibase", "informix72", "informix", "mssql", "mssql_n", "mysql", "mysqli", "mysqlt", "oci805", "oci8", "oci8po", "odbc", "odbc_mssql", "odbc_oracle", "oracle", "postgres64", "postgres7", "postgres", "proxy", "sqlanywhere", "sybase", "vfp");
       foreach ($dbtypes as $dbtype) {
           $dboptions[$dbtype] = $dbtype;
       }
       choose_from_menu($dboptions, "type", $config->type, "");
    ?>

    </td>
    <td>
    <?php print_string("auth_dbtype","auth") ?>
    </td>
</tr>

<tr valign="top" class="required">
    <td align="right"><label for="menusybasequoting"><?php print_string("auth_dbsybasequoting", "auth") ?></label></td>
    <td>
        <?php choose_from_menu($yesno, 'sybasequoting', $config->sybasequoting, ''); ?>
    </td>
    <td><?php print_string("auth_dbsybasequotinghelp", "auth") ?></td>
</tr>

<tr valign="top" class="required">
    <td align="right"><label for="name"><?php print_string("auth_dbname_key", "auth") ?></label></td>
    <td>
        <input id="name" name="name" type="text" size="30" value="<?php echo $config->name?>" />
        <?php

        if (isset($err["name"])) {
            formerr($err["name"]);
        }

        ?>
    </td>
    <td><?php print_string("auth_dbname", "auth") ?></td>
</tr>

<tr valign="top" class="required">
    <td align="right"><label for="user"><?php print_string("auth_dbuser_key", "auth") ?></label></td>
    <td>
        <input id="user" name="user" type="text" size="30" value="<?php echo $config->user?>" />
        <?php

        if (isset($err["user"])) {
            formerr($err["user"]);
        }

        ?>
    </td>
    <td><?php print_string("auth_dbuser", "auth") ?></td>
</tr>

<tr valign="top" class="required">
    <td align="right"><label for="pass"><?php print_string("auth_dbpass_key", "auth") ?></label></td>
    <td>
        <input id="pass" name="pass" type="text" size="30" value="<?php echo $config->pass?>" />
        <?php

        if (isset($err["pass"])) {
            formerr($err["pass"]);
        }

        ?>
    </td>
    <td>
    <?php print_string("auth_dbpass", "auth") ?>
    </td>
</tr>

<tr valign="top" class="required">
    <td align="right"><label for="table"><?php print_string("auth_dbtable_key", "auth") ?></label></td>
    <td>
        <input id="table" name="table" type="text" size="30" value="<?php echo $config->table?>" />
        <?php

        if (isset($err["table"])) {
            formerr($err["table"]);
        }

        ?>
    </td>
    <td><?php print_string("auth_dbtable", "auth") ?></td>
</tr>

<tr valign="top" class="required">
    <td align="right"><label for="fielduser"><?php print_string("auth_dbfielduser_key", "auth") ?></label></td>
    <td>
        <input id="fielduser" name="fielduser" type="text" size="30" value="<?php echo $config->fielduser?>" />
        <?php

        if (isset($err["fielduser"])) {
            formerr($err["fielduser"]);
        }

        ?>
    </td>
    <td><?php print_string("auth_dbfielduser", "auth") ?></td>
</tr>

<tr valign="top" class="required">
    <td align="right"><label for="fieldpass"><?php print_string("auth_dbfieldpass_key", "auth") ?></label></td>
    <td>
        <input id="fieldpass" name="fieldpass" type="text" size="30" value="<?php echo $config->fieldpass?>" />
        <?php

        if (isset($err["fieldpass"])) {
            formerr($err["fieldpass"]);
        }

        ?>
    </td>
    <td><?php print_string("auth_dbfieldpass", "auth") ?></td>
</tr>

<tr valign="top" class="required">
    <td align="right"><label for="menupasstype"><?php print_string("auth_dbpasstype_key", "auth") ?></label></td>
    <td>
        <?php
        $passtype = array();
        $passtype["plaintext"] = get_string("plaintext", "auth");
        $passtype["md5"]       = get_string("md5", "auth");
        $passtype["sha1"]      = get_string("sha1", "auth");
        $passtype["internal"]  = get_string("internal", "auth");
        choose_from_menu($passtype, "passtype", $config->passtype, "");

        ?>
    </td>
    <td><?php print_string("auth_dbpasstype", "auth") ?></td>
</tr>

<tr valign="top" class="required">
    <td align="right"><label for="extencoding"><?php print_string("auth_dbextencoding", "auth") ?></label></td>
    <td>
        <input id="extencoding" name="extencoding" type="text" value="<?php echo $config->extencoding ?>" />
        <?php

        if (isset($err['extencoding'])) {
            formerr($err['extencoding']);
        }

        ?>
    </td>
    <td><?php print_string('auth_dbextencodinghelp', 'auth') ?></td>
</tr>

<tr valign="top">
    <td align="right"><label for="setupsql"><?php print_string("auth_dbsetupsql", "auth") ?></label></td>
    <td>
        <input id="setupsql" name="setupsql" type="text" value="<?php echo $config->setupsql ?>" />
    </td>
    <td><?php print_string('auth_dbsetupsqlhelp', 'auth') ?></td>
</tr>

<tr valign="top">
    <td align="right"><label for="menudebugauthdb"><?php print_string("auth_dbdebugauthdb", "auth") ?></label></td>
    <td>
        <?php choose_from_menu($yesno, 'debugauthdb', $config->debugauthdb, ''); ?>
    </td>
    <td><?php print_string("auth_dbdebugauthdbhelp", "auth") ?></td>
</tr>

<tr valign="top">
    <td align="right"><label for="changepasswordurl"><?php print_string("auth_dbchangepasswordurl_key", "auth") ?></label></td>
    <td>
        <input id="changepasswordurl" name="changepasswordurl" type="text" value="<?php echo $config->changepasswordurl ?>" />
        <?php

        if (isset($err['changepasswordurl'])) {
            formerr($err['changepasswordurl']);
        }

        ?>
    </td>
    <td><?php print_string('changepasswordhelp', 'auth') ?></td>
</tr>

<tr>
   <td colspan="2">
        <h4><?php print_string('auth_sync_script', 'auth') ?> </h4>
   </td>
</tr>

<tr valign="top">
    <td align="right"><label for="menuremoveuser"><?php print_string('auth_remove_user_key','auth') ?></label></td>
    <td>
    <?php
       $deleteopt = array();
       $deleteopt['0'] = get_string('auth_remove_keep','auth');
       $deleteopt['1'] = get_string('auth_remove_suspend','auth');
       $deleteopt['2'] = get_string('auth_remove_delete','auth');
       choose_from_menu($deleteopt, 'removeuser', $config->removeuser, '');
    ?>
    </td>
    <td>
    <?php print_string('auth_remove_user','auth') ?>
    </td>
</tr>

<?php

print_auth_lock_options('db', $user_fields, get_string('auth_dbextrafields', 'auth'), true, true);

?>
</table>
