diff --git a/Dockerfile b/Dockerfile index ac9d06b7a432032270f7e2a4c3c3bad65a740061..8df1f70833f2ca4cc8c308c9010b57879afee844 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,5 +6,7 @@ RUN apt-get update RUN apt-get install -y libpq-dev \ && docker-php-ext-install pgsql pdo pdo_pgsql - +EXPOSE 8080 +EXPOSE 80 +EXPOSE 5432 RUN service apache2 restart \ No newline at end of file diff --git a/api/subscribe/subscribe.php b/api/subscribe/subscribe.php new file mode 100644 index 0000000000000000000000000000000000000000..8c5240eb42822d242791ac444a35d7a2098c2e7d --- /dev/null +++ b/api/subscribe/subscribe.php @@ -0,0 +1,40 @@ +<?php + if(session_status() === PHP_SESSION_NONE){ + session_start(); + } + if(!isset($_SESSION["user_id"])){ + header("Location: /login"); + } + $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:subscribe> + <user_id>' . $user_id . '</user_id> + </tns:subscribe> + </soap:Body> + </soap:Envelope>'; + $headers = array( + "Content-Type: text/xml;charset=\"utf-8\"", + ); + $url = "http://host.docker.internal:8080/subscription"; + $ch = curl_init(); + var_dump($ch); + // var_dump(curl_error($ch)); + 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); + if($response === FALSE){ + $_SESSION["error"] = "Subscription request has failed!"; + }else{ + $_SESSION["success"] = "Request has been submitted!"; + } + header("Location: /profile"); + +?> \ No newline at end of file diff --git a/app/views/profile/index.php b/app/views/profile/index.php index d6aff009e70d95d0f5cd13afd835ac688eaca07f..5321d46ef6e609c0550b84f54b56f3816d189d20 100644 --- a/app/views/profile/index.php +++ b/app/views/profile/index.php @@ -7,6 +7,8 @@ <title>Profile Update</title> <link href="../../public/css/profile/profile.css" rel="stylesheet"> <script src="../../public/js/profile.js" defer></script> + <script src="../../public/js/subscribe.js"></script> + </head> <body> @@ -20,6 +22,18 @@ include __DIR__ . '/../navbar/navbar.php'; $thisUser = $user->getUserById($_SESSION["user_id"]); } + if(isset($_SESSION["success"])){ + $message = $_SESSION["success"]; + $type = "success"; + include(__DIR__."/../components/alertBox.php"); + unset($_SESSION["success"]); + } + if(isset($_SESSION["error"])){ + $message = $_SESSION["error"]; + $type = "error"; + include(__DIR__."/../components/alertBox.php"); + unset($_SESSION["error"]); + } ?> <section class='popup-section'> <div class='popup-overlay'></div> @@ -114,6 +128,9 @@ <div class='profile-toggle-fixed'> <button type='button' onclick='toggle()' class='edit-button' id='profile-button'>Edit</button> </div> + <div> + <button id="subscribe-button" type="button" class="edit-button" ><a href="/api/subscribe/subscribe.php">Subscribe</a></button> + </div> </form> </div> </section> diff --git a/public/js/subscribe.js b/public/js/subscribe.js new file mode 100644 index 0000000000000000000000000000000000000000..c7b02fbcc4942ea1849852f800e0d0a4b08ebb00 --- /dev/null +++ b/public/js/subscribe.js @@ -0,0 +1,29 @@ +const SOAP_URL = "http://localhost:8080/subscription"; + +const subscribe = async () => { + let user_id = 2; + const syntax = ` + <?xml vresion="1.0" encoding="utf-8" ?> + <soapenv:Envelope + xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" + xmlns:tns="http://service.LMS.com/"> + <soapenv:Body> + <tns:subscribe> + <user_id>${user_id}</user_id> + </tns:subscribe> + </soapenv:Body> +</soapenv:Envelope>` + + const xhr = new XMLHttpRequest(); + xhr.open("POST",SOAP_URL, true); + xhr.setRequestHeader("Content-Type","text/xml"); + xhr.onload = function(){ + console.log(this) + if(this.status === 200){ + console.log(this.responseText) + }else{ + console.log(this); + } + } + xhr.send(syntax) +};