<?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"];
    $date = $_REQUEST["fdate"];
    $end_date = $_REQUEST["tdate"];
    $name = $_REQUEST["name"];

    $hide_var = "";
    if ($hide == 0) {
        $hide_var = 'style="display:none;"';
    }
    $mctr = $ctr;
    $mctr++;
    while (strtotime($date) <= strtotime($end_date)) {

        $gdate = mysqli_query($conn,"SELECT DAYNAME('$date') as day")or die(mysqli_error($conn));
        ($fdate = mysqli_fetch_array($gdate));

        $gattend = mysqli_query($conn,"SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') as mydt FROM `attend` WHERE `vouchdt` = '$date' AND staff = '$name'")or die(mysqli_error($conn));
        ($attend = mysqli_fetch_array($gattend));

        Echo "<tr>";
        echo "<td><input type='date' class='form-control fdate' name='vouchdt_$ctr' value='$date'></td>";
        Echo "<td><input type='text' class='form-control form day' name='day_$ctr' value='$fdate[day]'></td>";
        var_dump($day);

//        Echo "<td><select class='form-control form ' name='staff_$ctr'>";
//        echo "<option value='$stafname[code]'>$stafname[name]</option>";
//        $gstaff = mysqli_query($conn,'SELECT `code`,`name` FROM `staff` WHERE `code` != "" order by name')or die(mysqli_error($conn));
//        while ($staff = mysqli_fetch_array($gstaff)) {
//            Echo "<option value='$staff[code]'>$staff[name]</option>";
//        }
//        Echo "</select></td>";

        Echo "<td><input type='number' class='form-control form text-right salhrs'      name='salhrs_$ctr'      value='0' readonly></td>";
        Echo "<td><input type='number' class='form-control form text-right hours'      name='hours_$ctr'      value='$attend[hours]'></td>";
        Echo "<td><input type='number' class='form-control form text-right advance'      name='advance_$ctr'      value='$attend[advance]'></td>";
        Echo "<td><input type='text' class='form-control form remarks'      name='remarks_$ctr'      value='$attend[remark]' ></td>";
        Echo "</tr>";
        $date = date("Y-m-d", strtotime("+1 day", strtotime($date)));
        $ctr++;
    }
    Echo "<input type='hidden' class='form-control form lasctr'      name='ctr'      value='$ctr'></td>";
} else {
    echo "ERROR";
}
?>