--- loncom/interface/lonannounce.pm 2006/03/15 21:55:43 1.46 +++ loncom/interface/lonannounce.pm 2006/05/12 02:17:50 1.52 @@ -1,7 +1,7 @@ # The LearningOnline Network # Announce # -# $Id: lonannounce.pm,v 1.46 2006/03/15 21:55:43 albertel Exp $ +# $Id: lonannounce.pm,v 1.52 2006/05/12 02:17:50 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -155,12 +155,12 @@ sub readcalendar { } sub emptycell { - return ' '; + return ' '; } sub normalcell { my ($day,$month,$year,$text)=@_; - my $output=''; + my $output; my @items=&order($text); foreach my $item (@items) { if ($item) { @@ -189,20 +189,22 @@ sub normalcell { $fullmsg=~s/[\n\r]/\\n/gs; $fullmsg=&HTML::Entities::encode($fullmsg,'<>&"\''); $fullmsg=~s/&/\\&/g; + my $short_msg = substr($msg,0,20).((length($msg) > 20)?'...':''); + if (defined($output)) { $output.='
'; } $output.=''. - substr($msg,0,20).'...
'; + $short_msg.''; } } - return ''.&tfont(''.&picklink($day,$day,$month,$year).'
'.$output).''; + ($year eq $todayhash{'year'}))?'_current':''). + '" >'.&picklink($day,$day,$month,$year).'
'.$output.''; } sub plaincell { my ($text)=@_; - my $output=''; + my $output; my @items=&order($text); foreach my $item (@items) { if ($item) { @@ -217,8 +219,10 @@ sub plaincell { $fullmsg=~s/[\n\r]/\\n/gs; $fullmsg=&HTML::Entities::encode($fullmsg,'<>&"\''); $fullmsg=~s/&/\\&/g; + my $short_msg = substr($msg,0,80).((length($msg) > 80)?'...':''); + if (defined($output)) { $output.='
'; } $output.=''. - substr($msg,0,80).'...
'; + $short_msg.''; } } return $output; @@ -295,15 +299,6 @@ sub showday { } } -sub tfont { - my $text=shift; - if ($env{'form.pickdate'} eq 'yes') { - return ''.$text.''; - } else { - return $text; - } -} - sub picklink { my ($text,$day,$month,$year)=@_; if ($env{'form.pickdate'} eq 'yes') { @@ -331,9 +326,43 @@ function dialin(day,month,year) { ENDDIA } +# ----------------------------------------------------- Summarize all calendars +sub get_all_calendars { + my %allcal=(); + foreach my $course (sort(&Apache::loncommon::findallcourses())) { + %allcal=(%allcal,&readcalendar($course)); + } + return %allcal; +} + +sub output_ics_file { + my ($r)=@_; +# RFC 2445 wants CRLF + my $crlf="\015\012"; +# Header + $r->print("BEGIN:VCALENDAR$crlf"); + $r->print("VERSION:2.0$crlf"); + $r->print("PRODID:-//LONCAPA//LONCAPA Calendar Output//EN$crlf"); + my %allcal=&get_all_calendars(); + foreach my $event (keys(%allcal)) { + my ($course,$startdate,$enddate)=($event=~/^(\w+)\@(\d+)\_(\d+)$/); + $r->print("BEGIN:VEVENT$crlf"); + $r->print("DTSTART:".&Apache::loncommon::utc_string($startdate).$crlf); + $r->print("DTEND:".&Apache::loncommon::utc_string($enddate).$crlf); + $r->print("SUMMARY:$allcal{$event}$crlf"); + $r->print("END:VEVENT$crlf"); + } +# Footer + $r->print("END:VCALENDAR$crlf"); +} sub handler { my $r = shift; + if ($r->uri=~/\.(ics|ical)$/) { + &Apache::loncommon::content_type($r,'text/calendar'); + &output_ics_file($r); + return OK; + } &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; return OK if $r->header_only; @@ -342,8 +371,7 @@ sub handler { my $today=time; %todayhash=&Apache::loncommon::timehash($today); # ----------------------------------------------------------------- Check marks - %showedcheck=(); - undef %showedcheck; + undef(%showedcheck); # ---------------------------------------------------------- Get month and year &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['month','year','pickdate','formname','element']); @@ -366,12 +394,8 @@ sub handler { 'dlsav' => -1 )); my $weekday=$firstday{'weekday'}; # ------------------------------------------------------------ Print the screen - my $html=&Apache::lonxml::xmlbegin(); - $r->print(< -The LearningOnline Network with CAPA - - ENDDOCUMENT + if ($pickdatemode) { # no big header in pickdate mode - $r->print(&Apache::loncommon::bodytag("Pick a Date",'','',1). + $r->print(&Apache::loncommon::start_page("Pick a Date",$js, + {'only_body' => 1,}). &dialscript(). ''); } else { - $r->print(&Apache::loncommon::bodytag("Announcements and Calendar")); + $r->print(&Apache::loncommon::start_page("Announcements and Calendar", + $js)); } # does this user have privileges to post, etc? my $allowed=0; @@ -487,11 +513,7 @@ SERVERANNOUNCE &editfield($r,$today,$tomorrow,''); } # ----------------------------------------------------- Summarize all calendars - my %allcal=(); - foreach my $course (&Apache::loncommon::findallcourses()) { - %allcal=(%allcal,&readcalendar($course)); - } - + my %allcal=&get_all_calendars(); # ------------------------------- Initialize table and forward backward buttons my ($pm,$py,$fm,$fy)=($month-1,$year,$month+1,$year); if ($pm<1) { ($pm,$py)=(12,$year-1); } @@ -507,9 +529,15 @@ SERVERANNOUNCE if (($year<1970) || ($year>2037)) { $r->print('

No calendar available for this date.

'. 'Current Month'); + '&year='.$todayhash{'year'}.'">Current Month'. + &Apache::loncommon::end_page()); return OK; } + + my $class = "LC_calendar"; + if ($env{'form.pickdate'} eq 'yes') { + $class .= " LC_calendar_pickdate"; + } $r->print( ''.&mt('Previous Month').' '. @@ -518,21 +546,14 @@ SERVERANNOUNCE '   '.&mt('Current Month').'

'. - ''); + '
'. -&tfont(&mt('Sun')) -.''. -&tfont(&mt('Mon')) -.''. -&tfont(&mt('Tue')) -.''. -&tfont(&mt('Wed')) -.''. -&tfont(&mt('Thu')) -.''. -&tfont(&mt('Fri')) -.''. -&tfont(&mt('Sat')) -.'
+ + + + + + +'); my $tk=&Apache::loncommon::maketime(%firstday); my $outp; @@ -559,8 +580,7 @@ SERVERANNOUNCE # ------------------------------------------------------------------- End table $r->print('
'.&mt('Sun').''.&mt('Mon').''.&mt('Tue').''.&mt('Wed').''.&mt('Thu').''.&mt('Fri').''.&mt('Sat').'
'); # ----------------------------------------------------------------- Check marks - %showedcheck=(); - undef %showedcheck; + undef(%showedcheck); # --------------------------------------------------------------- Remove button if ($allowed) { $r->print(''. &Apache::loncommon::help_open_topic('Calendar_Remove_Announcement').''); } @@ -572,8 +592,7 @@ SERVERANNOUNCE '   '.&mt('Current Month').'

'. - ($pickdatemode?'
':''). - ''); + ($pickdatemode?'':'').&Apache::loncommon::end_page()); return OK; } 500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.