<?php

    global $CFG;

    // Set to defaults if undefined
    if (!isset($config->auth_instructions) or empty($config->user_attribute)) {
        $config->auth_instructions = get_string('auth_shib_instructions', 'auth_shibboleth', $CFG->wwwroot.'/auth/shibboleth/index.php');
    }
    if (!isset ($config->user_attribute)) {
        $config->user_attribute = '';
    }
    if (!isset ($config->convert_data)) {
        $config->convert_data = '';
    }
    if (!isset($config->changepasswordurl)) {
        $config->changepasswordurl = '';
    }

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

<tr valign="top" class="required">
    <td align="right"><?php print_string("username") ?>:</td>
    <td>
        <input name="user_attribute" type="text" size="30" value="<?php echo $config->user_attribute ?>" />
    </td>
    <td><?php print_string("auth_shib_username_description", "auth_shibboleth") ?></td>
</tr>

<tr valign="top">
    <td align="right"><?php print_string("auth_shib_convert_data", "auth_shibboleth") ?>:</td>
    <td>
        <input name="convert_data" type="text" size="30" value="<?php echo $config->convert_data?>" />
        <?php

        if ($config->convert_data and $config->convert_data != '' and !is_readable($config->convert_data)) {
              echo '<br/><span class="notifyproblem">';
              print_string("auth_shib_convert_data_warning", "auth_shibboleth");
              echo '</span>';
        }

        ?>
    </td>
    <td><?php print_string("auth_shib_convert_data_description", "auth_shibboleth"); echo $config->alt_login ?></td>
</tr>

<tr valign="top">
    <td align="right"><?php print_string("auth_shib_integrated_wayf", "auth_shibboleth") ?>:</td>
    <td>
        <input name="alt_login" type="checkbox" <?php
        if ( isset($config->alt_login) and $config->alt_login == 'on' ){
                echo 'checked="checked"';
            }
        ?> />
    </td>
    <td><?php print_string("auth_shib_integrated_wayf_description", "auth_shibboleth") ?></td>
</tr>

<tr valign="top">
    <td align="right"><?php print_string("auth_shib_idp_list", "auth_shibboleth") ?>:</td>
    <td>
        <textarea name="organization_selection" rows="10" cols="30" style="overflow: auto;"
><?php
        if (!isset($config->organization_selection)){
            echo  'urn:mace:organization1:providerID, Example Organization 1
https://another.idp-id.com/shibboleth, Other Example Organization, /Shibboleth.sso/DS/SWITCHaai
urn:mace:organization2:providerID, Example Organization 2, /Shibboleth.sso/WAYF/SWITCHaai';
        } else {
            echo htmlentities($config->organization_selection);
        }
        ?>
</textarea>
    <?php
       if (isset($config->organization_selection) && empty($config->organization_selection) && isset($config->alt_login) && $config->alt_login == 'on') {
              echo '<br/><span class="notifyproblem">';
              print_string("auth_shib_no_organizations_warning", "auth_shibboleth");
              echo '</span>';
        }
    ?>
    </td>
    <td><?php print_string("auth_shib_idp_list_description", "auth_shibboleth") ?></td>
</tr>

<tr valign="top">
    <td align="right"><?php print_string("auth_shib_logout_url", "auth_shibboleth") ?>:</td>
    <td>
        <input name="logout_handler" type="text" size="30" value="<?php
        if ( isset($config->logout_handler) and !empty($config->logout_handler)){
            echo $config->logout_handler;
        }
        ?>" />
    </td>
    <td><?php print_string("auth_shib_logout_url_description", "auth_shibboleth") ?></td>
</tr>

<tr valign="top">
    <td align="right"><?php print_string("auth_shib_logout_return_url", "auth_shibboleth") ?>:</td>
    <td>
        <input name="logout_return_url" type="text" size="30" value="<?php
        if ( isset($config->logout_return_url) and !empty($config->logout_return_url)){
            echo $config->logout_return_url;
        }
        ?>" />
    </td>
    <td><?php print_string("auth_shib_logout_return_url_description", "auth_shibboleth") ?></td>
</tr>

<tr valign="top">
    <td align="right"><?php print_string("auth_shib_auth_method", "auth_shibboleth") ?>:</td>
    <td>
        <input name="login_name" type="text" size="30" value="<?php
        if ( isset($config->login_name) and !empty($config->login_name)){
            echo htmlentities($config->login_name);
        } else {
            echo 'Shibboleth Login';
        }
        ?>" />
    </td>
    <td><?php print_string("auth_shib_auth_method_description", "auth_shibboleth") ?></td>
</tr>

<tr valign="top">
    <td align="right"><?php print_string('auth_shib_changepasswordurl', 'auth_shibboleth') ?>: </td>
    <td>
        <input name="changepasswordurl" type="text" 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>



<?php

print_auth_lock_options('shibboleth', $user_fields, '<!-- empty help -->', true, false);

?>
</table>
