diff --git a/src/admin/gym/application/index.php b/src/admin/gym/application/index.php
index 7f28c352b4a788468649e61b511f0154f200cce4..7017ef39843af646df7ee458ea32a86a8b8171f9 100644
--- a/src/admin/gym/application/index.php
+++ b/src/admin/gym/application/index.php
@@ -24,6 +24,8 @@ AuthMiddleware::getInstance()->secureRoute(true);
const urlParams = new URLSearchParams(window.location.search);
const gymId = urlParams.get("gym_id");
const username = urlParams.get("trainer_username");
+ const soapkey = <?php echo json_encode($_ENV['AUTHORIZATION']) ?>;
+ const soapurl = <?php echo json_encode($_ENV['SOAP_URL']) ?>;
</script>
<?php
echo NavbarAdmin();
@@ -73,7 +75,7 @@ AuthMiddleware::getInstance()->secureRoute(true);
<script src="/public/javascript/gym/trainer_card.js"></script>
<script src="/public/javascript/gym/application.js"></script>
<script>
- getApplication(gymId, username);
+ getApplication(username, gymId);
</script>
</body>
diff --git a/src/admin/gym/trainer/index.php b/src/admin/gym/trainer/index.php
index 5bbafa60564b6bc015ebf2e65ff651df8da347be..36e31c2b4352d1de658651d58882c6dd6fab3519 100644
--- a/src/admin/gym/trainer/index.php
+++ b/src/admin/gym/trainer/index.php
@@ -24,6 +24,8 @@ AuthMiddleware::getInstance()->secureRoute(true);
const urlParams = new URLSearchParams(window.location.search);
const gymId = urlParams.get("gym_id");
const username = urlParams.get("trainer_username");
+ const soapkey = <?php echo json_encode($_ENV['AUTHORIZATION']) ?>;
+ const soapurl = <?php echo json_encode($_ENV['SOAP_URL']) ?>;
</script>
<?php
echo NavbarAdmin();
diff --git a/src/public/javascript/gym/application.js b/src/public/javascript/gym/application.js
index f597e91bd8f16aa60fae3eb25694f102b83db232..71b51be6d8f91b373385dac0471142372cf7e494 100644
--- a/src/public/javascript/gym/application.js
+++ b/src/public/javascript/gym/application.js
@@ -32,36 +32,21 @@ const response = `<?xml version="1.0"?>
</S:Body>
</S:Envelope>`
-
-function modifyGymApplicationList(data) {
- const gymApplicationList = document.getElementById("gym-application-list");
- gymApplicationList.innerHTML = "";
- if (data.length == 0) {
- gymApplicationList.innerHTML = `
- <div class="space"></div>
- <div class="gym-card-text"> No Application found </div>
- `;
- }
- data.forEach((trainer) => {
- gymApplicationList.innerHTML += ApplicationCard(trainer);
- });
-}
-
function getGymApplication(gymId) {
- modifyGymApplicationList(filterApplication(parseXmlResponse(response), 0));
- showGymTrainers(filterApplication(parseXmlResponse(response), 1));
+ // modifyGymApplicationList(filterApplication(parseXmlResponseList(response), 0));
+ // showGymTrainers(filterApplication(parseXmlResponseList(response), 1));
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (this.readyState === 4) {
if (this.status === 200) {
- const applications = parseXmlResponse(this.responseText);
- alert("trainer : " + applications);
+ const applications = parseXmlResponseList(this.responseText);
+ // alert("trainer : " + applications);
modifyGymApplicationList(filterApplication(applications, 0));
showGymTrainers(filterApplication(applications, 1));
} else {
const xml = this.responseXML;
- alert("error status : " + this.status + " error text : " + xml);
+ console.log("error status : " + this.status + " error text : " + xml);
}
}
};
@@ -75,16 +60,42 @@ function getGymApplication(gymId) {
</Envelope>`;
// alert("soapbody : " + soapBody);
xhr.open("POST", soapurl, true);
+ // no need to to make options method for cors because we use soap
+ // xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
+ // xhr.setRequestHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
xhr.setRequestHeader("Content-Type", "text/xml");
xhr.setRequestHeader("Authorization", soapkey);
xhr.send(soapBody);
}
-
function getApplication(username, gymId) {
- // alert("get application with username: " + username + " and gym id: " + gymId);
- modifyApplication(trainer);
+ const xhr = new XMLHttpRequest();
+ xhr.onreadystatechange = function () {
+ if (this.readyState === 4) {
+ if (this.status === 200) {
+ const applications = parseXmlResponseList(this.responseText);
+ // alert("trainer : " + applications);
+ modifyApplication(applications[0]);
+ } else {
+ const xml = this.responseXML;
+ console.log("error status : " + this.status + " error text : " + xml);
+ }
+ }
+ };
+ const soapBody = `<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
+ <Body>
+ <getAplication xmlns="http://service.gymtracker.com/">
+ <username xmlns="">${username}</username>
+ <gym_id xmlns="">${gymId}</gym_id>
+ </getAplication>
+ </Body>
+ </Envelope>`;
+
+ xhr.open("POST", soapurl, true);
+ xhr.setRequestHeader("Content-Type", "text/xml");
+ xhr.setRequestHeader("Authorization", soapkey);
+ xhr.send(soapBody);
}
function acceptApplication(username, gymId) {
@@ -126,6 +137,20 @@ function rejectApplication(username, gymId) {
xhr.send();
}
+function modifyGymApplicationList(data) {
+ const gymApplicationList = document.getElementById("gym-application-list");
+ gymApplicationList.innerHTML = "";
+ if (data.length == 0) {
+ gymApplicationList.innerHTML = `
+ <div class="space"></div>
+ <div class="gym-card-text"> No Application found </div>
+ `;
+ }
+ data.forEach((trainer) => {
+ gymApplicationList.innerHTML += ApplicationCard(trainer);
+ });
+}
+
function modifyApplication(trainer) {
const gymApplicationList = document.getElementById("application-trainer");
gymApplicationList.innerHTML = `
@@ -155,17 +180,17 @@ function modifyApplication(trainer) {
`
}
-function parseXmlResponse(xmlString) {
+function parseXmlResponseList(xmlString) {
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xmlString, "text/xml");
const returnElement = xmlDoc.getElementsByTagName("return")[0];
const returnText = returnElement.textContent;
// Split the return text into an array of trainer strings
- const trainerStrings = returnText.split("\n").filter(str => str.trim() !== "");
+ const trainerStr = returnText.split("\n").filter(str => str.trim() !== "");
// Parse each trainer string into a trainer object
- const trainers = trainerStrings.map(trainerString => {
+ const trainers = trainerStr.map(trainerString => {
const values = trainerString.replace("[", "").replace("]", "").split(", ");
return {
username: values[0],