<?php

ob_start();
error_reporting(E_ALL);
require("includes/check_auth_user.php");

require("includes/dbconnect.php");
include ('includes/function.php');

$zdb = $_SESSION["zdbyear_$dbname"];
mysqli_select_db($conn, $zdb);

if ($_REQUEST["ctr"]) {
    $ctr = $_REQUEST["ctr"];
    $mctr = $ctr;
    $mctr++;

    echo "<tr>";
    echo '<td align="center" valign="top"><input type="image" src="images/delbut.png" name="remove" class="remove form" value="remove"></td>';
    echo "<td align='left' valign='top'><input type='text' size='6' maxlength='6' name='srno_$ctr' class='sno form-control form' style='height:33px;' value='$mctr'/></td>";

    echo "<td align='left'>";
    echo "<input list='descrip_$ctr' name='descrip_$ctr' class='descrip form-control form'  value='' style='height:33px;'>";
    echo "<datalist id='descrip_$ctr'>";
    echo "<option value=''>";
    $mdesc2 = mysqli_query($conn, "SELECT `name` FROM `item` ORDER BY `code`") or die(mysqli_error($conn));
    while ($trow2 = mysqli_fetch_array($mdesc2)) {
        echo "<option value='$trow2[name]'>";
    }
    echo "</datalist>";
    echo "</td>";
    echo "<td align='right' valign='top'><input type='text' size='4'  name='qty_$ctr' class='qty form-control form'  style='text-align:right;height:33px;' value='0'></td>";
    echo '<td align="left">';
    echo "<input list='unit_$ctr' name='unit_$ctr'  class='unit form-control form' style='height:33px;'>";
    echo "<datalist id='unit_$ctr'>"; 
    echo '<option value=""></option>';
    $munit2 = mysqli_query($conn, "SELECT `name` FROM `unit` ORDER BY `code`") or die(mysqli_error($conn));
    while ($trow5 = mysqli_fetch_array($munit2)) {
        echo "<option value='$trow5[name]'>";
    }
    echo '</datalist>';
    echo '</td>';
    echo "<td align='right' valign='top'><input type='text' size='4'  name='rate_$ctr' class='rate form-control form'  style='text-align:right;height:33px;' value='0'></td>";
    echo "<td align='right' valign='top'><input type='text' size='4'  name='amt_$ctr' class='amt form-control form'  style='text-align:right;height:33px;' value='0' readonly></td>";

    echo "</tr>";
    $ctr++;
} else {
    echo "ERROR";
}
?>
