Removed debug statement
[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         next if(grep($_ == "$today", @off));
109         return $today;
110     }
111     $today = Date::Calc->new(Date::Calc->gmtime->date);
112     for($today = ($today < $lastday ? $today : $lastday); $today > $firstday; $today--) {
113         next unless(grep($_ == Day_of_Week($today->date), @days));
114         next if(grep($_ == "$today", @off));
115         return $today;
116     }
117     return undef;
118 }
119
120 sub off_for_holidays {
121     my %class = @_;
122     $class{'duration'} =~ /(\d\d\d\d)(\d\d)(\d\d)-(\d\d\d\d)(\d\d)(\d\d)/;
123     my $days = Delta_Days($1,$2,$3,$4,$5,$6);
124     my $firstday = Date::Calc->new($1,$2,$3);
125     my $lastday = Date::Calc->new($4,$5,$6);
126     my $year = Date::Calendar::Year->new($1, $opts{'holidays'});
127     my @holidays=();
128     my @days=();
129     foreach(split(" ",$class{days})) {
130         $days[Decode_Day_of_Week($_)] = 1;
131     }
132     foreach ($year->search("")) {
133         my $good=1;
134         #foreach my $x ($year->labels($_)) {
135         #    $good=0 if ($x =~ /Veteran/ or $x =~ /President/);
136         #}
137         next unless ($year->is_full($_) && $_>=$firstday && $_<=$lastday);
138         push @holidays, $_
139             if (defined($days[Day_of_Week($_->date)]) && $good > 0);
140     }
141     return wantarray ? @holidays : "@holidays";
142 }
143
144 sub off_for_exams {
145     my %class = @_;
146     my $time = $class{'begin'} . "-" . $class{'end'};
147     $class{'duration'} =~ /\d{8}-(\d\d\d\d)(\d\d)(\d\d)/;
148     my $lastday = Date::Calc->new($1,$2,$3);
149     return wantarray ? () : undef unless (Day_of_Week($lastday->date) == 7);
150     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)";
151     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)";
152     my $days = join(" ",map {Decode_Day_of_Week($_)} split(/ /, $class{'days'}));
153     if($days eq "1 3") {
154         if($time =~ /$beginning/) {
155             return $lastday-4;
156         } elsif($time =~ /$ending/) {
157             return $lastday-6;
158         }
159     } elsif($days eq "2 4") {
160         if($time =~ /$beginning/) {
161             return $lastday-3;
162         } elsif($time =~ /$ending/) {
163             return $lastday-5;
164         }
165     } elsif($days eq "5") {
166         return $lastday-2;
167     }
168     return wantarray ? () : "";
169 }
170
171 sub capitalize {
172     local $_ = shift || "";
173     s/ +$//;
174     s/\b([A-Z])([A-Z]*)\b/$1\L$2/g;
175     s/\b(I)(i*)\b/$1\U$2/g;
176     s/\bUs\b/US/g;
177     s/ (And|For|Of|Or|The|To|With) / \l$1 /g;
178     s/\b(Mc)([a-z])/$1\u$2/g;
179     s/\b(Tcp\/Ip|Pc|Tba)\b/\U$&/g;
180     s/\bThru\b/Through/g;
181     s/\bAcct\b/Accounting/g;
182     s/\bAmer\b/American/g;
183     s/\bChem\b/Chemistry/g;
184     s/\bComp\b/Composition/g;
185     s/\bFed\b/Federal/g;
186     s/\bGen\b/General/g;
187     s/\bIntro\b/Introduction/g;
188     s/\bPrgm\b/Programming/g;
189     s/\bOp Sys\b/Operating System/g;
190     #s/\bGovt\b/Government/g;
191     s/\bLit\b/Literature/g;
192     s/\bPrin\b/Principles/g;
193     s/\bBus\b/Business/g;
194     s/\bSyst\b/Sys/g;
195     return $_;
196 }
197
198 sub get_schedule {
199     my $content;
200     if($schedurl =~ /:\/\//) {
201         my $ua = LWP::UserAgent->new;
202         $ua->timeout(10);
203         $ua->env_proxy;
204 #       $ua->cookie_jar( {} );
205         $response = $ua->get("$schedurl") or die "$!";
206         die $response->status_line unless $response->is_success;
207         $content = $response->content;
208     } else {
209         open(F,$schedurl) || die "$!";
210         $content = join ("", <F>);
211         close F;
212     }
213     my $ref = XMLin($content, ForceArray => [ 'class', 'off' ], KeyAttr => "");
214     return @{$ref->{'class'}};
215 }
216
217 sub get_grades {
218     my $content;
219     if($gradeurl =~ /:\/\//) {
220         my $ua = LWP::UserAgent->new;
221         $ua->timeout(10);
222         $ua->env_proxy;
223 #       $ua->cookie_jar( {} );
224         $response = $ua->get("$gradeurl") or die "$!";
225         die $response->status_line unless $response->is_success;
226         $content = $response->content;
227     } else {
228         open(F,$schedurl) || die "$!";
229         $content = join ("", <F>);
230         close F;
231     }
232     my $ref = XMLin($content, ForceArray => [ 'class', 'cumulative' ], KeyAttr => "");
233     return $ref;
234 }
235
236 sub do_html_grades {
237     my ($file, $grades);
238     my @showheaders = ("Section ID", "Course Title", "Grade", "Earned<br />Hours", "Quality<br />Hours", "Quality<br />Points");
239     #$file = shift unless (!defined $_[0] or $_[0] =~ /^\d/);
240     $grades = get_grades(@_);
241     my ($row);
242     my $shade = "dark";
243     print '<table id="grades" cellpadding="3" cellspacing="0">'."\n<tr>";
244     print '<th align="left" class="sectionid">', $showheaders[0];
245     print '</th><th align="left" class="coursetitle">', $showheaders[1];
246     print '</th><th align="center" class="grade">';
247     print join('</th><th align="center" class="right-number">',@showheaders[2 .. 5]);
248     print "</th></tr>\n";
249     foreach my $ts ($grades->{'class'}) {
250         foreach my $row (@$ts) {
251             print '<tr class="'.$shade.'">';
252             $shade = ($shade eq "dark"?"light":"dark");
253             print '<td align="left" class="sectionid">', $row->{'id'}, '</td>';
254             print '<td align="left" class="coursetitle">', $row->{'title'}, '</td>';
255             print '<td align="center" class="grade">';
256             #print join('</td><td>', @$row[0 .. 1]);
257             print join('</td><td align="right" class="right-number">', ($row->{'grade'},$row->{'earned'},$row->{'hours'},$row->{'points'}));
258             print "</td></tr>\n";
259         }
260     }
261     my $lastrow = $grades->{'cumulative'}->[scalar @{$grades->{'cumulative'}}-1];
262     print '<tr class="cumulative '.$shade.'"><td id="cumulative" colspan="2">Cumulative: through ', capitalize($lastrow->{'term'});
263     print '</td><td align="center" id="gpa" class="grade">';
264     print $lastrow->{'gpa'};
265     print '</td><td align="right" class="right-number">';
266     print join('</td><td align="right" class="right-number">', ($lastrow->{'earned'}, $lastrow->{'hours'}, $lastrow->{'points'}));
267     print "</td></tr>\n";
268     print "</table>\n";
269 }
270
271 sub get_faculty_email {
272     my ($name, $school, $email);
273     if((-f $ENV{'HOME'} . "/public_html/faculty.csv") && ! %faculty) {
274         open INS, $ENV{'HOME'} . "/public_html/faculty.csv";
275         while($_ = <INS>) {
276             chomp;
277             m/"([^"]*)",([^,]*),([^,]*)/; # "
278             ($name, $email, $school) = ($1, $2, $3);
279             $name =~ s/ [A-Z]\.//g;
280             $name = lc $name;
281             $name =~ s/\W//g;
282             $faculty{$name} = $email;
283         }
284     }
285     $name = shift;
286     $name =~ s/ [A-Z]r?\.//g;
287     $name = lc $name;
288     $name =~ s/\W//g;
289     return $faculty{$name};
290 }
291
292 sub get_mhc_header {
293 return (
294 "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",
295 "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",
296 "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",
297 "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",
298 "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",
299 "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",
300 "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",
301 "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",
302 "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",
303 "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",
304 );
305 }
306
307 sub do_mhc_schedule {
308     $| = 1;
309     my %days = (M => "Mon", T => "Tue", W => "Wed", R => "Thu", F => "Fri", S => "Sat", U => "SU");
310     my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
311     my ($file, $current, @mhc, @schedule);
312     $file = shift unless (!defined $_[0] or $_[0] =~ /^\d/);
313     @schedule = get_schedule(@_);
314     @mhc = get_mhc_header;
315     if(defined($file) && (-d $file)) {
316         my @mhc2;
317         foreach (@mhc) {
318             $_ =~ s/X-SC-Subject: ([^\n]*)/X-SC-Subject: $1\nSubject: $1/;
319             $_ =~ s/X-SC-Category: ([^\n]*)/X-SC-Category: $1\nFrom: $1/;
320             $_ =~ 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;
321             push @mhc2, $_;
322         }
323         @mhc = @mhc2;
324     }
325     foreach my $row (@schedule) {
326         map {s/\n/-/g if defined; $_} %$row;
327         my $id=generate_id($row->{'id'});
328         $row->{'days'} =~ s/([MTWRFS])/ $days{$1}/g;
329         $row->{'days'} =~ s/^ //;
330         #$row->{'duration'} =~ s/(\d\d)-(\d\d)-(\d\d)/20$3$1$2/g;
331         my @day = ();
332         @day = map { "!" . $_ } (@{$row->{'off'}}) if ($row->{'off'});
333         $current = "";
334         #print "# $id\n";
335         $current .= "X-SC-Subject: " . $row->{'title'} . "\n";
336         $current .= "X-SC-Location: " . $row->{'location'} . "\n";
337         $current .= "X-SC-Category: School\n";
338         $current .= "X-SC-Cond: " . $row->{'days'} . "\n";
339         $current .= "X-SC-Time: ".$row->{'begin'}."-".$row->{'end'}."\n";
340         $current .= "X-SC-Duration: " . $row->{'duration'} . "\n";
341         $current .= "X-SC-Day: @day\n" if(exists $day[0]);
342         $current .= "X-SC-Alarm: 15 minutes\n";
343         $current .= "X-SC-Record-Id: <".$row->{'id'}."\@from.sctweb>\n";
344         if(defined($file) && (-d $file)) {
345             my $email = get_faculty_email $row->{'instructor'};
346             $row->{'instructor'} = '"' . $row->{'instructor'} . '" <'. ($email || ($1 || "unknown") . "\@from.sctweb") . ">";
347             $row->{'duration'} =~ /^(\d\d\d\d)(\d\d)(\d\d)-\d{8}$/;
348             $row->{'begin'} =~ /^(\d\d):(\d\d)$/;
349             my $next = next_class(%$row);
350             my @date = Gmtime(Mktime($next->date,$1,$2,0));
351             $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];
352             $current .= "Subject: " . $row->{'title'} . "\n";
353             $current .= "From: " . $row->{'instructor'} . "\n";
354         }
355         #print "\n$current";
356         push @mhc, $current;
357     }
358     if(defined($file) && (-d $file)) {
359         my @lines;
360         foreach my $name (<$file/[1-9]*>) {
361             next unless $name =~ /^$file\/[1-9][0-9]*$/;
362             open FH, $name;
363             @lines = <FH>;
364             close FH;
365             foreach (@lines) {
366                 unlink $name if /^X-SC-Record-Id: <.*\@from.sctweb>/;
367             }
368         }
369         my $i=0;
370         foreach (@mhc) {
371             while(-f ++$i) {}
372             open FH, ">$file/$i" or die $!;
373             print FH $_;
374             close FH;
375         }
376     } else {
377         open(STDOUT, ">" . $file) if(defined($file));
378         print "# MHC school schedule\n# Autogenerated by sctweb ".localtime()."\n\n";
379         print join("\n", @mhc);
380     }
381 }
382
383 sub do_csv_schedule {
384     $| = 1;
385     my %days = (M => "Mon", T => "Tue", W => "Wed", R => "Thu", F => "Fri", S => "Sat", U => "SU");
386     my @mon = qw(Jan. Feb. Mar. Apr. May June July Aug. Sept. Oct. Nov. Dec.);
387     my (@terms, $file, $current, @mhc, @schedule);
388     $file = shift unless (!defined $_[0] or $_[0] =~ /^\d/);
389     @schedule = get_schedule(@_);
390     open(STDOUT, ">" . $file) if(defined($file));
391     foreach my $row (@schedule) {
392         map {s/\n/-/g if defined; $_} %$row;
393         my $id=generate_id($row->{'id'});
394         $row->{'days'} =~ s/([MTWRFS])/ $days{$1}/g;
395         $row->{'days'} =~ s/^ //;
396         my $next = next_class(%$row);
397         $current = "";
398         #print "# $id\n";
399         $current .= $row->{'id'} . ",";
400         $current .= $row->{'title'} . ",";
401         $current .= '"' . $row->{'instructor'} . '",';
402         $next =~ /^(\d\d\d\d)(\d\d)(\d\d)$/;
403         $current .= $1 . "-". $2 ."-" . $3 . "\n";
404         print $current;
405     }
406 }
407
408 sub do_vcalendar_schedule {
409     $| = 1;
410     my %days = (M => "MO", T => "TU", W => "WE", R => "TH", F => "FR", S => "SA", U => "SU");
411     my $file = shift if (defined $_[0] and $_[0] !~ /^\d/);
412     my @schedule = get_schedule(@_);
413     open(STDOUT, ">>" . $file) if(defined($file) && (! -d $file));
414     open(STDOUT, ">/dev/null") if(defined($file) && (-d $file));
415     print "BEGIN:VCALENDAR\r\nVERSION:1.0\r\n";
416     foreach my $row (@schedule) {
417         map { s/\n/-/g; $_} %$row;
418         $row->{'days'} =~ s/([MTWRFS])/ $days{$1}/g;
419         $row->{'days'} =~ s/^ //;
420         my @day = ();
421         @day = @{$row->{'off'}} if ($row->{'off'});
422         my $day = "";
423         if(exists($day[0])) {
424             $day = join(";", @day);
425             $day =~ s/\b(\d{8})\b/$1T000000/g;
426         }
427         my ($starttime, $stoptime)=($row->{'begin'}, $row->{'end'});
428         my ($startdate, $stopdate)=split(/-/, $row->{'duration'});
429         $starttime =~ s/://;
430         $stoptime =~ s/://;
431         if(defined($file) && (-d $file)) {
432             open FH, ">$file/" . $row->{'id'} . ".vcs" or die "$!";
433             select FH;
434             print "BEGIN:VCALENDAR\r\nVERSION:1.0\r\n";
435         }
436         print "BEGIN:VEVENT\r\n";
437         print "SUMMARY:", $row->{'title'}, "\r\n";
438         print "DESCRIPTION:", $row->{'id'}, "\r\n";
439         print "LOCATION:", $row->{'location'}, "\r\n";
440         print "CATEGORIES:Education\r\n";
441         print "DTSTART:", $startdate."T".$starttime, "00\r\n";
442         print "DTEND:", $startdate."T".$stoptime, "00\r\n";
443         print "RRULE:W1 ", $row->{'days'} . " $stopdate", "T000000\r\n";
444         print("EXDATE:$day\r\n") if($day);
445         print "ATTENDEE;ROLE=OWNER;STATUS=CONFIRMED:", $opts{'name'}, "\r\n" if(defined($opts{'name'}));
446         print "ATTENDEE;ROLE=ORGANIZER;STATUS=CONFIRMED:", $row->{'instructor'}, " <" . (get_faculty_email($row->{'instructor'}) || "fake\@ddress"), ">\r\n";
447         print "END:VEVENT\r\n";
448         if(defined($file) && (-d $file)) {
449             print "END:VCALENDAR\r\n";
450             close FH;
451             select STDOUT;
452         }
453     }
454     print "END:VCALENDAR\r\n";
455 }
456
457 sub do_xml_schedule {
458     my $file = shift if (defined $_[0] and $_[0] !~ /^\d/);
459     my $schedule = { class => [ get_schedule(@_) ] };
460     my $xml = XMLout($schedule, NoAttr => 1, RootName => 'schedule');
461     if($file) {
462         open FH, ">$file";
463         print FH $xml;
464         close FH;
465     } else {
466         print $xml;
467     }
468 }
469
470 sub do_html_schedule {
471     my @showheaders = ("Section ID/Title", "Instructor", "Days", "Time", "Duration", "Location");
472     my $shade = "dark";
473     my @schedule = get_schedule(@_);
474     print '<table id="schedule" cellpadding="3" cellspacing="0">'."\n<tr><th>";
475     print join("</th><th>",@showheaders);
476     print "</th></tr>\n";
477         foreach my $row (@schedule) {
478             map { s/\n/<br \/>/g; $_} %$row;
479             #$row->{'time'} =~ s/-/-<wbr \/>/;
480             $row->{'duration'} =~ s/-/<br \/>/g;
481             $row->{'duration'} =~ s/\d\d(\d\d)(\d\d)(\d\d)/$2-$3-$1/g;
482             print '<tr class="'.$shade.'">';
483             $shade = ($shade eq "dark"?"light":"dark");
484             print '<td class="idtitle">';
485             print '<span class="sectionid">' .$row->{'id'}. '</span><br />';
486             print '<span class="coursetitle">' .$row->{'title'}. '</span></td>';
487             my $instructor = $row->{'instructor'};
488             my $email = get_faculty_email($row->{'instructor'});
489             #if($email) {
490                 #print '<td><a href="mailto:' . $email . '">'
491                 #. $row->{'instructor'} . "</a></td>";
492             # } else {
493                 print "<td>" . $row->{'instructor'} . "</td>";
494             #}
495             print "<td>" . $row->{'days'} . "</td>";
496             print "<td>" . $row->{'begin'}."-<wbr />".$row->{'end'} . "</td>";
497             print "<td>" . $row->{'duration'} . "</td>";
498             print "<td>" . $row->{'location'} . "</td>";
499             print "</tr>\n";
500         }
501     print "</table>\n";
502 }
503
504 if ($arg eq "-s" || $arg eq "-h") {
505     do_html_schedule(@ARGV);
506 } elsif ($arg eq "-m") {
507     do_mhc_schedule(@ARGV);
508 } elsif ($arg eq "-c") {
509     do_csv_schedule(@ARGV);
510 } elsif ($arg eq "-v") {
511     do_vcalendar_schedule(@ARGV);
512 } elsif ($arg eq "-x") {
513     do_xml_schedule(@ARGV);
514 } elsif ($arg eq "-g") {
515     do_html_grades(@ARGV);
516 }
517