diff options
| author | moehm | 2014-03-21 18:40:44 +0100 |
|---|---|---|
| committer | moehm | 2014-03-21 18:40:44 +0100 |
| commit | cd7aeaef26bf05e42e789da6bc4a97118c40d616 (patch) | |
| tree | 1a253657f8ee29fb09dd9b9f03251b0ee6eae41a /www/functions/func_content.php | |
| parent | 08e945b89d649759f40916877f40044657314d9a (diff) | |
| download | files.iamfabulous.de-cd7aeaef26bf05e42e789da6bc4a97118c40d616.tar.gz | |
The index.php starts the download. Also extra function to print empty folders.
Diffstat (limited to 'www/functions/func_content.php')
| -rwxr-xr-x | www/functions/func_content.php | 87 |
1 files changed, 75 insertions, 12 deletions
diff --git a/www/functions/func_content.php b/www/functions/func_content.php index f7c4629..c750554 100755 --- a/www/functions/func_content.php +++ b/www/functions/func_content.php @@ -1,5 +1,23 @@ <?php +function collect_content($db,$username, $folder_path){ + $owner = user_id($db, $username); + + if(!$owner){ + failure("This user doesn't exist!"); + } + + $file_id = select_file_id($db, $owner, $folder_path); + + if(!$file_id){ + print_empty_folder($db, $username, $folder_path); + } + + $content = get_content($db, $file_id, $owner); + + return $content; +} + function get_content($db, $file_id, $owner){ $content_db = $db->query("SELECT * FROM files WHERE parent=" . $file_id . " AND owner=" . $owner . ";"); @@ -19,21 +37,66 @@ function get_content($db, $file_id, $owner){ $count++; } -/* - var_dump($content); exit; - if($content[0][4] == "FILE"){ - if(!start_file_download($username, $folder_path)){ - echo "False!"; exit; - return false; - } else { - echo "True!"; exit; - return true; - } - } -*/ if(!empty($content)){ return $content; // returns everything listed in the folder which is commited as parameter } else { return false; // empty folder } } + +function get_path_to_empty_folder($db, $username, $folder_path){ + + if($_SESSION["login"] && $_SESSION["userid"] == $owner){ + if($_SESSION["login"] && $_SESSION["userid"] == $owner){} + } else { + $share ="AND share='PUBLIC'"; + } + + $folder_array_unsafe = explode("/",$folder_path); + $length = count($folder_array_unsafe); + + $root_db = $db->query("SELECT id FROM files WHERE parent=0 AND owner=" . SQLite3::escapeString($owner) . " AND fo lder='DIRECTORY' " . $share . ";"); + $root_ar = $root_db->fetchArray(SQLITE3_NUM); + $root_id = $root_ar[0]; + + if(empty($root_id[0])){ + return NOT_PUBLIC; + } + + $parentdir = $root_id; + + for($i=0; $i<$length; $i++){ + $parentdir_db = $db->query("SELECT id, parent FROM files WHERE owner=" . $owner . $share . " AND parent=" . $parentdir . " AND name='" . SQLite3::escapeString($folder_array_unsafe[$i]) . "';"); + $prim_id = $parentdir_db->fetchArray(SQLITE3_NUM); + + if($parentdir != $prim_id[1]){ + $wrong_folder = $folder_array_unsafe[$i]; + $working_path[0] = $wrong_folder; + + for($j=0; $j<$i; $j++){ + $working_path[$j] = $folder_array_unsafe[$j]; + } + + $lwp = count($working_path); + $working_path[$lwp] = $wrong_folder; + + return $working_path; // returns working path and wrong folder as an array + } + + } + + return false; +} + +function print_empty_folder($content){ + $length = count($content); + + $wrong_folder = $content[$length-1]; + $working_path[0] = $wrong_folder; // initialize empty array + + for($i=0; $i<$length-2, $i++){ + $working_path[$i] = $content[$i]; + } + + get_404($working_path, $wrong_folder); +} |
