File "create.php"

Full path: /home2/santhos2/public_html/bharath-coe.firstmatrix.in.net/api/exam_timetable/create.php
File size: 1.57 KiB (1606 bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Back

<?php
require_once '../../config/config.php';
require_once '../helper/audit_log.php';
header('Content-Type: application/json');

try {
    $exam_subject_id = (int)($_POST['exam_subject_id'] ?? 0);
    $exam_date = trim($_POST['exam_date'] ?? '');
    $session = trim($_POST['session'] ?? 'FN');
    $start_time = trim($_POST['start_time'] ?? '');
    $end_time = trim($_POST['end_time'] ?? '');

    $errors=[];
    if ($exam_subject_id<=0) $errors[]='Exam Subject is required';
    if ($exam_date==='') $errors[]='Exam Date is required';
    if ($session==='') $errors[]='Session is required';
    if ($start_time==='') $errors[]='Start Time is required';
    if ($end_time==='') $errors[]='End Time is required';
    if ($errors) { echo json_encode(['status'=>'error','message'=>implode(', ', $errors)]); exit; }

    $stmt = $pdo->prepare('INSERT INTO exam_timetable (exam_subject_id, exam_date, session, start_time, end_time) VALUES (?,?,?,?,?)');
    $stmt->execute([$exam_subject_id, $exam_date, $session, $start_time, $end_time]);
    $id = (int)$pdo->lastInsertId();

    write_audit_log($pdo, [
        'module'=>'Exam Timetable','action'=>'create','entity_table'=>'exam_timetable','entity_id'=>$id,
        'after_data'=>compact('id','exam_subject_id','exam_date','session','start_time','end_time'),
        'message'=>'Exam timetable created'
    ]);
    echo json_encode(['status'=>'success','message'=>'Exam timetable created','data'=>['timetable_id'=>$id]]);
} catch (Throwable $e) {
    http_response_code(500);
    echo json_encode(['status'=>'error','message'=>$e->getMessage()]);
}
?>



PHP File Manager