Grr, freakin' carriage returns...
[tpope-extra.git] / perl / sctweb
index 0381b1dfa0de0e4c9065caf8ed3a6f37f13afa90..2380f31074598f540a57a3845aa1899b2d902ebb 100755 (executable)
@@ -188,7 +188,7 @@ sub off_for_exams {
 }
 
 sub capitalize {
-    local $_ = shift;
+    local $_ = shift || "";
     s/ +$//;
     s/\b([A-Z])([A-Z]*)\b/$1\L$2/g;
     s/\b(I)(i*)\b/$1\U$2/g;
@@ -559,6 +559,7 @@ sub do_html_schedule {
 
 sub do_html_grades {
     my @readheaders = ("Section ID", "Course Title", "Grade", "Earned  Hours", "Quality  Hours", "Quality  Points", "GPA");
+    @readheaders = ("Section", "Course Title", "FinalGrade", "Earned Hours", "Quality Hours", "Quality Points", "GPA") if($opts{'school'} eq 'tamuk');
     my @showheaders = ("Section ID", "Course Title", "Grade", "Earned<br />Hours", "Quality<br />Hours", "Quality<br />Points");
     my ($row, $lastrow);
     my $te = new HTML::TableExtract( headers => [ @readheaders ] );
@@ -567,31 +568,36 @@ sub do_html_grades {
     #my @terms = reverse grep {s/^<option value="([^"]*)">.*/$1/} (split( /\r\n/, $response->content));
     my @terms = ();
     my $year = Date::Calc->localtime->year;
-    for(my $y=$year-4;$y<=$year;$y++) { push @terms, ($y.2,$y.3,$y.4,$y.1); }
+    for(my $y=$year-4;$y<=$year;$y++) { push @terms, ($y.2,$y."F",$y.3,$y.4,$y.1,$y."S"); }
     foreach(@_ ? @_ : @terms) {
        $response = $ua->get("$url&tserve_tip_write=||WID|SID|PIN|Term&tserve_trans_config=rgrades.cfg&Term=".($_) );
        die $response->status_line unless $response->is_success;
        $te->parse($response->content);
     }
     print '<table cellpadding="3" cellspacing="0">'."\n<tr><th>";
-    print join("</th><th>",@showheaders);
+    print $showheaders[0], '</th><th>';
+    print join('</th><th>',@showheaders[1 .. 5]);
     print "</th></tr>\n";
     foreach my $ts ($te->table_states) {
        foreach my $row ($ts->rows) {
-           map { s/\xa0//g; s/\n/<br \/>/g; $_} @$row;
+           map { s/^\s+//; s/\xa0|\r//g; s/\n/<br \/>/g; $_} @$row;
            $row->[1] = capitalize($row->[1]);
+           $row->[1] =~ s/&/&amp;/g;
            $lastrow=$row;
-           next if $row->[0] =~ /:/;
+           next if $row->[0] =~ /:|Current Term|Cumulative/;
            print '<tr><td>';
-           print join('</td><td>', @$row[0 .. 5]);
+           print $$row[0], '</td><td>', $$row[1], '</td>';
+           print '<td align="center">';
+           #print join('</td><td>', @$row[0 .. 1]);
+           print join('</td><td>', @$row[2 .. 5]);
            print "</td></tr>\n";
        }
     }
     print '<tr><td colspan="2">', capitalize($lastrow->[0]);
     #shift @$lastrow; shift @$lastrow;
-    print "</td><td>";
+    print '</td><td align="center">';
     print $$lastrow[6];
-    print "</td><td>";
+    print '</td><td>';
     print join('</td><td>', @$lastrow[3 .. 5]);
     print "</td></tr>\n";
     print "</table>\n";