diff --git a/api/exercise/submit.php b/api/exercise/submit.php index a4f34b95ec5214ed69d27d5551bf6d5d9300c7d8..deaabedea069678c09d7a678ce83411bb5d90e2a 100644 --- a/api/exercise/submit.php +++ b/api/exercise/submit.php @@ -19,7 +19,7 @@ function submitQuiz($exerciseId, $exerciseName, $selectedOptions, $userId, $isDo $ch = curl_init(); // curl_setopt($ch, CURLOPT_URL, "http://express:5000/exercise/result/" . $exerciseId); - curl_setopt($ch, CURLOPT_URL, "http://192.168.0.11:5000/exercise/result/" . $exerciseId); + curl_setopt($ch, CURLOPT_URL, "http://172.20.10.2:5000/exercise/result/" . $exerciseId); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt( @@ -61,7 +61,7 @@ function submitQuiz($exerciseId, $exerciseName, $selectedOptions, $userId, $isDo // rest add progress $ch = curl_init(); // curl_setopt($ch, CURLOPT_URL, "http://express:5000/progress/create"); - curl_setopt($ch, CURLOPT_URL, "http://192.168.0.11:5000/progress/create"); + curl_setopt($ch, CURLOPT_URL, "http://172.20.10.2:5000/progress/create"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt( diff --git a/api/merch/buy.php b/api/merch/buy.php index 20059286a0e2090aad9fc07010cbddb51e3de730..911721c1578de0f818fc76872bcf9e6e12994b9e 100644 --- a/api/merch/buy.php +++ b/api/merch/buy.php @@ -4,7 +4,7 @@ function buyItem($merchId, $userId, $email) // rest buy merchandise $ch = curl_init(); // curl_setopt($ch, CURLOPT_URL, "http://express:5000/merch/buy/" . $merchId); - curl_setopt($ch, CURLOPT_URL, "http://192.168.0.11:5000/merch/buy/" . $merchId); + curl_setopt($ch, CURLOPT_URL, "http://172.20.10.2:5000/merch/buy/" . $merchId); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt( diff --git a/api/merch/redeem.php b/api/merch/redeem.php index 039c07f32db2590a2f940d997646c1c7336daf9b..2b2881f4eee509bfadfc6a2957b2722c99dc3f62 100644 --- a/api/merch/redeem.php +++ b/api/merch/redeem.php @@ -35,10 +35,14 @@ function redeem($voucher, $userId) } -if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['redeemVoucher'])) { +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['redeemVoucher']) && isset($_POST['voucher'])) { $userId = $_POST['userId']; $voucher = $_POST['voucher']; + if (empty($voucher)) { + header('Location: ../../merchandise'); + } + $isSuccess = redeem($voucher, $userId); header('Location: ../../merchandise'); diff --git a/app/controllers/Exercise.php b/app/controllers/Exercise.php index a842071a397b42ea0ec6b041eded57fa8776a4d3..ca992ecdbc921c337039a75d6f01b7086fa9af5b 100644 --- a/app/controllers/Exercise.php +++ b/app/controllers/Exercise.php @@ -12,7 +12,7 @@ class Exercise extends Controller // get exercises // $baseUrl = 'http://express:5000/exercise'; - $baseUrl = 'http://192.168.0.11:5000/exercise'; + $baseUrl = 'http://172.20.10.2:5000/exercise'; $ch = curl_init($baseUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); @@ -22,7 +22,7 @@ class Exercise extends Controller // progress // $baseUrl = 'http://express:5000/progress/user/' . $data["user_id"]; - $baseUrl = 'http://192.168.0.11:5000/progress/user/' . $data["user_id"]; + $baseUrl = 'http://172.20.10.2:5000/progress/user/' . $data["user_id"]; $ch = curl_init($baseUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); @@ -49,7 +49,7 @@ class Exercise extends Controller // selected exercise // $baseUrl = 'http://express:5000/exercise'; - $baseUrl = 'http://192.168.0.11:5000/exercise'; + $baseUrl = 'http://172.20.10.2:5000/exercise'; $ch = curl_init($baseUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); @@ -66,7 +66,7 @@ class Exercise extends Controller // progress // $baseUrl = 'http://express:5000/progress/user/' . $data["user_id"]; - $baseUrl = 'http://192.168.0.11:5000/progress/user/' . $data["user_id"]; + $baseUrl = 'http://172.20.10.2:5000/progress/user/' . $data["user_id"]; $ch = curl_init($baseUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); @@ -83,7 +83,7 @@ class Exercise extends Controller // questions // $baseUrl = 'http://express:5000/question/' . $data["exercise_id"]; - $baseUrl = 'http://192.168.0.11:5000/question/' . $data["exercise_id"]; + $baseUrl = 'http://172.20.10.2:5000/question/' . $data["exercise_id"]; $ch = curl_init($baseUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); @@ -94,7 +94,7 @@ class Exercise extends Controller // options foreach ($data["questions"] as &$question) { // $baseUrl = 'http://express:5000/option/' . $question["question_id"]; - $baseUrl = 'http://192.168.0.11:5000/option/' . $question["question_id"]; + $baseUrl = 'http://172.20.10.2:5000/option/' . $question["question_id"]; $ch = curl_init($baseUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); @@ -187,7 +187,7 @@ class Exercise extends Controller { if (isset($exerciseId) && !empty($exerciseId)) { // $baseUrl = 'http://express:5000/exercise/validate/' . $exerciseId; - $baseUrl = 'http://192.168.0.11:5000/exercise/validate/' . $exerciseId; + $baseUrl = 'http://172.20.10.2:5000/exercise/validate/' . $exerciseId; $ch = curl_init($baseUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); diff --git a/app/views/confirmation/index.php b/app/views/confirmation/index.php index a401c7abbe9c13abdec8e2745a9f2ce6b21a5969..902c1d313f8c3dbede47eca93c47c12266f3e554 100644 --- a/app/views/confirmation/index.php +++ b/app/views/confirmation/index.php @@ -11,7 +11,7 @@ <? endif; ?> <div class="conf-items"> <div class="merch-item" - style="background-image: url('http://192.168.0.11:5000/image/?filename=<?= $data['merch']['image'] ?>');"> + style="background-image: url('http://172.20.10.2:5000/image/?filename=<?= $data['merch']['image'] ?>');"> <div class="merch-image"></div> <div class="merch-details"> <div class="merch-name"> diff --git a/app/views/merchandise/index.php b/app/views/merchandise/index.php index 49ae797d2f1d7c3ba0c038a356b385ed59c3dd96..519a3463a096f67ea35c84324aaec232db5e01da 100644 --- a/app/views/merchandise/index.php +++ b/app/views/merchandise/index.php @@ -31,7 +31,7 @@ <div class="merchandise-items"> <? foreach ($data['merch'] as $merch): ?> <div class="merch-item" - style="background-image: url('http://192.168.0.11:5000/image/?filename=<?= $merch['image'] ?>');"> + style="background-image: url('http://172.20.10.2:5000/image/?filename=<?= $merch['image'] ?>');"> <div class="merch-image"></div> <div class="merch-details"> <div class="merch-name"> @@ -45,10 +45,30 @@ </div> <div> <form action="../../../api/merch/buy.php" method="post"> + <!-- Modal --> + <div class="confirm-container close-modal-trigger"> + <div class="confirm-card"> + <div class="confirm-content"> + <h2 class="text-md text-red font-reg">Are you sure?</h2> + <p class="text-sm text-black font-reg">Please re-check your purchase before buying</p> + </div> + <div class="modal-button-container"> + <button type="button" + class="secondary-btn font-reg text-sm close-modal-trigger" data-index="0"> + Cancel + </button> + <button class="primary-btn font-reg text-sm" id="logout-btn" name="buyMerch" + type="submit"> + Buy + </button> + </div> + </div> + </div> + <input type="hidden" name="merchId" value="<?= $merch['merchandise_id'] ?>"> <input type="hidden" name="userId" value="<?= $data['user_id'] ?>"> <input type="hidden" name="email" value="<?= $data['email'] ?>"> - <button class="buy-button" type="submit" name="buyMerch">Buy</button> + <button class="buy-button modal-trigger" type="button" name="buyMerch">Buy</button> </form> </div> </div> @@ -56,4 +76,5 @@ <? endforeach; ?> </div> </div> -</div> \ No newline at end of file +</div> +<script src="../../../public/js/modalIter.js"></script> \ No newline at end of file diff --git a/app/views/question/index.php b/app/views/question/index.php index 5cdec55a1c790c758a42252713aba8ca1df87369..bad1736e882f8a39c3ed6ac8c5584d745d39829e 100644 --- a/app/views/question/index.php +++ b/app/views/question/index.php @@ -4,6 +4,24 @@ <?= $data['currentExercise']['exe_name'] ?> </h1> <form method="post" action="../../../api/exercise/submit.php"> + <!-- Modal --> + <div class="confirm-container close-modal-trigger"> + <div class="confirm-card"> + <div class="confirm-content"> + <h2 class="text-md text-red font-reg">Are you sure?</h2> + <p class="text-sm text-black font-reg">Please re-check your answers before submitting</p> + </div> + <div class="modal-button-container"> + <button type="button" class="secondary-btn font-reg text-sm close-modal-trigger"> + Cancel + </button> + <button class="primary-btn font-reg text-sm" id="logout-btn" name="submitQuiz" type="submit"> + Submit + </button> + </div> + </div> + </div> + <div class="question-content"> <?php $questionNumber = 1; ?> <?php foreach ($data["questions"] as $question): ?> @@ -38,7 +56,7 @@ <input type="hidden" name="userId" value="<?= $data["user_id"] ?>"> <input type="hidden" name="isDone" value="<?= $data["isDone"] ?>"> <div class="button-container"> - <button class="primary-button submit-button" type="submit" name="submitQuiz" onclick="submitFormAndRedirect()">Submit</button> + <button class="primary-button submit-button modal-trigger" type="button" name="submitQuiz">Submit</button> </div> </div> </form> @@ -65,4 +83,5 @@ <input type="hidden" name="selectedOptions" value="${listString}"> `; } -</script> \ No newline at end of file +</script> +<script src="../../../public/js/modal.js"></script> \ No newline at end of file diff --git a/public/js/modalIter.js b/public/js/modalIter.js new file mode 100644 index 0000000000000000000000000000000000000000..6bcc2f342a8cad4a3228d0b4315529a6cf19cbcd --- /dev/null +++ b/public/js/modalIter.js @@ -0,0 +1,14 @@ +const modalTriggers = document.querySelectorAll(".modal-trigger"); + +modalTriggers.forEach((trigger, index) => { + const modalBox = trigger.parentNode.querySelector(".confirm-container"); + const closeBtn = modalBox.querySelector(".close-modal-trigger"); + + trigger.addEventListener("click", () => { + modalBox.classList.add("active"); + }); + + closeBtn.addEventListener("click", () => { + modalBox.classList.remove("active"); + }); +}); \ No newline at end of file