Add new setting idb_time_format. :P
[iDB.git] / inc / categories.php
blobe4c99e1e7562fb15649b464ab8862fda022d2b79
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: 07/18/2011 SVN 720 - 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=="yes") { $_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 if($InSubCategory!="0") {
68 $iscquery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."categories\" WHERE \"id\"=%i".$CatIgnoreList2." LIMIT 1", array($InSubCategory));
69 $iscresult=sql_query($iscquery,$SQLStat);
70 $iscnum=sql_num_rows($iscresult);
71 if($iscnum>=1) {
72 $iscCategoryID=sql_result($iscresult,0,"id");
73 $iscCategoryName=sql_result($iscresult,0,"Name");
74 $iscCategoryShow=sql_result($iscresult,0,"ShowCategory");
75 $iscCategoryType=sql_result($iscresult,0,"CategoryType");
76 $iscCategoryType = strtolower($iscCategoryType); }
77 if($iscnum<1) { $InSubCategory = "0"; }
78 sql_free_result($iscresult); }
80 <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>
81 <div class="DivNavLinks">&nbsp;</div>
82 <?php
83 if($CategoryType=="subcategory") {
84 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));
85 ob_clean(); header("Content-Type: text/plain; charset=".$Settings['charset']); $urlstatus = 302;
86 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); } }
87 $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));
88 $result=sql_query($query,$SQLStat);
89 $num=sql_num_rows($result);
90 $i=0;
91 if($num>=1) {
93 <div class="Table1Border">
94 <?php if($ThemeSet['TableStyle']=="div") { ?>
95 <div class="TableRow1">
96 <span style="text-align: left;">
97 <?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>
98 <?php } ?>
99 <table id="Cat<?php echo $CategoryID; ?>" class="Table1">
100 <?php if($ThemeSet['TableStyle']=="table") { ?>
101 <tr id="CatStart<?php echo $CategoryID; ?>" class="TableRow1">
102 <td class="TableColumn1" colspan="5"><span style="text-align: left;">
103 <?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>
104 </td>
105 </tr><?php } ?>
106 <tr id="ForumStatRow<?php echo $CategoryID; ?>" class="TableRow2">
107 <th class="TableColumn2" style="width: 4%;">&nbsp;</th>
108 <th class="TableColumn2" style="width: 58%;">Forum</th>
109 <th class="TableColumn2" style="width: 7%;">Topics</th>
110 <th class="TableColumn2" style="width: 7%;">Posts</th>
111 <th class="TableColumn2" style="width: 24%;">Last Topic</th>
112 </tr>
113 <?php }
114 while ($i < $num) {
115 $ForumID=sql_result($result,$i,"id");
116 $ForumName=sql_result($result,$i,"Name");
117 $ForumShow=sql_result($result,$i,"ShowForum");
118 $ForumType=sql_result($result,$i,"ForumType");
119 $ForumShowTopics=sql_result($result,$i,"CanHaveTopics");
120 $ForumShowTopics = strtolower($ForumShowTopics);
121 $NumTopics=sql_result($result,$i,"NumTopics");
122 $NumPosts=sql_result($result,$i,"NumPosts");
123 $NumRedirects=sql_result($result,$i,"Redirects");
124 $ForumDescription=sql_result($result,$i,"Description");
125 $ForumType = strtolower($ForumType); $sflist = null;
126 $gltf = array(null); $gltf[0] = $ForumID;
127 if ($ForumType=="subforum") {
128 $apcquery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."forums\" WHERE \"ShowForum\"='yes' AND \"InSubForum\"=%i".$ForumIgnoreList2." ORDER BY \"OrderID\" ASC, \"id\" ASC", array($ForumID));
129 $apcresult=sql_query($apcquery,$SQLStat);
130 $apcnum=sql_num_rows($apcresult);
131 $apci=0; $apcl=1; if($apcnum>=1) {
132 while ($apci < $apcnum) {
133 $NumsTopics=sql_result($apcresult,$apci,"NumTopics");
134 $NumTopics = $NumsTopics + $NumTopics;
135 $NumsPosts=sql_result($apcresult,$apci,"NumPosts");
136 $NumPosts = $NumsPosts + $NumPosts;
137 $SubsForumID=sql_result($apcresult,$apci,"id");
138 $SubsForumName=sql_result($apcresult,$apci,"Name");
139 $SubsForumType=sql_result($apcresult,$apci,"ForumType");
140 $SubsForumShowTopics=sql_result($result,$i,"CanHaveTopics");
141 if(isset($PermissionInfo['CanViewForum'][$SubsForumID])&&
142 $PermissionInfo['CanViewForum'][$SubsForumID]=="yes") {
143 $ExStr = ""; if ($SubsForumType!="redirect"&&
144 $SubsForumShowTopics!="no") { $ExStr = "&page=1"; }
145 $sfurl = "<a href=\"";
146 $sfurl = url_maker($exfile[$SubsForumType],$Settings['file_ext'],"act=view&id=".$SubsForumID.$ExStr,$Settings['qstr'],$Settings['qsep'],$prexqstr[$SubsForumType],$exqstr[$SubsForumType]);
147 $sfurl = "<a href=\"".$sfurl."\">".$SubsForumName."</a>";
148 if($apcl==1) {
149 $sflist = "Subforums:";
150 $sflist = $sflist." ".$sfurl; }
151 if($apcl>1) {
152 $sflist = $sflist.", ".$sfurl; }
153 $gltf[$apcl] = $SubsForumID; ++$apcl; }
154 ++$apci; }
155 sql_free_result($apcresult); } }
156 if(isset($PermissionInfo['CanViewForum'][$ForumID])&&
157 $PermissionInfo['CanViewForum'][$ForumID]=="yes") {
158 $LastTopic = "&nbsp;<br />&nbsp;<br />&nbsp;";
159 if(!isset($LastTopic)) { $LastTopic = null; }
160 $gltnum = count($gltf); $glti = 0;
161 $OldUpdateTime = 0; $UseThisFonum = null;
162 if ($ForumType=="subforum") {
163 while ($glti < $gltnum) {
164 $ExtraIgnores = null;
165 if($PermissionInfo['CanModForum'][$gltf[$glti]]=="no") {
166 $ExtraIgnores = " AND \"Closed\"<>3"; }
167 $gltfoquery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."topics\" WHERE \"ForumID\"=%i".$ExtraIgnores.$ForumIgnoreList4." ORDER BY \"LastUpdate\" DESC LIMIT 1", array($gltf[$glti]));
168 $gltforesult=sql_query($gltfoquery,$SQLStat);
169 $gltfonum=sql_num_rows($gltforesult);
170 if($gltfonum>0) {
171 $NewUpdateTime=sql_result($gltforesult,0,"LastUpdate");
172 if($NewUpdateTime>$OldUpdateTime) {
173 $UseThisFonum = $gltf[$glti];
174 $OldUpdateTime = $NewUpdateTime; }
175 sql_free_result($gltforesult); }
176 ++$glti; }
177 if($UseThisFonum==0) {
178 $UseThisFonum = $gltf[0]; } }
179 if ($ForumType!="subforum"&&$ForumType!="redirect") { $UseThisFonum = $gltf[0]; }
180 if ($ForumType!="redirect") {
181 $ExtraIgnores = null;
182 if($PermissionInfo['CanModForum'][$UseThisFonum]=="no") {
183 $ExtraIgnores = " AND \"Closed\"<>3"; }
184 $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));
185 $gltresult=sql_query($gltquery,$SQLStat);
186 $gltnum=sql_num_rows($gltresult);
187 if($gltnum>0){
188 $TopicID=sql_result($gltresult,0,"id");
189 $TopicName=sql_result($gltresult,0,"TopicName");
190 $NumReplys=sql_result($gltresult,0,"NumReply");
191 $NumPages = null; $NumRPosts = $NumReplys + 1;
192 if(!isset($Settings['max_posts'])) { $Settings['max_posts'] = 10; }
193 if($NumRPosts>$Settings['max_posts']) {
194 $NumPages = ceil($NumRPosts/$Settings['max_posts']); }
195 if($NumRPosts<=$Settings['max_posts']) { $NumPages = 1; }
196 $TopicName1 = pre_substr($TopicName,0,20);
197 $oldtopicname=$TopicName;
198 if (pre_strlen($TopicName)>20) {
199 $TopicName1 = $TopicName1."..."; $TopicName=$TopicName1; }
200 $glrquery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."posts\" WHERE \"TopicID\"=%i ORDER BY \"TimeStamp\" DESC LIMIT 1", array($TopicID));
201 $glrresult=sql_query($glrquery,$SQLStat);
202 $glrnum=sql_num_rows($glrresult);
203 if($glrnum>0){
204 $ReplyID=sql_result($glrresult,0,"id");
205 $UsersID=sql_result($glrresult,0,"UserID");
206 $GuestsName=sql_result($glrresult,0,"GuestName");
207 $TimeStamp=sql_result($glrresult,0,"TimeStamp");
208 $TimeStamp=GMTimeChange("F j Y, ".$Settings['idb_time_format'],$TimeStamp,$_SESSION['UserTimeZone'],0,$_SESSION['UserDST']);
209 sql_free_result($glrresult); }
210 $PreUsersName = GetUserName($UsersID,$Settings['sqltable'],$SQLStat);
211 if($PreUsersName['Name']===null) { $UsersID = -1;
212 $PreUsersName = GetUserName($UsersID,$Settings['sqltable'],$SQLStat); }
213 $UsersName = $PreUsersName['Name'];
214 $UsersHidden = $PreUsersName['Hidden'];
215 if($UsersName=="Guest") { $UsersName=$GuestsName;
216 if($UsersName==null) { $UsersName="Guest"; } }
217 $UsersName1 = pre_substr($UsersName,0,20);
218 $oldusername=$UsersName;
219 if (pre_strlen($UsersName)>20) {
220 $UsersName1 = $UsersName1."..."; $UsersName=$UsersName1; }
221 $lul = null;
222 if($UsersID>0&&$UsersHidden=="no") {
223 $lul = url_maker($exfile['member'],$Settings['file_ext'],"act=view&id=".$UsersID,$Settings['qstr'],$Settings['qsep'],$prexqstr['member'],$exqstr['member']);
224 $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>"; }
225 if($UsersID<=0||$UsersHidden=="yes") {
226 if($UsersID==-1) { $UserPre = "Guest:"; }
227 if(($UsersID<-1&&$UsersHidden=="yes")||$UsersID==0||($UsersID>0&&$UsersHidden=="yes")) {
228 $UserPre = "Hidden:"; }
229 $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>"; } }
230 if($LastTopic==null) { $LastTopic = "&nbsp;<br />&nbsp;<br />&nbsp;"; }
231 sql_free_result($gltresult); }
232 if ($ForumType=="redirect") { $LastTopic="&nbsp;<br />Redirects: ".$NumRedirects."<br />&nbsp;"; }
233 $PreForum = $ThemeSet['ForumIcon'];
234 if ($ForumType=="forum") { $PreForum=$ThemeSet['ForumIcon']; }
235 if ($ForumType=="subforum") { $PreForum=$ThemeSet['SubForumIcon']; }
236 if ($ForumType=="redirect") { $PreForum=$ThemeSet['RedirectIcon']; }
237 $ExStr = ""; if ($ForumType!="redirect"&&
238 $ForumShowTopics!="no") { $ExStr = "&page=1"; }
239 if($ThemeSet['ForumStyle']==1) {
240 $ForumClass[1] = " class=\"TableColumn3\" ";
241 $ForumClass[2] = " class=\"TableColumn3\" ";
242 $ForumClass[3] = " class=\"TableColumn3\" ";
243 $ForumClass[4] = " class=\"TableColumn3\" ";
244 $ForumClass[5] = " class=\"TableColumn3\" "; }
245 if($ThemeSet['ForumStyle']==2) {
246 $ForumClass[1] = " class=\"TableColumn3\" ";
247 $ForumClass[2] = " class=\"TableColumn3\" ";
248 $ForumClass[3] = " class=\"TableColumn3Alt\" ";
249 $ForumClass[4] = " class=\"TableColumn3Alt\" ";
250 $ForumClass[5] = " class=\"TableColumn3Alt\" "; }
252 <tr class="TableRow3" id="Forum<?php echo $ForumID; ?>">
253 <td<?php echo $ForumClass[1]; ?>><div class="forumicon">
254 <?php echo $PreForum; ?></div></td>
255 <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>
256 <div class="forumdescription">
257 <?php echo $ForumDescription; ?><br />
258 <?php echo $sflist; ?></div></td>
259 <td<?php echo $ForumClass[3]; ?>style="text-align: center;"><?php echo $NumTopics; ?></td>
260 <td<?php echo $ForumClass[4]; ?>style="text-align: center;"><?php echo $NumPosts; ?></td>
261 <td<?php echo $ForumClass[5]; ?>><?php echo $LastTopic; ?></td>
262 </tr>
263 <?php } ++$i; } sql_free_result($result);
264 if($num>=1) { ?>
265 <tr id="CatEnd<?php echo $CategoryID; ?>" class="TableRow4">
266 <td class="TableColumn4" colspan="5">&nbsp;</td>
267 </tr>
268 </table></div>
269 <div class="DivCategories">&nbsp;</div>
270 <?php } } }
271 sql_free_result($preresult); ?>