OSDN Git Service

ba2feaa6ec76e5fc0095d3b41d9cd1d511b6d891
[idb/iDB.git.git] / inc / subcategories.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-2008 Cool Dude 2k - http://idb.berlios.de/
12     Copyright 2004-2008 Game Maker 2k - http://intdb.sourceforge.net/
13
14     $FileInfo: subcategories.php - Last Update: 12/05/2008 SVN 199 - Author: cooldude2k $
15 */
16 $File3Name = basename($_SERVER['SCRIPT_NAME']);
17 if ($File3Name=="subcategories.php"||$File3Name=="/subcategories.php") {
18         require('index.php');
19         exit(); }
20 if(!is_numeric($_GET['id'])) { $_GET['id'] = null; }
21 $checkquery = query("SELECT * FROM `".$Settings['sqltable']."categories` WHERE `id`=%i LIMIT 1", array($_GET['id']));
22 $checkresult=mysql_query($checkquery);
23 $checknum=mysql_num_rows($checkresult);
24 if($checknum==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($checkresult);
25 ob_clean(); @header("Content-Type: text/plain; charset=".$Settings['charset']);
26 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); @mysql_close(); die(); }
27 if($checknum>=1) {
28 $CategoryID=mysql_result($checkresult,0,"id");
29 $CategoryName=mysql_result($checkresult,0,"Name");
30 $CategoryShow=mysql_result($checkresult,0,"ShowCategory");
31 $CategoryType=mysql_result($checkresult,0,"CategoryType");
32 $SubShowForums=mysql_result($checkresult,0,"SubShowForums");
33 $CategoryType = strtolower($CategoryType); $SubShowForums = strtolower($SubShowForums);
34 $SCategoryName = $CategoryName;
35 if(!isset($CatPermissionInfo['CanViewCategory'][$CategoryID])) {
36         $CatPermissionInfo['CanViewCategory'][$CategoryID] = "no"; }
37 if($CatPermissionInfo['CanViewCategory'][$CategoryID]=="no"||
38         $CatPermissionInfo['CanViewCategory'][$CategoryID]!="yes") {
39 redirect("location",$basedir.url_maker($exfile['index'],$Settings['file_ext'],"act=view",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false));
40 ob_clean(); @header("Content-Type: text/plain; charset=".$Settings['charset']);
41 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); @mysql_close(); die(); }
42 if($CatPermissionInfo['CanViewCategory'][$CategoryID]=="yes") {
43 ?>
44 <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 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>
45 <div class="DivNavLinks">&nbsp;</div>
46 <?php
47 if($CategoryType=="category") {
48 redirect("location",$basedir.url_maker($exfile['category'],$Settings['file_ext'],"act=".$_GET['act']."&id=".$_GET['id'],$Settings['qstr'],$Settings['qsep'],$prexqstr['category'],$exqstr['category'],FALSE));
49 ob_clean(); @header("Content-Type: text/plain; charset=".$Settings['charset']);
50 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); @mysql_close(); die(); }
51 @mysql_free_result($checkresult);
52 $prequery = query("SELECT * FROM `".$Settings['sqltable']."categories` WHERE `ShowCategory`='yes' AND `InSubCategory`=%i ORDER BY `OrderID` ASC, `id` ASC", array($_GET['id']));
53 $preresult=mysql_query($prequery);
54 $prenum=mysql_num_rows($preresult);
55 $prei=0;
56 while ($prei < $prenum) {
57 $CategoryID=mysql_result($preresult,$prei,"id");
58 $CategoryName=mysql_result($preresult,$prei,"Name");
59 $CategoryShow=mysql_result($preresult,$prei,"ShowCategory");
60 $CategoryType=mysql_result($preresult,$prei,"CategoryType");
61 $SSubShowForums=mysql_result($preresult,$prei,"SubShowForums");
62 $CategoryDescription=mysql_result($preresult,$prei,"Description");
63 $CategoryType = strtolower($CategoryType); $SubShowForums = strtolower($SubShowForums);
64 if(isset($CatPermissionInfo['CanViewCategory'][$CategoryID])&&
65         $CatPermissionInfo['CanViewCategory'][$CategoryID]=="yes") {
66 $query = query("SELECT * FROM `".$Settings['sqltable']."forums` WHERE `ShowForum`='yes' AND `CategoryID`=%i AND `InSubForum`=0 ORDER BY `OrderID` ASC, `id` ASC", array($CategoryID));
67 $result=mysql_query($query);
68 $num=mysql_num_rows($result);
69 $i=0;
70 if($num>=1) {
71 ?>
72 <div class="Table1Border">
73 <?php if($ThemeSet['TableStyle']=="div") { ?>
74 <div class="TableRow1">
75 <span style="text-align: left;">
76 <?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>
77 <?php } ?>
78 <table class="Table1" id="SubCat<?php echo $CategoryID; ?>">
79 <?php if($ThemeSet['TableStyle']=="table") { ?>
80 <tr id="SubCatStart<?php echo $CategoryID; ?>" class="TableRow1">
81 <td class="TableColumn1" colspan="5"><span style="text-align: left;">
82 <?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>
83 </td>
84 </tr><?php } ?>
85 <tr id="ForumStatRow<?php echo $CategoryID; ?>" class="TableRow2">
86 <th class="TableColumn2" style="width: 4%;">&nbsp;</th>
87 <th class="TableColumn2" style="width: 58%;">Forum</th>
88 <th class="TableColumn2" style="width: 7%;">Topics</th>
89 <th class="TableColumn2" style="width: 7%;">Posts</th>
90 <th class="TableColumn2" style="width: 24%;">Last Topic</th>
91 </tr>
92 <?php }
93 while ($i < $num) {
94 $ForumID=mysql_result($result,$i,"id");
95 $ForumName=mysql_result($result,$i,"Name");
96 $ForumShow=mysql_result($result,$i,"ShowForum");
97 $ForumType=mysql_result($result,$i,"ForumType");
98 $ForumShowTopics=mysql_result($result,$i,"CanHaveTopics");
99 $ForumShowTopics = strtolower($ForumShowTopics);
100 $NumTopics=mysql_result($result,$i,"NumTopics");
101 $NumPosts=mysql_result($result,$i,"NumPosts");
102 $NumRedirects=mysql_result($result,$i,"Redirects");
103 $ForumDescription=mysql_result($result,$i,"Description");
104 $ForumType = strtolower($ForumType);
105 $gltf = array(null); $gltf[0] = $ForumID;
106 if ($ForumType=="subforum") { 
107 $apcquery = query("SELECT * FROM `".$Settings['sqltable']."forums` WHERE `ShowForum`='yes' AND `InSubForum`=%i ORDER BY `OrderID` ASC, `id` ASC", array($ForumID));
108 $apcresult=mysql_query($apcquery);
109 $apcnum=mysql_num_rows($apcresult);
110 $apci=0; $apcl=1; if($apcnum>=1) {
111 while ($apci < $apcnum) {
112 $NumsTopics=mysql_result($apcresult,$apci,"NumTopics");
113 $NumTopics = $NumsTopics + $NumTopics;
114 $NumsPosts=mysql_result($apcresult,$apci,"NumPosts");
115 $NumPosts = $NumsPosts + $NumPosts;
116 $SubsForumID=mysql_result($apcresult,$apci,"id");
117 if(isset($PermissionInfo['CanViewForum'][$SubsForumID])&&
118         $PermissionInfo['CanViewForum'][$SubsForumID]=="yes") {
119 $gltf[$apcl] = $SubsForumID; ++$apcl; }
120 ++$apci; }
121 @mysql_free_result($apcresult); } }
122 if(isset($PermissionInfo['CanViewForum'][$ForumID])&&
123         $PermissionInfo['CanViewForum'][$ForumID]=="yes") {
124 $LastTopic = null; 
125 if(!isset($LastTopic)) { $LastTopic = null; }
126 $gltnum = count($gltf); $glti = 0; 
127 $OldUpdateTime = 0; $UseThisFonum = null;
128 if ($ForumType=="subforum") { 
129 while ($glti < $gltnum) {
130 $gltfoquery = query("SELECT * FROM `".$Settings['sqltable']."topics` WHERE `CategoryID`=%i AND `ForumID`=%i ORDER BY `LastUpdate` DESC LIMIT 1", array($CategoryID,$gltf[$glti]));
131 $gltforesult=mysql_query($gltfoquery);
132 $gltfonum=mysql_num_rows($gltforesult);
133 if($gltfonum>0) {
134 $NewUpdateTime=mysql_result($gltforesult,0,"LastUpdate");
135 if($NewUpdateTime>$OldUpdateTime) { 
136         $UseThisFonum = $gltf[$glti]; 
137 $OldUpdateTime = $NewUpdateTime; } }
138 @mysql_free_result($gltforesult);
139 ++$glti; } }
140 if ($ForumType!="subforum"&&$ForumType!="redirect") { $UseThisFonum = $gltf[0]; }
141 if ($ForumType!="redirect") {
142 $gltquery = query("SELECT * FROM `".$Settings['sqltable']."topics` WHERE `CategoryID`=%i AND `ForumID`=%i ORDER BY `LastUpdate` DESC LIMIT 1", array($CategoryID,$UseThisFonum));
143 $gltresult=mysql_query($gltquery);
144 $gltnum=mysql_num_rows($gltresult);
145 if($gltnum>0){
146 $TopicID=mysql_result($gltresult,0,"id");
147 $TopicName=mysql_result($gltresult,0,"TopicName");
148 $NumReplys=mysql_result($gltresult,0,"NumReply");
149 $ShowReply = $NumReplys + 1;
150 $TopicName1 = pre_substr($TopicName,0,20);
151 if (pre_strlen($TopicName)>20) { $TopicName1 = $TopicName1."..."; 
152 $oldtopicname=$TopicName; $TopicName=$TopicName1; }
153 $UsersID=mysql_result($gltresult,0,"UserID");
154 $GuestName=mysql_result($gltresult,0,"GuestName");
155 $UsersName = GetUserName($UsersID,$Settings['sqltable']);
156 $UsersName1 = pre_substr($UsersName,0,20);
157 if($UsersName=="Guest") { $UsersName=$GuestName;
158 if($UsersName==null) { $UsersName="Guest"; } }
159 if (pre_strlen($UsersName)>20) { $UsersName1 = $UsersName1."...";
160 $oldusername=$UsersName; $UsersName=$UsersName1; } $lul = null;
161 if($UsersID!="-1") {
162 $lul = url_maker($exfile['member'],$Settings['file_ext'],"act=view&id=".$UsersID,$Settings['qstr'],$Settings['qsep'],$prexqstr['member'],$exqstr['member']);
163 $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>"; }
164 if($UsersID=="-1") {
165 $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>"; } }
166 if($LastTopic==null) { $LastTopic="&nbsp;<br />&nbsp;"; } }
167 @mysql_free_result($gltresult);
168 if ($ForumType=="redirect") { $LastTopic="Redirects: ".$NumRedirects; }
169 $PreForum = $ThemeSet['ForumIcon'];
170 if ($ForumType=="forum") { $PreForum=$ThemeSet['ForumIcon']; }
171 if ($ForumType=="subforum") { $PreForum=$ThemeSet['SubForumIcon']; }
172 if ($ForumType=="redirect") { $PreForum=$ThemeSet['RedirectIcon']; }
173 $ExStr = ""; if ($ForumType!="redirect"&&
174         $ForumShowTopics!="no") { $ExStr = "&page=1"; }
175 ?>
176 <tr class="TableRow3" id="Forum<?php echo $ForumID; ?>">
177 <td class="TableColumn3"><div class="forumicon">
178 <?php echo $PreForum; ?></div></td>
179 <td class="TableColumn3"><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>
180 <div class="forumdescription"><?php echo $ForumDescription; ?></div></td>
181 <td class="TableColumn3" style="text-align: center;"><?php echo $NumTopics; ?></td>
182 <td class="TableColumn3" style="text-align: center;"><?php echo $NumPosts; ?></td>
183 <td class="TableColumn3"><?php echo $LastTopic; ?></td>
184 </tr>
185 <?php } ++$i; } @mysql_free_result($result);
186 if($num>=1) {
187 ?>
188 <tr id="SubCatEnd<?php echo $CategoryID; ?>" class="TableRow4">
189 <td class="TableColumn4" colspan="5">&nbsp;</td>
190 </tr>
191 </table></div>
192 <div class="DivSubCategories">&nbsp;</div>
193 <?php } } ++$prei; } }
194 @mysql_free_result($preresult);
195 $CatCheck = "skip";
196 if($SubShowForums!="yes") { 
197         $CategoryName = $SCategoryName; }
198 if($SubShowForums!="no") {
199 require($SettDir['inc'].'categories.php'); } }
200 ?>