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

www lon-capa-cvs@mail.lon-capa.org
Fri, 12 May 2006 02:17:50 -0000


www		Thu May 11 22:17:50 2006 EDT

  Modified files:              
    /loncom/interface	filetypes.tab lonannounce.pm loncommon.pm 
  Log:
  Saving my work on iCalendar files.
  
  Still left to do:
  
  * time format wrong: 200656 instead of 20060506
  * Calendar does not seem to collect all data from all courses
  * remove "INTERNAL:"
  * put in course description
  
  
Index: loncom/interface/filetypes.tab
diff -u loncom/interface/filetypes.tab:1.28 loncom/interface/filetypes.tab:1.29
--- loncom/interface/filetypes.tab:1.28	Thu May 11 20:42:45 2006
+++ loncom/interface/filetypes.tab	Thu May 11 22:17:50 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # file extension description file
 #
-# $Id: filetypes.tab,v 1.28 2006/05/12 00:42:45 www Exp $
+# $Id: filetypes.tab,v 1.29 2006/05/12 02:17:50 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1277,7 +1277,6 @@
 icm             unk    unk              Image Color Matching Profile File
 icn             unk    unk              Icon Program
 ico             unk    unk              Icon 
-ics             unk    unk              Outlook Calendar File
 id              unk    unk              Disk Identification File
 ida             unk    unk              MS Server File (default.ida is attacked by the Code R
 idb             unk    unk              MS Developer Intermediate File
@@ -3283,3 +3282,4 @@
 xlt             unk     application/vnd.ms-excel         Excel Template
 xlv             unk     application/vnd.ms-excel         Excel VBA
 xlw             unk     application/vnd.ms-excel         Excel Workspace
+ics             unk     text/calendar                    iCalendar File
Index: loncom/interface/lonannounce.pm
diff -u loncom/interface/lonannounce.pm:1.51 loncom/interface/lonannounce.pm:1.52
--- loncom/interface/lonannounce.pm:1.51	Sun Apr 23 03:16:07 2006
+++ loncom/interface/lonannounce.pm	Thu May 11 22:17:50 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Announce
 #
-# $Id: lonannounce.pm,v 1.51 2006/04/23 07:16:07 albertel Exp $
+# $Id: lonannounce.pm,v 1.52 2006/05/12 02:17:50 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -326,9 +326,43 @@
 </script>
 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;
@@ -479,11 +513,7 @@
         &editfield($r,$today,$tomorrow,'');
     }
 # ----------------------------------------------------- Summarize all calendars
-    my %allcal=();
-    foreach my $course (sort(&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); }
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.369 loncom/interface/loncommon.pm:1.370
--- loncom/interface/loncommon.pm:1.369	Thu May 11 15:04:31 2006
+++ loncom/interface/loncommon.pm	Thu May 11 22:17:50 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.369 2006/05/11 19:04:31 www Exp $
+# $Id: loncommon.pm,v 1.370 2006/05/12 02:17:50 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2606,6 +2606,14 @@
              'dlsav'   => $ltime[8] );
 }
 
+sub utc_string {
+    my ($date)=@_;
+    my @utctime=gmtime($date);
+    my $year=$utctime[5]+1900;
+    my $month=$utctime[4]+1;
+    return "$year$month$utctime[3]T$utctime[2]$utctime[1]$utctime[0]Z";
+}
+
 sub maketime {
     my %th=@_;
     return POSIX::mktime(