-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.php
76 lines (72 loc) · 2.99 KB
/
view.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
session_start();
include "../connectdb.php";
mysqli_select_db($db, 'fleamarket') or die(mysqli_error($db));
/* Article fetch */
$query = "select * from articles where articleID=".$_GET['id'];
$result = mysqli_query($db, $query) or die(mysqli_error($db));
$article = mysqli_fetch_assoc($result);
/* bookmarked check */
if(isset($_SESSION['userid'])){
if(isset($_GET['bookmark'])){
$query = "insert into bookmarks values('";
$query.= $_SESSION['userid']."',".$_GET['id'].")";
mysqli_query($db, $query) or die(mysqli_error($db));
header('Location: ?id='.$_GET['id']);
}
if(isset($_GET['unmark'])){
$query = "delete from bookmarks where articleID=".$_GET['id'];
$query .= " and userID='".$_SESSION['userid']."'";
mysqli_query($db, $query) or die(mysqli_error($db));
header('Location: ?id='.$_GET['id']);
}
if(isset($_GET['remove']) && $_SESSION['userid'] === $article['uploader']){
if(!unlink($article['thumbnail'])) die('Error deleting file');
$query = "delete from articles where articleID=".$_GET['id'];
mysqli_query($db, $query) or die(mysqli_error($db));
header('Location: index.php');
}
$query = "select * from bookmarks where articleID=".$_GET['id'];
$query .= " and userID='".$_SESSION['userid']."'";
$result = mysqli_query($db, $query) or die(mysqli_error($db));
$bookmarked = mysqli_num_rows($result);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style/main.css">
<title>Flea Market</title>
</head>
<body>
<header>
<?php require "module/header.php";?>
</header>
<?php require "module/search.php";?>
<div class="main-wrap">
<section class="articleview">
<?php
echo '<div class="item-imgwrap">';
echo '<img src='.$article['thumbnail'].'></div>';
echo '<p class="item-title">'.$article['title'].'</p>';
echo '<hr><p class="item-category">'. ucfirst($article['category']).'</p>';
echo '<p class="item-desc">'. $article['content'].'</p>';
echo '<footer><div>';
echo '<p class="item-author">'. $article['uploader'].'</p>';
echo '<p class="item-date">'. $article['uploadDate'].'</p></div>';
echo '<div class="menu">';
if(isset($_SESSION['userid'])){
if($bookmarked) echo button('?id='.$_GET['id'].'&unmark','Unmark');
else echo button('?id='.$_GET['id'].'&bookmark','Bookmark');
if($article['uploader']===$_SESSION['userid']){
echo button('?id='.$_GET['id'].'&remove', "Remove");
}
}
echo '</div></footer>';
?>
</section>
</div>
</body>
</html>