Mini Shell

Direktori : /home/mhcadmin/www/Portal/
Upload File :
Current File : /home/mhcadmin/www/Portal/MAnageSubjects.php

<?php
session_start();
$rootPath = realpath(dirname(__FILE__) . '/..');
require_once $rootPath . '/Portal/config/config.php';
require_once $rootPath . '/Portal/AccessControl.php';
require_once $rootPath . '/Portal/include/auth_validate.php';

if ($Manage_Students == 1) {



    /////// Code for new access control on header menu /////////////////////////
    $User = $_SESSION['id'];
    $UserAccessName = $query3 = $result3 = $Status = "";

    $result = mysqli_query($conn, "SELECT * FROM admin_accounts WHERE id = '$User'");
    $num = mysqli_num_rows($result);

    if ($num > 0) {
        $rows = mysqli_fetch_array($result);
        $UserAccessName = $rows['Access_Level'];
    }

    $db = getDbInstance();

    // Get data from query string
	//$search_string = filter_input(INPUT_GET, 'search_string', FILTER_SANITIZE_STRING);
    //$del_id = filter_input(INPUT_GET, 'del_id', FILTER_SANITIZE_NUMBER_INT);
    //$filter_col = filter_input(INPUT_GET, 'filter_col', FILTER_SANITIZE_STRING);
	// $order_by = filter_input(INPUT_GET, 'order_by', FILTER_SANITIZE_STRING);
	
	
	$search_string = filter_input(INPUT_GET, 'search_string', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
    $del_id = filter_input(INPUT_GET, 'del_id', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
	
    $filter_col = filter_input(INPUT_GET, 'filter_col', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
	
    $order_by = filter_input(INPUT_GET, 'order_by', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
	
    $page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_NUMBER_INT);
    
    $pagelimit = 5;
    if (!$page) {
        $page = 1;
    }
    
    // If filter types are not selected we show latest added data first
    if (!$filter_col) {
        $filter_col = "id";
    }
    if (!$order_by) {
        $order_by = "desc";
    }
    
    // Select the columns
    $select = array('id', 'Name', 'Remarks');
    
    // If user searches 
    if ($search_string) {
        $db->where('Name', '%' . $search_string . '%', 'like');
    }

    if ($order_by) {
        $db->orderBy($filter_col, $order_by);
    }

    $db->pageLimit = $pagelimit;
    $result = $db->arraybuilder()->paginate("offered_subjects", $page, $select);
    $total_pages = $db->totalPages;

    // Get columns for order filter
    $filter_options = array();
    if (!empty($result)) {
        foreach ($result as $value) {
            foreach ($value as $col_name => $col_value) {
                $filter_options[$col_name] = $col_name;
            }
            // Execute only once
            break;
        }
    }

    


    $query3 = "SELECT * FROM `admin_accounts`";
    $result3 = mysqli_query($conn, $query3);

    include_once 'include/AdminHeader.php';
?>

<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-6">
            <h4 class="page-header">Manage Subjects</h4>
        </div>
        <div class="col-lg-6" style="">
            <div class="page-action-links text-right">
                <a href="#" data-toggle="modal" data-target="#Adding-NewUser">
                    <button class="btn btn-success"><span class="glyphicon glyphicon-plus"></span> Add Subject</button>
                </a>
                <a href=""> <button class="btn btn-success"><span class="glyphicon glyphicon-refresh"></span> Refresh</button></a>
            </div>
        </div>
    </div>
    
    <?php include('include/flash_messages.php') ?>

    <?php
    if (isset($del_stat) && $del_stat == 1) {
        echo '<div class="alert alert-info">Successfully deleted</div>';
    }
    ?>
    
    <!-- Begin filter section -->
    <div class="well text-center filter-form">
        <form class="form form-inline" action="">
            <label for="input_search">Search</label>
            <input type="text" class="form-control" id="input_search" placeholder ="Subject Name"  name="search_string" value="<?php echo htmlspecialchars($search_string ?? ''); ?>">
            <label for="input_order">Order By</label>
            <select name="filter_col" class="form-control">
                <?php
                foreach ($filter_options as $option) {
                    $selected = ($filter_col === $option) ? "selected" : "";
                    echo '<option value="' . htmlspecialchars($option) . '" ' . $selected . '>' . htmlspecialchars($option) . '</option>';
                }
                ?>
            </select>

            <select name="order_by" class="form-control" id="input_order">
                <option value="Asc" <?php echo ($order_by == 'Asc') ? "selected" : ""; ?>>Asc</option>
                <option value="Desc" <?php echo ($order_by == 'Desc') ? "selected" : ""; ?>>Desc</option>
            </select>
            <input type="submit" value="Go" class="btn btn-primary">
        </form>
    </div>
    <!-- Filter section end -->
    
    <hr>
    <table class="table table-striped table-bordered table-condensed">
        <thead>
            <tr style="background-color:#BAC4CC;">
                <th>Subject Name</th>
                <th>Remarks</th>
                
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            <?php if (!empty($result)): ?>
                <?php foreach ($result as $row): ?>
                    <tr>
                        <td><h5><?php echo htmlspecialchars($row['Name'] ?? '') ?></h5></td>
                        <td><h5><?php echo htmlspecialchars($row['Remarks'] ?? '') ?></h5></td>
                        
                        
                        <td>
                            <ul class="nav navbar-top-links navbar-right">
                                <li class="dropdown">
                                    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                                        <i class="fa fa-folder-open"></i> 
                                    </a>
                                    <ul class="dropdown-menu dropdown-user">
                                        <li class="divider"></li>
                                        <li><h6><a href="#" data-toggle="modal" data-target="#Update-Account-<?php echo $row['id'] ?>"><span class="btn btn-primary"> Update Record</span></a></h6></li>
                                        
                                        <li class="divider"></li>
                                        <li><h6><a href="#" data-toggle="modal" data-target="#confirm-delete-<?php echo $row['id'] ?>"><span class="btn btn-danger delete_btn"> Delete Record</span></a></h6></li>
                                    </ul>
                                </li>
                            </ul>
                        </td>
                    </tr>

                    <!-- Record Updation Modal -->
                    <div class="modal fade" id="Update-Account-<?php echo $row['id'] ?>" role="dialog">
                        <div class="modal-dialog">
                            <form action="Add_Update_Delete_Subject.php" method="POST">
                                <div class="modal-content">
                                    <div class="modal-header" style="text-align:center; background-color:#BAC4CC;">
                                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                                        <h4 class="modal-title">Update Subject Record</h4>
                                    </div>
                                    <div class="modal-body">
                                        <?php
                                        $SujectID = $row['id'];
                                        $queryv = "SELECT * FROM `offered_subjects` WHERE id = '$SujectID'";
                                        $resultv = mysqli_query($conn, $queryv);
                                        
                                        if ($resultv && mysqli_num_rows($resultv) > 0) {
                                            $rowsv = mysqli_fetch_array($resultv);
                                        } else {
                                            $rowsv = array();
                                        }
                                        ?>
                                        
                                        <div class="form-group">
                                            <label class="control-label">Subject Name *</label>
                                            <input type="text" name="Full_Name" placeholder="Full Name" class="form-control" value="<?php echo htmlspecialchars($rowsv['Name'] ?? '') ?>" required autocomplete="off">
                                            <input type="hidden" name="SubjectID" class="form-control" value="<?php echo htmlspecialchars($rowsv['id'] ?? '') ?>" required>
                                        </div>
                                        
											
										<div class="form-group">
                                            <label class="control-label">Remarks (Optional) </label>
											
											<textarea name="Remarks" placeholder="Not More than 1000 characters" class="form-control" id="address"><?php echo htmlspecialchars($rowsv['Remarks'] ?? '') ?></textarea></td>
									   </div>
									
                                        
                                    </div>
                                    <div class="modal-footer">
                                        <button type="submit" name="Update_Subject" id="submit" class="btn btn-warning pull-left">Save <span class="glyphicon glyphicon-send"></span></button>
                                        <button type="button" class="btn btn-primary" data-dismiss="modal">Cancel <span class="glyphicon glyphicon-remove"></span></button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>

                    <!-- Delete Confirmation Modal -->
                    <div class="modal fade" id="confirm-delete-<?php echo $row['id'] ?>" role="dialog">
                        <div class="modal-dialog">
                            <form action="Add_Update_Delete_Subject.php" method="POST">
                                <div class="modal-content">
                                    <div class="modal-header" style="text-align:center; background-color:#BAC4CC;">
                                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                                        <h4 class="modal-title">Confirm</h4>
                                    </div>
                                    <div class="modal-body">
                                        <input type="hidden" name="SubjectID" id="del_id" value="<?php echo $row['id'] ?>">
                                        <p>Are you sure you want to delete this Subject?</p>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="submit" name="Delete_Subject" id="submit" class="btn btn-danger delete_btn pull-left">Delete <span class="glyphicon glyphicon-trash"></span></button>
                                        <button type="button" class="btn btn-primary" data-dismiss="modal">Cancel <span class="glyphicon glyphicon-remove"></span></button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    
                    <!-- Add Activation/Deactivation Modals here if needed -->
                    
                <?php endforeach; ?>
            <?php else: ?>
                <tr>
                    <td colspan="8" class="text-center">No Subject found</td>
                </tr>
            <?php endif; ?>
        </tbody>
    </table>

    <!-- Adding a New User Modal -->
    <div class="modal fade" id="Adding-NewUser" role="dialog">
        <div class="modal-dialog">
            <form action="Add_Update_Delete_Subject.php" method="post" id="contact_form" enctype="multipart/form-data">
                <div class="modal-content">
                    <div class="modal-header" style="text-align:center; background-color:#BAC4CC;">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h5 class="modal-title" style="text-align:center;"><strong>ADD A NEW SUBJECT</strong></h5>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                                            <label class="control-label">Subjest Name *</label>
                                            <input type="text" name="Full_Name" placeholder="Full Name" class="form-control" value="" required autocomplete="off">
                                            
                                        </div>
                                        
											
										<div class="form-group">
                                            <label class="control-label">Remarks (Optional) </label>
											<span class="input-group-addon"></span>
											<textarea name="Remarks" placeholder="Not More than 1000 characters" class="form-control" id="address"></textarea></td>
									   </div>
									
                    </div>
                    <div class="modal-footer">
                        <button type="submit" name="Add_Subject" id="submit" class="btn btn-warning pull-left">Save <span class="glyphicon glyphicon-send"></span></button>
                        <button type="button" class="btn btn-primary" data-dismiss="modal">Cancel <span class="glyphicon glyphicon-remove"></span></button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <!-- Pagination links -->
    <div class="text-center">
        <?php
        if ($total_pages > 1) {
            // Build query string
            $query_params = $_GET;
            unset($query_params['page']);
            $query_string = !empty($query_params) ? '?' . http_build_query($query_params) : '?';
            
            echo '<ul class="pagination text-center">';
            for ($i = 1; $i <= $total_pages; $i++) {
                $li_class = ($page == $i) ? ' class="active"' : '';
                echo '<li' . $li_class . '><a href="MAnageSubjects.php' . $query_string . '&page=' . $i . '">' . $i . '</a></li>';
            }
            echo '</ul>';
        }
        ?>
    </div>
</div>

<?php 
} else { 
    header('location: AccessLevelMessage.php');
    exit();
}

include_once 'include/footer.php'; 
?>