#!/usr/local/bin/perl # # DCGuest.cgi Version 2.1 # Release Date 15 Aug 2000 # # Modification Version: mod.2000.08.15.02 # # MODIFICATION HISTORY # # mod.2000.08.15.02 - limit pages to 10 # # mod.2000.08.15.01 - replaced flock() with manual filelock # # Written By David S. Choi, david@dcscripts.com # First Release DCGuest97, 16 November 1997 # DCGuest Version 2.1, 15 Aug 2000 # DCGuest Version 2.0, 22 July 1999 # ########## YOU MUST KEEP THIS COPYRIGHTS NOTICE INTACT ############### # Copyright ©1997-2000 DCScripts All Rights Reserved # As part of the installation process, you will be asked # to accept the terms of this Agreement. This Agreement is # a legal contract, which specifies the terms of the license # and warranty limitation between you and DCScripts and DCGuest. # You should carefully read the following terms and conditions before # installing or using this software. Unless you have a different license # agreement obtained from DCScripts, installation or use of this software # indicates your acceptance of the license and warranty limitation terms # contained in this Agreement. If you do not agree to the terms of this # Agreement, promptly delete and destroy all copies of the Software. # # Versions of the Software # You may install as many copies of DCGuest Script. # # License to Redistribute # Distributing the software and/or documentation with other products # (commercial or otherwise) or by other than electronic means without # DCScripts's prior written permission is forbidden. # All rights to the DCGuest software and documentation not expressly # granted under this Agreement are reserved to DCScripts. # # Disclaimer of Warranty # THIS SOFTWARE AND ACCOMPANYING DOCUMENTATION ARE PROVIDED "AS IS" AND # WITHOUT WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR ANY OTHER # WARRANTIES WHETHER EXPRESSED OR IMPLIED. BECAUSE OF THE VARIOUS HARDWARE # AND SOFTWARE ENVIRONMENTS INTO WHICH DCGUEST MAY BE USED, NO WARRANTY OF # FITNESS FOR A PARTICULAR PURPOSE IS OFFERED. THE USER MUST ASSUME THE # ENTIRE RISK OF USING THIS PROGRAM. ANY LIABILITY OF DCSCRIPTS WILL BE # LIMITED EXCLUSIVELY TO PRODUCT REPLACEMENT OR REFUND OF PURCHASE PRICE. # IN NO CASE SHALL DCSCRIPTS BE LIABLE FOR ANY INCIDENTAL, SPECIAL OR # CONSEQUENTIAL DAMAGES OR LOSS, INCLUDING, WITHOUT LIMITATION, LOST PROFITS # OR THE INABILITY TO USE EQUIPMENT OR ACCESS DATA, WHETHER SUCH DAMAGES ARE # BASED UPON A BREACH OF EXPRESS OR IMPLIED WARRANTIES, BREACH OF CONTRACT, # NEGLIGENCE, STRICT TORT, OR ANY OTHER LEGAL THEORY. THIS IS TRUE EVEN IF # DCSCRIPTS IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN NO CASE WILL # DCSCRIPT'S LIABILITY EXCEED THE AMOUNT OF THE LICENSE FEE ACTUALLY PAID # BY LICENSEE TO DCSCRIPTS. # ########################################################################### # Define directory path to your setup file. # Try relative path $path = "."; #-----------NO NEED TO EDIT ANYTHING BELOW THIS LINE------ require "$path/invite.setup"; require "$path/cgi-lib.cgi"; check_datafile($datafile); check_datafile($counter); # OK Let's read in formdata &ReadParse(); # Send HTTP header to the server print "Content-type: text/html\n\n"; # Format Comment input so that it will fit nicely in the database # Depending on Form input: # 1) Display add to guest form # 2) Add guest information to the database # 3) Display guests if ($in{'action'} eq "add_form") { $header = $add_guest_header; $sub_header = $add_guest_sub_header; &add_form(); } elsif ($in{'action'} eq "add_guest") { $header = $thank_you_header; $sub_header = $thank_you_sub_header; &check_required_fields; &add_guest(); &send_all_mails(); } else { $header = $display_guest_header; $sub_header = $display_guest_sub_header; &display_guests(); } &display_output(); exit(0); ####################### END OF THE MAIN PROGRAM #################### ##### # function display_guests # ##### sub display_guests { my $marker; if ($in{'marker'}) { $marker = $in{'marker'}; } else { $marker = 1; } my ($num_guests,$guest,$start_num,$stop_num) = get_guests($datafile,$marker); my $num_blocks = int(($num_guests-1)/$num_view) + 1; my $current_page = int($marker/$num_view); $html_output .= qq~

