<?php

/*
 * @name        JMY CMS
 * @link        https://jmy.su/
 * @copyright   Copyright (C) 2012-2025 JMY LTD
 * @license     LICENSE.txt (see attached file)
 * @version     VERSION.txt (see attached file)
 * @author      Komarov Ivan
 * @edited      Orlov Alexsey
 */

if (!defined('ACCESS')) {
    header('Location: /');
    exit;
}
loadConfigBLOCK('board');
global $db, $core, $lang, $board_conf;
$core->loadblockLang('board');
if ($board_conf['on']) {
    $noShow = '';
    $where = (!empty($noShow) ? 'WHERE t.forum NOT IN (' . $noShow . ')' : '');
    echo '<table style="width=:100%; border: 0; border-spacing: 1px; border-collapse: separate;" class="boardBlockTable">' . "\n";
    $result = $core->select_data('board_threads', $where, 'lastTime DESC LIMIT 0,' . $board_conf['num'], 't.*, u.nick', 'as t LEFT JOIN ' . DB_PREFIX . '_users as u on(t.poster = u.id)');
    if ($db->numRows($result) > 0) {
        echo '<tr>
      <th colspan="2" style="width:15%;">' . $lang['topic_t'] . '</th>
      <th style="width:15%;">' . $lang['board_answers'] . '</th>
      <th style="width:10%;">' . $lang['board_author'] . '</th>
      <th style="width:3%;">' . $lang['board_views'] . '</th>
      <th style="width:140px;">' . $lang['board_last'] . '</th>
   </tr>' . "\n";
        while ($row = $db->getRow($result)) {
            echo '<tr>
      <td style="width:16px;">' . ($row['icon'] ? '<img src="media/board/theme_icon/' . $row['icon'] . '" style="border:0" alt="" />' : '<img src="media/board/noicon.png" style="border:0" alt="" />') . '</td>
       <td style="text-align:center"><a href="board/topic-' . $row['id'] . '/getlastpost" title="' . $lang['board_view_topic'] . '">' . ($row['important'] == 1 ? colorSpan('red', $row['title']) : $row['title']) . '</a></td>
       <td style="text-align:center">' . $row['replies'] . '</td>
       <td style="text-align:center"><a href="profile/' . $row['nick'] . '" title="' . $lang['board_author'] . '">' . $row['nick'] . '</a></td>
       <td style="text-align:center">' . $row['views'] . '</td>
      <td  style="text-align:center"><a href="board/topic-' . $row['id'] . '/getlastpost" title="' . $lang['board_to_last_message'] . '"><img src="media/board/up.png" style="border:0" alt="' . $lang['board_last_message'] . '" style="vertical-align:middle" /></a>' . formatDate($row['lastTime'], true) . ' <br /><a href="profile/' . $row['lastPoster'] . '" title="' . $lang['board_last_responder'] . '"><strong>' . $row['lastPoster'] . '</strong></a></td>
   </tr>' . "\n";
        }
    } else {
        $core->tpl->info($lang['board_list_empty']);
    }
    echo '</table>' . "\n";
} else {
    if ($board_conf['info_off']) $core->tpl->info($lang['board_off']);
}