﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:import href="../GenericTemplates/AutoSuggestUsers.xslt"/>
    <xsl:import href="../ShareITDataList.xslt"/>
    <xsl:import href="BrandAutoSuggest.xslt"/>

    <xsl:template match="/">
        <xsl:variable name ="BrandID" select="normalize-space(BrandAdminCountData/BrandID)"></xsl:variable>
        <xsl:variable name ="CommunityBrandID" select="normalize-space(BrandAdminCountData/BrandCommunityID)"></xsl:variable>
        <xsl:variable name ="TemplateURL" select="normalize-space(BrandAdminCountData/TemplateURL)"></xsl:variable>
        <xsl:variable name="HostName" select="normalize-space(BrandAdminCountData/HostName)"></xsl:variable>
        <xsl:variable name ="BrandPermissionID" select="normalize-space(BrandAdminCountData/BrandPermissionID)"></xsl:variable>

        <xsl:variable name ="TodayVisits" select="normalize-space(BrandAdminCountData/Visits/Today/TotalTodayVisitors)"></xsl:variable>
        <xsl:variable name ="WeekVisits" select="normalize-space(BrandAdminCountData/Visits/Week/TotalWeekVisitors)"></xsl:variable>
        <xsl:variable name="MonthVisits" select="normalize-space(BrandAdminCountData/Visits/Month/TotalMonthVisitors)"></xsl:variable>

        <xsl:variable name ="TodayFollow" select="normalize-space(BrandAdminCountData/Follow/Today/TotalTodayFollow)"></xsl:variable>
        <xsl:variable name ="WeekFollow" select="normalize-space(BrandAdminCountData/Follow/Week/TotalWeekFollow)"></xsl:variable>
        <xsl:variable name="MonthFollow" select="normalize-space(BrandAdminCountData/Follow/Month/TotalMonthFollow)"></xsl:variable>

        <xsl:variable name="TotalPosts" select="normalize-space(BrandAdminCountData/PostsData/AllPosts/PostsCount)"></xsl:variable>
        <xsl:variable name="TotalDrafts" select="normalize-space(BrandAdminCountData/PostsData/AllPosts/Drafts)"></xsl:variable>

        <xsl:variable name="TotalVisits" select="normalize-space(BrandAdminCountData/Visits/All/TotalVisitors)"></xsl:variable>
        <xsl:variable name="TotalFollows" select="normalize-space(BrandAdminCountData/Follow/All/TotalFollowers)"></xsl:variable>

        <xsl:variable name ="TodayTemp" select="normalize-space(BrandAdminCountData/Templates/Today)"></xsl:variable>
        <xsl:variable name ="WeekTemp" select="normalize-space(BrandAdminCountData/Templates/ThisWeek)"></xsl:variable>
        <xsl:variable name="MonthTemp" select="normalize-space(BrandAdminCountData/Templates/ThisMonth)"></xsl:variable>
        <xsl:variable name ="AllTemp" select="normalize-space(BrandAdminCountData/Templates/Total)"></xsl:variable>

        <xsl:variable name ="TodayPubl" select="normalize-space(BrandAdminCountData/Publications/Today)"></xsl:variable>
        <xsl:variable name="WeekPubl" select="normalize-space(BrandAdminCountData/Publications/ThisWeek)"></xsl:variable>
        <xsl:variable name ="MonthPubl" select="normalize-space(BrandAdminCountData/Publications/ThisMonth)"></xsl:variable>
        <xsl:variable name ="AllPubl" select="normalize-space(BrandAdminCountData/Publications/Total)"></xsl:variable>

        <xsl:variable name="PortalTypeID" select="normalize-space(BrandAdminCountData/Brand/PortalTypeID)"></xsl:variable>
        <xsl:variable name="PortalType" select="normalize-space(BrandAdminCountData/Brand/PortalType)"></xsl:variable>
        <xsl:variable name="PortalItemID" select="normalize-space(BrandAdminCountData/Brand/PortalItemID)"></xsl:variable>


        <xsl:variable name="PostsText">
            <xsl:choose>
                <xsl:when test="$TotalPosts = 1">
                    <xsl:text>Post</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:text>Posts</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <xsl:variable name="DraftsText">
            <xsl:choose>
                <xsl:when test="$TotalDrafts = 1">
                    <xsl:text>Draft</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:text>Drafts</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <xsl:variable name ="IsCommunityAdmin" select="normalize-space(BrandAdminCountData/IsCommunityAdmin)"></xsl:variable>
        <xsl:variable name="RoleName" select="normalize-space(BrandAdminCountData/UserRoles/Role/RoleName)"></xsl:variable>

        <xsl:choose>
            <xsl:when test="$BrandPermissionID != 4 and count(BrandAdminCountData/UserRoles/Role[RoleName = 'Brand Admin']) = 0">
                <div class="labelError">
                    <span style="padding:5px;">You are not authorized to view this page.</span>
                </div>
            </xsl:when>
            <xsl:otherwise>
                <div id="divBrandAdmin" style="background-color:White;" >
                    <div style="height:25px;margin-left:15px;padding-top:15px;" width="50%" class="labelSize12">Statistics </div>
                    <center>
                        <table width="90%" cellpadding="3" cellspacing="3"
                             style="border:2px solid rgb(56, 93, 138);">
                            <tr>
                                <td width="50%" >
                                    <span class="labelSize12">
                                        <xsl:text>Visitors</xsl:text>
                                    </span>
                                </td>
                                <td width="50%" >
                                    <span class="labelSize12">
                                        <xsl:text>Followers</xsl:text>
                                    </span>
                                </td>
                            </tr>
                            <tr>
                                <td width="50%">
                                    <center>
                                        <table width="88%"  border="1" cellpadding="0" cellspacing="0">
                                            <tr>
                                                <td align="center" style="text-align:center;" width="22%">
                                                    <span class="labelSize10">
                                                        <xsl:text>Today</xsl:text>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;" width="22%">
                                                    <span class="labelSize10">
                                                        <xsl:text>This Week</xsl:text>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;" width="22%">
                                                    <span class="labelSize10">
                                                        <xsl:text>This Month</xsl:text>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;" width="22%">
                                                    <span class="labelSize10">
                                                        <xsl:text>All</xsl:text>
                                                    </span>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="center" style="text-align:center;">
                                                    <span class="labelSize10">
                                                        <xsl:value-of select ="$TodayVisits"/>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;">
                                                    <span class="labelSize10">
                                                        <xsl:value-of select ="$WeekVisits"/>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;">
                                                    <span class="labelSize10">
                                                        <xsl:value-of select ="$MonthVisits"/>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;">
                                                    <span class="labelSize10">
                                                        <xsl:value-of select ="$TotalVisits"/>
                                                    </span>
                                                </td>
                                            </tr>
                                        </table>
                                    </center>
                                </td>
                                <td width="50%">
                                    <center>
                                        <table width="88%"  border="1" cellpadding="0" cellspacing="0">
                                            <tr>
                                                <td align="center" style="text-align:center;" width="22%">
                                                    <span class="labelSize10">
                                                        <xsl:text>Today</xsl:text>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;" width="22%">
                                                    <span class="labelSize10">
                                                        <xsl:text>This Week</xsl:text>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;" width="22%">
                                                    <span class="labelSize10">
                                                        <xsl:text>This Month</xsl:text>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;" width="22%">
                                                    <span class="labelSize10">
                                                        <xsl:text>All</xsl:text>
                                                    </span>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="center" style="text-align:center;">
                                                    <span class="labelSize10">
                                                        <xsl:value-of select ="$TodayFollow"/>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;">
                                                    <span class="labelSize10">
                                                        <xsl:value-of select ="$WeekFollow"/>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;">
                                                    <span class="labelSize10">
                                                        <xsl:value-of select ="$MonthFollow"/>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;">
                                                    <span class="labelSize10">
                                                        <xsl:value-of select ="$TotalFollows"/>
                                                    </span>
                                                </td>
                                            </tr>
                                        </table>
                                    </center>
                                </td>
                            </tr>
                            <tr style="padding-top:15px;">
                                <td width="50%" >
                                    <span class="labelSize12">
                                        <xsl:text>Publications</xsl:text>
                                    </span>
                                </td>
                                <td width="50%" >
                                    <span class="labelSize12">
                                        <xsl:text>Templates</xsl:text>
                                    </span>
                                </td>
                            </tr>
                            <tr>
                                <td width="50%">
                                    <center>
                                        <table width="88%"  border="1" cellpadding="0" cellspacing="0">
                                            <tr>
                                                <td align="center" style="text-align:center;" width="22%">
                                                    <span class="labelSize10">
                                                        <xsl:text>Today</xsl:text>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;" width="22%">
                                                    <span class="labelSize10">
                                                        <xsl:text>This Week</xsl:text>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;" width="22%">
                                                    <span class="labelSize10">
                                                        <xsl:text>This Month</xsl:text>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;" width="22%">
                                                    <span class="labelSize10">
                                                        <xsl:text>All</xsl:text>
                                                    </span>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="center" style="text-align:center;">
                                                    <span class="labelSize10">
                                                        <xsl:value-of select ="$TodayPubl"/>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;">
                                                    <span class="labelSize10">
                                                        <xsl:value-of select ="$WeekPubl"/>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;">
                                                    <span class="labelSize10">
                                                        <xsl:value-of select ="$MonthPubl"/>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;">
                                                    <span class="labelSize10">
                                                        <xsl:value-of select ="$AllPubl"/>
                                                    </span>
                                                </td>
                                            </tr>
                                        </table>
                                    </center>
                                </td>
                                <td width="50%">
                                    <center>
                                        <table width="88%"  border="1" cellpadding="0" cellspacing="0">
                                            <tr>
                                                <td align="center" style="text-align:center;" width="22%">
                                                    <span class="labelSize10">
                                                        <xsl:text>Today</xsl:text>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;" width="22%">
                                                    <span class="labelSize10">
                                                        <xsl:text>This Week</xsl:text>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;" width="22%">
                                                    <span class="labelSize10">
                                                        <xsl:text>This Month</xsl:text>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;" width="22%">
                                                    <span class="labelSize10">
                                                        <xsl:text>All</xsl:text>
                                                    </span>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="center" style="text-align:center;">
                                                    <span class="labelSize10">
                                                        <xsl:value-of select ="$TodayTemp"/>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;">
                                                    <span class="labelSize10">
                                                        <xsl:value-of select ="$WeekTemp"/>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;">
                                                    <span class="labelSize10">
                                                        <xsl:value-of select ="$MonthTemp"/>
                                                    </span>
                                                </td>
                                                <td align="center" style="text-align:center;">
                                                    <span class="labelSize10">
                                                        <xsl:value-of select ="$AllTemp"/>
                                                    </span>
                                                </td>
                                            </tr>
                                        </table>
                                    </center>
                                </td>
                            </tr>
                        </table>
                    </center>
                    <div style="height:25px;margin-left:15px;padding-top:20px;" width="50%" class="labelSize12">Admin</div>
                    <center>
                        <table cellpadding="5" cellspacing="5" width="90%" style="border:2px solid rgb(56, 93, 138);">                           
                            <tr>
                                <td>
                                    <div id="div_EditBrandInfo" style="display:inline;margin-top:15px;">
                                        <xsl:choose>
                                            <xsl:when test="$PortalTypeID = 1">
                                                <a class="link" href="http://{$HostName}/CreateCoach.aspx?ID={$BrandID}"
                                                       onmouseover="this.style.textDecoration='underline';"
                                                       onmouseout="this.style.textDecoration='none';">
                                                    Edit Coach Info
                                                </a>
                                            </xsl:when>
                                            <xsl:when test="$PortalTypeID = 4">
                                                <a class="link" href="http://{$HostName}/CreateCorporate.aspx?ID={$BrandID}"
                                                       onmouseover="this.style.textDecoration='underline';"
                                                       onmouseout="this.style.textDecoration='none';">
                                                    Edit Corporate Info
                                                </a>
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <a class="link" href="http://{$HostName}/CreateBrand.aspx?ID={$BrandID}"
                                                        onmouseover="this.style.textDecoration='underline';"
                                                        onmouseout="this.style.textDecoration='none';">
                                                    Edit Brand Info
                                                </a>
                                            </xsl:otherwise>
                                        </xsl:choose>

                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <div id="div_ShowAllPostsLink" style="display: inline; margin-top: 15px;">
                                        <a class="link" onClick="brand_ViewAllPosts(
                                                                '{$BrandID}', '-99', 'divBrandAdmin');"
                                           onmouseover="this.style.textDecoration='underline';"
                                           onmouseout="this.style.textDecoration='none';">
                                            View All Posts
                                            &#xa0;
                                            (<xsl:value-of select ="$TotalPosts"/>&#xa0;<xsl:value-of select ="$PostsText"/>,
                                            &#xa0;
                                            <xsl:value-of select ="$TotalDrafts"/>&#xa0;<xsl:value-of select ="$DraftsText"/>)
                                        </a>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <div id="div_ShowAllPostsLink" style="display: inline; margin-top: 15px;">
                                        <a class="link" target="_blank" href="http://{$HostName}/ClientPortal.aspx?ID={$PortalItemID}"
                                           onmouseover="this.style.textDecoration='underline';"
                                           onmouseout="this.style.textDecoration='none';">
                                            Open My Portal
                                        </a>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </center>
                    <div id="brandShareIt" >
                        <div style="height:25px;margin-left:15px;padding-top:20px;" width="50%" class="labelSize12">Security</div>
                        <center>
                            <table cellpadding="5" cellspacing="5" width="90%" style="border:2px solid rgb(56, 93, 138);">
                                <tr>
                                    <td>
                                        <div id="div_shareIt_{$BrandID}" style="margin-top: 10px;">
                                            <div id="div_shareIt_{$BrandID}_ListShareITData" class="tableLocal" style="margin-left: 10px;">
                                                <xsl:call-template name="ShareItDataList">
                                                    <xsl:with-param name="ShareITRecords" select="BrandAdminCountData/ShareITRecords/."></xsl:with-param>
                                                    <xsl:with-param name="SourceID" select="BrandAdminCountData/ShareITRecords/SourceID"></xsl:with-param>
                                                    <xsl:with-param name="Origin" select="BrandAdminCountData/ShareITRecords/Origin"></xsl:with-param>
                                                </xsl:call-template>
                                            </div>

                                            <xsl:call-template name="BrandAutoSuggest">
                                                <xsl:with-param name="BrandID" select="$BrandID"></xsl:with-param>
                                                <xsl:with-param name="TargetDivID">
                                                    <xsl:text>div_shareIt_</xsl:text>
                                                    <xsl:value-of select="$BrandID"/>
                                                </xsl:with-param>
                                                <xsl:with-param name="Origin">
                                                    <xsl:text>BrandShareIt</xsl:text>
                                                </xsl:with-param>
                                            </xsl:call-template>
                                        </div>
                                    </td>
                                </tr>
                            </table >
                        </center>
                    </div>


                    <div style="height:25px;padding-top:20px;margin-left:15px;" width="50%" class="labelSize12">Custom Styles</div>
                    <table style="border:2px solid rgb(56, 93, 138);margin-left:35px;margin-bottom:20px;" cellpadding="3" cellspacing="3">
                        <xsl:for-each select="BrandAdminCountData/DynamicCSS/CSS">
                            <tr>
                                <td>
                                    <span class="label">
                                        <xsl:value-of select="DisplayName"/>
                                    </span>
                                </td>
                                <td>
                                    <input  id="dynamicClass_{BrandCustomStyleID}" type="text" value="{Color}" style="width:70px; margin-right:10px;"
                                            onblur="BrandDetail_UpdateDynamicCSS('{$BrandID}' ,'{ClassName}', 'dynamicClass_{BrandCustomStyleID}','{DisplayName}', '{BaseStyle}');"></input>
                                    <xsl:variable name="classss" >
                                        <xsl:text>color {valueElement:'dynamicClass_</xsl:text>
                                        <xsl:value-of  select="BrandCustomStyleID"/>
                                        <xsl:text>'}</xsl:text>
                                    </xsl:variable>
                                    <input class="{$classss}" style="width:20px;"
                                           onblur="BrandDetail_UpdateDynamicCSS('{$BrandID}' ,'{ClassName}', 'dynamicClass_{BrandCustomStyleID}','{DisplayName}', '{BaseStyle}');"></input>
                                </td>
                            </tr>
                        </xsl:for-each>
                        <tr>
                            <td colspan="2" style="text-align:center;">
                                <input type="button" class="button" value="Restore Defaults" style="margin-top:10px;"
                                       onclick="BrandDetail_RestoreDefaultCSS('{$BrandID}');"></input>
                            </td>
                        </tr>
                    </table>
                </div>


            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>
