<head>
<!--style sheets-->
<link rel="stylesheet" href="../window/dhtmlwindow.css" type="text/css" />
<link rel="stylesheet" href="../window/modal.css" type="text/css" />

<!--jscript-->
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script> 
<script type="text/javascript" src="../window/dhtmlwindow.js"></script>
<script type="text/javascript" src="../window/modal.js"></script>
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>


<?php
$screen = $_GET['screen'];

$table_name = $_SESSION['db_prefix']."_captured_sundries";
$table_name2 = $_SESSION['db_prefix']."_captured_sundries_temp";
$additional_query = "SELECT * FROM $table_name WHERE cap_job = '".$_SESSION['job_no']."' UNION ALL SELECT * FROM $table_name2 WHERE cap_job = '".$_SESSION['job_no']."' AND user =  '".$_SESSION['username']."' ";
$additional_result = mySQL_query($additional_query);
$additional_num = mysql_num_rows($additional_result);

?>

</head>

<?php include('../include/wait.php') ?>

<body onLoad="MM_showHideLayers('wait','','hide'); <?php if ($screen==1) { ?>editwindow=dhtmlmodal.open('editBox', 'iframe', '../edit_windows/authorisation_add.php?category=Direct materials&sub_category=Sundries', 'Add item', 'width=500px,height=220px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false; <?php } ?> <?php if ($_SESSION['error_5']==1) {?>alertMessage(2, 'authorisationWizbase.php?p=5&s=', 'This item is already in the list and will not be added to the list.<br><br>If you require additional quantity, you should <br>edit the quantity in the list.');<?php }; $_SESSION['error_5']=0 ?>" onFocus="MM_showHideLayers('wait','','hide');" onBlur="<?php if ($_SESSION['s']=='13') { ?> needToConfirm = false; <?php } ?> ">

<div class="page_middle_frame">
<form action="authorisationWizbase.php" method="get">

        <div class="scroll_frame_medium" style="height:340px; width:640px;">
          <table width="599">
            <tr>
              <td colspan="5"><label class="label_std" style="font-size:14px;">Additional sundries:</label></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td colspan="2"><label class="label_std">Captured</label></td>
              <td><label class="label_std">Authorised</label></td>
            </tr>
            <?php 
				  $m=0;
				  $_SESSION['list_6'] = $additional_num;
				  while ($m<$additional_num) { 
				        $_SESSION['additional_line'.$m] = mysql_result($additional_result, $m, "cap_sundries_id");
					    $_SESSION['additional_item_id'.$m] = mysql_result($additional_result, $m, "cap_item_id");
						
						if ($_SESSION['start5']==0) {
							
							
						if ($_SESSION['additional_quantity_'.$m]=='') {
						       $_SESSION['additional_quantity_'.$m] = mysql_result($additional_result, $m, "cap_quantity");
						}
						if ($_SESSION['additional_quantity_'.$m]=='0') {
						       $_SESSION['additional_quantity_'.$m] = mysql_result($additional_result, $m, "auth_quantity");
						}
						
						}
						
						if ($_SESSION['additional_line'.$m]=='0') {
							 
							     $_SESSION['additional_quantity_'.$m] = mysql_result($additional_result, $m, "auth_quantity");
						}
						$_additional_quantity = mysql_result($additional_result, $m, "cap_quantity");
						$table_name = $_SESSION['db_prefix']."_store_items";
						$item_name_query = "SELECT item_name, unit FROM $table_name WHERE store_item_id = '".$_SESSION['additional_item_id'.$m]."' ";
						$item_name_result = mySQL_query($item_name_query);
						$item_name_num = mysql_num_rows($item_name_result);
						if ($item_name_num!=0) {
						$item_name = mysql_result($item_name_result, 0, "item_name"); 
						$unit = mysql_result($item_name_result, 0, "unit"); 
						}
								
				 ?>
            <tr>
              <td colspan="2"><label class="label_std" ><?php echo $item_name ?>
                <input type="hidden" name="additional_line_<?php echo $m?>" id="additional_line_<?php echo $m?>" value="<?php echo $_SESSION['additional_line'.$m] ?>">
                <input type="hidden" name="additional_item_id_<?php echo $m?>" id="additional_item_id_<?php echo $m?>" value="<?php echo $_SESSION['additional_item_id'.$m] ?>">
                <input type="hidden" name="additional_num" id="additional_num" value="<?php echo $additional_num?>">
              </label></td>
              <td width="32" align="right"><?php echo $_additional_quantity ?></td>
              <td width="32">&nbsp;&nbsp;<?php echo $unit ?></td>
              <td width="249"><input name="additional_quantity_<?php echo $m?>" type="text" class="text60" id="additional_quantity_<?php echo $m?>" style="text-align:right" onKeyPress="return numbersonly(this, event)"  value="<?php echo $_SESSION['additional_quantity_'.$m] ?>">
&nbsp;&nbsp;<?php echo $unit ?></td>
            </tr>
                        <?php
			  $m++;
             }
             ?>
             <tr>
              <td colspan="5"><input type="submit" name="Submit" id="button" class="imagebutton" value="Add" onClick="needToConfirm=false; this.form.action='authorisationWiz5_save.php';  MM_showHideLayers('wait','','show');">
              </td>
            </tr>
          </table>
      </div>
      
      <div class="wizard_frame" style="border:hidden;">
      <table width="590" height="50" align="left" id="table_button_bar">
        <tr>
          <td width="117"><input type="button" name="lastprev_button" class="imagebutton" value="Prev" onClick="needToConfirm = false;MM_showHideLayers('wait','','show');MM_goToURL('parent','authorisationWizbase.php?s=&amp;p=4');return document.MM_returnValue"  tabindex="3"/></td>
          <td width="115">&nbsp;</td>
          <td width="99"><input name="p" type="hidden" id="p" value="5" />
            <input name="s" type="hidden" id="s" value="5" />
            </span></td>
          <td width="125" align="right"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false; cancel_confirmation(1, '../production/production_main.php');" value="Cancel" /></td>
          <td width="110" align="right"><input type="submit" name="next_button" class="imagebutton" value="Next" onClick="needToConfirm = false; MM_showHideLayers('wait','','show'); " /></td>
        </tr>
      </table>
      </div>
</form>
</div>
</body>      