[LON-CAPA-cvs] cvs: loncom /interface lonannounce.pm

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 12 Jan 2006 22:58:47 -0000


albertel		Thu Jan 12 17:58:47 2006 EDT

  Modified files:              
    /loncom/interface	lonannounce.pm 
  Log:
  - sigh, cal items were displayed in hash order
  
  
Index: loncom/interface/lonannounce.pm
diff -u loncom/interface/lonannounce.pm:1.39 loncom/interface/lonannounce.pm:1.40
--- loncom/interface/lonannounce.pm:1.39	Thu Jan 12 17:45:19 2006
+++ loncom/interface/lonannounce.pm	Thu Jan 12 17:58:47 2006
@@ -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 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 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 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 @@
     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 @@
 	$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) {