#-------------------------------------------------------------------------- # # Author: Michel Bourget # ported and slightly extended bu thomas@bitrot.de # #-------------------------------------------------------------------------- # This function returns the day of the week of the first day of the # specified month. Rewritten 21.12.98 thomas@bitrot.de #-------------------------------------------------------------------------- sub firstdom { local($mo, $yr)=@_; local($da, # the day Jan 1 of this year is on $offset, # difference between last year and this year $i, # loop index ); @days=(0,31,28,31,30,31,30,31,31,30,31,30,31 ); $da=(5+$yr+int(($yr+3)/4))%7; $days[2]=29 if ($yr%4 == 0); for ($i=1; $i<$mo; $i++) { $da+=$days[$i]; } $da%7; } # firstdom #-------------------------------------------------------------------------- # This routine print Day label and day content for Month and Day view #-------------------------------------------------------------------------- sub printday { local($day, $mo, $yr,$dayweek,$mode,$url)=@_; local($date, # Date to examine $descr, # description of the event $flags, # how to sort out the various types of data $filter,# gets matched against flags $count, # number of events encountered so far ); local($i,$PrtRows); $numsize=4; $datasize=2; print ""; if (!$day) { print "$day

\n"; } else { if ($mode eq short) { if ( $height < 2 ) { $height = 2 ; } print ""; $Today_Flag=""; if ( $Today_Year == $yr && $Today_Month == $mo && $Today_Day == $day ) { $Today_Flag=""; } $holiday_text=""; foreach $line ( @PlanHoliday ) { @tmp=split(/;/,$line); @hol=split(/\./,$tmp[1]); if ( $hol[0] eq $day && $hol[1] eq $mo ) { $holiday_text=$tmp[2]; last; } } print "$Today_Flag$day $holiday_text
\n"; } else { print "
\n"; } $PrtRows=0; foreach $line (@PlanData) { if ( $line =~ /, $day\./ ) { @printpart= split(/;/,$line); # Filter User you want to see : Team never ignored if ( $Group eq "none" || $Group =~ $printpart[4] || $printpart[4] =~ "Team" ) { if ( "$printpart[4]" ne "Team" ) { # Filter Private Appt if ( $show_private eq "no" && substr($printpart[5],0,1) eq "." ) { next; } # Filter Appointment if ( $show_appt eq "no" && $printpart[2] ne "-" ) { next; } } if ( $mode eq short ) { $qui=substr($printpart[4],0,4); $note=substr($printpart[5],0,10); print ""; print "$qui "; print ""; print "$note
\n"; print ""; } else { $id=$printpart[0]; $debut=$printpart[2]; $fin=$printpart[3]; $qui=$printpart[4]; $note=$printpart[5]; print ""; print "
Del
"; # print "$id"; print "
$debut
"; print "
$fin
"; print "  $qui"; print "  $note"; # print "$id\t$debut\t$fin\t$qui\t$note

\n"; print ""; } $PrtRows++; } } } if ( $mode eq short ) { #for ($i=$PrtRows;$i<=$height;$i++) { #print ("
\n"); #} print ("
\n"); } } } # printday #-------------------------------------------------------------------------- # Print out the month's calendar #-------------------------------------------------------------------------- sub month { local($mo,$yr,$url)=@_; local($da,$i); $da=&firstdom($mo,$yr); $pmo=$mo-1; $pyr=$yr; if ( $pmo < 1 ) { $pmo=12; $pyr=$yr-1; } $nmo=$mo+1; $nyr=$yr; if ( $nmo > 12 ) { $nmo=1; $nyr=$yr+1; } $Ppyr=$yr-1; $Pnyr=$yr+1; print "
"; print "\n"; # Get us spaced over to the appropriate day of the week for ($i=0; $i<$da; $i++) { &printday("",$mo,$yr); } # Print out the actual calendar for ($i=1; $i <= $days[$mo]; $i++ ) { if (($i==3) && ($days[$mo]==19)) { # attend to the fruitbasket $i+=11; $days[$mo]+=11; } &printday($i,$mo,$yr,$da,"short","$url"); $da++; if ($da > 6) { $da=0; print "\n\n" if ($i<$days[$mo]); } } # Fill out the rest of the calendar while (($da>0)&&($da<7)) { $da++; &printday("",$mo,$yr); } print "\n\n
$Ppyr $month[$pmo] $month[$Month] $Year $month[$nmo] $Pnyr
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
\n"; # wrap it all up print "
"; } # month #-------------------------------------------------------------------------- # Print out the day's calendar #-------------------------------------------------------------------------- sub day { local($jour,$mo,$yr,$url)=@_; local($da,$i); @DayOfTheWeek = ( "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" ); $da=&firstdom($mo,$yr); $pjour=$jour-1; $pmo=$mo; $pyr=$yr; if ( $pjour < 1 ) { $pmo=$mo-1; if ( $pmo < 1 ) { $pmo=12; $pyr=$yr-1; } $pjour=$days[$pmo]; } $njour=$jour+1; $nmo=$mo; $nyr=$yr; if ( $njour > $days[$mo] ) { $nmo=$mo+1; if ( $nmo > 12 ) { $nmo=1; $nyr=$yr+1; } $njour=1; } $holiday_text=""; foreach $line ( @PlanHoliday ) { @tmp=split(/;/,$line); @hol=split(/\./,$tmp[1]); if ( $hol[0] eq $jour && $hol[1] eq $mo ) { $holiday_text=$tmp[2]; last; } } print "
"; print "\n"; # Print out the actual calendar &printday($jour,$mo,$yr,$da,"long","$url"); print "\n\n
Previous $DayOfTheWeek[($da+$jour-1)%7] $month[$mo] $jour $yr ($holiday_text) Next
  From Length Who? Description
