<%@ 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:clearMessageCache(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:setBundle basename='/messages/TzMsg' var='TzMsg' scope='request' />

    <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>
</app:handleError>

<html>
<app:head mailbox="${mailbox}" print="true"/>
<body style='background:white;'>
<c:set var="zd" value="${not empty param.zd}" />
<table width="90%" align="center">
    <tr>
        <td class='ZhZimbraTitle'><fmt:message key="zimbraTitle"/></td>
        <c:set var="mailboxName" value="${(not empty param.acct ? param.acct : mailbox.name)}" />
        <td nowrap width='1%'><c:if test="${mailboxName ne 'local@host.local'}"><b>${fn:escapeXml(mailboxName)}</b></c:if></td>
    </tr>
</table>
<hr/>
<c:set var="apptIds" value="${fn:join(paramValues.id, ',')}"/>
<c:forEach items="${apptIds}" var="id" varStatus="status">
<app:handleError>
    <zm:getMessage var="msg" id="${id}" markread="true" neuterimages="1"/>
    <c:set var="invite" value="${msg.invite}"/>
    <c:set var="readOnly" value="${true}"/>

</app:handleError>


<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>

<zm:currentResultUrl var="extImageUrl" value="search" action="view" context="${context}" xim="1"/>

<%--
<zm:currentResultUrl var="composeUrl" value="search" context="${context}"
action="compose" paction="view" id="${msg.id}"/>
--%>
<app:calendarUrl var="composeUrl" id="${id}" action="compose" paction="view" apptFromParam="${true}" inviteReplyInst=""  inviteReplyAllDay="${invite.component.allDay ? '1' : ''}"/>
<%-- <zm:currentResultUrl var="newWindowUrl" value="message" context="${context}" id="${msg.id}"/> --%>

<c:set var="message" value="${msg}" />
<c:set var="showInviteReply" value="${not readOnly}" />
<c:set var="externalImageUrl" value="${extImageUrl}" />


<%--compute body up front, so attachments refereneced in multipart/related don't show up --%>
<c:set var="body" value="${message.body}"/>
<c:set var="theBody">
    <c:if test="${body.isTextHtml or body.isTextPlain}">
        ${zm:getPartHtmlContent(body, message)}
    </c:if>
</c:set>

<c:set var="appt" value="${invite.component}"/>
<c:catch>
    <c:set var="myAttendee" value="${zm:getMyAttendee(invite, mailbox)}"/>
    <c:set var="pstat" value="${not empty param.pstat ? zm:cook(param.pstat) : not empty myAttendee ? myAttendee.participantStatus : ''}"/>
</c:catch>
<fmt:message var="noSubject" key="noSubject"/>

<c:set var="isPart" value="${!empty message.partName}"/>
<table width="100%" cellspacing="0" cellpadding="0">
    <tr>
        <td>
            <table border="0" cellpadding="2" cellspacing="2">
                <tr>
                    <td width="24"><app:img src="${appt.exception or not empty appt.recurrence ? 'calendar/ImgApptRecur.png' : 'startup/ImgAppointment.png'}" alt="appointment"/></td>
                    <td class='apptHeader'>
                        ${fn:escapeXml(empty appt.name ? noSubject : appt.name)}
                    </td>
                </tr>
            </table>
        </td>
        <td align="right" width="1%">
            <table border="0" cellpadding="2" cellspacing="2">
                <tr>
                    <td class="companyName" width="100%">
                        <c:set var="folderImage" value="${zm:getFolder(pageContext, message.folderId).image}"/>
                        <app:img altkey='ALT_CONTACT_FOLDER' src="${folderImage}"/>
                    </td>
                    <td class="companyFolder">${zm:getFolderName(pageContext, message.folderId)}</td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<hr/>
<table width="100%" cellpadding="5" cellspacing="0" border="0">
<tr>
    <td class='MsgHdrName'>
        <fmt:message key="subject"/>
        :
    </td>
    <td class='MsgHdrValue'>${fn:escapeXml(empty appt.name ? noSubject : appt.name)}</td>
</tr>
<c:if test="${not empty appt.location}">
    <tr>
        <td class='MsgHdrName'>
            <fmt:message key="location"/>
            :
        </td>
        <td class='MsgHdrValue'>${fn:escapeXml(appt.location)}</td>
    </tr>
</c:if>
<tr>
    <td class='MsgHdrName'>
        <fmt:message key="date"/>
        :
    </td>
    <td class='MsgHdrValue'>

        <c:choose>
            <c:when test="${param.useInstance eq '1' and (not empty param.instStartTime and not empty param.instDuration)}">
                <c:set var="startDateCal" value="${zm:getCalendar(param.instStartTime, tz)}"/>
                <c:set var="endDateCal" value="${zm:getCalendar(param.instStartTime + param.instDuration, tz)}"/>
                <c:set var="startDate" value="${startDateCal.time}"/>
                <c:set var="endDate" value="${endDateCal.time}"/>
            </c:when>
            <c:otherwise>
                <c:set var="startDate" value="${appt.start.date}"/>
                <c:set var="endDate" value="${appt.computedEndDate}"/>
                <c:set var="startDateCal" value="${zm:getCalendar(startDate.time, tz)}"/>
                <c:set var="endDateCal" value="${zm:getCalendar(endDate.time, tz)}"/>
            </c:otherwise>
        </c:choose>
        <fmt:message key="ZM_formatPrintApptDate" var="formatPrintApptDate"/>
        <fmt:message key="ZM_formatPrintApptTime" var="formatPrintApptTime"/>
        <c:choose>
            <c:when test="${formatPrintApptDate eq '???ZM_formatPrintApptDate???' or formatPrintApptTime eq '???ZM_formatPrintApptTime???'}">
                ${fn:escapeXml(zm:getApptDateBlurb(pageContext, tz, startDate.time, endDate.time, appt.allDay))}
            </c:when>
            <c:otherwise>
                ${fn:escapeXml(zm:getApptDateBlurbWithTemplate(pageContext, tz, startDate.time, endDate.time, appt.allDay, "ZM_formatPrintApptDate", "ZM_formatPrintApptTime"))}
            </c:otherwise>
        </c:choose>
        &nbsp;
        <span class='ZhCalTimeZone'>
        <fmt:message var="displayName" bundle='${TzMsg}' key="${tz.ID}"/>
        ${fn:escapeXml(displayName)}
        </span>
    </td>
</tr>
<c:if test="${appt.exception}">
    <tr>
        <td class='MsgHdrName'>
            &nbsp;
        </td>
        <td class='MgrHdrValue'>
            <table cellpadding="0" cellspacing="0">
                <tr>
                    <td width="24" class='ImgApptExceptionIndicator'></td>
                    <td><b><fmt:message key="apptExceptionNote"/></b></td>
                </tr>
            </table>
        </td>
    </tr>
</c:if>
<c:if test="${not empty appt.organizer}">
    <tr>
        <td class='MsgHdrName'>
            <fmt:message key="organizer"/>
            :
        </td>
        <td class='MsgHdrValue'>
                ${fn:escapeXml(appt.organizer.emailAddress.fullAddress)}
        </td>
    </tr>
</c:if>

<c:if test="${not empty appt.attendees}">
    <tr>
        <td class='MsgHdrName'>
            <fmt:message key="attendees"/>
            :
        </td>
        <td class='MsgHdrValue'>
            <c:forEach var="attendee" items="${appt.attendees}" varStatus="status">
                <c:if test="${not status.first}">, </c:if>
                ${fn:escapeXml(attendee.emailAddress.fullAddress)}
            </c:forEach>
        </td>
    </tr>
</c:if>
<c:set var="repeat" value="${appt.simpleRecurrence}"/>
<c:if test="${not repeat.type.none}">
    <tr>
        <td class='MsgHdrName'>
            <fmt:message key="repeats"/>
            :
        </td>
        <td class='MsgHdrValue'>
            <fmt:message key="ZM_formatPrintApptRecurDate" var="formatPrintApptRecurDate"/>
            <c:choose>
                <c:when test="${formatPrintApptRecurDate eq '???ZM_formatPrintApptRecurDate???'}">
                    ${fn:escapeXml(zm:getRepeatBlurb(repeat, pageContext, tz, appt.start.date))}
                </c:when>
                <c:otherwise>
                    ${fn:escapeXml(zm:getRepeatBlurbWithTemplate(repeat, pageContext, tz, appt.start.date, "ZM_formatPrintApptRecurDate"))}
                </c:otherwise>
            </c:choose>
        </td>
    </tr>
</c:if>
<c:if test="${not empty pstat}">
    <tr>
        <td class='MsgHdrName'>
            <fmt:message key="status"/>
            :
        </td>
        <td class='MsgHdrValue'>
            <fmt:message key="apptPtst${pstat}"/>
        </td>
    </tr>
</c:if>
</table>
<hr/>
</td>
</tr>
<tr>
    <td id="iframeBody_apptContent" style="padding:10px;" >
        <c:choose>
            <c:when test="${zm:boolean(body.isTextHtml)}">
                <c:url var="iframeUrl" value="/h/imessage">
                    <c:param name="id" value="${message.id}"/>
                    <c:param name="part" value="${message.partName}"/>
                    <c:param name="xim" value="${true}"/>
                </c:url>
                <app:body message="${message}" body="${message.body}" theBody="${theBody}" mailbox="${mailbox}" isPrintView="${true}" counter="${status.index}"/>
            </c:when>
            <c:when test="${appt.isNoBlob}">
                <app:body message="${message}" body="${message.body}" theBody="${not empty appt.descriptionHtml ? appt.descriptionHtml : zm:textToHtml(appt.description)}" mailbox="${mailbox}" isPrintView="${true}" counter="${status.index}"/>
            </c:when>
            <c:otherwise>
                ${theBody}
            </c:otherwise>
        </c:choose>
        <c:if test="${not empty message.attachments}">
            <hr/>
            <app:attachments mailbox="${mailbox}" message="${message}" print="${true}" composeUrl="${composeUrl}"/>
        </c:if>
    </td>
</tr>
<tr>
    <td>
        <hr/>
    </td>
</tr>
</table>
</c:forEach>

<br/>
<br/>
<script type="text/javascript">
    <!--
    window.print();
    // -->
</script>

</body>
</html>









