encryptData($phone); $check = $con->prepare("SELECT id FROM adminUser WHERE phone = ? OR fingerprint_hash = ? LIMIT 1"); $check->execute([$encPhoneInput, $fpHash]); if ($check->rowCount() > 0) { jsonError("رقم الهاتف أو الجهاز مسجل مسبقاً."); exit; } // 3. تجهيز البيانات $uniqueId = bin2hex(random_bytes(16)); // UUID آمن (32 حرف hex عشوائي) $hashedPassword = password_hash($password, PASSWORD_DEFAULT); $encName = $encryptionHelper->encryptData($name); $encPhone = $encPhoneInput; $encFp = $encryptionHelper->encryptData($fingerprint); // التأكد من وجود عمود phone و status في الجدول try { $con->exec("ALTER TABLE adminUser ADD COLUMN phone VARCHAR(255) NULL AFTER name"); $con->exec("ALTER TABLE adminUser ADD COLUMN status VARCHAR(50) DEFAULT 'pending' AFTER role"); } catch (Exception $e) { /* الأعمدة موجودة مسبقاً */ } // 4. الإدخال في قاعدة البيانات بحالة pending $sql = "INSERT INTO adminUser (id, fingerprint, fingerprint_hash, name, phone, password, role, status, created_at) VALUES (:id, :fp, :fp_hash, :name, :phone, :pass, 'admin', 'pending', NOW())"; $stmt = $con->prepare($sql); $stmt->execute([ ':id' => $uniqueId, ':fp' => $encFp, ':fp_hash' => $fpHash, ':name' => $encName, ':phone' => $encPhone, ':pass' => $hashedPassword ]); printSuccess([ "status" => "pending", "message" => "تم تسجيل حسابك بنجاح وهو الآن قيد المراجعة. يرجى انتظار تفعيل المشرف العام." ]); } catch (Exception $e) { error_log("[Admin Register Error] " . $e->getMessage()); jsonError("خطأ في السيرفر: " . $e->getMessage()); } exit();