<?php include ('header1f.php');?>
<script src="js/jquery-3.5.1.min.js"></script>
<link rel="stylesheet" href="jquery-ui.css">
<script src="jquery.min.js"></script>
<script src="jquery-ui.js"></script>
<?php 
date_default_timezone_set('Asia/Calcutta');
$today = date("d/m/Y");
$today3 = date("Y-m-d");
$today1 = date("d/m");

$startDate = date('Y-m-d', strtotime('monday this week'));

// Define the end date of the week
$endDate = date('Y-m-d', strtotime('sunday this week'));

// Generate an array of days in the 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">
<form name="chkForm" id="chkForm" action="insert_therapy_chart.php"  method="post" >



<div class="row">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Therapy Chart</h3>
</div>
<div class="panel-body">
<div class="col-sm-3 col-xs-12">
<div class="form-group">
<label><b>Therapy  Date</b></label>
<select name="day" class="form-control select2" id="state">
<option value="" selected="selected">Select Date</option>
    <?php
    // Get today's date
    $today = date('Y-m-d');

    // Get the current month and year
    $currentMonth = date('m');
    $currentYear = date('Y');
    $numDays = date('t');

    // Loop through the days of the current month and generate options for each day
    for ($day = 1; $day <= $numDays; $day++) {
        // Format the day with leading zero if necessary
        $formattedDay = sprintf('%02d', $day);
        
        // Get the day of the week for the current date
        $dayOfWeek = date('w', mktime(0, 0, 0, $currentMonth, $day, $currentYear));
        // Convert the day of the week number to its corresponding name
        $dayName = date('l', mktime(0, 0, 0, $currentMonth, $day, $currentYear));
        // Format the date in "DayName, dd-mm-yyyy" format
        $formattedDate = "$dayName, $formattedDay-$currentMonth-$currentYear";
		$formattedDate1 = "$currentYear-$currentMonth-$formattedDay";

        // Check if the date is greater than or equal to today's date
        $dateToCompare = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $day, $currentYear));
        if ($dateToCompare >= $today) {
            echo "<option value='$formattedDate1'>$formattedDate</option>";
        }
    }
?>

</select>
</div>
</div>

<div class="col-sm-9 col-xs-12">
<div class="form-group"  id="city">

</div>
</div>







 <div class="clearfix"></div>
 
  <div class="col-sm-3 col-xs-12">
<div class="form-group">
<label><b>Room Name</b></label>
<select  class="form-control select2" name="room_no" id="state1"  required>
<option value="" selected="selected">Select Room No</option>
<option value="Room_1">Therapy Room 1</option>
<option value="Room_2">Therapy Room 2</option>
</select></div>

</div>
 
 <div class="col-sm-3 col-xs-12">
<div class="form-group">
<label><b>Timing</b></label>
<div class="form-group"  id="city1"></div>

</div>
</div>


 <div class="col-sm-3 col-xs-12">
<div class="form-group">
<label><b>Therapist Name</b></label>
<select  class="form-control select2" data-style="py-0" name="therapist_id"  required>
<option value="" selected="selected">Select Therapist</option>
<?php 
$querynp1 = "select * from therapist_master";
$resultmp1 = mysqli_query($conn,$querynp1);
while($row=mysqli_fetch_array($resultmp1))
{
$therapist_name = $row['therapist_name'];
$therapist_id = $row['therapist_id'];
?>
<option value="<?php echo $therapist_id ?>"><?php echo $therapist_name ?> </option>
<?php 	}?>
</select></div>
</div>


<div class="col-sm-3 col-xs-12">
                                            <div class="m-t-20">
							   <div class="form-group">
                                <label for="middle_name" class="control-label">Patient Name</label>
                				<input class="form-control" type="text" name="patient_name" placeholder="Name" required/>
                            </div>
</div></div>

<div class="col-sm-3 col-xs-12">
                                            <div class="m-t-20">
							   <div class="form-group">
                                <label for="middle_name" class="control-label">Patient Contact No</label>
                				<input class="form-control" type="text" name="patient_contact_no"  placeholder="Mobile No" required pattern="[0-9]{10}"/>
                            </div>
</div></div>

 <div class="col-sm-3 col-xs-12">
<div class="form-group">
<label><b>Therapy Name</b></label>
<select  class="form-control select2" name="therapyID"  required>
<option value="" selected="selected">Select Therapy</option>
<?php 
$querynp2 = "select * from therapy_master";
$resultmp2 = mysqli_query($conn,$querynp2);
while($row=mysqli_fetch_array($resultmp2))
{
$therapy_name = $row['therapy_name'];
$therapyID = $row['therapyID'];
?>
<option value="<?php echo $therapyID ?>"><?php echo $therapy_name ?> </option>
<?php 	}?>
</select></div>
</div>


 <div class="col-sm-3 col-xs-12">
<div class="form-group">
<label><b>Location</b></label>
<select  class="form-control" name="branch_id"  required>
<option value="" selected="selected">Select Location</option>
<?php 
$querynp3 = "select * from branch_master";
$resultmp3 = mysqli_query($conn,$querynp3);
while($row=mysqli_fetch_array($resultmp3))
{
$branch_name = $row['branch_name'];
$branch_id = $row['branch_id'];
?>
<option value="<?php echo $branch_id ?>"><?php echo $branch_name ?> </option>
<?php 	}?>
</select></div>
</div>


<div class="col-sm-12 col-xs-12">
<div class="m-t-20">
<div class="form-group">
<input type="submit" name="Submit" class="btn waves-light" value="Submit" style="float:right; background-color:#65bd77; color: #FFFFFF">
</div>
</div>
</div>

<script>
        $(document).ready(function() {
           
			
			
            $("#state").on('change', function() {
                var stateid = $(this).val();
                $.ajax({
                    method: "POST",
                    url: "Tchart.php",
                    data: {
                        sid: stateid
                    },
                    datatype: "html",
                    success: function(data) {
                        $("#city").html(data);

                    }

                });
				
				});
				
					$("#state1").on('change', function() {
                var stateid1 = $(this).val();
                $.ajax({
                    method: "POST",
                    url: "Tchart.php",
                    data: {
                        sid1: stateid1
                    },
                    datatype: "html",
                    success: function(data) {
                        $("#city1").html(data);

                    }

                });
				
				});
				
		
        });
    </script>
</div>
</div>
</div>
</div></form>

<div class="row">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Therapy Chart Current Week <button style="float:right" type="button" class="btn btn-danger  waves-effect waves-light" onclick="window.open('calendar.php', '_blank')">View all Records </button></h3>
</div>
<div class="panel-body">
<table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>Timing</th>
                <?php foreach ($daysInWeek as $day): ?>
                    <th><?php echo date('D, d-m-y', 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';?>
