Commit e8a75c30 authored by arung-agamani's avatar arung-agamani
Browse files

Initial commit = Udah kelar haha

parent 38262b7c
Pipeline #28521 canceled with stages
<?php
include "../utils/redirect.php";
include "../components/navbar.php";
include "../components/head.php";
$isAdmin = false;
if (!isset($_COOKIE["accessToken"])) {
RoutingUtils\redirect("login.php");
}
if ($_COOKIE["accessToken"] === "ADMIN") {
$isAdmin = true;
} else {
RoutingUtils\redirect('index.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add Coklat - Admin</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Tangerine">
<link rel="stylesheet" href="../assets/css/global.css">
</head>
<body>
<?php
echo createNavbar($isAdmin);
?>
<div class="form-wrapper">
<h1>Tambah Coklat Baru</h1>
<form action="Javascript:getFormCoklatData()" id="input-coklat-form" enctype="multipart/form-data">
<div class="form-input-group">
<div class="form-input-group-col-text">
<label for="nama">Nama</label>
</div>
<div class="form-input-group-col">
<input type="text" name="nama" id="input-nama">
</div>
</div>
<div class="form-input-group">
<div class="form-input-group-col-text">
<label for="harga">Harga</label>
</div>
<div class="form-input-group-col">
<input type="text" name="harga" id="input-harga">
</div>
</div>
<div class="form-input-group">
<div class="form-input-group-col-text">
<label for="deskripsi">Deskripsi</label>
</div>
<div class="form-input-group-col">
<textarea name="deskripsi" id="input-deskripsi" rows="10"></textarea>
</div>
</div>
<div class="form-input-group">
<div class="form-input-group-col-text">
<label for="sold">Terjual</label>
</div>
<div class="form-input-group-col">
<input type="text" name="sold" id="input-sold">
</div>
</div>
<div class="form-input-group">
<div class="form-input-group-col-text">
<label for="remaining">Sisa</label>
</div>
<div class="form-input-group-col">
<input type="text" name="remaining" id="input-remaining">
</div>
</div>
<div class="form-input-group">
<div class="form-input-group-col-text">
<label for="imageUrl">Gambar</label>
</div>
<div class="form-input-group-col">
<input type="file" name="image" id="input-image">
</div>
</div>
<div class="form-input-group">
<button type="submit">Tambah Coklat</button>
</div>
</form>
</div>
</form>
<script>
function callXHR(url, method, data) {
return new Promise((resolve, reject) => {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
resolve(JSON.parse(xhr.response));
} else if (xhr.readyState === 4 && xhr.status !== 200) {
reject(xhr.response);
}
}
xhr.open(method, url);
xhr.send(data);
})
}
</script>
<script>
function getFormCoklatData() {
var coklatForm = document.getElementById('input-coklat-form');
var formData = new FormData(coklatForm);
callXHR('/api/addCoklat.php', 'POST', formData)
.then(res => {
console.log(res);
alert("Berhasil menambahkan coklat baru!");
window.location = "/";
})
.catch(err => {
console.log(err)
alert("Gagal menambahkan coklat baru.");
});
}
</script>
</body>
</html>
\ No newline at end of file
<?php
include "../utils/db.php";
$user_sql = "CREATE TABLE User (
username varchar(32) not null primary key,
email varchar(50) not null,
password varchar(32) not null,
isAdmin int(1) not null);
";
$chocolate_sql = "CREATE TABLE Coklat (
id int(5) unsigned auto_increment primary key,
nama varchar(32) not null,
deskripsi text not null,
harga int not null,
sold int not null,
remaining int not null,
imageUrl text
);";
$access_sql = "CREATE TABLE UserSession (
id int(5) unsigned auto_increment primary key,
username varchar(32) not null,
accessToken varchar(100) not null,
expiryDate timestamp not null
);";
$transaction_sql = "CREATE TABLE Transaction (
id int(5) unsigned auto_increment primary key,
coklatId int(5) unsigned not null,
username varchar(32) not null,
amount int not null,
transactionTime timestamp not null,
address text not null,
foreign key (coklatId) references coklat(id),
foreign key (username) references user(username)
);";
$delete_chocolate = "DROP TABLE Coklat;";
$delete_user = "DROP TABLE User";
$delete_trans = "DROP TABLE Transaction";
if (querySQL($transaction_sql)) {
echo "Success creating table UserSession";
} else {
echo "Something went wrong";
}
<?php
include "../utils/db.php";
createDatabase("willywangky");
<?php
include "../utils/db.php";
if (isset($_POST["nama"]) && isset($_POST["deskripsi"]) && isset($_POST["harga"]) && isset($_POST["sold"]) && isset($_POST["remaining"]) && isset($_FILES["image"])) {
$target_dir = "../assets/img/";
$target_file = $target_dir . basename($_FILES["image"]["name"]);
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
$nama = $_POST["nama"];
$deskripsi = $_POST["deskripsi"];
$harga = intval($_POST["harga"]);
$sold = intval($_POST["sold"]);
$remaining = intval($_POST["remaining"]);
$check = getimagesize($_FILES["image"]["tmp_name"]);
if ($check !== false) {
move_uploaded_file($_FILES["image"]["tmp_name"], $target_file);
if (addCoklat($nama, $deskripsi, $harga, $sold, $remaining, $target_file)) {
http_response_code(200);
header("content-type: application/json");
echo ('{"message" : "success", "status": 200}');
} else {
http_response_code(500);
}
} else {
http_response_code(400);
echo "Bad request: No image";
}
} else {
http_response_code(401);
echo "Bad request";
}
<?php
include "../utils/db.php";
if (isset($_COOKIE["userId"]) && isset($_POST["coklatId"]) && isset($_POST["amount"]) && isset($_POST["address"])) {
$nama = $_COOKIE["userId"];
$coklat = $_POST["coklatId"];
$amount = intval($_POST["amount"]);
$alamat = $_POST["address"];
if (addTransaction($nama, $coklat, $amount, $alamat)) {
http_response_code(200);
header("content-type: application/json");
echo ('{"message" : "success", "status": 200}');
} else {
http_response_code(500);
}
} else {
http_response_code(401);
echo "Bad request";
}
<?php
include "../utils/db.php";
// include "../utils/returnType.php";
if ($_SERVER["REQUEST_METHOD"] == "GET") {
if (isset($_COOKIE["userId"]) && isset($_GET["coklatId"])) {
try {
$nama = $_COOKIE["userId"];
$coklat = $_GET["coklatId"];
$data = getChocolate($coklat)[0];
$obj = new ReturnObject("success", $data);
http_response_code(200);
header("content-type: application/json");
echo json_encode($obj);
} catch (\Throwable $th) {
http_response_code(500);
}
} else if (isset($_COOKIE["userId"]) && isset($_GET["page"])) {
if (!isset($_GET["sq"])) {
$page = intval($_GET["page"]);
$data = getAllCoklatPaginated($page, 10);
http_response_code(200);
header("content-type: application/json");
echo json_encode($data);
} else {
$page = intval($_GET["page"]);
$data = getSearchCoklatPaginated($page, 10, $_GET["sq"]);
http_response_code(200);
header("content-type: application/json");
echo json_encode($data);
}
} else {
http_response_code(401);
echo "Bad request";
}
} else if ($_SERVER["REQUEST_METHOD"] == "POST") {
if ($_COOKIE["accessToken"] == "ADMIN") {
if (isset($_POST["action"]) && isset($_POST["data"]) && isset($_POST["id"])) {
if ($_POST["action"] == "add") {
$id = $_POST["id"];
$add = $_POST["data"];
if (addCoklatStock($id, $add)) {
http_response_code(200);
echo "OK";
} else {
http_response_code(500);
echo "Something went oof-ed";
}
} else {
http_response_code(400);
echo "Bad request";
}
}
} else {
http_response_code(401);
echo "Unauthorized";
}
}
<?php
include "../utils/db.php";
if (isset($_COOKIE["userId"])) {
$transaksi = getUserTransactions($_COOKIE["userId"]);
http_response_code(200);
header("Content-Type: application/json");
echo json_encode($transaksi);
} else {
http_response_code(401);
echo "Please login";
}
<?php
include "../utils/db.php";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST["username"]) && isset($_POST["email"])) {
$username = $_POST["username"];
$email = $_POST["email"];
$isUnique = checkUserUniqueness($username, $email);
if ($isUnique) {
http_response_code(200);
header("Content-Type: application/json");
echo 'OK';
} else {
http_response_code(400);
echo "Not unique";
}
} else {
http_response_code(400);
echo "Bad request";
}
} else {
http_response_code(400);
echo "Bad request";
}
body {
margin: 0;
}
.nav-wrapper {
width: 100vw;
padding-left: 5px;
background-color: chocolate;
display: flex;
flex-direction: row;
font-family: "Roboto", Open Sans;
}
.nav-wrapper .nav-item {
padding: 5px;
padding-top: 2px;
padding-bottom: 2px;
min-width: 100px;
border-right: 1px solid rgb(138, 72, 26);
}
.nav-item .nav-link {
text-align: center;
width: 100%;
color: rgb(255, 225, 203);
}
.nav-search {
height: 100%;
display: flex;
}
.nav-grow {
display: flex;
flex-grow: 1;
}
.nav-search > input {
margin-top: 5px;
margin-bottom: 5px;
padding-left: 1rem;
width: 100%;
background-color: rgb(245, 211, 187);
}
.nav-item:hover {
background-color: rgb(221, 147, 94);
cursor: pointer;
}
.nav-link a {
text-decoration: none;
color: rgb(255, 225, 203);
}
main {
margin: 2rem;
}
main .heading {
font-size: 3rem;
margin-bottom: 2rem;
font-family: "Roboto", serif;
font-weight: 200;
}
.catalogue {
display: flex;
flex-direction: row;
flex-wrap: wrap;
font-family: "Roboto", serif;
}
.card-item {
background-color: white;
border: 1px solid rgb(235, 200, 155);
border-radius: 10px;
display: flex;
flex-direction: column;
text-align: center;
align-items: center;
margin-left: auto;
margin-right: auto;
margin-bottom: 10px;
}
.card-item:hover {
cursor: pointer;
}
.card-item .card-image {
width: 200px;
height: 200px;
border-radius: 10px 10px 0px 0px;
background-size: cover;
}
.card-item .card-content {
width: 100%;
margin: 5px;
margin-bottom: 0px;
border-radius: 0px 0px 10px 10px;
padding-top: 5px;
padding-bottom: 5px;
display: flex;
flex-direction: column;
background-color: rgb(235, 225, 217);
}
.card-content .card-content-heading {
font-size: 1.5rem;
font-weight: bold;
}
.container {
margin-left: 5rem;
margin-right: 5rem;
}
.item-wrapper {
padding: 1rem;
display: flex;
flex-direction: row;
}
.item-wrapper .item-image {
margin-right: 1rem;
margin-top: 2rem;
}
.item-wrapper .item-image img {
width: 200px;
height: auto;
}
.item-wrapper .item-contents {
font-family: "Roboto", serif;
}
.item-action {
width: 100%;
display: flex;
justify-content: flex-end;
}
.button-primary {
min-width: 100px;
max-width: 200px;
padding: 10px;
font-size: 1.5rem;
font-family: "Roboto", serif;
background-color: chocolate;
color: white;
border: 3px solid rgb(82, 38, 8);
text-align: center;
margin-left: 1rem;
}
.button-primary:hover {
cursor: pointer;
}
.order-count-info {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.order-count-control {
display: flex;
flex-direction: row;
}
.order-control-button {
display: flex;
border: 1px solid black;
text-align: center;
justify-content: center;
align-items: center;
height: 50px;
width: 50px;
}
.order-control-amount {
min-width: 100px;
text-align: center;
border-top: 1px solid black;
border-bottom: 1px solid black;
display: flex;
justify-content: center;
align-items: center;
}
.order-count,
.order-info {
display: flex;
flex-direction: column;
}
.order-count > span,
.order-info > span {
margin-bottom: 1rem;
}
.order-info {
margin-left: 2rem;
}
.order-address {
display: flex;
flex-direction: column;
margin-top: 2rem;
margin-bottom: 2rem;
}
.order-address > span {
margin-bottom: 1rem;
}
.d-none {
display: none;
}
#table-transaksi {
width: 100%;
}
#table-transaksi,
#table-transaksi th,
#table-transaksi td {
border: 1px solid black;
}
.form-wrapper {
margin: auto;
padding: 2rem;
padding-left: 5rem;
padding-right: 5rem;
font-family: Roboto;
}
.form-input-group {
display: flex;
flex-direction: column;
}
.form-input-group,
.form-input-group-col,
.form-input-group-col > input,
.form-input-group-col > textarea {
width: 100%;
}
.form-input-group-col > input {
padding: 10px;
padding-left: 0px;
padding-right: 0px;
margin-right: 10px;
}
.form-input-group {
margin-bottom: 1rem;
}
.pagination-control {
display: flex;
flex-direction: row;
justify-content: center;
margin-bottom: 1rem;
font-size: 1.5rem;
}
.pagination-control-button,
.pagination-control-amount {
padding: 10px;
margin: 10px;
}
.glow-green {
box-shadow: 0px 0px 10px 5px green;
transition: box-shadow 0.25s;
}
.glow-red {
box-shadow: 0px 0px 10px 5px red;
transition: box-shadow 0.25s;
}
body {
margin: 0;
background-image: url(../img/login-bg.jpg);
background-size: cover;
background-position: center;
overflow-x: hidden;
}
.wrapper {
height: 100vh;
width: 100vw;
display: flex;