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_copy.php
<?php

function add_location(){
	global $wpdb;
	$id = '';
	$data = '';
	if(isset($_GET['id'])){
		$id = $_GET['id'];
        $data = $wpdb->get_row("select * from " . DB_COACHING_LOCATIONS . " where ID ='$id'");

       	if($data->working_hours){
       	 	$working_hours = json_decode($data->working_hours, TRUE);
       }
       	if($data->blocking_hours){
       	 	$blocking_hours = json_decode($data->blocking_hours, TRUE);
       }

	}

	?>
	<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>
						<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') 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_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_open').value = '',document.getElementById('select1').value = '0'"  >X</button>

							</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') 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_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_open').value = '',document.getElementById('select2').value = '0'"  >X</button>

							</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') 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_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_open').value = '',document.getElementById('select3').value = '0'"  >X</button>

							</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') 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_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_open').value = '',document.getElementById('select4').value = '0'"  >X</button>

							</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') 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_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_open').value = '',document.getElementById('select5').value = '0'"  >X</button>

							</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') 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_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_open').value = '',document.getElementById('select6').value = '0'"  >X</button>

							</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') 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_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_open').value = '',document.getElementById('select7').value = '0'"  >X</button>

							</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'] == ""){
			$working_hours['monday'] = array( 'open' => "", 'close' => "", 'package' => "" );
		} 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']);
		}

		if($_POST['tue_open'] == "" || $_POST['tue_close'] == "" || $_POST['tue_package'] == ""){
			$working_hours['tuesday'] = array( 'open' => "", 'close' => "", 'package' => "" );
		} 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']);
		}

		if($_POST['wed_open'] == "" || $_POST['wed_close'] == "" || $_POST['wed_package'] == ""){
			$working_hours['wednesday'] = array( 'open' => "", 'close' => "", 'package' => "" );
		} 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'] );
		}

		if($_POST['thu_open'] == "" || $_POST['thu_close'] == "" || $_POST['thu_package'] == ""){
			$working_hours['thursday'] = array( 'open' => "", 'close' => "", 'package' => "" );
		} 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'] );
		}

		if($_POST['fri_open'] == "" || $_POST['fri_close'] == "" || $_POST['fri_package'] == ""){
			$working_hours['friday'] = array( 'open' => "", 'close' => "" , 'package' => "");
		} 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']);
		}

		if($_POST['sat_open'] == "" || $_POST['sat_close'] == "" || $_POST['sat_package'] == ""){
			$working_hours['saturday'] = array( 'open' => "", 'close' => "" , 'package' => "");
		} 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']);
		}
		if($_POST['sun_open'] == "" || $_POST['sun_close'] == "" || $_POST['sun_package'] == ""){
			$working_hours['sunday'] = array( 'open' => "", 'close' => "", 'package' => "" );
		} 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'] );
		}
////////////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'])) );
		}

		// $name = str_replace("\'","'",$_POST['name']); 
		global $wpdb;
		$args = array(
			"name" =>str_replace("\'","'",$_POST['name']),
			"phone" =>$_POST['phone'],
			"status" =>$_POST['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']){
				$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);

				$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' ) );
				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);
					// 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));
		}

		die( $wpdb->last_query);
	}

?>