File "update.php"

Full path: /home2/santhos2/public_html/bharath-coe.firstmatrix.in.net/api/fee_structure/update.php
File size: 1.6 KiB (1639 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 { $id=(int)($_POST['id']??0); $course_id=(int)($_POST['course_id']??0); $fee_type_id=(int)($_POST['fee_type_id']??0); $amount=(float)($_POST['amount']??0); $effective_from=trim($_POST['effective_from']??''); $effective_to=trim($_POST['effective_to']??''); $errors=[]; if($id<=0)$errors[]='Invalid ID.'; if($course_id<=0)$errors[]='Course required.'; if($fee_type_id<=0)$errors[]='Fee Type required.'; if($amount<=0)$errors[]='Amount must be > 0.'; if($effective_from==='')$errors[]='Effective From required.'; if($errors){ echo json_encode(['status'=>'error','message'=>$errors]); exit; } $before=null; try{ $b=$pdo->prepare('SELECT * FROM course_fee_structure WHERE fee_structure_id=?'); $b->execute([$id]); $before=$b->fetch(PDO::FETCH_ASSOC);}catch(Throwable $e){} $stmt=$pdo->prepare('UPDATE course_fee_structure SET course_id=?, fee_type_id=?, amount=?, effective_from=?, effective_to=? WHERE fee_structure_id=?'); $stmt->execute([$course_id,$fee_type_id,$amount,$effective_from,$effective_to?:null,$id]); write_audit_log($pdo, ['module'=>'Fee Management','action'=>'update','entity_table'=>'course_fee_structure','entity_id'=>$id,'before_data'=>$before,'after_data'=>compact('course_id','fee_type_id','amount','effective_from','effective_to'),'message'=>'Fee structure updated']); echo json_encode(['status'=>'success','message'=>'Fee structure updated successfully.']); } catch(Throwable $e){ http_response_code(500); echo json_encode(['status'=>'error','message'=>$e->getMessage()]); }
?>


PHP File Manager