90 lines
4.4 KiB
PHP
90 lines
4.4 KiB
PHP
<?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"; |