############################################################## 
## MOD Title:          Extra permission 
## MOD Author:         Niels < ncr@db9.dk > (Niels Chr. Rd) http://mods.db9.dk
## MOD Description:    If you wish to control witch users may see/use
##                     special pages this mod makes it posible to include
##                     some code to the php pages, so you as admin may
##                     define per user / usergroup what permissions they have.
## MOD Version:        1.0.1
## MOD Compatibility:  2.0.6
## 
## Installation Level: Easy
## Installation Time:  4 Minutes (1mn by EasyMOD of Nuttzy) 
## Files To Edit:      8
##	index.php
##	memberlist.php
##	admin/admin_forumauth.php
##	includes/auth.php
##	includes/constants.php  
##	includes/functions_admin.php
##	includes/page_header.php
##	templates/subSilver/overall_header.tpl
##
## Included Files:     3
##      extra_perm_db_update.php
##      examples/add_perm_db_update.php
##      examples/remove_perm_db_update.php
##
############################################################## 
## For Security Purposes, Please Check: http://www.phpbb.com/mods/ for the 
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code 
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered 
## in our MOD-Database, located at: http://www.phpbb.com/mods/ 
############################################################## 
## Author Notes: 
## 
## 1. Full MOD description
## -----------
## If you wish to control witch users may see/use special pages
## this mod makes it posible to include some code to the php pages,
## so you as admin may define per user / usergroup what permissions
## they have. The pages permission are controlled as a forum, and
## the permission can therefor be controlled in the forum
## permission page (admin panel)
##
## After the extra_perm_db_update.php have been run and the
## small change to the files are done you forum support extra
## permission mod, and it will be posible to code into the files
## what you would like to restrict, I have given a example in
## the "index + memberlist page" I have provided the change
## to memberlist.php and index.php as a example
## (example/add_perm_db_update.php).
## If you want to remove this example, just execute
## example/remove_perm_db_update.php
##
## 2. EasyMOD
## -----------
## This MOD is compatible and can be installed by EasyMOD
## of Nuttzy (but is not officially EasyMOD Compliant)!
## http://area51.phpbb.com/phpBB22/viewforum.php?sid=&f=15
##
## However, on alpha releases of EM and meanwhile beta or 
## final release some actions are NOT performed.
## You'll have to do them manually !
##
## 2.1 SQL commands are not performed
## -----------
## This MOD need a database update.
## Then, in any case if you install this MOD manually or using
## an alpha release of EM, please copying the *_db_update.php
## in your phpBB root directory, run it with your navigator,
## and then delete it from the phpBB root directory.
##
## Please, do it NOW! Before editing phpBB files by EM or manually!!!
## Otherwise, you may have an error message during your next
## connection.
##
## 3. Official last version link
## -----------
## Meanwhile the phpBB group validation and as the MOD is not yet
## in the phpBB MOD database, check this official link for updates...
## http://mods.db9.dk/viewtopic.php?t=918
##
## 4. Warning !
## -----------
## This mod can not work proper if you also have installed
## the "Forum Sort in Auth Panel Config" (By Ptirhiik) 
##
############################################################## 
## MOD History: 
## 
##   2003-12-10 - Version 1.0.1
##      - phpBB template & EasyMOD compliance enhancement
## 
##   ????-??-?? - Version 1.0.0
##      - now EM ready, and considered as final
## 
##   ????-??-?? - Version 0.9.7
##      - corrected some mistakes in the how-to related to
##        auth.php and admin_forumauth.php
## 
##   ????-??-?? - Version 0.9.6
##      - now also includeds auth.php, witch was missing
##        from the how-to
## 
##   ????-??-?? - Version 0.9.5
##      - correcterd a wrong find/replace in admin_authforum.php,
##        causing no save of permission
## 
##   ????-??-?? - Version 0.9.4
##      - corrected a wrong FIND and REPLACE tag in the how-to
## 
##   ????-??-?? - Version 0.9.3
##      - correcte admin_forumauth.php to avoid double forums
## 
##   ????-??-?? - Version 0.9.2
##      - corrected that topic could be moved into special pages...
## 
##   ????-??-?? - Version 0.9.1
##      - minor correction to the how-to
## 
##   ????-??-?? - Version 0.9.0
##      - released for BETA testing
## 
##   ????-??-?? - Version 0.6.0
##      - incomplete version  
##
############################################################## 
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
############################################################## 
# 
#-----[ COPY ]------------------------------------------------ 
# 
copy extra_perm_db_update.php to extra_perm_db_update.php

