-
Notifications
You must be signed in to change notification settings - Fork 0
/
moreNews.php
91 lines (82 loc) · 3.45 KB
/
moreNews.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
// The hashed password from the form
require $_SERVER['DOCUMENT_ROOT'].'/scripts/dbConnector.php';
include $_SERVER['DOCUMENT_ROOT'].'/scripts/functions.php';
sec_session_start();
$admin = 0;
if(login_check($db) == true) {
$admin = 1;
if ($_SESSION['admin'] == 1) {
$clientView = 0;
} else {
$clientView = 1;
}
}
if (isset($_GET['pageSet'])) {
$currentPage = $_GET['pageSet'];
$offset = $currentPage * 4;
$toEnd = $offset + 4;
$finished = 0;
$sql='SELECT * FROM articles WHERE enabled = "1" ORDER BY creationTimestamp DESC LIMIT '.$offset.','.$toEnd;
/* Prepare statement */
$stmt = $db->prepare($sql);
if($stmt === false) {
trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $db->error, E_USER_ERROR);
}
/* Execute statement */
$stmt->execute();
$message = '';
$status = 'Success';
$totalNumber = 0;
$stmt->bind_result($id, $shortName, $fullName, $tags, $content, $description, $creationUser, $timeStamp, $editUser, $editTimeStamp, $enabled);
while ($stmt->fetch()) {
$message = $message . "<article>";
if ($admin==1 && $clientView != 1) {
$message = $message . "<div class='contentEdit'>
<a href='/editBlog.php?action=edit&id=".$id."'><img src='/img/editBtn.png' alt='edit button' /></a>
<a href='/deleteBlog.php?id=".$id."'><img src='/img/deleteBtn.png' alt='edit button' /></a>
</div>";
}
$message = $message . "<div class='date'>
" . date('j',$timeStamp) . "<span class='showMobile'><br /></span><span class='hideMobile'>.</span>". date('n',$timeStamp) . "<span class='showMobile'><br /></span><span class='hideMobile'>.</span>" . date('Y',$timeStamp) . "
</div>
<div class='details'>
<h2>".$fullName."</h2>
<div class='articleTags'>";
$test = explode(',',$tags);
$first = 1;
foreach ($test as $value) {
if ($first != 1) {
$message = $message . ', ';
} else {
$first = 0;
}
$message = $message . '#' . $value;
}
$message = $message . "</div>
<div class='muted'>".$creationUser."</div>
<div class='articleContent'>
".$description."</p>
<a href='/article/".$shortName."' class='moreLink'><More></a>
</div>
</div>
</article> ";
$totalNumber = $totalNumber + 1;
}
if ($totalNumber < 4) {
$finished = 1;
}
} else {
$status = 'failed';
$message = 'Failure';
}
$data = array(
'status' => $status,
'message' => $message,
'finished' => $finished,
'admin' => $admin,
'clientView' => $clientView
);
echo json_encode($data);
exit;
?>