<?php include ('header1f.php');?><?php 
// Get the current year and month
$currentYear = date('Y');
$currentMonth = date('m');

// Check if there's a specific week requested, default is current week
if (isset($_GET['week'])) {
    $selectedWeek = strtotime($_GET['week']);
} else {
    $selectedWeek = strtotime('this week');
}

// Calculate the start date of the selected week (Monday)
$startDate = date('Y-m-d', strtotime('monday', $selectedWeek));

// Calculate the end date of the selected week (Sunday)
$endDate = date('Y-m-d', strtotime('sunday', $selectedWeek));

// Generate an array of days in the selected week
$daysInWeek = [];
$currentDate = $startDate;
while ($currentDate <= $endDate) {
    $daysInWeek[] = $currentDate;
    $currentDate = date('Y-m-d', strtotime('+1 day', strtotime($currentDate)));
}
?>

<div class="content-page">
<div class="content">
<div class="container">

<div class="row">
<div class="col-sm-12">
<div class="page-header-title">
<button type="button" class="btn btn-dark  waves-effect waves-light" onclick="location.href='index.php'">BACK </button>
<button type="button" class="btn btn-primary  waves-effect waves-light" onclick="location.href='therapy_chart.php'">THERAPY APPOINTMENT</button>
<div class="clearfix"></div>
</div>
</div>
</div>

<div class="row">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-heading">
 <h3>Weekly Calendar <span style="font-size:14px; float:right">
        <a href="?week=<?php echo date('Y-m-d', strtotime('-1 week', $selectedWeek)); ?>"  class="btn btn-dark  waves-effect waves-light">Previous Week</a>
        <span><?php echo date('D, d M Y', strtotime($startDate)); ?> - <?php echo date('D, d M Y', strtotime($endDate)); ?></span>
        <a href="?week=<?php echo date('Y-m-d', strtotime('+1 week', $selectedWeek)); ?>"  class="btn btn-dark  waves-effect waves-light">Next Week</a></span>
 </h3>
</div>
<div class="panel-body">


   
    <table  id="datatable-buttons" class="table table-striped table-bordered">
        <thead>
            <tr> <th>Timming</th>
                <?php foreach ($daysInWeek as $day): ?>
                    <th><?php echo date('l', strtotime($day)); ?></th>
                <?php endforeach; ?>
            </tr>
        </thead>
        <tbody><?php $queryls1q = "select * from time_slot";
$resultls1q  = mysqli_query($conn,$queryls1q);	
while($row=mysqli_fetch_array($resultls1q))
{ $time_slot = $row['time_slot'];
?>
            <tr><td><?php echo $time_slot?></td>
                <?php foreach ($daysInWeek as $day): ?>
                    <td>
                        <?php
						
						
						$queryls1 = "select * from therapy_chart_more where appointment_date='$day' and appointment_time='$time_slot'";
$resultls1  = mysqli_query($conn,$queryls1);	
while($row=mysqli_fetch_array($resultls1))
{
$patient_name = $row['patient_name'];
$therapy_name = $row['therapy_name'];
$therapist_name =  $row['therapist_name'];
$appointment_time = $row['appointment_time'];

                        // Replace this with your logic to fetch and display data for each day
                       ?><?php echo $therapist_name?><br /><?php echo $patient_name?><br /><?php echo $therapy_name; }?>
                    </td>
                <?php endforeach; ?>
            </tr><?php } ?>
        </tbody>
    </table></div></div></div></div></div></div>
<?php include 'footer1a.php';?>