\n"; # wrap it all up print "
"; } # day 1; #-------------------------------------------------------------------------- # Get the list of user on netplan server #-------------------------------------------------------------------------- sub get_group { open(IN,"/usr/local/bin/plan -W localhost -F | sort |"); @PlanUsers=; close(IN); return @PlanUsers; } #-------------------------------------------------------------------------- # read data from plan's output for the specified month and year #-------------------------------------------------------------------------- sub get_plan_data { local($jj,$mo,$yr,$who)=@_; local($Who,@PlanData); if ( $who eq "none" ) { $Who="-o"; } else { $Who="-u $who,Team"; } $da=&firstdom($mo,$yr); if ( $jj eq 0 ) { open ( IN , "/usr/local/bin/plan -W $Who -i -t 1\.$mo\.$yr $days[$mo] |" ); } else { open ( IN , "/usr/local/bin/plan -W $Who -i -t $jj\.$mo\.$yr 1 |" ); } @PlanData=; close(IN); return @PlanData; } #-------------------------------------------------------------------------- # Get User data in user:serverName #-------------------------------------------------------------------------- sub obtain_user { local(@PlanData); open ( IN , "/usr/local/bin/plan -W -F | sort | " ); @PlanData=; close(IN); return @PlanData; } # obtain_user #-------------------------------------------------------------------------- # Print User's List #-------------------------------------------------------------------------- sub listUser { print "
\n";
   print "List of Users and their NetPlan server:

\n"; foreach $line ( @PlanData ) { @info=split(/;/,$line); chop $info[1]; print "$info[0]\t\t$info[1]\n"; } print "
\n"; print "
"; } # listUser #-------------------------------------------------------------------------- # read holiday data #-------------------------------------------------------------------------- sub get_holiday { local ($yr) = @_; open ( IN , "/usr/local/bin/plan -W -H $yr |" ); @PlanHoliday=; close(IN); return @PlanHoliday; } #-------------------------------------------------------------------------- # Get User's List according to who.txt DB #-------------------------------------------------------------------------- sub getUserList { $first=1; $userList=""; open ( DB , "who.txt" ) || die "can\'t open who.txt: $!";; while() { next if /^#/ ; chop ; ($region,$fonction,$cie,$nickname,$firstName,$lastName,$expertise)=split(":",$_); if( $What ne Team ) { next if ( $region ne $What ) ; } if( $Who ne Team ) { if( $Who eq Cray ) { next if ( $cie ne Cray ) ; } elsif ( $Who eq Mgr ) { next if ( $fonction ne Mgr ); } elsif ( $Who eq Ec ) { next if ( $fonction ne Ec ); } else { next if ( index("$expertise","$Who") eq -1 ); } } #print "$region $fonction $cie $nickname $firstName $lastName $expertise\n"; if(!$first) { $userList="$userList,"; } $userList="$userList$nickname"; $first=0; } close(DB); return $userList; } #-------------------------------------------------------------------------- # Prepare a form to add a new entry #-------------------------------------------------------------------------- sub add_entry { local ($goCal) = @_; print "
"; print "
"; print ""; print "
"; print "
\n"; @group_list=&get_group; print ""; # User print "User: "; print "\n"; # print "
"; # Start Date print "Start Date: "; # print "\n"; print "\n"; print "\n"; # print "
"; # Type print "Type: "; print "\n"; # print "DayEvent do not require Hour:Min Entry "; print "

\n"; print "
If Appointment, enter Time:"; print "\n"; print "Length: "; print "\n"; # Repeat Option print "
Repeat on a day of the month:"; print "\n"; print "
Repeat on a weekday: "; print "\n"; print "
Repeat every n days: "; print "\n"; print "
If Repeat is set, enter Stop Date: "; # print "\n"; # for ($i=1998;$i<=2034;$i++) { # print "\n"; print "\n"; print "

"; # Text print ""; if ( $goCal eq 1 ) { print "" } print "
";
   	open(CAL,"/usr/bin/cal $Month $Year |");
   	while() {
		chop;
		print "$_
"; } close(CAL); print "
"; print "Note: "; print "

\n

" ; print ""; print "\n" ; print "

"; } # form