From e12c771abf0b546576f56858474ec0eda49555ed Mon Sep 17 00:00:00 2001 From: addhen Date: Tue, 7 Oct 2008 08:41:38 +0000 Subject: [PATCH] Fixed issues with role names not showing properly on the users display page. --- .htaccess | 2 +- application/config/config.php | 2 +- application/controllers/admin/users.php | 1 + application/models/roles_user.php | 4 +++- application/views/admin/users.php | 23 +++++++++++++++-------- application/views/admin/users_js.php | 4 ++-- 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/.htaccess b/.htaccess index 7e8ca77014..b582118daa 100644 --- a/.htaccess +++ b/.htaccess @@ -2,7 +2,7 @@ RewriteEngine On # Installation directory -RewriteBase / +RewriteBase /ushahidi # Protect application and system files from being viewed # RewriteRule ^(application|modules|system) - [F,L] diff --git a/application/config/config.php b/application/config/config.php index 6756011d97..c2dbbef4a6 100755 --- a/application/config/config.php +++ b/application/config/config.php @@ -4,7 +4,7 @@ * then a full URL will be used, eg: http://localhost/ushahidi/. If it only includes * the path, and a site_protocol is specified, the domain will be auto-detected. */ -$config['site_domain'] = '/'; +$config['site_domain'] = '/ushahidi/'; /** * Force a default protocol to be used by the site. If no site_protocol is diff --git a/application/controllers/admin/users.php b/application/controllers/admin/users.php index 973888ac96..c1cbfd780f 100644 --- a/application/controllers/admin/users.php +++ b/application/controllers/admin/users.php @@ -151,6 +151,7 @@ function index() $this->template->content->total_items = $pagination->total_items; $this->template->content->users = $users; $this->template->content->roles = $roles; + $this->template->content->roles_users = $this->roles_users; // Javascript Header diff --git a/application/models/roles_user.php b/application/models/roles_user.php index 72f07c536b..fe2275482e 100644 --- a/application/models/roles_user.php +++ b/application/models/roles_user.php @@ -17,7 +17,9 @@ public function __construct($id = NULL) */ public function get_role_id( $user_id ){ //TODO write necessary code to fetch role id specific to a user id. - + $this->db->where('user_id', $user_id ); + $query = $this->db->select('role_id')->from('roles_users')->get(); + return $query->current(); } /** diff --git a/application/views/admin/users.php b/application/views/admin/users.php index 08aacafdbb..88807816c5 100644 --- a/application/views/admin/users.php +++ b/application/views/admin/users.php @@ -118,12 +118,19 @@ $name = $user->name; $email = $user->email; - // Get Roles - foreach(ORM::factory('role')->find_all() as $role) - { - if ($user->has(new Role_Model($role->name))) - $role = $role->name; - } + //ORM can do much better, will look + // into it more. + //get role ids + $role_id = + $roles_users->get_role_id($user_id ); + + $roles = + ORM::factory('role')->where('id', + $role_id->role_id )->find(); + + //get role names + $role = $roles->name; + ?> @@ -142,13 +149,13 @@ '', '', '', - '', + 'role_id));?>', '')">Edit
  • Delete
  • diff --git a/application/views/admin/users_js.php b/application/views/admin/users_js.php index 143796190f..7f9efe2044 100644 --- a/application/views/admin/users_js.php +++ b/application/views/admin/users_js.php @@ -7,7 +7,7 @@ function fillFields(id, username, name, role, email) $("#user_id").attr("value", unescape(id)); $("#username").attr("value", unescape(username)); $("#name").attr("value", unescape(name)); - $('#role').attr("value",unescape( $('#role').val() ) ); + $('#role').attr("value",unescape( role ) ); $('#email').attr("value",unescape( email ) ); } @@ -26,7 +26,7 @@ function userAction ( action, user_id,username, $("#user_id").attr("value",user_id); $("#username").attr("value", unescape(username)); $("#name").attr("value", unescape(name)); - $('#role').attr("value",unescape( $('#role').val() ) ); + $('#role').attr("value",unescape( role ) ); $('#email').attr("value",unescape( email ) ); // Submit Form