EVOLUTION-NINJA
Edit File: test_result.php
<?php echo view('includes/faculty_header'); ?> <link rel="stylesheet" type="text/css" media="screen" href="<?php echo base_url('public/assets/css/jquery-ui.css'); ?>" /> <link rel="stylesheet" type="text/css" media="screen" href="<?php echo base_url('public/assets/jqgrid/css/ui.jqgrid.css'); ?>" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script> <!-- <link rel="stylesheet" type="text/css" href="<?php //echo base_url('public/assets/css/timingfield.css'); ?>"/> <script type="text/javascript" src="<?php //echo base_url('public/assets/js/timingfield.js'); ?>"></script> --> <link rel="stylesheet" type="text/css" href="<?php echo base_url('public/assets/website_assets/css/timepicki.css'); ?>" /> <script type="text/javascript" src="<?php echo base_url('public/assets/website_assets/js/timepicki.js'); ?>"></script> <script type="text/ecmascript" src="<?php echo base_url('public/assets/jqgrid/js/jquery.jqGrid.min.js'); ?>"></script> <script type="text/ecmascript" src="<?php echo base_url('public/assets/jqgrid/js/i18n/grid.locale-en.js'); ?>"></script> <script src="<?php echo base_url('public/assets/js/jquery-ui.js'); ?>" type="text/javascript"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css"> <!-- DataTables CSS --> <link rel="stylesheet" href="https://cdn.datatables.net/1.13.4/css/jquery.dataTables.min.css"> <!-- DataTables JavaScript --> <script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script> <style> table { width: 100%; border-collapse: collapse; margin-top: 20px; height: 100%; } th, td { border: 1px solid black; padding: 10px; text-align: left; } th { background-color: #f4f4f4; } </style> <div id="page-wrapper"> <div class="my_header"> <h3 style="padding-bottom:10px;border-bottom:2px dashed #ccc;margin-bottom:20px; font-weight: bold;">TEST RESULTS</h3> <div class="col-md-2"> </div> <div class="col-md-8"> <div class="form_div"> <form id="form"> <div class="form row"> <div class="col-sm-3"> <label for="Chapter" class="form-label inpfieldname">Courses</label> <select class="form-select form-control fieldsbox" id="course" name="course"> <?php $login_id =session()->get('faculty_login_id'); // print_r($login_id);die(); echo '<option value="">Select Courses</option>'; if ($login_id == 357) { echo '<option value="1">Business Development Officer</option>'; } else if($login_id == 361){ echo '<option value="2">Cybersecurity</option>'; } ?> </select> </div> <div class="col-sm-3"> <label for="Chapter" class="form-label inpfieldname">Chapter Name</label> <select class="form-select form-control fieldsbox" id="chapter" name="chapter"> <!--<option value=""></option>--> </select> </div> </div> <br> <button type="button" class="submit btn" id="getResultsBtn" style="margin-block:10px">Get Results</button> <button type="button" class="submit btn" id="exportExcelBtn" style="margin-block:10px">Export to Excel</button> </form> </div> <!--<div id="assessment" class="tab-pane fade">--> <!-- <div class="row" id="assessment_uploads_div"></div><!-- row --> <br><br> <table id="uploaded_files_table" class="display"> <thead> <tr> <th>SI.No.</th> <th>Student</th> <th>Student marks</th> </tr> </thead> <tbody id="uploaded_files"> <!-- Dynamic Content Goes Here --> </tbody> </table> <div class="row" id="blank_assessment_uploads_div"></div><!-- row --> </div> </div> </div> </div> <script> $(document).ready(function () { var table = $('#uploaded_files_table').DataTable(); // Handle Get Results button click $('#getResultsBtn').click(function () { fetchFiles(); // Fetch data for selected chapter }); // Export to Excel handler (optional logic) $('#exportExcelBtn').click(function () { var table = document.getElementById('uploaded_files_table'); var workbook = XLSX.utils.table_to_book(table, { sheet: "Test Results" }); XLSX.writeFile(workbook, 'test_results.xlsx'); }); // Fetch test results function fetchFiles() { var chapterId = $('#chapter').val() || ''; if (!chapterId) { alert('Please select a chapter.'); return; } $.ajax({ url: "<?= base_url('fetch_test_result') ?>", type: 'POST', data: { chapter_id: chapterId }, dataType: 'json', success: function (response) { console.log(response); // Debug var filesHTML = ''; if (response.data && response.data.length > 0) { $.each(response.data, function (index, data) { filesHTML += ` <tr> <td>${index + 1}</td> <td>${data.name}</td> <td>${data.total_marks}</td> </tr>`; }); } else { filesHTML = `<tr><td colspan="3" style="text-align: center;">No results found.</td></tr>`; } // Update table table.clear().destroy(); $('#uploaded_files').html(filesHTML); table = $('#uploaded_files_table').DataTable({ destroy: true, retrieve: true }); }, error: function () { alert('Error fetching data. Please try again.'); } }); } }); </script> <script> function export_page() { let id = jQuery("#list3").jqGrid('getDataIDs'); let type = $('#type').val(); $.ajax({ type: 'POST', url: "<?php echo site_url('fetch_test_result'); ?>?type=" + type, data: { id: id }, dataType: 'json', success: function (response) { console.log(response); let count = 1; let content = ` <thead> <tr> <th>SI NO</th> <th>Student</th> <th>Student Marks</th> </tr> </thead> <tbody> `; $.each(response.data, function (index, item) { content += ` <tr> <td>${index + 1}</td> <td>${data.name}</td> <td>${data.total_marks}</td> </tr> `; }); content += `</tbody>`; $('.export_table').html(content); export_data(); // Call after content is injected }, error: function () { alert("Failed to fetch data for export."); } }); } function exportToExcel() { $("#uploaded_files_table").table2excel({ exclude: ".noExl", name: "Test Results", filename: "Test_Results", fileext: ".xls", exclude_img: true, exclude_links: true, exclude_inputs: true }); } </script> <script> $(document).ready(function () { $('#course').change(function () { var course_id = $(this).val(); $('#chapter').empty().append('<option value="">Select Chapter</option>'); // Clear previous chapters $('#topic').empty().append('<option value="">Select Topic</option>'); // Clear previous topics if (course_id) { $.ajax({ url: "<?php echo base_url('fetch-chapter'); ?>/" + course_id, type: 'GET', dataType: 'json', success: function (response) { if (response.error) { alert(response.error); return; } $.each(response, function (index, chapter) { $('#chapter').append(`<option value="${chapter.chapter_id}">${chapter.chapter_name}</option>`); }); }, error: function () { alert('Error fetching chapters.'); } }); } }); }); </script> <script> $(document).ready(function () { $("#student").autocomplete({ source: function (request, response) { $.ajax({ url: "<?= base_url('fetch-student'); ?>", // Your CI4 API route type: "GET", dataType: "json", data: { term: request.term }, // Send user input to the server success: function (data) { response($.map(data, function (item) { return { label: item.username, // What appears in the dropdown value: item.username, // What gets inserted into the input field id: item.login_id // Student ID (stored separately) }; })); } }); }, minLength: 2, // Start suggesting after 2 characters select: function (event, ui) { $("#student").val(ui.item.value); // Set selected username $("#student_id").val(ui.item.id); // Store selected student ID in hidden field console.log("Selected Student ID: " + ui.item.id); return false; // Prevent default behavior } }); // Get selected Student ID $("#student").on("blur", function () { var studentId = $("#student_id").val() || ''; console.log("Final Student ID: " + studentId); }); }); </script> <?php echo view('includes/faculty_footer'); ?> <style> #page-wrapper{ background-image: url(public/assets/website_assets/images/banner.png); background-size:cover; } #FrmGrid_list2 { width: 100% !important; } .ui-jqdialog .ui-jqdialog-titlebar { height: 29px !important; background-color: #001a00; color: white; padding-left: 10px; } .fm-button { height: 21px !important; padding: 1px; margin-right: 10px !important; height: 21px !important; width: 43%; margin-top: -7px !important; } .ui-jqdialog-content td.navButton { padding-top: 12px !important; } .ui-jqgrid .ui-jqgrid-titlebar { height: 27px !important; /*background:#1e7ad7 !important;*/ color: white !important; } .fade{ opacity:1; } .ui-jqgrid-bdiv { height: auto !important; } .ui-widget-overlay { z-index: 0 !important; } /* .ui-widget-header { background: #1e7ad7 !important; } */ .ui-jqgrid-hdiv ui-state-default { /* width: 873px !important; */ cursor: default !important } ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight { border: 1px solid #fed22f; background: #ffe45c; } .ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { font-weight: bold; color: black; } /* .ui-jqgrid .ui-jqgrid-bdiv { overflow-y: scroll; overflow-x: scroll ; } .ui-jqgrid-htable{ width: 100% !important; } #list2{ width: 100% !important; } */ .timepicker_wrap { top: 35px !important; } #jaytab { width: 100% !important; overflow-x: scroll !important; } @media only screen and (min-width:320px) and (max-width:640px) { #jaytab { width: 100% !important; overflow-x: scroll !important; } .ui-jqgrid ui-widget ui-widget-content ui-corner-all { width: 900px !important; } .ui-jqgrid-view { width: 900px !important; } .ui-jqgrid-hdiv { width: 900px !important; } .ui-jqgrid-htable { width: 900px !important; } .ui-jqgrid-bdiv { width: 900px !important; } #list2 { width: 900px !important; } #pager2 { width: 900px !important; } .ui-jqgrid { width: 100% !important; } } @media only screen and (min-width:641px) and (max-width:991px) { #jaytab { width: auto !important; overflow-x: scroll !important; } .ui-jqgrid ui-widget ui-widget-content ui-corner-all { width: 900px !important; } .ui-jqgrid-view { width: 900px !important; } .ui-jqgrid-hdiv { width: 900px !important; } .ui-jqgrid-htable { width: 900px !important; } .ui-jqgrid-bdiv { width: 900px !important; } #list2 { width: 900px !important; } #pager2 { width: 900px !important; } } @media only screen and (min-width:992px) and (max-width:1258px) { #jaytab { width: 100% !important; overflow-x: scroll !important; } .ui-jqgrid ui-widget ui-widget-content ui-corner-all { width: 100% !important; } .ui-jqgrid-view { width: 100% !important; } .ui-jqgrid-hdiv { width: 100% !important; } .ui-jqgrid-htable { width: 100% !important; } .ui-jqgrid-bdiv { width: 100% !important; } #list2 { width: 100% !important; } #pager2 { width: 100% !important; } } </style>