Location: PHPKode > projects > ADbNewsSender > ADbNewsSender_2.0.4/protected/admin/nl/SendNL.php.inc
<?php
//Copyright (c) Florian Grannemann
//Last change in version: 2.0 RC 2
/*
    ******************************************************************************
    ADbNewsSender 2

    Copyright (C) 2009  Florian Grannemann (hide@address.com)
    Website: http://adbnewssender.sf.net



    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 3 of the License, or
    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, see http://www.gnu.org/licenses/
    ******************************************************************************
*/
include "$path_to_languagefolder/lang_admin_sendNL.php.inc";
//Do not edit anything unless you realy REALY know what you are doing!
if($_SESSION["CurrentNL"] && $MyCFG->NL_exists($_SESSION["CurrentNL"]))
{

    
    $SendNLOPTION=$_REQUEST["SendNLOPTION"];
    $NLid=$_SESSION["CurrentNL"];

    $subject="NL".$NLid."_Subject";
    $body="NL".$NLid."_Body";
    $type="NL".$NLid."_type";
    $curmodul=$_SESSION["currentModulType"]."|".intval($_SESSION["currentModulNr"]);
    $UseDraft="NL".$NLid."UseDraft";

    //if a NL has been uploaded:
    if($_FILES["uploadfile".$NLid]['tmp_name'])
    {
	  //  print $_FILES["uploadfile$NLid"]["error"];
	    if(!$_FILES["uploadfile$NLid"]["error"])
	    {
		$text=file($_FILES["uploadfile$NLid"]["tmp_name"]);
		$text=implode("\n",$text);
		$_SESSION[$body]=$text;
		$_SESSION[$subject]=$_REQUEST[$subject];
		if($_FILES["uploadfile$NLid"]["type"]=="text/html")
		{
		    $_SESSION[$type]="html";
		}
		else
		{
		    $_SESSION[$type]="text";
		}
		print "<b>$MSGUploadSuccess</b>";
	    }
	    else
	    {
		print "<b>$ErorUploadfailed</b>";
	    }

	    @unlink($_FILES["uploadfile".$NLid]["tmp_name"]);
	    print "<br><br>";
    }
    if(!$SendNLOPTION )
    {

	if(intval($_REQUEST[$UseDraft])>0)
	{
    
	    $MyDrafts=new ADBNS_Drafts($NLid,$MyDB);
	    $draftARR=array();
	    $draftARR=$MyDrafts->get_draft_data($_REQUEST[$UseDraft]);
	    if(count($draftARR) >1)
	    {
		$_SESSION[$UseDraft]=$draftARR["id"];
		$_SESSION[$subject]=html_entity_decode($draftARR["subject"]);
		$_SESSION[$body]=html_entity_decode($draftARR["message"]);
		$_SESSION[$type]=html_entity_decode($draftARR["type"]);
	    }
	    else
	    {
		$_SESSION[$UseDraft]=0;
	    }
	}

	print "<h2>$TXT_SendNewsletter_Title</h2>";
	print "<b><a href=\"".$_SERVER["PHP_SELF"]."?SelectNL=$NLid&SendNLOPTION=UploadFile&modul=".$curmodul."\">";
	print $TXT_UploadNewsletter."</a> | ";
	print "<a href=\"".$_SERVER["PHP_SELF"]."?SelectNL=$NLid&modul=nl|5\">";

	print "$TXT_UseADraft</a></b><br><br>";
	

	print $TXT_EnterNewsletter[0]."<br>";
	if($MyNL->get_NLconfig_setting("Archive_enabled")=="yes")
	{
	    print $TXT_ArchiveEntryURLInfo."<br>";
	}
	print "<form name=\"sendNL\" action=\"".$_SERVER["PHP_SELF"]."\" method=\"post\">";
	print "<p>";
	print "$TXT_NL_type <select name=\"$type\""; 

	if($MyCFG->get_config_value("EnableTinyMCE")=="yes")
	{
	    print "onChange=\"switchEditor()\"";
	}
	print ">";
	print "<option value=\"text\""; if( $_SESSION[$type] !="html"){print "selected";} print ">$TXT_type_text</option>";
	print "<option value=\"html\""; if( $_SESSION[$type] =="html"){print "selected";}  print ">$TXT_type_html</option>";
	print "</select><br><br>";
	print "$TXT_Subject <input type=\"Text\" name=\"$subject\" value=\"".$_SESSION[$subject]."\" size=\"35\"> <br><br>";
        print "$TXT_Mailtext<br><textarea name=\"$body\" cols=\"70\" rows=\"18\" >".stripslashes(htmlentities($_SESSION[$body]))."</textarea> ";
        print "<input type=hidden name=\"SendNLOPTION\" value=\"previewNL\"><input type=hidden name=modul value=".$curmodul."\">";
	print "<input type=hidden name=\"SelectNL\" value=\"$NLid\"><br> <input type=\"submit\" value=\"$TXT_EnterNewsletter_SubmitButton\"></form>";
        print "</p>"; 
    }
    if($SendNLOPTION=="UploadFile" )
    {
	    print "<h3>$TXT_SendNewsletter_uploadFile_title</h3>
		<form action=\"".$_SERVER['PHP_SELF']."\" enctype=\"multipart/form-data\" method=\"post\">
		$TXT_Subject <input type=\"text\" name=\"$subject\" value=\"".$_SESSION[$subject]."\"><br>
		$TXT_File <input name=\"uploadfile$NLid\" type=\"file\"><br>
		<input type=\"hidden\" name=\"SelectNL\" value=\"$NLid\"><br>
		<input type=hidden name=modul value=".$curmodul."\">
		<input name=\"Upload\" type=\"submit\" value=\"$MSG_Upload\">
		</form><br><br>
		<a href=\"".$_SERVER['PHP_SELF']."?modul=".$curmodul."&SelectNL=$NLid\">$MSG_Abort_Upload</a>
		";

    }
    if($SendNLOPTION=="previewNL")
    {
	$_SESSION[$body]=$_REQUEST[$body];
	$_SESSION[$subject]=$_REQUEST[$subject];
	$_SESSION[$type]=$_REQUEST[$type];
	
	
	if($_SESSION[$type]=="html")
	{       
		
		
		print "<b>".$TXT_previewNewsletter_TXT[1]."</b> <input type =text value=\"".$_SESSION[$subject]."\" size=50 readonly></font><br>";
		

		print "<iframe src='previewNL.php' framespacing='0' frameborder='1' WIDTH=100% height=500 scrolling='yes'></iframe>";
		print "<br><p><font color=\"black\"><form action=".$_SERVER["PHP_SELF"]." method=post>";
		print "<input type=\"hidden\" name=\"SelectNL\" value=\"$NLid\"><input type=hidden name=modul value=".$curmodul."\">";	
                print $TXT_previewNewsletter_Option[0]." <select  name=\"SendNLOPTION\" >";
		print "<option value=\"sendNL\">".stripslashes($TXT_previewNewsletter_Option[1])."</option>";
		print "<option value=\"newDraft\">".stripslashes($TXT_previewNewsletter_Option[2])."</option>";
		if(intval($_SESSION[$UseDraft])>0)
		{
			print "<option value=\"updateDraft\">".stripslashes($TXT_previewNewsletter_Option[3])."</option>";

		}
		print "<option value=\"\" selected>".stripslashes($TXT_previewNewsletter_Option[4])."</option>";
 	
		print "</select> <input type=submit value=\"OK\"></form></font></p>";
		
	}
	else
	{	
		
		print "<h2>$TXT_previewNewsletter_Title</h2>";
		print "<p><b>".$TXT_previewNewsletter_TXT[1]."</b> <input type=text size=35 value=\"".$_SESSION[$subject]."\" readonly>";

		print "<br><br><b>".$TXT_previewNewsletter_TXT[2]."</b><br>";
		
		if($MyNL->get_NLconfig_setting("Archive_enabled")=="yes")
		{
		    print "<textarea cols=\"65\" rows=\"12\" readonly>";
		    print htmlentities(preg_replace("/\[ArchiveEntryURL\]/",$TXT_RepArchiveURL,$_SESSION[$body]));
		    print "</textarea>";
		}
		else
		{
		    print "<textarea cols=\"65\" rows=\"12\" readonly>";
		    print htmlentities($_SESSION[$body]);
		    print "</textarea>";
		}
			    
        	
                print "<br><br><form action=".$_SERVER["PHP_SELF"]." method=post>";
		print "<input type=\"hidden\" name=\"SelectNL\" value=\"$NLid\"><input type=hidden name=modul value=".$curmodul."\">";	
		
                print $TXT_previewNewsletter_Option[0];
		print "<select name=\"SendNLOPTION\">";
		print "<option value=\"sendNL\">".stripslashes($TXT_previewNewsletter_Option[1])."</option>";
		print "<option value=\"newDraft\">".stripslashes($TXT_previewNewsletter_Option[2])."</option>";
		if(intval($_SESSION[$UseDraft])>0)
		{
			print "<option value=\"updateDraft\">".stripslashes($TXT_previewNewsletter_Option[3])."</option>";

		}
		print "<option value=\"\" selected>".stripslashes($TXT_previewNewsletter_Option[4])."</option>";
 		print "</select> <input type=submit value=\"OK\"></form></p>"; 
		
		
	}
	


    }
    if($SendNLOPTION=="sendNL" || $SendNLOPTION=="newDraft" || $SendNLOPTION=="updateDraft")
    {
	
	print "<h3>$TXT_SendNewsletter_Title</h3>";
	
	//draft options:
	if($SendNLOPTION=="newDraft")
	{
	    $MyDrafts=new ADBNS_Drafts($NLid,$MyDB);
	    $result=$MyDrafts->add_draft($_SESSION[$body],$_SESSION[$subject],$_SESSION[$type]);
	    if($result >0)
	    {
		print $MSG_SendNewsletter_NewsletterSavednew."<br>";
	    }
	   
	}
	if($SendNLOPTION=="updateDraft")
	{
	    $MyDrafts=new ADBNS_Drafts($NLid,$MyDB);
	    if($MyDrafts->update_draft($_SESSION[$UseDraft],$_SESSION[$body],$_SESSION[$subject],$_SESSION[$type]))
	    {
		print $MSG_SendNewsletter_NewsletterSaved."<br>";
	    }
	  
	}
	if($MyNL->number_of_ML_entries() >0)
	{
	    

	    if($MyNL->get_NLconfig_setting("Archive_enabled")=="yes")
	    {
		
		$MyArchive=new priv_Archive($NLid,$MyDB);
		$EntryID=$MyArchive->add_entry($_SESSION[$body],$_SESSION[$subject],$_SESSION[$type]);
		if($EntryID >0)
		{
		    $EntryURL=$MyCFG->get_config_value("ArchiveURL")."?NewsletterID=$NLid&EntryID=$EntryID";
		    $_SESSION[$body]=preg_replace("/\[ArchiveEntryURL\]/",$EntryURL,$_SESSION[$body]);
		}
	    }
	    
	    $MyNL->send_NL($_SESSION[$body],$_SESSION[$subject],$_SESSION[$type],$path_to_protected."/localisation/lang/".$MyNL->get_NLconfig_setting("Language")."/lang_unsubscribe_info.php.inc");
	    print $MSG_SendNewsletter_NewsletterSent;
	}
	else
	{
	    print "<b>$ErrorNLhasNOsubscribers</b>";
	}
	$_SESSION[$body]="";
	$_SESSION[$subject]="";
	$_SESSION[$type]="";
	$_SESSION[$UseDraft]=0;
    }
    

}
else
{
    print $ErrorNLdoesnotExist;

}

?> 
Return current item: ADbNewsSender