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