<?php

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

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

$sid = $_POST["sid"];
if ($sid == "today") {
    $dt = date("Y-m-d");
} else {
    $dt = "$sid";
}
$pdt = date("d-m-Y", strtotime($dt));
echo "<tr >";
echo "<td colspan='7'>";
echo "<b style='color:#0165a0;font-weight:bolder;font-size:20px'>Date : $pdt</b>";
echo "</td>";
echo "</tr>";

echo "<tr class='' style='background-color:#85899e'>";
echo " <td class='font-weight-bolder text-center' style='color:white; font-size: 18px;width:5%'>Sr.</td>";
echo "<td class='font-weight-bolder ' style='color:white;font-size: 18px;width:20%'>Name</td>";
echo "<td class='font-weight-bolder ' style='color:white;font-size: 18px;width:10%'>Time</td>";
echo "<td class='font-weight-bolder ' style='color:white;font-size: 18px;width: 16%;'>Purpose</td>";
echo "<td class='font-weight-bolder ' style='color:white;font-size: 18px;width: 15%;'>Reffered By</td>";
echo "<td class='font-weight-bolder ' style='color:white;font-size: 18px;width: 7%;'>Status</td>";
echo "<td class='font-weight-bolder ' style='color:white;font-size: 18px;width: 35%;'>Remark</td>";
echo "</tr>";
$getscedule = mysqli_query($conn, "SELECT a.*, b.acttype, b.name, b.accode FROM `schedtreat`a
                    LEFT JOIN accmast b ON a.accode=b.accode where a.scheddate='$dt' order by apttime ASC") or die(mysqli_error($conn));
$tctr = 0;
while ($scedule = mysqli_fetch_array($getscedule)) {
    $purpvis = $scedule['purpvisit'];
    if ($scedule['treatment'] > 0) {
        $gettt = mysqli_query($conn, "SELECT code,name FROM `treatment` WHERE `code`='$scedule[treatment]'") or die(mysqli_error($conn));
        if (mysqli_num_rows($gettt) > 0) {
            $tcode = mysqli_fetch_array($gettt);
            $treatname = $tcode['name'];
            $purpvis = $treatname . " Appointment";
        }
    }
    $status = "";
    $bgcolor = "";

    if ($scedule['consult'] == 1) {
        $status = "Done";
        $bgcolor = "background-color:#10cc61";
    }
    $ctr++;
    echo "<tr class='ts-entry ' style='background-color:#0165a0'>";
    echo "<td class='font-weight-bolder text-center' style='color:white; font-size: 14px;'>$ctr</td>";
    echo "<td class='font-weight-bolder ' style='color:white;font-size: 14px;'>$scedule[name]</td>";
    echo "<td class='font-weight-bolder ' style='color:white;font-size: 14px;'>$scedule[apttime]</td>";
    echo "<td class='font-weight-bolder ' style='color:white;font-size: 14px;'>$purpvis</td>";
    echo "<td class='font-weight-bolder ' style='color:white;font-size: 14px;'>$scedule[refby]</td>";
    echo "<td class='font-weight-bolder ' style='color:white;font-size: 14px;$bgcolor'>$status</td>";
    echo "<td class='font-weight-bolder ' style='color:black;background-color:white;font-size: 14px;'>$scedule[remarks]";
//    echo "<input type='text' name='remarks_$tctr' value='$scedule[remarks]'>";
    echo "<input type='hidden' class='acttype' name='acttype_$tctr' value='$scedule[acttype]'>";
    echo "<input type='hidden' class='vouchno' name='vouchno_$tctr' value='$scedule[vouchno]'>";
    echo "<input type='hidden' class='accod' name='accod_$tctr' value='$scedule[accode]'>";
    echo "</td>";
//    echo "<td class='font-weight-bolder ' ><button type='button' class='btn btn-secondary'>Edit</td>";
    echo "</tr>";
    $tctr++;
}
?>