diff --git a/components/permissions/class.permissions.php b/components/permissions/class.permissions.php index a4fa5c6..0180484 100644 --- a/components/permissions/class.permissions.php +++ b/components/permissions/class.permissions.php @@ -37,6 +37,12 @@ class Permissions { $level = self::LEVELS[$level]; } else { + exit( formatJSEND( "error", "Access Level does not exist." ) ); + } + } else { + + if( ! in_array( $level, self::LEVELS ) ) { + exit( formatJSEND( "error", "Access Level does not exist." ) ); } } @@ -46,19 +52,11 @@ class Permissions { public static function check_path( $level, $path ) { - if( ! in_array( $level, array_keys( self::LEVELS ) ) ) { - - exit( formatJSEND( "error", "Access Level does not exist." ) ); - } - - $pass = false; $user_level = self::get_access( $path ); - if( $user_level >= self::LEVELS[$level] ) { - - $pass = true; - } - return( $pass ); + echo var_dump( $level, $user_level, $path ); + + return self::check_access( $level, $user_level ); } public static function get_access( $path ) { @@ -100,7 +98,7 @@ class Permissions { } } - //echo var_dump( $full_path, $full_project_path, $path_postition, $user["level"], $pass ); + //echo var_dump( $full_path, $full_project_path, $path_postition, $user["level"], $data["owner"], $_SESSION["user"] ); if( $access > 0 ) { break; diff --git a/components/project/class.project.php b/components/project/class.project.php index e89ccab..2350866 100755 --- a/components/project/class.project.php +++ b/components/project/class.project.php @@ -117,6 +117,7 @@ class Project extends Common { public function check_duplicate( $full_path ) { + global $sql; $pass = true; $query = "SELECT id, path, owner FROM projects;"; $result = $sql->query( $query, array(), array(), "fetchAll" ); @@ -231,6 +232,26 @@ class Project extends Common { return( $return ); } + public function get_all_projects() { + + if( is_admin() ) { + + global $sql; + $query = "SELECT * FROM projects"; + $bind_variables = array(); + $return = $sql->query( $query, $bind_variables, array() ); + + if( empty( $return ) ) { + + $return = formatJSEND( "error", "Error fetching projects." ); + } + } else { + + $return = formatJSEND( "error", "Only admins are allowed to view all projects." ); + } + return( $return ); + } + public function get_projects() { global $sql; @@ -394,13 +415,14 @@ class Project extends Common { } if ( $this->path != '' ) { - if( ! $this->public_project && ! $this->isAbsPath( $this->path ) ) { + $user_path = WORKSPACE . '/' . preg_replace( '/[^\w-]/', '', strtolower( $_SESSION["user"] ) ); + + if( ! $this->isAbsPath( $this->path ) ) { - $user_path = WORKSPACE . '/' . preg_replace( '/[^\w-]/', '', strtolower( $_SESSION["user"] ) ); $this->path = $_SESSION["user"] . '/' . $this->path; } - $pass = $this->check_duplicate(); + $pass = $this->check_duplicate( $this->path ); if ( $pass ) { if( ! is_dir( $user_path ) ) { @@ -410,7 +432,10 @@ class Project extends Common { if ( ! $this->isAbsPath( $this->path ) ) { - mkdir( WORKSPACE . '/' . $this->path ); + if( ! is_dir( WORKSPACE . '/' . $this->path ) ) { + + mkdir( WORKSPACE . '/' . $this->path ); + } } else { if( ! is_admin() ) { @@ -520,7 +545,7 @@ class Project extends Common { global $sql; $query = "DELETE FROM projects WHERE path=?"; - $bind_variables = array( $this->path, $_SESSION["user"] ); + $bind_variables = array( $this->path ); $return = $sql->query( $query, $bind_variables, 0, "rowCount" ); if( $return > 0 ) { diff --git a/components/project/dialog.php b/components/project/dialog.php index 16d3af7..6d1416b 100755 --- a/components/project/dialog.php +++ b/components/project/dialog.php @@ -56,7 +56,12 @@ switch( $_GET['action'] ) { case 'list': //Get projects data - $projects = $Project->get_projects(); + if( isset( $_GET["all"] ) ) { + + $projects = $Project->get_all_projects(); + } else { + $projects = $Project->get_projects(); + } ?>