<?php
#############################################################################
#                              Site@School Forum
# 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)
############################################################################
# archive.php: last changed 24/03/2004  version 1.0
#                  by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: archive.php,v 1.1 2006/10/03 10:33:57 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(IsSet($_GET['option']))                {$option = $_GET['option'];} else {$option = "list";}
if(IsSet($_GET['newsletter_id']))         {$newsletter_id = $_GET['newsletter_id'];}

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);
$moduletables = mysql_result($result,0);
unset($query);
unset($result);
$moduletables = explode(",", $moduletables);
$table_newsletter_content = "$moduletables[0]";
$table_newsletters = "$moduletables[1]";

switch ($option)                                                          // start of switch
{
case "view":
$query = "SELECT content FROM $table_newsletter_content WHERE id = '$newsletter_id'";    // getting the newsletter content
$result = mysql_query($query);
$content = mysql_result($result,0);
unset($query);
unset($result);
print $content ;                                                               //show the content of newsletter
break;

case "list":
   print "<h3>".$lang['newsletter_module_archive'].":</h3>";
   $query1 = "SELECT id, title FROM $table_newsletters WHERE public='0'";     // get all the newsletter categories which are public
   $result1 = mysql_query($query1);
   
   print "<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">";
   while ($cat_list = mysql_fetch_array($result1)) {
    print "<tr><td colspan=\"2\">&nbsp;</td></tr><tr><td colspan=\"2\"><a href=\"index.php?section=$section&page=$page&newsletter_id=$cat_list[0]\"><b>$cat_list[1]</b></a>
           </td></tr>" ;
    if($cat_list[0] == $newsletter_id) {   
        $query3 = "SELECT id, title FROM $table_newsletter_content WHERE newsletter_id='$newsletter_id' AND archive='1' AND published='1' ORDER BY date DESC";
        $result3 = mysql_query($query3);
        
        while ($newsletter_list = mysql_fetch_array($result3))
        {
        print "<tr><td>&nbsp;</td>
               <td><a href=\"index.php?section=$section&page=$page&option=view&newsletter_id=$newsletter_list[0]\"><b>$newsletter_list[1]</b></a></td>
               </tr>";        
        }
        
       }     
    } 
    print "</table><p>";
break;
}
?>
