diff --git a/app/modules_app/tenants/update.php b/app/modules_app/tenants/update.php new file mode 100644 index 0000000..3bc1682 --- /dev/null +++ b/app/modules_app/tenants/update.php @@ -0,0 +1,63 @@ + 'required', + 'name' => 'required', + 'email' => 'required|email', + 'status' => 'required' +]); + +if ($errors) { + json_error('Validation Failed', 422, $errors); +} + +$db = Database::getInstance(); + +try { + // Encrypt sensitive data + $encryptedName = \App\Core\Encryption::encrypt($data['name']); + $encryptedEmail = \App\Core\Encryption::encrypt($data['email']); + + $stmt = $db->prepare(" + UPDATE tenants + SET name = ?, email = ?, phone = ?, status = ?, updated_at = NOW() + WHERE id = ? + "); + + $stmt->execute([ + $encryptedName, + $encryptedEmail, + $data['phone'] ?? null, + $data['status'], + $data['id'] + ]); + + if ($stmt->rowCount() === 0) { + // Might be unchanged or ID doesn't exist + $check = $db->prepare("SELECT id FROM tenants WHERE id = ?"); + $check->execute([$data['id']]); + if (!$check->fetch()) { + json_error('Tenant not found', 404); + } + } + + json_success(null, 'تم تحديث بيانات المكتب بنجاح'); + +} catch (\Exception $e) { + json_error('حدث خطأ أثناء التحديث: ' . $e->getMessage(), 500); +} diff --git a/public/index.php b/public/index.php index ab7aad6..3a78f91 100644 --- a/public/index.php +++ b/public/index.php @@ -36,6 +36,7 @@ $routes = [ 'v1/dashboard/stats' => ['GET', 'dashboard/stats.php'], 'v1/tenants' => ['GET', 'tenants/index.php'], 'v1/tenants/create' => ['POST', 'tenants/create.php'], + 'v1/tenants/update' => ['POST', 'tenants/update.php'], ]; if (isset($routes[$route])) { diff --git a/public/shell.php b/public/shell.php index 70cf18e..321efb5 100644 --- a/public/shell.php +++ b/public/shell.php @@ -274,7 +274,7 @@