Commit 7b04b010 authored by Wildan Dicky Alnatara's avatar Wildan Dicky Alnatara
Browse files
parents 3a161e5e 22bc5eda
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Error Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="../css/color-lib.css">
<link rel="stylesheet" type="text/css" href="../css/basic.css">
</head>
<body>
<div class="text-size-80 orange-text margin-20" align="center">
404
</div>
<div class="text-size-20" align="center">
Page Not Found
</div>
</body>
</html>
\ No newline at end of file
<?php
require ('../autoload.php');
require ('view.php');
class bookDetailController {
private $book_id;
private $book_detail;
private $reviews;
private $book_rating;
private $fetchsuccess = TRUE;
public function __construct($book_id) {
$this->book_id = $book_id;
$this->fetchBookDetails();
$this->fetchReviews();
$this->fetchRating();
}
public function showBookDetail() {
if ($this->fetchsuccess) {
/*if (isLogin()) {
$user_token = getTokenLogin();
$user = getUserInfo(getUserIDbyToken($user_token));*/
$params = [
'username' => 'ermaer',
//'username' => $user['username'],
'book_detail' => $this->book_detail,
'reviews' => $this->reviews,
'book_rating' => $this->book_rating
];
bookDetailViewer::viewBookDetail($params);
/*} else {
$login = '../login';
header('Location: '.$login);
}*/
} else {
include('../404.html');
}
}
private function fetchBookDetails() {
$conn = connect_to_mysql();
$sql_query = 'SELECT * FROM books WHERE id=' . $this->book_id;
$result = $conn->query($sql_query);
$this->book_detail = $result->fetch_assoc();
if ($this->book_detail == NULL) {
$this->fetchsuccess = FALSE;
}
$conn->close();
}
private function fetchReviews() {
$conn = connect_to_mysql();
$sql_query = 'SELECT username, profile_picture, komentar, rating
FROM (
SELECT order_id, book_id, user_id, komentar, rating
FROM (
SELECT Nomor_Order, book_id, user_id
FROM books INNER JOIN book_order ON books.ID=book_id
WHERE books.id='. $this->book_id .') as T1
INNER JOIN review ON Nomor_Order=order_id) as T2
INNER JOIN user ON user_id=user.id
';
$result = $conn->query($sql_query);
$conn->close();
if ($result != NULL) {
$this->reviews = [];
while ($row = $result->fetch_assoc())
$this->reviews[] = $row;
} else {
$this->reviews = NULL;
}
}
private function fetchRating() {
if ($this->reviews != NULL) {
$count = 0;
$sum = 0.0;
foreach ($this->reviews as $review) {
$sum += $review['rating'];
$count += 1;
}
$this->book_rating = round($sum/$count, 1);
} else {
$this->book_rating = (float) 0;
}
}
}
?>
\ No newline at end of file
<?php
require('controller.php');
if (isset($_GET['id'])) {
$book_id = $_GET['id'];
$bookDetail = new bookDetailController($book_id);
$bookDetail->showBookDetail();
} else {
include ('../404.html');
}
?>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Book Detail</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="../css/header.css">
<link rel="stylesheet" type="text/css" href="../css/color-lib.css">
<link rel="stylesheet" type="text/css" href="../css/basic.css">
<link rel="stylesheet" type="text/css" media="screen" href="../css/book_detail.css" />
<script type="text/javascript" src="../js/order-book.js"></script>
</head>
<body>
<div class="detail-container">
<div class="flex-container book-detail">
<div class="flex-1 book-desc">
<div class="orange-text text-size-50" >Judul Buku</div>
<div class="book-author">Pengarang</div>
<div class="text-size-20">Buku ini adalah dsajdjdsfjdsbvfbdhvbfd lorem ipsum dolor sit a</div>
</div>
<div class="add-flex-direction-column book-desc" align="center">
<div class="flex-1">
<img id="book-pict" src="../images/books_picture/4.jpg">
</div>
<div class="rating-pict">
<img class="rating" src="../svgIcon/star-filled.svg">
<img class="rating" src="../svgIcon/star-filled.svg">
<img class="rating" src="../svgIcon/star-filled.svg">
<img class="rating" src="../svgIcon/star-filled.svg">
<img class="rating" src="../svgIcon/star.svg">
</div>
<div class="text-size-20">5.0/5.0</div>
</div>
</div>
<div class="book-detail">
<div class="text-size-30">Order</div>
<div class="order-select">
<label>Jumlah: </label>
<select id="order-qty">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
<div align="right">
<button class="order-button light-blue" type="button" onclick="orderBook(1)">Order</button>
</div>
</div>
<div class="book-detail">
<div class="text-size-30">Reviews</div>
<div class="flex-review-tab">
<div>
<img id="profile_pict" src="../images/profiles_picture/baron44.jpg">
</div>
<div class="review-desc">
<div class="text-size-20">@heitayo</div>
<div class="text-size-20">Waw keren juga ya asique. lalal yeye llalala yayayay yeyeyeye. lalal yeye llalala yayayay yeyeyeye. lalal yeye llalala yayayay yeyeyeye</div>
</div>
<div class="add-flex-direction-column">
<img id="star-icon" src="../svgIcon/star-filled.svg">
<div class="text-size-20" align="center">5.0/5.0</div>
</div>
</div>
<div class="flex-review-tab">
<div class="picture">
<img id="profile_pict" src="../images/profiles_picture/baron44.jpg">
</div>
<div class="flex-1 book-desc">
<div class="text-size-20">@heitayo</div>
<div class="text-size-20">Waw keren juga ya asique. lalal</div>
</div>
<div class="add-flex-direction-column">
<img id="star-icon" src="../svgIcon/star-filled.svg">
<div class="rating-numeric text-size-20" align="center">5.0/5.0</div>
</div>
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
<?php
class bookDetailViewer {
public const STAR_IMG = 'star.svg';
public const STAR_FULL_IMG = 'star-filled.svg';
public static function viewBookDetail($params) {
$book_detail = $params['book_detail'];
$reviews = $params['reviews'];
$book_rating = $params['book_rating'];
echo Header::generateHead($book_detail['Judul'].' Book Detail', 'book_detail');
Body::outputInBody(
Header::headerLogin($params['username']).
Header::headerMenu(Header::BROWSE).
self::generateBookDetail($book_detail, $reviews, $book_rating).
self::showScript()
);
}
private function generateBookDetail($book_detail, $reviews, $book_rating) {
$str = '<body>
<div class="detail-container">'.
self::showBookDesc($book_detail, $book_rating).
self::showOrder().
self::showReviews($reviews).
'</div>
</body>';
return $str;
}
private function showBookDesc($book_detail, $book_rating) {
$str = '
<div class="flex-container book-detail">
<div class="flex-1 book-desc">
<div class="orange-text text-size-50" >'.$book_detail['Judul'].'</div>
<div class="book-author">'.$book_detail['Pengarang'].'</div>
<div class="text-size-20">'.$book_detail['Deskripsi'].'</div>
</div>
<div class="add-flex-direction-column book-desc" align="center">
<div class="flex-1">
<img id="book-pict" src="'.self::showPicture('books','../images/books_picture/4.jpg').'">
</div>
<div class="rating-pict">'.
self::drawRating($book_rating).
'</div>
<div class="text-size-20">'.$book_rating.'/5.0</div>
</div>
</div>';
return $str;
}
private function drawRating($book_rating) {
$count = floor($book_rating);
$str = '<div class="rating-pict">';
for ($i = 1; $i <= 5; $i++) {
if ($i <= $count) {
$star = self::STAR_FULL_IMG;
} else {
$star = self::STAR_IMG;
}
$img = '<img class="rating" src="../svgIcon/'. $star.'">';
$str = $str . $img;
}
return $str . '</div>';
}
private function showPicture($obj, $picSrc) {
if ($picSrc == NULL) {
return '../images/'. $obj .'_picture/default.jpg';
} else {
return $picSrc;
}
}
private function showOrder() {
$str = '
<div class="book-detail">
<div class="text-size-30">Order</div>
<div class="order-select">
<label>Jumlah: </label>
<select id="order-qty">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
<div align="right">
<button class="order-button light-blue" type="button" onclick="orderBook(1)">Order</button>
</div>
</div>';
return $str;
}
private function showReviews($reviews) {
$str = '
<div class="book-detail">
<div class="text-size-30">Reviews</div>'.
self::showPerReview($reviews).
'</div>';
return $str;
}
private function showPerReview($reviews) {
$str = '';
foreach ($reviews as $review) {
$str_review = '
<div class="flex-review-tab">
<div>
<img id="profile_pict" src="'.self::showPicture('profiles',$review['profile_picture']).'">
</div>
<div class="book-desc">
<div class="text-size-20">@'.$review['username'].'</div>
<div class="text-size-20">'.$review['komentar'].'</div>
</div>
<div class="add-flex-direction-column">
<img id="star-icon" src="../svgIcon/star-filled.svg">
<div class="text-size-20" align="center">'.round($review['rating'], 1).'/5.0</div>
</div>
</div>';
$str = $str . $str_review;
}
return $str;
}
private function showScript() {
return '<script type="text/javascript" src="../js/order-book.js"></script>';
}
}
?>
\ No newline at end of file
<?php
require ('../database/accessDB.php');
//check login state
//if (isLogin()) {
// $user_token = getTokenLogin();
// $user_id = getUserInfo(getUserIDbyToken($user_token))
$user_id = 1;
$book_id = $_GET['book_id'];
$quantity = $_GET['qty'];
//$orderstatus = createNewOrder($book_id, $user_id, $quantity);
$orderstatus = TRUE;
showOrderModal($orderstatus);
///}
function createNewOrder($book_id, $user_id, $quantity) {
$conn = connect_to_mysql();
if ($conn !== NULL) {
$currentdate = getCurrDate($conn);
$sql_query = 'INSERT INTO book_order (jumlah, tanggal, has_reviewed, book_id, user_id)
VALUES ("'. $quantity . '", "' . $currentdate . '", 0, "'
. $book_id . '", "' . $user_id . '")';
$result = $conn->query($sql_query);
$conn->close();
return TRUE;
} else {
return FALSE;
}
}
function getCurrDate($conn) {
$sql_query = 'SELECT CURDATE()';
$result = $conn->query($sql_query);
$date = $result->fetch_assoc();
return $date['CURDATE()'];
}
function showOrderModal($issuccess) {
echo '<script type="text/javascript">';
echo 'alert("Hore")';
echo '</script>';
}
?>
\ No newline at end of file
......@@ -89,6 +89,10 @@ a {
margin: 20px;
}
.margin-10 {
margin: 10px;
}
.text-size-10{
font-size: 10px !important;
}
......
.detail-container {
width: 80%;
margin: 50px auto;
margin-top: 30px;
margin-bottom: 30px;
position: relative;
font-family: 'Lucida Sans Regular';
}
.detail-container > div {
margin-block-end: 20px;
width: 100%;
}
.book-detail > div {
margin-right: 20px;
margin-block-end: 10px;
}
.book-desc > div {
width: 100%;
margin-block-end: 10px;
}
.book-author {
font-size: 25px;
}
#book-pict {
max-width: 180px;
max-height: 180px;
}
#profile_pict {
max-width: 100px;
max-height: 100px;
}
.flex-review-tab {
width: 100%;
display: flex;
}
.flex-review-tab > div {
margin-right: 20px;
}
.rating {
max-width: 30px;
}
#star-icon {
width: 70px;
}
.order-button {
border: none;
display: inline-block;
padding: 8px 16px;
vertical-align: middle;
text-align: center;
cursor: pointer;
white-space: nowrap;
background-color: #fff;
font-size: 15px;
}
.order-button:hover {background-color: #3e8e41}
.order-button:active {
box-shadow: 0 5px #666;
transform: translateY(4px);
}
.order_select {
font-size: 20px;
}
#order-qty {
width: 100px;
height: 30px;
margin-left: 10px;
}
\ No newline at end of file
.out_container{
background-color: deepskyblue;
width: 440px;
height:300px;
margin:100px auto;
height:auto;
margin:43px auto;
position: relative;
border-radius: 5px;
padding: 5px 10px;
padding: 30px 8px;
}
.in_container{
width: 440px;
height:250px;
height:auto;
position: relative;
margin-top: 5px;
padding-top: 12px;
padding-bottom: 22px;
background-image: url("../images/dot.png");
background-color: white;
background-position: center;
background-size: cover;
background-size: contain;
}
.content{
......@@ -33,13 +33,25 @@
letter-spacing: 3px;
}
.content form{
font: 1.1em sans-serif;
.content form {
font: 1.0em sans-serif;
text-align: center;
letter-spacing: 2px;
}
#dont_have_account{
input {
padding: 3px 3px;
}
input, textarea {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
resize: none;
font: 10pt sans-serif;
}
#account_existence{
margin-left: 10px;
text-align: left;
font-size: 0.9em;
......@@ -47,7 +59,7 @@
letter-spacing: 0px;
}
#login_submit{
#submit_button{
padding: 10px;
background-color: white;
border:solid orange;
......
table {
text-align: right;
}
td {
vertical-align:top;
padding: 3px 3px;
}
#validate_form, #validate_username, #validate_email {
float: left;
margin-right: 5px;
}
textarea {
width: 100%;
}
\ No newline at end of file
......@@ -160,7 +160,7 @@
$sql_query = 'INSERT into active_token(token,expiry_time, user_id) values ("'.$token.'","'.$expiry_time.'",'.$user_id.')';
// echo $sql_query;
$result = $conn->query($sql_query);
// if ($result == TRUE){
//if ($result == TRUE){
// echo "BERHASIL";
// } else{
// echo "GAGAL";
......
//AJAX Order Book
function orderBook(book_id) {
qty = document.getElementById('order-qty').value;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById('order-modal').innerHTML = this.response;
}
};
xmlhttp.open("GET", "../book_order/transaction.php?book_id=" + book_id + "&qty=" + qty, true);
xmlhttp.send();
}
\ No newline at end of file
//Match password and confirmed password
function validatePassword() {
var pass = document.forms["registrationform"]["password"].value;
var conf_pass = document.forms["registrationform"]["conf_password"].value;
if (pass != conf_pass) {
alert("Unmatched password and confirmed password");
return false;
} else {
return true;
}
}
function validateAccount($input) {
var checkTick = document.getElementById("validate_" + $input).innerHTML;
if (checkTick == "") {
alert($input + " is unavailable!");
return false;
} else {
return true;