#
# This MOD need a database update.
# Then, as you must have now copied the extra_perm_db_update.php file
# in your phpBB root directory, run it with your navigator...
# http://www.yourWebSite.xxx/phpbbRootDir/extra_perm_db_update.php
#
# ...and then delete it from the phpBB root directory!!!
#
# Please, do it NOW! Before editing phpBB files by EM or manually!!!
# Otherwise, you may have an error message during your next
# connection.
#

# 
#-----[ OPEN ]------------------------------------------------ 
# 
index.php

# 
#-----[ FIND ]------------------------------------------------ 
#
// End session management
//

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#

// Start add - Extra permission PM MOD
//
// Start auth check
//
$is_auth = array();
$is_auth = auth(AUTH_READ, PAGE_INDEX_PERMISSION, $userdata);
if( !$is_auth['auth_read'] )
{
	if ( !$userdata['session_logged_in'] )
	{
		$header_location = ( @preg_match("/Microsoft|WebSTAR|Xitami/", getenv("SERVER_SOFTWARE")) ) ? "Refresh: 0; URL=" : "Location: ";
		header($header_location . append_sid("login.$phpEx?redirect=index.$phpEx", true));
		exit;
	}
	$message = sprintf ($lang['Sorry_no_auth'],$is_auth['auth_read_type']);
	message_die(GENERAL_MESSAGE, $message);
}
//
// End auth check
//
// End add - Extra permission PM MOD

# 
#-----[ OPEN ]------------------------------------------------ 
# 
memberlist.php

# 
#-----[ FIND ]------------------------------------------------ 
#
// End session management
//

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#

// Start add - Extra permission PM MOD
//
// Start auth check
//
$is_auth = array();
$is_auth = auth(AUTH_ALL, PAGE_VIEWMEMBERS, $userdata);

if( !$is_auth['auth_read'] )
{
	if ( !$userdata['session_logged_in'] )
	{
		$header_location = ( @preg_match("/Microsoft|WebSTAR|Xitami/", getenv("SERVER_SOFTWARE")) ) ? "Refresh: 0; URL=" : "Location: ";
		header($header_location . append_sid("login.$phpEx?redirect=memberlist.$phpEx", true));
		exit;
	}
	$message = ( !$is_auth['auth_view'] ) ? $lang['Not_Authorised'] : sprintf ($lang['Sorry_no_auth'],$is_auth['auth_read_type']);
	message_die(GENERAL_MESSAGE, $message);
}
//
// End auth check
//
// End add - Extra permission PM MOD

# 
#-----[ OPEN ]------------------------------------------------
# 
admin/admin_forumauth.php

# 
#-----[ FIND ]------------------------------------------------ 
# 
if(!empty($forum_id))

# 
#-----[ REPLACE WITH ]---------------------------------------- 
#

// Start replacement - Extra permission PM MOD
if(isset($forum_id))
// End replacement - Extra permission PM MOD

# 
#-----[ FIND ]------------------------------------------------ 
#
$sql = "UPDATE 

# 
#-----[ IN-LINE FIND ]---------------------------------------- 
#
$forum_id

# 
#-----[ IN-LINE REPLACE WITH ]-------------------------------- 
#
'$forum_id'

# 
#-----[ FIND ]------------------------------------------------ 
#
# This is not a error, you should find the same code and
# same change 2 places in this file.
#
$sql = "UPDATE 

# 
#-----[ IN-LINE FIND ]---------------------------------------- 
#
$forum_id

# 
#-----[ IN-LINE REPLACE WITH ]-------------------------------- 
#
'$forum_id'

# 
#-----[ FIND ]------------------------------------------------ 
# 
// no id was specified or just the requsted if it
// was
//

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#

