#!/usr/local/bin/perl -T
#
# csyllabus.pl
#
# Script for fetching a curse syllabus ("kursplan").
#
use strict;
#use DBI;


print "content-type: text/html\n\n";

my $course_code = $ENV{courseCode} || '';
#TEST:
# $course_code = 'TDDC76';

unless ($course_code || $course_code !~ /^([A-Z]{4}|\d{3}[AG])\d\d$/i) {
    print "<!-- Environment variable 'courseCode' is not definied or wrong format -->\n";
}

my $PAGE_LANG = $ENV{pageLang} || 'sv';


# Someone really made the wrong design decision with these links!

my $template_programme_sv = 'https://liu.se/studieinfo/programkurs/!COURSECODE!';
my $template_programme_en = 'https://liu.se/en/studieinfo/programkurs/!COURSECODE!';
my $template_course_sv = 'https://liu.se/studieinfo/kurs/!COURSECODE!';
my $template_course_en = 'https://liu.se/en/studieinfo/kurs/!COURSECODE!';

# First version, simply assume that all our TFK courses are programme courses

my $is_programme = ( $course_code =~ m/^T/ );

if ($PAGE_LANG eq 'sv') {
    my $location = $template_course_sv;
    $location =~ s/!COURSECODE!/lc($course_code)/e;
    print "<p>\nV.g. se <a href=\"$location\">LiU:s studieinformation</a>.\n</p>\n\n";
}
else {
    my $location = $template_course_en;
    $location =~ s/!COURSECODE!/lc($course_code)/e;
    print "<p>\nPlease, see <a href=\"$location\">LiU Study Guide</a>.\n</p>\n\n";
}
exit;

__END__
