csrtechnew.ohctech.in/tranning_atendence.php
2026-01-07 09:12:10 +05:30

455 lines
19 KiB
PHP

<?php
use Beta\Microsoft\Graph\Model\Alert;
include('techsyn_header.php'); ?>
<?php include('log_entry.php'); ?>
<!-- Main Content Container for side bar and body -->
<div class="main-container ace-save-state" id="main-container" style="text-transform: none;">
<script type="text/javascript">
try {
ace.settings.loadState('main-container');
} catch (e) {}
</script>
<?php include('techsyn_sidebar.php'); ?>
<!-- Breadcrumb -->
<div class="main-content">
<div class="main-content-inner">
<div class="breadcrumbs ace-save-state" id="breadcrumbs">
<ul class="breadcrumb">
<li class="#">Daily Attendance</li>
<li class="active">Beneficiary Attendance</li>
</ul>
</div>
<!-- End of Breadcrumb -->
<?php
$ohc_type_id = $_SESSION['current_ohcttype'];
error_log("Form_data_check : " . htmlspecialchars($_POST['batch_name'], ENT_QUOTES, 'UTF-8'));
// Initialize variables
$i = 0;
$row = ['attendence_date' => date('Y-m-d')];
if (isset($_REQUEST['batch_name']) && !empty($_REQUEST['at_date'])) {
$batch_name = mysqli_real_escape_string($conn, $_REQUEST['batch_name']);
$date = mysqli_real_escape_string($conn, $_REQUEST['at_date']);
$sql = "SELECT * FROM training_batch_enrollment_beneficiary WHERE batch_id = ?";
if ($stmt = mysqli_prepare($conn, $sql)) {
mysqli_stmt_bind_param($stmt, 's', $batch_name);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($result)) {
$batch_name = getFieldFromTable('batch_name', 'training_batch_master', 'batch_id', $row['batch_id']);
$row['attendence_date'] = $date;
} else {
error_log("No rows returned for the query: " . $sql);
}
}
}
$count = 0;
?>
<div class="page-content">
<div class="box box-primary" style="padding: 10px; margin: 2px 0px 50px 5px; width: 99.5%;">
<form id="attendence_form" name="attendence_form">
<div class="box-body">
<div class="container" style="max-width: 800px; margin: 0 auto;">
<div class="row">
<!-- Form Group for Batch and Date -->
<div class="col-sm-6">
<div class="form-group">
<label for="batch_name">Batch</label><span style="color:red">*</span>
<input type="hidden" name="exm_id" id="exm_id" value="<?php echo htmlspecialchars($row['exm_id'], ENT_QUOTES, 'UTF-8'); ?>">
<select class="form-control chosen-select" name="batch_name" id="batch_name" placeholder="Select Batch" onchange="check_attendence()">
<option value="">Please Select Batch Name</option>
<!-- <?php echo generateOptionWithWhereClause('training_batch_master', 'batch_name', 'batch_id', $row['batch_id'], '', 'ohc_type_id', $ohc_type_id); ?> -->
<?php
$voa = "VOA";
$option_query = "SELECT batch_id FROM training_batch_enrollment WHERE status = '" . $voa . "' AND ohc_type_id = '" . $ohc_type_id . "'";
$option_arry = mysqli_query($conn, $option_query);
if (!$option_arry) {
die("Query failed: " . mysqli_error($conn));
}
while ($op = mysqli_fetch_array($option_arry)) {
$selectted = '';
if ($op['batch_id'] == $row['batch_id']) {
$selectted = 'selected';
}
$batch_name = getFieldFromTable('batch_name', 'training_batch_master', 'batch_id', $op['batch_id']);
echo '<option value="' . $op['batch_id'] . '" ' . $selectted . '>' . htmlspecialchars($batch_name) . '</option>';
}
?>
<!-- <?php echo generateOptionWithWhereClause('training_batch_enrollment', 'batch_name', 'batch_id', $row['batch_id'], '', '', ''); ?> -->
</select>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="at_date">Date</label><span style="color:red">*</span>
<input type="date" id="at_date" name="at_date" class="form-control" value="<?php echo htmlspecialchars($row['attendence_date'], ENT_QUOTES, 'UTF-8'); ?>">
</div>
</div>
</div>
</div>
</div>
<!-- End box-body -->
<!-- box-footer -->
<div class="box-footer" style="text-align: center; margin-top: 20px;">
<button id="save_btn" class="btn btn-info" type="button" onclick="validate();">
<i class="fa fa-cog icon fa-spin"></i>
Load
</button>
&nbsp; &nbsp; &nbsp;
<a style="color:white" href="./attendence_list.php" class="btn btn-success">
<i class="fa fa-list"></i>
View Attendance
</a>
&nbsp; &nbsp; &nbsp;
<button class="btn btn-warning" type="reset" onclick="check_reset()">
<i class="ace-icon fa fa-undo bigger-110"></i>
Reset
</button>
</div>
<!-- End box-footer -->
</form>
</div>
</div>
<script>
function check_reset() {
BootstrapDialog.confirm('Are you sure to Reset This Page?', function(result) {
if (result) {
location.href = "tranning_atendence.php";
}
});
}
var msg1 = '<p style="text-transform: none;">Please Select Batch Name.!!!</p>';
var msg2 = '<p style="text-transform: none;">Please Select Attendance Date.!!!</p>';
function validate() {
var batch_name = $('#batch_name').val();
var at_date = $('#at_date').val();
if (batch_name == '') {
BootstrapDialog.alert(msg1);
return false;
} else if (at_date == '') {
BootstrapDialog.alert(msg2);
return false;
}
datalist();
}
function datalist() {
document.forms['attendence_form'].action = "tranning_atendence.php";
document.forms['attendence_form'].method = 'POST';
document.forms['attendence_form'].submit();
}
</script>
<style>
.card-container {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 10px;
}
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
max-width: 200px;
font-family: Arial, sans-serif;
text-align: center;
padding: 5px;
border-radius: 3px;
background-color: white;
flex: 1 1 200px;
}
.card h4 {
margin-bottom: 5px;
}
.card button {
border: 1px solid white;
outline: none;
color: white;
cursor: pointer;
width: 48%;
font-size: 12px;
margin: 0 1%;
border-radius: 2px;
padding: 3px;
}
.card button:hover {
opacity: 0.7;
}
.button-container {
display: flex;
justify-content: space-between;
margin-top: 10px;
}
.warning {
color: #d9534f;
border: 2px solid #d9534f;
padding: 10px;
background-color: #f9f2f4;
border-radius: 4px;
}
</style>
<div class="card-container">
<?php
do {
if ($row['batch_id']) {
$batch_name = getFieldFromTable('batch_name', 'training_batch_master', 'batch_id', $row['batch_id']);
$beneficiary_name = getFieldFromTable('patient_name', 'patient_master', 'id', $row['beneficiary_id']);
$row2 = checkStatus($row['beneficiary_id'], $row['batch_id'], $date);
$status = $row2['status'];
$style = $status == "Present" ? 'background-color: #aaf0c9;' : ($status == "Absent" ? 'background-color: #ffb3b2;' : ($status == "Leave" ? 'background-color: #FFFD8D;' : 'background-color: #efede7;'));
if ($row2['id'] > 0 || $row2['id'] != '') {
$id = $row2['id'];
if ($row2['ba_id'] > 0) {
$ba_id = $row2['ba_id'];
} else {
$ba_id = '';
}
} else {
$id = '';
}
?>
<?php
$beneficiary_id = $row['beneficiary_id'];
$batch_id = $row['batch_id'];
$at_date = $_REQUEST['at_date'];
$leaveQuery = "SELECT lc.id
FROM leave_child lc
INNER JOIN leave_primary lp ON lc.pid = lp.pid
WHERE lp.beneficiary_id = '$beneficiary_id'
AND lp.batch_id = '$batch_id'
AND lc.from_date <= '$at_date'
AND lc.to_date >= '$at_date'
AND lc.status = 'Approved'";
$leaveResult = mysqli_query($conn, $leaveQuery);
$leaveApproved = mysqli_num_rows($leaveResult) > 0;
?>
<div class="card" id="cl<?php echo $count ?>" style="<?php echo $style; ?>">
<h4><?php echo htmlspecialchars($beneficiary_name, ENT_QUOTES, 'UTF-8'); ?></h4>
<p></p>
<div class="button-container">
<button class="btn-success" onclick="atend('p','<?= $row['beneficiary_id'] ?>','<?= $at_date ?>','<?= $row['batch_id'] ?>','<?php echo $count ?>');">Present</button>
<button class="btn-danger" onclick="atend('a','<?= $row['beneficiary_id'] ?>','<?= $at_date ?>','<?= $row['batch_id'] ?>','<?php echo $count ?>');">Absent</button>
<?php if ($leaveApproved) { ?>
<button class="btn-warning" onclick="atend('l','<?= $row['beneficiary_id'] ?>','<?= $at_date ?>','<?= $row['batch_id'] ?>','<?php echo $count ?>');">Leave</button>
<?php } ?>
</div>
</div>
<?php
} else {
echo "<tr><td><h3 class=\"warning\">Data Not Found In This Date And Batch</h3></td></tr>";
}
$count++;
} while ($row = mysqli_fetch_array($result));
?>
</div>
</div>
</div>
</div>
<?php
function checkStatus($beneficiary_id, $batch_id, $date)
{
global $conn; // Access the global $conn variable
// Escape input parameters to prevent SQL injection
$beneficiary_id = mysqli_real_escape_string($conn, $beneficiary_id);
$batch_id = mysqli_real_escape_string($conn, $batch_id);
$date = mysqli_real_escape_string($conn, $date);
$ohc_id = $_SESSION['current_ohcttype'];
// Correct SQL query
$sql = "SELECT *
FROM beneficiary_attendence a
LEFT JOIN attendance_batch b
ON b.id = a.pti_id
WHERE b.batch_id = '$batch_id'
AND b.attendence_date = '$date'
AND a.beneficiary_id = '$beneficiary_id' AND b.ohc_type_id = '$ohc_id'";
// Log the SQL query for debugging
error_log("check_sql_query22 : " . $sql);
// Execute the SQL query
$result = mysqli_query($conn, $sql);
// Check for SQL errors
if (!$result) {
error_log("SQL Error: " . mysqli_error($conn));
return null; // Return null if there's an error
}
// Fetch the result as an associative array
$row2 = mysqli_fetch_assoc($result);
error_log("check_sql_query22 : " . $row2['status']);
// Return the result row
return $row2;
}
?>
<script>
function atend(action, beneficiary_id, date, batch_id, count) {
var msg1 = '<p style="text-transform: none;">Already Current Attendance Status Exists</p>';
var msg2 = '<p style="text-transform: none;">Restriction: Not Permitted To Change Attendance for Different Date</p>';
// if (action == 'l') {
// check_leave(beneficiary_id, date, batch_id);
// }
$.ajax({
url: 'attendence_save.php',
type: "POST",
data: {
action: action,
beneficiary_id: beneficiary_id,
date: date,
batch_id: batch_id,
},
dataType: 'json',
success: function(data) {
if (data.status === 200) {
var color = action === 'p' ? '#aaf0c9' :
(action === 'a' ? '#ffb3b2' :
(action === 'l' ? '#FFFD8D' : '#efede7'));
$('#cl' + count).css('background-color', color);
} else {
console.error('Error in response: ' + data.message);
BootstrapDialog.alert(msg1);
}
},
error: function(xhr, status, error) {
console.error('Error:', status, error);
BootstrapDialog.alert(msg2);
$('#cl' + count).css('background-color', '#ffb3b2');
}
});
}
</script>
<script>
function check_attendence() {
var batch_id = $('#batch_name').val();
var msg1 = '<p style="text-transform: none;">Today attendance has been filled</p>';
var msg2 = '<p style="text-transform: none;">Today attendance has not been filled</p>';
$.ajax({
url: 'check_attendence.php',
type: "POST",
data: {
batch_id: batch_id
},
dataType: 'json',
success: function(data) {
if (data.attendance_done == 'YES') {
BootstrapDialog.alert(msg1);
} else {
BootstrapDialog.alert(msg2);
}
},
error: function(jqXHR, textStatus, errorThrown) {
BootstrapDialog.alert("An error occurred: " + textStatus + " - " + errorThrown);
}
});
}
function check_leave(beneficiary_id, date, batch_id) {
$.ajax({
url: 'check_leave.php',
type: "POST",
data: {
beneficiary_id: beneficiary_id,
date: date,
batch_id: batch_id,
},
dataType: 'json',
success: function(data) {
if (data.leave >= data.leave_limit) {
BootstrapDialog.alert({
title: 'Leave Limit Exceeded',
message: `<p style="text-transform: none;">This beneficiary has taken ${data.leave} leaves</p>`,
type: BootstrapDialog.TYPE_WARNING
});
data.leave = 0;
}
},
error: function(jqXHR, textStatus, errorThrown) {
BootstrapDialog.alert("An error occurred: " + textStatus + " - " + errorThrown);
}
});
}
</script>
<!-- Bootstrap & FontAwesome -->
<link rel="stylesheet" href="assets/font-awesome/4.5.0/css/font-awesome.min.css" />
<!-- Page specific plugin styles -->
<link rel="stylesheet" href="assets/css/jquery-ui.custom.min.css" />
<link rel="stylesheet" href="assets/css/chosen.min.css" />
<link rel="stylesheet" href="assets/css/bootstrap-datepicker3.min.css" />
<link rel="stylesheet" href="assets/css/bootstrap-timepicker.min.css" />
<link rel="stylesheet" href="assets/css/daterangepicker.min.css" />
<link rel="stylesheet" href="assets/css/bootstrap-datetimepicker.min.css" />
<link rel="stylesheet" href="assets/css/bootstrap-colorpicker.min.css" />
<script type="text/javascript" src="js/typeahead.bundle.js"></script>
<script src="assets/js/jquery-ui.custom.min.js"></script>
<script src="assets/js/jquery.ui.touch-punch.min.js"></script>
<script src="assets/js/chosen.jquery.min.js"></script>
<script src="assets/js/spinbox.min.js"></script>
<script src="assets/js/bootstrap-datepicker.min.js"></script>
<script src="assets/js/bootstrap-timepicker.min.js"></script>
<script src="assets/js/jquery.dataTables.min.js"></script>
<script src="assets/js/jquery.dataTables.bootstrap.min.js"></script>
<script src="assets/js/dataTables.buttons.min.js"></script>
<script src="assets/js/buttons.flash.min.js"></script>
<script src="assets/js/buttons.html5.min.js"></script>
<script src="assets/js/buttons.print.min.js"></script>
<script src="assets/js/buttons.colVis.min.js"></script>
<script src="assets/js/dataTables.select.min.js"></script>
<script src="assets/js/moment.min.js"></script>
<script src="assets/js/daterangepicker.min.js"></script>
<script src="assets/js/bootstrap-datetimepicker.min.js"></script>
<script src="assets/js/bootstrap-colorpicker.min.js"></script>
<script src="assets/js/jquery.knob.min.js"></script>
<script src="assets/js/autosize.min.js"></script>
<script src="assets/js/jquery.inputlimiter.min.js"></script>
<script src="assets/js/jquery.maskedinput.min.js"></script>
<script src="assets/js/bootstrap-tag.min.js"></script>
<script src="assets/js/ace-elements.min.js"></script>