<%@ 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"/>
    <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>
    <fmt:setBundle basename="/messages/ZhMsg" scope="request"/>
    
    <fmt:message var="title" key="attachFiles"/>

    <c:set var="attachSize" value="${zm:displaySize(pageContext, mailbox.accountInfo.attachmentSizeLimit div mailbox.base64ToNormalRatio)}"/>
    
    <zm:composeUploader var="uploader"/>
    <c:set var="compose" value="${uploader.compose}"/>
</app:handleError>

<app:view mailbox="${mailbox}" title="${title}" selected='compose' folders="true" tags="true" searches="true" context="${null}" keys="false">

    <c:set var="toolbar">
        <table width=100% cellspacing=0>
            <tr valign='middle'>
                <td class='TbBt'>
                    <table cellspacing=0 cellpadding=0 class='Tb'>
                        <tr>
                            <app:button name="actionAttachDone" src="common/ImgCheck.png" tooltip="done" text="done"/>
                            <td><div class='vertSep'></div></td>
                            <app:button name="actionAttachCancel" src="common/ImgCancel.png" tooltip="cancel" text="cancel"/>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </c:set>

    <form action="" method="post" enctype="multipart/form-data" accept-charset="utf-8">
        <table width=100% cellpadding="0" cellspacing="0">
            <tr>
                <td class='TbTop'>
                    ${toolbar}
                </td>
            </tr>
            <tr>
                <td class='ZhAppContent'>
                        <table cellpadding=0 cellspacing=10 height=80% width=100% class='Compose'>
                            <tr>
                                <td align='right'><app:img altkey="ALT_ATTACHMENT" src="startup/ImgAttachment.png"/></td>
                                <td colspan=2><b><fmt:message key="selectFilesToAttach"/></b></td>
                            </tr>
                            <c:forEach begin="1" end="10" var="current">
                                <tr>
                                    <td align='right'>${current}.</td>
                                    <td colspan=2><input type=file size="40" name="fileUpload"></td>
                                </tr>
                            </c:forEach>
                            <tr>
                                <td>&nbsp;</td>
                                <td colspan="2"><b>
                                    <fmt:message key="attachmentLimitMsg">
                                        <fmt:param value="${attachSize}"/>
                                    </fmt:message>
                                    </b>
                                </td>
                            </tr>
                        </table>
                </td>
            </tr>
            <tr>
                <td class='TbBottom'>
                    ${toolbar}
                </td>
            </tr>
        </table>
        <input type="hidden" name="to" value="${fn:escapeXml(compose.to)}"/>
        <input type="hidden" name="sendUID" value="${fn:escapeXml(compose.sendUID)}"/>        
        <input type="hidden" name="cc" value="${fn:escapeXml(compose.cc)}"/>
        <input type="hidden" name="bcc" value="${fn:escapeXml(compose.bcc)}"/>
        <input type="hidden" name="subject" value="${fn:escapeXml(compose.subject)}"/>
        <c:forEach var="ma" items="${compose.messageAttachments}">
            <input type="hidden" name="messageAttachment" value="${ma.id}:${fn:escapeXml(ma.subject)}"/>
        </c:forEach>
        <c:forEach var="ca" items="${compose.checkedAttachmentNames}">
            <input type="hidden" name="originalAttachment" value="${fn:escapeXml(ca.key)}"/>
        </c:forEach>
        <c:set var="composeformat" value="${mailbox.prefs.composeFormat}" />
        <c:if test="${mailbox.prefs.forwardReplyInOriginalFormat && !empty param.rf && (param.rf eq 'html' || param.rf eq 'text')}">
            <c:set var="composeformat" value="${param.rf}"/>
        </c:if>
        <c:set var="isHtml" value="${composeformat eq 'html'}"/>
        <c:set var="theBody" value="${isHtml ? (empty compose.htmlContent ?  compose.content : compose.htmlContent) : compose.content}"/>
        <input type="hidden" name="body" value="${fn:escapeXml(theBody)}"/>
        <input type="hidden" name="replyto" value="${fn:escapeXml(compose.replyTo)}"/>
        <input type="hidden" name="from" value="${fn:escapeXml(compose.from)}"/>
        <input type="hidden" name="inreplyto" value="${fn:escapeXml(compose.inReplyTo)}"/>
        <input type="hidden" name="messageid" value="${fn:escapeXml(compose.messageId)}"/>
        <input type="hidden" name="replytype" value="${fn:escapeXml(compose.replyType)}"/>
        <input type="hidden" name="draftid" value="${fn:escapeXml(empty requestScope.draftid ? compose.draftId : requestScope.draftid)}"/>
        <input type="hidden" name="inviteReplyVerb" value="${fn:escapeXml(compose.inviteReplyVerb)}"/>
        <input type="hidden" name="inviteReplyInst" value="${fn:escapeXml(compose.inviteReplyInst)}"/>
        <input type="hidden" name="inviteReplyAllDay" value="${fn:escapeXml(compose.inviteReplyAllDay)}"/>        
        <input type="hidden" name="compNum" value="${fn:escapeXml(compose.compNum)}"/>
        <input type="hidden" name="instCompNum" value="${fn:escapeXml(compose.instanceCompNum)}"/>        
    </form>
</app:view>
