#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); package main; #use strict; #use vars qw( $calendar_type $session_file $session_name $session_email # $session_group $session_username $currentmonth $currentyear # $current_month_name $greatest_year $category $base_file # $database_file $temp_file $lock_file $db_exist $ltyear # $ltmon $ltday $lib $framecal_dir %form_data ); my( $action ) = (); # First, tell Perl to bypass the buffer. Set up binary mode for input/output # if using dos derivatives. $| = 1; if( $^O =~ /(dos|win|os2|vms)/io ) { binmode(STDIN); binmode(STDOUT); binmode(STDERR); } # LOCATE LIBRARIES # # $lib is the path to the directory containing the library files that # are used by this, and many other, scripts. Note that the line below # sets it using a relative path. On some server setups, you will have to # change this to an absolute path. $framecal_dir is the directory # that the framecal.pl, fc_admin.pl, and fc_recur.pl files are located # in. Set this to an absolute path if need be. $lib = "../libs"; $framecal_dir = "."; # GET FORM DATA # # Now we use the subroutine parse_data to get our form data # into the hash %form_data. After this, we will be able # to get all incoming form data by referencing $form_data{'variablename'}. %form_data = (); %form_data = &parse_data(); # DETERMINE CALENDAR # # Since this script allows us to keep many different calendars using one # script, we need to get the calendar to use from the form data. This # information will be stored in the key 'calendar'. We read this information # in and untaint it. Note that only alphanumeric are allowed. # In order to access this, the original link must have had ?calendar=some/dir # in the URL. If this value is omitted, we assume we are using calendar files # stored in the script directory. # After getting the calendar, we finish by requiring the calendar specific # files. if( $form_data{'calendar'} ne '' ) { $form_data{'calendar'} =~ /^(\w+\/?\w*)/o; $calendar_type = "./$1"; } else { # $calendar_type = "."; $calendar_type = "./sfbay"; } &CgiRequire( "$calendar_type/calendar.setup", "$calendar_type/auth.setup", "global.setup" ); &CgiRequire( "$auths::auth_lib/auth-lib.pl" ); $home = $form_data{'home'}; # IN MAINTENANCE # # We can place the calendar in maintenance mode by placing a text file called # 'fc_maint.txt' in the calendar's directory. This allows us to do admin tasks # such as working manually with the database files, uploading new copies of the # program, etc., while keeping the calendar locked out. if( -e "$calendar_type/fc_maint.txt" ) { &header( "Calendar Unavailable" ); print qq!
I'm sorry, but the calendar is currently unavailable due to system maintenance. Please try back in 15 minutes.!; &footer; } else { # SESSION FILE # # The session file is used on every pass through the script, to determine # who is using it on the given pass. So, we define a variable and set it # to the value of session_file passed through the form data. On the first # pass, this will be blank, and will start us into the authorization process # in a little while. if( $form_data{'session_file'} ne '' ) { $form_data{'session_file'} =~ /^(\w+)/o; $session_file = $1; } else { $session_file = ''; } # DATE INFORMATION # # Okay, this is a calendar script, so there should be a lot of date # variables, right? This is where we start defining them all. We # get the current day, month, and year from the system time. Note that # the system returns the month as a number from 0-11, and year returns # the number of years since 1900, so we need to modify them a little. # We then set the currentyear for the script by either reading in the # year passed to us by the form data, or, in the absence of that, we # set it to the localtime year. We do the same with the currentmonth. # We also go ahead and get the name of the currentmonth at this time. ( $ltday, $ltmon, $ltyear ) = ( localtime(time) )[3,4,5]; $ltmon += 1; $ltyear += 1900; if( $form_data{'year'} ne '' ) { $form_data{'year'} =~ /^(\d{4})/o; $currentyear = "$1"; } else { $currentyear = "$ltyear"; } if( $form_data{'month'} ne '' ) { $form_data{'month'} =~ /^(\d{1,2})/o; $currentmonth = "$1"; } else { $currentmonth = "$ltmon"; } $current_month_name = $fcs::month_hash{ $currentmonth }; $greatest_year = $ltyear + $fcs::num_years - 1; if( $form_data{'category'} ne '' ) { $category = join( ",", ( split("\0", $form_data{'category'} ) ) ); } else { $category = ''; } if( $form_data{'category'} ne '' ) { $cat3 = join( ", ", ( split("\0", $form_data{'category'} ) ) ); } else { $cat3 = ''; } # DEFINE DATABASE FILES # # This implementation of the script uses a database file for # each month and year. Thus, for January 1999, we will be working # with a base file called 199901. We set up the base file # from the month and year variables we just defined, set the # database file to this plus ".events", and then define a lock # file and temp file. Since we're here, we also check to see if the # database file currently exists. $base_file = "$currentyear".sprintf( "%.2d", $currentmonth ); $database_file = "$calendar_type/$base_file".".events"; $temp_file = "$fcs::temp_lock_dir/framecal_temp.file"; $lock_file = "$fcs::temp_lock_dir/framecal_lock.file"; $db_exist = ( -e $database_file ); $places_file = "$calendar_type/places.db"; # USER AUTHENTICATION # # Okay, at this point, we want to find out if the user should actually be # here. We use the GetSessionInfo subroutine found in auth-lib.pl, which # we have already required, to get the user to login, and authenticate them. # We also chomp the session email, which removes a new line character if one # exists on it. ($session_file, $session_username, $session_group, $session_name, $session_email) = &al::GetSessionInfo($session_file, "$fcs::this_script_url", \%form_data); chomp $session_email; # WHAT DO YOU WANT ME TO DO? # # Each button on the forms that are presented, and most links, provide a tag # called 'action'. This form data variable tells the script what button # or type of link you selected, and thus, what you want to do. So, we grab # this data, and do it with a 'perl-esque' Case statement. Note that if # no action is defined, we must want to see the month table, and we also have # the option to clean up old datafiles if the URL we call the script with # has the 'first_pass=on' value in it. Note that no portion of the script # will ever include that item, so if you want automatic clean up of files, # you will have to set it in your URL that you call the script with, and # set a number of months to save in your calendar.setup file. This is the # end of the MAIN section of the script. From here on out, we are just # calling subroutines. unless( $session_file eq '' ) { $action = $form_data{'action'} if( exists($form_data{'action'}) ); CASE: { if( $action =~ /^view_month/io ) { do { view_week_month_sub(); last CASE; } } if( $action =~ /^view_week/io ) { do { view_week_month_sub(); last CASE; } } if( $action =~ /^spam_week/io ) { do { spam_week_sub(); last CASE; } } if( $action =~ /^Send Spam/io ) { do { notification2(); last CASE; } } if( $action =~ /^view_day/io ) { do { view_day_sub(); last CASE; } } if( $action =~ /^view_search/io ) { do { view_search_sub(); last CASE; } } if( $action =~ /^w/io ) { do { short2(); last CASE; } } if( $action =~ /^short/io ) { do { view_search_2(); last CASE; } } if( $action =~ /^lists_users/io ) { do { lists_users(); last CASE; } } if( $action =~ /^e_f/io ) { do { mail_friend(); last CASE; } } if( $action =~ /^Add Event/io ) { do { add_item_form_sub(); last CASE; } } if( $action =~ /^Add Item/io ) { do { add_event_sub(); last CASE; } } if( $action =~ /^Modify Item/io ) { do { modify_item_form_sub(); last CASE; } } if( $action =~ /^Modify Event/io ) { do { modify_event_sub(); last CASE; } } if( $action =~ /^Delete Item/io ) { do { delete_item_form_sub(); last CASE; } } if( $action =~ /^Delete Event/io ) { do { delete_event_sub(); last CASE; } } if( $action =~ /^Search/io ) { do { search_form(); last CASE; } } if( $action =~ /^Find Events/io ) { do { search_events(); last CASE; } } if( exists($form_data{'first_pass'}) ) { &trim_events(); } &view_cal_sub(); } } } # SUB VIEW_CAL_SUB # # Okay, if we have called this subroutine, that means we want to print out the # table formatted month. sub view_cal_sub { # We need to make an array that is formatted for the current month, i.e., has # the day numbers in the correct indices in the array, so we call the # make_month_array subroutine with the julian day for the first day of the month # and year that we are in. my (@mymonth) = &make_month_array(); my ($size_of_mymonth); my ($variable_list,$next_month,$next_year,$prev_month,$prev_year); my ($next_link,$prev_link,$month_link,$day,%event_days,$temp_cat); my ($count_till_last_day,$weekday,$day_number,$td_color); my ($num_weeks,$start,$end,$count,$i,$city_hash); $size_of_mymonth = scalar(@mymonth); # We start to print out our HTML page here, with the header sub being called. &header2 ("Calendar: $current_month_name - $currentyear"); # We now create our Next Month, Prev. Month, and View Month links. We do this # by just increasing the month by one for Next, decreasing it by one for Prev., # and checking to see if we thus move into another year, and correct for that. # We then concatenate together three strings to be used to hold the link information # for these values, providing all the information that would be required by the script. $variable_list = ''; $variable_list .= "calendar=$form_data{'calendar'}"; $variable_list .= "&session_file=$session_file&category=$category&home=$form_data{'home'}"; $next_month = $currentmonth + 1; $next_year = $currentyear; $prev_month = $currentmonth - 1; $prev_year = $currentyear; if ($next_month > 12) { $next_month = 1; $next_year++; } if ($prev_month < 1) { $prev_month = 12; $prev_year--; } $next_link = $variable_list."&month=$next_month&year=$next_year"; $prev_link = $variable_list."&month=$prev_month&year=$prev_year"; $month_link = "$variable_list"; $month_link .= "&action=view_month&month=$currentmonth&year=$currentyear"; # Now that we have the links together, we put them in a small one row table at the # top of the month table, and then start the month table, setting its title. #begin dave mod # sping mod = bgcolor=$fcs::apptcol print qq!!; &footer; #
Other Listings:
#
| # |
# Maps # E-Guide # SF Station # SF Weekly # MetroActive # | # |
# SF Girl # Craigs List # Bay Insider # CitySearch # BayGuardian # |
Sorry, but theres nothing scheduled for today. Youll have to get a life on your own...!; } # If we are using help in this script, print out the help topic link. # Then, close the HTML with the standard footer. if ($fcs::use_help) { print "
"; } &footer; } # SUB VIEW_WEEK_MONTH_SUB # # If we have called this subroutine, it means we want to see all of the # events for the selected month or week. sub view_week_month_sub { my ($day,$username,$time,$temp_cat,$id,$item_found,$cat_tag,$dayname); my (@events,$event,$end,$start,$word,$help,$title); my ($last_day) = ''; # We start by initializing some of our variables that will tell us whether # we want to view a month or a specified week. Depending on that information, # we initialize $word and $help. $start = $form_data{'start'}; $end = $form_data{'end'}; if( $start && $end ) { $help = 13; $word = "Week"; $title = "Week of $current_month_name $start - $end, $currentyear"; } else { $start = 0; $end = 32; $help = 8; $word = "Month"; $title = "Month of $current_month_name, $currentyear"; } # We print out the header for the page, and we go ahead and # close the form tag immediately, since we don't have any interaction on # the page that is generated. We then check to see if the database file # for the selected month/week exists, and if it does, we open it. &header ("$current_month_name, $currentyear"); print "
I'm sorry, but there are not any events scheduled for the current $word and selected category. Please check back again later for future additions.!; } # If we are using help with the calendar, we print out the link to # the help topic, and then we close the HTML page with the standard # footer. if ($fcs::use_help) { print "
"; } &footer; } # SUB VIEW_SEARCH_SUB # # If this subroutine has been selected, it means that someone is trying to # get the details on an event that was returned as a hit from a previous search. sub view_search_sub { my ($day,$id,$dayname); # The extra info passed by this type of link is the actual id number of the event # that we want to look at, as we will only be looking at one at a time. We need # to untaint this value in order to open it. We also get the day of the event # from the link. $form_data{'id'} =~ /^(\d+)(_\d)?(\d*)$/o; $id = "$1$2$3"; $day = $form_data{'day'}; $dayname = &day_of_week($currentyear, $currentmonth, $day); # We now print out the standard HTML header, and close out the form since there # is not interaction options for this subroutine's output, especially since it # will be opened in its own "mini-window". &header ("$dayname, $current_month_name $day, $currentyear"); print ""; # Now we just print out the information for the event as we have in the previous # event displaying subroutines. Nothing new here. We of course close with the # standard footer. if ($session_username ne $user && $temp_cat =~ /\bPrivate\b/) { print qq! You do not have permission to view this event. !; } print qq! $dayname, $current_month_name $day, $currentyear
/g; $form_data{$value} =~ s//\"/g; $form_data{$value} =~ s/\^/\'/g; $form_data{$value} =~ s//-/g; $form_data{$value} =~ s//-/g; $form_data{$value} =~ s/\ '/ \\;/g; $form_data{$value} =~ s/\/\\;/g; $form_data{$value} =~ s/\'/\\;/g; $form_data{$value} =~ s//\\;/g; $form_data{$value} =~ s//\\;/g; $form_data{$value} =~ s//\\;/g; $form_data{$value} =~ s//\\;/g; $form_data{$value} =~ s//\\;/g; $form_data{$value} =~ s//\\;/g; $form_data{$value} =~ s//\\;/g; $form_data{$value} =~ s//\.\.\.\;/g; $form_data{$value} =~ s/’/\\;/g; $form_data{$value} =~ s/“/\\; /g; $form_data{$value} =~ s/”/\\; /g; $form_data{$value} =~ s/\n\"/\n\\;/g; $form_data{$value} =~ s/ \"/ \\;/g; $form_data{$value} =~ s/\" /\\; /g; $form_data{$value} =~ s/\"\./\\;\./g; $form_data{$value} =~ s/\.\"/\.\\;/g; $form_data{$value} =~ s/\"\n/\\;\n/g; $form_data{$value} =~ s/\"-/\\;-/g; $form_data{$value} =~ s/\"\,/\\;\,/g; $form_data{$value} =~ s/\"\)/\\;\)/g; $form_data{$value} =~ s/\,\"/\,\\;/g; $form_data{$value} =~ s/\"/\\;/g; $form_data{$value} =~ s/\\;http/\"http/g; $form_data{$value} =~ s/\\;mailto/\"mailto/g; $form_data{$value} =~ s/\\;>/\">/g; $form_data{$value} =~ s/\n>/\n/g; $form_data{$value} =~ s/\n> \n/
/g; $form_data{$value} =~ s/\n>\n/
/g;
$form_data{$value} =~ s/\n/ /g; #was
$form_data{$value} =~ s/
/ \ \;
/g;
$form_data{$value} =~ s/
\ \;/ \ \;/g; $form_data{$value} =~ s/href/target\=\"new\" href/g; } # end Dave mod # We are going to fill in our session names from the hidden values entered # via the submission form subroutine. We have still checked for a valid # session file, we just do this for flexibility later on. $session_name = "$form_data{'real_name'}"; $session_email = "$form_data{'email'}"; $session_username = "$form_data{'username'}"; # We now check for missing information for our required fields. foreach $var_name (@fcs::req_fields) { if ($form_data{$var_name} eq '') { $missing_info = 1; } } if ($session_name eq '' && (($form_data{'real_name'} eq '') || ($form_data{'email'} eq ''))) { $missing_info = 1; } # If we have missing information, we print out an error message, and # set our error flag. if ($missing_info) { print qq!
You didn't complete all the required fields. Please hit the back button and try again.!; $error = 1; } # We now check for the error flag being set, and if it isn't we start in. # If we are allowing use of the notify users option, we process the multiple # select list by splitting the email addresses into an array, then join # the array with commas. unless( $error ) { if ($form_data{'notify'} eq "on") { @notify_users = split ("\0", $form_data{'mail_choices'}); $notified = join (",", @notify_users); } # We assign the rest of our form data information to variables. Note that # if no duration time was entered, we set the event up to be displayed as a # general information event, applicable to the whole day. #assign URL and Title $day = "$form_data{'day'}"; $time_zone = "$form_data{'time_zone'}"; $event_cat = $category; $dur_hrs = "$form_data{'dur_hrs'}"; $dur_mins = "$form_data{'dur_mins'}"; if ($dur_hrs || $dur_mins) { $time = "$form_data{'time'}"; } else { $time = ' '; } $name = "$session_name"; $email = "$session_email"; if (($form_data{'linktitle'} ne '') && ($form_data{'linkurl'} ne '')) { $linktitle = "$form_data{'linktitle'}"; $form_data{'linkurl'} =~ s/\\/\//go; if ($form_data{'linkurl'} =~ /(^(http:|https:|ftp:|news:)\/\/)|(^mailto:)/o) { $linkurl = "$form_data{'linkurl'}"; } else { $linkurl = "http://$form_data{'linkurl'}"; } } # start Dave's mod elsif (($form_data{'linkurl'} ne '')) { $linktitle = "$form_data{'linkurl'}"; $form_data{'linkurl'} =~ s/\\/\//go; if ($form_data{'linkurl'} =~ /(^(http:|https:|ftp:|news:)\/\/)|(^mailto:)/o) { $linkurl = "$form_data{'linkurl'}"; } else { $linkurl = "http://$form_data{'linkurl'}"; } } # end Dave's mod else { $linkurl = ''; $linktitle = ''; } #Start Dave's mapping mod # $location = "$form_data{'location'}"; $city_map = $global::city_hash{$form_data{'calendar'}}; $city_map =~ s/ /\+/go; $state_map = $global::state_hash{$form_data{'calendar'}}; if (($form_data{'street_add'} ne '') && ($form_data{'city_add'} ne '')) { foreach $value (@fcs::field_values) { $form_data{'street_add'} =~ s/ /\+/g; $form_data{'city_add'} =~ s/ /\+/g; } if ($session_username eq "David") { $location = "$form_data{'location'} (map)"; } elsif ($form_data{'calendar'} eq "london"){ $location = "$form_data{'location'} - $form_data{'street_add'}, $form_data{'city_add'}"; } else { $location = "$form_data{'location'} (map)"; } } elsif ($form_data{'street_add'} ne '') { foreach $value (@fcs::field_values) { $form_data{'street_add'} =~ s/ /\+/g; } if ($session_username eq "David") { $location = "$form_data{'location'} (map)"; } elsif ($form_data{'calendar'} eq "london"){ $location = "$form_data{'location'} - $form_data{'street_add'}, London"; } else { $location = "$form_data{'location'} (map)"; } } else { $location = "$form_data{'location'}"; } #end dave's mapping location. $cost = "$form_data{'cost'}"; $phone = "$form_data{'phone'}"; $subject = "$form_data{'subject'}"; $body = "$form_data{'body'}"; $cat2 = "$cat3"; $end_month = $fcs::month_hash{$form_data{'rec_mon'}}; $end_date = "$end_month $form_data{'rec_day'}"; # We now fill in the new_event variable with a string that will be used to # create the event file for this particular event. If you are going to modify # information stored for each event, this is another place you will have to make # modifications. $new_event = "time->$time\ntimezone->$time_zone\ndurationhrs->$dur_hrs\n"; $new_event .= "durationmins->$dur_mins\nname->$name\nemail->$email\n"; $new_event .= "notified->$notified\nlinkurl->$linkurl\nlinktitle->$linktitle\n"; $new_event .= "location->$location\nsubject->$subject\nbody->$body\ncost->$cost\nphone->$phone\n"; $new_event .= "cat2->$cat2\nend_date->$end_date\n"; # Now we need to check for recurring events, and get the dates that the event # will apply to. If the user has specified a recurring event, we do our error # checking here to be sure the values are valid before attempting to get the # dates from fc_recur.pl. if( $form_data{'rep_opt'} == 0 ) { $datea = "$base_file".sprintf("%.2d", $day); $dateb = ''; push( @dates, $datea ); } else { &CgiRequire( "$framecal_dir/fc_recur.pl" ); $datea = "$base_file".sprintf("%.2d", $day); $dateb = &fcr::date_join( $form_data{'rec_year'},$form_data{'rec_mon'}, $form_data{'rec_day'} ); unless( ($dateb ge $datea) && (&fcr::is_val_date( $dateb )) ) { $error = 1; } if( ($form_data{'rep_opt'} == 1) && (! $error) ) { my( @temp ); $rec_a = int($form_data{'rec_a'}); $rec_b = $form_data{'rec_b'}; $rec_b =~ s/rec/$rec_a/i; $recur = $rec_b; } elsif( ($form_data{'rep_opt'} == 2) && (! $error) ) { $rec_a = int($form_data{'rec_c'}); $rec_b = join( ",", split("\0", $form_data{'rec_d'}) ); $recur = "0:0:$rec_a*$rec_b"; } elsif( ($form_data{'rep_opt'} == 3) && (! $error) ) { my( $rec_c ); $rec_a = join( ",", split("\0", $form_data{'rec_e'}) ); $rec_b = join( ",", split("\0", $form_data{'rec_f'}) ); $rec_c = $form_data{'rec_g'}; $recur = "$rec_c*$rec_a:$rec_b"; } else { $error = 1; } @dates = &fcr::get_dates( $recur, $datea, $dateb ) unless( $error ); if( $#dates < 0 ) { $error = 1; } } if( $error ) { print qq!
I'm very sorry, but there was a problem with the information you specified for your recurring event. Please hit your back button, and try again, being sure to specify a valid end date, that the end date is after the begin date, and that you only used the values in the form to specify the recurrence.!; } else { if( scalar(@dates) > $fcs::max_posts ) { if ($session_group ne "admin") { @dates = @dates[ 0..($fcs::max_posts - 1) ]; } } $id = &counter; # We are now ready to start writing to files. First we get our filelock. If our # database exists, we open it in append mode. If it does not, we create it and # open it at the same time. We then print our new row to the database, close # the database, release our file lock, and sort the events in the database file. # Note that in the case of a recurring event, we may have to switch databases, # so that is kept track of as we move through our array of dates. &GetFileLock ("$lock_file"); open (DATABASE, ">>$database_file") || &open_error($database_file); for( $i = 0; $i <= $#dates; $i++ ) { $dates[ $i ] =~ /^(\d{6})(\d{2})/o; ( $temp_base, $day ) = ( $1, $2 ); $day = int($day); if( $temp_base != $base_file ) { close( DATABASE ); &sort_events(); $database_file = "$calendar_type/$temp_base".".events"; $db_exist = (-e $database_file); open (DATABASE, ">>$database_file") || &open_error($database_file); } if( $#dates == 0 ) { $event_id = $id; } else { $event_id = "$id"."_"."$i"; } $new_row = "$day\|$time\|$session_username\|$event_cat\|$event_id"; print DATABASE "$new_row\n"; $event_id =~ /^(\d+)(_\d)?(\d*)$/o; $event_id = "$1$2$3"; open (EVENTFILE, ">$fcs::path_to_events/$event_id") || &open_error("event file $event_id"); print EVENTFILE "$new_event"; close (EVENTFILE); } close (DATABASE); &sort_events(); &ReleaseFileLock ("$lock_file"); # We now print out some information to the user regarding the addition of the # event to the calendar database, and close it out with the required form data # tags and the standard footer. print qq!
"; if ($fcs::allow_notify) { print qq!Note: In the "Notify" selection box above, be aware that those already notified when the event was added will be notified of the modification. Select only additional people to notify of the event if you need to.!; } print qq!
Note: Make sure to select an item to modify using the radio buttons on the top table. Then change any of the form inputs you want changed, leaving the others as they are. Feel free to cut and paste from the top table to the bottom table if you only need to change a small amount of text.
I'm sorry, I was not able to modify the database because none of the checkboxes on the table were selected, so I was not sure which item to delete. Would you please make sure that you select an item. Just hit your back button. Thanks.!; } else { # We are now processing the deletion. First, we get our lock file in place # to prevent someone else from modifying the file while we are trying to. # We then open up the temp file and database file specific to the events # database we will be deleting from. We also set a variable to let us know # that we are in a public calendar, for email purposes (no $session_email # if not using authentication). $no_email = 0; $no_email = 1 if( $session_email eq '' ); &GetFileLock ("$lock_file"); open (TEMP, ">$temp_file") || &open_error($temp_file); open (DATA, "$database_file") || &open_error($database_file); # We now read through our database file one line at a time. For each line, # we get the event id from the line, as well as the day, remove the new line # character from the id number, and check to see if the id number is in our # index of events to delete. If it is not, we print the item to the temp # file. while () { @grepfields=split(/\|/,$_); $id = pop (@grepfields); $category = pop (@grepfields); $day = shift (@grepfields); chomp $id; unless ($del_events{$id}) { print TEMP "$_"; } else { # If the id number is in our index of items to delete, we do not print the line # to the temp file. Instead, we check to see if we want to notify people of the # change. If we do, we get the information about the event from its file, and # prepare to notify people. ($time,$time_zone,$dur_hrs,$dur_mins,$name,$email,$notified, $linkurl,$linktitle,$location,$subject,$body,$cost,$phone,$cat2,$end_date) = &get_event_info("$id"); $to_notify = ''; $session_email = $email if( $no_email ); if ($fcs::allow_notify) { $to_notify = "$notified"; } # If the administrator wants notification of event changes, we add their address # onto the list of people to notify. if ($fcs::notify_event) { $to_notify = "$auths::auth_admin_email_address,$to_notify"; } # If the people to notify is not empty, we send out the message to everyone # using the notification subroutine, with the final value set to tell that # subroutine that it is a deletion. if ($to_notify) { $date = "$currentmonth/$day/$currentyear"; $category =~ tr/_/ /; ¬ification ($date,$time,$time_zone,$dur_hrs,$dur_mins, $to_notify,$location,$subject,$body,$cost,$phone,$cat2,$end_date,$linkurl, $linktitle,"0"); } # We now untaint the id number, and use it to delete the event file associated # with the event. $id =~ /^(\d+)(_\d)?(\d*)$/o; $id = "$1$2$3"; unlink ("$fcs::path_to_events/$id"); } } # We are now done reading through the DATA file, so we close it and the TEMP file # as well. We remove the DATA file, and replace it with the TEMP file, which # now contains all the information of the original file, minus the events that # we wanted to delete, then release the file lock. close (DATA); close (TEMP); unlink ("$database_file"); rename ($temp_file, $database_file); &ReleaseFileLock ("$lock_file"); # We are now done with all of our processing, so we let the user know that # we are done, and provide a button to refresh the Month Table view in the # month frame. We close the HTML with the standard footer. &header ("Deleted an Item from the $fcs::cal_name Calendar"); print qq!
I'm sorry, I was not able to modify the database because none of the radio buttons on the table were selected, so I was not sure which item to modify. Would you please make sure that you select an item \"and\" fill in the new information. Just hit your back button. Thanks.!; $error = 1; } unless( $error ) { # If we have made it to here, we are ready to modify our selected event. # We read in the original year and original month form data variables, because # we want to be sure that if the user is modifying an event in a way that # would move it into a different month, we can handle it. $form_data{'orig_year'} =~ /^(\d{4})/o; $orig_year = $1; $form_data{'orig_month'} =~ /^(\d{1,2})/o; $orig_month = sprintf("%.2d", $1); $temp_base = "$orig_year$orig_month"; $temp_db = "$calendar_type/$temp_base".".events"; # We are now ready to open up the original database file, so we first lock it, # open up a temp file, and go through the database, looking for the id number # we are going to modify. If the id is not the item we are going to modify, # we print it to the temp file. Otherwise, set the fields we have into our # old fields variables. We then close the temp file and original database, # unlink the original database, and rename the temp file to the original database. &GetFileLock ("$lock_file"); open (TEMPFILE, ">$temp_file") || &open_error($temp_file); open (DATABASE, "$temp_db") || &open_error($temp_db); while (
/g; $form_data{$value} =~ s/\n\*/\n
/g;
$form_data{$value} =~ s/\n/ /g; #was
}
}
#end Dave mod
# We now go through all of our form data, and update our event if the corresponding
# form data value is present.
$day = $form_data{'day'} if ($form_data{'day'} ne '');
$username = $form_data{'username'} if ($form_data{'username'} ne '');
$event_cat = $form_data{'category'} if ($form_data{'category'} ne '');
$time_zone = $form_data{'time_zone'} if ($form_data{'time_zone'} ne '');
$name = $form_data{'real_name'} if ($form_data{'real_name'} ne '');
$email = $form_data{'email'} if ($form_data{'email'} ne '');
$location = $form_data{'location'} if ($form_data{'location'} ne '');
$subject = $form_data{'subject'} if ($form_data{'subject'} ne '');
$body = $form_data{'body'} if ($form_data{'body'} ne '');
$cost = $form_data{'cost'} if ($form_data{'cost'} ne '');
$phone = $form_data{'phone'} if ($form_data{'phone'} ne '');
$dur_hrs = $form_data{'dur_hrs'} if ($form_data{'dur_hrs'} ne '');
$dur_mins = $form_data{'dur_mins'} if ($form_data{'dur_mins'} ne '');
if ($dur_hrs || $dur_mins) {
$time = $form_data{'time'} if ($form_data{'time'} ne '');
$time = "09:00" if ($time eq ' ');
} else {
$time = ' ';
}
# With the notification service turned on, however, we need to do some extra
# formatting. The user can add new people to be notified after the event
# has been added. We bring in the data from the form, split it, and
# add the email addresses to the notify_users array. If we did indeed have
# people selected to be notified (@notify_users > 0), we need to merge them
# into our original list of attendees. We do this by using the %seen hash.
# We split out the original list and put it into @old_users. We then
# go through each array, and add them to the hash. With the %seen hash, if there
# is a repeat, it overwrites itself, and we don't get any copies. We then
# get our final result by joining the keys of the seen hash, which are the
# email addresses, using commas, and put this onto the new_event array. If
# form data did not have any users selected, we just push the old list onto
# the new array.
if ($form_data{'notify'} eq "on") {
@notify_users = split ("\0", $form_data{'mail_choices'});
}
if (scalar(@notify_users > 0)) {
my (@old_users) = split (/,/, $notified);
my (%seen, $item, $result);
foreach $item (@notify_users) { $seen{$item} = 1; }
foreach $item (@old_users) { $seen{$item} = 1; }
$notified = join(",", (keys(%seen)));
}
$linktitle = $form_data{'linktitle'} if ($form_data{'linktitle'} ne '');
$linkurl = $form_data{'linkurl'} if ($form_data{'linkurl'} ne '');
if ($linkurl ne '' && $linktitle ne '') {
$linkurl =~ s/\\/\//go;
unless ($linkurl =~ /(^(http:|https:|ftp:|news:)\/\/)|(^mailto:)/o) {
$linkurl = "http://$linkurl";
}
} else {
$linkurl = '';
$linktitle = '';
}
# Okay, we are done updating our event, so we need to write out the information to
# files. We create our new line by joining the values with "|". We then get a
# lock file, and open up the new database file, creating it if it doesn't exist,
# appending to it if it does. We print our new line to the database, close it up,
# release the file lock, and sort the file.
$new_line = "$day\|$time\|$username\|$event_cat\|$mod_item";
&GetFileLock("$lock_file");
open (DATABASE, ">>$database_file") || &open_error($database_file);
print DATABASE "$new_line\n";
close (DATABASE);
&sort_events ();
&ReleaseFileLock ("$lock_file");
# We now create the event file for the modified event. Since the information is
# all at hand, we will just clobber the original file in the process of updating
# it, to make this a little easier. We format our file just as we did in the
# original add event subroutine.
$new_line = '';
$new_line = "time->$time\ntimezone->$time_zone\ndurationhrs->$dur_hrs\n";
$new_line .= "durationmins->$dur_mins\nname->$name\nemail->$email\n";
$new_line .= "notified->$notified\nlinkurl->$linkurl\nlinktitle->$linktitle\n";
$new_line .= "location->$location\nsubject->$subject\nbody->$body\ncost->$cost\nphone->$phone\n";
open (EVENTFILE, ">$fcs::path_to_events/$mod_item") || &open_error ("event file $mod_item");
print EVENTFILE "$new_line";
close (EVENTFILE);
# If we are set up to notify people of these changes, we make our list of people
# to notify, adding the administrator if they have so chosen. We use the
# original poster's email address if this is a public calendar and a new email
# address was not supplied.
$session_email = $email if( $session_email eq '' );
if ($fcs::allow_notify) {
$to_notify = "$notified";
}
if ($fcs::notify_event) {
$to_notify = "$auths::auth_admin_email_address,$to_notify";
}
# We now send out the notification to all the email addresses in the string.
if ($to_notify) {
$date = "$currentmonth/$day/$currentyear";
$event_cat =~ tr/_/ /;
$category = $event_cat;
¬ification ($date,$time,$time_zone,$dur_hrs,$dur_mins,
$to_notify,$location,$subject,$body,$cost,$phone,$cat2,$end_date,$linkurl,
$linktitle,"2");
}
# Finally, we are done, so we print out a confirmation message to the user,
# and provide a button for them to refresh the calendar. We of course
# close with the standard footer.
print qq!
| Start Search: | !; &select_a_month(); print "\ \;"; &select_a_day( "startday" ); print ",\ \;\ \;"; &select_a_year(); # Now we need our end date. We can't use select_a_month and select_a_year # again, because then the selectors would have the same name as the start # date selectors, and we wouldn't get anywhere. So we need to create # them manually. We basically copy the code out of the two subroutines, # and simply supply a different name for the selectors. See the comments # in these subroutines if you want to know what is happening here. print qq! |
| End Search: | !; &select_a_month( "endmonth" ); print "\ \;"; &select_an_end_day( "endday" ); print ",\ \;\ \;"; &select_a_year( "endyear" ); print " |
| Category: | !; &select_a_category (1); print " |
| Keywords: | Enter keywords separated by spaces. |
| Match: | All of the words above Any of the words above |
| Search In: | Body Subject Location Posted by |
!; # We are done with this form, so we print out our online help link if we are # using online help, and close with the standard footer. if ($fcs::use_help) { print "
"; &help_link ("10"); } print "
I'm sorry, but you entered an End Date that is earlier than the Start Date for your search. Please hit your back button and try again.!; &footer; } elsif (scalar(@fields) < 1) { &header ("No Search Fields Selected"); print qq!
I'm sorry, but you did not select any fields to be searched. Please hit your back button and try again.!; &footer; } elsif (scalar(@keywords) < 1) { &header ("No Keywords Entered"); print qq!
I'm sorry, but you did not enter any keywords for which to search. Please hit your back button and try again.!; &footer; } else { # If we have made it through all of our error checks, we are ready to start our # search. We initialize our search_year and search_month variables with the # currentyear and currentmonth, as they hold the values for the start year and # month for the search. We make a new base file out of these, and then a # new db_file that we will search for. This is all so we have a more efficient # loop through the start and end search dates. $search_year = $currentyear; $search_month = $currentmonth; $base_file = "$currentyear".sprintf("%.2d", $currentmonth); $base_file =~ /^(\d{6})/o; $base_file = $1; $db_file = "$calendar_type/$base_file.events"; # We now make sure that our bse_file is less than or equal to our end_file. This # is to handle the conditions where the user wants to search in only one month, or # wants to search through many months. This one statement will handle both conditions. # We will continue going through our event files until this is false. while ( $base_file <= $end_file ) { if ( -e $db_file ) { # If the db_file exists, we open up the file, then start reading through it # one line at a time. We remove the new line character from our id number for # each event, then, on each pass, we initialize our search variables, $srch_str, # $match_found, and $and_res. This is handled on one line. We then get the # day number set to our base file plus the day number for the event. open (DATA, "$db_file") || &open_error ( $db_file ); while () { ($day,$time,$user,$tmp_cat,$id) = split(/\|/, $_); # chomp ($tmp_cat,$id); $srch_str = ''; $match_found = 0; $and_res = 0; $day_num = "$base_file".sprintf("%.2d", $day); # If our day number is greater than or equal to our start number and it is also # less than or equal to our end number, we have an event that we want to search # through, so we get the event information using get_event_info, and then # use the information found therein to make our search string ($srch_str) by # concatenating each item the user has asked to search through onto this string. if ( ($day_num ge $start_num) && ($day_num le $end_num) && ($tmp_cat =~ /\b$category\b/ || $category eq '') ) { ($time,$time_zone,$dur_hrs,$dur_mins,$name,$email,$notified, $linkurl,$linktitle,$location,$subject,$body,$cost,$phone,$cat2,$end_date) = &get_event_info("$id"); foreach $i (@fields) { if ($i eq "subject") { $srch_str .= " $subject"; } elsif ($i eq "location") { $srch_str .= " $location"; } elsif ($i eq "body") { $srch_str .= " $body"; } elsif ($i eq "name") { $srch_str .= " $name"; } } # If the user has selected any as the logic type, we do a search on our keywords, # using a regular expression with each word separated by the or symbol in regular # expressions (|). That is why above we joined our keywords with the "|" symbol. # If we get a match, we set our $match_found flag to true. # Else, if the user has selected all as the logic type, we loop through each keyword # in our keyword array. For each keyword that we find in the search string, using # regular expressions, we add one to the $and_res variable. At the end of the # loop, we determine if $and_res equals the number of keywords we entered. If it # does, we found each of the keywords in our search string, and so we set our # $match_found flag to true. if ( $logic eq "any" ) { if ( $srch_str =~ /\b($keywords)\b/i ) {$match_found = 1;} } elsif ( $logic eq "all" ) { foreach $i (@keywords) {$and_res++ if ($srch_str =~ /\b($i)\b/i);} if ( scalar(@keywords) == $and_res ) {$match_found = 1;} } # If we made a match on the current event, as determined by our $match_found flag being # set to 1, we create a link to this event, formatted to use our javascript function # in the header of each HTML page, and including all the information that will be # required by the view_search_sub above. We then push it onto our results array for # later printing. if ( $match_found ) { if ($session_username ne $user && $tmp_cat =~ /\bPrivate\b/) { $link = ""; } else { $link = ""; $link .= "$subject"; $link .= "\ \;\ \;--\ \;\ \;$fcs::month_hash{$search_month} "; $link .= "$day, $search_year"; if ($time =~ /\d+/o) { $link .= " at $fcs::TIME{$time}"; } else { $link .= " (All Day)"; } $link .= "
"; push (@results, $link); } } } # end if. } # end while # Once we are done with the current db_file, we close it. close (DATA); } # We now increment our search_month variable, correcting the search_year and # search_month if we go over 12. Then we concatenate it into a new base_file # and a new db_file for our next pass through the while loop above. Thus, we # will efficiently cover all of our months to search through. $search_month++; if ($search_month > 12) { $search_month = 1; $search_year++; } $base_file = "$search_year".sprintf("%.2d", $search_month); $base_file =~ /^(\d{6})/o; $base_file = $1; $db_file = "$calendar_type/$base_file.events"; } # Once the while loop quits, we are done searching through files, so we print out # the results to the user. We provide some basic HTML to let them know what we # are showing them. Then, if our results array contains one or more items, we # print each of them out. Else, we let the user know that we didn't find any # events matching their criteria. &header("Search Results"); print qq!
Below are the results from your search. Click on a link to get detailed information regarding the event.
"; } print "