<%--
/*
 * ***** BEGIN LICENSE BLOCK *****
 * Zimbra Collaboration Suite Web Client
 * Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Synacor, Inc.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software Foundation,
 * version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 * ***** END LICENSE BLOCK *****
 */
--%>
<%@ 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: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: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:remove var="skin" scope="session"/>
    <app:skin mailbox="${mailbox}"/>
    <fmt:setBundle basename="/messages/ZhMsg" scope="request"/>

    <fmt:message var="title" key="zimbra"/>
</app:handleError>
<%--TODO: clean up this code --%>
<html>
<app:head mailbox="${mailbox}" print="true"/>
<body style='background:white;'>
<style type="text/css">
    .smalltext{
        font-size:8pt;
        color:#666;
    }
    .ZhCallListPrintView td, .zPrintMsgs *{
        font-family:Tahoma,Arial,Helvetica,sans-serif;
        font-size:${mailbox.prefs.defaultPrintFontSize};
    }
    .companyName{
        color: #555555 !important;
    }
    .sectionLabel{
        color: gray !important;
    }
</style>
<div class="ZhCallListPrintView">
<table><tr>
    <td><b><fmt:message key="zimbraTitle"/></b></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="taskIds" value="${fn:join(paramValues.id, ',')}"/>
<c:choose>
    <c:when test="${not empty taskIds}">
        <c:forEach items="${taskIds}" var="id" varStatus="status">
            <app:handleError>
                <zm:composeUploader var="uploader"/>
                <c:set var="compose" value="${uploader.compose}"/>
                
                <zm:getMessage var="message" id="${id}" markread="true" neuterimages="${empty param.xim}"/>
                <c:choose>
                    <c:when test="${empty compose}">
                        <zm:messageCompose var="compose" message="${message}" action="${empty message ? 'apptnew' : 'apptedit'}"
                                           date="${requestScope.dateContext}"
                                           inviteId="${param.id}"
                                           exceptionInviteId="${empty param.exInvId? null : param.exInvId}"
                                           useInstance="${param.useInstance eq '1'}"
                                           istask="${true}"
                                           instanceStartTime="${zm:nonNull(param.instStartTime)}"
                                           instanceDuration="${zm:nonNull(param.instDuration)}"/>
                    </c:when>
                    <c:when test="${uploader.isUpload and not empty message}">
                        <zm:fixupMessageCompose message="${message}" compose="${compose}" newattachments="${uploader.compose.hasFileItems}"/>
                    </c:when>
                </c:choose>

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


            <div class="zPrintMsgs" style="width: 100%;">
                <table cellpadding="2" cellspacing="0" width="100%">
                    <tr>
                        <td colspan="2">
                            <table cellpadding="2" cellspacing="0" width="100%">
                            <tr>
                                <td class="apptHeader">
                                    <b>${fn:escapeXml(compose.subject)}</b>
                                </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}"/>
                                                <c:set var="folderName" value="${zm:getFolderName(pageContext, message.folderId)}"/>
                                                <app:img alt='${folderName}' src="${folderImage}"/>
                                            </td>
                                            <td class="companyFolder">${folderName}</td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            </table>    
                        <hr>
                        </td>
                    </tr>
                    <tr>
                        <td class="MsgHdrName"><fmt:message key="location"/>:</td>
                        <td class="MsgHdrValue">${fn:escapeXml(compose.location)}</td>
                    </tr>
                    <tr>
                        <td class="MsgHdrName"><fmt:message key="priority"/>:</td>
                        <td class="MsgHdrValue">
                            <c:if test="${compose.taskPriority eq '9'}"><fmt:message key="taskPrioLow"/></c:if>
                            <c:if test="${compose.taskPriority eq '5'}"><fmt:message key="taskPrioNormal"/></c:if>
                            <c:if test="${compose.taskPriority eq '1'}"><fmt:message key="taskPrioHigh"/></c:if>
                        </td>
                    </tr>
                    <tr>
                        <td class="MsgHdrName"><fmt:message key="status" /> : </td>
                        <td nowrap class="MsgHdrValue">
                            <c:if test="${compose.taskStatus eq 'NEED'}"><fmt:message key="TASK_NEED"/></c:if>
                            <c:if test="${compose.taskStatus eq 'COMP'}"><fmt:message key="TASK_COMP"/></c:if>
                            <c:if test="${compose.taskStatus eq 'INPR'}"><fmt:message key="TASK_INPR"/></c:if>
                            <c:if test="${compose.taskStatus eq 'WAITING'}"><fmt:message key="TASK_WAITING"/></c:if>
                            <c:if test="${compose.taskStatus eq 'DEFERRED'}"><fmt:message key="TASK_DEFERRED"/></c:if>
                            &nbsp; ${compose.taskPercentComplete}%
                        </td>
                    </tr>
                    <c:set var="taskObj" value="${message.invite.component}"/>
                    <fmt:message var="tdtPattern" key="CAL_APPT_EDIT_DATE_FORMAT_HINT"/>
                    <c:if test="${not empty compose.startDate}">
                    <tr>
                        <td class="MsgHdrName"><fmt:message key="startDate"/>:</td>
                        <td class="MsgHdrValue">
                                <fmt:formatDate var="sDate" pattern="${tdtPattern}" value="${taskObj.start.date}"/>
                                ${fn:escapeXml(sDate)}
                        </td>

                    </tr>
                    </c:if>
                    <c:if test="${not empty compose.endDate}">
                    <tr>
                        <td class="MsgHdrName"><fmt:message key="taskDueDate"/>:</td>
                        <td class="MsgHdrValue">
                                <fmt:formatDate var="eDate" pattern="${tdtPattern}" value="${taskObj.end.date}"/>
                                ${fn:escapeXml(eDate)}
                        </td>
                    </tr>
                    </c:if>
                </table>
            </div>
            <hr/>
            <table cellpadding="2" cellspacing="0" width="100%"><tr><td>
                    <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="${message.invite.component.isNoBlob}">
                            <app:body message="${message}" body="${message.body}" theBody="${not empty compose.descriptionHtml ? compose.descriptionHtml : zm:cook(compose.description)}" mailbox="${mailbox}" isPrintView="${true}" counter="${status.index}"/>
                        </c:when>
                        <c:otherwise>
                            ${theBody}
                        </c:otherwise>
                    </c:choose>

                </td></tr>
            </table>
            <hr/>
        </c:forEach>
    </c:when>
    <c:otherwise>
        <app:handleError>
            <zm:computeSearchContext var="context" usecache="true"/>
        </app:handleError>
        <c:forEach items="${context.searchResult.hits}" var="hit" varStatus="status">
            <c:set var="taskHit" value="${hit.taskHit}"/>
            <c:set var="id" value="${taskHit.inviteId}" />
            <app:handleError>
                <zm:composeUploader var="uploader"/>
                <c:set var="compose" value="${uploader.compose}"/>

                <zm:getMessage var="message" id="${id}" markread="true" neuterimages="${empty param.xim}"/>
                <c:choose>
                    <c:when test="${empty compose}">
                        <zm:messageCompose var="compose" message="${message}" action="${empty message ? 'apptnew' : 'apptedit'}"
                                           date="${requestScope.dateContext}"
                                           inviteId="${param.id}"
                                           exceptionInviteId="${empty param.exInvId? null : param.exInvId}"
                                           useInstance="${param.useInstance eq '1'}"
                                           istask="${true}"
                                           instanceStartTime="${zm:nonNull(param.instStartTime)}"
                                           instanceDuration="${zm:nonNull(param.instDuration)}"/>
                    </c:when>
                    <c:when test="${uploader.isUpload and not empty message}">
                        <zm:fixupMessageCompose message="${message}" compose="${compose}" newattachments="${uploader.compose.hasFileItems}"/>
                    </c:when>
                </c:choose>
                <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>
            </app:handleError>

            <div class="zPrintMsgs" style="width: 100%;">
                <table cellpadding="2" cellspacing="0" width="100%">
                    <tr>
                        <td colspan="2">
                            <table cellpadding="2" cellspacing="0" width="100%">
                            <tr>
                                <td class="apptHeader">
                                    <b>${fn:escapeXml(compose.subject)}</b>
                                </td>
                                <td align="right" width="1%">
                                    <table border="0" cellpadding="2" cellspacing="2">
                                        <tr>
                                            <td class="companyName" width="100%">
                                                <c:set var="folder" value="${zm:getFolder(pageContext, message.folderId)}"/>
                                                <c:set var="folderImage" value="${not empty folder ? folder.image : ''}"/>
                                                <c:if test="${not empty folderImage}">
                                                     <app:img alt='${folderName}' src="${folderImage}"/>
                                                </c:if>
                                            </td>
                                            <td class="companyFolder">${not empty folder ? zm:getFolderName(pageContext,folder.id) : ''}</td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            </table>
                        <hr>
                        </td>
                    </tr>
                    <tr>
                        <td class="MsgHdrName"><fmt:message key="location"/>:</td>
                        <td class="MsgHdrValue">${fn:escapeXml(compose.location)}</td>
                    </tr>
                    <tr>
                        <td class="MsgHdrName"><fmt:message key="priority"/>:</td>
                        <td class="MsgHdrValue">
                            <c:if test="${compose.taskPriority eq '9'}"><fmt:message key="taskPrioLow"/></c:if>
                            <c:if test="${compose.taskPriority eq '5'}"><fmt:message key="taskPrioNormal"/></c:if>
                            <c:if test="${compose.taskPriority eq '1'}"><fmt:message key="taskPrioHigh"/></c:if>
                        </td>
                    </tr>
                    <tr>
                        <td class="MsgHdrName"><fmt:message key="status" /> : </td>
                        <td nowrap class="MsgHdrValue">
                            <c:if test="${compose.taskStatus eq 'NEED'}"><fmt:message key="TASK_NEED"/></c:if>
                            <c:if test="${compose.taskStatus eq 'COMP'}"><fmt:message key="TASK_COMP"/></c:if>
                            <c:if test="${compose.taskStatus eq 'INPR'}"><fmt:message key="TASK_INPR"/></c:if>
                            <c:if test="${compose.taskStatus eq 'WAITING'}"><fmt:message key="TASK_WAITING"/></c:if>
                            <c:if test="${compose.taskStatus eq 'DEFERRED'}"><fmt:message key="TASK_DEFERRED"/></c:if>
                            &nbsp; ${compose.taskPercentComplete}%
                        </td>
                    </tr>
                    <c:set var="taskObj" value="${message.invite.component}"/>
                    <fmt:message var="tdtPattern" key="CAL_APPT_EDIT_DATE_FORMAT_HINT"/>
                    <c:if test="${not empty compose.startDate}">
                    <tr>
                        <td class="MsgHdrName"><fmt:message key="startDate"/>:</td>
                        <td class="MsgHdrValue">
                                <fmt:formatDate var="sDate" pattern="${tdtPattern}" value="${taskObj.start.date}"/>
                                ${fn:escapeXml(sDate)}
                        </td>

                    </tr>
                    </c:if>
                    <c:if test="${not empty compose.endDate}">
                    <tr>
                        <td class="MsgHdrName"><fmt:message key="taskDueDate"/>:</td>
                        <td class="MsgHdrValue">
                                <fmt:formatDate var="eDate" pattern="${tdtPattern}" value="${taskObj.end.date}"/>
                                ${fn:escapeXml(eDate)}
                        </td>
                    </tr>
                    </c:if>
                </table>
            </div>
            <hr/>
            <table cellpadding="2" cellspacing="0" width="100%"><tr><td>
                   <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="${message.invite.component.isNoBlob}">
                            <app:body message="${message}" body="${message.body}" theBody="${not empty compose.descriptionHtml ? compose.descriptionHtml : zm:cook(compose.description)}" mailbox="${mailbox}" isPrintView="${true}" counter="${status.index}"/>
                        </c:when>
                        <c:otherwise>
                            ${theBody}
                        </c:otherwise>
                    </c:choose>
                </td></tr>
            </table>
            <hr/>
        </c:forEach>
    </c:otherwise>
