csrtechnew.ohctech.in/set_indent_option.php
2025-04-14 13:28:09 +05:30

60 lines
1.9 KiB
PHP

<?php
include('includes/config/config.php');
include('log_entry.php');
include_once("includes/functions.php");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$csr_program_id = isset($_REQUEST['program_id']) ? intval($_REQUEST['program_id']) : 0;
// Log the program ID to confirm it's being received
error_log("CSR Program ID: " . $csr_program_id);
$activity_id = getFieldFromTable('activity_id', 'participate_csr_program', 'participate_csr_program_id', $csr_program_id);
error_log("Activity ID: " . $activity_id);
// Check session variables
error_log("Session role_type: " . $_SESSION['role_type']);
error_log("Session ohc_type_id: " . $_SESSION['current_ohcttype']);
$role_type = mysqli_real_escape_string($conn, $_SESSION['role_type']);
// Construct the SQL query
$item_sql = "SELECT item_id, item_name
FROM tbl_items
WHERE RoleCode = '$role_type'
AND activity IN ($activity_id)
AND ohc_type_id = '".$_SESSION['current_ohcttype']."'";
error_log("SQL Query: " . $item_sql);
$result = mysqli_query($conn, $item_sql);
// Check for SQL errors
if (!$result) {
error_log("SQL Error: " . mysqli_error($conn));
}
$options_html = '';
if ($result && mysqli_num_rows($result) > 0) {
$options_html .= '<option value="">Please Select Item</option>';
while ($row = mysqli_fetch_assoc($result)) {
$options_html .= '<option value="' . $row['item_id'] . '">' . $row['item_name'] . '</option>';
}
} else {
$options_html .= '<option value="">No items available</option>';
}
// Log the options HTML to check if it's being built correctly
error_log("Options HTML: " . $options_html);
// Return the options HTML as a JSON response
header('Content-Type: application/json');
echo json_encode(['options_html' => $options_html]);
// Close the database connection
mysqli_close($conn);
?>