##############################################################
## MOD Title:          Last news headlined
## MOD Author:         -=ET=- < N/A > (N/A) http://www.golfexpert.net/phpbb 
## MOD Description:    This mod let admins put the lastest news
##                     (topics of a news/announcement forum) on
##                     the home page (Index page) of their forums
## MOD Version:        1.0.0
## 
## Installation Level: Easy
## Installation Time:  5 Minutes (1mn by EasyMOD)
## Files To Edit:
##      index.php
##      admin/admin_board.php
##      language/lang_english/lang_admin.php
##      language/lang_english/lang_main.php
##      templates/subSilver/index_body.tpl
##      templates/subSilver/admin/board_config_body.tpl
## Included Files:     N/A
## License: http://opensource.org/licenses/gpl-license.php GNU General Public License v2
##############################################################
## For security purposes, please check: http://www.phpbb.com/mods/
## for the latest version of this MOD. Although MODs are checked
## before being allowed in the MODs Database there is no guarantee
## that there are no security problems within the MOD. No support
## will be given for MODs not found within the MODs Database which
## can be found at http://www.phpbb.com/mods/
##############################################################
## Author Notes: 
##
## 1. Compatibility
## -----------
## - This MOD is phpBB 2.0.17->2.0.18 compliant (prior release not tested)
##
## 2. EasyMOD
## -----------
## This MOD is compatible with EasyMOD and can be installed
## by it but is not yet certified EMC (EasyMOD Compliant)!
## http://area51.phpbb.com/phpBB22/viewforum.php?sid=&f=15
##
## 3. Official last version link
## -----------
## Meanwhile the phpBB group validation and as the MOD is not yet
## in the phpBB MOD database, check this official link for updates...
## http://www.golfexpert.net/phpBB
##
############################################################## 
## MOD History: 
##
##   2005-08-07 - Version 1.0.0
##      - Initial final release
## 
############################################################## 
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
############################################################## 
#
#-----[ SQL ]-------------------------------------------------
#
INSERT INTO phpbb_config (config_name, config_value) VALUES ('display_last_news', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('news_forum_id', '1');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('news_displayed', '3');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('news_date_format', 'd M');

# 
#-----[ OPEN ]------------------------------------------------ 
# 
index.php

# 
#-----[ FIND ]------------------------------------------------ 
# 
//
// Start page proper

# 
#-----[ BEFORE, ADD ]-----------------------------------------
# 
// Start add - Last news headlined MOD
if ( $board_config['display_last_news'] && $board_config['news_forum_id'] && $board_config['news_displayed'])
{
	$template->assign_block_vars('switch_last_news', array());

	$sql = "SELECT t.topic_id, t.topic_title, p.post_time
		FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
		WHERE t.forum_id = ".$board_config['news_forum_id']."
			AND p.post_id = t.topic_last_post_id
		ORDER BY t.topic_last_post_id DESC
		LIMIT ".$board_config['news_displayed'];
	if ( !($result = $db->sql_query($sql)) )
	{
	   message_die(GENERAL_ERROR, 'Could not obtain topic information', '', __LINE__, __FILE__, $sql);
	}

	$total_news = 0;
	while( $row = $db->sql_fetchrow($result) )
	{
		$news_rowset[] = $row;
		$total_news++;
	}

	$db->sql_freeresult($result);

	if( $total_news )
	{
		$template->assign_vars(array(
			'NEWS_TABLE_TITLE' => $lang['News_table_title'])
		);

		for($i = 0; $i < $total_news; $i++)
		{
			$news_id = $news_rowset[$i]['topic_id'];
			$news_title = $news_rowset[$i]['topic_title'];
			$news_time = create_date($board_config['news_date_format'], $news_rowset[$i]['post_time'], $board_config['board_timezone']);
			$view_news_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$news_id");

			$template->assign_block_vars('switch_last_news.newsrow', array(
				'NEWS_TITLE' => $news_title,
				'NEWS_TIME' => $news_time, 
				'U_VIEW_NEWS' => $view_news_url)
			);
		}
	}
}
// End add - Last news headlined MOD

# 
#-----[ OPEN ]------------------------------------------------ 
# 
admin/admin_board.php 

# 
#-----[ FIND ]------------------------------------------------
#
#
# $smtp_no = ( !$new['smtp_delivery'] ) ? "checked=\"checked\"" : "";
#
$smtp_no = (

#
#-----[ AFTER, ADD ]------------------------------------------
#

// Start add - Last news headlined MOD
$display_last_news_yes = ( $new['display_last_news'] ) ? "checked=\"checked\"" : "";
$display_last_news_no = ( !$new['display_last_news'] ) ? "checked=\"checked\"" : "";

$sql = "SELECT f.*
	FROM " . FORUMS_TABLE . " f, " . CATEGORIES_TABLE . " c
	WHERE c.cat_id = f.cat_id
	ORDER BY c.cat_order ASC, f.forum_order ASC";
if ( !($result = $db->sql_query($sql)) )
{
	message_die(GENERAL_ERROR, "Couldn't obtain forum list", "", __LINE__, __FILE__, $sql);
}

$news_forum_rows = $db->sql_fetchrowset($result);
$db->sql_freeresult($result);

$news_forum_select = '<select name="news_forum_id">';
for($i = 0; $i < count($news_forum_rows); $i++)
{
	$news_forum_selected = ( $board_config['news_forum_id'] == $news_forum_rows[$i]['forum_id'] ) ? ' selected="selected"' : '';
	$news_forum_select .= '<option value="' . $news_forum_rows[$i]['forum_id'] . '"'  . $news_forum_selected . '>' . $news_forum_rows[$i]['forum_name'] . '</option>';
}
$news_forum_select .= '</select>';
// End add - Last news headlined MOD

# 
#-----[ FIND ]------------------------------------------------ 
# 
# NOTE: this is a search by part(s) of code line(s)!
# The original line(s) to find is(are) longer and must look like this (if no MOD has already modify them):
#
# "L_SMTP_PASSWORD_EXPLAIN" => $lang['SMTP_password_explain'],
#
"L_SMTP_PASSWORD_EXPLAIN" =>

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#

// Start add - Last news headlined MOD
"L_LAST_NEWS_SETTINGS" => $lang['Last_news_settings'],
"L_DISPLAY_LAST_NEWS" => $lang['Display_last_news'],
"L_NEWS_FORUM_ID" => $lang['News_forum_id'],
"L_NEWS_DISPLAYED" => $lang['News_displayed'],
"L_NEWS_DATE_FORMAT" => $lang['News_date_format'],
// End add - Last news headlined MOD

# 
#-----[ FIND ]------------------------------------------------ 
# 
# NOTE: this is a search by part(s) of code line(s)!
# The original line(s) to find is(are) longer and must look like this (if no MOD has already modify them):
#
# "SMTP_PASSWORD" => $new['smtp_password'],
#
"SMTP_PASSWORD" =>

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#

// Start add - Last news headlined MOD
"DISPLAY_LAST_NEWS_YES" => $display_last_news_yes,
"DISPLAY_LAST_NEWS_NO" => $display_last_news_no,
"NEWS_FORUM_SELECT" => $news_forum_select,
"NEWS_DISPLAYED" => $new['news_displayed'],
"NEWS_DATE_FORMAT" => $new['news_date_format'],
// End add - Last news headlined MOD

#
#-----[ OPEN ]------------------------------------------------
#
language/lang_english/lang_admin.php

#
#-----[ FIND ]------------------------------------------------
#
?>

#
#-----[ BEFORE, ADD ]-----------------------------------------
#

// Start add - Last news headlined MOD
$lang['Last_news_settings'] = 'Last announcement & news settings';
$lang['Display_last_news'] = 'Display a Last announcement & news table';
$lang['News_forum_id'] = 'Forum where the Last announcement & news are';
$lang['News_displayed'] = 'N of news to display';
$lang['News_date_format'] = 'News date format';
// End add - Last news headlined MOD

#
#-----[ OPEN ]------------------------------------------------
#
language/lang_english/lang_main.php

#
#-----[ FIND ]------------------------------------------------
#
?>

#
#-----[ BEFORE, ADD ]-----------------------------------------
#

// Start add - Last news headlined MOD
$lang['News_table_title'] = 'Lastest announcements & news';
// End add - Last news headlined MOD

# 
#-----[ OPEN ]------------------------------------------------ 
# 
templates/subSilver/index_body.tpl 

# 
#-----[ FIND ]------------------------------------------------ 
# 
<table width="100%" cellspacing="0" cellpadding="2" border="0" align="center">

# 
#-----[ BEFORE, ADD ]-----------------------------------------
#

<!-- Start add - Last news headlined MOD -->
<!-- BEGIN switch_last_news -->
<table class="forumline" width="450" cellspacing="1" cellpadding="3" border="0" align="center">
	<tr>
		<th class="thHead">{NEWS_TABLE_TITLE}</th>
	</tr>
	<!-- BEGIN newsrow -->
	<tr>
		<td class="row1" width="100%"><span class="topictitle"><a href="{switch_last_news.newsrow.U_VIEW_NEWS}" class="topictitle">{switch_last_news.newsrow.NEWS_TIME} - {switch_last_news.newsrow.NEWS_TITLE}</a></span></td>
	</tr>
	<!-- END newsrow -->
</table>
<br />
<!-- END switch_last_news -->
<!-- End add - Last news headlined MOD -->

#
#-----[ OPEN ]------------------------------------------------
#
templates/subSilver/admin/board_config_body.tpl

#
#-----[ FIND ]------------------------------------------------
#
# NOTE: this is a search by part(s) of code line(s)!
# The original line(s) to find is(are) longer and must look like this (if no MOD has already modify them):
#
# 
#
<tr>
{L_SUBMIT}

#
#-----[ BEFORE, ADD ]-----------------------------------------
#

<!-- Start add - Last news headlined MOD -->
	<tr>
	  <th class="thHead" colspan="2">{L_LAST_NEWS_SETTINGS}</th>
	</tr>
	<tr>
		<td class="row1">{L_DISPLAY_LAST_NEWS}</td>
		<td class="row2"><input type="radio" name="display_last_news" value="1" {DISPLAY_LAST_NEWS_YES} /> {L_YES}&nbsp;&nbsp;<input type="radio" name="display_last_news" value="0" {DISPLAY_LAST_NEWS_NO} /> {L_NO}</td>
	</tr>
	<tr>
		<td class="row1">{L_NEWS_FORUM_ID}</td>
		<td class="row2">{NEWS_FORUM_SELECT}</td>
	</tr>
	<tr>
		<td class="row1">{L_NEWS_DISPLAYED}</td>
		<td class="row2"><input class="post" type="text" name="news_displayed" size="2" maxlength="2" value="{NEWS_DISPLAYED}" /></td>
	</tr>
	<tr>
		<td class="row1">{L_NEWS_DATE_FORMAT}</td>
		<td class="row2"><input class="post" type="text" name="news_date_format" value="{NEWS_DATE_FORMAT}" /></td>
	</tr>
<!-- End add - Last news headlined MOD -->

# 
#-----[ DIY INSTRUCTIONS ]------------------------------------
#
Regardless how you've installed this MOD (by EasyMOD or manually), if you want to install other languages than English please use the sub MODs in the /translations/ directory (as for the moment EasyMOD is not able to carry on automatically).

# 
#-----[ SAVE/CLOSE ALL FILES ]-------------------------------- 
# 
# EoM