###################################################################################
## 
## Hack Title:   Custom User Rank - optional stuff
## Hack Version: 2.0.7
## Author        Acid
## Support:	 http://www.phpbbhacks.com/forums
##
## Description:  just some optional modifications for this hack
##			display both ranks (normal/special AND custom)
##			admins/mods can have custom rank without necessary postcount
##			only admins can set custom ranks for users
##			custom rank cant be used twice
################################################################################### 
## 
## Installation/Author Notes: 
## First always backup the files that you're going to edit. 
## 
################################################################################### 


##### if you want to display both ranks (normal/special AND custom) #####
# 
#-----[ OPEN ]------------------------------------------ 
# viewtopic.php
# 
#-----[ FIND ]---------------------------------------------------
# 
	if ( $postrow[$i]['user_custom_rank'] ) 
	{ 
                  $poster_custom_rank = ( $postrow[$i]['user_custom_rank'] && $postrow[$i]['user_id'] != ANONYMOUS ) ? $postrow[$i]['user_custom_rank'] : ''; 
                  $poster_rank = '';
                  $rank_image = '';
	} 

# 
#-----[ REPLACE WITH ]---------------------------------------------------
# 
	$poster_custom_rank = ( $postrow[$i]['user_custom_rank'] && $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Custom_Rank'] . ': ' . $postrow[$i]['user_custom_rank'] : ''; 



# 
#-----[ OPEN ]------------------------------------------ 
# templates/xxx/viewtopic_body.tpl
# 
#-----[ FIND ]---------------------------------------------------
# 
{postrow.POSTER_RANK}{postrow.CUSTOM_RANK}<br />{postrow.RANK_IMAGE}

# 
#-----[ REPLACE WITH ]---------------------------------------------------
# 
{postrow.POSTER_RANK}<br />{postrow.RANK_IMAGE}<br />{postrow.CUSTOM_RANK}



# 
#-----[ OPEN ]------------------------------------------ 
# includes/usercp_viewprofile.php
# 
#-----[ FIND ]---------------------------------------------------
# 
if ( $profiledata['user_custom_rank'] ) 
{ 
        $poster_custom_rank = ( $profiledata['user_custom_rank'] ) ? $profiledata['user_custom_rank'] : '&nbsp;'; 
        $poster_rank = ''; 
} 

# 
#-----[ REPLACE WITH ]---------------------------------------------------
# 
$poster_custom_rank = ( $profiledata['user_custom_rank'] ) ? $lang['Custom_Rank'] . ': ' . $profiledata['user_custom_rank'] : '&nbsp;'; 



# 
#-----[ OPEN ]------------------------------------------ 
# templates/xxx/profile_view_body.tpl
# 
#-----[ FIND ]---------------------------------------------------
# 
{POSTER_RANK}{CUSTOM_RANK}

# 
#-----[ REPLACE WITH ]---------------------------------------------------
# 
{POSTER_RANK}<br />{CUSTOM_RANK}



##### if you want to set that admins/mods can have their custom rank ####
##### (even if they dont reach the necessary post count) #####
# 
#-----[ OPEN ]------------------------------------------ 
# includes/usercp_register.php
# 
#-----[ FIND ]---------------------------------------------------
# 
if ( $userdata['user_posts'] >= $board_config['allow_custom_rank'] && $userdata['session_logged_in'] && $mode != 'register' && $userdata['user_allow_rank'] == '1' )
{
        $allow_custom_rank = TRUE;
}

# 
#-----[ REPLACE WITH ]---------------------------------------------------
# 
# $userdata['user_level'] >= 1		(all user_levels higher than normal user)
# $userdata['user_level'] == ADMIN	(only administrator)
# $userdata['user_level'] == MOD	(only moderator)

if ( $userdata['user_posts'] >= $board_config['allow_custom_rank'] && $userdata['session_logged_in'] && $mode != 'register' && $userdata['user_allow_rank'] == '1' || $userdata['user_level'] >= 1 )
{
        $allow_custom_rank = TRUE;
}



##### if you want that only admins can set custom ranks for users ####
# 
#
# then.. just omit the modifications of usercp_register.php/profile_add_body.tpl and
#        admin_board.php/board_config_body.tpl
#	 furthermore you can delete the new field in config table



##### custom rank cant be used twice ####
# 
#-----[ OPEN ]------------------------------------------ 
# includes/usercp_register.php
# 
#-----[ FIND ]---------------------------------------------------
# 
	if ( !$error )
	{
		if ( $avatar_sql == '' )

# 
#-----[ BEFORE ADD ]---------------------------------------------------
# 
	if ( $custom_rank != '' )
	{
		$sql = "SELECT user_custom_rank
		           FROM ". USERS_TABLE ."
		           WHERE user_custom_rank = '". str_replace("\'", "''", $custom_rank) ."'";
		if (!($result = $db->sql_query($sql)))
		{
			message_die(GENERAL_ERROR, "Couldn't obtain custom_ranks.", "", __LINE__, __FILE__, $sql);
		}
		
		if ($row = $db->sql_fetchrow($result))
		{
                		$error = TRUE;
                		$error_msg .= ( ( isset($error_msg) ) ? '<br />' : '' ) . $lang['Custom_Rank_Taken'];
              	}
	}


# 
#-----[ OPEN ]------------------------------------------ 
# language/lang_english/lang_main.php
# 
#-----[ FIND ]---------------------------------------------------
# 
$lang['Custom_Rank_Explain'] = 'Define your own rank.'; 

# 
#-----[ BELOW ADD ]---------------------------------------------------
# 
$lang['Custom_Rank_Taken'] = 'Rank already in use. Choose another one.'; 


###################################################################################
################################################################################### 
################################################################################### 