{function name=test_mbox}
    {assign var="my_box" value=$data->{"`$mbox`box"}}
    {assign var="pid" value=$data->{"pid_`$mbox`"}}
    {assign var="last_check_start" value=$data->{"last_check_start_`$mbox`"}}
    {assign var="last_check_stop" value=$data->{"last_check_stop_`$mbox`"}}
    {assign var="number_mails" value=$data->{"number_`$mbox`_total"}}

    {assign var="status_class" value="ok"}
    {assign var="last_succ_connect" value=$last_check_stop->us_date_time()}
    {if $pid !== null}
        {$last_succ_connect = "Start: `$last_check_start->us_date_time()`"}
        {$status_class = "dialog_make_load16"}
    {/if}

    {if ($last_check_start->format('U') > $last_check_stop->format('U')) OR ( $interval_limit->format('U') > $last_check_start->format('U') )} 
        {$status_class = "cancel"}
    {/if}

    {assign var="pm_class" value="projectmail_`$data->id`_`$mbox`box"}
    {assign var="onclk" value="$(this).find('span.dialog_make_btn16').removeClass('ok cancel').addClass('dialog_make_load16');openx('portlet', 'projectmail_overview', 'test_refresh', '`$pm_class`');"}
    {assign var="title" value=sprintf($testbutton_title, $last_succ_connect)}

    {if !empty($my_box)}
    <span class='{"dialog_make_text_btn ui-corner-all `$pm_class`"}' title="{$title}" onclick="{$onclk}">
        <span class='{"dialog_make_btn16 ui-corner-all `$status_class`"}'></span>
        {$my_box} <small style="opacity: .4">({$number_mails} Mails)</small>
    </span>
    {else}
    -
    {/if}
{/function}

{function name=reset_mailcache}
    {assign var="my_box" value=$data->{"`$mbox`box"}}
    {if !empty($my_box)}
        <span onclick="if(confirm(lang_basic.enter_confirm) === false) return false; openx('portlet', 'projectmail_overview', 'reset_mailcache', '{$data->email_account_id}', '{$my_box}');" 
            title="" class="dialog_make_btn16 reset ui-corner-all">
            {if $mbox==='in'}{$i.inoutbox_inbox}{else}{$i.inoutbox_outbox}{/if}: {$i.inoutbox_reset_cache}<br />({$my_box})
        </span>
    {/if}
{/function}


<table class="list">
    <thead>
        <tr>
            <th>&nbsp;</th>
            <th>{$i.projectadmin_project}</th>
            <th>{$i.projectadmin_project_mail}</th>
            <th>{$i.projectadmin_path_inbox}</th>
            <th>{$i.projectadmin_path_outbox}</th>
            <th>{$i.projectadmin_project_mail_security}</th>
            <th>{$i.projectadmin_project_mail_delete}</th>
        </tr>
    </thead>
    <tbody>
    {$last_project_id = false}
    {$last_email_account_email = false}
    {foreach item="projectmail" from=$projectmails}
        {assign var="security" value="rights_r`$projectmail->security`"}
        <tr>
            <td>
                <span class="dialog_make_btn24 dot3ps smallbtns" onclick="$(this).closest('div.portlet-content').css('overflow', 'visible');tableeditpop.open(this, '', '')"></span>
                <div class="ui-corner-all ui-widget-header dot3-container">
                    <div class="dot3-caret">
                        <div class="dot3-caret-outer"></div>
                        <div class="dot3-caret-inner"></div>
                    </div>

                    <a href="{site_url url="start/open/projectadmin/index/$xjxcookie/edit_projectmail/{$projectmail->project_id}/"}"
                        onclick="window.open(this.href); return false;"
                        class="dialog_make_btn16 edit smallbtns ui-corner-all" title="{$i.basic_edit}">{$i.basic_edit}</a>
                        <ul>
                            <li>{reset_mailcache mbox='in' data=$projectmail}</li>
                            <li>{reset_mailcache mbox='out' data=$projectmail}</li>
                        </ul>
                </div>
            </td>
            <td>
                {if $last_project_id != $projectmail->project_id}
                    {$projectmail->project}
                {/if}
            </td>
            <td>
                {if $last_email_account_email != $projectmail->email_account_email}
                    {$projectmail->email_account_email}
                {/if}
            </td>
            <td>{test_mbox mbox='in' data=$projectmail}</td>
            <td>{test_mbox mbox='out' data=$projectmail}</td>
            <td>{$i.$security}</td>
            <td>
                {assign var="delete_eml" value="projectadmin_project_mail_delete_eml_`$projectmail->delete_after_save`"}
                {$i.$delete_eml}
            </td>
        </tr>
        {$last_project_id = $projectmail->project_id}
        {$last_email_account_email = $projectmail->email_account_email}
    {/foreach}
    </tbody>
</table>