Welcome, Guest. Please login or register.
Did you miss your activation email?


Login with username, password and session length

Search

 
Advanced search

8043 Posts in 1856 Topics- by 2099 Members - Latest Member: roi
Calendar Script CommunityCustomizationHacks and Mods (Moderators: scott, DanO, Marty)Successful Meta-Calendar Hack
Pages: [1]   Go Down
Print
Author Topic: Successful Meta-Calendar Hack  (Read 756 times)
0 Members and 1 Guest are viewing this topic.
Willman023
New Member
*

Karma: 0
Offline Offline

Posts: 0

Web Programmer


WWW
« on: November 14, 2002, 12:13:00 PM »

Well I'm pleased to report that I've successfully reverse engineered Matt's script to certain degree to get it to do what I need.  I have it so that if I add any event to any other calender but the default, it copy's the event to the default.  I used a non standard perl module from www.cpan.org,  File::ReadBackwards, so if you too would like to use this you will need to download and install this module.  I'm only going to include the two functions I've modified, add event and add schedule (around line 500 & 1000).  As of now I have not incorporated a delete function.  But if somebody does add this feature, please let me know.

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..Cool { # Function to print all 9 fields to default/events.txt
            print EVENTS $last_current_event[$_];  
            if($_ < Cool { 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 Willman
Willman@drexel.edu

Logged
Willman023
New Member
*

Karma: 0
Offline Offline

Posts: 0

Web Programmer


WWW
« Reply #1 on: November 14, 2002, 12:52:00 PM »

I hate to do this, but I found a problem with Single Events and had to fix it.  This is for the schedule function.

# -----------------------------------------------
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;
            
            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;

            }
             # 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;
         }
   }
}

------------------

Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 230

Please don't PM me. Post in the open forum.


WWW
« Reply #2 on: November 14, 2002, 09:04:00 PM »

** if I add any event to any other calender but the default, it copy's the event to the default. **

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.

------------------

Logged
Willman023
New Member
*

Karma: 0
Offline Offline

Posts: 0

Web Programmer


WWW
« Reply #3 on: November 15, 2002, 07:43:00 AM »

Dan,

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

------------------

Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 230

Please don't PM me. Post in the open forum.


WWW
« Reply #4 on: November 15, 2002, 01:39:00 PM »

** 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... **

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)?

Dan O.

------------------

Logged
Willman023
New Member
*

Karma: 0
Offline Offline

Posts: 0

Web Programmer


WWW
« Reply #5 on: November 15, 2002, 02:29:00 PM »

Shoot, maybe u should write a meta-calendar mod...would have saved me alot of time

------------------

Logged
Khayyin
Guest
« Reply #6 on: December 06, 2002, 10:17:00 AM »

I work with a programming group with a very hierarchical structure. Would there be any way to have a calendar for each group, with each groups calendar incorporating all events in calendars above? That way, a compnay-wide event would show up on every calendar in the system, while an event set by a group of five people would only be seen by those five people. This would probably require a full plugin for ease of administration, so I understand if no one is interested in doing it for us. But if it is possible, would anyone be willing to help us out a little? We have our own programmers, but none of them are as  familiar with the workings as you are. If anyone can help, please contact me.

AIM: ZachDHunt
Yahoo: ZachDHunt
MSN: Khayyin@hotmail.com
ICQ: 158824703
IRC: Khayyin (irc.cyberarmy.com:6667, #Khayyin)
Email: Khayyin@hotmail.com

Logged
Molly_E
New Member
*

Karma: 0
Offline Offline

Posts: 0


WWW
« Reply #7 on: March 15, 2003, 10:44:00 PM »

Anyone got a hack that does the exact opposite of this? (add event to default cal, and it gets added to all of them)

------------------

Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 230

Please don't PM me. Post in the open forum.


WWW
« Reply #8 on: March 16, 2003, 06:57:00 PM »

** Anyone got a hack that does the exact opposite of this? **

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.

Dan O.

------------------

[This message has been edited by DanO (edited March 16, 2003).]

Logged
jimnycricket
New Member
*

Karma: 0
Offline Offline

Posts: 0

Clergy


WWW
« Reply #9 on: September 23, 2003, 04:21:00 PM »

MEta Calendar is working beautifully...however I can't have the description shown when entered by other user than Adminstrator...what permission do I need to give each of the users so their description will show up on the "meta Calendar?"

------------------

Logged
Pages: [1]   Go Up
Print
Jump to: