update setup file
This commit is contained in:
parent
393595fe77
commit
aabdb7b681
238
db/schema.sql
Normal file
238
db/schema.sql
Normal file
@ -0,0 +1,238 @@
|
||||
-- Table structure for `branches`
|
||||
CREATE TABLE IF NOT EXISTS `branches` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`code` varchar(50) NOT NULL,
|
||||
`name_ar` varchar(100) NOT NULL,
|
||||
`name_en` varchar(100) NOT NULL,
|
||||
`city_ar` varchar(100) DEFAULT NULL,
|
||||
`city_en` varchar(100) DEFAULT NULL,
|
||||
`created_at` datetime DEFAULT current_timestamp(),
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `code` (`code`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Table structure for `categories`
|
||||
CREATE TABLE IF NOT EXISTS `categories` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name_ar` varchar(150) NOT NULL,
|
||||
`name_en` varchar(150) NOT NULL,
|
||||
`description` text DEFAULT NULL,
|
||||
`created_at` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Table structure for `customers`
|
||||
CREATE TABLE IF NOT EXISTS `customers` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(150) NOT NULL,
|
||||
`phone` varchar(50) DEFAULT NULL,
|
||||
`email` varchar(150) DEFAULT NULL,
|
||||
`address` text DEFAULT NULL,
|
||||
`created_at` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Table structure for `expense_categories`
|
||||
CREATE TABLE IF NOT EXISTS `expense_categories` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name_ar` varchar(255) NOT NULL,
|
||||
`name_en` varchar(255) NOT NULL,
|
||||
`created_at` timestamp NULL DEFAULT current_timestamp(),
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Table structure for `expenses`
|
||||
CREATE TABLE IF NOT EXISTS `expenses` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`branch_code` varchar(50) DEFAULT NULL,
|
||||
`category_id` int(11) NOT NULL,
|
||||
`amount` decimal(10,3) NOT NULL,
|
||||
`expense_date` date NOT NULL,
|
||||
`description` text DEFAULT NULL,
|
||||
`created_by` int(11) DEFAULT NULL,
|
||||
`created_at` timestamp NULL DEFAULT current_timestamp(),
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `category_id` (`category_id`),
|
||||
CONSTRAINT `expenses_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `expense_categories` (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Table structure for `items`
|
||||
CREATE TABLE IF NOT EXISTS `items` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`sku` varchar(50) NOT NULL,
|
||||
`name` varchar(200) NOT NULL,
|
||||
`price` decimal(10,3) NOT NULL,
|
||||
`cost_price` decimal(10,2) DEFAULT 0.00,
|
||||
`base_stock` int(11) NOT NULL DEFAULT 0,
|
||||
`vat` decimal(5,3) NOT NULL DEFAULT 5.000,
|
||||
`category_id` int(10) unsigned DEFAULT NULL,
|
||||
`supplier_id` int(10) unsigned DEFAULT NULL,
|
||||
`image_url` varchar(255) DEFAULT NULL,
|
||||
`created_at` datetime DEFAULT current_timestamp(),
|
||||
`unit_id` int(10) unsigned DEFAULT NULL,
|
||||
`in_catalog` tinyint(1) NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `sku` (`sku`),
|
||||
KEY `category_id` (`category_id`),
|
||||
KEY `supplier_id` (`supplier_id`),
|
||||
KEY `items_unit_fk` (`unit_id`),
|
||||
CONSTRAINT `items_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON DELETE SET NULL,
|
||||
CONSTRAINT `items_ibfk_2` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`id`) ON DELETE SET NULL,
|
||||
CONSTRAINT `items_unit_fk` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE SET NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Table structure for `online_orders`
|
||||
CREATE TABLE IF NOT EXISTS `online_orders` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`customer_name` varchar(255) NOT NULL,
|
||||
`customer_phone` varchar(50) NOT NULL,
|
||||
`customer_address` text NOT NULL,
|
||||
`items_json` longtext NOT NULL,
|
||||
`subtotal` decimal(10,2) DEFAULT 0.00,
|
||||
`vat_amount` decimal(10,2) DEFAULT 0.00,
|
||||
`total_amount` decimal(10,2) NOT NULL,
|
||||
`status` varchar(20) NOT NULL DEFAULT 'pending',
|
||||
`created_at` datetime DEFAULT current_timestamp(),
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Table structure for `purchase_orders`
|
||||
CREATE TABLE IF NOT EXISTS `purchase_orders` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`reference_no` varchar(50) NOT NULL,
|
||||
`branch_code` varchar(30) NOT NULL,
|
||||
`user_username` varchar(60) NOT NULL,
|
||||
`user_name` varchar(120) NOT NULL,
|
||||
`role_name` varchar(40) NOT NULL,
|
||||
`supplier_name` varchar(120) DEFAULT NULL,
|
||||
`items_json` longtext NOT NULL,
|
||||
`item_count` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`subtotal` decimal(10,2) NOT NULL DEFAULT 0.00,
|
||||
`vat_amount` decimal(10,3) NOT NULL DEFAULT 0.000,
|
||||
`total_amount` decimal(10,2) NOT NULL DEFAULT 0.00,
|
||||
`notes` text DEFAULT NULL,
|
||||
`status` varchar(20) NOT NULL DEFAULT 'completed',
|
||||
`purchase_date` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
`created_at` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `reference_no` (`reference_no`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Table structure for `sales_orders`
|
||||
CREATE TABLE IF NOT EXISTS `sales_orders` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`receipt_no` varchar(50) NOT NULL,
|
||||
`sale_mode` varchar(20) NOT NULL,
|
||||
`branch_code` varchar(30) NOT NULL,
|
||||
`cashier_username` varchar(60) NOT NULL,
|
||||
`cashier_name` varchar(120) NOT NULL,
|
||||
`role_name` varchar(40) NOT NULL,
|
||||
`customer_name` varchar(120) DEFAULT NULL,
|
||||
`payment_method` varchar(30) NOT NULL,
|
||||
`items_json` longtext NOT NULL,
|
||||
`item_count` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`subtotal` decimal(10,2) NOT NULL DEFAULT 0.00,
|
||||
`vat_amount` decimal(10,3) NOT NULL DEFAULT 0.000,
|
||||
`total_amount` decimal(10,2) NOT NULL DEFAULT 0.00,
|
||||
`notes` text DEFAULT NULL,
|
||||
`sale_date` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
`created_at` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
`status` varchar(20) NOT NULL DEFAULT 'completed',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `receipt_no` (`receipt_no`),
|
||||
KEY `idx_sale_mode` (`sale_mode`),
|
||||
KEY `idx_branch_code` (`branch_code`),
|
||||
KEY `idx_sale_date` (`sale_date`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Table structure for `settings`
|
||||
CREATE TABLE IF NOT EXISTS `settings` (
|
||||
`setting_key` varchar(50) NOT NULL,
|
||||
`setting_value` text DEFAULT NULL,
|
||||
PRIMARY KEY (`setting_key`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Table structure for `suppliers`
|
||||
CREATE TABLE IF NOT EXISTS `suppliers` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(150) NOT NULL,
|
||||
`contact_person` varchar(150) DEFAULT NULL,
|
||||
`phone` varchar(50) DEFAULT NULL,
|
||||
`email` varchar(150) DEFAULT NULL,
|
||||
`address` text DEFAULT NULL,
|
||||
`created_at` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Table structure for `units`
|
||||
CREATE TABLE IF NOT EXISTS `units` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name_ar` varchar(150) NOT NULL,
|
||||
`name_en` varchar(150) NOT NULL,
|
||||
`created_at` datetime DEFAULT current_timestamp(),
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Table structure for `users`
|
||||
CREATE TABLE IF NOT EXISTS `users` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`username` varchar(50) NOT NULL,
|
||||
`password` varchar(255) NOT NULL,
|
||||
`role` varchar(50) NOT NULL,
|
||||
`permissions` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`permissions`)),
|
||||
`branch_code` varchar(50) NOT NULL,
|
||||
`allowed_branches` varchar(255) DEFAULT NULL,
|
||||
`name_ar` varchar(100) NOT NULL,
|
||||
`name_en` varchar(100) NOT NULL,
|
||||
`created_at` timestamp NULL DEFAULT current_timestamp(),
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `username` (`username`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Data for table `branches`
|
||||
INSERT IGNORE INTO `branches` (`id`, `code`, `name_ar`, `name_en`, `city_ar`, `city_en`, `created_at`) VALUES ('1', 'muscat', 'الفرع الرئيسي', 'Main Branch', 'مسقط', 'Muscat', '2026-04-19 15:16:52');
|
||||
INSERT IGNORE INTO `branches` (`id`, `code`, `name_ar`, `name_en`, `city_ar`, `city_en`, `created_at`) VALUES ('2', 'sohar', 'فرع صحار', 'Sohar Branch', 'صحار', 'Sohar', '2026-04-19 15:16:52');
|
||||
INSERT IGNORE INTO `branches` (`id`, `code`, `name_ar`, `name_en`, `city_ar`, `city_en`, `created_at`) VALUES ('3', 'nizwa', 'فرع نزوى', 'Nizwa Branch', 'نزوى', 'Nizwa', '2026-04-19 15:16:52');
|
||||
|
||||
-- Data for table `categories`
|
||||
INSERT IGNORE INTO `categories` (`id`, `name_ar`, `name_en`, `description`, `created_at`) VALUES ('1', 'إلكترونيات', 'Electronics', NULL, '2026-04-19 02:39:32');
|
||||
INSERT IGNORE INTO `categories` (`id`, `name_ar`, `name_en`, `description`, `created_at`) VALUES ('2', 'إكسسوارات', 'Accessories', NULL, '2026-04-19 02:39:32');
|
||||
INSERT IGNORE INTO `categories` (`id`, `name_ar`, `name_en`, `description`, `created_at`) VALUES ('3', 'ملابس', 'Clothing', NULL, '2026-04-19 02:39:32');
|
||||
|
||||
-- Data for table `expense_categories`
|
||||
INSERT IGNORE INTO `expense_categories` (`id`, `name_ar`, `name_en`, `created_at`) VALUES ('1', 'رواتب', 'Salary', '2026-04-20 02:33:54');
|
||||
INSERT IGNORE INTO `expense_categories` (`id`, `name_ar`, `name_en`, `created_at`) VALUES ('2', 'كهرباء وماء', 'Water & Electricity ', '2026-04-20 02:34:28');
|
||||
INSERT IGNORE INTO `expense_categories` (`id`, `name_ar`, `name_en`, `created_at`) VALUES ('3', 'أجور عمال', 'Labour', '2026-04-20 02:34:53');
|
||||
INSERT IGNORE INTO `expense_categories` (`id`, `name_ar`, `name_en`, `created_at`) VALUES ('4', 'ضرائب', 'Taxes', '2026-04-20 02:35:13');
|
||||
|
||||
-- Data for table `settings`
|
||||
INSERT IGNORE INTO `settings` (`setting_key`, `setting_value`) VALUES ('company_address', '');
|
||||
INSERT IGNORE INTO `settings` (`setting_key`, `setting_value`) VALUES ('company_email', '');
|
||||
INSERT IGNORE INTO `settings` (`setting_key`, `setting_value`) VALUES ('company_favicon', '');
|
||||
INSERT IGNORE INTO `settings` (`setting_key`, `setting_value`) VALUES ('company_logo', '');
|
||||
INSERT IGNORE INTO `settings` (`setting_key`, `setting_value`) VALUES ('company_name_ar', 'حلوى الريامي');
|
||||
INSERT IGNORE INTO `settings` (`setting_key`, `setting_value`) VALUES ('company_name_en', 'Al Riyami Sweets');
|
||||
INSERT IGNORE INTO `settings` (`setting_key`, `setting_value`) VALUES ('company_phone', '');
|
||||
INSERT IGNORE INTO `settings` (`setting_key`, `setting_value`) VALUES ('company_vat_number', '');
|
||||
INSERT IGNORE INTO `settings` (`setting_key`, `setting_value`) VALUES ('mail_from', '');
|
||||
INSERT IGNORE INTO `settings` (`setting_key`, `setting_value`) VALUES ('mail_from_name', '');
|
||||
INSERT IGNORE INTO `settings` (`setting_key`, `setting_value`) VALUES ('smtp_host', '');
|
||||
INSERT IGNORE INTO `settings` (`setting_key`, `setting_value`) VALUES ('smtp_pass', '');
|
||||
INSERT IGNORE INTO `settings` (`setting_key`, `setting_value`) VALUES ('smtp_port', '587');
|
||||
INSERT IGNORE INTO `settings` (`setting_key`, `setting_value`) VALUES ('smtp_secure', '');
|
||||
INSERT IGNORE INTO `settings` (`setting_key`, `setting_value`) VALUES ('smtp_user', '');
|
||||
INSERT IGNORE INTO `settings` (`setting_key`, `setting_value`) VALUES ('timezone', 'Asia/Muscat');
|
||||
INSERT IGNORE INTO `settings` (`setting_key`, `setting_value`) VALUES ('vat_percentage', '5');
|
||||
|
||||
-- Data for table `units`
|
||||
INSERT IGNORE INTO `units` (`id`, `name_ar`, `name_en`, `created_at`) VALUES ('1', 'حبة', 'piece ', '2026-04-19 05:03:16');
|
||||
INSERT IGNORE INTO `units` (`id`, `name_ar`, `name_en`, `created_at`) VALUES ('2', 'كيلوم جرام', 'Kilogram', '2026-04-19 05:03:44');
|
||||
INSERT IGNORE INTO `units` (`id`, `name_ar`, `name_en`, `created_at`) VALUES ('3', 'جرام', 'gram', '2026-04-19 05:04:01');
|
||||
INSERT IGNORE INTO `units` (`id`, `name_ar`, `name_en`, `created_at`) VALUES ('4', 'كرتون', 'Carton', '2026-04-19 05:04:21');
|
||||
INSERT IGNORE INTO `units` (`id`, `name_ar`, `name_en`, `created_at`) VALUES ('5', 'كيس', 'bag', '2026-04-19 05:04:36');
|
||||
|
||||
-- Data for table `users`
|
||||
INSERT IGNORE INTO `users` (`id`, `username`, `password`, `role`, `permissions`, `branch_code`, `allowed_branches`, `name_ar`, `name_en`, `created_at`) VALUES ('1', 'owner', '$2y$10$QpW18WHHU8wSKQrYdYTRJuaNPw1v1puJgBpvfc6m9H8gnsws5C9/q', 'owner', NULL, 'muscat', NULL, 'مالك النظام', 'System Owner', '2026-04-19 09:23:45');
|
||||
INSERT IGNORE INTO `users` (`id`, `username`, `password`, `role`, `permissions`, `branch_code`, `allowed_branches`, `name_ar`, `name_en`, `created_at`) VALUES ('2', 'manager_muscat', '$2y$10$mXI290vI7qEIP.At1YFeFOt/pHf096S3h7CWHYfJYluw7QQlM7uDm', 'manager', NULL, 'muscat', NULL, 'مدير فرع مسقط', 'Muscat Branch Manager', '2026-04-19 09:23:45');
|
||||
INSERT IGNORE INTO `users` (`id`, `username`, `password`, `role`, `permissions`, `branch_code`, `allowed_branches`, `name_ar`, `name_en`, `created_at`) VALUES ('3', 'cashier_sohar', '$2y$10$.iWxSZWkRuWhuNrmt/LAv./HCWlHQJSpoYqa9pJMoobHCWbMpvXZe', 'cashier', NULL, 'sohar', NULL, 'كاشير فرع صحار', 'Sohar Cashier', '2026-04-19 09:23:46');
|
||||
|
||||
40
db/setup.php
Normal file
40
db/setup.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Database Setup & Migration Script
|
||||
*
|
||||
* Run this file once to set up the database structure and insert default values.
|
||||
* Access via browser: http://localhost/db/setup.php
|
||||
* Or via CLI: php db/setup.php
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/config.php';
|
||||
|
||||
$pdo = db();
|
||||
|
||||
$sql_file = __DIR__ . '/schema.sql';
|
||||
|
||||
if (!file_exists($sql_file)) {
|
||||
die("Error: schema.sql not found in db directory.");
|
||||
}
|
||||
|
||||
$sql = file_get_contents($sql_file);
|
||||
|
||||
try {
|
||||
// Execute the full SQL file
|
||||
$pdo->exec($sql);
|
||||
$message = "Database schema and default data successfully migrated!";
|
||||
if (php_sapi_name() === 'cli') {
|
||||
echo $message . "\n";
|
||||
} else {
|
||||
echo "<h2 style='color:green; font-family:sans-serif;'>$message</h2>";
|
||||
echo "<p style='font-family:sans-serif;'><a href='../index.php'>Go to App</a></p>";
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$error = "Migration Failed: " . $e->getMessage();
|
||||
if (php_sapi_name() === 'cli') {
|
||||
echo $error . "\n";
|
||||
} else {
|
||||
echo "<h2 style='color:red; font-family:sans-serif;'>$error</h2>";
|
||||
}
|
||||
}
|
||||
|
||||
36
db_seed.php
36
db_seed.php
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
require 'db/config.php';
|
||||
$db = db();
|
||||
|
||||
// 1. Create items table
|
||||
$db->exec("
|
||||
CREATE TABLE IF NOT EXISTS items (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
sku VARCHAR(50) NOT NULL UNIQUE,
|
||||
name VARCHAR(200) NOT NULL,
|
||||
price DECIMAL(10,3) NOT NULL,
|
||||
base_stock INT NOT NULL DEFAULT 0,
|
||||
vat DECIMAL(5,3) NOT NULL DEFAULT 5.000,
|
||||
category_id INT UNSIGNED NULL,
|
||||
supplier_id INT UNSIGNED NULL,
|
||||
image_url VARCHAR(255) NULL,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (supplier_id) REFERENCES suppliers(id) ON DELETE SET NULL
|
||||
);
|
||||
");
|
||||
|
||||
// 2. Insert Categories
|
||||
$db->exec("INSERT IGNORE INTO categories (id, name_ar, name_en) VALUES
|
||||
(1, 'إلكترونيات', 'Electronics'),
|
||||
(2, 'إكسسوارات', 'Accessories'),
|
||||
(3, 'ملابس', 'Clothing');");
|
||||
|
||||
// 3. Insert Suppliers
|
||||
$db->exec("INSERT IGNORE INTO suppliers (id, name, contact_person, phone) VALUES
|
||||
(1, 'TechCorp', 'John Doe', '123456789'),
|
||||
(2, 'ElectroWholesale', 'Jane Smith', '987654321'),
|
||||
(3, 'StyleCo', 'Mike Johnson', '555666777');");
|
||||
|
||||
echo "Database schema and base entities created.\n";
|
||||
|
||||
14
dump_schema.php
Normal file
14
dump_schema.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
require_once 'db/config.php';
|
||||
$pdo = db();
|
||||
$stmt = $pdo->query("SHOW TABLES");
|
||||
$tables = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
$sql = "";
|
||||
foreach ($tables as $table) {
|
||||
$createStmt = $pdo->query("SHOW CREATE TABLE `$table`")->fetch(PDO::FETCH_ASSOC);
|
||||
$sql .= "-- Table structure for `$table`\n";
|
||||
$sql .= $createStmt['Create Table'] . ";\n\n";
|
||||
}
|
||||
echo $sql;
|
||||
|
||||
90
patch.php
90
patch.php
@ -1,90 +0,0 @@
|
||||
<?php
|
||||
$content = file_get_contents('online_orders.php');
|
||||
|
||||
$phpBackend = <<<'PHP'
|
||||
} elseif ($_POST['action'] === 'edit_order') {
|
||||
$id = (int)$_POST['id'];
|
||||
$customer_name = trim($_POST['customer_name'] ?? '');
|
||||
$customer_phone = trim($_POST['customer_phone'] ?? '');
|
||||
$customer_address = trim($_POST['customer_address'] ?? '');
|
||||
|
||||
if ($customer_name && $customer_phone && $customer_address) {
|
||||
$stmt = $db->prepare("UPDATE online_orders SET customer_name = ?, customer_phone = ?, customer_address = ? WHERE id = ?");
|
||||
$stmt->execute([$customer_name, $customer_phone, $customer_address, $id]);
|
||||
set_flash('success', tr('تم تعديل الطلب بنجاح', 'Order updated successfully'));
|
||||
} else {
|
||||
set_flash('danger', tr('الرجاء تعبئة جميع الحقول', 'Please fill all fields'));
|
||||
}
|
||||
redirect_to('online_orders.php');
|
||||
PHP;
|
||||
|
||||
$content = str_replace("redirect_to('online_orders.php');\n }\n", "redirect_to('online_orders.php');\n }\n" . $phpBackend . "\n }\n", $content);
|
||||
|
||||
$editButton = <<<'HTML'
|
||||
<button class="btn btn-sm btn-info shadow-sm text-white" onclick='editOrder(<?= json_encode([
|
||||
"id" => $o["id"],
|
||||
"name" => $o["customer_name"],
|
||||
"phone" => $o["customer_phone"],
|
||||
"address" => $o["customer_address"]
|
||||
], JSON_UNESCAPED_UNICODE) ?>)'>
|
||||
<i class="bi bi-pencil"></i>
|
||||
</button>
|
||||
HTML;
|
||||
|
||||
$content = str_replace('<i class="bi bi-eye"></i>
|
||||
</button>', "<i class=\"bi bi-eye\"></i>\n </button>\n" . $editButton, $content);
|
||||
|
||||
$editModal = <<<'HTML'
|
||||
<!-- Edit Order Modal -->
|
||||
<div class="modal fade d-print-none" id="editOrderModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content rounded-4 border-0 shadow">
|
||||
<form method="post">
|
||||
<input type="hidden" name="action" value="edit_order">
|
||||
<input type="hidden" name="id" id="editOrderId" value="">
|
||||
<div class="modal-header border-bottom-0 pb-0 pt-4 px-4">
|
||||
<h5 class="modal-title fw-bold"><?= h(tr('تعديل بيانات الطلب', 'Edit Order Details')) ?></h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body p-4">
|
||||
<div class="mb-3">
|
||||
<label class="form-label"><?= h(tr('اسم العميل', 'Customer Name')) ?></label>
|
||||
<input type="text" name="customer_name" id="editCustomerName" class="form-control" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label"><?= h(tr('رقم الهاتف', 'Phone Number')) ?></label>
|
||||
<input type="text" name="customer_phone" id="editCustomerPhone" class="form-control" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label"><?= h(tr('العنوان', 'Address')) ?></label>
|
||||
<textarea name="customer_address" id="editCustomerAddress" class="form-control" rows="3" required></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer border-top-0 pt-0 pb-4 px-4">
|
||||
<button type="button" class="btn btn-secondary rounded-pill px-4" data-bs-dismiss="modal"><?= h(tr('إلغاء', 'Cancel')) ?></button>
|
||||
<button type="submit" class="btn btn-primary rounded-pill px-4"><?= h(tr('حفظ التعديلات', 'Save Changes')) ?></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
HTML;
|
||||
|
||||
$content = str_replace('<!-- Order Modal', $editModal . "\n\n<!-- Order Modal", $content);
|
||||
|
||||
$js = <<<'JS'
|
||||
const editOrderModal = new bootstrap.Modal(document.getElementById('editOrderModal'));
|
||||
|
||||
function editOrder(order) {
|
||||
document.getElementById('editOrderId').value = order.id;
|
||||
document.getElementById('editCustomerName').value = order.name;
|
||||
document.getElementById('editCustomerPhone').value = order.phone;
|
||||
document.getElementById('editCustomerAddress').value = order.address;
|
||||
editOrderModal.show();
|
||||
}
|
||||
JS;
|
||||
|
||||
$content = str_replace('const orderModal = new bootstrap.Modal', $js . "\n\nconst orderModal = new bootstrap.Modal", $content);
|
||||
|
||||
file_put_contents('online_orders.php', $content);
|
||||
echo "Patched\n";
|
||||
Loading…
x
Reference in New Issue
Block a user