Near fleshed out faves functionality...

This commit is contained in:
Maxim Stewart 2018-08-25 00:53:44 -05:00
parent 949bca618e
commit 44db7ec95c
6 changed files with 104 additions and 26 deletions

View File

@ -21,9 +21,10 @@
<!-- Uploader --> <!-- Uploader -->
<h2 id="fullPathHeader"> <h2 id="fullPathHeader">
<button type="button" title="Other Options" name="button" onclick="tgglElmView('popOutControls')">&#9881;</button> <button type="button" title="Other Options" onclick="tgglElmView('popOutControls')">&#9881;</button>
<button type="button" title="Refresh" name="button" onclick="getDir('./')">&#8635;</button> <button type="button" id="faves" title="Favorites" onclick="faveManager(this)">&#9734;</button>
<button type="button" title="Back" name="button" onclick="getDir('../')">&lArr;</button> <button type="button" title="Refresh" onclick="getDir('./')">&#8635;</button>
<button type="button" title="Back" onclick="getDir('../')">&lArr;</button>
&nbsp;&nbsp;&nbsp;&nbsp;Path:&nbsp;&nbsp;<span id="path"></span> &nbsp;&nbsp;&nbsp;&nbsp;Path:&nbsp;&nbsp;<span id="path"></span>
</h2> </h2>
@ -58,6 +59,7 @@
<div id="serverMsgView" style="display:none;"> <div id="serverMsgView" style="display:none;">
</div> </div>
<script type="text/javascript" src="resources/js/favorites.js" charset="utf-8"></script>
<script type="text/javascript" src="resources/js/passwordFieldInsert.js" charset="utf-8"></script> <script type="text/javascript" src="resources/js/passwordFieldInsert.js" charset="utf-8"></script>
<script type="text/javascript" src="resources/js/cookieHandler.js" charset="utf-8"></script> <script type="text/javascript" src="resources/js/cookieHandler.js" charset="utf-8"></script>
<script type="text/javascript" src="resources/js/xmlParser.js" charset="utf-8"></script> <script type="text/javascript" src="resources/js/xmlParser.js" charset="utf-8"></script>

17
resources/js/favorites.js Normal file
View File

@ -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);
}

View File

