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

Размер файла: 11.56Kb
  1. <?
  2. if( in_array($status, array('admin', 'moderator')) )
  3. {
  4. $f = intval($_GET['f']);
  5. $forums = mysql_query("SELECT * FROM mforums
  6. WHERE id=".$f);
  7. if(mysql_num_rows($forums) < 1)
  8. {
  9. if($version == "wml")
  10. {
  11. header('Content-type: text/vnd.wap.wml; charset=utf-8');
  12. header("Cache-Control: no-cache");
  13. echo(doctype("Ошибка").$tag.'Такого подфорума не существует! <br />
  14. -
  15. <a href="./?p=1&amp;v=wml&amp;sid='.$sid.'">Форумы</a>
  16. '.$tagC.'
  17. </p></card></wml>');
  18. }
  19. elseif($version == "xhtml")
  20. {
  21. header("Content-type: text/html; charset=utf-8");
  22. header("Last-Modified:".gmdate("D, d M Y H:i:s")." GMT");
  23. header("Cache-Control: no-cache, must-relative");
  24. echo('<html>
  25. <head>
  26. <title>Ошибка</title>
  27. </head>
  28. <body bgcolor="'.$style['background'].'" link="'.$style['link'].'" vlink="'.$style['link'].'" text="#000000">
  29. <table align="center" border="0" cellspacing="1" cellpadding="5" width="350">
  30. <tr><td align="center" bgcolor="'.$style['title'].'">
  31. <font color="#FFFFFF"><b>Ошибка</b></font>
  32. </td></tr>
  33. <tr><td bgcolor="'.$style['text'].'">'.$tag.'
  34. Такого подфорума не существует!
  35. '.$tagC.'
  36. </td></tr>
  37. <tr><td bgcolor="'.$style['bottom'].'">
  38. <a href="./?p=1&amp;v=xhtml&amp;sid='.$sid.'">Форумы</a>
  39. </td></tr></table>
  40. </body></html>');
  41. }
  42. } else
  43. {
  44. // Навигация
  45. $count = mysql_result(
  46. mysql_query("SELECT COUNT(*)
  47. FROM mthemes
  48. WHERE id_forum=".$f), 0);
  49. $start = intval($_GET['s']);
  50. if(!empty($start))
  51. {
  52. $limit = "LIMIT ".$start.", ".abs($count - $start);
  53. $int = $start;
  54. }
  55. else
  56. {
  57. $int = 0;
  58. }
  59.  
  60.  
  61.  
  62. // Заголовок
  63. $forRows = mysql_fetch_assoc($forums);
  64. $pcnt = mysql_fetch_assoc(
  65. mysql_query("SELECT COUNT(*) AS cnt, MAX(mposts.time) AS mt
  66. FROM mposts
  67. LEFT JOIN mthemes
  68. ON mposts.id_theme=mthemes.id
  69. WHERE id_forum=".$f));
  70. if($authorize)
  71. {
  72. if(!mysql_result(
  73. mysql_query("SELECT COUNT(*)
  74. FROM `mcounter`
  75. WHERE `username`='".$username."'
  76. AND `fid`=".$f), 0))
  77. {
  78. mysql_query("INSERT INTO `mcounter`
  79. VALUES(0, '".$username."', ".$f.", (SELECT MIN(time)FROM posts))");
  80. }
  81. $lastTimeQ = mysql_query("SELECT `time`
  82. FROM `mcounter`
  83. WHERE `username`='".$username."'
  84. AND `fid`=".$f);
  85. $lastTimeR = mysql_fetch_assoc($lastTimeQ);
  86. $lastTime = $lastTimeR['time'];
  87. $newPosts = @intval(
  88. mysql_result(
  89. mysql_query("SELECT COUNT(*)
  90. FROM mposts, mthemes
  91. WHERE mposts.id_theme=mthemes.id
  92. AND id_forum=".$f."
  93. AND mposts.time > '".$lastTime."'
  94. AND mposts.name != '".$username."'
  95. GROUP BY mthemes.id_forum"), 0)).'/';
  96.  
  97. if($newPosts < 1)
  98. {
  99. $newPosts = '0/';
  100. }
  101. $title = "".$newPosts.intval($pcnt['cnt'])."-".$forRows['name']."";
  102. }
  103. else
  104. {
  105. $title = "".intval($pcnt['cnt'])."-".$forRows['name']."";
  106. }
  107.  
  108. if($authorize)
  109. {
  110. if(!mysql_result(
  111. mysql_query("SELECT COUNT(*)
  112. FROM `mcounter`
  113. WHERE `username`='".$username."'
  114. AND `fid`=".$f), 0))
  115. {
  116. mysql_query("INSERT INTO `mcounter`
  117. VALUES(0, '".$username."', ".$f.", (SELECT MIN(time)FROM posts))");
  118. }
  119. $lastTimeQ = mysql_query("SELECT `time`
  120. FROM `mcounter`
  121. WHERE `username`='".$username."'
  122. AND `fid`=".$f);
  123. $lastTimeR = mysql_fetch_assoc($lastTimeQ);
  124. $lastTime = $lastTimeR['time'];
  125. }
  126.  
  127. if($version == "wml")
  128. {
  129. $validChar = '$$';
  130. }
  131. else
  132. {
  133. $validChar = '$';
  134. }
  135. if($version=="xhtml"){
  136. $thisPageSize = $pageSize;
  137. }
  138. else
  139. {
  140. $thisPageSize = 1750;
  141. }
  142. if($version == "wml")
  143. {
  144. header('Content-type: text/vnd.wap.wml; charset=utf-8');
  145. header("Cache-Control: no-cache");
  146. echo(doctype($title));
  147. echo($tag."<a href=\"./?p=1&amp;v=wml&amp;sid=".$sid."\">Форумы</a><br />\r\n");
  148. if($private = mysql_result(
  149. mysql_query("SELECT COUNT(*)
  150. FROM `private`
  151. WHERE `name`='".$username."'
  152. AND `new`=1
  153. AND `mod`='i'"), 0))
  154. {
  155. 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");
  156. }
  157. if($authorize)
  158. {
  159.  
  160. if($order == 0)
  161. {
  162. echo("<a href=\"./?p=16&amp;v=wml&amp;sid=".$sid."&amp;f=".$f."\">Популярные темы</a><br />\r\n");
  163. }
  164. else
  165. {
  166. echo("<a href=\"./?p=16&amp;v=wml&amp;sid=".$sid."&amp;f=".$f."\">Последние темы</a><br />\r\n");
  167. }
  168.  
  169. }
  170.  
  171. } elseif($version == "xhtml")
  172. {
  173. header("Content-type: text/html; charset=utf-8");
  174. header("Last-Modified:".gmdate("D, d M Y H:i:s")." GMT");
  175. header("Cache-Control: no-cache, must-relative");
  176. echo('<html>
  177. <head>
  178. <title>'.$title.'</title>
  179. </head>
  180. <body bgcolor="'.$style['background'].'" link="'.$style['link'].'" vlink="'.$style['link'].'" text="#000000">
  181. <table align="center" border="0" cellspacing="1" cellpadding="5" width="350">
  182. <tr><td align="center" bgcolor="'.$style['title'].'">
  183. <font color="#FFFFFF"><b>'.$title.'</b></font>
  184. </td></tr>
  185. <tr><td bgcolor="'.$style['bottom'].'">'.$tag.'
  186. <a href="./?p=1&amp;v=xhtml&amp;sid='.$sid."\">Форумы</a><br />\r\n");
  187. if($private = mysql_result(
  188. mysql_query("SELECT COUNT(*)
  189. FROM `private`
  190. WHERE `name`='".$username."'
  191. AND `new`=1
  192. AND `mod`='i'"), 0))
  193. {
  194. 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 />');
  195. }
  196. if($authorize)
  197. {
  198.  
  199. if($order == 0)
  200. {
  201. echo("<a href=\"./?p=16&amp;v=xhtml&amp;sid=".$sid."&amp;f=".$f."\">Популярные темы</a><br />\r\n");
  202. }
  203. else
  204. {
  205. echo("<a href=\"./?p=16&amp;v=xhtml&amp;sid=".$sid."&amp;f=".$f."\">Последние темы</a><br />\r\n");
  206. }
  207. }
  208. echo($tagC."</td></tr>\r\n");
  209. echo("<tr><td bgcolor=\"".$style['text']."\">\r\n".$tag);
  210. if($status == "admin")
  211. {
  212. echo("<form action=\"./?p=25&amp;v=xhtml&amp;sid=".$sid."&amp;fid=".$f."&amp;mode=checkboxm\" method=\"post\">\r\n");
  213. }
  214. }
  215.  
  216. if($status != "admin")
  217. {
  218. $noDel = "`del`=0 AND";
  219. }
  220. if($authorize && $order == 1)
  221. {
  222. $SQL = "SELECT mthemes.*, MAX(mposts.id) AS mpid, COUNT(mposts.id) AS cnt
  223. FROM mthemes, mposts
  224. WHERE mposts.id_theme=mthemes.id
  225. AND mthemes.id_forum=".$f."
  226. GROUP BY mthemes.id
  227. ORDER BY pos, mpid DESC
  228. ".$limit;
  229. }
  230. else
  231. {
  232. $SQL = "SELECT mthemes . * , COUNT( mposts.id ) AS cnt
  233. FROM mthemes , mposts
  234. WHERE ".$noDel." id_forum = ".$f."
  235. AND mposts.id_theme = mthemes.id
  236. GROUP BY mthemes.id
  237. ORDER BY `pos` , `id` DESC
  238. ".$limit;
  239. }
  240. $topicsa = mysql_query($SQL);
  241. if($authorize)
  242. {
  243. while($topics = mysql_fetch_assoc($topicsa))
  244. {
  245. static $s;
  246. $s += strlen($topics['tname'].$topics['name'].$topics['time']);
  247. $topics['cnt'] = $topics['cnt'] - 1;
  248. if(($status == "admin") && $version == "xhtml")
  249. {
  250. echo("<input type=\"checkbox\" name=\"id[]\" value=\"".$topics['id']."\" />\r\n");
  251. }
  252. if($topics['pos'] < 1)
  253. {
  254. echo('<b>[!]</b>');
  255. }
  256. echo(date("d/m H:i", $topics['time'])."");
  257. if($topics['close'] == "on")
  258. {
  259. echo('<b>#</b>');
  260. }
  261. else
  262. {
  263. echo(']');
  264. }
  265. $newPosts = mysql_result(
  266. mysql_query("SELECT COUNT(*)
  267. FROM `mposts`
  268. WHERE `time` > '".$lastTime."'
  269. AND `name` != '".$username."'
  270. AND `id_theme`=".$topics['id']), 0);
  271. $authoriz = mysql_query("SELECT * FROM `users` WHERE `username`='".$username."' AND `password`='".$password."'");
  272. $Sauthoriz = mysql_fetch_array($authoriz);
  273. if(!$authorize || $Sauthoriz['private'] == "off")
  274. {
  275. echo("<b>".$topics['name']."</b>\r\n");
  276. }
  277. elseif($Sauthoriz['private'] == "private")
  278. {
  279. echo("<b><a href=\"./?p=24&amp;uid=".UserName2id($topics['name'])."&amp;v=".$version."&amp;sid=".$sid."&amp;d=1\">".$topics['name']."</a></b>\r\n");
  280. }
  281. elseif($Sauthoriz['private'] == "user")
  282. {
  283. echo("<b><a href=\"./?p=6&amp;v=xhtml&amp;id=".UserName2id($topics['name'])."&amp;th=".$color."\">".$topics['name']."</a></b>\r\n");
  284. }
  285.  
  286. if($status == "admin")
  287. {
  288. echo(' <a href="./?p=25&amp;id='.$topics['id'].'&amp;v='.$version.'&amp;sid='.$sid."&amp;mode=mtopicm\">X</a>\r\n");
  289. }
  290.  
  291. if($topics['del'] == "1" AND $status == "admin" ) { echo('<strike><font color="red">'); }
  292. 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>");
  293. if($topics['del'] == "1" AND $status == "admin" ) { echo('</font></strike>'); }
  294. $SnewPosts = ($topics['cnt'] + 1) - $newPosts;
  295. echo('(');
  296. if($newPosts > $topics['cnt'])
  297. {
  298. $newPosts = $topics['cnt'];
  299. }
  300. if($newPosts > 1 && $topics['cnt'] != 0)
  301. {
  302. echo('<a href="./?p=5&amp;t='.$topics['id'].'&amp;s='.$SnewPosts.'&amp;v='.$version.'&amp;sid='.$sid.'"><b>'.($newPosts).'</b></a>/');
  303. } elseif($newPosts == 1 && $topics['cnt'] != 0)
  304. {
  305. echo('<a href="./?p=5&amp;t='.$topics['id'].'&amp;s='.$SnewPosts.'&amp;v='.$version.'&amp;sid='.$sid.'"><b>1</b></a>/');
  306. }
  307. echo($topics['cnt'].') <br />');
  308. echo("<br />\r\n");
  309.  
  310.  
  311. $int++;
  312. if($s + 1700 > $pageSize)
  313. {
  314. if($int != $count)
  315. {
  316. $next = $int;
  317. }
  318. break;
  319. }
  320. }
  321. } else
  322. {
  323. while($topics = mysql_fetch_assoc($topicsa))
  324. {
  325. static $s;
  326. $s += strlen($topics['tname'].$topics['name'].$topics['time']);
  327. if($topics['pos'] < 1)
  328. {
  329. echo('<b>[!]</b>');
  330. }
  331. echo(date("d/m H:i", $topics['time'])."");
  332. if($topics['close'] == "on")
  333. {
  334. echo('<b>#</b>');
  335. }
  336. else
  337. {
  338. echo(']');
  339. }
  340. echo("<b>".$topics['name']."</b>\r\n");
  341.  
  342. echo('<br /><b><a href="./?p=5&amp;t='.$topics['id'].'&amp;v='.$version.'">'.str_replace('&#36;', $validChar, $topics['tname'])."</a></b>\r\n");
  343. echo('('.$topics['cnt'].') <br /><br />');
  344. $int++;
  345. if($s + 1700 > $pageSize)
  346. {
  347. if($int != $count)
  348. {
  349. $next = $int;
  350. }
  351. break;
  352. }
  353.  
  354. }
  355. }
  356.  
  357. if($version == "wml")
  358. {
  359. echo('<br />');
  360. if(!empty($next))
  361. {
  362. echo("<a accesskey=\"3\" href=\"./?v=wml&amp;sid=".$sid."&amp;f=".$f."&amp;s=".$next."&amp;p=5\">Дальше...(3)</a><br />\r\n");
  363. }
  364. echo("<a href=\"./?p=10&amp;v=wml&amp;sid=".$sid."&amp;f=".$f."\">Новая тема</a><br />\r\n");
  365. echo('<a href="'.htmlspecialchars($_SERVER['REQUEST_URI']).'&amp;'.time().'">В начало</a>
  366. '.$tagC.'
  367. </p></card></wml>');
  368. } elseif($version == "xhtml")
  369. {
  370. echo($tagC."</td></tr>
  371. <tr><td bgcolor=\"".$style['bottom']."\">\r\n".$tag);
  372. if(!empty($next))
  373. {
  374. echo("<a href=\"./?v=xhtml&amp;sid=".$sid."&amp;f=".$f."&amp;s=".$next."&amp;p=5\">Дальше...</a><br />\r\n");
  375. }
  376. if($status == "admin")
  377. {
  378. echo("<input type=\"submit\" value=\"Удалить отмечанные\" /><br />\r\n</form>");
  379. }
  380. echo('<a href="./?p=10&amp;v=xhtml&amp;sid='.$sid.'&amp;f='.$f."\">Новая тема</a><br />\r\n");
  381. echo('
  382. <a href="'.htmlspecialchars($_SERVER['REQUEST_URI']).'&amp;'.time()."\">В начало</a>
  383. ".$tagC."</td></tr>
  384. </table>
  385. </body></html>\r\n");
  386. }
  387. }}
  388. ?>