JezK
Edit File: monthly_attendance.php
<?php session_start(); date_default_timezone_set("Asia/Calcutta"); include("session_check.php"); include("menuheader.php"); //~ include_once("Config.php"); //~ include_once("DbConnect.php"); require_once dirname(__FILE__) . '/DbConnect.php'; include_once("school_admin_access_file.php"); if (!(in_array(1, $access) && in_array(1, $allow))) echo "<script>location.replace('dashboard.php');</script>"; //~ print_r($_SESSION['child']); $school_id = $_SESSION['child']['log_school_id']; //school_id $academic_id = $_SESSION['child']['choosen_academic_id']; // academic_year_id $user_id = $_SESSION['child']['auth_id']; //user_id //~ function __construct() //~ { //~ require_once dirname(__FILE__) . '/DbConnect.php'; //~ // opening db connection //~ $db = new DbConn(); //~ $this->conn = $db->connect(); //~ } $db = new DbConn(); $obj = $db->connect(); //~ echo $db->conn;exit; $fun = new adminaccess(); //~ echo 1243; ///////////////////////////////////// checking school existance in system $timeout = $fun->check_my_status($_SESSION['child']['log_school_id']); //~ print_r($timeout); if ($timeout == 0) echo "<script>location.replace('logout.php');</script>"; ///////////////////////////////////// $sections = $fun->get_sections($_GET['classid'], $academic_id); //~ print_r($sections); $details = $fun->get_classes($school_id, $academic_id); $chosen_date = $fun->get_current_academicyear_id($academic_id, $school_id); //~ $studentdetails = $fun->student_data($_GET['classid'],$chosen_date,$sections['section_id'],) $ts1 = strtotime($chosen_date['start_date']); $ts2 = strtotime($chosen_date['end_date']); $year1 = date('Y', $ts1); $year2 = date('Y', $ts2); $month1 = date('m', $ts1); $month2 = date('m', $ts2); $diff = (($year2 - $year1) * 12) + ($month2 - $month1); $acyearmonths = array(); if ($diff == 0) { $acyearmonths[0] = $chosen_date['start_date']; } else { $date = date('Y-m-d', strtotime($chosen_date['start_date'])); $acyearmonths[0] = $date; for ($i = 1; $i <= $diff; $i++) { // echo 'hello';exit; $date = date('Y-m-d', strtotime('+1 month', strtotime($date))); $acyearmonths[$i] = $date; } } if ($sections) { foreach ($sections as $row) { if ($_GET['sec_id'] == $row['section_id']) { $secs .= "<option value='{$row['section_id']}' selected>{$row['section_name']}</option>"; } else { $secs .= "<option value='{$row['section_id']}' >{$row['section_name']}</option>"; } } } if ($details) { foreach ($details as $row) { if ($_GET['classid'] == $row['class_id']) { $classes_list .= "<option value='{$row['class_id']}' selected>{$row['class_name']}</option>"; } else { $classes_list .= "<option value='{$row['class_id']}' >{$row['class_name']}</option>"; } } } $class_id = $_REQUEST['classid']; $dateid = explode(' ', $_REQUEST['month_value']); $section_id = $_REQUEST['sec_id']; $currentyear = $dateid[1]; $month_id = $dateid[0]; $datestring = $currentyear . "-" . $month_id; if ($month_id) { $no_of_days = cal_days_in_month(CAL_GREGORIAN, $month_id, $currentyear); //$working_days=$fun->attendance_dates($month_id,$class_id,$section_id,$school_id,$academic_id); //$workdays=count($working_days); //$holidays=$no_of_days-$workdays; //echo count($working_days); } $sql1 = "SELECT student_id,student_firstname, student_lastname FROM ced_t_students WHERE class_id=" . (int)$class_id . " and section_id=" . (int)$section_id . " and school_id=" . (int)$school_id . " and academic_year_id=" . (int)$academic_id . " and status=1"; //~ echo $sql1; $res1 = mysqli_query($obj, $sql1); $i = 0; while ($row1 = mysqli_fetch_assoc($res1)) { $i++; $student_id = $row1['student_id']; $sql = "SELECT attendance_date,status,absent_id,leave_id FROM ced_t_attendance WHERE attendance_date like '%$datestring%' and `student_id`='$student_id' and academic_year_id=" . (int)$academic_id; //~ echo 123; //~ echo $sql; $res = mysqli_query($obj, $sql); while ($row = mysqli_fetch_assoc($res)) { $info[$row1['student_id']][substr($row['attendance_date'], 8)] = $row; } $trow = ''; for ($j = 1; $j <= $no_of_days; $j++) { if ($j < 10) { $c = "0" . $j; } else { $c = $j; } $datein = $currentyear . "-" . $month_id . "-" . $c; if (date_format(date_create($datein), 'l') == "Sunday") { $status = "S"; } else { if ($info[$row1['student_id']][$c]['status'] == '') $status = '-'; else $status = $info[$row1['student_id']][$c]['status']; } //$c=(int)$j; if ($datein > date('Y-m-d')) { $checkinleave = "select leave_id from ced_t_leavedetails where student_id=" . (int)$row1['student_id'] . " and academic_year_id=" . $academic_id . " and '" . $datein . "' between leave_from and leave_to"; $exeleave = mysqli_query($obj, $checkinleave); if (mysqli_num_rows($exeleave)) { $leaveres = mysqli_fetch_array($exeleave); $trow .= '<td style=" font-size:14px;"><a href="#" data-target="#pwdModal" data-toggle="modal" onclick="leave_details(' . $row1[student_id] . ',\'' . $datein . '\')" style="font-weight:bold;text-decoration:underline;">L</a></td>'; } else { $trow .= '<td style=" font-size:14px;">' . $status . '</td>'; } } else { if ($info[$row1['student_id']][$c]['status'] == 'L') { $trow .= '<td style=" font-size:14px;"><a href="#" data-target="#pwdModal" data-toggle="modal" onclick="leave_details(' . $row1[student_id] . ',\'' . $datein . '\')" style="font-weight:bold;text-decoration:underline;">L</a></td>'; } else if ($info[$row1['student_id']][$c]['status'] == 'A') { $trow .= '<td style=" font-size:14px;"><a href="#" data-target="#pwdModal1" data-toggle="modal" onclick="absent_details(' . $row1[student_id] . ',\'' . $datein . '\')" style="font-weight:bold;text-decoration:underline;">A</a></td>'; } else { $trow .= '<td style=" font-size:14px;">' . $status . '</td>'; } } } $tablerow .= '<tr><td class="col-sm-1 text-center" style=" font-size:14px;">' . $i . '</td> <td style=" font-size:14px;">' . $row1['student_firstname'] . ' ' . $row1['student_lastname'] . '</td> ' . $trow . '</tr>'; } //echo $tablerow; ?> <style> .table-condensed>thead>tr>th, .table-condensed>tbody>tr>th, .table-condensed>tfoot>tr>th, .table-condensed>thead>tr>td, .table-condensed>tbody>tr>td, .table-condensed>tfoot>tr>td { padding: 3px; } select { width: 62px !important; background-color: #FFF; border: 1px solid #CCC; } </style> <body style=" overflow-x: hidden;"> <div class="row" style="margin-top: 30px; margin-left:1px;"> <div class="col-md-9 text-start" style="font:Arial, Helvetica, sans-serif;font-style:normal;font-size:24px; margin-left:10px; margin-top:10px;"> <a href="attendance.php"> <i class="fa-solid fa-chevron-left back" title="Back" style="color:#01aee6;font-weight:bolder"></i> </a> <img src="images/attendence-black@2x.png" title="Student Attendance" style="font-size: 20px; margin-top:-10px;"> Month Wise Attendance </div> </div> <form class="form-horizontal"> <div class="box-body" style="background-color:#fff; padding: 10px; font-family:Arial, Helvetica, sans-serif; font-size:13px; "> <div class="mt-2"> <div class="form-group row col-md-6" style="margin-bottom:1.0%;"> <div class="col-md-4 col-md-offset-1 text-md-end"> <b style="color:#666666;">Class</b><span style="color:#FF0000; margin:2px;">*</span> </div> <div class="col-md-7"> <select class="form-select" id="classes" style="height:29px; font-size:12px; width:300px!important;" tabindex="1"> <option value='0' selected>--Select Class--</option> <?php echo $classes_list; ?> </select> <!-- if there is an error--> <div class="col-md-10" id="err_class" style="color:#990000;"></div> <!--- end error--> </div> </div> </div> <div class=""> <div class="form-group row col-md-6" style="margin-bottom:1.0%;"> <div class="col-md-4 col-md-offset-1 text-md-end"> <b style="color:#666666; ">Section</b><span style="color:#FF0000; margin:2px;">*</span> </div> <div class="col-md-7"> <select class="form-select" id="sections" style="height:29px; font-size:12px; width:300px!important;" tabindex="2"> <option value='0' selected>--Select Section--</option> <?php echo $secs; ?> </select> <!-- if there is an error--> <div class="col-md-10" id="err_section" style="color:#990000;"></div> <!--- end error--> </div> </div> </div> <div class=""> <div class="form-group row col-md-6" style="margin-bottom:1.0%;"> <div class="col-md-4 col-md-offset-1 text-md-end"> <b style="color:#666666;">Month</b><span style="color:#FF0000; margin:2px;">*</span> </div> <div class="col-md-7"> <select class="form-select" id="select_month" style="height:29px; font-size:12px; width:300px!important;" tabindex="3" onchange="month_attendance()"> <option value='0'>--Select Month--</option> <?php foreach ($acyearmonths as $mo) if ($_GET['month_value'] == date('m Y', strtotime($mo))){ echo "<option value='" . date('m Y', strtotime($mo)) . "' selected>" . date('M Y', strtotime($mo)) . "</option>"; } else{ echo "<option value='" . date('m Y', strtotime($mo)) . "'>" . date('M Y', strtotime($mo)) . "</option>"; } ?> </select> <!-- if there is an error--> <div class="col-md-10" id="err_attnmon" style="color:#990000;"></div> <!--- end error--> </div> </div> </div> </div> </form> <!-- <div class="row" style=" font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px;"> <div class="col-md-1"></div> <div class="col-md-7"> <div class="col-md-4"> <div class="col-md-12" > <b style="color:#666666;">Working Days</b> <span style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px;margin-left:20px;"><?php //echo $workdays; ?></span> </div> </div> <div class="col-md-4"> <div class="col-md-6" > <b style="color:#666666;">Holidays</b><span style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px;margin-left:20px;"><?php echo $holidays; ?></span> </div> </div> <div class="col-md-4"> <div class="col-md-12" > <b style="color:#666666;">Total Number Of Days</b> <span style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px;margin-left:20px;"><?php echo $no_of_days; ?></span> </div> </div> </div> </div> --> <div class="row" style="margin-left:10px;margin-right:10px;"> <div class="col-md-12 centered" style="font-family: Arial, Helvetica, sans-serif;"> <table id="myTable" class="table table-condensed table-hover"> <thead> <tr class="info"> <th class="col-md-1 text-center">Sl.No</th> <th>Name</th> <?php for ($z = 1; $z <= $no_of_days; $z++) if ($z < 10) { $z = '0' . $z; echo '<th>' . $z . '</th>'; } else { echo '<th>' . $z . '</th>'; } ?> </tr> </thead> <tbody> <?php echo $tablerow; ?> </tbody> </table> </div> </div> <script src="//code.jquery.com/jquery-1.12.0.min.js"></script> <script src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script> <script src="https://cdn.datatables.net/buttons/1.1.2/js/dataTables.buttons.min.js"></script> <script src="//cdn.datatables.net/buttons/1.1.2/js/buttons.print.min.js"></script> <script src="//cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/pdfmake.min.js"></script> <script src="//cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/vfs_fonts.js"></script> <script src="//cdn.datatables.net/buttons/1.1.2/js/buttons.html5.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script> <script type="text/javascript" language="javascript" class="init"> $(document).ready(function() { var clname = $("#classes").find('option:selected').text(); var scnam = $("#sections").find('option:selected').text(); var mnth = $("#select_month").find('option:selected').text(); $('#myTable').DataTable({ dom: 'B<"clear">lfrtip', "iDisplayLength": 100, stateSave: true, buttons: [{ extend: 'print', title: '<center><h3><?php echo $_SESSION['child']['school_name'] ?></h3></center>', message: 'Monthly Attendance<br>Academic Year:<?php echo $_SESSION[child][choosen_year_name] ?>   Class:' + clname + '   Section:' + scnam + '   Month:' + mnth + '<br>' }, { extend: 'pdfHtml5', orientation: 'landscape', title: '<?php echo $_SESSION['child']['school_name'] ?>', message: 'Monthly Attendance\nAcademic Year:<?php echo $_SESSION[child][choosen_year_name] ?>\t Class:' + clname + '\tSection:' + scnam + '\t Month:' + mnth + '\n' }, { extend: 'excelHtml5', } ] }); $("#classes").change(function() { $('#err_class').text(''); if ($(this).val() == 0) { $('#err_class').text("Please select Class"); $('#err_class').show(); return false; } else { $('#select_month').val(0); var x = $(this).val(); $.ajax({ url: "ajaxcalls_attn.php", type: "POST", data: "mode=" + "choose_class" + "&data=" + x, success: function(result) { var result2 = eval("(" + result + ")"); //alert(result2[0]); var section_option = '<option value="0">--Select Section--</option>'; for (var i = 0; i < result2.length; i++) { section_option += '<option value="' + result2[i].section_id + '">' + result2[i].section_name + '</option>'; } $("#sections").html(section_option); }, error: function(e) {} }); } }); $("#sections").change(function() { /*if($("#classes").val()!= 0 && $("#sections").val() != 0 && $("#select_month").val() !=0) { month_attendance(); }*/ $("#select_month").val(0); }); }); function month_attendance() { $('#err_class').text(''); $('#err_sections').text(''); $('#err_attnmon').text(''); if ($("#classes").val() == 0) { $('#err_class').text("Please select Class"); $('#err_class').show(); return false; } else if ($("#sections").val() == 0) { $('#err_section').text("Please select Section"); $('#err_section').show(); return false; } else if ($("#select_month").val() == 0) { $('#err_attnmon').text("Please select Month"); $('#err_attnmon').show(); return false; } else { var cls = $("#classes").val(); var month = $("#select_month").val(); var sec_id = $("#sections").val(); window.location.href = "monthly_attendance.php?classid=" + cls + "&month_value=" + month + "&sec_id=" + sec_id; } } function leave_details(id, dt) { $.post('load_leave.php', { student_id: id, rdate: dt }, function(data) { document.getElementById('pwdModal').innerHTML = data; }); } function absent_details(id, dt) { $.post('load_absent.php', { student_id: id, rdate: dt }, function(data) { document.getElementById('pwdModal1').innerHTML = data; }); } </script> <div id="pwdModal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" data-width="760"> <p> </p> </div> <div id="pwdModal1" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" data-width="760"> <p> </p> </div> </body> </html>