#!/usr/bin/perl # MimerDesk # Web based groupware and eLearning environment # www.mimerdesk.org # # Copyright (C) 2001 Ionstream Ltd. # www.ionstream.fi # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 2 of the License, or (at your option) # any later version. # # This program is distributed with a hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # $Id: calendar.html,v 1.39 2002/06/17 12:27:53 inf Exp $ #"""""""""""""""""""""""""""""""""""""""""# # # # MimerDesk: Calendar # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # (c) Ionstream Oy 1999 - 2001 # # # # Programmed by: Hannes Muurinen # # # #_________________________________________# use lib::MimerDesk; use strict; use vars qw($form $APPLICATION $USER $IP $LAST_ACT $FORWARDED $TIME_USED $IDLE $ACTIVEGRP %calendarcolors %month_names %month_names_short %day_names @date %calendar_sizes %day_names_long $grid $calendar_status $default_hour $admin_status $GROUPACTIVOR $CALENDAR $CALENDARUSER $edit_on @startepochs @endepochs @eventcolors $num_of_events $gettext); use CGI::Carp "fatalsToBrowser"; $APPLICATION = 'Personal - Calendar'; sub print_template; sub abs_days_in_between; sub day_num; sub floor; sub days_in_month; sub leapyear; sub day_of_the_week; sub build_calendar; sub build_cal_month; sub build_cal_year; sub weekday_cells; sub add_grid; read_config('../config/mimerdesk.cfg'); initialize(); $form = decode_multipart(); $form->{'ID'} =~ tr/0-9//cd; $form->{'auth'} =~ tr/0-9a-z//cd; ($USER, $IP, $LAST_ACT, $FORWARDED, $TIME_USED, $IDLE, $ACTIVEGRP) = authenticate($form->{'ID'}, $form->{'auth'}, $form->{'changeGroup'}); $gettext = lib::MimerDesk->new_gettext(program => 'calendar',language => $config{'language'}); $config{'theme'} = 'default'; $APPLICATION = $gettext->gettext('Personal - Calendar'); # The colors of the calendar in a hash: %calendarcolors = ( # The colors displayed in the second row of the calendar text_num_of_week => "8A9AB5", # the cell containing the text 'week' text_time => "8A9AB5", # the cell containing the text 'time' day_montuewedthufri => "8A9AB5", # monday, tuesday,... , friday day_sat => "8A9AB5", # Saturday day_sun => "8A9AB5", # Sunday # The colors of the days of the calendar for even months 2 => "FFFFFF", # mon 3 => "FFFFFF", # tue 4 => "FFFFFF", # wed 5 => "FFFFFF", # thu 6 => "FFFFFF", # fri 0 => "F6F8FA", # sat 1 => "DCE1E8", # sun # The colors of the days of the calendar for odd months 9 => "E7EBF1", # mon 10 => "E7EBF1", # tue 11 => "E7EBF1", # wed 12 => "E7EBF1", # thu 13 => "E7EBF1", # fri 7 => "DDE3ED", # sat 8 => "CFD6E0", # sun curr_day => "E4F4ED", # the background color of the current day gridcolor => "000000", # the grid color of the calendar num_week_col => "B1BBCB", # the background color of the numbers of week in the left side of the calendar hour => "B1BBCB", # the background color of the hour markers in the left side of the calendar (week&day views) month_date => "AAB8CE", # the background color of the date cells in month view # Colors for occupied timeblocks: occ_curr_day => "F4E4ED", # days of even months, occupied occ_2 => "FFEEEE", # mon occ_3 => "FFEEEE", # tue occ_4 => "FFEEEE", # wed occ_5 => "FFEEEE", # thu occ_6 => "FFEEEE", # fri occ_0 => "F6E8EA", # sat occ_1 => "DCD1D8", # sun # days of odd months, occupied occ_9 => "E7DBE1", # mon occ_10 => "E7DBE1", # tue occ_11 => "E7DBE1", # wed occ_12 => "E7DBE1", # thu occ_13 => "E7DBE1", # fri occ_7 => "DDD3DD", # sat occ_8 => "CFC6D0", # sun ); %month_names = ( 1 => $gettext->gettext("January"), 2 => $gettext->gettext("February"), 3 => $gettext->gettext("March"), 4 => $gettext->gettext("April"), 5 => $gettext->gettext("May"), 6 => $gettext->gettext("June"), 7 => $gettext->gettext("July"), 8 => $gettext->gettext("August"), 9 => $gettext->gettext("September"), 10 => $gettext->gettext("October"), 11 => $gettext->gettext("November"), 12 => $gettext->gettext("December"), '01' => $gettext->gettext("January"), '02' => $gettext->gettext("February"), '03' => $gettext->gettext("March"), '04' => $gettext->gettext("April"), '05' => $gettext->gettext("May"), '06' => $gettext->gettext("June"), '07' => $gettext->gettext("July"), '08' => $gettext->gettext("August"), '09' => $gettext->gettext("September") ); # the shorter versions of the names %month_names_short = ( 1 => $gettext->gettext("Jan"), 2 => $gettext->gettext("Feb"), 3 => $gettext->gettext("Mar"), 4 => $gettext->gettext("Apr"), 5 => $gettext->gettext("May"), 6 => $gettext->gettext("Jun"), 7 => $gettext->gettext("Jul"), 8 => $gettext->gettext("Aug"), 9 => $gettext->gettext("Sep"), 10 => $gettext->gettext("Oct"), 11 => $gettext->gettext("Nov"), 12 => $gettext->gettext("Dec") ); # the names of the days of the week (in a hash for easy customication) %day_names = (0 => $gettext->gettext("Sat"), 1 => $gettext->gettext("Sun"), 2 => $gettext->gettext("Mon"), 3 => $gettext->gettext("Tue"), 4 => $gettext->gettext("Wed"), 5 => $gettext->gettext("Thu"), 6 => $gettext->gettext("Fri")); #long day names: %day_names_long = (0 => $gettext->gettext("Saturday"), 1 => $gettext->gettext("Sunday"), 2 => $gettext->gettext("Monday"), 3 => $gettext->gettext("Tuesday"), 4 => $gettext->gettext("Wednesday"), 5 => $gettext->gettext("Thursday"), 6 => $gettext->gettext("Friday")); %calendar_sizes = ( horiz_size => "13%", # the horizontal size of the table cells vert_size_date => "15", # the vertical size of the date table cells (month&year views) vert_size => "85", # the vertical size of the event table cells (month&year views) vert_size_wv => "15", # the vertical size of the hour cells for week view (wv) vert_size_day => "15", # the vertical size of the hour cells for day view cal_size => "100%", # the horizontal size of the whole calendar week_horiz => "2%", # the horizontal size of the number-of-the-week cells time_horiz => "2%", # the horizontal size of the time cells (week view) day_horiz => "95%", # the horizontal size of the cell in day-view day_horiz_hour => "5%", # the horizontal size of the hour cell in day-view ); $grid = "on"; # off $default_hour = "08"; # the default hour that is sent to the calendar_add_event.html in month and year views $CALENDAR = 'calendar'; # the database table name $CALENDARUSER = ''; # the user of the calendar (group name for public group calendars, user's login name for private calendar) $edit_on = 'true'; # no links to the calendar_add_event -page are printed if !$edit_on (if the user hasn't rights to modify a public calendar, $edit_on = '') $num_of_events = 0; # the number of loaded events (== the number of start/end epoch pairs and items in @eventcolors) # The main program ################### $CALENDARUSER = $USER; # alustavasti if ($form->{'grouptool'} =~ /^\d+$/) { lock_tables('READ', 'groupusers'); db_list("SELECT RIGHTS,USER FROM groupusers where USER = '$USER' and GID = '$form->{'grouptool'}'"); while (my $ref = $sth->fetchrow_hashref()) { $admin_status = $ref->{'RIGHTS'}; $GROUPACTIVOR = $ref->{'USER'}; } db_end(); unlock_tables(); if (!$GROUPACTIVOR) { lock_tables('READ', 'users'); db_list("SELECT * FROM users where nimi = '$USER'"); while (my $ref = $sth->fetchrow_hashref()) {$admin_status = $ref->{'flags'};} db_end(); unlock_tables(); } else { $CALENDAR = "$form->{'grouptool'}_$CALENDAR"; $CALENDARUSER = $form->{'grouptool'}; } $edit_on = '' if $admin_status !~ /C0/; # only checked in public calendars } else { lock_tables('READ', 'users'); db_list("SELECT * FROM users where nimi = '$USER'"); while (my $ref = $sth->fetchrow_hashref()) {$admin_status = $ref->{'flags'};} db_end(); unlock_tables(); } $form->{'view'} = 'week' if $form->{'view'} eq ""; # näin testivaiheessa vain.. tähän voisi lukea es. defaultnäkymän asetuksista @date = utc_epoch2date(time); # If the date is undefined, we'll use the current date: check_date(); $calendar_status = check_form_data(); my $send_event_message = ''; if($form->{'selectedGO'} eq 'Remove') { $send_event_message = remove_selected_events(); } elsif($form->{'selectedGO'} eq 'Groupsend' and $GROUPACTIVOR and $edit_on) { $send_event_message = fetch_group_members(); } elsif($form->{'selectedGO'} eq 'Personaladd' and $GROUPACTIVOR) { $send_event_message = add_selected_to_personal_cal(); } $send_event_message = send_events() if($form->{'sendstuff'} eq 'Send events' && $form->{'send_these'} =~ tr/a-z0-9_ //c == 0); if($form->{'selectedGO'} eq 'Send') { print_send_events_template("$config{'theme'}_calendar_send_events");} elsif($form->{'selectedGO'} eq 'View') { print_view_events_template("$config{'theme'}_calendar_view_events");} elsif($form->{'view'} eq 'list') { print_list_events_template("$config{'theme'}_calendar_list_events");} else { print_template("$config{'theme'}_calendar", $send_event_message); } # Subs: ########### # print_template # # 1. makes the calendar / error message (if invalid data is given) # 2. prints the header # 3. concatenates the different parts of the page # 4. replaces the <<>>-tags (including the <>-tag) # 5. prints the rest of the page # sub print_template { my ($calendartopic, $template, $ref, $fulltemplate, $calendar, $navigation_right, $calinfo, $navigation_left, $num_of_checkboxes, $send_ev_msg); ($template, $send_ev_msg) = @_; if ($calendar_status ne 'ok') {$calendar = calendar_error_message($calendar_status);} else {($calendar,$navigation_left, $navigation_right, $calinfo, $num_of_checkboxes) = build_calendar($form->{'view'},$form->{'day'},$form->{'month'},$form->{'year'});} if ($form->{'grouptool'} !~ /^\d+$/) { lock_tables('READ', 'users'); db_list("SELECT info FROM users where nimi = '$CALENDARUSER'"); while (my $ref = $sth->fetchrow_hashref()) {$calendartopic = "$CALENDARUSER ($ref->{'info'})";} db_end(); unlock_tables(); } else { lock_tables('READ', 'groups'); db_list("SELECT GRPNAME FROM groups where GID = '$CALENDARUSER'"); while (my $ref = $sth->fetchrow_hashref()) {$calendartopic = $ref->{'GRPNAME'};} db_end(); unlock_tables(); } $calinfo = sprintf($gettext->gettext('%s\'s calendar'),$calendartopic)." - $calinfo"; print_header('pragma'); $ref = get_template('maintemplate',$template); $ref->{'maintemplate'} =~ s/<>/$ref->{$template}/m; $fulltemplate = $ref->{'maintemplate'}; if ($GROUPACTIVOR) { $fulltemplate = create_buttons($fulltemplate, 'Group', 'Calendar', $form); $APPLICATION = $gettext->gettext('Group - Calendar'); } else {$fulltemplate = create_buttons($fulltemplate, 'Personal', 'Calendar', $form);} $fulltemplate =~ s/<>/minea/gm; $ref = get_template('js_doClock', 'js_help', 'js_gotosite'); my $stuff = $ref->{'js_doClock'}.$ref->{'js_help'}.$ref->{'js_gotosite'}; $fulltemplate =~ s/<>/$stuff/ms; $fulltemplate =~ s/<>/MimerDesk\: $APPLICATION/ms; $fulltemplate =~ s/<>/$num_of_checkboxes/ms; $fulltemplate =~ s/<>/$calendarcolors{'curr_day'}/ms; $fulltemplate =~ s/<>/$calendarcolors{'9'}/ms; $fulltemplate =~ s/<>/$calendarcolors{'2'}/ms; $fulltemplate =~ s/<>/$calendarcolors{'0'}/ms; $fulltemplate =~ s/<>/$calendarcolors{'7'}/ms; $fulltemplate =~ s/<>/$calendarcolors{'1'}/ms; $fulltemplate =~ s/<>/$calendarcolors{'8'}/ms; $fulltemplate =~ s/<>/$send_ev_msg/ms; $fulltemplate =~ s/<>/$calinfo/ms; my ($nextalttext, $previousalttext) = ($gettext->gettext('NEXT'),$gettext->gettext('PREVIOUS')); $fulltemplate =~ s/<>/[ ${nextalttext} ]<\/a>/ms; $fulltemplate =~ s/<>/[ ${previousalttext} ]<\/a>/ms; $fulltemplate =~ s/<>/$calendar/ms; $fulltemplate =~ s/<>/$form->{'day'}/ms; $fulltemplate =~ s/<>/$form->{'month'}/ms; $fulltemplate =~ s/<>/$form->{'year'}/ms; $fulltemplate =~ s/<>/$form->{'grouptool'}/msg; $stuff = make_calendar_view_options($form->{'view'}); $fulltemplate =~ s/<>/$stuff/ms; my @dropitems = ('View details of the event(s)' ,'Send event(s) to a friend'); my %dropvalues = ('View details of the event(s)' => $gettext->gettext('View details of the event(s)'), 'Send event(s) to a friend' => $gettext->gettext('Send event(s) to a friend')); if ($GROUPACTIVOR) { if ($admin_status =~ /C0/) { push @dropitems, 'Remove event(s)'; push @dropitems, 'Send event(s) to all members of this group'; $dropvalues{'Remove event(s)'} = $gettext->gettext('Remove event(s)'); $dropvalues{'Send event(s) to all members of this group'} = $gettext->gettext('Send event(s) to all members of this group'); } push @dropitems, 'Add event(s) to my personal calendar'; $dropvalues{'Add event(s) to my personal calendar'} = $gettext->gettext('Add event(s) to my personal calendar'); } else { push @dropitems, 'Remove event(s)'; $dropvalues{'Remove event(s)'} = $gettext->gettext('Remove event(s)'); } my %dropargs = (name => 'checkboxaction', order => \@dropitems, 'values'=> \%dropvalues, default => 'View details of the event(s)' ); $stuff = dropdownmenu(%dropargs); $fulltemplate =~ s/<>/$stuff/ms; # make the quick calendar access menu: @dropitems = (''); my %groupIDhash = ('' => $gettext->gettext('Personal calendar')); lock_tables('READ', 'groups', 'groupusers'); db_list("SELECT groups.TOOLS,groups.GRPNAME,groups.GID FROM groups,groupusers where groupusers.USER = '$USER' and groupusers.GID = groups.GID"); while (my $ref = $sth->fetchrow_hashref()) { push @dropitems, $ref->{'GID'} if $ref->{'TOOLS'} =~ /C/; $groupIDhash{$ref->{'GID'}} = "$ref->{'GRPNAME'} ". $gettext->gettext('(group)'); } db_end(); unlock_tables(); %dropargs = ( name => 'quickcalaccess', order => \@dropitems, default => $form->{'grouptool'}, onChange => 'return change_calendar();', 'values' => \%groupIDhash ); $stuff = dropdownmenu(%dropargs); $fulltemplate =~ s/<>/$stuff/ms; # $form->{'day'} = '0'.$form->{'day'} while length($form->{'day'}) < 2; # @dropitems = ('01'..'31'); # %dropargs = ( name => 'day', # order => \@dropitems, # default => $form->{'day'}, # ); # $stuff = dropdownmenu(%dropargs); # $form->{'month'} = '0'.$form->{'month'} while length($form->{'month'}) < 2; # @dropitems = ('01'..'12'); # %dropargs = ( name => 'month', # order => \@dropitems, # default => $form->{'month'}, # ); # $stuff .= dropdownmenu(%dropargs); # my @dropdownyears; # for(my $i = $date[5]-5;$i<=$date[5]+10;$i++) {push @dropdownyears,$i}; # %dropargs = ( name => 'year', # order => \@dropdownyears, # default => $form->{'year'}, # ); # $stuff .= dropdownmenu(%dropargs); $stuff = date_dropdown($form->{'day'},$form->{'month'},$form->{'year'},'day','month','year'); $fulltemplate =~ s/<>/$stuff/ms; #make the category filter dropdown: @dropitems = (''); %dropvalues = ('' => $gettext->gettext('every')); push (@dropitems, fetch_user_categories($CALENDARUSER,$CALENDAR)); foreach(@dropitems) {$dropvalues{$_} = $_ if $_ ne '';} %dropargs = ( name => 'category_filter', order => \@dropitems, 'values'=> \%dropvalues, default => $form->{'category_filter'} ); $stuff = dropdownmenu(%dropargs); $fulltemplate =~ s/<>/$stuff/ms; $fulltemplate = replace_tags($fulltemplate, $USER, $form->{'auth'}, $form->{'ID'}, $TIME_USED); $fulltemplate = add_popups($fulltemplate, $USER, $form->{'auth'}, $form->{'ID'}); print $fulltemplate; db_end('disconnect'); exit; } ######################################################################### # print_send_events_template - prints the send_events template # #-----------------------------------------------------------------------# # # ######################################################################### sub print_send_events_template { my ($template, $ref, $fulltemplate, $calendar, $navigation_right, $calinfo, $navigation_left, $num_of_checkboxes); $template = shift; my $eventstuff = get_selected_event_details('print_hidden_IDs','notmodify','noemptymessages','norecurrence','noreminder'); if($eventstuff eq '') { print_template("$config{'theme'}_calendar", tag('div', {class => 'error'}).$gettext->gettext('No events selected!').endtag('div')); } else { print_header('pragma'); $ref = get_template('maintemplate',$template); $ref->{'maintemplate'} =~ s/<>/$ref->{$template}/m; $fulltemplate = $ref->{'maintemplate'}; if ($GROUPACTIVOR) { $fulltemplate = create_buttons($fulltemplate, 'Group', 'Calendar', $form); $APPLICATION =~ s/Personal/Group/; } else {$fulltemplate = create_buttons($fulltemplate, 'Personal', 'Calendar', $form);} $fulltemplate =~ s/<>/minea/gm; $ref = get_template('js_doClock', 'js_help', 'js_gotosite'); my $stuff = $ref->{'js_doClock'}.$ref->{'js_help'}.$ref->{'js_gotosite'}; $fulltemplate =~ s/<>/$stuff/ms; $fulltemplate =~ s/<>/MimerDesk\: $APPLICATION/ms; $fulltemplate =~ s/<>/$form->{'day'}/ms; $fulltemplate =~ s/<>/$form->{'month'}/ms; $fulltemplate =~ s/<>/$form->{'year'}/ms; $fulltemplate =~ s/<>/$form->{'grouptool'}/ms; $fulltemplate =~ s/<>/$form->{'view'}/ms; $stuff = ''; db_list("select users.nimi,users.info from users,friends where users.nimi = friends.friend and friends.user = '$USER' order by users.nimi"); while (my $ref = $sth->fetchrow_hashref()) {$stuff .= qq[\n] if $ref->{'nimi'} ne $CALENDARUSER;} db_end(); $fulltemplate =~ s/<>/$stuff/ms; $stuff = ''; db_list("select GID,GRPNAME,TOOLS from groups order by GRPNAME"); while (my $ref = $sth->fetchrow_hashref()) {$stuff .= qq[\n] if $ref->{'TOOLS'} =~ /C/;} db_end(); $fulltemplate =~ s/<>/$stuff/ms; $fulltemplate =~ s/<>/$eventstuff/ms; $fulltemplate = replace_tags($fulltemplate, $USER, $form->{'auth'}, $form->{'ID'}, $TIME_USED); $fulltemplate = add_popups($fulltemplate, $USER, $form->{'auth'}, $form->{'ID'}); print $fulltemplate; db_end('disconnect'); exit; } } ######################################################################### # print_view_events_template - prints the send_events template # #-----------------------------------------------------------------------# # # ######################################################################### sub print_view_events_template { my ($template, $ref, $fulltemplate, $calendar, $navigation_right, $calinfo, $navigation_left, $num_of_checkboxes); $template = shift; my $eventstuff = get_selected_event_details('','','noemptymessages','',''); if($eventstuff eq '') { print_template("$config{'theme'}_calendar", tag('div', {class => 'error'}). $gettext->gettext('No events selected!').endtag('div')); } else { print_header('pragma'); $ref = get_template('maintemplate',$template); $ref->{'maintemplate'} =~ s/<>/$ref->{$template}/m; $fulltemplate = $ref->{'maintemplate'}; if ($GROUPACTIVOR) { $fulltemplate = create_buttons($fulltemplate, 'Group', 'Calendar', $form); $APPLICATION =~ s/Personal/Group/; } else {$fulltemplate = create_buttons($fulltemplate, 'Personal', 'Calendar', $form);} $fulltemplate =~ s/<>/minea/gm; $ref = get_template('js_doClock', 'js_help', 'js_gotosite'); my $stuff = $ref->{'js_doClock'}.$ref->{'js_help'}.$ref->{'js_gotosite'}; $fulltemplate =~ s/<>/$stuff/ms; $fulltemplate =~ s/<>/MimerDesk\: $APPLICATION/ms; $fulltemplate =~ s/<>/$form->{'day'}/ms; $fulltemplate =~ s/<>/$form->{'month'}/ms; $fulltemplate =~ s/<>/$form->{'year'}/ms; $fulltemplate =~ s/<>/$form->{'grouptool'}/ms; $fulltemplate =~ s/<>/$form->{'view'}/ms; $fulltemplate =~ s/<>/$eventstuff/ms; $fulltemplate = replace_tags($fulltemplate, $USER, $form->{'auth'}, $form->{'ID'}, $TIME_USED); $fulltemplate = add_popups($fulltemplate, $USER, $form->{'auth'}, $form->{'ID'}); print $fulltemplate; db_end('disconnect'); exit; } } ######################################################################### # print_list_events_template - prints the list_events template # #-----------------------------------------------------------------------# # # ######################################################################### sub print_list_events_template { my ($template, $ref, $fulltemplate, $calendar, $navigation_right, $calinfo, $navigation_left, $num_of_checkboxes); $template = shift; $form->{'end_day'} = $form->{'day'} if !$form->{'end_day'}; $form->{'end_month'} = $form->{'month'} if !$form->{'end_month'}; $form->{'end_year'} = $form->{'year'} if $form->{'end_year'} eq ''; my %day_info = fetch_events($form->{'day'},$form->{'month'},$form->{'year'}, $form->{'end_day'},$form->{'end_month'},$form->{'end_year'}, $form->{'category_filter'}, '', '', 'return_only_IDs'); $form->{'numofcheckboxes'} = 0; foreach(sort(keys %day_info)) { $form->{"checkb$form->{'numofcheckboxes'}"} = $day_info{$_}; $form->{'numofcheckboxes'}++; } my $eventstuff = get_selected_event_details('','','','',''); print_header('pragma'); $ref = get_template('maintemplate',$template); $ref->{'maintemplate'} =~ s/<>/$ref->{$template}/m; $fulltemplate = $ref->{'maintemplate'}; if ($GROUPACTIVOR) { $fulltemplate = create_buttons($fulltemplate, 'Group', 'Calendar', $form); $APPLICATION =~ s/Personal/Group/; } else {$fulltemplate = create_buttons($fulltemplate, 'Personal', 'Calendar', $form);} $fulltemplate =~ s/<>/minea/gm; $ref = get_template('js_doClock', 'js_help', 'js_gotosite'); my $stuff = $ref->{'js_doClock'}.$ref->{'js_help'}.$ref->{'js_gotosite'}; $fulltemplate =~ s/<>/$stuff/ms; $fulltemplate =~ s/<>/MimerDesk\: $APPLICATION/ms; $fulltemplate =~ s/<>/$form->{'grouptool'}/ms; $fulltemplate =~ s/<>/$form->{'view'}/ms; $fulltemplate =~ s/<>/$eventstuff/ms; $stuff = make_calendar_view_options($form->{'view'}); $fulltemplate =~ s/<>/$stuff/ms; my @dropitems = (''); my %groupIDhash = ('' => $gettext->gettext('Personal calendar')); lock_tables('READ', 'groups', 'groupusers'); db_list("SELECT groups.TOOLS,groups.GRPNAME,groups.GID FROM groups,groupusers where groupusers.USER = '$USER' and groupusers.GID = groups.GID"); while (my $ref = $sth->fetchrow_hashref()) { push @dropitems, $ref->{'GID'} if $ref->{'TOOLS'} =~ /C/; $groupIDhash{$ref->{'GID'}} = "$ref->{'GRPNAME'} ". $gettext->gettext('(group)'); } db_end(); unlock_tables(); my %dropargs =( name => 'quickcalaccess', order => \@dropitems, default => $form->{'grouptool'}, onChange => 'return change_calendar();', 'values' => \%groupIDhash ); $stuff = dropdownmenu(%dropargs); $fulltemplate =~ s/<>/$stuff/ms; $stuff = date_dropdown($form->{'day'},$form->{'month'},$form->{'year'},'day','month','year'); $fulltemplate =~ s/<>/$stuff/ms; $stuff = date_dropdown($form->{'end_day'},$form->{'end_month'},$form->{'end_year'},'end_day','end_month','end_year'); $fulltemplate =~ s/<>/$stuff/ms; #make the category filter dropdown: @dropitems = (''); my %dropvalues = ('' => $gettext->gettext('every')); push (@dropitems, fetch_user_categories($CALENDARUSER,$CALENDAR)); foreach(@dropitems) {$dropvalues{$_} = $_ if $_ ne '';} %dropargs = ( name => 'category_filter', order => \@dropitems, 'values'=> \%dropvalues, default => $form->{'category_filter'} ); $stuff = dropdownmenu(%dropargs); $fulltemplate =~ s/<>/$stuff/ms; $fulltemplate = replace_tags($fulltemplate, $USER, $form->{'auth'}, $form->{'ID'}, $TIME_USED); $fulltemplate = add_popups($fulltemplate, $USER, $form->{'auth'}, $form->{'ID'}); print $fulltemplate; db_end('disconnect'); exit; } ######################################################################### # remove_selected_events - removes the selected events. # #-----------------------------------------------------------------------# # # # returns error/success messages. # # # ######################################################################### sub remove_selected_events { my ($check, $message) = ('',''); # all checkboxes in the form are checked: are there ones selected? for(my $i=0; $i < $form->{'numofcheckboxes'}; $i++) { if($form->{"checkb$i"}) #if the checkbox is checked, do the stuff: { if($GROUPACTIVOR) #group admin check: { if($admin_status =~ /C0/) { my ($ref) = db_select('reminderID',$CALENDAR,"IDnumber = '".$form->{"checkb$i"}."' and user = '$CALENDARUSER'"); db_delete($CALENDAR,"IDnumber = '".$form->{"checkb$i"}."' and user = '$CALENDARUSER'"); db_delete('messages',"TYPE = 'REMINDER' and SENDER = '$USER' and TARGET = '$USER' and MESSAGE = '".$form->{"checkb$i"}."/$form->{'grouptool'}' and LINE = '$ref->{'reminderID'}'"); $check .= 'ok'; } else { } #calendar misuse -- should a note be added to the logs? } else #you don't need admin status to modify your personal calendar: { my ($ref) = db_select('reminderID',$CALENDAR,"IDnumber = '".$form->{"checkb$i"}."' and user = '$CALENDARUSER'"); db_delete($CALENDAR,"IDnumber = '".$form->{"checkb$i"}."' and user = '$CALENDARUSER'"); db_delete('messages',"TYPE = 'REMINDER' and SENDER = '$USER' and TARGET = '$USER' and MESSAGE = '".$form->{"checkb$i"}."/$form->{'grouptool'}' and LINE = '$ref->{'reminderID'}'"); $check .= 'ok'; } } } if(!$check) { $message = tag('div', {class => 'error'}) .$gettext->gettext('No events selected!').endtag('div');} else { $message = tag('div', {class => 'success'}) .$gettext->gettext('Events removed successfully!').endtag('div'); } return $message; } ################################################################################################# # get_selected_event_details - gets the detailed information of the selected events. # #-----------------------------------------------------------------------------------------------# # # # $HTML = get_selected_event_details(['print_hidden_IDs'],['notmodify'],['noemptymessages'],['norecurrence'],['noreminder']); # # # ################################################################################################# sub get_selected_event_details { my ($printid, $nomodify, $noemptymsg, $norecurrence, $noreminder) = @_; my $num_of_hidden = 0; my $HTML_stuff = ''; # all checkboxes in the form are checked: are there ones selected? for(my $i=0; $i < $form->{'numofcheckboxes'}; $i++) { if($form->{"checkb$i"}) #if the checkbox is checked, do the stuff: { db_list("SELECT $CALENDAR.* FROM $CALENDAR where $CALENDAR.IDnumber = '".$form->{"checkb$i"}."' and $CALENDAR.user = '$CALENDARUSER'"); while (my $ref = $sth->fetchrow_hashref()) { my @startdate = utc_epoch2date($ref->{'epoch'}); my @enddate = utc_epoch2date($ref->{'end_epoch'}); my @recenddate = utc_epoch2date($ref->{'rec_end_epoch'}); my ($recurrence_stuff, $second_date_stuff, $recur, $editlink, $reminder_stuff) = ('','','','',''); if ($ref->{'recrule'} ne 'norec') { #my @eventdates = translate_rec_rule($ref->{'recrule'}, $startdate[3],$startdate[4],$startdate[5], $startdate[3],$startdate[4],$startdate[5], $recenddate[3],$recenddate[4],$recenddate[5]); #my $datelist = ''; #foreach(@eventdates) {$datelist .= "$_
\n"}; #$recurrence_stuff = startrow(class => 'content') . column(bgcolor => 'CEDFE8', align => 'left', valign => 'top', width => '29%', content => 'List of recurrence dates') . column(bgcolor => 'FFFFFF', width => '71%', align => 'left', content => "$datelist  ") . endrow(); if($ref->{'recrule'} eq 'daily') { $recur = $gettext->gettext('Daily');} elsif($ref->{'recrule'} eq 'weekly') { $recur = $gettext->gettext('Weekly');} elsif($ref->{'recrule'} eq 'monthly') { $recur = $gettext->gettext('Monthly');} elsif($ref->{'recrule'} eq 'yearly') { $recur = $gettext->gettext('Yearly');} elsif($ref->{'recrule'} eq '2weeks') { $recur = $gettext->gettext('Every two weeks');} #$recur .= " from $startdate[3] $month_names{$startdate[4]} $startdate[5] to $recenddate[3] $month_names{$recenddate[4]} $recenddate[5]"; } else { $recur = $gettext->gettext('No recurrence');} $second_date_stuff = " ".$day_names{day_of_the_week($enddate[3],$enddate[4],$enddate[5])}." $enddate[3] $month_names{$enddate[4]} $enddate[5]" if day_num($startdate[3],$startdate[4],$startdate[5]) != day_num($enddate[3],$enddate[4],$enddate[5]); $editlink = qq[
].$gettext->gettext('Modify this event').qq[] if ($edit_on && $nomodify ne 'notmodify'); if($ref->{'reminderID'}) {$reminder_stuff = $gettext->gettext('Popup');} else {$reminder_stuff = $gettext->gettext('No reminder');} $ref->{'text'} =~ s/\n/
/gm; $ref->{'text'} =~ s/^
//gm; my($sth_stuff); $sth_stuff = "$startdate[2]:$startdate[1] -$second_date_stuff $enddate[2]:$enddate[1]" if($ref->{'time'} ne 'full'); $HTML_stuff .= startrow(class => 'content') . column(bgcolor => 'CEDFE8', align => 'left', valign => 'top', width => '29%', content => $gettext->gettext('Title')) . column(bgcolor => 'FFFFFF', width => '71%', align => 'left', content => "$ref->{'summary'} ") . endrow() . startrow(class => 'content') . column(bgcolor => 'CEDFE8', align => 'left', valign => 'top', width => '29%', content => $gettext->gettext('Description')) . column(bgcolor => 'FFFFFF', width => '71%', align => 'left', content => itag_replacer("$ref->{'text'} ")) . endrow() . startrow(class => 'content') . column(bgcolor => 'CEDFE8', align => 'left', valign => 'top', width => '29%', content => $gettext->gettext('Date & time')) . column(bgcolor => 'FFFFFF', width => '71%', align => 'left', content => $day_names{day_of_the_week($startdate[3],$startdate[4],$startdate[5])}." $startdate[3] $month_names{$startdate[4]} $startdate[5] $sth_stuff ") . endrow() . startrow(class => 'content') . column(bgcolor => 'CEDFE8', align => 'left', valign => 'top', width => '29%', content => $gettext->gettext('Category')) . column(bgcolor => 'FFFFFF', width => '71%', align => 'left', content => "$ref->{'type'} ") . endrow(); $HTML_stuff .= startrow(class => 'content') . column(bgcolor => 'CEDFE8', align => 'left', valign => 'top', width => '29%', content => $gettext->gettext('Recurrence')) . column(bgcolor => 'FFFFFF', width => '71%', align => 'left', content => "$recur ") . endrow() . $recurrence_stuff if(!$norecurrence); #reminder stuff: my ($ref2) = db_select('SEND_TIME','messages',"TYPE = 'REMINDER' and LINE = $ref->{'reminderID'}"); my @reminderdate = utc_epoch2date($ref2->{'SEND_TIME'}); $HTML_stuff .= startrow(class => 'content') . column(bgcolor => 'CEDFE8', align => 'left', valign => 'top', width => '29%', content => $gettext->gettext('Reminder')) . column(bgcolor => 'FFFFFF', width => '71%', align => 'left', content => "$reminder_stuff ") . endrow() if(!$noreminder); $HTML_stuff .= startrow(class => 'content') . column(bgcolor => 'CEDFE8', align => 'left', valign => 'top', width => '29%', content => $gettext->gettext('Reminder time')) . column(bgcolor => 'FFFFFF', width => '71%', align => 'left', content => $day_names{day_of_the_week($reminderdate[3],$reminderdate[4],$reminderdate[5])}." $reminderdate[3] $month_names{$reminderdate[4]} $reminderdate[5] $reminderdate[2]:$reminderdate[1] ") . endrow() if(!$noreminder and $ref->{'reminderID'}); $HTML_stuff .= startrow(class => 'rowTitle') . column(bgcolor => 'AABFD7', colspan => '2', align => 'left', valign => 'top', content => "$editlink ") . endrow(); if($printid eq 'print_hidden_IDs') { $HTML_stuff .= hiddenfield("event$num_of_hidden",$ref->{'IDnumber'}); $num_of_hidden++; } } db_end(); } } $HTML_stuff = startrow(bgcolor => 'FFFFFF', class => 'content') . column(colspan => '2', content => $gettext->gettext('No events to view!')) . endrow() if ($HTML_stuff eq '' && !$noemptymsg); $HTML_stuff .= hiddenfield('num_of_hidden_IDs',$num_of_hidden) if($printid eq 'print_hidden_IDs' && $HTML_stuff ne ''); return $HTML_stuff; } ######################################################################### # send_events - sends the selected events to other users. # #-----------------------------------------------------------------------# # # # returns error/success message. # # # ######################################################################### sub send_events { my ($message, @eventID, @groupNames); my $time = time(); # $form->{'grouptool'} = 0 if $form->{'grouptool'} eq ''; for (my $i=0; $i<$form->{'num_of_hidden_IDs'}; $i++) { push @eventID, $form->{"event$i"};} return tag('div', {class => 'error'}).$gettext->gettext('No events to send!').endtag('div') if @eventID == 0; lock_tables('WRITE', 'messages', $CALENDAR, 'groups'); my $already_added = ''; foreach my $MDeventID (@eventID) { my ($eventref) = db_select('*',$CALENDAR,"IDnumber = '$MDeventID' and user = '$CALENDARUSER'"); $eventref->{'type'} =~ s/"//gsm; $eventref->{'summary'} =~ s/"//gsm; $eventref->{'text'} =~ s/"//gsm; db_end(); foreach (split / /, $form->{'send_these'}) { my ($nimi); next if db_select('MESSAGE','messages',"TYPE = 'CALENDAR' and TARGET = '$_' and MESSAGE = '0/$form->{'grouptool'}/$eventref->{'epoch'}/$eventref->{'end_epoch'}/$eventref->{'type'}/$eventref->{'time'}/$eventref->{'summary'}/$eventref->{'text'}'"); # groupID/events_information -- groupID == 0 => send event to private calendar, else send to group calendar with ID groupID db_list("insert into messages (TARGET,SENDER,TIME,STATUS,MESSAGE,TYPE) values ('$_', '$USER', '$time', 'no','0/$form->{'grouptool'}/$eventref->{'epoch'}/$eventref->{'end_epoch'}/$eventref->{'type'}/$eventref->{'time'}/$eventref->{'summary'}/$eventref->{'text'}','CALENDAR')"); db_end(); } foreach my $groupID (split / /, $form->{'send_these_groups'}) { my ($reff) = db_select('CREATOR,GRPNAME','groups',"GID ='$groupID'"); my $groupname = $reff->{'GRPNAME'}; my $groupadmin = $reff->{'CREATOR'}; if ($already_added !~ / $MDeventID /) { push @groupNames, $groupname if !(grep /^$groupname$/, @groupNames); $already_added .= " $MDeventID "; } db_end(); next if db_select('MESSAGE','messages',"TYPE = 'CALENDAR' and TARGET = '$groupadmin' and MESSAGE ='$groupID/$form->{'grouptool'}/$eventref->{'epoch'}/$eventref->{'end_epoch'}/$eventref->{'type'}/$eventref->{'time'}/$eventref->{'summary'}/$eventref->{'text'}'"); db_list("insert into messages (TARGET,SENDER,TIME,STATUS,MESSAGE,TYPE) values ('$groupadmin', '$USER', '$time','no','$groupID/$form->{'grouptool'}/$eventref->{'epoch'}/$eventref->{'end_epoch'}/$eventref->{'type'}/$eventref->{'time'}/$eventref->{'summary'}/$eventref->{'text'}','CALENDAR')"); db_end(); } } unlock_tables(); if ($form->{'send_these'} =~ /^ +$/ and $form->{'send_these_groups'} =~ /^ +$/) {$message = tag('div', {class => 'error'}).$gettext->gettext('You must select at least one user or group!').endtag('div');} else { $form->{'send_these'} =~ s/ /, /g; my $groupnms = join ", ", @groupNames; $message = ''; $message .= tag('div', {class => 'success'}).$gettext->gettext('The event(s) have been sent to the following users: '). $form->{'send_these'}. endtag('div') if $form->{'send_these'}; $message .= tag('div', {class => 'success'}).$gettext->gettext('The event(s) have been sent to the following groups: '). $groupnms . endtag('div') if $groupnms; } return $message; } ################################################################################################# # fetch_group_members - fetches the group members and sends events to them. # #-----------------------------------------------------------------------------------------------# # # # The arguments and results are read from and saved into the $form-variable # # # ################################################################################################# sub fetch_group_members { my @groupuserlist; db_list("SELECT user FROM groupusers where GID = '$form->{'grouptool'}'"); while (my $ref = $sth->fetchrow_hashref()) { push @groupuserlist, $ref->{'user'};} db_end(); my ($message); my $time = time(); my @eventID; for(my $i=0; $i < $form->{'numofcheckboxes'}; $i++) { push @eventID, $form->{"checkb$i"} if($form->{"checkb$i"}); #if the checkbox is checked, do the stuff: } return tag('div', {class => 'error'}).$gettext->gettext('No events to send!').endtag('div') if @eventID == 0; lock_tables('WRITE', 'messages', $CALENDAR); foreach my $MDeventID (@eventID) { my ($eventref) = db_select('*',$CALENDAR,"IDnumber = '$MDeventID' and user = '$CALENDARUSER'"); $eventref->{'type'} =~ s/"//gsm; $eventref->{'summary'} =~ s/"//gsm; $eventref->{'text'} =~ s/"//gsm; db_end(); foreach (@groupuserlist) { my ($nimi); next if db_select('MESSAGE','messages',"TYPE = 'CALENDAR' and TARGET = '$_' and MESSAGE = '0/$form->{'grouptool'}/$eventref->{'epoch'}/$eventref->{'end_epoch'}/$eventref->{'type'}/$eventref->{'time'}/$eventref->{'summary'}/$eventref->{'text'}'"); db_list("insert into messages (TARGET,SENDER,TIME,STATUS,MESSAGE,TYPE) values ('$_', '$USER', '$time', 'no','0/$form->{'grouptool'}/$eventref->{'epoch'}/$eventref->{'end_epoch'}/$eventref->{'type'}/$eventref->{'time'}/$eventref->{'summary'}/$eventref->{'text'}','CALENDAR')"); db_end(); } } unlock_tables(); my $list_of_users = join ', ', @groupuserlist; if ($list_of_users =~ /^ +$/) {$message = tag('div', {class => 'error'}).$gettext->gettext('You must select at least one user!').endtag('div');} else { $message = tag('div', {class => 'success'}).$gettext->gettext('The event(s) have been sent to the following users: ').$list_of_users.endtag('div');} return $message; } ################################################################################################# # add_selected_to_personal_cal - adds the selected events from group calendar to personal one # #-----------------------------------------------------------------------------------------------# # # # The arguments and results are read from and saved into the $form-variable # # # ################################################################################################# sub add_selected_to_personal_cal { my $groupname; my ($check, $message) = ('',''); if($GROUPACTIVOR) { db_list("SELECT GRPNAME FROM groups where GID = '$form->{'grouptool'}'"); while (my $ref = $sth->fetchrow_hashref()) { $groupname = $ref->{'GRPNAME'}; } db_end(); # all checkboxes in the form are examined: are there ones selected? for(my $i=0; $i < $form->{'numofcheckboxes'}; $i++) { if($form->{"checkb$i"}) #if the checkbox is checked, do the stuff: { $check .= 'ok'; my %calendar_hash; db_list("SELECT * FROM $CALENDAR where IDnumber = '".$form->{"checkb$i"}."' and user = '$CALENDARUSER'"); while (my $ref = $sth->fetchrow_hashref()) { $calendar_hash{'user'} = $USER; $calendar_hash{'recrule'} = 'norec'; $calendar_hash{'prevrec'} = 'NULL'; $calendar_hash{'nextrec'} = 'NULL'; $calendar_hash{'IDnumber'} = 'NULL'; $calendar_hash{'reminderID'} = 'NULL'; $calendar_hash{'text'} = $ref->{'text'} . "\n". sprintf($gettext->gettext('(You have transferred this event to your personal calendar from the group calendar of the group %s)'),$groupname); $calendar_hash{'epoch'} = $ref->{'epoch'}; $calendar_hash{'time'} = $ref->{'time'}; $calendar_hash{'end_epoch'} = $ref->{'end_epoch'}; $calendar_hash{'type'} = $ref->{'type'}; $calendar_hash{'summary'} = $ref->{'summary'}; } db_end(); db_insert('calendar',\%calendar_hash); db_end(); $check .= 'ok'; } } } if(!$check) { $message = tag('div', {class => 'error'}).tag('br').$gettext->gettext('No events selected!').endtag('div');} else { $message = tag('div', {class => 'success'}).tag('br').$gettext->gettext('Events added successfully!').endtag('div'); } return $message; } ################################################################################################# # date_dropdown - returns a set of dropdowns with the given date and names # #-----------------------------------------------------------------------------------------------# # date_dropdown($day,$month,$year, $day_dd_name,$month_dd_name,$year_dd_name) # # # # Usage: # # $html = date_dropdown(1,1,2002, 'day_drop','month_drop','year_drop') # # # ################################################################################################# sub date_dropdown { my ($dd_day,$dd_month,$dd_year, $day_dd_name,$month_dd_name,$year_dd_name) = @_; my ($dd_stuff, @ddropitems, %ddropargs); $dd_day = '0'.$dd_day while length($dd_day) < 2; $dd_month = '0'.$dd_month while length($dd_month) < 2; @ddropitems = ('01'..'31'); %ddropargs = ( name => $day_dd_name, order => \@ddropitems, default => $dd_day ); $dd_stuff = dropdownmenu(%ddropargs); @ddropitems = ('01'..'12'); %ddropargs = ( name => $month_dd_name, order => \@ddropitems, default => $dd_month ); $dd_stuff .= dropdownmenu(%ddropargs); @ddropitems = ($date[5]-5 .. $date[5]+10); # for(my $i = $date[5]-5;$i<=$date[5]+10;$i++) {push @ddropitems,$i}; %ddropargs = ( name => $year_dd_name, order => \@ddropitems, default => $dd_year ); $dd_stuff .= dropdownmenu(%ddropargs); return $dd_stuff; } ######################################################### # check_date - checks the date given in the form # #-------------------------------------------------------# # check_date() # # # # Usage: # # check_date() # # # ######################################################### sub check_date { $form->{'day'} = $date[3] if ($form->{'day'} eq ""); $form->{'month'} = $date[4] if ($form->{'month'} eq ""); $form->{'year'} = $date[5] if ($form->{'year'} eq ""); $form->{'day'} =~ s/^0*//ms; $form->{'month'} =~ s/^0*//ms; $form->{'year'} =~ s/^0*//ms; $form->{'year'} = 0 if $form->{'year'} eq ""; } ################################################################# # calendar_error_message - returns error message in HTML # #---------------------------------------------------------------# # calendar_error_message($error_msg) # # # # Usage: # # $HTML = calendar_error_message('Invalid value in form') # # # ################################################################# sub calendar_error_message { my $message = shift; return qq[
Calendar error:
$message
Return to the standard calendar starting page ->
]; } ################################################################################# # check_form_data - checks the form data and returns possible error messages # #-------------------------------------------------------------------------------# # check_form_data() # # # # Usage: # # $calendar_error_msg = check_form_data() # # # ################################################################################# sub check_form_data { my $cal_error_msg = ""; if($form->{'day'} > days_in_month($form->{'month'},$form->{'year'}) or $form->{'day'} < 1 or $form->{'day'} !~ /^[0-9]+$/ or $form->{'month'} > 12 or $form->{'month'} < 1 or $form->{'month'} !~ /^[0-9]+$/ or $form->{'year'} !~ /^[0-9]+$/) { $cal_error_msg .= "Invalid calendar date given: \"$form->{'day'}.$form->{'month'}.$form->{'year'}\"
"; # $form->{'day'} = ''; # $form->{'month'} = ''; # $form->{'year'} = ''; } if($form->{'view'} ne 'week' and $form->{'view'} ne 'day' and $form->{'view'} ne 'month' and $form->{'view'} ne 'year' and $form->{'view'} ne 'list') { $cal_error_msg .= "Invalid calendar view: \"$form->{'view'}\"
"; $form->{'view'} = ''; } $cal_error_msg = 'ok' if $cal_error_msg eq ''; return $cal_error_msg; } ######################################################### # floor - floor function # #-------------------------------------------------------# # floor($number) # # # # The floor function returns the number rounded # # into the next smaller integer. # # # # Usage: # # &floor(3.8) returns 3 # # &floor(-2.1) returns -3 # # &floor(-1.9) returns -2 # # # ######################################################### sub floor { my $number = shift; if ($number >= 0) { return int($number); } else { return int($number-1); } # negatiivisilla luvuilla pelkkä int-pyöristys ei toimi } ######################################################### # roof - roof function # #-------------------------------------------------------# # roof($number) # # # # The roof function returns the number rounded # # into the next greater integer. # # # # Usage: # # &floor(3.8) returns 4 # # &floor(-2.1) returns -2 # # &floor(-1.9) returns -1 # # # ######################################################### sub roof { my $number = shift; # if desimaaliosa == 0, return int-osa: return int($number) if ($number-int($number)==0.000000000000); if ($number >= 0) { return int($number+1); } else { return int($number); } # negatiivisilla luvuilla pelkkä int-pyöristys ei toimi } ######################################################### # day_num - the ordinal number of the day # #-------------------------------------------------------# # day_num($day,$month,$year) # # # # returns the ordinal number of a given date. # # (0.0.0000 => -33) # # # # Usage: # # &day_num(1,12,2000) # # # ######################################################### sub day_num { my ($day,$month,$year) = @_; # tammimonth ja helmimonth spesiaalimonthkausia: return (365*$year + $day + 31*($month-1) + floor(($year-1)/4) - floor(3*floor((($year-1)/100)+1)/4)) if ($month == 1 || $month == 2); # jos monthkausi joku muu month kuin 1 tai 2, käytetään seuraavaa laskutapaa: return (365*$year + $day + 31*($month-1) - floor(0.4*$month + 2.3) + floor($year/4) - floor (3*(floor($year/100)+1)/4)); } ################################################################# # abs_days_in_between - the number of days between two dates # #---------------------------------------------------------------# # abs_days_in_between($day1,$month1,$year1, $day2,$month2,$year2) # # # # returns the number of days between two given dates. # # # # Usage: # # &abs_days_in_between(1,12,2000, 2,12,2000) returns 1 # # &abs_days_in_between(2,12,2000, 1,12,2000) returns 1 # # &abs_days_in_between(2,12,2000, 2,12,2000) returns 0 # # # ################################################################# sub abs_days_in_between { my ($day1,$month1,$year1,$day2,$month2,$year2) = @_; return abs(day_num($day2,$month2,$year2)-day_num($day1,$month1,$year1)); } ################################################################# # days_in_between - the number of days between two dates # #---------------------------------------------------------------# # days_in_between($day1,$month1,$year1, $day2,$month2,$year2) # # # # returns the number of days between two given dates. # # # # Usage: # # &abs_days_in_between(1,12,2000, 2,12,2000) returns 1 # # &abs_days_in_between(2,12,2000, 1,12,2000) returns 1 # # &abs_days_in_between(2,12,2000, 2,12,2000) returns 0 # # # ################################################################# sub days_in_between { my ($day1,$month1,$year1,$day2,$month2,$year2) = @_; return (day_num($day2,$month2,$year2)-day_num($day1,$month1,$year1)); } ################################################################# # days_in_month - the number of days in a month # #---------------------------------------------------------------# # days_in_month($month,$year) # # # # calculates the number of days in the given month. # # # # Usage: # # &days_in_month(12,2000) returns 31 (the number of days in # # December 2000) # # # ################################################################# sub days_in_month { my ($mon1,$year1) = @_; my($mon2,$year2) = ($mon1+1, $year1); if ($mon2>12) { $mon2 -= 12; $year2 += 1; } return abs_days_in_between(1,$mon2,$year2, 1,$mon1,$year1); } ################################################################# # leapyear - is it leapyear? # #---------------------------------------------------------------# # leapyear($year) # # # # Returns 1, if the given year is a leapyear, otherwise 0. # # # # Usage: # # &leapyear(2000) returns 1 ('cause year 2000 is a leapyear) # # # ################################################################# sub leapyear { my $year = shift; # Infe: Join nested if statements together! return 1 if ($year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0)); return 0; } ################################################################# # day_of_the_week - the day of the week # #---------------------------------------------------------------# # day_of_the_week($day,$month,$year) # # # # Calculates the day of the week for the given date. # # 0==Saturday, 1==Sunday, 2==Monday, ... , 6==Friday # # # # Usage: # # day_of_the_week(2,12,2000) returns 0, => 2.12.2000 is Sat. # # # ################################################################# # # # Note that this function is an unstandard one since the # # day of week returned by the perl gmtime function starts # # from 0==Sunday. There's now a more standard function in # # the Mimerdesk.pm library, but the calendar is built using # # this function, so the new function must be overriden. # # # ################################################################# sub day_of_the_week { my ($day,$month,$year) = @_; return (7+(day_num($day,$month,$year) + 7*floor(day_num($day,$month,$year)/(-7)))); } ################################################################# # week_of_the_year - the week of the year # #---------------------------------------------------------------# # week_of_the_year($day,$month,$year) # # # # Calculates the ordinal number of the week of the year for the # # given date. # # # # Usage: # # week_of_the_year(5,12,2000) returns 49, => its week #49 # # # ################################################################# sub week_of_the_year { my ($day,$month,$year) = @_; # the date of the Thursday of the given week: my ($thu_day, $thu_month, $thu_year) = date_after_x_days($day,$month,$year, 3-((day_of_the_week($day,$month,$year)+5) % 7)); # the date of the first Thursday of the newly calculated $thu_year my ($first_thu_day, $first_thu_month, $first_thu_year) = date_after_x_days(1,1,$thu_year, 3-((day_of_the_week(1,1,$thu_year)+5) % 7)); ($first_thu_day, $first_thu_month, $first_thu_year) = date_after_x_days($first_thu_day, $first_thu_month, $first_thu_year, 7) while $first_thu_year < $thu_year; # week number is the difference between the first Thu of the year and the given Thu divided by 7 plus 1 # (week #1 is the week containing the first Thursday of the year) my $week = days_in_between($first_thu_day,$first_thu_month,$first_thu_year, $thu_day,$thu_month,$thu_year) / 7 + 1; return $week; } ################################################################# # build_calendar - builds a calendar # #---------------------------------------------------------------# # build_calendar($type, $day,$month,$year), # # # # where $type is one of the strings 'day', 'week', 'five', # # 'month' or 'year'. # # # # The alternatives: # # 'day' => one-day calendar # # 'week' => the calendar of the given week # # 'five' => the calendar of the five following days # # 'month' => the calendar of the given month # # 'year' => the calendar of the given year # # # # returns the calendar as a HTML table. # # # # Usage: # # $HTML_table = &build_calendar('month', 7, 11, 2000); # # # # # # 1. tries to determine what kind of a calendar is wanted # # 2. builds the calendar according to the given arguments # # # ################################################################# sub build_calendar { my ($type,$day,$month,$year) = @_; return build_cal_month($month,$year) if ($type eq 'month'); # calendar of a month return build_cal_year($year) if ($type eq 'year'); # calendar of a year return build_cal_week($day,$month,$year) if ($type eq 'week'); # calendar of a week return build_cal_day($day,$month,$year) if ($type eq 'day'); # calendar of a day } ################################################################## # build_cal_month # #----------------------------------------------------------------# # build_cal_month($month,$year) # # # # returns the calendar of a month # # # # Usage: # # &build_cal_month(12,2000) # # # # 1. builds the table header and the title row # # (which shows the current month and year and the navigation # # links) # # 2. builds the second row where the names of the days of the # # week are located # # 3. inserts the right amount of "blank" days in the beginning # # of the calendar (that is, if the first day of the month is # # for example Wednesday, three blank days have to be inserted)# # 4. inserts the days of the month # # 5. inserts the "blank" days in the end of the calendar # # 6. inserts the end of the table # # # ################################################################## sub build_cal_month { my ($blank_days, @event_info, $event_counter); my ($month,$year) = @_; # calculated in the beginning: my($prev_month,$prev_year) = ($month-1,$year); if ($prev_month < 1) { $prev_month += 12; $prev_year--; } my($next_month,$next_year) = ($month+1,$year); if ($next_month > 12) { $next_month -= 12; $next_year++; } my %day_info = fetch_events(1,$month,$year, 1,$next_month,$next_year,$form->{'category_filter'}); my $calinfo = "$month_names{$month} $year"; my $navigation_left = "calendar.html?ID=$form->{'ID'}&auth=$form->{'auth'}&view=month&month=$prev_month&year=$prev_year&grouptool=$form->{'grouptool'}&category_filter=$form->{'category_filter'}"; my $navigation_right = "calendar.html?ID=$form->{'ID'}&auth=$form->{'auth'}&view=month&month=$next_month&year=$next_year&grouptool=$form->{'grouptool'}&category_filter=$form->{'category_filter'}"; my $the_table = qq[ ]; $the_table .= weekday_cells('long'); $the_table .= "\n"; $event_counter = 0; # Infe: Avoiding use of multiple \" with qq[] instead of "" $blank_days = (day_of_the_week(1,$month,$year)+5) % 7; # kalenterin alun "tyhjien" päivien lkm laskettuna simppelinä kongruenssina for(my $i = 0; $i < $blank_days; $i++) { # If it's monday, add the beginning of a new line and the nuber-of-week cell: $the_table .= "\n".qq[] if day_of_the_week(days_in_month($prev_month,$prev_year)+1-$blank_days+$i,$prev_month,$prev_year) == 2; # maanantain kohdalla taulukon rivi alkaa $the_table .= qq[\n]; # lisätään tyhjiä laatikoita calendarn almonthn $event_info[$event_counter] = ' '; $event_counter++; } my $daysmonth = days_in_month($month,$year); # lasketaan nyt, jottei tarvitsisi laskea erikseen seuraavassa luupissa pariakymmentä kertaa.. for (my $dayy=1; $dayy <= $daysmonth; $dayy++) # käydään läpi kaikki monthkauden päivät { my ($cell_color); my $weekday = day_of_the_week($dayy,$month,$year); # tarvitaan muutaman kerran luupin aikana.. if ($weekday == 2) # maanantai (&day_of_the_week==2) aloittaa taulukossa uuden rivin { $the_table .= qq[\n]; $the_table .= qq[]; } $the_table .= qq[ \n]; #pistetään päivän tiedot vastaavaan taulukon alkioon: # if (info_toggle == on) # { $event_info[$event_counter] = $day_info{"$dayy.$month.$year/info"}; # } # else # { # $event_info[$event_counter] = ''; # } $event_info[$event_counter] .= qq[$day_info{"$dayy.$month.$year/full"}$day_info{"$dayy.$month.$year"} ]; $event_info[$event_counter] .= qq[+] if $edit_on; $event_counter++; if ($weekday == 1) # sunnuntain jälkeen taulukon rivi päättyy { $the_table .= qq[\n]; $the_table .= generate_weeknumber_cell($dayy,$month,$year); for(my $j=0; $j<7; $j++) { my ($da,$mo,$ye) = date_after_x_days($dayy,$month,$year, -6+$j); $event_info[$j] = ' ' if $event_info[$j] eq ''; $the_table .= qq[ ]; } $the_table .= "\n"; $event_counter = 0; } } $blank_days = (8-day_of_the_week($daysmonth,$month,$year)) % 7; # monthkausicalendarn lopun "tyhjien" päivien lkm laskettuna laskettuna kongruenssina for(my $i = 0; $i < $blank_days; $i++) { $the_table .= qq[\n]; # lisätään tyhjiä laatikoita calendarn loppuun $event_info[$event_counter] = ' '; $event_counter++; if (day_of_the_week(1+$i,$next_month,$next_year) == 1) # sunnuntain jälkeen taulukon rivi päättyy { $the_table .= qq[\n]; $the_table .= generate_weeknumber_cell(1+$i,$next_month,$next_year); for(my $j=0; $j<7; $j++) { my ($da,$mo,$ye) = date_after_x_days(1+$i,$next_month,$next_year, -6+$j); $the_table .= qq[ ]; } $the_table .= "\n"; $event_counter = 0; } } $the_table .= "
  
  $day_names{$weekday} $dayy $month_names_short{$month} $year
