break; case "sunday": case "Sunday": $day_id = 7; break; } $query_room_schedule = mysql_query("SELECT * FROM class_schedule_t WHERE room_code='{$room_code}' AND day='{$day_id}'") or die(mysql_error()); while ($row_room_schedule = mysql_fetch_assoc($query_room_schedule)) { $time_start = $row_room_schedule['time_start']; $time_end = $row_room_schedule['time_end']; $time_start = strtotime($time_start); $time_end = strtotime($time_end); //echo $time_start." - ".$time_end."\n"; //echo conflict_check($time_start, $time_end, $time, $time)."<br>"; //echo $time[0]."\n"; if (conflict_check($time_start, $time_end, $time, $time) == "conflict") { echo $row_room_schedule['schedule_id']; return; } } //echo $time_start; /* localtime(true); returns associative array with these indexes "tm_sec" - seconds, 0 to 59 "tm_min" - minutes, 0 to 59 "tm_hour" - hours, 0 to 23 "tm_mday" - day of the month, 1 to 31 "tm_mon" - month of the year, 0 (Jan) to 11 (Dec) "tm_year" - years since 1900 "tm_wday" - day of the week, 0 (Sun) to 6 (Sat) "tm_yday" - day of the year, 0 to 365
} else { echo $str_start . " = " . $str_end; } } echo "<br>"; $start1 = "12:00"; $end1 = "13:00"; $start2 = "13:00"; $end2 = "14:00"; $t_start1 = strtotime($start1); $t_end1 = strtotime($end1); $t_start2 = strtotime($start2); $t_end2 = strtotime($end2); echo "{$start1} - {$end1} <br>"; echo "{$start2} - {$end2} <br>"; echo conflict_check($t_start1, $t_end1, $t_start2, $t_end2); function conflict_check_print($t_start1, $t_end1, $t_start2, $t_end2) { if ($t_start1 >= $t_start2 && $t_start1 < $t_end2) { echo "conflict."; } else { echo "good."; } echo "<br>"; if ($t_end1 > $t_start2 && $t_end1 <= $t_end2) { echo "conflict."; } else { echo "good."; } echo "<br>"; if ($t_start2 >= $t_start1 && $t_start2 < $t_end1) {
function is_faculty_loaded_e($class_id, $start, $end, $days, $schedule_id) { $query = mysql_query("SELECT * FROM class_t WHERE class_id={$class_id}"); $row = mysql_fetch_assoc($query); $emp_id = $row['teacher_id']; if ($emp_id == NULL) { return ""; } $sy_id = get_active_sy(); foreach ($days as $day) { $query = mysql_query("SELECT * FROM class_schedule_t WHERE schedule_id <> {$schedule_id} AND day='{$day}' AND class_id IN (SELECT class_id FROM class_t WHERE teacher_id='{$emp_id}' AND sy_id={$sy_id}) ") or die(mysql_error() . " yeh"); while ($row = mysql_fetch_assoc($query)) { $db_start = $row['time_start']; $db_end = $row['time_end']; $t_start = strtotime($start); $t_end = strtotime($end); $t_db_start = strtotime($db_start); $t_db_end = strtotime($db_end); if ("conflict" == conflict_check($t_start, $t_end, $t_db_start, $t_db_end)) { $class_id = $row['class_id']; $query_subject = mysql_query("SELECT subject_t.subject_title FROM subject_t, class_t WHERE class_t.class_id={$class_id} AND subject_t.subject_code=class_t.subject_code"); $row_subject = mysql_fetch_assoc($query_subject); $subject = $row_subject['subject_title']; $st = date('h:i A', $t_db_start); $en = date('h:i A', $t_db_end); return "Teacher has conflicting schedule {$subject} @ {$st} - {$en}."; //$row_subject['subject_title']; } } } return ""; }