<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--  $Id$  -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:dyn="http://exslt.org/dynamic" extension-element-prefixes="dyn">
    <xsl:output method="html" indent="no" doctype-system="" encoding="utf-8" />

    <!-- This is really an RPS page: Use that global template -->
    <xsl:include href="/app/tools/rps/templates/global.xsl" />

    <xsl:include href="list.xsl" />
    <xsl:include href="edit.xsl" />
	<xsl:include href="show.xsl" />
	<xsl:include href="changepw.xsl" />
    <xsl:include href="import.xsl" />
    <xsl:include href="terms.xsl" />
    <xsl:include href="view_terms.xsl" />
    <xsl:include href="../passwordtoggle.xsl" />

	<xsl:template name="pickLayout">
        <xsl:choose>
            <xsl:when test="$cmd = 'edit' or $cmd = 'profile'">
                <div class="MainBaseSection">
                    <xsl:call-template name="userEntryLayout" />
                </div>
            </xsl:when>
            <xsl:when test="$cmd = 'show'">
                <div class="MainBaseSection">
                    <xsl:call-template name="userShowLayout" />
                </div>
            </xsl:when>
            <xsl:when test="$cmd = 'resetmfa'">
                <div class="MainBaseSection">
                    <xsl:call-template name="userMFAResetShowLayout" />
                </div>
            </xsl:when>
            <xsl:when test="$cmd = 'changepw'">
                <div class="MainBaseSection">
                    <xsl:call-template name="changePWLayout" />
                </div>
            </xsl:when>
            <xsl:when test="$cmd = 'import'">
                <div class="MainBaseSection">
                    <xsl:call-template name="userImportLayout" />
                </div>
            </xsl:when>
            <xsl:when test="$cmd = 'terms'">
                <div class="MainBaseSection">
                    <xsl:call-template name="termsLayout" />
                </div>
            </xsl:when>
            <xsl:when test="$cmd = 'view_terms'">
                <div class="MainBaseSection">
                    <xsl:call-template name="viewTermsLayout" />
                </div>
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="userSummaryLayout" />
            </xsl:otherwise>
        </xsl:choose>
	</xsl:template>

    <xsl:template name="submitButton">
        <xsl:choose>
            <xsl:when test="$cmd = 'edit' or $cmd = 'profile'">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="content">
                        <xsl:if test="normalize-space(Form/AppUser/UserID)">Update</xsl:if>
                        <xsl:if test="not(normalize-space(Form/AppUser/UserID))">Create</xsl:if>
                    </xsl:with-param>
                    <xsl:with-param name="name" select="'submit'" />
                    <xsl:with-param name="type" select="'primary'" />
                    <xsl:with-param name="elemType" select="'submit'" />
                    <xsl:with-param name="id" select="'submitButton'" />
                    <xsl:with-param name="className" select="'Form-button'" />
                    <xsl:with-param name="onClick">selectAllMulti('Form_AppUser_UserAccess_LabelID');</xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="$cmd = 'changepw'">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="type" select="'primary'" />
                    <xsl:with-param name="name" select="'submit'" />

                    <xsl:with-param name="elemType" select="'submit'" />

                    <xsl:with-param name="id" select="'submitButton'" />
                    <xsl:with-param name="content" select="'Update'" />
                    <xsl:with-param name="className" select="'Form-button'" />
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="$cmd = 'show' and Access/rps/user/edit = 1 and Form/AccessLevelList/AccessLevel[AccessLevelID = /Root/User/AccessLevel]/CanEditList/CanEdit[@id = /Root/Form/AppUser/AccessLevel] = 1">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="type" select="'primary'" />
                    <xsl:with-param name="name" select="'editButton'" />
                    <xsl:with-param name="content" select="'Edit'" />
                    <xsl:with-param name="className" select="'Form-button'" />
                    <xsl:with-param name="onClick">location.href='user?UserID=<xsl:value-of select="Form/AppUser/UserID" />&amp;c=edit'</xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="Messages/Message/Code = 'import_success'">
            </xsl:when>
            <xsl:when test="$cmd = 'import'">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="type" select="'primary'" />
                    <xsl:with-param name="name" select="'submit'" />
                    <xsl:with-param name="elemType" select="'submit'" />
                    <xsl:with-param name="id" select="'submitButton'" />
                    <xsl:with-param name="content" select="'Import'" />
                    <xsl:with-param name="className" select="'Form-button'" />
                    <xsl:with-param name="onClick">selectAllMulti('Form_UserAccess_LabelID');</xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="cancelButton">
        <xsl:choose>
            <xsl:when test="$cmd = 'profile'">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="type" select="'default'" />
                    <xsl:with-param name="name" select="'Cancel'" />
                    <xsl:with-param name="elemType" select="'button'" />
                    <xsl:with-param name="content" select="'Cancel'" />
                    <xsl:with-param name="className" select="'Form-button'" />
                    <xsl:with-param name="onClick">location.href='/'</xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="$cmd = 'edit' and normalize-space(Form/AppUser/UserID)">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="type" select="'default'" />
                    <xsl:with-param name="name" select="'Cancel'" />
                    <xsl:with-param name="elemType" select="'button'" />
                    <xsl:with-param name="content" select="'Return to User'" />
                    <xsl:with-param name="className" select="'Form-button'" />
                    <xsl:with-param name="onClick">location.href='user?UserID=<xsl:value-of select="Form/AppUser/UserID" />&amp;c=show'</xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="$area = 'login' and $cmd = 'changepw'">
<!-- suppress profile button if area = login and cmd = changepw -->
            </xsl:when>
            <!--xsl:when test="($area = 'user' and $cmd = 'changepw') or $cmd = 'view_terms'"-->
            <xsl:when test="$cmd = 'changepw' or $cmd = 'view_terms'">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="type" select="'default'" />
                    <xsl:with-param name="elemType" select="'button'" />
                    <xsl:with-param name="content" select="'Back to Profile'" />
                    <xsl:with-param name="className" select="'Form-button'" />
                    <xsl:with-param name="onClick">location.href='user?c=profile'</xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="$cmd = 'import' and Messages/Message/Code = 'email_found'">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="type" select="'default'" />
                    <xsl:with-param name="elemType" select="'button'" />
                    <xsl:with-param name="content" select="'Back to Import User'" />
                    <xsl:with-param name="className" select="'Form-button'" />
                    <xsl:with-param name="onClick">location.href='user?c=import'</xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="type" select="'default'" />
                    <xsl:with-param name="elemType" select="'button'" />
                    <xsl:with-param name="content" select="'Back to User List'" />
                    <xsl:with-param name="className" select="'Form-button'" />
                    <xsl:with-param name="onClick">location.href='user'</xsl:with-param>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

</xsl:stylesheet>

