calandar_admin.pl:# at the top put use File::ReadBackwards;
# -----------------------------------------------elsif ($in{'command'} eq "add_event") { unless(&handleCustomFunction("before_add_event")) { &checkPermissions("","ADD_EVENT"); my ($properties,$name,$error); my ($db) = new DBFile($events_db); my ($id); foreach (keys %in) { if ((/^FIELD_(.*)/) && ($in{$_} ne "")) { $properties->{$1} = $in{$_}; } } $error=0; foreach (keys %{$db->{'properties'}}) { if ($db->{'properties'}->{$_}->{'required'} && ($properties->{$_} eq "")) { $name = $db->{'properties'}->{$_}->{'name'} | | $_; &addUserMessage(&getMessage("FIELD_IS_REQUIRED",$name)); $error=1; } } if ($error) { $Template::record = $properties; &ERROR(&getMessage("EVENT_NOT_ADDED_FIELDS_MISSING")); } unless ($Config->get("allow_html")) { foreach (keys %{$properties}) { $properties->{$_} = &HTML::filter($properties->{$_}); } } $properties->{'author_id'} = $User->{'username'}; $properties->{'author_name'} = $User->{'name'}; $properties->{'time_added'} = time; if ($User->hasPermission("","APPROVE") | | $User->hasPermission($calendar,"APPROVE_OWN_EVENTS")) { $properties->{'approved'} = 1; } else { &addUserMessage(&getMessage("EVENT_SAVED_PENDING_APPROVAL")); } if ($id = $db->addRecord($properties)) { &addUserMessage(&getMessage("EVENT_ADDED")); $properties->{'id'} = $id; $Template::event = $properties; } else { &ERROR($db->getErrorMessage()); } &handleCustomFunction("after_add_event"); # Copying over events to default if ($calendar ne default) { open (EVENTS_ID, "calendars/default/events.id"); while(<EVENTS_ID> ){$new_default_id = $_ + 1;} close EVENTS_ID; # $last_current_event is the event that was just added. open (CURRENTEVENTS, "calendars/$calendar/events.txt"); my $last_current_event; local $_; $last_current_event = $_ while <CURRENTEVENTS>; @last_current_event = split(/\t/, $last_current_event); $last_current_event[0] = $new_default_id; close CURRENTEVENTS; open (EVENTS, ">>calendars/default/events.txt"); for(0.. { # Function to print all 9 fields to default/events.txt print EVENTS $last_current_event[$_]; if($_ < { print EVENTS "\t"; } } close EVENTS; # Increment the ID file open (EID, ">calendars/default/events.id"); print EID $new_default_id; close EID; } }}
# -----------------------------------------------elsif ($in{'command'} eq "schedule_event") { unless(&handleCustomFunction("before_schedule_event")) { my ($db) = new DBFile($schedule_db); my ($event_id) = $in{'EVENT_id'}; my ($schedule);
foreach (sort keys %in) { if (/^SCHEDULE_(.*)/) { $schedule->{$1} = $in{$_}; } } $db->deleteRecords( {'event_id'=>$event_id} ); if (&Event::scheduleEvent($db, $schedule, $event_id)) { &addUserMessage(&getMessage("SCHEDULE_SAVED")); } else { &addUserMessage(&getMessage("ERROR_WHILE_SAVING_SCHEDULE")); &addUserMessage(&Event::getErrorMessage()); $Template::schedule = $schedule; &showSameScreen(); } &handleCustomFunction("after_schedule_event"); # copying over schedule to default if ($calendar ne default) { open (SCHEDULE_ID, "calendars/default/schedule.id"); while(<SCHEDULE_ID> ){$new_default_id = $_ +1;} close SCHEDULE_ID; $bw = File::ReadBackwards->new( "calendars/$calendar/schedule.txt" ) or die "can't read 'schedule.txt' $!" ; until ( $bw->eof ) { push (@line, $bw->readline); # @line holds each line in logfile in reverse order } $size = @line; $size = $size--; @lastline = split(/\t/, $line[0]); @secondlast = split(/\t/, $line[1]); # Single Event if($lastline[1] != $secondlast[1]) { # $last_current_schedule is the event that was just added. open (CURRENTSCHEDULE, "calendars/$calendar/schedule.txt"); my $last_current_schedule; local $_; $last_current_schedule = $_ while <CURRENTSCHEDULE>; @last_current_schedule = split(/\t/, $last_current_schedule); $last_current_schedule[0] = $new_default_id; close CURRENTSCHEDULE; open (SCHEDULE, ">>calendars/default/schedule.txt"); for(0..13) { # Function to print all 14 fields to default/schedule.txt print SCHEDULE $last_current_schedule[$_]; if($_ < 13) { print SCHEDULE "\t"; } } close SCHEDULE; # Increment the ID file open (SID, ">calendars/default/schedule.id"); print SID $new_default_id; close SID;
} # Multiple Events else { # Gets default schedule values $bw1 = File::ReadBackwards->new( "calendars/default/schedule.txt" ) or die "can't read 'schedule.txt' $!"; $lastsched = $bw1->readline; @lastsched = split(/\t/, $lastsched); if($lastsched[0] == "#format:id"){ $sid = 2; } else { $sid = $lastsched[0] + 1; } if($lastsched[1] == "event_id") { $eid = 2; } else { $eid = $lastsched[1] + 1; } $bw1 -> close; # Gets current schedule values push @output, $line[0]; push @output, $line[1]; for (2..$size) { @nextline = split(/\t/, $line[$_]); if($lastline[1] == $nextline[1]) { push @output, $line[$_]; } } # Print added events to default open (SCHEDULE, ">>calendars/default/schedule.txt"); $outsize = @output; $outsize--; # @output = reverse @output; for ($i = $#output; $i >= 0; $i--) { @out = split(/\t/, $output[$i]); $out[0] = $sid; $out[1] = $eid; $sid++; for(0..13) { # Function to print all 14 fields to default/schedule.txt print SCHEDULE $out[$_]; if($_ < 13) { print SCHEDULE "\t"; } } } close SCHEDULE; # Increment the ID file $new_default_id = $lastline[0]; open (SID, ">calendars/default/schedule.id"); print SID $new_default_id; close SID; } $bw -> close; } }}
Bryan WillmanWillman@drexel.edu
foreach (sort keys %in) { if (/^SCHEDULE_(.*)/) { $schedule->{$1} = $in{$_}; } } $db->deleteRecords( {'event_id'=>$event_id} ); if (&Event::scheduleEvent($db, $schedule, $event_id)) { &addUserMessage(&getMessage("SCHEDULE_SAVED")); } else { &addUserMessage(&getMessage("ERROR_WHILE_SAVING_SCHEDULE")); &addUserMessage(&Event::getErrorMessage()); $Template::schedule = $schedule; &showSameScreen(); } &handleCustomFunction("after_schedule_event"); # copying over schedule to default if ($calendar ne default) { open (SCHEDULE_ID, "calendars/default/schedule.id"); while(<SCHEDULE_ID> ){$new_default_id = $_+1;} close SCHEDULE_ID; $bw = File::ReadBackwards->new( "calendars/$calendar/schedule.txt" ) or die "can't read 'schedule.txt' $!" ; until ( $bw->eof ) { push (@line, $bw->readline); # @line holds each line in logfile in reverse order } $size = @line; $size = $size--; @lastline = split(/\t/, $line[0]); @secondlast = split(/\t/, $line[1]); # Single Event if($lastline[1] != $secondlast[1]) { # $last_current_schedule is the event that was just added. open (CURRENTSCHEDULE, "calendars/$calendar/schedule.txt"); my $last_current_schedule; local $_; $last_current_schedule = $_ while <CURRENTSCHEDULE>; @last_current_schedule = split(/\t/, $last_current_schedule); $last_current_schedule[0] = $new_default_id; open (EID, "calendars/default/events.id"); while(<EID> ){ $eid = $_; } close EID; $last_current_schedule[1] = $eid; close CURRENTSCHEDULE; open (SCHEDULE, ">>calendars/default/schedule.txt"); for(0..13) { # Function to print all 14 fields to default/schedule.txt print SCHEDULE $last_current_schedule[$_]; if($_ < 13) { print SCHEDULE "\t"; } } close SCHEDULE; # Increment the ID file open (SID, ">calendars/default/schedule.id"); print SID $new_default_id; close SID;
------------------
Do or can you still add events to the default calendar?
** only going to include the two functions I've modified, add event and add schedule **
What about edit Event and Schedule?
Anyway... I just posted a mirror of TubaDave's 'Unofficial CalendarScript - Mods and PlugIns' site at www.much2.com and added a couple of items. The 'Move Event' plugin might give you some ideas how to simplify posting of events to another calendar without the need for an extra Perl module?
Dan O.
Yes you can still add events to the default calendar. I did not make an edit or delete function. For my purposes I don't need those two, as I plan to feed the calendar from a database, but I imagine other people would be interested in these functions, I'm not sure how difficult it would be, but I'm sure its doable. Its not that I had to use the File::Readbackwards module, but it makes reading backwards a whole lot easier than if I were to program it myself...thats the whole benifit to modules But for now if users wanted to delete/edit something they would have to delete from both that calendar and the default.
bW
There is no reading backwards needed in my 'Move Event' plugin. Utilizing only 1/2 of its code could be used to post events to a second calendar using the data extracted from the original posting. It looks like quite a bit less code than what you've posted.
In fact there's an easier way to get multiple calendar's event data at once which wouldn't require duplication of the data at all. Maybe I'll work on a full fledged plugin myself (if I ever get the time)?
AIM: ZachDHuntYahoo: ZachDHuntMSN: Khayyin@hotmail.comICQ: 158824703IRC: Khayyin (irc.cyberarmy.com:6667, #Khayyin)Email: Khayyin@hotmail.com
The Meta Calendar plug-in at the Unofficial CalendarScript - Mods and Plugins site could probably be changed to just display the default calendar's events on all the other calendars without the need for duplicating each event record. That would also make maintaining those events easier since if any editing was needed, only one record would need to be modified instead one in each of the calendars.
[This message has been edited by DanO (edited March 16, 2003).]