about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--backend.php5
-rw-r--r--css/index.css8
-rw-r--r--index.php43
-rw-r--r--js/read.js12
-rw-r--r--read.html11
5 files changed, 69 insertions, 10 deletions
diff --git a/backend.php b/backend.php
index 9ce0bfa..83977b7 100644
--- a/backend.php
+++ b/backend.php
@@ -33,6 +33,7 @@
 				$base_filename = basename($filename);
 
 				header("Content-type: " . mime_content_type($filename));
+				header('Cache-control: max-age= ' . (86400*24));
 
 				readfile($filename);
 			} else {
@@ -110,7 +111,7 @@
 		break;
 	case "getlastread":
 		$bookid = (int) $_REQUEST["id"];
-		$lastread = -1;
+		$lastread = 0;
 
 		if ($bookid) {
 
@@ -156,7 +157,7 @@
 			db_query($link, "COMMIT");
 		}
 
-		print $page;
+		print json_encode(["lastread" => $page]);
 
 		break;
 
diff --git a/css/index.css b/css/index.css
index 58356ab..265ceb2 100644
--- a/css/index.css
+++ b/css/index.css
@@ -2,6 +2,14 @@
 	max-height : 180px;
 }
 
+.thumb.read img {
+	opacity : 0.25;
+}
+
+.in_progress {
+	font-style : italic;
+}
+
 .caption div {
 	overflow : hidden;
 	text-overflow: ellipsis;
diff --git a/index.php b/index.php
index d7e6397..8fc693a 100644
--- a/index.php
+++ b/index.php
@@ -1,3 +1,10 @@
+<?php
+	require_once "config.php";
+	require_once "include/functions.php";
+
+	$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
+	init_connection($link);
+?>
 <!DOCTYPE html>
 <html>
 <head>
@@ -85,27 +92,53 @@
 
 		$cover_link = "backend.php?" . http_build_query(["op" => "cover", "id" => $line["id"]]);
 		$author_link = "?" . http_build_query(["query" => $line["author_sort"]]);
-		$read_link = $line["epub_id"] ? "read.html?" . http_build_query(["id" => $line["epub_id"]]) : "";
+
+		$in_progress = false;
+		$is_read = false;
+
+		if ($line["epub_id"]) {
+			$read_link = "read.html?" . http_build_query(["id" => $line["epub_id"]]);
+
+			$lastread_result = db_query($link, "SELECT lastread, total_pages FROM epube_books, epube_pagination
+				WHERE epube_pagination.bookid = epube_books.bookid AND
+					epube_books.bookid = " . $line["epub_id"] . " AND owner = '$owner'");
+
+			if (db_num_rows($lastread_result) > 0) {
+				$lastread = db_fetch_result($lastread_result, 0, "lastread");
+				$total_pages = db_fetch_result($lastread_result, 0, "total_pages");
+
+				$is_read = $total_pages - $lastread < 5;
+				$in_progress = $lastread > 1;
+
+			}
+
+		} else {
+			$read_link = "";
+		}
+
+		$cover_read = $is_read ? "read" : "";
 
 		print "<div class='col-xs-6 col-sm-3 col-md-2' style='height : 250px'>";
-		print "<div class='thumb'>";
+		print "<div class=\"thumb $cover_read\">";
 
 		if ($read_link) print "<a href=\"$read_link\">";
 
 		if ($line["has_cover"]) {
 			print "<img src='$cover_link'>";
 		} else {
-			print "<img src='holder.js/120x180'>";
+			print "<img data-src='holder.js/120x180'>";
 		}
 
 		if ($read_link) print "</a>";
 
 		print "<div class='caption'>";
 
+		$title_class = $in_progress ? "in_progress" : "";
+
 		if ($read_link) {
-			print "<div><a href=\"$read_link\">" . $line["title"] . "</a></div>";
+			print "<div class=\"$title_class\"><a href=\"$read_link\">" . $line["title"] . "</a></div>";
 		} else {
-			print "<div>" . $line["title"] . "</div>";
+			print "<div class=\"$title_class\">" . $line["title"] . "</div>";
 		}
 
 		print "<div><a href=\"$author_link\">" . $line["author_sort"] . "</a></div>";
diff --git a/js/read.js b/js/read.js
index 4afa0f5..c6da974 100644
--- a/js/read.js
+++ b/js/read.js
@@ -93,7 +93,17 @@ function zoom(incr) {
 function clear_lastread() {
 	if (confirm("Clear stored last read page?")) {
 		$.post("backend.php", { op: "storelastread", page: -1, id: $.urlParam("id") }, function(data) {
-			$(".lastread_input").val(data);
+			$(".lastread_input").val(data.lastread);
+		});
+	}
+}
+
+function mark_as_read() {
+	if (confirm("Mark book as read?")) {
+		var total = window.book.pagination.totalPages;
+
+		$.post("backend.php", { op: "storelastread", page: total, id: $.urlParam("id") }, function(data) {
+			$(".lastread_input").val(data.lastread);
 		});
 	}
 }
diff --git a/read.html b/read.html
index bbb8d65..19b53f0 100644
--- a/read.html
+++ b/read.html
@@ -75,10 +75,17 @@
 					</div>
   				</div>
 
+				<div class="form-group">
+					<label class="col-sm-3 control-label"></label>
+					<div class="col-sm-9">
+						<button class="btn btn-primary" type="button" onclick="mark_as_read()">Mark as read</button>
+					</div>
+  				</div>
+
 			</form>      
       </div>
       <div class="modal-footer">
-        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>		  	
+             <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>		  	
       </div>
     </div>
   </div>
@@ -103,7 +110,7 @@
 
 <div class="header">
 	<span>
-		<a href="index.php">&laquo;&nbsp;Exit</a>
+		<a href="#" onclick="history.back()">&laquo;&nbsp;Exit</a>
 		<span class="title"></span>
 	</span>
 	<span class="toolbar">