<?php

############################################################################
#                              Site@School Newsletter module
# Site@School is a website management system designed for schools.
# This is a newsletter module which can be used in Site@School.
#
# coded by Fred Stuurman (fc.stuurman@hccnet.nl)
############################################################################
# newsletter_latest.php: last changed 18/10/2005   SAS version 2.4
#                  by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: newsletter_latest.php,v 1.1 2006/10/03 10:33:58 fstuurman Exp $
############################################################################
#                        LICENSE INFORMATION
# Copyright (C) 2002 - 2005 Municipality of Amsterdam, City District
#  'de Baarsjes', Amsterdam, the Netherlands.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
##############################################################################
if (!defined('IN_SAS'))
{
	die("Hacking attempt");
}

if (file_exists($cmsdir . "/languages/" . $language . "/sn_newsletter/" . $language . ".php"))
{
	include ($cmsdir . "/languages/" . $language . "/sn_newsletter/" . $language . ".php");
}
else
{
	include ($cmsdir . "/languages/EN/sn_newsletter/EN.php");
}

$query = "SELECT dbtables FROM $table_modules WHERE location='sn_newsletter'"; // getting the table names
$result = mysql_query($query) or die_script($query, mysql_error());
$moduletables = mysql_result($result, 0);
unset ($query);
unset ($result);
$moduletables = explode(",", $moduletables);
$table_newsletter_content = "$moduletables[0]";
$table_newsletters = "$moduletables[1]";

$query1 = "SELECT id FROM $table_newsletters WHERE name='$pagetitle'"; // do we have a newsletter with this pagename
$result1 = mysql_query($query1) or die_script($query1, mysql_error());
$RecordCount = mysql_num_rows($result1);
if ($RecordCount == 1)
{
	$newsletter_id = mysql_result($result1, 0, 0);

	$query = "SELECT header,content,footer,title FROM $table_newsletter_content WHERE newsletter_id = '$newsletter_id' ORDER BY date DESC LIMIT 1"; // getting the newsletter content
	$result = mysql_query($query) or die_script($query, mysql_error());
	$RecordCount = mysql_num_rows($result);
	if ($RecordCount > 0)
	{
		$header = mysql_result($result, 0, 0);
		$content = mysql_result($result, 0, 1);
		$footer = mysql_result($result, 0, 2);
		$newsletter_title = mysql_result($result, 0, 3);
		unset ($query);
		unset ($result);
		print $header . $content . $footer;
	}
}
else
{
	print $sas_lang['newsletter_module_page_error'];
}
?>
