OSDN Git Service

Small bug fix for hidden categories. :P
[idb/iDB.git.git] / inc / categories.php
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.
5
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.
10
11     Copyright 2004-2007 Cool Dude 2k - http://intdb.sourceforge.net/
12     Copyright 2004-2007 Game Maker 2k - http://upload.idb.s1.jcink.com/
13
14     $FileInfo: categories.php - Last Update: 09/30/2007 SVN 113 - Author: cooldude2k $
15 */
16 $File3Name = basename($_SERVER['SCRIPT_NAME']);
17 if ($File3Name=="categories.php"||$File3Name=="/categories.php") {
18         require('index.php');
19         exit(); }
20 $prequery = query("SELECT * FROM `".$Settings['sqltable']."categories` WHERE `id`=%i", array($_GET['id']));
21 $preresult=mysql_query($prequery);
22 $prenum=mysql_num_rows($preresult);
23 if($prenum==0) { redirect("location",$basedir.url_maker($exfile['index'],$Settings['file_ext'],"act=view",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false)); @mysql_free_result($preresult);
24 ob_clean(); @header("Content-Type: text/plain; charset=".$Settings['charset']);
25 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); @mysql_close(); die(); }
26 if($prenum>=1) {
27 $CategoryID=mysql_result($preresult,0,"id");
28 $CategoryName=mysql_result($preresult,0,"Name");
29 $CategoryShow=mysql_result($preresult,0,"ShowCategory");
30 $CategoryType=mysql_result($preresult,0,"CategoryType");
31 $SubShowForums=mysql_result($preresult,0,"SubShowForums");
32 $CategoryDescription=mysql_result($preresult,0,"Description");
33 $CategoryType = strtolower($CategoryType); $SubShowForums = strtolower($SubShowForums);
34 if(!isset($CatPermissionInfo['CanViewCategory'][$CategoryID])) {
35         $CatPermissionInfo['CanViewCategory'][$CategoryID] = "no"; }
36 if($CatPermissionInfo['CanViewCategory'][$CategoryID]=="no"||
37         $CatPermissionInfo['CanViewCategory'][$CategoryID]!="yes") {
38 redirect("location",$basedir.url_maker($exfile['index'],$Settings['file_ext'],"act=view",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false));
39 ob_clean(); @header("Content-Type: text/plain; charset=".$Settings['charset']);
40 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); @mysql_close(); die(); }
41 if($CatPermissionInfo['CanViewCategory'][$CategoryID]=="yes") {
42 if(!isset($CatCheck)) { $CatCheck = null; } 
43 if($CatCheck!="skip") {
44 if($CategoryType=="subcategory") {
45 redirect("location",$basedir.url_maker($exfile['subcategory'],$Settings['file_ext'],"act=".$_GET['act']."&id=".$_GET['id'],$Settings['qstr'],$Settings['qsep'],$prexqstr['subcategory'],$exqstr['subcategory'],FALSE));
46 ob_clean(); @header("Content-Type: text/plain; charset=".$Settings['charset']);
47 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); @mysql_close(); die(); } }
48 $query = query("SELECT * FROM `".$Settings['sqltable']."forums` WHERE `ShowForum`='yes' AND `CategoryID`=%i AND `InSubForum`=0 ORDER BY `OrderID` ASC, `id` ASC", array($CategoryID));
49 $result=mysql_query($query);
50 $num=mysql_num_rows($result);
51 $i=0;
52 if($num>=1) {
53 ?>
54 <div class="Table1Border">
55 <table id="Cat<?php echo $CategoryID; ?>" class="Table1">
56 <tr id="CatStart<?php echo $CategoryID; ?>" class="TableRow1">
57 <td class="TableRow1" colspan="5"><span style="float: left;">
58 <?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>
59 <?php echo "<span style=\"float: right;\">&nbsp;</span>"; ?></td>
60 </tr>
61 <tr id="ForumStatRow<?php echo $CategoryID; ?>" class="TableRow2">
62 <th class="TableRow2" style="width: 4%;">&nbsp;</th>
63 <th class="TableRow2" style="width: 58%;">Forum</th>
64 <th class="TableRow2" style="width: 7%;">Topics</th>
65 <th class="TableRow2" style="width: 7%;">Posts</th>
66 <th class="TableRow2" style="width: 24%;">Last Topic</th>
67 </tr>
68 <?php }
69 while ($i < $num) {
70 $ForumID=mysql_result($result,$i,"id");
71 $ForumName=mysql_result($result,$i,"Name");
72 $ForumShow=mysql_result($result,$i,"ShowForum");
73 $ForumType=mysql_result($result,$i,"ForumType");
74 $NumTopics=mysql_result($result,$i,"NumTopics");
75 $NumPosts=mysql_result($result,$i,"NumPosts");
76 $NumRedirects=mysql_result($result,$i,"Redirects");
77 $ForumDescription=mysql_result($result,$i,"Description");
78 $ForumType = strtolower($ForumType);
79 $gltf = array(null); $gltf[0] = $ForumID;
80 if ($ForumType=="subforum") { 
81 $apcquery = query("SELECT * FROM `".$Settings['sqltable']."forums` WHERE `ShowForum`='yes' AND `InSubForum`=%i ORDER BY `OrderID` ASC, `id` ASC", array($ForumID));
82 $apcresult=mysql_query($apcquery);
83 $apcnum=mysql_num_rows($apcresult);
84 $apci=0; $apcl=1; if($apcnum>=1) {
85 while ($apci < $apcnum) {
86 $NumsTopics=mysql_result($apcresult,$apci,"NumTopics");
87 $NumTopics = $NumsTopics + $NumTopics;
88 $NumsPosts=mysql_result($apcresult,$apci,"NumPosts");
89 $NumPosts = $NumsPosts + $NumPosts;
90 $SubsForumID=mysql_result($apcresult,$apci,"id");
91 if(isset($PermissionInfo['CanViewForum'][$SubsForumID])&&
92         $PermissionInfo['CanViewForum'][$SubsForumID]=="yes") {
93 $gltf[$apcl] = $SubsForumID; ++$apcl; }
94 ++$apci; }
95 @mysql_free_result($apcresult); } }
96 if(isset($PermissionInfo['CanViewForum'][$ForumID])&&
97         $PermissionInfo['CanViewForum'][$ForumID]=="yes") {
98 unset($LastTopic); if(!isset($LastTopic)) { $LastTopic = null; }
99 $gltnum = count($gltf); $glti = 0; 
100 $OldUpdateTime = 0; $UseThisFonum = null;
101 if ($ForumType=="subforum") { 
102 while ($glti < $gltnum) {
103 $gltfoquery = query("SELECT * FROM `".$Settings['sqltable']."topics` WHERE `CategoryID`=%i AND `ForumID`=%i ORDER BY `LastUpdate` DESC", array($CategoryID,$gltf[$glti]));
104 $gltforesult=mysql_query($gltfoquery);
105 $gltfonum=mysql_num_rows($gltforesult);
106 if($gltfonum>0) {
107 $NewUpdateTime=mysql_result($gltforesult,0,"LastUpdate");
108 if($NewUpdateTime>$OldUpdateTime) { 
109         $UseThisFonum = $gltf[$glti]; 
110 $OldUpdateTime = $NewUpdateTime; } }
111 @mysql_free_result($gltforesult);
112 ++$glti; } }
113 if ($ForumType!="subforum"&&$ForumType!="redirect") { $UseThisFonum = $gltf[0]; }
114 if ($ForumType!="redirect") {
115 $gltquery = query("SELECT * FROM `".$Settings['sqltable']."topics` WHERE `CategoryID`=%i AND `ForumID`=%i ORDER BY `LastUpdate` DESC", array($CategoryID,$UseThisFonum));
116 $gltresult=mysql_query($gltquery);
117 $gltnum=mysql_num_rows($gltresult);
118 if($gltnum>0){
119 $TopicID=mysql_result($gltresult,0,"id");
120 $TopicName=mysql_result($gltresult,0,"TopicName");
121 $NumReplys=mysql_result($gltresult,0,"NumReply");
122 $ShowReply = $NumReplys + 1;
123 $TopicName1 = substr($TopicName,0,15);
124 if (strlen($TopicName)>12) { $TopicName1 = $TopicName1."..."; }
125 $UsersID=mysql_result($gltresult,0,"UserID");
126 $GuestName=mysql_result($gltresult,0,"GuestName");
127 $UsersName = GetUserName($UsersID,$Settings['sqltable']);
128 if($UsersName=="Guest") { $UsersName=$GuestName;
129 if($UsersName==null) { $UsersName="Guest"; } }
130 $UsersName1 = substr($UsersName,0,18);
131 if (strlen($UsersName)>15) { $UsersName1 = $UsersName1."...";
132 $oldtopicname=$TopicName; $oldusername=$UsersName;
133 $TopicName=$TopicName1; $UsersName=$UsersName1; } $lul = null;
134 if($UsersID!="-1") {
135 $lul = url_maker($exfile['member'],$Settings['file_ext'],"act=view&id=".$UsersID,$Settings['qstr'],$Settings['qsep'],$prexqstr['member'],$exqstr['member']);
136 $LastTopic = "User: <a href=\"".$lul."\" title=\"".$oldusername."\">".$UsersName."</a><br />\nTopic: <a href=\"".url_maker($exfile['topic'],$Settings['file_ext'],"act=view&id=".$TopicID,$Settings['qstr'],$Settings['qsep'],$prexqstr['topic'],$exqstr['topic'])."#reply".$ShowReply."\" title=\"".$oldtopicname."\">".$TopicName."</a>"; }
137 if($UsersID=="-1") {
138 $LastTopic = "User: <span title=\"".$oldusername."\">".$UsersName."</span><br />\nTopic: <a href=\"".url_maker($exfile['topic'],$Settings['file_ext'],"act=view&id=".$TopicID,$Settings['qstr'],$Settings['qsep'],$prexqstr['topic'],$exqstr['topic'])."#reply".$ShowReply."\" title=\"".$oldtopicname."\">".$TopicName."</a>"; } }
139 if($LastTopic==null) { $LastTopic="&nbsp;<br />&nbsp;"; } }
140 @mysql_free_result($gltresult);
141 if ($ForumType=="redirect") { $LastTopic="Redirects: ".$NumRedirects; }
142 $PreForum = $ThemeSet['ForumIcon'];
143 if ($ForumType=="forum") { $PreForum=$ThemeSet['ForumIcon']; }
144 if ($ForumType=="subforum") { $PreForum=$ThemeSet['SubForumIcon']; }
145 if ($ForumType=="redirect") { $PreForum=$ThemeSet['RedirectIcon']; }
146 ?>
147 <tr class="TableRow3" id="Forum<?php echo $ForumID; ?>">
148 <td class="TableRow3"><div class="forumicon">
149 <?php echo $PreForum; ?></div></td>
150 <td class="TableRow3"><div class="forumname"><a href="<?php echo url_maker($exfile[$ForumType],$Settings['file_ext'],"act=view&id=".$ForumID,$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>
151 <div class="forumescription"><?php echo $ForumDescription; ?></div></td>
152 <td class="TableRow3" style="text-align: center;"><?php echo $NumTopics; ?></td>
153 <td class="TableRow3" style="text-align: center;"><?php echo $NumPosts; ?></td>
154 <td class="TableRow3"><?php echo $LastTopic; ?></td>
155 </tr>
156 <?php } ++$i; } @mysql_free_result($result);
157 if($num>=1) { ?>
158 <tr id="CatEnd<?php echo $CategoryID; ?>" class="TableRow4">
159 <td class="TableRow4" colspan="5">&nbsp;</td>
160 </tr>
161 </table></div>
162 <div>&nbsp;</div>
163 <?php } } }
164 @mysql_free_result($preresult); ?>