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

{include file="delete_prjmember.js"}
{include file="delete_file.js"}
{include file="delete_expense.js"}

{literal}
<script type="text/javascript">

    $(document).ready(function() {
        var ocplot = null;

        $.getJSON("data_service.php?req=opcat&prj_id={/literal}{$project.prj_id}{literal}", 
            function(data){ ocplot = get_opcat_plot('prjopcat', data); }
        );

        $("#tab_container").tabs();
        $('#tab_container').bind('tabsshow', function(event, ui) {
            if (ui.panel.id == "project-task-categories")
                ocplot.replot();
        });

        /* 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;
        });

        /* Add a task to the project */

        var $addTaskDialog = $('<div><\/div>').dialog({ 
            autoOpen: false, 
            title: '{/literal}{t}Add task{/t}{literal}', 
            modal: true, 
            width: 'auto', 
            height: 'auto',
            buttons: { 
                "Cancel": function() { $(this).dialog("close"); },
                "OK": function() { 
                    data = $('#faddop').serialize();
                    $.ajax({
                        url: 'service.php',
                        type: 'POST',
                        data: 'saction=47&'+data,
                        dataType: 'json',
                        cache: false,
                        success: function(result) {
                            if (result.status != 0) {
                                hidePageStatus();
                                alert(result.message);
                            } else {
                                location.href='project.php?id={/literal}{$project.prj_id}{literal}';
                            }
                        }
                    });
                  }
                }
            });

        $('#tadd').click(function() {
            $addTaskDialog.load('service.php?saction='+{/literal}{$smarty.const.ACTION_SERVICE_GETADDTASK_HTML}{literal}
                +'&id={/literal}{$project.prj_id}{literal}');
            $addTaskDialog.dialog('open');
            return false;
        });


        $('#createinvoice').click(function() { $( "#invoicebox" ).dialog( "open" ); });
        $('#chk_manhours').click(function() {
                if ($(this).attr('checked'))
                    $('#sm1,#sm2').removeAttr('disabled');
                else
                    $('#sm1,#sm2').attr('disabled', 'disabled');
        });

        $("#invoicebox").dialog({
                autoOpen: false,
                height: 300,
                width: 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;
        });

        /* Colorbox settings */

        h = $(window).height() * 0.9;
        w = $(window).width() * 0.9;
        $(".cbox_img").colorbox({ photo: true, maxHeight: h, maxWidth: w });

    });

function confirm_delete(prj_id) {
    if (window.confirm('{/literal}{t}Are you sure you want to delete this project?{/t}{literal}')) {
        location.href = 'project.php?id='+prj_id+'&action={/literal}{$smarty.const.ACTION_PRJ_REMOVE}{literal}';
    }
}

function confirm_delete_material(mat_id, mat_info) {
    if (window.confirm(mat_info+'\n\n{/literal}{t}Are you sure you want to delete this material?{/t}{literal}')) {
        location.href = '{/literal}{$smarty.const.PHPAGA_SELF}?action={$smarty.const.ACTION_MATERIAL_REMOVE}{if (isset($DELETE_OP_URL_EXTRA) && strlen($DELETE_OP_URL_EXTRA))}{$DELETE_OP_URL_EXTRA}{/if}{literal}&mat_id='+mat_id;
    }
}

</script>
{/literal}

{include file="upload.tpl.html"}

{assign var=files value=$project.files}

{if strlen($relmap)}{$relmap}{/if}

<h2>{t}Project{/t}: {$project.prj_title|wash}</h2>

<ul class="actions">
    {if $prjmanage || $perm_invoice}
    {if $perm_invoice}
    <li><a id="createinvoice" class="ptr" href="#">{t}Create invoice{/t}</a></li>
    {/if}
    <li><a class="ptr" onclick="confirm_delete({$project.prj_id});">{t}Delete{/t}</a></li>
    <li><a href="edit_project.php?prj_id={$project.prj_id}">{t}Edit{/t}</a></li>
    <li><a href="prjmember.php?prj_id={$project.prj_id}">{t}Add project member{/t}</a></li>
    {/if}
    {if $prjmember || $prjmanage}<li><a href="add_material.php?prj_id={$project.prj_id}">{t}Add material{/t}</a></li>
    <li><a href="add_expense.php?prj_id={$project.prj_id}">{t}Add expense{/t}</a></li>
    <li><a id="tadd" href="add_operation.php?prj_id={$project.prj_id}">{t}Add task{/t}</a></li>
    <li><a id="uplink" class="ptr" onclick="show_box('uplink', 'upload');">{t}Add files{/t}</a></li>
    {/if}
