Location: PHPKode > projects > ADbNewsSender > ADbNewsSender 2.1.0/protected/admin/nl/SendNL.php.inc
<?php
//Copyright (c) Florian Grannemann
//Last change in version: 2.1 Alpha 4
/*
    ******************************************************************************
    ADbNewsSender 2

    Copyright (C) 2010 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($MySessionHandler->getNLID())
{   
    $SendNLOPTION=$MyRequestHandler->getNLModuleKeyValue("SendNLOPTION");
    $NLid=$MySessionHandler->getNLID();

    $curmodul=$MySessionHandler->getCurrentModule();
    
    //request & session vars:
    //body
    //type
    //subject
    //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);
		$MySessionHandler->setNLModuleKey("body",$text);
		$MySessionHandler->setNLModuleKey("subject",$MyRequestHandler->getNLModuleKeyValue("subject"));
		if($_FILES["uploadfile$NLid"]["type"]=="text/html")
		{
		    $MySessionHandler->setNLModuleKey("type","html");
		}
		else
		{
		    $MySessionHandler->setNLModuleKey("type","text");
		}
		print "<b>$MSGUploadSuccess</b>";
	    }
	    else
	    {
		print "<b>$ErorUploadfailed</b>";
	    }

	    @unlink($_FILES["uploadfile".$NLid]["tmp_name"]);
	    print "<br><br>";
    }
    if(!$SendNLOPTION )
    {
	if(intval($MyRequestHandler->getNLModuleKeyValue("UseDraft"))>0)
	{    
	    $MyDrafts=new ADBNS_Drafts($NLid,$MyDB);
	    $draftARR=array();
	    $draftARR=$MyDrafts->get_draft_data($MyRequestHandler->getNLModuleKeyValue("UseDraft"));
	    if(count($draftARR) >1)
	    {
		$MySessionHandler->setNLModuleKey("UseDraft",$draftARR["id"]);
		$MySessionHandler->setNLModuleKey("subject",html_entity_decode($draftARR["subject"]));
		$MySessionHandler->setNLModuleKey("body",html_entity_decode($draftARR["message"]));
		$MySessionHandler->setNLModuleKey("type",html_entity_decode($draftARR["type"]));
	    }
	    else
	    {
		$MySessionHandler->setNLModuleKey("UseDraft",0);
	    }
	}

	print "<h2>$TXT_SendNewsletter_Title</h2>";
	print "<b><a href=\"".$_SERVER["PHP_SELF"]."?SelectNL=$NLid&".$MyRequestHandler->getNLModuleKeyName("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=\"".$MyRequestHandler->getNLModuleKeyName("type")."\""; 

	if($MyCFG->get_config_value("EnableTinyMCE")=="yes")
	{
	    print "onChange=\"switchEditor()\"";
	}
	print ">";
	print "<option value=\"text\""; if( $MySessionHandler->getNLModuleKeyValue("type") !="html"){print "selected";} print ">$TXT_type_text</option>";
	print "<option value=\"html\""; if( $MySessionHandler->getNLModuleKeyValue("type") =="html"){print "selected";}  print ">$TXT_type_html</option>";
	print "</select><br><br>";
	print "$TXT_Subject <input type=\"Text\" name=\"".$MyRequestHandler->getNLModuleKeyName("subject")."\" value=\"".$MySessionHandler->getNLModuleKeyValue("subject")."\" size=\"35\"> <br><br>";
        print "$TXT_Mailtext<br><textarea name=\"".$MyRequestHandler->getNLModuleKeyName("body")."\" cols=\"70\" rows=\"18\" >".stripslashes(htmlentities($MySessionHandler->getNLModuleKeyValue("body")))."</textarea> ";
        print "<input type=hidden name=\"".$MyRequestHandler->getNLModuleKeyName("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=\"".$MyRequestHandler->getNLModuleKeyName("subject")."\" value=\"".$MySessionHandler->getNLModuleKeyValue("subject")."\"><br>
		$TXT_File <input name=\"uploadfile$NLid\" type=\"file\"><br>
		<input type=\"hidden\" name=\"".$MyRequestHandler->getNLModuleKeyName("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")
    {
	
	$MySessionHandler->setNLModuleKey("body",$MyRequestHandler->getNLModuleKeyValue("body"));
	$MySessionHandler->setNLModuleKey("subject",$MyRequestHandler->getNLModuleKeyValue("subject"));
	$MySessionHandler->setNLModuleKey("type",$MyRequestHandler->getNLModuleKeyValue("type"));
	if($MySessionHandler->getNLModuleKeyValue("type")=="html")
	{       
		
		
		print "<b>".$TXT_previewNewsletter_TXT[1]."</b> <input type =text value=\"".$MySessionHandler->getNLModuleKeyValue("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"]."\" onSubmit=\"return setWaitMessage('".$MSG_pleaseWait."')\" method=post>";
		print "<input type=\"hidden\" name=\"SelectNL\" value=\"$NLid\"><input type=hidden name=modul value=".$curmodul."\">";	
                print $TXT_previewNewsletter_Option[0]." <select  name=\"".$MyRequestHandler->getNLModuleKeyName("SendNLOPTION")."\" >";
		print "<option value=\"sendNL\">".stripslashes($TXT_previewNewsletter_Option[1])."</option>";
		print "<option value=\"newDraft\">".stripslashes($TXT_previewNewsletter_Option[2])."</option>";
		if(intval($MySessionHandler->getNLModuleKeyValue("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 id=\"submitButton\" 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=\"".$MySessionHandler->getNLModuleKeyValue("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,$MySessionHandler->getNLModuleKeyValue("body")));
		    print "</textarea>";
		}
		else
		{
		    print "<textarea cols=\"65\" rows=\"12\" readonly>";
		    print htmlentities($MySessionHandler->getNLModuleKeyValue("body"));
		    print "</textarea>";
		}
			    
        	
                print "<br><br><form action=\"".$_SERVER["PHP_SELF"]."\" method=post onSubmit=\"return setWaitMessage('".$MSG_pleaseWait."')\">";
		print "<input type=\"hidden\" name=\"SelectNL\" value=\"$NLid\"><input type=hidden name=modul value=".$curmodul."\">";	
		
                print $TXT_previewNewsletter_Option[0];
		print "<select name=\"".$MyRequestHandler->getNLModuleKeyName("SendNLOPTION")."\">";
		print "<option value=\"sendNL\">".stripslashes($TXT_previewNewsletter_Option[1])."</option>";
		print "<option value=\"newDraft\">".stripslashes($TXT_previewNewsletter_Option[2])."</option>";
		if(intval($MySessionHandler->getNLModuleKeyValue("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 id=\"submitButton\" 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($MySessionHandler->getNLModuleKeyValue("body"),$MySessionHandler->getNLModuleKeyValue("subject"),$MySessionHandler->getNLModuleKeyValue("type"));
	    if($result >0)
	    {
		print $MSG_SendNewsletter_NewsletterSavednew."<br>";
	    }
	   
	}
	if($SendNLOPTION=="updateDraft")
	{
	    $MyDrafts=new ADBNS_Drafts($NLid,$MyDB);
	    if($MyDrafts->update_draft($MySessionHandler->getNLModuleKeyValue("UseDraft"),$MySessionHandler->getNLModuleKeyValue("body"),$MySessionHandler->getNLModuleKeyValue("subject"),$MySessionHandler->getNLModuleKeyValue("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($MySessionHandler->getNLModuleKeyValue("body"),$MySessionHandler->getNLModuleKeyValue("subject"),$MySessionHandler->getNLModuleKeyValue("type"));
		if($EntryID >0)
		{
		    $EntryURL=$MyCFG->get_config_value("ArchiveURL")."?NewsletterID=$NLid&EntryID=$EntryID";
		    $MySessionHandler->setNLModuleKey("body",preg_replace("/\[ArchiveEntryURL\]/",$EntryURL,$MySessionHandler->getNLModuleKeyValue("body")));
		}
	    }
	    $path_to_unsubscribe_info=$path_to_protected."/localization/lang/".$MyNL->get_NLconfig_setting("Language")."/lang_unsubscribe_info.php.inc";
	    if(!file_exists($path_to_unsubscribe_info))
	    {	//if the newsletter specific language file does not exist, use the global language file
		$path_to_unsubscribe_info=$path_to_languagefolder."/lang_unsubscribe_info.php.inc";
	    }
	    $MyNL->send_NL($MySessionHandler->getNLModuleKeyValue("body"),$MySessionHandler->getNLModuleKeyValue("subject"),$MySessionHandler->getNLModuleKeyValue("type"),$path_to_unsubscribe_info, $MyCFG->get_config_value("PauseNLSendProcessEvery"),$MyCFG->get_config_value("PauseNLSendProcessTime"));
	    print $MSG_SendNewsletter_NewsletterSent;
	}
	else
	{
	    print "<b>$ErrorNLhasNOsubscribers</b>";
	}
	$MySessionHandler->setNLModuleKey("body","");
	$MySessionHandler->setNLModuleKey("subject","");
	$MySessionHandler->setNLModuleKey("type","");
	$MySessionHandler->setNLModuleKey("UseDraft",0);
    }
    

}
else
{
    print $ErrorNLdoesnotExist;

}
?> 
Return current item: ADbNewsSender