{extends "reports/reports_base.tpl.html"}
{block "title"}Recent Activity{/block}

{block "report_content"}
<h3 align="center">
    {t}Recent Activity Report{/t}
</h3>
<form method="post" name="recent_activity">
    <input type="hidden" name="cat" value="generate">
    <table class="bordered filters">
        <tr>
            <th width="120">
                {t}Report Type{/t}:
            </th>
            <td width="200" NOWRAP>
                <label><input type="radio" name="report_type" value="recent" {if $smarty.request.report_type|default:'' != 'range'}checked{/if} onClick="changeType('recent');">
                    {t}Recent{/t}</label>&nbsp;
                <label><input type="radio" name="report_type" value="range" {if $smarty.request.report_type|default:'' == 'range'}CHECKED{/if} onClick="changeType('range');">
                    {t}Date Range{/t}</label>&nbsp;
            </td>
        </tr>
        <tr>
            <th width="120">
                {t}Activity Type{/t}:
            </th>
            <td width="200">
                <select name="activity_types[]" size="5" multiple>
                    {html_options options=$type_list selected=$activity_types}
                </select>
            </td>
        </tr>
        <tr id="recent_row">
            <th width="120">
                {t}Activity in Past{/t}:
            </th>
            <td width="200">
                <input type="text" size="3" name="amount" value="{$amount|default:24}" style="text-align: right">&nbsp;
                <select name="unit">
                    {html_options options=$units selected=$unit}
                </select>
            </td>
        </tr>
        <tr id="start_row">
            <th width="120">
                {t}Start{/t}:
            </th>
            <td width="200">
                {html_select_date time=$start_date|default:'' prefix="" field_array="start" start_year="-2" end_year="+1" field_order="YMD" month_format="%b" all_extra="class='default'"}
            </td>
        </tr>
        <tr id="end_row">
            <th width="120">
                {t}End{/t}:
            </th>
            <td width="200">
                {html_select_date time=$end_date|default:'' prefix="" field_array="end" start_year="-2" end_year="+1" field_order="YMD" month_format="%b" all_extra="class='default'"}
            </td>
        </tr>
        <tr>
            <th width="120">
                {t}Developer{/t}:
            </th>
            <td width="200">
                <select name="developer">
                    <option value="" label="All">{t}All{/t}</option>
                    {html_options options=$users selected=$developer}
                </select>
            </td>
        </tr>
        <tr>
            <th width="120">
                {t}Sort Order{/t}:
            </th>
            <td width="200">
                <select name="sort_order">
                    <option value="ASC" label="{t}Ascending{/t}" {if $sort_order != 'DESC'}selected{/if}>{t}Ascending{/t}</option>
                    <option value="DESC" label="{t}Descending{/t}" {if $sort_order == 'DESC'}selected{/if}>{t}Descending{/t}</option>
                </select>
            </td>
        </tr>
        <tr class="buttons">
            <td align="center" colspan="2">
                <input type="submit" value="{t}Generate{/t}" class="shortcut">
            </td>
        </tr>
    </table>
</form>

<script type="text/javascript">

    function changeType(type) {
        if (type == 'range') {
            $('#recent_row').hide();
            $('#start_row').show();
            $('#end_row').show();
        } else {
            $('#recent_row').show();
            $('#start_row').hide();
            $('#end_row').hide();
        }
    }


        changeType("{$smarty.request.report_type|default:''}");
</script>

{if $data|default:'' != ''}
<br />
{if $data.phone != ''}
<table class="bordered grid">
    <tr class="title">
        <th colspan="{if $core.has_crm}8{else}7{/if}">
            {t}Recent Phone Calls{/t}
        </th>
    </tr>
    <tr>
        <th NOWRAP>{include file="expandable_cell/buttons.tpl.html" ec_id="phone"}</th>
        <th>{t}Issue ID{/t}</th>
        {if $core.has_crm}
        <th>{t}Customer{/t}</th>
        {/if}
        <th>{t}Date{/t}</th>
        <th>{t}Developer{/t}</th>
        <th>{t}Type{/t}</th>
        <th>{t}Line{/t}</th>
        <th>{t}Description{/t}</th>
    </tr>
    {foreach from=$data.phone item=row}
    <tr class="{cycle values='odd,even'}">
        <td NOWRAP>{include file="expandable_cell/buttons.tpl.html" ec_id="phone" list_id=$row.phs_id}</td>
        <td bgcolor="{$row.sta_color}" align="right">
            <a target="_blank" href="{$core.rel_url}view.php?id={$row.phs_iss_id}">{$row.phs_iss_id}</a>
        </td>
        {if $core.has_crm}
        <td>{$row.customer}</td>
        {/if}
        <td nowrap>{$row.date}</td>
        <td>{$row.usr_full_name|escape:html}</td>
        <td>{$row.phs_type}</td>
        <td>{$row.phc_title}</td>
        <td>{$row.phs_description|nl2br}</td>
    </tr>
    {include file="expandable_cell/body.tpl.html" ec_id="phone" list_id=$row.phs_id colspan="8"}
    {foreachelse}
    <tr>
        <td colspan="8" align="center"><i>{t}No Phone Calls Found{/t}</i></td>
    </tr>
    {/foreach}
