Files
d-t-n.org/archive/version_01/dtn.cgi
2017-03-02 21:36:05 -06:00

1677 lines
62 KiB
Perl
Executable File

#! /usr/bin/perl
#
########################################
#
# script to edit DTN site content
# written by benjamin ramey
# bsr@rameydesign.net
# january, 2004
#
########################################
if( $ENV{ 'REQUEST_METHOD' } eq 'POST' )
{
read( STDIN, $buffer, $ENV{ 'CONTENT_LENGTH' } );
@pairs = split( /&/, $buffer ); #split form contents into name=value pairs
foreach $pair ( @pairs ) #step through the array @pairs
{
( $name, $value ) = split( /=/, $pair); #split each pair into the form element name and that form element's value
$name =~ tr/+/ /; #replace all the + signs with spaces
$value =~ tr/+/ /;
$name =~ s/%(..)/pack( "C", hex( $1 ) )/eg; #replace all hexidecimal characters with their corresponding, easier to understand characters
$value =~ s/%(..)/pack( "C", hex( $1 ) )/eg;
if( $contents{ $name } ) #in case there is a multiple-select scroll down menu this will append a value to an already existing key instead of reassigning it
{
$contents{ $name } .= "\t$value";
}
else{ $contents{ $name } = $value; } #but, normally, we'll just assign the value in the hash to it's corresponding key
}
}
#####################################################################################################################################################################
# MAIN PROGRAM
#####################################################################################################################################################################
if( $contents{ 'file' } ) { $file_path = $contents{ 'file' }; }
else { $file_path = "nothing yet"; }
$username = "warren4";
$password = "john316";
print "Content-type: text/html\n\n";
&Print_Top_HTML; #always need to display at least this
&Password;
&Print_Bottom_HTML; #and we always need to display this
exit;
##############
############## DISPLAYS PASSWORD PAGES, SO ONLY WARREN CAN ACCESS EDITING SECTIONS
##############
sub Password
{
if( !$contents{ 'username' } && !$contents{ 'file' } )
{
print<<"HTML";
<table class="section_table" cellpadding="0" cellspacing="0" border="0" width="95%">
<tr>
<td class="corner">&nbsp;</td>
<td class="header" align="left"><!--TITLE-->Edit DTN<!--END_TITLE-->&nbsp;&nbsp;&nbsp;<span class="top_anchor"><a name="edit_dtn" 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>Please enter the following information before you start editing DtN.</b><br /> <br />
<form action="dtn.cgi" method="post">
<b>Username: </b><input type="text" size="15" name="username" /><br />
<b>Password: </b><input type="password" size="15" name="password" /><br />
<input type="submit" value="Submit" />
</form>
</td>
</tr>
</table>
HTML
}
elsif( $contents{ 'username' } && !$contents{ 'file' } )
{
if( ($contents{ 'username' } eq $username) && ($contents{ 'password' } eq $password) )
{
&Display_Edit_Choice; #if the username and password are correct, go on to display the editing choice
}
else
{
print<<"HTML";
<table class="section_table" cellpadding="0" cellspacing="0" border="0" width="95%">
<tr>
<td class="corner">&nbsp;</td>
<td class="header" align="left"><!--TITLE-->Edit DTN<!--END_TITLE-->&nbsp;&nbsp;&nbsp;<span class="top_anchor"><a name="edit_dtn" href="#top">&nbsp;</a></span></td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="left" valign="top">&nbsp;</td>
<td colspan="2" class="content_column">
<span style='font-weight: bold; color: red'>ERROR: Either your username or password was not entered correctly.
Please make sure you typed them in correctly. Both username and password are case sensitive!!</span>
<form action="dtn.cgi" method="post">
<input type="submit" value="Try Again" />
</form>
</td>
</tr>
</table>
HTML
}
}
else
{
if( $file_path ne 'nothing yet' ) #if file_path exists, a page to edit has been chosen and the contents of the page can be collected and displayed
{
if( $file_path eq 'media' ) { &Media_Edit; }
elsif( $file_path eq 'travel' ) { &Travel_Edit; }
elsif( $file_path eq 'randomverse' ) { &Random_Verses; }
else
{
print<<"HTML";
<table class="section_table" cellpadding="0" cellspacing="0" border="0" width="95%">
<tr>
<td class="corner">&nbsp;</td>
<td class="header" align="left">Edit DTN&nbsp;&nbsp;&nbsp;<span class="top_anchor"><a name="edit_dtn" href="#top">&nbsp;</a></span></td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="left" valign="top">&nbsp;</td>
<td colspan="2" class="content_column"><span style='font-weight: bold; color: red'>ERROR: This section not yet editable.</span>
</td>
</tr>
</table>
HTML
}
}
else { &Display_Edit_Choice; } #if there is not file_path a file to edit needs to be chosen, so display the choice page
}
}
##############
############## DISPLAYS THE PAGE WHERE YOU CHOOSE WHAT PAGE TO EDIT
##############
sub Display_Edit_Choice
{
print <<"HTML";
<table class="section_table" cellpadding="0" cellspacing="0" border="0" width="95%">
<tr>
<td class="corner">&nbsp;</td>
<td class="header" align="left"><!--TITLE-->Edit DTN<!--END_TITLE-->&nbsp;&nbsp;&nbsp;<span class="top_anchor"><a name="edit_dtn" href="#top">&nbsp;</a></span></td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="left" valign="top">&nbsp;</td>
<td colspan="2" class="content_column">
<form action="./dtn.cgi" method="post">
<b>Please select which page to edit:</b><br />
<select name="file">
<option value="randomverse">Add/Edit Random Verses</option>
<option value="./whoweare.htm">Who We Are</option>
<option value="./resources.htm">Resources</option>
<option value="./prayer.htm">Prayer Requests</option>
<option value="travel">Travel Info</option>
<option value="media">Photos / Videos</option>
</select>
<input type="submit" name="submit_btn" value="Choose" /><br />&nbsp;<br />
<b>Currently editing:</b> $file_path</b>
</form><br />
<b>To update the links list on the "Resources" page, click below.</b><br />
<input type="button" value="Update Links" onclick="window.open( 'links.pl', '_blank', 'width=200, height=100' )" />
</td>
</tr>
</table>
HTML
}
#####################################################################################################################################################################
# SUB ROUTINES FOR EDITING THE MEDIA PAGE
#####################################################################################################################################################################
##############
############## MAIN BRAIN OF MEDIA EDITING SECTIONS
##############
sub Media_Edit
{
&Display_Edit_Choice;
print <<"HTML";
<table class="section_table" cellpadding="0" cellspacing="0" border="0" width="95%">
<tr>
<td class="corner">&nbsp;</td>
<td class="header" align="left">Edit Media Page</td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="left" valign="top">&nbsp;</td>
<td colspan="2" class="content_column">
HTML
if( !$contents{ 'media_edit_action' } )
{
print <<"HTML";
<b>Choose what you would like to do:</b><br />
<form action="./dtn.cgi" method="post">
<input type="hidden" value="media" name="file" />
<input type="radio" value="delete_album" name="media_edit_action" /> <b>Delete a photo album from media page</b><br />
<input type="radio" value="add_album" name="media_edit_action" /> <b>Add a photo album to media page</b><br />
<input type="radio" value="edit_album" name="media_edit_action" /> <b>Edit an existing photo album on media page</b><br />
<input type="radio" value="delete_video" name="media_edit_action" /> <b>Delete a video from media page</b><br />
<input type="radio" value="add_video" name="media_edit_action" /> <b>Add a video to media page</b><br />
<input type="radio" value="edit_video" name="media_edit_action" /> <b>Edit an existing video on media page</b>
<br />&nbsp;<br />
<input type="submit" name="submit_btn" value="Choose" /><br />
</form>
HTML
}
elsif( $contents{ 'media_edit_action' } eq 'delete_album' )
{
&Media_Edit_Delete_Album;
}
elsif( $contents{ 'media_edit_action' } eq 'add_album' )
{
&Media_Edit_Add_Album;
}
elsif( $contents{ 'media_edit_action' } eq 'edit_album' )
{
&Media_Edit_Edit_Album;
}
elsif( $contents{ 'media_edit_action' } eq 'delete_video' )
{
&Media_Edit_Delete_Video;
}
elsif( $contents{ 'media_edit_action' } eq 'add_video' )
{
&Media_Edit_Add_Video;
}
elsif( $contents{ 'media_edit_action' } eq 'edit_video' )
{
&Media_Edit_Edit_Video;
}
print <<"HTML";
</td>
</tr>
</table>
HTML
}
##############
############## DEALS WITH DELETING A PHOTO ALBUM
##############
sub Media_Edit_Delete_Album
{
my $data_file = "./data/media_data.txt";
###########################gather info for album deletion
if( !$contents{ 'which_album' } ) #if the user has not chosen an album to delete yet, then gather all the albums and print appropriate
{ #HTML for him to choose one--perl is pretty straight forward here
my $in_albums = 0;
print "<b>Choose which album you would like to delete:</b><br />\n";
print "<form action=\"./dtn.cgi\" method=\"post\">\n";
print "<select name=\"which_album\">\n";
open( INFILE, "$data_file" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $data_file.</span>";
while( my $file_line = <INFILE> )
{
if( $file_line =~ m/<albumsection>/ ) { $in_albums = 1; }
if( $file_line =~ m/<\/albumsection>/ ) { $in_albums = 0; }
if( ($file_line =~ m/<name>(.*)<\/name>/) && $in_albums )
{
print "<option value=\"$1\">$1</option>\n";
}
}
close( INFILE );
print "</select>\n";
print "<input type=\"hidden\" value=\"delete_album\" name=\"media_edit_action\" />\n";
print "<input type=\"hidden\" value=\"media\" name=\"file\" />\n";
print "<input type=\"submit\" value=\"Delete Album\" name=\"submit_btn\" />\n";
print "</form>\n";
}
###########################process deletion of album
elsif( $contents{ 'which_album' } )
{
my $in_albums = 0;
my $file_name = 0;
require Tie::File;
tie( @file_lines, 'Tie::File', $data_file ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $data_file file.</span>";
for( my $i = 0; $i <= $#file_lines; $i++ )
{
if( $file_lines[ $i ] =~ m/<albumsection>/ ) { $in_albums = 1; } #just to make sure, if there is another data type (like a video) with the same name
if( $file_lines[ $i ] =~ m/<\/albumsection>/ ) { $in_albums = 0; } #it doesn't get deleted too
if( ($file_lines[ $i ] =~ m/<name>$contents{ 'which_album' }<\/name>/) && $in_albums )
{
$file_name = $file_lines[ $i + 1 ];
splice( @file_lines, ($i - 1), 6 );
}
}
untie( @file_lines );
$file_name =~ s/.*<link>album_(.*)<\/link>.*/$1/; #delete the related files when deleting an album
my @files = ( "./photo_albums/album_$file_name", "./photo_albums/images_$file_name", "./photo_albums/index_$file_name" );
unlink( @files ) or print $!;
print<<"HTML";
<b>Album $contents{ 'which_album' } deleted! Click <a href='media.pl'>here</a> to view the Photos/Videos page to make sure everything went according to plan.</b><br /><br />
Remember that, if you just deleted a nested album, you need to delete the link to the deleted album from the album it was nested in.<br /> <br />
To continue editing, please select a page to edit at the top of this page.
HTML
}
}
##############
############## DEALS WITH ADDING A PHOTO ALBUM
##############
sub Media_Edit_Add_Album
{
my $data_file = "./data/media_data.txt";
my $in_albums = 0;
my $k = 0;
open( INFILE, "$data_file" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $data_file.</span>";
while( my $file_line = <INFILE> )
{
if( $file_line =~ m/<albumsection>/ ) { $in_albums = 1; }
if( $file_line =~ m/<\/albumsection>/ ) { $in_albums = 0; }
if( ($file_line =~ m/<name>(.*)<\/name>/) && $in_albums )
{
$albums[ $k ] = $1;
}
if( ($file_line =~ m/<link>(.*)<\/link>/) && $in_albums ) #these arrays are used later to add and nest the added album
{
$links[ $k ] = $1;
$k++;
}
}
close( INFILE );
###########################gather info for new album
if( !$contents{ 'new_album_name' } )
{
print<<"HTML";
<b>Instructions:</b><br />
<ul>
<li>Album name: name that will appear on page under link to album</li>
<li>Place after album: this will determine where the album will appear on the page, ie in what order.</li>
<li>Albums folder: you must have uploaded the folder containing all the full-sized images, smaller images, and thumbnails. The smaller image
names MUST begin with "small_"; the thumbnail images MUST begin with "thumb_". This folder must already be present on the server
(ie, you've uploaded it already) before you try to make a new album. The photos MUST be labelled exactly or this script will not construct
the album pages correctly!!<br /> <br />
Guidelines for photos:<br />
thumbnails: largest dimension 100 pixels
small images: largest dimension 400 pixels
large (normal) images: largest dimension 800 pixels<br /> <br />
For the photo album pages to look good you HAVE to keep these guidelines.</li>
<li>Album inside another: if you don't want this to be a main album (ie, it won't appear on the Photos/Videos page) then choose which
main album it will be nestled in. You can also nestle new albums in already nestled albums.</li>
</ul><br />Note: An album folder must be inside the folder "/graphics/media/albums/".<br /> <br />
<b>Please enter the following information:</b><br />
<form action="./dtn.cgi" method="post">
<b>Album Name:</b><br /><input type="text" name="new_album_name" size="40" /><br /> <br />
<b>Place album after:</b><br />
<select name="first_album">
<option value="make_first">Make first album</option>
HTML
foreach my $album ( @albums )
{
print "<option value=\"$album\">$album</option>\n";
}
print "</select><br />(To put at end of list choose the last album in list. To put album at beginning of list choose \"Make first album\".)<br /> <br />\n";
print "<b>Select the album folder:</b><br /><select name=\"album_folder\">\n";
opendir( MEDIA_DIR, "./graphics/media/albums/" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open media directory.</span>";
my @media_files = grep { not m/^\.\.?\z/ } readdir MEDIA_DIR; #won't read the . and .. directories
@media_files = grep { not m/\.\w{3}?\z/ } @media_files; #weeds out the images
closedir( MEDIA_DIR );
foreach my $media_file ( @media_files )
{
unless( $media_file eq '_notes' ) { print "<option value=\"$media_file\">$media_file</option>\n"; }
}
print "</select><br />(Note: you have to have uploaded the folder containing all photos already)<br /> <br />\n";
print "<b>If this album will be inside another album, choose which it is to be inside:</b><br />\n";
print "<select name=\"inside_album\">\n";
print "<option value=\"none\">Not inside another</option>\n";
my $c = 0;
foreach my $album ( @albums )
{
print "<option value=\"$c\">$album</option>\n";
$c++;
}
print "</select><br />(If this is album will not be inside another, select the \"Not inside another\" option)<br />\n";
print<<"HTML";
<br />
<input type="hidden" value="add_album" name="media_edit_action" />
<input type="hidden" value="media" name="file" />
<input type="submit" value="Add Album" name="submit_btn" />
</form>
HTML
}
###########################processes for adding new album
elsif( $contents{ 'new_album_name' } )
{
require Tie::File;
my $inside_file = $links[ $contents{ 'inside_album' } ]; #if the album is nested inside another, the <inside></inside> info will display which index_ file it is link to from
if( $contents{ 'inside_album' } eq 'none' ) { $inside_file = "none"; } #if the album is not nested in another, the <inside></inside> info should read "none"
my $new_album = "album_$contents{ 'album_folder' }.htm"; #create all three files from the name of the image folder
my $new_index = "index_$contents{ 'album_folder' }.htm";
my $new_images = "images_$contents{ 'album_folder' }.htm";
my $new_folder = $contents{ 'album_folder' };
$new_folder =~ s/([ ,',",\\,\/,-])/sprintf( "%%%lx", (unpack( "C", $1 )) )/eg;
my @new_album = ( "\t\t<album>\n", #construct the new album lines which will be added to the data_file
"\t\t\t<name>$contents{ 'new_album_name' }</name>\n",
"\t\t\t<link>$new_album</link>\n",
"\t\t\t<inside>$inside_file</inside>\n",
"\t\t\t<imagefolder>$contents{ 'album_folder' }</imagefolder>\n",
"\t\t</album>\n" );
tie( my @file_lines, 'Tie::File', "$data_file" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $data_file.</span>";
for( my $i = 0; $i <= $#file_lines; $i++ )
{
if( ($contents{ 'first_album' } eq 'make_first') && ($contents{ 'inside_album' } eq 'none') ) #if it is to be first on the media page, slip it in at the top fo the data_file
{
if( $file_lines[ $i ] =~ m/<albumsection>/ ) { splice( @file_lines, $i, 1, ( "\t<albumsection>\n", @new_album ) ); $i = $#file_lines; }
}
elsif( $contents{ 'inside_album' } ne 'none' ) #if it is a nested album, we'll put it at the bottom of the list (since order doesn't matter for these, they won't be listed on the media page
{
if( $file_lines[ $i ] =~ m/<\/albumsection>/ )
{
splice( @file_lines, $i, 1, ( @new_album, "\t<\/albumsection>\n" ) ); $i = $#file_lines;
}
}
else #if it's not the first album, look for the album it will come after and place it after that album
{
if( $file_lines[ $i ] =~ m/<name>$contents{ 'first_album' }<\/name>/ ) { splice( @file_lines, ($i + 4), 1, ( "\t\t</album>\n", @new_album ) ); $i = $#file_lines; }
}
}
untie( @file_lines );
if( $contents{ 'inside_album' } ne 'none' )
{
my $inside_index_file = $inside_file;
$inside_index_file =~ s/album_/index_/;
#add link to nested album from parent album
tie( my @parent_file_lines, 'Tie::File', "./photo_albums/$inside_index_file" ) or print "can't open file";
for( my $w = 0; $w <= $#parent_file_lines; $w++ )
{
if( $parent_file_lines[ $w ] =~ m/<!--ALBUMS-->/ )
{
splice( @parent_file_lines, $w, 1, ( "<!--ALBUMS-->\n",
"\t<a href=\"javascript:void(0)\" onclick=\"parent.location='$new_album'\">\n",
"\t\t<img src=\"../graphics/media/album_icon.gif\" width=\"60\" height=\"53\" border=\"0\"></a><br>\n",
"\t\t$contents{ 'new_album_name' }\n",
"\t\t<br> <br>\n" ) );
$w = $#parent_file_lines; #business done, jump out of loop
}
}
untie( @parents_file_lines );
}
###########################creation of the three files needed for each album: the frameset file, index file, image file
opendir( ALBUM_DIR, "./graphics/media/albums/$contents{ 'album_folder' }/" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open new album directory.</span>";
my @album_images = grep { not m/^\.\.?\z/ } readdir ALBUM_DIR; #won't read the . and .. directories
@album_images = grep { not m/^small_/ } @album_images;
@album_images = grep { not m/^thumb_/ } @album_images;
for( my $q = 0; $q <= $#album_images; $q++ ) { $album_images[ $q ] =~ s/([ ,',",\\,\/,-])/sprintf( "%%%lx", (unpack( "C", $1 )) )/eg; }
closedir( ALBUM_DIR ); #gather all the images, change any offensive characters to readable ones, so they don't interfere with quotation marks and what-not
###########################creates frameset (album_) file
open( NEW_ALBUM, ">./photo_albums/$new_album" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not create $new_album.</span>";
print NEW_ALBUM <<"HTML";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Photo Album: $contents{ 'new_album_name' }</title>
</head>
<frameset cols="150,*" frameborder="NO" border="0" framespacing="0">
<frame src="$new_index" name="leftFrame" scrolling="yes" noresize="noresize">
<frame src="$new_images" name="mainFrame">
</frameset>
<noframes><body>
</body></noframes>
</html>
HTML
close( NEW_ALBUM );
###########################creates images file
open( NEW_IMAGES, ">./photo_albums/$new_images" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not create $new_images.</span>";
print NEW_IMAGES <<"HTML";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Photo Album: $contents{ 'new_album_name' }</title>
<script language="javascript" type="text/javascript" src="../albums.js">
</script>
</head>
<body style="background-color: #000000">
<div align="center">
<img src="../graphics/media/albums/$new_folder/small_$album_images[ 0 ]" name="main_image" id="main_image">
<br>
<br>
<span onclick="Show_Large_Photo();" style="cursor: pointer; font-weight: bold; color: #CCCCCC; font-family: Arial, Helvetica, sans-serif">Click here for larger image</span>
</div>
</body>
</html>
HTML
close( NEW_IMAGES );
###########################creates index file
open( NEW_INDEX, ">./photo_albums/$new_index" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not create $new_index.</span>";
print NEW_INDEX <<"HTML";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Photo Album: $contents{ 'new_album_name' }</title>
<style type="text/css">
body { font-family: Arial, Helvetica, sans-serif; font-size: 14px; }
img { margin: 5px 0px 5px 0px; }
a:link { font-weight: bold; color: #CCCCCC; text-decoration: none; }
a:visited { font-weight: bold; color: #CCCCCC; text-decoration: none; }
a:hover { font-weight: bold; color: #FFFFFF; text-decoration: underline; }
</style>
</head>
<body style="background-color: #000000; color: #CCCCCC; font-family:Arial, Helvetica, sans-serif; font-size: 12px;">
HTML
if( $contents{ 'inside_album' } ne 'none' ) #if this is a nested album, make sure a link to the parent album is put in at the top of the left frame
{
print NEW_INDEX <<"HTML";
<div name="parent_album" align="center"><a href="javascript:void(0)" onclick='parent.location="$inside_file"'>Back to $albums[ $contents{ 'inside_album' } ]</a></div>
<br> <br>
HTML
}
print NEW_INDEX "<div align=\"center\">\n";
print NEW_INDEX "<!--ALBUMS-->\n";
print NEW_INDEX "<!--IMAGES-->\n";
my $j = 0;
foreach ( @album_images ) #make sure the same link is put in for the thumbnail that's shown by counting through with $j
{
print NEW_INDEX "\t\t\t<a href=\"javascript:void(0)\"\n";
print NEW_INDEX "\t\t\t\tonclick=\"top.mainFrame.main_image.src='../graphics/media/albums/$new_folder/small_$album_images[ $j ]'\">\n";
print NEW_INDEX "\t\t\t\t<img src=\"../graphics/media/albums/$new_folder/thumb_$album_images[ $j ]\" border=\"0\"></a><br>\n";
$j++;
}
print NEW_INDEX "\n</div>\n</body>\n</html>";
close( NEW_INDEX );
print<<"HTML";
<b>Album added! Click <a href='media.pl'>here</a> to view the Photos/Videos page to make sure everything went according to plan.</b><br /><br />
To continue editing, please select a page to edit at the top of this page.
HTML
}
}
##############
############## DEALS WITH EDITING A PHOTO ALBUM
##############
sub Media_Edit_Edit_Album
{
my $data_file = "./data/media_data.txt";
###########################gather info for album editing
if( !$contents{ 'which_album' } ) #if the user has not chosen an album to edit yet, then gather all the albums and print appropriate
{ #HTML for him to choose one--perl is pretty straight forward here
my $in_albums = 0;
print "<b>Choose which album you would like to edit:</b><br />\n";
print "<form action=\"./dtn.cgi\" method=\"post\">\n";
print "<select name=\"which_album\">\n";
open( INFILE, "$data_file" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $data_file.</span>";
while( my $file_line = <INFILE> )
{
if( $file_line =~ m/<albumsection>/ ) { $in_albums = 1; }
if( $file_line =~ m/<\/albumsection>/ ) { $in_albums = 0; }
if( ($file_line =~ m/<name>(.*)<\/name>/) && $in_albums )
{
print "<option value=\"$1\">$1</option>\n";
}
}
close( INFILE );
print "</select>\n";
print "<input type=\"hidden\" value=\"edit_album\" name=\"media_edit_action\" />\n";
print "<input type=\"hidden\" value=\"media\" name=\"file\" />\n";
print "<input type=\"submit\" value=\"Edit Album\" name=\"submit_btn\" />\n";
print "</form>\n";
}
###########################display editing information
elsif( $contents{ 'which_album' } && !$contents{ 'new_album_name' } )
{
my $album_name = $contents{ 'which_album' };
my $album_link = 0;
my $album_inside = 0;
my $album_folder = 0;
my $album_index = 0;
my $album_images = 0;
############get album file name to access correct index and image .htm files
open( INFILE, "$data_file" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $data_file.</span>";
while( my $file_line = <INFILE> )
{
if( $file_line =~ m/<albumsection>/ ) { $in_albums = 1; }
if( $file_line =~ m/<\/albumsection>/ ) { $in_albums = 0; }
if( ($file_line =~ m/<name>$album_name<\/name>/) && $in_albums )
{
while( $file_line !~ m/<\/album>/ )
{
$file_line = <INFILE>;
if( $file_line =~ m/<link>(.*)<\/link>/ )
{
$album_link = $1;
$album_index = $album_link;
$album_images = $album_link;
$album_index =~ s/album_/index_/;
$album_images =~ s/album_/images_/;
}
if( $file_line =~ m/<inside>(.*)<\/inside>/ ) { $album_inside = $1; }
if( $file_line =~ m/<imagefolder>(.*)<\/imagefolder>/ ) { $album_folder = $1; }
}
}
}
close( INFILE );
print "<b>On the left, delete photos/nested albums from the album. On the right, edit which picture appears first when the album is opened and add images to the album.</b><br /> <br />\n";
print "Note: when deleting a nested album, you are only deleting the fact that it is nested in the album being edited. In other words, the actual nested album is not deleted.<br />\n";
print "<form action=\"./dtn.cgi\" method=\"post\">\n";
print "<b>Change album name:</b> <input type='text' name='new_album_name' value=\"$album_name\" size='40' /><br /> <br />\n";
print "<table cellpadding='5' cellspacing='0' border='1' style='font-size: 12px'>\n";
print "<tr>\n<td align='left' valign='top' width='150'>\n<b>To delete an image (or album), check its corresponding checkbox.</b><br /> <br />\n";
############open index file and display which images are in it
open( INDEX_FILE, "./photo_albums/$album_index" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open index file.</span>";
while( my $file_line = <INDEX_FILE> )
{
if( $file_line =~ m/<img src="(.*\.\w{3})".*>/ )
{
my $current_file = $1;
$current_file =~ s/\.\.\//\.\//;
if( $current_file =~ m/album_icon/ )
{
my $current_album = <INDEX_FILE>;
chomp( $current_album );
$current_album =~ s/^\s*(.*)\s*$/$1/;
print "<img src=\"$current_file\" /> <input type='checkbox' value=\"$current_album\" name='delete_album' /><br />\n";
print "<b>Album Name:</b> $current_album<br /> <br />\n";
}
else
{
print "<img src=\"$current_file\" /> <input type='checkbox' value=\"$current_file\" name='delete_thumb' /><br />\n";
$current_file =~ s/.*\/thumb_(.*\.\w{3})$/$1/;
$current_file =~ s/%(..)/pack( "C", hex( $1 ) )/eg;
print "<b>Image Name:</b><br />$current_file<br /> <br />\n";
}
}
}
close( INDEX_FILE );
print "</td>\n";
print "<td align='center' valign='top'>\n<b>To change the first image, choose which to change it too from the drop-down menu.</b><br /> <br />\n";
############open image file and display the main image there and menu to change that image
open( IMAGE_FILE, "./photo_albums/$album_images" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open images file.</span>";
while( my $file_line = <IMAGE_FILE> )
{
if( $file_line =~ m/<img src="(.*\.\w{3})".*>/ )
{
my $main_image = $1;
$main_image =~ s/\.\.\//\.\//;
print "<b>Current main image:</b><br /><img src=\"$main_image\" />\n";
}
}
close( IMAGE_FILE );
opendir( IMAGE_FOLDER, "./graphics/media/albums/$album_folder" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open images folder. Because $!</span>";
my @image_files = grep { not m/^\.\.?\z/ } readdir IMAGE_FOLDER or print "can't readdir";
@image_files = grep { m/\.\w{3}\z/ } @image_files;
@image_files = grep { not m/(thumb_)|(small_)/ } @image_files;
print "<br /><br /><b>Select new main image:</b> <select name='new_main_image'>\n";
print "<option value='same' selected='selected'>Keep Same Image</option>\n";
foreach my $image_file ( @image_files )
{
my $nice_name = $image_file;
$nice_name =~ s/([ ,',",\\,\/,\-])/sprintf( "%%%lx", (unpack( "C", $1 )) )/eg;
print "\t<option value=\"small_$nice_name\">$image_file</option>\n";
}
print "</select><br /> <br /><hr />\n";
print "<br /><b>Select which images to add:</b><br />Note: hold down the ctrl key to select multiple images<br />Note: You have to have already uploaded any new images.<br />\n";
print "<select size='10' name='additional_images' multiple='multiple'>\n";
print "<option value='none' selected='selected'>Add None</option>\n";
foreach my $image_file ( @image_files )
{
my $nice_name = $image_file;
$nice_name =~ s/([ ,',",\\,\/,\-])/sprintf( "%%%lx", (unpack( "C", $1 )) )/eg;
print "\t<option value=\"$nice_name\">$image_file</option>\n";
}
print "</select>\n";
closedir( IMAGE_FOLDER );
print "</td>\n";
print "</tr>\n</table><br /> <br />\n";
print "<input type='hidden' value=\"$album_link\" name='album_link' />\n";
print "<input type='hidden' value=\"$album_folder\" name='album_folder' />\n";
print "<input type='hidden' value=\"$album_name\" name='old_name' />\n";
print "<input type='hidden' value=\"$contents{ 'which_album' }\" name='which_album' />\n";
print "<input type=\"hidden\" value=\"edit_album\" name=\"media_edit_action\" />\n";
print "<input type=\"hidden\" value=\"media\" name=\"file\" />\n";
print "<input type=\"submit\" value=\"Edit Album\" name=\"submit_btn\" />\n";
print "</form>\n";
}
###########################applies edited information for editing albums
elsif( $contents{ 'which_album' } && $contents{ 'new_album_name' } )
{
require Tie::File;
my $album_index = $contents{ 'album_link' };
my $album_images = $contents{ 'album_link' };
my $file_friendly_folder = $contents{ 'album_folder' };
$file_friendly_folder =~ s/([ ,',",\\,\/,\-])/sprintf( "%%%lx", (unpack( "C", $1 )) )/eg;
$album_index =~ s/album_/index_/;
$album_images =~ s/album_/images_/;
my @edited_album = ( "\t\t\t<name>$contents{ 'new_album_name' }</name>\n" );
tie( my @file_lines, 'Tie::File', "$data_file" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $data_file.</span>";
for( my $i = 0; $i <= $#file_lines; $i++ )
{
if( $file_lines[ $i ] =~ m/<name>$contents{ 'old_name' }<\/name>/ ) { splice( @file_lines, $i, 1, @edited_album ); }
}
untie( @file_lines );
my @new_images = split( /\t/, $contents{ 'additional_images' } );
my @deleted_images = split( /\t/, $contents{ 'delete_thumb' } );
my @deleted_albums = split( /\t/, $contents{ 'delete_album' } );
tie( my @file_lines, 'Tie::File', "./photo_albums/$album_index" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $new_index_file.</span>";
for( my $i = 0; $i <= $#file_lines; $i++ )
{
$file_lines[ $i ] =~ s/<title>.*<\/title>/<title>$contents{ 'new_album_name' } Album<\/title>/;
if( $file_lines[ $i ] =~ m/<!--IMAGES-->/ ) { $images_line_no = $i; }
for( my $k = 0; $k <= $#deleted_albums; $k++ )
{
if( $file_lines[ $i ] =~ m/$deleted_albums[ $k ]/ ) { splice( @file_lines, ($i - 2), 4 ); }
}
for( my $c = 0; $c <= $#deleted_images; $c++ )
{
if( $file_lines[ $i ] =~ m/$deleted_images[ $c ]/ ) { splice( @file_lines, ($i - 1), 3 ); }
}
}
if( $contents{ 'additional_images' } ne 'none' )
{
my @new_images_lines;
for( my $v = 0; $v <= $#new_images; $v++ )
{
push( @new_images_lines, ( "\t<a href=\"javascript:void(0)\"\n",
"\t\tonclick=\"top.mainFrame.main_image.src='../graphics/media/albums/$file_friendly_folder/small_$new_images[ $v ]'\">\n",
"\t\t<img src=\"../graphics/media/albums/$file_friendly_folder/thumb_$new_images[ $v ]\" border=\"0\"></a><br>\n" ) );
}
splice( @file_lines, $images_line_no, 1, ( "<!--IMAGES-->", @new_images_lines ) );
}
untie( @file_lines );
tie( my @file_lines, 'Tie::File', "./photo_albums/$album_images" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $new_images_file.</span>";
for( my $x = 0; $x <= $#file_lines; $x++ )
{
$file_lines[ $x ] =~ s/<title>.*<\/title>/<title>$contents{ 'new_album_name' } Album<\/title>/;
if( $contents{ 'new_main_image' } ne 'same' )
{
if( $file_lines[ $x ] =~ m/<img src=".*" name="main_image"(.*)>/ ) { $file_lines[ $x ] = "<img src=\"../graphics/media/albums/$file_friendly_folder/$contents{ 'new_main_image' }\" name=\"main_image\"$1>"; }
}
}
untie( @file_lines );
print<<"HTML";
<b>Editing done! Click <a href='media.pl'>here</a> to view the Photos/Videos page to make sure everything went according to plan.</b><br /><br />
To continue editing, please select a page to edit at the top of this page.
HTML
}
}
##############
############## DEALS WITH DELETING A VIDEO
##############
sub Media_Edit_Delete_Video
{
my $data_file = "./data/media_data.txt";
###########################gather info for which video to delete
if( !$contents{ 'which_video' } ) #if the user has not chosen an album to delete yet, then gather all the albums and print appropriate
{ #HTML for him to choose one--perl is pretty straight forward here
my $in_videos = 0;
print "<b>Choose which video you would like to delete:</b><br />\n";
print "<form action=\"./dtn.cgi\" method=\"post\">\n";
print "<select name=\"which_video\">\n";
open( INFILE, "$data_file" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $data_file.</span>";
while( my $file_line = <INFILE> )
{
if( $file_line =~ m/<videosection>/ ) { $in_videos = 1; }
if( $file_line =~ m/<\/videosection>/ ) { $in_videos = 0; }
if( ($file_line =~ m/<name>(.*)<\/name>/) && $in_videos )
{
print "<option value=\"$1\">$1</option>\n";
}
}
close( INFILE );
print "</select>\n";
print "<input type=\"hidden\" value=\"delete_video\" name=\"media_edit_action\" />\n";
print "<input type=\"hidden\" value=\"media\" name=\"file\" />\n";
print "<input type=\"submit\" value=\"Delete Video\" name=\"submit_btn\" />\n";
print "</form>\n";
}
###########################process video deletion
elsif( $contents{ 'which_video' } )
{
my $in_videos = 0;
my $file_name = 0;
require Tie::File;
tie( @file_lines, 'Tie::File', $data_file ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $data_file file.</span>";
for( my $i = 0; $i <= $#file_lines; $i++ )
{
if( $file_lines[ $i ] =~ m/<videosection>/ ) { $in_videos = 1; } #just to make sure, if there is another data type (like a video) with the same name
if( $file_lines[ $i ] =~ m/<\/videosection>/ ) { $in_videos = 0; } #it doesn't get deleted too
if( ($file_lines[ $i ] =~ m/<name>$contents{ 'which_video' }<\/name>/) && $in_videos )
{
$file_name = $file_lines[ $i + 1 ];
splice( @file_lines, ($i - 1), 6 );
}
}
untie( @file_lines );
$file_name =~ s/.*<link>(.*)<\/link>.*/$1/;
unlink "./video_pages/$file_name";
print<<"HTML";
<b>Video $contents{ 'which_video' } deleted! Click <a href='media.pl'>here</a> to view the Photos/Videos page to make sure everything went according to plan.</b><br /><br />
To continue editing, please select a page to edit at the top of this page.
HTML
}
}
##############
############## DEALS WITH ADDING A VIDEO
##############
sub Media_Edit_Add_Video
{
my $data_file = "./data/media_data.txt";
my $in_videos = 0;
my $k = 0;
open( INFILE, "$data_file" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $data_file.</span>";
while( my $file_line = <INFILE> )
{
if( $file_line =~ m/<videosection>/ ) { $in_videos = 1; }
if( $file_line =~ m/<\/videosection>/ ) { $in_videos = 0; }
if( ($file_line =~ m/<name>(.*)<\/name>/) && $in_videos )
{
$names[ $k ] = $1;
}
if( ($file_line =~ m/<link>(.*)<\/link>/) && $in_videos )
{
$links[ $k ] = $1;
}
if( ($file_line =~ m/<image>(.*)<\/image>/) && $in_videos )
{
$images[ $k ] = $1;
$k++;
}
}
close( INFILE );
###########################gather info for new video
if( !$contents{ 'new_video_name' } )
{
print<<"HTML";
<b>Instructions:</b><br />
<ul>
<li>Video name: name that will appear on page under link to the video</li>
<li>Place after video: this will determine where the video will appear on the page, ie in what order.</li>
<li>Video file: this is the actual video. It MUST be uploaded to the folder "/graphics/media/video_clips/"</li>
<li>Thumbnail image: this is the image that appears on the Photos/Videos page representing the movie. It MUST be uploaded
to the folder "/graphics/media/video_thumbs/". Suggested size: largest dimension no larger than 100 pixels. </li>
</ul><br /> <br />
<b>Please enter the following information:</b><br />
<form action="./dtn.cgi" method="post">
<b>Video Name:</b><br /><input type="text" name="new_video_name" size="40" /><br /> <br />
<b>Place video after:</b><br />
<select name="first_video">
<option value="make_first">Make first video</option>
HTML
foreach my $name ( @names )
{
print "<option value=\"$name\">$name</option>\n";
}
print "</select><br />(To put at end of list choose the last video in list. To put video at beginning of list choose \"Make first video\".)<br /> <br />\n";
print "<b>Select which video file:</b><br /><select name=\"video_file\">\n";
opendir( MEDIA_DIR, "./graphics/media/video_clips/" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open video_clips directory.</span>";
my @media_files = grep { not m/^\.\.?\z/ } readdir MEDIA_DIR; #won't read the . and .. directories
closedir( MEDIA_DIR );
foreach my $media_file ( @media_files )
{
unless( $media_file eq 'WS_FTP.LOG' ) { print "<option value=\"$media_file\">$media_file</option>\n"; }
}
print "</select><br />(Note: you have to have uploaded the video already)<br /> <br />\n";
print "<b>Select which thumbnail image:</b><br /><select name=\"video_thumb\">\n";
opendir( MEDIA_DIR, "./graphics/media/video_thumbs/" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open video_thumbs directory.</span>";
my @media_files = grep { not m/^\.\.?\z/ } readdir MEDIA_DIR; #won't read the . and .. directories
closedir( MEDIA_DIR );
foreach my $media_file ( @media_files )
{
unless( $media_file eq 'WS_FTP.LOG' ) { print "<option value=\"$media_file\">$media_file</option>\n"; }
}
print "</select><br />(Note: you have to have uploaded the video thumbnail already)<br /> <br />\n";
print<<"HTML";
<br />
<input type="hidden" value="add_video" name="media_edit_action" />
<input type="hidden" value="media" name="file" />
<input type="submit" value="Add Video" name="submit_btn" />
</form>
HTML
}
###########################process info for new video
elsif( $contents{ 'new_video_name' } )
{
require Tie::File;
tie( @file_lines, 'Tie::File', "$data_file" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $data_file.</span>";
$contents{ 'video_file' } =~ s/(\.\w{3})//;
my $extension = $1;
my @new_video = ( "\t\t<video>\n",
"\t\t\t<name>$contents{ 'new_video_name' }</name>\n",
"\t\t\t<file>$contents{ 'video_file' }$extension</file>\n",
"\t\t\t<link>video_$contents{ 'video_file' }.htm</link>\n",
"\t\t\t<image>graphics/media/video_thumbs/$contents{ 'video_thumb' }</image>\n",
"\t\t</video>\n" );
for( my $i = 0; $i <= $#file_lines; $i++ )
{
if( $contents{ 'first_video' } eq 'make_first' )
{
if( $file_lines[ $i ] =~ m/<videosection>/ ) { splice( @file_lines, $i, 1, ( "\t<videosection>\n", @new_video ) ); }
}
else { if( $file_lines[ $i ] =~ m/<name>$contents{ 'first_video' }<\/name>/ ) { splice( @file_lines, ($i + 3), 1, ( "\t\t</video>\n", @new_video ) ); } }
}
untie( @file_lines );
open( VIDEO_FILE, ">./video_pages/video_$contents{ 'video_file' }.htm" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not create new video file.</span>";
print VIDEO_FILE <<"HTML";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Video: $contents{ 'new_video_name' }</title>
</head>
<body style="background-color: #000000">
<div align="center">
<embed src="../graphics/media/video_clips/$contents{ 'video_file'}$extension" width="320" height="255" pluginspage="http://www.apple.com/quicktime/"></embed>
</div>
</body>
</html>
HTML
close( VIDEO_FILE );
print<<"HTML";
<b>Video $contents{ 'new_video_name' } added! Click <a href='media.pl'>here</a> to view the Photos/Videos page to make sure everything went according to plan.</b><br /><br />
To continue editing, please select a page to edit at the top of this page.
HTML
}
}
##############
############## DEALS WITH EDITING A VIDEO
##############
sub Media_Edit_Edit_Video
{
my $data_file = "./data/media_data.txt";
my $in_videos = 0;
my $k = 0;
open( INFILE, "$data_file" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $data_file.</span>";
while( my $file_line = <INFILE> )
{
if( $file_line =~ m/<videosection>/ ) { $in_videos = 1; }
if( $file_line =~ m/<\/videosection>/ ) { $in_videos = 0; }
if( ($file_line =~ m/<name>(.*)<\/name>/) && $in_videos )
{
$names[ $k ] = $1;
}
if( ($file_line =~ m/<file>(.*)<\/file>/) && $in_videos )
{
$videos[ $k ] = $1;
}
if( ($file_line =~ m/<link>(.*)<\/link>/) && $in_videos )
{
$links[ $k ] = $1;
}
if( ($file_line =~ m/<image>(.*)<\/image>/) && $in_videos )
{
$images[ $k ] = $1;
$k++;
}
}
close( INFILE );
if( !$contents{ 'which_video_edit' } && !$contents{ 'new_video_name' } )
{
print<<"HTML";
<form action="./dtn.cgi" method="post">
<b>Please choose which video to edit:</b><br /> <br />
<select name="which_video_edit">
HTML
foreach my $name ( @names )
{
print "<option value=\"$name\">$name</option>\n";
}
print "</select>\n";
print "<input type=\"hidden\" value=\"edit_video\" name=\"media_edit_action\" />\n";
print "<input type=\"hidden\" value=\"media\" name=\"file\" />\n";
print "<input type=\"submit\" value=\"Choose Video\" name=\"submit_btn\" />\n";
print "</form>\n";
}
elsif( $contents{ 'which_video_edit' } && !$contents{ 'make_edit' } )
{
my $current_name = $contents{ 'which_video_edit' };
my $current_after = 0;
my $current_video = 0;
my $current_link = 0;
my $current_image = 0;
for( my $k = 0; $k <= $#names; $k++ )
{
if( $names[ $k ] eq $current_name )
{
if( $k == 0 )
{
$current_after = "Make first video";
}
else{ $current_after = $names[ $k - 1 ]; }
$current_video = $videos[ $k ];
$current_link = $links[ $k ];
$current_image = $images[ $k ];
$current_image =~ s/graphics\/media\/video_thumbs\///;
$k = $#names; #break out of loop when all our variables have been found
}
}
print<<"HTML";
<b>Instructions:</b><br />
Same as for adding a new video. What you currently have for each section is displayed after each field<br /> <br />
<b>Please enter the following information:</b><br />
<form action="./dtn.cgi" method="post">
<b>Video Name:</b><br /><input type="text" name="new_video_name" size="40" value="$current_name" /><br /> <br />
<b>Place video after:</b> (current selection: $current_after)<br />
<select name="first_video">
<option value="make_first">Make first video</option>
HTML
foreach my $name ( @names )
{
unless( $name eq $current_name ) { print "<option value=\"$name\">$name</option>\n"; }
}
print "</select><br />(To put at end of list choose the last video in list. To put video at beginning of list choose \"Make first video\".)<br /> <br />\n";
print "<b>Select which video file:</b> (current selection: $current_video)<br /><select name=\"video_file\">\n";
opendir( MEDIA_DIR, "./graphics/media/video_clips/" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open video_clips directory.</span>";
my @media_files = grep { not m/^\.\.?\z/ } readdir MEDIA_DIR; #won't read the . and .. directories
closedir( MEDIA_DIR );
foreach my $media_file ( @media_files )
{
my $nice_name = $media_file;
$nice_name =~ s/([ ,',",\\,\/,\-])/sprintf( "%%%lx", (unpack( "C", $1 )) )/eg;
print "<option value=\"$nice_name\">$media_file</option>\n";
}
print "</select><br />(Note: you have to have uploaded the video already)<br /> <br />\n";
print "<b>Select which thumbnail image:</b> (current selection: $current_image)<br /><select name=\"video_thumb\">\n";
opendir( MEDIA_DIR, "./graphics/media/video_thumbs/" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open video_thumbs directory.</span>";
my @media_files = grep { not m/^\.\.?\z/ } readdir MEDIA_DIR; #won't read the . and .. directories
closedir( MEDIA_DIR );
foreach my $media_file ( @media_files )
{
my $nice_name = $media_file;
$nice_name =~ s/([ ,',",\\,\/,\-])/sprintf( "%%%lx", (unpack( "C", $1 )) )/eg;
print "<option value=\"$nice_name\">$media_file</option>\n";
}
print "</select><br />(Note: you have to have uploaded the video thumbnail already)<br /> <br />\n";
print<<"HTML";
<br />
<input type="hidden" value="edit_video" name="media_edit_action" />
<input type="hidden" value="$current_name" name="old_name" />
<input type="hidden" value="$current_link" name="old_link" />
<input type="hidden" value="media" name="file" />
<input type="submit" value="Edit Video" name="submit_btn" />
</form>
HTML
}
elsif( $contents{ 'new_video_name' } )
{
my $in_videos = 0;
my $deleted = 0;
require Tie::File;
tie( @file_lines, 'Tie::File', "$data_file" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $data_file.</span>";
$contents{ 'video_file' } =~ s/(\.\w{3})//;
my $extension = $1;
my @new_video = ( "\t\t<video>\n",
"\t\t\t<name>$contents{ 'new_video_name' }</name>\n",
"\t\t\t<file>$contents{ 'video_file' }$extension</file>\n",
"\t\t\t<link>video_$contents{ 'video_file' }.htm</link>\n",
"\t\t\t<image>graphics/media/video_thumbs/$contents{ 'video_thumb' }</image>\n",
"\t\t</video>\n" );
for( my $i = 0; $i <= $#file_lines; $i++ )
{
if( $file_lines[ $i ] =~ m/<videosection>/ ) { $in_videos = 1; } #just to make sure, if there is another data type (like a video) with the same name
if( $file_lines[ $i ] =~ m/<\/videosection>/ ) { $in_videos = 0; } #it doesn't get deleted too
if( ($file_lines[ $i ] =~ m/<name>$contents{ 'old_name' }<\/name>/) && $in_videos && !$deleted )
{
splice( @file_lines, ($i - 1), 6 );
$deleted = 1;
}
if( $contents{ 'first_video' } eq 'make_first' )
{
if( $file_lines[ $i ] =~ m/<videosection>/ ) { splice( @file_lines, $i, 1, ( "\t<videosection>\n", @new_video ) ); $i += 4; }
}
elsif( $in_videos ) { if( $file_lines[ $i ] =~ m/<name>$contents{ 'first_video' }<\/name>/ ) { splice( @file_lines, ($i + 4), 1, ( "\t\t</video>\n", @new_video ) ); $i += 7; } }
}
untie( @file_lines );
unlink "./video_pages/$contents{ 'old_link' }";
open( VIDEO_FILE, ">./video_pages/video_$contents{ 'video_file' }.htm" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not create new video file.</span>";
print VIDEO_FILE <<"HTML";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Video: $contents{ 'new_video_name' }</title>
</head>
<body style="background-color: #000000">
<div align="center">
<embed src="../graphics/media/video_clips/$contents{ 'video_file'}$extension" width="320" height="255" pluginspage="http://www.apple.com/quicktime/"></embed>
</div>
</body>
</html>
HTML
close( VIDEO_FILE );
print<<"HTML";
<b>Video $contents{ 'new_video_name' } edited! Click <a href='media.pl'>here</a> to view the Photos/Videos page to make sure everything went according to plan.</b><br /><br />
To continue editing, please select a page to edit at the top of this page.
HTML
}
}
#####################################################################################################################################################################
# SUB ROUTINES FOR EDITING THE TRAVEL PAGE
#####################################################################################################################################################################
##############
############## MAIN BRAIN OF TRAVEL PAGE EDITING
##############
sub Travel_Edit
{
&Display_Edit_Choice;
print <<"HTML";
<table class="section_table" cellpadding="0" cellspacing="0" border="0" width="95%">
<tr>
<td class="corner">&nbsp;</td>
<td class="header" align="left">Edit Mission & Travel Page</td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="left" valign="top">&nbsp;</td>
<td colspan="2" class="content_column">
HTML
if( !$contents{ 'travel_edit_action' } )
{
print <<"HTML";
<b>Choose what you would like to do:</b><br />
<form action="./dtn.cgi" method="post">
<input type="hidden" value="travel" name="file" />
<input type="radio" value="cmm" name="travel_edit_action" /> <b>Add a Carter's Ministry Moments</b><br />
<br />&nbsp;<br />
<input type="submit" name="submit_btn" value="Choose" /><br />
</form>
HTML
}
elsif( $contents{ 'travel_edit_action' } eq 'cmm' )
{
&Travel_Edit_Add_CMM;
}
print <<"HTML";
</td>
</tr>
</table>
HTML
}
##############
############## DEALS WITH ADDING A CARTER'S MINISTRY MOMENT
##############
sub Travel_Edit_Add_CMM
{
my $data_file = "./data/travel_data.txt";
if( !$contents{ 'add_cmm' } )
{
print <<"HTML";
<b>Please fill out the following fields:</b><br />
<form action="./dtn.cgi" method="post">
<input type="hidden" value="travel" name="file" />
<input type="hidden" value="1" name="add_cmm" />
<input type="hidden" value="cmm" name="travel_edit_action" />
<b>Date:</b> <input type="text" name="cmm_date" /><br /> <br />
<b>Content of CMM:</b><br />
<textarea name="cmm_content" cols='50' rows='15'></textarea>
<br />&nbsp;<br />
<input type="submit" name="submit_btn" value="Add CMM" /><br />
</form>
HTML
}
elsif( $contents{ 'add_cmm' } )
{
require Tie::File;
$contents{ 'cmm_content' } =~ s/\n/<br \/>/g;
$contents{ 'cmm_content' } =~ m/(.{0,300})(\w*)\s/s;
my $cmm_summary = $1 . $2 . "...";
my $file_friendly_date = $contents{ 'cmm_date' };
$file_friendly_date =~ s/([',",\\,\/,\-])/ /g;
my $in_section = 0;
my @new_cmm = ( "\t\t<entry>\n",
"\t\t\t<date>$contents{ 'cmm_date' }</date>\n",
"\t\t\t<file>./ministry_moments/$file_friendly_date.htm</file>\n",
"\t\t\t<summary>$cmm_summary</summary>\n",
"\t\t</entry>\n" );
tie( my @file_lines, 'Tie::File', $data_file );
for( my $i = 0; $i <= $#file_lines; $i++ )
{
if( $file_lines[ $i ] =~ m/<cartercalender>/ ) { splice( @file_lines, $i, 1, ( "\t<cartercalender>\n", @new_cmm ) ); }
}
untie( @file_lines );
open( NEW_CMM, ">./ministry_moments/$file_friendly_date.htm" );
print NEW_CMM <<"HTML";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Disciple the Nations :: Carter's Ministry Moments</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body style="background-color: #999999; border-style: solid; border-width: 5px; border-color: #FFFFFF; margin: 0px; padding: 10px;">
<div align="left">
<b style="text-decoration: underline">Carter's Ministry Moments from $contents{ 'cmm_date' }</b>
<br /> <br />
$contents{ 'cmm_content' }
<br /> <br />
<input type="button" value="Close Window" onclick="window.close();" />
</div>
</body>
</html>
HTML
close( NEW_CMM );
print<<"HTML";
<b>Your new Carter's Ministry Moments has been added! Click <a href='travel.pl'>here</a> to view the Missions & Travel page to make sure everything went according to plan.</b><br /><br />
To continue editing, please select a page to edit at the top of this page.
HTML
}
}
#####################################################################################################################################################################
# SUB ROUTINES FOR EDITING THE RANDOM VERSES
#####################################################################################################################################################################
sub Random_Verses
{
&Display_Edit_Choice;
my $verse_file = "./random_verse.js";
my $in_verses = 0;
print <<"HTML";
<table class="section_table" cellpadding="0" cellspacing="0" border="0" width="95%">
<tr>
<td class="corner">&nbsp;</td>
<td class="header" align="left">Edit Random Verse List</td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="left" valign="top">&nbsp;</td>
<td colspan="2" class="content_column">
HTML
if( !$contents{ 'edit_verses' } )
{
print<<"HTML";
<b>Below all current verses in the list are listed. If you want to delete a verse, check it's corresponding checkbox.
If you want to add a verse, fill in the appropriate information at the bottom of the list where it says "Add Verse".</b><br /> <br />
<form action="./dtn.cgi" method="post">
<input type="hidden" value="randomverse" name="file" />
<input type="hidden" value="1" name="edit_verses" />
HTML
open( INFILE, $verse_file );
while( my $file_line = <INFILE> )
{
if( $file_line =~ m/~VERSES~/ ) { $in_verses = 1; }
if( $file_line =~ m/~ENDVERSES~/ ) { $in_verses = 0; }
if( ($file_line =~ m/verses\[ (\d+) \] = "<i>\\"(.*)\\"<\/i>(.*)"\;/) && $in_verses )
{
my $verse_num = $1 + 1;
print "<input type='checkbox' value='$1' name='verses_delete' /> <b>Verse $verse_num:</b> <i>$2</i> $3<br />\n";
}
}
close( INFILE );
print "\n<br />\n";
print<<"HTML";
<b>Add Verse:</b><br />
Verse: <input type="text" size="50" name="verse_text" /><br />
Reference: <input type="text" size="25" name="verse_ref" /><br /> <br />
<input type="submit" value="Edit Verses" />
</form>
HTML
}
elsif( $contents{ 'edit_verses' } )
{
require Tie::File;
my $in_verses = 0;
my $verse_counter = 0;
my $deleted = 0;
tie( my @file_lines, 'Tie::File', $verse_file ) or print "can't open file";
for( my $i = 0; $i <= $#file_lines; $i++ )
{
if( $file_lines[ $i ] =~ m/~VERSES~/ ) { $in_verses = 1; }
if( $file_lines[ $i ] =~ m/~ENDVERSES~/ )
{
$in_verses = 0;
my $new_verse = "\t\tverses[ $verse_counter ] = \"<i>\\\"$contents{ 'verse_text' }\\\"</i> $contents{ 'verse_ref' }\"\;";
if( $contents{ 'verse_text' } ) { splice( @file_lines, $i, 1, ( $new_verse, "\t\t//~ENDVERSES~" ) ); }
$i = $#file_lines;
}
if( ($file_lines[ $i ] =~ m/verses\[ $contents{ 'verses_delete' } \]/) && $in_verses && !$deleted ) { splice( @file_lines, $i, 1 ); $i--; $verse_counter--; $deleted = 1; }
if( ($file_lines[ $i ] =~ s/verses\[ \d+ \]/verses\[ $verse_counter \]/) && $in_verses ) { $verse_counter++; }
}
untie( @file_lines );
if( $contents{ 'verses_delete' } )
{
print<<"HTML";
<b>Verse(s) deleted!</b><br />
HTML
}
if( $contents{ 'verse_text' } )
{
print<<"HTML";
<b>$contents{ 'verse_ref' }</b> has been added to the list!<br />
HTML
}
}
print <<"HTML";
</td>
</tr>
</table>
HTML
}
################################################################################################################################################
# SUB ROUTINES FOR PRINTING GENERIC HTML
################################################################################################################################################
##############displays top of editing pages##############
sub Print_Top_HTML
{
print <<"HTML";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Disciple the Nations - Edit DTN</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_whoweare.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_whoweare.js" language="JavaScript1.2"></SCRIPT>
</head>
<body>
<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">travel info</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: url('graphics/whoweare/sidebar_bg.gif')">
<img src="graphics/whoweare/sidebar_dtn_logo.gif" border="0" /><br />
<img src="graphics/sidebar_editdtn.gif" />
</td>
<td width="100%" valign="top" class="content_table" align="center">
<div align="left"><img src="graphics/editdtn_title.gif" /></div>
<table cellpadding="0" cellspacing="0" width="100%" class="sub_link_div">
<tr>
<td align="center" style="font-size: 12px;">
Welcome to the DtN editing center, Mr. Carter!
</td>
</tr>
</table>
HTML
}
##############displays bottom of editing pages##############
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>&nbsp;</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
}