<?php

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

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

if ($_REQUEST["ctr"]) {
    $ctr = $_REQUEST["ctr"];
    $hide = $_REQUEST["hide"];
    $hide_var = "";
    if ($hide == 0) {
        $hide_var = 'style="display:none;"';
    }
    $mctr = $ctr;
    $mctr++;

    echo "<tr>";
    echo "<td></td>";
    echo "<td><input type='text' class='form-control form srno' value='$mctr' name='srno_$ctr'></td>";
    echo "<td>";
    echo "<input list='treatment' name='treatment_$ctr' class='treatment form-control form focusFld_$ctr' autocomplete='off' value=''> ";
    echo "<datalist id='treatment' char='#'>";
    echo "<option>";

    $mit = mysqli_query($conn, "SELECT `name` FROM `treatment` group by name order by name") or die(mysqli_error($conn));

    while ($tit = mysqli_fetch_array($mit)) {
        $itname = $tit['name'];
        echo "<option value='$itname'>";
    }

    echo "</datalist>";
    echo "</td>";
//    echo "<td>";
//    echo "<select id='treatment' name='treatment_$ctr' class='form-control treatment form select2 fetchpart_$ctr' style='width:100%'>";
//    echo "<option></option>";
//    $mown = mysqli_query($conn, "SELECT code, `name` FROM `treatment` order by name") or die(mysqli_error($conn));
//    while ($trow = mysqli_fetch_array($mown)) {
//        echo "<option value='$trow[code]'>$trow[name]</option>";
//    }
//    echo "</select>";
//    echo "</td>";
    echo "<td><input type='text' class='form-control form text-right qty' value='0' name='qty_$ctr'></td>";
    echo "<td><input type='text' class='form-control form text-right duration' value='0' name='tduration_$ctr'></td>";
    
    echo "<td><input type='text' class='form-control form remarks' value='' name='tremarks_$ctr'></td>";
//    echo "<td><input type='textbox' name='treatrate_$ctr' class='treatrate text-right form-control form' value='0' readonly></td>";
//    echo "<td><input type='textbox' name='treatamt_$ctr' class='treatamt text-right form-control form' value='0'  readonly tabindex='-1'></td>";
//    echo "<td>";
//    echo "<input type='checkbox' name='aprov_$ctr' class='aprov form-control form' value='1' style='height:25px;width:25px'>";
//    echo "</td>";
//    echo "<td><input type='date' class='form-control form firstdate' value='' name='firstdate_$ctr'></td>";
//    echo "<td><input type='textbox' name='aprvqty_$ctr' class='aprvqty text-right form-control form' value='0' ></td>";
//    echo "<td><input type='textbox' name='rate_$ctr' class='rate text-right form-control form' value='0' ></td>";
//    echo "<td><input type='textbox' name='amt_$ctr' class='amt text-right form-control form' value='0'  readonly tabindex='-1'></td>";
    echo "</tr>";
    $ctr++;
} else {
    echo "ERROR";
}
?>