OSDN Git Service

Small bug fix.
[idb/iDB.git.git] / inc / lowtopics.php
1 <?php
2 /*
3     This program is free software; you can redistribute it and/or modify
4     it under the terms of the Revised BSD License.
5
6     This program is distributed in the hope that it will be useful,
7     but WITHOUT ANY WARRANTY; without even the implied warranty of
8     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9     Revised BSD License for more details.
10
11     Copyright 2004-2011 iDB Support - http://idb.berlios.de/
12     Copyright 2004-2011 Game Maker 2k - http://gamemaker2k.org/
13
14     $FileInfo: lowtopics.php - Last Update: 11/17/2011 SVN 770 - Author: cooldude2k $
15 */
16 $File3Name = basename($_SERVER['SCRIPT_NAME']);
17 if ($File3Name=="lowtopics.php"||$File3Name=="/lowtopics.php") {
18         require('index.php');
19         exit(); }
20 $pstring = null; $pagenum = null;
21 if(!is_numeric($_GET['id'])) { $_GET['id'] = null; }
22 if(!is_numeric($_GET['page'])) { $_GET['page'] = 1; }
23 if(!isset($_GET['st'])) { $_GET['st'] = 0; }
24 if(!is_numeric($_GET['st'])) { $_GET['st'] = 0; }
25 $prequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."forums\" WHERE \"id\"=%i".$ForumIgnoreList2." LIMIT 1", array($_GET['id']));
26 $preresult=sql_query($prequery,$SQLStat);
27 $prenum=sql_num_rows($preresult);
28 if($prenum==0) { redirect("location",$rbasedir.url_maker($exfile['index'],$Settings['file_ext'],"act=lowview",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false)); sql_free_result($preresult);
29 ob_clean(); header("Content-Type: text/plain; charset=".$Settings['charset']); $urlstatus = 302;
30 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
31 if($prenum>=1) {
32 $ForumID=sql_result($preresult,0,"id");
33 $ForumCatID=sql_result($preresult,0,"CategoryID");
34 $ForumName=sql_result($preresult,0,"Name");
35 $ForumType=sql_result($preresult,0,"ForumType");
36 $ForumShow=sql_result($preresult,0,"ShowForum");
37 if($ForumShow=="no") { $_SESSION['ShowActHidden'] = "yes"; }
38 $InSubForum=sql_result($preresult,0,"InSubForum");
39 $RedirectURL=sql_result($preresult,0,"RedirectURL");
40 $RedirectTimes=sql_result($preresult,0,"Redirects");
41 $NumberViews=sql_result($preresult,0,"NumViews");
42 $NumberPosts=sql_result($preresult,0,"NumPosts");
43 $NumberTopics=sql_result($preresult,0,"NumTopics");
44 $PostCountAdd=sql_result($preresult,0,"PostCountAdd");
45 $CanHaveTopics=sql_result($preresult,0,"CanHaveTopics");
46 $HotTopicPosts=sql_result($preresult,0,"HotTopicPosts");
47 if($HotTopicPosts!=0&&is_numeric($HotTopicPosts)) {
48         $Settings['hot_topic_num'] = $HotTopicPosts; }
49 if(!is_numeric($Settings['hot_topic_num'])) {
50         $Settings['hot_topic_num'] = 15; }
51 $ForumPostCountView=sql_result($preresult,0,"PostCountView");
52 $ForumKarmaCountView=sql_result($preresult,0,"KarmaCountView");
53 sql_free_result($preresult);
54 $ForumType = strtolower($ForumType); $CanHaveTopics = strtolower($CanHaveTopics);
55 $catcheck = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."categories\" WHERE \"id\"=%i".$CatIgnoreList2."  LIMIT 1", array($ForumCatID));
56 $catresult=sql_query($catcheck,$SQLStat);
57 $CategoryName=sql_result($catresult,0,"Name");
58 $CategoryShow=sql_result($catresult,0,"ShowCategory");
59 if($CategoryShow=="no") { $_SESSION['ShowActHidden'] = "yes"; }
60 $CategoryType=sql_result($catresult,0,"CategoryType");
61 $CategoryPostCountView=sql_result($catresult,0,"PostCountView");
62 $CategoryKarmaCountView=sql_result($catresult,0,"KarmaCountView");
63 sql_free_result($catresult);
64 if($GroupInfo['HasAdminCP']!="yes"||$GroupInfo['HasModCP']!="yes") {
65 if($MyPostCountChk==null) { $MyPostCountChk = 0; }
66 if($MyKarmaCount==null) { $MyKarmaCount = 0; }
67 if($ForumPostCountView!=0&&$MyPostCountChk<$ForumPostCountView) {
68 redirect("location",$rbasedir.url_maker($exfile['index'],$Settings['file_ext'],"act=lowview",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false)); }
69 if($CategoryPostCountView!=0&&$MyPostCountChk<$CategoryPostCountView) {
70 redirect("location",$rbasedir.url_maker($exfile['index'],$Settings['file_ext'],"act=lowview",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false)); }
71 if($ForumKarmaCountView!=0&&$MyKarmaCount<$ForumKarmaCountView) {
72 redirect("location",$rbasedir.url_maker($exfile['index'],$Settings['file_ext'],"act=lowview",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false)); }
73 if($CategoryKarmaCountView!=0&&$MyKarmaCount<$CategoryKarmaCountView) {
74 redirect("location",$rbasedir.url_maker($exfile['index'],$Settings['file_ext'],"act=lowview",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false)); } }
75 if($InSubForum!="0") {
76 $isfquery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."forums\" WHERE \"id\"=%i".$ForumIgnoreList2." LIMIT 1", array($InSubForum));
77 $isfresult=sql_query($isfquery,$SQLStat);
78 $isfnum=sql_num_rows($isfresult);
79 if($isfnum>=1) {
80 $isfForumID=sql_result($isfresult,0,"id");
81 $isfForumCatID=sql_result($isfresult,0,"CategoryID");
82 $isfForumName=sql_result($isfresult,0,"Name");
83 $isfForumType=sql_result($isfresult,0,"ForumType");
84 $isfForumType = strtolower($isfForumType);
85 $isfRedirectURL=sql_result($isfresult,0,"RedirectURL"); }
86 if($isfnum<1) { $InSubForum = "0"; }
87 sql_free_result($isfresult); }
88 $_SESSION['ViewingPage'] = url_maker(null,"no+ext","act=lowview&id=".$ForumID."&page=".$_GET['page'],"&","=",$prexqstr[$ForumType],$exqstr[$ForumType]);
89 if($Settings['file_ext']!="no+ext"&&$Settings['file_ext']!="no ext") {
90 $_SESSION['ViewingFile'] = $exfile[$ForumType].$Settings['file_ext']; }
91 if($Settings['file_ext']=="no+ext"||$Settings['file_ext']=="no ext") {
92 $_SESSION['ViewingFile'] = $exfile[$ForumType]; }
93 $_SESSION['PreViewingTitle'] = "Viewing Forum:";
94 $_SESSION['ViewingTitle'] = $ForumName;
95 if($ForumCheck!="skip") {
96 ?>
97 <div style="font-size: 1.0em; font-weight: bold; margin-bottom: 10px; padding-top: 3px; width: auto;">Full Version: <a href="<?php echo url_maker($exfile['forum'],$Settings['file_ext'],"act=view&id=".$ForumID."&page=".$_GET['page'],$Settings['qstr'],$Settings['qsep'],$prexqstr['forum'],$exqstr['forum']); ?>"><?php echo $ForumName; ?></a></div>
98 <div style="font-size: 11px; font-weight: bold; padding: 10px; border: 1px solid gray;"><a href="<?php echo url_maker($exfile['index'],$Settings['file_ext'],"act=lowview",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index']); ?>"><?php echo $Settings['board_name']; ?></a><?php echo $ThemeSet['NavLinkDivider']; ?><a href="<?php echo url_maker($exfile[$CategoryType],$Settings['file_ext'],"act=lowview&id=".$ForumCatID,$Settings['qstr'],$Settings['qsep'],$prexqstr[$CategoryType],$exqstr[$CategoryType]); ?>"><?php echo $CategoryName; ?></a><?php if($InSubForum!="0") { echo $ThemeSet['NavLinkDivider']; ?><a href="<?php echo url_maker($exfile[$isfForumType],$Settings['file_ext'],"act=view&id=".$isfForumID."&page=1",$Settings['qstr'],$Settings['qsep'],$prexqstr[$isfForumType],$exqstr[$isfForumType]); ?>"><?php echo $isfForumName; ?></a><?php } echo $ThemeSet['NavLinkDivider']; ?><a href="<?php echo url_maker($exfile[$ForumType],$Settings['file_ext'],"act=lowview&id=".$ForumID."&page=1",$Settings['qstr'],$Settings['qsep'],$prexqstr[$ForumType],$exqstr[$ForumType]); ?>"><?php echo $ForumName; ?></a></div>
99 <div>&nbsp;</div>
100 <?php }
101 if(!isset($CatPermissionInfo['CanViewCategory'][$ForumCatID])) {
102         $CatPermissionInfo['CanViewCategory'][$ForumCatID] = "no"; }
103 if($CatPermissionInfo['CanViewCategory'][$ForumCatID]=="no"||
104         $CatPermissionInfo['CanViewCategory'][$ForumCatID]!="yes") {
105 redirect("location",$rbasedir.url_maker($exfile['index'],$Settings['file_ext'],"act=lowview",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false));
106 ob_clean(); header("Content-Type: text/plain; charset=".$Settings['charset']); $urlstatus = 302;
107 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
108 if(!isset($PermissionInfo['CanViewForum'][$ForumID])) {
109         $PermissionInfo['CanViewForum'][$ForumID] = "no"; }
110 if($PermissionInfo['CanViewForum'][$ForumID]=="no"||
111         $PermissionInfo['CanViewForum'][$ForumID]!="yes") {
112 redirect("location",$rbasedir.url_maker($exfile['index'],$Settings['file_ext'],"act=lowview",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false));
113 ob_clean(); header("Content-Type: text/plain; charset=".$Settings['charset']); $urlstatus = 302;
114 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
115 if($CatPermissionInfo['CanViewCategory'][$ForumCatID]=="yes"&&
116         $PermissionInfo['CanViewForum'][$ForumID]=="yes") {
117 if($ForumType!="redirect") {
118 if($NumberViews==0||$NumberViews==null) { $NewNumberViews = 1; }
119 if($NumberViews!=0&&$NumberViews!=null) { $NewNumberViews = $NumberViews + 1; }
120 $viewup = sql_pre_query("UPDATE \"".$Settings['sqltable']."forums\" SET \"NumViews\"=%i WHERE \"id\"=%i", array($NewNumberViews,$_GET['id']));
121 sql_query($viewup,$SQLStat); }
122 if($ForumType=="redirect") {
123 if($RedirectTimes==0||$RedirectTimes==null) { $NewRedirTime = 1; }
124 if($RedirectTimes!=0&&$RedirectTimes!=null) { $NewRedirTime = $RedirectTimes + 1; }
125 $redirup = sql_pre_query("UPDATE \"".$Settings['sqltable']."forums\" SET \"Redirects\"=%i WHERE \"id\"=%i", array($NewRedirTime,$_GET['id']));
126 sql_query($redirup,$SQLStat);
127 if($RedirectURL!="http://"&&$RedirectURL!="") {
128 redirect("location",$RedirectURL,0,null,false); ob_clean();
129 header("Content-Type: text/plain; charset=".$Settings['charset']); $urlstatus = 302;
130 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
131 if($RedirectURL=="http://"||$RedirectURL=="") {
132 redirect("location",$rbasedir.url_maker($exfile['index'],$Settings['file_ext'],"act=lowview",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false));
133 ob_clean(); header("Content-Type: text/plain; charset=".$Settings['charset']); $urlstatus = 302;
134 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); } }
135 if($ForumCheck!="skip") {
136 if($ForumType=="subforum") {
137 redirect("location",$rbasedir.url_maker($exfile['subforum'],$Settings['file_ext'],"act=".$_GET['act']."&id=".$_GET['id'],$Settings['qstr'],$Settings['qsep'],$prexqstr['subforum'],$exqstr['subforum'],FALSE));
138 ob_clean(); header("Content-Type: text/plain; charset=".$Settings['charset']); $urlstatus = 302;
139 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); } }
140 if($_GET['act']=="lowview") {
141 if($NumberTopics==null) { 
142         $NumberTopics = 0; }
143 $num=$NumberTopics;
144 //Start Topic Page Code
145 if(!isset($Settings['max_topics'])) { $Settings['max_topics'] = 10; }
146 if($_GET['page']==null) { $_GET['page'] = 1; } 
147 if($_GET['page']<=0) { $_GET['page'] = 1; }
148 if($_GET['st']<=0||!isset($_GET['st'])) {
149 $nums = $_GET['page'] * $Settings['max_topics']; }
150 if($_GET['st']>0&&isset($_GET['st'])) {
151 $nums = $_GET['st']; }
152 if($nums>$num) { $nums = $num; }
153 $numz = $nums - $Settings['max_topics'];
154 if($numz<=0) { $numz = 0; }
155 //$i=$numz;
156 if($nums<$num) { $nextpage = $_GET['page'] + 1; }
157 if($nums>=$num) { $nextpage = $_GET['page']; }
158 if($numz>=$Settings['max_topics']) { $backpage = $_GET['page'] - 1; }
159 if($_GET['page']<=1) { $backpage = 1; }
160 $pnum = $num; $l = 1; $Pages = null;
161 while ($pnum>0) {
162 if($pnum>=$Settings['max_topics']) { 
163         $pnum = $pnum - $Settings['max_topics']; 
164         $Pages[$l] = $l; ++$l; }
165 if($pnum<$Settings['max_topics']&&$pnum>0) { 
166         $pnum = $pnum - $pnum; 
167         $Pages[$l] = $l; ++$l; } }
168 $snumber = $_GET['page'] - 1;
169 if($_GET['st']<=0||!isset($_GET['st'])) {
170 $PageLimit = $Settings['max_topics'] * $snumber; }
171 if($_GET['st']>0&&isset($_GET['st'])) {
172 $PageLimit = $_GET['st']; }
173 if($PageLimit<0) { $PageLimit = 0; }
174 //End Topic Page Code
175 $i=0;
176 $ExtraIgnores = null;
177 if($PermissionInfo['CanModForum'][$_GET['id']]=="no") {
178         $ExtraIgnores = " AND \"Closed\"<>3"; }
179 $query = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."topics\" WHERE \"ForumID\"=%i".$ExtraIgnores.$ForumIgnoreList4." ORDER BY \"Pinned\" DESC, \"LastUpdate\" DESC ".$SQLimit, array($_GET['id'],$PageLimit,$Settings['max_topics']));
180 $result=sql_query($query,$SQLStat);
181 $num=sql_num_rows($result);
182 //List Page Number Code Start
183 $pagenum=count($Pages);
184 if($_GET['page']>$pagenum) {
185         $_GET['page'] = $pagenum; }
186 $pagei=0; $pstring = null;
187 if($pagenum>1) {
188 $pstring = "<div class=\"PageList\"><span class=\"pagelink\">".$pagenum." Pages:</span> "; }
189 if($_GET['page']<4) { $Pagez[0] = null; }
190 if($_GET['page']>=4) { $Pagez[0] = "First"; }
191 if($_GET['page']>=3) {
192 $Pagez[1] = $_GET['page'] - 2; }
193 if($_GET['page']<3) {
194 $Pagez[1] = null; }
195 if($_GET['page']>=2) {
196 $Pagez[2] = $_GET['page'] - 1; }
197 if($_GET['page']<2) {
198 $Pagez[2] = null; }
199 $Pagez[3] = $_GET['page'];
200 if($_GET['page']<$pagenum) {
201 $Pagez[4] = $_GET['page'] + 1; }
202 if($_GET['page']>=$pagenum) {
203 $Pagez[4] = null; }
204 $pagenext = $_GET['page'] + 1;
205 if($pagenext<$pagenum) {
206 $Pagez[5] = $_GET['page'] + 2; }
207 if($pagenext>=$pagenum) {
208 $Pagez[5] = null; }
209 if($_GET['page']<$pagenum) { $Pagez[6] = "Last"; }
210 if($_GET['page']>=$pagenum) { $Pagez[6] = null; }
211 $pagenumi=count($Pagez);
212 if($NumberTopics==0) {
213 $pagenumi = 0;
214 $pstring = null; }
215 if($pagenum>1) {
216 while ($pagei < $pagenumi) {
217 if($_GET['page']!=1&&$pagei==1) {
218 $Pback = $_GET['page'] - 1;
219 $pstring = $pstring."<span class=\"pagelink\"><a href=\"".url_maker($exfile[$ForumType],$Settings['file_ext'],"act=lowview&id=".$_GET['id']."&page=".$Pback,$Settings['qstr'],$Settings['qsep'],$prexqstr[$ForumType],$exqstr[$ForumType])."\">&lt;</a></span> "; }
220 if($Pagez[$pagei]!=null&&
221    $Pagez[$pagei]!="First"&&
222    $Pagez[$pagei]!="Last") {
223 if($pagei!=3) { 
224 $pstring = $pstring."<span class=\"pagelink\"><a href=\"".url_maker($exfile[$ForumType],$Settings['file_ext'],"act=lowview&id=".$_GET['id']."&page=".$Pagez[$pagei],$Settings['qstr'],$Settings['qsep'],$prexqstr[$ForumType],$exqstr[$ForumType])."\">".$Pagez[$pagei]."</a></span> "; }
225 if($pagei==3) { 
226 $pstring = $pstring."<span class=\"pagecurrent\"><a href=\"".url_maker($exfile[$ForumType],$Settings['file_ext'],"act=lowview&id=".$_GET['id']."&page=".$Pagez[$pagei],$Settings['qstr'],$Settings['qsep'],$prexqstr[$ForumType],$exqstr[$ForumType])."\">".$Pagez[$pagei]."</a></span> "; } }
227 if($Pagez[$pagei]=="First") {
228 $pstring = $pstring."<span class=\"pagelinklast\"><a href=\"".url_maker($exfile[$ForumType],$Settings['file_ext'],"act=lowview&id=".$_GET['id']."&page=1",$Settings['qstr'],$Settings['qsep'],$prexqstr[$ForumType],$exqstr[$ForumType])."\">&laquo;</a></span> "; }
229 if($Pagez[$pagei]=="Last") {
230 $ptestnext = $pagenext + 1;
231 $paget = $pagei - 1;
232 $Pnext = $_GET['page'] + 1;
233 $pstring = $pstring."<span class=\"pagelink\"><a href=\"".url_maker($exfile[$ForumType],$Settings['file_ext'],"act=lowview&id=".$_GET['id']."&page=".$Pnext,$Settings['qstr'],$Settings['qsep'],$prexqstr[$ForumType],$exqstr[$ForumType])."\">&gt;</a></span> ";
234 if($ptestnext<$pagenum) {
235 $pstring = $pstring."<span class=\"pagelinklast\"><a href=\"".url_maker($exfile[$ForumType],$Settings['file_ext'],"act=lowview&id=".$_GET['id']."&page=".$pagenum,$Settings['qstr'],$Settings['qsep'],$prexqstr[$ForumType],$exqstr[$ForumType])."\">&raquo;</a></span> "; } }
236         ++$pagei; } $pstring = $pstring."</div>"; }
237 ?>
238 <div style="font-size: 11px; font-weight: bold; padding: 10px; border: 1px solid gray;">
239 <?php echo $pstring; ?></div>
240 <div>&nbsp;</div>
241 <div style="padding: 10px; border: 1px solid gray;">
242 <?php if($num<=0) { ?>
243 <ul style="list-style-type: none;">
244 <li>&nbsp;</li>
245 <?php } if($num>0) { ?>
246 <ul style="list-style-type: decimal;">
247 <?php }
248 while ($i < $num) {
249 $TopicID=sql_result($result,$i,"id");
250 $TForumID=sql_result($result,$i,"ForumID");
251 $OldForumID=sql_result($result,$i,"OldForumID");
252 $UsersID=sql_result($result,$i,"UserID");
253 $GuestsName=sql_result($result,$i,"GuestName");
254 $TheTime=sql_result($result,$i,"TimeStamp");
255 $TheTime=GMTimeChange($_SESSION['iDBDateFormat'].", ".$_SESSION['iDBTimeFormat'],$TheTime,$_SESSION['UserTimeZone'],0,$_SESSION['UserDST']);
256 $NumReply=sql_result($result,$i,"NumReply");
257 $NumberPosts=$NumReply + 1;
258 $prepagelist = null;
259 if(!isset($Settings['max_posts'])) { 
260         $Settings['max_posts'] = 10; }
261 $TopicName=sql_result($result,$i,"TopicName");
262 $TopicDescription=sql_result($result,$i,"Description");
263 $PinnedTopic=sql_result($result,$i,"Pinned");
264 $TopicStat=sql_result($result,$i,"Closed");
265 $PreTopic = null;
266 if ($PinnedTopic>2) { $PinnedTopic = 1; } 
267 if ($PinnedTopic<0) { $PinnedTopic = 0; }
268 if(!is_numeric($PinnedTopic)) { $PinnedTopic = 0; }
269 if ($TopicStat>3) { $TopicStat = 1; } 
270 if ($TopicStat<0) { $TopicStat = 0; }
271 if(!is_numeric($TopicStat)) { $TopicStat = 1; }
272 if ($PinnedTopic>0&&$PinnedTopic<3) { $PreTopic="<span style=\"font-weight: bold;\">Pinned: </span>"; }
273 if ($PinnedTopic==0) { $PreTopic=null; }
274 if ($OldForumID==$ForumID&&$TForumID!=$ForumID) { $PreTopic="<span>Moved: </span>"; }
275 ?>
276 <li><?php echo $PreTopic; ?><a href="<?php echo url_maker($exfile['topic'],$Settings['file_ext'],"act=lowview&id=".$TopicID."&page=1",$Settings['qstr'],$Settings['qsep'],$prexqstr['topic'],$exqstr['topic']); ?>"><?php echo $TopicName; ?></a> <span style="color: gray; font-size: 10px;">(<?php echo $NumReply; ?> replies)</span></li>
277 <?php ++$i; } ?>
278 </ul></div><div>&nbsp;</div>
279 <div style="font-size: 11px; font-weight: bold; padding: 10px; border: 1px solid gray;">
280 <?php echo $pstring; ?></div>
281 <div>&nbsp;</div>
282 <?php sql_free_result($result); } } } ?>