
| Current Path : /var/www/web-klick.de/dsh/90_akt/old/utility/Process/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/web-klick.de/dsh/90_akt/old/utility/Process/Calendar.pm |
package Process::Calendar;
use strict;
# use POSIX;
use Time::ParseDate;
use Date::Format;
sub new {
my $class = shift;
my $self = {};
$self->{'WDAY'} = ["So","Mo","Di","Mi","Do","Fr","Sa"];
bless($self,$class);
return($self);
}
#************************************************************************
sub load_calendar {
my $self = shift;
my $text = shift;
while( $text =~ s/\n[- ]*\n/\n/gs ) { 1; }
$text =~ s/\n(\S)/\n\n$1/gs;
$text = $text . "\n";
my $o; my $o1; my $o2; my $date; my $time; my $wday;
my @ee = split(/\n\n/,$text);
my $ff = [];
foreach $o (@ee) {
$date = "";
$time = "";
if ($o =~ /^(.*?)(\d+)\.(\d+)\.(\d\d\d\d)/) {
$o1 = $1;
$date = $4.sprintf("%02u",$3).sprintf("%02u",$2);
$wday = (localtime(parsedate($2.".".$3.".".$4,UK=>1)))[6];
if ($o1 =~ /^(Mo|Di|Mi|Do|Fr|Sa|So), $/) {
$o = substr($o,4);
$o1 = "";
}
if (!$o1) { $o = $self->{'WDAY'}->[$wday] . ", " . $o; }
}
next if (!$date);
if ($o =~ /(\d+)\.(\d+)(\s*)--(\s*)(\d+)\.(\d+)/) {
$time = sprintf("%02u",$1) . sprintf("%02u",$2) .
sprintf("%02u",$5) . sprintf("%02u",$6);
} else {
$time = "00002400";
}
push(@$ff,[$o."\n",$date.$time]);
}
$self->{'CALENDAR'} = $ff;
}
#*************************************************************************
sub sort_calendar {
my $self = shift;
$self->{'CALENDAR'} = [sort {$a->[1] cmp $b->[1]} @{$self->{'CALENDAR'}}];
}
#*************************************************************************
sub reduce {
my $self = shift;
my $cond = shift;
my $all = shift;
my $bed; my $o; my $o1; my $text = "";
my @cc = split(/,/,$cond);
foreach $o (@{$self->{'CALENDAR'}}) {
$bed = 1;
foreach $o1 (@cc) {
next if ($o->[0] =~ /$o1/);
$bed = 0;
last;
}
next if (!$bed);
$o1 = $o->[0];
if (!$all) {
$o1 =~ s/^(.*)\[(.*)\]/$1/s;
$o1 =~ s/\n *\n/\n/gs;
}
$text = $text . $o1;
}
return($text);
}
#*****************************************************************
sub synchronize {
my $self = shift;
my $cal_list = shift; # Zu synchronisierende Kalender
my $nr = shift; # Laufende Nummer
my $text = shift; # Messages von anderen Kalendern
my $force = shift;
$cal_list = "," . $cal_list . ",";
my $cal; my $termin; my $calendars; my @calendars1; my $rest; my $o; my $o1;
my $name; my $status;
#------------- Ausgabe der Kalender-Anfragen:
my $queries = {};
foreach $o (@{$self->{'CALENDAR'}}) {
$termin = $o->[0];
next if ($termin !~ /^(.*)\[(.*)\]([\n ]*)$/s);
$termin = $1;
$calendars = $2;
$rest = $3;
@calendars1 = ();
foreach $cal (split(/,/,$calendars)) {
if ($cal =~ /^(.*)(\d)$/) {
$name = $1;
$status = $2;
$o1 = "," . $name . ",";
if ($cal_list =~ /$o1/) {
if ($status == 1 or ($status == 2 and $force)) {
$queries->{$name} = $queries->{$name} .
$self->anfrage($o,$termin);
$status = 2;
}
push(@calendars1,$name.$status);
$cal = "";
}
}
if ($cal) {
push(@calendars1,$cal);
}
}
$o->[0] = $termin . "\[" . join(",",@calendars1) . "\]" . $rest;
}
return($queries);
}
#************************************************************************
sub anfrage {
my $self = shift;
my $o = shift;
my $termin = shift;
my $text = $o->[1] . "\n" . $termin . "\n";
return($text);
}
1;