57 lines
2.2 KiB
PHP
57 lines
2.2 KiB
PHP
<?php
|
|
include('includes/config/config.php');
|
|
include('includes/functions.php');
|
|
include('log_entry.php');
|
|
|
|
// Logging request attributes
|
|
$requestStr = "";
|
|
foreach ($_POST as $key => $value) {
|
|
$requestStr .= $key . " : " . $value . "\n";
|
|
}
|
|
error_log("Start Printing Request Attributes\n" . $requestStr . "End Printing Request Attributes");
|
|
|
|
// Check if flex_patient_id is provided in the request
|
|
if (!empty($_POST['flex_patient_id'])) {
|
|
$flex_patient_id = mysqli_real_escape_string($conn, $_POST['flex_patient_id']);
|
|
|
|
// Update admission status for beneficiaries
|
|
$sql_1 = "SELECT * FROM training_batch_enrollment_beneficiary WHERE batch_pri_tbl_id = '$flex_patient_id'";
|
|
$result = mysqli_query($conn, $sql_1);
|
|
|
|
// Get the batch end date
|
|
$batch_end_date = getFieldFromTable('batch_end_date', 'training_batch_enrollment', 'id', $flex_patient_id);
|
|
// $batch_end_date = getFieldFromTable('end_date', 'training_batch_master', 'batch_id', $batch_id);
|
|
error_log("check_end_date : ".$batch_end_date);
|
|
|
|
// Ensure that the date comparison is done correctly
|
|
if ($batch_end_date > date('Y-m-d')) {
|
|
while ($row1 = mysqli_fetch_assoc($result)) {
|
|
$beneficiary_id = mysqli_real_escape_string($conn, $row1['beneficiary_id']);
|
|
$status_query = "UPDATE beneficiary_enquiry SET addmission_status = 'BPE' WHERE patient_id = '$beneficiary_id'";
|
|
error_log("Checke_update_query : ".$status_query);
|
|
mysqli_query($conn, $status_query);
|
|
}
|
|
}
|
|
|
|
// Delete child records
|
|
$query_child = "DELETE FROM training_batch_enrollment_beneficiary WHERE batch_pri_tbl_id = '$flex_patient_id'";
|
|
error_log($query_child . " delete child");
|
|
mysqli_query($conn, $query_child);
|
|
|
|
// Construct the delete query for the main record
|
|
$query = "DELETE FROM training_batch_enrollment WHERE id = '$flex_patient_id'";
|
|
error_log("Check_update_query : ".$query);
|
|
// Execute the delete query directly
|
|
if (mysqli_query($conn, $query)) {
|
|
echo json_encode("SUCCESS");
|
|
} else {
|
|
echo json_encode("FAILURE: " . mysqli_error($conn));
|
|
}
|
|
} else {
|
|
echo json_encode("Invalid Request: No id provided.");
|
|
}
|
|
|
|
// Close database connection
|
|
mysqli_close($conn);
|
|
?>
|