</table>
<br />
{/if}

{if $data.note != ''}
<table class="bordered grid">
    <tr class="title">
        <th colspan="{if $core.has_crm}6{else}5{/if}">
            {t}Recent Notes{/t}
        </th>
    </tr>
    <tr>
        <th nowrap>{include file="expandable_cell/buttons.tpl.html" ec_id="note"}</th>
        <th>{t}Issue ID{/t}</th>
        {if $core.has_crm}
        <th>{t}Customer{/t}</th>
        {/if}
        <th>{t}Posted Date{/t}</th>
        <th>{t}User{/t}</th>
        <th>{t}Title{/t}</th>
    </tr>
    {foreach from=$data.note item=row}
    <tr class="{cycle values='odd,even'}">
        <td NOWRAP>{include file="expandable_cell/buttons.tpl.html" ec_id="note" list_id=$row.not_id}</td>
        <td bgcolor="{$row.sta_color}" align="right">
            <a target="_blank" href="{$core.rel_url}view.php?id={$row.not_iss_id}" title="{$row.iss_summary|htmlspecialchars}">{$row.not_iss_id}</a>
        </td>
        {if $core.has_crm}
        <td>{$row.customer}</td>
        {/if}
        <td nowrap>{$row.date}</td>
        <td>{$row.usr_full_name|escape:html}</td>
        <td>{$row.not_title|nl2br}</td>
    </tr>
    {include file="expandable_cell/body.tpl.html" ec_id="note" list_id=$row.not_id colspan="6"}
    {foreachelse}
    <tr>
        <td colspan="6" align="center"><i>{t}No Notes Found{/t}</i></td>
    </tr>
    {/foreach}
</table>
<br />
{/if}

{if $data.email != ''}
<table class="bordered grid">
    <tr class="title">
        <th colspan="{if $core.has_crm}7{else}6{/if}">
            {t}Recent Emails{/t}
        </th>
    </tr>
    <tr>
        <th align="center" NOWRAP>{include file="expandable_cell/buttons.tpl.html" ec_id="email"}</th>
        <th nowrap>{t}Issue ID{/t}</th>
        {if $core.has_crm}
        <th>{t}Customer{/t}</th>
        {/if}
        <th>{t}From{/t}</th>
        <th>{t}To{/t}</th>
        <th>{t}Date{/t}</th>
        <th>{t}Subject{/t}</th>
    </tr>
    {foreach from=$data.email item=row}
    <tr class="{cycle values='odd,even'}">
        <td align="center" nowrap>
            {include file="expandable_cell/buttons.tpl.html" ec_id="email" list_id=$row.composite_id}
        </td>
        <td bgcolor="{$row.sta_color}" align="right">
            <a target="_blank" href="{$core.rel_url}view.php?id={$row.sup_iss_id}" title="{$row.iss_summary|htmlspecialchars}">{$row.sup_iss_id}</a>
        </td>
        {if $core.has_crm}
        <td>{$row.customer}</td>
        {/if}
        <td>{$row.sup_from|escape:"html"}</td>
        <td>
            {if $row.sup_to == ""}
            <i>{t}sent to notification list{/t}</i>
            {else}
            {$row.sup_to|escape:"html"}
            {/if}
        </td>
        <td nowrap>{$row.date}</td>
        <td>{$row.sup_subject|nl2br}</td>
    </tr>
    {include file="expandable_cell/body.tpl.html" ec_id="email" list_id=$row.composite_id colspan=7}
    {foreachelse}
    <tr>
        <td colspan="7" align="center"><i>{t}No Emails Found{/t}</i></td>
    </tr>
    {/foreach}
</table>
<br />
{/if}

