diff --git a/index.html b/index.html index 2bea4df..9818d17 100644 --- a/index.html +++ b/index.html @@ -21,9 +21,10 @@

- - - + + + +     Path:  

@@ -58,6 +59,7 @@ + diff --git a/resources/js/favorites.js b/resources/js/favorites.js new file mode 100644 index 0000000..528d72a --- /dev/null +++ b/resources/js/favorites.js @@ -0,0 +1,17 @@ +function faveManager(elm) { + var path = document.getElementById("path").innerHTML; + var data = ""; + + if (elm.style.backgroundColor != "") { + elm.style.backgroundColor = ""; + elm.style.color = ""; + data = "deleteLink=true"; + } else { + elm.style.backgroundColor = "rgb(255, 255, 255)"; + elm.style.color = "rgb(0, 0, 0)"; + data = "deleteLink=false"; + } + + data += "&linkPath=" + path; + doAjax("resources/php/dbController.php", data); +} diff --git a/resources/js/xmlParser.js b/resources/js/xmlParser.js index 9c4b054..fc4387f 100644 --- a/resources/js/xmlParser.js +++ b/resources/js/xmlParser.js @@ -14,6 +14,7 @@ function handleXMLReturnData(data) { async function updateHTMLDirList(data) { + var isInFaves = data.getElementsByTagName('IN_FAVE')[0].innerHTML; var dirPath = data.getElementsByTagName('PATH_HEAD')[0].innerHTML; var dirs = data.getElementsByTagName('DIR'); var videos = data.getElementsByTagName('VID_FILE'); @@ -27,6 +28,17 @@ async function updateHTMLDirList(data) { document.getElementById("path").innerHTML = dirPath; insertArea.innerHTML = ""; + // determin whether to style faves or nor + if (isInFaves == "true") { + var elm = document.getElementById("faves"); + elm.style.backgroundColor = "rgb(255, 255, 255)"; + elm.style.color = "rgb(0, 0, 0)"; + } else { + var elm = document.getElementById("faves"); + elm.style.backgroundColor = ""; + elm.style.color = ""; + } + size = dirs.length; for (; i < size; i++) { var dir = dirs[i].innerHTML; diff --git a/resources/php/config.php b/resources/php/config.php index 326c5f5..516eeca 100644 --- a/resources/php/config.php +++ b/resources/php/config.php @@ -8,8 +8,8 @@ $TEXTVIEWER = "leafpad"; $FILEMANAGER = "spacefm"; // NOTE: Split folders with :::: - $LOCKEDFOLDERS = "./dirLockCheck/"; + $LOCKEDFOLDERS = "./MEGA_Sync/"; $LOCKPASSWORD = "1234"; - $UNLOCKTIME = 60; // Every ~3 sec this ticks down + $UNLOCKTIME = 80; // Every ~3 sec this ticks down // Ex: 3*60 == 180 sec or 3 minutes ?> diff --git a/resources/php/dbController.php b/resources/php/dbController.php index dcb88a3..808c132 100644 --- a/resources/php/dbController.php +++ b/resources/php/dbController.php @@ -1,47 +1,74 @@ Database connection failed!"; + serverMessage("error", $message); die("ERROR: Could not connect to db."); } $res = $db->query('Select * FROM faves'); $GeneratedXML = ""; while ($row = $res->fetchArray(SQLITE3_ASSOC)) { - $GeneratedXML .= "" . $row['id'] . "" . - "" . $row['link'] . ""; + $GeneratedXML .= "" . $row['link'] . ""; } $GeneratedXML .= ""; echo $GeneratedXML; } -function addLink($PATHID, $PATH) { +function manageLink($ACTION, $PATH) { $db = new SQLite3('resources/db/webfm.db'); + $ACTION_TYPE = ""; if($db === false){ + $message = "Server: [Error] --> Database connection failed!"; + serverMessage("error", $message); die("ERROR: Could not connect to db."); } - $stmt = $db->prepare('INSERT INTO faves VALUES(:id,:link)'); - $stmt->bindValue(":id", $PATHID, SQLITE3_TEXT); - $stmt->bindValue(":link", $PATH, SQLITE3_TEXT); + // If action isn't true then we add else we delete or exit. + if ($ACTION == "false") { + $stmt = $db->prepare('INSERT INTO faves VALUES(:link)'); + $ACTION_TYPE = "added to"; + } elseif ($ACTION == "true") { + $stmt = $db->prepare('DELETE FROM faves WHERE link = :link'); + $ACTION_TYPE = "deleted from"; + } else { + $message = "Server: [Error] --> Action for adding or deleting isn't set properly!"; + serverMessage("error", $message); + return; + } + $stmt->bindValue(":link", $PATH, SQLITE3_TEXT); $stmt->execute(); + + $message = "Server: [Success] --> Fave link: " . + $PATH . " " . $ACTION_TYPE . " the database!"; + serverMessage("success", $message); } -function deleteLink($PATHID) { +function isInDBCheck($PATH) { $db = new SQLite3('resources/db/webfm.db'); if($db === false){ + $message = "Server: [Error] --> Database connection failed!"; + serverMessage("error", $message); die("ERROR: Could not connect to db."); } - $stmt = $db->prepare('DELETE FROM faves WHERE id = :id'); - $stmt->bindValue(":id", $PATHID, SQLITE3_TEXT); - $stmt->execute(); + $stmt = $db->prepare('SELECT 1 FROM faves WHERE link = :link'); + $stmt->bindValue(":link", $PATH, SQLITE3_TEXT); + $result = $stmt->execute() ; + $row = $result->fetchArray() ; + + if ($row > 0) { + return "true"; + } else { + return "false"; + } } @@ -49,16 +76,12 @@ function deleteLink($PATHID) { chdir("../../"); if (isset($_POST['getTabs'])) { getTabLinks(); -} elseif (isset($_POST['addLink'], - $_POST['pathID'], - $_POST['linkPath'])) { - addLink($_POST['pathID'], $_POST['linkPath']); } elseif (isset($_POST['deleteLink'], - $_POST['pathID'])) { - deleteLink($_POST['pathID']); + $_POST['linkPath'])) { + manageLink($_POST['deleteLink'], $_POST['linkPath']); } else { - echo "" . - "Server: [Error] --> Illegal Access Method!"; + $message = "Server: [Error] --> Illegal Access Method!"; + serverMessage("error", $message); } ?> diff --git a/resources/php/getDirList.php b/resources/php/getDirList.php index afeab66..71bedac 100644 --- a/resources/php/getDirList.php +++ b/resources/php/getDirList.php @@ -1,10 +1,12 @@ " . "" . $NEWPATH . ""; @@ -12,6 +14,7 @@ function startListing($NEWPATH, $MERGESEASSONS, $PASSWD) { // the video src.... It's left blank when not in a sub dir listDir($GeneratedXML, $NEWPATH, $MERGESEASSONS, $subPath); + $GeneratedXML .= "" . isInDBCheck($NEWPATH) . ""; $GeneratedXML .= ""; echo $GeneratedXML; } else { @@ -70,14 +73,35 @@ function processItem(&$GeneratedXML, &$fullPath, &$fileName, $subPath) { } } +function isInDBCheck($PATH) { + $db = new SQLite3('resources/db/webfm.db'); + + if($db === false){ + $message = "Server: [Error] --> Database connection failed!"; + serverMessage("error", $message); + die("ERROR: Could not connect to db."); + } + + $stmt = $db->prepare('SELECT 1 FROM faves WHERE link = :link'); + $stmt->bindValue(":link", $PATH, SQLITE3_TEXT); + $result = $stmt->execute() ; + $row = $result->fetchArray() ; + + if ($row > 0) { + return "true"; + } else { + return "false"; + } +} + // Determin action chdir("../../"); if (isset($_POST['dirQuery'])) { startListing(trim($_POST['dirQuery']), $_POST['mergeType'], $_POST['passwd']); } else { - echo "" . - "Server: [Error] --> Incorrect access attempt!"; + $message = "Server: [Error] --> Illegal Access Method!"; + serverMessage("error", $message); } ?>