From 775549229e5efecc66994b5c5fa0d1d08cec7464 Mon Sep 17 00:00:00 2001
From: Haidar <16521522@mahasiswa.itb.ac.id>
Date: Fri, 17 Nov 2023 09:35:16 +0700
Subject: [PATCH] feat: add code rest from soap

---
 api/challenge/claim.php | 43 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/api/challenge/claim.php b/api/challenge/claim.php
index d6d1c86..4d24430 100644
--- a/api/challenge/claim.php
+++ b/api/challenge/claim.php
@@ -1,5 +1,7 @@
 <?php
 
+session_start();
+
 include_once __DIR__."/../session.php";
 
 if ($_SERVER['REQUEST_METHOD'] === 'POST') {
@@ -12,7 +14,48 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
     $sql = "INSERT INTO user_quest (user_id, quest_id) VALUES ($user_id, $quest_id)";
     $result = $conn->query($sql);
 
+    $username = $_SESSION['username'];
+    $query = "SELECT * FROM users WHERE username = ?";
+    $stmt = $conn->prepare($query);
+    $stmt->bind_param("s", $username);
+    $stmt->execute();
+    $results = $stmt->get_result();
+    $row = $results->fetch_assoc();
+    $UserId = $row['id'];
+
+    $requestBody = '<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
+        <Body>
+            <updatePoint xmlns="http://service.example.org/">
+                <arg0 xmlns="">' . $UserId . '</arg0>
+                <arg1 xmlns="">10</arg1>
+            </updatePoint>
+        </Body>
+    </Envelope>';
+        // echo $requestBody;
+        $curl = curl_init();
+        curl_setopt($curl, CURLOPT_URL, '10.97.51.237:8081/updatePoint');
+        curl_setopt($curl, CURLOPT_POST, true);
+        curl_setopt($curl, CURLOPT_HTTPHEADER, [
+            'Content-Type: text/xml; charset="utf-8"',
+            'X-API-KEY: PHPClient',
+        ]);
+        curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody);
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+
+        $response = curl_exec($curl);
+        if ($response === false) {
+            $error = curl_error($curl);
+            echo 'Error: ' . $error;
+        } else {
+            $responseXml = simplexml_load_string($response);
+            $returnValue = $responseXml->xpath('//return');
+            $value = (string) $returnValue[0];
+            echo $value;
+        }
+
     echo $sql;
+    echo "ini bawah sql";
+    echo $row['id'];
 
 } else {
     http_response_code(405);
-- 
GitLab