<?php
    global $OUTPUT;
    // 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 = AUTH_REMOVEUSER_KEEP;
    }

    $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_db") ?></label></td>
    <td>
        <input id="host" name="host" type="text" class="text-ltr" size="30" value="<?php echo $config->host?>" />
        <?php

        if (isset($err["host"])) {
            echo $OUTPUT->error_text($err["host"]);
        }

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

<tr valign="top" class="required">
    <td align="right"><label for="menutype"><?php print_string("auth_dbtype_key", "auth_db") ?></label></td>
    <td>
    <?php  $dbtypes = array("access","ado_access", "ado", "ado_mssql", "borland_ibase", "csv", "db2", "fbsql", "firebird", "ibase", "informix72", "informix", "mssql", "mssql_n", "mssqlnative", "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;
       }
       echo html_writer::select($dboptions, "type", $config->type, false);
    ?>

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

<tr valign="top" class="required">
    <td align="right"><label for="menusybasequoting"><?php print_string("auth_dbsybasequoting", "auth_db") ?></label></td>
    <td>
        <?php echo html_writer::select($yesno, 'sybasequoting', $config->sybasequoting, false); ?>
    </td>
    <td><?php print_string("auth_dbsybasequotinghelp", "auth_db") ?></td>
</tr>

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

        if (isset($err["name"])) {
            echo $OUTPUT->error_text($err["name"]);
        }

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

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

        if (isset($err["user"])) {
            echo $OUTPUT->error_text($err["user"]);
        }

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

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

        if (isset($err["pass"])) {
            echo $OUTPUT->error_text($err["pass"]);
        }

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

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

        if (isset($err["table"])) {
            echo $OUTPUT->error_text($err["table"]);
        }

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

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

        if (isset($err["fielduser"])) {
            echo $OUTPUT->error_text($err["fielduser"]);
        }

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

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

        if (isset($err["fieldpass"])) {
            echo $OUTPUT->error_text($err["fieldpass"]);
        }

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

<tr valign="top" class="required">
    <td align="right"><label for="menupasstype"><?php print_string("auth_dbpasstype_key", "auth_db") ?></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["saltedcrypt"]      = get_string("auth_dbsaltedcrypt", "auth_db");
        $passtype["internal"]  = get_string("internal", "auth");
        echo html_writer::select($passtype, "passtype", $config->passtype, false);

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

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

        if (isset($err['extencoding'])) {
            echo $OUTPUT->error_text($err['extencoding']);
        }

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

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

<tr valign="top">
    <td align="right"><label for="menudebugauthdb"><?php print_string("auth_dbdebugauthdb", "auth_db") ?></label></td>
    <td>
        <?php echo html_writer::select($yesno, 'debugauthdb', $config->debugauthdb, false); ?>
    </td>
    <td><?php print_string("auth_dbdebugauthdbhelp", "auth_db") ?></td>
</tr>

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

        if (isset($err['changepasswordurl'])) {
            echo $OUTPUT->error_text($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[AUTH_REMOVEUSER_KEEP] = get_string('auth_remove_keep','auth');
       $deleteopt[AUTH_REMOVEUSER_SUSPEND] = get_string('auth_remove_suspend','auth');
       $deleteopt[AUTH_REMOVEUSER_FULLDELETE] = get_string('auth_remove_delete','auth');
       echo html_writer::select($deleteopt, 'removeuser', $config->removeuser, false);
    ?>
    </td>
    <td>
    <?php print_string('auth_remove_user','auth') ?>
    </td>
</tr>

<?php

print_auth_lock_options($this->authtype, $user_fields, get_string('auth_dbextrafields', 'auth_db'), true, true, $this->get_custom_user_profile_fields());

?>
</table>