// Start add - Extra permission PM MOD
$sql = "SELECT f.*
	FROM " . FORUMS_TABLE . " f
	WHERE f.cat_id=0 
	$forum_sql
	ORDER BY f.forum_name ASC";
if ( !($result = $db->sql_query($sql)) )
{
	message_die(GENERAL_ERROR, "Couldn't obtain special pages list", "", __LINE__, __FILE__, $sql);
}
$forum_rows = $db->sql_fetchrowset($result);
$db->sql_freeresult($result);
// End add - Extra permission PM MOD

# 
#-----[ FIND ]------------------------------------------------ 
# 
$forum_rows = $db->sql_fetchrowset($result);

# 
#-----[ REPLACE WITH ]---------------------------------------- 
#

// Start replacement - Extra permission PM MOD
$forum_rows = array_merge($forum_rows,$db->sql_fetchrowset($result));
// End replacement - Extra permission PM MOD

# 
#-----[ OPEN ]------------------------------------------------
# 
includes/auth.php

# 
#-----[ FIND ]------------------------------------------------ 
# 
$forum_match_sql = ( $forum_id != AUTH_LIST_ALL ) ? "WHERE a.forum_id = $forum_id" : ''; 

# 
#-----[ IN-LINE FIND ]---------------------------------------- 
# 
= $forum_id 

# 
#-----[ IN-LINE REPLACE WITH ]-------------------------------- 
# 
= '$forum_id'

# 
#-----[ FIND ]------------------------------------------------ 
# 
$forum_match_sql = ( $forum_id != AUTH_LIST_ALL ) ? "AND a.forum_id = $forum_id"

# 
#-----[ IN-LINE FIND ]---------------------------------------- 
# 
= $forum_id 

# 
#-----[ IN-LINE REPLACE WITH ]-------------------------------- 
# 
= '$forum_id'

# 
#-----[ OPEN ]------------------------------------------------
# 
includes/constants.php

# 
#-----[ FIND ]------------------------------------------------ 
# 
define('PAGE_TOPIC_OFFSET', 5000);

# 
#-----[ BEFORE, ADD ]----------------------------------------- 
#

// Start add - Extra permission PM MOD
define('PAGE_INDEX_PERMISSION', -99);
// End add - Extra permission PM MOD

# 
#-----[ OPEN ]------------------------------------------------
# 
includes/functions_admin.php

# 
#-----[ FIND ]------------------------------------------------ 
# 
$sql = "SELECT forum_id, forum_name
FROM " . FORUMS_TABLE . "

# 
#-----[ IN-LINE FIND ]---------------------------------------- 
# 
FROM " . FORUMS_TABLE . "

# 
#-----[ IN-LINE AFTER, ADD ]---------------------------------- 
# 
 WHERE forum_id > 0

# 
#-----[ OPEN ]------------------------------------------------ 
# 
includes/page_header.php 

# 
#-----[ FIND ]------------------------------------------------ 
# 
//
// The following assigns all _common_ variables that may be used at any point

# 
#-----[ BEFORE, ADD ]----------------------------------------- 
#

// Start add - Extra permission PM MOD
unset($view_pages_ary);
$view_pages_ary = array ();
$view_pages_ary = auth(AUTH_VIEW, AUTH_LIST_ALL, $userdata);

if ($view_pages_ary[''.PAGE_INDEX_PERMISSION.'']['auth_view']) 
{
	$template->assign_block_vars('switch_index_on', array());
}
if ($view_pages_ary[''.PAGE_VIEWMEMBERS]['auth_view']) 
{
	$template->assign_block_vars('switch_memberlist_on', array());
}
unset($view_pages_ary);
// End add - Extra permission PM MOD

# 
#-----[ OPEN ]------------------------------------------------ 
# 
templates/subSilver/overall_header.tpl

# 
#-----[ FIND ]------------------------------------------------ 
#
<a href="{U_MEMBERLIST}" class="mainmenu">

# 
#-----[ BEFORE, ADD ]----------------------------------------- 
#

<!-- BEGIN switch_memberlist_on -->

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#

<!-- END switch_memberlist_on -->

# 
#-----[ SAVE/CLOSE ALL FILES ]-------------------------------- 
# 
# EoM