|
From: Jon O. <jon...@us...> - 2005-04-12 21:10:43
|
Update of /cvsroot/mxbb/core/includes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29720/includes Modified Files: mx_auth.php Log Message: i have renamed mx_auth_group_cache to mx_auth_group and removed old function with shorter name ;) ...to make it clearer Index: mx_auth.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/mx_auth.php,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** mx_auth.php 6 Mar 2005 01:10:14 -0000 1.4 --- mx_auth.php 12 Apr 2005 21:10:33 -0000 1.5 *************** *** 1,514 **** ! <?php ! /** ------------------------------------------------------------------------ ! * subject : mx-portal, CMS & portal ! * begin : june, 2002 ! * copyright : (C) 2002-2005 MX-System ! * email : jon...@ho... ! * project site : www.mx-system.com ! * ! * description : ! * ------------------------------------------------------------------------- ! * ! * $Id$ ! */ ! ! /** ! * This program is free software; you can redistribute it and/or modify ! * it under the terms of the GNU General Public License as published by ! * the Free Software Foundation; either version 2 of the License', or ! * ('at your option) any later version. ! */ ! ! /** ! * Included functions in this file: ! * - block_auth ! * - page_auth ! * - menu_auth ! * - mx_auth_check_user (from auth.php - validated for phpbb 2.0.10) ! * - get_auth_forum ! * - mx_auth_group ! */ ! ! /* ! $type's accepted (pre-pend with AUTH_): ! VIEW, READ, POST, REPLY, EDIT, DELETE, STICKY, ANNOUNCE, VOTE, POLLCREATE ! ! Possible options ($type/module_id combinations): ! ! * If you include a type and module_id then a specific lookup will be done and ! the single result returned ! ! * If you set type to AUTH_ALL and specify a module_id an array of all auth types ! will be returned ! ! * If you provide a module_id a specific lookup on that module will be done ! ! * If you set module_id to AUTH_LIST_ALL and specify a type an array listing the ! results for all modules will be returned ! ! * If you set module_id to AUTH_LIST_ALL and type to AUTH_ALL a multidimensional ! array containing the auth permissions for all types and all modules for that ! user is returned ! ! All results are returned as associative arrays, even when a single auth type is ! specified. ! ! If available you can send an array (either one or two dimensional) containing the ! module auth levels, this will prevent the auth function having to do its own ! lookup ! */ ! function block_auth( $type, $module_id, $userdata, $f_access = '', $f_access_group = '' ) ! { ! global $db, $lang; ! ! switch ( $type ) ! { ! // case AUTH_ALL: ! // $a_sql = 'a.auth_view, a.auth_edit, a.auth_delete'; ! // $a_sql_groups = 'a.auth_view_group, a.auth_edit_group, a.auth_delete_group'; ! // $auth_fields = array( 'auth_view', 'auth_edit', 'auth_delete' ); ! // $auth_fields_groups = array( 'auth_view_group', 'auth_edit_group', 'auth_delete_group' ); ! // break; ! ! case AUTH_VIEW: ! $a_sql = 'a.auth_view'; ! $a_sql_groups = 'a.auth_view_group'; ! $auth_fields = array( 'auth_view' ); ! $auth_fields_groups = array( 'auth_view_group' ); ! break; ! ! case AUTH_EDIT: ! $a_sql = 'a.auth_edit'; ! $a_sql_groups = 'a.auth_edit_group'; ! $auth_fields = array( 'auth_edit' ); ! $auth_fields_groups = array( 'auth_edit_group' ); ! break; ! ! case AUTH_DELETE: ! $a_sql = 'a.auth_delete'; ! $a_sql_groups = 'a.auth_delete_group'; ! $auth_fields = array( 'auth_delete' ); ! $auth_fields_groups = array( 'auth_delete_group' ); ! break; ! ! default: ! break; ! } ! ! if ( $module_id == 0 ) ! { ! if ( $userdata['user_level'] == ADMIN && $userdata['session_logged_in'] ) ! { ! $auth_user[$auth_fields[0]] = 1; ! $auth_user[$auth_fields[0] . '_type'] = $lang['Auth_Moderators']; ! } ! else ! { ! $auth_user[$auth_fields[0]] = 0; ! $auth_user[$auth_fields[0] . '_type'] = $lang['Auth_Moderators']; ! } ! return $auth_user; ! } ! ! $is_admin = ( $userdata['user_level'] == ADMIN && $userdata['session_logged_in'] ) ? true : 0; ! ! $auth_user = array(); ! for( $i = 0; $i < count( $auth_fields ); $i++ ) ! { ! $key = $auth_fields[$i]; ! $key_groups = $auth_fields_groups[$i]; ! // If the user is logged on and the module type is either ALL or REG then the user has access ! // If the type if ACL, MOD or ADMIN then we need to see if the user has specific permissions ! // to do whatever it is they want to do ... to do this we pull relevant information for the ! // user (and any groups they belong to) ! // Now we compare the users access level against the modules. We assume here that a moderator ! // and admin automatically have access to an ACL module, similarly we assume admins meet an ! // auth requirement of MOD ! $value = $f_access[$key]; ! // $value_groups = $f_access_group[$key_groups]; ! $value_groups = $f_access_group; ! ! switch ( $value ) ! { ! case AUTH_ALL: ! $auth_user[$key] = true; ! $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; ! break; ! ! case AUTH_REG: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? true : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Registered_Users']; ! break; ! ! case AUTH_ANONYMOUS: ! $auth_user[$key] = ( ! $userdata['session_logged_in'] ) ? true : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; ! break; ! ! case AUTH_ACL: // PRIVATE ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group_cache( $value_groups ) || $is_admin : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Users_granted_access']; ! break; ! ! case AUTH_MOD: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group_cache( $f_access_group['auth_moderator_group'] ) || $is_admin : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Moderators']; ! break; ! ! case AUTH_ADMIN: ! $auth_user[$key] = $is_admin; ! $auth_user[$key . '_type'] = $lang['Auth_Administrators']; ! break; ! ! default: ! $auth_user[$key] = 0; ! break; ! } ! } ! // Is user a moderator? ! $auth_user['auth_mod'] = ( $userdata['session_logged_in'] ) ? mx_auth_group_cache( $f_access_group['auth_moderator_group'] ) || $is_admin : 0; ! ! return $auth_user; ! } ! ! function page_auth( $type, $userdata, $f_access = '', $f_access_group = '' ) ! { ! global $db, $lang; ! ! $a_sql = 'a.auth_view'; ! $a_sql_groups = 'a.auth_view_group'; ! $auth_fields = array( 'auth_view' ); ! $auth_fields_groups = array( 'auth_view_group' ); ! ! $is_admin = ( $userdata['user_level'] == ADMIN && $userdata['session_logged_in'] ) ? true : 0; ! ! $auth_user = array(); ! for( $i = 0; $i < count( $auth_fields ); $i++ ) ! { ! $key = $auth_fields[$i]; ! $key_groups = $auth_fields_groups[$i]; ! ! $value = $f_access[$key]; ! // $value_groups = $f_access_group[$key_groups]; ! $value_groups = $f_access_group; ! ! switch ( $value ) ! { ! case AUTH_ALL: ! $auth_user[$key] = true; ! $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; ! break; ! ! case AUTH_REG: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? true : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Registered_Users']; ! break; ! ! case AUTH_ANONYMOUS: ! $auth_user[$key] = ( ! $userdata['session_logged_in'] ) ? true : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; ! break; ! ! case AUTH_ACL: // PRIVATE ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group_cache( $value_groups ) || $is_admin : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Users_granted_access']; ! break; ! ! case AUTH_MOD: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group_cache( $f_access_group['auth_moderator_group'] ) || $is_admin : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Moderators']; ! break; ! ! case AUTH_ADMIN: ! $auth_user[$key] = $is_admin; ! $auth_user[$key . '_type'] = $lang['Auth_Administrators']; ! break; ! ! default: ! $auth_user[$key] = 0; ! break; ! } ! } ! // Is user a moderator? ! $auth_user['auth_mod'] = ( $userdata['session_logged_in'] ) ? mx_auth_group_cache( $f_access_group['auth_moderator_group'] ) || $is_admin : 0; ! ! return $auth_user; ! } ! // ************************************************************************** ! function menu_auth( $type, $menu_id, $userdata, $f_access = '', $f_access_group = '' ) ! { ! global $db, $lang; ! ! switch ( $type ) ! { ! case AUTH_ALL: ! $a_sql = 'a.auth_view'; ! $auth_fields = array( 'auth_view' ); ! break; ! ! case AUTH_VIEW: ! $a_sql = 'a.auth_view'; ! $auth_fields = array( 'auth_view' ); ! break; ! ! default: ! break; ! } ! // If f_access has been passed, or auth is needed to return an array of menus ! // then we need to pull the auth information on the given menu (or all menus) ! $is_admin = ( $userdata['user_level'] == ADMIN && $userdata['session_logged_in'] ) ? true : 0; ! ! $auth_user = array(); ! for( $i = 0; $i < count( $auth_fields ); $i++ ) ! { ! $key = $auth_fields[$i]; ! // If the user is logged on and the menu type is either ALL or REG then the user has access ! // If the type if ACL, MOD or ADMIN then we need to see if the user has specific permissions ! // to do whatever it is they want to do ... to do this we pull relevant information for the ! // user (and any groups they belong to) ! // Now we compare the users access level against the menus. We assume here that a moderator ! // and admin automatically have access to an ACL menu, similarly we assume admins meet an ! // auth requirement of MOD ! $value = $f_access[$key]; ! ! switch ( $value ) ! { ! case AUTH_ALL: ! $auth_user[$key] = true; ! $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; ! break; ! ! case AUTH_REG: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? true : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Registered_Users']; ! break; ! ! case AUTH_ANONYMOUS: ! $auth_user[$key] = ( ! $userdata['session_logged_in'] ) ? true : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; ! break; ! ! case AUTH_ACL: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group_cache( $f_access_group ) || $is_admin : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Users_granted_access']; ! break; ! ! case AUTH_MOD: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group_cache( $f_access_group ) || $is_admin : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Moderators']; ! break; ! ! case AUTH_ADMIN: ! $auth_user[$key] = $is_admin; ! $auth_user[$key . '_type'] = $lang['Auth_Administrators']; ! break; ! ! default: ! $auth_user[$key] = 0; ! break; ! } ! } ! // Is user a moderator? ! // $auth_user['auth_mod'] = ( $userdata['session_logged_in'] ) ? mx_auth_group_cache( $f_access_group ) || $is_admin : 0; ! ! return $auth_user; ! } ! ! // New optimized get_auth_forum ! // Credits to Markus_Petrux :-) ! function get_auth_forum( $mode = 'phpbb' ) ! { ! global $userdata, $mx_root_path, $phpEx; ! ! switch ( $mode ) ! { ! case 'phpbb': ! ! // Try to reuse auth_view query result. ! $userdata_key = 'mx_get_auth_forum' . $userdata['user_id']; ! if ( !empty( $userdata[$userdata_key] ) ) ! { ! $auth_data_sql = $userdata[$userdata_key]; ! return $auth_data_sql; ! } ! // Now, this tries to optimize DB access involved in auth(), ! // passing AUTH_LIST_ALL will load info for all forums at once. ! $is_auth_ary = auth( AUTH_VIEW, AUTH_LIST_ALL, $userdata ); ! // Loop through the list of forums to retrieve the ids for ! // those with AUTH_VIEW allowed. ! $auth_data_sql = ''; ! foreach( $is_auth_ary as $fid => $is_auth_row ) ! { ! if ( $is_auth_row['auth_view'] ) ! { ! $auth_data_sql .= ( $auth_data_sql != '' ) ? ', ' . $fid : $fid; ! } ! } ! ! if ( empty( $auth_data_sql ) ) ! { ! $auth_data_sql = -1; ! } ! $userdata[$userdata_key] = $auth_data_sql; ! return $auth_data_sql; ! break; ! ! case 'kb': ! ! // Try to reuse auth_view query result. ! $userdata_key = 'mx_get_auth_kb' . $userdata['user_id']; ! if ( !empty( $userdata[$userdata_key] ) ) ! { ! $auth_data_sql = $userdata[$userdata_key]; ! return $auth_data_sql; ! } ! // Now, this tries to optimize DB access involved in auth(), ! // passing AUTH_LIST_ALL will load info for all forums at once. ! ! include_once( $mx_root_path . 'modules/mx_kb/includes/functions_kb_auth.' . $phpEx ); ! $is_auth_ary = kb_auth( AUTH_VIEW, AUTH_LIST_ALL, $userdata ); ! // Loop through the list of forums to retrieve the ids for ! // those with AUTH_VIEW allowed. ! $auth_data_sql = ''; ! foreach( $is_auth_ary as $fid => $is_auth_row ) ! { ! if ( $is_auth_row['auth_view'] ) ! { ! $auth_data_sql .= ( $auth_data_sql != '' ) ? ', ' . $fid : $fid; ! } ! } ! ! if ( empty( $auth_data_sql ) ) ! { ! $auth_data_sql = -1; ! } ! $userdata[$userdata_key] = $auth_data_sql; ! return $auth_data_sql; ! break; ! default: ! //nothing ! break; ! } ! ! } ! ! // MX add-on ! // Check if user $user_id belongs to group $group_id (or group ids x1, x2, x3 etc) ! // ...function based on original function written by AbelaJohnB :-) ! function mx_auth_group( $group_ids = '', $user_id = '', $group_mod_mode = false ) ! { ! global $db; ! global $mx_root_path, $module_root_path, $page_id, $phpEx, $is_block; ! ! echo('x'); ! ! if ( $user_id == '' ) ! { ! message_die( GENERAL_ERROR, "no valid group function call, user_id:" . $user_id . ", group_id:" . $group_ids, '', '', '', '' ); ! } ! ! if ( $group_ids == '' ) ! { ! return false; ! } ! ! $group_ids_array = explode(",", $group_ids); ! ! for ( $i = 0; $i < count( $group_ids_array ); $i++ ) ! { ! if ( $group_mod_mode ) ! { ! // Check if user is group moderator.. ! $sql = "SELECT * FROM " . GROUPS_TABLE . " WHERE group_id='" . $group_ids_array[$i] . "' AND group_moderator='" . $user_id . "' AND user_pending = 0 LIMIT 1"; ! } ! else ! { ! // Check if user is member of the proper group.. ! $sql = "SELECT * FROM " . USER_GROUP_TABLE . " WHERE group_id='" . $group_ids_array[$i] . "' AND user_id='" . $user_id . "' AND user_pending = 0 LIMIT 1"; ! } ! ! if ( !( $result = $db->sql_query( $sql ) ) ) ! { ! message_die( GENERAL_ERROR, "Could not query group rights information", '', '', '', '' ); ! } ! ! if ( $db->sql_numrows( $result ) != 0 ) ! { ! $is_member = true; ! return $is_member; ! } ! ! } ! return false; ! } ! ! // Validates if user belongs to group included in group_ids list ! // Also, adds all usergroups to userdata array ! function mx_auth_group_cache( $group_ids = '', $group_mod_mode = false ) ! { ! global $userdata, $db; ! ! if ( $group_ids == '' ) ! { ! return false; ! } ! ! $group_ids_array = explode(",", $group_ids); ! ! // Try to reuse usergroups result. ! if ( $group_mod_mode ) ! { ! $userdata_key = 'mx_usergroups_mod' . $userdata['user_id']; ! ! if ( empty( $userdata[$userdata_key] ) ) ! { ! // Check if user is group moderator.. ! $sql = "SELECT gr.group_id ! FROM " . GROUPS_TABLE . " gr, ! " . USER_GROUP_TABLE . " ugr ! WHERE gr.group_id = ugr.group_id ! AND gr.group_moderator = '" . $userdata['user_id'] . "' ! AND ugr.user_pending = '0' "; ! ! if ( !( $result = $db->sql_query( $sql ) ) ) ! { ! message_die( GENERAL_ERROR, "Could not query group rights information", '', '', '', '' ); ! } ! ! $group_row = $db->sql_fetchrowset( $result ); ! ! $userdata[$userdata_key_mod] = $group_row; ! } ! } ! else ! { ! $userdata_key = 'mx_usergroups' . $userdata['user_id']; ! ! if ( empty( $userdata[$userdata_key] ) ) ! { ! // Check if user is member of the proper group.. ! $sql = "SELECT group_id FROM " . USER_GROUP_TABLE . " WHERE user_id='" . $userdata['user_id'] . "' AND user_pending = 0"; ! ! if ( !( $result = $db->sql_query( $sql ) ) ) ! { ! message_die( GENERAL_ERROR, "Could not query group rights information", '', '', '', '' ); ! } ! ! $group_row = $db->sql_fetchrowset( $result ); ! ! $userdata[$userdata_key] = $group_row; ! } ! } ! ! for ( $i = 0; $i < count( $userdata[$userdata_key] ); $i++ ) ! { ! if ( in_array( $userdata[$userdata_key][$i]['group_id'], $group_ids_array ) ) ! { ! $is_member = true; ! return $is_member; ! } ! } ! ! return false; ! } ?> \ No newline at end of file --- 1,464 ---- ! <?php ! /** ------------------------------------------------------------------------ ! * subject : mx-portal, CMS & portal ! * begin : june, 2002 ! * copyright : (C) 2002-2005 MX-System ! * email : jon...@ho... ! * project site : www.mx-system.com ! * ! * description : ! * ------------------------------------------------------------------------- ! * ! * $Id$ ! */ ! ! /** ! * This program is free software; you can redistribute it and/or modify ! * it under the terms of the GNU General Public License as published by ! * the Free Software Foundation; either version 2 of the License', or ! * ('at your option) any later version. ! */ ! ! /** ! * Included functions in this file: ! * - block_auth ! * - page_auth ! * - menu_auth ! * - mx_auth_check_user (from auth.php - validated for phpbb 2.0.10) ! * - get_auth_forum ! * - mx_auth_group_cache ! */ ! ! /* ! $type's accepted (pre-pend with AUTH_): ! VIEW, READ, POST, REPLY, EDIT, DELETE, STICKY, ANNOUNCE, VOTE, POLLCREATE ! ! Possible options ($type/module_id combinations): ! ! * If you include a type and module_id then a specific lookup will be done and ! the single result returned ! ! * If you set type to AUTH_ALL and specify a module_id an array of all auth types ! will be returned ! ! * If you provide a module_id a specific lookup on that module will be done ! ! * If you set module_id to AUTH_LIST_ALL and specify a type an array listing the ! results for all modules will be returned ! ! * If you set module_id to AUTH_LIST_ALL and type to AUTH_ALL a multidimensional ! array containing the auth permissions for all types and all modules for that ! user is returned ! ! All results are returned as associative arrays, even when a single auth type is ! specified. ! ! If available you can send an array (either one or two dimensional) containing the ! module auth levels, this will prevent the auth function having to do its own ! lookup ! */ ! function block_auth( $type, $module_id, $userdata, $f_access = '', $f_access_group = '' ) ! { ! global $db, $lang; ! ! switch ( $type ) ! { ! // case AUTH_ALL: ! // $a_sql = 'a.auth_view, a.auth_edit, a.auth_delete'; ! // $a_sql_groups = 'a.auth_view_group, a.auth_edit_group, a.auth_delete_group'; ! // $auth_fields = array( 'auth_view', 'auth_edit', 'auth_delete' ); ! // $auth_fields_groups = array( 'auth_view_group', 'auth_edit_group', 'auth_delete_group' ); ! // break; ! ! case AUTH_VIEW: ! $a_sql = 'a.auth_view'; ! $a_sql_groups = 'a.auth_view_group'; ! $auth_fields = array( 'auth_view' ); ! $auth_fields_groups = array( 'auth_view_group' ); ! break; ! ! case AUTH_EDIT: ! $a_sql = 'a.auth_edit'; ! $a_sql_groups = 'a.auth_edit_group'; ! $auth_fields = array( 'auth_edit' ); ! $auth_fields_groups = array( 'auth_edit_group' ); ! break; ! ! case AUTH_DELETE: ! $a_sql = 'a.auth_delete'; ! $a_sql_groups = 'a.auth_delete_group'; ! $auth_fields = array( 'auth_delete' ); ! $auth_fields_groups = array( 'auth_delete_group' ); ! break; ! ! default: ! break; ! } ! ! if ( $module_id == 0 ) ! { ! if ( $userdata['user_level'] == ADMIN && $userdata['session_logged_in'] ) ! { ! $auth_user[$auth_fields[0]] = 1; ! $auth_user[$auth_fields[0] . '_type'] = $lang['Auth_Moderators']; ! } ! else ! { ! $auth_user[$auth_fields[0]] = 0; ! $auth_user[$auth_fields[0] . '_type'] = $lang['Auth_Moderators']; ! } ! return $auth_user; ! } ! ! $is_admin = ( $userdata['user_level'] == ADMIN && $userdata['session_logged_in'] ) ? true : 0; ! ! $auth_user = array(); ! for( $i = 0; $i < count( $auth_fields ); $i++ ) ! { ! $key = $auth_fields[$i]; ! $key_groups = $auth_fields_groups[$i]; ! // If the user is logged on and the module type is either ALL or REG then the user has access ! // If the type if ACL, MOD or ADMIN then we need to see if the user has specific permissions ! // to do whatever it is they want to do ... to do this we pull relevant information for the ! // user (and any groups they belong to) ! // Now we compare the users access level against the modules. We assume here that a moderator ! // and admin automatically have access to an ACL module, similarly we assume admins meet an ! // auth requirement of MOD ! $value = $f_access[$key]; ! // $value_groups = $f_access_group[$key_groups]; ! $value_groups = $f_access_group; ! ! switch ( $value ) ! { ! case AUTH_ALL: ! $auth_user[$key] = true; ! $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; ! break; ! ! case AUTH_REG: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? true : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Registered_Users']; ! break; ! ! case AUTH_ANONYMOUS: ! $auth_user[$key] = ( ! $userdata['session_logged_in'] ) ? true : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; ! break; ! ! case AUTH_ACL: // PRIVATE ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group( $value_groups ) || $is_admin : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Users_granted_access']; ! break; ! ! case AUTH_MOD: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group( $f_access_group['auth_moderator_group'] ) || $is_admin : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Moderators']; ! break; ! ! case AUTH_ADMIN: ! $auth_user[$key] = $is_admin; ! $auth_user[$key . '_type'] = $lang['Auth_Administrators']; ! break; ! ! default: ! $auth_user[$key] = 0; ! break; ! } ! } ! // Is user a moderator? ! $auth_user['auth_mod'] = ( $userdata['session_logged_in'] ) ? mx_auth_group( $f_access_group['auth_moderator_group'] ) || $is_admin : 0; ! ! return $auth_user; ! } ! ! function page_auth( $type, $userdata, $f_access = '', $f_access_group = '' ) ! { ! global $db, $lang; ! ! $a_sql = 'a.auth_view'; ! $a_sql_groups = 'a.auth_view_group'; ! $auth_fields = array( 'auth_view' ); ! $auth_fields_groups = array( 'auth_view_group' ); ! ! $is_admin = ( $userdata['user_level'] == ADMIN && $userdata['session_logged_in'] ) ? true : 0; ! ! $auth_user = array(); ! for( $i = 0; $i < count( $auth_fields ); $i++ ) ! { ! $key = $auth_fields[$i]; ! $key_groups = $auth_fields_groups[$i]; ! ! $value = $f_access[$key]; ! // $value_groups = $f_access_group[$key_groups]; ! $value_groups = $f_access_group; ! ! switch ( $value ) ! { ! case AUTH_ALL: ! $auth_user[$key] = true; ! $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; ! break; ! ! case AUTH_REG: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? true : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Registered_Users']; ! break; ! ! case AUTH_ANONYMOUS: ! $auth_user[$key] = ( ! $userdata['session_logged_in'] ) ? true : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; ! break; ! ! case AUTH_ACL: // PRIVATE ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group( $value_groups ) || $is_admin : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Users_granted_access']; ! break; ! ! case AUTH_MOD: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group( $f_access_group['auth_moderator_group'] ) || $is_admin : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Moderators']; ! break; ! ! case AUTH_ADMIN: ! $auth_user[$key] = $is_admin; ! $auth_user[$key . '_type'] = $lang['Auth_Administrators']; ! break; ! ! default: ! $auth_user[$key] = 0; ! break; ! } ! } ! // Is user a moderator? ! $auth_user['auth_mod'] = ( $userdata['session_logged_in'] ) ? mx_auth_group( $f_access_group['auth_moderator_group'] ) || $is_admin : 0; ! ! return $auth_user; ! } ! // ************************************************************************** ! function menu_auth( $type, $menu_id, $userdata, $f_access = '', $f_access_group = '' ) ! { ! global $db, $lang; ! ! switch ( $type ) ! { ! case AUTH_ALL: ! $a_sql = 'a.auth_view'; ! $auth_fields = array( 'auth_view' ); ! break; ! ! case AUTH_VIEW: ! $a_sql = 'a.auth_view'; ! $auth_fields = array( 'auth_view' ); ! break; ! ! default: ! break; ! } ! // If f_access has been passed, or auth is needed to return an array of menus ! // then we need to pull the auth information on the given menu (or all menus) ! $is_admin = ( $userdata['user_level'] == ADMIN && $userdata['session_logged_in'] ) ? true : 0; ! ! $auth_user = array(); ! for( $i = 0; $i < count( $auth_fields ); $i++ ) ! { ! $key = $auth_fields[$i]; ! // If the user is logged on and the menu type is either ALL or REG then the user has access ! // If the type if ACL, MOD or ADMIN then we need to see if the user has specific permissions ! // to do whatever it is they want to do ... to do this we pull relevant information for the ! // user (and any groups they belong to) ! // Now we compare the users access level against the menus. We assume here that a moderator ! // and admin automatically have access to an ACL menu, similarly we assume admins meet an ! // auth requirement of MOD ! $value = $f_access[$key]; ! ! switch ( $value ) ! { ! case AUTH_ALL: ! $auth_user[$key] = true; ! $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; ! break; ! ! case AUTH_REG: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? true : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Registered_Users']; ! break; ! ! case AUTH_ANONYMOUS: ! $auth_user[$key] = ( ! $userdata['session_logged_in'] ) ? true : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; ! break; ! ! case AUTH_ACL: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group( $f_access_group ) || $is_admin : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Users_granted_access']; ! break; ! ! case AUTH_MOD: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group( $f_access_group ) || $is_admin : 0; ! $auth_user[$key . '_type'] = $lang['Auth_Moderators']; ! break; ! ! case AUTH_ADMIN: ! $auth_user[$key] = $is_admin; ! $auth_user[$key . '_type'] = $lang['Auth_Administrators']; ! break; ! ! default: ! $auth_user[$key] = 0; ! break; ! } ! } ! // Is user a moderator? ! // $auth_user['auth_mod'] = ( $userdata['session_logged_in'] ) ? mx_auth_group( $f_access_group ) || $is_admin : 0; ! ! return $auth_user; ! } ! ! // New optimized get_auth_forum ! // Credits to Markus_Petrux :-) ! function get_auth_forum( $mode = 'phpbb' ) ! { ! global $userdata, $mx_root_path, $phpEx; ! ! switch ( $mode ) ! { ! case 'phpbb': ! ! // Try to reuse auth_view query result. ! $userdata_key = 'mx_get_auth_forum' . $userdata['user_id']; ! if ( !empty( $userdata[$userdata_key] ) ) ! { ! $auth_data_sql = $userdata[$userdata_key]; ! return $auth_data_sql; ! } ! // Now, this tries to optimize DB access involved in auth(), ! // passing AUTH_LIST_ALL will load info for all forums at once. ! $is_auth_ary = auth( AUTH_VIEW, AUTH_LIST_ALL, $userdata ); ! // Loop through the list of forums to retrieve the ids for ! // those with AUTH_VIEW allowed. ! $auth_data_sql = ''; ! foreach( $is_auth_ary as $fid => $is_auth_row ) ! { ! if ( $is_auth_row['auth_view'] ) ! { ! $auth_data_sql .= ( $auth_data_sql != '' ) ? ', ' . $fid : $fid; ! } ! } ! ! if ( empty( $auth_data_sql ) ) ! { ! $auth_data_sql = -1; ! } ! $userdata[$userdata_key] = $auth_data_sql; ! return $auth_data_sql; ! break; ! ! case 'kb': ! ! // Try to reuse auth_view query result. ! $userdata_key = 'mx_get_auth_kb' . $userdata['user_id']; ! if ( !empty( $userdata[$userdata_key] ) ) ! { ! $auth_data_sql = $userdata[$userdata_key]; ! return $auth_data_sql; ! } ! // Now, this tries to optimize DB access involved in auth(), ! // passing AUTH_LIST_ALL will load info for all forums at once. ! ! include_once( $mx_root_path . 'modules/mx_kb/includes/functions_kb_auth.' . $phpEx ); ! $is_auth_ary = kb_auth( AUTH_VIEW, AUTH_LIST_ALL, $userdata ); ! // Loop through the list of forums to retrieve the ids for ! // those with AUTH_VIEW allowed. ! $auth_data_sql = ''; ! foreach( $is_auth_ary as $fid => $is_auth_row ) ! { ! if ( $is_auth_row['auth_view'] ) ! { ! $auth_data_sql .= ( $auth_data_sql != '' ) ? ', ' . $fid : $fid; ! } ! } ! ! if ( empty( $auth_data_sql ) ) ! { ! $auth_data_sql = -1; ! } ! $userdata[$userdata_key] = $auth_data_sql; ! return $auth_data_sql; ! break; ! default: ! //nothing ! break; ! } ! ! } ! ! // Validates if user belongs to group included in group_ids list ! // Also, adds all usergroups to userdata array ! function mx_auth_group( $group_ids = '', $group_mod_mode = false ) ! { ! global $userdata, $db; ! ! if ( $group_ids == '' ) ! { ! return false; ! } ! ! $group_ids_array = explode(",", $group_ids); ! ! // Try to reuse usergroups result. ! if ( $group_mod_mode ) ! { ! $userdata_key = 'mx_usergroups_mod' . $userdata['user_id']; ! ! if ( empty( $userdata[$userdata_key] ) ) ! { ! // Check if user is group moderator.. ! $sql = "SELECT gr.group_id ! FROM " . GROUPS_TABLE . " gr, ! " . USER_GROUP_TABLE . " ugr ! WHERE gr.group_id = ugr.group_id ! AND gr.group_moderator = '" . $userdata['user_id'] . "' ! AND ugr.user_pending = '0' "; ! ! if ( !( $result = $db->sql_query( $sql ) ) ) ! { ! message_die( GENERAL_ERROR, "Could not query group rights information", '', '', '', '' ); ! } ! ! $group_row = $db->sql_fetchrowset( $result ); ! ! $userdata[$userdata_key_mod] = $group_row; ! } ! } ! else ! { ! $userdata_key = 'mx_usergroups' . $userdata['user_id']; ! ! if ( empty( $userdata[$userdata_key] ) ) ! { ! // Check if user is member of the proper group.. ! $sql = "SELECT group_id FROM " . USER_GROUP_TABLE . " WHERE user_id='" . $userdata['user_id'] . "' AND user_pending = 0"; ! ! if ( !( $result = $db->sql_query( $sql ) ) ) ! { ! message_die( GENERAL_ERROR, "Could not query group rights information", '', '', '', '' ); ! } ! ! $group_row = $db->sql_fetchrowset( $result ); ! ! $userdata[$userdata_key] = $group_row; ! } ! } ! ! for ( $i = 0; $i < count( $userdata[$userdata_key] ); $i++ ) ! { ! if ( in_array( $userdata[$userdata_key][$i]['group_id'], $group_ids_array ) ) ! { ! $is_member = true; ! return $is_member; ! } ! } ! ! return false; ! } ?> \ No newline at end of file |