#! /usr/bin/perl -w
#
########################################
#
#	displays prayer page for DTN site
#	written by benjamin ramey
#	bsr@rameydesign.net
#	april, 2004
#
########################################

$data_file = "./data/prayer_data.txt";

print "Content-type: text/html\n\n";

&Print_Top_HTML;

&Carters_Min_Cal;
&Email_Updates;
&Prayer_Letters;

&Print_Bottom_HTML;

################################################################################################################################################
#	SUB ROUTINES FOR DYNAMIC HTML
################################################################################################################################################

sub Carters_Min_Cal
{
	my $travel_data = './data/travel_data.txt';
	my $in_section = 0;
	my $moment_counter = 0;
	my $cur_date = 0;
	
	print <<"HTML";
		<table class="section_table" cellpadding="0" cellspacing="0" border="0">
        		<tr>
        			<td class="corner">&nbsp;</td>
        			<td class="header" align="left">Carter's Ministry Calendar&nbsp;&nbsp;&nbsp;<span class="top_anchor"><a name="carters_ministry_cal" href="#top">&nbsp;</a></span>
			</td>
        			<td>&nbsp;</td>
        		</tr>
        		<tr>
        			<td align="left" valign="top">&nbsp;</td>
        			<td colspan="2" class="content_column">
			<b>The last six Carter's Missionary Moments</b>
			<ul>
HTML
	
	open( INFILE, $travel_data ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $travel_data.</span>";
	
		while( (my $fl = <INFILE>) && ($moment_counter <= 6) )
		{
			if( $fl =~ m/<cartercalender>/ ) { $in_section = 1; }
			if( $fl =~ m/<\/cartercalender>/ ) { $in_section = 0; }
			
			if( ($fl =~ m/<date>(.*)<\/date>/ ) && $in_section ) { $cur_date = $1; }
		
			if( ($fl =~ m/<file>(.*)<\/file>/) && $in_section )
			{
				print "<li><a href=\"javascript:void(0)\" onclick=\"window.open( '$1', '_blank', 'height=400, width=600, scrollbars=yes' )\">$cur_date</a></li>\n";
				$moment_counter++;
			}
		}
	
	close( INFILE );

	print <<"HTML";
			</ul>
			</td>
        		</tr>
        		</table>
HTML
}

sub Email_Updates
{
	print <<"HTML";
		<table class="section_table" cellpadding="0" cellspacing="0" border="0">
        		<tr>
        			<td class="corner">&nbsp;</td>
        			<td class="header" align="left">E-mail Updates&nbsp;&nbsp;&nbsp;<span class="top_anchor">/ <a name="email_updates" href="#top">top</a> /</span>
			</td>
        			<td>&nbsp;</td>
        		</tr>
        		<tr>
        			<td align="left" valign="top">&nbsp;</td>
        			<td colspan="2" class="content_column">
        			<b>None for now!  Check back later.</b>
HTML
	

	print <<"HTML";
			</td>
        		</tr>
        		</table>
HTML
}

sub Prayer_Letters
{
	print <<"HTML";
		<table class="section_table" cellpadding="0" cellspacing="0" border="0">
        		<tr>
        			<td class="corner">&nbsp;</td>
        			<td class="header" align="left">Prayer Letter&nbsp;&nbsp;&nbsp;<span class="top_anchor">/ <a name="prayer_letter" href="#top">top</a> /</span>
			</td>
        			<td>&nbsp;</td>
        		</tr>
        		<tr>
        			<td align="left" valign="top">&nbsp;</td>
        			<td colspan="2" class="content_column">
HTML

		opendir( PL_DIR, "./prayer_pages/prayer_letters/" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open correct directory.</span>";
		
			my @letters = readdir PL_DIR;
			my $newest_date = 'first';
			my $youngest_file = 0;
			
			foreach my $letter ( @letters )
			{
				my $cur_date = -M $letter;
				
				if( ($newest_date > $cur_date) ||  ($newest_date eq 'first') ) { $newest_date = $cur_date; $youngest_file = $letter; }	
			}
			
			print "<a href='javascript:void(0)' onclick=\"window.open( './prayer_pages/prayer_letters/$youngest_file', '_blank', 'height=600, width=800, scrollbars=yes, resizeable=yes' )\">Click here to read the latest prayer letter</a>.\n";
		
		closedir( PL_DIR );
	
		print <<"HTML";
			</td>
        		</tr>
        		</table>
HTML
}


	
################################################################################################################################################
#	SUB ROUTINES FOR PRINTING GENERIC HTML
################################################################################################################################################

##############displays top of media page##############
sub Print_Top_HTML
{
	print <<"HTML";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Disciple the Nations - Prayer Requests</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="dtn.css" />
<link rel="stylesheet" type="text/css" href="dtn_prayer.css" />

<SCRIPT SRC="ssm.js" language="JavaScript1.2">

//Dynamic-FX slide in menu v6.5 (By maXimus, maximus@nsimail.com)
//Site: http://maximus.ravecore.com/
//For full source, and 100's more DHTML scripts, visit http://www.dynamicdrive.com

</SCRIPT>
<SCRIPT SRC="ssmItems_prayer.js" language="JavaScript1.2"></SCRIPT>
<script language="javascript" type="text/javascript" src="random_verse.js"></script>

</head>

<body>
<a name="top"></a>
<div align="left">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
	<td class="first_strip" colspan="3"><a name="#top"><img src="graphics/spacer.gif" border="0" width="1" height="10" /></a></td>
</tr>
<tr>
	<td class="second_strip_top" colspan="3"><img src="graphics/spacer.gif" border="0" width="1" height="10" /></td>
</tr>
<tr>
	<td align="left" colspan="2">
	<table cellpadding="0" cellspacing="0" border="0" width="100%">
	<tr>
		<td>&nbsp</td>
		<td align="right">
			<span style="font-size: 12px; margin-right: 10px" align="center">
				<a href="home.htm" class="location">home</a> | 
				<a href="whoweare.pl" class="location">who we are</a> | 
				<a href="resources.pl" class="location">resources</a> | 
				<a href="prayer.pl" class="location">prayer requests</a> | 
				<a href="travel.pl" class="location">mission & travel</a> | 
				<a href="media.pl" class="location">photos/videos</a>
			</span>
		</td>
	</tr>
	</table>
	</td>
	<td><img src="graphics/spacer.gif" border="0" width="1" height="20" /></td>
</tr>
<tr>
	<td valign="top" style="background-image: url( graphics/prayer/sidebar_bg.gif );" width="195">
		<img src="graphics/prayer/sidebar_dtn_logo.gif" /><br />
		<img src="graphics/prayer/sidebar_prayer.gif" />
	</td>
	<td width="100%" valign="top" class="content_table" align="left">
		<table cellpadding="0" cellspacing="0" style="margin-top: 2px" width="100%">
		<tr>
			<td valign="bottom" align="left">
				<img src="graphics/prayer/prayer_title.gif" /> <br />
				<span class="location" style="margin-left: 15px;">
				<script language="javascript" type="text/javascript">
				<!--
					Random_Verse();
				//-->
				</script>
				</span></td>
		</tr>
		<tr>
			<td align="center">
			<table cellpadding="0" cellspacing="0" width="100%" class="sub_link_div">
			<tr>
				<td align="center">
				<a href="#carters_ministry_cal" class="sub_link_table">carter's ministry calendar</a> |
				 <a href="#email_updates" class="sub_link_table">e-mail updates</a> | 
				 <a href="#prayer_letter" class="sub_link_table">prayer letter</a></td>
			</tr>
			</table>
			</td>
		</tr>
		</table>
HTML
}


##############displays bottom of media page##############
sub Print_Bottom_HTML
{
	print <<"HTML";
</td>
	<td><img src="graphics/spacer.gif" width="15" height="1" /></td>
</tr>
<tr>
	<td><img src="graphics/spacer.gif" border="0" width="1" height="20" /></td>
	<td align="center" style="padding: 5px 0px 5px 0px">
		<span style="font-size: 12px" align="center">
			<a href="whoweare.pl">who we are</a> | 
			<a href="resources.pl">resources</a> | 
			<a href="prayer.pl">prayer requests</a> | 
			<a href="travel.pl">mission & travel</a> | 
			<a href="media.pl">photos/videos</a>
		</span>
	</td>
	<td>&nbsp;</td>
</tr>
<tr>
	<td class="second_strip_bottom" colspan="3"><img src="graphics/spacer.gif" border="0" width="1" height="10" /></td>
</tr>
<tr>
	<td class="first_strip" colspan="3">all site content copyright of Disciple the Nations, all rights reserved | site designed by <a href="http://www.rameydesign.net" target="_blank" class="first_strip">ramey design</a></td>
</tr>
</table>
</div>
</body>
</html>

HTML
}






