Small update
[iDB.git] / inc / searches.php
bloba50cfd833a1e239d56390dd654a5987d95cfc3fd
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-2024 iDB Support - https://idb.osdn.jp/support/category.php?act=view&id=1
12 Copyright 2004-2024 Game Maker 2k - https://idb.osdn.jp/support/category.php?act=view&id=2
14 $FileInfo: searches.php - Last Update: 8/26/2024 SVN 1048 - Author: cooldude2k $
16 $File3Name = basename($_SERVER['SCRIPT_NAME']);
17 if ($File3Name == "searches.php" || $File3Name == "/searches.php") {
18 require('index.php');
19 exit();
21 if ($Settings['enable_search'] == "off" ||
22 $GroupInfo['CanSearch'] == "no") {
23 redirect("location", $rbasedir.url_maker($exfile['index'], $Settings['file_ext'], "act=view", $Settings['qstr'], $Settings['qsep'], $prexqstr['index'], $exqstr['index'], false));
24 header("Content-Type: text/plain; charset=".$Settings['charset']);
25 ob_clean();
26 echo "Sorry you do not have permission to do a search.";
27 $urlstatus = 302;
28 gzip_page($Settings['use_gzip'], $GZipEncode['Type']);
29 session_write_close();
30 die();
32 $pagenum = null;
33 if ($Settings['enable_search'] == "on" ||
34 $GroupInfo['CanSearch'] == "yes") {
35 if (isset($_SESSION['OldViewingPage'])) {
36 $_SESSION['AncientViewingPage'] = $_SESSION['OldViewingPage'];
37 } else {
38 $_SESSION['AncientViewingPage'] = url_maker(null, "no+ext", "act=view", "&", "=", $prexqstr['index'], $exqstr['index']);
40 if (isset($_SESSION['OldViewingFile'])) {
41 $_SESSION['AncientViewingFile'] = $_SESSION['OldViewingFile'];
42 } else {
43 if ($Settings['file_ext'] != "no+ext" && $Settings['file_ext'] != "no ext") {
44 $_SESSION['AncientViewingFile'] = $exfile['index'].$Settings['file_ext'];
46 if ($Settings['file_ext'] == "no+ext" || $Settings['file_ext'] == "no ext") {
47 $_SESSION['AncientViewingFile'] = $exfile['index'];
50 if (isset($_SESSION['OldPreViewingTitle'])) {
51 $_SESSION['AncientPreViewingTitle'] = $_SESSION['OldPreViewingTitle'];
52 } else {
53 $_SESSION['AncientPreViewingTitle'] = "Viewing";
55 if (isset($_SESSION['OldViewingTitle'])) {
56 $_SESSION['AncientViewingTitle'] = $_SESSION['OldViewingTitle'];
57 } else {
58 $_SESSION['AncientViewingTitle'] = "Board index";
60 if (isset($_SESSION['OldExtraData'])) {
61 $_SESSION['AncientExtraData'] = $_SESSION['OldExtraData'];
62 } else {
63 $_SESSION['AncientExtraData'] = "currentact:view; currentcategoryid:0; currentforumid:0; currenttopicid:0; currentmessageid:0; currenteventid:0; currentmemberid:0;";
65 if (isset($_SESSION['ViewingPage'])) {
66 $_SESSION['OldViewingPage'] = $_SESSION['ViewingPage'];
67 } else {
68 $_SESSION['OldViewingPage'] = url_maker(null, "no+ext", "act=view", "&", "=", $prexqstr['index'], $exqstr['index']);
70 if (isset($_SESSION['ViewingFile'])) {
71 $_SESSION['OldViewingFile'] = $_SESSION['ViewingFile'];
72 } else {
73 if ($Settings['file_ext'] != "no+ext" && $Settings['file_ext'] != "no ext") {
74 $_SESSION['OldViewingFile'] = $exfile['index'].$Settings['file_ext'];
76 if ($Settings['file_ext'] == "no+ext" || $Settings['file_ext'] == "no ext") {
77 $_SESSION['OldViewingFile'] = $exfile['index'];
80 if (isset($_SESSION['PreViewingTitle'])) {
81 $_SESSION['OldPreViewingTitle'] = $_SESSION['PreViewingTitle'];
82 } else {
83 $_SESSION['OldPreViewingTitle'] = "Viewing";
85 if (isset($_SESSION['ViewingTitle'])) {
86 $_SESSION['OldViewingTitle'] = $_SESSION['ViewingTitle'];
87 } else {
88 $_SESSION['OldViewingTitle'] = "Board index";
90 if (isset($_SESSION['ExtraData'])) {
91 $_SESSION['OldExtraData'] = $_SESSION['ExtraData'];
92 } else {
93 $_SESSION['OldExtraData'] = "currentact:view; currentcategoryid:0; currentforumid:0; currenttopicid:0; currentmessageid:0; currenteventid:0; currentmemberid:0;";
95 $_SESSION['ViewingPage'] = url_maker(null, "no+ext", "act=topics", "&", "=", $prexqstr['search'], $exqstr['search']);
96 if ($Settings['file_ext'] != "no+ext" && $Settings['file_ext'] != "no ext") {
97 $_SESSION['ViewingFile'] = $exfile['search'].$Settings['file_ext'];
99 if ($Settings['file_ext'] == "no+ext" || $Settings['file_ext'] == "no ext") {
100 $_SESSION['ViewingFile'] = $exfile['search'];
102 $_SESSION['PreViewingTitle'] = "Searching";
103 $_SESSION['ViewingTitle'] = "Topics";
104 $_SESSION['ExtraData'] = "currentact:".$_GET['act']."; currentcategoryid:0; currentforumid:0; currenttopicid:0; currentmessageid:0; currenteventid:0; currentmemberid:0;";
105 if ($_GET['act'] == "topics") {
106 if ($_GET['search'] == null && $_GET['type'] == null) {
108 <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 echo $ThemeSet['NavLinkDivider']; ?><a href="<?php echo url_maker($exfile['search'], $Settings['file_ext'], "act=topics", $Settings['qstr'], $Settings['qsep'], $prexqstr['search'], $exqstr['search']); ?>">Search topics</a></div>
109 <div class="DivNavLinks">&#160;</div>
110 <div class="Table1Border">
111 <?php if ($ThemeSet['TableStyle'] == "div") { ?>
112 <div class="TableRow1">
113 <span style="text-align: left;">
114 <?php echo $ThemeSet['TitleIcon']; ?><a href="<?php echo url_maker($exfile['search'], $Settings['file_ext'], "act=topics", $Settings['qstr'], $Settings['qsep'], $prexqstr['search'], $exqstr['search']); ?>">Topic Search</a></span></div>
115 <?php } ?>
116 <table class="Table1">
117 <?php if ($ThemeSet['TableStyle'] == "table") { ?>
118 <tr id="SearchStart" class="TableRow1">
119 <td class="TableColumn1" colspan="6"><span style="text-align: left;">
120 <?php echo $ThemeSet['TitleIcon']; ?><a href="<?php echo url_maker($exfile['search'], $Settings['file_ext'], "act=topics", $Settings['qstr'], $Settings['qsep'], $prexqstr['search'], $exqstr['search']); ?>">Topic Search</a></span>
121 </td>
122 </tr><?php } ?>
123 <tr class="TableRow2">
124 <th class="TableColumn2" style="width: 100%; text-align: left;">&#160;Search for topic: </th>
125 </tr>
126 <tr class="TableRow3">
127 <td class="TableColumn3">
128 <form style="display: inline;" method="post" action="<?php echo url_maker($exfile['search'], $Settings['file_ext'], "act=topics", $Settings['qstr'], $Settings['qsep'], $prexqstr['search'], $exqstr['search']); ?>">
129 <table style="text-align: left;">
130 <tr style="text-align: left;">
131 <td style="width: 30%;"><label class="TextBoxLabel" for="search">Enter SearchTerm: </label></td>
132 <td style="width: 70%;"><input maxlength="35" class="TextBox" id="search" type="search" name="search" /></td>
133 </tr><tr style="text-align: left;">
134 <td style="width: 30%;"><label class="TextBoxLabel" for="msearch">Filter by Member (optional): </label></td>
135 <td style="width: 70%;"><input maxlength="25" class="TextBox" id="msearch" type="search" name="msearch" /></td>
136 </tr><tr style="text-align: left;">
137 <td style="width: 30%;"><label class="TextBoxLabel" title="Wildcard is %" for="type">Search Type: </label></td>
138 <td style="width: 70%;"><select id="type" name="type" class="TextBox">
139 <option value="normal">Normal Search</option>
140 <option value="wildcard">Wildcard Search</option>
141 </select></td>
142 </tr></table>
143 <table style="text-align: left;">
144 <tr style="text-align: left;">
145 <td style="width: 100%;">
146 <input type="hidden" name="act" value="topics" style="display: none;" />
147 <input class="Button" type="submit" value="Search" />
148 </td></tr></table>
149 </form>
150 </td>
151 </tr>
152 <tr class="TableRow4">
153 <td class="TableColumn4">&#160;</td>
154 </tr>
155 </table></div>
156 <?php } if (($_GET['search'] != null && $_GET['type'] != null) || $_GET['type'] == "getactive") {
157 if (pre_strlen($_GET['msearch']) >= "25") {
158 $_GET['msearch'] = null;
160 if (isset($_GET['msearch']) && $_GET['msearch'] != null) {
161 $_GET['memid'] = null;
162 $memsinum = sql_count_rows(sql_pre_query("SELECT COUNT(*) AS cnt FROM \"".$Settings['sqltable']."members\" WHERE \"Name\"='%s' LIMIT 1", array($_GET['msearch'])), $SQLStat);
163 $memsiquery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."members\" WHERE \"Name\"='%s' LIMIT 1", array($_GET['msearch']));
164 $memsiresult = sql_query($memsiquery, $SQLStat);
165 $memsi = 0;
166 if ($memsinum == 0) {
167 $memsid = -1;
169 if ($memsinum != 0) {
170 $memsiresult_array = sql_fetch_assoc($memsiresult);
171 $memsid = $memsiresult_array['id'];
172 sql_free_result($memsiresult);
175 if (!isset($_GET['memid'])) {
176 $_GET['memid'] = null;
178 if (!is_numeric($_GET['memid']) || $_GET['memid'] < 1) {
179 $_GET['memid'] = null;
181 if ($_GET['memid'] != null && is_numeric($_GET['memid'])) {
182 $memnamea = GetUserName($_GET['memid'], $Settings['sqltable']);
183 if ($memnamea['Hidden'] == "no") {
184 $_GET['msearch'] = $memnamea['Name'];
185 $memsid = $_GET['memid'];
187 if ($memnamea['Hidden'] == "yes") {
188 $_GET['msearch'] = null;
189 $_GET['memid'] = null;
190 $memsid = null;
193 // Get SQL LIMIT Number
194 $nums = $_GET['page'] * $Settings['max_topics'];
195 $PageLimit = max(0, $nums - $Settings['max_topics']);
196 $SQLimit = getSQLLimitClause($Settings['sqltype'], $Settings['max_topics'], $PageLimit);
198 // Prepare search query based on search type
199 if (empty($_GET['msearch'])) {
200 if ($_GET['type'] === "normal") {
201 $NumberTopics = sql_count_rows(sql_pre_query("SELECT COUNT(*) AS cnt FROM \"".$Settings['sqltable']."topics\" WHERE \"TopicName\"='%s'".$ForumIgnoreList4."", array($_GET['search'])), $SQLStat);
202 $query = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."topics\" WHERE \"TopicName\"='%s'".$ForumIgnoreList4." ORDER BY \"LastUpdate\" DESC ".$SQLimit, array($_GET['search']));
203 } elseif ($_GET['type'] === "wildcard") {
204 $NumberTopics = sql_count_rows(sql_pre_query("SELECT COUNT(*) AS cnt FROM \"".$Settings['sqltable']."topics\" WHERE \"TopicName\" LIKE '%s'".$ForumIgnoreList4."", array($_GET['search'])), $SQLStat);
205 $query = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."topics\" WHERE \"TopicName\" LIKE '%s'".$ForumIgnoreList4." ORDER BY \"LastUpdate\" DESC ".$SQLimit, array($_GET['search']));
207 } else {
208 if ($_GET['type'] === "normal") {
209 $NumberTopics = sql_count_rows(sql_pre_query("SELECT COUNT(*) AS cnt FROM \"".$Settings['sqltable']."topics\" WHERE \"TopicName\"='%s' AND \"UserID\"=%i".$ForumIgnoreList4."", array($_GET['search'], $memsid)), $SQLStat);
210 $query = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."topics\" WHERE \"TopicName\"='%s' AND \"UserID\"=%i".$ForumIgnoreList4." ORDER BY \"LastUpdate\" DESC ".$SQLimit, array($_GET['search'], $memsid));
211 if ($memsid == -1) {
212 $NumberTopics = sql_count_rows(sql_pre_query("SELECT COUNT(*) AS cnt FROM \"".$Settings['sqltable']."topics\" WHERE \"TopicName\"='%s' AND \"GuestName\"='%s'".$ForumIgnoreList4."", array($_GET['search'], $_GET['msearch'])), $SQLStat);
213 $query = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."topics\" WHERE \"TopicName\"='%s' AND \"GuestName\"='%s'".$ForumIgnoreList4." ORDER BY \"LastUpdate\" DESC ".$SQLimit, array($_GET['search'], $_GET['msearch']));
215 } elseif ($_GET['type'] === "wildcard") {
216 $NumberTopics = sql_count_rows(sql_pre_query("SELECT COUNT(*) AS cnt FROM \"".$Settings['sqltable']."topics\" WHERE \"TopicName\" LIKE '%s' AND \"UserID\"=%i".$ForumIgnoreList4."", array($_GET['search'], $_GET['msearch'])), $SQLStat);
217 $query = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."topics\" WHERE \"TopicName\" LIKE '%s' AND \"UserID\"=%i".$ForumIgnoreList4." ORDER BY \"LastUpdate\" DESC ".$SQLimit, array($_GET['search'], $memsid));
218 if ($memsid == -1) {
219 $NumberTopics = sql_count_rows(sql_pre_query("SELECT COUNT(*) AS cnt FROM \"".$Settings['sqltable']."topics\" WHERE \"TopicName\" LIKE '%s' AND \"GuestName\"='%s'".$ForumIgnoreList4."", array($_GET['search'], $_GET['msearch'])), $SQLStat);
220 $query = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."topics\" WHERE \"TopicName\" LIKE '%s' AND \"GuestName\"='%s'".$ForumIgnoreList4." ORDER BY \"LastUpdate\" DESC ".$SQLimit, array($_GET['search'], $_GET['msearch']));
225 // Fetch active topics based on time range
226 if ($_GET['type'] === "getactive") {
227 if (!isset($active_start) || !isset($active_end)) {
228 $active_month = $usercurtime->format("m");
229 $active_day = $usercurtime->format("d");
230 $active_year = $usercurtime->format("Y");
231 $active_start = mktime(0, 0, 0, $active_month, $active_day, $active_year);
232 $active_end = mktime(23, 59, 59, $active_month, $active_day, $active_year);
234 $SQLimit = getSQLLimitClause($Settings['sqltype'], $Settings['max_topics'], $PageLimit);
235 $NumberTopics = sql_count_rows(sql_pre_query("SELECT COUNT(*) AS cnt FROM \"".$Settings['sqltable']."topics\" WHERE (\"TimeStamp\">=%i AND \"TimeStamp\"<=%i) OR (\"LastUpdate\">=%i AND \"LastUpdate\"<=%i)".$ForumIgnoreList4."", array($active_start, $active_end, $active_start, $active_end)), $SQLStat);
236 $query = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."topics\" WHERE (\"TimeStamp\">=%i AND \"TimeStamp\"<=%i) OR (\"LastUpdate\">=%i AND \"LastUpdate\"<=%i)".$ForumIgnoreList4." ORDER BY \"LastUpdate\" DESC ".$SQLimit, array($active_start, $active_end, $active_start, $active_end));
239 $result = sql_query($query, $SQLStat);
240 $NumberTopics = $NumberTopics ?? 0;
241 $num = $NumberTopics;
243 // Start Topic Page Code
244 $Settings['max_topics'] = $Settings['max_topics'] ?? 10;
245 $_GET['page'] = max(1, (int)($_GET['page'] ?? 1));
247 $nums = min($_GET['page'] * $Settings['max_topics'], $num);
248 $numz = max(0, $nums - $Settings['max_topics']);
250 // Calculate next and previous pages
251 $nextpage = ($nums < $num) ? $_GET['page'] + 1 : $_GET['page'];
252 $backpage = ($_GET['page'] > 1) ? $_GET['page'] - 1 : 1;
254 // Generate pagination
255 $Pages = [];
256 for ($l = 1, $pnum = $num; $pnum > 0; ++$l) {
257 $pnum = max(0, $pnum - $Settings['max_topics']);
258 $Pages[$l] = $l;
261 if (!isset($active_start) || !isset($active_end)) {
262 $active_month = $usercurtime->format("m");
263 $active_day = $usercurtime->format("d");
264 $active_year = $usercurtime->format("Y");
265 $active_start = mktime(0, 0, 0, $active_month, $active_day, $active_year);
266 $active_end = mktime(23, 59, 59, $active_month, $active_day, $active_year);
269 // End Topic Page Code
270 $SQLimit = getSQLLimitClause($Settings['sqltype'], $Settings['max_topics'], $PageLimit);
271 $num = sql_count_rows(sql_pre_query("SELECT COUNT(*) AS cnt FROM \"".$Settings['sqltable']."topics\" WHERE (\"TimeStamp\">=%i AND \"TimeStamp\"<=%i) OR (\"LastUpdate\">=%i AND \"LastUpdate\"<=%i)".$ForumIgnoreList4." ORDER BY \"LastUpdate\" DESC ".$SQLimit, array($active_start, $active_end, $active_start, $active_end)), $SQLStat);
273 // Handle no results found
274 if ($num <= 0) {
275 redirect("location", $rbasedir . url_maker($exfile['search'], $Settings['file_ext'], "act=topics", $Settings['qstr'], $Settings['qsep'], $prexqstr['search'], $exqstr['search'], false));
276 header("Content-Type: text/plain; charset=" . $Settings['charset']);
277 $urlstatus = 302;
278 ob_clean();
279 echo "Sorry could not find any search results.";
280 sql_free_result($result);
281 gzip_page($Settings['use_gzip'], $GZipEncode['Type']);
282 session_write_close();
283 die();
286 // Pagination display logic
287 $pagenum = count($Pages);
288 $_GET['page'] = min($_GET['page'], $pagenum);
290 $pstring = null;
291 if ($pagenum > 1) {
292 $pstring = "<div class=\"PageList\"><span class=\"pagelink\">{$pagenum} Pages:</span> ";
293 $Pagez = [
294 0 => ($_GET['page'] >= 4) ? "First" : null,
295 1 => ($_GET['page'] >= 3) ? $_GET['page'] - 2 : null,
296 2 => ($_GET['page'] >= 2) ? $_GET['page'] - 1 : null,
297 3 => $_GET['page'],
298 4 => ($_GET['page'] < $pagenum) ? $_GET['page'] + 1 : null,
299 5 => ($_GET['page'] + 1 < $pagenum) ? $_GET['page'] + 2 : null,
300 6 => ($_GET['page'] < $pagenum) ? "Last" : null
303 // Build pagination links
304 for ($pagei = 0, $pagenumi = count($Pagez); $pagei < $pagenumi; ++$pagei) {
305 if ($pagei == 1 && $_GET['page'] > 1) {
306 $Pback = $_GET['page'] - 1;
307 $pstring .= "<span class=\"pagelink\"><a href=\"".url_maker($exfile['search'], $Settings['file_ext'], "act=topics&search={$_GET['search']}&type={$_GET['type']}&page={$Pback}", $Settings['qstr'], $Settings['qsep'], $prexqstr['search'], $exqstr['search'])."\">&lt;</a></span> ";
310 if ($Pagez[$pagei] !== null && $Pagez[$pagei] != "First" && $Pagez[$pagei] != "Last") {
311 $pstring .= ($pagei == 3)
312 ? "<span class=\"pagecurrent\"><a href=\"".url_maker($exfile['search'], $Settings['file_ext'], "act=topics&search={$_GET['search']}&type={$_GET['type']}&page={$Pagez[$pagei]}", $Settings['qstr'], $Settings['qsep'], $prexqstr['search'], $exqstr['search'])."\">{$Pagez[$pagei]}</a></span> "
313 : "<span class=\"pagelink\"><a href=\"".url_maker($exfile['search'], $Settings['file_ext'], "act=topics&search={$_GET['search']}&type={$_GET['type']}&page={$Pagez[$pagei]}", $Settings['qstr'], $Settings['qsep'], $prexqstr['search'], $exqstr['search'])."\">{$Pagez[$pagei]}</a></span> ";
316 if ($Pagez[$pagei] == "First") {
317 $pstring .= "<span class=\"pagelinklast\"><a href=\"".url_maker($exfile['search'], $Settings['file_ext'], "act=topics&search={$_GET['search']}&type={$_GET['type']}&page=1", $Settings['qstr'], $Settings['qsep'], $prexqstr['search'], $exqstr['search'])."\">&laquo;</a></span> ";
320 if ($Pagez[$pagei] == "Last") {
321 $Pnext = $_GET['page'] + 1;
322 $pstring .= "<span class=\"pagelink\"><a href=\"".url_maker($exfile['search'], $Settings['file_ext'], "act=topics&search={$_GET['search']}&type={$_GET['type']}&page={$Pnext}", $Settings['qstr'], $Settings['qsep'], $prexqstr['search'], $exqstr['search'])."\">&gt;</a></span> ";
323 $pstring .= "<span class=\"pagelinklast\"><a href=\"".url_maker($exfile['search'], $Settings['file_ext'], "act=topics&search={$_GET['search']}&type={$_GET['type']}&page={$pagenum}", $Settings['qstr'], $Settings['qsep'], $prexqstr['search'], $exqstr['search'])."\">&raquo;</a></span> ";
326 $pstring .= "</div>";
329 // Output pagination string
330 echo $pstring;
332 // Show div for page links if there are multiple pages
333 if ($pagenum > 1) {
334 echo "<div class=\"DivPageLinks\">&#160;</div>";
336 $i = 0;
338 <div class="Table1Border">
339 <?php if ($ThemeSet['TableStyle'] == "div") { ?>
340 <div class="TableRow1">
341 <span style="text-align: left;">
342 <?php echo $ThemeSet['TitleIcon'];
343 if ($_GET['msearch'] == null && $_GET['search'] != null) { ?>
344 <a href="<?php echo url_maker($exfile['search'], $Settings['file_ext'], "act=topics&search=".$_GET['search']."&type=".$_GET['type']."&page=".$_GET['page'], $Settings['qstr'], $Settings['qsep'], $prexqstr['search'], $exqstr['search']); ?>">Searching for <?php echo $_GET['search']; ?></a>
345 <?php } if ($_GET['msearch'] != null && $_GET['search'] != null) { ?>
346 <a href="<?php echo url_maker($exfile['search'], $Settings['file_ext'], "act=topics&search=".$_GET['search']."&type=".$_GET['type']."&msearch=".$_GET['msearch']."&page=".$_GET['page'], $Settings['qstr'], $Settings['qsep'], $prexqstr['search'], $exqstr['search']); ?>">Searching for <?php echo $_GET['search']; ?> by <?php echo $_GET['msearch']; ?></a>
347 <?php } if ($_GET['type'] == "getactive") { ?>
348 <a href="<?php echo url_maker($exfile['search'], $Settings['file_ext'], "act=topics&search=".$_GET['search']."&type=".$_GET['type']."&page=".$_GET['page'], $Settings['qstr'], $Settings['qsep'], $prexqstr['search'], $exqstr['search']); ?>">Todays Active Topics</a>
349 <?php } ?></span></div>
350 <?php } ?>
351 <table class="Table1">
352 <?php if ($ThemeSet['TableStyle'] == "table") { ?>
353 <tr id="SearchStart" class="TableRow1">
354 <td class="TableColumn1" colspan="6"><span style="text-align: left;">
355 <?php echo $ThemeSet['TitleIcon'];
356 if ($_GET['msearch'] == null && $_GET['search'] != null) { ?>
357 <a href="<?php echo url_maker($exfile['search'], $Settings['file_ext'], "act=topics&search=".$_GET['search']."&type=".$_GET['type']."&page=".$_GET['page'], $Settings['qstr'], $Settings['qsep'], $prexqstr['search'], $exqstr['search']); ?>">Searching for <?php echo $_GET['search']; ?></a>
358 <?php } if ($_GET['msearch'] != null && $_GET['search'] != null) { ?>
359 <a href="<?php echo url_maker($exfile['search'], $Settings['file_ext'], "act=topics&search=".$_GET['search']."&type=".$_GET['type']."&msearch=".$_GET['msearch']."&page=".$_GET['page'], $Settings['qstr'], $Settings['qsep'], $prexqstr['search'], $exqstr['search']); ?>">Searching for <?php echo $_GET['search']; ?> by <?php echo $_GET['msearch']; ?></a>
360 <?php } if ($_GET['type'] == "getactive") { ?>
361 <a href="<?php echo url_maker($exfile['search'], $Settings['file_ext'], "act=topics&search=".$_GET['search']."&type=".$_GET['type']."&page=".$_GET['page'], $Settings['qstr'], $Settings['qsep'], $prexqstr['search'], $exqstr['search']); ?>">Todays Active Topics</a>
362 <?php } ?></span>
363 </td>
364 </tr><?php } ?>
365 <tr id="SearchStatRow" class="TableRow2">
366 <th class="TableColumn2" style="width: 4%;">State</th>
367 <th class="TableColumn2" style="width: 36%;">Topic Name</th>
368 <th class="TableColumn2" style="width: 15%;">Author</th>
369 <th class="TableColumn2" style="width: 15%;">Time</th>
370 <th class="TableColumn2" style="width: 5%;">Replys</th>
371 <th class="TableColumn2" style="width: 25%;">Last Reply</th>
372 </tr>
373 <?php
374 while ($i < $num) {
375 $result_array = sql_fetch_assoc($result);
376 $TopicID = $result_array['id'];
377 $ForumID = $result_array['ForumID'];
378 $prenum = sql_count_rows(sql_pre_query("SELECT COUNT(*) AS cnt FROM \"".$Settings['sqltable']."forums\" WHERE \"id\"=%i".$ForumIgnoreList2." LIMIT 1", array($ForumID)), $SQLStat);
379 $prequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."forums\" WHERE \"id\"=%i".$ForumIgnoreList2." LIMIT 1", array($ForumID));
380 $preresult = sql_query($prequery, $SQLStat);
381 $HotTopicPosts = $Settings['hot_topic_num'];
382 if ($prenum > 0) {
383 $preresult_array = sql_fetch_assoc($preresult);
384 $HotTopicPosts = $preresult_array['HotTopicPosts'];
386 sql_free_result($preresult);
387 if ($HotTopicPosts != 0 && is_numeric($HotTopicPosts)) {
388 $Settings['hot_topic_num'] = $HotTopicPosts;
390 if (!is_numeric($Settings['hot_topic_num'])) {
391 $Settings['hot_topic_num'] = 15;
393 $CategoryID = $result_array['CategoryID'];
394 $UsersID = $result_array['UserID'];
395 $GuestsName = $result_array['GuestName'];
396 $TheTime = $result_array['TimeStamp'];
397 $tmpusrcurtime = new DateTime();
398 $tmpusrcurtime->setTimestamp($TheTime);
399 $tmpusrcurtime->setTimezone($usertz);
400 $TheTime = $tmpusrcurtime->format($_SESSION['iDBDateFormat'].", ".$_SESSION['iDBTimeFormat']);
401 $NumReply = $result_array['NumReply'];
402 $NumberPosts = $NumReply + 1;
403 $prepagelist = null;
404 if (!isset($Settings['max_posts'])) {
405 $Settings['max_posts'] = 10;
407 if (!isset($ThemeSet['MiniPageAltStyle'])) {
408 $ThemeSet['MiniPageAltStyle'] = "off";
410 if ($ThemeSet['MiniPageAltStyle'] != "on" &&
411 $ThemeSet['MiniPageAltStyle'] != "off") {
412 $ThemeSet['MiniPageAltStyle'] = "off";
414 if ($NumberPosts > $Settings['max_posts']) {
415 $NumberPages = ceil($NumberPosts / $Settings['max_posts']);
417 if ($NumberPosts <= $Settings['max_posts']) {
418 $NumberPages = 1;
420 if ($NumberPages > 4) {
421 $prepagelist = " &#160;";
423 if ($NumberPages >= 2) {
424 if ($ThemeSet['MiniPageAltStyle'] == "off") {
425 $prepagelist = "<span class=\"small\">(Pages: ";
427 if ($ThemeSet['MiniPageAltStyle'] == "on") {
428 $prepagelist = $prepagelist."<span class=\"minipagelink\">";
430 $prepagelist = $prepagelist."<a href=\"".url_maker($exfile['topic'], $Settings['file_ext'], "act=view&id=".$TopicID."&page=1", $Settings['qstr'], $Settings['qsep'], $prexqstr['topic'], $exqstr['topic'])."\">1</a>";
431 if ($ThemeSet['MiniPageAltStyle'] == "on") {
432 $prepagelist = $prepagelist."</span>";
434 if ($ThemeSet['MiniPageAltStyle'] == "off") {
435 $prepagelist = $prepagelist." ";
437 if ($ThemeSet['MiniPageAltStyle'] == "on") {
438 $prepagelist = $prepagelist."<span class=\"minipagelink\">";
440 $prepagelist = $prepagelist."<a href=\"".url_maker($exfile['topic'], $Settings['file_ext'], "act=view&id=".$TopicID."&page=2", $Settings['qstr'], $Settings['qsep'], $prexqstr['topic'], $exqstr['topic'])."\">2</a>";
441 if ($ThemeSet['MiniPageAltStyle'] == "on") {
442 $prepagelist = $prepagelist."</span>";
444 if ($NumberPages >= 3) {
445 if ($ThemeSet['MiniPageAltStyle'] == "off") {
446 $prepagelist = $prepagelist." ";
448 if ($ThemeSet['MiniPageAltStyle'] == "on") {
449 $prepagelist = $prepagelist."<span class=\"minipagelink\">";
451 $prepagelist = $prepagelist."<a href=\"".url_maker($exfile['topic'], $Settings['file_ext'], "act=view&id=".$TopicID."&page=3", $Settings['qstr'], $Settings['qsep'], $prexqstr['topic'], $exqstr['topic'])."\">3</a>";
452 if ($ThemeSet['MiniPageAltStyle'] == "on") {
453 $prepagelist = $prepagelist."</span>";
456 if ($NumberPages == 4) {
457 if ($ThemeSet['MiniPageAltStyle'] == "off") {
458 $prepagelist = $prepagelist." ";
460 if ($ThemeSet['MiniPageAltStyle'] == "on") {
461 $prepagelist = $prepagelist."<span class=\"minipagelinklast\">";
463 if ($ThemeSet['MiniPageAltStyle'] == "on") {
464 $prepagelist = $prepagelist."<a href=\"".url_maker($exfile['topic'], $Settings['file_ext'], "act=view&id=".$TopicID."&page=4", $Settings['qstr'], $Settings['qsep'], $prexqstr['topic'], $exqstr['topic'])."\">4</a>";
466 if ($ThemeSet['MiniPageAltStyle'] == "off") {
467 $prepagelist = $prepagelist."<a href=\"".url_maker($exfile['topic'], $Settings['file_ext'], "act=view&id=".$TopicID."&page=4", $Settings['qstr'], $Settings['qsep'], $prexqstr['topic'], $exqstr['topic'])."\"> ...4</a>";
469 if ($ThemeSet['MiniPageAltStyle'] == "on") {
470 $prepagelist = $prepagelist."</span>";
473 if ($NumberPages > 4) {
474 if ($ThemeSet['MiniPageAltStyle'] == "off") {
475 $prepagelist = $prepagelist." ";
477 if ($ThemeSet['MiniPageAltStyle'] == "on") {
478 $prepagelist = $prepagelist."<span class=\"minipagelinklast\">";
480 if ($ThemeSet['MiniPageAltStyle'] == "on") {
481 $prepagelist = $prepagelist."<a href=\"".url_maker($exfile['topic'], $Settings['file_ext'], "act=view&id=".$TopicID."&page=".$NumberPages, $Settings['qstr'], $Settings['qsep'], $prexqstr['topic'], $exqstr['topic'])."\">&raquo; ".$NumberPages."</a>";
483 if ($ThemeSet['MiniPageAltStyle'] == "off") {
484 $prepagelist = $prepagelist."<a href=\"".url_maker($exfile['topic'], $Settings['file_ext'], "act=view&id=".$TopicID."&page=".$NumberPages, $Settings['qstr'], $Settings['qsep'], $prexqstr['topic'], $exqstr['topic'])."\"> ...".$NumberPages."</a>";
486 if ($ThemeSet['MiniPageAltStyle'] == "on") {
487 $prepagelist = $prepagelist."</span>";
490 if ($ThemeSet['MiniPageAltStyle'] == "off") {
491 $prepagelist = $prepagelist.")</span>";
494 $TopicName = $result_array['TopicName'];
495 $TopicDescription = $result_array['Description'];
496 $PinnedTopic = $result_array['Pinned'];
497 if ($PinnedTopic > 2) {
498 $PinnedTopic = 1;
500 if ($PinnedTopic < 0) {
501 $PinnedTopic = 0;
503 if (!is_numeric($PinnedTopic)) {
504 $PinnedTopic = 0;
506 $TopicStat = $result_array['Closed'];
507 if ($TopicStat > 3) {
508 $TopicStat = 1;
510 if ($TopicStat < 0) {
511 $TopicStat = 0;
513 if (!is_numeric($TopicStat)) {
514 $TopicStat = 1;
516 $PreUsersName = GetUserName($UsersID, $Settings['sqltable'], $SQLStat);
517 if ($PreUsersName['Name'] === null) {
518 $UsersID = -1;
519 $PreUsersName = GetUserName($UsersID, $Settings['sqltable'], $SQLStat);
521 $UsersName = $PreUsersName['Name'];
522 $UsersHidden = $PreUsersName['Hidden'];
523 if ($UsersName == "Guest") {
524 $UsersName = $GuestsName;
525 if ($UsersName == null) {
526 $UsersName = "Guest";
529 if (($PermissionInfo['CanViewForum'][$ForumID] == "yes" &&
530 $CatPermissionInfo['CanViewCategory'][$CategoryID] == "yes" &&
531 $TopicStat >= 0 && $TopicStat < 3) ||
532 ($PermissionInfo['CanViewForum'][$ForumID] == "yes" &&
533 $CatPermissionInfo['CanViewCategory'][$CategoryID] == "yes" &&
534 $PermissionInfo['CanModForum'][$ForumID] == "yes" && $TopicStat == 3)) {
535 $LastReply = "&#160;<br />&#160;";
536 $glrnum = sql_count_rows(sql_pre_query("SELECT COUNT(*) AS cnt FROM \"".$Settings['sqltable']."posts\" WHERE \"TopicID\"=%i ORDER BY \"TimeStamp\" DESC LIMIT 1", array($TopicID)), $SQLStat);
537 $glrquery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."posts\" WHERE \"TopicID\"=%i ORDER BY \"TimeStamp\" DESC LIMIT 1", array($TopicID));
538 $glrresult = sql_query($glrquery, $SQLStat);
539 if ($glrnum > 0) {
540 $glrresult_array = sql_fetch_assoc($glrresult);
541 $ReplyID1 = $glrresult_array['id'];
542 $UsersID1 = $glrresult_array['UserID'];
543 $GuestsName1 = $glrresult_array['GuestName'];
544 $TimeStamp1 = $glrresult_array['TimeStamp'];
545 $tmpusrcurtime = new DateTime();
546 $tmpusrcurtime->setTimestamp($TimeStamp1);
547 $tmpusrcurtime->setTimezone($usertz);
548 $TimeStamp1 = $tmpusrcurtime->format($_SESSION['iDBDateFormat'].", ".$_SESSION['iDBTimeFormat']);
549 $PreUsersName1 = GetUserName($UsersID1, $Settings['sqltable'], $SQLStat);
550 if ($PreUsersName1['Name'] === null) {
551 $UsersID1 = -1;
552 $PreUsersName1 = GetUserName($UsersID1, $Settings['sqltable'], $SQLStat);
554 $UsersName1 = $PreUsersName1['Name'];
555 $UsersHidden1 = $PreUsersName1['Hidden'];
557 $NumPages = null;
558 $NumRPosts = $NumReply + 1;
559 if (!isset($Settings['max_posts'])) {
560 $Settings['max_posts'] = 10;
562 if ($NumRPosts > $Settings['max_posts']) {
563 $NumPages = ceil($NumRPosts / $Settings['max_posts']);
565 if ($NumRPosts <= $Settings['max_posts']) {
566 $NumPages = 1;
568 $Users_Name1 = pre_substr($UsersName1, 0, 20);
569 if ($UsersName1 == "Guest") {
570 $UsersName1 = $GuestsName1;
571 if ($UsersName1 == null) {
572 $UsersName1 = "Guest";
575 if (pre_strlen($UsersName1) > 20) {
576 $Users_Name1 = $Users_Name1."...";
577 $oldusername = $UsersName1;
578 $UsersName1 = $Users_Name1;
579 } $lul = null;
580 if ($TimeStamp1 != null) {
581 $lul = null;
582 if ($UsersID1 > 0 && $UsersHidden1 == "no") {
583 $lul = url_maker($exfile['member'], $Settings['file_ext'], "act=view&id=".$UsersID1, $Settings['qstr'], $Settings['qsep'], $prexqstr['member'], $exqstr['member']);
584 $luln = 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;
585 $LastReply = "Time: <a href=\"".$luln."\">".$TimeStamp1."</a><br />\nUser: <a href=\"".$lul."\" title=\"".$oldusername."\">".$UsersName1."</a>";
587 if ($UsersID1 <= 0 || $UsersHidden1 == "yes") {
588 if ($UsersID1 == -1) {
589 $UserPre = "Guest:";
591 if (($UsersID1 < -1 && $UsersHidden1 == "yes") || $UsersID1 == 0 || ($UsersID1 > 0 && $UsersHidden1 == "yes")) {
592 $UserPre = "Hidden:";
594 $lul = url_maker($exfile['index'], $Settings['file_ext'], "act=view", $Settings['qstr'], $Settings['qsep'], $prexqstr['index'], $exqstr['index']);
595 $luln = 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;
596 $LastReply = "Time: <a href=\"".$luln."\">".$TimeStamp1."</a><br />\n".$UserPre." <span title=\"".$oldusername."\">".$UsersName1."</span>";
599 sql_free_result($glrresult);
600 if ($TimeStamp1 == null) {
601 $LastReply = "&#160;<br />&#160;";
603 $PreTopic = $ThemeSet['TopicIcon'];
604 if ($PinnedTopic > 0 && $PinnedTopic < 3 && $TopicStat == 0) {
605 if ($NumReply >= $Settings['hot_topic_num']) {
606 $PreTopic = $ThemeSet['HotPinTopic'];
608 if ($NumReply < $Settings['hot_topic_num']) {
609 $PreTopic = $ThemeSet['PinTopic'];
612 if ($TopicStat >= 0 && $TopicStat <= 3 && $PinnedTopic == 0) {
613 if ($NumReply >= $Settings['hot_topic_num']) {
614 $PreTopic = $ThemeSet['HotClosedTopic'];
616 if ($NumReply < $Settings['hot_topic_num']) {
617 $PreTopic = $ThemeSet['ClosedTopic'];
620 if ($PinnedTopic == 0 && $TopicStat == 0) {
621 if ($NumReply >= $Settings['hot_topic_num']) {
622 $PreTopic = $ThemeSet['HotTopic'];
624 if ($NumReply < $Settings['hot_topic_num']) {
625 $PreTopic = $ThemeSet['TopicIcon'];
628 if ($PinnedTopic > 0 && $PinnedTopic < 3 && $TopicStat >= 0 && $TopicStat <= 3) {
629 if ($NumReply >= $Settings['hot_topic_num']) {
630 $PreTopic = $ThemeSet['HotPinClosedTopic'];
632 if ($NumReply < $Settings['hot_topic_num']) {
633 $PreTopic = $ThemeSet['PinClosedTopic'];
637 <tr class="TableRow3" id="Topic<?php echo $TopicID; ?>">
638 <td class="TableColumn3"><div class="topicstate">
639 <?php echo $PreTopic; ?></div></td>
640 <td class="TableColumn3"><div class="topicname">
641 <a href="<?php echo url_maker($exfile['topic'], $Settings['file_ext'], "act=view&id=".$TopicID, $Settings['qstr'], $Settings['qsep'], $prexqstr['topic'], $exqstr['topic']); ?>"><?php echo $TopicName; ?></a>
642 <?php if ($prepagelist !== null) {
643 echo $prepagelist;
644 } ?></div>
645 <div class="topicdescription"><?php echo $TopicDescription; ?></div></td>
646 <td class="TableColumn3" style="text-align: center;"><?php
647 if ($UsersID > 0) {
648 echo "<a href=\"";
649 echo url_maker($exfile['member'], $Settings['file_ext'], "act=view&id=".$UsersID, $Settings['qstr'], $Settings['qsep'], $prexqstr['member'], $exqstr['member']);
650 echo "\">".$UsersName."</a>";
652 if ($UsersID <= 0) {
653 echo "<span>".$UsersName."</span>";
655 ?></td>
656 <td class="TableColumn3" style="text-align: center;"><?php echo $TheTime; ?></td>
657 <td class="TableColumn3" style="text-align: center;"><?php echo $NumReply; ?></td>
658 <td class="TableColumn3"><?php echo $LastReply; ?></td>
659 </tr>
660 <?php } ++$i;
663 <tr id="SearchEnd" class="TableRow4">
664 <td class="TableColumn4" colspan="6">&#160;</td>
665 </tr>
666 </table></div>
667 <?php if ($pagenum > 1) { ?>
668 <div class="DivSearch">&#160;</div>
669 <?php }
670 echo $pstring;
671 //List Page Number Code end
672 if ($pagenum > 1) {
674 <div class="DivPageLinks">&#160;</div>
675 <?php }
676 sql_free_result($result);
680 if ($pagenum <= 1) { ?>
681 <div class="DivSearch">&#160;</div>
682 <?php } ?>