diff options
Diffstat (limited to 'public_html/class')
| -rw-r--r-- | public_html/class/vfsdata.php | 79 | ||||
| -rw-r--r-- | public_html/class/vfsuser.php | 3 |
2 files changed, 82 insertions, 0 deletions
diff --git a/public_html/class/vfsdata.php b/public_html/class/vfsdata.php new file mode 100644 index 0000000..1d35384 --- /dev/null +++ b/public_html/class/vfsdata.php @@ -0,0 +1,79 @@ +<?php + +class vfsdata { + + protected $folder_path; + protected $current_user; + protected $userid; + + public function __construct($user, $folderpath){ + $this->current_user = $user; + $this->folder_path = $folderpath; + + return true; + } + + public function setFolderPath($folder){ + $this->folder_path = $folder; + } + + public function setCurrentUser($user){ + $this->current_user = $user; + } + + protected function _getRoot($user, $folderpath, $visbility){ + $folder_array = explode('/', $this->folder_path); + + $sql = $vfsdb->prepare("SELECT id FROM files WHERE parent=0 AND type='DIRECTORY' and owner = %s " . $visibility . ";", $this->owner); + $root_db = $vfsdb->doQuery($sql); + $root_ar = $root_db->fetch_array(MYSQLI_ASSOC); + $root_id = $root_ar["id"]; + + return $root_id; + } + + public function getId($user = NULL, $folder = NULL){ + global $vfsuser; + + if ( is_null($user) ) + $user = $this->current_user; + + if ( is_null($folder) ) + $folder = $this->folder_path; + + $this->userid = $vfsuser->getUserId(); + + # checks if the current user is the actual owner + if ( $vfsuser->isLoggedIn() && $_SESSION["userid"] == $this->userid ) + $visibility = ""; + else + $visibility = " AND visibility='PUBLIC'"; + + $tmp_length = count($folder); + + if ( empty($folder[$tmp_length-1]) ) + $length = $tmp_length-1; + else + $length = $tmp_length; + + $parentdir = $this->_getRoot($user, $folder, $visibility); + + if ( empty($folder[0]) ) + return $parentdir; + + for ( $i=0; $i<$length, $i++ ) { + $sql = $vfsdb->prepare("SELECT id, parent FROM files WHERE owner = %d AND parent = %d AND name = %s ".$visibility. ";", $this->userid, $parentdir, $folder[$i]); + $parentdir_db = $vfsdb->doQuery($sql); + + $prim_id = $parentdir_db->fetch_array(MYSQLI_ASSOC); + + if ( $parentdir != $prim_id["parent"] ) + return false; + + $parentdir = $prim_id["parent"]; + } + + # returns the primary key from the last entry in the $folder array + return $parentdir; + } +} diff --git a/public_html/class/vfsuser.php b/public_html/class/vfsuser.php index e3767b8..c0bc83f 100644 --- a/public_html/class/vfsuser.php +++ b/public_html/class/vfsuser.php @@ -108,6 +108,9 @@ class vfsuser { # set session variable to true $_SESSION["loggedin"] = true; + # assign userid to the session variable + $_SESSION["userid"] = $this->getUserId(); + return true; } |
