diff --git a/functions.php b/functions.php index 350ae3b..7ea50f1 100755 --- a/functions.php +++ b/functions.php @@ -479,6 +479,6 @@ function logAudit($con, $adminId, $action, $tableName = null, $recordId = null, return true; } catch (Exception $e) { error_log("Audit Log Error: " . $e->getMessage()); - return false; + return $e->getMessage(); } } diff --git a/ride/kazan/update.php b/ride/kazan/update.php index bb31470..eb9f5c8 100644 --- a/ride/kazan/update.php +++ b/ride/kazan/update.php @@ -31,12 +31,12 @@ $stmt = $con->prepare($sql); $stmt->execute($params); // تسجيل العملية في السجل دائماً (حتى لو لم تتغير القيمة) لضمان الشفافية -logAudit($con, $user_id, "تحديث عمولة/أسعار النظام (Kazan)", "kazan", $id, $params); +$auditResult = logAudit($con, $user_id ?? 'unknown_admin', "تحديث عمولة/أسعار النظام (Kazan)", "kazan", $id, $params); if ($stmt->rowCount() > 0) { - jsonSuccess(null, "Kazan data updated successfully"); + jsonSuccess(null, "Kazan data updated successfully. Audit: " . ($auditResult === true ? 'OK' : $auditResult)); } else { // If no rows were changed but execute was successful, it might be because the data is the same - jsonSuccess(null, "Kazan data remains unchanged or updated"); + jsonSuccess(null, "Kazan data remains unchanged or updated. Audit: " . ($auditResult === true ? 'OK' : $auditResult)); } ?> \ No newline at end of file diff --git a/test_audit.php b/test_audit.php new file mode 100644 index 0000000..aff2743 --- /dev/null +++ b/test_audit.php @@ -0,0 +1,33 @@ +فحص نظام السجلات (Audit Log Test)"; + +try { + $stmt = $con->prepare(" + INSERT INTO `admin_audit_log` (`admin_id`, `action`, `table_name`, `record_id`, `details`) + VALUES (:admin_id, :action, :table_name, :record_id, :details) + "); + $result = $stmt->execute([ + ':admin_id' => 'test_admin_01', + ':action' => 'فحص النظام', + ':table_name' => 'test_table', + ':record_id' => '999', + ':details' => json_encode(['status' => 'test'], JSON_UNESCAPED_UNICODE) + ]); + + if ($result) { + echo "
✅ نجاح: تم إضافة سجل اختباري بنجاح إلى قاعدة البيانات.
"; + } else { + echo "⚠️ فشل الإضافة ولكن لم يظهر خطأ!
"; + } +} catch (Exception $e) { + echo "❌ خطأ في قاعدة البيانات: " . $e->getMessage() . "
"; +} +?>