diff --git a/.htaccess b/.htaccess index 44aee7036a119764acd354a844d07e714655a794..4eafe2474b7de81ea37eb8f1192d73d9913a42aa 100644 --- a/.htaccess +++ b/.htaccess @@ -29,8 +29,10 @@ RewriteRule ^api/signup$ src/signupServerSide.php RewriteRule ^api/filterPlaces$ src/filterPlaceServerSide.php RewriteRule ^api/get-places-location$ src/getLocationServerside.php RewriteRule ^api/get-places-category$ src/getCategoryServerside.php +RewriteRule ^api/add-destination$ src/addDestinationController.php RewriteCond %{REQUEST_METHOD} ^GET$ +RewriteRule ^api/profile$ src/profileController.php RewriteCond %{REQUEST_METHOD} ^PUT$ diff --git a/app/views/404.php b/app/views/404.php new file mode 100644 index 0000000000000000000000000000000000000000..907df84fbf4c1e696a5e42ce348b82cdfedce943 --- /dev/null +++ b/app/views/404.php @@ -0,0 +1,18 @@ +<!DOCTYPE html> +<html lang="en"> + +<head> + <meta charset="UTF-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <link rel="stylesheet" href="../../public/css/404.css"> + <title>404 Tidak Ditemukan</title> +</head> + +<body> + <h1>404</h1> + <p>Banyak jalan menuju Roma, tapi kali ini Roma-nya gak ada heheh.</p> + <p><a href="/">Balik ke halaman utama</a></p> +</body> + +</html> diff --git a/app/views/adddestination.php b/app/views/adddestination.php index 6158624741845147f1cc83d6678f28aecce173d2..64498cc7aaabda052a1e260d84c52415662fd69e 100644 --- a/app/views/adddestination.php +++ b/app/views/adddestination.php @@ -50,7 +50,7 @@ <h2>Deskripsi:</h2> <textarea name="description" id="description" cols="30" rows="10"></textarea> </div> - <button type="submit" name="submit" id="submit"><a href="pilih-wisata">Submit</a></button> + <button type="submit" name="submit" id="submit" onclick="uploadDestination(event)"><a href="pilih-wisata">Submit</a></button> </div> <script src="../../public/js/addtempatwisata.js"></script> </body> diff --git a/public/js/addtempatwisata.js b/public/js/addtempatwisata.js index 3714781fef7d940cbafc72c32dd1503fb15f232d..92d5420bc0b7583987abe8494b29a1186e2db7f7 100644 --- a/public/js/addtempatwisata.js +++ b/public/js/addtempatwisata.js @@ -1,10 +1,43 @@ -const submit = document.querySelector('.submit'); -const newdestinationbox = document.getElementById('listdestination') +const uploadDestination = async (e) => { + e.preventDefault(); -submit.addEventListener('click', AddNew); + const namaTempat = document.getElementById('placename').value; + const lokasi = document.getElementById('location').value; + const harga = document.getElementById('price').value; + const kontak = document.getElementById('contact').value; + const jamBuka = document.getElementById('openhour').value; + const jamTutup = document.getElementById('closehour').value; + const deskripsi = document.getElementById('description').value; + const tipe = document.getElementById('type').value; + const email = document.getElementById('email').value; + const website = document.getElementById('website').value; -function AddNew() { - const destinationboxbaru = document.createElement('div'); - destinationboxbaru.classList.add('destinationbox'); - newdestinationbox.body.appendChild(destinationboxbaru); -} \ No newline at end of file + const formData = new FormData(); + formData.append('image', document.getElementById('upload').files[0]); + formData.append('nama_tempat', namaTempat); + formData.append('lokasi', lokasi); + formData.append('harga', harga); + formData.append('kontak', kontak); + formData.append('jam_buka', jamBuka); + formData.append('jam_tutup', jamTutup); + formData.append('deskripsi', deskripsi); + formData.append('tipe', tipe); + formData.append('email', email); + formData.append('website', website); + + try { + const response = await fetch('/api/add-destination', { + method: 'POST', + body: formData + }); + + if (response.ok) { + const jsonRes = await response.json(); + console.log(jsonRes); + } else { + console.error('Error:', response.status, response.statusText); + } + } catch (error) { + console.error('Error:', error); + } +}; diff --git a/public/js/profile.js b/public/js/profile.js new file mode 100644 index 0000000000000000000000000000000000000000..ab5ae7101676687b8266355f3a10f96158573296 --- /dev/null +++ b/public/js/profile.js @@ -0,0 +1,29 @@ +const updateInfo = async() => { + const usernameElement = document.getElementById("profile-username"); + const firstNameElement = document.getElementById("profile-firstname"); + const lastNameElement = document.getElementById("profile-lastname"); + const emailElement = document.getElementById("profile-email"); + const phoneElement = document.getElementById("profile-phone"); + + if (username) { + + const lib = new Lib(); + const res = await lib.get('/api/profile'); + console.log(res); + const jsonRes = JSON.parse(res); + + datas = jsonRes["data"]; + usernameElement.textContent = datas["Username"]; + firstNameElement.textContent = datas["FirstName"]; + lastNameElement.textContent = datas["LastName"]; + emailElement.textContent = datas["Email"]; + phoneElement.textContent = datas["PhoneNumber"]; + } else { + // User is not logged in, show "login first" message + const loginMessageElement = document.createElement("p"); + loginMessageElement.textContent = "Please login first to view your information."; + document.querySelector(".infouser").appendChild(loginMessageElement); + } +} + +window.onload = updateInfo; \ No newline at end of file diff --git a/src/addDestinationController.php b/src/addDestinationController.php new file mode 100644 index 0000000000000000000000000000000000000000..26c89a6c689cd2adfbd61de0375493aef444d17c --- /dev/null +++ b/src/addDestinationController.php @@ -0,0 +1,71 @@ +<?php +if ($_SERVER["REQUEST_METHOD"] == "POST") { + $imageFile = $_FILES['image']; + $imageName = basename($imageFile['name']); + + $namaTempat = $_POST['nama_tempat']; + $lokasi = $_POST['lokasi']; + $harga = $_POST['harga']; + $kontak = $_POST['kontak']; + $jamBuka = $_POST['jam_buka']; + $jamTutup = $_POST['jam_tutup']; + $deskripsi = $_POST['deskripsi']; + $tipe = $_POST['tipe']; + $email = $_POST['email']; + $website = $_POST['website']; + + $targetDir = "../db/PlaceImg/"; + + + $host = "172.21.0.3"; + $port = "3306"; + $dbusername = "root"; // Change this to your database username + $dbpassword = "1234"; // Change this to your database password + $dbname = "travelution_database"; // Change this to your database name + + try { + // Create a PDO connection + $pdo = new PDO("mysql:host=$host;port=$port;dbname=$dbname", $dbusername, $dbpassword); + + // Set PDO to throw exceptions on errors + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + $sql = "SELECT count(PlaceID) AS count FROM Place"; + $stmt = $pdo->prepare($sql); + $stmt->execute(); + + $countIdPlace = $stmt->fetch((PDO::FETCH_ASSOC))["count"]; + $idPlace = $countIdPlace + 1; + + $sql = "INSERT INTO Place + (PlaceID, PlaceName, PlaceLocation, PlaceDescription, PlaceType, PlacePrice, PlaceOpenTime, PlaceCloseTime, PlaceContact, PlaceEmail, PlaceWebsite) + VALUES ($idPlace, '$namaTempat', '$lokasi', '$deskripsi', '$tipe', $harga, '$jamBuka', '$jamTutup', '$kontak', '$email', '$website')"; + $stmt = $pdo->prepare($sql); + $stmt->execute(); + + $fileName = $idPlace . '_1' . '.' . strtolower(pathinfo($imageName, PATHINFO_EXTENSION)); + + $sql = "INSERT INTO PlaceImage () VALUES ($idPlace, '$fileName') "; + $stmt = $pdo->prepare($sql); + $stmt->execute(); + + $targetFile = $targetDir . $fileName; + + if (move_uploaded_file($_FILES["image"]["tmp_name"], $targetFile)) { + $data = ['message' => 'Destination added successfully']; + echo json_encode($data); + } else { + $data = ['message' => 'Failed to add destination']; + echo json_encode($data); + } + + + } catch (PDOException $e) { + $data = ['message' => $e]; + echo json_encode($data); + } + +} else { + $data = ['message' => 'Access denied']; + echo json_encode($data); +} \ No newline at end of file diff --git a/src/profileController.php b/src/profileController.php new file mode 100644 index 0000000000000000000000000000000000000000..de71bbceb5c5067ce91bdc0763840c5adcd7a6c9 --- /dev/null +++ b/src/profileController.php @@ -0,0 +1,39 @@ +<?php +session_start(); +if ($_SERVER["REQUEST_METHOD"] == "GET") { + if (!isset($_SESSION["Username"])) { + $res = ['message' => $_SESSION]; + echo json_encode($res); + } else { + $host = "172.21.0.3"; + $port = "3306"; + $dbusername = "root"; + $dbpassword = "1234"; + $dbname = "travelution_database"; + + try { + $pdo = new PDO("mysql:host=$host;port=$port;dbname=$dbname", $dbusername, $dbpassword); + + // Set PDO to throw exceptions on errors + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $username = $_SESSION["Username"]; + // Example query + $sql = "SELECT Username, FirstName, LastName, Email, PhoneNumber FROM Account WHERE Username = '$username'"; // Change this to your table name + $stmt = $pdo->prepare($sql); + $stmt->execute(); + + $data = $stmt->fetch(PDO::FETCH_ASSOC); + + $res = ['data' => $data, 'message' => 'Information obtained']; + echo json_encode($res); + + + } catch (PDOException $e) { + $res = ['message' => $e]; + echo json_encode($res); + } + } +} else { + $res = ['message' => 'Access denied']; + echo json_encode($res); +} \ No newline at end of file