Bug fix
[tpope-extra.git] / perl / schedproc
1 #!/usr/bin/perl -w
2 # $Id$
3 # -*- perl -*- vim: ft=perl sw=4 sts=4
4
5 # Brief usage instructions:
6 # Create a ~/.sct6rc that has SID=yourssn and PIN=yourpin
7 # You'll need to change the url below if you go anywhere but TAMUK.
8
9 use strict;
10 use Date::Calc::Object qw(Day_of_Week Decode_Day_of_Week Decode_Month Week_of_Year Monday_of_Week Day_of_Week_Abbreviation Delta_Days Add_Delta_Days Nth_Weekday_of_Month_Year Gmtime Mktime);
11 use Date::Calendar::Profiles qw($Profiles);
12 use Date::Calendar::Year;
13 use LWP::UserAgent;
14 use XML::Simple;
15 use vars qw(%opts %faculty);
16
17 my ($response);
18
19 $opts{'holidays'} = { # %{$Profiles->{'US-TX'}},
20     "Martin Luther King Day"    => "3/Mon/Jan",
21     "Good Friday"               => "-2",
22     "Spring Break Monday"       => \&Spring_Break,
23     "Spring Break Tuesday"      => \&Spring_Break,
24     "Spring Break Wednesday"    => \&Spring_Break,
25     "Spring Break Thursday"     => \&Spring_Break,
26     "Spring Break Friday"       => \&Spring_Break,
27     "Spring Break Saturday"     => \&Spring_Break,
28     "Study Day"                 => "4/Thu/Apr", # ?
29     "Memorial Day"              => "5/Mon/May",
30     "Independence Day"          => \&US_Independence,
31     "Labor Day"                 => \&US_Labor,
32     #"Columbus Day"              => "2/Mon/Oct",
33     "Thanksgiving Day"          => "4/Thu/Nov",
34     "Thanksgiving Friday"       => \&Thanksgiving_Friday,
35 };
36
37 sub Spring_Break {
38     my($year,$label) = @_;
39     $label =~ s/^Spring Break //;
40     return( Add_Delta_Days(
41             Nth_Weekday_of_Month_Year($year,1,1,1),
42             7*(11-1) # This is for the 11th Monday of the year
43             +Decode_Day_of_Week($label)-1) );
44 }
45
46 sub Thanksgiving_Friday {
47     my($year,$label) = @_;
48     return( Add_Delta_Days(Nth_Weekday_of_Month_Year($year,11,4,4), 1) );
49 }
50 sub US_Independence # Fourth of July
51 {
52     my($year,$label) = @_;
53     return( &Date::Calendar::Profiles::Nearest_Workday($year,7,4) );
54 }
55 sub US_Labor # First Monday after the first Sunday in September
56 {
57     my($year,$label) = @_;
58     return( Add_Delta_Days(
59         Nth_Weekday_of_Month_Year($year,9,7,1), +1) );
60 }
61
62 my $config = $ENV{HOME} . "/.schedprocrc";
63 if (($ARGV[0] || "") eq '-F') {
64     shift;
65     $config = shift;
66 }
67
68 my $arg = "";
69 $arg = shift if (defined($ARGV[0]) && $ARGV[0] =~ /^-\w$/);
70
71 if (-r $config) {
72     open CONFIG, $config;
73     while(<CONFIG>) {
74         s/\#.*//;
75         next unless m/^([^=]*)=(.*)/;
76         $opts{$1}=$2;
77     }
78     close CONFIG;
79 }
80 my $schedurl = $ENV{HOME} . "/schedule.xml";
81 $schedurl = $opts{'schedule'} if(defined($opts{'schedule'}));
82 my $gradeurl = $ENV{HOME} . "/grades.xml";
83 $gradeurl = $opts{'grades'} if(defined($opts{'schedule'}));
84
85 sub generate_id {
86     my ($section, $number) = split("-", shift);
87     my $id = 0;
88     foreach (split //, $section) {$id=26*$id+(ord($_)-1)%32;}
89     $id=10000*$id+$number;
90     return $id;
91 }
92
93 sub next_class {
94     my %class = @_;
95     $class{'duration'} =~ /(\d\d\d\d)(\d\d)(\d\d)-(\d\d\d\d)(\d\d)(\d\d)/;
96     my $days = Delta_Days($1,$2,$3,$4,$5,$6);
97     my $firstday = Date::Calc->new($1,$2,$3);
98     my $lastday = Date::Calc->new($4,$5,$6);
99     my $today = Date::Calc->new(Date::Calc->localtime(time+3600*6)->date);
100     my @days=();
101     foreach(split(" ",$class{'days'})) {
102         push @days, Decode_Day_of_Week($_);
103     }
104     my @off = ();
105     @off = @{$class{'off'}} if ($class{'off'});
106     for($today = ($today > $firstday ? $today : $firstday); $today < $lastday; $today++) {
107         next unless(grep($_ == Day_of_Week($today->date), @days));
108         print "$today\n";
109         next if(grep($_ == "$today", @off));
110         return $today;
111     }
112     $today = Date::Calc->new(Date::Calc->gmtime->date);
113     for($today = ($today < $lastday ? $today : $lastday); $today > $firstday; $today--) {
114         next unless(grep($_ == Day_of_Week($today->date), @days));
115         next if(grep($_ == "$today", @off));
116         return $today;
117     }
118     return undef;
119 }
120
121 sub off_for_holidays {
122     my %class = @_;
123     $class{'duration'} =~ /(\d\d\d\d)(\d\d)(\d\d)-(\d\d\d\d)(\d\d)(\d\d)/;
124     my $days = Delta_Days($1,$2,$3,$4,$5,$6);
125     my $firstday = Date::Calc->new($1,$2,$3);
126     my $lastday = Date::Calc->new($4,$5,$6);
127     my $year = Date::Calendar::Year->new($1, $opts{'holidays'});
128     my @holidays=();
129     my @days=();
130     foreach(split(" ",$class{days})) {
131         $days[Decode_Day_of_Week($_)] = 1;
132     }
133     foreach ($year->search("")) {
134         my $good=1;
135         #foreach my $x ($year->labels($_)) {
136         #    $good=0 if ($x =~ /Veteran/ or $x =~ /President/);
137         #}
138         next unless ($year->is_full($_) && $_>=$firstday && $_<=$lastday);
139         push @holidays, $_
140             if (defined($days[Day_of_Week($_->date)]) && $good > 0);
141     }
142     return wantarray ? @holidays : "@holidays";
143 }
144
145 sub off_for_exams {
146     my %class = @_;
147     my $time = $class{'begin'} . "-" . $class{'end'};
148     $class{'duration'} =~ /\d{8}-(\d\d\d\d)(\d\d)(\d\d)/;
149     my $lastday = Date::Calc->new($1,$2,$3);
150     return wantarray ? () : undef unless (Day_of_Week($lastday->date) == 7);
151     my $beginning="(08:00-09:15|11:00-12:15|14:00-15:15|17:00-18:15|17:30-18:45|20:00-21:15|20:30-21:45)";
152     my $ending   ="(06:30-07:45|09:30-10:45|12:30-13:45|15:30-16:45|18:30-19:45|19:00-20:15)";
153     my $days = join(" ",map {Decode_Day_of_Week($_)} split(/ /, $class{'days'}));
154     if($days eq "1 3") {
155         if($time =~ /$beginning/) {
156             return $lastday-4;
157         } elsif($time =~ /$ending/) {
158             return $lastday-6;
159         }
160     } elsif($days eq "2 4") {
161         if($time =~ /$beginning/) {
162             return $lastday-3;
163         } elsif($time =~ /$ending/) {
164             return $lastday-5;
165         }
166     } elsif($days eq "5") {
167         return $lastday-2;
168     }
169     return wantarray ? () : "";
170 }
171
172 sub capitalize {
173     local $_ = shift || "";
174     s/ +$//;
175     s/\b([A-Z])([A-Z]*)\b/$1\L$2/g;
176     s/\b(I)(i*)\b/$1\U$2/g;
177     s/\bUs\b/US/g;
178     s/ (And|For|Of|Or|The|To|With) / \l$1 /g;
179     s/\b(Mc)([a-z])/$1\u$2/g;
180     s/\b(Tcp\/Ip|Pc|Tba)\b/\U$&/g;
181     s/\bThru\b/Through/g;
182     s/\bAcct\b/Accounting/g;
183     s/\bAmer\b/American/g;
184     s/\bChem\b/Chemistry/g;
185     s/\bComp\b/Composition/g;
186     s/\bFed\b/Federal/g;
187     s/\bGen\b/General/g;
188     s/\bIntro\b/Introduction/g;
189     s/\bPrgm\b/Programming/g;
190     s/\bOp Sys\b/Operating System/g;
191     #s/\bGovt\b/Government/g;
192     s/\bLit\b/Literature/g;
193     s/\bPrin\b/Principles/g;
194     s/\bBus\b/Business/g;
195     s/\bSyst\b/Sys/g;
196     return $_;
197 }
198
199 sub get_schedule {
200     my $content;
201     if($schedurl =~ /:\/\//) {
202         my $ua = LWP::UserAgent->new;
203         $ua->timeout(10);
204         $ua->env_proxy;
205 #       $ua->cookie_jar( {} );
206         $response = $ua->get("$schedurl") or die "$!";
207         die $response->status_line unless $response->is_success;
208         $content = $response->content;
209     } else {
210         open(F,$schedurl) || die "$!";
211         $content = join ("", <F>);
212         close F;
213     }
214     my $ref = XMLin($content, ForceArray => [ 'class', 'off' ], KeyAttr => "");
215     return @{$ref->{'class'}};
216 }
217
218 sub get_grades {
219     my $content;
220     if($gradeurl =~ /:\/\//) {
221         my $ua = LWP::UserAgent->new;
222         $ua->timeout(10);
223         $ua->env_proxy;
224 #       $ua->cookie_jar( {} );
225         $response = $ua->get("$gradeurl") or die "$!";
226         die $response->status_line unless $response->is_success;
227         $content = $response->content;
228     } else {
229         open(F,$schedurl) || die "$!";
230         $content = join ("", <F>);
231         close F;
232     }
233     my $ref = XMLin($content, ForceArray => [ 'class', 'cumulative' ], KeyAttr => "");
234     return $ref;
235 }
236
237 sub do_html_grades {
238     my ($file, $grades);
239     my @showheaders = ("Section ID", "Course Title", "Grade", "Earned<br />Hours", "Quality<br />Hours", "Quality<br />Points");
240     #$file = shift unless (!defined $_[0] or $_[0] =~ /^\d/);
241     $grades = get_grades(@_);
242     my ($row);
243     my $shade = "dark";
244     print '<table id="grades" cellpadding="3" cellspacing="0">'."\n<tr>";
245     print '<th align="left" class="sectionid">', $showheaders[0];
246     print '</th><th align="left" class="coursetitle">', $showheaders[1];
247     print '</th><th align="center" class="grade">';
248     print join('</th><th align="center" class="right-number">',@showheaders[2 .. 5]);
249     print "</th></tr>\n";
250     foreach my $ts ($grades->{'class'}) {
251         foreach my $row (@$ts) {
252             print '<tr class="'.$shade.'">';
253             $shade = ($shade eq "dark"?"light":"dark");
254             print '<td align="left" class="sectionid">', $row->{'id'}, '</td>';
255             print '<td align="left" class="coursetitle">', $row->{'title'}, '</td>';
256             print '<td align="center" class="grade">';
257             #print join('</td><td>', @$row[0 .. 1]);
258             print join('</td><td align="right" class="right-number">', ($row->{'grade'},$row->{'earned'},$row->{'hours'},$row->{'points'}));
259             print "</td></tr>\n";
260         }
261     }
262     my $lastrow = $grades->{'cumulative'}->[scalar @{$grades->{'cumulative'}}-1];
263     print '<tr class="cumulative '.$shade.'"><td id="cumulative" colspan="2">Cumulative: through ', capitalize($lastrow->{'term'});
264     print '</td><td align="center" id="gpa" class="grade">';
265     print $lastrow->{'gpa'};
266     print '</td><td align="right" class="right-number">';
267     print join('</td><td align="right" class="right-number">', ($lastrow->{'earned'}, $lastrow->{'hours'}, $lastrow->{'points'}));
268     print "</td></tr>\n";
269     print "</table>\n";
270 }
271
272 sub get_faculty_email {
273     my ($name, $school, $email);
274     if((-f $ENV{'HOME'} . "/public_html/faculty.csv") && ! %faculty) {
275         open INS, $ENV{'HOME'} . "/public_html/faculty.csv";
276         while($_ = <INS>) {
277             chomp;
278             m/"([^"]*)",([^,]*),([^,]*)/; # "
279             ($name, $email, $school) = ($1, $2, $3);
280             $name =~ s/ [A-Z]\.//g;
281             $name = lc $name;
282             $name =~ s/\W//g;
283             $faculty{$name} = $email;
284         }
285     }
286     $name = shift;
287     $name =~ s/ [A-Z]r?\.//g;
288     $name = lc $name;
289     $name =~ s/\W//g;
290     return $faculty{$name};
291 }
292
293 sub get_mhc_header {
294 return (
295 "X-SC-Subject: New Years Day\nX-SC-Category: Holiday\nX-SC-Cond: 1 Jan\nX-SC-Duration: 00010101-\nX-SC-Record-Id: <New_Years_Day\@from.sctweb>\n",
296 "X-SC-Subject: Martin Luther King, Jr. Day\nX-SC-Category: Holiday\nX-SC-Cond: 3rd Mon Jan\nX-SC-Duration: 19870119-\nX-SC-Record-Id: <Martin_Luther_King_Jr_Day\@from.sctweb>\n",
297 "X-SC-Subject: Presidents Day\nX-SC-Category: Holiday\nX-SC-Cond: 3rd Mon Feb\nX-SC-Duration: 19710515-\nX-SC-Record-Id: <Presidents_Day\@from.sctweb>\n",
298 "X-SC-Subject: Memorial Day\nX-SC-Category: Holiday\nX-SC-Cond: Last Mon May\nX-SC-Duration: 19710531-\nX-SC-Record-Id: <Memorial_Day\@from.sctweb>\n",
299 "X-SC-Subject: Independence Day\nX-SC-Category: Holiday\nX-SC-Cond: 4 Jul\nX-SC-Duration: 17760704-\nX-SC-Record-Id: <Independence_Day\@from.sctweb>\n",
300 "X-SC-Subject: Labor Day\nX-SC-Category: Holiday\nX-SC-Cond: 1st Mon Sep\nX-SC-Duration: 18840901-\nX-SC-Record-Id: <Labor_Day\@from.sctweb>\n",
301 "X-SC-Subject: Columbus Day\nX-SC-Category: Holiday\nX-SC-Cond: 2nd Mon Oct\nX-SC-Duration: 19711011-\nX-SC-Record-Id: <Columbus_Day\@from.sctweb>\n",
302 "X-SC-Subject: Veterans Day\nX-SC-Category: Holiday\nX-SC-Cond: 11 Nov\nX-SC-Duration: 19261111-\nX-SC-Record-Id: <Veterans_Day\@from.sctweb>\n",
303 "X-SC-Subject: Thanksgiving\nX-SC-Category: Holiday\nX-SC-Cond: 4th Thu Nov\nX-SC-Duration: 14921122-\nX-SC-Record-Id: <Thanksgiving\@from.sctweb>\n",
304 "X-SC-Subject: Christmas\nX-SC-Category: Holiday\nX-SC-Cond: 25 Dec\nX-SC-Duration: 00011225-\nX-SC-Record-Id: <Christmas\@from.sctweb>\n",
305 );
306 }
307
308 sub do_mhc_schedule {
309     $| = 1;
310     my %days = (M => "Mon", T => "Tue", W => "Wed", R => "Thu", F => "Fri", S => "Sat", U => "SU");
311     my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
312     my ($file, $current, @mhc, @schedule);
313     $file = shift unless (!defined $_[0] or $_[0] =~ /^\d/);
314     @schedule = get_schedule(@_);
315     @mhc = get_mhc_header;
316     if(defined($file) && (-d $file)) {
317         my @mhc2;
318         foreach (@mhc) {
319             $_ =~ s/X-SC-Subject: ([^\n]*)/X-SC-Subject: $1\nSubject: $1/;
320             $_ =~ s/X-SC-Category: ([^\n]*)/X-SC-Category: $1\nFrom: $1/;
321             $_ =~ s/X-SC-Duration: (\d\d\d\d)(\d\d)(\d\d)-/"X-SC-Duration: $1$2$3-\nDate: $3 " . $mon[$2-1] . " 1970 12:00:00 +0000"/e;
322             push @mhc2, $_;
323         }
324         @mhc = @mhc2;
325     }
326     foreach my $row (@schedule) {
327         map {s/\n/-/g if defined; $_} %$row;
328         my $id=generate_id($row->{'id'});
329         $row->{'days'} =~ s/([MTWRFS])/ $days{$1}/g;
330         $row->{'days'} =~ s/^ //;
331         #$row->{'duration'} =~ s/(\d\d)-(\d\d)-(\d\d)/20$3$1$2/g;
332         my @day = ();
333         @day = map { "!" . $_ } (@{$row->{'off'}}) if ($row->{'off'});
334         $current = "";
335         #print "# $id\n";
336         $current .= "X-SC-Subject: " . $row->{'title'} . "\n";
337         $current .= "X-SC-Location: " . $row->{'location'} . "\n";
338         $current .= "X-SC-Category: School\n";
339         $current .= "X-SC-Cond: " . $row->{'days'} . "\n";
340         $current .= "X-SC-Time: ".$row->{'begin'}."-".$row->{'end'}."\n";
341         $current .= "X-SC-Duration: " . $row->{'duration'} . "\n";
342         $current .= "X-SC-Day: @day\n" if(exists $day[0]);
343         $current .= "X-SC-Alarm: 15 minutes\n";
344         $current .= "X-SC-Record-Id: <".$row->{'id'}."\@from.sctweb>\n";
345         if(defined($file) && (-d $file)) {
346             my $email = get_faculty_email $row->{'instructor'};
347             $row->{'instructor'} = '"' . $row->{'instructor'} . '" <'. ($email || ($1 || "unknown") . "\@from.sctweb") . ">";
348             $row->{'duration'} =~ /^(\d\d\d\d)(\d\d)(\d\d)-\d{8}$/;
349             $row->{'begin'} =~ /^(\d\d):(\d\d)$/;
350             my $next = next_class(%$row);
351             my @date = Gmtime(Mktime($next->date,$1,$2,0));
352             $current .= sprintf "Date: %s, %2d %s %4d %02d:%02d:00 +0000\n", Day_of_Week_Abbreviation($date[7]), $date[2], $mon[$date[1]-1], $date[0], $date[3], $date[4], $date[5];
353             $current .= "Subject: " . $row->{'title'} . "\n";
354             $current .= "From: " . $row->{'instructor'} . "\n";
355         }
356         #print "\n$current";
357         push @mhc, $current;
358     }
359     if(defined($file) && (-d $file)) {
360         my @lines;
361         foreach my $name (<$file/[1-9]*>) {
362             next unless $name =~ /^$file\/[1-9][0-9]*$/;
363             open FH, $name;
364             @lines = <FH>;
365             close FH;
366             foreach (@lines) {
367                 unlink $name if /^X-SC-Record-Id: <.*\@from.sctweb>/;
368             }
369         }
370         my $i=0;
371         foreach (@mhc) {
372             while(-f ++$i) {}
373             open FH, ">$file/$i" or die $!;
374             print FH $_;
375             close FH;
376         }
377     } else {
378         open(STDOUT, ">" . $file) if(defined($file));
379         print "# MHC school schedule\n# Autogenerated by sctweb ".localtime()."\n\n";
380         print join("\n", @mhc);
381     }
382 }
383
384 sub do_csv_schedule {
385     $| = 1;
386     my %days = (M => "Mon", T => "Tue", W => "Wed", R => "Thu", F => "Fri", S => "Sat", U => "SU");
387     my @mon = qw(Jan. Feb. Mar. Apr. May June July Aug. Sept. Oct. Nov. Dec.);
388     my (@terms, $file, $current, @mhc, @schedule);
389     $file = shift unless (!defined $_[0] or $_[0] =~ /^\d/);
390     @schedule = get_schedule(@_);
391     open(STDOUT, ">" . $file) if(defined($file));
392     foreach my $row (@schedule) {
393         map {s/\n/-/g if defined; $_} %$row;
394         my $id=generate_id($row->{'id'});
395         $row->{'days'} =~ s/([MTWRFS])/ $days{$1}/g;
396         $row->{'days'} =~ s/^ //;
397         my $next = next_class(%$row);
398         $current = "";
399         #print "# $id\n";
400         $current .= $row->{'id'} . ",";
401         $current .= $row->{'title'} . ",";
402         $current .= '"' . $row->{'instructor'} . '",';
403         $next =~ /^(\d\d\d\d)(\d\d)(\d\d)$/;
404         $current .= $1 . "-". $2 ."-" . $3 . "\n";
405         print $current;
406     }
407 }
408
409 sub do_vcalendar_schedule {
410     $| = 1;
411     my %days = (M => "MO", T => "TU", W => "WE", R => "TH", F => "FR", S => "SA", U => "SU");
412     my $file = shift if (defined $_[0] and $_[0] !~ /^\d/);
413     my @schedule = get_schedule(@_);
414     open(STDOUT, ">>" . $file) if(defined($file) && (! -d $file));
415     open(STDOUT, ">/dev/null") if(defined($file) && (-d $file));
416     print "BEGIN:VCALENDAR\r\nVERSION:1.0\r\n";
417     foreach my $row (@schedule) {
418         map { s/\n/-/g; $_} %$row;
419         $row->{'days'} =~ s/([MTWRFS])/ $days{$1}/g;
420         $row->{'days'} =~ s/^ //;
421         my @day = ();
422         @day = @{$row->{'off'}} if ($row->{'off'});
423         my $day = "";
424         if(exists($day[0])) {
425             $day = join(";", @day);
426             $day =~ s/\b(\d{8})\b/$1T000000/g;
427         }
428         my ($starttime, $stoptime)=($row->{'begin'}, $row->{'end'});
429         my ($startdate, $stopdate)=split(/-/, $row->{'duration'});
430         $starttime =~ s/://;
431         $stoptime =~ s/://;
432         if(defined($file) && (-d $file)) {
433             open FH, ">$file/" . $row->{'id'} . ".vcs" or die "$!";
434             select FH;
435             print "BEGIN:VCALENDAR\r\nVERSION:1.0\r\n";
436         }
437         print "BEGIN:VEVENT\r\n";
438         print "SUMMARY:", $row->{'title'}, "\r\n";
439         print "DESCRIPTION:", $row->{'id'}, "\r\n";
440         print "LOCATION:", $row->{'location'}, "\r\n";
441         print "CATEGORIES:Education\r\n";
442         print "DTSTART:", $startdate."T".$starttime, "00\r\n";
443         print "DTEND:", $startdate."T".$stoptime, "00\r\n";
444         print "RRULE:W1 ", $row->{'days'} . " $stopdate", "T000000\r\n";
445         print("EXDATE:$day\r\n") if($day);
446         print "ATTENDEE;ROLE=OWNER;STATUS=CONFIRMED:", $opts{'name'}, "\r\n" if(defined($opts{'name'}));
447         print "ATTENDEE;ROLE=ORGANIZER;STATUS=CONFIRMED:", $row->{'instructor'}, " <" . (get_faculty_email($row->{'instructor'}) || "fake\@ddress"), ">\r\n";
448         print "END:VEVENT\r\n";
449         if(defined($file) && (-d $file)) {
450             print "END:VCALENDAR\r\n";
451             close FH;
452             select STDOUT;
453         }
454     }
455     print "END:VCALENDAR\r\n";
456 }
457
458 sub do_xml_schedule {
459     my $file = shift if (defined $_[0] and $_[0] !~ /^\d/);
460     my $schedule = { class => [ get_schedule(@_) ] };
461     my $xml = XMLout($schedule, NoAttr => 1, RootName => 'schedule');
462     if($file) {
463         open FH, ">$file";
464         print FH $xml;
465         close FH;
466     } else {
467         print $xml;
468     }
469 }
470
471 sub do_html_schedule {
472     my @showheaders = ("Section ID/Title", "Instructor", "Days", "Time", "Duration", "Location");
473     my $shade = "dark";
474     my @schedule = get_schedule(@_);
475     print '<table id="schedule" cellpadding="3" cellspacing="0">'."\n<tr><th>";
476     print join("</th><th>",@showheaders);
477     print "</th></tr>\n";
478         foreach my $row (@schedule) {
479             map { s/\n/<br \/>/g; $_} %$row;
480             #$row->{'time'} =~ s/-/-<wbr \/>/;
481             $row->{'duration'} =~ s/-/<br \/>/g;
482             $row->{'duration'} =~ s/\d\d(\d\d)(\d\d)(\d\d)/$2-$3-$1/g;
483             print '<tr class="'.$shade.'">';
484             $shade = ($shade eq "dark"?"light":"dark");
485             print '<td class="idtitle">';
486             print '<span class="sectionid">' .$row->{'id'}. '</span><br />';
487             print '<span class="coursetitle">' .$row->{'title'}. '</span></td>';
488             my $instructor = $row->{'instructor'};
489             my $email = get_faculty_email($row->{'instructor'});
490             #if($email) {
491                 #print '<td><a href="mailto:' . $email . '">'
492                 #. $row->{'instructor'} . "</a></td>";
493             # } else {
494                 print "<td>" . $row->{'instructor'} . "</td>";
495             #}
496             print "<td>" . $row->{'days'} . "</td>";
497             print "<td>" . $row->{'begin'}."-<wbr />".$row->{'end'} . "</td>";
498             print "<td>" . $row->{'duration'} . "</td>";
499             print "<td>" . $row->{'location'} . "</td>";
500             print "</tr>\n";
501         }
502     print "</table>\n";
503 }
504
505 if ($arg eq "-s" || $arg eq "-h") {
506     do_html_schedule(@ARGV);
507 } elsif ($arg eq "-m") {
508     do_mhc_schedule(@ARGV);
509 } elsif ($arg eq "-c") {
510     do_csv_schedule(@ARGV);
511 } elsif ($arg eq "-v") {
512     do_vcalendar_schedule(@ARGV);
513 } elsif ($arg eq "-x") {
514     do_xml_schedule(@ARGV);
515 } elsif ($arg eq "-g") {
516     do_html_grades(@ARGV);
517 }
518