~; # mod.2000.08.15.02 # Only display 10 pages at a time if ($current_page < 5) { $start_page = 1; $stop_page = 10; } elsif ($num_blocks - $current_page < 5) { $start_page = $num_blocks - 9; $stop_page = $num_blocks; } else { $start_page = $current_page - 4; $stop_page = $current_page + 5; } $html_output .= "Page # "; unless ($start_page == 1 ) { $html_output .= ""; } else { $start_page = 1; } if ($stop_page > $num_blocks ) { $stop_page = $num_blocks; } for ($j=$start_page; $j<= $stop_page; $j++) { $j_start = ($j-1)*$num_view + 1; $j_stop = $j*$num_view; if ($j_stop > $num_guests) { $j_stop = $num_guests; } if ($start_num == $j_start) { $html_output .= " $j "; } else { $html_output .= ""; } } unless ($stop_num == $num_blocks ) { my $next_marker = ($num_blocks-1) * $num_view; $html_output .= ""; } $html_output .= qq~

~; foreach (reverse sort {$a <=> $b} keys %{$guest}){ my $temp = $guest_layout; $guest->{$_}->{'Date'} = y2k($guest->{$_}->{'Date'}); $guest->{$_}->{'Your_Email'} = "
{$_}->{'Your_Email'}\">$guest->{$_}->{'Your_Email'}" if ($guest->{$_}->{'Your_Email'}); $guest->{$_}->{'Friends_Name'} = "From $guest->{$_}->{'Friends_Name'}" if ($guest->{$_}->{'Friends_Name'}); $guest->{$_}->{'Friends_Email'} = ", $guest->{$_}->{'Friends_Email'}" if ($guest->{$_}->{'Friends_Email'}); $temp =~ s//$guest->{$_}->{$1}/g; $html_output .= $temp; } } ##### # function check_required_fields # Checks to make sure all required fields were submitted # ##### sub check_required_fields { foreach $require_field (@required_fields) { if ($in{$require_field} eq "" || $in{$required_field} eq " ") { $flag = "1"; $header = "Oops!"; $sub_header = "You must submit your name and e-mail address, and the name and e-mail address of the person to whom you wish to send the message. Please try again."; &add_form; &display_output(); &exit; } } } ##### # function add_guest # Add guest entry # ##### sub add_guest { # mod.2000.08.15.01 my $r_data = readdata($datafile); $id = &get_number(); ($date,$localtime) = &get_date(); $date = $localtime." ".$date; $in{'ID'} = $id; $in{'Date'} = $date; foreach $field (@guest_fields) { unless ($allow_html eq "yes") { $in{$field} =~ s/<([^>]|\n)*>//g; } $in{$field} =~ s/\|/\s/g; $in{$field} = remove_badwords($in{$field}); $newline .= $in{$field}."|"; } chop($newline); $newline .= "\n"; unshift(@{$r_data},$newline); # mod.2000.08.15.01 writedata($datafile,$r_data); } ##### # function remove_badwords # replaces bad words with #### # ##### sub remove_badwords { my $body = shift; foreach (@badwords) { $body =~ s/$_/####/gi; } $body; } ##### # function add_form # display form for guest entry ##### sub add_form { $html_output .= qq~ ~; foreach $guest_field (@guest_fields){ $html_output .= &table_row($guest_field,$field_input_type{$guest_field}); } $html_output .= qq~
~; } ##### # function table_entry # ##### sub table_row { my ($field,$type) = @_; my ($table_row); if ($type eq "text"){ $table_row .= qq~ $field ~; } elsif ($type eq "textarea") { $table_row .= qq~ $field ~; } $table_row; } ##### # function get_number # Get next guest ID # ##### sub get_number { my $num; # mod.2000.08.15.01 # remove the use of flock lock_file("$counter.lock"); if (open(NUMBER,"$counter")) { # First read in $num $num = ; close(NUMBER); unless ($num){ $num = 1; } else { #increment $num++; } #write back to $counter file open(NUMBER,">$counter") or my_die("Can't open $counter to write",$!); print NUMBER $num; close(NUMBER); unlock_file("$counter.lock"); } else { my_die("Error in function get_number during read",$!); } return $num; } ##### # function display_output # display output to template ##### sub display_output { my %name = ( HEADER => $header, SUBHEADER => $sub_header, HTMLOUTPUT => $html_output ); # Open template and read in open(TEMPLATE,"$booktemplate") or my_die("can't open $booktemplate",$!); { local($/) = undef; $template =