/home/techb158/workloadmatch.com/workloadmatch.com/Manager/Inc
Edit: /home/techb158/workloadmatch.com/workloadmatch.com/Manager/Inc/AddGroup - Copy.php (4531B)
query($query);
$time_slots = [];
while ($row = $result->fetch_assoc()) {
$time_slots[] = $row; // Store each result as an array
}
// Check if the time slots were retrieved
if (empty($time_slots)) {
echo "No time slots found for the provided IDs.";
exit();
}
// Initialize variables to store the earliest Time_From and latest Time_To values
$earliest_time = null;
$latest_time = null;
// Now, we need to loop through $time_slots to get each time slot
$time_slot_values = [];
foreach ($time_slots as $slot) {
$time_slot_values[] = $slot['Time_Slot'];
// Check if this Time_From is earlier than the current earliest_time
if ($earliest_time === null || strtotime($slot['Time_From']) < strtotime($earliest_time)) {
$earliest_time = $slot['Time_From'];
}
// Check if this Time_To is later than the current latest_time
if ($latest_time === null || strtotime($slot['Time_To']) > strtotime($latest_time)) {
$latest_time = $slot['Time_To'];
}
}
// Joining all time slots into a single string for insertion
$time_slot_combined = implode(",", $time_slot_values);
$user_n = $_SESSION['user_id'];
$querys = "SELECT * FROM Manager_Profile WHERE Manager_ID = '$user_n'";
$results = $mysqli->query($querys);
$rows = $results->fetch_assoc();
$Admin_ID = $rows['Admin_ID'];
$Master_ID = $rows['Master_ID'];
$Manager_ID = $rows['Manager_ID'];
$Manager_ID_Profile = $rows['Manager_ID'];
$User_Type_ID = $rows['User_Type_ID'];
$query = "SELECT * FROM Manager_Group_Name WHERE Admin_ID = '$Admin_ID' AND Master_ID = '$Master_ID' AND Manager_ID = '$Manager_ID' AND Group_Name = '$Group_Name'";
$result = $mysqli->query($query);
$Managers = $result->fetch_assoc();
$Manager_Group_ID = $Managers['Manager_Group_ID'];
if ($Manager_Group_ID != "") {
header('Location: addgroup.php?error=Group Name already exists!');
exit();
} else {
$Register_Time = date("Y/m/d") . ' ' . date('H:i:s');
$weekendClass = isset($_POST['weekendClass']) ? 1 : 0;
// Now use the earliest_time for Time_From and latest_time for Time_To
if ($insert_stmt = $mysqli->prepare("INSERT INTO Manager_Group_Name (Admin_ID, Master_ID, Manager_ID, Program_ID, Weekend_Class, Group_Name, Group_Year, Time_Slot, Time_From, Time_To, Date_Time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
$insert_stmt->bind_param('sssssssssss', $Admin_ID, $Master_ID, $Manager_ID, $Program_ID, $weekendClass, $Group_Name, $Group_Year, $time_slot_combined, $earliest_time, $latest_time, $Register_Time);
if (!$insert_stmt->execute()) {
header('Location: addgroup.php?error=Registration failure to add Group Name!' . $insert_stmt->error());
exit();
} else {
header('Location: addgroup.php?error=Group Information added successfully!');
exit();
}
}
}
} else {
header('Location: addgroup.php?error=Registration failure please insert Group!');
exit();
}
}
?>