<!-- BEGIN {$smarty.template} -->

<script type="text/javascript">
{literal}
    $(document).ready(function() {

        var dates = $('#op_startdatefrom, #op_startdateto').datepicker({
            changeMonth: true,
            changeYear: true,
            numberOfMonths: 2,
            dateFormat: 'yy-mm-dd',
            showOn: 'both',
            buttonImage: '../img/phpaga/cal.png',
            buttonImageOnly: true,
            onSelect: function(selectedDate) {
                var option = this.id == "op_startdatefrom" ? "minDate" : "maxDate";
                var instance = $(this).data("datepicker");
                var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
                dates.not(this).datepicker("option", option, date);
            }

        });

        /* View task details */

        var $viewTaskDialog = $('<div><\/div>').dialog({ 
            autoOpen: false, 
            title: '{/literal}{t}Task information{/t}{literal}', 
            width: 'auto', 
            height: 'auto' 
            });

        $('.tview').live('click', function() {
            var id = $(this).attr('id');
            var task_id = id.replace(/^tv/g, "");
            $viewTaskDialog.load('service.php?saction='+{/literal}{$smarty.const.ACTION_SERVICE_OPDETAILS}{literal}
                +'&id=' + task_id);
            $viewTaskDialog.dialog('open');
            return false;
        });

        /* Create invoice */

        $('#createinvoice').click(function() { $( "#invoicebox" ).dialog( "open" ); });
        $("#invoicebox").dialog({
            autoOpen: false,
            minWidth: 600,
            modal: true,
            buttons: {
                "{/literal}{t}Create invoice{/t}{literal}": function() {
                   $('#invoiceboxfrm').submit(); 
                },
                Cancel: function() {
                    $( this ).dialog( "close" );
                }
            },
            close: function() {
        }
        });

        /* Delete tasks */

        var delOperationDialog = $('<div><span id="opinfo"><\/span>{/literal}Delete this task?{literal}<\/div>').dialog({ 
            autoOpen: false, 
            title: '{/literal}Delete this task?{literal}', 
            width: 'auto', 
            height: 'auto',
            modal: true
            });

        $('.opdel').live('click', function() {
                    op_id = $(this).attr('id').replace(/^op/g, "");

                    $.get('service.php?saction={/literal}{$smarty.const.ACTION_SERVICE_OPDETAILS}{literal}&id=' + op_id, function(data) { $('#opinfo').html(data+'<br \/>'); });

                    delOperationDialog.dialog("option", {
                            buttons: {
                                '{/literal}Delete{literal}': function() {
                                    $.ajax({
                                            url: 'service.php',
                                            type: 'POST',
                                            data: 'saction={/literal}{$smarty.const.ACTION_SERVICE_DELETE_OP}{literal}&op_id='+op_id,
                                            dataType: 'json',
                                            cache: false,
                                            success: function(result) {
                                                if (result.status != 0) {
                                                    alert(result.message);
                                                } else {
                                                    delOperationDialog.dialog('close');
                                                    $('#oprow'+op_id).fadeOut();
                                                }
                                            }
                                        });
                                },
                                Cancel: function() { $(this).dialog('close'); }
                            }
                        });

                    delOperationDialog.dialog('open');
                    return false;
            });
    });
{/literal}
</script>

