############################################################## 
## MOD Title:		Categories hierarchy : upgrade from 2.0.4 RC-2 to 2.0.4 (final)
## MOD Author:		Ptirhiik < ptirhiik@clanmckeen.com > (Pierre) http://rpgnet.clanmckeen.com
## MOD Description:
##			Upgrade categories hierarchy from 2.0.4 RC-2 to 2.0.4 - final
## MOD Version:		2.0.4
## 
## Installation Level:	Easy
## Installation Time:	15 Minutes
## Files To Edit:
##			viewforum.php
##			admin/admin_forums.php
##			admin/admin_forums_extend.php
##			admin/admin_forum_prune.php
##			includes/functions_post.php
##			templates/subSilver/admin/forum_admin_body.tpl
##			templates/subSilver/admin/forum_extend_edit_body.tpl
##
## Included Files:	n/a
############################################################## 
## 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: 
##
##
##	special thanks to senghong79 who has found most of the issues 
############################################################## 
## MOD History: 
## 
##   2003-11-22 - Version 2.0.4
##      - fix topics count and forum link type hit count not displayed when caches used
##	- fix moving cats and forums in forum extend
## 
############################################################## 
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
##############################################################
#
#-----[ OPEN ]------------------------------------------------
#
viewforum.php
#
#-----[ FIND ]------------------------------------------------
#
	}

	// prepare url
#
#-----[ BEFORE, ADD ]-----------------------------------------
#
		cache_tree(true);
#
#-----[ OPEN ]------------------------------------------------
#
# this one is optional : do it only if you don't use the forum extend administration
#
admin/admin_forums.php
#
#-----[ FIND ]------------------------------------------------
#
			// add indentation to the display
			$rowspan = empty($cat['cat_desc']) ? 1 : 2;
			for ($k=1; $k <= $level; $k++)
			{
				$template->assign_block_vars('catrow.cathead.inc', array('ROWSPAN' => $rowspan));
			}
#
#-----[ REPLACE WITH ]---------------------------------------- 
#
			// add indentation to the display
			for ($k=1; $k <= $level; $k++)
			{
				$template->assign_block_vars('catrow.cathead.inc', array());
			}
#
#-----[ OPEN ]------------------------------------------------
#
admin/admin_forums_extend.php
#
#-----[ FIND ]------------------------------------------------
#
 *	version			: 1.0.0 - 13/11/2003
#
#-----[ REPLACE WITH ]---------------------------------------- 
#
 *	version			: 1.0.1 - 22/11/2003
#
#-----[ FIND ]------------------------------------------------
#
	// read the tree
	read_tree();
#
#-----[ REPLACE WITH ]----------------------------------------
#
	// read the tree
	read_tree(true);
#
#-----[ FIND ]------------------------------------------------
#
		// moving up
		if ( $mode == 'moveup' )
		{
			if ( $prec != $main )
			{
				$idx = $tree['keys'][$prec];
				if ( $tree['type'][$idx] == POST_FORUM_URL )
				{
					$order = $tree['data'][$idx]['forum_order'] - 5;
					$sql = "UPDATE " . FORUMS_TABLE . "
								SET forum_order = $order
								WHERE forum_id = " . intval(substr($fid, 1));
				}
				else
				{
					$order = $tree['data'][$idx]['cat_order'] - 5;
					$sql = "UPDATE " . CATEGORIES_TABLE . "
								SET cat_order = $order
								WHERE cat_id = " . intval(substr($fid, 1));
				}
				if ( !$db->sql_query($sql) )
				{
					message_die(GENERAL_ERROR, 'Couldn\'t update order in categories/forums table', '', __LINE__, __FILE__, $sql);
				}
			}
		}
		// moving down
		if ( $mode == 'movedw' )
		{
			if ( $next != $fid )
			{
				$idx = $tree['keys'][$next];
				if ( $tree['type'][$idx] == POST_FORUM_URL )
				{
					$order = $tree['data'][$idx]['forum_order'] + 5;
					$sql = "UPDATE " . FORUMS_TABLE . "
								SET forum_order = $order
								WHERE forum_id = " . intval(substr($fid, 1));
				}
				else
				{
					$order = $tree['data'][$idx]['cat_order'] + 5;
					$sql = "UPDATE " . CATEGORIES_TABLE . "
								SET cat_order = $order
								WHERE cat_id = " . intval(substr($fid, 1));
				}
				if ( !$db->sql_query($sql) )
				{
					message_die(GENERAL_ERROR, 'Couldn\'t update order in categories/forums table', '', __LINE__, __FILE__, $sql);
				}
			}
		}