{if $data.draft != ''}
<table class="bordered grid">
    <tr class="title">
        <th colspan="{if $core.has_crm}8{else}7{/if}">
            {t}Recent Drafts{/t}
        </th>
    </tr>
    <tr>
        <th NOWRAP>{include file="expandable_cell/buttons.tpl.html" ec_id="draft"}</th>
        <th>{t}Issue ID{/t}</th>
        {if $core.has_crm}
        <th>{t}Customer{/t}</th>
        {/if}
        <th>{t}Status{/t}</th>
        <th>{t}From{/t}</th>
        <th>{t}To{/t}</th>
        <th>{t}Date{/t}</th>
        <th>{t}Subject{/t}</th>
    </tr>
    {foreach from=$data.draft item=row}
    <tr class="{cycle values='odd,even'}" {if $row.emd_status != 'pending'}style="text-decoration: line-through;"{/if}>
    <td NOWRAP>{include file="expandable_cell/buttons.tpl.html" ec_id="draft" list_id=$row.emd_id}</td>
    <td bgcolor="{$row.sta_color}" align="right">
        <a target="_blank" href="{$core.rel_url}view.php?id={$row.emd_iss_id}">{$row.emd_iss_id}</a>
    </td>
    {if $core.has_crm}
    <td>{$row.customer}</td>
    {/if}
    <td>{$row.emd_status}</td>
    <td>{$row.from|escape:"html"}</td>
    <td>{$row.to|escape:"html"}</td>
    </td>
    <td nowrap>{$row.date}</td>
    <td>{$row.emd_subject|nl2br}</td>
    </tr>
    {include file="expandable_cell/body.tpl.html" ec_id="draft" list_id=$row.emd_id colspan=8}
    {foreachelse}
    <tr>
        <td colspan="8" align="center"><i>{t}No Drafts Found{/t}</i></td>
    </tr>
    {/foreach}
</table>
<br />
{/if}

{if $data.time != ''}
<table class="bordered grid">
    <tr class="title">
        <th colspan="{if $core.has_crm}7{else}6{/if}">
            {t}Recent Time Entries{/t}
        </th>
    </tr>
    <tr>
        <th>{t}Issue ID{/t}</th>
        {if $core.has_crm}
        <th>{t}Customer{/t}</th>
        {/if}
        <th>{t}Date of Work{/t}</th>
        <th>{t}User{/t}</th>
        <th>{t}Time Spent{/t}</th>
        <th>{t}Category{/t}</th>
        <th>{t}Summary{/t}</th>
    </tr>
    {foreach from=$data.time item=row}
    <tr class="{cycle values='odd,even'}">
        <td bgcolor="{$row.sta_color}" align="right">
            <a target="_blank" href="{$core.rel_url}view.php?id={$row.ttr_iss_id}" title="{$row.iss_summary|htmlspecialchars}">{$row.ttr_iss_id}</a>
        </td>
        {if $core.has_crm}
        <td>{$row.customer}</td>
        {/if}
        <td nowrap>{$row.date}</td>
        <td>{$row.usr_full_name|escape:html}</td>
        <td>{$row.time_spent}</td>
        <td>{$row.ttc_title}</td>
        <td>{$row.ttr_summary|nl2br}</td>
    </tr>
    {foreachelse}
    <tr>
        <td colspan="7" align="center"><i>{t}No Time Entries Found{/t}</i></td>
    </tr>
    {/foreach}
</table>
<br />
{/if}

{if $data.reminder|default:'' != ''}
<table class="bordered grid">
    <tr class="title">
        <th colspan="{if $core.has_crm}4{else}3{/if}">
            {t}Recent Reminder Actions{/t}
        </th>
    </tr>
    <tr>
        <th>{t}Issue ID{/t}</th>
        {if $core.has_crm}
        <th>{t}Customer{/t}</th>
        {/if}
        <th>{t}Date Triggered{/t}</th>
        <th>{t}Title{/t}</th>
    </tr>
    {foreach from=$data.reminder item=row}
    <tr class="{cycle values='odd,even'}">
        <td bgcolor="{$row.sta_color}" align="right">
            <a target="_blank" href="{$core.rel_url}view.php?id={$row.rmh_iss_id}">{$row.rmh_iss_id}</a>
        </td>
        {if $core.has_crm}
        <td>{$row.customer}</td>
        {/if}
        <td nowrap>{$row.date}</td>
        <td>{$row.rma_title}</td>
        {foreachelse}
    <tr>
        <td colspan="7" align="center"><i>{t}No Reminder Entries Found{/t}</i></td>
    </tr>
    {/foreach}
</table>
<br />
{/if}
{/if}
<br />
{/block}
