Location: PHPKode > projects > ADbNewsSender > ADbNewsSender 2.1.0/protected/archive.php.inc
<?php
//File: archive.php.inc
//Last change in version: 2.1 Alpha 1
/*
    ******************************************************************************
    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/
    ******************************************************************************

*/
//don't change anything unless you realy know what you are doing!

include "$path_to_protected_folder/skeleton/public_apis.class.php.inc";
$path_to_DB_defs="$path_to_protected_folder/skeleton/includes/db_defs/";
$path_to_DB_conf="$path_to_protected_folder/database/DBconf.php.inc";

$MyDB = new ADBNS_DB($path_to_DB_defs,$path_to_DB_conf);
$lang="";
$MyCFG=new global_config_ro($MyDB);
//trying to override the time zone:
$MyCFG->setTimeZone();

$NLID=intval($_REQUEST["NewsletterID"]);
if(!$NLID || !$MyCFG->NL_exists($NLID))
{
    //no archive has been selected, preparing for archive selection:

    if($archive_selection_language=="global")
    {
	$lang=$MyCFG->get_config_value("Language");
    }
    else
    {
	$lang=$archive_selection_language;
	if(!file_exists($path_to_protected_folder."/localization/lang/$lang/lang-archive.php.inc"))
	{
	    $lang=$MyCFG->get_config_value("Language");
	}
    }
    
    include $path_to_protected_folder."/localization/lang/$lang/lang-archive.php.inc";
 
   //getting available archives:
    $nl_array=array();
    $nl_array=$MyCFG->get_all_newsletters();
    
    //now let's see where the archive is enabled and put the available archives in an array
    $archive_array=array();
    $i=0;
    $j=0;
    while ($i <count($nl_array))
    {
	
	$MyNL=new pub_Newsletter($nl_array[$i], $MyDB);
	if($MyNL->get_NLconfig_setting("Archive_enabled")=="yes")
	{
	   
	    $archive_array[$j]=array();
	    $archive_array[$j]["id"]=$nl_array[$i];
	    $archive_array[$j]["name"]=$MyNL->get_NLconfig_setting("NL_name");
	    $j++;
	}
	$i++;
    }
    if(count($archive_array) <1)
    {
	//no archives available
	print "<H2$ERR_NoArchiveAvailable</h2>";
    }
    else
    {
	//loading layout file:
	if(!file_exists($ArchiveSelectionLayout))
	{
	    die("<h1>".preg_replace("/<-file->/",$ArchiveSelectionLayout,$ERR_CouldNotOpenLayoutFile)."</h1>");
	}
	$Layout=file($ArchiveSelectionLayout);
	$Layout=implode("\n",$Layout);
	//preparing  messages:
	$Layout=preg_replace("/<-TXTPleaseSelectArchive->/",$MSG_SelectArchive,$Layout);
	$Layout=preg_replace("/<-TXTSubmit->/",$MSG_Submit,$Layout);
	$Layout=preg_replace("/<-ThisFile->/",$_SERVER["PHP_SELF"],$Layout);
	
	//preparing archive option list:
	$Optionlist="<option value=\"0\">$MSG_PleaseSelect</option>\n";
	$i=0;
	
	while($i < count($archive_array))
	{
	    $Optionlist=$Optionlist."<option value=\"".$archive_array[$i]["id"]."\">".$archive_array[$i]["name"]."</option>\n";
	    $i++;
	}
	$Layout=preg_replace("/<-ArchiveList->/",$Optionlist,$Layout);
	print $Layout;
    }
}
else
{
    $EntryID=intval($_REQUEST["EntryID"]);
    if(!$EntryID || $EntryID <1)
    {
	
	
	//no Entry has been selected.
	$MyNL=new pub_Newsletter($NLID, $MyDB);
	
	if(!file_exists($path_to_protected_folder."/localization/lang/".$MyNL->get_NLconfig_setting("Language")."/lang-archive.php.inc"))
	{
	    include $path_to_protected_folder."/localization/lang/".$MyCFG->get_config_value("Language")."/lang-archive.php.inc";
	}
	else{
	    include $path_to_protected_folder."/localization/lang/".$MyNL->get_NLconfig_setting("Language")."/lang-archive.php.inc";
	}
	if($MyNL->get_NLconfig_setting("Archive_enabled") !="yes")
	{
	    die("<h2>".preg_replace("/<-ArchiveURL->/",$MyCFG->get_config_value("ArchiveURL"),$ERR_Archive_does_not_exist)."</h2>");
	}
	//try to open the headline layout file:
	if(!file_exists($ArchiveHeadlineLayoutfile))
	{
	    die("<h1>".preg_replace("/<-file->/",$ArchiveHeadlineLayoutfile,$ERR_CouldNotOpenLayoutFile)."</h1>");
	}
	$Layout=file($ArchiveHeadlineLayoutfile);
	$Layout=implode("\n",$Layout);
	//preparing messages and texts:

	$ArchiveName=preg_replace("/<-ArchiveName->/",$MyNL->get_NLconfig_setting("NL_name"),$MSG_Archive_Title);
	$Layout=preg_replace("/<-ArchiveName->/",$ArchiveName,$Layout);
	$Layout=preg_replace("/<-ArchiveURL->/",$MyCFG->get_config_value("ArchiveURL"),$Layout);
	
	$Layout=preg_replace("/<-ThisFile->/",$_SERVER["PHP_SELF"],$Layout);
	$Layout=preg_replace("/<-TXT_Back_to_Archive_selection->/",$MSG_BackToArchiveSelection,$Layout);
	$Layout=preg_replace("/<-TXTChangeYear->/",$TXT_ChangeYEAR,$Layout);
	$Layout=preg_replace("/<-NLID->/",$NLID,$Layout);
	//Creating public Archive Opbject:
	$MyArchive =new pub_Archive($NLID, $MyDB);
	
	$ViewMonth=intval($_REQUEST["ViewMonth"]);
	$ChangeYear=intval($_REQUEST["ChangeYear"]);
	if(!$ChangeYear || $ChangeYear < $MyArchive->get_earliest_year() || $ChangeYear >date("Y"))
	{
	    $ChangeYear=date("Y");
	    $ViewMonth=date("n");
	  
	}
	if(!$ViewMonth || $ViewMonth < 1 || $ViewMonth >12)
	{
	    if ($ChangeYear==date("Y"))
	    {
		$ViewMonth=date("n");
	    }
	    else
	    {
		$ViewMonth=12;
	    }
	   
	}
	if($ChangeYear ==date("Y") && $ViewMonth >date("n"))
	{
	    $ViewMonth=date("n");
	}
	//preparing month list
	if($ChangeYear ==date("Y"))
	{
	    $endmonth=date("n");
	}
	else
	{
	    $endmonth=12;
	}
	$monthlist="";
	
	$i=$endmonth;
	while ($i >=1)
	{
	    $addToMonthlist ="<a href=\"".$_SERVER["PHP_SELF"]."?NewsletterID=$NLID&ViewMonth=$i&ChangeYear=$ChangeYear\">".$Month[$i-1]."</a>";
	    if($i ==$ViewMonth)
	    {
		$addToMonthlist="<b>".$addToMonthlist."</b>";
	    }
	    $monthlist=$monthlist." $addToMonthlist ";
	   
	    if($i >1)
	    {
		$monthlist=$monthlist."|";
	    }
	    $i--;
	}
	$Layout=preg_replace("/<-MonthList->/",$monthlist,$Layout);
	//preparing yearlist
	$earliestYear=$MyArchive->get_earliest_year();
	$i=date("Y");
	$yearlist="";
	while($i >=$earliestYear)
	{
	    $addtoYearlist="<option value=\"$i\"";
	    if($i ==$ChangeYear)
	    {
		$addtoYearlist=$addtoYearlist." selected";
	    }
	    $addtoYearlist=$addtoYearlist.">$i</option>\n";
	    $yearlist=$yearlist.$addtoYearlist;
	    $i--;
	}
	$Layout=preg_replace("/<-SelectYearList->/",$yearlist,$Layout);

	//Now getting headlines:
	if($MyArchive->get_number_of_entries_of_month($ViewMonth,$ChangeYear) <1)
	{
	    //no entries available
	    
	    $Layout=preg_replace("/<-Headlines->/",$ERR_Headline_NoNLAvailable_in_Month,$Layout);
	}
	else
	{
	    $Headlines=array();
	    $Headlines=$MyArchive->get_entries_of_month($ViewMonth,$ChangeYear);
	    
	    $Headlines_text="";
	    $i=0;
	    $ArchiveHeadline=preg_replace("/<-TimeZone->/",$MyCFG->get_timezone(),$ArchiveHeadline);
	    
	    while($i < count($Headlines))
	    {

		$EntryDate=date($DateformatHeadline,$Headlines[$i]["date"]);
		$EntrySubject="<a href=\"".$_SERVER["PHP_SELF"]."?NewsletterID=$NLID&EntryID=".$Headlines[$i]["id"]."\">".$Headlines[$i]["subject"]."</a>";
		$AddToHeadline=preg_replace("/<-NLSubject->/",$EntrySubject,$ArchiveHeadline);
		$AddToHeadline=preg_replace("/<-NLDate->/",$EntryDate,$AddToHeadline);

		$Headlines_text=$Headlines_text.$AddToHeadline;    
		$i++;
	    }
	    $Layout=preg_replace("/<-Headlines->/",$Headlines_text,$Layout);
	   
	}
	 //printing headlines:
	 print $Layout;

    }
    else
    {
	//An Entry has been selected:
	$MyNL=new pub_Newsletter($NLID, $MyDB);
	if(!file_exists($path_to_protected_folder."/localization/lang/".$MyNL->get_NLconfig_setting("Language")."/lang-archive.php.inc"))
	{
	    include $path_to_protected_folder."/localization/lang/".$MyCFG->get_config_value("Language")."/lang-archive.php.inc";
	}
	else{
	    include $path_to_protected_folder."/localization/lang/".$MyNL->get_NLconfig_setting("Language")."/lang-archive.php.inc";
	}
	
	if($MyNL->get_NLconfig_setting("Archive_enabled") !="yes")
	{
	    die("<h2>".preg_replace("/<-ArchiveURL->/",$MyCFG->get_config_value("ArchiveURL"),$ERR_Archive_does_not_exist)."</h2>");
	}
	$MyArchive= new pub_Archive($NLID, $MyDB);

	//fetching entry:
	$Entry=array();    
	$Entry=$MyArchive->get_entry_data($EntryID);
	$HeadlinesURL=$MyCFG->get_config_value("ArchiveURL")."?NewsletterID=$NLID&ViewMonth=".date("n",$Entry["date"])."&ChangeYear=".date("Y",$Entry["date"]); 
	//does the entry exist?
	if(count($Entry) <1)
	{
	    //no, dieing:
	    die(preg_replace("/<-HeadlinesURL->/",$HeadlinesURL,$ERR_Entry_does_Not_Exist));
	}
	//try to open the headline layout file:
	if(!file_exists($ViewArchiveEntryLayoutfile))
	{
	    die("<h1>".preg_replace("/<-file->/",$ViewArchiveEntryLayoutfile,$ERR_CouldNotOpenLayoutFile)."</h1>");
	}
	$Layout=file($ViewArchiveEntryLayoutfile);
	$Layout=implode("\n",$Layout);
	
	//prepare texts and messages
	$ArchiveName=preg_replace("/<-ArchiveName->/",$MyNL->get_NLconfig_setting("NL_name"),$MSG_Archive_Title);
	$Layout=preg_replace("/<-ArchiveName->/",$ArchiveName,$Layout);
	$Layout=preg_replace("/<-BacktoHeadlinesLink->/","<a href=\"$HeadlinesURL\">$MSG_Backlink</a>",$Layout);
	$Layout=preg_replace("/<-TXTSubject->/",$TXT_Subject,$Layout);
	$Layout=preg_replace("/<-TXTDate->/",$TXT_Date,$Layout);
	$Layout=preg_replace("/<-TXTMessage->/",$TXT_Message,$Layout);
	
	//preparing entry data:
	$Layout=preg_replace("/<-PrintNLSubject->/",$Entry["subject"],$Layout);
	$Layout=preg_replace("/<-PrintNLDate->/",date($DateformatViewEntry,$Entry["date"]),$Layout);
	$EntryURL=$MyCFG->get_config_value("ArchiveURL")."?NewsletterID=$NLID&EntryID=$EntryID";
	$Entry["message"]=preg_replace("/\[ArchiveEntryURL\]/",$EntryURL,$Entry["message"]);
	$Entry["message"]=preg_replace("/\[UnsubscribeLink\]/","",$Entry["message"]);
	
	if($Entry["type"]=="html")
	{
	  $Iframe="<iframe src=\"$HTML_Archive_DisplayFile?NLID=$NLID&EntryID=$EntryID\" $HTML_Archive_IFrameOptions><a href=\"$HTML_Archive_DisplayFile?NLID=$NLID&EntryID=$EntryID\">$MSG_ClickHere</a></iframe>";
	   $Layout=preg_replace("/<-PrintNLBody->/", $Iframe,$Layout);
	}
	else
	{
	   $TextArea="<Textarea $HTML_Archive_TEXT_AreaOptions>".$Entry["message"]."</textarea>";
	   $Layout=preg_replace("/<-PrintNLBody->/",$TextArea,$Layout);
	}

	print $Layout;
    }

}
?> 
Return current item: ADbNewsSender