diff --git a/api/exercise/submit.php b/api/exercise/submit.php index 55a2ec28cd6ac159c18624aa0da3a40a007cccd1..a1d847778cea91d9fd2c98529909ba76bad6ba3d 100644 --- a/api/exercise/submit.php +++ b/api/exercise/submit.php @@ -16,7 +16,7 @@ function submitQuiz($exerciseId, $selectedOption) var_dump($exerciseId); $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, "http://172.20.10.2:5000/exercise/result/" . $exerciseId); + curl_setopt($ch, CURLOPT_URL, "http://express:5000/exercise/result/" . $exerciseId); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($submitData)); diff --git a/app/controllers/Exercise.php b/app/controllers/Exercise.php index 1d37887a67be374615f8704ed62a2f189152a178..60ca4148172c4dd58c739221b1629be7e6908a34 100644 --- a/app/controllers/Exercise.php +++ b/app/controllers/Exercise.php @@ -9,7 +9,7 @@ class Exercise extends Controller $data["pageTitle"] = "Test your knowledge!"; $data["languages"] = $this->model("LanguageModel")->getAllLanguage(); - $baseUrl = 'http://172.20.10.2:5000/exercise'; + $baseUrl = 'http://express:5000/exercise'; $ch = curl_init($baseUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); @@ -35,7 +35,7 @@ class Exercise extends Controller $data["user_id"] = $_SESSION['user_id']; $data["exercise_id"] = intval($exerciseId); - $baseUrl = 'http://172.20.10.2:5000/exercise'; + $baseUrl = 'http://express:5000/exercise'; $ch = curl_init($baseUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); @@ -50,7 +50,7 @@ class Exercise extends Controller } } - $baseUrl = 'http://172.20.10.2:5000/question/' . $data["exercise_id"]; + $baseUrl = 'http://express:5000/question/' . $data["exercise_id"]; $ch = curl_init($baseUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); @@ -58,7 +58,7 @@ class Exercise extends Controller $data["question"] = $question['result'][0]; // ini '0' bisa diganti page - $baseUrl = 'http://172.20.10.2:5000/option/' . $data["question"]["question_id"]; + $baseUrl = 'http://express:5000/option/' . $data["question"]["question_id"]; $ch = curl_init($baseUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); diff --git a/app/controllers/Merchandise.php b/app/controllers/Merchandise.php index b9867ea6fda18a0b0f1cae566086a2dfa6dd3204..8e499e92134adbfc0f5dd48ac97ca9a1cb0ea1a6 100644 --- a/app/controllers/Merchandise.php +++ b/app/controllers/Merchandise.php @@ -9,7 +9,7 @@ class Merchandise extends Controller $data["pageTitle"] = "Merch!"; $data["user_id"] = $_SESSION['user_id']; - $baseUrl = 'http://10.97.58.62:8080/gems'; + $baseUrl = 'http://soap:8080/gems'; $soapRequest = '<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" @@ -17,7 +17,7 @@ class Merchandise extends Controller <x:Header/> <x:Body> <ser:getGems> - <arg0>1</arg0> + <arg0>' . $data["user_id"] . '</arg0> </ser:getGems> </x:Body> </x:Envelope>'; @@ -26,10 +26,14 @@ class Merchandise extends Controller curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $soapRequest); - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Content-Type: text/xml', - 'SOAPAction: getGems' - ) + curl_setopt( + $ch, + CURLOPT_HTTPHEADER, + array( + 'Content-Type: text/xml', + 'SOAPAction: getGems', + 'X-api-key: toco_php' + ) ); $response = curl_exec($ch); @@ -40,7 +44,12 @@ class Merchandise extends Controller curl_close($ch); $data['gems'] = $response; - + + if (preg_match('/<return>(\d+)<\/return>/', $response, $matches)) { + $data['gems'] = (int)$matches[1]; + } else { + echo 'Error extracting numeric value from XML response.'; + } $this->view('header/index', $data); $this->view('navbar/index');