From 0cc882060c19c20af110616d19f9e29f772ac97b Mon Sep 17 00:00:00 2001 From: Theo Weijmer Date: Mon, 25 Dec 2017 20:23:32 +0100 Subject: [PATCH] users --- application/controllers/Main.php | 18 +-- application/controllers/Menu.php | 4 +- .../controllers/beheer/RolesController.php | 34 +++++ .../controllers/beheer/usersController.php | 33 ++++ application/core/MY_Controller.php | 9 +- application/models/eloquent/BaseModel.php | 55 +++++++ application/models/eloquent/Page.php | 22 ++- application/models/eloquent/Role.php | 46 ++++++ application/models/eloquent/User.php | 37 ++++- application/views/main_view.php | 45 +++--- application/views/modals/user_modal.php | 141 ++++++++++++++++++ application/views/pages/content.php | 3 + application/views/pages/dashboard_view.php | 1 + .../views/pages/login/dashboard_view.php | 1 + application/views/pages/login/login_view.php | 3 +- application/views/pages/projects_view.php | 1 + application/views/pages/users_view.php | 44 ++++++ application/views/partials/_content.php | 3 - application/views/partials/_css.php | 5 +- application/views/partials/_js.php | 13 +- application/views/partials/_modals.php | 6 + application/views/partials/_navbar-left.php | 4 +- public/css/correction.css | 4 + public/css/images/dbo-01-80x80.png | Bin 0 -> 4760 bytes public/css/main.css | 9 ++ public/js/lib/dataservices.js | 6 - public/js/lib/dataservices/pageDataservice.js | 18 +++ .../js/lib/dataservices/rolesDataservice.js | 23 +++ public/js/lib/dataservices/userDataservice.js | 33 ++++ public/js/lib/helpers.js | 13 ++ public/js/lib/main.js | 16 +- public/js/lib/modules/beheer/usersModule.js | 46 ++++++ public/js/lib/modules/login/loginModule.js | 2 +- public/js/lib/modules/menuModule.js | 38 ++++- public/js/lib/modules/modals/userModal.js | 118 +++++++++++++++ public/js/lib/pageDataservice.js | 13 -- 36 files changed, 781 insertions(+), 86 deletions(-) create mode 100644 application/controllers/beheer/RolesController.php create mode 100644 application/controllers/beheer/usersController.php create mode 100644 application/models/eloquent/BaseModel.php create mode 100644 application/models/eloquent/Role.php create mode 100644 application/views/modals/user_modal.php create mode 100644 application/views/pages/content.php create mode 100644 application/views/pages/dashboard_view.php create mode 100644 application/views/pages/login/dashboard_view.php create mode 100644 application/views/pages/projects_view.php create mode 100644 application/views/pages/users_view.php delete mode 100644 application/views/partials/_content.php create mode 100644 application/views/partials/_modals.php create mode 100644 public/css/images/dbo-01-80x80.png create mode 100644 public/css/main.css delete mode 100644 public/js/lib/dataservices.js create mode 100644 public/js/lib/dataservices/pageDataservice.js create mode 100644 public/js/lib/dataservices/rolesDataservice.js create mode 100644 public/js/lib/dataservices/userDataservice.js create mode 100644 public/js/lib/helpers.js create mode 100644 public/js/lib/modules/beheer/usersModule.js create mode 100644 public/js/lib/modules/modals/userModal.js delete mode 100644 public/js/lib/pageDataservice.js 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 @@ + + ** De Beleidsonderzoeker ** load->view( 'partials/_css' ); ?> @@ -20,28 +22,33 @@ + +load->view('partials/_modals'); ?> + + load->view( 'partials/_navbar-left' ); ?> - - subpages ) == 0 ): ?> - -
- load->view( 'partials/_content', ['pageurl' => $page->pageurl] ); ?> -
- - - subpages as $subpage ): ?> - -
- load->view( 'partials/_content', ['pageurl' => $subpage->pageurl] ); ?> + diff --git a/application/views/modals/user_modal.php b/application/views/modals/user_modal.php new file mode 100644 index 0000000..d8549c7 --- /dev/null +++ b/application/views/modals/user_modal.php @@ -0,0 +1,141 @@ + \ No newline at end of file diff --git a/application/views/pages/content.php b/application/views/pages/content.php new file mode 100644 index 0000000..5efd6cb --- /dev/null +++ b/application/views/pages/content.php @@ -0,0 +1,3 @@ +
+ load->view( 'pages/' . strtolower( $pageurl ) . '_view' ); ?> +
\ No newline at end of file diff --git a/application/views/pages/dashboard_view.php b/application/views/pages/dashboard_view.php new file mode 100644 index 0000000..9a9b30b --- /dev/null +++ b/application/views/pages/dashboard_view.php @@ -0,0 +1 @@ +

DASHBOARD

\ No newline at end of file diff --git a/application/views/pages/login/dashboard_view.php b/application/views/pages/login/dashboard_view.php new file mode 100644 index 0000000..9a9b30b --- /dev/null +++ b/application/views/pages/login/dashboard_view.php @@ -0,0 +1 @@ +

DASHBOARD

\ No newline at end of file diff --git a/application/views/pages/login/login_view.php b/application/views/pages/login/login_view.php index 9f102d6..b4943c1 100644 --- a/application/views/pages/login/login_view.php +++ b/application/views/pages/login/login_view.php @@ -9,8 +9,7 @@ Login V3 | Remark Admin Template - - + diff --git a/application/views/pages/projects_view.php b/application/views/pages/projects_view.php new file mode 100644 index 0000000..2c10887 --- /dev/null +++ b/application/views/pages/projects_view.php @@ -0,0 +1 @@ +

projects

\ No newline at end of file diff --git a/application/views/pages/users_view.php b/application/views/pages/users_view.php new file mode 100644 index 0000000..5122fde --- /dev/null +++ b/application/views/pages/users_view.php @@ -0,0 +1,44 @@ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
voornaamachternaamtussenvoegselgebruikersnaamemailrol 
+ + + + +
+ +
+
+
+
\ No newline at end of file diff --git a/application/views/partials/_content.php b/application/views/partials/_content.php deleted file mode 100644 index cf355f2..0000000 --- a/application/views/partials/_content.php +++ /dev/null @@ -1,3 +0,0 @@ -
-

-
\ No newline at end of file diff --git a/application/views/partials/_css.php b/application/views/partials/_css.php index ea3b354..efe51c1 100644 --- a/application/views/partials/_css.php +++ b/application/views/partials/_css.php @@ -3,7 +3,9 @@ - + + + @@ -15,6 +17,7 @@ + \ No newline at end of file diff --git a/application/views/partials/_js.php b/application/views/partials/_js.php index f6c1cf8..78ee7a4 100644 --- a/application/views/partials/_js.php +++ b/application/views/partials/_js.php @@ -49,4 +49,15 @@ - \ No newline at end of file + + + + + + + + + + + + \ No newline at end of file diff --git a/application/views/partials/_modals.php b/application/views/partials/_modals.php new file mode 100644 index 0000000..039d929 --- /dev/null +++ b/application/views/partials/_modals.php @@ -0,0 +1,6 @@ +load->view('modals/user_modal'); + +?> + diff --git a/application/views/partials/_navbar-left.php b/application/views/partials/_navbar-left.php index 291923e..af72c85 100644 --- a/application/views/partials/_navbar-left.php +++ b/application/views/partials/_navbar-left.php @@ -6,7 +6,7 @@ subpages ) == 0 ): ?> - @@ -14,7 +14,7 @@ pagename ?>