diff --git a/app/controllers/PremiumController.php b/app/controllers/PremiumController.php index 8ed22cfb9a123baab524cc23a1f098b06c12ea50..0984910bc9e0b5784491e2d1563e2cfcb9fe3b16 100644 --- a/app/controllers/PremiumController.php +++ b/app/controllers/PremiumController.php @@ -5,7 +5,8 @@ exit; } public function lists($params){ - + $premium_middleware = $this->middleware("PremiumMiddleware"); + $premium_middleware->isPremium(); $components = explode("=",$params); $page_number = $components[1]; // Fetch data courses diff --git a/app/controllers/ProfileController.php b/app/controllers/ProfileController.php index 7bc03c5917b2f07afa73aafac5d80ee35fdf5265..34eb37655a82fd46e9a797b03230129f8f0a3e13 100644 --- a/app/controllers/ProfileController.php +++ b/app/controllers/ProfileController.php @@ -17,6 +17,7 @@ $headers = array( "Content-Type: text/xml;charset=\"utf-8\"", 'Content-Length: ' .strlen($request_param), + "X-API-KEY: PHPApp" ); $url = $_ENV["SOAP_URL"]; $ch = curl_init(); diff --git a/app/middlewares/PremiumMiddleware.php b/app/middlewares/PremiumMiddleware.php new file mode 100644 index 0000000000000000000000000000000000000000..516cd2dfcb5348a7a6cc162230fa56e35ebaadee --- /dev/null +++ b/app/middlewares/PremiumMiddleware.php @@ -0,0 +1,44 @@ +<?php + require_once("LoginMiddleware.php"); + class PremiumMiddleware{ + private $database; + + public function __construct(){ + $this->database = Database::instance(); + } + + public function isPremium(){ + $user_middleware = new LoginMiddleware(); + $user_middleware->hasLoggedIn(); + $user_id = $_SESSION["user_id"]; + $request_param = '<?xml version="1.0" encoding="utf-8" ?> + <soap:Envelope + xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" + xmlns:tns="http://service.LMS.com/"> + <soap:Body> + <tns:getPremiumStatus> + <user_id>' . $user_id . '</user_id> + </tns:getPremiumStatus> + </soap:Body> + </soap:Envelope>'; + $headers = array( + "X-API-KEY: PHPApp", + "Content-Type: text/xml;charset=\"utf-8\"", + ); + $url = $_ENV["SOAP_URL"]; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_POSTFIELDS, $request_param); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + $response = curl_exec($ch); + curl_close($ch); + $temp = str_replace('<?xml version=\'1.0\' encoding=\'UTF-8\'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:getPremiumStatusResponse xmlns:ns2="http://service.LMS.com/"><return>',"",$response); + $temp2 = str_replace('</return></ns2:getPremiumStatusResponse></S:Body></S:Envelope>',"",$temp); + if($temp2 !== "ACCEPTED"){ + header("Location: /notfound"); + } + } + } +?> \ No newline at end of file diff --git a/app/views/navbar/navbar.php b/app/views/navbar/navbar.php index 6f215fe532a640963f346937404b737a65cc8bd5..f18b886a5c3ffbaea1dc86314d285eed28fa5d60 100644 --- a/app/views/navbar/navbar.php +++ b/app/views/navbar/navbar.php @@ -28,7 +28,39 @@ if($user["user_role"] === "ADMIN"){ $admin = true; } + $user_id = $_SESSION["user_id"]; + $request_param = '<?xml version="1.0" encoding="utf-8" ?> + <soap:Envelope + xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" + xmlns:tns="http://service.LMS.com/"> + <soap:Body> + <tns:getPremiumStatus> + <user_id>' . $user_id . '</user_id> + </tns:getPremiumStatus> + </soap:Body> + </soap:Envelope>'; + $headers = array( + "X-API-KEY: PHPApp", + "Content-Type: text/xml;charset=\"utf-8\"", + ); + $url = $_ENV["SOAP_URL"]; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_POSTFIELDS, $request_param); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + $response = curl_exec($ch); + curl_close($ch); + $temp = str_replace('<?xml version=\'1.0\' encoding=\'UTF-8\'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:getPremiumStatusResponse xmlns:ns2="http://service.LMS.com/"><return>',"",$response); + $temp2 = str_replace('</return></ns2:getPremiumStatusResponse></S:Body></S:Envelope>',"",$temp); + if($temp2 !== "ACCEPTED"){ + $premium = false; + }else{ + $premium = true; + } } + ?> <!-- PROFILE PICTURE, NAME, ROLE --> <?php @@ -106,8 +138,23 @@ </a> <span class="tooltip">Search</span> </li> - <!-- LOGOUT BUTTON --> - + <!-- PREMIUM BUTTON --> + <?php + if($premium){ + ?> + <li> + <a href=<?php echo ("/premium") ?>> + <i> + <svg fill="white" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"> + <path d="M6 22h15v-2H6.012C5.55 19.988 5 19.805 5 19s.55-.988 1.012-1H21V4c0-1.103-.897-2-2-2H6c-1.206 0-3 .799-3 3v14c0 2.201 1.794 3 3 3zM5 8V5c0-.805.55-.988 1-1h13v12H5V8z"/> + <path d="M8 6h9v2H8z"/> + </svg> + </i> + <span class="link-name"><?php echo ("Premium courses") ?></span> + </a> + <span class="tooltip"><?php echo ("Premium courses") ?></span> + </li> + <?php } ?> <?php }?> <?php if(session_status() === PHP_SESSION_NONE){ diff --git a/app/views/premium/detailModule.php b/app/views/premium/detailModule.php index 9c8fdd5990108780c3514000328ba02b3a73ef7b..74b477ffd3fcdbf54b5d1e402ca75a0fb84e596c 100644 --- a/app/views/premium/detailModule.php +++ b/app/views/premium/detailModule.php @@ -68,7 +68,7 @@ $materials = $data["materials"]; foreach ($materials as $material) { - $path = "http://localhost:8000/".$material["material_path"] ; + $path = "http://localhost:8000/file/".$material["material_path"] ; echo" <div class='accordion'> <div class='accordion-content' style='display: flex; justify-content: space-between;'> @@ -78,7 +78,7 @@ <i class='fa-solid fa-plus'></i> </header> "; - if ($material['source_type'] == "pdf"){ + if ($material['source_type'] == "PDF"){ echo " <div class='description'> <span>$material[description]<span> diff --git a/app/views/profile/index.php b/app/views/profile/index.php index 43f5d2a0f890835de5e4160312b6562869c3ed53..6f0d8dd202469ad3b61658bf08635402fa7d1e89 100644 --- a/app/views/profile/index.php +++ b/app/views/profile/index.php @@ -139,7 +139,7 @@ </div> <div> <?php - if($thisUser["user_role"] === "STUDENT" &&($data['premium_status'] === "NOT PREMIUM" || $data["premium_status" === "REJECTED"])){ + if($thisUser["user_role"] === "STUDENT" && ($data['premium_status'] !== "WAITING" && $data["premium_status"] !== "ACCEPTED")){ ?> <button id="subscribe-button" type="button" class="edit-button" ><a href="/api/subscribe/subscribe.php">Subscribe</a></button> <?php } ?>