OSDN Git Service

Small update and bugfix
[idb/iDB.git.git] / inc / forums.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-2015 iDB Support - http://idb.berlios.de/
12     Copyright 2004-2015 Game Maker 2k - http://gamemaker2k.org/
13
14     $FileInfo: forums.php - Last Update: 01/26/2017 SVN 810 - Author: cooldude2k $
15 */
16 $File3Name = basename($_SERVER['SCRIPT_NAME']);
17 if ($File3Name=="forums.php"||$File3Name=="/forums.php") {
18     require('index.php');
19     exit(); }
20 if(!isset($ThemeSet['ForumStyle'])) { $ThemeSet['ForumStyle'] = 1; }
21 if(!is_numeric($ThemeSet['ForumStyle'])) { $ThemeSet['ForumStyle'] = 1; }
22 if($ThemeSet['ForumStyle']>2||$ThemeSet['ForumStyle']<1) {
23         $ThemeSet['ForumStyle'] = 1; }
24 $prequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."categories\" WHERE \"ShowCategory\"='yes' AND \"InSubCategory\"=0".$CatIgnoreList2." ORDER BY \"OrderID\" ASC, \"id\" ASC", array());
25 $preresult=sql_query($prequery,$SQLStat);
26 $prenum=sql_num_rows($preresult);
27 $prei=0;
28 $_SESSION['ViewingPage'] = url_maker(null,"no+ext","act=view","&","=",$prexqstr['index'],$exqstr['index']);
29 if($Settings['file_ext']!="no+ext"&&$Settings['file_ext']!="no ext") {
30 $_SESSION['ViewingFile'] = $exfile['index'].$Settings['file_ext']; }
31 if($Settings['file_ext']=="no+ext"||$Settings['file_ext']=="no ext") {
32 $_SESSION['ViewingFile'] = $exfile['index']; }
33 $_SESSION['PreViewingTitle'] = "Viewing";
34 $_SESSION['ViewingTitle'] = "Board index";
35 $_SESSION['ExtraData'] = "currentact:".$_GET['act']."; currentcategoryid:0; currentforumid:0; currenttopicid:0; currentmessageid:0; currenteventid:0; currentmemberid:0;";
36 ?>
37 <div class="NavLinks"><?php echo $ThemeSet['NavLinkIcon']; ?><a href="<?php echo url_maker($exfile['index'],$Settings['file_ext'],"act=view",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index']); ?>"><?php echo $Settings['board_name']; ?></a></div>
38 <div class="DivNavLinks">&nbsp;</div>
39 <?php
40 while ($prei < $prenum) {
41 $CategoryID=sql_result($preresult,$prei,"id");
42 $CategoryName=sql_result($preresult,$prei,"Name");
43 $CategoryShow=sql_result($preresult,$prei,"ShowCategory");
44 if($CategoryShow=="no") { $_SESSION['ShowActHidden'] = "yes"; }
45 $CategoryType=sql_result($preresult,$prei,"CategoryType");
46 $SubShowForums=sql_result($preresult,$prei,"SubShowForums");
47 $CategoryDescription=sql_result($preresult,$prei,"Description");
48 $CategoryType = strtolower($CategoryType); $SubShowForums = strtolower($SubShowForums);
49 $CategoryPostCountView=sql_result($preresult,0,"PostCountView");
50 $CategoryKarmaCountView=sql_result($preresult,0,"KarmaCountView");
51 if($MyPostCountChk==null) { $MyPostCountChk = 0; }
52 if($MyKarmaCount==null) { $MyKarmaCount = 0; }
53 if($GroupInfo['HasAdminCP']!="yes"||$GroupInfo['HasModCP']!="yes") {
54 if($CategoryPostCountView!=0&&$MyPostCountChk<$CategoryPostCountView) {
55 redirect("location",$rbasedir.url_maker($exfile['index'],$Settings['file_ext'],"act=view",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false)); }
56 if($CategoryKarmaCountView!=0&&$MyKarmaCount<$CategoryKarmaCountView) {
57 redirect("location",$rbasedir.url_maker($exfile['index'],$Settings['file_ext'],"act=view",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false)); } }
58 if(isset($CatPermissionInfo['CanViewCategory'][$CategoryID])&&
59     $CatPermissionInfo['CanViewCategory'][$CategoryID]=="yes") {
60 $query = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."forums\" WHERE \"ShowForum\"='yes' AND \"CategoryID\"=%i AND \"InSubForum\"=0".$ForumIgnoreList2." ORDER BY \"OrderID\" ASC, \"id\" ASC", array($CategoryID));
61 $result=sql_query($query,$SQLStat);
62 $num=sql_num_rows($result);
63 $i=0;
64 if($num>=1) {
65 ?>
66 <div class="Table1Border">
67 <?php if($ThemeSet['TableStyle']=="div") { ?>
68 <div class="TableRow1">
69 <span style="text-align: left;">
70 <?php echo $ThemeSet['TitleIcon']; ?><a href="<?php echo url_maker($exfile[$CategoryType],$Settings['file_ext'],"act=view&id=".$CategoryID,$Settings['qstr'],$Settings['qsep'],$prexqstr[$CategoryType],$exqstr[$CategoryType]); ?>"><?php echo $CategoryName; ?></a></span></div>
71 <?php } ?>
72 <table class="Table1" id="Cat<?php echo $CategoryID; ?>">
73 <?php if($ThemeSet['TableStyle']=="table") { ?>
74 <tr class="TableRow1" id="CatStart<?php echo $CategoryID; ?>">
75 <td class="TableColumn1" colspan="5"><span style="text-align: left;">
76 <?php echo $ThemeSet['TitleIcon']; ?><a href="<?php echo url_maker($exfile[$CategoryType],$Settings['file_ext'],"act=view&id=".$CategoryID,$Settings['qstr'],$Settings['qsep'],$prexqstr[$CategoryType],$exqstr[$CategoryType]); ?>"><?php echo $CategoryName; ?></a></span>
77 </td>
78 </tr><?php } ?>
79 <tr id="ForumStatRow<?php echo $CategoryID; ?>" class="TableRow2">
80 <th class="TableColumn2" style="width: 4%;">&nbsp;</th>
81 <th class="TableColumn2" style="width: 58%;">Forum</th>
82 <th class="TableColumn2" style="width: 7%;">Topics</th>
83 <th class="TableColumn2" style="width: 7%;">Posts</th>
84 <th class="TableColumn2" style="width: 24%;">Last Topic</th>
85 </tr>
86 <?php }
87 while ($i < $num) {
88 $ForumID=sql_result($result,$i,"id");
89 $ForumName=sql_result($result,$i,"Name");
90 $ForumShow=sql_result($result,$i,"ShowForum");
91 if($ForumShow=="no") { $_SESSION['ShowActHidden'] = "yes"; }
92 $ForumType=sql_result($result,$i,"ForumType");
93 $ForumShowTopics=sql_result($result,$i,"CanHaveTopics");
94 $ForumShowTopics = strtolower($ForumShowTopics);
95 $NumTopics=sql_result($result,$i,"NumTopics");
96 $NumPosts=sql_result($result,$i,"NumPosts");
97 $NumRedirects=sql_result($result,$i,"Redirects");
98 $ForumDescription=sql_result($result,$i,"Description");
99 $ForumType = strtolower($ForumType); $sflist = null;
100 $gltf = array(null); $gltf[0] = $ForumID;
101 if ($ForumType=="subforum") {
102 $apcquery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."forums\" WHERE \"ShowForum\"='yes' AND \"InSubForum\"=%i".$ForumIgnoreList2." ORDER BY \"OrderID\" ASC, \"id\" ASC", array($ForumID));
103 $apcresult=sql_query($apcquery,$SQLStat);
104 $apcnum=sql_num_rows($apcresult);
105 $apci=0; $apcl=1; if($apcnum>=1) {
106 while ($apci < $apcnum) {
107 $NumsTopics=sql_result($apcresult,$apci,"NumTopics");
108 $NumTopics = $NumsTopics + $NumTopics;
109 $NumsPosts=sql_result($apcresult,$apci,"NumPosts");
110 $NumPosts = $NumsPosts + $NumPosts;
111 $SubsForumID=sql_result($apcresult,$apci,"id");
112 $SubsForumName=sql_result($apcresult,$apci,"Name");
113 $SubsForumType=sql_result($apcresult,$apci,"ForumType");
114 $SubsForumShowTopics=sql_result($apcresult,$apci,"CanHaveTopics");
115 $SubsForumDescription=sql_result($apcresult,$apci,"Description");
116 if(isset($PermissionInfo['CanViewForum'][$SubsForumID])&&
117     $PermissionInfo['CanViewForum'][$SubsForumID]=="yes") {
118 $ExStr = ""; if ($SubsForumType!="redirect"&&
119     $SubsForumShowTopics!="no") { $ExStr = "&page=1"; }
120 //$sfurl = "<a href=\"";
121 $sfurl = url_maker($exfile[$SubsForumType],$Settings['file_ext'],"act=view&id=".$SubsForumID.$ExStr,$Settings['qstr'],$Settings['qsep'],$prexqstr[$SubsForumType],$exqstr[$SubsForumType]);
122 $sfurl = "<a title=\"".$SubsForumDescription."\" href=\"".$sfurl."\">".$SubsForumName."</a>";
123 if($apcl==1) {
124 $sflist = "Subforums:";
125 $sflist = $sflist." ".$sfurl; }
126 if($apcl>1) {
127 $sflist = $sflist.", ".$sfurl; }
128 $gltf[$apcl] = $SubsForumID; ++$apcl; }
129 ++$apci; }
130 sql_free_result($apcresult); } }
131 if(isset($PermissionInfo['CanViewForum'][$ForumID])&&
132     $PermissionInfo['CanViewForum'][$ForumID]=="yes") {
133 $LastTopic = "&nbsp;<br />&nbsp;<br />&nbsp;";
134 if(!isset($LastTopic)) { $LastTopic = null; }
135 $gltnum = count($gltf); $glti = 0;
136 $OldUpdateTime = 0; $UseThisFonum = null;
137 if ($ForumType=="subforum") {
138 while ($glti < $gltnum) {
139 $ExtraIgnores = null;
140 if($PermissionInfo['CanModForum'][$gltf[$glti]]=="no") {
141         $ExtraIgnores = " AND \"Closed\"<>3"; }
142 $gltfoquery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."topics\" WHERE \"ForumID\"=%i".$ExtraIgnores." ORDER BY \"LastUpdate\" DESC LIMIT 1", array($gltf[$glti]));
143 $gltforesult=sql_query($gltfoquery,$SQLStat);
144 $gltfonum=sql_num_rows($gltforesult);
145 if($gltfonum>0) {
146 $NewUpdateTime=sql_result($gltforesult,0,"LastUpdate");
147 if($NewUpdateTime>$OldUpdateTime) {
148     $UseThisFonum = $gltf[$glti];
149 $OldUpdateTime = $NewUpdateTime; } }
150 sql_free_result($gltforesult);
151 ++$glti; } 
152 if($UseThisFonum==0) {
153         $UseThisFonum = $gltf[0]; } }
154 if ($ForumType!="subforum"&&$ForumType!="redirect") { $UseThisFonum = $gltf[0]; }
155 if ($ForumType!="redirect") {
156 $ExtraIgnores = null;
157 if($PermissionInfo['CanModForum'][$UseThisFonum]=="no") {
158         $ExtraIgnores = " AND \"Closed\"<>3"; }
159 $gltquery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."topics\" WHERE (\"ForumID\"=%i".$ExtraIgnores.$ForumIgnoreList4.") OR (\"OldForumID\"=%i".$ExtraIgnores.$ForumIgnoreList4.") ORDER BY \"LastUpdate\" DESC LIMIT 1", array($UseThisFonum,$UseThisFonum));
160 $gltresult=sql_query($gltquery,$SQLStat);
161 $gltnum=sql_num_rows($gltresult);
162 if($gltnum>0){
163 $TopicID=sql_result($gltresult,0,"id");
164 $TopicName=sql_result($gltresult,0,"TopicName");
165 $NumReplys=sql_result($gltresult,0,"NumReply");
166 $NumPages = null; $NumRPosts = $NumReplys + 1;
167 if(!isset($Settings['max_posts'])) { $Settings['max_posts'] = 10; }
168 if($NumRPosts>$Settings['max_posts']) {
169 $NumPages = ceil($NumRPosts/$Settings['max_posts']); }
170 if($NumRPosts<=$Settings['max_posts']) { $NumPages = 1; }
171 $TopicName1 = pre_substr($TopicName,0,20);
172 $oldtopicname=$TopicName;
173 if (pre_strlen($TopicName)>20) {
174 $TopicName1 = $TopicName1."..."; $TopicName=$TopicName1; }
175 $glrquery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."posts\" WHERE \"TopicID\"=%i ORDER BY \"TimeStamp\" DESC LIMIT 1", array($TopicID));
176 $glrresult=sql_query($glrquery,$SQLStat);
177 $glrnum=sql_num_rows($glrresult);
178 if($glrnum>0){
179 $ReplyID=sql_result($glrresult,0,"id");
180 $UsersID=sql_result($glrresult,0,"UserID");
181 $GuestsName=sql_result($glrresult,0,"GuestName");
182 $TimeStamp=sql_result($glrresult,0,"TimeStamp");
183 $tmpusrcurtime = new DateTime();
184 $tmpusrcurtime->setTimestamp($TimeStamp);
185 $tmpusrcurtime->setTimezone($usertz);
186 $TimeStamp=$tmpusrcurtime->format($_SESSION['iDBDateFormat'].", ".$_SESSION['iDBTimeFormat']);
187 sql_free_result($glrresult); }
188 $PreUsersName = GetUserName($UsersID,$Settings['sqltable'],$SQLStat);
189 if($PreUsersName['Name']===null) { $UsersID = -1;
190 $PreUsersName = GetUserName($UsersID,$Settings['sqltable'],$SQLStat); }
191 $UsersName = $PreUsersName['Name'];
192 $UsersHidden = $PreUsersName['Hidden'];
193 $UsersName1 = pre_substr($UsersName,0,20);
194 if($UsersName=="Guest") { $UsersName=$GuestsName;
195 if($UsersName==null) { $UsersName="Guest"; } }
196 $oldusername=$UsersName;
197 if (pre_strlen($UsersName)>20) {
198 $UsersName1 = $UsersName1."..."; $UsersName=$UsersName1; }
199 $lul = null;
200 if($UsersID>0&&$UsersHidden=="no") {
201 $lul = url_maker($exfile['member'],$Settings['file_ext'],"act=view&id=".$UsersID,$Settings['qstr'],$Settings['qsep'],$prexqstr['member'],$exqstr['member']);
202 $LastTopic = $TimeStamp."<br />\nTopic: <a href=\"".url_maker($exfile['topic'],$Settings['file_ext'],"act=view&id=".$TopicID."&page=".$NumPages,$Settings['qstr'],$Settings['qsep'],$prexqstr['topic'],$exqstr['topic']).$qstrhtml."&#35;reply".$NumRPosts."\" title=\"".$oldtopicname."\">".$TopicName."</a><br />\nUser: <a href=\"".$lul."\" title=\"".$oldusername."\">".$UsersName."</a>"; }
203 if($UsersID<=0||$UsersHidden=="yes") {
204 if($UsersID==-1) { $UserPre = "Guest:"; }
205 if(($UsersID<-1&&$UsersHidden=="yes")||$UsersID==0||($UsersID>0&&$UsersHidden=="yes")) {
206     $UserPre = "Hidden:"; }
207 $LastTopic = $TimeStamp."<br />\nTopic: <a href=\"".url_maker($exfile['topic'],$Settings['file_ext'],"act=view&id=".$TopicID."&page=".$NumPages,$Settings['qstr'],$Settings['qsep'],$prexqstr['topic'],$exqstr['topic']).$qstrhtml."&#35;reply".$NumRPosts."\" title=\"".$oldtopicname."\">".$TopicName."</a><br />\n".$UserPre." <span title=\"".$oldusername."\">".$UsersName."</span>"; } }
208 if($LastTopic==null) { $LastTopic="&nbsp;<br />&nbsp;"; }
209 sql_free_result($gltresult); }
210 if ($ForumType=="redirect") { $LastTopic="&nbsp;<br />Redirects: ".$NumRedirects."<br />&nbsp;"; }
211 $PreForum = $ThemeSet['ForumIcon'];
212 if ($ForumType=="forum") { $PreForum=$ThemeSet['ForumIcon']; }
213 if ($ForumType=="subforum") { $PreForum=$ThemeSet['SubForumIcon']; }
214 if ($ForumType=="redirect") { $PreForum=$ThemeSet['RedirectIcon']; }
215 $ExStr = ""; if ($ForumType!="redirect"&&
216     $ForumShowTopics!="no") { $ExStr = "&page=1"; }
217 if($ThemeSet['ForumStyle']==1) {
218         $ForumClass[1] = " class=\"TableColumn3\" ";
219         $ForumClass[2] = " class=\"TableColumn3\" ";
220         $ForumClass[3] = " class=\"TableColumn3\" ";
221         $ForumClass[4] = " class=\"TableColumn3\" ";
222         $ForumClass[5] = " class=\"TableColumn3\" "; }
223 if($ThemeSet['ForumStyle']==2) {
224         $ForumClass[1] = " class=\"TableColumn3\" ";
225         $ForumClass[2] = " class=\"TableColumn3\" ";
226         $ForumClass[3] = " class=\"TableColumn3Alt\" ";
227         $ForumClass[4] = " class=\"TableColumn3Alt\" ";
228         $ForumClass[5] = " class=\"TableColumn3Alt\" "; }
229 ?>
230 <tr class="TableRow3" id="Forum<?php echo $ForumID; ?>">
231 <td<?php echo $ForumClass[1]; ?>><div class="forumicon">
232 <?php echo $PreForum; ?></div></td>
233 <td<?php echo $ForumClass[2]; ?>><div class="forumname"><a href="<?php echo url_maker($exfile[$ForumType],$Settings['file_ext'],"act=view&id=".$ForumID.$ExStr,$Settings['qstr'],$Settings['qsep'],$prexqstr[$ForumType],$exqstr[$ForumType]); ?>"<?php if($ForumType=="redirect") { echo " onclick=\"window.open(this.href);return false;\""; } ?>><?php echo $ForumName; ?></a></div>
234 <div class="forumdescription">
235 <?php echo $ForumDescription; ?><br />
236 <?php echo $sflist; ?></div></td>
237 <td<?php echo $ForumClass[3]; ?>style="text-align: center;"><?php echo $NumTopics; ?></td>
238 <td<?php echo $ForumClass[4]; ?>style="text-align: center;"><?php echo $NumPosts; ?></td>
239 <td<?php echo $ForumClass[5]; ?>><?php echo $LastTopic; ?></td>
240 </tr>
241 <?php } ++$i; } sql_free_result($result);
242 if($num>=1) {
243 ?>
244 <tr id="CatEnd<?php echo $CategoryID; ?>" class="TableRow4">
245 <td class="TableColumn4" colspan="5">&nbsp;</td>
246 </tr>
247 </table></div>
248 <?php if($prei < $prenum - 1) { ?>
249 <div class="DivForums">&nbsp;</div>
250 <?php } if($prei == $prenum - 1) { ?>
251 <div class="DivStsts">&nbsp;</div>
252 <?php } } } ++$prei; }
253 sql_free_result($preresult); ?>