diff --git a/hospital_services.php b/hospital_services.php new file mode 100644 index 0000000..93fadf6 --- /dev/null +++ b/hospital_services.php @@ -0,0 +1,57 @@ +prepare("INSERT INTO services (name_en, name_ar, department_id, price, is_active) VALUES (?, ?, ?, ?, ?)"); + $stmt->execute([ + $_POST['name_en'], + $_POST['name_ar'], + $_POST['department_id'], + $_POST['price'], + isset($_POST['is_active']) ? 1 : 0 + ]); + $_SESSION['flash_message'] = '
' . __('service_added_successfully') . '
'; + } elseif ($_POST['action'] === 'edit_service') { + $stmt = $db->prepare("UPDATE services SET name_en = ?, name_ar = ?, department_id = ?, price = ?, is_active = ? WHERE id = ?"); + $stmt->execute([ + $_POST['name_en'], + $_POST['name_ar'], + $_POST['department_id'], + $_POST['price'], + isset($_POST['is_active']) ? 1 : 0, + $_POST['id'] + ]); + $_SESSION['flash_message'] = '
' . __('service_updated_successfully') . '
'; + } elseif ($_POST['action'] === 'delete_service') { + $stmt = $db->prepare("DELETE FROM services WHERE id = ?"); + $stmt->execute([$_POST['id']]); + $_SESSION['flash_message'] = '
' . __('service_deleted_successfully') . '
'; + } + // Redirect after successful operation + header("Location: hospital_services.php"); + exit; + } catch (PDOException $e) { + $_SESSION['flash_message'] = '
' . __('error') . ': ' . $e->getMessage() . '
'; + // Redirect even on error, so the user sees the message + header("Location: hospital_services.php"); + exit; + } + } +} + +// Session check logic (if needed in future) +// if (!isset($_SESSION['user_id'])) { ... } + +$section = 'services'; +$title = __('services'); + +require_once __DIR__ . '/includes/layout/header.php'; +require_once __DIR__ . '/includes/pages/services.php'; +require_once __DIR__ . '/includes/layout/footer.php'; diff --git a/includes/layout/header.php b/includes/layout/header.php index a7748f9..4cd0eca 100644 --- a/includes/layout/header.php +++ b/includes/layout/header.php @@ -146,7 +146,7 @@ $site_favicon = !empty($site_settings['company_favicon']) ? $site_settings['comp - + diff --git a/includes/pages/services.php b/includes/pages/services.php index a4a53ef..ea462b3 100644 --- a/includes/pages/services.php +++ b/includes/pages/services.php @@ -1,42 +1,4 @@ prepare("INSERT INTO services (name_en, name_ar, department_id, price, is_active) VALUES (?, ?, ?, ?, ?)"); - $stmt->execute([ - $_POST['name_en'], - $_POST['name_ar'], - $_POST['department_id'], - $_POST['price'], - isset($_POST['is_active']) ? 1 : 0 - ]); - $_SESSION['flash_message'] = '
' . __('service_added_successfully') . '
'; - } elseif ($_POST['action'] === 'edit_service') { - $stmt = $db->prepare("UPDATE services SET name_en = ?, name_ar = ?, department_id = ?, price = ?, is_active = ? WHERE id = ?"); - $stmt->execute([ - $_POST['name_en'], - $_POST['name_ar'], - $_POST['department_id'], - $_POST['price'], - isset($_POST['is_active']) ? 1 : 0, - $_POST['id'] - ]); - $_SESSION['flash_message'] = '
' . __('service_updated_successfully') . '
'; - } elseif ($_POST['action'] === 'delete_service') { - $stmt = $db->prepare("DELETE FROM services WHERE id = ?"); - $stmt->execute([$_POST['id']]); - $_SESSION['flash_message'] = '
' . __('service_deleted_successfully') . '
'; - } - } catch (PDOException $e) { - $_SESSION['flash_message'] = '
' . __('error') . ': ' . $e->getMessage() . '
'; - } - header("Location: services.php"); - exit; - } -} - // Fetch Departments for Dropdown $deptQuery = "SELECT * FROM departments ORDER BY name_$lang"; $deptStmt = $db->query($deptQuery); @@ -93,7 +55,7 @@ $services = $stmt->fetchAll();
-
+
@@ -220,7 +182,7 @@ $services = $stmt->fetchAll();