@ -14,6 +14,7 @@ function handleXMLReturnData(data) {
async function updateHTMLDirList(data) { async function updateHTMLDirList(data) {
var isInFaves = data.getElementsByTagName('IN_FAVE')[0].innerHTML;
var dirPath = data.getElementsByTagName('PATH_HEAD')[0].innerHTML; var dirPath = data.getElementsByTagName('PATH_HEAD')[0].innerHTML;
var dirs = data.getElementsByTagName('DIR'); var dirs = data.getElementsByTagName('DIR');
var videos = data.getElementsByTagName('VID_FILE'); var videos = data.getElementsByTagName('VID_FILE');
@ -27,6 +28,17 @@ async function updateHTMLDirList(data) {
document.getElementById("path").innerHTML = dirPath; document.getElementById("path").innerHTML = dirPath;
insertArea.innerHTML = ""; 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; size = dirs.length;
for (; i < size; i++) { for (; i < size; i++) {
var dir = dirs[i].innerHTML; var dir = dirs[i].innerHTML;

View File

@ -8,8 +8,8 @@
$TEXTVIEWER = "leafpad"; $TEXTVIEWER = "leafpad";
$FILEMANAGER = "spacefm"; $FILEMANAGER = "spacefm";
// NOTE: Split folders with :::: // NOTE: Split folders with ::::
$LOCKEDFOLDERS = "./dirLockCheck/"; $LOCKEDFOLDERS = "./MEGA_Sync/";
$LOCKPASSWORD = "1234"; $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 // Ex: 3*60 == 180 sec or 3 minutes
?> ?>

View File

@ -1,47 +1,74 @@
<?php <?php
session_start(); include 'serverMessanger.php';
function getTabLinks() { function getTabLinks() {
$db = new SQLite3('resources/db/webfm.db'); $db = new SQLite3('resources/db/webfm.db');
if($db === false){ if($db === false){
$message = "Server: [Error] --> Database connection failed!";
serverMessage("error", $message);
die("ERROR: Could not connect to db."); die("ERROR: Could not connect to db.");
} }
$res = $db->query('Select * FROM faves'); $res = $db->query('Select * FROM faves');
$GeneratedXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><TABS_LIST>"; $GeneratedXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><TABS_LIST>";
while ($row = $res->fetchArray(SQLITE3_ASSOC)) { while ($row = $res->fetchArray(SQLITE3_ASSOC)) {
$GeneratedXML .= "<TAB_ID>" . $row['id'] . "</TAB_ID>" . $GeneratedXML .= "<TAB_LINK>" . $row['link'] . "</TAB_LINK>";
"<TAB_LINK>" . $row['link'] . "</TAB_LINK>";
} }
$GeneratedXML .= "</TABS_LIST>"; $GeneratedXML .= "</TABS_LIST>";
echo $GeneratedXML; echo $GeneratedXML;
} }
function addLink($PATHID, $PATH) { function manageLink($ACTION, $PATH) {
$db = new SQLite3('resources/db/webfm.db'); $db = new SQLite3('resources/db/webfm.db');
$ACTION_TYPE = "";
if($db === false){ if($db === false){
$message = "Server: [Error] --> Database connection failed!";
serverMessage("error", $message);
die("ERROR: Could not connect to db."); die("ERROR: Could not connect to db.");
} }
$stmt = $db->prepare('INSERT INTO faves VALUES(:id,:link)'); // If action isn't true then we add else we delete or exit.
$stmt->bindValue(":id", $PATHID, SQLITE3_TEXT); if ($ACTION == "false") {
$stmt->bindValue(":link", $PATH, SQLITE3_TEXT); $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(); $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'); $db = new SQLite3('resources/db/webfm.db');
if($db === false){ if($db === false){
$message = "Server: [Error] --> Database connection failed!";
serverMessage("error", $message);
die("ERROR: Could not connect to db."); die("ERROR: Could not connect to db.");
} }
$stmt = $db->prepare('DELETE FROM faves WHERE id = :id'); $stmt = $db->prepare('SELECT 1 FROM faves WHERE link = :link');
$stmt->bindValue(":id", $PATHID, SQLITE3_TEXT); $stmt->bindValue(":link", $PATH, SQLITE3_TEXT);
$stmt->execute(); $result = $stmt->execute() ;
$row = $result->fetchArray() ;
if ($row > 0) {
return "true";
} else {
return "false";
}
} }
@ -49,16 +76,12 @@ function deleteLink($PATHID) {
chdir("../../"); chdir("../../");
if (isset($_POST['getTabs'])) { if (isset($_POST['getTabs'])) {
getTabLinks(); getTabLinks();
} elseif (isset($_POST['addLink'],
$_POST['pathID'],
$_POST['linkPath'])) {
addLink($_POST['pathID'], $_POST['linkPath']);
} elseif (isset($_POST['deleteLink'], } elseif (isset($_POST['deleteLink'],
$_POST['pathID'])) { $_POST['linkPath'])) {
deleteLink($_POST['pathID']); manageLink($_POST['deleteLink'], $_POST['linkPath']);
} else { } else {
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><SERV_MSG class='error'>" . $message = "Server: [Error] --> Illegal Access Method!";
"Server: [Error] --> Illegal Access Method!</SERV_MSG>"; serverMessage("error", $message);
} }
?> ?>

View File

@ -1,10 +1,12 @@
<?php <?php
session_start(); session_start();
include 'serverMessanger.php';
// Start of retrieving dir data // Start of retrieving dir data
function startListing($NEWPATH, $MERGESEASSONS, $PASSWD) { function startListing($NEWPATH, $MERGESEASSONS, $PASSWD) {
if (is_dir($NEWPATH)) { if (is_dir($NEWPATH)) {
include 'lockedFolders.php'; include 'lockedFolders.php';
if (checkForLock($NEWPATH, $PASSWD) == false) { if (checkForLock($NEWPATH, $PASSWD) == false) {
$GeneratedXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><DIR_LIST>" $GeneratedXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><DIR_LIST>"
. "<PATH_HEAD>" . $NEWPATH . "</PATH_HEAD>"; . "<PATH_HEAD>" . $NEWPATH . "</PATH_HEAD>";
@ -12,6 +14,7 @@ function startListing($NEWPATH, $MERGESEASSONS, $PASSWD) {
// the video src.... It's left blank when not in a sub dir // the video src.... It's left blank when not in a sub dir
listDir($GeneratedXML, $NEWPATH, $MERGESEASSONS, $subPath); listDir($GeneratedXML, $NEWPATH, $MERGESEASSONS, $subPath);
$GeneratedXML .= "<IN_FAVE>" . isInDBCheck($NEWPATH) . "</IN_FAVE>";
$GeneratedXML .= "</DIR_LIST>"; $GeneratedXML .= "</DIR_LIST>";
echo $GeneratedXML; echo $GeneratedXML;
} else { } 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 // Determin action
chdir("../../"); chdir("../../");
if (isset($_POST['dirQuery'])) { if (isset($_POST['dirQuery'])) {
startListing(trim($_POST['dirQuery']), $_POST['mergeType'], $_POST['passwd']); startListing(trim($_POST['dirQuery']), $_POST['mergeType'], $_POST['passwd']);
} else { } else {
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><SERV_MSG class='error'>" . $message = "Server: [Error] --> Illegal Access Method!";
"Server: [Error] --> Incorrect access attempt!</SERV_MSG>"; serverMessage("error", $message);
} }
?> ?>