<div class="floatcontainer">
    <form action="{$FORM_ACTION}" method="get" name="form">
        <input type="hidden" name="order" value="{$ORDER}">

        <fieldset class="search">
            <legend>{t}Search tasks{/t}</legend>


            <fieldset class="flleft"><legend>{t}Project{/t}</legend>

                <label for="cpn_id">{t}Customer{/t}:</label>
                <select id="cpn_id" name="cpn_id">
                    {html_options options=$select_cpn selected=$operation.cpn_id}
                </select>
                <br>

                <label for="cpn_id_issuebill">{t}Billing company{/t}:</label>
                <select name="cpn_id_issuebill">
                    {html_options options=$select_cpn selected=$operation.cpn_id_issuebill}
                </select>
                <br>

                <label for="prj_id">{t}Project{/t}:</label>
                <select id="prj_id" name="prj_id">
                    {html_options options=$select_project selected=$operation.prj_id}
                </select>
                <br>

                <label for="prjcat_id">{t}Category{/t}:</label>
                <select id="prjcat_id" name="prjcat_id">
                    {html_options options=$select_prjcat selected=$operation.prjcat_id}
                </select>
                <br>

                <label for="prj_status">{t}Project status{/t}:</label>
                <select id="prj_status" name="prj_status">
                    {html_options options=$select_prjstat selected=$operation.prj_status}
                </select>
                <br>

                <label for="prj_billabletype">{t}Project billable{/t}:</label>
                <select id="prj_billabletype" name="prj_billabletype">
                    {html_options options=$select_prj_billabletype selected=$operation.prj_billabletype}
                </select>

            </fieldset>

            <fieldset class="flleft"><legend>{t}Task{/t}</legend>

                <label for="opcat_id">{t}Category{/t}:</label>
                <select id="opcat_id" name="opcat_id">
                    {html_options options=$select_opcat selected=$operation.opcat_id}
                </select>
                <br>

                <label for="op_billed">{t}Billing status{/t}:</label>
                <select id="op_billed" name="op_billed">
                    {html_options options=$select_billed selected=$operation.op_billed}
                </select>
                <br>

                <label for="pe_id">{t}Person{/t}:</label>
                <select id="pe_id" name="pe_id">
                    {html_options options=$select_person selected=$operation.pe_id}
                </select>
                <br>

                <label for="jcat_id">{t}Job category{/t}:</label>
                <select id="jcat_id" name="jcat_id">
                    {html_options options=$select_jcat selected=$operation.jcat_id}
                </select>
                <br>

                <label for="op_desc">{t}Description{/t}:</label>
                <input type="text" class="tinput" id="op_desc" name="op_desc" value="{$operation.op_desc|wash}" size="20" maxlength="100">
                <br>

                <label for="op_startdatefrom">{t}Between{/t}:</label>
                <input type="text" class="tinput" name="op_startdatefrom" id="op_startdatefrom" value="{$operation.op_startdatefrom|wash}" size="10" maxlength="10" title="yyyy-mm-dd">
                <br>

                <label for="op_startdateto">{t}And{/t}:</label>
                <input type="text" class="tinput" name="op_startdateto" id="op_startdateto" value="{$operation.op_startdateto|wash}" size="10" maxlength="10" title="yyyy-mm-dd">

            </fieldset>

<div class="spacer"></div>
            <input type="submit" name="submit" value="{t}Search{/t}">
        </fieldset>
    </form>
</div>
<div class="spacer"></div>

{$STATUSMSG}

<div id="invoicebox" title="{t}Create invoice{/t}">

    <form action="add_bill.php" method="get" id="invoiceboxfrm">
        {foreach from=$operation item=opv key=opk}
        <input type="hidden" name="{$opk}" value="{$opv}" />
        {/foreach}
        <input type="hidden" name="action" value="{$smarty.const.ACTION_BILL_WITHOPERATIONS}" />

        {if (isset($operation.cpn_id) && is_numeric($operation.cpn_id)) || (isset($operation.prj_id) && is_numeric($operation.prj_id))}
        <input type="checkbox" name="add_expenses" id="add_expenses" />
        <label for="add_expenses">{t}Add unbilled expenses{/t}</label><br />
        {/if}

        <label for="bill_additional_line">{t}Additional information{/t}</label>
        <input type="text" name="bill_additional_line" id="bill_additional_line" size="40" maxlength="255" value="{$config.LETTERHEAD_ADDITIONAL_LINE}" />

    </form>
</div>

<div id="opdetails"> </div>

