File "create.php"
Full path: /home2/santhos2/public_html/bharath-coe.firstmatrix.in.net/api/grading_systems/create.php
File size: 1.18 KiB (1212 bytes)
MIME-type: text/x-php
Charset: utf-8
<?php
require_once '../../config/config.php';
require_once '../helper/audit_log.php';
header('Content-Type: application/json');
try {
$system_name = trim($_POST['system_name'] ?? '');
$course_id = (int)($_POST['course_id'] ?? 0);
$is_active = isset($_POST['is_active']) ? (int)($_POST['is_active'] ? 1 : 0) : 1;
$errors = [];
if ($system_name === '') { $errors[] = 'System Name is required.'; }
if ($course_id <= 0) { $errors[] = 'Course is required.'; }
if ($errors) { echo json_encode(['status'=>'error','message'=>$errors]); exit; }
$stmt = $pdo->prepare('INSERT INTO grading_systems (system_name, course_id, is_active) VALUES (?,?,?)');
$stmt->execute([$system_name,$course_id,$is_active]);
write_audit_log($pdo, ['module'=>'Grading System','action'=>'create','entity_table'=>'grading_systems','entity_id'=>$pdo->lastInsertId(),'after_data'=>compact('system_name','course_id','is_active'),'message'=>'Grading system created']);
echo json_encode(['status'=>'success','message'=>'Grading system created successfully.']);
} catch (Throwable $e){ http_response_code(500); echo json_encode(['status'=>'error','message'=>$e->getMessage()]); }
?>