)
{
$uid = "$_";
}
flock(CF, 8);
close(CF);
$new_number = $uid + 1;
open(CF, ">$counter_file");
flock(CF, 2);
print CF "$new_number";
flock(CF, 8);
close(CF);
open(DF, ">>$data_file_path");
flock(DF, 2);
$new_line .= "$uid\|";
$new_line .= "$shortdate\|";
$new_line .= "$form_data{'name'}\|";
$new_line .= "$form_data{'email'}\|";
$new_line .= "$form_data{'subject'}\|";
$form_data{'body'} =~ s/\n/
/g;
$form_data{'body'} =~ s/\r/ /g;
$form_data{'body'} =~ s/\r\r//g;
$form_data{'body'} =~ s/\|/:/g;
$new_line .= "$form_data{'body'}\|";
$new_line .= "$form_data{'notify_me'}\|";
$new_line .= "$form_data{'post_type'}\|";
$new_line .= "$form_data{'link_url'}\|";
$new_line .= "$form_data{'link_title'}\|";
$new_line .= "$form_data{'image_url'}\|";
$new_line .= "$form_data{'parent'}\|";
$new_line .= "$form_data{'children'}\|";
$new_line .= "$replies\|";
$new_line .= "$forum_name\n";
print DF "$new_line";
@notify = $new_line; # set an array with the reply record
flock(DF, 8);
close(DF);
# here we need to modify the record of the message this is a reply to.
# fields updated are the children and replies fields.
unless (open(DATAFILE, "$data_file_path")) {
die ("cannot open database file $data_file_path \n");
} # end unless
flock(DATAFILE, 2);
while (($data_line = ))
{
@fields = split(/\|/, $data_line); # Splits the record into fields
$match_number = $fields[0];
if ($match_number eq $record_to_modify) {
$fields[12] .= "$uid,"; # sets the child field to the follow up message number
$fields[13] += 1; # increment this number by one
push(@notify, join("\|", @fields));
}
push(@database_rows, join("\|", @fields)); # just rewrite the record to the database array
} # end while
flock(DATAFILE, 8);
close(DATAFILE);
# now write the new database array to the datafile
unless (open(DATAFILE, ">$data_file_path")) {
die ("cannot open database file $data_file_path \n");
}
flock(DATAFILE, 2);
foreach $record (@database_rows) {
print DATAFILE "$record";
} # end foreach
flock(DATAFILE, 8);
close(DATAFILE);
# send the email notification
&send_notification(@notify);
&display_default; # goes back to the main screen
} # end of function
#--------------------#
# Post a new message #
#--------------------#
sub post_message
{
$replies = 0; # The default is zero, record updates will alter this
# get the current counter number and index it
if (-e "$counter_file") {
open(CF, "$counter_file");
flock(CF, 2);
while ()
{
$uid = "$_";
}
flock(CF, 8);
close(CF);
} else {
$uid = 0;
}
$new_number = $uid + 1;
open(CF, ">$counter_file");
flock(CF, 2);
print CF "$new_number";
flock(CF, 8);
close(CF);
open(DF, ">>$data_file_path");
flock(DF, 2);
$new_line .= "$uid\|";
$new_line .= "$shortdate\|";
$new_line .= "$form_data{'name'}\|";
$new_line .= "$form_data{'email'}\|";
$new_line .= "$form_data{'subject'}\|";
$form_data{'body'} =~ s/\n/
/g;
$form_data{'body'} =~ s/\r/ /g;
$form_data{'body'} =~ s/\r\r//g;
$form_data{'body'} =~ s/\|/:/g;
$new_line .= "$form_data{'body'}\|";
$new_line .= "$form_data{'notify_me'}\|";
$new_line .= "$form_data{'post_type'}\|";
$new_line .= "$form_data{'link_url'}\|";
$new_line .= "$form_data{'link_title'}\|";
$new_line .= "$form_data{'image_url'}\|";
$new_line .= "$form_data{'parent'}\|";
$new_line .= "$form_data{'children'}\|";
$new_line .= "$replies\|";
$new_line .= "$forum_name\n";
print DF "$new_line";
flock(DF, 8);
close(DF);
&display_default; # goes back to the main display
} # end function
#-----------------------------------------------------------------------#
# send email notification #
# Send the origonal poster an email telling them someone posted a reply #
#-----------------------------------------------------------------------#
sub send_notification
{
local (@arg_list) = @_;
($follow_up, $parent) = @arg_list;
@parent_fields = split(/\|/, $parent);
@follow_up_fields = split(/\|/, $follow_up);
$follow_up_number = "message_number\=$follow_up_fields[0]";
$options = "forum_name\=$forum_name";
# does the parent want to receive a notification
if ($parent_fields[6] == 1) {
open(MAIL, "|$mail_program -t")|| die "Can't open $mail_program!\n";
print MAIL "From: $admin_email ($admin_name)\n";
print MAIL "Reply-To: $admin_email ($admin_name)\n";
print MAIL "Errors-to: $admin_email ($admin_name)\n";
print MAIL "To: $parent_fields[3]\n";
print MAIL "Subject: $notify_subject\n\n";
print MAIL "I just wanted to let you know that $follow_up_fields[2] ($follow_up_fields[3])\n";
print MAIL "has posted a reply at the $forum_title dialogue to the posting entitled ";
print MAIL "$parent_fields[4], which was originally posted by $parent_fields[2] ($parent_fields[3]) ";
print MAIL " on $parent_fields[1].\n\n";
print MAIL "You can read this reply right now by going to this URL:\n";
print MAIL "$databoard_url?$options&$follow_up_number\n \n";
print MAIL "Regards,\n";
print MAIL "$admin_name.\n";
close (MAIL);
} # end if
} # end function
#---------------------------------------------------#
# forum power search #
# this searches forums from the db_TalkToMe program #
#---------------------------------------------------#
sub forum_power_search
{
# Make sure the user supplied reasonable data in the entry fields.
# Also set the how many types variable.
$how_many_types = 0;
if($form_data{'limit_view'}) {
if ($form_data{'limit_view'} =~ /\d/) {
$how_many_types += 1;
} else {
&error_control("Invalid Character - Field requires numeric characters only.");
} # end else
} # end if
if ($form_data{'poster_name'}) {
if ($form_data{'poster_name'} =~ /[\w]+/) {
$how_many_types += 1;
} else {
&error_control("Invalid Character - Field requires alpha characters only.");
} # end else
} # end if
if ($form_data{'keywords'}) {
if ($form_data{'keywords'} =~ /[\w]+/) {
@words = split(/\s+/, $form_data{'keywords'});
$how_many_types += 1;
} else {
&error_control("Invalid Character - Field requires alpha characters only.");
} # end else
} # end if
# do we want to search
if ($how_many_types == 0) {
&error_control("Invalid - No search cryteria was specified.");
} # end if
# Now we need to decide where we are going to search.
push (@forums_to_search, $form_data{'forum_name'});
# Start results output.
&page_header;
print qq~
Power Search Results |
The search results are grouped by forum. Click the message link to
view the message in a new window.
|
~;
# Start the initial searching logic
# Begin looping through the list of forums to search.
# For each forum we will create a two dimensional array to use as the search target.
@name_result = ();
@date_result = ();
@keyword_result = ();
foreach (@forums_to_search) {
$this_file = "$_.data";
$current_name = "$_";
open (FDF, "$this_file" );
flock(FDF, 2);
while ( ) {
if ($_ !~ /^COMMENT:/) {
@tmp = split(/\|/);
push @DFA, [ @tmp ];
}
}
flock(FDF, 8);
close(FDF);
# Search for a name
if ($form_data{'poster_name'}) {
for $i ( 0 .. $#DFA) {
if ($DFA[$i][2] =~ /$form_data{'poster_name'}/i) {
push (@name_result, $i);
}
}
}
if ($form_data{'limit_view'} ne "") {
$i = 0;
$oldest = (&today() - $form_data{'limit_view'});
for $i ( 0 .. $#DFA) {
$day_jv = &jday(substr($DFA[$i][1],0,2),substr($DFA[$i][1],3,2),substr($DFA[$i][1],6,4));
if ($day_jv >= $oldest) {
push (@date_result, $i);
}
}
}
if ($form_data{'keywords'}) {
@keywords = split(/\s+/, $form_data{'keywords'});
if ($form_data{'boolean'} eq "any") {
$i = 0;
for $i ( 0 .. $#DFA) {
foreach $word (@keywords) {
if ($form_data{'case'}) {
# Case sensitive
if ("@{$DFA[$i]}" =~ /\b$word\b/) {
push (@keyword_result, $i);
last;
}
} else {
#case insensitive
if ("@{$DFA[$i]}" =~ /\b$word\b/i) {
push (@keyword_result, $i);
last;
}
}
}
}
} else {
# All keywords
$i = 0;
for $i ( 0 ..$#DFA) {
$match = 1;
foreach $word (@keywords) {
if ($match == 1) {
if ($form_data{'case'}) {
# Case sensitive
if ("@{$DFA[$i]}" =~ /\b$word\b/) {
$match = 1;
next;
} else {
$match = 0;
last;
}
} else {
# case insensitive
if ("@{$DFA[$i]}" =~ /\b$word\b/i) {
$match = 1;
next;
} else {
$match = 0;
last;
}
}
}
}
if ($match == 1) {
push (@keyword_result, $i);
}
}
}
}
# Now we need to process the results depending if this was a single search
# or a multiple cryteria search.
if ($how_many_types == 1) {
# This was a single type of search. Populate the Results array with
# any matches from any single type of search.
push (@Results, @date_result);
push (@Results, @name_result);
push (@Results, @keyword_result);
} elsif ($how_many_types == 2) {
# This was a multiple type of search. We need to filter the single
# results to find those records that matched in each type of search.
print "starting the 2 type logic ";
if ($form_data{'poster_name'} && $form_data{'limit_view'}) {
foreach $N (@name_result) {
foreach $D (@date_result) {
if ($N eq $D) {
push (@Results, $N);
}
}
}
} elsif ($form_data{'poster_name'} && $form_data{'keywords'}) {
foreach $N (@name_result) {
foreach $K (@keyword_result) {
if ($N eq $K) {
push (@Results, $N);
}
}
}
} elsif ($form_data{'limit_view'} && $form_data{'keywords'}) {
foreach $D (@date_result) {
foreach $K (@keyword_result) {
if ($D eq $K) {
push (@Results, $D);
}
}
}
}
} else {
# All Three cryteria
foreach $N (@name_result) {
foreach $D (@date_result) {
if ($N eq $D) {
push (@Hold, $N);
}
}
}
# before we continue, if nothing matched we can exit here.
if (@Hold) {
foreach $H (@Hold) {
foreach $K (@keyword_result) {
if ($H eq $K) {
push (@Results, $H);
}
}
}
}
}
# We should have now populated the array Results IF we matched all the requested
# cryteria. if it's blank, we didn't pass all the tests.
# output the matching records
print qq~
$current_name |
~;
if ($Results[0] ne "") {
foreach (@Results) {
print qq~
$DFA[$_][4]
- $DFA[$_][2] $DFA[$_][1] ($DFA[$_][13]) |
~;
}
} else {
print qq~
[ No matching records ] |
~;
}
# Reset the arrays to no elements
undef (@name_result);
undef (@date_result);
undef (@keyword_result);
undef (@Results);
undef (@Hold);
undef (@DFA);
} # end of main foreach forum
# End the output, finish up the table
print qq~
[ return to $forum_title ] |
|
~;
# page footer here
&page_footer;
} # end forum power search function
######################################
#
# verify_fields
sub verify_fields
{
if ($form_data{'name'} eq "" || $form_data{'email'} eq "" || $form_data{'subject'} eq "" || $form_data{'body'} eq "") {
&error_control("Required Field Missing - Minimum fields are Name, Email, Subject, Message.");
} # end if
} # end verify fields
######################################
#
# Clean the incomming field data to remove unwanted characters.
# Added 8-2-99
sub clean_input
{
@field_names = ("name",
"email",
"subject",
"body",
"notify_me",
"post_type",
"link_url",
"link_title",
"image_url",
"parent",
"children",
"forum_name" );
foreach (@field_names) {
$form_data{$_} =~ s/\|/|/g;
$form_data{$_} =~ s/\{/}/g;
$form_data{$_} =~ s/\}/{/g;
$form_data{$_} =~ s/\(/(/g;
$form_data{$_} =~ s/\)/)/g;
$form_data{$_} =~ s/\[/[/g;
$form_data{$_} =~ s/\]/]/g;
$form_data{$_} =~ s/\~/~/g;
$form_data{$_} =~ s/\$/$/g;
$form_data{$_} =~ s/\|/|/g;
}
} # end function
#---------------------------------------------------------------#
# Error Control Function #
# Provides a standard error reporting utility to display errors #
# to the browser. #
#---------------------------------------------------------------#
sub error_control
{
local ($error_msg) = @_;
&page_header;
print qq~
error control |
something screwed up. please use your browsers back
button and correct the problem. |
details:
$error_msg
|
if you continue to have trouble
e-mail the administrator |
~;
&page_footer;
exit;
} # end error control function