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

{if isset($STATUSMSG) && strlen($STATUSMSG)}
{$STATUSMSG}
{/if}

<script type="text/javascript" src="js/material.js"></script>

<form action="{$smarty.const.PHPAGA_SELF}" method="post" name="form">
<input type="hidden" name="mat_id" value="{$matinfo.mat_id}">
<input type="hidden" name="prj_id" value="{$matinfo.prj_id}">

{if (!is_array($select_person)) || (count($select_person) == 0)}
<div class="msg">
{if $is_owner_or_manager}
{t}Materials can only be tracked for members. This project does currently not have any members.{/t}
{else}
{t}You are not a member of this project.{/t}
{/if}
</div>
{else}

<script type="text/javascript" src="js/billing.js"></script>
<script type="text/javascript" src="js/material.js"></script>

<table class="stdtable" cellspacing="0">
  <caption><em>{if !strlen($matinfo.mat_id)}{t}Add material{/t}{else}{t}Edit material{/t}{/if}</em></caption>
  <tr>
    <th colspan="4">{t}Project{/t}</th>
  </tr>

  <tr>
    <td class="label"> {t}Project{/t}: </td>
    <td class="data" colspan="3"> <a href="project.php?id={$prjInfo.prj_id}">{$prjInfo.prj_title|wash|default:"&nbsp;"}</a> </td>
  </tr>
  <tr>
    <td class="label"> {t}Customer{/t}: </td>
    <td class="data" colspan="3"> <a href="company.php?id={$prjInfo.cpn_id}">{$prjInfo.cpn_name|wash|default:"&nbsp;"}</a> </td>
  </tr>
  <tr>
    <td class="label"> {t}Start date{/t}: </td>
    <td class="data"> {$prjInfo.prj_startdate|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_LONG|default:"&nbsp;"} </td>
    <td class="label"> {t}Projected end{/t}: </td>
    <td class="data"> {$prjInfo.prj_estimatedend|wash|default:"&nbsp;"} </td>
  </tr>
  <tr>
    <td class="label"> {t}Category{/t}: </td>
    <td class="data"> {$prjInfo.prjcat_title|wash|default:"&nbsp;"} </td>
    <td class="label"> {t}Hours{/t}: </td>
    <td class="data"> {$HOURS_SO_FAR|default:"&nbsp;"} </td>
  </tr>

  <tr>
    <th colspan="4">{t}Material{/t}</th>
  </tr>

  <tr>
    <td class="label"> {t}Person{/t}: </td>
    <td class="data" colspan="3">
      <select name="pe_id">
        {html_options options=$select_person selected=$matinfo.pe_id}
      </select>
    </td>
  </tr>

  <tr>
    <td class="label"> {t}Product code{/t}: </td>
    <td class="data">
      <input type="text" class="tinput" name="mat_prodcode" value="{$matinfo.mat_prodcode|wash}" size="18" maxlength="18" id="mat_prodcode" onblur="getMatProdInfo();">
      <input type="hidden" name="prod_id" value="{$matinfo.prod_id|wash}" id="prod_id">
      <a class="ptr" onclick="materialGetProductCatalog(1)"><img alt="{t}Products{/t}" src="img/phpaga/catalog.png" width="16" height="16"></a>

    </td>
    <td class="label"> {t}Qty.{/t}: </td>
    <td class="data">
      <input type="text" class="tinput" name="mat_qty" value="{$matinfo.mat_qty|wash}" size="4" maxlength="10" id="mat_qty">
    </td>
  </tr>

  <tr>
    <td class="label"> {t}Material{/t}: </td>
    <td class="data" colspan="3">
      <input type="text" class="tinput" name="mat_name" value="{$matinfo.mat_name|wash}" size="60" maxlength="100" id="mat_name">
    </td>
  </tr>

  <tr>
    <td class="label"> {t}Price{/t}: </td>
    <td class="data">
      <input type="text" class="tinput" name="mat_price" value="{$matinfo.mat_price|wash}" size="12" maxlength="12" id="mat_price">
    </td>
    <td class="label"> {t}Currency{/t}: </td>
    <td class="data">
      <select name="curr_id">
        {html_options options=$select_curr selected=$matinfo.curr_id}
      </select>
    </td>
  </tr>
  <tr>
    <td class="label"> {t}Description{/t}: </td>
    <td class="data" colspan="3">
      <textarea name="mat_desc" cols="50" rows="6" wrap="virtual">{$matinfo.mat_desc|wash}</textarea>
    </td>
  </tr>
  <tr>
    <td colspan="4"><input type="submit" name="submit" value="{t}Submit{/t}"> <input type="button" onclick="location.href='project.php?id={$prjInfo.prj_id}';" value="{t}Cancel{/t}"></td>
  </tr>
</table>

<div id="prodselectbox">
  <input type="hidden" id="prodselectdest" name="prodselectdest" value="">
  <table class="stdtable prodselect" cellspacing="0">
    <caption><em>{t}Products{/t}</em>
      <a class="ptr" onclick="hideElement('prodselectbox');"><img src="img/phpaga/close.png" alt="X" title="{t}Close{/t}"></a>
    </caption>
    <tr>
      <th> {t}Product code{/t} </th>
      <th> {t}Name{/t} </th>
      <th> {t}Price{/t} </th>
      <th> {t}Stock{/t} </th>
      <th> {t}Category{/t} </th>
    </tr>
    {section name=pr loop=$products}
    <tr class="{cycle values="odd,even"} pointer" onclick="materialSelectProduct('{$products[pr].prod_code|wash}');">
      <td> {$products[pr].prod_code|wash|default:"&nbsp;"} </td>
      <td> {$products[pr].prod_name|wash|default:"&nbsp;"} </td>
      <td class="number"> {$products[pr].prod_price|wash|phpaga_formatamount|default:"&nbsp;"} </td>
      <td class="number"> {$products[pr].prod_stock|wash|default:"&nbsp;"} </td>
      <td> {$products[pr].prcat_title|wash|default:"&nbsp;"} </td>
    </tr>
    {/section}
  </table>
</div>

</form>

{literal}
<script type="text/javascript">
document.getElementById('mat_prodcode').focus();
</script>
{/literal}

{/if}

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