F diff --git a/css/style.css b/css/style.css
--- a/css/style.css
+++ b/css/style.css
justify-content: center;
}
+ .filesystem > h2,
form > h2 {
color: #4d4d4d;
margin: 0;
border-top-right-radius: 0.5rem;
}
-
- .window > h2 button {
- border: none;
- padding: 0.3rem 1rem;
- background: inherit;
- border-radius: 0;
- }
-
- .window > h2 button:not(.pathentry):hover {
- background: white;
- }
-
- .window > h2 > .separator {
- flex: 0 0 1px;
- align-self: stretch;
- background: #bbb;
- }
-
- .window > h2 > *:first-child {
- border-top-left-radius: 0.5rem;
- }
form p {
margin: 1rem 0px 0.3rem 0px;
}
+
.hero_form_error {
animation: fadein 0.2s;
background-color: #ff4d4d;
display: none;
}
- .window {
+ .filesystem {
background: #fafafa;
- margin: 0rem;
+ margin: 1rem;
padding: 0;
box-shadow: 0 0.8rem 1.3rem rgba(0,0,0,0.2);
border-radius: 0.5rem;
border: 1px solid #b9b9b9;
display: block;
- position: absolute;
- top: 0;
- left: 0;
- width: 800px;
- height: 600px;
- }
-
- .window > h2 {
- color: #4d4d4d;
- background: #f0f0f0;
- margin: 0;
- border-top-left-radius: 0.5rem;
- border-top-right-radius: 0.5rem;
-
- cursor: grab;
-
- display: flex;
- align-items: stretch;
- font-weight: normal;
- padding: 0rem;
- border-bottom: 1px solid #bbb;
- font-size: 1.3rem;
}
-
.files {
padding: 0.3rem;
display: grid;
filter: brightness(120%);
}
+ .filesystem > h2 {
+ display: flex;
+ align-items: stretch;
+ font-weight: normal;
+ padding: 0rem;
+ border-bottom: 1px solid #bbb;
+ font-size: 1.3rem;
+ }
+
+ .filesystem > h2 button {
+ border: none;
+ padding: 0.3rem 1rem;
+ background: inherit;
+ border-radius: 0;
+ }
+
+ .filesystem > h2 button:not(.pathentry):hover {
+ background: white;
+ }
+
+ .filesystem > h2 > .separator {
+ flex: 0 0 1px;
+ align-self: stretch;
+ background: #bbb;
+ }
+
+ .filesystem > h2 > *:first-child {
+ border-top-left-radius: 0.5rem;
+ }
.path {
display: flex;
F diff --git a/loggedin.js b/loggedin.js
--- a/loggedin.js
+++ b/loggedin.js
xhr.send(data);
}
- function begin_drag_fileview(e, fileview) {
+ function begin_drag(e, fileview) {
if (dragging)
end_drag();
dragging_placeholder = document.createElement('div');
- dragging_fileview = fileview;
+ fileview.visuals.parentNode.insertBefore(dragging_placeholder, fileview.visuals);
dragging = fileview.visuals;
-
- // document.body.appendChild(dragging);
-
- begin_drag(e, fileview.visuals,);
- }
-
- function begin_drag(e, obj) {
-
- dragging = obj;
+ dragging_fileview = fileview;
dragging.classList.add("dragged");
var elemRect = dragging.getBoundingClientRect();
- dragging_offset_x = e.clientX - elemRect.left;
- dragging_offset_y = -e.clientY + elemRect.top;
-
- console.log(elemRect);
- console.log(e.clientY, elemRect.top);
- if (dragging_placeholder)
- obj.parentNode.insertBefore(dragging_placeholder, obj);
-
- dragging.style.left = (e.clientX - dragging_offset_x) + "px";
- dragging.style.top = (e.clientY + dragging_offset_y) + "px";
+ dragging_offset_x = elemRect.width - (elemRect.left - e.clientX);
+ dragging_offset_y = elemRect.top - e.clientY;
+ dragging.style.position = "absolute";
dragging.style.width = elemRect.width + "px";
dragging.style.height = elemRect.height + "px";
-
- dragging.style.position = "absolute";
document.body.appendChild(dragging);
- }
- function end_drag(_e) {
- if (dragging_placeholder) {
- dragging_placeholder.parentNode.insertBefore(dragging, dragging_placeholder);
- dragging_placeholder.remove();
- dragging_placeholder = null;
- }
-
- if (dragging_fileview) {
- dragging.style.removeProperty("position");
- dragging.style.removeProperty("width");
- dragging.style.removeProperty("height");
- dragging.style.removeProperty("left");
- dragging.style.removeProperty("top");
- dragging_fileview = null;
- }
+ dragging.style.left = (e.clientX - dragging_offset_x) + "px";
+ dragging.style.top = (e.clientY + dragging_offset_y) + "px";
+ }
+ function end_drag(e) {
+ dragging_placeholder.parentNode.insertBefore(dragging, dragging_placeholder);
+ dragging_placeholder.remove();
+ dragging.style.removeProperty("position");
+ dragging.style.removeProperty("width");
+ dragging.style.removeProperty("height");
+ dragging.style.removeProperty("left");
+ dragging.style.removeProperty("top");
dragging.classList.remove("dragged");
dragging = null;
}
function open_file(fileview) {
var data = new FormData();
data.append('folder', get_path());
- data.append('filename', fileview.filename);
+ data.append('path', get_path());
var xhr = new XMLHttpRequest();
xhr.open('POST', '/php/readfile.php', true);
xhr.onload = function () {
- console.log(xhr.responseText);
+
};
xhr.send(data);
}
}
visuals.ondragstart = (e) => {
- begin_drag_fileview(e, fileview);
+ begin_drag(e, fileview);
e.preventDefault();
};
context_menu.remove();
}
- function init_window(wnd) {
- var h2 = wnd.getElementsByTagName("h2")[0];
- h2.onmousedown = (e) => {
- begin_drag(e, wnd);
- e.preventDefault();
- };
- }
-
- init_window(document.getElementById("root_window"));
-
load_dir();
F diff --git a/loggedin.php b/loggedin.php
--- a/loggedin.php
+++ b/loggedin.php
<div>
- <div class="window" id="root_window">
+ <div class="filesystem">
<h2 style="display: flex; gap: 0rem;">
<button id="upload_btn" onclick="begin_upload()">Upload</button>
<div class="separator"></div>
<div class="separator"></div>
<div class="path" id="the_path">
<button class="pathentry" id="home_path_entry">
- <?php echo $_SESSION['user_object']->username; ?>'s files
- </button>
+ <?php
+ $user=$_SESSION['user_object'];
+ echo $user->username;
+ ?>
+ 's files</button>
</div>
</h2>
F diff --git a/php/configuration.php b/php/configuration.php
--- a/php/configuration.php
+++ b/php/configuration.php
$storage_root = "/srv/apache/testing/project/files/";
}
-
+ /*if we save deleted files just in case of an error*/
+ $has_trash=true;
$password_hash_algo=PASSWORD_BCRYPT;
$has_email_verification=false;
F diff --git a/php/database.php b/php/database.php
--- a/php/database.php
+++ b/php/database.php
}
}
+ /*returns NULL if directory or error*/
+ function get_code_of_node(int $node_id)
+ {
+ global $storage_root;
+
+ $prep=$this->pdo->prepare("select code
+ from nodes
+ where node_id=:id
+ ");
+ $prep->bindParam(':id',$node_id);
+ if($prep->execute()==false)
+ {
+ error_log("could not execute sql statement in get_file_location_of_node");
+ return NULL;
+ }
+ $hold=$prep->fetch(PDO::FETCH_ASSOC);
+ if(count($hold)!=1)
+ {
+ return NULL;
+ }else
+ {
+ /*BEWARE*/
+ return $hold["code"];
+ }
+ }
+ /*
+ we remove the node and
+ 1. move the file represented by the node to the trash folder
+ 2. remove the file
+ depends on the conf file
+ */
+ function delete_node_by_id(int $node_id)
+ {
+ global $has_trash;
+ global $storage_root;
+
+ $location=get_file_location_of_node($node_id);
+
+ /*actually delete the file*/
+ if($has_trash)
+ {
+ /*BEWARE*/
+ if(!copy($storage_root."/".$location,$storage_root."/trash/".$location))
+ {
+ error_log("could not copy file aborting node deletion in delete_node_by_id");
+ return;
+ }
+ }
+ unlink($storage_root,"/".$location);
+
+ if($location==NULL)
+ {
+ error_log("trying to delete a node that does not exist in delete_node_by_id!");
+ return;
+ }
+ $prep=$this->pdo->prepare("delete
+ from nodes
+ where node_id=:id
+ ");
+ $prep->bindParam(':id',$node_id);
+ if($prep->execute()==false)
+ {
+ error_log("sql statement in delete_node_by_id could not execute");
+ return NULL;
+ }
+ }
/*this is used to create seperate roots for the users*/
function create_dangling_directory(): int
return $id["id"];
}
+
/*links source to target*/
function link_nodes(int $target_id,int $source_id,string $name,string $note)
{
error_log("there was an error with the statement ni link_nodes");
}
}
+
+ function create_home_directory():int
+ {
+ $ret=$this->create_dangling_directory();
+ $trash_folder_id=$this->create_dangling_directory();
+ $this->link_nodes($ret,$trash_folder_id,"trash","trash folder");
+ return $ret;
+ }
+
function check_if_name_is_taken(string $filename,int $dir_id):bool
{
if($this->get_node_id($filename,$dir_id)!=NULL)
}else
{
$hashed_pass=password_hash($password,$password_hash_algo);
- $home_dir=$this->create_dangling_directory();
+ $home_dir=$this->create_home_directory();
$prep=$this->pdo->prepare("insert into users(username,password,email,home_directory) values(:username,:password,:email,:dir)");
$prep->bindParam(':username',$user);
$prep->bindParam(':password',$hashed_pass);
F diff --git a/php/delete.php b/php/delete.php
new file mode 100644
--- /dev/null
+++ b/php/delete.php
+ <?php
+
+
+
+
+ ?>
F diff --git a/php/node.php b/php/node.php
--- a/php/node.php
+++ b/php/node.php
<?php
require_once "database.php";
require_once "user.php";
-
/*path is in terms of the simulated filesystem*/
function get_directory(string $abstract_path,User $user)
{
+
global $database;
- if($abstract_path[0] != "/") {
+ if($abstract_path[0] != "/")
+ {
return NULL;
}
- $component = strtok($abstract_path,"/");
- $current_dir = $user->home_directory;
+ $component = strtok($abstract_path,"/");
+ $current_dir = $user->home_directory;
- while ($component) {
+ while($component)
+ {
$current_dir = $database->get_node_id($component, $current_dir);
- $component = strtok("/");
- };
+ $component = strtok("/");
+ }
- return $current_dir;
+ return $current_dir;
}
/*returns an assoc arrat of Node-s*/
global $database;
$parent_dir_id=get_directory($abstract_path,$user);
+
if($database->check_if_name_is_taken($directory_name,$parent_dir_id))
{
return NULL;
F diff --git a/php/readfile.php b/php/readfile.php
--- a/php/readfile.php
+++ b/php/readfile.php
require_once "misc.php";
session_start();
- if (!isset($_POST["filename"]) || !isset($_POST["folder"])) {
+ if (!isset($_POST["filename"]) || !isset($_FILES["folder"])) {
error_log("/php/readfile.php - invalid request");
http_response_code(400);
exit(1);
$dir = get_directory($folder, $user);
if (!$dir) {
- error_log("/php/readfile.php - invalid directory");
+ error_log("i/php/readfile.php - invalid directory");
http_response_code(409);
exit(0);
}
foreach ($contents_of_dir as $c) {
if ($c['name'] == $filename) {
$file_node = $c;
- break;
}
}
- if (!$file_node) {
- error_log("/php/readfile.php - invalid filename");
- http_response_code(409);
- exit(0);
- }
-
- header("Content-type: $file_node[mimetype]");
- readfile("$storage_root/$file_node[code]");
+ var_error_log($file_node);
F diff --git a/sql/fileshare.sql b/sql/fileshare.sql
--- a/sql/fileshare.sql
+++ b/sql/fileshare.sql
email varchar(50),
home_directory int not null,
primary key (user_id),
- foreign key (home_directory) references nodes(node_id)
+ foreign key (home_directory) references nodes(node_id) on delete cascade
);
create table node_access (
can_view boolean not null default true,
can_edit boolean not null default false,
- foreign key (node_id) references nodes(node_id),
- foreign key (user_id) references users(user_id)
+ foreign key (node_id) references nodes(node_id) on delete cascade,
+ foreign key (user_id) references users(user_id) on delete cascade
);
/*we can name a node in many different ways */
create table node_links (
name varchar(100) not null default 'no name',
note varchar(200) not null default "",
check (directory_id != node_id),
- foreign key (directory_id) references nodes(node_id),
- foreign key (node_id) references nodes(node_id)
+ foreign key (directory_id) references nodes(node_id) on delete cascade,
+ foreign key (node_id) references nodes(node_id) on delete cascade
);