HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: /var/www/html/shootinschool/wp-content/plugins/shootin-school-plugin/add_location.php
<?php

function add_location()
{
	global $wpdb;
	$id = '';
	$data = '';
	if (isset($_GET['id'])) {
		$id = $_GET['id'];
		$get_monday = date('Y-m-d', strtotime('monday this week'));




		$data = $wpdb->get_row("select * from " . DB_COACHING_LOCATIONS . " where ID ='$id'");
		$CurrentWeekquery = $wpdb->get_results("SELECT *  FROM " . DB_WORKING_HOURS . " WHERE `location_id` = '$id' AND `start_date` = '$get_monday'");
		// echo $wpdb->last_query;
		// // $currentWeekCheck = $wpdb->get_results($CurrentWeekquery, ARRAY_A);
		// echo "<pre>";

		// print_r($CurrentWeekquery);
		// die();
		if ($CurrentWeekquery) {
			if ($data->working_hours) {
				$working_hours = json_decode($data->working_hours, TRUE);
			}
			if ($data->blocking_hours) {
				$blocking_hours = json_decode($data->blocking_hours, TRUE);
			}
		}
		function fetchGradeData($wpdb, $id, $dayOfWeek)
		{
			$query = $wpdb->prepare("SELECT * FROM " . DB_GRADE_LOCATIONS . " WHERE location_id = %d AND day = %s", $id, $dayOfWeek);
			$grade_location = $wpdb->get_row($query);
			$count = $grade_location ? 1 : 0; // Check if a row was found
			$gradehrsArr = $grade_location ? json_decode($grade_location->grade_hours, true) : null;

			return [$count, $gradehrsArr];
		}
		if ($CurrentWeekquery) {
			$dayOfWeek = 'Monday';
			list($monCount, $monGradehrsArr) = fetchGradeData($wpdb, $id, $dayOfWeek);

			$tuedayOfWeek = 'Tuesday';
			list($tueCount, $tueGradehrsArr) = fetchGradeData($wpdb, $id, $tuedayOfWeek);

			$weddayOfWeek = 'Wednesday';
			list($wedCount, $wedGradehrsArr) = fetchGradeData($wpdb, $id, $weddayOfWeek);

			$thudayOfWeek = 'Thursday';
			list($thuCount, $thuGradehrsArr) = fetchGradeData($wpdb, $id, $thudayOfWeek);

			$friDayOfWeek = 'Friday';
			list($friCount, $friGradehrsArr) = fetchGradeData($wpdb, $id, $friDayOfWeek);

			$satDayOfWeek = 'Saturday';
			list($satCount, $satGradehrsArr) = fetchGradeData($wpdb, $id, $satDayOfWeek);

			$sunDayOfWeek = 'Sunday';
			list($sunCount, $sunGradehrsArr) = fetchGradeData($wpdb, $id, $sunDayOfWeek);
		}
		function getGradeData($wpdb, $gradeValue)
		{
			$query = $wpdb->prepare("SELECT * FROM " . DB_GRADE_SESSIONS . " WHERE status = 1");
			$gradeData = $wpdb->get_results($query, ARRAY_A);

			return $gradeData;
		}
	}

?>
	<style>
		.biodata {
			width: 37.4% !important;
		}

		.red {
			border: 1px solid red !important;
		}

		.modal {
			display: none;
			position: fixed;
			z-index: 1;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
			background-color: rgba(0, 0, 0, 0.5);
		}

		.modal-content {
			background-color: white;
			margin: 15% auto;
			padding: 20px;
			width: 60%;
			box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
			text-align: center;
		}

		/* Styling for buttons */
		.btn-yes,
		.btn-no {
			padding: 10px 20px;
			margin: 5px;
			cursor: pointer;
		}

		.btn-yes {
			background-color: #008000;
			color: #fff;
		}

		.btn-no {
			background-color: #ff0000;
			color: #fff;
		}

		.confirmyes {
			padding: 5px;
			background-color: darkgreen;
			color: white;
		}

		.confirmno {
			padding: 5px;
			background-color: #b60707;
			color: white;
		}
	</style>

	<div class="wrap">
		<div class="modal" id="myModal" role="dialog">
			<div class="modal-dialog">
				<div class="modal-content" style="width: 100%;">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" onclick="cancelSelection()">&times;</button>
						<h4 class="modal-title">Confirm Selection</h4>
					</div>
					<div class="modal-body" id="appendSavedCardsDiv">
						<p><strong>This is not a common scenario. Are you sure you want to select <span id="selectedValue"></span>?</strong></p>
					</div>
					<div class="modal-footer">
						<button type="button" id="proceedBtn" data-appt_pur_ids="" class="btn btn-primary" onclick="confirmSelection()">Yes, Proceed</button>
						<button type="button" class="btn btn-default" data-dismiss="modal" onclick="cancelSelection()">No</button>
					</div>
				</div>
			</div>
		</div>
		<div class="alert alert-info" role="alert" style="border: 1px solid green;border-radius: 5px;">
			<h3> <?php if ($data->id) {
						echo "Edit Coaching Location";
					} else {
						echo "Add Coaching Location";
					} ?> </h3>
			<a class="add-new-h2 btn btn-success" href="admin.php?page=siab-locations">Back to Coaching Locations</a>
			<!-- <button type="button" class="btn btn-success"> + Add Location </button> -->
		</div>
		<div id="Saveress" class="Saveress below-h2" tabindex="-1"></div>
		<form id="createlocation">
			<input type="hidden" name="action" value="save_location">
			<input type="hidden" name="id" value="<?php echo $data->id; ?>">
			<table class="form-table" id='links'>
				<tbody>
					<tr>
						<th> Name*</th>
						<td><input type="text" name="name" id="project-name" autocomplete="off" placeholder="Name" value="<?php echo $data->name; ?>" class="biodata form-control common2" required /></td>
					</tr>
					<tr>
						<th> Address*</th>
						<td>
							<textarea name="address" id="floor-name" autocomplete="off" placeholder="Address" class="biodata common2 form-control" required><?php echo $data->address; ?></textarea>
						</td>
					</tr>
					<tr>
						<th> Phone*</th>
						<td><input type="text" data-parsley-pattern="^[\d\+\-\.\(\)\/\s]*$" name="phone" id="floor-name" autocomplete="off" placeholder="Phone" value="<?php echo $data->phone; ?>" class="biodata common2 form-control" required />
						</td>
					</tr>
					<tr>
						<th> Admin Only*</th>
						<td><input type="checkbox" name="status" value="1" id="floor-status" <?php if ($data->status == '1') {
																									echo "checked";
																								} ?> class="" />
						</td>
					</tr>
					<tr colspan=1>
						<th> Platform*</th>
						<td><input type="radio" name="platform" value="1" id="platform" <?php if ($data->platform == '1') {
																							echo "checked";
																						} ?> class="" onchange="handlePlatformChange()" />&nbsp;&nbsp;&nbsp;Shootin School</td>

					</tr>

					<th> </th>
					<td><input type="radio" name="platform" value="2" id="platform" <?php if ($data->platform == '2') {
																						echo "checked";
																					} ?> class="" onchange="handlePlatformChange()" />&nbsp;&nbsp;&nbsp;BWC</td>

					</tr>
					<tr>
						<th> </th>
						<td><input type="radio" name="platform" value="3" id="platformBoth" <?php if ($data->platform == '3') {
																								echo "checked";
																							} ?> class="" onchange="handlePlatformChange()" />&nbsp;&nbsp;&nbsp;Both</td>

					</tr>
					<tr class="customLabel" style="<?php echo ($data->platform == '3') ? 'display: table-row;' : 'display: none;'; ?>">
						<th> BWC Label*</th>
						<td><input type="text" name="customlabelBwc" id="customlabelBwc" autocomplete="off" placeholder="Label For BWC" value="<?php echo $data->customlabelBwc; ?>" class="biodata form-control common2" /></td>
					</tr>
					<tr class="customLabel" style="<?php echo ($data->platform == '3') ? 'display: table-row;' : 'display: none;'; ?>">
						<th>SHOOTIN SCHOOL Label*</th>
						<td><input type="text" name="customlabelShoot" id="customlabelShoot" autocomplete="off" placeholder="Label For Shootin School" value="<?php echo $data->customlabelShoot; ?>" class="biodata form-control common2" /></td>
					</tr>
					<tr>
					<tr>
						<th> Description*</th>
						<td>
							<textarea name="description" id="floor-name" autocomplete="off" placeholder="Description" class="biodata common2 form-control" required><?php echo $data->description; ?></textarea>
						</td>
					</tr>
					<tr>
						<th> Working Hours</th>
						<td style="padding: 0; margin: 0;">
							<table>

								<tr>
									<td>
										Monday
									</td>
									<td>
										<?php $selectedmonday = $working_hours['monday']['package']; ?>
										<select name="mon_package" id="select1" onchange="showModal(1)" style="width: 100%;">
											<?php if ($working_hours['monday']['open'] != '') { ?>
												<!-- <option value="both" <?php if ($selectedmonday === 'both') echo 'selected'; ?>>Both</option> -->
											<?php } else { ?>
												<option value="0">--Select Instruction Type--</option>
											<?php } ?>
											<option value="individual" <?php if ($selectedmonday === 'individual') echo 'selected'; ?>>Individual</option>
											<option value="group" <?php if ($selectedmonday === 'group') echo 'selected'; ?>>Group</option>
											<option value="both" <?php if ($selectedmonday === 'both' && $working_hours['monday']['open'] != '') echo 'selected'; ?>>Both</option>
										</select><br>
										<label id="label1" style="color:red;font-size:11px;"></label>
									</td>
									<td class="v-align-top">
									<input type="text" id="mon_label" value="<?php echo $working_hours['monday']['label'] ?>" name="mon_label" placeholder="Add Label">
									</td>
									<td class="v-align-top">
										<input type="text" id="mon_open" name="mon_open" value="<?php echo $working_hours['monday']['open'] ? date("g:i A", strtotime($working_hours['monday']['open'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
									</td>
									<td class="v-align-top">
										<input type="text" id="mon_close" name="mon_close" value="<?php echo $working_hours['monday']['close'] ? date("g:i A", strtotime($working_hours['monday']['close'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
										<button type="button" class="btn btn-danger btn-xs" onclick="document.getElementById('mon_close').value = ''; document.getElementById('mon_label').value = ''; document.getElementById('mon_open').value = ''; document.getElementById('select1').value = '0';document.getElementById('addTimeGrade1').style.display = 'none';  removeAllTimeGradeContainers1();">X</button>
									</td>
									<td><?php if ($selectedmonday === 'both' || $selectedmonday === 'group') { ?><div id="addmore1"><button type="button" id="addTimeGrade1" onclick="addTimeGradeField(1)" style="margin-bottom: 18px;">Add Split</button>
											<?php } else { ?><div id="addmore1" style="display:none;"><button type="button" id="addTimeGrade1" onclick="addTimeGradeField(1)" style="margin-bottom: 18px;">Add Split</button>
												<?php } ?>
									</td>

								</tr>
								<tr>
									<td style="padding:0px;"></td>
									<td align="right" colspan="4" style="padding:0px 10px;">
										<?php if ($monCount > 0) {
											$count = count($monGradehrsArr);
											$html = '';
											$day = 1;
											$rowNumber = 1;
											foreach ($monGradehrsArr as $key => $grade) {
												$givenValue = $grade['grade'];
												$gradeData = getGradeData($wpdb, $givenValue);
												$html .= '<div id="timeGradeContainer' . $day . $rowNumber . '" class="split-wrp-outer split1"><div class="split-wrp" >
												<input type="text" id="Monday_stime[]" name="Monday_stime[]" placeholder="Start Time" value="' . date("g:i A", strtotime($grade['open'])) . '" readonly="" onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo timepicker_demo input-style">
												<input type="text" id="Monday_etime[]" name="Monday_etime[]" placeholder="End Time" value="' . date("g:i A", strtotime($grade['close'])) . '" readonly="" onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo timepicker_demo input-style">
												<input type="text" id="Monday_label[]" value="'.$grade['label'].'" name="Monday_label[]" placeholder="Add Label">
												<select name="Monday_grade[]" id="grade_select1" class="grade_select1">
												<option value="">Select a Grade</option>';
												foreach ($gradeData as $gradeOption) {
													$selected = $gradeOption['id'] == $grade['grade'] ? 'selected' : '';
													if ($gradeOption['upper_grade'] != '') {
														$html .= '<option value="' . $gradeOption['id'] . '" ' . $selected . '>' . 'Grade (' . $gradeOption['lower_grade'] . '-' . $gradeOption['upper_grade'] . ')</option>';
													} else {
														$html .= '<option value="' . $gradeOption['id'] . '" ' . $selected . '>' . 'Grade (' . $gradeOption['lower_grade'] . ')</option>';
													}
												}
												$html .= '</select>
												
												<button type="button" onclick="removeTimeGradeFieldpage(' . $day . $rowNumber . ')" class="button-wordwrap">Remove</button>
											</div></div>';
												$rowNumber++;
											}

											// Output the generated HTML
											echo $html;
										} ?>
										<?php if ($selectedmonday === 'both' || $selectedmonday === 'group') { ?>
											<div id="timeGradeContainer1" class="split-wrp-outer"></div> <?php } else { ?>
											<div id="timeGradeContainer1" class="split-wrp-outer"></div> <?php } ?>
									</td>
								</tr>
								<tr>
									<td>
										Tuesday
									</td>
									<td>
										<?php $selectedtuesday = $working_hours['tuesday']['package']; ?>
										<select name="tue_package" id="select2" onchange="showModal(2)" style="width: 100%;">
											<?php if ($working_hours['tuesday']['open'] != '') { ?>
												<!-- <option value="both" <?php if ($selectedtuesday === 'both') echo 'selected'; ?>>Both</option> -->
											<?php } else { ?>
												<option value="0">--Select Instruction Type--</option>
											<?php } ?>
											<option value="individual" <?php if ($selectedtuesday === 'individual') echo 'selected'; ?>>Individual</option>
											<option value="group" <?php if ($selectedtuesday === 'group') echo 'selected'; ?>>Group</option>
											<option value="both" <?php if ($selectedtuesday === 'both' && $working_hours['tuesday']['open'] != '') echo 'selected'; ?>>Both</option>
										</select><br>
										<label id="label2" style="color:red;font-size:11px;"></label>
									</td>
									<td class="v-align-top">
									<input type="text" id="tue_label" value="<?php echo $working_hours['tuesday']['label'] ?>" name="tue_label" placeholder="Add Label">
									</td>	
									<td class="v-align-top">
										<input type="text" id="tue_open" name="tue_open" value="<?php echo $working_hours['tuesday']['open'] ? date("g:i A", strtotime($working_hours['tuesday']['open'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
									</td>
									<td class="v-align-top">
										<input type="text" id="tue_close" name="tue_close" value="<?php echo $working_hours['tuesday']['close'] ? date("g:i A", strtotime($working_hours['tuesday']['close'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
										<button type="button" class="btn btn-danger btn-xs" onclick="document.getElementById('tue_close').value = '',document.getElementById('tue_label').value = '',document.getElementById('tue_open').value = '',document.getElementById('select2').value = '0';document.getElementById('addTimeGrade2').style.display = 'none'; removeAllTimeGradeContainers2();">X</button>
									</td>
									<td><?php if ($selectedtuesday === 'both' || $selectedtuesday === 'group') { ?><div id="addmore2"><button type="button" id="addTimeGrade2" onclick="addTimeGradeField(2)" style="margin-bottom: 18px;">Add Split</button>
											<?php } else { ?><div id="addmore2" style="display:none;"><button type="button" id="addTimeGrade2" onclick="addTimeGradeField(2)" style="margin-bottom: 18px;">Add Split</button>
												<?php } ?>
									</td>


								</tr>
								<tr>
									<td style="padding:0px;"></td>
									<td align="right" colspan="4" style="padding:0px 10px;">
										<?php if ($tueCount > 0) {
											$html = '';
											$day = 2;
											$rowNumber = 1;
											foreach ($tueGradehrsArr as $key => $grade) {
												$givenValue = $grade['grade'];
												$gradeData = getGradeData($wpdb, $givenValue);
												$html .= '<div id="timeGradeContainer' . $day . $rowNumber . '"  class="split-wrp-outer split2"><div class="split-wrp" >
												<input type="text" id="Tuesday_stime[]" name="Tuesday_stime[]" placeholder="Start Time" value="' . date("g:i A", strtotime($grade['open'])) . '" readonly="" onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo timepicker_demo input-style">
												<input type="text" id="Tuesday_etime[]" name="Tuesday_etime[]" placeholder="End Time" value="' . date("g:i A", strtotime($grade['close'])) . '" readonly="" onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo timepicker_demo input-style">
												<input type="text" id="Tuesday_label[]" value="'.$grade['label'].'" name="Tuesday_label[]" placeholder="Add Label">
												<select name="Tuesday_grade[]" id="grade_select2" class="grade_select2">
												<option value="">Select a Grade</option>';
												foreach ($gradeData as $gradeOption) {
													$selected = $gradeOption['id'] == $grade['grade'] ? 'selected' : '';
													if ($gradeOption['upper_grade'] != '') {
														$html .= '<option value="' . $gradeOption['id'] . '" ' . $selected . '>' . 'Grade (' . $gradeOption['lower_grade'] . '-' . $gradeOption['upper_grade'] . ')</option>';
													} else {
														$html .= '<option value="' . $gradeOption['id'] . '" ' . $selected . '>' . 'Grade (' . $gradeOption['lower_grade'] . ')</option>';
													}
												}
												$html .= '</select>
												
												<button type="button" onclick="removeTimeGradeFieldpage(' . $day . $rowNumber . ')" class="button-wordwrap">Remove</button>
											</div></div>';
												$rowNumber++;
											}

											// Output the generated HTML
											echo $html;
										} ?>
										<?php if ($selectedtuesday === 'both' || $selectedtuesday === 'group') { ?>
											<div id="timeGradeContainer2" class="split-wrp-outer"></div> <?php } else { ?>
											<div id="timeGradeContainer2" class="split-wrp-outer"></div> <?php } ?>
									</td>
								</tr>
								<tr>
									<td>
										Wednesday
									</td>
									<td>
										<?php $selectedwednesday = $working_hours['wednesday']['package']; ?>
										<select name="wed_package" id="select3" onchange="showModal(3)" style="width: 100%;">
											<?php if ($working_hours['wednesday']['open'] != '') { ?>
												<!-- <option value="both" <?php if ($selectedwednesday === 'both') echo 'selected'; ?>>Both</option> -->
											<?php } else { ?>
												<option value="0">--Select Instruction Type--</option>
											<?php } ?>
											<option value="individual" <?php if ($selectedwednesday === 'individual') echo 'selected'; ?>>Individual</option>
											<option value="group" <?php if ($selectedwednesday === 'group') echo 'selected'; ?>>Group</option>
											<option value="both" <?php if ($selectedwednesday === 'both' && $working_hours['wednesday']['open'] != '') echo 'selected'; ?>>Both</option>
										</select>
										<br>
										<label id="label3" style="color:red;font-size:11px;"></label>
									</td>
									<td class="v-align-top">
									<input type="text" id="wed_label" value="<?php echo $working_hours['wednesday']['label'] ?>" name="wed_label" placeholder="Add Label">
									</td>			
									<td class="v-align-top">
										<input type="text" id="wed_open" name="wed_open" value="<?php echo $working_hours['wednesday']['open'] ? date("g:i A", strtotime($working_hours['wednesday']['open'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
									</td>
									<td class="v-align-top">
										<input type="text" id="wed_close" name="wed_close" value="<?php echo $working_hours['wednesday']['close'] ? date("g:i A", strtotime($working_hours['wednesday']['close'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
										<button type="button" class="btn btn-danger btn-xs" onclick="document.getElementById('wed_close').value = '',document.getElementById('wed_label').value = '',document.getElementById('wed_open').value = '',document.getElementById('select3').value = '0';document.getElementById('addTimeGrade3').style.display = 'none'; removeAllTimeGradeContainers3();">X</button>
									</td>

									<td><?php if ($selectedwednesday === 'both' || $selectedwednesday === 'group') { ?><div id="addmore3"><button type="button" id="addTimeGrade3" onclick="addTimeGradeField(3)" style="margin-bottom: 18px;">Add Split</button>
											<?php } else { ?><div id="addmore3" style="display:none;"><button type="button" id="addTimeGrade3" onclick="addTimeGradeField(3)" style="margin-bottom: 18px;">Add Split</button>
												<?php } ?>
									</td>


								</tr>
								<tr>
									<td style="padding:0px;"></td>
									<td align="right" colspan="4" style="padding:0px 10px;">
										<?php if ($wedCount > 0) {
											$html = '';
											$day = 3;
											$rowNumber = 1;
											foreach ($wedGradehrsArr as $key => $grade) {
												$givenValue = $grade['grade'];
												$gradeData = getGradeData($wpdb, $givenValue);
												$html .= '<div id="timeGradeContainer' . $day . $rowNumber . '"  class="split-wrp-outer split3"><div class="split-wrp" >
												<input type="text" id="Wednesday_stime[]" name="Wednesday_stime[]" placeholder="Start Time" value="' . date("g:i A", strtotime($grade['open'])) . '" readonly="" onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo timepicker_demo input-style">
												<input type="text" id="Wednesday_etime[]" name="Wednesday_etime[]" placeholder="End Time" value="' . date("g:i A", strtotime($grade['close'])) . '" readonly="" onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo timepicker_demo input-style">
												<input type="text" id="Wednesday_label[]" value="'.$grade['label'].'" name="Wednesday_label[]" placeholder="Add Label">
												<select name="Wednesday_grade[]" id="grade_select3" class="grade_select3">
												<option value="">Select a Grade</option>';
												foreach ($gradeData as $gradeOption) {
													$selected = $gradeOption['id'] == $grade['grade'] ? 'selected' : '';
													$html .= '<option value="' . $gradeOption['id'] . '" ' . $selected . '>' . 'Grade (' . $gradeOption['lower_grade'] . '-' . $gradeOption['upper_grade'] . ')</option>';
												}
												$html .= '</select>
												<button type="button" onclick="removeTimeGradeFieldpage(' . $day . $rowNumber . ')" class="button-wordwrap">Remove</button>
											</div></div>';
												$rowNumber++;
											}

											// Output the generated HTML
											echo $html;
										} ?>
										<?php if ($selectedwednesday === 'both' || $selectedwednesday === 'group') { ?>
											<div id="timeGradeContainer3" class="split-wrp-outer"></div> <?php } else { ?>
											<div id="timeGradeContainer3" class="split-wrp-outer"></div> <?php } ?>
									</td>
								</tr>
								<tr>
									<td>
										Thursday
									</td>
									<td>
										<?php $selectedthursday = $working_hours['thursday']['package']; ?>
										<select name="thu_package" id="select4" onchange="showModal(4)" style="width: 100%;">
											<?php if ($working_hours['thursday']['open'] != '') { ?>
												<!-- <option value="both" <?php if ($selectedthursday === 'both') echo 'selected'; ?>>Both</option> -->
											<?php } else { ?>
												<option value="0">--Select Instruction Type--</option>
											<?php } ?>
											<option value="individual" <?php if ($selectedthursday === 'individual') echo 'selected'; ?>>Individual</option>
											<option value="group" <?php if ($selectedthursday === 'group') echo 'selected'; ?>>Group</option>
											<option value="both" <?php if ($selectedthursday === 'both' && $working_hours['thursday']['open'] != '') echo 'selected'; ?>>Both</option>

										</select>
										<br>
										<label id="label4" style="color:red;font-size:11px;"></label>
									</td>
									<td class="v-align-top">
									<input type="text" id="thu_label" value="<?php echo $working_hours['thursday']['label'] ?>" name="thu_label" placeholder="Add Label">
									</td>
									<td class="v-align-top">
										<input type="text" id="thu_open" name="thu_open" value="<?php echo $working_hours['thursday']['open'] ? date("g:i A", strtotime($working_hours['thursday']['open'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
									</td>
									<td class="v-align-top">
										<input type="text" id="thu_close" name="thu_close" value="<?php echo $working_hours['thursday']['close'] ? date("g:i A", strtotime($working_hours['thursday']['close'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
										<button type="button" class="btn btn-danger btn-xs" onclick="document.getElementById('thu_close').value = '',document.getElementById('thu_label').value = '',document.getElementById('thu_open').value = '',document.getElementById('select4').value = '0';document.getElementById('addTimeGrade4').style.display = 'none'; removeAllTimeGradeContainers4();">X</button>
									</td>

									<td><?php if ($selectedthursday === 'both' || $selectedthursday === 'group') { ?><div id="addmore4"><button type="button" id="addTimeGrade4" onclick="addTimeGradeField(4)" style="margin-bottom: 18px;">Add Split</button>
											<?php } else { ?><div id="addmore4" style="display:none;"><button type="button" id="addTimeGrade4" onclick="addTimeGradeField(4)" style="margin-bottom: 18px;">Add Split</button>
												<?php } ?>
									</td>


								</tr>
								<tr>
									<td style="padding:0px;"></td>
									<td align="right" colspan="4" style="padding:0px 10px;">
										<?php if ($thuCount > 0) {
											$html = '';
											$day = 4;
											$rowNumber = 1;
											foreach ($thuGradehrsArr as $key => $grade) {
												$givenValue = $grade['grade'];
												$gradeData = getGradeData($wpdb, $givenValue);
												$html .= '<div id="timeGradeContainer' . $day . $rowNumber . '"  class="split-wrp-outer split4"><div class="split-wrp" >
												<input type="text" id="Thursday_stime[]" name="Thursday_stime[]" placeholder="Start Time" value="' . date("g:i A", strtotime($grade['open'])) . '" readonly="" onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo timepicker_demo input-style">
												<input type="text" id="Thursday_etime[]" name="Thursday_etime[]" placeholder="End Time" value="' . date("g:i A", strtotime($grade['close'])) . '" readonly="" onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo timepicker_demo input-style">
												<input type="text" id="Thursday_label[]" value="'.$grade['label'].'" name="Thursday_label[]" placeholder="Add Label">
												<select name="Thursday_grade[]" id="grade_select4" class="grade_select4">
												<option value="">Select a Grade</option>';
												foreach ($gradeData as $gradeOption) {
													$selected = $gradeOption['id'] == $grade['grade'] ? 'selected' : '';
													if ($gradeOption['upper_grade'] != '') {
														$html .= '<option value="' . $gradeOption['id'] . '" ' . $selected . '>' . 'Grade (' . $gradeOption['lower_grade'] . '-' . $gradeOption['upper_grade'] . ')</option>';
													} else {
														$html .= '<option value="' . $gradeOption['id'] . '" ' . $selected . '>' . 'Grade (' . $gradeOption['lower_grade'] . ')</option>';
													}
												}
												$html .= '</select>
												<button type="button" onclick="removeTimeGradeFieldpage(' . $day . $rowNumber . ')" class="button-wordwrap">Remove</button>
											</div></div>';
												$rowNumber++;
											}

											// Output the generated HTML
											echo $html;
										} ?>
										<?php if ($selectedthursday === 'both' || $selectedthursday === 'group') { ?>
											<div id="timeGradeContainer4" class="split-wrp-outer"></div> <?php } else { ?>
											<div id="timeGradeContainer4" class="split-wrp-outer"></div> <?php } ?>
									</td>
								</tr>
								<tr>
									<td>
										Friday
									</td>
									<td>
										<?php $selectedfriday = $working_hours['friday']['package']; ?>
										<select name="fri_package" id="select5" onchange="showModal(5)" style="width: 100%;">
											<?php if ($working_hours['friday']['open'] != '') { ?>
												<!-- <option value="both" <?php if ($selectedfriday === 'both') echo 'selected'; ?>>Both</option> -->
											<?php } else { ?>
												<option value="0">--Select Instruction Type--</option>
											<?php } ?>
											<option value="individual" <?php if ($selectedfriday === 'individual') echo 'selected'; ?>>Individual</option>
											<option value="group" <?php if ($selectedfriday === 'group') echo 'selected'; ?>>Group</option>
											<option value="both" <?php if ($selectedfriday === 'both' && $working_hours['friday']['open'] != '') echo 'selected'; ?>>Both</option>
										</select>
										<br>
										<label id="label5" style="color:red;font-size:11px;"></label>
									</td>
									<td class="v-align-top">
									<input type="text" id="fri_label" value="<?php echo $working_hours['friday']['label'] ?>" name="fri_label" placeholder="Add Label">
									</td>
									<td class="v-align-top">
										<input type="text" id="fri_open" name="fri_open" value="<?php echo $working_hours['friday']['open'] ? date("g:i A", strtotime($working_hours['friday']['open'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
									</td>
									<td class="v-align-top">
										<input type="text" id="fri_close" name="fri_close" value="<?php echo $working_hours['friday']['close'] ? date("g:i A", strtotime($working_hours['friday']['close'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
										<button type="button" class="btn btn-danger btn-xs" onclick="document.getElementById('fri_close').value = '',document.getElementById('fri_label').value = '',document.getElementById('fri_open').value = '',document.getElementById('select5').value = '0';document.getElementById('addTimeGrade5').style.display = 'none'; removeAllTimeGradeContainers5();">X</button>
									</td>
									<td><?php if ($selectedfriday === 'both' || $selectedfriday === 'group') { ?><div id="addmore5"><button type="button" id="addTimeGrade5" onclick="addTimeGradeField(5)" style="margin-bottom: 18px;">Add Split</button>
											<?php } else { ?><div id="addmore5" style="display:none;"><button type="button" id="addTimeGrade5" onclick="addTimeGradeField(5)" style="margin-bottom: 18px;">Add Split</button>
												<?php } ?>
									</td>


								</tr>
								<tr>
									<td style="padding:0px;"></td>
									<td align="right" colspan="4" style="padding:0px 10px;">
										<?php if ($friCount > 0) {
											$html = '';
											$day = 5;
											$rowNumber = 1;
											foreach ($friGradehrsArr as $key => $grade) {
												$givenValue = $grade['grade'];
												$gradeData = getGradeData($wpdb, $givenValue);
												$html .= '<div id="timeGradeContainer' . $day . $rowNumber . '"  class="split-wrp-outer split5"><div class="split-wrp" >
												<input type="text" id="Friday_stime[]" name="Friday_stime[]" placeholder="Start Time" value="' . date("g:i A", strtotime($grade['open'])) . '" readonly="" onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo timepicker_demo input-style">
												<input type="text" id="Friday_etime[]" name="Friday_etime[]" placeholder="End Time" value="' . date("g:i A", strtotime($grade['close'])) . '" readonly="" onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo timepicker_demo input-style">
												<input type="text" id="Friday_label[]" value="'.$grade['label'].'" name="Friday_label[]" placeholder="Add Label">
												<select name="Friday_grade[]" id="grade_select5" class="grade_select5">
												<option value="">Select a Grade</option>';
												foreach ($gradeData as $gradeOption) {
													$selected = $gradeOption['id'] == $grade['grade'] ? 'selected' : '';
													if ($gradeOption['upper_grade'] != '') {
														$html .= '<option value="' . $gradeOption['id'] . '" ' . $selected . '>' . 'Grade (' . $gradeOption['lower_grade'] . '-' . $gradeOption['upper_grade'] . ')</option>';
													} else {
														$html .= '<option value="' . $gradeOption['id'] . '" ' . $selected . '>' . 'Grade (' . $gradeOption['lower_grade'] . ')</option>';
													}
												}
												$html .= '</select>
												<button type="button" onclick="removeTimeGradeFieldpage(' . $day . $rowNumber . ')" class="button-wordwrap">Remove</button>
											</div></div>';
												$rowNumber++;
											}

											// Output the generated HTML
											echo $html;
										} ?>
										<?php if ($selectedfriday === 'both' || $selectedfriday === 'group') { ?>
											<div id="timeGradeContainer5" class="split-wrp-outer"></div> <?php } else { ?>
											<div id="timeGradeContainer5" class="split-wrp-outer"></div> <?php } ?>
									</td>
								</tr>
								<tr>
									<td>
										Saturday
									</td>
									<td>
										<?php $selectedsaturday = $working_hours['saturday']['package']; ?>
										<select name="sat_package" id="select6" onchange="showModal(6)" style="width: 100%;">
											<?php if ($working_hours['saturday']['open'] != '') { ?>
												<!-- <option value="both" <?php if ($selectedsaturday === 'both') echo 'selected'; ?>>Both</option> -->
											<?php } else { ?>
												<option value="0">--Select Instruction Type--</option>
											<?php } ?>
											<option value="individual" <?php if ($selectedsaturday === 'individual') echo 'selected'; ?>>Individual</option>
											<option value="group" <?php if ($selectedsaturday === 'group') echo 'selected'; ?>>Group</option>
											<option value="both" <?php if ($selectedsaturday === 'both' && $working_hours['saturday']['open'] != '') echo 'selected'; ?>>Both</option>
										</select>
										<br>
										<label id="label6" style="color:red;font-size:11px;"></label>
									</td>
									<td class="v-align-top">
									<input type="text" id="sat_label" value="<?php echo $working_hours['saturday']['label'] ?>" name="sat_label" placeholder="Add Label">
									</td>
									<td class="v-align-top">
										<input type="text" id="sat_open" name="sat_open" value="<?php echo $working_hours['saturday']['open'] ? date("g:i A", strtotime($working_hours['saturday']['open'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
									</td>
									<td class="v-align-top">
										<input type="text" id="sat_close" name="sat_close" value="<?php echo $working_hours['saturday']['close'] ? date("g:i A", strtotime($working_hours['saturday']['close'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
										<button type="button" class="btn btn-danger btn-xs" onclick="document.getElementById('sat_close').value = '',document.getElementById('sat_label').value = '',document.getElementById('sat_open').value = '',document.getElementById('select6').value = '0';document.getElementById('addTimeGrade6').style.display = 'none'; removeAllTimeGradeContainers6();">X</button>
									</td>
									<td><?php if ($selectedsaturday === 'both' || $selectedsaturday === 'group') { ?><div id="addmore6"><button type="button" id="addTimeGrade6" onclick="addTimeGradeField(6)" style="margin-bottom: 18px;">Add Split</button>
											<?php } else { ?><div id="addmore6" style="display:none;"><button type="button" id="addTimeGrade6" onclick="addTimeGradeField(6)" style="margin-bottom: 18px;">Add Split</button>
												<?php } ?>
									</td>


								</tr>
								<tr>
									<td style="padding:0px;"></td>
									<td align="right" colspan="4" style="padding:0px 10px;">
										<?php if ($satCount > 0) {
											$html = '';
											$day = 6;
											$rowNumber = 1;
											foreach ($satGradehrsArr as $key => $grade) {
												$givenValue = $grade['grade'];
												$gradeData = getGradeData($wpdb, $givenValue);
												$html .= '<div id="timeGradeContainer' . $day . $rowNumber . '"  class="split-wrp-outer split6"><div class="split-wrp" >
												<input type="text" id="Saturday_stime[]" name="Saturday_stime[]" placeholder="Start Time" value="' . date("g:i A", strtotime($grade['open'])) . '" readonly="" onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo timepicker_demo input-style">
												<input type="text" id="Saturday_etime[]" name="Saturday_etime[]" placeholder="End Time" value="' . date("g:i A", strtotime($grade['close'])) . '" readonly="" onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo timepicker_demo input-style">
												<input type="text" id="Saturday_label[]" value="'.$grade['label'].'" name="Saturday_label[]" placeholder="Add Label">
												<select name="Saturday_grade[]" id="grade_select6" class="grade_select6">
												<option value="">Select a Grade</option>';
												foreach ($gradeData as $gradeOption) {
													$selected = $gradeOption['id'] == $grade['grade'] ? 'selected' : '';
													if ($gradeOption['upper_grade'] != '') {
														$html .= '<option value="' . $gradeOption['id'] . '" ' . $selected . '>' . 'Grade (' . $gradeOption['lower_grade'] . '-' . $gradeOption['upper_grade'] . ')</option>';
													} else {
														$html .= '<option value="' . $gradeOption['id'] . '" ' . $selected . '>' . 'Grade (' . $gradeOption['lower_grade'] . ')</option>';
													}
												}
												$html .= '</select>
												<button type="button" onclick="removeTimeGradeFieldpage(' . $day . $rowNumber . ')" class="button-wordwrap">Remove</button>
											</div></div>';
												$rowNumber++;
											}

											// Output the generated HTML
											echo $html;
										} ?>
										<?php if ($selectedsaturday === 'both' || $selectedsaturday === 'group') { ?>
											<div id="timeGradeContainer6" class="split-wrp-outer"></div> <?php } else { ?>
											<div id="timeGradeContainer6" class="split-wrp-outer"></div> <?php } ?>
									</td>
								</tr>
								<tr>
									<td class="v-align-top" style="padding-top: 22px;">
										Sunday
									</td>

									<td>
										<?php $selectedsunday = $working_hours['sunday']['package']; ?>
										<select name="sun_package" id="select7" onchange="showModal(7)" style="width: 100%;">
											<?php if ($working_hours['sunday']['open'] != '') { ?>
												<!-- <option value="both" <?php if ($selectedsunday === 'both') echo 'selected'; ?>>Both</option> -->
											<?php } else { ?>
												<option value="0">--Select Instruction Type--</option>
											<?php } ?>
											<option value="individual" <?php if ($selectedsunday === 'individual') echo 'selected'; ?>>Individual</option>
											<option value="group" <?php if ($selectedsunday === 'group') echo 'selected'; ?>>Group</option>
											<option value="both" <?php if ($selectedsunday === 'both' && $working_hours['sunday']['open'] != '') echo 'selected'; ?>>Both</option>
										</select>
										<br>
										<label id="label7" style="color:red;font-size:11px;"></label>
									</td>
									<td class="v-align-top">
									<input type="text" id="sun_label" value="<?php echo $working_hours['sunday']['label'] ?>" name="sun_label" placeholder="Add Label">
									</td>
									<td class="v-align-top">
										<input type="text" id="sun_open" name="sun_open" value="<?php echo $working_hours['sunday']['open'] ? date("g:i A", strtotime($working_hours['sunday']['open'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
									</td>
									<td class="v-align-top">
										<input type="text" id="sun_close" name="sun_close" value="<?php echo $working_hours['sunday']['close'] ? date("g:i A", strtotime($working_hours['sunday']['close'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
										
										<button type="button" class="btn btn-danger btn-xs" onclick="document.getElementById('sun_close').value = '',document.getElementById('sun_label').value = '',document.getElementById('sun_open').value = '',document.getElementById('select7').value = '0';document.getElementById('addTimeGrade7').style.display = 'none'; removeAllTimeGradeContainers7();">X</button>
									</td>
									
									<td><?php if ($selectedsunday === 'both' || $selectedsunday === 'group') { ?><div id="addmore7"><button type="button" id="addTimeGrade7" onclick="addTimeGradeField(7)" style="margin-bottom: 18px;">Add Split</button>
											<?php } else { ?><div id="addmore7" style="display:none;"><button type="button" id="addTimeGrade7" onclick="addTimeGradeField(7)" style="margin-bottom: 18px;">Add Split</button>
												<?php } ?>
									</td>


								</tr>
								<tr>
									<td style="padding:0px;"></td>
									<td align="right" colspan="4" style="padding:0px 10px;">
										<?php if ($sunCount > 0) {
											$html = '';
											$day = 7;
											$rowNumber = 1;
											foreach ($sunGradehrsArr as $key => $grade) {
												$givenValue = $grade['grade'];
												$gradeData = getGradeData($wpdb, $givenValue);
												$html .= '<div id="timeGradeContainer' . $day . $rowNumber . '"  class="split-wrp-outer split7"><div class="split-wrp" >
												<input type="text" id="Sunday_stime[]" name="Sunday_stime[]" placeholder="Start Time" value="' . date("g:i A", strtotime($grade['open'])) . '" readonly="" onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo timepicker_demo input-style">
												<input type="text" id="Sunday_etime[]" name="Sunday_etime[]" placeholder="End Time" value="' . date("g:i A", strtotime($grade['close'])) . '" readonly="" onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo timepicker_demo input-style">
												<input type="text" id="Sunday_label[]" value="'.$grade['label'].'" name="Sunday_label[]" placeholder="Add Label">
												
												<select name="Sunday_grade[]" id="grade_select7" class="grade_select7">
												<option value="">Select a Grade</option>';
												foreach ($gradeData as $gradeOption) {
													$selected = $gradeOption['id'] == $grade['grade'] ? 'selected' : '';
													if ($gradeOption['upper_grade'] != '') {
														$html .= '<option value="' . $gradeOption['id'] . '" ' . $selected . '>' . 'Grade (' . $gradeOption['lower_grade'] . '-' . $gradeOption['upper_grade'] . ')</option>';
													} else {
														$html .= '<option value="' . $gradeOption['id'] . '" ' . $selected . '>' . 'Grade (' . $gradeOption['lower_grade'] . ')</option>';
													}
												}
												$html .= '</select>
												<button type="button" onclick="removeTimeGradeFieldpage(' . $day . $rowNumber . ')" class="button-wordwrap">Remove</button>
											</div></div>';
												$rowNumber++;
											}

											// Output the generated HTML
											echo $html;
										} ?>
										<?php if ($selectedsunday === 'both' || $selectedsunday === 'group') { ?>
											<div id="timeGradeContainer7" class="split-wrp-outer"></div> <?php } else { ?>
											<div id="timeGradeContainer7" class="split-wrp-outer"></div> <?php } ?>
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<!---Blocking Hours--->
					<tr>
						<th> Blocking Hours</th>
						<td style="padding: 0; margin: 0;">
							<table>

								<tr>
									<td>
										Monday
									</td>
									<td class="v-align-top">
										<input type="text" id="mon_block_open" name="mon_block_open" value="<?php echo $blocking_hours['monday']['open'] ? date("g:i A", strtotime($blocking_hours['monday']['open'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
									</td>
									<td class="v-align-top">
										<input type="text" id="mon_block_close" name="mon_block_close" value="<?php echo $blocking_hours['monday']['close'] ? date("g:i A", strtotime($blocking_hours['monday']['close'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
										<button type="button" class="btn btn-danger btn-xs" onclick="document.getElementById('mon_block_close').value = '',document.getElementById('mon_block_open').value = ''">X</button>

									</td>

								</tr>
								<tr>
									<td>
										Tuesday
									</td>
									<td class="v-align-top">
										<input type="text" id="tue_block_open" name="tue_block_open" value="<?php echo $blocking_hours['tuesday']['open'] ? date("g:i A", strtotime($blocking_hours['tuesday']['open'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
									</td>
									<td class="v-align-top">
										<input type="text" id="tue_block_close" name="tue_block_close" value="<?php echo $blocking_hours['tuesday']['close'] ? date("g:i A", strtotime($blocking_hours['tuesday']['close'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
										<button type="button" class="btn btn-danger btn-xs" onclick="document.getElementById('tue_block_close').value = '',document.getElementById('tue_block_open').value = ''">X</button>

									</td>
								</tr>
								<tr>
									<td>
										Wednesday
									</td>


									<td class="v-align-top">
										<input type="text" id="wed_block_open" name="wed_block_open" value="<?php echo $blocking_hours['wednesday']['open'] ? date("g:i A", strtotime($blocking_hours['wednesday']['open'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
									</td>
									<td class="v-align-top">
										<input type="text" id="wed_block_close" name="wed_block_close" value="<?php echo $blocking_hours['wednesday']['close'] ? date("g:i A", strtotime($blocking_hours['wednesday']['close'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
										<button type="button" class="btn btn-danger btn-xs" onclick="document.getElementById('wed_block_close').value = '',document.getElementById('wed_block_open').value = ''">X</button>

									</td>

								</tr>
								<tr>
									<td>
										Thursday
									</td>

									<td class="v-align-top">
										<input type="text" id="thu_block_open" name="thu_block_open" value="<?php echo $blocking_hours['thursday']['open'] ? date("g:i A", strtotime($blocking_hours['thursday']['open'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
									</td>
									<td class="v-align-top">
										<input type="text" id="thu_block_close" name="thu_block_close" value="<?php echo $blocking_hours['thursday']['close'] ? date("g:i A", strtotime($blocking_hours['thursday']['close'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
										<button type="button" class="btn btn-danger btn-xs" onclick="document.getElementById('thu_block_close').value = '',document.getElementById('thu_block_open').value = ''">X</button>

									</td>

								</tr>
								<tr>
									<td>
										Friday
									</td>
									<td class="v-align-top">
										<input type="text" id="fri_block_open" name="fri_block_open" value="<?php echo $blocking_hours['friday']['open'] ? date("g:i A", strtotime($blocking_hours['friday']['open'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
									</td>
									<td class="v-align-top">
										<input type="text" id="fri_block_close" name="fri_block_close" value="<?php echo $blocking_hours['friday']['close'] ? date("g:i A", strtotime($blocking_hours['friday']['close'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
										<button type="button" class="btn btn-danger btn-xs" onclick="document.getElementById('fri_block_close').value = '',document.getElementById('fri_block_open').value = ''">X</button>

									</td>
								</tr>
								<tr>
									<td>
										Saturday
									</td>
									<td class="v-align-top">
										<input type="text" id="sat_block_open" name="sat_block_open" value="<?php echo $blocking_hours['saturday']['open'] ? date("g:i A", strtotime($blocking_hours['saturday']['open'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
									</td>
									<td class="v-align-top">
										<input type="text" id="sat_block_close" name="sat_block_close" value="<?php echo $blocking_hours['saturday']['close'] ? date("g:i A", strtotime($blocking_hours['saturday']['close'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
										<button type="button" class="btn btn-danger btn-xs" onclick="document.getElementById('sat_block_close').value = '',document.getElementById('sat_block_open').value = ''">X</button>

									</td>
								</tr>
								<tr>
									<td class="v-align-top" style="padding-top: 22px;">
										Sunday
									</td>
									<td class="v-align-top">
										<input type="text" id="sun_block_open" name="sun_block_open" value="<?php echo $blocking_hours['sunday']['open'] ? date("g:i A", strtotime($blocking_hours['sunday']['open'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
									</td>
									<td class="v-align-top">
										<input type="text" id="sun_block_close" name="sun_block_close" value="<?php echo $blocking_hours['sunday']['close'] ? date("g:i A", strtotime($blocking_hours['sunday']['close'])) : '' ?>" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
										<button type="button" class="btn btn-danger btn-xs" onclick="document.getElementById('sun_block_close').value = '',document.getElementById('sun_block_open').value = ''">X</button>

									</td>
								</tr>
							</table>
						</td>
					</tr>
				</tbody>
			</table>
			<p class="submit">
				<input type="button" name="submitm" value="Save Changes " id="" onclick="SaveLocation()" class="button button-primary" />
			</p>
		</form>
	</div>

<?php }

