Commit cd2e8206 authored by Ranindya Paramitha's avatar Ranindya Paramitha
Browse files
parents ed43e794 8a340399
......@@ -3,11 +3,11 @@
class fileProcessing {
public const PROFILE_DEFAULT = 'default.jpg';
public static function isExistBookImage (string $name): bool {
public static function isExistBookImage ($name): bool {
return file_exists('../images/books_picture/'.$name.'.jpg');
}
public static function isExistProfileImage (string $name): bool {
public static function isExistProfileImage ($name): bool {
return file_exists('../uploads/'.$name.'.jpg');
}
......
......@@ -79,7 +79,11 @@ class Header {
</a>
</div>
<div class="left-right-border orange-background flex-1 ">
<span class="text-size-40">H</span>ISTORY
<a href="'.self::URL_HISTORY.'">
<div>
<span class="text-size-40">H</span>ISTORY
</div>
</a>
</div>
<div class="flex-1 ">
<a href="'.self::URL_PROFILE.'">
......@@ -95,7 +99,11 @@ class Header {
return '
<div class="flex-container-menu">
<div class="orange-background flex-1 ">
<span class="text-size-40">B</span>ROWSE
<a href="'.self::URL_BROWSE.'">
<div>
<span class="text-size-40">B</span>ROWSE
</div>
</a>
</div>
<div class="left-right-border flex-1 ">
<a href="'.self::URL_HISTORY.'">
......@@ -132,7 +140,11 @@ class Header {
</a>
</div>
<div class="orange-background flex-1 ">
<span class="text-size-40">P</span>ROFILE
<a href="'.self::URL_PROFILE.'">
<div>
<span class="text-size-40">P</span>ROFILE
</div>
</a>
</div>
</div>';
}
......
......@@ -3,14 +3,16 @@
require ('view.php');
class bookDetailController {
private $username;
private $book_id;
private $book_detail;
private $reviews;
private $book_rating;
private $fetchsuccess = TRUE;
public function __construct($book_id) {
public function __construct($book_id, $username) {
$this->book_id = $book_id;
$this->username = $username;
$this->fetchBookDetails();
$this->fetchReviews();
$this->fetchRating();
......@@ -18,21 +20,13 @@
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);
}*/
$params = [
'username' => $this->username,
'book_detail' => $this->book_detail,
'reviews' => $this->reviews,
'book_rating' => $this->book_rating
];
bookDetailViewer::viewBookDetail($params);
} else {
include('../404.html');
}
......
<?php
require('controller.php');
if (isset($_GET['id'])) {
$book_id = $_GET['id'];
$bookDetail = new bookDetailController($book_id);
$bookDetail->showBookDetail();
if (isLogin()) {
$user_token = getTokenLogin();
$user = getUserInfo(getUserIDbyToken($user_token));
if (isset($_GET['id'])) {
$book_id = $_GET['id'];
$bookDetail = new bookDetailController($book_id, $user['username']);
$bookDetail->showBookDetail();
} else {
include ('../404.html');
}
} else {
include ('../404.html');
}
$login = '../login';
header('Location: '.$login);
}
?>
\ No newline at end of file
......@@ -34,15 +34,13 @@
}
.order-button {
width: 100px;
display: inline-block;
padding: 8px 16px;
vertical-align: middle;
text-align: center;
cursor: pointer;
white-space: nowrap;
background-color: #fff;
font-size: 20px;
float: right;
margin-bottom: 100px;
padding: 5px 30px;
font-size: 25px;
background-color: dodgerblue;
color: white;
border-radius: 4px;
}
.order-button:hover {background-color: #3e8e41}
......
......@@ -4,11 +4,12 @@
font-size: 28px;
font-family: 'Nunito', sans-serif;
margin-block-end: 40px;
padding: 5px;
}
.fivestar-rating {
max-width: 60px;
max-height: 60px;
max-width: 90px;
max-height: 90px;
cursor: pointer;
}
......
......@@ -205,4 +205,20 @@
function getTokenLogin() {
return $_COOKIE["login"];
}
function selectFromWhere($attr, $table, $wherecondition) {
$conn = connect_to_mysql();
$listofattr = [];
if ($conn !== NULL){
$sql_query = "SELECT ". $attr ." FROM ". $table ." WHERE ". $wherecondition;
$result = $conn->query($sql_query);
if ($result != NULL){
while ($row = $result->fetch_assoc()) {
$listofattr[] = $row[$attr];
}
}
$conn->close();
}
return $listofattr;
}
?>
\ No newline at end of file
......@@ -12,6 +12,7 @@ function ratingClick(starValue) {
}
}
document.getElementById("rating-given").value = starValue;
document.getElementById("output").innerHTML = document.getElementById("rating-given").value;
}
function hoverStar(starValue) {
......
......@@ -8,7 +8,7 @@ function viewProfile (array $params) {
<div class="flex-profile-header">
<div class="flex-1"></div>
<div class="flex-2">
<img class="profile-photo margin-20" src="uploads/'.$params['profile_picture'].'">
<img class="profile-photo margin-20" src="/uploads/'.$params['profile_picture'].'">
<div id="username" class="text-size-50">'.$params['name'].'</div>
</div>
<a class="flex-container add-flex-end-justify flex-1 " href="edit_profile">
......
......@@ -9,10 +9,6 @@
$address = $_POST["address"];
$phonenumber= $_POST["phonenumber"];
# Parameter hashnya apaan
#$hashedpassword = password_hash($password, PASSWORD_DEFAULT);
$hashedpassword = $password;
insertNewUser($name, $username, $hashedpassword, $email, $address, $phonenumber);
insertNewUser($name, $username, $password, $email, $address, $phonenumber);
login();
?>
\ No newline at end of file
......@@ -38,7 +38,7 @@
$form= '<h1>REGISTER</h1>
<form id="registrationform" action="registration/register.php" onsubmit="return submitValidation()" method = "POST">
'. getTable().
'<p id="account_existence"><a href="../login/login_form.php">Already have an account?</a></p>
'<p id="account_existence"><a href="../login">Already have an account?</a></p>
<input id="submit_button" type="submit" value="REGISTER">
</form>
';
......
<?php
require ('../autoload.php');
require ('view.php');
class reviewController {
private $username;
private $order_id;
private $ordered_book;
private $fetchsuccess = TRUE;
public function __construct($order_id, $username) {
$this->order_id = $order_id;
$this->username = $username;
$this->fetchOrderDetail();
}
public function showReviewForm() {
if ($this->fetchsuccess) {
$params = [
'username' => $this->username,
'ordered_book' => $this->ordered_book
];
reviewFormViewer::viewReviewForm($params);
} else {
include('../404.html');
}
}
private function fetchOrderDetail() {
$conn = connect_to_mysql();
$sql_query = 'SELECT Judul, Pengarang, Nomor_Order as order_id, book_id
FROM (SELECT Nomor_Order, book_id FROM book_order WHERE Nomor_Order='. $this->order_id .
') as T1 INNER JOIN books ON id=book_id';
$result = $conn->query($sql_query);
$this->ordered_book = $result->fetch_assoc();
if ($this->ordered_book == NULL) {
$this->fetchsuccess = FALSE;
}
$conn->close();
}
public static function validateOrderHistory($order_id, $user_id) {
$listOfHistoryID = selectFromWhere('Nomor_Order', 'book_order', 'user_id='.$user_id.' AND has_reviewed=0');
foreach ($listOfHistoryID as $hist) {
if ($hist == $order_id) {
return TRUE;
}
}
return FALSE;
}
}
?>
\ No newline at end of file
<?php
include('view.php');
require ('controller.php');
//Login Check
if (isLogin()) {
$user_token = getTokenLogin();
$user = getUserInfo(getUserIDbyToken($user_token));
//if (isset($_GET['id'])) {
//$order_id = $_GET['id'];
$order_id = 301; //dummy
if (reviewController::validateOrderHistory($order_id, $user['ID'])) {
$review = new reviewController($order_id, $user['username']);
$review->showReviewForm();
} else {
include ('../404.html');
}
//} else {
// include ('../404.html');
//}
} else {
$login = '../login';
header('Location: '.$login);
}
?>
\ No newline at end of file
<?php
include_once ('../database/accessDB.php');
$rating = $_POST['rating-value'];
$comment = $_POST['comment'];
$book_id = $_POST['book-id'];
$order_id = $_POST['order-id'];
$insertsuccess = insertReview($order_id, $rating, $comment);
include('../history');
function insertReview($order_id, $rating, $comment) {
$conn = connect_to_mysql();
$sql_query = 'INSERT INTO review(order_id, komentar, rating)
VALUES ('. $order_id .', "'.$comment.'", '.$rating.')';
$result = $conn->query($sql_query);
$querystatus = setOrderReviewed($conn, $order_id);
$conn->close();
return $querystatus;
}
function setOrderReviewed($conn, $order_id) {
$sql_query = 'UPDATE book_order SET has_reviewed=1 WHERE Nomor_Order='.$order_id;
$result = $conn->query($sql_query);
return $result != NULL;
}
?>
\ 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 Review</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/review.css" />
<script type="text/javascript" src="../javascript/review-book.js"></script>
</head>
<body>
<div class="detail-container add-nunito-font">
<div class="flex-container book-detail">
<div class="flex-1">
<div class="book-title orange-text"><b>Judul Buku</b></div>
<div class="book-author"><b>Pengarang</b></div>
</div>
<div class="add-flex-direction-column" id="rightbar-pic" align="center">
<div class="flex-1">
<img id="book-pict" src="../images/books_picture/4.jpg">
</div>
</div>
</div>
<form action="submit_review.php" method="POST">
<div class="book-detail">
<div class="head-title">Add Rating</div>
<div class="order-select">
<div class="rating-pict">
<input type="image" id="star1" class="fivestar-rating" onclick="ratingClick(this.value); return false;"
src="../svgIcon/star.png" value="1"
onmouseout="noHoverStar(this.value)" onmouseover="hoverStar(this.value)">
<input type="image" id="star2" class="fivestar-rating" onclick="ratingClick(this.value); return false;"
src="../svgIcon/star.png" value="2"
onmouseout="noHoverStar(this.value)" onmouseover="hoverStar(this.value)">
<input type="image" id="star3" class="fivestar-rating" onclick="ratingClick(this.value); return false;"
src="../svgIcon/star.png" value="3"
onmouseout="noHoverStar(this.value)" onmouseover="hoverStar(this.value)">
<input type="image" id="star4" class="fivestar-rating" onclick="ratingClick(this.value); return false;"
src="../svgIcon/star.png" value="4"
onmouseout="noHoverStar(this.value)" onmouseover="hoverStar(this.value)">
<input type="image" id="star5" class="fivestar-rating" onclick="ratingClick(this.value); return false;"
src="../svgIcon/star.png" value="5"
onmouseout="noHoverStar(this.value)" onmouseover="hoverStar(this.value)">
<!-- Rating value submitted via POST Method-->
<input name="rating-value" id="rating-given" type="hidden" value="0">
<input name="order-id" type="hidden" value="0">
<input name="book-id" type="hidden" value="0">
</div>
</div>
</div>
<div class="book-detail">
<div class="head-title">Add Comment</div>
<div class="flex-review-tab">
<div class="comment-bar">
<textarea id="textarea-comment" name="comment" cols="180" rows="5"></textarea>
</div>
</div>
</div>
<div class="review-button">
<div>
<button class="back-button c-button" type="button" onClick="window.history.back()">Back</button>
<button class="submit-button c-button light-blue" type="submit">Submit</button>
</div>
</div>
</form>
</div>
</body>
</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 Review</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/review.css" />
<?php
class reviewFormViewer {
<script type="text/javascript" src="../javascript/review-book.js"></script>
</head>
<body>
<div class="detail-container add-nunito-font">
<div class="flex-container book-detail">
<div class="flex-1">
<div class="book-title orange-text"><b>Judul Buku</b></div>
<div class="book-author"><b>Pengarang</b></div>
</div>
<div class="add-flex-direction-column" id="rightbar-pic" align="center">
<div class="flex-1">
<img id="book-pict" src="../images/books_picture/4.jpg">
</div>
</div>
</div>
<form action="submit_review.php" method="POST">
<div class="book-detail">
<div class="head-title">Add Rating</div>
<div class="order-select">
<div class="rating-pict">
<input type="image" id="star1" class="fivestar-rating" onclick="ratingClick(this.value); return false;"
src="../svgIcon/star.png" value="1"
onmouseout="noHoverStar(this.value)" onmouseover="hoverStar(this.value)">
<input type="image" id="star2" class="fivestar-rating" onclick="ratingClick(this.value); return false;"
src="../svgIcon/star.png" value="2"
onmouseout="noHoverStar(this.value)" onmouseover="hoverStar(this.value)">
<input type="image" id="star3" class="fivestar-rating" onclick="ratingClick(this.value); return false;"
src="../svgIcon/star.png" value="3"
onmouseout="noHoverStar(this.value)" onmouseover="hoverStar(this.value)">
<input type="image" id="star4" class="fivestar-rating" onclick="ratingClick(this.value); return false;"
src="../svgIcon/star.png" value="4"
onmouseout="noHoverStar(this.value)" onmouseover="hoverStar(this.value)">
<input type="image" id="star5" class="fivestar-rating" onclick="ratingClick(this.value); return false;"
src="../svgIcon/star.png" value="5"
onmouseout="noHoverStar(this.value)" onmouseover="hoverStar(this.value)">
<!-- Rating value submitted via POST Method-->
<input name="rating-value" id="rating-given" type="hidden" value="0">
public static function viewReviewForm($params) {
$ordered_book = $params['ordered_book'];
echo Header::generateHead($ordered_book['Judul'].' Review', 'review');
Body::outputInBody(
Header::headerLogin($params['username']).
Header::headerMenu(Header::BROWSE).
self::showScript().
self::showBody($ordered_book)
);
}
private function showScript() {
return '<script type="text/javascript" src="../javascript/review-book.js"></script>';
}
private function showBody($ordered_book) {
$str = '<body>
<div class="detail-container add-nunito-font">'.
self::showBookDesc($ordered_book).
self::showReviewForm($ordered_book['order_id'], $ordered_book['book_id']).
'</div>
</body>';
return $str;
}
private function showBookDesc($ordered_book) {
$str = '
<div class="flex-container book-detail">
<div class="flex-1">
<div class="book-title orange-text"><b>'.$ordered_book['Judul'].'</b></div>
<div class="book-author"><b>'.$ordered_book['Pengarang'].'</b></div>
</div>
<div class="add-flex-direction-column" id="rightbar-pic" align="center">
<div class="flex-1">
<img id="book-pict" src="../images/books_picture/4.jpg">
<p id="output"></p>
</div>
</div>
</div>
</div>
<div class="book-detail">
<div class="head-title">Add Comment</div>
<div class="flex-review-tab">
<div class="comment-bar">
<textarea id="textarea-comment" name="comment" cols="180" rows="5"></textarea>
</div>';
return $str;
}
private function showReviewForm($order_id, $book_id) {
$str = '
<form action="review/submit_review.php" method="POST">
<div class="book-detail">
<div class="head-title">Add Rating</div>
<div class="order-select">'.
self::showRatingButton().
self::showHiddenInputForm($order_id, $book_id).
'</div>
</div>
</div>
</div>
<div class="review-button">
<div>
<button class="back-button c-button" type="button" onClick="window.history.back()">Back</button>
<button class="submit-button c-button light-blue" type="submit">Submit</button>
</div>
</div>
</form>
</div>
</body>
</html>
\ No newline at end of file
<div class="book-detail">
<div class="head-title">Add Comment</div>
<div class="flex-review-tab">
<div class="comment-bar">
<textarea id="textarea-comment" name="comment" cols="180" rows="5"></textarea>
</div>
</div>
</div>
<div class="review-button">
<div>
<button class="back-button c-button" type="button" onClick="window.history.back()">Back</button>
<button class="submit-button c-button light-blue" type="submit">Submit</button>
</div>
</div>
</form>';
return $str;
}
private function showRatingButton() {
$str = '
<div class="rating-pict">'.
self::show5Stars().
'</div>';
return $str;
}
private function show5Stars() {
$str = "";
for ($i=1; $i<=5; $i++) {
$str = $str .
'<input type="image" id="star'.$i.'" class="fivestar-rating"
onclick="ratingClick(this.value); return false;" src="../svgIcon/star.png"
value="'.$i.'" onmouseout="noHoverStar(this.value)"
onmouseover="hoverStar(this.value)">';
}
return $str;
}
private function showHiddenInputForm($order_id, $book_id) {
$str = '
<!-- Values submitted via POST Method-->
<input name="rating-value" id="rating-given" type="hidden" value="0">
<input name="order-id" type="hidden" value="'.$order_id.'">
<input name="book-id" type="hidden" value="'.$book_id.'">';
return $str;
}
}
?>
\ No newline at end of file