Просмотр файла include/mtopics.php

Размер файла: 11.54Kb
<?
if( in_array($status, array('admin', 'moderator')) )
			{
	$f = intval($_GET['f']);
	$forums = mysql_query("SELECT * FROM mforums
	                       WHERE id=".$f);
	if(mysql_num_rows($forums) < 1)
	{
		if($version == "wml")
		{
			header('Content-type: text/vnd.wap.wml; charset=utf-8');
			header("Cache-Control: no-cache");
			echo(doctype("Ошибка").$tag.'Такого подфорума не существует! <br />
-
<a href="./?p=1&amp;v=wml&amp;sid='.$sid.'">Форумы</a>
'.$tagC.'
</p></card></wml>');
		}
			elseif($version == "xhtml")
			{
				header("Content-type: text/html; charset=utf-8");
				header("Last-Modified:".gmdate("D, d M Y H:i:s")." GMT");
   header("Cache-Control: no-cache, must-relative");
				echo('<html>
<head>
<title>Ошибка</title>
</head>
<body bgcolor="'.$style['background'].'" link="'.$style['link'].'" vlink="'.$style['link'].'" text="#000000">
<table align="center" border="0" cellspacing="1" cellpadding="5" width="350">
<tr><td align="center" bgcolor="'.$style['title'].'">
<font color="#FFFFFF"><b>Ошибка</b></font>
</td></tr>
<tr><td bgcolor="'.$style['text'].'">'.$tag.'
Такого подфорума не существует!
'.$tagC.'
</td></tr>
<tr><td bgcolor="'.$style['bottom'].'">
<a href="./?p=1&amp;v=xhtml&amp;sid='.$sid.'">Форумы</a>
</td></tr></table>
</body></html>');
			}
	} else
	{
		//   Навигация
  		$count = mysql_result(
  		         mysql_query("SELECT COUNT(*)
  		                      FROM mthemes
  		                      WHERE id_forum=".$f), 0);
		$start = intval($_GET['s']);
		if(!empty($start))
		{
			$limit = "LIMIT ".$start.", ".abs($count - $start);
			$int = $start;
		}
		else
		{
			$int = 0;
		}



		 // Заголовок
		$forRows = mysql_fetch_assoc($forums);
		$pcnt = mysql_fetch_assoc(
		        mysql_query("SELECT COUNT(*) AS cnt, MAX(mposts.time) AS mt
							 FROM mposts
							 LEFT JOIN mthemes
							 ON mposts.id_theme=mthemes.id
							 WHERE id_forum=".$f));
		if($authorize)
		{
			if(!mysql_result(
			    mysql_query("SELECT COUNT(*)
			    			 FROM `counter`
			    			 WHERE `username`='".$username."'
			    			 AND `fid`=".$f), 0))
		{
			mysql_query("INSERT INTO `counter`
			             VALUES(0, '".$username."', ".$f.", (SELECT MIN(time)FROM posts))");
		}
			$lastTimeQ = mysql_query("SELECT `time`
									  FROM `counter`
									  WHERE `username`='".$username."'
									  AND `fid`=".$f);
            $lastTimeR = mysql_fetch_assoc($lastTimeQ);
			$lastTime = $lastTimeR['time'];
			$newPosts = @intval(
			            mysql_result(
			            mysql_query("SELECT COUNT(*)
									 FROM mposts, mthemes
									 WHERE mposts.id_theme=mthemes.id
									 AND id_forum=".$f."
									 AND mposts.time > '".$lastTime."'
									 AND mposts.name != '".$username."'
									 GROUP BY mthemes.id_forum"), 0)).'/';

			if($newPosts < 1)
			{
				$newPosts = '0/';
			}
			$title = "".$newPosts.intval($pcnt['cnt'])."-".$forRows['name']."";
		}
		else
		{
		$title = "".intval($pcnt['cnt'])."-".$forRows['name']."";
}

		if($authorize)
		{
			if(!mysql_result(
			    mysql_query("SELECT COUNT(*)
			    			 FROM `counter`
			    			 WHERE `username`='".$username."'
			    			 AND `fid`=".$f), 0))
		{
			mysql_query("INSERT INTO `counter`
			             VALUES(0, '".$username."', ".$f.", (SELECT MIN(time)FROM posts))");
		}
			$lastTimeQ = mysql_query("SELECT `time`
									  FROM `counter`
									  WHERE `username`='".$username."'
									  AND `fid`=".$f);
            $lastTimeR = mysql_fetch_assoc($lastTimeQ);
			$lastTime = $lastTimeR['time'];
		}

		if($version == "wml")
		{
			$validChar = '$$';
		}
		else
		{
			$validChar = '$';
		}
		if($version=="xhtml"){
		$thisPageSize = $pageSize;
		}
		else
		{
		$thisPageSize = 1750;
		}
			if($version == "wml")
			{
				header('Content-type: text/vnd.wap.wml; charset=utf-8');
				header("Cache-Control: no-cache");
				echo(doctype($title));
				echo($tag."<a href=\"./?p=1&amp;v=wml&amp;sid=".$sid."\">Форумы</a><br />\r\n");
				if($private = mysql_result(
							  mysql_query("SELECT COUNT(*)
							  			   FROM `private`
							  			   WHERE `name`='".$username."'
							  			   AND `new`=1
							  			   AND `mod`='i'"), 0))
				{
					echo("<a href=\"./?p=24&amp;v=wml&amp;sid=".$sid."\">Приват</a> - <a href=\"./?p=24&amp;v=wml&amp;sid=".$sid."&amp;new=1\">".$private."</a><br />\r\n");
				}
				if($authorize)
				{

					if($order == 0)
					{
						echo("<a href=\"./?p=16&amp;v=wml&amp;sid=".$sid."&amp;f=".$f."\">Популярные темы</a><br />\r\n");
					}
					else
					{
						echo("<a href=\"./?p=16&amp;v=wml&amp;sid=".$sid."&amp;f=".$f."\">Последние темы</a><br />\r\n");
					}

				}

			} elseif($version == "xhtml")
			{
				header("Content-type: text/html; charset=utf-8");
				header("Last-Modified:".gmdate("D, d M Y H:i:s")." GMT");
   header("Cache-Control: no-cache, must-relative");
				echo('<html>
<head>
<title>'.$title.'</title>
</head>
<body bgcolor="'.$style['background'].'" link="'.$style['link'].'" vlink="'.$style['link'].'" text="#000000">
<table align="center" border="0" cellspacing="1" cellpadding="5" width="350">
<tr><td align="center" bgcolor="'.$style['title'].'">
<font color="#FFFFFF"><b>'.$title.'</b></font>
</td></tr>
<tr><td bgcolor="'.$style['bottom'].'">'.$tag.'
<a href="./?p=1&amp;v=xhtml&amp;sid='.$sid."\">Форумы</a><br />\r\n");
			if($private = mysql_result(
					      mysql_query("SELECT COUNT(*)
					                   FROM `private`
					                   WHERE `name`='".$username."'
					                   AND `new`=1
					                   AND `mod`='i'"), 0))
			{
				echo('<a href="./?p=24&amp;v=xhtml&amp;sid='.$sid.'">Приват</a> - <a href="./?p=24&amp;v=xhtml&amp;sid='.$sid.'&amp;new=1">'.$private.'</a><br />');
			}
				if($authorize)
				{

					if($order == 0)
					{
						echo("<a href=\"./?p=16&amp;v=xhtml&amp;sid=".$sid."&amp;f=".$f."\">Популярные темы</a><br />\r\n");
					}
					else
					{
						echo("<a href=\"./?p=16&amp;v=xhtml&amp;sid=".$sid."&amp;f=".$f."\">Последние темы</a><br />\r\n");
					}
				}
					echo($tagC."</td></tr>\r\n");
					echo("<tr><td bgcolor=\"".$style['text']."\">\r\n".$tag);
			if($status == "admin")
			{
				echo("<form action=\"./?p=25&amp;v=xhtml&amp;sid=".$sid."&amp;fid=".$f."&amp;mode=checkboxm\" method=\"post\">\r\n");
			}
			}

			if($status != "admin")
			{
				$noDel = "`del`=0 AND";
			}
			if($authorize && $order == 1)
			{
				$SQL = "SELECT mthemes.*, MAX(mposts.id) AS mpid, COUNT(mposts.id) AS cnt
						FROM mthemes, mposts
						WHERE mposts.id_theme=mthemes.id
						AND mthemes.id_forum=".$f."
						GROUP BY mthemes.id
						ORDER BY pos, mpid DESC
  						".$limit;
			}
			else
			{
				$SQL = "SELECT mthemes . * , COUNT( mposts.id ) AS cnt
						FROM mthemes , mposts
						WHERE ".$noDel." id_forum = ".$f."
						AND mposts.id_theme = mthemes.id
						GROUP BY mthemes.id
						ORDER BY `pos` , `id` DESC
						".$limit;
			}
			$topicsa = mysql_query($SQL);
			if($authorize)
			{
				while($topics = mysql_fetch_assoc($topicsa))
				{
					static $s;
					$s += strlen($topics['tname'].$topics['name'].$topics['time']);
					$topics['cnt'] = $topics['cnt'] - 1;
					if(($status == "admin") && $version == "xhtml")
					{
						echo("<input type=\"checkbox\" name=\"id[]\" value=\"".$topics['id']."\" />\r\n");
					}
                    if($topics['pos'] < 1)
					{
						echo('<b>[!]</b>');
					}
					echo(date("d/m H:s", $topics['time'])."");
					if($topics['close'] == "on")
					{
						echo('<b>#</b>');
					}
					else
					{
						echo(']');
					}
					$newPosts = mysql_result(
							    mysql_query("SELECT COUNT(*)
										 	 FROM `mposts`
											 WHERE `time` > '".$lastTime."'
											 AND `name` != '".$username."'
											 AND `id_theme`=".$topics['id']), 0);
					$authoriz = mysql_query("SELECT * FROM `users` WHERE `username`='".$username."' AND `password`='".$password."'");
					$Sauthoriz = mysql_fetch_array($authoriz);
					if(!$authorize || $Sauthoriz['private'] == "off")
					{
					echo("<b>".$topics['name']."</b>\r\n");
					}
					elseif($Sauthoriz['private'] == "private")
					{
					echo("<b><a href=\"./?p=24&amp;uid=".UserName2id($topics['name'])."&amp;v=".$version."&amp;sid=".$sid."&amp;p=1\">".$topics['name']."</a></b>\r\n");
					}
					elseif($Sauthoriz['private'] == "user")
					{
					echo("<b><a href=\"./?p=6&amp;v=xhtml&amp;id=".UserName2id($topics['name'])."&amp;th=".$color."\">".$topics['name']."</a></b>\r\n");
					}

					if($status == "admin")
					{
						echo(' <a href="./?p=25&amp;id='.$topics['id'].'&amp;v='.$version.'&amp;sid='.$sid."&amp;mode=mtopicm\">X</a>\r\n");
					}

					if($topics['del'] == "1" AND $status == "admin" ) { echo('<i>'); }
					echo('<br /><b><a href="./?p=5&amp;t='.$topics['id'].'&amp;v='.$version.'&amp;sid='.$sid.'">'.str_replace('&#36;', $validChar, $topics['tname'])."</a></b>");
					if($topics['del'] == "1" AND $status == "admin" ) { echo('</i>');  }
					$SnewPosts = ($topics['cnt'] + 1) - $newPosts;
					echo('(');
					if($newPosts > $topics['cnt'])
					{
						$newPosts = $topics['cnt'];
					}
					if($newPosts > 1 && $topics['cnt'] != 0)
					{
						echo('<a href="./?p=5&amp;t='.$topics['id'].'&amp;s='.$SnewPosts.'&amp;v='.$version.'&amp;sid='.$sid.'"><b>'.($newPosts).'</b></a>/');
					} elseif($newPosts == 1 && $topics['cnt'] != 0)
					{
						echo('<a href="./?p=5&amp;t='.$topics['id'].'&amp;s='.$SnewPosts.'&amp;v='.$version.'&amp;sid='.$sid.'"><b>1</b></a>/');
					}
					echo($topics['cnt'].') <br />');
					echo("<br />\r\n");


					$int++;
					if($s + 1700 > $pageSize)
					{
						if($int != $count)
						{
							$next = $int;
						}
						break;
					}
				}
			} else
			{
				while($topics = mysql_fetch_assoc($topicsa))
				{
					static $s;
					$s += strlen($topics['tname'].$topics['name'].$topics['time']);
					if($topics['pos'] < 1)
					{
						echo('<b>[!]</b>');
					}
					echo(date("d/m H:s", $topics['time'])."");
					if($topics['close'] == "on")
					{
						echo('<b>#</b>');
					}
					else
					{
						echo(']');
					}
					echo("<b>".$topics['name']."</b>\r\n");

					echo('<br /><b><a href="./?p=5&amp;t='.$topics['id'].'&amp;v='.$version.'">'.str_replace('&#36;', $validChar, $topics['tname'])."</a></b>\r\n");
					echo('('.$topics['cnt'].') <br /><br />');
					$int++;
					if($s + 1700 > $pageSize)
					{
						if($int != $count)
						{
							$next = $int;
					    }
						break;
					}

				}
			}

		if($version == "wml")
		{
			echo('<br />');
			if(!empty($next))
			{
				echo("<a accesskey=\"3\" href=\"./?v=wml&amp;sid=".$sid."&amp;f=".$f."&amp;s=".$next."&amp;mode=topicsm\">Дальше...(3)</a><br />\r\n");
			}
echo("<a href=\"./?p=10&amp;v=wml&amp;sid=".$sid."&amp;f=".$f."\">Новая тема</a><br />\r\n");
echo('<a href="'.htmlspecialchars($_SERVER['REQUEST_URI']).'&amp;'.time().'">В начало</a>
'.$tagC.'
</p></card></wml>');
		} elseif($version == "xhtml")
		{
			echo($tagC."</td></tr>
<tr><td bgcolor=\"".$style['bottom']."\">\r\n".$tag);
			if(!empty($next))
			{
				echo("<a href=\"./?v=xhtml&amp;sid=".$sid."&amp;f=".$f."&amp;s=".$next."&amp;mode=topicsm\">Дальше...</a><br />\r\n");
			}
			if($status == "admin")
			{
				echo("<input type=\"submit\" value=\"Удалить отмечанные\" /><br />\r\n</form>");
			}
			echo('<a href="./?p=10&amp;v=xhtml&amp;sid='.$sid.'&amp;f='.$f."\">Новая тема</a><br />\r\n");
			echo('
<a href="'.htmlspecialchars($_SERVER['REQUEST_URI']).'&amp;'.time()."\">В начало</a>
".$tagC."</td></tr>
</table>
</body></html>\r\n");
			}
	}}
?>