$event_info[$j]
 
$event_info[$j]
\n"; # taulukon loppu $the_table = add_grid($the_table) if $grid eq 'on'; return ($the_table, $navigation_left, $navigation_right, $calinfo, $day_info{'number_of_checkboxes'}); } ################################################################# # build_cal_year # #---------------------------------------------------------------# # build_cal_year($year) # # # # returns the calendar of a year # # # # Usage: # # &build_cal_year(2000) # # # # 1. builds the table header and the title row of the table # # (which shows the current year and the links to the other # # views) # # 2. builds the second row where the names of the days of the # # week are located # # 3. inserts the right amount of "blank" days in the beginning # # of the calendar (that is, if the first day of January # # is for example Wednesday, three blank days have to be # # inserted) # # 4. inserts the days of each month # # 5. inserts the "blank" days in the end of the calendar # # 6. inserts the end of the table # # # ################################################################# sub build_cal_year { my ($blank_days); my ($year) = @_; my ($prev_year, $next_year) = ($year-1, $year+1); # The info from the database is stored into a hash my %day_info = fetch_events(1,1,$year, 1,1,$next_year,$form->{'category_filter'}); my $calinfo = $year; my $navigation_left = "calendar.html?ID=$form->{'ID'}&auth=$form->{'auth'}&view=year&year=$prev_year&grouptool=$form->{'grouptool'}&category_filter=$form->{'category_filter'}"; my $navigation_right = "calendar.html?ID=$form->{'ID'}&auth=$form->{'auth'}&view=year&year=$next_year&grouptool=$form->{'grouptool'}&category_filter=$form->{'category_filter'}"; my $the_table = qq[ ]; $the_table .= weekday_cells(); $the_table .= "\n"; $blank_days = (day_of_the_week(1,1,$year)+5) % 7; # the number of "blank" days in the beginning of the year my $last_month = 12; my $year2 = $year-1; for(my $i = 0; $i < $blank_days; $i++) { # If it's monday, add the beginning of a new line and the nuber-of-week cell: $the_table .= "\n".generate_weeknumber_cell(days_in_month($last_month,$year2)+1-$blank_days+$i,$last_month,$year2) if day_of_the_week(days_in_month($last_month,$year2)+1-$blank_days+$i,$last_month,$year2) == 2; # a new row in the table starts in monday $the_table .= qq[\n]; # add the blank cells } for(my $month = 1; $month <=12; $month++) { my $daysmonth = days_in_month($month,$year); for (my $dayy=1; $dayy <= $daysmonth; $dayy++) { my ($cell_color); my $weekday = day_of_the_week($dayy,$month,$year); $the_table .= ("\n" . generate_weeknumber_cell($dayy,$month,$year)) if $weekday == 2; # Monday (&day_of_the_week==2) starts a new row in the table # add the day-cell and everything inside it: $the_table .= qq[ \n]; $the_table .= "\n" if $weekday == 1; # Sunday ends a row of the table } } $blank_days = (8-day_of_the_week(days_in_month(12,$year),12,$year)) % 7; # the amount of blank days in the end $last_month = 1; # next month $year2 = $year+1; # next year for(my $i = 0; $i < $blank_days; $i++) { $the_table .= qq[\n]; # add the blanks $the_table .= "\n" if day_of_the_week(1+$i,$last_month,$year2) == 1; # Sunday ends a row of the table } $the_table .= "
 
