prepare("SELECT * FROM user_permissions WHERE user_id = ? AND page = 'accounting' AND can_view = 1");
$stmt->execute([$user_id]);
if (!$stmt->fetch()) {
echo "
لا تملك صلاحية الوصول لهذه الصفحة.
";
require_once 'includes/footer.php';
exit;
}
$message = null;
$messageType = 'success';
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['add_account'])) {
$name = $_POST['name'];
$type = $_POST['type'];
$stmt = db()->prepare("INSERT INTO accounting_accounts (name, type) VALUES (?, ?)");
if($stmt->execute([$name, $type])) {
$message = "تم إضافة الحساب بنجاح.";
}
} elseif (isset($_POST['delete_account'])) {
$id = $_POST['id'];
$stmt = db()->prepare("DELETE FROM accounting_accounts WHERE id = ?");
if($stmt->execute([$id])) {
$message = "تم حذف الحساب.";
}
} elseif (isset($_POST['edit_account'])) {
$id = $_POST['id'];
$name = $_POST['name'];
$type = $_POST['type'];
$stmt = db()->prepare("UPDATE accounting_accounts SET name = ?, type = ? WHERE id = ?");
if($stmt->execute([$name, $type, $id])) {
$message = "تم تحديث الحساب بنجاح.";
}
}
}
// Pagination
$page = isset($_GET['p']) ? (int)$_GET['p'] : 1;
$limit = 10;
$offset = ($page - 1) * $limit;
$totalAccounts = db()->query("SELECT COUNT(*) FROM accounting_accounts")->fetchColumn();
$totalPages = ceil($totalAccounts / $limit);
$accounts = db()->prepare("SELECT * FROM accounting_accounts ORDER BY type, name LIMIT ? OFFSET ?");
$accounts->bindValue(1, $limit, PDO::PARAM_INT);
$accounts->bindValue(2, $offset, PDO::PARAM_INT);
$accounts->execute();
$accounts = $accounts->fetchAll(PDO::FETCH_ASSOC);
// Map English types to Arabic
$typeMap = [
'Assets' => 'أصول',
'Liabilities' => 'خصوم',
'Equity' => 'حقوق ملكية',
'Revenue' => 'إيرادات',
'Expenses' => 'مصروفات',
'أصول' => 'أصول',
'خصوم' => 'خصوم',
'حقوق ملكية' => 'حقوق ملكية',
'إيرادات' => 'إيرادات',
'مصروفات' => 'مصروفات'
];
?>
دليل الحسابات
الاسم
النوع
إجراءات
= htmlspecialchars($account['name']) ?>
= htmlspecialchars($typeMap[$account['type']] ?? $account['type']) ?>
لا توجد حسابات مضافة بعد.
1): ?>