--- loncom/interface/lonannounce.pm 2007/03/02 23:17:58 1.66 +++ loncom/interface/lonannounce.pm 2009/04/04 21:47:40 1.79 @@ -1,7 +1,7 @@ # The LearningOnline Network # Announce # -# $Id: lonannounce.pm,v 1.66 2007/03/02 23:17:58 albertel Exp $ +# $Id: lonannounce.pm,v 1.79 2009/04/04 21:47:40 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -38,6 +38,8 @@ use Apache::lonrss(); use Apache::lonnet; use HTML::Entities(); use LONCAPA qw(:match); +use DateTime; +use DateTime::TimeZone; my %todayhash; my %showedcheck; @@ -51,14 +53,17 @@ sub editfield { my $enddateform = &Apache::lonhtmlcommon::date_setter('anno', 'enddate', $end); - my $help=&Apache::loncommon::help_open_menu('Calendar Add Announcement','Calendar_Add_Announcement',274,'Communication Tools'); - my %lt=&Apache::lonlocal::texthash('post' => 'Post Announcement', + #my $help=&Apache::loncommon::help_open_menu('Calendar Add Announcement','Calendar_Add_Announcement',274,'Communication Tools'); + my $help=&Apache::loncommon::help_open_topic('Calendar_Add_Announcement'); + + my %lt=&Apache::lonlocal::texthash('annon' => 'Course Announcements', + 'post' => 'Post Announcement', 'start' => 'Starting date', 'end' => 'Ending date', 'incrss' => 'Include in course RSS newsfeed'); $r->print(<$lt{'annon'} $help
@@ -74,6 +79,16 @@ sub readcalendar { my $courseid=shift; my $coursenum=$env{'course.'.$courseid.'.num'}; my $coursedom=$env{'course.'.$courseid.'.domain'}; + if ($coursenum eq '' || $coursedom eq '') { + my %courseinfo=&Apache::lonnet::coursedescription($courseid); + if ($coursenum eq '' && exists($courseinfo{'num'})) { + $coursenum = $courseinfo{'num'}; + } + if ($coursedom eq '' && exists($courseinfo{'domain'})) { + $coursedom = $courseinfo{'domain'}; + } + } + my %thiscal=&Apache::lonnet::dump('calendar',$coursedom,$coursenum); my %returnhash=(); foreach my $item (keys(%thiscal)) { @@ -89,12 +104,17 @@ sub readcalendar { if ($courseid eq $env{'request.course.id'}) { $navmap = Apache::lonnavmaps::navmap->new(); } - my %resourcedata= + + my $resourcedata= &Apache::lonnet::get_courseresdata($coursenum,$coursedom); - foreach my $thiskey (sort keys %resourcedata) { - if ($resourcedata{$thiskey.'.type'}=~/^date/) { + if (ref($resourcedata) ne 'HASH') { + return %returnhash; + } + foreach my $thiskey (keys(%$resourcedata)) { + if ($resourcedata->{$thiskey.'.type'}=~/^date/) { my ($course,$middle,$part,$name)= - ($thiskey=~/^($match_courseid)\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/); + ($thiskey=~/^(\Q$courseid\E)\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/); + my %data = ( 'section' => &mt('All Students')); if ($middle=~/^\[(.*)\]\./) { my $sec=$1; @@ -120,7 +140,9 @@ sub readcalendar { } if (!$can_see_hidden) { my $res = $navmap->getResourceByUrl($map_url); - if ($res && $res->randomout()) { next; } + if ($res && $res->randomout()) { + next; + } } $data{'realm'}=&mt('Folder/Map'); $data{'url'} = $map_url; @@ -130,7 +152,9 @@ sub readcalendar { } if (!$can_see_hidden) { my $res = $navmap->getBySymb($middle); - if ($res && $res->randomout()) { next; } + if ($res && $res->randomout()) { + next; + } } $data{'realm'} = &mt('Resource'); $data{'symb'} = $middle; @@ -141,7 +165,7 @@ sub readcalendar { # see if accidentally answerdate is before duedate my $answerkey=$thiskey; $answerkey=~s/duedate$/answerdate/; - if ($resourcedata{$thiskey}>$resourcedata{$answerkey}) { + if ($resourcedata->{$thiskey}>$resourcedata->{$answerkey}) { $data{'datetype'} = &mt('Due and Answer Available'); } } @@ -156,15 +180,15 @@ sub readcalendar { # see if accidentally answerdate is before duedate my $duekey=$thiskey; $duekey=~s/answerdate$/duedate/; - if ($resourcedata{$duekey}>$resourcedata{$thiskey}) { + if ($resourcedata->{$duekey}>$resourcedata->{$thiskey}) { # forget it next; } $data{'datetype'}=&mt('Answer Available'); } $returnhash{join("\0",$courseid, - $resourcedata{$thiskey}, - $resourcedata{$thiskey})}=\%data; + $resourcedata->{$thiskey}, + $resourcedata->{$thiskey})}=\%data; } } return %returnhash; @@ -273,11 +297,59 @@ sub order { } sub nextday { - my %th=@_; - $th{'day'}++; + my ($tk,%th)=@_; + my ($incmonth,$incyear); + if ($th{'day'} > 27) { + if ($th{'month'} == 2) { + if ($th{'day'} == 29) { + $incmonth = 1; + } elsif ($th{'day'} == 28) { + if (!&is_leap_year($tk)) { + $incmonth = 1; + } + } + } elsif (($th{'month'} == 4) || ($th{'month'} == 6) || + ($th{'month'} == 9) || ($th{'month'} == 11)) { + if ($th{'day'} == 30) { + $incmonth = 1; + } + } elsif ($th{'day'} == 31) { + if ($th{'month'} == 12) { + $incyear = 1; + } else { + $incmonth = 1; + } + } + if ($incyear) { + $th{'day'} = 1; + $th{'month'} = 1; + $th{'year'}++; + } elsif ($incmonth) { + $th{'day'} = 1; + $th{'month'}++; + } else { + $th{'day'}++; + } + } else { + $th{'day'}++; + } return (&Apache::loncommon::maketime(%th),$th{'month'}); } +sub is_leap_year { + my ($thistime) = @_; + my ($is_leap,$timezone,$dt); + $timezone = &Apache::lonlocal::gettimezone(); + eval { + $dt = DateTime->from_epoch(epoch => $thistime) + ->set_time_zone($timezone); + }; + if (!$@) { + $is_leap = $dt->is_leap_year; + } + return $is_leap; +} + sub display_msg { my ($msg) = @_; @@ -304,7 +376,7 @@ sub display_msg { sub showday { my ($tk,$mode,%allcal)=@_; my %th=&Apache::loncommon::timehash($tk); - my ($nextday,$nextmonth)=&nextday(%th); + my ($nextday,$nextmonth)=&nextday($tk,%th); my @outp; if ($mode) { my $oneday=24*3600; @@ -343,7 +415,7 @@ sub picklink { sub dialscript { return (< +
$lt{'start'}:$startdateform