query("SELECT id FROM files WHERE parent=0 AND owner=" . $owner . " AND folder='DIRECTORY' " . $share . ";"); $root_ar = $root_db->fetchArray(SQLITE3_NUM); $root_id = $root_ar[0]; if(empty($root_ar)){ failure("Seems like the user doesn't want to show his tree: " . $root_id); } $parentdir = SQLite3::escapeString($root_id); $temp_id = $root_id; if(empty($folder_array_unsafe)){ return $root_id; } for($i=0; $i<$length; $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]) . "';"); if(empty($folder_array_unsafe[$i])){ return $parentdir; // TODO: Is there a way this can happen? } $prim_id = $parentdir_db->fetchArray(SQLITE3_NUM); if(empty($prim_id)){ failure("Database error."); } 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]; } get_404($working_path, $wrong_folder); return false; } $parentdir = $prim_id[0]; } return $parentdir; // returns the primary key from the last entry in the folder array }