OSDN Git Service

Added more support for PostgreSQL.
[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-2009 iDB Support - http://idb.berlios.de/
12     Copyright 2004-2009 Game Maker 2k - http://gamemaker2k.org/
13
14     $FileInfo: lowtopics.php - Last Update: 12/10/2009 SVN 386 - 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 $prequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."forums\" WHERE \"id\"=%i LIMIT 1", array($_GET['id']));
24 $preresult=sql_query($prequery,$SQLStat);
25 $prenum=sql_num_rows($preresult);
26 if($prenum==0) { redirect("location",$basedir.url_maker($exfile['index'],$Settings['file_ext'],"act=lowview",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false)); sql_free_result($preresult);
27 ob_clean(); header("Content-Type: text/plain; charset=".$Settings['charset']);
28 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
29 if($prenum>=1) {
30 $ForumID=sql_result($preresult,0,"id");
31 $ForumCatID=sql_result($preresult,0,"CategoryID");
32 $ForumName=sql_result($preresult,0,"Name");
33 $ForumType=sql_result($preresult,0,"ForumType");
34 $InSubForum=sql_result($preresult,0,"InSubForum");
35 $RedirectURL=sql_result($preresult,0,"RedirectURL");
36 $RedirectTimes=sql_result($preresult,0,"Redirects");
37 $NumberViews=sql_result($preresult,0,"NumViews");
38 $NumberPosts=sql_result($preresult,0,"NumPosts");
39 $NumberTopics=sql_result($preresult,0,"NumTopics");
40 $PostCountAdd=sql_result($preresult,0,"PostCountAdd");
41 $CanHaveTopics=sql_result($preresult,0,"CanHaveTopics");
42 $HotTopicPosts=sql_result($preresult,0,"HotTopicPosts");
43 if($HotTopicPosts!=0&&is_numeric($HotTopicPosts)) {
44         $Settings['hot_topic_num'] = $HotTopicPosts; }
45 if(!is_numeric($Settings['hot_topic_num'])) {
46         $Settings['hot_topic_num'] = 15; }
47 $ForumPostCountView=sql_result($preresult,0,"PostCountView");
48 $ForumKarmaCountView=sql_result($preresult,0,"KarmaCountView");
49 sql_free_result($preresult);
50 $ForumType = strtolower($ForumType); $CanHaveTopics = strtolower($CanHaveTopics);
51 $catcheck = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."categories\" WHERE \"id\"=%i  LIMIT 1", array($ForumCatID));
52 $catresult=sql_query($catcheck,$SQLStat);
53 $CategoryName=sql_result($catresult,0,"Name");
54 $CategoryType=sql_result($catresult,0,"CategoryType");
55 $CategoryPostCountView=sql_result($catresult,0,"PostCountView");
56 $CategoryKarmaCountView=sql_result($catresult,0,"KarmaCountView");
57 sql_free_result($catresult);
58 if($GroupInfo['HasAdminCP']!="yes"||$GroupInfo['HasModCP']!="yes") {
59 if($MyPostCountChk==null) { $MyPostCountChk = 0; }
60 if($MyKarmaCount==null) { $MyKarmaCount = 0; }
61 if($ForumPostCountView!=0&&$MyPostCountChk<$ForumPostCountView) {
62 redirect("location",$basedir.url_maker($exfile['index'],$Settings['file_ext'],"act=lowview",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false)); }
63 if($CategoryPostCountView!=0&&$MyPostCountChk<$CategoryPostCountView) {
64 redirect("location",$basedir.url_maker($exfile['index'],$Settings['file_ext'],"act=lowview",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false)); }
65 if($ForumKarmaCountView!=0&&$MyKarmaCount<$ForumKarmaCountView) {
66 redirect("location",$basedir.url_maker($exfile['index'],$Settings['file_ext'],"act=lowview",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false)); }
67 if($CategoryKarmaCountView!=0&&$MyKarmaCount<$CategoryKarmaCountView) {
68 redirect("location",$basedir.url_maker($exfile['index'],$Settings['file_ext'],"act=lowview",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false)); } }
69 if($InSubForum!="0") {
70 $isfquery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."forums\" WHERE \"id\"=%i LIMIT 1", array($InSubForum));
71 $isfresult=sql_query($isfquery,$SQLStat);
72 $isfnum=sql_num_rows($isfresult);
73 if($isfnum>=1) {
74 $isfForumID=sql_result($isfresult,0,"id");
75 $isfForumCatID=sql_result($isfresult,0,"CategoryID");
76 $isfForumName=sql_result($isfresult,0,"Name");
77 $isfForumType=sql_result($isfresult,0,"ForumType");
78 $isfForumType = strtolower($isfForumType);
79 $isfRedirectURL=sql_result($isfresult,0,"RedirectURL"); }
80 if($isfnum<1) { $InSubForum = "0"; }
81 sql_free_result($isfresult); }
82 $_SESSION['ViewingPage'] = url_maker(null,"no+ext","act=lowview&id=".$ForumID."&page=".$_GET['page'],"&","=",$prexqstr[$ForumType],$exqstr[$ForumType]);
83 if($Settings['file_ext']!="no+ext"&&$Settings['file_ext']!="no ext") {
84 $_SESSION['ViewingFile'] = $exfile[$ForumType].$Settings['file_ext']; }
85 if($Settings['file_ext']=="no+ext"||$Settings['file_ext']=="no ext") {
86 $_SESSION['ViewingFile'] = $exfile[$ForumType]; }
87 $_SESSION['PreViewingTitle'] = "Viewing Forum:";
88 $_SESSION['ViewingTitle'] = $ForumName;
89 if($ForumCheck!="skip") {
90 ?>
91 <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>
92 <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']); ?>">Board index</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>
93 <div>&nbsp;</div>
94 <?php }
95 if(!isset($CatPermissionInfo['CanViewCategory'][$ForumCatID])) {
96         $CatPermissionInfo['CanViewCategory'][$ForumCatID] = "no"; }
97 if($CatPermissionInfo['CanViewCategory'][$ForumCatID]=="no"||
98         $CatPermissionInfo['CanViewCategory'][$ForumCatID]!="yes") {
99 redirect("location",$basedir.url_maker($exfile['index'],$Settings['file_ext'],"act=lowview",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false));
100 ob_clean(); header("Content-Type: text/plain; charset=".$Settings['charset']);
101 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
102 if(!isset($PermissionInfo['CanViewForum'][$ForumID])) {
103         $PermissionInfo['CanViewForum'][$ForumID] = "no"; }
104 if($PermissionInfo['CanViewForum'][$ForumID]=="no"||
105         $PermissionInfo['CanViewForum'][$ForumID]!="yes") {
106 redirect("location",$basedir.url_maker($exfile['index'],$Settings['file_ext'],"act=lowview",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false));
107 ob_clean(); header("Content-Type: text/plain; charset=".$Settings['charset']);
108 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
109 if($CatPermissionInfo['CanViewCategory'][$ForumCatID]=="yes"&&
110         $PermissionInfo['CanViewForum'][$ForumID]=="yes") {
111 if($ForumType!="redirect") {
112 if($NumberViews==0||$NumberViews==null) { $NewNumberViews = 1; }
113 if($NumberViews!=0&&$NumberViews!=null) { $NewNumberViews = $NumberViews + 1; }
114 $viewup = sql_pre_query("UPDATE \"".$Settings['sqltable']."forums\" SET \"NumViews\"=%i WHERE \"id\"=%i", array($NewNumberViews,$_GET['id']));
115 sql_query($viewup,$SQLStat); }
116 if($ForumType=="redirect") {
117 if($RedirectTimes==0||$RedirectTimes==null) { $NewRedirTime = 1; }
118 if($RedirectTimes!=0&&$RedirectTimes!=null) { $NewRedirTime = $RedirectTimes + 1; }
119 $redirup = sql_pre_query("UPDATE \"".$Settings['sqltable']."forums\" SET \"Redirects\"=%i WHERE \"id\"=%i", array($NewRedirTime,$_GET['id']));
120 sql_query($redirup,$SQLStat);
121 if($RedirectURL!="http://"&&$RedirectURL!="") {
122 redirect("location",$RedirectURL,0,null,false); ob_clean();
123 header("Content-Type: text/plain; charset=".$Settings['charset']);
124 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
125 if($RedirectURL=="http://"||$RedirectURL=="") {
126 redirect("location",$basedir.url_maker($exfile['index'],$Settings['file_ext'],"act=lowview",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false));
127 ob_clean(); header("Content-Type: text/plain; charset=".$Settings['charset']);
128 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); } }
129 if($ForumCheck!="skip") {
130 if($ForumType=="subforum") {
131 redirect("location",$basedir.url_maker($exfile['subforum'],$Settings['file_ext'],"act=".$_GET['act']."&id=".$_GET['id'],$Settings['qstr'],$Settings['qsep'],$prexqstr['subforum'],$exqstr['subforum'],FALSE));
132 ob_clean(); header("Content-Type: text/plain; charset=".$Settings['charset']);
133 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); } }
134 if($_GET['act']=="lowview") {
135 if($NumberTopics==null) { 
136         $NumberTopics = 0; }
137 $num=$NumberTopics;
138 //Start Topic Page Code
139 if(!isset($Settings['max_topics'])) { $Settings['max_topics'] = 10; }
140 if($_GET['page']==null) { $_GET['page'] = 1; } 
141 if($_GET['page']<=0) { $_GET['page'] = 1; }
142 $nums = $_GET['page'] * $Settings['max_topics'];
143 if($nums>$num) { $nums = $num; }
144 $numz = $nums - $Settings['max_topics'];
145 if($numz<=0) { $numz = 0; }
146 //$i=$numz;
147 if($nums<$num) { $nextpage = $_GET['page'] + 1; }
148 if($nums>=$num) { $nextpage = $_GET['page']; }
149 if($numz>=$Settings['max_topics']) { $backpage = $_GET['page'] - 1; }
150 if($_GET['page']<=1) { $backpage = 1; }
151 $pnum = $num; $l = 1; $Pages = null;
152 while ($pnum>0) {
153 if($pnum>=$Settings['max_topics']) { 
154         $pnum = $pnum - $Settings['max_topics']; 
155         $Pages[$l] = $l; ++$l; }
156 if($pnum<$Settings['max_topics']&&$pnum>0) { 
157         $pnum = $pnum - $pnum; 
158         $Pages[$l] = $l; ++$l; } }
159 $snumber = $_GET['page'] - 1;
160 $PageLimit = $Settings['max_topics'] * $snumber;
161 if($PageLimit<0) { $PageLimit = 0; }
162 //End Topic Page Code
163 $i=0;
164 $query = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."topics\" WHERE \"ForumID\"=%i ORDER BY \"Pinned\" DESC, \"LastUpdate\" DESC ".$SQLimit, array($_GET['id'],$PageLimit,$Settings['max_topics']));
165 $result=sql_query($query,$SQLStat);
166 $num=sql_num_rows($result);
167 //List Page Number Code Start
168 $pagenum=count($Pages);
169 if($_GET['page']>$pagenum) {
170         $_GET['page'] = $pagenum; }
171 $pagei=0; $pstring = null;
172 if($pagenum>1) {
173 $pstring = "<div class=\"PageList\"><span class=\"pagelink\">".$pagenum." Pages:</span> "; }
174 if($_GET['page']<4) { $Pagez[0] = null; }
175 if($_GET['page']>=4) { $Pagez[0] = "First"; }
176 if($_GET['page']>=3) {
177 $Pagez[1] = $_GET['page'] - 2; }
178 if($_GET['page']<3) {
179 $Pagez[1] = null; }
180 if($_GET['page']>=2) {
181 $Pagez[2] = $_GET['page'] - 1; }
182 if($_GET['page']<2) {
183 $Pagez[2] = null; }
184 $Pagez[3] = $_GET['page'];
185 if($_GET['page']<$pagenum) {
186 $Pagez[4] = $_GET['page'] + 1; }
187 if($_GET['page']>=$pagenum) {
188 $Pagez[4] = null; }
189 $pagenext = $_GET['page'] + 1;
190 if($pagenext<$pagenum) {
191 $Pagez[5] = $_GET['page'] + 2; }
192 if($pagenext>=$pagenum) {
193 $Pagez[5] = null; }
194 if($_GET['page']<$pagenum) { $Pagez[6] = "Last"; }
195 if($_GET['page']>=$pagenum) { $Pagez[6] = null; }
196 $pagenumi=count($Pagez);
197 if($NumberTopics==0) {
198 $pagenumi = 0;
199 $pstring = null; }
200 if($pagenum>1) {
201 while ($pagei < $pagenumi) {
202 if($_GET['page']!=1&&$pagei==1) {
203 $Pback = $_GET['page'] - 1;
204 $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> "; }
205 if($Pagez[$pagei]!=null&&
206    $Pagez[$pagei]!="First"&&
207    $Pagez[$pagei]!="Last") {
208 if($pagei!=3) { 
209 $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> "; }
210 if($pagei==3) { 
211 $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> "; } }
212 if($Pagez[$pagei]=="First") {
213 $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> "; }
214 if($Pagez[$pagei]=="Last") {
215 $ptestnext = $pagenext + 1;
216 $paget = $pagei - 1;
217 $Pnext = $_GET['page'] + 1;
218 $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> ";
219 if($ptestnext<$pagenum) {
220 $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> "; } }
221         ++$pagei; } $pstring = $pstring."</div>"; }
222 ?>
223 <div style="font-size: 11px; font-weight: bold; padding: 10px; border: 1px solid gray;">
224 <?php echo $pstring; ?></div>
225 <div>&nbsp;</div>
226 <div style="padding: 10px; border: 1px solid gray;">
227 <?php if($num<=0) { ?>
228 <ul style="list-style-type: none;">
229 <li>&nbsp;</li>
230 <?php } if($num>0) { ?>
231 <ul style="list-style-type: decimal;">
232 <?php }
233 while ($i < $num) {
234 $TopicID=sql_result($result,$i,"id");
235 $UsersID=sql_result($result,$i,"UserID");
236 $GuestsName=sql_result($result,$i,"GuestName");
237 $TheTime=sql_result($result,$i,"TimeStamp");
238 $TheTime=GMTimeChange("F j Y, g:i a",$TheTime,$_SESSION['UserTimeZone'],0,$_SESSION['UserDST']);
239 $NumReply=sql_result($result,$i,"NumReply");
240 $NumberPosts=$NumReply + 1;
241 $prepagelist = null;
242 if(!isset($Settings['max_posts'])) { 
243         $Settings['max_posts'] = 10; }
244 $TopicName=sql_result($result,$i,"TopicName");
245 $TopicDescription=sql_result($result,$i,"Description");
246 $PinnedTopic=sql_result($result,$i,"Pinned");
247 $TopicStat=sql_result($result,$i,"Closed");
248 $PreTopic = null;
249 if ($PinnedTopic>1) { $PinnedTopic = 1; } 
250 if ($PinnedTopic<0) { $PinnedTopic = 0; }
251 if(!is_numeric($PinnedTopic)) { $PinnedTopic = 0; }
252 if ($TopicStat>1) { $TopicStat = 1; } 
253 if ($TopicStat<0) { $TopicStat = 0; }
254 if(!is_numeric($TopicStat)) { $TopicStat = 1; }
255 if ($PinnedTopic==1) { $PreTopic="Pinned: "; }
256 if ($PinnedTopic==0) { $PreTopic=null; }
257 ?>
258 <li><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 $PreTopic.$TopicName; ?></a> <span style="color: gray; font-size: 10px;">(<?php echo $NumReply; ?> replies)</span></li>
259 <?php ++$i; } ?>
260 </ul></div><div>&nbsp;</div>
261 <?php sql_free_result($result); } } } ?>