[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: stages.php
<?php /** * Educational Stages Management Page * This page allows admin to add, edit, and delete educational stages */ require_once '../config/config.php'; requireLogin('admin'); $database = new Database(); $conn = $database->getConnection(); $message = ''; $message_type = ''; // Handle form submissions if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (isset($_POST['action'])) { switch ($_POST['action']) { case 'add': $name = trim($_POST['name']); if (!empty($name)) { $query = "INSERT INTO stages (name) VALUES (:name)"; $stmt = $conn->prepare($query); $stmt->bindParam(':name', $name); if ($stmt->execute()) { $message = 'تم إضافة المرحلة بنجاح'; $message_type = 'success'; } else { $message = 'حدث خطأ أثناء إضافة المرحلة'; $message_type = 'danger'; } } else { $message = 'يرجى إدخال اسم المرحلة'; $message_type = 'danger'; } break; case 'edit': $id = $_POST['id']; $name = trim($_POST['name']); if (!empty($name) && !empty($id)) { $query = "UPDATE stages SET name = :name WHERE id = :id"; $stmt = $conn->prepare($query); $stmt->bindParam(':name', $name); $stmt->bindParam(':id', $id); if ($stmt->execute()) { $message = 'تم تحديث المرحلة بنجاح'; $message_type = 'success'; } else { $message = 'حدث خطأ أثناء تحديث المرحلة'; $message_type = 'danger'; } } else { $message = 'يرجى إدخال جميع البيانات المطلوبة'; $message_type = 'danger'; } break; case 'delete': $id = $_POST['id']; // Check if stage has grades $check_query = "SELECT COUNT(*) as count FROM grades WHERE stage_id = :id"; $check_stmt = $conn->prepare($check_query); $check_stmt->bindParam(':id', $id); $check_stmt->execute(); $count = $check_stmt->fetch(PDO::FETCH_ASSOC)['count']; if ($count > 0) { $message = 'لا يمكن حذف المرحلة لأنها تحتوي على صفوف دراسية'; $message_type = 'danger'; } else { $query = "DELETE FROM stages WHERE id = :id"; $stmt = $conn->prepare($query); $stmt->bindParam(':id', $id); if ($stmt->execute()) { $message = 'تم حذف المرحلة بنجاح'; $message_type = 'success'; } else { $message = 'حدث خطأ أثناء حذف المرحلة'; $message_type = 'danger'; } } break; } } } // Get all stages $query = "SELECT s.*, COUNT(g.id) as grades_count FROM stages s LEFT JOIN grades g ON s.id = g.stage_id GROUP BY s.id ORDER BY s.created_at DESC"; $stmt = $conn->query($query); $stages = $stmt->fetchAll(PDO::FETCH_ASSOC); $page_title = 'إدارة المراحل الدراسية'; include '../includes/header.php'; ?> <div class="container-fluid"> <div class="row"> <!-- Sidebar --> <div class="col-lg-3 col-md-4 sidebar p-0"> <div class="d-flex flex-column h-100"> <div class="p-3 text-white"> <h4 class="mb-0"> <i class="fas fa-user-shield me-2"></i> لوحة المدير </h4> <small>مرحباً <?php echo $_SESSION['admin_username']; ?></small> </div> <nav class="nav nav-pills flex-column p-3"> <a class="nav-link" href="dashboard.php"> <i class="fas fa-tachometer-alt me-2"></i>الرئيسية </a> <a class="nav-link active" href="stages.php"> <i class="fas fa-layer-group me-2"></i>المراحل الدراسية </a> <a class="nav-link" href="grades.php"> <i class="fas fa-graduation-cap me-2"></i>الصفوف الدراسية </a> <a class="nav-link" href="subjects.php"> <i class="fas fa-book me-2"></i>المواد الدراسية </a> <a class="nav-link" href="teachers.php"> <i class="fas fa-chalkboard-teacher me-2"></i>إدارة المعلمين </a> <a class="nav-link" href="whatsapp_setup.php"> <i class="fab fa-whatsapp me-2"></i>إعداد واتساب </a> <div class="mt-auto"> <a class="nav-link text-light" href="../logout.php"> <i class="fas fa-sign-out-alt me-2"></i>تسجيل الخروج </a> </div> </nav> </div> </div> <!-- Main Content --> <div class="col-lg-9 col-md-8 main-content p-4"> <div class="d-flex justify-content-between align-items-center mb-4"> <h2>إدارة المراحل الدراسية</h2> <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addStageModal"> <i class="fas fa-plus me-2"></i>إضافة مرحلة جديدة </button> </div> <!-- Messages --> <?php if (!empty($message)): ?> <div class="alert alert-<?php echo $message_type; ?> alert-dismissible fade show" role="alert"> <i class="fas fa-<?php echo $message_type == 'success' ? 'check-circle' : 'exclamation-triangle'; ?> me-2"></i> <?php echo $message; ?> <button type="button" class="btn-close" data-bs-dismiss="alert"></button> </div> <?php endif; ?> <!-- Stages Table --> <div class="card"> <div class="card-header"> <h5 class="mb-0">قائمة المراحل الدراسية</h5> </div> <div class="card-body"> <div class="table-responsive"> <table class="table table-striped"> <thead> <tr> <th>الرقم</th> <th>اسم المرحلة</th> <th>عدد الصفوف</th> <th>تاريخ الإنشاء</th> <th>الإجراءات</th> </tr> </thead> <tbody> <?php foreach ($stages as $index => $stage): ?> <tr> <td><?php echo $index + 1; ?></td> <td><?php echo htmlspecialchars($stage['name']); ?></td> <td> <span class="badge bg-info"><?php echo $stage['grades_count']; ?> صف</span> </td> <td><?php echo date('Y/m/d', strtotime($stage['created_at'])); ?></td> <td> <button class="btn btn-sm btn-warning me-1" onclick="editStage(<?php echo $stage['id']; ?>, '<?php echo htmlspecialchars($stage['name']); ?>')"> <i class="fas fa-edit"></i> </button> <button class="btn btn-sm btn-danger" onclick="deleteStage(<?php echo $stage['id']; ?>)"> <i class="fas fa-trash"></i> </button> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> </div> </div> </div> <!-- Add Stage Modal --> <div class="modal fade" id="addStageModal" tabindex="-1"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">إضافة مرحلة دراسية جديدة</h5> <button type="button" class="btn-close" data-bs-dismiss="modal"></button> </div> <form method="POST" action=""> <div class="modal-body"> <input type="hidden" name="action" value="add"> <div class="mb-3"> <label for="stageName" class="form-label">اسم المرحلة</label> <input type="text" class="form-control" id="stageName" name="name" required placeholder="مثال: المرحلة الابتدائية"> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">إلغاء</button> <button type="submit" class="btn btn-primary"> <i class="fas fa-save me-2"></i>حفظ </button> </div> </form> </div> </div> </div> <!-- Edit Stage Modal --> <div class="modal fade" id="editStageModal" tabindex="-1"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">تعديل المرحلة الدراسية</h5> <button type="button" class="btn-close" data-bs-dismiss="modal"></button> </div> <form method="POST" action=""> <div class="modal-body"> <input type="hidden" id="editStageId" name="id"> <input type="hidden" name="action" value="edit"> <div class="mb-3"> <label for="editStageName" class="form-label">اسم المرحلة</label> <input type="text" class="form-control" id="editStageName" name="name" required> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">إلغاء</button> <button type="submit" class="btn btn-warning"> <i class="fas fa-save me-2"></i>حفظ التغييرات </button> </div> </form> </div> </div> </div> <!-- Delete Stage Modal --> <div class="modal fade" id="deleteStageModal" tabindex="-1"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">حذف المرحلة</h5> <button type="button" class="btn-close" data-bs-dismiss="modal"></button> </div> <form method="POST" action=""> <div class="modal-body"> <input type="hidden" id="deleteStageId" name="id"> <input type="hidden" name="action" value="delete"> <p>هل أنت متأكد من حذف هذه المرحلة؟</p> <p class="text-danger">سيتم حذف جميع الصفوف المرتبطة بها.</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">إلغاء</button> <button type="submit" class="btn btn-danger"> <i class="fas fa-trash me-2"></i>حذف </button> </div> </form> </div> </div> </div> <script> function editStage(id, name) { $('#editStageId').val(id); $('#editStageName').val(name); $('#editStageModal').modal('show'); } function deleteStage(id) { $('#deleteStageId').val(id); $('#deleteStageModal').modal('show'); } </script> <?php include '../includes/footer.php'; ?>
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: premium320.web-hosting.com
Server IP: 66.29.153.54
PHP Version: 8.2.29
Server Software: LiteSpeed
System: Linux premium320.web-hosting.com 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
HDD Total: 97.87 GB
HDD Free: 76.87 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:
No
git:
Yes
User Info
Username: aoneqssk
User ID (UID): 1285
Group ID (GID): 1290
Script Owner UID: 1285
Current Dir Owner: 1285