add_action('wp_ajax_nopriv_save_location', 'save_location');
add_action('wp_ajax_save_location', 'save_location');
function save_location()
{
	//------------------Adding New Package-------------------
	
	$flag = 0;
	if ($_POST['mon_open'] == "" || $_POST['mon_close'] == "" || $_POST['mon_package'] == "") {
		// die("dd");
		$working_hours['monday'] = array('open' => "", 'close' => "", 'package' => "", 'label' => "");
	} else if (strtotime($_POST['mon_open']) >= strtotime($_POST['mon_close'])) {
		$flag = 1;
	} else {
		$mon_package	=	$_POST['mon_package'];
		$working_hours['monday'] = array('open' => date("G:i", strtotime($_POST['mon_open'])), 'close' => date("G:i", strtotime($_POST['mon_close'])), 'package' => $_POST['mon_package'], 'label' => $_POST['mon_label']);
	}

	if ($_POST['tue_open'] == "" || $_POST['tue_close'] == "" || $_POST['tue_package'] == "") {
		$working_hours['tuesday'] = array('open' => "", 'close' => "", 'package' => "", 'label' => "");
	} else if (strtotime($_POST['tue_open']) >= strtotime($_POST['tue_close'])) {
		$flag = 1;
	} else {
		$tue_package	=	$_POST['tue_package'];
		$working_hours['tuesday'] = array('open' => date("G:i", strtotime($_POST['tue_open'])), 'close' => date("G:i", strtotime($_POST['tue_close'])), 'package' => $_POST['tue_package'] , 'label' => $_POST['tue_label']);
	}

	if ($_POST['wed_open'] == "" || $_POST['wed_close'] == "" || $_POST['wed_package'] == "") {
		$working_hours['wednesday'] = array('open' => "", 'close' => "", 'package' => "", 'label' => "");
	} else if (strtotime($_POST['wed_open']) >= strtotime($_POST['wed_close'])) {
		$flag = 1;
	} else {
		$wed_package	=	$_POST['wed_package'];
		$working_hours['wednesday'] = array('open' => date("G:i", strtotime($_POST['wed_open'])), 'close' => date("G:i", strtotime($_POST['wed_close'])), 'package' => $_POST['wed_package'], 'label' => $_POST['wed_label']);
	}

	if ($_POST['thu_open'] == "" || $_POST['thu_close'] == "" || $_POST['thu_package'] == "") {
		$working_hours['thursday'] = array('open' => "", 'close' => "", 'package' => "", 'label' => "");
	} else if (strtotime($_POST['thu_open']) >= strtotime($_POST['thu_close'])) {
		$flag = 1;
	} else {
		$thu_package	=	$_POST['thu_package'];
		$working_hours['thursday'] = array('open' => date("G:i", strtotime($_POST['thu_open'])), 'close' => date("G:i", strtotime($_POST['thu_close'])), 'package' => $_POST['thu_package'], 'label' => $_POST['thu_label']);
	}

	if ($_POST['fri_open'] == "" || $_POST['fri_close'] == "" || $_POST['fri_package'] == "") {
		$working_hours['friday'] = array('open' => "", 'close' => "", 'package' => "", 'label' => "");
	} else if (strtotime($_POST['fri_open']) >= strtotime($_POST['fri_close'])) {
		$flag = 1;
	} else {
		$fri_package	=	$_POST['fri_package'];
		$working_hours['friday'] = array('open' => date("G:i", strtotime($_POST['fri_open'])), 'close' => date("G:i", strtotime($_POST['fri_close'])), 'package' => $_POST['fri_package'], 'label' => $_POST['fri_label']);
	}

	if ($_POST['sat_open'] == "" || $_POST['sat_close'] == "" || $_POST['sat_package'] == "") {
		$working_hours['saturday'] = array('open' => "", 'close' => "", 'package' => "", 'label' => "");
	} else if (strtotime($_POST['sat_open']) >= strtotime($_POST['sat_close'])) {
		$flag = 1;
	} else {
		$sat_package	=	$_POST['sat_package'];
		$working_hours['saturday'] = array('open' => date("G:i", strtotime($_POST['sat_open'])), 'close' => date("G:i", strtotime($_POST['sat_close'])), 'package' => $_POST['sat_package'], 'label' => $_POST['sat_label']);
	}
	if ($_POST['sun_open'] == "" || $_POST['sun_close'] == "" || $_POST['sun_package'] == "") {
		$working_hours['sunday'] = array('open' => "", 'close' => "", 'package' => "", 'label' => "");
	} else if (strtotime($_POST['sun_open']) >= strtotime($_POST['sun_close'])) {
		$flag = 1;
	} else {
		$sun_package	=	$_POST['sun_package'];
		$working_hours['sunday'] = array('open' => date("G:i", strtotime($_POST['sun_open'])), 'close' => date("G:i", strtotime($_POST['sun_close'])), 'package' => $_POST['sun_package'], 'label' => $_POST['sun_label']);
	}
	////////////BLocking hours//////////////////
	if ($_POST['mon_block_open'] == "" || $_POST['mon_block_close'] == "") {
		$blocking_hours['monday'] = array('open' => "", 'close' => "");
	} else if (strtotime($_POST['mon_block_open']) >= strtotime($_POST['mon_block_close'])) {
		$flag = 1;
	} else if (strtotime($_POST['mon_block_open']) < strtotime($_POST['mon_open']) && strtotime($_POST['mon_block_close']) > strtotime($_POST['mon_close'])) {
		$flag = 2;
	} else {
		$blocking_hours['monday'] = array('open' => date("G:i", strtotime($_POST['mon_block_open'])), 'close' => date("G:i", strtotime($_POST['mon_block_close'])));
	}

	if ($_POST['tue_block_open'] == "" || $_POST['tue_block_close'] == "") {
		$blocking_hours['tuesday'] = array('open' => "", 'close' => "");
	} else if (strtotime($_POST['tue_block_open']) >= strtotime($_POST['tue_block_close'])) {
		$flag = 1;
	} else if (strtotime($_POST['tue_block_open']) < strtotime($_POST['tue_open']) && strtotime($_POST['tue_block_close']) > strtotime($_POST['tue_close'])) {
		$flag = 2;
	} else {
		$blocking_hours['tuesday'] = array('open' => date("G:i", strtotime($_POST['tue_block_open'])), 'close' => date("G:i", strtotime($_POST['tue_block_close'])));
	}

	if ($_POST['wed_block_open'] == "" || $_POST['wed_block_close'] == "") {
		$blocking_hours['wednesday'] = array('open' => "", 'close' => "");
	} else if (strtotime($_POST['wed_block_open']) >= strtotime($_POST['wed_block_close'])) {
		$flag = 1;
	} else if (strtotime($_POST['wed_block_open']) < strtotime($_POST['wed_open']) && strtotime($_POST['wed_block_close']) > strtotime($_POST['wed_close'])) {
		$flag = 2;
	} else {
		$blocking_hours['wednesday'] = array('open' => date("G:i", strtotime($_POST['wed_open'])), 'close' => date("G:i", strtotime($_POST['wed_block_close'])));
	}

	if ($_POST['thu_block_open'] == "" || $_POST['thu_block_close'] == "") {
		$blocking_hours['thursday'] = array('open' => "", 'close' => "");
	} else if (strtotime($_POST['thu_block_open']) >= strtotime($_POST['thu_block_close'])) {
		$flag = 1;
	} else if (strtotime($_POST['thu_block_open']) < strtotime($_POST['thu_open']) && strtotime($_POST['thu_block_close']) > strtotime($_POST['thu_close'])) {
		$flag = 2;
	} else {
		$blocking_hours['thursday'] = array('open' => date("G:i", strtotime($_POST['thu_block_open'])), 'close' => date("G:i", strtotime($_POST['thu_block_close'])));
	}

	if ($_POST['fri_block_open'] == "" || $_POST['fri_block_close'] == "") {
		$blocking_hours['friday'] = array('open' => "", 'close' => "");
	} else if (strtotime($_POST['fri_block_open']) >= strtotime($_POST['fri_block_close'])) {
		$flag = 1;
	} else if (strtotime($_POST['fri_block_open']) < strtotime($_POST['fri_open']) && strtotime($_POST['fri_block_close']) > strtotime($_POST['fri_close'])) {
		$flag = 2;
	} else {
		$blocking_hours['friday'] = array('open' => date("G:i", strtotime($_POST['fri_block_open'])), 'close' => date("G:i", strtotime($_POST['fri_block_close'])));
	}

	if ($_POST['sat_block_open'] == "" || $_POST['sat_block_close'] == "") {
		$blocking_hours['saturday'] = array('open' => "", 'close' => "");
	} else if (strtotime($_POST['sat_block_open']) >= strtotime($_POST['sat_block_close'])) {
		$flag = 1;
	} else if (strtotime($_POST['sat_block_open']) < strtotime($_POST['sat_open']) && strtotime($_POST['sat_block_close']) > strtotime($_POST['sat_close'])) {
		$flag = 2;
	} else {
		$blocking_hours['saturday'] = array('open' => date("G:i", strtotime($_POST['sat_block_open'])), 'close' => date("G:i", strtotime($_POST['sat_block_close'])));
	}

	if ($_POST['sun_block_open'] == "" || $_POST['sun_block_close'] == "") {
		$blocking_hours['sunday'] = array('open' => "", 'close' => "");
	} else if (strtotime($_POST['sun_block_open']) >= strtotime($_POST['sun_block_close'])) {
		$flag = 1;
	} else if (strtotime($_POST['sun_block_open']) < strtotime($_POST['sun_open']) && strtotime($_POST['sun_block_close']) > strtotime($_POST['sun_close'])) {
		$flag = 2;
	} else {
		$blocking_hours['sunday'] = array('open' => date("G:i", strtotime($_POST['sun_block_open'])), 'close' => date("G:i", strtotime($_POST['sun_block_close'])));
	}
	if ($_POST['customlabelBwc'] != "" && $_POST['customlabelShoot'] != "") {

		if ($_POST['customlabelBwc'] == $_POST['customlabelShoot']) {
			$flag = 3;
		}
	}


	// $name = str_replace("\'","'",$_POST['name']); 
	global $wpdb;
	if (isset($_POST['status'])) {
		$status = $_POST['status'];
	} else {
		$status = 0;
	}

	
	$args = array(
		"name" => str_replace("\'", "'", $_POST['name']),
		"phone" => $_POST['phone'],
		"platform" => $_POST['platform'],
		"customlabelBwc" => $_POST['customlabelBwc'],
		"customlabelShoot" => $_POST['customlabelShoot'],
		"status" => $status,
		"description" => str_replace("\'", "'", $_POST['description']),
		"address" => str_replace("\'", "'", $_POST['address']),
		"working_hours" => json_encode($working_hours),
		"blocking_hours" => json_encode($blocking_hours)
	);


	if ($flag == 0) {
		if ($_POST['id']) {
			$args = array(
				"name" => str_replace("\'", "'", $_POST['name']),
				"phone" => $_POST['phone'],
				"platform" => $_POST['platform'],
				"customlabelBwc" => $_POST['customlabelBwc'],
				"customlabelShoot" => $_POST['customlabelShoot'],
				"status" => $status,
				"description" => str_replace("\'", "'", $_POST['description']),
				"address" => str_replace("\'", "'", $_POST['address']),
				"working_hours" => json_encode($working_hours),
				"blocking_hours" => json_encode($blocking_hours)
			);
			$monday = date('Y-m-d', strtotime('monday this week'));

			$where = array("id" => $_POST['id']);
			$sql = $wpdb->update(DB_COACHING_LOCATIONS, $args, $where);

			/////////////SYNC WHERE/////////////////
			$loc_id = $_POST['id'];
			$wpdb->query("DELETE FROM " . DB_WORKING_HOURS . " WHERE `location_id` = '$loc_id' AND `start_date` = '$monday'");
			global $wpdb;
			$sync = array(
				"location_id" => $loc_id,
				"start_date" => $monday,
				"end_date" => $monday,
				"working_hours" => json_encode($working_hours),
				"blocking_hours" => json_encode($blocking_hours)
			);

			$wpdb->insert(DB_WORKING_HOURS, $sync);
			//---------------------------------------------------------------------------------------------------
			global $wpdb;
			$table_name = $wpdb->prefix . 'siab_perage_locations';
			//-----------------------Monday
			$location_id = $loc_id;
			$day = "Monday";
			$Monday_stime = $_POST['Monday_stime'];
			$Monday_etime = $_POST['Monday_etime'];
			$Monday_grade = $_POST['Monday_grade'];
			$Monday_label = $_POST['Monday_label'];
			$counter = 1;
			if (isset($_POST['Monday_stime'])) {
				foreach (array_map(null, $Monday_stime, $Monday_etime, $Monday_grade,$Monday_label) as list($stime, $etime, $mgrade,$mlabel)) {
					$grade_hours['key' . $counter] = array(
						'open' => date("G:i", strtotime($stime)),
						'close' => date("G:i", strtotime($etime)),
						'grade' => $mgrade,
						'label' => $mlabel,
					);
					$counter++;
				}
				$count = count($grade_hours);
				$existing_record = $wpdb->get_row(
					$wpdb->prepare(
						"SELECT * FROM $table_name WHERE location_id = %d AND day = %s",
						$location_id,
						$day
					)
				);
				if ($count >= 1) {
					if ($existing_record) {
						$data = array(
							'grade_hours' => json_encode($grade_hours)
						);
						$where = array(
							'location_id' => $location_id,
							'day' => $day
						);
						$wpdb->update($table_name, $data, $where);
					} else {
						$data = array(
							'location_id' => $location_id,
							'day' => $day,
							'grade_hours' => json_encode($grade_hours),
							'is_deleted' => 0,
						);
						$wpdb->insert($table_name, $data);
					}
				} else {
					if ($existing_record) {
						$where = array(
							'location_id' => $location_id,
							'day' => $day
						);
						$wpdb->delete($table_name, $where);
					}
				}
				$statusArr = array("status" => False, "message" => $count);
			} else {
				$where = array(
					'location_id' => $location_id,
					'day' => $day
				);
				$wpdb->delete($table_name, $where);
			}
			//die( json_encode($statusArr)); 
			//-------------------Tuesday
			$location_id = $loc_id;
			$day = "Tuesday";
			$Tuesday_stime = $_POST['Tuesday_stime'];
			$Tuesday_etime = $_POST['Tuesday_etime'];
			$Tuesday_grade = $_POST['Tuesday_grade'];
			$Tuesday_label = $_POST['Tuesday_label'];
			$counter = 1;
			if (isset($_POST['Tuesday_stime'])) {
				foreach (array_map(null, $Tuesday_stime, $Tuesday_etime, $Tuesday_grade,$Tuesday_label) as list($stime, $etime, $tugrade,$tulabel)) {
					$tuegrade_hours['key' . $counter] = array(
						'open' => date("G:i", strtotime($stime)),
						'close' => date("G:i", strtotime($etime)),
						'grade' => $tugrade,
						'label' => $tulabel
					);
					$counter++;
				}
				$existing_record = $wpdb->get_row(
					$wpdb->prepare(
						"SELECT * FROM $table_name WHERE location_id = %d AND day = %s",
						$location_id,
						$day
					)
				);
				if ($existing_record) {
					$tuedata = array(
						'grade_hours' => json_encode($tuegrade_hours)
					);
					$where = array(
						'location_id' => $location_id,
						'day' => $day
					);
					$wpdb->update($table_name, $tuedata, $where);
				} else {
					$tuedata = array(
						'location_id' => $location_id,
						'day' => $day,
						'grade_hours' => json_encode($tuegrade_hours),
						'is_deleted' => 0,
					);
					$wpdb->insert($table_name, $tuedata);
				}
			} else {
				$where = array(
					'location_id' => $location_id,
					'day' => $day
				);
				$wpdb->delete($table_name, $where);
			}
			//-------------------Wednesday
			$location_id = $loc_id;
			$day = "Wednesday";
			$Wednesday_stime = $_POST['Wednesday_stime'];
			$Wednesday_etime = $_POST['Wednesday_etime'];
			$Wednesday_grade = $_POST['Wednesday_grade'];
			$Wednesday_label = $_POST['Wednesday_label'];
			$counter = 1;
			if (isset($_POST['Wednesday_stime'])) {
				foreach (array_map(null, $Wednesday_stime, $Wednesday_etime, $Wednesday_grade, $Wednesday_label) as list($stime, $etime, $wgrade, $wlabel)) {
					$wedgrade_hours['key' . $counter] = array(
						'open' => date("G:i", strtotime($stime)),
						'close' => date("G:i", strtotime($etime)),
						'grade' => $wgrade,
						'label' => $wlabel
					);
					$counter++;
				}
				$existing_record = $wpdb->get_row(
					$wpdb->prepare(
						"SELECT * FROM $table_name WHERE location_id = %d AND day = %s",
						$location_id,
						$day
					)
				);
				if ($existing_record) {
					$weddata = array(
						'grade_hours' => json_encode($wedgrade_hours)
					);
					$where = array(
						'location_id' => $location_id,
						'day' => $day
					);
					$wpdb->update($table_name, $weddata, $where);
				} else {
					$weddata = array(
						'location_id' => $location_id,
						'day' => $day,
						'grade_hours' => json_encode($wedgrade_hours),
						'is_deleted' => 0,
					);
					$wpdb->insert($table_name, $weddata);
				}
			} else {
				$where = array(
					'location_id' => $location_id,
					'day' => $day
				);
				$wpdb->delete($table_name, $where);
			}
			//-------------------Thursday
			$location_id = $loc_id;
			$day = "Thursday";
			$Thursday_stime = $_POST['Thursday_stime'];
			$Thursday_etime = $_POST['Thursday_etime'];
			$Thursday_grade = $_POST['Thursday_grade'];
			$Thursday_label = $_POST['Thursday_label'];
			$counter = 1;
			if (isset($_POST['Thursday_stime'])) {
				foreach (array_map(null, $Thursday_stime, $Thursday_etime, $Thursday_grade, $Thursday_label) as list($stime, $etime, $thgrade, $thlabel)) {
					$thugrade_hours['key' . $counter] = array(
						'open' => date("G:i", strtotime($stime)),
						'close' => date("G:i", strtotime($etime)),
						'grade' => $thgrade,
						'label' => $thlabel
					);
					$counter++;
				}
				$existing_record = $wpdb->get_row(
					$wpdb->prepare(
						"SELECT * FROM $table_name WHERE location_id = %d AND day = %s",
						$location_id,
						$day
					)
				);
				if ($existing_record) {
					$thudata = array(
						'grade_hours' => json_encode($thugrade_hours)
					);
					$where = array(
						'location_id' => $location_id,
						'day' => $day
					);
					$wpdb->update($table_name, $thudata, $where);
				} else {
					$thudata = array(
						'location_id' => $location_id,
						'day' => $day,
						'grade_hours' => json_encode($thugrade_hours),
						'is_deleted' => 0,
					);
					$wpdb->insert($table_name, $thudata);
				}
			} else {
				$where = array(
					'location_id' => $location_id,
					'day' => $day
				);
				$wpdb->delete($table_name, $where);
			}
			//-------------------Friday
			$location_id = $loc_id;
			$day = "Friday";
			$Friday_stime = $_POST['Friday_stime'];
			$Friday_etime = $_POST['Friday_etime'];
			$Friday_grade = $_POST['Friday_grade'];
			$Friday_label = $_POST['Friday_label'];
			$counter = 1;
			if (isset($_POST['Friday_stime'])) {
				foreach (array_map(null, $Friday_stime, $Friday_etime, $Friday_grade, $Friday_label) as list($stime, $etime, $fgrade,$flabel)) {
					$frigrade_hours['key' . $counter] = array(
						'open' => date("G:i", strtotime($stime)),
						'close' => date("G:i", strtotime($etime)),
						'grade' => $fgrade,
						'label' => $flabel
					);
					$counter++;
				}
				$existing_record = $wpdb->get_row(
					$wpdb->prepare(
						"SELECT * FROM $table_name WHERE location_id = %d AND day = %s",
						$location_id,
						$day
					)
				);
				if ($existing_record) {
					$fridata = array(
						'grade_hours' => json_encode($frigrade_hours)
					);
					$where = array(
						'location_id' => $location_id,
						'day' => $day
					);
					$wpdb->update($table_name, $fridata, $where);
				} else {
					$fridata = array(
						'location_id' => $location_id,
						'day' => $day,
						'grade_hours' => json_encode($frigrade_hours),
						'is_deleted' => 0,
					);
					$wpdb->insert($table_name, $fridata);
				}
			} else {
				$where = array(
					'location_id' => $location_id,
					'day' => $day
				);
				$wpdb->delete($table_name, $where);
			}
			//-------------------Saturday
			$location_id = $loc_id;
			$day = "Saturday";
			$Saturday_stime = $_POST['Saturday_stime'];
			$Saturday_etime = $_POST['Saturday_etime'];
			$Saturday_grade = $_POST['Saturday_grade'];
			$Saturday_label = $_POST['Saturday_label'];
			$counter = 1;
			if (isset($_POST['Saturday_stime'])) {
				foreach (array_map(null, $Saturday_stime, $Saturday_etime, $Saturday_grade, $Saturday_label) as list($stime, $etime, $sgrade, $slabel)) {
					$satgrade_hours['key' . $counter] = array(
						'open' => date("G:i", strtotime($stime)),
						'close' => date("G:i", strtotime($etime)),
						'grade' => $sgrade,
						'label' => $slabel
					);
					$counter++;
				}
				$existing_record = $wpdb->get_row(
					$wpdb->prepare(
						"SELECT * FROM $table_name WHERE location_id = %d AND day = %s",
						$location_id,
						$day
					)
				);
				if ($existing_record) {
					$satdata = array(
						'grade_hours' => json_encode($satgrade_hours)
					);
					$where = array(
						'location_id' => $location_id,
						'day' => $day
					);
					$wpdb->update($table_name, $satdata, $where);
				} else {
					$satdata = array(
						'location_id' => $location_id,
						'day' => $day,
						'grade_hours' => json_encode($satgrade_hours),
						'is_deleted' => 0,
					);
					$wpdb->insert($table_name, $satdata);
				}
			} else {
				$where = array(
					'location_id' => $location_id,
					'day' => $day
				);
				$wpdb->delete($table_name, $where);
			}
			//-------------------Sunday
			$location_id = $loc_id;
			$day = "Sunday";
			$Sunday_stime = $_POST['Sunday_stime'];
			$Sunday_etime = $_POST['Sunday_etime'];
			$Sunday_grade = $_POST['Sunday_grade'];
			$Sunday_label = $_POST['Sunday_label'];
			$counter = 1;
			if (isset($_POST['Sunday_stime'])) {
				foreach (array_map(null, $Sunday_stime, $Sunday_etime, $Sunday_grade, $Sunday_label) as list($stime, $etime, $sugrade, $sulabel)) {
					$sungrade_hours['key' . $counter] = array(
						'open' => date("G:i", strtotime($stime)),
						'close' => date("G:i", strtotime($etime)),
						'grade' => $sugrade,
						'label' => $sulabel
					);
					$counter++;
				}
				$existing_record = $wpdb->get_row(
					$wpdb->prepare(
						"SELECT * FROM $table_name WHERE location_id = %d AND day = %s",
						$location_id,
						$day
					)
				);
				if ($existing_record) {
					$sundata = array(
						'grade_hours' => json_encode($sungrade_hours)
					);
					$where = array(
						'location_id' => $location_id,
						'day' => $day
					);
					$wpdb->update($table_name, $sundata, $where);
				} else {
					$sundata = array(
						'location_id' => $location_id,
						'day' => $day,
						'grade_hours' => json_encode($sungrade_hours),
						'is_deleted' => 0,
					);
					$wpdb->insert($table_name, $sundata);
				}
			} else {
				$where = array(
					'location_id' => $location_id,
					'day' => $day
				);
				$wpdb->delete($table_name, $where);
			}
			//---------------------------------------------------------------------------------------------------

			$statusArr = array("status" => TRUE, "type" => 1, "message" => "Coaching Location has been updated successfully.");
			// set_scheduled_values('', 'second');
			die(json_encode($statusArr));
		} else {
			$sql = $wpdb->insert(DB_COACHING_LOCATIONS, $args);
			$lastid = $wpdb->insert_id;
			$monday = date('Y-m-d', strtotime('monday this week'));
			$wpdb->query("DELETE FROM " . DB_WORKING_HOURS . " WHERE `location_id` = '$lastid' AND `start_date` = '$monday'");
			if ($sql) {
				global $wpdb;
				$sync = array(
					"location_id" => $lastid,
					"start_date" => $monday,
					"end_date" => $monday,
					"working_hours" => json_encode($working_hours),
					"blocking_hours" => json_encode($blocking_hours),

				);

				$wpdb->insert(DB_WORKING_HOURS, $sync);
				//---------------------------------------------------------------------------------------------------
				global $wpdb;
				$table_name = $wpdb->prefix . 'siab_perage_locations';
				//-----------------------Monday
				if ($_GET['id']) $location_id = $_GET['id'];
				else $location_id = $lastid;
				$day = "Monday";
				$Monday_stime = $_POST['Monday_stime'];
				$Monday_etime = $_POST['Monday_etime'];
				$Monday_grade = $_POST['Monday_grade'];
				$Monday_label = $_POST['Monday_label'];
				$counter = 1;
				if (isset($_POST['Monday_stime'])) {
					foreach (array_map(null, $Monday_stime, $Monday_etime, $Monday_grade, $Monday_label) as list($stime, $etime, $mgrade, $mlabel)) {
						$mongrade_hours['key' . $counter] = array(
							'open' => date("G:i", strtotime($stime)),
							'close' => date("G:i", strtotime($etime)),
							'grade' => $mgrade,
							'label' => $mlabel
						);
						$counter++;
					}

					$data = array(
						'location_id' => $location_id,
						'day' => $day,
						'grade_hours' => json_encode($mongrade_hours),
						'is_deleted' => 0,
					);
					$wpdb->insert($table_name, $data);
				}
				//-------------------Tuesday
				if ($_POST['id']) $location_id = $_POST['id'];
				else $location_id = $lastid;
				$day = "Tuesday";
				$Tuesday_stime = $_POST['Tuesday_stime'];
				$Tuesday_etime = $_POST['Tuesday_etime'];
				$Tuesday_grade = $_POST['Tuesday_grade'];
				$Tuesday_label = $_POST['Tuesday_label'];
				$counter = 1;
				if (isset($_POST['Tuesday_stime'])) {
					foreach (array_map(null, $Tuesday_stime, $Tuesday_etime, $Tuesday_grade, $Tuesday_label) as list($stime, $etime, $tugrade, $tulabel)) {
						$tuegrade_hours['key' . $counter] = array(
							'open' => date("G:i", strtotime($stime)),
							'close' => date("G:i", strtotime($etime)),
							'grade' => $tugrade,
							'label' => $tulabel
						);
						$counter++;
					}

					$tuedata = array(
						'location_id' => $location_id,
						'day' => $day,
						'grade_hours' => json_encode($tuegrade_hours),
						'is_deleted' => 0,
					);
					$wpdb->insert($table_name, $tuedata);
				}
				//-------------------Wednesday
				if ($_POST['id']) $location_id = $_POST['id'];
				else $location_id = $lastid;
				$day = "Wednesday";
				$Wednesday_stime = $_POST['Wednesday_stime'];
				$Wednesday_etime = $_POST['Wednesday_etime'];
				$Wednesday_grade = $_POST['Wednesday_grade'];
				$Wednesday_label = $_POST['Wednesday_label'];
				$counter = 1;
				if (isset($_POST['Wednesday_stime'])) {
					foreach (array_map(null, $Wednesday_stime, $Wednesday_etime, $Wednesday_grade, $Wednesday_label) as list($stime, $etime, $wgrade, $wlabel)) {
						$wedgrade_hours['key' . $counter] = array(
							'open' => date("G:i", strtotime($stime)),
							'close' => date("G:i", strtotime($etime)),
							'grade' => $wgrade,
							'label' => $wlabel
						);
						$counter++;
					}

					$weddata = array(
						'location_id' => $location_id,
						'day' => $day,
						'grade_hours' => json_encode($wedgrade_hours),
						'is_deleted' => 0,
					);
					$wpdb->insert($table_name, $weddata);
				}
				//-------------------Thursday
				if ($_POST['id']) $location_id = $_POST['id'];
				else $location_id = $lastid;
				$day = "Thursday";

				$Thursday_stime = $_POST['Thursday_stime'];
				$Thursday_etime = $_POST['Thursday_etime'];
				$Thursday_grade = $_POST['Thursday_grade'];
				$Thursday_label = $_POST['Thursday_label'];
				$counter = 1;
				if (isset($_POST['Thursday_stime'])) {
					foreach (array_map(null, $Thursday_stime, $Thursday_etime, $Thursday_grade, $Thursday_label) as list($stime, $etime, $thgrade, $thlabel)) {
						$thugrade_hours['key' . $counter] = array(
							'open' => date("G:i", strtotime($stime)),
							'close' => date("G:i", strtotime($etime)),
							'grade' => $thgrade,
							'label' => $thlabel
						);
						$counter++;
					}

					$thudata = array(
						'location_id' => $location_id,
						'day' => $day,
						'grade_hours' => json_encode($thugrade_hours),
						'is_deleted' => 0,
					);
					$wpdb->insert($table_name, $thudata);
				}
				//-------------------Friday
				if ($_POST['id']) $location_id = $_POST['id'];
				else $location_id = $lastid;
				$day = "Friday";
				$Friday_stime = $_POST['Friday_stime'];
				$Friday_etime = $_POST['Friday_etime'];
				$Friday_grade = $_POST['Friday_grade'];
				$Friday_label = $_POST['Friday_label'];
				$counter = 1;
				if (isset($_POST['Friday_stime'])) {
					foreach (array_map(null, $Friday_stime, $Friday_etime, $Friday_grade, $Friday_label) as list($stime, $etime, $fgrade, $flabel)) {
						$frigrade_hours['key' . $counter] = array(
							'open' => date("G:i", strtotime($stime)),
							'close' => date("G:i", strtotime($etime)),
							'grade' => $fgrade,
							'label' => $flabel
						);
						$counter++;
					}

					$fridata = array(
						'location_id' => $location_id,
						'day' => $day,
						'grade_hours' => json_encode($frigrade_hours),
						'is_deleted' => 0,
					);
					$wpdb->insert($table_name, $fridata);
				}
				//-------------------Saturday
				if ($_POST['id']) $location_id = $_POST['id'];
				else $location_id = $lastid;
				$day = "Saturday";
				$Saturday_stime = $_POST['Saturday_stime'];
				$Saturday_etime = $_POST['Saturday_etime'];
				$Saturday_grade = $_POST['Saturday_grade'];
				$Saturday_label = $_POST['Saturday_label'];
				$counter = 1;
				if (isset($_POST['Saturday_stime'])) {
					foreach (array_map(null, $Saturday_stime, $Saturday_etime, $Saturday_grade, $Saturday_label) as list($stime, $etime, $sgrade, $slabel)) {
						$satgrade_hours['key' . $counter] = array(
							'open' => date("G:i", strtotime($stime)),
							'close' => date("G:i", strtotime($etime)),
							'grade' => $sgrade,
							'label' => $slabel,
						);
						$counter++;
					}

					$satdata = array(
						'location_id' => $location_id,
						'day' => $day,
						'grade_hours' => json_encode($satgrade_hours),
						'is_deleted' => 0,
					);
					$wpdb->insert($table_name, $satdata);
				}
				//-------------------Sunday
				if ($_POST['id']) $location_id = $_POST['id'];
				else $location_id = $lastid;
				$day = "Sunday";
				$Sunday_stime = $_POST['Sunday_stime'];
				$Sunday_etime = $_POST['Sunday_etime'];
				$Sunday_grade = $_POST['Sunday_grade'];
				$Sunday_label = $_POST['Sunday_label'];
				$counter = 1;
				if (isset($_POST['Sunday_stime'])) {
					foreach (array_map(null, $Sunday_stime, $Sunday_etime, $Sunday_grade, $Sunday_label) as list($stime, $etime, $sugrade, $sulabel)) {
						$sungrade_hours['key' . $counter] = array(
							'open' => date("G:i", strtotime($stime)),
							'close' => date("G:i", strtotime($etime)),
							'grade' => $sugrade,
							'label' => $sulabel
						);
						$counter++;
					}

					$sundata = array(
						'location_id' => $location_id,
						'day' => $day,
						'grade_hours' => json_encode($sungrade_hours),
						'is_deleted' => 0,
					);
					$wpdb->insert($table_name, $sundata);
				}
				//---------------------------------------------------------------------------------------------------
				// echo $wpdb->last_query;
				$statusArr = array("status" => TRUE, "type" => 0, "message" => "Coaching Location has been created successfully.");

				set_scheduled_values('', 'second');
				die(json_encode($statusArr));
			} else {
				$statusArr = array("status" => False, "message" => "You have successfully submitted your details");
			}
		}
	} else if ($flag == 1) {
		$statusArr = array("status" => False, "message" => "Start time should be less than End time");
		die(json_encode($statusArr));
	} else if ($flag == 2) {
		$statusArr = array("status" => False, "message" => "Blocking Hours should be in between Working Hours");
		die(json_encode($statusArr));
	} else if ($flag == 3) {
		$statusArr = array("status" => False, "message" => "Label for BWC and Shootin School Cannot be Same");
		die(json_encode($statusArr));
	}

	die($wpdb->last_query);
}

function fetch_grade_values()
{
	global $wpdb;

	// Replace 'your_table_name' with your actual table name
	$table_name = $wpdb->prefix . 'siab_grade_management';

	// Perform the database query
	$grades = $wpdb->get_results("SELECT * FROM $table_name where status=1");

	// Check if there are grades to return
	if ($grades) {
		// Return the results as JSON
		echo json_encode($grades);
	} else {
		// Handle cases where no data is found
		echo json_encode([]); // Return an empty JSON array
	}

	wp_die(); // This is necessary to end the AJAX request.
}

add_action('wp_ajax_fetch_grade_values', 'fetch_grade_values');
add_action('wp_ajax_nopriv_fetch_grade_values', 'fetch_grade_values');



?>