sql_query($sql); if(!$af_result) { error_die(QUERY_ERROR, "Failed obtaining forum access control lists"); } else { if(!$db->sql_numrows($af_result)) { error_die(GENERAL_ERROR, "No forum access control lists exist!"); } else { $f_access = ($forum_id != AUTH_LIST_ALL) ? $db->sql_fetchrow($af_result) : $db->sql_fetchrowset($af_result); } } } // // If the user isn't logged on then // all we need do is check if the forum // has the type set to ALL, if yes then // they're good to go, if not then they // are denied access // $auth_user = array(); if($userdata['session_logged_in']) { $forum_match_sql = ($forum_id != AUTH_LIST_ALL) ? "AND au.forum_id = $forum_id" : ""; $sql = "SELECT au.forum_id, $a_sql, au.auth_mod, g.group_single_user FROM ".AUTH_ACCESS_TABLE." au, " . USER_GROUP_TABLE. " ug, " . GROUPS_TABLE. " g WHERE ug.user_id = ".$userdata['user_id']. " AND g.group_id = ug.group_id AND au.group_id = ug.group_id $forum_match_sql"; $au_result = $db->sql_query($sql); if(!$au_result) { error_die(QUERY_ERROR, "Failed obtaining forum access control lists"); } $num_u_access = $db->sql_numrows($au_result); if($num_u_access) { if($forum_id != AUTH_LIST_ALL) { $u_access = $db->sql_fetchrowset($au_result); } else { while($u_row = $db->sql_fetchrow($au_result)) { $u_access[$u_row['forum_id']] = $u_row; } } } } $is_admin = ($userdata['user_level'] == ADMIN) ? 1 : 0; $auth_user = array(); for($i = 0; $i < count($auth_fields); $i++) { $key = $auth_fields[$i]; // // If the user is logged on and the forum 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 forums // We assume here that a moderator and admin automatically // have access to an ACL forum, similarly we assume admins // meet an auth requirement of MOD // // The access level assigned to a single user automatically // takes precedence over any levels granted by that user being // a member of a multi-user usergroup, eg. a user who is banned // from a forum won't gain access to it even if they belong to // a group which has access (and vice versa). This check is // done via the single_user check // // PS : I appologise for the fantastically clear and hugely // readable code here ;) Simple gist is, if this row of // auth_access doesn't represent a single user then OR the // contents of relevant auth_access levels against the current // level (allows maximum group privileges to be assigned). If // the row does represent a single user then forget any previous // group results and instead set the auth to whatever the OR'd // contents of the access levels are. // if($forum_id != AUTH_LIST_ALL) { $value = $f_access[$key]; switch($value) { case AUTH_ALL: $auth_user[$key] = 1; $auth_user[$key . '_type'] = $lang['Anonymous_users']; break; case AUTH_REG: $auth_user[$key] = ($userdata['session_logged_in']) ? 1 : 0; $auth_user[$key . '_type'] = $lang['Registered_Users']; break; case AUTH_ACL: $auth_user[$key] = ($userdata['session_logged_in'] && $num_u_access) ? auth_check_user(AUTH_ACL, $key, $u_access, $is_admin) : 0; $auth_user[$key . '_type'] = $lang['Users_granted_access']; break; case AUTH_MOD: $auth_user[$key] = ($userdata['session_logged_in'] && $num_u_access) ? auth_check_user(AUTH_MOD, $key, $u_access, $is_admin) : 0; $auth_user[$key . '_type'] = $lang['Moderators']; break; case AUTH_ADMIN: $auth_user[$key] = $is_admin; $auth_user[$key . '_type'] = $lang['Administrators']; break; default: $auth_user[$key] = 0; break; } } else { for($k = 0; $k < count($f_access); $k++) { $value = $f_access[$k][$key]; $f_forum_id = $f_access[$k]['forum_id']; switch($value) { case AUTH_ALL: $auth_user[$f_forum_id][$key] = 1; $auth_user[$f_forum_id][$key . '_type'] = $lang['Anonymous_users']; break; case AUTH_REG: $auth_user[$f_forum_id][$key] = ($userdata['session_logged_in']) ? 1 : 0; $auth_user[$f_forum_id][$key . '_type'] = $lang['Registered_Users']; break; case AUTH_ACL: $auth_user[$f_forum_id][$key] = ($userdata['session_logged_in'] && $num_u_access) ? auth_check_user(AUTH_ACL, $key, $u_access[$f_forum_id], $is_admin) : 0; $auth_user[$f_forum_id][$key . '_type'] = $lang['Users_granted_access']; break; case AUTH_MOD: $auth_user[$f_forum_id][$key] = ($userdata['session_logged_in'] && $num_u_access) ? auth_check_user(AUTH_MOD, $key, $u_access[$f_forum_id], $is_admin) : 0; $auth_user[$f_forum_id][$key . '_type'] = $lang['Moderators']; break; case AUTH_ADMIN: $auth_user[$f_forum_id][$key] = $is_admin; $auth_user[$f_forum_id][$key . '_type'] = $lang['Administrators']; break; default: $auth_user[$f_forum_id][$key] = 0; break; } } } } // // Is user a moderator? // if($forum_id != AUTH_LIST_ALL) { $auth_user['auth_mod'] = ($userdata['session_logged_in'] && $num_u_access) ? auth_check_user(AUTH_MOD, 'auth_mod', $u_access, $is_admin) : 0; } else { for($k = 0; $k < count($f_access); $k++) { $f_forum_id = $f_access[$k]['forum_id']; $auth_user[$f_forum_id]['auth_mod'] = ($userdata['session_logged_in'] && $num_u_access) ? auth_check_user(AUTH_MOD, 'auth_mod', $u_access[$f_forum_id], $is_admin) : 0; } } // // Is user an admin (this is // really redundant at this time) // if($forum_id != AUTH_LIST_ALL) { $auth_user['auth_admin'] = $is_admin; } else { for($k = 0; $k < count($f_access); $k++) { $f_forum_id = $f_access[$k]['forum_id']; $auth_user[$f_forum_id]['auth_admin'] = $is_admin; } } return $auth_user; } function auth_check_user($type, $key, $u_access, $is_admin) { $single_user = 0; $auth_user = 0; for($j = 0; $j < count($u_access); $j++) { if(!$single_user) { $single_user = $u_access[$j]['group_single_user']; $result = 0; switch($type) { case AUTH_ACL: $result = $u_access[$j][$key]; case AUTH_MOD: $result = $result || $u_access[$j]['auth_mod']; case AUTH_ADMIN: $result = $result || $is_admin; break; } $auth_user = (!$single_user) ? ( $auth_user || $result ) : $result; } } return $auth_user; } ?>