<?

/*
FlexCMS (http://www.flexcms.com)
Flexible, Powerful, Affordable.

Contents of this file are protected by the copyright
notice found at http://www.flexcms.com/flex/pages/copyright.html,
and its usage is subject to the terms of the licensing agreement 
available at http://www.flexcms.com/flex/pages/license.html
*/



	// ========================================================================================
	// compose new message
	// ========================================================================================
	
	$query = "select * from `".$Settings['DBPrefix']."nl-Settings`";
	$result = mysql_query($query) or die (mysql_error());
	while ($row = mysql_fetch_array($result)) {
		$nlSettings[$row['Name']] = $row['Value'];
	}
	
	
	$PageTitle = '<img src="'.$ImagesURL.'/admin/admincp_newsletter.gif" width="22" height="21"> '.$MsgText[5][2];
	$BrowserTitle = $MsgText[5][2];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="' . $MainURL . '/options.html">'.$MsgText[0][4].'</a> > '.$MsgText[5][2];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[501] == 'y') {
							
		
			if ($nlSettings['DoubleOptInMode'] == 'y') {
			// double opt in mode		
												
				$query = "select count(Email) as SubscribersCount from `".$Settings['DBPrefix']."nl-Addresses` where DoubleConfirmed='y'";
				$result = mysql_query($query) or die (mysql_error());
				$row = mysql_fetch_array($result);
				$AddressesCount = $row['SubscribersCount'];
								
			}
			else {
			// not double opt in mode
			
				$query = "select count(Email) as SubscribersCount from `".$Settings['DBPrefix']."nl-Addresses`";
				$result = mysql_query($query) or die (mysql_error());
				$row = mysql_fetch_array($result);
				$AddressesCount = $row['SubscribersCount'];
			
			}
			
			if ($AddressesCount > 0) {
			// subscribers found
							
				$PageContents = '
				<script>
							
				function ShowMessagePreview() {
					document.forms["NewsletterCompose"].elements["ShowPreview"].value = "yes";
					document.forms["NewsletterCompose"].elements["submit"].click();
				}
				function ValidateForm() {					

					if (FCKeditorAPI.GetInstance("PageContents").GetXHTML() == "") {
						alert("'.$MsgText[5][22].'");
						return false;
					}
					if (document.forms["NewsletterCompose"].elements["Title"].value == "") {
						alert("'.$MsgText[5][23].'");
						return false;
					}
					
					document.forms["NewsletterCompose"].elements["submit"].disabled = true;
					document.forms["NewsletterCompose"].elements["preview"].disabled = true;
				
					return true;					
				
				}
				
				</script>
				
				
				<br>'.$MsgText[5][14].': '.$AddressesCount.'<br><br><br><b>'.$MsgText[5][2].':</b><br><form name="NewsletterCompose" action="'.$MainURL.'/admin/newsletter_send" method="post" onSubmit="return ValidateForm();">
<input type="hidden" name="ShowPreview" value="">
<b>'.$MsgText[5][15].':</b><br><input type="text" name="Title" size="65">
<br><br>
<b>'.$MsgText[5][16].':</b><br>
<script>
var EditorStarted = false;

function UpdatePageType() {
	var PageType = document.getElementById("PageType").value;
	
	if (PageType == 1) {
		if (EditorStarted == false) {
			var oFCKeditor = new FCKeditor( "PageContents" ) ;

			oFCKeditor.BasePath = "'.$BaseURL.'/fckeditor/" ;

			oFCKeditor.Height	= 500 ;
			
			oFCKeditor.Config["BaseURL"] = "'.$BaseURL.'";
				
			//oFCKeditor.Create() ;
			oFCKeditor.ReplaceTextarea();
			
			EditorStarted = true;
		}
	
		document.getElementById("EditorDiv").style.display = "";
		document.getElementById("NonEditorDiv").style.display = "none";
	}
	else if (PageType == 2) {
		document.getElementById("EditorDiv").style.display = "none";
		document.getElementById("NonEditorDiv").style.display = "";
	}
	
	
}
</script>

<select name="PageType" id="PageType" size="1" onChange="UpdatePageType();">
<option value="1"'.$PageTypeSelected[1].'> Rich Text / HTML Editor</option>
<option value="2"'.$PageTypeSelected[2].'> Plain Text / HTML Without Editor</option>
</select><br>

<br>


<div id="EditorDiv"><textarea id="PageContents" name="PageContents" cols="65" rows="8" style="width: 100%; height: 500px;" wrap="virtual"></textarea></div><div id="NonEditorDiv" style="display: none;"><textarea id="PageContents2" name="PageContents2" cols="65" rows="8" style="width: 100%; height: 500px;" wrap="virtual"></textarea></div>

<br><br>
<b>'.$MsgText[5][17].':</b> <input type="radio" name="MailFormat" value="html" checked> HTML &nbsp;<input type="radio" name="MailFormat" value="text" onClick="document.getElementById(\'PageType\').value=2; UpdatePageType();"> '.$MsgText[5][18].'<br>
<br><br>
<script>var FlexCMSScriptName="'.$Settings['ScriptName'].'";</script><script type="text/javascript" src="'.$BaseURL.'/fckeditor/fckeditor.js"></script><script>UpdatePageType();</script>
<input type="submit" name="submit" value="'.$MsgText[5][19].'">&nbsp;&nbsp;&nbsp;<input type="button" name="preview" value="'.$MsgText[5][20].'" onClick="ShowMessagePreview();">
</form>';
			
			}
			else {
			// no subscribers found
			
				$PageContents = '<br>'.$MsgText[5][21];
			
			}
			
			
		}
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}
		


?>
