File: /var/www/html/shootinschool/wp-content/plugins/shootin-school-plugin/edit_instructor.php
<?php
function render_edit_siab_instructor()
{
global $wpdb;
// $allLocations = $wpdb->get_results("SELECT * FROM " . DB_COACHING_LOCATIONS);
$allLocations = $wpdb->get_results("SELECT * FROM " . DB_COACHING_LOCATIONS . " WHERE is_deleted = '0'");
$allSessions = $wpdb->get_results("SELECT * FROM " . DB_PACKAGE_SESSIONS);
$weekdays = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
$user = get_user_by('id', $_REQUEST['id']);
// if ( ! in_array( 'siab_instructor', (array) $user->roles ) ) {
// echo "<br/>You are Not allowed to view this page";
// exit();
// }
$allAvailabilities = $wpdb->get_results("SELECT * FROM " . DB_INSTRUCTORS_AVAILABILITY . " WHERE instructor_id = '$user->ID'", ARRAY_A);
$allOffDays = $wpdb->get_results("SELECT * FROM " . DB_INSTRUCTORS_OFF_DAYS . " WHERE instructor_id = '$user->ID'", ARRAY_A);
$phone = get_user_meta($user->id, $key = 'billing_billing_phone');
$issupervisor = get_user_meta($user->id, $key = 'issupervisor');
// Check if the meta exists
if ($issupervisor[0] !== 1) {
// Meta exists
$userTypevalue = 4;
} else {
// Meta doesn't exist
$userTypevalue = 2;
}
?>
<div class="wrap">
<div class="css_loader">Loading…</div>
<div class="alert alert-info" role="alert" style="border: 1px solid green;border-radius: 5px;">
<?php
if ($issupervisor[0] == 1) { ?>
<h3> Update Supervisor Availability </h3>
<a class="add-new-h2 btn btn-success" href="admin.php?page=siab-supervisors"> Back to Supervisor Listing</a>
<?php } else { ?>
<h3> Update Instructor Availability </h3>
<a class="add-new-h2 btn btn-success" href="admin.php?page=siab-instructors"> Back to Instructors Listing</a>
<?php } ?>
</div>
<form id="createinstructor">
<div class="form-group">
<label for="firstName">Name</label>
<input type="text" name="name" class="form-control" value="<?php echo $user->display_name; ?>" placeholder="Enter Name" required="required">
</div>
<!-- <div class="form-group">
<label for="lastName">Last Name</label>
<input type="text" name="lname" class="form-control" required="required">
</div> -->
<!-- <div class="form-group">
<label for="phone">Phone</label>
<input type="text" name="phone" class="form-control" required="required">
</div> -->
<div class="form-group">
<label for="emailText">Email</label>
<input type="email" class="form-control" name="email" value="<?php echo $user->user_email; ?>" placeholder="Enter Email" disabled="disabled">
</div>
<div class="form-group">
<label for="instructorPhone">Phone</label>
<input type="text" class="form-control" name="instructor_phone" value="<?php echo $phone[0]; ?> " placeholder="Enter PhoneNumber" required="required">
</div>
<div class="form-group">
<br /><label for="">Availability</label>
</div>
<!-- Start -->
<?php foreach ($weekdays as $day) { ?>
<div class="row">
<div class="col-md-4">
<strong style="color: #22a022;"> <?php echo strtoupper($day); ?> </strong>
<button type="button" class="btn btn-primary btn-xs addMoreLocation" onclick="addMorelocationadmin('<?php echo $day; ?>')"> + Add Availability</button>
<button type="button" class="btn btn-primary btn-xs setAllTimings" onclick="setAllTimings_admin('<?php echo $day; ?>')"> All hours/locations</button>
</div>
</div>
<br />
<div id="<?php echo $day; ?>_container">
<?php foreach ($allAvailabilities as $availability) {
if ($availability['weekday'] == $day) { ?>
<div class="row existing_data">
<!-- <div class="col-md-2">
<div class="form-group">
<select class="form-control session_sel">
<option value=""> -- Choose Session -- </option>
<?php foreach ($allSessions as $session) { ?>
<option value="<?php echo $session->id; ?>" <?php echo $session->id == $availability['session_id'] ? 'selected' : ''; ?>> <?php echo $session->session_name; ?> </option>
<?php } ?>
</select>
</div>
</div> -->
<div class="col-md-3">
<div class="form-group">
<input type="hidden" class="existing_data_id" value="<?php echo $availability['id']; ?>">
<select class="form-control loc_sel" onchange="getAvailability(this, '<?php echo $day; ?>')">
<option value=""> -- Choose Location -- </option>
<?php
$get_monday = date('Y-m-d', strtotime('monday this week'));
foreach ($allLocations as $key => $value) {
$CurrentWeekquery = $wpdb->get_row("SELECT * FROM " . DB_WORKING_HOURS . " WHERE `location_id` = '$value->id' AND `start_date` = '$get_monday'");
// echo $day;
// if(!empty($CurrentWeekquery)){
$working_hours = json_decode($CurrentWeekquery->working_hours);
if ($working_hours->{$day}->open == "" || $working_hours->{$day}->close == "") {
unset($allLocations[$key]);
// }
}
}
foreach ($allLocations as $single) { ?>
<option value="<?php echo $single->id; ?>" <?php echo $single->id == $availability['location_id'] ? 'selected' : ''; ?>> <?php echo $single->name; ?> </option>
<?php } ?>
</select>
</div>
</div>
<?php
$selectOne = renderSelectBoxInstructor($availability['location_id'], 'start', $day, $availability['start_time'], $availability['end_time']);
$selectTwo = renderSelectBoxInstructor($availability['location_id'], 'end', $day, $availability['start_time'], $availability['end_time']);
?>
<div class="col-md-3">
<div class="form-group">
<select class="form-control loc_start" onchange="getStartTime(this, '<?php echo $day; ?>')">
<?php echo $selectOne; ?>
</select>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<select class="form-control loc_end" onchange="getEndTime(this, '<?php echo $day; ?>')">
<?php echo $selectTwo; ?>
</select>
</div>
</div>
<div class="col-md-1">
<div class="form-group">
<button type="button" class="btn btn-danger btn-xs" onclick="this.parentNode.parentNode.parentNode.remove();">X</button>
</div>
</div>
</div>
<?php } ?>
<?php } ?>
<!-- Append Here -->
</div>
<hr>
<?php } ?>
<div class="row">
<div class="col-md-4">
<strong> Specify OFF DAYS </strong>
<button type="button" class="btn btn-primary btn-xs addOffDays" onclick="addOffDay()"> + Add Off day</button>
</div>
</div>
<br />
<div class="offday_Div" id="offday_Div">
<?php foreach ($allOffDays as $single) { ?>
<div class="row">
<div class="col-md-2">
<div class="form-group">
<input type="date" name="off_day[]" value="<?php echo $single['off_day']; ?>">
</div>
</div>
<div class="col-md-1">
<div class="form-group">
<button type="button" class="btn btn-danger btn-xs" onclick="this.parentNode.parentNode.parentNode.remove();">X</button>
</div>
</div>
</div>
<?php } ?>
<!-- Append Here -->
</div>
<br />
<div class="row">
<div class="col-md-2">
<button type="button" class="btn btn-success" onclick="saveInstructor('update', <?php echo $user->ID; ?>)"> Update </button>
</div>
</div>
</form>
</div>
<?php } ?>