#
#-----[ REPLACE WITH ]---------------------------------------- 
#
		// moving up/down
		$ref = ($mode == 'moveup') ? $prec : $next;
		$inc = ($mode == 'moveup') ? -5 : +5;
		if ( ( ($mode == 'moveup') && ($ref != $main) ) || ( ($mode == 'movedw') && ($ref != $fid) ) )
		{
			$idx = $tree['keys'][$ref];
			if ( $tree['type'][$idx] == POST_FORUM_URL )
			{
				$order = $tree['data'][$idx]['forum_order'] + $inc;
			}
			else
			{
				$order = $tree['data'][$idx]['cat_order'] + $inc;
			}

			// update the current one
			if ( substr($fid, 0, 1) == POST_FORUM_URL )
			{
				$sql = "UPDATE " . FORUMS_TABLE . "
							SET forum_order = $order
							WHERE forum_id = " . intval(substr($fid, 1));
			}
			else
			{
				$sql = "UPDATE " . CATEGORIES_TABLE . "
							SET cat_order = $order
							WHERE cat_id = " . intval(substr($fid, 1));
			}
			if ( !$db->sql_query($sql) )
			{
				message_die(GENERAL_ERROR, 'Couldn\'t update order in categories/forums table', '', __LINE__, __FILE__, $sql);
			}
		}
#
#-----[ FIND ]------------------------------------------------
#
	// reorder
	reorder_tree();
	$mode = '';
}
#
#-----[ REPLACE WITH ]---------------------------------------- 
#
	// reorder
	reorder_tree();

	// add topics count and various informations
	get_user_tree($userdata);
	$mode = '';
}
#
#-----[ OPEN ]------------------------------------------------
#
admin/admin_forum_prune.php
#
#-----[ FIND ]------------------------------------------------
#
	if ( empty($fid) || ( $fid = POST_CAT_URL . '0' ) )
#
#-----[ REPLACE WITH ]---------------------------------------- 
#
	if ( empty($fid) || ( $fid == POST_CAT_URL . '0' ) )
#
#-----[ OPEN ]------------------------------------------------
#
includes/functions_post.php
#
#-----[ FIND ]------------------------------------------------
#
				message_die(GENERAL_ERROR, 'Error deleting pruned poll options', '', __LINE__, __FILE__, $sql);
			}
		}
	}

//-- mod : categories hierarchy --------------------------------------------------------------------
//-- add
	board_stats();
#
#-----[ AFTER, ADD ]------------------------------------------
#
	cache_tree(true);
#
#-----[ FIND ]------------------------------------------------
#
			message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
		}
	}

//-- mod : categories hierarchy --------------------------------------------------------------------
//-- add
	board_stats();
#
#-----[ AFTER, ADD ]------------------------------------------
#
	cache_tree(true);
#
#-----[ FIND ]------------------------------------------------
#
	$message .=  '<br /><br />' . sprintf($lang['Click_return_forum'], '<a href="' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a>');

//-- mod : categories hierarchy --------------------------------------------------------------------
//-- add
	board_stats();
#
#-----[ AFTER, ADD ]------------------------------------------
#
	cache_tree(true);
#
#-----[ OPEN ]------------------------------------------------
#
# this one is optional : do it only if you don't use the forum extend administration
#
templates/subSilver/admin/forum_admin_body.tpl
#
#-----[ FIND ]------------------------------------------------
#
# this is a partial search : the full-line is longer
#
class="row2" rowspan="{catrow.cathead.inc.ROWSPAN}"
#
#-----[ IN-LINE FIND ]---------------------------------------- 
#
class="row2" rowspan="{catrow.cathead.inc.ROWSPAN}"
#
#-----[ IN-LINE REPLACE WITH ]--------------------------------
#
class="row2"
#
#-----[ OPEN ]------------------------------------------------
#
templates/subSilver/admin/forum_extend_edit_body.tpl
#
#-----[ FIND ]------------------------------------------------
#
# this is a partial search : the full line is longer
#
>{DESC}</textarea>
#
#-----[ IN-LINE FIND ]---------------------------------------- 
#
>{DESC}</textarea>
#
#-----[ IN-LINE BEFORE, ADD ]---------------------------------
#
 class="post"
#
#-----[ SAVE/CLOSE ALL FILES ]--------------------------------
#
# EoM