##############################################################
## MOD Title:		View or mark unread posts (upgrade from version 1.0.5c to 1.0.6)
## MOD Author: asinshesq < N/A > (Alan) N/A
## MOD Description:	Upgrades view or mark unread posts from version 1.0.5c to 1.0.6
##
## MOD Version:		1.0.6
##
## Installation Level:	Easy
## Installation Time:	5 Minutes
##
## Files To Edit:	search.php
##					viewtopic.php
##					includes/functions.php
##					includes/functions_privmsgs.php
##					includes/ucp/ucp_pm.php
##					includes/ucp/ucp_pm_viewfolder.php
##					language/en/common.php
##					styles/prosilver/template/index_body.html
##					styles/subsilver2/template/overall_header.html
##
## Included Files:	N/A
##
## 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:	Use this upgrade script after upgrading to phpbb3.0.6RC1 or higher.
##					The script assumes you have selected 'Merge modifications' for all
##					files the phpbb updater reports as 'Modified files' and have selected
##					'Merge modifications (Loose modified code within conflicting blocks)'
##					for all files the phpbb updater reports as 'Conflict files'.
##					If you choose other options when you update phpbb, you will have to
##					figure out whether you will need to make a corresponding change in this script.
##					In a clean phpbb 3.0.5 install that includes version 1.0.5c of this mod,
##					the only file the phpbb updater reports as a 'Conflict file' is
##					styles/subsilver2/template/overall_header.html
##
##					Important: this is just an upgrade mod.  To use it, you must have
##					upgraded to phpbb 3.0.6RC1 or higher and you must have
##					view or mark unread posts version 1.0.5c already installed.
##					If you haven't already installed any version of view or mark unread posts,
##					you should install the latest version of view or mark unread posts or pms
##					directly in the most recent version of phpbb and you should not use this upgrade mod at all.
##
##					Note: the changes from version 1.0.5c to 1.0.6 that appear below for
##					the following files have been posted on the phpbb.com topic for
##					this mod on or before July 3, 2009:
##
##					includes/functions_privmsgs.php
##					includes/ucp/ucp_pm.php
##					includes/ucp/ucp_pm_viewfolder.php
##					language/en/common.php (only the first change has already been posted)
##
##############################################################
## 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 ]------------------------------------------
#
search.php

#
#-----[ FIND ]------------------------------------------
#
				$l_search_title = $user->lang['SEARCH_UNREAD'];

#
#-----[ AFTER, ADD ]------------------------------------------
#
				// start mod view or mark unread posts
				$template->assign_vars(array(
					'U_MARK_FORUMS'				=> append_sid("{$phpbb_root_path}index.$phpEx", 'hash=' . generate_link_hash('global') . '&amp;mark=forums'),
					'S_SHOW_MARK_FORUMS_LINK'	=> true));
				// end mod view or mark unread posts

#
#-----[ FIND ]------------------------------------------
#
			
			// start mod view or mark unread posts
			case 'unread':
				$sql = unread_list_sql($l_search_title, $show_results, $sort_key, $sort_dir, $sort_by_sql, $sql_sort, $limit_days, $sort_by_text, $sort_days, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param, $m_approve_fid_sql, $ex_fid_ary, $field);
			break;
			// end mod view or mark unread posts
			case 'egosearch':

#
#-----[ REPLACE WITH ]------------------------------------------
#
			case 'egosearch':

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

#
#-----[ FIND ]------------------------------------------
# Note: actual line is longer
	'S_ENABLE_FEEDS_TOPIC'

#
#-----[ AFTER, ADD ]------------------------------------------
#
	// start mod view or mark unread posts - set flag that determines if user will see mark post unread links in the posts
	'S_INC_UNREAD_LINK'		=> ($config['load_db_lastread'] && $user->data['is_registered']) ? true : false,
	// end mod  view or mark unread posts

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

#
#-----[ FIND ]------------------------------------------
#
	// start mod view or mark unread posts
	if ($config['load_db_lastread'] && $user->data['is_registered'])
	{
		$u_search_unread = append_sid("{$phpbb_root_path}search.$phpEx", 'search_id=unread');
		$s_exists_unreads = check_unread_posts();
		$s_inc_unread_link = true;
	}
	else
	{
		$u_search_unread = $s_exists_unreads = $s_inc_unread_link = false;
	}
	// end mod view or mark unread posts

#
#-----[ REPLACE WITH ]------------------------------------------
#
	// start mod view or mark unread posts - set flag that toggles text for link to unreads (if user not logged in or board not using db for unreads, set to true so that text will always read view unreads
	$s_exists_unreads = check_unread_posts();
	// end mod view or mark unread posts

#
#-----[ FIND ]------------------------------------------
#
		// start mod view or mark unread posts
		'U_SEARCH_UNREAD'		=> $u_search_unread,
		'S_EXISTS_UNREADS'		=> $s_exists_unreads,
		'S_INC_UNREAD_LINK'		=> $s_inc_unread_link,

#
#-----[ REPLACE WITH ]------------------------------------------
#
		// start mod view or mark unread posts
		'S_EXISTS_UNREADS'		=> $s_exists_unreads,

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

#
#-----[ FIND ]------------------------------------------
#
		case 'mark_important':

