<?php
/*
*****************************************************************
News.php
*****************************************************************
LSP: Lunabyte Systems Portal
Open-Source Project Inspired by Zef Hemel (hide@address.com)
*****************************************************************
Software Version: LSP 2.0 "Enigma 2"
Software by: Lunabyte Systems (http://www.lunabyte.net)
Copyright 2002-2005 by: Lunabyte Systems (http://www.lunabyte.net)
Support, News, Updates at: http://www.lunabyte.net
*****************************************************************
This program is free software; you may redistribute it and/or modify it
under the terms of the provided license as published by Lunabyte Systems.
This program is distributed in the hope that it is and will be useful,
but WITHOUT ANY WARRANTIES; without even any implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the "LSP_license.txt" file for details of the LSP license.
The latest version can always be found at http://www.lunabyte.net.
*****************************************************************
*/
if (!defined('ENIGMA'))
die('<b>Access Violation</b><br />Direct Access to this location is not allowed.');
// default news function
function NewsHub($home=0)
{
global $context, $txt, $scripturl;
loadPLanguage('News');
$sa = (!empty($_POST['sa'])) ? $_POST['sa'] :
!empty($_REQUEST['sa']) ? $_REQUEST['sa'] :
!empty($_GET['sa']) ? $_GET['sa'] : '';
$subActions = array(
'newsarchive',
'newsIndex',
'addnews',
);
if (in_array($sa, $subActions))
$sa();
elseif (isset($subActions[$sa])) // is a sub-action set?
$subActions[$sa]();
elseif ($home) // is news set for the home page and are we displaying featured news?
{
$context['page_title'] = $context['forum_name'];
SiteNews('home');
}
else // show the default news display
{
$context['page_title'] = $context['forum_name'] . ' ' . $txt['news_500'];
SiteNews();
}
unset($subActions);
}
function SiteNews($home=0)
{
global $context, $settings, $modSettings, $scripturl, $txt, $db_prefix, $ID_MEMBER, $user_info, $sc;
loadPTemplate('News');
loadPLanguage('News');
// if only one category was selected....
if (isset($_REQUEST['id']) && $_REQUEST['id'] != '' && $_REQUEST['id'] != 'none')
$catid = $_REQUEST['id'];
elseif (!empty($_REQUEST['id']) && $_REQUEST['id'] == 'none')
$catid = '0';
else
$catid = '';
// ...then setup the query accordingly
$cat_query = ($catid >= '0') ? 'AND n.ID_CATEGORY = \'' . $catid . '\'': '';
// if user has reviewing rights, pull news that's been approved AND is awaiting approval
if (allowedTo('review_news'))
{
$review_news = 1;
$stage = 'AND (n.stage = 0 OR n.stage = 1 OR n.stage = 4)';
$publish = '';
}
else // otherwise, only show news that's approved
{
$review_news = '';
$publish = 'AND n.publish = 0';
$stage = 'AND n.stage = 1 AND reviewFlag = 0';
}
// Make a nice page listed display for the News page, or if the front page uses news.
if (!isset($_GET['start']) || $_GET['start'] < 0)
{
$_GET['start'] = 0;
}
// just in case they don't have a default value.
if (empty($modSettings['maxNPdisplay']))
{
$modSettings['maxNPdisplay'] = 5;
}
// just in case they don't have a default value.
if (empty($modSettings['maxnewsitems']))
{
$modSettings['maxnewsitems'] = 5;
}
$nstart = isset($_GET['start']) ? $_GET['start'] : '0';
$nend = isset($modSettings['maxNPdisplay']) ? $modSettings['maxNPdisplay'] : '5';
$fpend = isset($modSettings['maxnewsitems']) ? $modSettings['maxnewsitems'] : '5';
if($home)
{
$LIMIT = 'LIMIT ' . $nstart . ', ' . $fpend;
$frontpage = 'AND n.featureFlag = 1';
$context['home_page'] = 1;
}
else
{
$LIMIT = 'LIMIT ' . $nstart . ', ' . $nend;
$frontpage = '';
}
$result = db_query("
SELECT
n.*, m.posterTime, m.subject, m.ID_TOPIC, m.ID_MEMBER, m.ID_MSG, m.ID_BOARD, b.name AS bName
FROM ({$db_prefix}news AS n, {$db_prefix}messages AS m, {$db_prefix}topics AS t2, {$db_prefix}boards AS b)
LEFT JOIN {$db_prefix}news_categories AS nc ON (n.ID_CATEGORY = nc.ID_CATEGORY)
LEFT JOIN {$db_prefix}topics AS t ON (n.ID_TOPIC = t.ID_FIRST_MSG)
WHERE $user_info[query_see_board]
AND n.ID_TOPIC = m.ID_TOPIC
$frontpage
$cat_query
$publish
$stage
AND b.ID_BOARD = m.ID_BOARD
AND m.ID_MSG = t2.ID_FIRST_MSG
GROUP BY m.ID_MSG DESC", __FILE__, __LINE__);
$num_news = mysql_num_rows($result);
mysql_free_result($result);
// if we're on the home page, set the page #'s
if($home)
{
$context['news_pages'] = constructPageIndex($scripturl . '?News' . ('') . (isset($filter) ? $filter['href'] : ''), $_GET['start'], $num_news, $fpend);
$context['start'] = $_GET['start'];
}
// if we're only showinf one News Category
elseif (isset($_REQUEST['id']))
{
$context['news_pages'] = constructPageIndex($scripturl . '?op=News;id='. $catid . ('') . (isset($filter) ? $filter['href'] : ''), $_GET['start'], $num_news, $nend);
$context['start'] = $_GET['start'];
}
// We must be on the main News page, if the above conditions were not met
else
{
$context['news_pages'] = constructPageIndex($scripturl . '?op=News' . ('') . (isset($filter) ? $filter['href'] : ''), $_GET['start'], $num_news, $nend);
$context['start'] = $_GET['start'];
}
// Find all the news for the current display. Newer ones will have higher IDs.
$request = db_query("
SELECT
n.*, m.posterTime, m.subject, m.ID_TOPIC, m.ID_MEMBER, m.ID_MSG, m.ID_BOARD, b.name AS bName, m.body,
t2.numReplies AS Replies, t2.numViews AS Views, nc.name AS CatName, nc.image AS CatImage, nc.ID_CATEGORY AS CatId,
IFNULL(mem.realName, m.posterName) AS posterName, " . ($user_info['is_guest'] ? '1 AS isRead, 0 as logTime' : '
IFNULL(lt.logTime, IFNULL(lmr.logTime, 0)) >= GREATEST(m.posterTime, m.modifiedTime) AS isRead,
IFNULL(lt.logTime, IFNULL(lmr.logTime, 0)) AS logTime') . ", t2.isSticky
FROM ({$db_prefix}news AS n, {$db_prefix}messages AS m, {$db_prefix}topics AS t2, {$db_prefix}boards AS b)
LEFT JOIN {$db_prefix}news_categories AS nc ON (n.ID_CATEGORY = nc.ID_CATEGORY)
LEFT JOIN {$db_prefix}topics AS t ON (n.ID_TOPIC = t.ID_FIRST_MSG)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)" . (!$user_info['is_guest'] ? "
LEFT JOIN {$db_prefix}log_topics AS lt ON (lt.ID_TOPIC = m.ID_TOPIC AND lt.ID_MEMBER = $ID_MEMBER)
LEFT JOIN {$db_prefix}log_mark_read AS lmr ON (lmr.ID_BOARD = m.ID_BOARD AND lmr.ID_MEMBER = $ID_MEMBER)" : '') . "
WHERE $user_info[query_see_board]
AND n.ID_TOPIC = m.ID_TOPIC
$frontpage
$cat_query
$publish
$stage
AND b.ID_BOARD = m.ID_BOARD
AND m.ID_MSG = t2.ID_FIRST_MSG
ORDER BY " . (!empty($modSettings['enableStickyTopics']) ? 't2.isSticky DESC' . ',
' : '') . " m.posterTime DESC
$LIMIT", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
{
// Censor the subject.
censorText($row['subject']);
censorText($row['body']);
// find out the current status if the user is a reviewer
if ($row['publish'] == 1 && $review_news)
$status = $txt['news_438'];
elseif ($review_news && $row['stage'] != '1')
$status = statusText($row['stage']);
else
$status = '';
$readmore = '';
// Set up the "Read more" feature.
if (stristr($row['body'],$txt['news_524'])) { $body_parts = explode($txt['news_524'],$row['body']); }
if (stristr($row['body'],$txt['news_525'])) { $body_parts = explode($txt['news_525'],$row['body']); }
if ((stristr($row['body'],$txt['news_524'])) OR (stristr($row['body'],$txt['news_525'])))
{
$row['body'] = $body_parts[0];
$readmore = '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . '#msg' . $row['ID_MSG'] . '">' . $txt['news_526'] . '</a> | ';
}
$commentsft = '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . ';topicseen#msg' . $row['ID_MSG'] . '">' . (!empty($row['Replies']) ? $row['Replies'] : '0') . ' ' . $txt['news_527'] . '</a> | ';
$replyft = '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.0;num_replies=' . (!empty($row['Replies']) ? $row['Replies'] : '0') . '">' . $txt['news_528'] . '</a>';
// Build the array.
$posts[] = array(
'board' => array(
'id' => $row['ID_BOARD'],
'name' => $row['bName'],
'href' => $scripturl . '?board=' . $row['ID_BOARD'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row['ID_BOARD'] . '.0">' . $row['bName'] . '</a>'
),
'topic' => $row['ID_TOPIC'],
'poster' => array(
'id' => $row['ID_MEMBER'],
'name' => $row['posterName'],
'href' => empty($row['ID_MEMBER']) ? '' : $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
'link' => empty($row['ID_MEMBER']) ? $row['posterName'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>'
),
'subject' => un_htmlspecialchars($row['subject']),
'status' => $status,
'short_subject' => strlen(un_htmlspecialchars($row['subject'])) > 25 ? htmlspecialchars(substr(un_htmlspecialchars($row['subject']), 0, 22) . '...') : $row['subject'],
'time' => timeformat($row['posterTime']),
'timestamp' => $row['posterTime'],
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . ';topicseen#msg' . $row['ID_MSG'],
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . '#msg' . $row['ID_MSG'] . '">' . $row['subject'] . '</a>',
'new' => !empty($row['isRead']),
'newtime' => $row['logTime'],
'body' => doUBBC($row['body']),
'comments' => (!empty($row['Replies']) ? $row['Replies'] : '0'),
'Views' => $row['Views'],
'CatName' => $row['CatName'],
'CatImage' => !empty($row['CatImage']) ? '<img src="' . $settings['images_url'] . '/News/' . $row['CatImage'] . '" title="'.$row['CatName'].'" alt="'.$row['CatName'].'" border="0" style="float: left; padding-right: 2px; padding-bottom: 2px;" />' : '',
'CatLink' => '<a href="' . $scripturl . '?op=News;id=' . $row['CatId'] . '">' . $row['CatName'] . '</a>',
'reply' => $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.0;num_replies=' . (!empty($row['Replies']) ? $row['Replies'] : '0'),
'footer' => (!empty($readmore) ? $readmore : '') . (!empty($commentsft) ? $commentsft : '') . (!empty($replyft) ? $replyft : ''),
'admin' => (allowedTo('moderate_forum') ? ' | <a href="' . $scripturl . '?action=post;msg=' . $row['ID_MSG'] . ';topic=' . $row['ID_TOPIC'] . '.0;sesc=' . $sc . '">' . $txt['news_529'] . '</a> | <a href="javascript:DoConfirm(\'' . $txt[162] . '\',\'' . $scripturl . '?action=removetopic2;topic=' . $row['ID_TOPIC'] . ';sesc=' . $sc . '\')">' . $txt['news_530'] . '</a>' : ''),
'sticky' => !empty($modSettings['enableStickyTopics']) && !empty($row['isSticky']),
'stickylink' => allowedTo('moderate_forum') ? $scripturl . '?action=sticky;topic=' . $row['ID_TOPIC'] . '.0;sesc=' . $sc : '',
);
}
mysql_free_result($request);
if (empty($posts)) // if by chance there isn't any news, load a message saying that
{
$posts = $txt['news_none'];
}
// if one category was selected, add it's name to the page title
if (isset($catid) && $catid >= '0' && $posts && $posts[0]['CatName'] != '')
{
$context['page_title'] .= ' - ' . $posts[0]['CatName'];
}
$context['sitenews'] = $posts;
unset ($posts);
// set the names for the functions in the template file
$context['sub_template'] = 'News_body';
$context['template_layers'][] = 'News';
}
function addnews()
{
// this is the default new submission function
// and will bring up a post window for the default news board selected in Portal Settings
global $modSettings, $scripturl;
// is user allowed to?
isAllowedTo('submit_news');
$boards = boardsAllowedTo('post_new');
$default = str_replace('Board_', '', $modSettings['news_defaultboard']);
if (empty($boards) && !in_array($default, $boards))
{
loadPLanguage('PortalErrors');
fatal_lang_error('cannot_post_new');
}
else
redirectexit("$scripturl?action=post;board=$default;sub=1", false);
}
function newsarchive()
{
global $context, $settings, $modSettings, $scripturl, $txt, $db_prefix, $ID_MEMBER, $user_info, $sc;
loadPTemplate('News');
// Initial archive display. Show them a list of categories they can see and choose from.
if (!isset($_REQUEST['catid']))
{
$get_cats = db_query("SELECT * FROM {$db_prefix}news_categories ORDER BY ID_CATEGORY", __FILE__, __LINE__);
while ($newscat = mysql_fetch_assoc($get_cats))
{
// Build the News Category Array
$gotcat[] = array(
'ID_CATEGORY' => !empty($newscat['ID_CATEGORY']) ? $newscat['ID_CATEGORY'] : $catid,
'image' => $settings['images_url'] . '/News/' . $newscat['image'],
'name' => !empty($newscat['name']) ? $newscat['name'] : '',
'caturl' => $scripturl . '?op=News;sa=newsarchive;catid=' . $newscat['ID_CATEGORY'],
'subs' => !empty($newscat['subs']) ? $newscat['subs'] : '',
);
}
mysql_free_result($get_cats);
$context['iscats'] = 1;
$context['ncats'] = $gotcat;
// Show the "none" news category
$context['lastcat'] = array(
'ID_CATEGORY' => 0,
'image' => $settings['images_url'] . '/News/default.jpg',
'name' => $txt['news_523'],
'caturl' => $scripturl . '?op=News;sa=newsarchive;catid=0',
'subs' => -1,
);
$context['page_title'] = !empty($context['page_title']) ? $txt['news_501'] : $txt['news_501'];
}
elseif (isset($_REQUEST['catid']))
{
// Ok, we have a category to display.
// Let's not overload the system, and only get 50 at a time. We'll need pages!
// Find all the news for the current display. Newer ones will have higher IDs.
if (isset($_REQUEST['catid']) && $_REQUEST['catid'] != '' && $_REQUEST['catid'] != 'none')
{
$catid = $_REQUEST['catid'];
}
elseif (isset($_REQUEST['catid']) && $_REQUEST['catid'] == 'none')
{
$catid = '0';
}
// ...then setup the query accordingly
$cat_query = (isset($catid) && $catid >= '0') ? 'AND n.ID_CATEGORY = \'' . $catid . '\'': '';
// if user has reviewing rights, pull news that's been approved AND is awaiting approval
if (allowedTo('review_news'))
{
$review_news = 1;
$stage = 'AND (n.stage = 0 OR n.stage = 1 OR n.stage = 4)';
$publish = '';
}
else // otherwise, only show news that's approved
{
$review_news = '';
$publish = 'AND n.publish = 0';
$stage = 'AND n.stage = 1 AND reviewFlag = 0';
}
// Make a nice page listed display for the News archive
if (!isset($_GET['start']) || $_GET['start'] < 0)
{
$_GET['start'] = 0;
}
$nstart = isset($_GET['start']) ? $_GET['start'] : '0';
$nend = '50';
$LIMIT = 'LIMIT ' . $nstart . ', ' . $nend;
$result = db_query("
SELECT
n.*, m.posterTime, m.subject, m.ID_TOPIC, m.ID_MEMBER, m.ID_MSG, m.ID_BOARD, b.name AS bName
FROM ({$db_prefix}news AS n, {$db_prefix}messages AS m, {$db_prefix}topics AS t2, {$db_prefix}boards AS b)
LEFT JOIN {$db_prefix}news_categories AS nc ON (n.ID_CATEGORY = nc.ID_CATEGORY)
LEFT JOIN {$db_prefix}topics AS t ON (n.ID_TOPIC = t.ID_FIRST_MSG)
WHERE $user_info[query_see_board]
$cat_query
AND n.ID_TOPIC = m.ID_TOPIC
$publish
$stage
AND b.ID_BOARD = m.ID_BOARD
AND m.ID_MSG = t2.ID_FIRST_MSG
GROUP BY m.ID_MSG DESC", __FILE__, __LINE__);
$num_news = mysql_num_rows($result);
mysql_free_result($result);
// page #'s hardcoded to 50 lines per page.
$context['newsar_pages'] = constructPageIndex($scripturl . '?op=newsarchive;catid=' . $catid . ('') . (isset($filter) ? $filter['href'] : ''), $_GET['start'], $num_news, $nend);
$context['start'] = $_GET['start'];
$get_cat_info = db_query("SELECT * FROM {$db_prefix}news_categories WHERE ID_CATEGORY = '$catid' LIMIT 1", __FILE__, __LINE__);
while ($rowcat = mysql_fetch_array($get_cat_info))
{
$context['catinfo'][] = array(
'catid' => !empty($rowcat['ID_CATEGORY']) ? $rowcat['ID_CATEGORY'] : $catid,
'image' => !empty($settings['images_url']) ? $settings['images_url'] . '/News/' . $rowcat['image'] :'',
'name' => !empty($rowcat['name']) ? $rowcat['name'] : '',
);
}
mysql_free_result($get_cat_info);
// If the above query is empty, as in it's the built-in category... create the array.
if(empty($context['catinfo']))
{
$context['catinfo'][0] = array(
'catid' => 0,
'image' => !empty($settings['images_url']) ? $settings['images_url'] . '/News/default.jpg' : '',
'name' => $txt['news_523'],
);
}
// Finally get the news items for the selected category
$request = db_query("
SELECT
n.*, m.posterTime, m.subject, m.ID_TOPIC, m.ID_MEMBER, m.ID_MSG, m.ID_BOARD, m.posterEmail,
IFNULL(mem.realName, m.posterName) AS posterName, t.ID_MEMBER_STARTED, nc.*
FROM
({$db_prefix}news_categories AS nc, {$db_prefix}news AS n,
{$db_prefix}messages AS m, {$db_prefix}topics AS t2,
{$db_prefix}boards AS b)
LEFT JOIN {$db_prefix}topics AS t ON (n.ID_TOPIC = t.ID_FIRST_MSG)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE $user_info[query_see_board]
$cat_query
AND n.ID_TOPIC = m.ID_TOPIC
AND n.publish = 0
AND n.stage = 1
AND n.reviewFlag = 0
AND b.ID_BOARD = m.ID_BOARD
AND m.ID_MSG = t2.ID_FIRST_MSG
GROUP BY t.isSticky DESC, m.ID_MSG DESC
$LIMIT", __FILE__, __LINE__);
//put each news item into the archive array
while ($row = mysql_fetch_array($request))
{
if ($row['ID_MEMBER_STARTED'] > 0)
$url = $scripturl . '?action=profile;u=' .$row['ID_MEMBER_STARTED'];
else
$url = 'mailto:' . $row['posterEmail'];
// Censor the subject
censorText($row['subject']);
$posts[] = array(
'board' => !empty($row['ID_BOARD']) ? $row['ID_BOARD'] : '',
'topic' => !empty($row['ID_TOPIC']) ? $row['ID_TOPIC'] : '',
'subject' => !empty($row['subject']) ? $row['subject'] : '',
'postedTime' => timeformat($row['posterTime']),
'bylineUrl' => $url,
'posterName' => !empty($row['posterName']) ? $row['posterName'] : '',
);
unset($url);
}
mysql_free_result($request);
$context['page_title'] = !empty($context['page_title']) ? $txt['news_501'] . ': ' . $context['catinfo'][0]['name'] : $txt['news_501'] . ': ' . $context['catinfo'][0]['name'];
$context['isarchive'] = 1;
$context['catarchive'] = !empty($posts) ? $posts : '';
unset ($posts);
}
// set the names for the functions in the template file
$context['sub_template'] = 'archive_body';
$context['template_layers'][] = 'News';
}
function newsIndex()
{
global $context, $db_prefix, $ID_MEMBER, $txt, $scripturl, $settings, $user_info;
loadPTemplate('News');
$context['page_title'] = '';
$context['page_title'] .= ' - ' . $txt['news_504'];
$context['linktree'][] = array(
'url' => $scripturl . '?op=submissions',
'name' => $txt['news_518'],
);
$context['linktree'][] = array(
'name' => $txt['news_504'],
);
// check the permissions
is_not_guest($txt['news_505']);
$revNewsAllowed = allowedTo('review_news');
$subNewsAllowed = allowedTo('submit_news');
if ($revNewsAllowed) {
$user_query = '';
}
else if ($subNewsAllowed) {
$user_query = 'AND n.ID_POSTER = ' . $ID_MEMBER;
}
else
{ //these guys don't have rights - zero out the values
loadPLanguage('PortalErrors');
fatal_lang_error($txt['sumbmit_news_error']);
}
// set the category filter, if a category was already selected
if (!empty($_POST['catfilter']) && $_POST['catfilter'] != 'none')
$catfilter = $_POST['catfilter'];
elseif (!empty($_POST['catfilter']) && $_POST['catfilter'] == 'none') // set category to 0 if the "none" cat was selected
$catfilter = '0'; // *** the quotation marks are important on this one
else
$catfilter = '';
// setup the category query based on the current selection
$cat_query = ($catfilter >= '0') ? 'AND n.ID_CATEGORY = ' . $catfilter : '';
// set the stage filter
$stagef = (isset($_POST['stagef'])) ? $_POST['stagef'] : '';
// set the stage query based on selection
$stage_query = ($stagef == 9 || $stagef == '') ? '' : 'AND n.stage = ' . $stagef;
// build the array for all the possible stages
$context['newsstage'] = array(
'alid' => array(
'option' => 'All',
'stage' => '9',
'selected' => ($stagef == 9 || $stagef == '') ? 'selected="selected" ' : ''),
'peid' => array(
'option' => 'Pending',
'stage' => '0',
'selected' => ($stagef == 0 && $stagef != '') ? 'selected="selected" ' : ''),
'apid' => array(
'option' => 'Approved',
'stage' => '1',
'selected' => ($stagef == 1) ? 'selected="selected" ' : ''),
'rjid' => array(
'option' => 'Rejected',
'stage' => '2',
'selected' => ($stagef == 2) ? 'selected="selected" ' : ''),
'caid' => array(
'option' => 'Canceled',
'stage' => '3',
'selected' => ($stagef == 3) ? 'selected="selected" ' : ''),
'rsid' => array(
'option' => 'ReSubmitted',
'stage' => '4',
'selected' => ($stagef == 4) ? 'selected="selected" ' : ''),
);
//setup the category filter
// setup All category
$context['filtercat'][] = array(
'name' => $txt['news_506'],
'value' => '',
'selected' => (($catfilter == '') ? 'selected="selected"' : ''),
);
// setup None category
$context['filtercat'][] = array(
'name' => $txt['news_516'],
'value' => 'none',
'selected' => (($catfilter == '0') ? 'selected="selected"' : ''),
);
// get the rest of the categories
$request = db_query("
SELECT *
FROM {$db_prefix}news_categories
ORDER BY name", __FILE__, __LINE__);
// setup the rest of the filter array
while ($cats = mysql_fetch_assoc($request))
{
$context['filtercat'][] = array(
'name' => $cats['name'],
'value' => $cats['ID_CATEGORY'],
'selected' => (($catfilter == $cats['ID_CATEGORY']) ? 'selected="selected"' : ''),
);
}
mysql_free_result ($request);
// Grab the selected submissions
$request = db_query("
SELECT n.ID_NEWS, n.ID_TOPIC AS ID_TOPIC, n.ID_POSTER, n.ID_REVIEWER, n.reviewFlag, n.stage, n.dateEntered, n.dateModified,
n.publish, IFNULL(n.dateModified, n.dateEntered) AS lastdate, c.image, c.name, c.ID_CATEGORY,
t.ID_TOPIC, t.ID_FIRST_MSG, m.posterName, m.ID_MSG,
m.subject, m.posterEmail AS posterEmail, mem.memberName AS srealName, m.ID_MEMBER, m.ID_BOARD,
IFNULL(mem.realName, mem.memberName) AS submitter, mem2.memberName AS rrealName,
IFNULL(mem2.realName, mem2.memberName) AS reviewer,
t.ID_FIRST_MSG, IFNULL(lt.logTime, 0) AS isRead, IFNULL(lmr.logTime, 0) AS isMarkedRead
FROM ({$db_prefix}topics as t, {$db_prefix}messages as m, {$db_prefix}news as n)
LEFT JOIN {$db_prefix}news_categories AS c ON (n.ID_CATEGORY = c.ID_CATEGORY)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER=n.ID_POSTER)
LEFT JOIN {$db_prefix}members AS mem2 ON (mem2.ID_MEMBER=n.ID_REVIEWER)
LEFT JOIN {$db_prefix}log_topics AS lt ON (lt.ID_TOPIC=t.ID_TOPIC AND lt.ID_MEMBER=$ID_MEMBER)
LEFT JOIN {$db_prefix}log_mark_read AS lmr ON (lmr.ID_BOARD=t.ID_BOARD AND lmr.ID_MEMBER=$ID_MEMBER)
WHERE $user_info[query_see_board]
AND t.ID_TOPIC = n.ID_TOPIC
AND m.ID_MSG=t.ID_FIRST_MSG
$stage_query
$cat_query
$user_query
ORDER BY IFNULL(dateModified, dateEntered) DESC", __FILE__, __LINE__);
// build the array to use in the template for displaying the submissions
while($row = mysql_fetch_assoc($request))
{
$new = ($row['isRead'] >= $row['lastdate'] || $row['isMarkedRead'] >= $row['lastdate'] ? false : true);
$context['newsindex'][] = array(
'msgsubject' => $row['subject'],
'msgurl' => $scripturl . '?topic=' . $row['ID_TOPIC'],
'submitter' => ($row['ID_POSTER'] == 0) ? $row['posterName'] : $row['submitter'],
'submitterlink'=> ($row['ID_POSTER'] == 0) ? 'mailto:' . $row['posterEmail'] : $scripturl . '?action=profile;u=' .$row['ID_POSTER'],
'reviewer' => ($row['ID_REVIEWER'] == '') ? '' : $row['reviewer'],
'reviewerlink' => ($row['ID_REVIEWER'] == '') ? '' : $scripturl . '?action=profile;u=' .$row['ID_REVIEWER'],
'status' => ($row['publish'] == 1) ? $txt['news_507'] : statusText($row['stage']),
'mdate' => !empty($row['posterTime']) ? timeformat($row['posterTime']) : '',
'subdate' => timeformat($row['dateEntered']),
'moddate' => (!$row['dateModified']) ? '' : timeformat($row['dateModified']),
'newurl' => (!$new || $user_info['is_guest']) ? '' : '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.from' . $row['isRead'] . '#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt['302'] . '" border="0" /></a>',
'catimage' => !empty($row['image']) ? $settings['images_url'] . '/News/' . $row['image'] : '',
'catname' => !empty($row['name']) ? $row['name'] : $txt['news_516'],
'caturl' => !empty($row['name']) ? $scripturl . '?op=News;id=' . $row['ID_CATEGORY'] : $scripturl . '?op=News;id=none',
);
}
mysql_free_result($request);
if (!$context['newsindex']) // if by chance there aren't any submissions for the current selection, load a message
$context['newsindex'] = $txt['news_517'];
$context['sub_template'] = 'news_index';
obExit();
}
?>