--- loncom/interface/lonannounce.pm 2006/01/12 22:45:19 1.39 +++ loncom/interface/lonannounce.pm 2006/01/12 22:58:47 1.40 @@ -1,7 +1,7 @@ # The LearningOnline Network # Announce # -# $Id: lonannounce.pm,v 1.39 2006/01/12 22:45:19 albertel Exp $ +# $Id: lonannounce.pm,v 1.40 2006/01/12 22:58:47 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -142,10 +142,11 @@ sub emptycell { sub normalcell { my ($day,$month,$year,$text)=@_; my $output=''; - foreach (split(/\_\_\_\&\&\&\_\_\_/,$text)) { - if ($_) { + my @items=&order($text); + foreach my $item (@items) { + if ($item) { my $internalflag=0; - my ($courseid,$start,$end,@msg)=split(/\@/,$_); + my ($courseid,$start,$end,@msg)=split(/\@/,$item); my $msg=join('@',@msg); if ($msg=~/INTERNAL\:/) { $msg=~s/INTERNAL\://gs; @@ -184,9 +185,10 @@ sub normalcell { sub plaincell { my ($text)=@_; my $output=''; - foreach (split(/\_\_\_\&\&\&\_\_\_/,$text)) { - if ($_) { - my ($courseid,$start,$end,@msg)=split(/\@/,$_); + my @items=&order($text); + foreach my $item (@items) { + if ($item) { + my ($courseid,$start,$end,@msg)=split(/\@/,$item); my $msg=join('@',@msg); my $fullmsg=&mt('Calendar Announcement for ').$env{'course.'.$courseid.'.description'}. '\n'.&Apache::lonlocal::locallocaltime($start); @@ -208,9 +210,10 @@ sub plaincell { sub listcell { my ($text)=@_; my $output=''; - foreach (split(/\_\_\_\&\&\&\_\_\_/,$text)) { - if ($_) { - my ($courseid,$start,$end,@msg)=split(/\@/,$_); + my @items=&order($text); + foreach my $item (@items) { + if ($item) { + my ($courseid,$start,$end,@msg)=split(/\@/,$item); my $msg=join('@',@msg); $msg=~s/INTERNAL\://gs; my $fullmsg=&Apache::lonlocal::locallocaltime($start); @@ -226,6 +229,19 @@ sub listcell { return $output; } +sub order { + my ($text)=@_; + my @items = split(/___&&&___/,$text); + sort { + my (undef,$astart,$aend)=split(/\@/,$a); + my (undef,$bstart,$bend)=split(/\@/,$b); + if ($astart != $bstart) { + return $astart <=> $bstart; + } + return $aend <=> $bend; + } @items; +} + sub nextday { my %th=@_; $th{'day'}++; @@ -242,11 +258,11 @@ sub showday { $tk-=$oneday; $nextday+=$oneday; } - foreach (keys %allcal) { - my ($course,$startdate,$enddate)=($_=~/^(\w+)\@(\d+)\_(\d+)$/); + foreach my $item (keys(%allcal)) { + my ($course,$startdate,$enddate)=($item=~/^(\w+)\@(\d+)\_(\d+)$/); if (($startdate<$nextday) && ($enddate>=$tk)) { $outp.='___&&&___'.$course.'@'.$startdate.'@'.$enddate.'@'. - $allcal{$_}; + $allcal{$item}; } } unless ($mode) {