</ul>
<div class="spacer"> </div>

  <div id="tab_container">
  <ul class="tab_items">
      <li><a href="#project-details" rel="project-details">{t}Project{/t}</a></li>
      {if (isset($opcats) && (count($opcats) > 0)) || ($prjmanage && (isset($project.opcatlist) && (count($project.opcatlist) > 0)))}
      <li><a href="#project-task-categories" rel="project-task-categories">{t}Task categories{/t}</a></li>
      {/if}
      {if (isset($project.operations) && (count($project.operations) > 0))}
      <li><a href="#project-tasks" rel="project-tasks">{t}Tasks{/t}</a></li>
      {/if}
      {if (count($project.prj_members) > 0) || ($prjmanage && isset($project.humancost.details) && (count($project.humancost.details) > 0))}
      <li><a href="#project-members" rel="project-members">{t}Members{/t}</a></li>
      {/if}
      {if count($project.materials.details) > 0}
      <li><a href="#project-material" rel="project-material">{t}Material{/t}</a></li>
      {/if}
      {if count($project.expenses) > 0}
      <li><a href="#project-expenses" rel="project-expenses">{t}Expenses{/t}</a></li>
      {/if}
      {if count($files) > 0}
      <li><a href="#project-files" rel="project-files">{t}Files{/t}</a></li>
      {/if}
  </ul>

  <div id="project-details" class="tab_content">

      <div class="floatcontainer">
          <table class="detail flleft" cellspacing="0">
              <caption> <em>{$project.prj_title|wash}</em> </caption>
              <tr>
                  <th> {t}Description{/t}: </th>
                  <td colspan="3"> {$project.prj_desc|wash|default:"&nbsp;"} </td>
              </tr>
              <tr>
                  <th> {t}Customer{/t}: </th>
                  <td colspan="3"> <a href="company.php?id={$project.cpn_id}">{$project.cpn_name|wash|default:"&nbsp;"}</a> </td>
              </tr>
              <tr>
                  <th> {t}Category{/t}: </th>
                  <td> {$project.prjcat_title|wash|default:"&nbsp;"} </td>
                  <th> {t}Status{/t}: </th>
                  <td> {$project.prjstat_title|wash|default:"&nbsp;"} </td>
              </tr>
              <tr>
                  <th> {t}Created by{/t}: </th>
                  <td> {if strlen($project.prj_owner)}<a href="person.php?id={$project.pe_id}">{$project.prj_owner|wash}</a>{else}&nbsp;{/if} </td>
                  <th> {t}From quotation{/t}: </th>
                  <td> {if strlen($project.quot_id)}<a href="quotation.php?id={$project.quot_id}">{$project.quot_number|wash|default:"&nbsp;"}/{$project.quot_date|wash|default:"&nbsp;"}</a>{else}&nbsp;{/if} </td>
              </tr>
              <tr>
                  <th> {t}Project manager{/t}: </th>
                  <td> {if strlen($project.prj_manager_pe_id)}<a href="person.php?id={$project.prj_manager_pe_id}">{$project.prj_manager|wash}</a>{else}&nbsp;{/if} </td>
                  <th> {t}Billable{/t}: </th>
                  <td> {$project.prj_billabletype_text|wash|default:"&nbsp;"} </td>
              </tr>
              <tr>
                  <th> {t}Priority{/t}: </th>
                  <td> {$project.prj_priority|wash|default:"&nbsp;"} </td>
                  <th class="tTip" title="{t}Company that issues the invoice{/t}"> {t}Billing company{/t}: </th>
                  <td> {if strlen($project.cpn_id_issuebill)}<a href="company.php?id={$project.cpn_id_issuebill}">{$project.cpn_name_issuebill|wash|default:"&nbsp;"}</a>{else}&nbsp;{/if} </td>
              </tr>

              <tr>
                  <th> {t}Start date{/t}: </th>
                  <td> {if strlen($project.prj_startdate)}{$project.prj_startdate|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT}{else}&nbsp;{/if} </td>
                  <th> {t}Estimated end{/t}: </th>
                  <td> {if strlen($project.prj_estimatedend)}{if $project.prj_overdue}<span class="overdue">{$project.prj_estimatedend|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT}</span>{else}{$project.prj_estimatedend|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT}{/if}{else}&nbsp;{/if} </td>
              </tr>
              <tr>
                  <th> {t}End date{/t}: </th>
                  <td> {if strlen($project.prj_enddate)}{$project.prj_enddate|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT}{else}&nbsp;{/if} </td>
                  <th> {t}Deadline Date{/t}: </th>
                  <td> {if strlen($project.prj_deadline)}{if $project.prj_overdue}<span class="overdue">{$project.prj_deadline|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT}</span>{else}{$project.prj_deadline|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT}{/if}{else}&nbsp;{/if} </td>
              </tr>
          </table>

          <table class="flleft" cellspacing="0">
              <caption><em>{t}Progress{/t}</em></caption>
              <thead>
                  <tr>
                      <th></th>
                      <th>{t}estimated{/t}</th>
                      <th>{t}tracked{/t}</th>
                      <th>{t}% complete{/t}</th>
                  </tr>
              </thead>
              <tbody>
                  <tr>
                      <td>{t}Manhours{/t}</td>
                      <td class="number">{$project.prj_planned_manhours|wash|phpaga_hours2duration|default:"&nbsp;"}</td>
                      <td class="number">{$project.prj_duration_minutes|phpaga_minutes2duration|default:"&nbsp;"}</td>
                      <td class="number{if (is_numeric($project.prj_perc_manhours) && ($project.prj_perc_manhours > 100))} warn{/if}">{$project.prj_perc_manhours|phpaga_formatpercentage|default:"&nbsp;"} %</td>
                  </tr>
                  <tr>
                      <td>{t}Manhours cost{/t}</td>
                      <td class="number">{$config.MONETARY_SYMBOL}{$project.prj_planned_cost_manhours|wash|phpaga_formatamount|default:"&nbsp;"}</td>
                      <td class="number">{$config.MONETARY_SYMBOL}{$project.humancost.total_amount|phpaga_formatamount|default:"&nbsp;"}</td>
                      <td class="number{if (is_numeric($project.prj_perc_cost_manhours) && ($project.prj_perc_cost_manhours > 100))} warn{/if}">{$project.prj_perc_cost_manhours|phpaga_formatpercentage|default:"&nbsp;"} %</td>
                  </tr>
                  <tr>
                      <td>{t}Material cost{/t}</td>
                      <td class="number">{$config.MONETARY_SYMBOL}{$project.prj_planned_cost_material|wash|phpaga_formatamount|default:"&nbsp;"}</td>
                      <td class="number">{$config.MONETARY_SYMBOL}{$project.materials.total_amount|phpaga_formatamount|default:"&nbsp;"}</td>
                      <td class="number{if (is_numeric($project.prj_perc_cost_material) && ($project.prj_perc_cost_material > 100))} warn{/if}">{$project.prj_perc_cost_material|phpaga_formatpercentage|default:"&nbsp;"} %</td>
                  </tr>
              </tbody>
          </table>

          <table class="flleft" cellspacing="0">
              <caption><em>{t}Relations{/t}</em></caption>

              <tr>
                  <th> {t}Parent project{/t}: </th>
                  <td> {if strlen($project.parent_prj_title)}<a href="project.php?id={$project.prj_prj_id}">{$project.parent_prj_title|wash}</a>{else}&nbsp;{/if} </td>
              </tr>
              <tr>
                  <th> {t}Child projects{/t}: </th>
                  <td class="datawrap"> {if (isset($project.childs) && (count($project.childs) > 0))}{foreach name=fchilds item=child from=$project.childs}<a href="project.php?id={$child.prj_id}">{$child.prj_title|wash}</a>{if !($smarty.foreach.fchilds.last)} | {/if}{/foreach}{else}&nbsp;{/if} </td>
              </tr>
              {if $use_graphviz}
              <tr>
                  <th> {t}Relationship{/t}: </th>
                  <td><img src="prjrelations_graph.php?prj_id={$project.prj_id}" alt="{t}Project relationship{/t}" usemap="#G" /></td>
              </tr>
              {/if}
          </table>
      </div>
      <div class="spacer"></div>
  </div>

  {if count($files) > 0}
  <div id="project-files" class="tab_content">
      {include file="listfiles.tpl.html"}
  </div>
  {/if}

  {if (isset($opcats) && (count($opcats) > 0)) || ($prjmanage && (isset($project.opcatlist) && (count($project.opcatlist) > 0)))}
  <div id="project-task-categories" class="tab_content">

      <div class="floatcontainer">
          <div id="prjopcat" class="opcatchart flleft"></div>

          {if (isset($opcats) && (count($opcats) > 0))}
          <table class="flleft" cellspacing="0">
              <caption><em>{t}Overall{/t}</em></caption>
              <tbody>
                  {section name=opcdet loop=$opcats}
                  <tr>
                      <td>{$opcats[opcdet].opcat_title|wash}:</td>
                      <td class="number">{$opcats[opcdet].opcat_duration|phpaga_minutes2duration}</td>
                  </tr>
                  {/section}
              </tbody>
              <tfoot>
                  <tr class="summary">
                      <td class="label">{t}Total duration{/t}: </td>
                      <td class="data number"> {$project.prj_duration_minutes|phpaga_minutes2duration} </td>
                  </tr>
              </tfoot>
          </table>


          <table class="flleft" cellspacing="0">
              <caption><em>{t}Per person{/t}</em></caption>
              <thead>
                  <tr class="r">
                      <th>&nbsp;</th>
                      {foreach item=pe from=$opcats_person.persons}
                      <th><a href="person.php?id={$pe.pe_id}">{$pe.pe_person|wash}</a></th>
                      {/foreach}
                      <th>{t}Total{/t}</th>
                  </tr>
              </thead>
              <tbody>
                  {foreach key=opckey item=opc from=$opcats_person.opcats}
                  <tr>
                      <td> {$opc.opcat_title|wash} </td>
                      {foreach item=row from=$opcats_person.rows[$opckey]}
                      <td class="time"> {if strlen($row.opcat_duration)}{$row.opcat_duration|phpaga_minutes2duration}{else}&nbsp;{/if} </td>
                      {/foreach}
                      <td class="time"> {$opc.duration|phpaga_minutes2duration} </td>
                  </tr>
                  {/foreach}
              </tbody>
              <tfoot>
                  <tr class="summary">
                      <td>&nbsp;</td>
                      {foreach item=pe from=$opcats_person.persons}
                      <td class="time">{$pe.duration|phpaga_minutes2duration}</td>
                      {/foreach}
                      <td class="time">{$project.prj_duration_minutes|phpaga_minutes2duration}</td>
                  </tr>
              </tfoot>
          </table>
          {/if}

          {if ($prjmanage && (isset($project.opcatlist) && (count($project.opcatlist) > 0)))}
          <table cellspacing="0" class="flleft">
              <caption><em>{t}Task categories: default hourly rates{/t}</em></caption>

              <tbody id="opcatratelist">
                  {section name=opc loop=$project.opcatlist}
                  <tr>
                      <td> {if strlen($project.opcatlist[opc].opcat_color)}<span class="opcol" style="background: {$project.opcatlist[opc].opcat_color|wash};">&nbsp;</span>{else}&nbsp;{/if} </td>
                      <td> {$project.opcatlist[opc].opcat_title|wash} </td>
                      {if strlen($project.opcatlist[opc].opcat_hourlyrate|wash)}
                      <td class="number"> {$project.opcatlist[opc].opcat_hourlyrate|wash} </td>
                      {else}
                      <td>{t}no default rate set{/t}</td>
                      {/if}
                  </tr>
                  {/section}
              </tbody>
          </table>
          {/if}
      </div>
      <div class="spacer"></div>
  </div>
  {/if}

  {if (count($project.prj_members) > 0) || ($prjmanage && isset($project.humancost.details) && (count($project.humancost.details) > 0))}
  <div id="project-members" class="tab_content">
      {if count($project.prj_members) > 0}
      <table cellspacing="0">
          <caption><em>{t}Project members{/t}</em></caption>
          <thead>
              <tr>
                  <th> {t}Member{/t} </th>
                  <th> {t}Role{/t} </th>
                  {if $prjmanage}
                  <th class="number"> {t}Default hourly rate{/t} </th>
                  <th> {t}Actions{/t} </th>
                  {/if}
              </tr>
          </thead>
          <tbody>
              {section name=members loop=$project.prj_members}
              <tr>
                  <td> <a href="person.php?id={$project.prj_members[members].pe_id}">{$project.prj_members[members].pe_person|wash}</a> </td>
                  <td> {$project.prj_members[members].jcat_title|wash} </td>
                  {if $prjmanage}
                  <td class="number"> {if strlen($project.prj_members[members].prjmem_hourlyrate)}{$config.MONETARY_SYMBOL}{$project.prj_members[members].prjmem_hourlyrate|phpaga_formatamount}{/if} </td>
                  <td class="last">
                      <a href="prjmember.php?prj_id={$project.prj_id}&amp;pe_id={$project.prj_members[members].pe_id}&amp;edit={$smarty.const.ACTION_EDIT}"><img src="img/phpaga/edit.png" height="16" width="16" border="0" alt="{t}Edit{/t}" title="{t}Edit{/t}"></a>
                      <a class="ptr" onclick="del_prjmember({$project.prj_id},{$project.prj_members[members].pe_id},'{$project.prj_members[members].pe_person|phpaga_popup_sanitizestr}');"><img src="img/phpaga/delete.png" height="16" width="16" border="0" alt="{t}Delete{/t}" title="{t}Delete{/t}"></a>
                  </td>
                  {/if}
              </tr>
              {/section}
          </tbody>
      </table>
      {/if}

      {if ($prjmanage && isset($project.humancost.details) && (count($project.humancost.details) > 0))}
      <table cellspacing="0">
          <caption><em>{t}Human cost{/t}</em></caption>
          <thead>
              <tr>
                  <th> {t}Person{/t} </th>
                  <th class="number"> {t}Duration{/t} </th>
                  <th class="number"> {t}Cost{/t} </th>
              </tr>
          </thead>
          <tbody>
              {section name=members loop=$project.humancost.details}
              <tr>
                  <td> <a href="person.php?id={$project.humancost.details[members].pe_id}">{$project.humancost.details[members].pe_person|wash}</a> </td>
                  <td class="time"> {$project.humancost.details[members].sum_duration|phpaga_minutes2duration} </td>
                  <td class="number last"> {$config.MONETARY_SYMBOL}{$project.humancost.details[members].amount|phpaga_formatamount} </td>
              </tr>
              {/section}
          </tbody>
          <tfoot>
              <tr>
                  <td> {t}Total{/t} </td>
                  <td class="time"> {$project.humancost.total_duration|phpaga_minutes2duration} </td>
                  <td class="number last"> {$config.MONETARY_SYMBOL}{$project.humancost.total_amount|phpaga_formatamount} </td>
              </tr>
          </tfoot>
      </table>
      {/if}
  </div>
  {/if}

  {if count($project.materials.details) > 0}
  <div id="project-material" class="tab_content">
      <table cellspacing="0">
          <caption><em>{t}Material{/t}</em></caption>
          <thead>
              <tr>
                  <th> {t}Date{/t} </th>
                  <th class="number"> {t}Prod. code{/t} </th>
                  <th> {t}Material{/t} </th>
                  <th> {t}Description{/t} </th>
                  <th> {t}Person{/t} </th>
                  <th class="number"> {t}Qty.{/t} </th>
                  <th class="number"> {t}Price{/t} </th>
                  <th> {t}Actions{/t} </th>
              </tr>
          </thead>
          <tbody>
              {section name=mat loop=$project.materials.details}
              {if ($prjmanage || ($auth_user.pe_id == $project.materials.details[mat].pe_id))}
              <tr>
                  <td> {$project.materials.details[mat].mat_added|date_format:$smarty.const.PHPAGA_DATETIMEFORMAT_SHORT} </td>
                  <td class="number"> {$project.materials.details[mat].mat_prodcode|wash|default:"&nbsp;"} </td>
                  <td> {$project.materials.details[mat].mat_name|wash|default:"&nbsp;"} </td>
                  <td{if ((strlen($project.materials.details[mat].mat_desc|wash) > $smarty.const.PHPAGA_SHOWOPDESCLENGHT))} class="tTip" title="{$project.materials.details[mat].mat_desc|phpaga_popup_sanitizestr}"{/if}>
                      {$project.materials.details[mat].mat_desc|wash|trnc:$smarty.const.PHPAGA_SHOWOPDESCLENGHT:"...":true|default:"&nbsp;"}
                  </td>
                  <td> <a href="person.php?id={$project.materials.details[mat].pe_id}">{$project.materials.details[mat].pe_person|wash}</a> </td>
                  <td class="number"> {$project.materials.details[mat].mat_qty|wash|default:"&nbsp;"} </td>
                  {if $project.materials.details[mat].mat_price}
                  <td class="number"> {$config.MONETARY_SYMBOL}{$project.materials.details[mat].mat_price|wash|phpaga_formatamount|default:"&nbsp;"} </td>
                  {else}<td class="number"></td>{/if}
                  <td class="last"> {strip}
                      {if ($project.materials.details[mat].mat_canedit)}
                      <a class="ptr" onclick="confirm_delete_material({$project.materials.details[mat].mat_id}, '{t}Product code{/t}: {$project.materials.details[mat].mat_prodcode}\n{$project.materials.details[mat].mat_name|phpaga_jsmessage_sanitizestr}\n{$project.materials.details[mat].mat_added|date_format:$smarty.const.PHPAGA_DATETIMEFORMAT_SHORT}');"><img src="img/phpaga/delete.png" height="16" width="16" border="0" alt="{t}Delete{/t}" title="{t}Delete{/t}"></a>
                      {/if}
                      {if (isset($project.materials.details[mat].bill_id) && is_numeric($project.materials.details[mat].bill_id))}
                      <a href="bill.php?id={$project.materials.details[mat].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>
              {/if}
              {/section}
          </tbody>
      </table>
  </div>
  {/if}

  {if count($project.expenses) > 0}
  <div id="project-expenses" class="tab_content">
      <table cellspacing="0">
          <caption><em>{t}Expenses{/t}</em></caption>
          <thead>
              <tr>
                  <th> {t}Description{/t} </th>
                  <th> {t}Date{/t} </th>
                  <th> {t}Person{/t} </th>
                  <th class="number"> {t}Cost{/t} </th>
                  <th> {t}Actions{/t} </th>
              </tr>
          </thead>
          <tbody>
              {section name=exp loop=$project.expenses}
              {if ($prjmanage || ($auth_user.pe_id == $project.expenses[exp].pe_id))}
              <tr>
                  <td{if ((strlen($project.expenses[exp].exp_desc) > $smarty.const.PHPAGA_SHOWOPDESCLENGHT))} class="tTip" title="{$project.expenses[exp].exp_desc|phpaga_popup_sanitizestr}"{/if}>
                      {$project.expenses[exp].exp_desc|wash|trnc:$smarty.const.PHPAGA_SHOWOPDESCLENGHT:"...":true}
                  </td>
                  <td> {$project.expenses[exp].exp_date|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT} </td>
                  <td> <a href="person.php?id={$project.expenses[exp].pe_id}">{$project.expenses[exp].pe_person}</a> </td>
                  <td class="number"> {$config.MONETARY_SYMBOL}{$project.expenses[exp].exp_sum|phpaga_formatamount} </td>
                  <td class="last">
                      {if ($prjmanage && !strlen($project.expenses[exp].bill_id))}
                      <a class="ptr" onclick="confirm_delete_exp({$project.prj_id}, {$project.expenses[exp].exp_id});"><img src="img/phpaga/delete.png" height="16" width="16" border="0" alt="{t}Delete{/t}" title="{t}Delete{/t}"></a>
                      {elseif $perm_invoices}
                      <a href="bill.php?id={$project.expenses[exp].bill_id}"><img src="img/phpaga/bill.png" height="16" width="16" border="0" alt="{t}View invoice{/t}" title="{t}View invoice{/t}"></a>
                      {else}
                      <img src="img/phpaga/bill.png" height="16" width="16" border="0" alt="{t}Invoiced{/t}" title="{t}Invoiced{/t}">
                      {/if}
                  </td>
              </tr>
              {/if}
              {/section}
          </tbody>
      </table>
  </div>
  {/if}

  {if (isset($project.operations) && (count($project.operations) > 0))}
  <div id="project-tasks" class="tab_content">
      <div id="opdetails"> </div>
      <table cellspacing="0">
          <caption><em>{t}Tasks{/t}</em></caption>
          <thead>
              <tr>
                  <th> {t}Task{/t} </th>
                  <th> {t}Date{/t} </th>
                  <th> {t}Person{/t} </th>
                  <th> {t}Category{/t} </th>
                  <th class="number"> {t}Hours{/t} </th>
                  <th> {t}Actions{/t} </th>
              </tr>
          </thead>
          {*    {if !$ophide} *}
          <tbody>
              {section name=projects loop=$project.operations}
              <tr id="oprow{$project.operations[projects].op_id}">
                  <td{if ((strlen($project.operations[projects].op_desc) > $smarty.const.PHPAGA_SHOWOPDESCLENGHT))} class="tTip" title="{$project.operations[projects].op_desc|phpaga_popup_sanitizestr}"{/if}>
                      {$project.operations[projects].op_desc|wash|trnc:$smarty.const.PHPAGA_SHOWOPDESCLENGHT:"...":true}
                  </td>
                  <td> {$project.operations[projects].op_startdate|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT} </td>
                  <td> <a href=person.php?id={$project.operations[projects].pe_id}>{$project.operations[projects].op_person|wash}</a> </td>
                  <td> {$project.operations[projects].opcat_title|wash} </td>
                  <td class="time"> {$project.operations[projects].op_duration_hrs} </td>
                  <td class="last"> {strip}
                      <a class="tview" id="tv{$project.operations[projects].op_id}" href="#"><img id="vimg{$project.operations[projects].op_id}" src="img/phpaga/view.png" height="16" width="16" border="0" alt="{t}View{/t}" title="{t}View{/t}"></a>
                      {if ($project.operations[projects].op_canedit)}
                      <a href="operation.php?id={$project.operations[projects].op_id}"><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{$project.operations[projects].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 (isset($project.operations[projects].bill_id) && is_numeric($project.operations[projects].bill_id))}
                      <a href="bill.php?id={$project.operations[projects].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}
          </tbody>
          {*    {/if}*}
      </table>
  </div>
  {/if}
