"Fossies" - the Fresh Open Source Software Archive

Member "metadot/metadot/Gizmo/AggregatedCalendar.pm" (17 Oct 2005, 8601 Bytes) of package /linux/www/old/Metadot6.4.5.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AggregatedCalendar.pm" see the Fossies "Dox" file reference documentation.

    1 ###########################################################################
    2 # <LICENSEINFO>
    3 # Copyright (C) Daniel Guermeur - 1999-2001
    4 # Copyright (C) Metadot Corporation - 2001-2005
    5 #
    6 # This file is part of Metadot Portal Server software $Name: Release_6_4_5_4 $
    7 #
    8 # Metadot Portal Server software is free software; you can
    9 # redistribute it and/or modify it under the terms of the GNU General Public
   10 # License as published by the Free Software Foundation; either version 2 of
   11 # the License, or (at your option) any later version.
   12 #
   13 # Metadot Portal Server software is distributed in the hope that it
   14 # will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
   15 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
   16 # Public License for more details.
   17 #
   18 # You should have received a copy of the GNU General Public License along with
   19 # Metadot Portal Server; if not, write to the Free Software
   20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21 #
   22 # For more information, please contact info@metadot.com.
   23 #</LICENSEINFO>
   24 ############################################################################
   25 package AggregatedCalendar;
   26 
   27 use strict;
   28 use CGI;
   29 use CGI qw(escapeHTML);
   30 use Metadot qw($USER %FORM $SESSION $HTTP_HEADER_SENT $PARAMS $DISPLAY);
   31 
   32 use Gizmo::Calendar;
   33 use DBAccess; 
   34 use Time::Local;
   35 use Utility;
   36 use vars qw(@ISA);
   37 
   38 @ISA=qw(Calendar);
   39 
   40 sub get_gizmo_name {
   41    my $self = shift;
   42    return "Aggregated Calendar View";
   43 }
   44 
   45 
   46 sub exec_show_summary {
   47     my $self = shift;
   48 
   49     return $self->SUPER::show_in_column(@_);
   50 }
   51 
   52 sub show_edit_form {
   53     my $self  = shift;
   54     my $title = shift;
   55 
   56     my $name = $self->name();
   57 
   58     my $clist = $self->get_calendar_selection_list();
   59 
   60     # We have to construct the edit form to get a list of all the calendars available
   61     my $html = "<h1>$title</h1>\n";
   62 
   63     $html .= "<b>Aggregated Calendar View name</b><br/>\n"
   64              ."<input type='text' name='name' size='55' maxlength='255' value='$name' />\n"
   65              ."<input type='hidden' name='c5' value='1' />\n"
   66              ."<input type='hidden' name='c3' value='on' />\n"
   67              ."<div style='margin-top: 40px'>The following is a list of available calendars</div>\n"
   68              ."<div id='aggregated_calendar_view_list'>\n"
   69              ."  <table border='2' cellspacing='2' cellpadding='2' width='45%' >\n"
   70              ."    <tr>\n"
   71              ."      <td><b>Add</b></td>\n"
   72              ."      <td><b>Calendar Name</b></td>\n"
   73              ."      <td><b>Description</b></td>\n"
   74              ."    </tr>\n";
   75 
   76     my $calendars = $self->get_all_calendars();
   77 
   78     foreach my $cal( @$calendars ){
   79        $DISPLAY->debug_msg(5,"got calendar id[".$cal->{iid}."]");
   80 
   81        my $cid   = $cal->id();
   82        my $cname = $cal->name();
   83        my $desc  = $cal->description() || '&nbsp;';
   84 
   85        my $checked = $self->is_calendar_selected($cid,$clist);
   86 
   87        my $cal_url = $self->make_url("index.pl?iid=$cid&amp;isa=Calendar&amp;op=show");
   88 
   89        $html .=  "    <tr>\n"
   90                 ."      <td><input type='checkbox' name='calendar_$cid' value='$cid' $checked /></td>\n"
   91                 ."      <td><a href='$cal_url'>$cname</a></td>\n"
   92                 ."      <td>$desc</td>\n"
   93                 ."    </tr>\n";
   94     }
   95     $html .=  "  </table>\n"
   96             . "</div>\n";
   97 
   98     return $html;
   99 }
  100 
  101 sub get_all_calendars {
  102     my $self = shift;
  103 
  104     $DISPLAY->debug_msg(5,"IN get all calendars");
  105     my @all_calendars = $self->get_object_accessor()->retrieve_where(where=>"isa='Calendar'");
  106     my @calendars = ();
  107 
  108     foreach my $calendar (@all_calendars) {
  109       if ($calendar->is_allowed_to_do('show')) {
  110         $DISPLAY->debug_msg(5,"IN get all calendars calendar[".$calendar->id()."] will be added");
  111         push @calendars, $calendar;
  112       }
  113     }
  114 
  115     return \@calendars;
  116 }
  117 
  118 sub get_calendar_selection_list {
  119     my $self = shift;
  120 
  121     my @list = split(/,/,$self->t10());
  122     return \@list;
  123 }
  124 
  125 sub get_calendar_selection_list_string {
  126     my $self = shift;
  127  
  128     return join(',',@{$self->get_calendar_selection_list()});
  129 }
  130 
  131 sub is_calendar_selected {
  132     my $self  = shift;
  133     my $cid   = shift;
  134     my $clist = shift;
  135 
  136     my $result = '';
  137 
  138     foreach my $cal(@$clist){
  139        if( $cid == $cal ){
  140            $DISPLAY->debug_msg(5,"Calendar[$cid] is selected!");
  141            return "checked='true'";
  142        }
  143     }
  144 
  145     return $result;
  146 }
  147 
  148 sub www_save {
  149     my $self = shift;
  150 
  151     my $calendar_selection;
  152     foreach my $key( keys %FORM){
  153        if( $key =~ "calendar_" ){
  154            $calendar_selection .= "$FORM{$key},";
  155        }
  156     }
  157 
  158     $self->t10($calendar_selection);
  159 
  160     $self->SUPER::www_save();
  161 }
  162 
  163 sub _get_parent_list {
  164     my $self = shift;
  165     $DISPLAY->debug_msg(5,"IN _get_parent_list");
  166     return $self->get_calendar_selection_list();
  167 }
  168 
  169 sub www_add_child {
  170     my $self = shift;
  171     my $args = shift || {};
  172 
  173     ## We do not want to allow adding events to an
  174     ## aggregated calendar
  175     $DISPLAY->debug_msg(5,"In add_child"); 
  176 
  177     my $dt = $args->{datetime};
  178    
  179     my $html = "<div><b>Please click on the calendar to which you want to add an event</b></div><br/>";
  180 
  181     foreach my $cal(@{$self->get_calendar_selection_list}){
  182        my $c = Calendar->new($cal);
  183        $html .= '<div>'.$c->make_add_event_link({datetime=>$dt, text=>$c->name(),view_mode=>'day'}).'</div>';
  184     } 
  185   
  186     $self->print_form($html,"Adding new event");
  187 
  188 }
  189 
  190 sub get_monthly_events_for_view {
  191     my $self = shift;
  192 
  193     $DISPLAY->debug_msg(5,"-IN get_monthly_events_for_view");
  194     my $start = '1122786000';
  195     my $end   = '1125809999';
  196     my $parents = $self->get_calendar_selection_list_string();
  197 
  198     my ($start_datetime, $end_datetime) = $self->_get_datetimes_of_month_display();
  199 
  200     my @start_date_array = (localtime($start_datetime))[3,4,5];
  201     my @end_date_array = (localtime($end_datetime))[3,4,5];
  202   
  203     $start = timelocal(0, 0, 0, @start_date_array);
  204     $end   = timelocal(0, 0, 0, @end_date_array);
  205        
  206     my $events = DBAccess->sqlSelectMany(
  207                     "distinct iid, i1",
  208                     "instance",
  209                     "parentiid in ($parents) AND
  210                      isa = 'Event' AND
  211                      i1 >= $start AND i1 <= $end",
  212                     "order by i1"
  213                  );
  214     $DISPLAY->debug_msg(5,"Get_montly_events_for_view will return events".$DISPLAY->dumper($events));        
  215     return $events; 
  216 }
  217 
  218 sub generate_day_view {
  219     my $self = shift;
  220     my $args = shift || {};
  221 
  222     $DISPLAY->debug_msg(5,"IN generate_day_view");
  223     $args->{disable_add_event} = 0;
  224 
  225     return $self->SUPER::generate_day_view($args);
  226 }
  227 
  228 sub get_day_event_listing {
  229     my $self = shift;
  230  
  231     $DISPLAY->debug_msg(5,"IN get_day_event_listing");
  232     my $selected_calendars = $self->get_calendar_selection_list();
  233     my $events_hash = {};
  234     my @column_maxes;
  235 
  236     # We will build a has as follows:
  237     # $events_hash->{event_hour}->{event_id}->{event_details}
  238 
  239     # Get events for selected calendars and build the
  240     # event hash
  241     foreach my $cal (@$selected_calendars){
  242        ## For each calendar, traverse down the event hash
  243        my $c = Calendar->new($cal);
  244 
  245        foreach my $hour (keys (%{$c->{events}})){
  246          my $event_id = $c->{events}->{$hour};
  247          foreach my $event_id (keys(%{$c->{events}->{$hour}}) ){
  248              $DISPLAY->debug_msg(5," I HAVE event[$event_id]");
  249     
  250              # Alter the description of the event to add calendar name
  251              my $desc = $c->{events}->{$hour}->{$event_id}->{'desc'};
  252              $desc .= "&nbsp;(".$c->name.")";
  253              $c->{events}->{$hour}->{$event_id}->{'desc'} = $desc;
  254 
  255              #$DISPLAY->debug_msg(5,"WILL add HOUR[$hour] event_id[$event_id] into events hash".$DISPLAY->dumper($c->{events}->{$hour}->{$event_id}));
  256              $events_hash->{$hour}->{$event_id} = $c->{events}->{$hour}->{$event_id};
  257 
  258              # Keep track of the maximum number of columns per event
  259              push @column_maxes, $c->{'MAXCOLS'};
  260          }
  261        }
  262     }
  263 
  264     #Determine the max column_maxa
  265     @column_maxes = sort @column_maxes;
  266     my $maxcol = pop @column_maxes;
  267     $events_hash->{MAXCOLS} = $maxcol + 1;
  268 
  269     # Add a list of calendars that were included in this event list
  270     $events_hash->{calendar_list} = $self->get_calendar_selection_list_string();
  271 
  272     $self->{events} = $events_hash;
  273 
  274     #$DISPLAY->debug_msg(5,"<br><br><br>++++++++++++++++++Final Hash is<br>".$DISPLAY->dumper($events_hash));
  275 
  276     return $self->SUPER::get_day_event_listing($events_hash);
  277 }
  278