From 2f0f4ca056f92ffd2bbf80e7b7c49b489d6e7ed4 Mon Sep 17 00:00:00 2001 From: Horus3 Date: Wed, 12 Mar 2014 22:11:50 +0100 Subject: more modular for greater flexibility --- www/functions/func_content.php | 27 ++++++++++++++++ www/functions/func_interface.php | 16 ++++++++- www/functions/func_login.php | 2 ++ www/functions/func_register.php | 4 +-- www/functions/func_select.php | 70 ++++++++++++---------------------------- www/functions/func_user.php | 13 +++++++- 6 files changed, 78 insertions(+), 54 deletions(-) create mode 100644 www/functions/func_content.php (limited to 'www/functions') diff --git a/www/functions/func_content.php b/www/functions/func_content.php new file mode 100644 index 0000000..2536dcc --- /dev/null +++ b/www/functions/func_content.php @@ -0,0 +1,27 @@ +query("SELECT * FROM files WHERE parent=" . $parentdir . " AND owner=" . $owner . ";"); + + $count=0; + + while($row = $content_db->fetchArray(SQLITE3_NUM)){ + $content[$count][0] = $row[0]; + $content[$count][1] = $row[1]; + $content[$count][2] = $row[2]; + $content[$count][3] = $row[3]; + $content[$count][4] = $row[4]; + $content[$count][5] = $row[5]; + $content[$count][6] = $row[6]; + $content[$count][7] = $row[7]; + $content[$count][8] = $row[8]; + $count++; + } + + if(!empty($content)){ + return $content; + } else { + return false; + } +} diff --git a/www/functions/func_interface.php b/www/functions/func_interface.php index 0116fe6..b7fbb5f 100644 --- a/www/functions/func_interface.php +++ b/www/functions/func_interface.php @@ -1,5 +1,19 @@ query("SELECT id FROM user WHERE name='" . SQLite3::escapeString($user) . "';"); - $owner_ar = $owner_db->fetchArray(SQLITE3_NUM); - if(empty($owner_ar)){ - failure("This user doesn't exist."); - } - - $owner = $owner_ar[0]; - + $folder_array_unsafe = explode("/",$_GET["folder"]); $length = count($folder_array_unsafe); @@ -32,49 +19,34 @@ function select($db){ $parentdir = SQLite3::escapeString($root_id); $temp_id = $root_id; + if(empty($folder_array_unsafe[$i])){ + + } for($i=0; $i<$length; $i++){ - if(!empty($folder_array_unsafe[$i])){ - $parentdir_db = $db->query("SELECT id, parent FROM files WHERE owner=" . $owner . " AND folder='DIRECTORY' " . $share . " AND parent=" . $parentdir . " AND name='" . SQLite3::escapeString($folder_array_unsafe[$i]) . "';"); - - $prim_id = $parentdir_db->fetchArray(SQLITE3_NUM); - if(empty($prim_id)){ - failure("Database error."); - } + $parentdir_db = $db->query("SELECT id, parent FROM files WHERE owner=" . $owner . " AND folder='DIRECTORY' " . $share . " AND parent=" . $parentdir . " AND name='" . SQLite3::escapeString($folder_array_unsafe[$i]) . "';"); - if($parentdir != $prim_id[1]){ + $prim_id = $parentdir_db->fetchArray(SQLITE3_NUM); + if(empty($prim_id)){ + failure("Database error."); + } - $wrong_folder = $folder_array_unsafe[$i]; - $working_path[0] = $wrong_folder; + if($parentdir != $prim_id[1]){ - for($j=0; $j<$i; $j++){ - $working_path[$j] = $folder_array_unsafe[$j]; - } + $wrong_folder = $folder_array_unsafe[$i]; + $working_path[0] = $wrong_folder; - get_404($working_path, $wrong_folder); - return false; + for($j=0; $j<$i; $j++){ + $working_path[$j] = $folder_array_unsafe[$j]; } - $parentdir = $prim_id[0]; + get_404($working_path, $wrong_folder); + return false; } - } - - $content_db = $db->query("SELECT * FROM files WHERE parent=" . $parentdir . " AND owner=" . $owner . ";"); - $count=0; - while($row = $content_db->fetchArray(SQLITE3_NUM)){ - $content[$count][0] = $row[0]; - $content[$count][1] = $row[1]; - $content[$count][2] = $row[2]; - $content[$count][3] = $row[3]; - $content[$count][4] = $row[4]; - $content[$count][5] = $row[5]; - $content[$count][6] = $row[6]; - $content[$count][7] = $row[7]; - $content[$count][8] = $row[8]; - $count++; + $parentdir = $prim_id[0]; } - return $content; + return $parentdir; } diff --git a/www/functions/func_user.php b/www/functions/func_user.php index 2e49651..59e6dda 100644 --- a/www/functions/func_user.php +++ b/www/functions/func_user.php @@ -1,5 +1,5 @@ query("SELECT invites FROM user WHERE name='" . $safe_name . "';"); @@ -11,3 +11,14 @@ function user($db){ return true; } +function user($db, $user){ + + $owner_db = $db->query("SELECT id FROM user WHERE name='" . SQLite3::escapeString($user) . "';"); + $owner_ar = $owner_db->fetchArray(SQLITE3_NUM); + if(empty($owner_ar)){ + return false; + } + + $owner = $owner_ar[0]; + return $owner; +} -- cgit v1.2.3