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