[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: manage-house-allocation.php
<?php // error_reporting(0); include("functions.php"); if(!isset($_SESSION['dbmail_Xw211qAAsq4'])){ header("location:../auth-login"); } else { $s_code = $_SESSION['s_code_Xw2119904']; $uname = $_SESSION['name_Xw2119904']; $stmt = $con->prepare("SELECT * FROM schools WHERE user_name = ? AND school_code = ?"); $stmt->execute(array($uname, $s_code)); $userstatus = $stmt->fetchAll(); // Initialize $namee to prevent potential errors $namee = null; foreach ($userstatus as $sta) { $namee = $sta['user_name']; $userid = $sta['id']; $school_name = $sta['school_name']; } $stmt = $con->prepare("Select * from schools where school_code = ?"); $stmt->execute(array($s_code)); $row = $stmt->fetch(); $logo = $row['logo']; if(empty($logo)){ header("Location:complete-process"); } else { $message = ""; if(isset($_POST['find'])){ $className = test_input($_POST['className']); } if (isset($_POST['assignHome'])) { $house_ids = $_POST['house_id'] ?? []; $index_numbers = $_POST['indexNo'] ?? []; if (!empty($house_ids) && !empty($index_numbers)) { foreach ($index_numbers as $key => $index_no) { $index_no = mysqli_real_escape_string($new, $index_no); $house_id = intval($house_ids[$key]); // Skip if no house was selected if ($house_id <= 0) continue; // Fetch house_name $house_query = mysqli_query($new, "SELECT house_name FROM house WHERE hid = $house_id AND school_code = '$s_code' LIMIT 1"); if (!$house_query) { echo "Error fetching house for $index_no: " . mysqli_error($new) . "<br>"; continue; } $house_data = mysqli_fetch_assoc($house_query); if (!$house_data) continue; $house_name = mysqli_real_escape_string($new, $house_data['house_name']); // Update record $update = mysqli_query($new, " UPDATE enrol_details SET house_id = '$house_id', housename = '$house_name' WHERE index_no = '$index_no' AND s_code = '$s_code' AND (house_id IS NULL OR house_id = '' OR house_id = 0) "); if (!mysqli_query($new, $update)) { echo "Error updating $index_no: " . mysqli_error($new) . "<br>"; } } } else { echo "<div class='alert alert-danger'>No data received!</div>"; } } ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Admission setup | Admission setup </title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta content="eliosof" name="author" /> <!-- App favicon --> <!-- <link rel="shortcut icon" href="assets/images/favicon.ico"> --> <!-- preloader css --> <link rel="stylesheet" href="assets/css/preloader.min.css" type="text/css" /> <!-- Bootstrap Css --> <link href="assets/css/bootstrap.min.css" id="bootstrap-style" rel="stylesheet" type="text/css" /> <!-- Icons Css --> <link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" /> <!-- App Css--> <link href="assets/css/app.min.css" id="app-style" rel="stylesheet" type="text/css" /> <link href="assets/libs/sweetalert2/sweetalert2.min.css" rel="stylesheet" type="text/css" /> </head> <body> <!-- <body data-layout="horizontal"> --> <!-- Begin page --> <div id="layout-wrapper"> <?php include("includes/header.php");?> <?php include("includes/sidebar.php");?> <div class="main-content"> <div class="page-content"> <div class="container-fluid"> <!-- start page title --> <div class="row"> <div class="col-12"> <div class="page-title-box d-sm-flex align-items-center justify-content-between"> <h4 class="mb-sm-0 font-size-18">MANAGE HOUSE ALLOCATION</h4> <div class="page-title-right"> <ol class="breadcrumb m-0"> <li class="breadcrumb-item"><a href="javascript: void(0);">Home</a></li> <li class="breadcrumb-item active">MANAGE HOUSE ALLOCATION</li> </ol> </div> </div> </div> </div> <!-- end page title --> <br /><br /> <div class="col-xl-12"> <div class="card-body"> <div class="table-responsive"> <!-- 🔍 Search Bar --> <div class="mb-3"> <input type="text" id="tableSearch" class="form-control" placeholder="Search by name, index number, or student ID..."> </div> <?php // fetch houses for this school once $houses = []; $hres = mysqli_query($new, "SELECT hid, house_name FROM house WHERE school_code = '$s_code' ORDER BY house_name"); if ($hres) { while ($hrow = mysqli_fetch_assoc($hres)) { $houses[] = $hrow; } } // fetch all students (no limit for search) $does = mysqli_query($new, "SELECT index_no, schoolID, student_name, housename, house_id,unique_student_code FROM enrol_details WHERE s_code = '$s_code' ORDER BY id DESC "); if (!$does) { die("Query failed: " . mysqli_error($new)); } $cnt = 1; $displayLimit = 100; // only show first 100 initially ?> <table id="studentTable" class="table table-bordered mb-0 borded"> <thead class="table-dark"> <tr> <th>#</th> <th>Student</th> <th>School ID</th> <th>Residential status</th> <th>Preview house</th> <th>Action</th> </tr> </thead> <tbody> <?php while ($getInfo = mysqli_fetch_assoc($does)): $index = htmlspecialchars($getInfo['index_no']); $isHidden = ($cnt > $displayLimit) ? 'style="display:none;"' : ''; ?> <tr id="row-<?php echo $index; ?>" <?php echo $isHidden; ?>> <td><?php echo $cnt++; ?></td> <td><?php echo htmlspecialchars($getInfo['student_name']); ?></td> <td><?php echo !empty($getInfo['schoolID']) ? htmlspecialchars($getInfo['unique_student_code']) : ''; ?></td> <td> <?php $getresident = mysqli_query($new,"SELECT status FROM enrol_generic WHERE indexNo = '$index' AND s_code = '$s_code'"); $status = ''; while ($seall = mysqli_fetch_array($getresident)) { $status = $seall['status']; } echo htmlspecialchars($status); ?> </td> <td class="housename"><?php echo htmlspecialchars($getInfo['housename'] ?: 'Not Assigned'); ?></td> <td> <button type="button" class="btn btn-sm btn-primary edit-house-btn" data-index="<?php echo $index; ?>" data-student="<?php echo htmlspecialchars($getInfo['student_name']); ?>" data-house="<?php echo (int)$getInfo['house_id']; ?>" >Edit</button> </td> </tr> <?php endwhile; ?> </tbody> </table> <div id="showMoreContainer" class="text-center mt-3"> <button id="showMoreBtn" class="btn btn-outline-primary btn-sm">Show All</button> </div> <script> const HOUSES = <?php echo json_encode($houses, JSON_HEX_TAG|JSON_HEX_AMP|JSON_HEX_APOS|JSON_HEX_QUOT); ?>; const S_CODE = <?php echo json_encode($s_code); ?>; </script> </div> </div> <!-- 🔍 Search + Show More Script --> <script> document.addEventListener("DOMContentLoaded", function () { const searchInput = document.getElementById("tableSearch"); const rows = Array.from(document.querySelectorAll("#studentTable tbody tr")); const showMoreBtn = document.getElementById("showMoreBtn"); // Show All Button showMoreBtn.addEventListener("click", function () { rows.forEach(row => row.style.display = ""); showMoreBtn.style.display = "none"; }); // Cache text for fast search const rowTextCache = rows.map(row => row.innerText.toLowerCase()); let timeout; searchInput.addEventListener("keyup", function () { clearTimeout(timeout); timeout = setTimeout(() => { const filter = this.value.toLowerCase(); if (!filter) { // Reset view: show only first 100 rows.forEach((row, i) => { row.style.display = i < 100 ? "" : "none"; }); showMoreBtn.style.display = "block"; return; } // Search all rows let visibleCount = 0; rows.forEach((row, i) => { if (rowTextCache[i].includes(filter)) { row.style.display = ""; visibleCount++; } else { row.style.display = "none"; } }); showMoreBtn.style.display = "none"; // hide show-all while searching }, 200); }); }); </script> <!-- end card --> </div> </div> </div> <!-- Edit House Modal --> <div class="modal fade" id="editHouseModal" tabindex="-1" aria-hidden="true"> <div class="modal-dialog"> <form id="editHouseForm"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">Assign House to <span id="modalStudentName"></span></h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <input type="hidden" id="modalIndexNo" name="index_no"> <div class="mb-3"> <label for="modalHouseSelect" class="form-label">Choose House</label> <select id="modalHouseSelect" name="house_id" class="form-control" required> <option value="0">-- SELECT HOUSE --</option> <!-- options populated by JS --> </select> </div> <div id="modalAlert" style="display:none;" class="alert"></div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> <button type="submit" class="btn btn-primary">Save changes</button> </div> </div> </form> </div> </div> <script> document.addEventListener('DOMContentLoaded', function() { // Build options once function buildHouseOptions(selectedId) { let html = '<option value="0">-- SELECT HOUSE --</option>'; for (const h of HOUSES) { const sel = (parseInt(h.hid) === parseInt(selectedId)) ? ' selected' : ''; html += `<option value="${h.hid}"${sel}>${h.house_name}</option>`; } return html; } // open modal when Edit clicked document.querySelectorAll('.edit-house-btn').forEach(btn => { btn.addEventListener('click', function() { const index = this.dataset.index; const student = this.dataset.student; const houseId = this.dataset.house || 0; document.getElementById('modalStudentName').textContent = student; document.getElementById('modalIndexNo').value = index; document.getElementById('modalHouseSelect').innerHTML = buildHouseOptions(houseId); document.getElementById('modalAlert').style.display = 'none'; // show Bootstrap modal const editModal = new bootstrap.Modal(document.getElementById('editHouseModal')); editModal.show(); }); }); // handle submit document.getElementById('editHouseForm').addEventListener('submit', function(e) { e.preventDefault(); const index_no = document.getElementById('modalIndexNo').value; const house_id = document.getElementById('modalHouseSelect').value; // Basic validation if (!index_no || !house_id || parseInt(house_id) === 0) { const alert = document.getElementById('modalAlert'); alert.className = 'alert alert-warning'; alert.innerText = 'Please select a house.'; alert.style.display = 'block'; return; } // send AJAX fetch('update_house.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ index_no, house_id, s_code: S_CODE }) }) .then(r => r.json()) .then(resp => { const alert = document.getElementById('modalAlert'); if (resp.success) { // update row in-place const row = document.querySelector(`#row-${CSS.escape(index_no)}`); if (row) { // find chosen house name const houseObj = HOUSES.find(h => String(h.hid) === String(house_id)); const houseName = houseObj ? houseObj.house_name : resp.house_name || 'Assigned'; const cell = row.querySelector('.housename'); if (cell) cell.textContent = houseName; } // show success and close after short delay alert.className = 'alert alert-success'; alert.innerText = resp.message || 'House updated.'; alert.style.display = 'block'; setTimeout(() => { const editModalEl = document.getElementById('editHouseModal'); const modal = bootstrap.Modal.getInstance(editModalEl); modal.hide(); }, 700); } else { alert.className = 'alert alert-danger'; alert.innerText = resp.message || 'Update failed.'; alert.style.display = 'block'; } }) .catch(err => { const alert = document.getElementById('modalAlert'); alert.className = 'alert alert-danger'; alert.innerText = 'Request error: ' + err.message; alert.style.display = 'block'; }); }); }); </script> </div> <!-- End Page-content --> <!-- Select2 CSS --> <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" /> <!-- Select2 JS --> <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script> <?php include("includes/footer.php");?> </div> <!-- end main content--> </div> <!-- END layout-wrapper --> <!-- Right Sidebar --> <div class="right-bar"> <div data-simplebar class="h-100"> <div class="rightbar-title d-flex align-items-center p-3"> <h5 class="m-0 me-2">Theme Customizer</h5> <a href="javascript:void(0);" class="right-bar-toggle ms-auto"> <i class="mdi mdi-close noti-icon"></i> </a> </div> <!-- Settings --> <hr class="m-0" /> <div class="p-4"> <h6 class="mb-3">Layout</h6> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout" id="layout-vertical" value="vertical"> <label class="form-check-label" for="layout-vertical">Vertical</label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout" id="layout-horizontal" value="horizontal"> <label class="form-check-label" for="layout-horizontal">Horizontal</label> </div> <h6 class="mt-4 mb-3 pt-2">Layout Mode</h6> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-mode" id="layout-mode-light" value="light"> <label class="form-check-label" for="layout-mode-light">Light</label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-mode" id="layout-mode-dark" value="dark"> <label class="form-check-label" for="layout-mode-dark">Dark</label> </div> <h6 class="mt-4 mb-3 pt-2">Layout Width</h6> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-width" id="layout-width-fuild" value="fuild" onchange="document.body.setAttribute('data-layout-size', 'fluid')"> <label class="form-check-label" for="layout-width-fuild">Fluid</label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-width" id="layout-width-boxed" value="boxed" onchange="document.body.setAttribute('data-layout-size', 'boxed')"> <label class="form-check-label" for="layout-width-boxed">Boxed</label> </div> <h6 class="mt-4 mb-3 pt-2">Layout Position</h6> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-position" id="layout-position-fixed" value="fixed" onchange="document.body.setAttribute('data-layout-scrollable', 'false')"> <label class="form-check-label" for="layout-position-fixed">Fixed</label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-position" id="layout-position-scrollable" value="scrollable" onchange="document.body.setAttribute('data-layout-scrollable', 'true')"> <label class="form-check-label" for="layout-position-scrollable">Scrollable</label> </div> <h6 class="mt-4 mb-3 pt-2">Topbar Color</h6> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="topbar-color" id="topbar-color-light" value="light" onchange="document.body.setAttribute('data-topbar', 'light')"> <label class="form-check-label" for="topbar-color-light">Light</label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="topbar-color" id="topbar-color-dark" value="dark" onchange="document.body.setAttribute('data-topbar', 'dark')"> <label class="form-check-label" for="topbar-color-dark">Dark</label> </div> <h6 class="mt-4 mb-3 pt-2 sidebar-setting">Sidebar Size</h6> <div class="form-check sidebar-setting"> <input class="form-check-input" type="radio" name="sidebar-size" id="sidebar-size-default" value="default" onchange="document.body.setAttribute('data-sidebar-size', 'lg')"> <label class="form-check-label" for="sidebar-size-default">Default</label> </div> <div class="form-check sidebar-setting"> <input class="form-check-input" type="radio" name="sidebar-size" id="sidebar-size-compact" value="compact" onchange="document.body.setAttribute('data-sidebar-size', 'md')"> <label class="form-check-label" for="sidebar-size-compact">Compact</label> </div> <div class="form-check sidebar-setting"> <input class="form-check-input" type="radio" name="sidebar-size" id="sidebar-size-small" value="small" onchange="document.body.setAttribute('data-sidebar-size', 'sm')"> <label class="form-check-label" for="sidebar-size-small">Small (Icon View)</label> </div> <h6 class="mt-4 mb-3 pt-2 sidebar-setting">Sidebar Color</h6> <div class="form-check sidebar-setting"> <input class="form-check-input" type="radio" name="sidebar-color" id="sidebar-color-light" value="light" onchange="document.body.setAttribute('data-sidebar', 'light')"> <label class="form-check-label" for="sidebar-color-light">Light</label> </div> <div class="form-check sidebar-setting"> <input class="form-check-input" type="radio" name="sidebar-color" id="sidebar-color-dark" value="dark" onchange="document.body.setAttribute('data-sidebar', 'dark')"> <label class="form-check-label" for="sidebar-color-dark">Dark</label> </div> <div class="form-check sidebar-setting"> <input class="form-check-input" type="radio" name="sidebar-color" id="sidebar-color-brand" value="brand" onchange="document.body.setAttribute('data-sidebar', 'brand')"> <label class="form-check-label" for="sidebar-color-brand">Brand</label> </div> <h6 class="mt-4 mb-3 pt-2">Direction</h6> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-direction" id="layout-direction-ltr" value="ltr"> <label class="form-check-label" for="layout-direction-ltr">LTR</label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-direction" id="layout-direction-rtl" value="rtl"> <label class="form-check-label" for="layout-direction-rtl">RTL</label> </div> </div> </div> <!-- end slimscroll-menu--> </div> <!-- /Right-bar --> <!-- Right bar overlay--> <div class="rightbar-overlay"></div> <!-- JAVASCRIPT --> <script src="assets/libs/jquery/jquery.min.js"></script> <script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script> <script src="assets/libs/metismenu/metisMenu.min.js"></script> <script src="assets/libs/simplebar/simplebar.min.js"></script> <script src="assets/libs/node-waves/waves.min.js"></script> <script src="assets/libs/feather-icons/feather.min.js"></script> <!-- pace js --> <script src="assets/libs/pace-js/pace.min.js"></script> <script src="assets/libs/sweetalert2/sweetalert2.min.js"></script> <script src="assets/js/app.js"></script> </body> </html> <?php } }?>
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.71 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002