</div>

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

    <form action="add_bill.php" method="get" id="invoiceboxfrm" name="invoiceboxfrm">
        <input type="hidden" name="prj_id" value="{$project.prj_id}" />
        <input type="hidden" name="cpn_id" value="{$project.cpn_id}" />
        <input type="hidden" name="action" value="{$smarty.const.ACTION_BILL_FROMPROJECT}" />
        <input type="hidden" name="op_billabletype" value="0" />

        <table cellspacing="0">
            <tr>
                <td class="label">{t}Add unbilled material{/t}</td>
                <td class="data">
                    <input type="checkbox" name="add_material" />
                </td>
            </tr>
            <tr>
                <td class="label">{t}Add unbilled expenses{/t}</td>
                <td class="data">
                    <input type="checkbox" name="add_expenses" />
                </td>
            </tr>
            <tr>
                <td class="label">{t}Add unbilled manhours{/t}</td>
                <td class="data">
                    <input type="checkbox" name="add_manhours" id="chk_manhours" /> <br />
                    <input type="radio" name="singlemulti" value="1" id="sm1" disabled="disabled"> {t}Single line item for all tasks{/t} <br />
                    <input type="radio" name="singlemulti" value="2" id="sm2" checked="checked" disabled="disabled"> {t}One line item for each task{/t}
                </td>
            </tr>
            <tr>
                <td class="label">{t}Additional information to add{/t}</td>
                <td class="data">
                    <input type="text" name="bill_additional_line" id="additional_line" size="40" maxlength="255" value="{$config.LETTERHEAD_ADDITIONAL_LINE}" /> <br />
                </td>
            </tr>
        </table>

    </form>
</div>


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