<table class="col2btn">
    {if !$correspondence->is_valid}
        <tr>
            <td>{$i.correspondence_is_valid}</td>
            <td>{boolview value=$correspondence->is_valid}</td>
        </tr>
    {/if}
    {if $correspondence->security<3}
        <tr>
            <td>{$i.correspondence_security}</td>
            <td>
                {security value=$correspondence->security add_title=true} 
                {if !$correspondence->security_zip && $corr_type neq 'html'}(X2 Security){/if}
            </td>
        </tr>
    {/if}
    <tr><!-- Required -->
        <td>{$i.correspondence_project}</td>
        <td>{$correspondence->project}</td>
    </tr>
    <tr><!-- Required -->
        <td>{$i.correspondence_subject}</td>
        <td>{$correspondence->subject}</td>
    </tr>    
    <tr><!-- Required -->
        {if $correspondence->correspondence_type_name eq null}
            <td colspan="2">
                <div class="warning warningborder ui-corner-all">
                    <h4 style="color:red">{$i.correspondence_no_type1}</h4>
                    {$i.correspondence_no_type2}
                </div>
            </td>
        {else}
            <td>{$i.correspondence_type}</td>
            <td>
                {$correspondence->correspondence_type_name}
            </td>
        {/if}
    </tr>   
    <tr><!-- Required -->
        <td>{$i.correspondence_date}</td>
        <td>{$correspondence->date->us_date()}</td>
    </tr>     
    <tr><!-- Required -->
        <td>{$i.correspondence_receiver}</td>
        <td>
            <a class="smallbtns"
                href="{site_url url="start/open/addressesandcontacts/index/$xjxcookie/view/{$correspondence->address_id}/"}"
                onclick="usComm.loadPage('addressesandcontacts','index', 'view', {$correspondence->address_id}); return false;"
                title="{$correspondence->address_email|escape:'html'}"
                >{$correspondence->address_name|truncate:80:"..."}</a>        
        </td>
    </tr> 
    <tr><!-- Required -->
        <td>{$i.correspondence_staff}</td>
        <td>{$correspondence->staff_name}</td>
    </tr>
    {if $correspondence->is_serial}
        <tr>
            <td>{$i.correspondence_is_serial2}</td>
            <td>{boolview value=$correspondence->is_serial}</td>
        </tr>
    {/if}
    <tr><!-- Required -->
        <td>{$i.correspondence_file}</td>
        <td>
            {if $action_change_security_mode!==false}<!-- Change to new security mode -->
                <a title="{$correspondence->file_path} - ID:{$correspondence->id}" class="dialog_make_text_btn ui-corner-all" href="#" 
                   onclick="{$action_change_security_mode}; return false;">{$i.correspondence_change_security_mode}</a>
                <br />
            {/if}
            <!-- Edit buttons -->
            {if $corr_locked_by===false || $corr_locked_by->session_uniqid===$curr_unique_id || !$corr_locked_by->is_active}
                {if !isset($correspondence->object_is_editable) || $correspondence->object_is_editable}
                        {if $action_edit neq false}
                            <a title="{$i.correspondence_edit_document} - {$correspondence->file_path} - ID:{$correspondence->id}" class="dialog_make_btn16 open_win smallbtns ui-corner-all frstbtn frstbtnflt" href="#" 
                               onclick="{$action_edit}; return false;"></a>
                        {/if}
                    <div style="padding-bottom:5px;">
                        {if $action_print_preview neq false}
                            <a title="{$i.basic_print_preview} - {$correspondence->file_path} - ID:{$correspondence->id}" class="dialog_make_btn16 open_printpreview smallbtns ui-corner-all" href="#" 
                               onclick="{$action_print_preview}; return false;"></a>
                        {/if}
                        {if $action_print neq false}
                            <a title="{$i.correspondence_print} - {$correspondence->file_path} - ID:{$correspondence->id}" class="dialog_make_btn16 print smallbtns ui-corner-all" href="#" 
                               onclick="{$action_print}; return false;"></a>
                        {/if}
                        {filelink_html($correspondence->file_path, 'file_preview', $correspondence->id, false, $correspondence, false)}
                        <!-- Right finder/explorer buttons -->
                        <span style="float:right; padding-right:5px; transform: scale(0.85);">
                            {if !empty($correspondence->file_path)}
                                {filelink type='folder' value=$correspondence->file_path}
                                {filelink value=dirname($correspondence->file_path)}
                            {else}
                                -
                            {/if}
                        </span>
                    </div>
                    {if (!$corr_no_edit_send || $correspondence->outbox_times<=0) && !$corr_is_old_format && ($file_manager eq 4 || $corr_type eq 'any')}
                        {include file='r/file-only.tpl' name="correspondence_upload" collapse="formstyleright" targettype="correspondence" targetdata=$correspondence->id mime_restriction=$mime_restriction}
                    {/if}
                {else}
                    {$i.correspondence_no_rights}
                {/if}
            {/if}
            {if $corr_locked_by!==false}
                {if $corr_locked_by->session_uniqid===$curr_unique_id}
                    {$i.correspondence_lock1you}
                {else}
                    {$i.correspondence_lock1}: {$corr_locked_by->staff_name}
                {/if}
                <br />
                {$i.correspondence_lock2}: {$corr_locked_by->lock_time->us_date_time()}
                {if !$corr_locked_by->is_active}<small>({$i.basic_inactive})</small>{/if}
                {if (!isset($correspondence->object_is_editable) || $correspondence->object_is_editable)}
                    <br />
                    {if $curr_user_id eq $corr_locked_by->staff_id || !$corr_locked_by->is_active}
                        {* Document is locked by current user *}
                        <a class="dialog_make_text_btn ui-corner-all" id="rem_lock_button" style="margin-left: 10px; text-align: center;"
                            href="javascript:correspondence.rem_lock_do('{$correspondence->id}');">{$i.correspondence_rem_lock_self}<br /><small>({$i.correspondence_rem_lock_self1})</small>
                        </a>
                    {else}
                        {* Document is locked by a different user *}
                        <a class="dialog_make_text_btn ui-corner-all" style="margin-left: 10px;"
                            href="javascript:correspondence.rem_lock('{$correspondence->id}', '{$corr_locked_by->staff_name|escape:'quotes'}');">{$i.correspondence_rem_lock}
                        </a>
                    {/if}
                {/if}
            {/if}
        </td>
    </tr>
    {if $corr_is_old_format}
        <td colspan="2">
            <div class="warningsmall warningborder ui-corner-all">
                {$i.correspondence_corr_is_old_doc_xls}
                {if $action_download neq false}
                    <br>
                    <span class="dialog_make_text_btn ui-corner-all" onclick="{$action_download}">
                        <span class="dialog_make_btn16 open_download ui-corner-all"></span>
                        {$i.basic_download}
                    </span>
                {/if}
            </div>
        </td>
    {/if}
    {if $corr_no_edit_send && $correspondence->outbox_times>=1}
        <td colspan="2">
            <div class="warningsmall warningborder ui-corner-all">
                {$i.correspondence_corr_already_edited}
            </div>
        </td>
    {/if}
    <tr>
        <td colspan="2"></td>
    </tr>
    <tr>
        <td>
            {$i.correspondence_attachments}
        </td>
         <td>
            {if $user_can_edit && $correspondence->is_valid_file_type}
                <span class="dialog_make_btn16 edit smallbtns ui-corner-all frstbtn frstbtnflt"
                    onclick="correspondence.attachment.open('{$correspondence->id}')"
                    title="{$i.basic_edit}"></span>
            {/if}
            {if isset($correspondence->attachments_list) && count($correspondence->attachments_list) > 0}
                <div class="many" id="inforight_correspondence_attachments">
                    {foreach from=$correspondence->attachments_list item=attachment}
                        <p style="">
                        {if !empty($attachment->filename)}
                            {if strtolower(substr($attachment->path, 0, 7)) === 'o365://' && (!isset($attachment->object_is_editable) || $attachment->object_is_editable)}
                                {filelink_html($attachment->path, 'correspondence_attachment', $attachment->id)}
                            {elseif $attachment->is_us_document && (!isset($attachment->object_is_editable) || $attachment->object_is_editable)}{*}US file attachment{*}
                                <span class="dialog_make_btn16 print smallbtns ui-corner-all"
                                    onclick="fullPopup.viewurl('{site_url url="start/open/correspondence_actions/open_us_attachment/`$xjxcookie`/`$attachment->id`"}')"
                                    title="{$i.correspondence_print} - {basename($attachment->path)|escape:'html'}"></span>
                                {if $attachment->security<3}
                                    {security value=$attachment->security} 
                                    {if !$attachment->security_zip && $attachment->file_ext neq 'html'}<span class="dialog_make_btn14 urgent1" title="X2 Security"></span>{/if}
                                {/if}
                            {elseif (!isset($attachment->object_is_editable) || $attachment->object_is_editable)}{*}Normal file attachment{*}
                                {filelink_html($attachment->path)}
                            {/if} 
                            {if $attachment->description neq 'datei'}{$attachment->description}<br />{/if}
                            {$attachment->filename}
                        {else}
                            {$attachment->description}
                        {/if}
                        </p>
                    {/foreach}
                </div>
            {/if}
         </td>
    </tr>
    {if !$correspondence->is_serial}
        <tr>
            <td>
                {$i.correspondence_copy_to}
            </td>
            <td>
                {if $corr_locked_by===false || $corr_locked_by->session_uniqid===$curr_unique_id}
                    {if !isset($correspondence->object_is_editable) || $correspondence->object_is_editable}
                        {if $user_can_edit && $correspondence->is_valid_file_type}
                            <span class="dialog_make_btn16 edit smallbtns ui-corner-all frstbtn frstbtnflt"
                                onclick="correspondence.open('{$correspondence->id}', false, '');"
                                title="{$i.basic_edit}"></span>
                        {/if}
                    {/if}
                {/if}
                {if isset($correspondence->copy_receivers) && count($correspondence->copy_receivers) > 0}
                    <div class="many">
                        {foreach from=$correspondence->copy_receivers item=address}
                            <p style="cursor: pointer;" onclick="usComm.windowOpen('{site_url url="start/open/addressesandcontacts/index/`$xjxcookie`/view/`$address->address_id`"}')"
                               title="{$address->address_email|escape:'html'}"
                               >{$address->address_name}</p>
                        {/foreach}
                    </div>
                {/if}     
            </td>    
        </tr>
    {/if}
    {if $correspondence->outbox_times>0}
        <tr>
            <td>{$i.correspondence_outbox_times_full}</td>
            <td>{$correspondence->outbox_times}</td>
        </tr>
    {/if}
    {if $correspondence->is_archived}
        <tr>
            <td>{$i.correspondence_is_archived}</td>
            <td>{boolview value=$correspondence->is_archived}</td>
        </tr>
    {/if}
    {if $correspondence->is_exported_to_fees}
        <tr>
            <td>{$i.correspondence_is_exported_to_fees}</td>
            <td>
                {boolview value=$correspondence->is_exported_to_fees}
                {if isset($correspondence->is_really_exported_to_fees) && !$correspondence->is_really_exported_to_fees}
                    0
                {/if}
            </td>
        </tr>
    {/if}
    {if $correspondence->fee_no neq ''}
        <tr>
            <td colspan="2"></td>
        </tr>
        <tr>
            <td>{$i.correspondence_fee_no}</td>
            <td>{$correspondence->fee_no}</td>
        </tr>
    {/if}
    {if $correspondence->fee_account_id!==null}
        <tr>
            <td>{$i.correspondence_fee_account_name}</td>
            <td>
                {$correspondence->fee_account_name|truncate:200:"..."}
            </td>
        </tr>
    {/if}
    {if $correspondence->fee_value neq 0}
        <tr>
            <td>{$i.correspondence_fee_value_vat}</td>
            <td>{isfloat value=$correspondence->fee_value} ({isfloat value=$correspondence->vat}%)</td>
        </tr> 
    {/if}
    {if $project_use_currency && $correspondence->fee_value_otcurr!=null}
        {if $correspondence->fee_value_otcurr neq 0}
            <tr>
                <td>{$correspondence->fee_currency_name} {$i.correspondence_fee_value1}</td>
                <td>{isfloat value=$correspondence->fee_value_otcurr} {$correspondence->fee_currency_abbreviation}</td>
            </tr>
            <tr>
                <td>{$i.correspondence_fee_exchange_rate}</td>
                <td>{isfloat value=$correspondence->fee_value/$correspondence->fee_value_otcurr maxf=4}</td>
            </tr> 
        {/if}
    {/if}
    {if $correspondence->discount neq 0}
        <tr>
            <td>{$i.correspondence_discount}</td>
            <td>{$correspondence->discount*100}%</td>
        </tr>
        <tr>
            <td>{$i.correspondence_discount_date}</td>
            <td>{$correspondence->discount_date->us_date()}</td>
        </tr>
    {/if}
    {if !$correspondence->to_date->is_null()}
        <tr>
            <th></th>
            <th><h6>{$i.correspondence_fee_period}</h6></th>
        </tr>
        <tr title="{$i.correspondence_fee_period}">
            <td>{$i.filter_from_date}</td>
            <td>{$correspondence->from_date->us_date()}</td>
        </tr>
        <tr title="{$i.correspondence_fee_period}">
            <td>{$i.filter_to_date}</td>
            <td>{$correspondence->to_date->us_date()}</td>
        </tr>
    {/if}
    {if !empty($correspondence->fees)}
        </tr>
            <td>{$i.basic_feeadmin}</td>
            <td>
                <div class="many">
                    {foreach from=$correspondence->fees item=fee_item}
                        <p>
                            <a href="{site_url url="start/open/feeadmin/index/$xjxcookie/view/{$fee_item->id}/"}"
                               onclick="usComm.windowOpen(this.href); return false;"
                               class="dialog_make_btn16 fees smallbtns ui-corner-all" title="{$i.basic_feeadmin}"></a>

                            {$fee_item->fee_no|truncate:50:"..."} | {isfloat value=$fee_item->value}
                        </p>
                    {foreachelse}
                        &nbsp;
                    {/foreach}
                </div>
            </td>
        </tr>
    {/if}
    {if !empty($correspondence->fees_collective_bills)}
        </tr>
            <td>{$i.correspondence_collective_bill}</td>
            <td>
                <div class="many">
                    {foreach from=$correspondence->fees_collective_bills item=fee_coll_item}
                        <p>
                            {if empty($fee_coll_item)}
                                x
                            {else}
                                <a href="{site_url url="start/open/feeadmin/index/$xjxcookie/view/{$fee_coll_item->full_fees_id}/"}"
                                   onclick="usComm.windowOpen(this.href); return false;"
                                   class="dialog_make_btn16 fees smallbtns ui-corner-all frstbtn" title="{$i.basic_feeadmin}"></a>

                                {$fee_coll_item->fees_fee_no|truncate:50:"..."} | {isfloat value=$fee_coll_item->fees_value}
                            {/if}
                        </p>
                    {foreachelse}
                        &nbsp;
                    {/foreach}
                </div>
            </td>
        </tr>
    {/if}
    {if !empty($correspondence->offer_collective_offers)}
        </tr>
            <td>{$i.correspondence_collective_offer}</td>
            <td>
                <div class="many">
                    {foreach from=$correspondence->offer_collective_offers item=offer_coll_item}
                        <p>
                            {if empty($offer_coll_item)}
                                x
                            {else}
                                <a href="{site_url url="start/open/projectadmin/index/$xjxcookie/view_offer_by_id/{$offer_coll_item->offer_id}/"}"
                                   onclick="usComm.windowOpen(this.href); return false;"
                                   class="dialog_make_btn16 project_offers smallbtns ui-corner-all frstbtn" title="{$i.correspondence_offer_order}"></a>

                                {if empty($offer_coll_item->offer_no) && empty($offer_coll_item->offer_title)}{$i.correspondence_offer_order}{/if}
                                {$offer_coll_item->offer_no}
                                {if !empty($offer_coll_item->offer_no) && !empty($offer_coll_item->offer_title)} - {/if}
                                {$offer_coll_item->offer_title}
                                [{$offer_coll_item->offer_date->us_date()}]
                            {/if}
                        </p>
                    {foreachelse}
                        &nbsp;
                    {/foreach}
                </div>
            </td>
        </tr>
    {/if}
    {if !empty($correspondence->related_id) && !empty($correspondence->related_type)}
        {if $correspondence->related_type === 'offer'}
            </tr>
                <td>{$i.correspondence_offer_order}</td>
                <td>
                    <a href="{site_url url="start/open/projectadmin/index/$xjxcookie/view_offer_by_id/`$correspondence->related_id`"}"
                       onclick="usComm.windowOpen(this.href); return false;"
                       class="dialog_make_btn16 fees smallbtns ui-corner-all frstbtn" title="{$i.correspondence_offer_order}"></a>
                    {boolview value=true}
                </td>
            </tr>
        {elseif $correspondence->related_type === 'delivery_note'}
            </tr>
                <td>{$i.correspondence_delivery_note}</td>
                <td>
                    <a href="{site_url url="start/open/drawingandproductdirectory/index/$xjxcookie/viewdn/{$correspondence->related_id}/"}"
                       onclick="usComm.windowOpen(this.href); return false;"
                       class="dialog_make_btn16 drawings smallbtns ui-corner-all frstbtn" title="{$i.correspondence_delivery_note}"></a>
                    {boolview value=true}
                </td>
            </tr>
        {elseif $correspondence->related_type === 'f2g_plan'}
            </tr>
                <td>{$i.correspondence_flink2go_plan}</td>
                <td title="Account: {$correspondence->related_id} Plan UUID: {$correspondence->related_uuid}">
                    {boolview value=true}
                </td>
            </tr>
        {elseif $correspondence->related_type === 'f2g_photo'}
            </tr>
                <td>{$i.correspondence_flink2go_photo}</td>
                <td title="Account: {$correspondence->related_id} Photo UUID: {$correspondence->related_uuid}">
                    {boolview value=true}
                </td>
            </tr>
        {/if}
    {/if}
    <tr>
        <td colspan="2"></td>
    </tr>
    <tr>
        <td>{$i.basic_created_by}</td>
        <td>{$correspondence->created_by_name}</td>
    </tr>     
    <tr>
        <td>{$i.basic_created_date}</td>
        <td>{$correspondence->created_date->us_date()}</td>
    </tr>    
    <tr>
        <td>{$i.basic_changed_by}</td>
        <td>{$correspondence->changed_by_name}</td>
    </tr>      
    <tr>
        <td>{$i.basic_change_date}</td>
        <td>{$correspondence->change_date->us_date()}</td>
    </tr>
    {if !empty($correspondence->gobd_hash)}      
    <tr>
        <td>{$i.basic_gobd}</td>
        <td>
            {$correspondence->gobd_date->us_date_time()}
            <a class="dialog_make_text_btn ui-corner-all" style="margin-left: 10px;"
                href="javascript:usComm.check_gobd('correspondence', '{$correspondence->id}');">{$i.basic_gobd_check}
            </a>
        </td>
    </tr>      
    {/if}  
    {foreach from=$correspondence->addi_fields item=field}
        <tr>
            {if $field->type eq US_exmodel::T_BLOCK}
                <th colspan="2" style="text-align:center; {if isset($field->color)}background:{$field->color}{/if}">{$field->name}</th>
            {else}
                <td style="{if isset($field->color)}background:{$field->color}{/if}">{$field->name}</td>
                <td>
                    {assign var='field_id' value=$field->field}
                    {addiview field=$field value=$correspondence->$field_id item=$correspondence}
                </td>
            {/if}
        </tr>
    {/foreach}    
    <tr>
        <td colspan="2"><kbd onclick="$(this).selectTextInElement()" contenteditable="true" style="display:block;">{site_url url='open/correspondence'}/{$correspondence->correspondence_id}/file</kbd></td>
    </tr>      
</table>
