Commit 9bd1b549 authored by Ranindya Paramitha's avatar Ranindya Paramitha
Browse files
parents 33cce55e 7b04b010
<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
class fileProcessing {
public const PROFILE_DEFAULT = 'default.jpg';
public static function isExistBookImage (string $name): bool {
return file_exists('../images/books_picture/'.$name.'.jpg');
}
public static function isExistProfileImage (string $name): bool {
return file_exists('../images/profiles_picture/'.$name.'.jpg');
return file_exists('../uploads/'.$name.'.jpg');
}
public static function getImageBookPathFromRoot (string $name): string {
......
......@@ -42,8 +42,10 @@ class Header {
<span class="yellow-text">Pro</span>-Book
</div>
<div class="flex-item-header">
<div class="underline-text white-text flex-item-center">
Hi, '.$name.'
<div class="text-size-20 white-text flex-item-center add-nunito-font">
<div class="c-border-bottom">
Hi, '.$name.'
</div>
</div>
<a href="/logout" class="flex-item-header orange-background" >
<img src="../svgIcon/power-button.svg" class="turn-off-button">
......@@ -72,17 +74,17 @@ class Header {
<div class="flex-1 ">
<a href="'.self::URL_BROWSE.'">
<div>
BROWSE
<span class="text-size-40">B</span>ROWSE
</div>
</a>
</div>
<div class="left-right-border orange-background flex-1 ">
HISTORY
<span class="text-size-40">H</span>ISTORY
</div>
<div class="flex-1 ">
<a href="'.self::URL_PROFILE.'">
<div>
PROFILE
<span class="text-size-40">P</span>ROFILE
</div>
</a>
</div>
......@@ -93,19 +95,19 @@ class Header {
return '
<div class="flex-container-menu">
<div class="orange-background flex-1 ">
BROWSE
<span class="text-size-40">B</span>ROWSE
</div>
<div class="left-right-border flex-1 ">
<a href="'.self::URL_HISTORY.'">
<div>
HISTORY
<span class="text-size-40">H</span>ISTORY
</div>
</a>
</div>
<div class="flex-1 ">
<a href="'.self::URL_PROFILE.'">
<div>
PROFILE
<span class="text-size-40">P</span>ROFILE
</div>
</a>
</div>
......@@ -118,19 +120,19 @@ class Header {
<div class="flex-1 ">
<a href="'.self::URL_BROWSE.'">
<div>
BROWSE
<span class="text-size-40">B</span>ROWSE
</div>
</a>
</div>
<div class="left-right-border flex-1 ">
<a href="'.self::URL_HISTORY.'">
<div>
HISTORY
<span class="text-size-40">H</span>ISTORY
</div>
</a>
</div>
<div class="orange-background flex-1 ">
PROFILE
<span class="text-size-40">P</span>ROFILE
</div>
</div>';
}
......
<?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
......@@ -3,7 +3,13 @@ require_once ('view.php');
class browseController {
public static function showBrowseController() {
$params = ['username' => 'wildan'];
viewBrowse($params);
if (isLogin()) {
$user_token = getTokenLogin();
$params = ['username' => getUsername($user_token)];
viewBrowse($params);
} else {
$login = '../login';
header('Location: '.$login);
}
}
}
\ No newline at end of file
......@@ -3,17 +3,18 @@
require_once ('../autoload.php');
function viewBrowse (array $params) {
echo Header::generateHead('Browse', 'browse');
echo Header::generateHeadWithJS('Browse', 'browse', 'browse');
$searchForm = '
<div class="flex-container-search-form orange-text" >
<label class="search-box-text" >Search Box</label>
<label class="search-box-text" >Search Book</label>
</div>
<form method="GET" action="http://www.sansadsa.com">
<div class="flex-container-search-form margin-top-bottom-10">
<input class="full-width" type="text" name="searchText" placeholder="Input search terms...">
<form id="searchForm" method="GET" action="search_result">
<div class="flex-container-search-form margin-top-bottom-10 add-flex-direction-column">
<p id="warning-empty-input" class="red-theme alert-box text-size-20 add-nunito-font c-round">Input can\'t be empty</p>
<input id="inputSearch" class="text-size-20 full-width c-input add-border-gray c-round" type="text" name="search_text" placeholder="Input search terms...">
</div>
<div class="flex-container-search-form add-flex-end-justify margin-top-bottom-10">
<button type="submit" class="c-button light-blue c-round">
<button id="submit-button" type="button" class="text-size-30 add-nunito-font c-button light-blue c-round" onclick="trySubmitSearch()">
Search
</button>
</div>
......
@font-face {
font-family: 'Nunito';
font-style: normal;
font-weight: 400;
src: url(../fonts/nunito.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
font-family: 'Nunito Bold';
font-style: normal;
font-weight: 700;
src: url(../fonts/nunito-bold.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
font-family: 'Nunito Semi Bold';
font-style: normal;
font-weight: 600;
src: url(../fonts/nunito-semi-bold.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
body {
margin: 0
}
.add-nunito-font {
font-family: 'Nunito', sans-serif !important;
}
a {
color: inherit; /* blue colors for links too */
text-decoration: inherit; /* no underline */
......@@ -23,6 +50,7 @@ a {
.align-content-space-between {
align-content: space-between !important;
}
.c-button {
border: none;
display: inline-block;
......@@ -37,6 +65,10 @@ a {
white-space: nowrap
}
.c-button:hover {
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)
}
.c-round {
border-radius: 4px
}
......@@ -57,6 +89,10 @@ a {
margin: 20px;
}
.margin-10 {
margin: 10px;
}
.text-size-10{
font-size: 10px !important;
}
......@@ -104,3 +140,28 @@ a {
.align-items-flex-end {
align-items: flex-end !important;
}
.c-input {
padding: 8px;
display: block;
border: none;
width: 100%;
}
.c-border-bottom {
border-bottom: 1px solid white!important;
}