$month_names_short{$month} $dayy
$day_info{"$dayy.$month.$year/info"} $day_info{"$dayy.$month.$year/full"} $day_info{"$dayy.$month.$year"} ]; $the_table .= qq[+] if $edit_on; $the_table .= qq[
 
\n"; # the end of the table $the_table = add_grid($the_table) if $grid eq 'on'; return ($the_table, $navigation_left, $navigation_right, $calinfo, $day_info{'number_of_checkboxes'}); } ################################################################# # build_cal_week # #---------------------------------------------------------------# # build_cal_week($day,$month,$year) # # # # returns the calendar of the week containing the given date. # # # # Usage: # # $HTML_table = build_cal_week(1,12,2000) # # # ################################################################# sub build_cal_week { my ($day,$month,$year) = @_; # calculates the date of the Monday of the week: my ($mon_day, $mon_month, $mon_year) = date_after_x_days($day,$month,$year, -((day_of_the_week($day,$month,$year)+5) % 7)); # calculates the previous week: my ($prev_day,$prev_month,$prev_year) = date_after_x_days($day,$month,$year, -7); # calculates the next week: my ($next_day,$next_month,$next_year) = date_after_x_days($mon_day,$mon_month,$mon_year, 7); # the time limits: my ($starthour, $endhour) = (8, 18); # The info from the database is stored into a hash my %day_info = fetch_events($mon_day,$mon_month,$mon_year, $next_day,$next_month,$next_year, $form->{'category_filter'}, 'usehours'); # check the time limits: if (keys %day_info > 1) { foreach(keys(%day_info)) { if ($_ !~ 'full' && $_ !~ 'info' && $_ ne 'greatest_hour' && $_ ne 'number_of_checkboxes') { my $hour = $_; #remove all the extra crap: $hour =~ s/^[0-9]+\.[0-9]+\.[0-9]+\///; # Check start of a hour $starthour = $hour if ($hour < $starthour); $endhour = $hour if ($hour > $endhour); } } # Check end of a hour $starthour = $day_info{'greatest_hour'} if ($day_info{'greatest_hour'} < $starthour); $endhour = $day_info{'greatest_hour'} if ($day_info{'greatest_hour'} > $endhour); } my $calinfo = $gettext->gettext('Week ').week_of_the_year($day,$month,$year).", $year"; my $navigation_left = "calendar.html?ID=$form->{'ID'}&auth=$form->{'auth'}&view=week&year=$prev_year&month=$prev_month&day=$prev_day&grouptool=$form->{'grouptool'}&category_filter=$form->{'category_filter'}"; my $navigation_right = "calendar.html?ID=$form->{'ID'}&auth=$form->{'auth'}&view=week&year=$next_year&month=$next_month&day=$next_day&grouptool=$form->{'grouptool'}&category_filter=$form->{'category_filter'}"; my $the_table = qq[ ]; $the_table .= qq[\n]; #calculated in advance: my (@the_day, @the_month, @the_year); for (my $i = 0; $i < 7; $i++) { my ($color); ($the_day[$i],$the_month[$i],$the_year[$i]) = date_after_x_days($mon_day,$mon_month,$mon_year, $i); my $day_otw = day_of_the_week($the_day[$i],$the_month[$i],$the_year[$i]); if ($day_otw == 1) {$color = $calendarcolors{'day_sun'};} elsif ($day_otw == 0) {$color = $calendarcolors{'day_sat'};} else {$color = $calendarcolors{'day_montuewedthufri'};} $the_table .= qq[ \n"; } $the_table .= "\n"; foreach my $hour ('full',$starthour .. $endhour) { while (length $hour < 2) { $hour = "0".$hour; } my ($shown_hour,$additional_options); if($hour =~ /^[0-9]+$/) {$shown_hour = "$hour:00"; $additional_options = "&hour=$hour";} else {$shown_hour = ''; $additional_options = '&use_time=0';} $the_table .= qq[ \n \n ]; for (my $i = 0; $i < 7; $i++) # seven days of the week { # $day_info{"$the_day[$i].$the_month[$i].$the_year[$i]/$hour"} = " " if $day_info{"$the_day[$i].$the_month[$i].$the_year[$i]/$hour"} eq ""; # add the day-cell and everything inside it: $the_table .= qq[ \n]; } $the_table .= qq[ \n]; } $the_table .= "
].$gettext->gettext('Time').qq[ $day_names_long{$day_otw}
{'grouptool'}"onMouseOver=\"doClock(); return true\" class="contentLink">]."$month_names_short{$the_month[$i]} {'ID'}&auth=$form->{'auth'}&view=day&year=$the_year[$i]&month=$the_month[$i]&day=$the_day[$i]".qq[&grouptool=$form->{'grouptool'}" onMouseOver="doClock(); return true" class="contentLink">]."$the_day[$i]
 $shown_hour  $day_info{"$the_day[$i].$the_month[$i].$the_year[$i]/$hour"} ]; $the_table .= qq[+] if $edit_on; $the_table .= qq[
\n"; $the_table = add_grid($the_table) if $grid eq 'on'; return ($the_table, $navigation_left, $navigation_right, $calinfo, $day_info{'number_of_checkboxes'}); } ################################################################# # build_cal_day # #---------------------------------------------------------------# # build_cal_day($day,$month,$year) # # # # returns the calendar of the given date. # # # # Usage: # # $HTML_table = build_cal_day(1,12,2000) # # # ################################################################# sub build_cal_day { my ($color); my ($day,$month,$year) = @_; my ($starthour, $endhour) = (8, 18); my ($day_otw) = day_of_the_week($day,$month,$year); # calculates the previous day: my ($prev_day,$prev_month,$prev_year) = date_after_x_days($day,$month,$year, -1); # calculates the next day: my ($next_day,$next_month,$next_year) = date_after_x_days($day,$month,$year, 1); # The info from the database is stored into a hash my %day_info = fetch_events($day,$month,$year, $next_day,$next_month,$next_year, $form->{'category_filter'}, 'usehours', 'writedetails'); if (keys %day_info > 1) { foreach(keys(%day_info)) { if ($_ !~ 'full' && $_ !~ 'info' && $_ ne 'greatest_hour' && $_ ne 'number_of_checkboxes') { my $hour = $_; #remove all the extra crap: $hour =~ s/^[0-9]+\.[0-9]+\.[0-9]+\///; # Check start of a hour $starthour = $hour if ($hour < $starthour); $endhour = $hour if ($hour > $endhour); } } # Check end of a hour $starthour = $day_info{'greatest_hour'} if ($day_info{'greatest_hour'} < $starthour); $endhour = $day_info{'greatest_hour'} if ($day_info{'greatest_hour'} > $endhour); } my $calinfo = "$day_names_long{$day_otw} $day $month_names{$month} $year, Week ".week_of_the_year($day,$month,$year); my $navigation_left = "calendar.html?ID=$form->{'ID'}&auth=$form->{'auth'}&view=day&year=$prev_year&month=$prev_month&day=$prev_day&grouptool=$form->{'grouptool'}&category_filter=$form->{'category_filter'}"; my $navigation_right = "calendar.html?ID=$form->{'ID'}&auth=$form->{'auth'}&view=day&year=$next_year&month=$next_month&day=$next_day&grouptool=$form->{'grouptool'}&category_filter=$form->{'category_filter'}"; my $the_table = qq[ ]; # add the day-cell and everything inside it: foreach my $hour ('full',$starthour .. $endhour) { while (length $hour < 2) { $hour = "0".$hour; } my ($shown_hour,$additional_options); if($hour =~ /^[0-9]+$/) {$shown_hour = "$hour:00"; $additional_options = "&hour=$hour";} else {$shown_hour = ''; $additional_options = '&use_time=0';} # $day_info{$hour} = " " if $day_info{$hour} eq ""; $the_table .= qq[ \n \n \n\n]; } $the_table .= "
 $shown_hour  $day_info{"$day.$month.$year/$hour"} ]; $the_table .= qq[+] if $edit_on; $the_table .= qq[
\n"; $the_table = add_grid($the_table) if $grid eq 'on'; return ($the_table, $navigation_left, $navigation_right, $calinfo, $day_info{'number_of_checkboxes'}); } ################################################################# # add_grid - Add outter table # #---------------------------------------------------------------# # add_grid(table) # # # # Adds grid to a calendar table. # # # # Usage: # # $the_table = add_grid($the_table) # # # ################################################################# sub add_grid { my $the_table = shift; return qq[
] . $the_table ."
"; } ################################################################# # weekday_cells - Generates weekday table cells # #---------------------------------------------------------------# # weekday_cells([long], [noweek / time]) # # # # Generates weekday table cells in long or short name format # # with or without the 'week'-column. # # long = Monday, Tuesday... short = Mon, Tue ... # # # # Note that there are only 7 columns in the table if the # # argument 'noweek' is used. Otherwise there are 8 of them. # # # # If the time argument is given, the 'week'-column is replaced # # with 'time'-column. The 'time' and 'noweek' arguments can't # # be used simultaneously. # # # # Usage: # # $cells = weekday_cells('long') # # $cells = weekday_cells('long','noweek') # # $cells = weekday_cells('noweek') # # $cells = weekday_cells('time') # # $cells = weekday_cells() # # # ################################################################# sub weekday_cells { my @style = @_; my ($color,$the_table); my $ref = \%day_names; # alustavasti my $what_to_draw = 'week'; foreach (@style) { $ref = \%day_names_long if $_ eq 'long'; $what_to_draw = 'nothing' if $_ eq 'noweek'; $what_to_draw = 'time' if $_ eq 'time'; } if($what_to_draw eq 'week') {$the_table = qq[].$gettext->gettext('Week').qq[\n];} elsif($what_to_draw eq 'time') {$the_table = qq[].$gettext->gettext('Time').qq[\n];} else {$the_table = "";} foreach (2..6,0,1) { if ($_ == 1) {$color = $calendarcolors{'day_sun'};} elsif ($_ == 0) {$color = $calendarcolors{'day_sat'};} else {$color = $calendarcolors{'day_montuewedthufri'};} $the_table .= qq[$ref->{$_}\n]; } return $the_table; } ######################################################################### # generate_weeknumber_cell - Makes the number-of-week cell # #-----------------------------------------------------------------------# # generate_weeknumber_cell($day,$month,$year) # # # # Generates a HTML-table cell containing the ordinal number of the # # week. The given date can be any day of that week. # # # # Usage: # # $cell = generate_weeknumber_cell($day,$month,$year) # # # ######################################################################### sub generate_weeknumber_cell { my ($day,$month,$year) = @_; my $week_number = week_of_the_year($day,$month,$year); return qq[ $week_number \n]; } ######################################################################### # date_after_x_days - calculates a date # #-----------------------------------------------------------------------# # date_after_x_days($day,$month,$year, $number_of_days) # # # # Calculates the date $number_of_days days before or after the given # # date. $number_of_days can be positive or negative. # # # # Usage: # # ($day,$month,$year) = date_after_x_days(6,12,2000, -7) # # [calculates the date one week before 6,12,2000] # # ($day,$month,$year) = date_after_x_days(6,12,2000, 7) # # [calculates the date one week after 6,12,2000] # # # ######################################################################### sub date_after_x_days { my ($day,$month,$year, $num_days) = @_; my ($new_day,$new_month,$new_year) = ($day+$num_days,$month,$year); if ($new_day <1) { while ($new_day<1) { $new_month--; if ($new_month<1) { $new_year--; $new_month += 12; } $new_day += days_in_month($new_month,$new_year); } } elsif ($new_day>days_in_month($month,$year)) { while ($new_day>days_in_month($new_month,$new_year)) { $new_day -= days_in_month($new_month,$new_year); # $new_month must be increased AFTER the previous statement, not before # like in the buggy version! $new_month++; if ($new_month>12) { $new_year++; $new_month -= 12; } } } return ($new_day,$new_month,$new_year); } ################################################################################################# # choose_cell_color - determines the color of a cell # #-----------------------------------------------------------------------------------------------# # choose_cell_color($sday,$smonth,$syear,$shour,$sminute, $eday,$emonth,$eyear,$ehour,$eminute) # # # # Returns the color of the cell with the given date. # # The border times of the cell are given as an argument. # # # # Usage: # # $cell_col = choose_cell_color(6,12,2000, 13,00) # # # ################################################################################################# sub choose_cell_color { my ($day,$month,$year,$hour,$minute, $eday,$emonth,$eyear,$ehour,$eminute) = @_; my $color_hash_key; # There's different colors for odd and even months. If it's current day, we'll use a special color. if ($day != $date[3] || $month != $date[4] || $year != $date[5]) { $color_hash_key = day_of_the_week($day,$month,$year)+(7*($month % 2)); } else { $color_hash_key = 'curr_day'; } return $calendarcolors{$color_hash_key} if ($hour eq 'full'); my $epokki = local_date2utc_epoch(0,$minute,$hour, $day,$month,$year); my $epokki2 = local_date2utc_epoch(0,$eminute,$ehour,$eday,$emonth,$eyear); my $occupied = 0; #check if the given date is between any start/end epoch pairs for (my $i = 0; $i<$num_of_events; $i++) { $occupied++ if ($epokki2 > $startepochs[$i] && $epokki < $endepochs[$i]); } $color_hash_key = 'occ_'.$color_hash_key if $occupied; return $calendarcolors{$color_hash_key}; } ################################################################################################# # fetch_user_categories - returns sorted list of distinct categories # #-----------------------------------------------------------------------------------------------# # fetch_user_categories($username, $calendar_db) # # # # Usage: # # @category_list = fetch_user_categories($username, $calendar_db) # # # ################################################################################################# sub fetch_user_categories { my($cal_username, $cal_dbname) = @_; my(@category_list); lock_tables('READ', $cal_dbname); db_list("SELECT DISTINCT type FROM $cal_dbname where user = '$cal_username' order by type"); while (my $ref = $sth->fetchrow_hashref()){ push @category_list, $ref->{'type'}; } db_end(); unlock_tables(); return @category_list; } ################################################################################################# # fetch_events - returns some events in HTML # #-----------------------------------------------------------------------------------------------# # fetch_events($startday, $startmonth, $startyear, $endday, $endmonth, $endyear, [$category], ['usehours'], ['writedetails'], ['return_only_IDs']) # # # # Returns the events of the the given time in a hash. The hash can be # # accessed with keywords in the following format: "$day.$month.$year[/$hour]". # # Special day specific info can be accessed with keyword # # "$day.$month.$year/info" # # # # # # Usage: # # %hash = fetch_events(1,12,2000, 1,1,2001); # # $some_HTML = $hash{'24.12.2000'}; # # # # 1. Gets the date-specific information from the databases (fixed # # holidays etc.) # # 2. Gets the user-specific information from the DB: # # 2.1. Calculates all the dates, in which this current note should be # # added, into an array # # 2.2. Discards the dates that aren't dates of the given year # # 2.3. Adds the note into all the dates defined by the array # # 3. Returns the hash # # # ################################################################################################# sub fetch_events { my ($startday, $startmonth, $startyear, $endday, $endmonth, $endyear, $filter_category, $usehours, $writedetails, $return_only_IDs) = @_; my (%the_hash, $category_sql); my $number_of_checkboxes = 0; # db_list("SELECT dateinfo.day,dateinfo.month,dateinfo.text_field_1,dateinfo.text_field_2 FROM dateinfo"); # while (my $ref = $sth->fetchrow_hashref()) # { # $the_hash{"$ref->{'day'}.$ref->{'month'}/info"} = "$ref->{'text_field_1'}
$ref->{'text_field_2'}
"; # $the_hash{"$ref->{'day'}.$ref->{'month'}/info"} =~ s/
$// if $the_hash{"$ref->{'day'}.$ref->{'month'}/info"} =~ /

