@@ -141,12 +141,18 @@ public function remove_group_from_user($userid, $groupid) {
141141 }
142142 }
143143
144- public function check_module_permissions ($ module ) {
144+
145+ /**
146+ * Check that the user has access to the given module.
147+ *
148+ * @return boolean
149+ */
150+ public function verify_module_permissions ($ module ) {
145151 // Check if the current user has the permissions to access this module
146152 $ module = trim (preg_replace ('@\s+@ ' , '' , $ module ));
147153 $ user_modules = explode (', ' ,$ _SESSION ["s " ]["user " ]["modules " ]);
154+ $ can_use_module = false ;
148155 if (strpos ($ module , ', ' ) !== false ){
149- $ can_use_module = false ;
150156 $ tmp_modules = explode (', ' , $ module );
151157 if (is_array ($ tmp_modules ) && !empty ($ tmp_modules )){
152158 foreach ($ tmp_modules as $ tmp_module ){
@@ -158,17 +164,21 @@ public function check_module_permissions($module) {
158164 }
159165 }
160166 }
161- if (!$ can_use_module ){
162- // echo "LOGIN_REDIRECT:/index.php";
163- header ("Location: /index.php " );
164- exit ;
165- }
166- } else {
167- if (!in_array ($ module ,$ user_modules )) {
168- // echo "LOGIN_REDIRECT:/index.php";
169- header ("Location: /index.php " );
170- exit ;
171- }
167+ }
168+ elseif (in_array ($ module ,$ user_modules )) {
169+ $ can_use_module = true ;
170+ }
171+ return $ can_use_module ;
172+ }
173+
174+ /**
175+ * Check that the user has access to the given module, redirect and exit on failure.
176+ */
177+ public function check_module_permissions ($ module ) {
178+ if (!$ this ->verify_module_permissions ($ module )) {
179+ // echo "LOGIN_REDIRECT:/index.php";
180+ header ("Location: /index.php " );
181+ exit ;
172182 }
173183 }
174184
0 commit comments