Courses
Fall 2004
#!/usr/bin/perl
#
# Program..: class_listing_post_s03.pls
# Date.....: 01 August 2003
# Notice...: Copyright (c) 2003, Educational Technology Center, Bowdoin College
# Notes....: Modified by Danny Ginn to use Apache:Request(), XML::LibXML, and the new (7/03) data feed from Telos, got rid of serialization as well.
# This program recieves added $semester to course catalog, necessitating ln in course catalog for spring semester
#
# CVS information
#
my $cvs_lastedit = '$Author: dginn $';
my $cvs_revdate = '$Date: 2003/08/12 16:02:14 $';
my $cvs_revision = '$Revison: $';
my $cvs_id = '$ID';
# Externals
#
#use diagnostics;
use strict;
use Apache::Request;
use XML::LibXML;
# Initialize the mod_perl object
#
my $apr = Apache::Request->new(shift);
my $dept_code = $apr->param('dept_code');
my $semester = $apr->param('semester');
my $request_uri = $ENV{'REQUEST_URI'};
my $http_referer = $ENV{'HTTP_REFERER'};
my $useragent = $ENV{'HTTP_USER_AGENT'};
my $ip_address = $ENV{'REMOTE_ADDR'};
my $dept_dir;
if ($request_uri =~ m{/(.*)/(.*)/(.*)}) {
$dept_dir = $1;
}
&update_came_from_info($ip_address, $useragent, $dept_dir);
print "Content-type:text/html\n\n";
&update_info($semester, $dept_code);
#-- update_info() ---------------------------------------------------------------------------------
#
sub update_info
{
my ($semester, $dept_code) = @_;
my $file = "classeslong".$dept_code.".xml";
my $class_info;
if (-f "/www-base/production/acad/docs/meta_data/classes/$semester/$file") {
$class_info = &student_rec_info($semester, $dept_code);
# $class_info = &student_rec_info($dept_code);
}
my $dept_shortname = lookup_shortname($dept_code);
foreach my $keys (sort keys %{$class_info}){
my $title = catalog_info($semester, $dept_code, $keys);
print qq{
| $keys
$title |
};
foreach my $element (@{$class_info->{$keys}}){
print qq{$element\n};
}
}
print qq{
};
if(-r "/www-base/production/acad/docs/meta_data/valid_courses/$semester/$dept_code"){
open G, "/www-base/production/acad/docs/meta_data/valid_courses/$semester/$dept_code";
while(
) {
print qq{$_};
}
close G;
}
}
#-- student_rec_info() ----------------------------------------------------------------------------
#
sub student_rec_info
{
my ($semester, $dept_code) = @_;
# my $dept_code) = shift;
my $file = "classeslong".$dept_code.".xml";
my $parser = XML::LibXML->new();
my $class_info = {};
my $doc = $parser->parse_file("/www-base/production/acad/docs/meta_data/classes/$semester/$file");
my @nodes = $doc->findnodes("//classes/class");
my %distribution;
foreach my $node (@nodes){
my $class_id = $node->findvalue('classID');
my $class_number = substr($class_id,3,3);
my $section_data; # string which will hold all the information, ready to print to HTML, for each class
# then stored in an array which will be interated through all at once.
# Check to see if it has a lab.
#
if (substr($class_id,6,1) eq "L"){
$section_data.=qq{\n| L}.substr($class_id,7,1).qq{ | };
}
elsif (substr($class_id,6,1) ne " "){
$section_data.=qq{
\n| }.substr($class_id,6,1).qq{ | };
}
else{
$section_data .= qq{
\n| | };
}
# Find the class times
#
my @days = $node->findnodes('classTime');
my @classtimes;
my ($start_time, $end_time);
foreach my $day (@days){
$start_time = $day->findvalue('startTime');
$end_time = $day->findvalue('endTime');
my $class_day = $day->findvalue('dayOfWeek');
push @classtimes, $class_day;
}
$section_data .= qq{\n}.join(',', @classtimes);
$section_data .= " ".$start_time."-".$end_time.qq{ | };
# Finds instructors
#
my @nodess = $node->findnodes("instructor");
my @instructors_info = ();
foreach my $an_instructor (@nodess){
my $first_name = $an_instructor->findvalue('name/nam/first');
my $last_name = $an_instructor->findvalue('name/nam/last');
my $middle_name = $an_instructor->findvalue('name/nam/middle');
# my $instructor_name = $last_name.", ".$first_name;
my $instructor_name = $an_instructor->findvalue('name/preferred');
my $email = $an_instructor->findvalue('email');
my @email_uid = split(/\@/, $email);
my $instructor_uid = $email_uid[0];
my @xf = split(//, $instructor_uid);
my $first_letter = uc($xf[0]);
my $instructor_href = qq{$instructor_name};
push @instructors_info, $instructor_href;
}
my $class_instructor = join(',
',@instructors_info);
$section_data .= qq{\n}.$class_instructor.qq{ | };
$section_data .= qq{\n}.$node->findvalue('location').qq{ | \n
};
# Puts all the class information into an array whos name is.
#
push @{$class_info->{$class_number}}, $section_data;
} # End foreach
return $class_info;
}
#-- catalog_info() --------------------------------------------------------------------------------
#
sub catalog_info
{
my ($semester, $dept_code, $course_number) = @_;
my $parser = XML::LibXML->new();
my $doc = $parser->parse_file("/www-base/production/acad/docs/course_catalog/$semester/$dept_code.xml");
my $xpath_query = qq{/child::department/course[child::course_number='$course_number']};
my (@nodeset) = $doc->findnodes($xpath_query);
my $title;
foreach my $node (@nodeset){
$title = $node->findvalue('title');
}
return $title;
}
#-- lookup_shortname() ----------------------------------------------------------------------------
#
sub lookup_shortname
{
my $xkey = shift;
my $department_shortname;
open XF, "/www-base/production/acad/docs/meta_data/depts_list.txt";
while (){
chomp;
my @xfields = split /:/;
if ($xfields[0] eq $xkey){
$department_shortname = $xfields[1];
}
}
close XF;
return $department_shortname;
}
#-- update_came_from_info() -----------------------------------------------------------------------
#
sub update_came_from_info{
my ($ip_address, $useragent, $dept_dir) = @_;
my $time_now = time();
use DBI;
my $dsn = "DBI:mysql:database=session_manager;";
my $dbh = DBI->connect($dsn, 'session', 'ettfsession');
my $ip = $dbh->quote($ip_address);
my $ua = $dbh->quote($useragent);
my $dir = $dbh->quote($dept_dir);
my $time = $dbh->quote($time_now);
$dbh->do(qq{INSERT INTO session VALUES($ip,$ua,$dir,$time)});
$dbh->disconnect;
}
#-- update_camefrom_into() ------------------------------------------------------------------------
#
sub update_camefrom_info {
my $time_now = time();
open X, ">>/www/tmp/camefrom";
#print X "$ip_address|$useragent|$dept_dir|$time_now\n";
close X;
}
Other Semester's Courses
Past Semesters