</c:choose>
</div> 
<script type="text/javascript">
	<!--
	window.print();
	// -->
</script>
</body>
</html>
<%--
<c:set var="firstAttachment" value="${true}"/>
<c:if test="${!empty compose.messageAttachments}">
    <c:forEach var="ma" items="${compose.messageAttachments}" varStatus="status">
        <tr>
            <td align='right'>
                <c:if test="${firstAttachment}">
                    <app:img altkey="ALT_ATTACHMENT" src="startup/ImgAttachment.png"/>
                    <c:set var="firstAttachment" value="${false}"/>
                </c:if>
            </td>
            <td colspan=2>
                <c:choose>
                    <c:when test="${empty ma.subject}"><fmt:message var="subj" key="noSubject"/></c:when>
                    <c:otherwise><c:set var="subj" value="${zm:truncate(ma.subject,100,true)}"/></c:otherwise>
                </c:choose>
                    ${fn:escapeXml(subj)}
                <input type="hidden" name="messageAttachment" value="${ma.id}:${fn:escapeXml(ma.subject)}"/>
            </td>
        </tr>
    </c:forEach>
</c:if>
<c:if test="${!empty compose.originalAttachments}">
    <c:forEach var="part" items="${compose.originalAttachments}" varStatus="status">
        <tr class="CompOrigAtt" valign="middle">
            <td align='right'>
                <c:if test="${firstAttachment}">
                    <app:img altkey="ALT_ATTACHMENT" src="startup/ImgAttachment.png"/>
                    <c:set var="firstAttachment" value="${false}"/>
                </c:if>
            </td>
            <c:set var="url" value="/service/home/~/?id=${message.id}&part=${part.partName}&auth=co"/>
            <c:set var="pname" value="${part.displayName}"/>
            <c:if test="${empty pname}">
                <fmt:message key="unknownContentType" var="pname">
                    <fmt:param value="${part.contentType}"/>
                </fmt:message>
            </c:if>
            <td>
                <table cellpadding=0 cellspacing=0 border="0">
                    <tr valign="middle">
                        <td>
                            <a target="_blank" href="${url}&disp=i">${fn:escapeXml(pname)}</a>&nbsp;(${part.displaySize})
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </c:forEach>
</c:if>
--%>
