diff --git a/backend/Admin/marketing/trigger_campaign.php b/backend/Admin/marketing/trigger_campaign.php index 68501aef..7f779d28 100644 --- a/backend/Admin/marketing/trigger_campaign.php +++ b/backend/Admin/marketing/trigger_campaign.php @@ -109,6 +109,22 @@ try { $dispatchedPassengers = []; $fcmErrors = []; + // 5.5 وضع المعاينة: يُرجع ما ستفعله الحملة (النص، الكود، حجم الجمهور) + // دون إنشاء كود ترويجي ودون إرسال أي إشعار. الحملة تُنشئ خصماً حقيقياً + // وتصل كل ركاب الدولة، فوجود معاينة قبل الإطلاق ضروري. + if (filterRequest('dry_run') === '1') { + jsonSuccess([ + 'dry_run' => true, + 'campaign_created' => false, + 'promo_code' => $promoCode, + 'discount_percent' => $discountVal, + 'region' => $regionName, + 'country_code' => strtoupper($countryCode), + 'audience_size' => count($targets), + 'ai_analysis' => $aiCampaign, + ], 'Preview only — no promo code was created and no notification was sent.'); + } + // 6. Save broadcast promo for this campaign (Option 1 - promos table adjustment) $sqlPromo = "INSERT INTO promos (promo_code, amount, description, passengerID, source, validity_start_date, validity_end_date) diff --git a/backend/serviceapp/updatePackages.php b/backend/serviceapp/updatePackages.php index 2aeaf61d..a3c307c9 100644 --- a/backend/serviceapp/updatePackages.php +++ b/backend/serviceapp/updatePackages.php @@ -1,26 +1,53 @@ 'failure', + 'message' => 'Forbidden. Admin access required.', + ], JSON_UNESCAPED_UNICODE); + exit; +} + +$id = filterRequest("id"); $version = filterRequest("version"); +if (empty($id) || empty($version)) { + jsonError("Both id and version are required.", 400); +} +// شكل الإصدار: أرقام ونقاط فقط (مثل 1.2.3) — يمنع أي محتوى آخر. +if (!preg_match('/^\d+(\.\d+){0,3}$/', $version)) { + jsonError("Invalid version format. Use digits separated by dots, e.g. 1.4.2", 400); +} -$sql = "UPDATE `packageInfo` SET `version` ='$version' WHERE `id` = '$id'"; +/** + * سابقاً كان الاستعلام يُبنى بدمج القيم مباشرة: + * "UPDATE packageInfo SET version ='$version' WHERE id = '$id'" + * وهو حقن SQL مباشر — أي مستخدم يملك توكناً صالحاً كان يستطيع تنفيذ ما يشاء + * على قاعدة البيانات عبر حقل الإصدار. الآن القيم مرتبطة كمعاملات. + */ +$stmt = $con->prepare("UPDATE `packageInfo` SET `version` = :version WHERE `id` = :id"); +$stmt->execute([ + ':version' => $version, + ':id' => $id, +]); -// Prepare and execute the statement -$stmt = $con->prepare($sql); -$stmt->execute(); -error_log("Updating package: ID = $sql, Version = $version"); +if (function_exists('logAudit')) { + try { + logAudit($con, (string) ($user_id ?? 'unknown'), 'تحديث إصدار التطبيق', 'packageInfo', $id, [ + 'version' => $version, + ]); + } catch (Throwable $e) { + error_log("[updatePackages] audit failed: " . $e->getMessage()); + } +} - -// Debugging: Check if the query affected any rows if ($stmt->rowCount() > 0) { - // If rows were affected, print success - echo json_encode(['status' => 'success', 'message' => "Package version updated successfully for ID $id"]); + jsonSuccess(['id' => $id, 'version' => $version], "Package version updated successfully for ID $id"); } else { - // If no rows were affected, print failure and debug the query - echo json_encode(['status' => 'failure', 'message' => "Failed to update package version. No rows affected. ID: $id, Version: $version"]); + jsonError("No package row was updated — check that ID $id exists and the version differs.", 404); } -?> \ No newline at end of file diff --git a/dashboard/siro-admin/index.html b/dashboard/siro-admin/index.html index 90878fa8..df13f403 100644 --- a/dashboard/siro-admin/index.html +++ b/dashboard/siro-admin/index.html @@ -12,7 +12,10 @@ - + +
@@ -601,6 +604,6 @@ - +