<!--// $Id$ //-->

{if !isset($attachment_support_already_loaded)}
    <link href="css/templates/attachments.css" rel="stylesheet">
    <script src="js/templates/attachments.js"></script>
    {$attachment_support_already_loaded = true}
{/if}

<form name="upload-{$attachmenttype}" method="post" action="?m=attachments&type={$attachmenttype}&resourceid={$attachmentresourceid}" id="upload-form-{$attachmenttype}">
</form>

<form name="filecontainer-form-{$attachmenttype}" method="POST"
        action="?m=attachments&type={$attachmenttype}&resourceid={$attachmentresourceid}&attachmentaction=updatecontainer"
        id="filecontainer-form-{$attachmenttype}">
</form>

{tab_container id="attachmentbox-{$attachmenttype}"}
    {tab_header content_id="attachmentpanel-{$attachmenttype}"}
        {tab_header_cell icon="lms-ui-icon-fileupload"}
            <strong>{t a=$filecontainers[$attachmenttype].prefix b=$filecontainers[$attachmenttype].containers|size}$a ($b):{/t}</strong>
        {/tab_header_cell}
    {/tab_header}

    {tab_contents id="attachmentpanel-{$attachmenttype}"}
        {tab_table}
            {if $filecontainers[$attachmenttype].containers}
            <div class="lms-ui-tab-table-row header">
                <div class="lms-ui-tab-table-wrapper col-3">
                    <div class="lms-ui-tab-table-wrapper date-creator col-2">
                        <div class="lms-ui-tab-table-column bold date">
                            {trans("Creation date:")}
                        </div>
                        <div class="lms-ui-tab-table-column bold creator">
                            {trans("Creator:")}
                        </div>
                    </div>
                    <div class="lms-ui-tab-table-column bold description">
                        {trans("Description:")}
                    </div>
                </div>

                <div class="lms-ui-tab-table-column bold buttons">
                    {trans("Files:")}
                </div>
            </div>
            {/if}

            {$images = array()}
            {foreach $filecontainers[$attachmenttype].containers as $container}
            {$images = array_merge($images, $container.images)}
            <div class="lms-ui-tab-table-row" data-id="{$container.id}" data-attachmenttype="{$attachmenttype}">
                <div class="lms-ui-tab-table-wrapper col-3">
                    <div class="lms-ui-tab-table-wrapper date-creator col-2">
                        <div class="lms-ui-tab-table-column date">
                            {$container.creationdate|date_format:"Y/m/d H:i:s"}
                        </div>
                        <div class="lms-ui-tab-table-column creator">
                            <a href="?m=userinfo&id={$container.creatorid}">{$container.creatorname}</a>
                        </div>
                    </div>
                    <div class="lms-ui-tab-table-column description">
                        <span class="container-view lms-ui-autolinker">
                            {$container.description|default:"---"}
                        </span>
                        <span class="container-modify" style="display: none;">
                            <input type="text" value="{$container.description}">
                        </span>
                    </div>
                </div>

                <div class="lms-ui-tab-table-column buttons">
                    {if count($container.images)}
                        {button type="link" icon="gallery" class="container-gallery" tip="Attachment gallery"
                            data_gallery="{base64_encode(json_encode($container.images))}"}
                    {/if}
                    {button type="link" href="#" class="container-edit" icon="edit" tip="Edit"}
                    {button type="link" href="#" class="container-save" icon="save" tip="Save"}
                    {button type="link" href="#" class="container-cancel" icon="cancel" tip="Cancel"}
                    {button type="link" href="?m=attachments&attachmentaction=downloadzippedcontainer&type={$attachmenttype}&id={$container.id}"
                        icon="download" tip="Download file container as zip archive"}
                    {button class="container-del" type="link" href="?m=attachments&attachmentaction=deletecontainer&type={$attachmenttype}&id={$container.id}{if isset($restore)}&restore=1&resourceid={$attachmentresourceid}{/if}"
                        icon="delete" tip="Delete file container"}
                    <a href="#" class="toggle-file-list" data-container-id="{$container.id}" title="{trans("Show file list")}">
                        <img src="img/asc_order.gif">
                    </a>
                    <div id="files-{$container.id}" style="display: none;" class="files">
                        {foreach $container.files as $file}
                            {documentview
                                id="{$container.id}-{$file.id}"
                                type=$file.contenttype
                                name=$file.filename
                                url="?m=attachments&attachmentaction=viewfile&type={$attachmenttype}&id={$container.id}&fileid={$file.id}"
                                external=true
                            }
                            <br>
                        {/foreach}
                    </div>
                </div>
            </div>
            {foreachelse}
                <div class="lms-ui-tab-empty-table">
                    {trans("There are no file containers in database.")}
                </div>
            {/foreach}

            {tab_button_panel}
                {tab_buttons}
                    {trans("Description:")}
                    <input type="text" name="upload[description]" size="50" value="{$upload.description}" form="upload-form-{$attachmenttype}">
                    <input type="hidden" name="upload[attachmenttype]" value="{$attachmenttype}" form="upload-form-{$attachmenttype}">
                    {* $restore is used i.e for netdevicemodels to force backto *}
                    {if isset($restore)}
                        <input type="hidden" name="upload[restore]" value="{$restore}" form="upload-form-{$attachmenttype}">
                    {/if}
                    {fileupload id="files-{$attachmenttype}" fileupload=$fileupload form="upload-form-{$attachmenttype}"}
                    {button icon="add" class="container-add-button" label="Add" form="upload-form-{$attachmenttype}"}
                {/tab_buttons}
                {if count($images)}
                    {tab_buttons}
                        {button icon="gallery" class="container-gallery" label="Attachment gallery"
                            data_gallery="{base64_encode(json_encode($images))}"}
                    {/tab_buttons}
                {/if}
            {/tab_button_panel}

        {/tab_table}
    {/tab_contents}
{/tab_container}
