D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
skyconb
/
newsyacine
/
Filename :
admin.php
back
Copy
<?php // =============================================== // admin.php (لوحة التحكم الموحدة - الكود النهائي والمصحح) // =============================================== // 1. التحقق من الجلسة أولاً session_start(); if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) { header("Location: login.php"); exit(); } // التحقق من صلاحية الدور (الأمان) if (($_SESSION['admin'] ?? 'user') !== 'admin') { $_SESSION['error'] = "ليس لديك صلاحية الوصول لهذه اللوحة."; header("Location: login.php"); exit(); } // الاتصال بقاعدة البيانات include 'db_connect.php'; // 2. تحديد القسم الحالي $current_section = $_GET['section'] ?? 'dashboard'; // 3. جلب رسائل الحالة $message = $_SESSION['message'] ?? ''; $error = $_SESSION['error'] ?? ''; unset($_SESSION['message'], $_SESSION['error']); // 4. متغيرات المحتوى $content_title = "لوحة التحكم الرئيسية"; $content_html = "<p>الرجاء اختيار قسم من الشريط الجانبي.</p>"; // =============================================== // 5. منطق الأقسام الديناميكي // =============================================== // --------------------------- // القسم: لوحة القيادة (Dashboard) // --------------------------- if ($current_section === 'dashboard') { $content_title = "لوحة القيادة"; $content_html = "<p style='padding: 30px; background: white; border-radius: 8px;'>مرحباً بك في لوحة الإدارة، يا مسؤول! استخدم القائمة الجانبية لإدارة محتوى الموقع.</p>"; } // --------------------------- // القسم: إدارة المقالات (articles) // --------------------------- elseif ($current_section === 'articles') { $content_title = "إدارة مقالات الأخبار"; $articles_sql = "SELECT a.id, a.title, a.slug, a.created_at, u.username FROM articles a LEFT JOIN users u ON a.author_id = u.id ORDER BY a.id DESC"; $articles_result = $conn->query($articles_sql); ob_start(); ?> <a href="add_article.php" class="add-button article-btn">+ إضافة مقال جديد</a> <?php if ($articles_result && $articles_result->num_rows > 0): ?> <table> <thead> <tr><th>ID</th><th>العنوان</th><th>Slug</th><th>الكاتب</th><th>تاريخ النشر</th><th>الإجراءات</th></tr> </thead> <tbody> <?php while($row = $articles_result->fetch_assoc()): $author = htmlspecialchars($row['username'] ?? 'N/A'); ?> <tr> <td><?php echo $row['id']; ?></td> <td><?php echo htmlspecialchars($row['title']); ?></td> <td><?php echo htmlspecialchars($row['slug']); ?></td> <td><?php echo $author; ?></td> <td><?php echo $row['created_at']; ?></td> <td> <a href='edit_article.php?id=<?php echo $row['id']; ?>' class='action-link edit-btn'>تعديل</a> <a href='delete_article.php?id=<?php echo $row['id']; ?>' class='action-link delete-btn' onclick="return confirm('هل أنت متأكد من حذف هذا المقال؟');">حذف</a> </td> </tr> <?php endwhile; ?> </tbody> </table> <?php else: ?> <p style="padding: 20px; background: white; border-radius: 4px;">لا توجد مقالات مضافة بعد.</p> <?php endif; $content_html = ob_get_clean(); // --------------------------- // القسم: إدارة الفيديوهات (videos) // --------------------------- } elseif ($current_section === 'videos') { $content_title = "إدارة الفيديوهات"; $sql = "SELECT id, title, m3u8_link, upload_date FROM videos ORDER BY id DESC"; $result = $conn->query($sql); ob_start(); ?> <a href="add_video.php" class="add-button">+ إضافة فيديو جديد</a> <?php if ($result && $result->num_rows > 0): ?> <table> <thead> <tr> <th>ID</th> <th>عنوان الفيديو</th> <th>رابط M3U8</th> <th>تاريخ الإضافة</th> <th>الإجراءات</th> </tr> </thead> <tbody> <?php while($row = $result->fetch_assoc()): ?> <tr> <td><?php echo $row['id']; ?></td> <td><?php echo htmlspecialchars($row['title']); ?></td> <td><a href="<?php echo htmlspecialchars($row['m3u8_link']); ?>" target="_blank">عرض الرابط</a></td> <td><?php echo $row['upload_date']; ?></td> <td> <a href="edit_video.php?id=<?php echo $row['id']; ?>" class="action-link edit-btn">تعديل</a> <a href="delete_video.php?id=<?php echo $row['id']; ?>" class="action-link delete-btn" onclick="return confirm('هل أنت متأكد من حذف هذا الفيديو؟');">حذف</a> </td> </tr> <?php endwhile; ?> </tbody> </table> <?php else: ?> <p style="padding: 20px; background: white; border-radius: 4px;">لا توجد فيديوهات مسجلة بعد.</p> <?php endif; $content_html = ob_get_clean(); // --------------------------- // قسم: إدارة الإعلانات (ads) 🎯 تم تعديل هذا القسم ليناسب جدولك // --------------------------- } elseif ($current_section === 'ads') { $content_title = "إدارة الإعلانات"; // 🎯 الاستعلام يستخدم الأعمدة الصحيحة من هيكل جدولك: title, position, is_active, created_at $ads_sql = "SELECT id, title, position, is_active, created_at FROM ads ORDER BY id DESC"; $ads_result = $conn->query($ads_sql); ob_start(); ?> <a href="add_ad.php" class="add-button ads-btn">+ إضافة إعلان جديد</a> <?php if ($ads_result && $ads_result->num_rows > 0): ?> <table> <thead> <tr> <th>ID</th> <th>العنوان الداخلي</th> <th>الموقع</th> <th>تاريخ الإنشاء</th> <th>الحالة</th> <th>الإجراءات</th> </tr> </thead> <tbody> <?php while($row = $ads_result->fetch_assoc()): ?> <tr> <td><?php echo $row['id']; ?></td> <td><?php echo htmlspecialchars($row['title']); ?></td> <td><?php echo htmlspecialchars($row['position']); ?></td> <td><?php echo $row['created_at']; ?></td> <td> <?php // نستخدم is_active (عمودك في قاعدة البيانات) if ($row['is_active'] == 1) { echo '<span style="color: green; font-weight: bold;">نشط</span>'; } else { echo '<span style="color: red;">متوقف</span>'; } ?> </td> <td> <a href="edit_ad.php?id=<?php echo $row['id']; ?>" class="action-link edit-btn">تعديل</a> <a href="delete_ad.php?id=<?php echo $row['id']; ?>" class="action-link delete-btn" onclick="return confirm('هل أنت متأكد من حذف هذا الإعلان؟');">حذف</a> </td> </tr> <?php endwhile; ?> </tbody> </table> <?php else: ?> <p style="padding: 20px; background: white; border-radius: 4px;">لا توجد إعلانات مضافة بعد.</p> <?php endif; $content_html = ob_get_clean(); } // =============================================== // 6. عرض محتوى HTML // =============================================== ?> <!DOCTYPE html> <html lang="ar" dir="rtl"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>لوحة الإدارة - <?php echo $content_title; ?></title> <style> /* CSS للتصميم الأساسي */ body { font-family: Tahoma, sans-serif; margin: 0; background-color: #f4f4f4; } .dashboard-container { display: flex; min-height: 100vh; } /* الشريط الجانبي (Sidebar) */ .sidebar { width: 250px; background-color: #2c3e50; color: white; padding: 20px; box-shadow: 2px 0 5px rgba(0,0,0,0.1); } .sidebar h2 { text-align: center; border-bottom: 2px solid #34495e; padding-bottom: 10px; margin-bottom: 30px; } .sidebar ul { list-style: none; padding: 0; margin: 0; } .sidebar ul li a { display: block; padding: 10px 15px; margin-bottom: 10px; text-decoration: none; color: white; border-radius: 4px; transition: background-color 0.3s; } .sidebar ul li a:hover, .sidebar ul li a.active { background-color: #34495e; } /* منطقة المحتوى الرئيسية */ .main-content { flex-grow: 1; padding: 20px; } .main-content h1 { border-bottom: 1px solid #ccc; padding-bottom: 15px; margin-top: 0; } /* رسائل الحالة */ .status-message { padding: 10px; margin-bottom: 15px; border-radius: 4px; text-align: center; font-weight: bold; } .success { background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb; } .error { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; } /* تنسيق جدول البيانات وأزرار الإضافة */ .add-button { display: inline-block; background-color: #2ecc71; color: white; padding: 10px 15px; text-decoration: none; border-radius: 4px; margin-bottom: 20px; transition: background-color 0.3s; } .add-button:hover { background-color: #27ae60; } /* CSS لزر إضافة المقالات المُعدَّل */ .add-button.article-btn { background-color: #f1c40f; color: #333; } .add-button.article-btn:hover { background-color: #e6b10d; } /* CSS لزر إضافة الإعلانات */ .add-button.ads-btn { background-color: #9b59b6; } .add-button.ads-btn:hover { background-color: #8e44ad; } table { width: 100%; border-collapse: collapse; background-color: white; box-shadow: 0 0 10px rgba(0,0,0,0.05); } th, td { padding: 12px; text-align: right; border-bottom: 1px solid #ddd; } th { background-color: #ecf0f1; color: #333; } tr:hover { background-color: #f5f5f5; } /* تنسيق أزرار الإجراءات */ .action-link { text-decoration: none; padding: 5px 10px; border-radius: 3px; margin: 0 3px; color: white; font-size: 0.9em; } .edit-btn { background-color: #3498db; } .delete-btn { background-color: #e74c3c; } .logout-btn { display: block; margin-top: 30px; text-align: center; padding-top: 10px; border-top: 1px solid #34495e; } .logout-btn a { color: #f39c12; text-decoration: none; } </style> </head> <body> <div class="dashboard-container"> <div class="sidebar"> <h2>لوحة الإدارة</h2> <ul> <li><a href="admin.php?section=dashboard" class="<?php echo ($current_section == 'dashboard') ? 'active' : ''; ?>">لوحة القيادة</a></li> <li><a href="admin.php?section=videos" class="<?php echo ($current_section == 'videos') ? 'active' : ''; ?>">إدارة الفيديوهات</a></li> <li><a href="admin.php?section=articles" class="<?php echo ($current_section == 'articles') ? 'active' : ''; ?>">إدارة المقالات</a></li> <li><a href="admin.php?section=ads" class="<?php echo ($current_section == 'ads') ? 'active' : ''; ?>">إدارة الإعلانات</a></li> </ul> <div class="logout-btn"> <a href="logout.php">تسجيل الخروج</a> </div> </div> <div class="main-content"> <h1><?php echo $content_title; ?></h1> <?php if ($message): ?><div class="status-message success"><?php echo $message; ?></div><?php endif; ?> <?php if ($error): ?><div class="status-message error"><?php echo $error; ?></div><?php endif; ?> <?php echo $content_html; ?> </div> </div> </body> </html> <?php // إغلاق الاتصال بقاعدة البيانات في النهاية $conn->close(); ?>