csrtechnew.ohctech.in/check_followup.php

63 lines
2.2 KiB
PHP
Raw Permalink Normal View History

2025-04-14 13:28:09 +05:30
<?php
include('includes/config/config.php');
include('log_entry.php');
$batchid = mysqli_real_escape_string($conn, $_REQUEST['batchid']);
$beneficiary = mysqli_real_escape_string($conn, $_REQUEST['beneficiary']);
$follow_up_routine = mysqli_real_escape_string($conn, $_REQUEST['follow_up_routine']);
$data = array();
// SQL query to check the current follow-up status
$query = "SELECT * FROM placement_feedback WHERE batch_id = '$batchid' AND beneficiary = '$beneficiary' AND follow_up_routine = '$follow_up_routine'";
error_log("test_query: " . $query);
$result = mysqli_query($conn, $query);
if (!$result) {
error_log("Database query failed: " . mysqli_error($conn));
$data['status'] = 'error';
$data['message'] = 'Database query failed';
echo json_encode($data);
exit;
}
// If a record is found for the requested follow-up routine
if ($row = mysqli_fetch_assoc($result)) {
error_log("test_query: " . $row['follow_up_routine']);
$data['complete'] = 'yes';
} else {
$data['complete'] = 'no';
// Adjusting query based on follow-up routine
if ($follow_up_routine == 'First Follow Up') {
$query = "SELECT * FROM placement_records WHERE batch_name = '$batchid' AND beneficiary = '$beneficiary'";
}
if ($follow_up_routine == 'Second Follow Up') {
$query = "SELECT * FROM placement_feedback WHERE batch_id = '$batchid' AND beneficiary = '$beneficiary' AND follow_up_routine = 'First Follow Up'";
} elseif ($follow_up_routine == 'Third Follow Up') {
$query = "SELECT * FROM placement_feedback WHERE batch_id = '$batchid' AND beneficiary = '$beneficiary' AND follow_up_routine = 'Second Follow Up'";
}
error_log("Check_follow_up_query: " . $query);
$result = mysqli_query($conn, $query);
if (!$result) {
error_log("Database query failed: " . mysqli_error($conn));
$data['status'] = 'error';
$data['message'] = 'Database query failed';
echo json_encode($data);
exit;
}
// Check for the previous follow-up status
if ($row = mysqli_fetch_assoc($result)) {
$data['follow_up'] = 'completed';
} else {
$data['follow_up'] = 'not_completed';
}
}
echo json_encode($data);