[system] / branches / ghe3_dev / webwork2 / lib / WeBWorK.pm Repository:
ViewVC logotype

Diff of /branches/ghe3_dev/webwork2/lib/WeBWorK.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2433 Revision 2434
36 36
37BEGIN { $main::VERSION = "2.0"; } 37BEGIN { $main::VERSION = "2.0"; }
38 38
39use strict; 39use strict;
40use warnings; 40use warnings;
41use Apache::Constants qw(:common :http REDIRECT DONE); 41use Apache::Constants qw(:common REDIRECT DONE);
42 42
43# load WeBWorK::Constants before anything else 43# load WeBWorK::Constants before anything else
44# this sets package variables in several packages 44# this sets package variables in several packages
45use WeBWorK::Constants; 45use WeBWorK::Constants;
46 46
56use WeBWorK::URLPath; 56use WeBWorK::URLPath;
57use WeBWorK::Utils qw(runtime_use); 57use WeBWorK::Utils qw(runtime_use);
58 58
59use constant AUTHEN_MODULE => "WeBWorK::ContentGenerator::Login"; 59use constant AUTHEN_MODULE => "WeBWorK::ContentGenerator::Login";
60use constant FIXDB_MODULE => "WeBWorK::ContentGenerator::FixDB"; 60use constant FIXDB_MODULE => "WeBWorK::ContentGenerator::FixDB";
61use constant ERROR_MODULE => "WeBWorK::ContentGenerator::Error";
62 61
63sub dispatch($) { 62sub dispatch($) {
64 my ($apache) = @_; 63 my ($apache) = @_;
65 my $r = new WeBWorK::Request $apache; 64 my $r = new WeBWorK::Request $apache;
66 65
111 my $urlPath = WeBWorK::URLPath->newFromPath($path); 110 my $urlPath = WeBWorK::URLPath->newFromPath($path);
112 debug("-------------------- call to WeBWorK::URLPath::newFromPath\n"); 111 debug("-------------------- call to WeBWorK::URLPath::newFromPath\n");
113 112
114 unless ($urlPath) { 113 unless ($urlPath) {
115 debug("This path is invalid... see you later!\n"); 114 debug("This path is invalid... see you later!\n");
116 return DECLINED; 115 die "The path '$path' is not valid.\n";
117 } 116 }
118 117
119 my $displayModule = $urlPath->module; 118 my $displayModule = $urlPath->module;
120 my %displayArgs = $urlPath->args; 119 my %displayArgs = $urlPath->args;
121 120
122 debug("The display module for this path is: $displayModule\n"); 121 debug("The display module for this path is: $displayModule\n");
123 debug("...and here are the arguments we'll pass to it:\n"); 122 debug("...and here are the arguments we'll pass to it:\n");
124 foreach my $key (keys %displayArgs) { 123 foreach my $key (keys %displayArgs) {
125 debug("\t$key => $displayArgs{$key}\n"); 124 debug("\t$key => $displayArgs{$key}\n");
126 } 125 }
127 126
128 unless ($displayModule) { 127 unless ($displayModule) {
129 debug("The display module is empty, so we can DECLINE here.\n"); 128 debug("The display module is empty, so we can DECLINE here.\n");
130 return DECLINED; 129 die "No display module found for this path.";
131 } 130 }
132 131
133 my $selfPath = $urlPath->path; 132 my $selfPath = $urlPath->path;
134 my $parent = $urlPath->parent; 133 my $parent = $urlPath->parent;
135 my $parentPath = $parent ? $parent->path : "<no parent>"; 134 my $parentPath = $parent ? $parent->path : "<no parent>";
169 168
170 debug("We need to get a course environment (with or without a courseID!)\n"); 169 debug("We need to get a course environment (with or without a courseID!)\n");
171 my $ce = new WeBWorK::CourseEnvironment($webwork_root, $location, $pg_root, $displayArgs{courseID}); 170 my $ce = new WeBWorK::CourseEnvironment($webwork_root, $location, $pg_root, $displayArgs{courseID});
172 debug("Here's the course environment: $ce\n"); 171 debug("Here's the course environment: $ce\n");
173 $r->ce($ce); 172 $r->ce($ce);
174
175 my $validCourse = 0;
176 if ($displayArgs{courseID}) {
177 my $courseRoot = $ce->{courseDirs}->{root};
178 $validCourse = -e $courseRoot and -r $courseRoot;
179
180 unless ($validCourse) { # send the user to an 404 style error page
181 $displayModule = ERROR_MODULE;
182 $r->status(HTTP_NOT_FOUND);
183 }
184 }
185 173
186 my @uploads = $r->upload; 174 my @uploads = $r->upload;
187 foreach my $u (@uploads) { 175 foreach my $u (@uploads) {
188 # make sure it's a "real" upload 176 # make sure it's a "real" upload
189 next unless $u->filename; 177 next unless $u->filename;
196 # store the upload ID and hash in the file upload field 184 # store the upload ID and hash in the file upload field
197 my $id = $upload->id; 185 my $id = $upload->id;
198 my $hash = $upload->hash; 186 my $hash = $upload->hash;
199 $r->param($u->name => "$id $hash"); 187 $r->param($u->name => "$id $hash");
200 } 188 }
201
202 189
203 my ($db, $authz); 190 my ($db, $authz);
204 191
205 if ($displayArgs{courseID} and $validCourse) { 192 if ($displayArgs{courseID} and not $ce->{'!'}) {
206 debug("We got a courseID from the URLPath, now we can do some stuff:\n"); 193 debug("We got a courseID from the URLPath, now we can do some stuff:\n");
207 debug("...we can create a database object...\n"); 194 debug("...we can create a database object...\n");
208 $db = new WeBWorK::DB($ce->{dbLayout}); 195 $db = new WeBWorK::DB($ce->{dbLayout});
209 debug("(here's the DB handle: $db)\n"); 196 debug("(here's the DB handle: $db)\n");
210 $r->db($db); 197 $r->db($db);
248 $displayModule = AUTHEN_MODULE; 235 $displayModule = AUTHEN_MODULE;
249 debug("set displayModule to $displayModule\n"); 236 debug("set displayModule to $displayModule\n");
250 } 237 }
251 } 238 }
252 239
240 # if a course ID was given in the URL and resulted in an error (as stored in $!)
241 # it probably means that the course does not exist or was misspelled
242 if ($displayArgs{courseID} and $ce->{'!'}) {
243 debug("Something was wrong with the courseID: \n");
244 debug("\t\t" . $ce->{'!'} . "\n");
245 debug("Time to bail!\n");
246 die "An error occured while accessing '$displayArgs{courseID}': '", $ce->{'!'}, "'.\n";
247 }
248
253 debug(("-" x 80) . "\n"); 249 debug(("-" x 80) . "\n");
254 debug("Finally, we'll load the display module...\n"); 250 debug("Finally, we'll load the display module...\n");
255 251
256 runtime_use($displayModule); 252 runtime_use($displayModule);
257 253

Legend:
Removed from v.2433  
changed lines
  Added in v.2434

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9