diff --git a/Dockerfile b/Dockerfile index afb87c0d27c23ee9577552e5d26de5f448d21c8b..989e8b93cd2e0642374645d6792c2c242c7cf9c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,10 @@ WORKDIR /var/www/html # PHP extension and Apache configuration RUN docker-php-ext-install mysqli RUN a2enmod rewrite -RUN apt-get -y update ; \ - apt-get -y upgrade ; \ - apt-get -y install ffmpeg ; \ \ No newline at end of file +RUN apt-get update \ + && apt-get install -y \ + libxml2-dev \ + && rm -rf /var/lib/apt/lists/* + +# Enable SOAP extension +RUN docker-php-ext-install soap \ No newline at end of file diff --git a/app/clients/SoapConsumer.php b/app/clients/SoapConsumer.php new file mode 100644 index 0000000000000000000000000000000000000000..02be5ae158084331e367c4581afd2e3160f08b17 --- /dev/null +++ b/app/clients/SoapConsumer.php @@ -0,0 +1,188 @@ +<? + +class SoapConsumer { + private SoapClient $subscriptionClient; + private SoapClient $requestClient; + private $apiKey; + + public function __construct() { + // Set SOAP client options + $options = [ + 'trace' => 1, // Allows you to trace request and response + 'exceptions' => true, // Enables exceptions for HTTP errors + "encoding" => "UTF-8", + "stream_context" => stream_context_create([ + 'http' => [ + 'ApiKey' => $_ENV['SOAP_API_KEY'] + ] + ]) + ]; + + $this->subscriptionClient = new SoapClient($_ENV['SOAP_URL'] . "subscription?wsdl", $options); + $this->requestClient = new SoapClient($_ENV['SOAP_URL'] . "request?wsdl", $options); + + $this->apiKey = $_ENV['SOAP_API_KEY']; + + $headerBody = new SoapVar($this->apiKey, XSD_STRING, null, null, 'ApiKey', 'http://ws.soap.com/'); + $header = new SoapHeader('http://ws.soap.com/', 'ApiKey', $headerBody); + + $this->subscriptionClient->__setSoapHeaders(array( + new SoapHeader( + 'http://ws.soap.com/', + 'ApiKey', + $this->apiKey, + false + ), + new SoapHeader( + 'ns2', + 'ApiKey', + $this->apiKey, + false + ), + new SoapHeader( + 'ns1', + 'ApiKey', + $this->apiKey, + false + ), + $header + )); + + $this->subscriptionClient->__setSoapHeaders($header); + + $this->requestClient->__setSoapHeaders( + new SoapHeader( + 'http://ws.soap.com/', + 'ApiKey', + $this->apiKey, + false + ) + ); + + } + + public function makeRequest($requestBy, $to, $requesterEmail) { + $response = $this->requestClient->MakeRequest([ + 'RequestBy' => $requestBy, + 'To' => $to, + 'RequesterEmail' => $requesterEmail, + ]); + + + + return $response; + + // $apiKey = $this->apiKey; + + // // Construct SOAP request XML + // $requestXml = <<<XML + // <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> + // <Header> + // <ApiKey xmlns="http://ws.soap.com/">$apiKey</ApiKey> + // </Header> + // <Body> + // <MakeRequest xmlns="http://ws.soap.com/"> + // <RequestBy xmlns="">$requestBy</RequestBy> + // <To xmlns="">$to</To> + // <RequesterEmail xmlns="">$requesterEmail</RequesterEmail> + // </MakeRequest> + // </Body> + // </Envelope> + // XML; + + // $endpoint = $_ENV['SOAP_URL'] . "request"; + + // $headers = [ + // 'Content-Type: text/xml; charset=utf-8', + // 'Content-Length: ' . strlen($requestXml), + // 'SOAPAction: http://ws.soap.com/MakeRequest', + // ]; + + // $ch = curl_init($endpoint); + // curl_setopt($ch, CURLOPT_POST, 1); + // curl_setopt($ch, CURLOPT_POSTFIELDS, $requestXml); + // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + // // Send SOAP request + // $responseXml = curl_exec($ch); + // curl_close($ch); + + // return $responseXml; + } + + public function getSubscriptionOf($requester) { + + // Define the SOAP request parameters + $requestParams = array( + 'ApiKey' => $this->apiKey, + 'GetSubscriptionOf' => array( + 'Username' => $requester, + ), + ); + + $res = $this->subscriptionClient->__soapCall('GetSubscriptionOf', array($requestParams)); + + // Process the result + var_dump($res); + + + // $response = $this->subscriptionClient->GetSubscriptionOf([ + // 'Username' => $requester, + // ]); + + // echo htmlentities( $this->subscriptionClient->__getLastRequest()); + + // return $response; + // $apiKey = $this->apiKey; + + // // Construct SOAP request XML + // $requestXml = <<<XML + // <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> + // <Header> + // <ApiKey xmlns="http://ws.soap.com/">$apiKey</ApiKey> + // </Header> + // <Body> + // <GetSubscriptionOf xmlns="http://ws.soap.com/"> + // <Username xmlns="">$requester</Username> + // </GetSubscriptionOf> + // </Body> + // </Envelope> + // XML; + + // $endpoint = $_ENV['SOAP_URL'] . "subscription"; + + // $headers = [ + // 'Content-Type: text/xml; charset=utf-8', + // 'Content-Length: ' . strlen($requestXml), + // 'SOAPAction: http://ws.soap.com/GetSubscriptionOf', + // ]; + + // $ch = curl_init($endpoint); + // curl_setopt($ch, CURLOPT_POST, 1); + // curl_setopt($ch, CURLOPT_POSTFIELDS, $requestXml); + // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + // // Send SOAP request + // $dataString = curl_exec($ch); + // curl_close($ch); + + // // Use regular expression to extract usernames + // preg_match_all('/\+07:00(.*?)true/', $dataString, $matches); + + // // Extract the usernames from the matches array + // $usernames = $matches[1]; + // for ($i = 0; $i < count($usernames); $i++) { + // // if the username started with 2023 + // if (substr($usernames[$i], 0, 4) == "2023") { + // $usernames[$i] = substr($usernames[$i], 29); + // } + // } + + // // Print the result + // echo "usernames = [" . implode(', ', $usernames) . "]\n"; + // return $dataString; + } +} +?> \ No newline at end of file diff --git a/app/controllers/TestController.php b/app/controllers/TestController.php new file mode 100644 index 0000000000000000000000000000000000000000..b70418e2e39f4b691a51d61ca2bb106776bf16ed --- /dev/null +++ b/app/controllers/TestController.php @@ -0,0 +1,26 @@ + +<?php + +class TestController extends Controller implements ControllerInterface +{ + private SoapConsumer $soap; + + public function __construct() { + require_once __DIR__ . '/../clients/SOAPConsumer.php'; + $this->soap = new SoapConsumer(); + } + + public function index() { + + } + + public function req() + { + echo $this->soap->makeRequest('addin', 'yusuf', 'test@gmail.com'); + } + + public function sub() + { + echo $this->soap->getSubscriptionOf('a'); + } +} \ No newline at end of file diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index 9b17add2bf6a357845ac04ba36358e1584b1b9d3..7898e9191dccc61c8340aa4831c6caf12387b851 100644 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -27,7 +27,10 @@ class UserController extends Controller implements ControllerInterface switch ($_SERVER['REQUEST_METHOD']) { case 'GET': // show the login page - $mySubscriptionView = $this->view('user', 'MySubscriptionView'); + $data = [ + 'username' => $_SESSION['username'] + ]; + $mySubscriptionView = $this->view('user', 'MySubscriptionView', $data); $mySubscriptionView->render(); break; default: diff --git a/app/main/Main.php b/app/main/Main.php index 4f2c4d80e8e470c593b68e38a0862c371403e2db..86d5ac852542d19e2ed7e5cf5827f8522216afb4 100644 --- a/app/main/Main.php +++ b/app/main/Main.php @@ -12,13 +12,14 @@ class Main { $controllerPart = $url[0] ?? null; $controllerPart = ucfirst($controllerPart); - + if (isset($controllerPart) && file_exists(__DIR__ . '/../controllers/' . $controllerPart . 'Controller.php')) { require_once __DIR__ . '/../controllers/' . $controllerPart . 'Controller.php'; $controllerClass = $controllerPart . 'Controller'; $this->controller = new $controllerClass(); }else{ - header('Location: /book/'); + require_once __DIR__ . '/../controllers/NotFoundController.php'; + $this->controller = new NotFoundController(); } unset($url[0]); diff --git a/app/pages/user/MySubscriptionPage.php b/app/pages/user/MySubscriptionPage.php index 3a26f6c79d7ca497a080884fbd1dbdec220e1900..1621d8b0ecb60ee9786d6abd8d699fa8a142d2f2 100644 --- a/app/pages/user/MySubscriptionPage.php +++ b/app/pages/user/MySubscriptionPage.php @@ -27,7 +27,6 @@ <table border="1" class="styled-table"> <thead> <tr> - <th>Id</th> <th>Curator Name</th> <th>Action</th> </tr> @@ -38,7 +37,6 @@ foreach ($authors as $author) { echo "<tr>"; - echo "<td>" . $author['author_id'] . "</td>"; echo "<td>" . $author['full_name'] . "</td>"; echo '<td><a href="/author/update/' . $author['author_id'] .'">Pending/Details</a></td>'; echo "</tr>"; diff --git a/db/seeding/book.py b/db/seeding/book.py index 04099757017b96bdf0c17029cf2d48c3313a9046..984c630659ce4550171dcb391b572cc246671ca1 100644 --- a/db/seeding/book.py +++ b/db/seeding/book.py @@ -22,8 +22,8 @@ with open('books.csv', newline='', encoding='utf-8') as csvfile: reader = csv.DictReader(csvfile) for row in reader: books.append({ - 'title': row['original_title'], - 'description': f"Buku {row['original_title']} karya {row['authors']} ini menceritakan tentang {row['original_title']}.", + 'title': row['title'], + 'description': f"Buku {row['title']} karya {row['authors']} ini menceritakan tentang {row['title']}.", 'book_image': row['small_image_url'] })