- <?php
- # news
- if (!defined('KODEVS') || KODEVS != 1)
- die();
- define('NEWS_REGULAR', 0);
- define('NEWS_ARCHIVE', 1);
- class Page extends BasePage
- {
- function doStartup()
- {
- $this->setTitle(isset($_GET['act']) ? 'PAGE_NEWS_TITLE' : 'PAGE_INDEX_TITLE');
- if (!isset($_GET['act']))
- $this->disableCache();
- }
- function doRun()
- {
- switch (@$_GET['act'])
- {
- case 'entry':
- {
- $this->doShowEntry();
- } break;
- default:
- {
- Template::SetPage('main');
- $this->doShowNews();
- $this->doShowUserRankings();
- $this->doShowClanRankings();
- $this->doShowKings();
- $this->loadTPL('main_content');
- }
- }
- }
- function doShowKings()
- {
- $db = $this->getGDB();
- $this->setKingName(NULL, 1);
- $this->setKingName(NULL, 2);
- $db->doQuery('SELECT byNation, strKingName FROM KING_SYSTEM');
- if ($db->hasError() || !$db->hasRows())
- return;
- while ($row = $db->doRead())
- {
- $name = trim($row['strKingName']);
- $this->setKingName($name, $row['byNation']);
- }
- }
- function setKingName($name, $nation)
- {
- Template::SetVar($nation == 1 ? 'KARUS_KING' : 'ELMORAD_KING', $name == NULL ? 'N/A' : '<a href="./?page=char&id=' . $name . '" class="largeFont">' . $name . '</a>');
- }
- function doShowNews()
- {
- $db = $this->getADB();
- for ($n = 0; $n < 6; $n++)
- Template::SetVar('SHORT-NEWS-' . $n, Template::Load('news-bit-empty'));
- $db->doQuery('SELECT TOP 6 id, date,n_title FROM NEWS ORDER BY id DESC');
- if ($db->hasError() || !$db->hasRows())
- return;
- $i = 0;
- while ($row = $db->doRead())
- {
- $date = explode(' ', str_replace(array('-', '/'), '.', $row['date']));
- $date = $date[0];
- $data = array('news-date' => $date, 'news-title' => strlen($row['n_title']) > 22 ? substr($row['n_title'], 0, 21) . '...' : $row['n_title'], 'news-id' => $row['id']);
- Template::SetVar('SHORT-NEWS-' . $i++, Template::Load('news-bit2', $data));
- }
- }
- function doShowUserRankings()
- {
- $db = $this->getGDB();
- $db->doQuery('SELECT TOP 25 strUserId, Loyalty, Nation FROM USERDATA WHERE Authority IN(1, 2) ORDER BY Loyalty DESC, strUserId ASC');
- if ($db->hasError() || !$db->hasRows())
- {
- Template::SetVar('rankings_short_user', NULL);
- return;
- }
- $i = 1;
- $maincontent = '';
- $content = '';
- $n = 0;
- while ($row = $db->doRead())
- {
- $NP = intval($row['Loyalty']);
- $data = array('rank_pos' => $i, 'rank_name' => $row['strUserId'], 'rank_loyalty' => number_format($NP), 'rank_type' => 'char', 'rank_nation' => $row['Nation']);
- $content .= Template::Load('short_rankings_entry', $data);
- $n++;
- if ($n == 10)
- {
- $maincontent .= Template::Load('short_rankings', array('short_rankings_data' => $content));
- $content = '';
- $n = 0;
- }
- $i++;
- }
- if ($n < 10 && $n > 0)
- $maincontent .= Template::Load('short_rankings', array('short_rankings_data' => $content));
- Template::SetVar('RANKINGS_SHORT_USER', $maincontent);
- }
- function doShowClanRankings()
- {
- $db = $this->getGDB();
- $db->doQuery('SELECT TOP 50 IDNum, IDName, Nation, (SELECT SUM(Loyalty) FROM USERDATA WHERE USERDATA.Knights = KNIGHTS.IDNum AND USERDATA.Authority = 1) as ClanLoyalty FROM KNIGHTS ORDER BY ClanLoyalty DESC, IDName ASC');
- if ($db->hasError() || !$db->hasRows())
- {
- Template::SetVar('rankings_short_clan', NULL);
- return;
- }
- $i = 1;
- $maincontent = '';
- $content = '';
- $n = 0;
- while ($row = $db->doRead())
- {
- $NP = intval($row['ClanLoyalty']);
- $data = array('rank_pos' => $i, 'rank_id' => $row['IDNum'], 'rank_name' => $row['IDName'], 'rank_loyalty' => number_format($NP), 'rank_type' => 'clan', 'rank_nation' => $row['Nation']);
- $content .= Template::Load('short_rankings_entry2', $data);
- $n++;
- if ($n == 10)
- {
- $maincontent .= Template::Load('short_rankings', array('short_rankings_data' => $content));
- $content = '';
- $n = 0;
- }
- $i++;
- }
- if ($n < 10 && $n > 0)
- $maincontent .= Template::Load('short_rankings', array('short_rankings_data' => $content));
- Template::SetVar('RANKINGS_SHORT_CLAN', $maincontent);
- }
- function doShowEntry()
- {
- $db = $this->getADB();
- $db->doQuery('SELECT date,n_title,n_text FROM News WHERE id = ?', intval(@$_GET['id']));
- if ($db->hasError() || !$db->hasRows())
- {
- $replace = array('news-message' => Template::GetLangVar('NEWS_MISSING'), 'news-title' => Template::GetLangVar('OOPS_PROBLEM'), 'news-date' => NULL);
- return;
- }
- $row = $db->doRead();
- $replace = array('news-message' => $row['n_text'], 'news-title' => $row['n_title'], 'news-date' => $row['date']);
- $this->loadTPL('news-entry', $replace);
- }
- }
- ?>