<?php

#############################################################################       
#                              Site@School
# Site@School is a website management system.
# This is a newsletter module which can be used in Site@School.
#
# coded by Fred Stuurman (fc.stuurman@hccnet.nl)
############################################################################
# admin.php: last changed 22/05/2006  , version: 2.4.01                                       
#              by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: admin.php,v 1.1 2006/10/03 10:33:58 fstuurman Exp $
############################################################################
#                        LICENSE INFORMATION
#
# 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 ($_POST[email]))
{
	$email = $_POST[email];
}
if (IsSet ($_POST[sender_email]))
{
	$sender_email = $_POST[sender_email];
}
if (IsSet ($_POST[confirm]))
{
	$confirm = $_POST[confirm];
}
if (IsSet ($_POST[category]))
{
	$category = $_POST[category];
}
if (IsSet ($_POST[group]))
{
	$group = $_POST[group];
}
if (IsSet ($_POST[name]))
{
	$name = $_POST[name];
}
if (IsSet ($_POST[surename]))
{
	$surename = $_POST[surename];
}
if (IsSet ($_POST[remark]))
{
	$remark = $_POST[remark];
}
if (IsSet ($_GET[activate]))
{
	$activate = $_GET[activate];
}
if (IsSet ($_GET[archive]))
{
	$archive = $_GET[archive];
}
if (IsSet ($_POST[filter]))
{
	$filter = $_POST[filter];
}
if (IsSet ($_GET[filter]))
{
	$filter = $_GET[filter];
}
if (IsSet ($_POST[enable]))
{
	$enable = $_POST[enable];
}
if (IsSet ($_POST[date]))
{
	$date = $_POST[date];
}
if (IsSet ($_POST[newsletter_id]))
{
	$newsletter_id = $_POST[newsletter_id];
}
if (IsSet ($_POST[info_field]))
{
	$info_field = $_POST[info_field];
}
if (IsSet ($_POST[contribute]))
{
	$contribute = $_POST[contribute];
}
if (IsSet ($_POST[published]))
{
	$published = $_POST[published];
}
if (IsSet ($_POST[link]))
{
	$link = $_POST[link];
}

if (!get_magic_quotes_gpc())
{
	$content = addslashes($_POST['content']);
	$contribute_text = addslashes($_POST['contribute_text']);
	$contribute_thanks = addslashes($_POST['contribute_thanks']);
	$register_text = addslashes($_POST['register_text']);
	$decline_text = addslashes($_POST['decline_text']);
	$title = addslashes($_POST['title']);
	$footer = addslashes($_POST['footer']);
	$header = addslashes($_POST['header']);
	$title = addslashes($_POST['title']);
	$template = addslashes($_POST['template']);
}
else
{
	$content = $_POST['content'];
	$contribute_text = $_POST['contribute_text'];
	$contribute_thanks = $_POST['contribute_thanks'];
	$register_text = $_POST['register_text'];
	$decline_text = $_POST['decline_text'];
	$title = $_POST['title'];
	$footer = $_POST['footer'];
	$header = $_POST['header'];
	$title = $_POST['title'];
	$template = $_POST['template'];
}

if (IsSet ($_POST[search_arg]))
{
	$search_arg = $_POST[search_arg];
}
if (IsSet ($_POST[format]))
{
	$format = $_POST[format];
}
if (IsSet ($_POST[is_public]))
{
	$is_public = $_POST[is_public];
}
if (IsSet ($_GET[save_newsletter_cat]))
{
	$save_newsletter_cat = $_GET[save_newsletter_cat];
}
if (IsSet ($_GET[save_newsletter_opt]))
{
	$save_newsletter_opt = $_GET[save_newsletter_opt];
}
if (IsSet ($_GET[edit_newsletter_opt]))
{
	$edit_newsletter_opt = $_GET[edit_newsletter_opt];
}
if (IsSet ($_GET[edit_newsletter_cat]))
{
	$edit_newsletter_cat = $_GET[edit_newsletter_cat];
}
if (IsSet ($_GET[edit_newsletter]))
{
	$edit_newsletter = $_GET[edit_newsletter];
}
if (IsSet ($_GET[send_newsletter]))
{
	$send_newsletter = $_GET[send_newsletter];
}
if (IsSet ($_GET[newsletter_id]))
{
	$newsletter_id = $_GET[newsletter_id];
}
if (IsSet ($_GET[test_send]))
{
	$test_send = $_GET[test_send];
}
if (IsSet ($_GET[delete_newsletter]))
{
	$delete_newsletter = $_GET[delete_newsletter];
}
if (IsSet ($_GET[delete_news_letter_cat]))
{
	$delete_news_letter_cat = $_GET[delete_news_letter_cat];
}
if (IsSet ($_GET[newsletter]))
{
	$newsletter = $_GET[newsletter];
}
if (IsSet ($_GET[editcontent]))
{
	$editcontent = $_GET[editcontent];
}
if (IsSet ($_GET[save_content]))
{
	$save_content = $_GET[save_content];
}
if (IsSet ($_GET[edit_user]))
{
	$edit_user = $_GET[edit_user];
}
if (IsSet ($_GET[save_user]))
{
	$save_user = $_GET[save_user];
}
if (IsSet ($_GET[delete_user]))
{
	$delete_user = $_GET[delete_user];
}
if (IsSet ($_GET[modoption]))
{
	$modoption = $_GET[modoption];
}
if (IsSet ($_GET[suboption]))
{
	$suboption = $_GET[suboption];
}
if (IsSet ($_GET[sort]))
{
	$sort = $_GET[sort];
}
else
{
	$sort = "name";
}
if (IsSet ($_GET[p]))
{
	$p = $_GET[p];
}
else
{
	$p = 1;
}
if (IsSet ($_GET[publish]))
{
	$publish = $_GET[publish];
}

load_language('', 'sn_newsletter'); //load language file
?>
<script language="JavaScript" type="text/javascript">
function checkinput ( form )
{  
	if (form.file.value == "")
	{
	alert( "<?php echo $sas_lang['newsletter_module_file_not_blank'] ?>" );
	form.file.focus();
	return false ;
	}
	if (form.format[0].value > 4) 
	{
	alert( "<?php echo $sas_lang['newsletter_module_file_not_blank'] ?>" );
	form.file.focus();
	return false ;
	}
  return true ;
}
</script>
<?php


function showtextintags($text)
{
	$text = preg_replace("/(\<script)(.*?)(script>)/si", "dada", "$text");
	$text = strip_tags($text);
	$text = str_replace("<!--", "&lt;!--", $text);
	$text = preg_replace("/(\<)(.*?)(--\>)/mi", "" . nl2br("\\2") . "", $text);

	return $text;
}

$query = "SELECT name FROM $table_modules WHERE id=$module"; //get module name          
$result = mysql_query($query) or die_script($query, mysql_error());
$modulename = mysql_result($result, 0);
unset ($query);
unset ($result);

$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]";
$table_email_adresses = "$moduletables[2]";

