Location: PHPKode > projects > ADbNewsSender > ADbNewsSender_2.0.4/protected/admin/nl/drafts.php.inc
<?php
//Copyright (c) Florian Grannemann
//Last change in version: 2.0 Alpha 3
/*
    ******************************************************************************
    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_drafts.php.inc";

//Do not edit anything unless you realy REALY know what you are doing!
if($_SESSION["CurrentNL"] && $MyCFG->NL_exists($_SESSION["CurrentNL"]))
{
    //preparing mudule variables:
    $NLID=$_SESSION["CurrentNL"];
    $DraftType="Drafts".$NLID."_type";
    $DraftBody="Drafts".$NLID."_Body";
    $DraftSubject="Drafts".$NLID."_Subject";
    $CurrentDraft="Drafts".$NLID."_CurDraft";
    
    $curmodul=$_SESSION["currentModulType"]."|".intval($_SESSION["currentModulNr"]);
    //create a ADBNS_Drafts object:
    $MyDrafts=new ADBNS_Drafts($NLID, $MyDB); 
	
    if(!$_REQUEST["DraftsOption"] || $_REQUEST["DraftsOption"]=="save"|| $_REQUEST["DraftsOption"]=="save_new" )
    {
	include "$path_to_languagefolder/localsettings.php.inc";
	if($_REQUEST["DraftsOption"]=="save")
	{
	    //save changes
	    if($MyDrafts->update_draft(intval($_SESSION[$CurrentDraft]),$_SESSION[$DraftBody],$_SESSION[$DraftSubject],$_SESSION[$DraftType]))
	    {
		print "<b>".preg_replace("/<-DraftID->/",$_SESSION[$CurrentDraft],$MSGUpdateSuccess)."</b><br>"; 
	    }
	    else
	    {
		print "<b>".preg_replace("/<-DraftID->/",$_SESSION[$CurrentDraft],$MSGUpdateFailed)."</b><br>";
	    }

	    $_SESSION[$CurrentDraft]="";
	    $_SESSION[$DraftType]="";
	    $_SESSION[$DraftBody]="";
	    $_SESSION[$DraftSubject]="";
	}
	if($_REQUEST["DraftsOption"]=="save_new")
	{
		//save as new  draft
	    $result=$MyDrafts->add_draft($_SESSION[$DraftBody],$_SESSION[$DraftSubject],$_SESSION[$DraftType]);
	    print "$MSG_Draft_saved <br>";
	    $_SESSION[$CurrentDraft]="";
	    $_SESSION[$DraftType]="";
	    $_SESSION[$DraftBody]="";
	    $_SESSION[$DraftSubject]="";
	}

	$DeleteDrafts="DeleteDrafts".$NLID;
	$DeleteDraftsDeleteList="DeleteDraftsDeleteList".$NLID;
	$DeleteDraftsDeleteListCount="DeleteDraftsDeleteListCount".$NLID;
	 //preparing:
	 $ShowDraftsDirection="ShowDarftsDirection".$NLID; //ASC or DESC
	 $ShowDraftsOrderby="ShowDraftsOrderby".$NLID; //field name (lower case)
	 $ShowDraftslastnext="ShowDraftslastnext".$NLID; //last or next
	 $ShowDraftsperpage="Draftsperpage".$NLID; //number 1-50
	  
	 $ShowDraftsStartat="ShowDraftsStartat".$NLID;
	 $ShowDraftsEndat="ShowDraftsEndat".$NLID;
	if($_POST[$DeleteDrafts]=="yes")
	{
	   $deletelist=$_POST[$DeleteDraftsDeleteList];
	   $i=0;
	   while($i < $_POST[$DeleteDraftsDeleteListCount])
	   {
		if(intval($deletelist[$i])>0)
		{
			if($MyDrafts->delete_draft($deletelist[$i]))
			{
			    print preg_replace("/<-ID->/",$deletelist[$i],$MSG_Draft_deleted)."<br>";
			}
		
		}
		$i++;
	    
	   }
	   print "<br><br>"; 
	   $_SESSION[$ShowDraftsperpage]=15;
	   $_SESSION[$ShowDraftsStartat]=0;
	}


	
	print "<b><a href=\"".$_SERVER["PHP_SELF"]."?DraftsOption=edit&DraftID=new\">$TXT_ADD_NewDraft</a></b><br><br>";
	//show drafts in a table:

	
	  //setting defaults:
	    if(!isset($_SESSION[$ShowDraftsOrderby]))
	    {
		$_SESSION[$ShowDraftsOrderby]="id";

	    }
	    if(!isset($_SESSION[$ShowDraftsStartat]))
	    {
		$_SESSION[$ShowDraftsStartat]=0;

	    }
	    if(!isset($_SESSION[$ShowDraftslastnext]))
	    {
		$_SESSION[$ShowDraftslastnext]="next";

	    }
	    if(!isset($_SESSION[$ShowDraftsperpage]))
	    {
		$_SESSION[$ShowDraftsperpage]=15;

	    }
	    if(!isset($_SESSION[$ShowDraftsEndat]))
	    {
		$_SESSION[$ShowDraftsEndat]=$_SESSION[$ShowDraftsperpage];

	    }
	    
	     if(!isset($_SESSION[$ShowDraftsDirection]))
	    {
		$_SESSION[$ShowDraftsDirection]="ASC";

	    }
	      //looking for changes:
	    
	    if($_REQUEST[$ShowDraftsDirection])
	    {
		
		$_SESSION[$ShowDraftsDirection]=$_REQUEST[$ShowDraftsDirection];
		$_SESSION[$ShowDraftsStartat]=0;
		$_SESSION[$ShowDraftsEndat]=$_SESSION[$ShowDraftsperpage];
	    }
	    if($_REQUEST[$ShowDraftsOrderby])
	    {
		$_SESSION[$ShowDraftsOrderby]=$_REQUEST[$ShowDraftsOrderby];
		$_SESSION[$ShowDraftsStartat]=0;
		$_SESSION[$ShowDraftsEndat]=$_SESSION[$ShowDraftsperpage];
	    }
	    if(isset($_REQUEST[$ShowDraftsStartat]))
	    {
		$_SESSION[$ShowDraftsStartat]=$_REQUEST[$ShowDraftsStartat];
	
		
	    }
	     if($_REQUEST[$ShowDraftsEndat])
	    {
		$_SESSION[$ShowDraftsEndat]=$_REQUEST[$ShowDraftsEndat];
	
		
	    }
	   
	    if($_REQUEST[$ShowDraftsperpage])
	    {
		$_SESSION[$ShowDraftsperpage]=$_REQUEST[$ShowDraftsperpage];
		$_SESSION[$ShowDraftsStartat]=0;
		$_SESSION[$ShowDraftsEndat]=$_SESSION[$ShowDraftsperpage];
	    }
       
	    //fetching drafts:
	    $drafts_array=array();
	    $offset=$_SESSION[$ShowDraftsEndat] -$_SESSION[$ShowDraftsStartat];
	    $drafts_array=$MyDrafts->get_drafts($_SESSION[$ShowDraftsStartat],$offset,$_SESSION[$ShowDraftsOrderby],$_SESSION[$ShowDraftsDirection]);
	
	    //displaying table:
	   
	    print "<form action=\"".$_SERVER["PHP_SELF"]."\" method=\"post\">$ShowDrafts_order_Direction: ";
	
	    print "<select name=\"$ShowDraftsDirection\">";
	    print "<option value=\"ASC\"";
	    if($_SESSION[$ShowDraftsDirection]== "ASC")
	    {
		print " selected ";
	    }
	    print ">$ShowDrafts_order_Asc</option>";

	     print "<option value=\"DESC\"";
	    if($_SESSION[$ShowDraftsDirection]== "DESC")
	    {
		print " selected ";
	    }
	    print ">$ShowDrafts_order_Desc</option></select>";

	    print "$ShowDrafts_showperpage: ";
	    print "<select name=\"$ShowDraftsperpage\">";
	    
	    $i=1;
	    while($i <= 50)
	    {
		print "<option value=\"$i\"";
		if ($i ==$_SESSION[$ShowDraftsperpage])
		{
		    print " selected ";
		}
		print ">$i</option>";
		
		$i++;
	    }
	    print "</select><input type=\"submit\" value=\"$ShowDrafts_change_options\"></form>";
	    print "<form action=\"".$_SERVER["PHP_SELF"]."\" method=\"post\">";
	    print "<table border=1 >";
	    print "<tr><td>$ShowDrafts_table_delete</td>";
	    
	    //Table column ID:
	    print "<td>";
	    print "<a href=\"".$_SERVER["PHP_SELF"]."?".$ShowDraftsOrderby."=id\" title=\"$ShowDrafts_tooltext_orderby\">";
	    if($_SESSION[$ShowDraftsOrderby]=="id")
	    {
		print "<b>$ShowDrafts_table_id</b>";
	    }
	    else
	    {
		print "$ShowDrafts_table_id";
	    }
	    print "</a></td>";
	   //Table column subject:
	   print "<td>";
	   print "<a href=\"".$_SERVER["PHP_SELF"]."?".$ShowDraftsOrderby."=subject\" title=\"$ShowDrafts_tooltext_orderby\">";
	   if($_SESSION[$ShowDraftsOrderby]=="subject")
	   {
		print "<b>$ShowDrafts_table_subject</b>";
	   }
	   else
	   {
		print "$ShowDrafts_table_subject";
	   }
	   print "</a></td>";
	   
	   //Table column type:
	   print "<td>";
	   print "<a href=\"".$_SERVER["PHP_SELF"]."?".$ShowDraftsOrderby."=type\" title=\"$ShowDrafts_tooltext_orderby\">";
	   if($_SESSION[$ShowDraftsOrderby]=="type")
	   {
		print "<b>$ShowDrafts_table_type</b>";
	   }
	   else
	   {
		print "$ShowDrafts_table_type";
	   }
	   print "</a></td>"; 

	   print "<td>";
	   print "<a href=\"".$_SERVER["PHP_SELF"]."?".$ShowDraftsOrderby."=date\" title=\"$ShowDrafts_tooltext_orderby\">";
	   if($_SESSION[$ShowDraftsOrderby]=="date")
	   {
		print "<b>$ShowDrafts_table_date</b>";
	   }
	   else
	   {
		print "$ShowDrafts_table_date";
	   }
	   print "</a></td>"; 
	   print "<td>$ShowDrafts_table_options</td></tr>";
	   
	   $i=0;
	    
	   $timezone=$MyCFG->get_timezone();
	   while ($i < count($drafts_array))
	   {

		if($drafts_array[$i]["id"])
		{
		    print "<tr><td>";
		    print  "<input type=\"checkbox\" name=\"".$DeleteDraftsDeleteList."[$i]\" value=\"".$drafts_array[$i]["id"]."\"></td>";
		    print "</td>";
		    print "<td>".$drafts_array[$i]["id"]."</td>";
		    print "<td>".html_entity_decode($drafts_array[$i]["subject"])."</td>";
		    
		    if($drafts_array[$i]["type"]=="html")
		    {
			print "<td>".$ShowDraftsTable_TypeHTML."</td>";
		    }
		    else
		    {
			print "<td>".$ShowDraftsTable_TypeText."</td>";
		    }
		    print "<td>".date("$dateformat, $timeformat",$drafts_array[$i]["date"])." ($timezone)</td>";
		
		    //draft options:
		    print "<td>";
		    print "<a href=\"".$_SERVER["PHP_SELF"]."?SelectNL=$NLID&modul=nl|0&NL".$NLID."UseDraft=".$drafts_array[$i]["id"]."&NL".$NLID."_type=".$drafts_array[$i]["type"]."\" title=\"$ShowDrafts_Drafts_option_Tooltip_SendDraft\" >$ShowDrafts_Drafts_option_SendDraft</a> <br>";
		    print "<a href=\"".$_SERVER["PHP_SELF"]."?SelectNL=$NLID&DraftsOption=edit&DraftID=".$drafts_array[$i]["id"]."&$DraftType=".$drafts_array[$i]["type"]."\" title=\"$ShowDrafts_Drafts_option_Tooltip_EditDraft\">$ShowDrafts_Drafts_option_EditDraft</a><br>";
		    print "<a href=\"ExportDraft.php?NLID=$NLID&DraftID=".$drafts_array[$i]["id"]."&DraftType=".$drafts_array[$i]["type"]."\" title=\"$ShowDrafts_Drafts_option_Tooltip_ExportDraft\" target=\"_blank\">$ShowDrafts_Drafts_option_ExportDraft</a><br>";
		    print "</td>";
		    print "</tr>";
		}

		$i++;
	   }
	    
	 print "</table>";
	 
	 print "<input type=\"hidden\" name=\"$DeleteDrafts\" value=\"yes\">";
	 print "<input type=\"hidden\" name=\"$DeleteDraftsDeleteListCount\" value=\"$i\">";
	 print "<input type=\"hidden\" name=\"$ShowDraftsStartat\" value=\"0\">";
	 print "<input type=\"hidden\" name=\"$ShowDraftsEndat\" value=\"15\">";
	 print "<input type=\"submit\" value=\"$ShowDrafts_deleteSelected\"></form>";
	
	  $NumberOfEntries=$MyDrafts->number_of_drafts();

	   
	    //next/last
	    //show last:
	    $last_entries=0;
	   if($_SESSION[$ShowDraftsStartat] >0)
	   {
		if($_SESSION[$ShowDraftsStartat]-$_SESSION[$ShowDraftsperpage] >=0)
		{
		    $last_entries=$_SESSION[$ShowDraftsperpage];

		}
		else
		{
		    $last_entries=$_SESSION[$ShowDraftsStartat];
		}
		
		print "<a href=\"".$_SERVER["PHP_SELF"]."?".$ShowDraftsStartat."=";
		print ($_SESSION[$ShowDraftsStartat]-$last_entries)."&".$ShowDraftsEndat."=";
		print ($_SESSION[$ShowDraftsStartat])."\">&lt;- $ShowDrafts_showlast  $last_entries</a>"; 
	   }
	   
	 //show next:
	   $next_entries=0;
	   if($_SESSION[$ShowDraftsEndat] < ($NumberOfEntries) )
	    {
		if($_SESSION[$ShowDraftsEndat]+$_SESSION[$ShowDraftsperpage] <=($NumberOfEntries-1))
		{
		    $next_entries=$_SESSION[$ShowDraftsperpage];
		}
		else
		{
		    $next_entries=($NumberOfEntries)-$_SESSION[$ShowDraftsEndat];

		}
		if ($last_entries >0)
		{
		    print " | ";
		}
		
		print "<a href=\"".$_SERVER["PHP_SELF"]."?".$ShowDraftsStartat."=";
		print ($_SESSION[$ShowDraftsEndat])."&".$ShowDraftsEndat."=";
		print ($_SESSION[$ShowDraftsEndat]+$next_entries)."\">$ShowDrafts_shownext  $next_entries -&gt;</a>"; 
	    }
	   
	  
	
	


    }
    if($_REQUEST["DraftsOption"]=="edit")
    {
	//add or edit a draft:
	print "<h3>$TXT_ADD_EDIT_draft</h3>";
	//if a draft 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[$DraftBody]=$text;
		$_SESSION[$DraftSubject]=$_REQUEST[$DraftSubject];
		if($_FILES["uploadfile".$NLID]["type"]=="text/html")
		{
		    $_SESSION[$DraftType]="html";
		}
		else
		{
		    $_SESSION[$DraftType]="text";
		}
		
	    }
	    else
	    {
		print "<b>$ErorUploadfailed</b>";
	    }

	    @unlink($_FILES["uploadfile".$NLID]["tmp_name"]);
	    print "<br><br>";
	}	
	if($_REQUEST["DraftID"]=="new")
	{
		$_SESSION[$CurrentDraft]="new";
		$_SESSION[$DraftType]="html";
		$_SESSION[$DraftBody]="";
		$_SESSION[$DraftSubject]="";
	}
	else
	{
	    if(intval($_REQUEST["DraftID"])>0)
	    {
		//load draft
		$DraftARR=array();
		$DraftARR=$MyDrafts->get_draft_data(intval($_REQUEST["DraftID"]));
		if(count ($DraftARR) <1)
		{
		    print "<b>$ERR_Draft_does_not_exist</b><br>";
		    $_SESSION[$CurrentDraft]="new";
		    $_SESSION[$DraftType]="html";
		    $_SESSION[$DraftBody]="";
		    $_SESSION[$DraftSubject]="";
		}
		else
		{
		    $_SESSION[$DraftType]=$DraftARR["type"];
		    $_SESSION[$CurrentDraft]=intval($_REQUEST["DraftID"]);
		    $_SESSION[$DraftBody]=html_entity_decode($DraftARR["message"]);
		    $_SESSION[$DraftSubject]=html_entity_decode($DraftARR["subject"]);
		}
	    }
	}
	
	
	print "<a href=\"".$_SERVER["PHP_SELF"]."?SelectNL=$NLID&DraftsOption=upload&modul=".$curmodul."\">";
	print $TXT_Upload_new."</a><br><br>";
	

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

	if($MyCFG->get_config_value("EnableTinyMCE")=="yes")
	{
	    print "onChange=\"switchEditor()\"";
	}
	print ">";
	print "<option value=\"text\""; if( $_SESSION[$DraftType] !="html"){print "selected";} print ">$TXT_type_text</option>";
	print "<option value=\"html\""; if( $_SESSION[$DraftType] =="html"){print "selected";}  print ">$TXT_type_html</option>";
	print "</select><br><br>";
	print "$TXT_Subject <input type=\"Text\" name=\"$DraftSubject\" value=\"".$_SESSION[$DraftSubject]."\" size=\"35\"> <br><br>";
        print "$TXT_Mailtext<br><textarea name=\"$DraftBody\" cols=\"70\" rows=\"18\" >".stripslashes(htmlentities($_SESSION[$DraftBody]))."</textarea> ";
        print "<input type=hidden name=\"DraftsOption\" value=\"preview\"><input type=hidden name=modul value=".$curmodul."\">";
	print "<input type=hidden name=\"SelectNL\" value=\"$NLID\"><br> <input type=\"submit\" value=\"$TXT_EnterDraft_SubmitButton\"></form>";
        print "</p>"; 
	print "<br><br><a href=\"".$_SERVER["PHP_SELF"]."?SelectNL=$NLID&modul=$curmodul\">$TXT_Back_to_draftsMenu</a><br>";

    }
    if($_REQUEST["DraftsOption"]=="upload")
    {
	print "<h3>$TXT_Drafts_uploadFile_title</h3>
		<form action=\"".$_SERVER['PHP_SELF']."\" enctype=\"multipart/form-data\" method=\"post\">
		$TXT_Subject <input type=\"text\" name=\"$DraftSubject\" value=\"".$_SESSION[$DraftSubject]."\"><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 type=hidden name=DraftsOption value=\"edit\">
		<input name=\"Upload\" type=\"submit\" value=\"$MSG_Upload\">
		</form><br><br>
		<a href=\"".$_SERVER['PHP_SELF']."?modul=".$curmodul."&SelectNL=$NLID&DraftsOption=edit\">$MSG_Abort_Upload</a>
		";

    }
   
    if($_REQUEST["DraftsOption"]=="preview")
    {
	$_SESSION[$DraftBody]=$_REQUEST[$DraftBody];
	$_SESSION[$DraftSubject]=$_REQUEST[$DraftSubject];
	$_SESSION[$DraftType]=$_REQUEST[$DraftType];

	
	if($_SESSION[$DraftType]=="html")
	{       
		
		
	    print "<b>".$TXT_Subject."</b> <input type =text value=\"".$_SESSION[$DraftSubject]."\" size=50 readonly></font><br>";
		

	    print "<iframe src='previewNL.php?what=draft' 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_previewDraftSelect." <select  name=\"DraftsOption\" >";
	    print "<option value=\"edit\" selected>".stripslashes($TXT_DraftsOption_Edit)."</option>";
	    if($_SESSION[$CurrentDraft]!="new")
	    {
		print "<option value=\"save\">".stripslashes($TXT_DraftsOption_save)."</option>";
	    }
	    print "<option value=\"save_new\">".stripslashes($TXT_DraftsOption_savenew)."</option>";
	    print "<option value=\"\">".stripslashes($TXT_DraftsOption_draftsMenu)."</option>";
	    print "</select> <input type=submit value=\"OK\"></form></font></p>";
		
	}
	else
	{	
		
		print "<h2>$TXT_previewDraft_Title</h2>";
		print "<p><b>".$TXT_Subject."</b> <input type=text size=35 value=\"".$_SESSION[$DraftSubject]."\" readonly>";

		print "<br><br><b>".$TXT_Mailtext."</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[$DraftBody]));
		    print "</textarea>";
		}
		else
		{
		    print "<textarea cols=\"65\" rows=\"12\" readonly>";
		    print htmlentities($_SESSION[$DraftBody]);
		    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_previewDraftSelect." <select  name=\"DraftsOption\" >";
		print "<option value=\"edit\" selected>".stripslashes($TXT_DraftsOption_Edit)."</option>";
		if($_SESSION[$CurrentDraft]!="new")
		{
		    print "<option value=\"save\">".stripslashes($TXT_DraftsOption_save)."</option>";
		}
		print "<option value=\"save_new\">".stripslashes($TXT_DraftsOption_savenew)."</option>";
		 print "<option value=\"\">".stripslashes($TXT_DraftsOption_draftsMenu)."</option>";
		print "</select> <input type=submit value=\"OK\"></form></font></p>";
	
		
	}
	
    }

}
else
{
      print $ErrorNLdoesnotExist;
} 
?>
Return current item: ADbNewsSender