diff -ubBwr --exclude=uploads --exclude=images --exclude=images_pcf --exclude=config.php --exclude=languages/polish --exclude=settings.php Upload/showthread.php forum/showthread.php
--- Upload/showthread.php	2006-09-28 13:02:53.000000000 +0200
+++ forum/showthread.php	2006-10-20 23:10:19.000000000 +0200
@@ -427,6 +429,105 @@
 		my_set_array_cookie("threadread", $tid, time());
 	}
 
+
+	// KK: correct_marking_forums_read.mod
+	// Jesli watek nie byl czytany, to po jego przeczytaniu trzeba sprawdzic czy forum jest przeczytane
+	if ($mybb->user['uid']) // Ale tylko dla zalogowanych - reszte olac
+	{
+		// First, figure out what time the thread or forum were last read
+		$query = $db->simple_select(TABLE_PREFIX."threadsread", "dateline", "uid='{$mybb->user['uid']}' AND tid='{$thread['tid']}'");
+		$thread_read = $db->fetch_field($query, "dateline");
+
+		// Get forum read date
+		$forumread = my_get_array_cookie("forumread", $fid);
+
+		// If last visit is greater than forum read, change forum read date
+		if($mybb->user['lastvisit'] > $forumread)
+		{
+			$forumread = $mybb->user['lastvisit'];
+		}
+		if($mybb->settings['threadreadcut'] > 0 && $thread['lastpost'] > $forumread)
+		{
+			// Jesli ucinamy stare threadread...
+			$cutoff = time()-$mybb->settings['threadreadcut']*60*60*24;
+			if($thread['lastpost'] > $cutoff)
+			{
+				// ...i data wypowiedzi jest nowsza niz data uciecia...
+				if($thread_read)
+				{
+					// ... i w threadread cos jest, to znaczy ze w threadread jest dobra wartosc ostatniego czytania
+					$lastread = $thread_read;
+				}
+				else
+				{
+					// ... w przeciwnym razie watek musielismy czytac dawno temu (i zostalo to usuniete z threadread)
+					$lastread = 1;
+				}
+			}
+		}
+		if(!$lastread)
+		{
+			// Widac w threadread nie ma prawidlowej daty ostatniego czytania lub ostatnia wypowiedz
+			// w watku jest przed data uciecia (w tym przypadku nie mozna okreslic czy ostatnie czytanie bylo przed
+			// czy po ostatniej wypowiedzi), wiec sprobujmy ciacha:
+			$readcookie = $threadread = my_get_array_cookie("threadread", $thread['tid']);
+			if($readcookie > $forumread)
+			{
+				// Mamy ciacho, yupi!
+				$lastread = $readcookie;
+			}
+			else
+			{
+				// Nie ma ciacha, wiec wezmy forumread
+				$lastread = $forumread;
+			}
+		}
+		/*
+		// Komentuje, ale moze byc przydatne przy bardzo dawnych odwiedzinach usera...
+		if($mybb->settings['threadreadcut'] > 0) // Jesli ucinamy informacje o czytaniu watkow
+		{
+			$cutoff = time()-$mybb->settings['threadreadcut']*60*60*24;
+			// Jesli forum przeczytane przed data uciecia, to bierzemy date uciecia
+			$forumread = max($forumread, $cutoff) ;
+		}
+		*/
+		if ($thread['lastpost'] > $lastread)
+		{
+			// Watek nieczytany, sprawdzmy zatem czy to ostatni z nieczytanych w forum
+			$forumreadcutoff = "AND t.lastpost > $forumread" ;
+			// Set here to fetch only approved topics (and then below for a moderator we change this).
+			$visibleonly = "AND t.visible='1'";
+			// Check if the active user is a moderator and get the inline moderation tools.
+			if(is_moderator($fid) == "yes")
+			{
+				$visibleonly = " AND (t.visible='1' OR t.visible='0')";
+			}
+			// Bierzemy watki:
+			//  - nowsze niz forumread
+			//  - widoczne dla usera
+			//  - nieistniejace w threadsread lub nowsze niz wpis tam
+			$query = $db->query("
+				SELECT COUNT(*) AS num
+					FROM ".TABLE_PREFIX."threads t
+					LEFT JOIN ".TABLE_PREFIX."threadsread tr ON (
+						tr.tid = t.tid
+					)
+					WHERE t.fid='$fid' $visibleonly $forumreadcutoff
+						AND t.tid != $tid
+						AND (tr.dateline IS NULL OR tr.dateline < t.lastpost)
+						AND tr.uid = " . $mybb->user['uid'] . "
+				");
+			$row = $db->fetch_array($query);
+			if ($row['num'] == 0)
+			{
+				// Oznacz forum przeczytane
+				my_set_array_cookie("forumread", $fid, time());
+			}
+		}
+	}
+	// KK^
+
+
 	// If the forum is not open, show closed newreply button unless the user is a moderator of this forum.
 	if($forum['open'] != "no")
 	{