$/; # $the_hash{"$ref->{'day'}.$ref->{'month'}/info"} =~ s/^
//; # } # db_end(); my $border1 = local_date2utc_epoch(0,0,0,$startday, $startmonth, $startyear); # d,m,y,h,min my $border2 = local_date2utc_epoch(0,0,0,$endday, $endmonth, $endyear); # d,m,y,h,min,s $category_sql = " and type = '$filter_category' " if $filter_category; db_list("SELECT * FROM $CALENDAR where user = '$CALENDARUSER' $category_sql and epoch >= '$border1' and epoch < '$border2' order by epoch"); while (my $ref = $sth->fetchrow_hashref()) { unless ($return_only_IDs) { my @the_date = utc_epoch2date($ref->{'epoch'}); my @the_date_end = utc_epoch2date($ref->{'end_epoch'}); my ($linkstart, $linkend, %arguments, $checked); #store the starting and ending epochs for the color encoding of the cells if ($ref->{'time'} eq 'full') { $startepochs[$num_of_events] = $ref->{'epoch'}; $endepochs[$num_of_events] = $ref->{'epoch'}; } else { $startepochs[$num_of_events] = $ref->{'epoch'}; $endepochs[$num_of_events] = $ref->{'end_epoch'}; } $num_of_events++; if($edit_on) { my $text = $ref->{'text'}; ($text) = html_escape($text); ($text) = itag_replacer($text); $text =~ s/\n/
/gm; $text = $gettext->gettext('No description.') unless $text; $linkstart = qq[]; $linkend = ''; } else { $linkstart = ''; $linkend = ''; } #the checkboxes are named checkb[some number] -- for example checkb0 for the first event for which a checkbox is generated $checked = ''; %arguments = ( name => "checkb$number_of_checkboxes", value => $ref->{'IDnumber'}, checked => $checked ); $number_of_checkboxes++; $the_date[5] =~ s/^0+//; $the_date[4] =~ s/^0//; $the_date[3] =~ s/^0//; $the_date[2] = '0'.$the_date[2] while length($the_date[2]) < 2; $the_date_end[2] = '0'.$the_date_end[2] while length($the_date_end[2]) < 2; $the_hash{'greatest_hour'} = $the_date_end[2] if $usehours && $the_hash{'greatest_hour'} < $the_date_end[2]; my ($hourstuff, $detailstuff, $recurrencemarker, $timestuff) = ('','','',''); $hourstuff = "/$the_date[2]" if $usehours; $detailstuff = itag_replacer("
$ref->{'text'}") if ($writedetails); $detailstuff =~ s/\n/
/gm; $recurrencemarker = ' (R)' if $ref->{'recrule'} ne 'norec'; if ($ref->{'time'} eq 'full') {$timestuff = ''; $hourstuff = '/full'} else {$timestuff = "$the_date[2]:$the_date[1] :";} $the_hash{"$the_date[3].$the_date[4].$the_date[5]$hourstuff"} .= checkbox(%arguments) . qq[$linkstart $timestuff $ref->{'summary'}$recurrencemarker $detailstuff $linkend].tag('br'); } else { $the_hash{$ref->{'epoch'}} = $ref->{'IDnumber'}; } } db_end(); $the_hash{'number_of_checkboxes'} = $number_of_checkboxes; return %the_hash; } ######################################################################### # make_calendar_view_options - makes HTML "select" options # #-----------------------------------------------------------------------# # make_calendar_view_options($view_type) # # # # Returns the "select" field options for calendar views in HTML. # # # # Usage: # # $HTML = make_calendar_view_options($form->{'view'}) # # # ######################################################################### sub make_calendar_view_options { my $viewtype = shift; my($HTML, %selected); $selected{$viewtype} = ' SELECTED'; my %option_text = ('day' => $gettext->gettext('Day view'), 'week' => $gettext->gettext('Week view'), 'month' => $gettext->gettext('Month view'), 'year' => $gettext->gettext('Year view'), 'list' => $gettext->gettext('List view')); foreach('day','week','month','year','list') { $HTML .= qq[]; } return $HTML; } ################################################################################# # make_date_list_of_the_week - makes a list of dates in a given week # #-------------------------------------------------------------------------------# # make_date_list_of_the_week($day,$month,$year) # # # # Returns the dates of the week in a single string. # # The returned dates are in the format "$day.$month.$year" and are separated # # with spacebar characters. # # The date given as an argument must be date of the monday of the week. # # # # Usage: # # $string = make_date_list_of_the_week(25,12,2000) # # # # # ################################################################################# sub make_date_list_of_the_week { my ($day,$month,$year) = @_; my ($the_string); for (my $i = 0; $i<7; $i++) { my ($day2,$month2,$year2) = date_after_x_days($day,$month,$year,$i); $the_string .= "$day2.$month2.$year2 "; } return $the_string; } ######################################################################### # date_to_epoch - modifies given time to epoch format # #-----------------------------------------------------------------------# # date_to_epoch($day,$month,$year,$hour,$minute,$second) # # # # Returns the date in epoch format (seconds since 1.1.1970, 0:00). # # # # Usage: # # $epoch = date_to_epoch($day,$month,$year,$hour,$minute,$second) # # # ######################################################################### #sub date_to_epoch #{ # my ($day,$month,$year,$hour,$minute,$second) = @_; # # return days_in_between(1,1,1970, $day,$month,$year)*86400+($hour-timezone())*3600+$minute*60+$second; #} ######################################################################### # timezone - returns the timezone the server is located in # #-----------------------------------------------------------------------# # timezone() # # # # Returns the timezone in which the server is located in. Timezone is # # returned in hours (the difference of time between the local time and # # GMT). # # # # Usage: # # $time_difference = timezone() # # # ######################################################################### #sub timezone #{ # my $time = time(); # my (@l) = localtime($time); # my (@g) = gmtime($time); # my $off = $l[0] - $g[0] + ($l[1] - $g[1]) * 60 + ($l[2] - $g[2]) * 3600; # if ($l[7] == $g[7]) {} # elsif ($l[7] == $g[7] + 1) {$off += 86400;} # elsif ($l[7] == $g[7] - 1) {$off -= 86400;} # elsif ($l[7] < $g[7]) {$off += 86400;} # else {$off -= 86400;} # $off /= 3600; # return $off; #}