<?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"];
    $dosage = $_REQUEST["dosage"];
    $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='medicine' name='medicine_$ctr' class='medicine form-control form ' autocomplete='off' value=''> ";
    echo "<datalist id='medicine' char='#'>";
    echo "<option>";

    $mit2 = mysqli_query($conn, "SELECT `name` FROM `product` group by name") or die(mysqli_error($conn));

    while ($tit2 = mysqli_fetch_array($mit2)) {
        $itname2 = $tit2['name'];
        echo "<option value='$itname2'>";
    }

    echo "</datalist>";
    echo "</td>";
    echo "<td>";
    echo "<input list='dosage' name='dosage_$ctr' class='dosage form-control form ' autocomplete='off' value='' maxlength='20'> ";
    echo "<datalist id='dosage' char='#'>";
    echo "<option>";

    $mitd = mysqli_query($conn, "SELECT `dosage` FROM `consultmed` group by dosage order by dosage") or die(mysqli_error($conn));

    while ($titd = mysqli_fetch_array($mitd)) {
        $itnamed = $titd['dosage'];
        echo "<option value='$itnamed'>";
    }

    echo "</datalist>";
    echo "</td>";
    //    
//    $getdosage = mysqli_query($conn, "SELECT `dosage` FROM `consultmed` group by dosage order by dosage DESC") or die(mysqli_error($conn));
//    $fetdosage = mysqli_fetch_array($getdosage);
//    $dosage = $fetdosage['dosage'];
//    echo "<td><input type='text' class='form-control form dosage' value='$dosage' name='dosage_$ctr'></td>";

    echo "<td><input type='text' class='form-control form text-right duration' value='' name='duration_$ctr'></td>";
//    echo "<td>";
//    echo "<select id='medfor' name='medfor_$ctr' class='form-control medfor form' style='width:100%'>";
//    echo "<option value=''></option>";
//    $mitG = mysqli_query($conn, "SELECT `name` FROM `medfor` order by name") or die(mysqli_error($conn));
//    while ($titG = mysqli_fetch_array($mitG)) {
//        $itnameG = $titG['name'];
//        echo "<option value='$itnameG'>$itnameG</option>";
//    }
//    echo "</select>";
//
//    echo "</td>";
    echo "<td style='padding-left:2.5%'>";
    echo "<input type='checkbox' name='medhair_$ctr' class='medhair form-control form' value='1' style='height:25px;width:25px'>";
    echo "</td>";
    echo "<td style='padding-left:2.5%'>";
    echo "<input type='checkbox' name='medskin_$ctr' class='medskin form-control form' value='1' style='height:25px;width:25px'>";
    echo "</td>";
    echo "<td style='padding-left:2.5%'>";
    echo "<input type='checkbox' name='daytake_$ctr' class='daytake form-control form' value='1' style='height:25px;width:25px'>";
    echo "</td>";
    echo "<td style='padding-left:2.5%'>";
    echo "<input type='checkbox' name='ngttake_$ctr' class='ngttake form-control form' value='1' style='height:25px;width:25px'>";
    echo "</td>";
    //    echo "<td><input type='text' class='form-control form text-right mqty' value='0' name='mqty_$ctr'></td>";
    //    echo "<td><input type='text' class='form-control form text-right mrate' value='0' name='mrate_$ctr'></td>";
    //    echo "<td><input type='text' class='form-control form text-right mamt' value='0' name='mamt_$ctr'  readonly></td>";
    echo "</tr>";
    $ctr++;
} else {
    echo "ERROR";
}
