403Webshell
Server IP : 173.209.174.21  /  Your IP : 216.73.216.89
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux wcfs-server 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64
User : nodor ( 1000)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/wcsd/School-alert/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/wcsd/School-alert/update_school_order.php.123
<?php
session_start();
require 'config/db.php';

// Check if the user is logged in and has admin privileges
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
    header('Location: dashboard.php');
    exit();
}

// Fetch all schools ordered by the display_order field
$stmt = $pdo->prepare("SELECT school_id, name, display_order FROM schools ORDER BY display_order ASC");
$stmt->execute();
$schools = $stmt->fetchAll(PDO::FETCH_ASSOC);

// Handle form submission for updating order
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['update_order'])) {
    // Update the display order of schools
    foreach ($_POST['order'] as $index => $school_id) {
        $stmt = $pdo->prepare("UPDATE schools SET display_order = ? WHERE school_id = ?");
        $stmt->execute([intval($index), $school_id]);
    }

    header('Location: update_school_order.php?message=School order updated successfully');
    exit();
}
?>

<?php include __DIR__ . '/views/header.php'; ?>

<div class="container">
    <h2 class="page-title">Update School Order</h2>

    <?php if (isset($_GET['message'])): ?>
        <div class="success-message">
            <?= htmlspecialchars($_GET['message']) ?>
        </div>
    <?php endif; ?>

    <form method="POST" action="update_school_order.php">
        <div class="sortable-box">
            <?php foreach ($schools as $index => $school): ?>
                <div class="sortable-item" id="school-<?= $school['school_id'] ?>">
                    <!-- Hidden field for school ID, which will be submitted in the form -->
                    <input type="hidden" name="order[]" value="<?= $school['school_id'] ?>">

                    <span class="school-name"><?= htmlspecialchars($school['name']) ?></span>

                    <!-- Buttons for moving up and down -->
                    <button type="button" class="move-up" data-index="<?= $index ?>">&#x2191;</button> <!-- Up Arrow -->
                    <button type="button" class="move-down" data-index="<?= $index ?>">&#x2193;</button> <!-- Down Arrow -->
                </div>
            <?php endforeach; ?>
        </div>

        <!-- Submit button to save the new order -->
        <button type="submit" name="update_order" class="btn-submit">Save Order</button>
    </form>
</div>

<!-- Include jQuery for ease of DOM manipulation -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<script>
$(document).ready(function() {
    // Move item up
    $('.move-up').click(function() {
        var index = $(this).data('index');
        var item = $('.sortable-item').eq(index);
        var prevItem = item.prev('.sortable-item');
        
        if (prevItem.length) {
            item.insertBefore(prevItem);
            updateOrder();
        }
    });

    // Move item down
    $('.move-down').click(function() {
        var index = $(this).data('index');
        var item = $('.sortable-item').eq(index);
        var nextItem = item.next('.sortable-item');
        
        if (nextItem.length) {
            item.insertAfter(nextItem);
            updateOrder();
        }
    });

    // Update hidden input fields to reflect the new order
    function updateOrder() {
        var order = [];
        $('.sortable-item').each(function() {
            order.push($(this).find('input[name="order[]"]').val());
        });

        // Update the hidden input fields to reflect the new order
        $('input[name="order[]"]').each(function(index) {
            $(this).val(order[index]);
        });
    }
});
</script>

<?php include __DIR__ . '/views/footer.php'; ?>

Youez - 2016 - github.com/yon3zu
LinuXploit