#
#-----[ BEFORE, ADD ]------------------------------------------
#
		// start mod view or mark unread posts
		case 'mark_marked_read':

			$sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . "
				SET pm_unread = 0
				WHERE folder_id = $cur_folder_id
					AND user_id = $user_id
					AND " . $db->sql_in_set('msg_id', $msg_ids);
			$db->sql_query($sql);

		break;

		case 'mark_marked_unread':

			$sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . "
				SET pm_unread = 1
				WHERE folder_id = $cur_folder_id
					AND user_id = $user_id
					AND " . $db->sql_in_set('msg_id', $msg_ids);
			$db->sql_query($sql);

		break;
		// end mod view or mark unread posts

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

#
#-----[ FIND ]------------------------------------------
#
				if (!in_array($mark_option, array('mark_important', 'delete_marked')) && $submit_mark)

#
#-----[ REPLACE WITH ]------------------------------------------
#
				// start mod view or mark unread posts (and end mod too)...added mark_marked_read and mark_marked_unread options to next line
				if (!in_array($mark_option, array('mark_important', 'mark_marked_read', 'mark_marked_unread', 'delete_marked')) && $submit_mark)

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

#
#-----[ FIND ]------------------------------------------
#
		$mark_options = array('mark_important', 'delete_marked');

#
#-----[ REPLACE WITH ]------------------------------------------
#
		// start mod view or mark unread posts (and end mod too)...added mark_marked_read and mark_marked_unread options to next line
		$mark_options = array('mark_important', 'mark_marked_read', 'mark_marked_unread', 'delete_marked');

#
#-----[ OPEN ]------------------------------------------
#
language/en/common.php

#
#-----[ FIND ]------------------------------------------
#
	'MARK_PM_UNREAD'			=> 'Mark pm as unread',

#
#-----[ BEFORE, ADD ]------------------------------------------
#
	'MARK_MARKED_READ'			=> 'Mark marked as read',
	'MARK_MARKED_UNREAD'		=> 'Mark marked as unread',

#
#-----[ FIND ]------------------------------------------
#
	'VIEW_UNREAD_PMS'			=> 'View unread pms',
	'VIEW_UNREADS'				=> 'View unread posts',

#
#-----[ REPLACE WITH ]------------------------------------------
#
	'VIEW_UNREAD_PMS'			=> 'View unread pms',

#
#-----[ OPEN ]------------------------------------------
#
styles/prosilver/template/index_body.html

#
#-----[ FIND ]------------------------------------------
#
		<li><a href="{U_SEARCH_UNANSWERED}">{L_SEARCH_UNANSWERED}</a><!-- IF S_USER_LOGGED_IN --> &bull; <a href="{U_SEARCH_NEW}">{L_SEARCH_NEW}</a><!-- IF S_INC_UNREAD_LINK --><!-- IF S_EXISTS_UNREADS --> &bull; <a href="{U_SEARCH_UNREAD}">{L_VIEW_UNREADS}</a><!-- ELSE --> &bull; <a href="{U_SEARCH_UNREAD}">{L_NO_UNREADS}</a><!-- ENDIF --><!-- ENDIF --><!-- ENDIF --> &bull; <a href="{U_SEARCH_ACTIVE_TOPICS}">{L_SEARCH_ACTIVE_TOPICS}</a></li>
		<!-- start mod view or mark unread posts (and end mod too) ... added unread references in the preceding line -->

#
#-----[ REPLACE WITH ]------------------------------------------
#
		<li><a href="{U_SEARCH_UNANSWERED}">{L_SEARCH_UNANSWERED}</a><!-- IF S_USER_LOGGED_IN --> &bull; <!-- IF S_EXISTS_UNREADS --><a href="{U_SEARCH_UNREAD}">{L_SEARCH_UNREAD}</a><!-- ELSE --><a href="{U_SEARCH_UNREAD}">{L_NO_UNREADS}</a><!-- ENDIF --> &bull; <a href="{U_SEARCH_NEW}">{L_SEARCH_NEW}</a><!-- ENDIF --> &bull; <a href="{U_SEARCH_ACTIVE_TOPICS}">{L_SEARCH_ACTIVE_TOPICS}</a></li>
		<!-- start mod view or mark unread posts (and end mod too) ... added code in preceding line to toggle link text between view unread and no unreads -->

#
#-----[ OPEN ]------------------------------------------
#
styles/subsilver2/template/overall_header.html

#
#-----[ FIND ]------------------------------------------
#  Note: the substance of this change was in 1.0.5c but the change gets deleted by the phpbb updater so we are re-doing it here
		<span style="float: {S_CONTENT_FLOW_END};"><a href="{U_SEARCH_UNREAD}">{L_SEARCH_UNREAD}</a> | <a href="{U_SEARCH_NEW}">{L_SEARCH_NEW}</a> | <a href="{U_SEARCH_SELF}">{L_SEARCH_SELF}</a></span>

#
#-----[ IN-LINE FIND ]------------------------------------------
#
<a href="{U_SEARCH_UNREAD}">{L_SEARCH_UNREAD}</a>

#
#-----[ IN-LINE REPLACE WITH ]------------------------------------------
#
<!-- IF S_EXISTS_UNREADS --><a href="{U_SEARCH_UNREAD}">{L_SEARCH_UNREAD}</a><!-- ELSE --><a href="{U_SEARCH_UNREAD}">{L_NO_UNREADS}</a><!-- ENDIF -->

#
#-----[ AFTER, ADD ]------------------------------------------
#
		<!-- start mod view or mark unread posts (and end mod too) ... added code in preceding line to toggle link text between view unread and no unreads -->

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