<table cellspacing="0">
    <caption><em>{t}Tasks{/t}</em> [
        {if ($show_create_bill)}
        <a id="createinvoice" href="#">{t}Create invoice{/t}</a> |
        {/if}
        <a href="operations_pdf.php?{$search_args}">{t}Print to PDF{/t}</a>
        ]
    </caption>
    <thead>
        <tr>
            <th> <a href="{$location}{$sort.pr}"{if $porder == $smarty.const.ORDER_OP_PR_ASC} class="sortasc"{elseif $porder == $smarty.const.ORDER_OP_PR_DESC} class="sortdesc"{/if}>{t}Project{/t}</a> </th>
            <th> {t}Project status{/t} </th>
            <th> {t}Task{/t} </th>
            <th class="time"> <a href="{$location}{$sort.start}"{if $porder == $smarty.const.ORDER_OP_TIMESTAMP_START_ASC} class="sortasc"{elseif $porder == $smarty.const.ORDER_OP_TIMESTAMP_START_DESC} class="sortdesc"{/if}>{t}Date{/t}</a> </th>
            <th> <a href="{$location}{$sort.pe}"{if $porder == $smarty.const.ORDER_OP_PE_ASC} class="sortasc"{elseif $porder == $smarty.const.ORDER_OP_PE_DESC} class="sortdesc"{/if}>{t}Person{/t}</a> </th>
            <th> <a href="{$location}{$sort.opcat}"{if $porder == $smarty.const.ORDER_OP_OPCAT_ASC} class="sortasc"{elseif $porder == $smarty.const.ORDER_OP_OPCAT_DESC} class="sortdesc"{/if}>{t}Category{/t}</a> </th>
            <th class="time"> <a href="{$location}{$sort.duration}"{if $porder == $smarty.const.ORDER_OP_DURATION_ASC} class="sortasc"{elseif $porder == $smarty.const.ORDER_OP_DURATION_DESC} class="sortdesc"{/if}>{t}Hours{/t}</a></th>
            <th> {t}Actions{/t} </th>
        </tr>
    </thead>
    {section name=details loop=$operations}
    <tr id="oprow{$operations[details].op_id}">
        <td{if ((strlen($operations[details].prj_title) > $smarty.const.PHPAGA_SHOWPRJTITLELENGHT))} class="tTip" title="{$operations[details].prj_title|phpaga_popup_sanitizestr}"{/if}>
            <a href="project.php?id={$operations[details].prj_id}"> {$operations[details].prj_title|wash|trnc:$smarty.const.PHPAGA_SHOWPRJTITLELENGHT:"...":true} </a>
        </td>
        <td> {$operations[details].prjstat_title} </td>
        <td{if ((strlen($operations[details].op_desc) > $smarty.const.PHPAGA_SHOWOPDESCLENGHT))} class="tTip" title="{$operations[details].op_desc|wash|phpaga_popup_sanitizestr}"{/if}>
            {$operations[details].op_desc|wash|trnc:$smarty.const.PHPAGA_SHOWOPDESCLENGHT:"...":true}
        </td>
        <td class="time"> {$operations[details].op_startdate|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT} </td>
        <td> <a href="person.php?id={$operations[details].pe_id}">{$operations[details].op_person|wash}</a> </td>
        <td{if ((strlen($operations[details].opcat_title) > $smarty.const.PHPAGA_SHOWOPCATTITLELENGHT))} class="tTip" title="{$operations[details].opcat_title|phpaga_popup_sanitizestr}"{/if}>
            {$operations[details].opcat_title|wash|trnc:$smarty.const.PHPAGA_SHOWOPCATTITLELENGHT:"...":true}
        </td>
        <td class="time"> {$operations[details].op_duration|phpaga_minutes2duration} </td>
        <td class="actions"> {strip}
            <a class="ptr tview" id="tv{$operations[details].op_id}"><img id="vimg{$operations[details].op_id}" src="img/phpaga/view.png" height="16" width="16" border="0" alt="{t}View{/t}" title="{t}View{/t}"></a>

            {if ($operations[details].op_canedit)}
            <a href="operation.php?id={$operations[details].op_id}&amp;ref={$refop}"><img src="img/phpaga/edit.png" height="16" width="16" border="0" alt="{t}Edit{/t}" title="{t}Edit{/t}"></a>
            <a class="opdel" id="op{$operations[details].op_id}" href="#"><img src="img/phpaga/delete.png" height="16" width="16" border="0" alt="{t}Delete{/t}" title="{t}Delete{/t}"></a>
            {/if}

            {if ($perm_view_invoices && isset($operations[details].bill_id) && is_numeric($operations[details].bill_id))}
            <a href="bill.php?id={$operations[details].bill_id}"><img src="img/phpaga/bill.png" height="16" width="16" border="0" alt="{t}Invoice{/t}" title="{t}Invoice{/t}"></a>
            {/if}

            {/strip}
        </td>
    </tr>
    {/section}
    <tfoot>
        <tr>
            <td class="browse" colspan="3"> {$BROWSE} </td>
            <td class="desc" colspan="2"> {t}Total duration{/t}: {$TOTALHOURS} </td>
            <td class="number" colspan="2"> {t}Subtotal{/t}: {$SUBTOTALHOURS|phpaga_minutes2duration} </td>
            <td>&nbsp;</td>
        </tr>
    </tfoot>
</table>

<!-- END {$smarty.template} -->
