diff --git a/application/controllers/Main.php b/application/controllers/Main.php index cde34be..0299dab 100755 --- a/application/controllers/Main.php +++ b/application/controllers/Main.php @@ -1,5 +1,5 @@ showLoginPage(); + public function index() + { + if ( AUTHENTICATED == FALSE ) return $this->showLoginPage(); - $pages = Page::getPages(); + $pages = Page::getPages( $this->user ); - $this->load->view('main_view', ['pages'=>$pages]); - } + $this->load->view( 'main_view', ['pages' => $pages] ); + } private function showLoginPage() { - $this->load->view('pages/login/login_view'); - } + $this->load->view( 'pages/login/login_view' ); + } } diff --git a/application/controllers/Menu.php b/application/controllers/Menu.php index 4b9bebf..d3c60d2 100644 --- a/application/controllers/Menu.php +++ b/application/controllers/Menu.php @@ -15,7 +15,9 @@ class Menu extends MY_Controller { public function getAppPages() { - $appPages = Page + $appPages = Page::getAppPages( $this->user ); + + $this->json( $appPages ); } } \ No newline at end of file diff --git a/application/controllers/beheer/RolesController.php b/application/controllers/beheer/RolesController.php new file mode 100644 index 0000000..db824f2 --- /dev/null +++ b/application/controllers/beheer/RolesController.php @@ -0,0 +1,34 @@ +load->model( $models ); + $this->load->library( $libraries ); + } + + public function index() + { + + } + + public function getAllRoles( $archive = 'F' ) + { + $roles = Role::getAllRoles( $archive ); + + $this->json( $roles ); + } + +} \ No newline at end of file diff --git a/application/controllers/beheer/usersController.php b/application/controllers/beheer/usersController.php new file mode 100644 index 0000000..706b702 --- /dev/null +++ b/application/controllers/beheer/usersController.php @@ -0,0 +1,33 @@ +load->model( $models ); + $this->load->library( $libraries ); + } + + public function index() + { + + } + + public function getAllUsers( $archive = 'F' ) + { + $users = User::getAllUsers( $archive ); + + $this->json( $users ); + } +} \ No newline at end of file diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php index 31e6b32..11a0b8f 100644 --- a/application/core/MY_Controller.php +++ b/application/core/MY_Controller.php @@ -9,6 +9,7 @@ class MY_Controller extends CI_Controller { public $authenticated; + public $user; public function __construct() { @@ -22,20 +23,22 @@ class MY_Controller extends CI_Controller { private function handle() { $this->retrieveusersession->handle(); + + $this->user = $this->User_model->get( USERID ); } function clean_input( $post ) { $value = $this->input->input_stream( $post, TRUE ); - $denulledValue = str_replace( 'null', '', $value); + $denulledValue = str_replace( 'null', '', $value ); return $denulledValue; } - public function json($data) + public function json( $data ) { - echo json_encode($data); + echo json_encode( $data ); } } \ No newline at end of file diff --git a/application/models/eloquent/BaseModel.php b/application/models/eloquent/BaseModel.php new file mode 100644 index 0000000..20612ea --- /dev/null +++ b/application/models/eloquent/BaseModel.php @@ -0,0 +1,55 @@ +created_by = $user->username; + $model->updated_by = $user->username; + } + } ); + static::updating( function ( $model ) { + if ( AUTHENTICATED ) + { + $user = User::find(USERID); + $model->updated_by = $user->username; + } + } ); + + } +} \ No newline at end of file diff --git a/application/models/eloquent/Page.php b/application/models/eloquent/Page.php index a265baf..7603b45 100644 --- a/application/models/eloquent/Page.php +++ b/application/models/eloquent/Page.php @@ -18,20 +18,28 @@ class Page extends Eloquent { } - public static function getPages($user) + public static function getPages( $user ) { - $pages = Page::whereRaw( 'id = page_id AND ' ) - ->with( ['subpages' => function($q){ - $q->whereRaw('id != page_id'); - }] ) + $pages = Page::whereRaw( 'id = page_id' ) + ->with( [ + 'subpages' => function ( $q ) use ( $user ) { + $q->whereRaw( + "id != page_id AND ((SELECT {$user->role} & pagelevel) != 0 OR pagelevel = 0)" ); + }] ) ->get(); return $pages; } - public static function getAppPages() + public static function getAppPages( $user ) { - $appPages = Page::whereRaw + $appPages = Page::select( 'id', 'pageurl' ) + ->whereAppPage( 'T' ) + ->whereRaw( + "((SELECT {$user->role} & pagelevel) != 0 OR pagelevel = 0)" ) + ->get(); + + return $appPages; } diff --git a/application/models/eloquent/Role.php b/application/models/eloquent/Role.php new file mode 100644 index 0000000..06e585a --- /dev/null +++ b/application/models/eloquent/Role.php @@ -0,0 +1,46 @@ +hasOne( 'User', 'role', 'rolelevel' ); + } + + public static function getAllRoles( $archive ) + { + $roleHierarchy = Role::getUserroleHierachy(); + + $roles = Role::orderBy( 'rolehierarchy' ) + ->where( 'rolehierarchy', '>=', $roleHierarchy ); + + if ( $archive == 'F' ) $roles = $roles->whereArchive( 'F' ); + + $roles = $roles->get(); + + return $roles; + } + + public static function getUserroleHierachy() + { + $userrole = User::getUserRoleHierarchy(); + + if( $userrole == 0 ) return 0; + + $roleHierarchy = Role::whereRolelevel($userrole) + ->first() + ->rolehierarchy; + + return $roleHierarchy; + } + + +} \ No newline at end of file diff --git a/application/models/eloquent/User.php b/application/models/eloquent/User.php index 30bea4f..af24183 100644 --- a/application/models/eloquent/User.php +++ b/application/models/eloquent/User.php @@ -7,12 +7,43 @@ */ -use \Illuminate\Database\Eloquent\Model as Eloquent; - -class User extends Eloquent { +class User extends BaseModel { protected $table = "users"; + public function role() + { + return $this->belongsTo( 'Role', 'level', 'rolelevel' ); + } + + public static function getAllUsers( $archive ) + { + $users = User::orderBy( 'lastname' ); + + if ( $archive == 'F' ) $users = $users->whereArchive( 'F' ); + + $users = $users->get(); + + return $users; + } + + public static function getUserRoleHierarchy() + { + $userrole = User::find( USERID )->role; + + return $userrole; + } + + public static function checkUsername( $username ) + { + $username = strtoupper( $username ); + + $user = User::whereRaw( "UCASE(username) = {$username}" ); + + if ( $user->count() == 0 ) return FALSE; + + return TRUE; + } } \ No newline at end of file diff --git a/application/views/main_view.php b/application/views/main_view.php index 88f651f..9e3a022 100644 --- a/application/views/main_view.php +++ b/application/views/main_view.php @@ -9,6 +9,8 @@ + +