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