37309-vm/distributors.php
2026-01-07 23:57:08 +00:00

73 lines
2.5 KiB
PHP

<?php
include 'layout/header.php';
require_once 'db/config.php';
try {
$pdo = db();
// Create table if it doesn't exist
$pdo->exec("CREATE TABLE IF NOT EXISTS distributors (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)");
// Check if table is empty
$stmt = $pdo->query("SELECT COUNT(*) FROM distributors");
if ($stmt->fetchColumn() == 0) {
// Insert initial data
$distributors = ['ابن سينا', 'فارما اوفرسيز', 'سوفيكو'];
$insert_stmt = $pdo->prepare("INSERT INTO distributors (name) VALUES (?)");
foreach ($distributors as $distributor) {
$insert_stmt->execute([$distributor]);
}
}
// Fetch distributors
$stmt = $pdo->query("SELECT id, name, created_at FROM distributors ORDER BY id");
$all_distributors = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo "<div class='alert alert-danger'>فشل الاتصال بقاعدة البيانات: " . $e->getMessage() . "</div>";
include 'layout/footer.php';
exit;
}
?>
<div class="d-flex justify-content-between align-items-center mb-3">
<h1>قائمة الموزعين</h1>
<!-- Button to be enabled later -->
<button class="btn btn-primary" disabled>إضافة موزع جديد</button>
</div>
<div class="card">
<div class="card-body">
<table class="table table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">الاسم</th>
<th scope="col">تاريخ الإنشاء</th>
<th scope="col">الإجراءات</th>
</tr>
</thead>
<tbody>
<?php foreach ($all_distributors as $distributor): ?>
<tr>
<th scope="row"><?php echo htmlspecialchars($distributor['id']); ?></th>
<td><?php echo htmlspecialchars($distributor['name']); ?></td>
<td><?php echo htmlspecialchars($distributor['created_at']); ?></td>
<td>
<button class="btn btn-sm btn-outline-primary" disabled>تعديل</button>
<button class="btn btn-sm btn-outline-danger" disabled>حذف</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php include 'layout/footer.php'; ?>