[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: assign_subject_teacher.php
<?php include("functions.php"); //error_reporting(0); if(!isset($_SESSION['dbmail_Xw211qAAsq4'])){ header("location:../auth-login"); } else { $s_code = $_SESSION['s_code_Xw2119904']; $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 { if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['assign_subjects'])) { $teacherId = test_input($_POST['teacher_id']); $programme = test_input($_POST['programme']); $selectedSubjects = $_POST['subject_names'] ?? []; // ✅ Fetch current assignments from DB $existingQuery = $new->prepare("SELECT subject_name FROM teacher_subjects WHERE teacher_id = ? AND s_code = ?"); $existingQuery->bind_param("is", $teacherId, $s_code); $existingQuery->execute(); $existingResult = $existingQuery->get_result(); $existingSubjects = []; while ($row = $existingResult->fetch_assoc()) { $existingSubjects[] = $row['subject_name']; } $existingQuery->close(); // ✅ Find subjects to ADD $subjectsToAdd = array_diff($selectedSubjects, $existingSubjects); foreach ($subjectsToAdd as $subjectName) { $stmt = $new->prepare("INSERT INTO teacher_subjects (teacher_id,programe, subject_name, s_code) VALUES (?, ?, ?,?)"); $stmt->bind_param("ssss", $teacherId,$programme, $subjectName, $s_code); $stmt->execute(); $stmt->close(); } // ✅ Find subjects to DELETE $subjectsToDelete = array_diff($existingSubjects, $selectedSubjects); foreach ($subjectsToDelete as $subjectName) { $stmt = $new->prepare("DELETE FROM teacher_subjects WHERE teacher_id = ? AND subject_name = ? AND s_code = ?"); $stmt->bind_param("iss", $teacherId, $subjectName, $s_code); $stmt->execute(); $stmt->close(); } echo "<script> document.addEventListener('DOMContentLoaded', function() { Swal.fire({ title: 'Success!', text: '✅ Subjects updated successfully!', icon: 'success', confirmButtonText: 'OK' }); }); </script>"; } } } ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title>ASSIGN CLASS TEACHER </title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- App favicon --> <!-- DataTables --> <link href="assets/libs/datatables.net-bs4/css/dataTables.bootstrap4.min.css" rel="stylesheet" type="text/css" /> <link href="assets/libs/datatables.net-buttons-bs4/css/buttons.bootstrap4.min.css" rel="stylesheet" type="text/css" /> <!-- Responsive datatable examples --> <link href="assets/libs/datatables.net-responsive-bs4/css/responsive.bootstrap4.min.css" rel="stylesheet" type="text/css" /> <!-- 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" /> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <!-- Include Select2 CSS --> <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script> <style type="text/css"> body { font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 20px; } .container { max-width: 950px; margin: auto; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); } h1 { text-align: center; color: #333; } h2 { margin-top: 20px; color: #4CAF50; } .exam-form { margin-bottom: 20px; background-color: #f9f9f9; padding: 20px; border-radius: 8px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); } .exam-form label { display: block; margin: 10px 0 5px; } .exam-form input { width: calc(100% - 20px); padding: 10px; margin-bottom: 10px; border: 1px solid #ddd; border-radius: 4px; } .exam-form button { background-color: #4CAF50; color: white; border: none; padding: 10px; border-radius: 4px; cursor: pointer; transition: background-color 0.3s; } .exam-form button:hover { background-color: #45a049; } table { width: 100%; border-collapse: collapse; margin-top: 20px; } thead { background-color: #4CAF50; color: white; } th, td { border: 1px solid #ddd; padding: 12px; text-align: center; font-size: 16px; } th { position: sticky; top: 0; /* Keeps the header fixed when scrolling */ } tbody tr:nth-child(even) { background-color: #f2f2f2; } tbody tr:hover { background-color: #e8f5e9; /* Light green on hover */ } tbody td { border: 1px solid #ddd; vertical-align: middle; /* Aligns text vertically center */ } /*table { table-layout: fixed; width: 100%; } td { word-wrap: break-word; word-break: break-all; white-space: normal; }*/ </style> </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">ASSIGN SUBJECT TEACHER</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">ASSIGN SUBJECT TEACHER</li> </ol> </div> </div> </div> </div> <!-- end page title --> <div class="row"> <div class="col-12"> <?php // --------------------------------------------------------------- // 1. FETCH ALL POSSIBLE SUBJECTS (once per page load) // --------------------------------------------------------------- $subjectQuery = $new->query("SELECT subject_com FROM class WHERE s_code = '$s_code'"); $allSubjects = []; while ($row = $subjectQuery->fetch_assoc()) { $subjectString = trim($row['subject_com']); if (strpos($subjectString, ',') !== false) { $subjects = array_map('trim', explode(',', $subjectString)); } elseif (strpos($subjectString, ' ') !== false) { $subjects = array_map('trim', preg_split('/\s+/', $subjectString)); } else { $subjects = [$subjectString]; } $allSubjects = array_merge($allSubjects, $subjects); } $allSubjects = array_unique(array_filter($allSubjects)); // dedupe + clean // --------------------------------------------------------------- ?> <!-- Teacher --> <div class="row"> <div class="col-3"> <label for="teacher" class="form-label fw-bold">Select Teacher</label> <select id="teacher" class="form-select" required> <option value="">-- Choose Teacher --</option> <?php $teachers = $new->query("SELECT id, user_name FROM schools WHERE school_code = '$s_code' AND user_name != 'Admin' ORDER BY user_name ASC"); while ($t = $teachers->fetch_assoc()) { ?> <option value="<?= htmlspecialchars($t['user_name']); ?>"> <?= htmlspecialchars($t['user_name']); ?> </option> <?php } ?> </select> </div> <!-- Programme --> <div class="col-3"> <label for="programme" class="form-label fw-bold">Select Programme</label> <select id="programme" class="form-select" required> <option value="">-- Choose Programme --</option> <?php $progs = $new->query("SELECT progid, program_name FROM programme WHERE s_code = '$s_code'"); while ($p = $progs->fetch_assoc()) { ?> <option value="<?= htmlspecialchars($p['program_name']); ?>"> <?= htmlspecialchars($p['program_name']); ?> </option> <?php } ?> </select> </div> <!-- Class --> <div class="col-2"> <label for="classname" class="form-label fw-bold">Select Class</label> <select id="classname" class="form-select" required> <option value="">-- Choose Class --</option> <?php $cls = $new->query("SELECT cid, class_name FROM class WHERE s_code = '$s_code'"); while ($c = $cls->fetch_assoc()) { ?> <option value="<?= htmlspecialchars($c['class_name']); ?>"> <?= htmlspecialchars($c['class_name']); ?> </option> <?php } ?> </select> </div> <!-- Semester --> <div class="col-2"> <label for="semester" class="form-label fw-bold">Select Semester</label> <select id="semester" class="form-select" required> <option value="">-- Choose Semester --</option> <?php $sems = $new->query("SELECT id, semester FROM semester WHERE s_code = '$s_code'"); while ($s = $sems->fetch_assoc()) { ?> <option value="<?= htmlspecialchars($s['semester']); ?>"> <?= htmlspecialchars($s['semester']); ?> </option> <?php } ?> </select> </div> <div class="col-2"> <label for="semester" class="form-label fw-bold">Load Subjects</label><br/> <button id="loadBtn" class="btn btn-outline-primary" disabled>Load Subjects</button> </div> </div> </div> <form id="subjectForm" method="POST"> <div id="subjectList" class="row"></div> <button type="submit" class="btn btn-success mt-3 d-none" id="saveBtn"> Save Selected Subjects </button> </form> <script> /* ============================================================== 3. JavaScript – enable Load button, fetch subjects, save ============================================================== */ const els = { teacher : document.getElementById('teacher'), programme : document.getElementById('programme'), classname : document.getElementById('classname'), semester : document.getElementById('semester'), loadBtn : document.getElementById('loadBtn'), subjectList: document.getElementById('subjectList'), saveBtn : document.getElementById('saveBtn') }; // ----- enable/disable Load button --------------------------------- function toggleLoadBtn() { const ready = els.teacher.value && els.programme.value && els.classname.value && els.semester.value; els.loadBtn.disabled = !ready; } [els.teacher, els.programme, els.classname, els.semester].forEach(sel => { sel.addEventListener('change', toggleLoadBtn); }); toggleLoadBtn(); // initial state // ----- PHP → JS array of *all* subjects --------------------------- const allSubjects = <?php echo json_encode(array_values($allSubjects)); ?>; // ----- Load button click ----------------------------------------- els.loadBtn.addEventListener('click', () => { const params = new URLSearchParams({ teacher_id: els.teacher.value, programme : els.programme.value, classname : els.classname.value, semester : els.semester.value }); fetch(`get_teacher_subjects.php?${params}`) .then(r => r.json()) .then(assigned => { els.subjectList.innerHTML = ''; // clear allSubjects.forEach((sub, idx) => { const col = document.createElement('div'); col.className = 'col-md-4 col-sm-6 mb-2'; const checked = assigned.includes(sub) ? 'checked' : ''; col.innerHTML = ` <div class="form-check"> <input type="checkbox" class="form-check-input" name="subject_names[]" value="${sub}" id="sub${idx}" ${checked}> <label class="form-check-label" for="sub${idx}"> ${sub} </label> </div>`; els.subjectList.appendChild(col); }); els.saveBtn.classList.remove('d-none'); }) .catch(err => { console.error(err); els.subjectList.innerHTML = '<div class="col-12 text-danger">Failed to load subjects.</div>'; }); }); // ----- Form submit (save) ---------------------------------------- document.getElementById('subjectForm').addEventListener('submit', e => { e.preventDefault(); const fd = new FormData(e.target); fd.append('teacher_id', els.teacher.value); fd.append('programme', els.programme.value); fd.append('classname', els.classname.value); fd.append('semester', els.semester.value); fetch('update_teacher_subjects.php', { method: 'POST', body: fd }) .then(r => r.text()) .then(msg => alert(msg.trim())) .catch(() => alert('Error saving data.')); }); </script> </div> </div> <!-- end col --> </div> <!-- end row --> </div> <!-- container-fluid --> </div> <!-- End Page-content --> <?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> </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> <!-- Required datatable js --> <script src="assets/libs/datatables.net/js/jquery.dataTables.min.js"></script> <script src="assets/libs/datatables.net-bs4/js/dataTables.bootstrap4.min.js"></script> <!-- Buttons examples --> <script src="assets/libs/datatables.net-buttons/js/dataTables.buttons.min.js"></script> <script src="assets/libs/datatables.net-buttons-bs4/js/buttons.bootstrap4.min.js"></script> <script src="assets/libs/jszip/jszip.min.js"></script> <script src="assets/libs/pdfmake/build/pdfmake.min.js"></script> <script src="assets/libs/pdfmake/build/vfs_fonts.js"></script> <script src="assets/libs/datatables.net-buttons/js/buttons.html5.min.js"></script> <script src="assets/libs/datatables.net-buttons/js/buttons.print.min.js"></script> <script src="assets/libs/datatables.net-buttons/js/buttons.colVis.min.js"></script> <!-- Responsive examples --> <script src="assets/libs/datatables.net-responsive/js/dataTables.responsive.min.js"></script> <script src="assets/libs/datatables.net-responsive-bs4/js/responsive.bootstrap4.min.js"></script> <script src="assets/libs/sweetalert2/sweetalert2.min.js"></script> <!-- Datatable init js --> <script src="assets/js/pages/datatables.init.js"></script> <script src="assets/js/app.js"></script> <script src="assets/js/pages/validation.init.js"></script> <script src="assets/js/pages/modal.init.js"></script> <script> var myModal = document.getElementById('myModal') var myInput = document.getElementById('myInput') myModal.addEventListener('shown.bs.modal', function () { myInput.focus() }) </script> </body> </html>
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: 60.07 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