From 1c88f0969c3c089048ee2d466ce8db07f46b6671 Mon Sep 17 00:00:00 2001
From: afnanramadhan <13521011@std.stei.itb.ac.id>
Date: Wed, 15 Nov 2023 18:27:20 +0700
Subject: [PATCH] feat: add exp user (connect app to soap)

---
 app/views/profile/index.php        |  2 ++
 public/js/profile.js               | 26 +++++++++++++++++++
 server/controller/auth/Profile.php | 40 ++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+)

diff --git a/app/views/profile/index.php b/app/views/profile/index.php
index 342f298..b5d9751 100644
--- a/app/views/profile/index.php
+++ b/app/views/profile/index.php
@@ -26,6 +26,7 @@ echo "<script>console.log('$id, $fullName, $email, $phone')</script>";
     <!-- include js -->
     <script src="../../../public/js/profile.js"></script>
     <script src="../../../public/js/register.js"></script>
+    <script>window.onload = function() {showExp();};</script>
     <title>NutriCraft</title>
 </head>
 <body>
@@ -43,6 +44,7 @@ echo "<script>console.log('$id, $fullName, $email, $phone')</script>";
             <div class="boxKiri">
                 <div class="photoContainer">
                     <img src=<?php echo $photo?> alt="photoProfile" class="photoProfile" id="photoProfile">
+                    <div id="exp"></div>
                     <div class="editPhotoButton">
                         <label for="file" class="fileLabel">Choose a Photo</label>
                         <input type="file" name="file" id="file" class="file" accept="image/*" onchange="updatePhoto()">
diff --git a/public/js/profile.js b/public/js/profile.js
index 06b5260..82502e4 100644
--- a/public/js/profile.js
+++ b/public/js/profile.js
@@ -77,4 +77,30 @@ function showConfirmationdelete() {
         console.log('cancel');
         hideConfirmation();
     });
+}
+
+function showExp(){
+    const show = "exp";
+
+    xhttp = new XMLHttpRequest();
+    xhttp.onreadystatechange = function() {
+        if (this.readyState === 4){
+            let response = this.response;
+            // const jsonObject = JSON.parse(response);
+            console.log(response);
+            
+            const parentElement = document.getElementById("exp");
+            let html = "";
+
+            html += `
+            <div">
+                <h1>EXP : ${response}</h1>
+            </div>
+            `;
+            
+            parentElement.innerHTML = html;        
+        }
+    };  
+    xhttp.open('GET', `../../server/controller/auth/Profile.php?show=${show}`, true);
+    xhttp.send();
 }
\ No newline at end of file
diff --git a/server/controller/auth/Profile.php b/server/controller/auth/Profile.php
index d7703e5..a2e9891 100644
--- a/server/controller/auth/Profile.php
+++ b/server/controller/auth/Profile.php
@@ -111,6 +111,46 @@ if(isset($_POST['submit'])){
     echo "<script>window.location.href='/?profile'</script>";
 }
 
+if(isset($_GET['show'])){
+    $serviceUrl =  $_ENV['SOAP_URL_USER_LEVEL']."?APIkey=".$_ENV["SOAP_KEY"];
+   
+    $soapRequest = '
+    <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
+        <Body>
+            <getExpUser xmlns="http://Services.nutricraft.org/">
+                <arg0 xmlns="">1</arg0>
+            </getExpUser>
+        </Body>
+    </Envelope>';
+
+    $options = [
+        CURLOPT_URL            => $serviceUrl,
+        CURLOPT_RETURNTRANSFER => true,
+        CURLOPT_POST           => true,
+        CURLOPT_POSTFIELDS     => $soapRequest,
+        CURLOPT_HTTPHEADER     => [
+            'Content-Type: text/xml; charset=utf-8',
+            'Content-Length: ' . strlen($soapRequest),
+        ],
+    ];
+
+    $curl = curl_init();
+    curl_setopt_array($curl, $options);
+
+    $response = curl_exec($curl);
+
+    curl_close($curl);
+
+    if (curl_errno($curl)) {
+        echo 'cURL Error: ' . curl_error($curl);
+    } else {
+        $xml = new SimpleXMLElement($response);
+        $returnValue = (string)$xml->xpath('//return')[0];
+        echo $returnValue;
+    }
+}
+
+
 // if(isset($_POST['submit'])){
 //     if(isset($_POST['fullName'])){
 //         $fullName = $_POST['fullName'];
-- 
GitLab