diff --git a/app/controllers/Transaction.php b/app/controllers/Transaction.php new file mode 100644 index 0000000000000000000000000000000000000000..49ba7781eafe11aeeb92efc4598a9f3c57edb6a6 --- /dev/null +++ b/app/controllers/Transaction.php @@ -0,0 +1,70 @@ +<?php + +class Transaction extends Controller +{ + public function index() + { + $this->validateSession(); + + $data["pageTitle"] = "Transaction History"; + $data["user_id"] = $_SESSION['user_id']; + + // user's transaction + $baseUrl = 'http://soap:8080/service/transaction'; + + $soapRequest = '<x:Envelope + xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" + xmlns:ser="http://service.toco.org/"> + <x:Header/> + <x:Body> + <ser:getTransactions> + <user_id>' . $data["user_id"] . '</user_id> + </ser:getTransactions> + </x:Body> + </x:Envelope>'; + + $ch = curl_init($baseUrl); + 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: getTransactions', + 'X-api-key: toco_php' + ) + ); + + $response = curl_exec($ch); + + if (curl_errno($ch)) { + echo 'Curl error: ' . curl_error($ch); + } + + curl_close($ch); + $data['transaction'] = $response; + + if (preg_match_all('/<return>(.*?)<\/return>/', $response, $matches)) { + $data['transaction'] = []; + + foreach ($matches[1] as $match) { + $components = explode(', ', $match); + $transaction = [ + 'amount' => intval($components[0]), + 'action' => $components[1], + 'status' => $components[2] + ]; + $data['transaction'][] = $transaction; + } + } else { + echo 'Error extracting values from XML response.'; + } + + $this->view('header/index', $data); + $this->view('navbar/index'); + $this->view('transaction/index', $data); + $this->view('footer/index'); + } +} \ No newline at end of file diff --git a/app/views/exercise/index.php b/app/views/exercise/index.php index d950ad0ab6d4b7337db616950b0fe06b99131377..15d1ad14b255235b81a8c11b5c44638f9d259343 100644 --- a/app/views/exercise/index.php +++ b/app/views/exercise/index.php @@ -5,7 +5,7 @@ $selectedLanguageId = isset($_GET['language']) ? (int) $_GET['language'] : -1; <div class="exercise"> <div class="container exercise-container"> <h1 class="font-bold text-xl text-blue-purple-gradient"> - Exercises + Exercise </h1> <form id="search-filter-sort-form" action="" method="GET"> diff --git a/app/views/navbar/index.php b/app/views/navbar/index.php index 68277f0ee28d02f14ebf34499b223449e7e6c7c1..1b245b75b0433ce0d63ef130a2e24c9cb4b05b43 100644 --- a/app/views/navbar/index.php +++ b/app/views/navbar/index.php @@ -37,6 +37,7 @@ $profile_pic = isset($_SESSION['profile_pic']) ? $_SESSION['profile_pic'] : '/pu <li><a href="<?php echo $username ? '/learn' : '/login'; ?>" class="text-sm text-black">Learn</a></li> <li><a href="/exercise" class="text-sm text-black">Exercise</a></li> <li><a href="/merchandise" class="text-sm text-black">Merchandise</a></li> + <li><a href="/transaction" class="text-sm text-black">Transactions</a></li> </ul> </div> @@ -72,8 +73,9 @@ $profile_pic = isset($_SESSION['profile_pic']) ? $_SESSION['profile_pic'] : '/pu <div class="dropdown-menu"> <ul> <li><a href="<?php echo $username ? '/learn' : '/login'; ?>" class="text-sm text-black">Learn</a></li> - <li><a href="/#" class="text-sm text-black">Articles</a></li> - <li><a href="/#" class="text-sm text-black">Bootcamp</a></li> + <li><a href="/exercise" class="text-sm text-black">Exercise</a></li> + <li><a href="/merchandise" class="text-sm text-black">Merchandise</a></li> + <li><a href="/transaction" class="text-sm text-black">Transactions</a></li> <?php if ($username) : ?> <?php if ($is_admin) : ?> <li><a href="/admin" class="text-sm text-black">CMS</a></li> diff --git a/app/views/transaction/index.php b/app/views/transaction/index.php new file mode 100644 index 0000000000000000000000000000000000000000..cca13b6e0f424395aee6f02b9096b17d1addd2a0 --- /dev/null +++ b/app/views/transaction/index.php @@ -0,0 +1,27 @@ +<?php +?> + +<div class="transaction"> + <div class="container transaction-container"> + <h1 class="font-bold text-xl text-blue-purple-gradient"> + Transaction + </h1> + + <div class="card-container" id="transaction-container"> + <?php foreach ($data['transaction'] as $transaction): ?> + <div class="transaction-card"> + <div class="transaction-head"> + <div class="content"> + <h2 class="font-bold text-md"> + <?= $transaction['amount'] ?> + </h2> + <span class="font-reg text-xs"> + <?= $transaction['action'] ?> ● + <?= $transaction['status'] ?> + </span> + </div> + </div> + </div> + <?php endforeach; ?> + </div> +</div> \ No newline at end of file