if (IsSet ($save_newsletter_cat))
{
	if ($save_newsletter_cat == "new")
	{
		mysql_query("INSERT INTO $table_newsletters (id, name, title, link, email, confirm, register_text, decline_text, contribute_text, contribute, extra_info, contribute_thanks, public, sender_email)
			VALUES (NULL, '$name', '$title', '$link', '$email', '$confirm', '$register_text', '$decline_text', '$contribute_text', '$contribute', '$info_field', '$contribute_thanks', '$is_public', '$sender_email')");
	}
	else
	{
		mysql_query("UPDATE $table_newsletters SET name='$name' WHERE id='$save_newsletter_cat'");
		mysql_query("UPDATE $table_newsletters SET title='$title' WHERE id='$save_newsletter_cat'");
		mysql_query("UPDATE $table_newsletters SET template='$template' WHERE id='$save_newsletter_cat'");
		mysql_query("UPDATE $table_newsletters SET link='$link' WHERE id='$save_newsletter_cat'");
		mysql_query("UPDATE $table_newsletters SET email='$email' WHERE id='$save_newsletter_cat'");
		mysql_query("UPDATE $table_newsletters SET sender_email='$sender_email' WHERE id='$save_newsletter_cat'");
		mysql_query("UPDATE $table_newsletters SET confirm='$confirm' WHERE id='$save_newsletter_cat'");
		mysql_query("UPDATE $table_newsletters SET register_text='$register_text' WHERE id='$save_newsletter_cat'");
		mysql_query("UPDATE $table_newsletters SET decline_text='$decline_text' WHERE id='$save_newsletter_cat'");
		mysql_query("UPDATE $table_newsletters SET contribute_text='$contribute_text' WHERE id='$save_newsletter_cat'");
		mysql_query("UPDATE $table_newsletters SET contribute='$contribute' WHERE id='$save_newsletter_cat'");
		mysql_query("UPDATE $table_newsletters SET contribute_thanks='$contribute_thanks' WHERE id='$save_newsletter_cat'");
		mysql_query("UPDATE $table_newsletters SET extra_info='$info_field' WHERE id='$save_newsletter_cat'");
		mysql_query("UPDATE $table_newsletters SET public='$is_public' WHERE id='$save_newsletter_cat'");
		mysql_query("UPDATE $table_newsletter_content SET public='$is_public' WHERE newsletter_id='$save_newsletter_cat'");

	}
}

$query = "SELECT email FROM $table_users WHERE id=$userid"; //get the email of the userid logged in         
$result = mysql_query($query) or die_script($query, mysql_error());
$owner_email = mysql_result($result, 0);
unset ($query);
unset ($result);

$query = "SELECT config_value FROM $table_configuration WHERE config_key='newsletter_admin_email'";
$result = mysql_query($query) or die_script($query, mysql_error());
$admin_email = mysql_result($result, 0);
unset ($query);
unset ($result);

//print "Owner email: ".$owner_email." admin email: ".$admin_email ;

if ($admin_email != $owner_email)
{
	$query = "SELECT id FROM $table_newsletters WHERE email LIKE '%$owner_email%'"; // getting the newsletter id of the user logged in
}
else
{
	$query = "SELECT id FROM $table_newsletters";
	$user_type = "admin";
}

$result = mysql_query($query) or die_script($query, mysql_error());
$i = 0;
while ($row = mysql_fetch_array($result)) //array with newsletter ids which
{
	$letter_ids[$i] = $row[0]; //the user is responsible for.
	$i++;
}
unset ($query);
unset ($result);

if (IsSet ($edit_newsletter))
{
	$query = "SELECT content, title FROM $table_newsletter_content WHERE id = '$edit_newsletter'"; // getting the newsletter content
	$result = mysql_query($query) or die_script($query, mysql_error());
	$content = mysql_result($result, 0, 0);
	$title = mysql_result($result, 0, 1);
	unset ($query);
	unset ($result);

	$query = "SELECT location FROM $table_editors WHERE id = '$editor'"; // getting the editors location
	$result = mysql_query($query) or die_script($query, mysql_error());
	$editor_loc = mysql_result($result, 0);
	unset ($query);
	unset ($result);
	if ($editor_loc == "htmlarea/editor.php")
	{
		//Xinha editor
		include ("modules/sn_newsletter/edit_content2.php");
	}
	else
	{
		//FCK editor
		include ("modules/sn_newsletter/edit_content.php");
	}

	include ("interface/pageend.inc.php");
	include ("interface/footer.inc.php");
	exit;
}

if (IsSet ($delete_newsletter))
{
	mysql_query("DELETE FROM $table_newsletter_content WHERE id = '$delete_newsletter'");
}

if (IsSet ($publish))
{
	mysql_query("UPDATE $table_newsletter_content SET published='$publish' WHERE id='$newsletter_id'");
	$query = "SELECT newsletter_id FROM $table_newsletter_content WHERE id ='$newsletter_id'";
	$result = mysql_query($query) or die_script($query, mysql_error());
	$newsletter_id = mysql_result($result, 0, 0);
	$query = "SELECT name FROM $table_newsletters WHERE id ='$newsletter_id'"; //get the title of the newsletter 
	$result = mysql_query($query) or die_script($query, mysql_error()); //use it to find the page on the site
	$page_name = mysql_result($result, 0, 0);
	$date1 = date("Y-m-d H:i:s"); //todays date
	mysql_query("UPDATE $table_pages SET lastupdate = '$date1' WHERE module = 'sn_newsletter/newsletter.php' AND name = '$page_name' ");
} //update the last changed date.

if (IsSet ($archive))
{
	mysql_query("UPDATE $table_newsletter_content SET archive='$archive' WHERE id='$newsletter_id'");
}

if (IsSet ($activate))
{
	mysql_query("UPDATE $table_email_adresses SET enable='2' WHERE email='$activate'");
}

if (IsSet ($delete_news_letter_cat))
{
	mysql_query("DELETE FROM $table_newsletter_content WHERE newsletter_id = '$delete_news_letter_cat'");
	mysql_query("DELETE FROM $table_newsletters WHERE id = '$delete_news_letter_cat'");
}

if (IsSet ($delete_user))
{
	mysql_query("DELETE FROM $table_email_adresses WHERE id = '$delete_user'");
}

if (IsSet ($save_user))
{
	if ($save_user == "new")
	{
		$query = "SELECT newsletter_id FROM $table_email_adresses WHERE email = '$email'"; // check email address
		$result = mysql_query($query) or die_script($query, mysql_error());
		$RecordCount = mysql_num_rows($result);
		if ($RecordCount == 0)
		{
			$date1 = date('Y-m-d');
			$code = random_code(12);
			mysql_query("INSERT INTO $table_email_adresses (id, surename, name, email, remarks, newsletter_id, enable, date, code)
					VALUES (NULL, '$surename', '$name', '$email', '$remark', '$newsletter_id', '$enable', '$date1', '$code')");
		}
		else
		{
			print "<span class=\"error\">" . $sas_lang['newsletter_module_email_exists'] . "<br><br></span>"; //email already exists  
		}
	}
	else
	{
		mysql_query("UPDATE $table_email_adresses SET email='$email' WHERE id='$save_user'");
		mysql_query("UPDATE $table_email_adresses SET surename='$surename' WHERE id='$save_user'");
		mysql_query("UPDATE $table_email_adresses SET name='$name' WHERE id='$save_user'");
		mysql_query("UPDATE $table_email_adresses SET remarks='$remark' WHERE id='$save_user'");
		mysql_query("UPDATE $table_email_adresses SET newsletter_id='$newsletter_id' WHERE id='$save_user'");
		mysql_query("UPDATE $table_email_adresses SET enable='$enable' WHERE id='$save_user'");
	}
}

if (IsSet ($save_newsletter_opt))
{
	if ($save_newsletter_opt == "new")
	{
		$query = "SELECT template FROM $table_newsletters WHERE id = '$newsletter'"; // getting the newsletter content
		$result = mysql_query($query) or die_script($query, mysql_error());
		$content = mysql_result($result, 0, 0); //get template content

		$date1 = date('Y-m-d');
		mysql_query("INSERT INTO $table_newsletter_content (id, title, archive, published, newsletter_id, date, header, footer, content)
			VALUES (NULL, '$title', '$archive', '$published', '$newsletter', '$date1', '$header', '$footer', '$content')");
	}
	else
	{
		mysql_query("UPDATE $table_newsletter_content SET title='$title' WHERE id='$save_newsletter_opt'");
		mysql_query("UPDATE $table_newsletter_content SET header='$header' WHERE id='$save_newsletter_opt'");
		mysql_query("UPDATE $table_newsletter_content SET footer='$footer' WHERE id='$save_newsletter_opt'");
		mysql_query("UPDATE $table_newsletter_content SET date='$date' WHERE id='$save_newsletter_opt'");
	}
}

if (IsSet ($save_content))
{
	mysql_query("UPDATE $table_newsletter_content SET content='$content' WHERE id='$save_content'");
}

include ("interface/header.inc.php");
include ("interface/menubar.inc.php");
include ("interface/menustart.inc.php");
print "<span class=heading>" . $sas_lang['filemanager_menu'] . "</span><br><br>";
print "<span class=link><a href=index.php?option=modulemanager&module=$module>" . $sas_lang['newsletter_module_newsletters'] . "</a></span><p>";
print "<span class=link><a href=index.php?option=modulemanager&module=$module&modoption=archive>" . $sas_lang['newsletter_module_archive'] . "</a></span><br>";
print "<p><br><span class=link><a href=index.php?option=modulemanager&module=$module&modoption=users>" . $sas_lang['newsletter_module_subscribers'] . "</a></span><br>";
print "<br><span class=link><a href=index.php?option=modulemanager&module=$module&modoption=users&suboption=not_active>" . $sas_lang['newsletter_module_new_subscribers'] . "</a></span><br>";
print "<br><span class=link><a href=index.php?option=modulemanager&module=$module&modoption=search>" . $sas_lang['newsletter_module_search'] . "</a></span><br>";

if ($user_type == "admin")
{
	print "<br><span class=link><a href=index.php?option=modulemanager&module=$module&modoption=import>" . $sas_lang['newsletter_module_import'] . "</a></span><br>";
	print "<br><span class=link><a href=index.php?option=modulemanager&module=$module&modoption=config>" . $sas_lang['newsletter_module_config'] . "</a></span><br>";
}

include ("interface/menuend.inc.php");
include ("interface/pagestart.inc.php");
print "<span class=\"heading\">$modulename<p></span>";
if ((count($letter_ids) == 0) and ($user_type != "admin"))
{
	print "<span class=\"error\">" . $sas_lang['newsletter_module_email_no_access'] . "</span>";
	exit;
}

if (IsSet ($send_newsletter))
{

	$query = "SELECT newsletter_id, content, sent, header, footer, title FROM $table_newsletter_content WHERE id ='$send_newsletter'";
	$result = mysql_query($query) or die_script($query, mysql_error());
	$newsletter_id = mysql_result($result, 0, 0);
	$content = mysql_result($result, 0, 1);
	$sent = mysql_result($result, 0, 2);
	$header = mysql_result($result, 0, 3);
	$footer = mysql_result($result, 0, 4);
	$title = showtextintags(mysql_result($result, 0, 5));
	unset ($query);
	unset ($result);
	$query = "SELECT link, email, name, public, sender_email FROM $table_newsletters WHERE id ='$newsletter_id'";
	$result = mysql_query($query) or die_script($query, mysql_error());
	$send_link = mysql_result($result, 0, 0);
	$owner_email = mysql_result($result, 0, 1);
	$newsletter_name = mysql_result($result, 0, 2);
	$newsletter_public = mysql_result($result, 0, 3);
	$sender_email = mysql_result($result, 0, 4);
	unset ($query);
	unset ($result);
	if ($send_link == 1) //send content or link
	{
		if ($newsletter_public == 1)
		{
			$table_pages = $dbprefix . "prot_pages";
		}
		$query = "SELECT id, section FROM $table_pages WHERE name ='$newsletter_name'";
		$result = mysql_query($query) or die_script($query, mysql_error());
		$RecordCount = mysql_num_rows($result);
		if ($RecordCount == 0)
		{
			print "<span class=\"error\">" . $sas_lang['newsletter_module_email_no_linkpage'] . "</span>";
			print "<p><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sas_lang[goback]\" name=\"backbutton\" 
							onClick=\"javascript:history.go(-1)\" class=\"backbutton\">";
			exit;
		}
		$page = mysql_result($result, 0, 0);
		$section = mysql_result($result, 0, 1);
		unset ($query);
		unset ($result);
		$content = str_replace("%newsletter_name%", $newsletter_name, $sas_lang['newsletter_module_link_intro']);
		$content .= "<br><a href=$site_url/index.php?section=$section&page=$page&option=view&newsletter_id=$send_newsletter>" .
		$sas_lang['newsletter_module_click_here'] . "</a>";
	}
	else
	{
		$content = $header . $content . $footer;
	}
	$content = str_replace("<br />", "<br />\n", $content); //add line breaks
	if ($test_send == "yes") //send a newsletter to owner as test
	{
		if ($owner_email != "")
		{
			$mail_list[0] = $owner_email; //just 1 email, from the owner
			require ("core/class.phpmailer.php"); //use the phpmailer class
			include ("modules/sn_newsletter/mail_function2.php"); //call the mail function
			newsletter_mail($mail_list, $content, $sender_email, $newsletter_name . " : " . $title . " : " . $sitename);
			print "<span class=\"text\"><b>" . $sas_lang['newsletter_module_send_email_owner'] . "</b></span><p>";
		}
	}
	else
	{
		$query = "SELECT email, name, remarks FROM $table_email_adresses WHERE newsletter_id LIKE '%$newsletter_id%' AND enable = '2'";
		$result = mysql_query($query) or die_script($query, mysql_error());
		print "<span class=\"link\"><b>Sending emails:</b></span><br><br>";

		$i = 0;
		while ($email_list = mysql_fetch_array($result)) //fill the email list array
		{
			$mail_list[$i] = $email_list[0];
			$i++;
		}
		require ("core/class.phpmailer.php"); //use the phpmailer class
		include ("modules/sn_newsletter/mail_function2.php"); //call the mail function
		$number = newsletter_mail($mail_list, $content, $sender_email, $newsletter_name . " : " . $title . " : " . $sitename);
		mysql_query("UPDATE $table_newsletter_content SET sent='1' WHERE id='$send_newsletter'");
		print "<span class=text>" . $sas_lang['newsletter_module_send_email_result'] . $number . "</span><p>";
	}

	print "\n<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;$sas_lang[goback]\" name=\"backbutton\" 
			onClick=\"parent.location='index.php?option=modulemanager&module=$module&newsletter=$newsletter_id';\" class=\"backbutton\">";

	exit;
}

if (IsSet ($edit_user))
{
	$query = "SELECT id, email, remarks, newsletter_id, date, enable, name, surename FROM $table_email_adresses WHERE id=$edit_user";
	$result = mysql_query($query) or die_script($query, mysql_error());
	$users_list = mysql_fetch_array($result);
	$query1 = "SELECT id, name FROM $table_newsletters ORDER BY id";
	$result1 = mysql_query($query1) or die_script($query1, mysql_error());

	print "<span class=\"link\"><b>" . $sas_lang['newsletter_module_email_change'] . ":</b></span><br><br>";
	print "<FORM METHOD=\"POST\" NAME=\"form\" ACTION=\"index.php?option=modulemanager&module=$module&modoption=$modoption&suboption=$suboption&save_user=$edit_user&p=$p&filter=$filter\">
	         <table border=\"0\" cellpadding=\"5\">";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_email'] . " (*):</span></td>
	         <td><input type=\"text\" name=\"email\" size=\"40\" value=\"$users_list[1]\" class=\"textfield\"></td>
	         <td rowspan=\"5\" valign=\"top\"><span class=text>";
	while ($letters_list = mysql_fetch_array($result1))
	{
		if (array_search($letters_list[0], $letter_ids) !== FALSE)
		{
			print "<b>" . $letters_list[0] . "</b>: " . $letters_list[1] . "<br>";
		}
	}
	print "</span></td>
	         </tr>
	         <tr><td><span class=text>" . $sas_lang['newsletter_module_surename'] . " :</span></td>
	         <td><input type=\"text\" name=\"surename\" size=\"40\" value=\"$users_list[7]\" class=\"textfield\"></td></tr>
	         <tr><td><span class=text>" . $sas_lang['newsletter_module_name'] . " :</span></td>
	         <td><input type=\"text\" name=\"name\" size=\"40\" value=\"$users_list[6]\" class=\"textfield\"></td></tr>
	         <tr><td><span class=text>" . $sas_lang['newsletter_module_info'] . " :</span></td>
	         <td><input type=\"text\" name=\"remark\" size=\"40\" value=\"$users_list[2]\" class=\"textfield\"></td></tr>";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_newsletter_id'] . " :</span></td>
	         <td><input type=\"text\" name=\"newsletter_id\" size=\"20\" value=\"$users_list[3]\" class=\"textfield\"></td></tr>";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_enabled'] . " :</span></td>";
	print "<td><span class=text>" . $sas_lang['yes'] . "</span>";
	if ($users_list[5] == 2)
	{
		print "<input type=\"radio\" value=\"2\" name=\"enable\" checked>";
		print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
		print "<input type=\"radio\" name=\"enable\" value=\"1\"></td>";
	}
	else
	{
		print "<input type=\"radio\" value=\"2\" name=\"enable\">";
		print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
		print "<input type=\"radio\" name=\"enable\" value=\"1\" checked></td>";
	}
	print "</tr>";

	print "</table>";
	print "\n<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sas_lang[goback]\" name=\"backbutton\" onClick=\"javascript:history.go(-1)\" class=\"backbutton\">";
	print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;$sas_lang[save]\" name=\"savebutton\" class=\"savebutton\">";
	print "</form>";
	exit;
}

if (isset ($edit_newsletter_cat))
{
	$query = "SELECT id, name, title, link, email, confirm, register_text, decline_text, contribute_text, 
				contribute, extra_info, contribute_thanks, public, template, sender_email 
				FROM $table_newsletters WHERE id=$edit_newsletter_cat";
	$result = mysql_query($query) or die_script($query, mysql_error());
	$editnewsletter_list = mysql_fetch_array($result);
	print "<FORM METHOD=\"POST\" NAME=\"form\" ACTION=\"index.php?option=modulemanager&module=$module&save_newsletter_cat=$editnewsletter_list[0]\">
	         <table border=\"0\" cellpadding=\"5\">";
	print "<tr><td><span class=\"link\"><b>" . $sas_lang['newsletter_module_newsletter_change'] . " :</b></td><td><span class=\"text\">" .
	$sas_lang['required_fields'] . "</span></td></tr>";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_pagename'] . " (*):</span></td>
	         <td><input type=\"text\" name=\"name\" size=\"40\" value=\"$editnewsletter_list[1]\" class=\"textfield\"></td></tr>";
	print "<tr><td valign=\"top\"><span class=text>" . $sas_lang['newsletter_module_title'] . " (*) :</span></td>
	         <td><textarea name=\"title\" ROWS=4 COLS=60>$editnewsletter_list[2]</textarea></td></tr>";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_email_sender'] . ":</span></td>
	         <td><input type=\"text\" name=\"sender_email\" size=\"60\" value=\"$editnewsletter_list[14]\" class=\"textfield\"></td></tr>";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_email_owner'] . ":</span></td>
	         <td><input type=\"text\" name=\"email\" size=\"60\" value=\"$editnewsletter_list[4]\" class=\"textfield\"></td></tr>";
	print "<tr><td valign=\"top\"><span class=text>" . $sas_lang['newsletter_module_welcome_subscribe'] . ":</span></td>
	         <td><textarea name=\"register_text\" ROWS=4 COLS=60>$editnewsletter_list[6]</textarea></td></tr>";
	print "<tr><td valign=\"top\"><span class=text>" . $sas_lang['newsletter_module_welcome_unsubscribe'] . ":</span></td>
	         <td><textarea name=\"decline_text\" ROWS=4 COLS=60>$editnewsletter_list[7]</textarea></td></tr>";
	print "<tr><td valign=\"top\"><span class=text>" . $sas_lang['newsletter_module_welcome_contribute'] . ":</span></td>
	         <td><textarea name=\"contribute_text\" ROWS=4 COLS=60>$editnewsletter_list[8]</textarea></td></tr>";
	print "<tr><td valign=\"top\"><span class=text>" . $sas_lang['newsletter_module_contribute_thanks'] . ":</span></td>
	         <td><textarea name=\"contribute_thanks\" ROWS=4 COLS=60>$editnewsletter_list[11]</textarea></td></tr>";
	print "<tr><td valign=\"top\"><span class=text>" . $sas_lang['newsletter_module_template'] . ":</span></td>
	         <td><textarea name=\"template\" ROWS=4 COLS=60>$editnewsletter_list[13]</textarea></td></tr>";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_info'] . " :</span></td>
	         <td><input type=\"text\" name=\"info_field\" size=\"40\" value=\"$editnewsletter_list[10]\" class=\"textfield\"></td></tr>";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_send_link'] . " :</span></td>";
	print "<td><span class=text>" . $sas_lang['yes'] . "</span>";
	if ($editnewsletter_list[3] == 1)
	{
		print "<input type=\"radio\" value=\"1\" name=\"link\" checked>";
		print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
		print "<input type=\"radio\" name=\"link\" value=\"0\"></td>";
	}
	else
	{
		print "<input type=\"radio\" value=\"1\" name=\"link\">";
		print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
		print "<input type=\"radio\" name=\"link\" value=\"0\" checked></td>";
	}
	print "</tr>";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_confirm_subscription'] . " :</span></td>";
	print "<td><span class=text>" . $sas_lang['yes'] . "</span>";
	if ($editnewsletter_list[5] == 1)
	{
		print "<input type=\"radio\" value=\"1\" name=\"confirm\" checked>";
		print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
		print "<input type=\"radio\" name=\"confirm\" value=\"0\"></td>";
	}
	else
	{
		print "<input type=\"radio\" value=\"1\" name=\"confirm\">";
		print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
		print "<input type=\"radio\" name=\"confirm\" value=\"0\" checked></td>";
	}
	print "</tr>";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_show_button'] . " :</span></td>";
	print "<td><span class=text>" . $sas_lang['yes'] . "</span>";
	if ($editnewsletter_list[9] == 1)
	{
		print "<input type=\"radio\" value=\"1\" name=\"contribute\" checked>";
		print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
		print "<input type=\"radio\" name=\"contribute\" value=\"0\"></td></tr>";
	}
	else
	{
		print "<input type=\"radio\" value=\"1\" name=\"contribute\">";
		print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
		print "<input type=\"radio\" name=\"contribute\" value=\"0\" checked></td></tr>";
	}

	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_is_public'] . " :</span></td>";
	print "<td><span class=text>" . $sas_lang['yes'] . "</span>";
	if ($editnewsletter_list[12] == 1)
	{
		print "<input type=\"radio\" value=\"1\" name=\"is_public\" checked>";
		print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
		print "<input type=\"radio\" name=\"is_public\" value=\"0\"></td></tr>";
	}
	else
	{
		print "<input type=\"radio\" value=\"1\" name=\"is_public\">";
		print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
		print "<input type=\"radio\" name=\"is_public\" value=\"0\" checked></td></tr>";
	}

	print "</table>";
	print "\n<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sas_lang[goback]\" name=\"backbutton\" 
			onClick=\"javascript:history.go(-1)\" class=\"backbutton\">";
	print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;$sas_lang[save]\" name=\"savebutton\" class=\"savebutton\">";
	print "</form>";
	exit;
}

if (isset ($edit_newsletter_opt))
{
	$query = "SELECT id, title, archive, published, newsletter_id, header, footer, UNIX_TIMESTAMP(date) FROM $table_newsletter_content WHERE id=$edit_newsletter_opt";
	$result = mysql_query($query) or die_script($query, mysql_error());
	$editnewsletter_list = mysql_fetch_array($result);
	print "<span class=\"link\"><b>" . $sas_lang['newsletter_module_newsletter_change'] . " :</b></span><br><br>";
	print "<FORM METHOD=\"POST\" NAME=\"form\" ACTION=\"index.php?option=modulemanager&module=$module&save_newsletter_opt=$editnewsletter_list[0]&newsletter=$editnewsletter_list[4]\">
		 <table border=\"0\" cellpadding=\"5\">";
	$date = strftime('%Y-%m-%d', $editnewsletter_list[7]);
	print "<tr><td valign=\"top\"><span class=text>" . $sas_lang['date'] . " (*):</span></td>
		 <td><input type=\"text\" name=\"date\" size=\"10\" value=\"$date\" class=\"textfield\">
		 <span class=text>&nbsp;&nbsp;<b>YYYY-MM-DD</b></span></td></tr>";
	print "<tr><td valign=\"top\"><span class=text>" . $sas_lang['newsletter_module_issue'] . " (*):</span></td>
		 <td><textarea name=\"title\" ROWS=4 COLS=60>$editnewsletter_list[1]</textarea></td></tr>";
	print "<tr><td valign=\"top\"><span class=text>" . $sas_lang['newsletter_module_header'] . " :</span></td>
		 <td><textarea name=\"header\" ROWS=6 COLS=60>$editnewsletter_list[5]</textarea></td></tr>";
	print "<tr><td valign=\"top\"><span class=text>" . $sas_lang['newsletter_module_footer'] . " :</span></td>
		 <td><textarea name=\"footer\" ROWS=6 COLS=60>$editnewsletter_list[6]</textarea></td></tr>";
	print "<td>&nbsp;</td><td><span class=\"text\">" . $sas_lang['required_fields'] . "</span></td></tr>";
	print "</table>";

	print "\n<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sas_lang[goback]\" name=\"backbutton\" 
			onClick=\"javascript:history.go(-1)\" class=\"backbutton\">";
	print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;$sas_lang[save]\" name=\"savebutton\" class=\"savebutton\">";
	print "</form>";
	exit;
}

if ($modoption == "saveconfig")
{
	$query = "SELECT id FROM $table_users WHERE email='$email'";
	$result = mysql_query($query) or die_script($query, mysql_error());
	$RecordCount = mysql_num_rows($result);
	//print "recordcount $RecordCount Query: $query <br>";
	if (($RecordCount > 0) and (trim($email) != ""))
	{
		mysql_query("UPDATE $table_configuration SET config_value='$email' WHERE config_key='newsletter_admin_email'");
	}
	else
	{
		print "<span class=\"error\">" . $sas_lang['newsletter_module_email_no_admin'] . "</span>";
		print "<p><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sas_lang[goback]\" name=\"backbutton\" 
				onClick=\"javascript:history.go(-1)\" class=\"backbutton\">";
		exit;
	}
}

if ($modoption == "config")
{
	$query = "SELECT config_value FROM $table_configuration WHERE config_key='newsletter_admin_email'";
	$result = mysql_query($query) or die_script($query, mysql_error());
	$admin_email = mysql_result($result, 0);
	unset ($query);
	unset ($result);
	print "<span class=\"link\"><b>" . $sas_lang['newsletter_module_config'] . ":</b></span><br><br>";
	print "<FORM METHOD=\"POST\" NAME=\"form\" ACTION=\"index.php?option=modulemanager&module=$module&modoption=saveconfig\">
	         <table border=\"0\" cellpadding=\"5\">";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_email_admin'] . ":</span></td>
	         <td><input type=\"text\" name=\"email\" size=\"60\" value=\"$admin_email\" class=\"textfield\"></td></tr>";
	print "</table>";
	print "<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sas_lang[goback]\" name=\"backbutton\" 
			onClick=\"javascript:history.go(-1)\" class=\"backbutton\">";
	print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;$sas_lang[save]\" name=\"savebutton\" class=\"savebutton\">";
	print "</form>";
	exit;
}

if ($modoption == "new_newsletter_cat")
{
	print "<span class=\"link\"><b>" . $sas_lang['newsletter_module_new_category'] . ":</b></span><br><br>";
	print "<FORM METHOD=\"POST\" NAME=\"form\" ACTION=\"index.php?option=modulemanager&module=$module&save_newsletter_cat=new\">
	         <table border=\"0\" cellpadding=\"5\">";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_pagename'] . " (*):</span></td>
	         <td><input type=\"text\" name=\"name\" size=\"40\"  class=\"textfield\"></td></tr>";
	print "<tr><td valign=\"top\"><span class=text>" . $sas_lang['newsletter_module_title'] . "(*) :</span></td>
	         <td><textarea name=\"title\" ROWS=4 COLS=60></textarea></td></tr>";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_email_sender'] . ":</span></td>
	         <td><input type=\"text\" name=\"sender_email\" size=\"60\" class=\"textfield\"></td></tr>";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_email_owner'] . ":</span></td>
	         <td><input type=\"text\" name=\"email\" size=\"60\" class=\"textfield\"></td></tr>";
	print "<tr><td valign=\"top\"><span class=text>" . $sas_lang['newsletter_module_welcome_subscribe'] . ":</span></td>
	         <td><textarea name=\"register_text\" ROWS=4 COLS=60></textarea></td></tr>";
	print "<tr><td valign=\"top\"><span class=text>" . $sas_lang['newsletter_module_welcome_unsubscribe'] . ":</span></td>
	         <td><textarea name=\"decline_text\" ROWS=4 COLS=60></textarea></td></tr>";
	print "<tr><td valign=\"top\"><span class=text>" . $sas_lang['newsletter_module_welcome_contribute'] . ":</span></td>
	         <td><textarea name=\"contribute_text\" ROWS=4 COLS=60></textarea></td></tr>";
	print "<tr><td valign=\"top\"><span class=text>" . $sas_lang['newsletter_module_contribute_thanks'] . ":</span></td>
	         <td><textarea name=\"contribute_thanks\" ROWS=4 COLS=60></textarea></td></tr>";
	print "<tr><td valign=\"top\"><span class=text>" . $sas_lang['newsletter_module_template'] . ":</span></td>
	         <td><textarea name=\"template\" ROWS=4 COLS=60></textarea></td></tr>";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_info'] . " :</span></td>
	         <td><input type=\"text\" name=\"info_field\" size=\"40\" class=\"textfield\"></td></tr>";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_send_link'] . " :</span></td>";
	print "<td><span class=text>" . $sas_lang['yes'] . "</span>";
	print "<input type=\"radio\" value=\"1\" name=\"link\">";
	print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
	print "<input type=\"radio\" name=\"link\" value=\"0\" checked></td>";

	print "</tr>";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_confirm_subscription'] . " :</span></td>";
	print "<td><span class=text>" . $sas_lang['yes'] . "</span>";
	print "<input type=\"radio\" value=\"1\" name=\"confirm\" checked>";
	print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
	print "<input type=\"radio\" name=\"confirm\" value=\"0\"></td>";
	print "</tr>";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_show_button'] . " :</span></td>";
	print "<td><span class=text>" . $sas_lang['yes'] . "</span>";
	print "<input type=\"radio\" value=\"1\" name=\"contribute\">";
	print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
	print "<input type=\"radio\" name=\"contribute\" value=\"0\" checked></td>";
	print "</tr>";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_is_public'] . " :</span></td>";
	print "<td><span class=text>" . $sas_lang['yes'] . "</span>";
	print "<input type=\"radio\" value=\"1\" name=\"is_public\">";
	print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
	print "<input type=\"radio\" name=\"is_public\" value=\"0\" checked></td>";
	print "</tr>";
	print "</table>";
	print "\n<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sas_lang[goback]\" name=\"backbutton\" 
			onClick=\"javascript:history.go(-1)\" class=\"backbutton\">";
	print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;$sas_lang[save]\" name=\"savebutton\" class=\"savebutton\">";
	print "</form>";
	exit;
}

if ($modoption == "new_newsletter")
{
	$query = "SELECT header, footer, title FROM $table_newsletter_content WHERE newsletter_id='$newsletter' ORDER BY date DESC";
	$result = mysql_query($query) or die_script($query, mysql_error());
	$RecordCount = mysql_num_rows($result);
	if ($RecordCount > 0)
	{
		$header = mysql_result($result, 0, 0);
		$footer = mysql_result($result, 0, 1);
		$title = mysql_result($result, 0, 2);
	}
	print "<span class=link>" . $sas_lang['newsletter_module_newsletter_add'] . "</span>";
	print "<FORM METHOD=\"POST\" NAME=\"form\" ACTION=\"index.php?option=modulemanager&module=$module&newsletter=$newsletter&save_newsletter_opt=new\">
	       <table border=\"0\" cellpadding=\"5\">";
	print "<tr><td valign=\"top\"><span class=text>" . $sas_lang['newsletter_module_issue'] . " (*):</span></td>
	       <td><textarea name=\"title\" ROWS=4 COLS=60>$title</textarea></td></tr>";
	print "<tr><td valign=\"top\"><span class=text>" . $sas_lang['newsletter_module_header'] . " :</span></td>
	       <td><textarea name=\"header\" ROWS=6 COLS=60>$header</textarea></td></tr>";
	print "<tr><td valign=\"top\"><span class=text>" . $sas_lang['newsletter_module_footer'] . " :</span></td>
	       <td><textarea name=\"footer\" ROWS=6 COLS=60>$footer</textarea></td></tr>";
	print "</table>";
	print "<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sas_lang[goback]\" name=\"backbutton\" 
			onClick=\"javascript:history.go(-1)\" class=\"backbutton\">";
	print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;$sas_lang[save]\" name=\"savebutton\" class=\"savebutton\">";
	print "</form>";
	exit;
}

if ($modoption == "upload")
{
	$date1 = date('Y-m-d');

	if ($suboption == "group")
	{
		//select pupils with email adresses filled  in.
		$query3 = "SELECT name, email FROM $table_users WHERE class = '$group' AND email !='' ";
		$result3 = mysql_query($query3) or die_script($query, mysql_error());
		$number = 0;

		while ($pupil_list = mysql_fetch_array($result3))
		{

			$query2 = "SELECT newsletter_id FROM $table_email_adresses WHERE email = '$pupil_list[1]'"; // check email address
			$result2 = mysql_query($query2) or die_script($query2, mysql_error());
			$RecordCount = mysql_num_rows($result2);
			if ($RecordCount == 0)
			{
				mysql_query("INSERT INTO $table_email_adresses (id, surename, name, email, remarks, newsletter_id, enable, date, code)
							VALUES (NULL, '', '$pupil_list[0]', '$pupil_list[1]', '', '$category', '2', '$date1', '')");
			}
			else
			{ //email already exists 
				$newsletter_id_old = mysql_result($result2, 0);
				$newsletter_id_old = explode(",", $newsletter_id_old);
				$result = array_search($category, $newsletter_id_old); //does id exists

				if ($result === FALSE)
				{
					array_push($newsletter_id_old, $category); //if not add it
					sort($newsletter_id_old);
					$newsletter_id_new = implode(",", $newsletter_id_old); //create comma delimited string 
					mysql_query("UPDATE $table_email_adresses SET newsletter_id='$newsletter_id_new' WHERE email = '$email$pupil_list[1]'");
				}
			}
			$number++;
		}
	}
	else
	{
		if (IsSet ($_FILES["file"]["name"]))
		{
			$temp = $_FILES["file"]["tmp_name"];
		}

		$handle = fopen($temp, "r");
		$number = 0;

		while ($data = fgetcsv($handle, 1000, ",")) //read uploaded CSV file
		{
			if ($format[0] != "")
			{
				$surname = $data[$format[0] - 1];
			}
			if ($format[1] != "")
			{
				$name = $data[$format[1] - 1];
			}
			if ($format[2] != "")
			{
				$email = $data[$format[2] - 1];
			}
			if ($format[3] != "")
			{
				$remarks = $data[$format[3] - 1];
			}
			// print $surname."<br>";
			// print $name."<br>";
			// print $email."<br>";
			// print $remarks."<br>";
			if ($email != "")
			{
				$query = "SELECT newsletter_id FROM $table_email_adresses WHERE email = '$email'"; // check email address
				$result = mysql_query($query) or die_script($query, mysql_error());
				$RecordCount = mysql_num_rows($result);
				if ($RecordCount == 0)
				{
					mysql_query("INSERT INTO $table_email_adresses (id, surename, name, email, remarks, newsletter_id, enable, date, code)
									VALUES (NULL, '$surname', '$name', '$email', '$remarks', '$category', '2', '$date1', '')");
				}
				else
				{ //email already exists 
					$newsletter_id_old = mysql_result($result, 0);
					$newsletter_id_old = explode(",", $newsletter_id_old);
					$result = array_search($category, $newsletter_id_old); //does id exists

					if ($result === FALSE)
					{
						array_push($newsletter_id_old, $category); //if not add it
						sort($newsletter_id_old);
						$newsletter_id_new = implode(",", $newsletter_id_old); //create comma delimited string 
						mysql_query("UPDATE $table_email_adresses SET newsletter_id='$newsletter_id_new' WHERE email = '$email'");
					}
				}
			}
			else
			{
				$number--;
			}
			$number++;
		}
		fclose($handle);
	}

	print "<span class=text>" . $number . " " . $sas_lang['newsletter_module_import_result'] . "</span>";
	print "<p><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sas_lang[goback]\" name=\"backbutton\" 
			onClick=\"javascript:history.go(-1)\" class=\"backbutton\">";

	exit;
}

if ($modoption == "import")
{
	$query = "SELECT id, name FROM $table_newsletters";
	$result1 = mysql_query($query);
	unset ($query);
	unset ($result);

	print "<span class=text><b>" . $sas_lang['newsletter_module_import_intro'] . "</b></span><p>";
	print "<form method=post enctype=\"multipart/form-data\" action=index.php?option=modulemanager&module=$module&modoption=upload&suboption=file 
			onsubmit=\"return checkinput(this);\">";

	print "<table><tr><td><span class=text><b>" . $sas_lang['newsletter_module_value'] . ":</b></span></td>\n
	<td><span class=text><b>" . $sas_lang['newsletter_module_order'] . ":</b></span></td></tr>\n
	       <tr><td><span class=text><b>" . $sas_lang['newsletter_module_surename'] . ":</b></span></td>\n
		   <td align=\"right\"><input name=\"format[0]\" size=\"1\"></td></tr>\n
	       <tr><td><span class=text><b>" . $sas_lang['newsletter_module_name'] . ":</b></span></td>\n
		   <td align=\"right\"><input name=\"format[1]\" size=\"1\"></td></tr>\n
	       <tr><td><span class=text><b>" . $sas_lang['newsletter_module_email'] . ":</b></span></td>\n
		   <td align=\"right\"><input name=\"format[2]\" size=\"1\"></td></tr>\n
	       <tr><td><span class=text><b>" . $sas_lang['newsletter_module_info'] . ":</b></span></td>\n
		   <td align=\"right\"><input name=\"format[3]\" size=\"1\"></td></tr>\n";
	print "</table><br>\n";
	print "<span class=text>" . $sas_lang['newsletter_module_newsletter'] . ": </span><select size=\"1\" name=\"category\">\n";
	while ($category_list = mysql_fetch_array($result1))
	{
		print "<option value=\"$category_list[0]\">$category_list[1]</option>";
	}
	print "</select>";
	print "<p><span class=text>" . $sas_lang['file'] . "</span>&nbsp;<input type=file name=file size=40 class=textfield>\n";
	print "&nbsp;<input type=submit value=&nbsp;&nbsp;&nbsp;" . $sas_lang['send'] . " name=B1 class=savebutton></form><hr>";

	$query = "SELECT id, name FROM $table_newsletters";
	$result1 = mysql_query($query);
	unset ($query);
	unset ($result);

	print "<span class=text><b>" . $sas_lang['newsletter_module_import_intro2'] . "</b></span><p>";
	print "<form method=post enctype=\"multipart/form-data\" action=index.php?option=modulemanager&module=$module&modoption=upload&suboption=group 
			onsubmit=\"return checkinput(this);\">";
	print "<span class=text>" . $sas_lang['newsletter_module_newsletter'] . ": </span><select size=\"1\" name=\"category\">\n";
	while ($category_list = mysql_fetch_array($result1))
	{
		print "<option value=\"$category_list[0]\">$category_list[1]</option>";
	}
	print "</select>";
	//get the class names
	$query = "SELECT id, name FROM $table_classes WHERE project = '0' ";
	$result1 = mysql_query($query);
	unset ($query);
	unset ($result);
	print "<p><span class=text>" . $sas_lang['class'] . ": </span><select size=\"1\" name=\"group\">\n";
	print "<option value=\"0\">Choose a group</option>\n";
	while ($group_list = mysql_fetch_array($result1))
	{
		print "<option value=\"$group_list[0]\">$group_list[1]</option>\n";
	}
	print "</select>";
	print "&nbsp;<input type=submit value=&nbsp;&nbsp;&nbsp;" . $sas_lang['send'] . " name=B1 class=savebutton></form>";
	print "<p><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sas_lang[goback]\" name=\"backbutton\" 
			onClick=\"javascript:history.go(-1)\" class=\"backbutton\">";

	exit;
}

if ($modoption == "newemail")
{
	$query1 = "SELECT id, name FROM $table_newsletters ORDER BY id";
	$result1 = mysql_query($query1) or die_script($query1, mysql_error());
	print "<span class=\"link\"><b>&nbsp;" . $sas_lang['newsletter_module_email_add'] . ":</b></span><br><br>";
	print "<FORM METHOD=\"POST\" NAME=\"form\" ACTION=\"index.php?option=modulemanager&module=$module&modoption=users&save_user=new\">
		 <table border=\"0\" cellpadding=\"5\">";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_email'] . " (*):</span></td>
		 <td><input type=\"text\" name=\"email\" size=\"40\" class=\"textfield\"></td>
		 <td rowspan=\"5\" valign=\"top\"><span class=text>";
	while ($letters_list = mysql_fetch_array($result1))
	{
		if (array_search($letters_list[0], $letter_ids) !== FALSE)
		{
			print "<b>" . $letters_list[0] . "</b>: " . $letters_list[1] . "<br>";
		}
	}
	print "</span></td></tr>
		 <tr><td><span class=text>" . $sas_lang['newsletter_module_surename'] . " :</span></td>
		 <td><input type=\"text\" name=\"surename\" size=\"40\" class=\"textfield\"></td></tr>
		 <tr><td><span class=text>" . $sas_lang['newsletter_module_name'] . " :</span></td>
		 <td><input type=\"text\" name=\"name\" size=\"40\" class=\"textfield\"></td></tr>
		 <tr><td><span class=text>" . $sas_lang['newsletter_module_info'] . " :</span></td>
		 <td><input type=\"text\" name=\"remark\" size=\"40\" class=\"textfield\"></td></tr>";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_newsletter_id'] . " (*) :</span></td>
		 <td><input type=\"text\" name=\"newsletter_id\" size=\"20\" class=\"textfield\"></td></tr>";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_enabled'] . " :</span></td>";
	print "<td><span class=text>" . $sas_lang['yes'] . "</span>";
	print "<input type=\"radio\" value=\"2\" name=\"enable\" checked>";
	print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
	print "<input type=\"radio\" name=\"enable\" value=\"1\"></td>";
	print "</tr>";
	print "</table>";
	print "<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sas_lang[goback]\" name=\"backbutton\" 
			onClick=\"javascript:history.go(-1)\" class=\"backbutton\">";
	print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;$sas_lang[save]\" name=\"savebutton\" class=\"savebutton\">";
	print "</form>";
	exit;
}

if ($modoption == "search")
{
	print "<span class=\"link\">" . $sas_lang['newsletter_module_search_title'] . ":</span><br><br>";
	print "<FORM METHOD=\"POST\" NAME=\"form\" ACTION=\"index.php?option=modulemanager&module=$module&modoption=users&suboption=search_result\">
	        <table border=\"0\" cellpadding=\"5\">";
	print "<tr><td><span class=text>" . $sas_lang['newsletter_module_search_arg'] . " :</span></td>
	       <td><input type=\"text\" name=\"search_arg\" size=\"30\" class=\"textfield\"></td>
	       <td><input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;$sas_lang[newsletter_module_search]\" name=\"savebutton\" class=\"savebutton\"></tr>
	       </tr></table>";
	print "<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sas_lang[goback]\" name=\"backbutton\" 
			onClick=\"javascript:history.go(-1)\" class=\"backbutton\">";

	print "</form>";
	exit;
}

if ($modoption == "users")
{
	$query1 = "SELECT id, name FROM $table_newsletters ORDER BY id";
	$result1 = mysql_query($query1) or die_script($query1, mysql_error()); //get the existing newsletter ids with their names
	$id_count = mysql_num_rows($result1); //total number of records

	if ($user_type != "admin")
	{
		foreach ($letter_ids as $value)
		{
			$where_clause .= " OR newsletter_id LIKE '%$value%'";
		}
		$where_clause = substr($where_clause, 4);
		$where_clause = "AND (" . $where_clause . ")";
	}
	if (IsSet ($filter))
	{
		if ($filter != "All")
		{
			$where_clause .= "AND newsletter_id LIKE '%$filter%'";
		}
	}
	if ($suboption == "not_active")
	{
		print "<span class=\"text\"><b>" . $sas_lang['newsletter_module_new_subscribers'] . ":</b></span>";
		$query = "SELECT id FROM $table_email_adresses WHERE (enable='1' OR enable='0') $where_clause";
		$result = mysql_query($query) or die_script($query, mysql_error());
		$rec_number = mysql_num_rows($result); //total number of records
		$begin_limit = $p * 25 - 25;
		$query = "SELECT id, email, remarks, newsletter_id, UNIX_TIMESTAMP(date), enable, name, surename FROM $table_email_adresses 
					WHERE (enable='1' OR enable='0')  $where_clause ORDER BY $sort LIMIT $begin_limit,25";
		//print $query;
		$result = mysql_query($query) or die_script($query, mysql_error());
	}
	elseif ($suboption == "search_result")
	{
		$query = "SELECT id FROM $table_email_adresses WHERE name LIKE '%$search_arg%' OR email LIKE '%$search_arg%' OR newsletter_id 
					LIKE '%$search_arg%' OR remarks LIKE '%$search_arg%' $where_clause";
		$result = mysql_query($query) or die_script($query, mysql_error());
		$rec_number = mysql_num_rows($result); //total number of records
		$begin_limit = $p * 25 - 25;
		$query = "SELECT id, email, remarks, newsletter_id, UNIX_TIMESTAMP(date), enable, name, surename FROM $table_email_adresses 
					  WHERE (name LIKE '%$search_arg%' OR email LIKE '%$search_arg%' OR remarks LIKE '%$search_arg%') $where_clause 
					  ORDER BY $sort LIMIT $begin_limit,25";
		$result = mysql_query($query) or die_script($query, mysql_error());
		print "<span class=\"link\">" . $sas_lang['newsletter_module_search_results'] . ":</span>";
	}
	else
	{
		print "<p><img src=graphics/folder_closed.gif alt=\"" . $sas_lang['newsletter_module_email_add'] . "\">
				  <a href=$PHP_SELF?option=modulemanager&module=$module&modoption=newemail><span class=link>&nbsp;" .
		$sas_lang['newsletter_module_email_add'] . "</span></a><br><br>";
		$query = "SELECT id FROM $table_email_adresses WHERE enable='2' $where_clause";
		$result = mysql_query($query) or die_script($query, mysql_error());
		$rec_number = mysql_num_rows($result); //total number of records
		$begin_limit = $p * 25 - 25;
		$query = "SELECT id, email, remarks, newsletter_id, UNIX_TIMESTAMP(date), enable, name, surename FROM $table_email_adresses 
					WHERE enable='2' $where_clause ORDER BY $sort LIMIT $begin_limit,25";
		$result = mysql_query($query) or die_script($query, mysql_error());
		print "<span class=\"text\"><b>" . $sas_lang['newsletter_module_subscribers'] . ":</b></span>";
	}
	//print $query;

	while ($newsletter_id_list = mysql_fetch_array($result1))
	{
		$id_list[$newsletter_id_list[0]] = $newsletter_id_list[1]; //put them in an array
	}

	print "<p><table border=\"0\" width=\"90%\">";
	print "<tr><td colspan=\"3\">
			<form METHOD=\"POST\" action=\"index.php?option=modulemanager&module=$module&modoption=users&suboption=$suboption\">";

	if ($id_count > 0) //do we have any newsletters, else skip search filter
	{
		if ($suboption != "search_result")
		{
			print "<span class=\"text\">" . $sas_lang['newsletter_module_filter'] . ": </span><select class=\"text\" name=\"filter\" onChange=\"this.form.submit();\"><option>All</option>";
			foreach ($id_list as $key => $value)
			{
				if ($filter == $key)
				{
					print "<option selected value=\"$key\">$value</option>";
				}
				else
				{
					print "<option value=\"$key\">$value</option>";
				}
			}
			print "</select><input type=\"hidden\" name=\"focus\"></form>";
		}

		print "</td><td colspan=\"4\" align=\"right\"><span class=\"text\">" . $sas_lang['newsletter_module_newsletter_id'] . ": ";
		foreach ($id_list as $key => $value)
			//while ($letters_list = mysql_fetch_array($result1)) 
		{
			if (array_search($key, $letter_ids) !== FALSE)
			{
				print "<b>" . $key . "</b>: " . $value . " ";
			}
		}
	}
	print "</span></td></tr><tr><td colspan=\"7\">&nbsp;</td></tr><tr><td colspan=\"2\">&nbsp;</td>
	       <td><span class=\"text\"><b><a id=\"name\" href=index.php?option=modulemanager&module=$module&modoption=users&suboption=$suboption&sort=name>" .
	$sas_lang['newsletter_module_name'] . "," . $sas_lang['newsletter_module_surename'] . ":";
	if ($sort == "name")
	{
		print "<img border=\"0\" src=\"modules/sn_newsletter/sort.gif\"></a></b></span></td>";
	}
	else
	{
		print "</a></b></span></td>";
	}
	print "<td><span class=\"text\"><b><a href=index.php?option=modulemanager&module=$module&modoption=users&suboption=$suboption&sort=email>" .
	$sas_lang['newsletter_module_email'] . ":";
	if ($sort == "email")
	{
		print "<img border=\"0\" src=\"modules/sn_newsletter/sort.gif\"></a></b></span></td>";
	}
	else
	{
		print "</a></b></span></td>";
	}
	print "<td><span class=\"text\"><b><a href=index.php?option=modulemanager&module=$module&modoption=users&suboption=$suboption&sort=newsletter_id>" .
	$sas_lang['newsletter_module_newsletter_id'] . ":";
	if ($sort == "newsletter_id")
	{
		print "<img border=\"0\" src=\"modules/sn_newsletter/sort.gif\"></a></b></span></td>";
	}
	else
	{
		print "</a></b></span></td>";
	}
	print "<td><span class=\"text\"><b>" . $sas_lang['newsletter_module_status'] . ":</b></span></td>
			<td><span class=\"text\"><b>" . $sas_lang['date'] . ":</b></span></td>
	       </tr>";
	$bgcolor = "E7E7EF";
	if (mysql_num_rows($result) > 0)
	{
		$pages = ceil($rec_number / 25); //number of pages 
		$next = $p +1; //next page number
		$prev = $p -1; //previous page number
		while ($editnewsletter_list = mysql_fetch_array($result))
		{
			print "<tr bgcolor=\"$bgcolor\">
			             <td><img border=\"0\" src=\"graphics/delete.gif\" alt=\"$sas_lang[delete]\" title=\"$sas_lang[delete]\" width=\"16\" height=\"16\" 
						 onClick=\"if(confirm('" . $sas_lang['newsletter_module_delete_subscriber'] . "')) parent.location='index.php?option=modulemanager&module=$module&modoption=$modoption&suboption=$suboption&delete_user=$editnewsletter_list[0]&suboption=$suboption&p=$p&filter=$filter';\"></td>
			             <td><img border=\"0\" src=\"graphics/edit.gif\" alt=\"$sas_lang[edit]\" title=\"$sas_lang[edit]\" 
						 width=\"16\" height=\"16\" onClick=\"parent.location='index.php?option=modulemanager&module=$module&modoption=$modoption&suboption=$suboption&edit_user=$editnewsletter_list[0]&p=$p&filter=$filter';\"></td>";
			if ($editnewsletter_list[7] == "")
			{
				print "<td><span class=link>$editnewsletter_list[6]</span></td>";
			}
			else
			{
				print "<td><span class=link>$editnewsletter_list[6] ,$editnewsletter_list[7]</span></td>";
			}
			print "<td><span class=link>$editnewsletter_list[1]</span></td>
			             <td><span class=link>$editnewsletter_list[3]</span></td>";
			if ($editnewsletter_list[5] == '0')
			{
				print "<td><span class=link>" . $sas_lang['newsletter_module_link_code0'] . "</span></td>";
			}
			if ($editnewsletter_list[5] == '1')
			{
				print "<td><span class=link>" . $sas_lang['newsletter_module_link_code1'] . "</span></td>";
			}
			if ($editnewsletter_list[5] == '2')
			{
				print "<td><span class=link>" . $sas_lang['newsletter_module_link_code2'] . "</span></td>";
			}
			$datum = strftime($sas_config[dateformat], $editnewsletter_list[4]);
			print "<td><span class=link>$datum</span></td>";
			if ($suboption == "not_active")
			{
				print "<td><a href=index.php?option=modulemanager&module=$module&modoption=users&suboption=$suboption&activate=$editnewsletter_list[1]>
								<img border=\"0\" alt=\"" . $sas_lang['newsletter_module_enable'] . "\" title=\"" . $sas_lang['newsletter_module_enable'] . "\" src=\"modules/sn_newsletter/unlock.gif\"></a></td>";
			}
			print "</tr>";
			if ($bgcolor == "#FFFFFF")
			{
				$bgcolor = "#E7E7EF";
			}
			else
			{
				$bgcolor = "#FFFFFF";
			}
		}
	}
	print "<tr><td colspan=\"6\">&nbsp;</td></tr>";
	print "<tr><td colspan=\"3\">";
	if ($prev > 0) //is previous page number greater than 0
	{
		print "<span class=link><a href=index.php?option=modulemanager&module=$module&modoption=users&suboption=$suboption&sort=$sort&p=$prev&filter=$filter>" .
		$sas_lang['newsletter_module_previous_page'] . "</a>";
	}
	print "&nbsp;</span></td>";
	print "<td align=\"center\"><span class=text><b>" . $sas_lang['page'] . " $p / $pages</b></span></td>";
	print "<td colspan=\"3\" align=\"right\">";
	if (($next <= $pages) AND ($rec_number > 0)) //does next page number not exceed the number of pages
	{
		print "<span class=link><a href=index.php?option=modulemanager&module=$module&modoption=users&suboption=$suboption&sort=$sort&p=$next&filter=$filter>" .
		$sas_lang['newsletter_module_next_page'] . "</a>";
	}
	print "</span></td></tr>";
	print "</table>";

	exit;
}

$query = "SELECT * FROM $table_newsletters ORDER BY name"; //get the newsletter categories
$result = mysql_query($query) or die_script($query, mysql_error());
if ($modoption == "archive")
{
	print "<span class=text><b>" . $sas_lang['newsletter_module_archive'] . ":</b></span><br><br>";
}
else
{
	print "<span class=text><b>" . $sas_lang['newsletter_module_newsletters'] . ":</b></span><br><br>";
}

if ($user_type == "admin")
{
	print "<img src=graphics/folder_closed.gif><a href=$PHP_SELF?option=modulemanager&module=$module&modoption=new_newsletter_cat><span class=link>&nbsp;" . $sas_lang['newsletter_module_new_category'] . "</span></a><br>";
}

while ($cat_list = mysql_fetch_array($result))
{
	if ((array_search($cat_list[0], $letter_ids) !== FALSE) AND (array_search($cat_list[0], $letter_ids) !== NULL))
	{

		$query3 = "SELECT id FROM $table_email_adresses WHERE newsletter_id LIKE '%$cat_list[0]%' AND enable = '2'";
		$result3 = mysql_query($query3) or die_script($query3, mysql_error());
		$count = mysql_num_rows($result3); //get the number of subscribers
		print "<br><table border=\"0\"><tr>";
		if ($user_type == "admin")
		{
			print "<td><img border=\"0\" src=\"graphics/delete.gif\" alt=\"$sas_lang[delete]\" title=\"$sas_lang[delete]\" width=\"16\" height=\"16\" onClick=\"if(confirm('" . $sas_lang['newsletter_module_delete_newsletter'] . "')) parent.location='index.php?option=modulemanager&module=$module&delete_news_letter_cat=$cat_list[0]';\"></td>
							 <td><img border=\"0\" src=\"graphics/edit.gif\" alt=\"$sas_lang[edit]\"  title=\"$sas_lang[edit]\" width=\"16\" height=\"16\" onClick=\"parent.location='index.php?option=modulemanager&module=$module&edit_newsletter_cat=$cat_list[0]';\"></td>";
		}
		print "<td><span class=link><a href=\"index.php?option=modulemanager&module=$module&modoption=$modoption&newsletter=$cat_list[0]\">
						   <img src=graphics/document.gif border=\"0\">$cat_list[1] [# $count] [id=$cat_list[0]]</a></span></td>
						 </tr></table>";
		print "<table border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\">";

		if ($cat_list[0] == $newsletter)
		{
			if ($modoption == "archive")
			{
				$query1 = "SELECT id, title, published, sent FROM $table_newsletter_content WHERE newsletter_id = '$cat_list[0]' AND archive = '1' ORDER BY date DESC";
				$result1 = mysql_query($query1) or die_script($query1, mysql_error());
			}
			else
			{
				$query1 = "SELECT id, title, published, sent FROM $table_newsletter_content WHERE newsletter_id = '$cat_list[0]' AND archive = '0' ORDER BY date DESC";
				$result1 = mysql_query($query1) or die_script($query1, mysql_error());
			}
			while ($newsletter_list = mysql_fetch_array($result1))
			{
				print "<tr>
												<td width=\"30\">&nbsp;</td>
												<td>
												<img border=\"0\" src=\"graphics/delete.gif\" title=\"" . $sas_lang['delete'] . "\" alt=\"" . $sas_lang['delete'] . "\" title=\"$sas_lang[delete]\" width=\"16\" height=\"16\" onClick=\"if(confirm('" . $sas_lang['newsletter_module_delete_issue'] . "')) 
												parent.location='index.php?option=modulemanager&module=$module&newsletter=$cat_list[0]&delete_newsletter=$newsletter_list[0]';\">
												</td>
												<td>
												<img border=\"0\" src=\"graphics/edit.gif\"  alt=\"$sas_lang[edit]\"  title=\"$sas_lang[edit]\" 
												onClick=\"parent.location='index.php?option=modulemanager&module=$module&edit_newsletter_opt=$newsletter_list[0]';\">
												</td><td width=\"300\"><span class=\"link\"><a href=\"index.php?option=modulemanager&module=$module&edit_newsletter=$newsletter_list[0]&newsletter=$newsletter\">$newsletter_list[1]</a></span>
												  </td></span></td>";

				if ($newsletter_list[2] == 1)
				{
					print "<td><a href=\"index.php?option=modulemanager&module=$module&modoption=$modoption&newsletter_id=$newsletter_list[0]&newsletter=$newsletter&publish=0\">
													   <img border=\"0\" title=\"" . $sas_lang['newsletter_module_not_publish'] . "\" alt=\"" . $sas_lang['newsletter_module_not_publish'] . "\" 
													   src=\"modules/sn_newsletter/world.gif\"></a></span></td>";
				}
				else
				{
					print "<td><a href=\"index.php?option=modulemanager&module=$module&modoption=$modoption&newsletter_id=$newsletter_list[0]&newsletter=$newsletter&publish=1\">
													   <img border=\"0\" title=\"" . $sas_lang['newsletter_module_publish'] . "\" alt=\"" . $sas_lang['newsletter_module_publish'] . "\" 
													   src=\"modules/sn_newsletter/world_not.gif\"></a></td>";
				}

				if ($modoption != "archive")
				{
					print "<td><a href=\"index.php?option=modulemanager&module=$module&modoption=$modoption&newsletter_id=$newsletter_list[0]&newsletter=$newsletter&archive=1\">
												 <img border=\"0\" title=\"" . $sas_lang['newsletter_module_archive'] . "\" alt=\"" . $sas_lang['newsletter_module_archive'] . "\" 
												 src=\"modules/sn_newsletter/archive.gif\"></a></td>";
				}
				else
				{
					print "<td><a href=\"index.php?option=modulemanager&module=$module&modoption=$modoption&newsletter_id=$newsletter_list[0]&newsletter=$newsletter&archive=0\">
											<img border=\"0\" title=\"" . $sas_lang['newsletter_module_not_archive'] . "\" alt=\"" . $sas_lang['newsletter_module_not_archive'] . "\" 
											src=\"modules/sn_newsletter/archive_not.gif\"></a></td>";
				}
				print "<td><a href=\"index.php?option=modulemanager&module=$module&send_newsletter=$newsletter_list[0]&test_send=yes\">
												<img border=\"0\" title=\"" . $sas_lang['newsletter_module_send_test'] . "\" 
												alt=\"" . $sas_lang['newsletter_module_send_test'] . "\" src=\"modules/sn_newsletter/mail_icon1.gif\"></a></td>
												<td>";
				if ($newsletter_list[3] == 1)
				{
					print "<a href=\"#\" onClick=\"if(confirm('" . $sas_lang['newsletter_module_send_email_confirm1'] . "'))parent.location='index.php?option=modulemanager&module=$module&send_newsletter=$newsletter_list[0]';\">
												<img border=\"0\" title=\"" . $sas_lang['newsletter_module_send'] . "\" 
												alt=\"" . $sas_lang['newsletter_module_send'] . "\" src=\"modules/sn_newsletter/mail_icon.gif\"></a>
												<td><img src=\"modules/sn_newsletter/check_on.gif\">";
				}
				else
				{
					print "<a href=\"#\" onClick=\"if(confirm('" . $sas_lang['newsletter_module_send_email_confirm'] . "'))parent.location='index.php?option=modulemanager&module=$module&send_newsletter=$newsletter_list[0]';\">
												<img border=\"0\" title=\"" . $sas_lang['newsletter_module_send'] . "\" alt=\"" . $sas_lang['newsletter_module_send'] . "\" 
												src=\"modules/sn_newsletter/mail_icon.gif\"></a><td>&nbsp;";
				}
				print "</td></tr>";
			}

			if ($modoption != "archive")
			{
				print "<tr><td colspan=\"8\" align=\"right\">
										<img src=graphics/document.gif>
										<a href=$PHP_SELF?option=modulemanager&module=$module&modoption=new_newsletter&newsletter=$newsletter><span class=link>&nbsp;" .
				$sas_lang['newsletter_module_newsletter_add'] . "</span></a>
										</td></tr>";
			}
		}
		print "</table>";
	}
}

print "\n<p><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['goback'] . "\" name=\"backbutton\" 
		onClick=\"javascript:parent.location='index.php?option=modulemanager';\" class=\"backbutton\">";
include ("interface/pageend.inc.php");
include ("interface/footer.inc.php");
?>