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