| … | |
… | |
| 57 | # alllll over the place. |
57 | # alllll over the place. |
| 58 | unless (substr($current_uri,-1) eq '/') { |
58 | unless (substr($current_uri,-1) eq '/') { |
| 59 | $r->header_out(Location => "$current_uri/" . ($args ? "?$args" : "")); |
59 | $r->header_out(Location => "$current_uri/" . ($args ? "?$args" : "")); |
| 60 | return REDIRECT; |
60 | return REDIRECT; |
| 61 | # *** any post data gets lost here -- fix that. |
61 | # *** any post data gets lost here -- fix that. |
|
|
62 | # (actually, it's not a problem, since all URLs generated |
|
|
63 | # from within the system have trailing slashes, and we don't |
|
|
64 | # need POST data from outside the system anyway!) |
| 62 | } |
65 | } |
| 63 | |
66 | |
| 64 | # Create the @components array, which contains the path specified in the URL |
67 | # Create the @components array, which contains the path specified in the URL |
| 65 | my($junk, @components) = split "/", $path_info; |
68 | my($junk, @components) = split "/", $path_info; |
| 66 | my $webwork_root = $r->dir_config('webwork_root'); # From a PerlSetVar in httpd.conf |
69 | my $webwork_root = $r->dir_config('webwork_root'); # From a PerlSetVar in httpd.conf |
| … | |
… | |
| 68 | my $course = shift @components; |
71 | my $course = shift @components; |
| 69 | |
72 | |
| 70 | # Try to get the course environment. |
73 | # Try to get the course environment. |
| 71 | my $ce = eval {WeBWorK::CourseEnvironment->new($webwork_root, $urlRoot, $pg_root, $course);}; |
74 | my $ce = eval {WeBWorK::CourseEnvironment->new($webwork_root, $urlRoot, $pg_root, $course);}; |
| 72 | if ($@) { # If there was an error getting the requested course |
75 | if ($@) { # If there was an error getting the requested course |
| 73 | # TODO: display an error page. For now, 404 it. |
76 | die "Failed to read course environment for $course: $@"; |
| 74 | warn $@; |
|
|
| 75 | return DECLINED; |
|
|
| 76 | } |
77 | } |
| 77 | |
78 | |
| 78 | # If no course was specified, redirect to the home URL |
79 | # If no course was specified, redirect to the home URL |
| 79 | unless (defined $course) { |
80 | unless (defined $course) { |
| 80 | $r->header_out(Location => $ce->{webworkURLs}->{home}); |
81 | $r->header_out(Location => $ce->{webworkURLs}->{home}); |
| 81 | return REDIRECT; |
82 | return REDIRECT; |
| 82 | } |
83 | } |
| 83 | |
84 | |
| 84 | # Freak out if the requested course doesn't exist. For now, this is just a |
85 | # Freak out if the requested course doesn't exist. For now, this is just a |
| 85 | # check to see if the course directory exists. |
86 | # check to see if the course directory exists. |
| 86 | if (!-e $ce->{webworkDirs}->{courses} . "/$course") { |
87 | my $courseDir = $ce->{webworkDirs}->{courses} . "/$course"; |
| 87 | warn "Course directory for $course not found at " |
88 | unless (-e $courseDir) { |
| 88 | . $ce->{webworkDirs}->{courses} . "/$course" ."\n"; |
89 | die "Course directory for $course ($courseDir) not found. Perhaps the course does not exist?"; |
| 89 | return DECLINED; |
|
|
| 90 | } |
90 | } |
| 91 | |
91 | |
| 92 | # Bring up a connection to the database (for Authen/Authz, and eventually |
92 | # Bring up a connection to the database (for Authen/Authz, and eventually |
| 93 | # to be passed to content generators, when we clean this file up). |
93 | # to be passed to content generators, when we clean this file up). |
| 94 | my $db = WeBWorK::DB->new($ce); |
94 | my $db = WeBWorK::DB->new($ce); |