From 833d72001d3df1680913759ff760708766618eb8 Mon Sep 17 00:00:00 2001
From: root
Date: Mon, 10 Mar 2014 15:31:56 +0100
Subject: starting to write the interface
---
tmp/select.php | 68 ++++++++++++++++++++++++++++++++++++++++++++
www/.functions.php.swp | Bin 0 -> 20480 bytes
www/.index.php.swp | Bin 12288 -> 12288 bytes
www/functions.php | 14 ++++-----
www/index.php | 7 +++--
www/interface_functions.php | 5 ++++
www/select.php | 68 --------------------------------------------
www/select_function.php | 23 +++++++++++++--
8 files changed, 103 insertions(+), 82 deletions(-)
create mode 100644 tmp/select.php
create mode 100644 www/.functions.php.swp
create mode 100644 www/interface_functions.php
delete mode 100644 www/select.php
diff --git a/tmp/select.php b/tmp/select.php
new file mode 100644
index 0000000..ffa12d1
--- /dev/null
+++ b/tmp/select.php
@@ -0,0 +1,68 @@
+
+
+session_start();
+
+if($_SESSION["login"]){
+ $share="";
+} else {
+ $share ="AND share='PUBLIC'";
+}
+
+$db = new SQLite3("../database/sqlite.db");
+
+function failure($reason){
+ echo "A 404 error occurred.
";
+ echo $reason;
+ exit;
+}
+
+if(!empty($_GET["name"])){
+ $user = $_GET["name"];
+} else {
+ failure("No user input.");
+}
+
+$owner_db = $db->query("SELECT id FROM user WHERE name='" . SQLite3::escapeString($user) . "';");
+
+if(empty($owner_db)){
+ failure("This user doesn't exist.");
+}
+
+$owner_ar = $owner_db->fetchArray(SQLITE3_NUM);
+$owner = $owner_ar[0];
+
+$folder_array_unsafe = explode("/",$_GET["folder"]);
+$length = count($folder_array_unsafe);
+
+
+$root_db = $db->query("SELECT id FROM files WHERE parent=0 AND owner=" . $owner . " AND folder='DIRECTORY' " . $share . ";");
+if(empty($root_db)){
+ failure("There is something seriously wrong. If you are a human you should never read this. Mail the admin please.");
+}
+$root_ar = $root_db->fetchArray(SQLITE3_NUM);
+$root_id = $root_ar[0];
+$parentdir = SQLite3::escapeString($root_id);
+$temp_id = $root_id;
+
+
+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]) . "';");
+ if(empty($parentdir_db)){
+ failure("Database error.");
+ }
+ $prim_id = $parentdir_db->fetchArray(SQLITE3_NUM);
+ if($parentdir != $prim_id[1]){
+ failure("This folder doesn't exist. Folder: " . $folder_array_unsafe[$i]);
+ }
+
+ $parentdir = $prim_id[0];
+ echo SQLite3::escapeString($folder_array_unsafe[$i]);
+
+ echo "
";
+ }
+}
+
+$content_db = $db->query("SELECT id, name, folder FROM files WHERE parent=" . $parentdir . " AND owner=" . $owner . ";");
+$content_ar = $conten_db->fetchArray(SQLITE3_NUM);
diff --git a/www/.functions.php.swp b/www/.functions.php.swp
new file mode 100644
index 0000000..51599d7
Binary files /dev/null and b/www/.functions.php.swp differ
diff --git a/www/.index.php.swp b/www/.index.php.swp
index 7dc5069..ea0fadf 100644
Binary files a/www/.index.php.swp and b/www/.index.php.swp differ
diff --git a/www/functions.php b/www/functions.php
index c1cdca6..96f4010 100644
--- a/www/functions.php
+++ b/www/functions.php
@@ -2,7 +2,7 @@
/* --LOGIN-- */
-require_once("select_functions.php");
+require_once("select_function.php");
function login($db){
if($_SERVER['REQUEST_METHOD'] == 'POST') {
@@ -267,7 +267,7 @@ function get_404(){
*/
//}
-function show($db){
+function rewrite($db){
/* test if first argument a username or folder */
@@ -286,14 +286,10 @@ function show($db){
} else {
get_404();
}
- } else {
-
- /* everything was okay, so show the content, please */
-
- $content = select($db);
- return $content;
- //exit;
+ return false;
}
+
+ return true;
}
function failure($reason){
diff --git a/www/index.php b/www/index.php
index d1f86ee..77a29e6 100644
--- a/www/index.php
+++ b/www/index.php
@@ -3,6 +3,7 @@
session_start();
require_once("functions.php");
+require_once("interface_functions.php");
$db = new SQLite3("../database/sqlite.db");
@@ -49,7 +50,9 @@ if(empty($_GET)){
/* shows the user content, main function */
- $content = show($db);
- var_dump($content);
+ if(rewrite($db)){
+ $content = select($db);
+ show($content);
+ }
}
}
diff --git a/www/interface_functions.php b/www/interface_functions.php
new file mode 100644
index 0000000..0116fe6
--- /dev/null
+++ b/www/interface_functions.php
@@ -0,0 +1,5 @@
+
+
+function show($content){
+ var_dump($content);
+}
diff --git a/www/select.php b/www/select.php
deleted file mode 100644
index ffa12d1..0000000
--- a/www/select.php
+++ /dev/null
@@ -1,68 +0,0 @@
-
-
-session_start();
-
-if($_SESSION["login"]){
- $share="";
-} else {
- $share ="AND share='PUBLIC'";
-}
-
-$db = new SQLite3("../database/sqlite.db");
-
-function failure($reason){
- echo "A 404 error occurred.
";
- echo $reason;
- exit;
-}
-
-if(!empty($_GET["name"])){
- $user = $_GET["name"];
-} else {
- failure("No user input.");
-}
-
-$owner_db = $db->query("SELECT id FROM user WHERE name='" . SQLite3::escapeString($user) . "';");
-
-if(empty($owner_db)){
- failure("This user doesn't exist.");
-}
-
-$owner_ar = $owner_db->fetchArray(SQLITE3_NUM);
-$owner = $owner_ar[0];
-
-$folder_array_unsafe = explode("/",$_GET["folder"]);
-$length = count($folder_array_unsafe);
-
-
-$root_db = $db->query("SELECT id FROM files WHERE parent=0 AND owner=" . $owner . " AND folder='DIRECTORY' " . $share . ";");
-if(empty($root_db)){
- failure("There is something seriously wrong. If you are a human you should never read this. Mail the admin please.");
-}
-$root_ar = $root_db->fetchArray(SQLITE3_NUM);
-$root_id = $root_ar[0];
-$parentdir = SQLite3::escapeString($root_id);
-$temp_id = $root_id;
-
-
-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]) . "';");
- if(empty($parentdir_db)){
- failure("Database error.");
- }
- $prim_id = $parentdir_db->fetchArray(SQLITE3_NUM);
- if($parentdir != $prim_id[1]){
- failure("This folder doesn't exist. Folder: " . $folder_array_unsafe[$i]);
- }
-
- $parentdir = $prim_id[0];
- echo SQLite3::escapeString($folder_array_unsafe[$i]);
-
- echo "
";
- }
-}
-
-$content_db = $db->query("SELECT id, name, folder FROM files WHERE parent=" . $parentdir . " AND owner=" . $owner . ";");
-$content_ar = $conten_db->fetchArray(SQLITE3_NUM);
diff --git a/www/select_function.php b/www/select_function.php
index b83fe04..6e4bc66 100644
--- a/www/select_function.php
+++ b/www/select_function.php
@@ -1,3 +1,4 @@
+
function select($db){
if($_SESSION["login"]){
$share="";
@@ -47,9 +48,25 @@ function select($db){
}
}
- $content_db = $db->query("SELECT id, name, folder FROM files WHERE parent=" . $parentdir . " AND owner=" . $owner . ";");
- $content_ar = $conten_db->fetchArray(SQLITE3_NUM);
+// echo "parent: " . $parentdir . "
";
+ $content_db = $db->query("SELECT * FROM files WHERE parent=" . $parentdir . " AND owner=" . $owner . ";");
+// $content_ar = $content_db->fetchArray(SQLITE3_NUM);
- return $content_ar;
+ $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];
+ //echo "" . $content[$count][3] . "
";
+ $count++;
+ }
+
+ return $content;
}
--
cgit v1.2.3