##############################################################
## MOD Title:		View or mark unread posts (upgrade from version 1.0.4 to 1.0.5c)
## MOD Author: asinshesq < N/A > (Alan) N/A
## MOD Description:	Upgrades view or mark unread posts from version 1.0.4 to 1.0.5c
##
## MOD Version:		1.0.5c
##
## Installation Level:	Easy
## Installation Time:	5 Minutes
##
## Files To Edit:	viewtopic.php
##					includes/functions_display.php
##					includes/ucp/ucp_pm.php
##					includes/ucp/ucp_pm_viewfolder.php
##
## Included Files:	includes/functions_view_or_mark_unread_posts.php
##
## License:			http://opensource.org/licenses/gpl-license.php GNU General Public License v2
##
##############################################################
## For security purposes, please check: http://www.phpbb.com/mods/
## for the latest version of this MOD. Although MODs are checked
## before being allowed in the MODs Database there is no guarantee
## that there are no security problems within the MOD. No support
## will be given for MODs not found within the MODs Database which
## can be found at http://www.phpbb.com/mods/
##############################################################
## Author Notes:	This is just an upgrade mod.  To use it, you must have
##					view or mark unread posts version 1.0.4 already installed.
##					If you haven't already installed any version of this mod,
##					install the latest version of this mod directly and don't use this mod at all.
##					Note: all changes from version 1.0.4 to 1.0.5a have been posted
##					on the phpbb.com topic for this mod on or before December 10, 2008
##					(if you already	have 1.0.5 or 1.0.5a installed you just need to replace 
##					functions_view_or_mark_unread_posts.php	and re-do the changes to viewtopic
##					that the install.xml file tells you to make).
##
##############################################################
## MOD History: see mod history in the main install file
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################

#
#-----[ COPY ]------------------------------------------------
#
copy root/includes/functions_view_or_mark_unread_posts.php to includes/functions_view_or_mark_unread_posts.php

#
#-----[ OPEN ]------------------------------------------
#
viewtopic.php

#
#-----[ FIND ]------------------------------------------
#
	mark_unread_post($unread_post_id);

#
#-----[ REPLACE WITH ]------------------------------------------
#
	mark_unread_post($unread_post_id, $forum_id);

#
#-----[ FIND ]------------------------------------------
#
		'U_MARK_UNREAD'		=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", "mu={$row['post_id']}"),

#
#-----[ REPLACE WITH ]------------------------------------------
#
		'U_MARK_UNREAD'		=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'mu=' . $row['post_id'] . '&amp;f=' . $forum_id),

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

#
#-----[ FIND ]------------------------------------------
#
	// start mod view or mark unread post
	// initialize the flag $exists_unread to signal that we have already checked unreads in functions_display()
	// so that when check_unread_posts() is called in the future it can skip the sql query and give the
	// answer that there are none (this gets reset to '1' later on in functions_display() if there are unreads)
	global $exists_unreads;
	$exists_unreads = -1;
	// end mod view or mark unread posts

#
#-----[ REPLACE WITH ]------------------------------------------
#
	// start mod view or mark unread post
	// initialize the flag $exists_unread to signal that we have already checked unreads in functions_display()
	// so that when check_unread_posts() is called in the future it can skip the sql query and give the
	// answer that there are none (this gets reset to '1' later on in functions_display() if there are unreads),
	// but do NOT initialize if the user is on viewforum since the test for unreads may give false negatives in that context
	if (!$sql_where)
	{
		global $exists_unreads;
		$exists_unreads = -1;
	}
	// end mod view or mark unread posts

#
#-----[ FIND ]------------------------------------------
#
		// start mod view or mark unread posts
		if ($forum_unread)
		{
			// if there are any unread topics, set $exists_unreads flag to 1 so that
			// when check_unreads_flag() is called in the future it can skip the sql query
			// and give the answer that there are unread posts'
			$exists_unreads = 1;
		}
		// end mod view or mark unread posts


		$folder_image = $folder_alt = $l_subforums = '';

#
#-----[ REPLACE WITH ]------------------------------------------
#
		$folder_image = $folder_alt = $l_subforums = '';

#
#-----[ FIND ]------------------------------------------
#
				// start mod view or mark unread posts
				if ($subforum_unread)
				{
					// if there are any unread topics, set $exists_unreads flag to 1 so that
					// when check_unreads_flag() is called in the future it can skip the sql query
					// and give the answer that there are unread posts'
					$exists_unreads = 1;
				}
				// end mod view or mark unread posts

				if ($subforum_row['display'] && $subforum_row['name'])

#
#-----[ REPLACE WITH ]------------------------------------------
#
				if ($subforum_row['display'] && $subforum_row['name'])

#
#-----[ FIND ]------------------------------------------
#
		// Which folder should we display?

#
#-----[ BEFORE, ADD ]------------------------------------------
#
		// start mod view or mark unread posts
		if ($forum_unread)
		{
			// if there are any unread topics, set $exists_unreads flag to 1 so that
			// when check_unreads_flag() is called in the future it can skip the sql query
			// and give the answer that there are unread posts'
			$exists_unreads = 1;
		}
		// end mod view or mark unread posts

#
#-----[ OPEN ]------------------------------------------
#
includes/ucp/ucp_pm.php

#
#-----[ FIND ]------------------------------------------
#
					$s_to_folder_options .= ($f_id != PRIVMSGS_OUTBOX && $f_id != PRIVMSGS_SENTBOX) ? $option : '';

#
#-----[ REPLACE WITH ]------------------------------------------
#
					// start mod view or mark unread posts (and end mod too)...added reference to unreadbox in next line to supress move to unread box entry in dropdown menu
					$s_to_folder_options .= ($f_id != PRIVMSGS_OUTBOX && $f_id != PRIVMSGS_SENTBOX && $f_id != PRIVMSGS_UNREADBOX) ? $option : '';

#
#-----[ OPEN ]------------------------------------------
#
includes/ucp/ucp_pm_viewfolder.php

#
#-----[ FIND ]------------------------------------------
#
				if ($f_id == PRIVMSGS_OUTBOX || $f_id == PRIVMSGS_SENTBOX || $f_id == $folder_id)

#
#-----[ REPLACE WITH ]------------------------------------------
#
				// start mod view or mark unread posts (and end mod too)...added reference to unreadbox in next line to supress move to unread box entry in dropdown menu
				if ($f_id == PRIVMSGS_OUTBOX || $f_id == PRIVMSGS_SENTBOX || $f_id == $folder_id || $f_id == PRIVMSGS_UNREADBOX)

#
#-----[ FIND ]------------------------------------------
#
	$folder_sql = ($folder_id == PRIVMSGS_UNREADBOX) ? '(t.pm_new = 1 OR t.pm_unread = 1)' : 't.folder_id = ' . (int) $folder_id;

#
#-----[ REPLACE WITH ]------------------------------------------
#
	$folder_sql = ($folder_id == PRIVMSGS_UNREADBOX) ? '((t.pm_new = 1 OR t.pm_unread = 1) AND t.folder_id != ' . PRIVMSGS_HOLD_BOX . ')' : 't.folder_id = ' . (int) $folder_id;

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