<?php

    global $CFG;
    require_once 'languages.php';

    $createoptions[0] = get_string("no");
    $createoptions[1] = get_string("yes");

    // set to defaults if undefined
    if (!isset ($config->hostname)) {
        $config->hostname = '';
    }
    if (!isset ($config->port)) {
        $config->port = '';
    }
    if (!isset ($config->casversion)) {
        $config->casversion = '';
    }
    if (!isset ($config->baseuri)) {
        $config->baseuri = '';
    }
    if (!isset ($config->language)) {
        $config->language = '';
    }
    if (!isset ($config->use_cas)) {
        $config->use_cas = '';
    }
    if (!isset ($config->auth_user_create)) {
        $config->auth_user_create = '0';
    }
    if (!isset ($config->create_user)) {
        $config->create_user = '0';
    }
    if (!isset($config->changepasswordurl)) {
        $config->changepasswordurl = '';
    }

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

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

<tr valign="top"  class="required">
    <td align="right"><?php print_string('auth_cas_use_cas', 'auth') ?>:</td>
    <td>
        <?php

        unset($options);
        $options[1] = get_string('yes');
        choose_from_menu ($options, 'use_cas', $config->use_cas, get_string('no'), '', '');

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

<tr valign="top" class="required">
    <td align="right"><?php print_string('auth_cas_hostname_key', 'auth') ?>:</td>
    <td>
        <input name="hostname" type="text" size="30" value="<?php echo $config->hostname ?>" />
        <?php

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

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

<tr valign="top"  class="required">
    <td align="right"><?php print_string('auth_cas_baseuri_key', 'auth') ?>:</td>
    <td>
        <input name="baseuri" type="text" size="30" value="<?php echo $config->baseuri ?>" />
        <?php

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

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

<tr valign="top" class="required">
    <td align="right"><?php print_string('auth_cas_port_key', 'auth') ?>:</td>
    <td>
        <input name="port" type="text" size="30" value="<?php echo $config->port ?>" />
        <?php

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

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

<tr valign="top"  class="required">
    <td align="right"><?php print_string('auth_cas_casversion', 'auth') ?>:</td>
    <td>
        <input name="casversion" type="text" size="30" value="<?php echo $config->casversion ?>" />
        <?php

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

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

<tr valign="top"  class="required">
    <td align="right"><?php print_string('auth_cas_language_key', 'auth') ?>:</td>
    <td>
        <?php

        choose_from_menu($CASLANGUAGES, 'language', $config->language, '');

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

<tr valign="top">
    <td align="right"><?php print_string('auth_cas_auth_user_create', 'auth') ?>: </td>
    <td>
      <?php

        choose_from_menu($createoptions, 'auth_user_create', $config->auth_user_create, '');
        if (isset($err['auth_user_create'])) {
            formerr($err['auth_user_create']);
        }

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

<tr valign="top"  class="required">
    <td align="right"><?php print_string('auth_cas_create_user_key', 'auth') ?>:</td>
    <td>
        <?php

        unset($options);
        $options[0] = get_string('no');
        $options[1] = get_string('yes');
        choose_from_menu($options, 'create_user', $config->create_user, '');

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

<tr valign="top">
    <td align="right"><?php print_string('auth_cas_changepasswordurl', 'auth') ?>: </td>
    <td>
        <input 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>

</table>

<?php

    $ldapplugin = get_auth_plugin('ldap');
    $ldapplugin->config_form(get_config('auth/ldap'), $err);

?>
