<%@ page buffer="8kb" autoFlush="true" %>
<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="zm" uri="com.zimbra.zm" %>
<%@ taglib prefix="app" uri="com.zimbra.htmlclient" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="com.zimbra.i18n" %>

<app:handleError>

    <zm:getMailbox var="mailbox"/>
    ${zm:refreshPrefs(mailbox)}
    ${zm:clearApptSummaryCache(mailbox)}
    <c:choose>
        <c:when test="${not empty mailbox.prefs.locale}">
            <fmt:setLocale value='${mailbox.prefs.locale}' scope='request' />
        </c:when>
        <c:otherwise>
            <fmt:setLocale value='${pageContext.request.locale}' scope='request' />
        </c:otherwise>
    </c:choose>
    <c:remove var="skin" scope="session"/>
    <app:skin mailbox="${mailbox}"/>
    <fmt:setBundle basename="/messages/ZhMsg" scope='request'/>
    <fmt:message var="dateFormat" key="CAL_APPT_EDIT_DATE_FORMAT"/>

    <c:choose>
        <c:when test="${not empty param.tz}">
            <fmt:setTimeZone var="tz" value="${param.tz}" scope="request"/>
        </c:when>
        <c:otherwise>
            <c:set var="tz" value="${mailbox.prefs.timeZone}" scope="request"/>
        </c:otherwise>
    </c:choose>

    <c:choose>
        <c:when test="${not empty param.date}">
            <fmt:parseDate timeZone="${tz}" var="date" pattern="yyyyMMdd" value="${param.date}"/>
            <c:set scope="request" var="dateContext" value="${zm:getCalendarMidnight(date.time, tz)}"/>
        </c:when>
        <c:otherwise>
            <c:set scope="request" var="dateContext" value="${zm:getToday(tz)}"/>
        </c:otherwise>
    </c:choose>

    <c:set var="checkedCalendars" value="${param.l}"/>
    <c:set var="view" value="${param.view}"/>
    <c:if test="${param.view eq 'list'}">
        <c:if test="${not empty param.startDate}">
            <fmt:parseDate value="${param.startDate}" pattern="yyyyMMdd'T'HHmmss" var="start" timeZone="${tz}" />
            <c:set scope="request" var="startDateContext" value="${zm:getCalendar(start.time, tz)}"/>
        </c:if>
    </c:if>
    <c:if test="${not empty param.endDate}">
        <fmt:parseDate value="${param.endDate}" pattern="yyyyMMdd'T'HHmmss" var="end" timeZone="${tz}"/>
        <c:set scope="request" var="endDateContext" value="${zm:getCalendar(end.time, tz)}"/>
    </c:if>

</app:handleError>

<html>
<app:head mailbox="${mailbox}" print="true"/>
<body style='background:white;'>
<style type="text/css">
    .zPrintMsgs *{
        font-family:Tahoma,Arial,Helvetica,sans-serif;
        font-size:${mailbox.prefs.defaultPrintFontSize};
    }
     .zhcalmonthheadermonth, .zhcalmonthheadercellstext, .zhappcontent, .zhcalmonthtable, .zhcaldaygrid, .zhcalmonthheaderrow, .zhcaldayhour, .zhcaldayheader, .zhcaldayheadertoday{ background-color: white;}
    .ZhCalDayHeader{font-weight: bold; }
</style>
<table width="90%" align="center" class="zPrintMsgs">
    <tr>
        <td><b><fmt:message key="zimbraTitle"/></b></td>
        <td>
            <table cellpadding="2" cellspacing="2" >
                <tr>
                <c:forEach items="${checkedCalendars}" var="checkedcal" >
                        <c:set var="folder" value="${zm:getFolder(pageContext,checkedcal)}"/>
                        <fmt:message var="colorOrange" key="colorOrange"/>
                        <fmt:message var="colorMsg" key="${folder.rgbColorMsg}"/>
                        <td width="10px" height="10px" style="background-color:${zm:lightenColor(not empty folder.rgb ? folder.rgb : (fn:startsWith(colorMsg,"???") ? colorOrange : colorMsg))}">
                            &nbsp;
                        </td>
                        <td>
                        ${zm:getFolderName(pageContext,folder.id)}
                        </td>
                        <td>
                            &nbsp;&nbsp;
                        </td>
                </c:forEach>
                </tr>
            </table>

        </td>
        <td nowrap width='1%'><c:if test="${mailbox.name ne 'local@host.local'}">${fn:escapeXml(mailbox.name)}</c:if></td>
    </tr>
</table>
<hr/>
<app:handleError>
    <c:choose>
        <c:when test="${view eq 'day'}">
            <app:multiDayPrintView timezone="${tz}" date="${dateContext}" endDate="${not empty param.endDate ? endDateContext : ''}" view='${view}' ft='${param.ft}' tt='${param.tt}' checkedCalendars="${checkedCalendars}" numdays="${not empty param.numdays ? param.numdays : 1}"/>
        </c:when>
        <c:when test="${view eq 'workWeek'}">
            <app:multiDayPrintView timezone="${tz}" date="${dateContext}" endDate="${not empty param.endDate ? endDateContext : ''}" view='${view}' ft='${param.ft}' tt='${param.tt}' checkedCalendars="${checkedCalendars}" numdays="7"/>
        </c:when>
        <c:when test="${view eq 'week'}">
            <app:multiDayPrintView timezone="${tz}" date="${dateContext}" endDate="${not empty param.endDate ? endDateContext : ''}" view='${view}' ft='${param.ft}' tt='${param.tt}' checkedCalendars="${checkedCalendars}" numdays="7" wdays="${not empty param.wdays ? param.wdays : ''}"/>
        </c:when>
        <c:when test="${view eq 'schedule'}">
            <app:multiDayPrintView timezone="${tz}" date="${dateContext}" endDate="${not empty param.endDate ? endDateContext : ''}" ft='${param.ft}' tt='${param.tt}' checkedCalendars="${checkedCalendars}" view="${view}" numdays="1"/>
        </c:when>
        <c:when test="${view eq 'list'}">
            <app:multiDayPrintView timezone="${tz}" date="${not empty param.startDate ? startDateContext : dateContext}" endDate="${not empty param.endDate ? endDateContext : ''}" checkedCalendars="${checkedCalendars}" view="${view}" numdays="7"/>
        </c:when> 
        <c:otherwise>
            <app:monthPrintView timezone="${tz}" checkedCalendars="${checkedCalendars}" date="${dateContext}" endDate="${not empty param.endDate ? endDateContext : ''}" wdays="${not empty param.wdays ? param.wdays : ''}"/>
        </c:otherwise>
    </c:choose>
</app:handleError>
<script type="text/javascript">
    <!--
    //Bug 97582 - Print out of 1 hour meetings are displayed as 30 minute meeting
    //Set individual appointment height to their parent td height
    var apptsToResize = document.querySelectorAll('.js-resize');
    for(var i = 0, len = apptsToResize.length; i < len; i++){
        var td = apptsToResize[i];
        td.children[0].style.height = td.offsetHeight;
    }
    setTimeout('window.print()', 2000);

    // -->
</script>

</body>
</html>
