﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
	<xsl:import href="../Version_2_0/BoxKeyTemplate.xslt"/>
	<xsl:import href="TopMenuBar.xslt"/>

	<xsl:output method="xml" indent="yes"/>

	<xsl:template match="/">

		<xsl:variable name="LogOffURL" select="AjaxRequest/LogOffURL"></xsl:variable>
		<xsl:variable name="Settings" select="AjaxRequest/Settings/."></xsl:variable>
		<xsl:variable name="CustomXML" select="AjaxRequest/Settings/CustomXML"></xsl:variable>
		<xsl:variable name="BrandXml" select="AjaxRequest/UserBrands/."></xsl:variable>
		<xsl:variable name="MasterPortalItemID" select="normalize-space(AjaxRequest/Params/MBrandItemID)" />
		<xsl:variable name="PortalItemID" select="normalize-space(AjaxRequest/Params/ItemID)" />
		<xsl:variable name="Item" select="normalize-space(AjaxRequest/Params/Item)" />
		<xsl:variable name="ItemID" select="normalize-space(AjaxRequest/Params/ItemID)" />
		<xsl:variable name="ImageURL" select="normalize-space(AjaxRequest/Params/ImageURL)" />
		<xsl:variable name="PermissionID" select="normalize-space(AjaxRequest/PermissionID)"></xsl:variable>
		<xsl:variable name="HostName" select="normalize-space(AjaxRequest/HostName)"></xsl:variable>
		<xsl:variable name="IsSecureConnection" select="AjaxRequest/IsSecureConnection"></xsl:variable>
		<xsl:variable name="LoggedInUser" select="AjaxRequest/LoggedInUser/User/UserData"></xsl:variable>
		<xsl:variable name="TemplateURL" select="normalize-space(AjaxRequest/TemplateURL)"></xsl:variable>

		<xsl:variable name="PortalSpecific">
			<xsl:choose>
				<xsl:when test="AjaxRequest/Params/PortalSpecific[text()]">
					<xsl:value-of select="normalize-space(AjaxRequest/Params/PortalSpecific)"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:number value="0"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>

		<xsl:variable name="Protocol">
			<xsl:choose>
				<xsl:when test="$IsSecureConnection = 1">
					<xsl:text>https://</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>http://</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>

		<xsl:variable name="ClientManagerItemID">
			<xsl:choose>
				<xsl:when test="AjaxRequest/UserBrands/Brand[(PermissionID >= -2) 
                          and (ItemID = $MasterPortalItemID or ParentPortalItemID = $MasterPortalItemID)]/ItemID[text()]">
					<xsl:value-of select="AjaxRequest/UserBrands/Brand[(PermissionID >= -2) 
                                  and (ItemID = $MasterPortalItemID or ParentPortalItemID = $MasterPortalItemID)]/ItemID"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:number value="0"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>

		<xsl:variable name="PortalTopMenuBarXML" select="AjaxRequest/Settings/TabMenus/."></xsl:variable>

		<xsl:variable name="PortalTopMenuItems" select="/AjaxRequest/Settings/TabMenus/TabMenu/MenuItems/Version_3_0/MenuItem
															[
																@Default = 'true' 
																and @Active= '1'
																and (
																		($MasterPortalItemID = $PortalItemID and ScopeLevel/Level = 0)
																		or 
																		($MasterPortalItemID != $PortalItemID and ScopeLevel/Level = 1)
																	)
															]/."></xsl:variable>

		<xsl:variable name="UserTabs">
			<xsl:copy-of select="$CustomXML/Tabs_3_0/Tab
												[
													@Active= '1'
													and
													(SecurityLevel/Level = $PermissionID)
													and
													(
														(ScopeLevel/Level = 0 and $MasterPortalItemID = $PortalItemID) 
														or 
														(ScopeLevel/Level = 1 and $MasterPortalItemID != $PortalItemID)
													)
												]"/>
		</xsl:variable>

		<!-- header -->


		<!-- content -->
		<xsl:if test="$PortalSpecific = 0">
			<xsl:call-template name="TopMenuBar">
				<xsl:with-param name="Settings" select="$Settings"></xsl:with-param>
				<xsl:with-param name="BrandXml" select="$BrandXml"></xsl:with-param>
				<xsl:with-param name="CustomXML" select="$CustomXML"></xsl:with-param>
				<xsl:with-param name="LogOffURL" select="$LogOffURL"></xsl:with-param>
				<xsl:with-param name="Protocol" select="$Protocol"></xsl:with-param>
				<xsl:with-param name="HostName" select="$HostName"></xsl:with-param>
				<xsl:with-param name="MBrandItemID" select="$MasterPortalItemID"></xsl:with-param>
				<xsl:with-param name="ClientManagerItemID" select="$ClientManagerItemID"></xsl:with-param>
				<xsl:with-param name="LoggedInUser" select="$LoggedInUser"></xsl:with-param>
				<xsl:with-param name="MenuType">
					<xsl:text>Detail</xsl:text>
				</xsl:with-param>
			</xsl:call-template>
		</xsl:if>
		<div id="divDashboardLayout" class="container-fluid">
			<xsl:call-template name="ItemHeaderBox">
				<xsl:with-param name="Item" select="$Item"></xsl:with-param>
				<xsl:with-param name="PermissionID" select="$PermissionID"></xsl:with-param>
				<xsl:with-param name="MasterPortalItemID" select="$MasterPortalItemID"></xsl:with-param>
				<xsl:with-param name="PortalItemID" select="$PortalItemID"></xsl:with-param>
				<xsl:with-param name="ImageURL" select="$ImageURL"></xsl:with-param>
				<xsl:with-param name="LoggedInUser" select="$LoggedInUser"></xsl:with-param>
				<xsl:with-param name="UserTabs" select="msxsl:node-set($UserTabs)"></xsl:with-param>
				<xsl:with-param name="BrandXml" select="$BrandXml"></xsl:with-param>
				<xsl:with-param name="PortalSpecific" select="$PortalSpecific"></xsl:with-param>
				<xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
				<xsl:with-param name="Protocol" select="$Protocol"></xsl:with-param>
				<xsl:with-param name="HostName" select="$HostName"></xsl:with-param>
			</xsl:call-template>
			<div id="divExceptionSummary"></div>
			<img id="imgExceptionSummary"></img>
			<div id="divClientPortalOperations_Container" class="row bord bordX">

				<script language="javascript" type="text/javascript">
					LoadCommunityItem_3_0_Base('<xsl:value-of select="$MasterPortalItemID"></xsl:value-of>',' <xsl:value-of select="$ItemID"></xsl:value-of>', '<xsl:value-of select="$LoggedInUser"></xsl:value-of>');
				</script>
			</div>

		</div>
	</xsl:template>

	<xsl:template name="ItemHeaderBox">
		<xsl:param name="Item" select="'N/A'"></xsl:param>
		<xsl:param name="PermissionID" select="'N/A'"></xsl:param>
		<xsl:param name="MasterPortalItemID" select="'N/A'"></xsl:param>
		<xsl:param name="PortalItemID" select="'N/A'"></xsl:param>
		<xsl:param name="ImageURL" select="'N/A'"></xsl:param>
		<xsl:param name="LoggedInUser" select="'N/A'"></xsl:param>
		<xsl:param name="UserTabs" select="'N/A'"></xsl:param>
		<xsl:param name="BrandXml" select="'N/A'"></xsl:param>
		<xsl:param name="PortalSpecific" select="'N/A'"></xsl:param>
		<xsl:param name="TemplateURL" select="'N/A'"></xsl:param>
		<xsl:param name="Protocol" select="'N/A'"></xsl:param>
		<xsl:param name="HostName" select="'N/A'"></xsl:param>

		<div class="row bord">
			<div class="col-sm-12">
				<span class="NavOutr">
					<div class="bord_one" style="border:none;">
						<div class="col-sm-12 pading0">
							<nav class="navbar navbar-default">
								<div class="container-fluid pading0">
									<div class="navbar-header">
										<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
											<span class="icon-bar"></span>
											<span class="icon-bar"></span>
											<span class="icon-bar"></span>
										</button>
									</div>
									<div class="collapse navbar-collapse btm pading0" id="myNavbar">
										<ul class="nav navbar-nav pull-right">
											<div class="padded">
												<xsl:for-each select="$UserTabs/Tab
														[
															@Active= '1'
															and
															(SecurityLevel/Level = $PermissionID)
															and
															(
																(ScopeLevel/Level = 0 and $MasterPortalItemID = $PortalItemID) 
																or 
																(ScopeLevel/Level = 1 and $MasterPortalItemID != $PortalItemID)
															)
														]">

													<xsl:variable name="onClickFunction">
														<xsl:choose>
															<xsl:when test="$MasterPortalItemID = $PortalItemID">
																LoadDashboar_3_0(<xsl:value-of select="$MasterPortalItemID"/>
																, null, <xsl:value-of select="$LoggedInUser/UserID"/>, null
																, 'divClientPortalOperations_Container'
																, '<xsl:value-of select="TabName"/>', null, 1
																, '<xsl:value-of select="DashboardKey"/>'
																, '<xsl:value-of select="Layout"/>');
															</xsl:when>
															<xsl:when test="$MasterPortalItemID != $PortalItemID  
																	  and count($BrandXml/Brand) &gt; 1 
																	  and ($PortalSpecific = 0 or $PortalSpecific = 2)">
																LoadDashboar_3_0(<xsl:value-of select="$MasterPortalItemID"/>
																, null, <xsl:value-of select="$LoggedInUser/UserID"/>, null
																, 'divClientPortalOperations_Container'
																, '<xsl:value-of select="TabName"/>', null, 1
																, '<xsl:value-of select="DashboardKey"/>'
																, '<xsl:value-of select="Layout"/>');
															</xsl:when>
															<xsl:otherwise>
																LoadDashboar_3_0(<xsl:value-of select="$MasterPortalItemID"/>
																, <xsl:value-of select="$PortalItemID"></xsl:value-of>
																, <xsl:value-of select="$LoggedInUser/UserID"/>, null
																, 'divClientPortalOperations_Container'
																, '<xsl:value-of select="TabName"/>','PortalSpecific', 0
																, '<xsl:value-of select="DashboardKey"/>'
																, '<xsl:value-of select="Layout"/>');
															</xsl:otherwise>
														</xsl:choose>
													</xsl:variable>

													<button class="big-button" type="button" onClick="{$onClickFunction}">
														<i class="{Icon} icon-large"></i>
														<span class="button-text">
															<xsl:value-of select="DisplayName"/>
														</span>
													</button>

												</xsl:for-each>

											</div>
										</ul>
									</div>
								</div>
							</nav>
						</div>
					</div>
				</span>
				<span class="LefTitle mrginTp lftxt">
					<xsl:choose>
						<xsl:when test="count($BrandXml/Brand) &gt; 1">
							<span class="RitNav" id="spanDashBoardTitleImage">
								<xsl:if test="$PortalSpecific = 1">
									<xsl:choose>
										<xsl:when test="$ImageURL != ''">
											<img src="{$ImageURL}" class="img-responsive"></img>
										</xsl:when>
										<xsl:otherwise>
											<xsl:choose>
												<xsl:when test="$PermissionID &gt;= 4">
													<img id="img_UserImage_{$PortalItemID}"
														 src="{$TemplateURL}Web/Images/Ver_2_0/DefaultPortalPic.jpg"
														 onload="setWidthAndHeightImage(this, 150);"
														 onclick="ImageUploader_PopupCenter('{$Protocol}{$HostName}/upload/uploadimage.aspx?guid={$BrandXml/Brand[ItemID = $PortalItemID]/BrandKey}&amp;cropRatio=1&amp;requiredHeight=100&amp;requiredWidth=0&amp;requiredFileName=Logo&amp;Key=UploadPathBrand', 'Upload_Image','530','390','{$PortalItemID}','UploadBrandLogo','spanDashBoardTitleImage',null,0);"
														 style="display:none;border:0px;" align="absmiddle"
														 onmouseover="this.className='grayOut';document.getElementById('span_imageText').style.display ='block';"
														 onmouseout="this.setAttribute('class','');document.getElementById('span_imageText').style.display ='none';">
													</img>
												</xsl:when>
												<xsl:otherwise>
													<img id="img_UserImage_{$PortalItemID}"
														 src="{$TemplateURL}Web/Images/Ver_2_0/DefaultPortalPic.jpg"
														 onload="setWidthAndHeightImage(this, 150);"
														 style="display:none;border:0px;" align="absmiddle">
													</img>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:if>
							</span>
							<span class="HeadOut onMouseOver" id="spanDashBoardTitle"
								  onClick="document.getElementById('optDashboardMyPortal').style.display='block';document.getElementById('spanDashBoardTitle').style.display='none';document.getElementById('spanDashBoardTitleImage').style.display='none';">
								<span style="width:auto;float:left;">
									<h1 class="cor text-center" style="margin-top: 20px !important;">
										<xsl:choose>
											<xsl:when test="$PortalSpecific = 1">
												<xsl:value-of select="$Item"/>
											</xsl:when>
											<xsl:otherwise>
												<xsl:text>All Portals</xsl:text>
											</xsl:otherwise>
										</xsl:choose>
									</h1>
								</span>
								<span style="width:auto;float:left;height: 46px;line-height: 46px;margin-left: 10px;">
									<b class="caret"></b>
								</span>
							</span>
							<select class="form-control" id="optDashboardMyPortal" style="display:none;"
									onChange="LoadDashboard_3_0({$MasterPortalItemID}, 'optDashboardMyPortal', 'divDashboardLayoutContainer');">
								<option value="{$BrandXml/Brand/ItemID}">
									<xsl:text>All Portals</xsl:text>
								</option>
								<xsl:for-each select="$BrandXml/Brand[ItemID != $MasterPortalItemID]">
									<xsl:choose>
										<xsl:when test="ItemID = $PortalItemID and $PortalSpecific = 1">
											<option value="{ItemID}" selected="">
												<xsl:value-of select="Item"/>
											</option>
										</xsl:when>
										<xsl:otherwise>
											<option value="{ItemID}">
												<xsl:value-of select="Item"/>
											</option>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:for-each>
							</select>
						</xsl:when>
						<xsl:otherwise>
							<span class="RitNav" id="spanDashBoardTitleImage">
								<xsl:choose>
									<xsl:when test="$ImageURL != ''">
										<img src="{$ImageURL}" class="img-responsive"></img>
									</xsl:when>
									<xsl:otherwise>
										<xsl:choose>
											<xsl:when test="$PermissionID &gt;= 4">
												<img id="img_UserImage_{$PortalItemID}"
													 src="{$TemplateURL}Web/Images/Ver_2_0/DefaultPortalPic.jpg"
													 onload="setWidthAndHeightImage(this, 150);"
													 onclick="ImageUploader_PopupCenter('{$Protocol}{$HostName}/upload/uploadimage.aspx?guid={$BrandXml/Brand[ItemID = $PortalItemID]/BrandKey}&amp;cropRatio=1&amp;requiredHeight=100&amp;requiredWidth=0&amp;requiredFileName=Logo&amp;Key=UploadPathBrand', 'Upload_Image','530','390','{$PortalItemID}','UploadBrandLogo','spanDashBoardTitleImage',null,0);"
													 style="display:none;border:0px;" align="absmiddle"
													 onmouseover="this.className='grayOut';document.getElementById('span_imageText').style.display ='block';"
													 onmouseout="this.setAttribute('class','');document.getElementById('span_imageText').style.display ='none';">
												</img>
											</xsl:when>
											<xsl:otherwise>
												<img id="img_UserImage_{$PortalItemID}"
													 src="{$TemplateURL}Web/Images/Ver_2_0/DefaultPortalPic.jpg"
													 onload="setWidthAndHeightImage(this, 150);"
													 style="display:none;border:0px;" align="absmiddle">
												</img>
											</xsl:otherwise>
										</xsl:choose>
									</xsl:otherwise>
								</xsl:choose>
							</span>
							<span class="HeadOut">
								<h1 class="cor text-center">
									<xsl:value-of select="$Item"/>
								</h1>
							</span>
						</xsl:otherwise>
					</xsl:choose>

				</span>


			</div>
		</div>
	</xsl:template>

</xsl:stylesheet>