function insert_schedule_entries($db_con, $class_id, $day, $time, $room) { //$schedule_details = array( "class_id"=>$class_id, "day"=>$day, "time"=>$time, "room"=>$room); $count = 0; $room = str_replace("-", " ", $room); $days = explode("/", $day); $times = explode("/", $time); $rooms = explode("/", $room); $building = explode(" ", $rooms[0])[0]; //echo $day." ".$time." ".$room." "; $count = count($days); if ($count < count($times)) { $count = count($times); } elseif ($count < count($rooms)) { $count = count($rooms); } for ($i = 0; $i < $count; $i++) { $day_i = $i < count($days) ? $i : count($days) - 1; $time_i = $i < count($times) ? $i : count($times) - 1; $room_i = $i < count($rooms) ? $i : count($rooms) - 1; $day_str = $days[$day_i]; $time = $times[$time_i]; $room = $rooms[$room_i]; if (is_numeric($room)) { $room = $building . " " . $room; } //echo $room." --------"; $building_code = strtolower($building); $building_code = insert_building($db_con, $building_code, ''); if ($building_code == NULL) { //notify : alert user that entry has building code not existing in the database continue; } $room_code = insert_room($db_con, $room, $building_code, NULL); //echo $room_code."- "; //echo $day_str." ".$time." ".$room." = "; $time_set = get_time_set($time); // returns array containing start time and end time of given time range $time_start = date("H:i:s", strtotime($time_set['time-start'])); $time_end = date("H:i:s", strtotime($time_set['time-end'])); $pos_m = stripos($day_str, "M"); $pos_t = stripos($day_str, "T"); $pos_w = stripos($day_str, "W"); $pos_th = stripos($day_str, "Th"); $pos_f = stripos($day_str, "F"); $pos_sat = stripos($day_str, "Sat"); //echo " [ ".$pos_m ." ] "; //echo " [ ".$pos_t ." ] "; //echo " [ ".$pos_w ." ] "; //echo " [ ".$pos_th." ] "; //echo " [ ".$pos_f ." ] "; if (is_numeric($pos_sat)) { $day = "saturday"; $day = 6; insert_schedule($db_con, $class_id, $day, $time_start, $time_end, $room_code); } else { if (is_numeric($pos_m)) { $day = "monday"; $day = 1; insert_schedule($db_con, $class_id, $day, $time_start, $time_end, $room_code); //echo "<br>monday<br>"; } if (is_numeric($pos_t)) { $check = true; if ($pos_t < strlen($day_str) - 1) { //echo "<br><br>".strcasecmp(substr($day_str, $pos_t+1, 1),"h"); if (strcasecmp(substr($day_str, $pos_t + 1, 1), "h") == 0) { $check = false; } } if ($check) { $day = "tuesday"; $day = 2; insert_schedule($db_con, $class_id, $day, $time_start, $time_end, $room_code); //echo "<br>tuesday<br>"; } } if (is_numeric($pos_w)) { $day = "wednesday"; $day = 3; insert_schedule($db_con, $class_id, $day, $time_start, $time_end, $room_code); //echo "<br>wednesday<br>"; } if (is_numeric($pos_th)) { $day = "thursday"; $day = 4; insert_schedule($db_con, $class_id, $day, $time_start, $time_end, $room_code); //echo "<br>thursday<br>"; } if (is_numeric($pos_f)) { $day = "friday"; $day = 5; insert_schedule($db_con, $class_id, $day, $time_start, $time_end, $room_code); //echo "<br>friday<br>"; } } } }
$count++; } echo "Copy class success :: {$count} entries<br>"; $count = 0; #Copy class schedule data $query_class_src = mysqli_query($src_db_con, "SELECT * FROM class_schedule_t") or die("Error in save_content.php : line 82 :: " . mysql_error($src_db_con)); while ($row_class_src = mysqli_fetch_array($query_class_src)) { $class_id = $row_class_src['class_id']; $day = $row_class_src['day']; $time_start = $row_class_src['time_start']; $time_end = $row_class_src['time_start']; $room_code = $row_class_src['room_code']; $room_code = NULL; insert_schedule($dest_db_con, $class_id, $day, $time_start, $time_end, $room_code); $count++; } echo "Copy class schedule success :: {$count} entries<br>"; $count = 0; #Copy Student Load data $query_load_src = mysqli_query($src_db_con, "SELECT * FROM student_load_t") or die("Error in save_content.php : line 82 :: " . mysql_error($src_db_con)); while ($row_load_src = mysqli_fetch_array($query_load_src)) { $class_id = $row_load_src['class_id']; $day = $row_load_src['day']; $time_start = $row_load_src['time_start']; $time_end = $row_load_src['time_end']; $room = $row_load_src['room']; insert_schedule($dest_db_con, $class_id, $day, $time_start, $time_end, $room); $count++; } echo "Copy student load success :: {$count} entries<br>"; echo "Hasayo";