File "create.php"

Full path: /home2/santhos2/public_html/bharath-coe.firstmatrix.in.net/api/grades/create.php
File size: 1.52 KiB (1561 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 {
    $grading_system_id = (int)($_POST['grading_system_id'] ?? 0);
    $grade_name = trim($_POST['grade_name'] ?? '');
    $min_marks = (int)($_POST['min_marks'] ?? 0);
    $max_marks = (int)($_POST['max_marks'] ?? 0);
    $grade_point = (float)($_POST['grade_point'] ?? 0);
    $is_pass = isset($_POST['is_pass']) ? (int)($_POST['is_pass'] ? 1 : 0) : 1;
    $errors=[];
    if ($grading_system_id<=0) $errors[]='Grading System required.';
    if ($grade_name==='') $errors[]='Grade Name required.';
    if ($min_marks<0 || $max_marks<0 || $min_marks>$max_marks) $errors[]='Enter valid min/max marks.';
    if ($errors){ echo json_encode(['status'=>'error','message'=>$errors]); exit; }
    $stmt=$pdo->prepare('INSERT INTO grades (grading_system_id, grade_name, min_marks, max_marks, grade_point, is_pass) VALUES (?,?,?,?,?,?)');
    $stmt->execute([$grading_system_id,$grade_name,$min_marks,$max_marks,$grade_point,$is_pass]);
    write_audit_log($pdo, ['module'=>'Grading System','action'=>'create','entity_table'=>'grades','entity_id'=>$pdo->lastInsertId(),'after_data'=>compact('grading_system_id','grade_name','min_marks','max_marks','grade_point','is_pass'),'message'=>'Grade created']);
    echo json_encode(['status'=>'success','message'=>'Grade created successfully.']);
} catch (Throwable $e){ http_response_code(500); echo json_encode(['status'=>'error','message'=>$e->getMessage()]); }
?>


PHP File Manager