-
Notifications
You must be signed in to change notification settings - Fork 2
/
dashboard.php
435 lines (410 loc) · 20.3 KB
/
dashboard.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
<?php require_once("includes/header.inc.php");
require_once("includes/meta.inc.php");
require_once("includes/css.inc.php");
function abc($a, $b)
{
return strcmp($a["name"], $b["name"]);
}
function pages($a, $b)
{
return ((count($a["pages"])-$a["bookmark"]) - (count($b["pages"])-$b["bookmark"]));
}
function pagesrev($a, $b)
{
return ((count($b["pages"])-$b["bookmark"]) - (count($a["pages"])-$a["bookmark"]));
}
$conn = dbConnect();
if (isset($_SESSION['user_id']) && !empty($_SESSION['user_id'])){
$user = mysqli_real_escape_string($conn, $_SESSION['user_id']);
}else{
header("Location:/");
}
if (isset($_POST) && !empty($_POST)){
//Subscribing, unsubscribing, favorites
if ($_POST['private']){
$stmt = $conn->prepare("UPDATE user_subs SET sub_type = 'private' WHERE comic_id=? and user_id=?");
$stmt->bind_param('ii', $_POST['private'], $_SESSION['user_id']);
$stmt->execute();
}elseif ($_POST['public']){
$stmt = $conn->prepare("UPDATE user_subs SET sub_type = 'public' WHERE comic_id=? and user_id=?");
$stmt->bind_param('ii', $_POST['public'], $_SESSION['user_id']);
$stmt->execute();
}elseif ($_POST['unsubscribe']){
$stmt = $conn->prepare("DELETE FROM user_subs WHERE user_id=? and comic_id=?;");
$stmt->bind_param('ii', $_SESSION['user_id'], $_POST['unsubscribe']);
$stmt->execute();
}elseif ($_POST['favorite']){
$stmt = $conn->prepare("UPDATE user_subs SET favorite = 1 WHERE comic_id=? and user_id=?;");
$stmt->bind_param('ii', $_POST['favorite'], $_SESSION['user_id']);
$stmt->execute();
}elseif ($_POST['unfavorite']){
$stmt = $conn->prepare("UPDATE user_subs SET favorite = 0 WHERE comic_id=? and user_id=?;");
$stmt->bind_param('ii', $_POST['unfavorite'], $_SESSION['user_id']);
$stmt->execute();
}
elseif ($_POST['bookmark'] || ($_POST['bookmark'] == 0 && $_POST['bookmark'] !== False)){
if($_POST['bookmark'] == 0 && $_POST['bookmark'] !== False){
$bmpage = 0;
}
else{
$bmpage = mysqli_real_escape_string($conn, filter_var($_POST['bookmark'],FILTER_SANITIZE_NUMBER_INT));
}
$bmcomic = mysqli_real_escape_string($conn, filter_var($_POST['bmsubmit'],FILTER_SANITIZE_NUMBER_INT));
$stmt = $conn->prepare("UPDATE user_subs SET bookmark = ? WHERE comic_id=? and user_id=?;");
$stmt->bind_param('iii', $bmpage, $bmcomic, $_SESSION['user_id']);
$stmt->execute();
}
}
//get their owned comics
$stmt = $conn->prepare("select comics.comic_id, comic_name, comic_image, comic_crawler from comics left join comic_owners on comics.comic_id = comic_owners.comic_id where user_id=?");
$stmt->bind_param('i', $user);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$owned_comics[] = array(
"id"=>$row["comic_id"],
"name"=>$row["comic_name"],
"image"=>$row["comic_image"],
"status"=>json_decode(str_replace('"crawler": ', '', str_replace("'", '"',$row["comic_crawler"])), true)
);
}
}
if (count($owned_comics) > 0){
//(SELECT count(favorite) as total FROM user_subs WHERE comic_id=3)
$stmt = $conn->prepare("SELECT count(comic_id) as subs, (select count(favorite) from user_subs where favorite=1 and comic_id=?) as favorites FROM user_subs WHERE comic_id=?");
$stmt->bind_param('ii', $comic_id, $comic_id);
$i = 0;
foreach ($owned_comics as $comics){
$comic_id = $comics["id"];
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$owned_comics[$i]["readers"] = $row["subs"];
$owned_comics[$i]["favorites"] = $row["favorites"];
}
}
$i++;
}
}
//get subbed comics
$stmt = $conn->prepare("select comics.comic_id, comic_name, comic_image, comic_status, comic_pages, last_update, reader_options, sub_type, bookmark, favorite from comics inner join user_subs on comics.comic_id = user_subs.comic_id where user_id=? order by last_update desc");
$stmt->bind_param('i', $user);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$subbed_comics[] = array("id"=>$row["comic_id"],
"name"=>$row["comic_name"],
"image"=>$row["comic_image"],
"status"=>$row["comic_status"],
"pages" => json_decode(str_replace("'", '"',$row["comic_pages"])),
"update"=>$row["last_update"],
"reader_options"=>json_decode($row["reader_options"], true),
"sub_type"=>$row["sub_type"],
"bookmark"=>$row["bookmark"],
"favorite"=>$row["favorite"]);
}
}
if ($_GET['sort'] == 'update' || $_SESSION['sort'] == 'update'){
$_SESSION['sort'] = 'update';
}
if ($_GET['sort'] == 'abc' || $_SESSION['sort'] == 'abc'){
usort($subbed_comics, "abc");
$_SESSION['sort'] = 'abc';
}
if ($_GET['sort'] == 'pages' || $_SESSION['sort'] == 'pages'){
usort($subbed_comics, "pages");
$_SESSION['sort'] = 'pages';
}
if ($_GET['sort'] == 'pages-reverse' || $_SESSION['sort'] == 'pages-reverse'){
usort($subbed_comics, "pagesrev");
$_SESSION['sort'] = 'pages-reverse';
}
$stmt->close();
$conn->close();
echo "<style>
";
if (count($owned_comics) > 0){
foreach ($owned_comics as $comic){
if (!empty($comic["image"])){
echo '.comic'.$comic["id"].':before {background-image: -moz-linear-gradient(90deg, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.8) 20%, rgba(0,0,0,0) 60%), url("/assets/usr_imgs/banners/'.$comic["image"].'");background-image: -webkit-linear-gradient(90deg, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.8) 20%, rgba(0,0,0,0) 60%), url("/assets/usr_imgs/banners/'.$comic["image"].'");background-image: linear-gradient(90deg, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.8) 20%, rgba(0,0,0,0) 60%), url("/assets/usr_imgs/banners/'.$comic["image"].'");filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#000000",endColorstr="#000000",GradientType=1), url("/assets/usr_imgs/banners/'.$comic["image"].'");}';
}else{
echo '.comic'.$comic["id"].' {background: inherit;}
';
}
}
}
foreach ($subbed_comics as $comic){
if (!empty($comic["image"])){
echo '.comic'.$comic["id"].':before {background-image: -moz-linear-gradient(90deg, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.8) 20%, rgba(0,0,0,0) 60%), url("/assets/usr_imgs/banners/'.$comic["image"].'");background-image: -webkit-linear-gradient(90deg, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.8) 20%, rgba(0,0,0,0) 60%), url("/assets/usr_imgs/banners/'.$comic["image"].'");background-image: linear-gradient(90deg, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.8) 20%, rgba(0,0,0,0) 60%), url("/assets/usr_imgs/banners/'.$comic["image"].'");filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#000000",endColorstr="#000000",GradientType=1), url("/assets/usr_imgs/banners/'.$comic["image"].'");}';
}
}
?>
.btn-group.special {
display: flex;
margin-bottom:15px;
}
.special .btn {
flex: 1
}
.progress{
margin:0;
border-radius:0;
}
.btn-group>.btn:first-child:not(:last-child):not(.dropdown-toggle) {
border-top-left-radius: 0;
}
.btn-group>.btn:last-child:not(:first-child), .btn-group>.dropdown-toggle:not(:first-child) {
border-top-right-radius: 0;
}
.dashboard-comic {
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}
</style>
</head>
<body>
<?php require_once 'includes/menu.inc.php';?>
<div class="container panel panel-default">
<div class="panel-body">
<div class="row">
<?php if (count($owned_comics) > 0){ ?>
<div class="col-md-8 text-justify">
<?php } else { ?>
<div class="col-md-12 text-justify">
<?php } ?>
<h1>Comic Dashboard</h1>
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Sort
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li><a href="/dashboard?sort=update">Last Update</a></li>
<li><a href="/dashboard?sort=abc">Alphabetical</a></li>
<li><a href="/dashboard?sort=pages">Pages to Read (Least to Most)</a></li>
<li><a href="/dashboard?sort=pages-reverse">Pages to Read (Most to Least)</a></li>
</ul>
</div>
<!--Favorites-->
<h2>Catch Up on Favorites</h2>
<?php if (isset($subbed_comics) && !empty($subbed_comics)){?>
<?php foreach ($subbed_comics as $comic){
if ($comic["favorite"] == 1 && $comic['bookmark']+1 != count($comic['pages'])){
echo '<a href="/comic/'.$comic['id'].'" class="list-group-item list-group-item-action dashboard-comic';
if (!empty($comic["image"])){
echo ' comic-bar comic'.$comic["id"];
}
echo '"><strong>'.$comic['name'].'</strong>';
echo '<span class="pull-right"';
if (!empty($comic["image"])){
echo ' style="color:#000;-webkit-font-smoothing: antialiased;text-shadow: 1px 1px #fff;z-index:2"';
}
if ($comic['update']) {
echo '>'.date("l, d M Y", strtotime($comic['update']));
if ($comic['status'] == 'Completed'){
echo ' (Completed)';
} elseif ($comic['status'] == 'Cancelled'){
echo ' (Cancelled)';
}elseif ($comic['status'] == 'On Hiatus'){
echo ' (Hiatus)';
}
} else {
echo '>N/A';
}
echo '</span>';?>
</a>
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="<?php $percent = ($comic['bookmark']+1)/count($comic['pages'])*100; echo $percent; ?>"
aria-valuemin="0" aria-valuemax="100" style="min-width:3em;width:<?php $percent = ($comic['bookmark']+1)/count($comic['pages'])*100; echo $percent; ?>%">
<?php echo $comic['bookmark']+1; echo '/'.count($comic['pages']); ?>
</div>
</div>
<form method="post" action="/dashboard">
<div class="btn-group special" role="group" aria-label="Subscription Controls">
<?php if (strpos($comic['pages'][0], 'webtoon') !== false || strpos($comic['pages'][0], 'smackjeeves') !== false || $comic['reader_options']['style'] == 'webtoons') {
?><a href="<?php echo $comic['pages'][$comic['bookmark']]; ?>" target="_blank" class="btn btn-default">Read</a>
<select name="bookmark" class="btn btn-static page-bookmark">
<?php
$pageno = 0;
foreach ($comic['pages'] as $pages){
echo '<option value="'.$pageno.'"';
if($pageno == $comic['bookmark']){echo ' selected';}
echo '>';
$pageno++;
echo $pageno.'</option>';
}
?>
</select>
<button type="submit" class="btn btn-default" name="bmsubmit" value="<?php echo $comic['id']; ?>">Bookmark</button>
<?php }else{?>
<a href="http://<?php echo $_SERVER['SERVER_NAME'];?>/reader/<?php echo $comic['id'];?>/<?php if($comic['bookmark']){echo $comic['bookmark'];}else{echo "0";} ?>" class="btn btn-default">Read</a>
<? }
if ($comic['sub_type']=="public"){ echo '<button type="submit" class="btn btn-default" name="private" value="'.$comic['id'].'">Public</button>';}else{echo '<button type="submit" class="btn btn-default" name="public" value="'.$comic['id'].'">Private</button>';} ?>
<button type="submit" class="btn btn-default" name="unsubscribe" value="<?php echo $comic['id']; ?>">Unsub</button>
<button type="submit" class="btn btn-default" name="unfavorite" value="<?php echo $comic['id']; ?>">Unfave</button>
</div>
</form>
<?php }
} ?>
<!--End Favorites-->
<h2>Reading List</h2>
<?php
//Not Favorites-->
foreach ($subbed_comics as $comic){
if ($comic["favorite"] == 0 && $comic['bookmark']+1 != count($comic['pages'])){
echo '<a href="/comic/'.$comic['id'].'" class="list-group-item list-group-item-action dashboard-comic';
if (!empty($comic["image"])){
echo ' comic-bar comic'.$comic["id"];
}
echo '"><strong>'.$comic['name'].'</strong>';
echo '<span class="pull-right"';
if (!empty($comic["image"])){
echo ' style="color:#000;-webkit-font-smoothing: antialiased;text-shadow: 1px 1px #fff;z-index:2"';
}
if ($comic['update']) {
echo '>'.date("l, d M Y", strtotime($comic['update']));
if ($comic['status'] == 'Completed'){
echo ' (Completed)';
} elseif ($comic['status'] == 'Cancelled'){
echo ' (Cancelled)';
}elseif ($comic['status'] == 'On Hiatus'){
echo ' (Hiatus)';
}
} else {
echo '>N/A';
}
echo '</span>';?>
</a>
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="<?php $percent = ($comic['bookmark']+1)/count($comic['pages'])*100; echo $percent; ?>"
aria-valuemin="0" aria-valuemax="100" style="min-width:3em;width:<?php $percent = ($comic['bookmark']+1)/count($comic['pages'])*100; echo $percent; ?>%">
<?php echo $comic['bookmark']+1;echo '/'.count($comic['pages']); ?>
</div>
</div>
<form method="post" action="/dashboard">
<div class="btn-group special" role="group" aria-label="Subscription Controls">
<?php if (strpos($comic['pages'][0], 'webtoon') !== false || strpos($comic['pages'][0], 'smackjeeves') !== false || $comic['reader_options']['style'] == 'webtoons') {
?><a href="<?php echo $comic['pages'][$comic['bookmark']]; ?>" target="_blank" class="btn btn-default">Read</a>
<select name="bookmark" class="btn btn-static page-bookmark">
<?php
$pageno = 0;
foreach ($comic['pages'] as $pages){
echo '<option value="'.$pageno.'"';
if($pageno == $comic['bookmark']){echo ' selected';}
echo '>';
$pageno++;
echo $pageno.'</option>';
}
?>
</select>
<button type="submit" class="btn btn-default" name="bmsubmit" value="<?php echo $comic['id']; ?>">Bookmark</button>
<?php }else{?>
<a href="http://<?php echo $_SERVER['SERVER_NAME'];?>/reader/<?php echo $comic['id'];?>/<?php if($comic['bookmark']){echo $comic['bookmark'];}else{echo "0";} ?>" class="btn btn-default">Read</a>
<? }
if ($comic['sub_type']=="public"){ echo '<button type="submit" class="btn btn-default" name="private" value="'.$comic['id'].'">Public</button>';}else{echo '<button type="submit" class="btn btn-default" name="public" value="'.$comic['id'].'">Private</button>';} ?>
<button type="submit" class="btn btn-default" name="unsubscribe" value="<?php echo $comic['id']; ?>">Unsub</button>
<button type="submit" class="btn btn-default" name="favorite" value="<?php echo $comic['id']; ?>">Favorite</button>
</div>
</form>
<?php }
} ?>
<!--End Not Favorites-->
<h2>Caught Up</h2>
<?php
foreach ($subbed_comics as $comic){
if ($comic['bookmark']+1 == count($comic['pages'])){
echo '<a href="/comic/'.$comic['id'].'" class="list-group-item list-group-item-action dashboard-comic';
if (!empty($comic["image"])){
echo ' comic-bar comic'.$comic["id"];
}
echo '"><strong>'.$comic['name'].'</strong>';
echo '<span class="pull-right"';
if (!empty($comic["image"])){
echo ' style="color:#000;-webkit-font-smoothing: antialiased;text-shadow: 1px 1px #fff;z-index:2"';
}
if ($comic['update']) {
echo '>'.date("l, d M Y", strtotime($comic['update']));
if ($comic['status'] == 'Completed'){
echo ' (Completed)';
} elseif ($comic['status'] == 'Cancelled'){
echo ' (Cancelled)';
}elseif ($comic['status'] == 'On Hiatus'){
echo ' (Hiatus)';
}
} else {
echo '>N/A';
}
echo '</span>';?>
</a>
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="<?php $percent = ($comic['bookmark']+1)/count($comic['pages'])*100; echo $percent; ?>"
aria-valuemin="0" aria-valuemax="100" style="min-width:3em;width:<?php $percent = ($comic['bookmark']+1)/count($comic['pages'])*100; echo $percent; ?>%">
<?php echo $comic['bookmark']+1; echo '/'.count($comic['pages']); ?>
</div>
</div>
<form method="post" action="/dashboard">
<div class="btn-group special" role="group" aria-label="Subscription Controls">
<?php if (strpos($comic['pages'][0], 'webtoon') !== false || strpos($comic['pages'][0], 'smackjeeves') !== false || $comic['reader_options']['style'] == 'webtoons') {
?><a href="<?php echo $comic['pages'][$comic['bookmark']]; ?>" target="_blank" class="btn btn-default">Read</a>
<select name="bookmark" class="btn btn-static page-bookmark">
<?php
$pageno = 0;
foreach ($comic['pages'] as $pages){
echo '<option value="'.$pageno.'"';
if($pageno == $comic['bookmark']){echo ' selected';}
echo '>';
$pageno++;
echo $pageno.'</option>';
}
?>
</select>
<button type="submit" class="btn btn-default" name="bmsubmit" value="<?php echo $comic['id']; ?>">Bookmark</button>
<?php }else{?>
<a href="http://<?php echo $_SERVER['SERVER_NAME'];?>/reader/<?php echo $comic['id'];?>/<?php if($comic['bookmark']){echo $comic['bookmark'];}else{echo "0";} ?>" class="btn btn-default">Read</a>
<? }
if ($comic['sub_type']=="public"){ echo '<button type="submit" class="btn btn-default" name="private" value="'.$comic['id'].'">Public</button>';}else{echo '<button type="submit" class="btn btn-default" name="public" value="'.$comic['id'].'">Private</button>';} ?>
<button type="submit" class="btn btn-default" name="unsubscribe" value="<?php echo $comic['id']; ?>">Unsub</button>
<button type="submit" class="btn btn-default" name="<?php if ($comic["favorite"] == 1){echo 'un';}?>favorite" value="<?php echo $comic['id']; ?>"><?php if ($comic["favorite"] == 1){echo 'Unf';}else{echo 'F';}?>avorite</button>
</div>
</form>
<?php }
}
}else{echo "You're not currently subscribed to any comics."; } ?>
</div>
<?php if (count($owned_comics) > 0){ ?>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">Claimed Comics</div>
<div class="panel-body"><?php foreach($owned_comics as $comic){
echo '<a href="/comic/'.$comic["id"].'" class="list-group-item list-group-item-action">';
if($comic["image"]){
echo '<div class="list-group-item-heading comic-bar comic'.$comic["id"].'"><h3>'.$comic["name"].'</h3></div>';
}
else{
echo '<div class="list-group-item-heading comic-bar comic'.$comic["id"].'"><h3 class="white-text">'.$comic["name"].'</h3></div>';
}
echo '<div class="row"><div class="panel-body">';
echo '<label>Crawler Status: </label> '.ucfirst($comic["status"]["status"]);
echo '<br /><label>Readers: </label> '.$comic["readers"];
echo '<br /><label>Favorites: </label> '.$comic["favorites"];
echo '</div></div>'; //row and body
echo '</a>
';
}
?>
</div>
</div>
</div>
<?php } ?>
</div>
</div><!--panel body-->
</div> <!-- /container -->
<?php require_once 'includes/footer.inc.php';?>
</body>
</html>