OSDN Git Service

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