summaryrefslogtreecommitdiff
path: root/www/functions/func_delete.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/functions/func_delete.php')
-rw-r--r--www/functions/func_delete.php83
1 files changed, 83 insertions, 0 deletions
diff --git a/www/functions/func_delete.php b/www/functions/func_delete.php
new file mode 100644
index 0000000..2dab9e2
--- /dev/null
+++ b/www/functions/func_delete.php
@@ -0,0 +1,83 @@
+<?php
+
+function delete_file($user, $path){
+ $db = $GLOBALS["db"];
+ $uploaddir = "../files/";
+
+ $file_id = select_file_id($db, $user, $path);
+
+ $check_if_file_db = $db->query("SELECT folder, hash FROM files WHERE id=".$file_id.";");
+ $check_if_file_ar = $check_if_file_db->fetchArray(SQLITE3_NUM);
+
+ if($check_if_file_ar[0] != "FILE"){
+ return DELETE_FILE_NO_FILE;
+ }
+
+ $file_hash = $check_if_file_ar[1];
+
+ if(!unlink($uploaddir.$file_hash.".gz")){
+ return DELETE_FILE_UNLINK;
+ }
+
+ if($db->exec("
+ BEGIN TRANSACTION;
+ DELETE FROM files WHERE id=".$file_id.";
+ COMMIT;
+ ")){
+ return DELETE_FILE_SUCCESS;
+ } else {
+ return DELETE_FILE_DATABASE;
+ }
+}
+
+function delete_user($user){
+ $db = $GLOBALS["db"];
+ $uploaddir = "../files/";
+
+ $owner = user_id($db, $user);
+
+ $hash_array_db = $db->query("SELECT hash FROM files WHERE folder='FILE' AND owner=".$owner.";");
+
+ $count = 0;
+ while($row1 = $hash_array_db->fetchArray(SQLITE3_NUM)){
+ $hash_ar[$count] = $row1[0];
+ $count++;
+ }
+
+ $count = 0;
+
+ for($i=0; $i<count($hash_ar); $i++){
+ $file_id_owner_db = $db->query("SELECT id, owner FROM files WHERE folder='FILE' AND hash=".$hash_ar[$i].";");
+ while($row2 = $file_id_owner->fetchArray(SQLITE3_NUM)){
+ if($row2[1] != $_SESSION["userid"]){
+ $saved_files[$count] = $hash_ar[$i];
+ }
+ $count++;
+ }
+ }
+
+ for($i=0; $i<count($saved_files); $i++){
+ $cur = $saved_files[$i]:
+ for($j=0;$j<count($hash_ar); $j++){
+ if($cur == $hash_ar[$j]){
+ $hash_ar[$j] = "";
+ }
+ }
+ }
+
+ for($i=0; $<count($hash_ar); $i++){
+ if(!unlink($uploaddir.$hash_ar[$i].".gz")){
+ return DELETE_USER_FILE_DELETE;
+ }
+ }
+
+ if($db->exec("
+ BEGIN TRANSACTION;
+ DELETE FROM user WHERE id=".$owner.";
+ COMMIT;
+ ")){
+ return DELETE_USER_SUCCESS;
+ } else {
+ return DELETE_USER_DATABASE;
+ }
+}