Parent Directory
|
Revision Log
profiler debugging. -sam
1 ################################################################################ 2 # WeBWorK mod_perl (c) 2000-2002 WeBWorK Project 3 # $Id$ 4 ################################################################################ 5 6 package WeBWorK; 7 8 =head1 NAME 9 10 WeBWorK - Dispatch requests to the appropriate ContentGenerator. 11 12 =cut 13 14 use strict; 15 use warnings; 16 use Apache::Constants qw(:common REDIRECT); 17 use Apache::Request; 18 use WeBWorK::Authen; 19 use WeBWorK::Authz; 20 use WeBWorK::ContentGenerator::Feedback; 21 use WeBWorK::ContentGenerator::Hardcopy; 22 use WeBWorK::ContentGenerator::Instructor::Index; 23 use WeBWorK::ContentGenerator::Instructor::PGProblemEditor; 24 use WeBWorK::ContentGenerator::Instructor::ProblemSetEditor; 25 use WeBWorK::ContentGenerator::Instructor::ProblemSetList; 26 use WeBWorK::ContentGenerator::Instructor::UserList; 27 use WeBWorK::ContentGenerator::Instructor::ProblemList; 28 use WeBWorK::ContentGenerator::Instructor::UserList; 29 use WeBWorK::ContentGenerator::Login; 30 use WeBWorK::ContentGenerator::Logout; 31 use WeBWorK::ContentGenerator::Options; 32 use WeBWorK::ContentGenerator::Problem; 33 use WeBWorK::ContentGenerator::ProblemSet; 34 use WeBWorK::ContentGenerator::GatewayQuiz; 35 use WeBWorK::ContentGenerator::ProblemSets; 36 use WeBWorK::ContentGenerator::Test; 37 use WeBWorK::CourseEnvironment; 38 use WeBWorK::DB; 39 40 #sub dispatch($) { 41 # print STDERR "Executing &WeBWorK::dispatch\n"; 42 # return DECLINED; 43 #} 44 #1; 45 #__END__ 46 47 sub dispatch($) { 48 my ($apache) = @_; 49 my $r = Apache::Request->new($apache); 50 # have to deal with unpredictable GET or POST data, and sift 51 # through it for the key. So use Apache::Request 52 53 # This stuff is pretty much copied out of the O'Reilly mod_perl book. 54 # It's for figuring out the basepath. I may change this up if I find a 55 # better way to do it. 56 my $path_info = $r->path_info || ""; 57 $path_info =~ s!/+!/!g; # strip multiple forward slashes 58 my $current_uri = $r->uri; 59 my $args = $r->args; 60 61 my ($urlRoot) = $current_uri =~ m/^(.*)$path_info/; 62 63 # If it's a valid WeBWorK URI, it ends in a /. This is assumed 64 # alllll over the place. 65 unless (substr($current_uri,-1) eq '/') { 66 $r->header_out(Location => "$current_uri/" . ($args ? "?$args" : "")); 67 return REDIRECT; 68 # *** any post data gets lost here -- fix that. 69 # (actually, it's not a problem, since all URLs generated 70 # from within the system have trailing slashes, and we don't 71 # need POST data from outside the system anyway!) 72 } 73 74 # Create the @components array, which contains the path specified in the URL 75 my($junk, @components) = split "/", $path_info; 76 my $webwork_root = $r->dir_config('webwork_root'); # From a PerlSetVar in httpd.conf 77 my $pg_root = $r->dir_config('pg_root'); # From a PerlSetVar in httpd.conf 78 my $course = shift @components; 79 80 # Try to get the course environment. 81 my $ce = eval {WeBWorK::CourseEnvironment->new($webwork_root, $urlRoot, $pg_root, $course);}; 82 if ($@) { # If there was an error getting the requested course 83 die "Failed to read course environment for $course: $@"; 84 } 85 86 # If no course was specified, redirect to the home URL 87 unless (defined $course) { 88 $r->header_out(Location => $ce->{webworkURLs}->{home}); 89 return REDIRECT; 90 } 91 92 # Freak out if the requested course doesn't exist. For now, this is just a 93 # check to see if the course directory exists. 94 my $courseDir = $ce->{webworkDirs}->{courses} . "/$course"; 95 unless (-e $courseDir) { 96 die "Course directory for $course ($courseDir) not found. Perhaps the course does not exist?"; 97 } 98 99 # Bring up a connection to the database (for Authen/Authz, and eventually 100 # to be passed to content generators, when we clean this file up). 101 my $db = WeBWorK::DB->new($ce); 102 103 ### Begin dispatching ### 104 105 # WeBWorK::Authen::verify erases the passwd field and sets the key field 106 # if login is successful. 107 if (!WeBWorK::Authen->new($r, $ce, $db)->verify) { 108 return WeBWorK::ContentGenerator::Login->new($r, $ce, $db)->go; 109 } else { 110 # After we are authenticated, there are some things that need to be 111 # sorted out, Authorization-wize, before we start dispatching to individual 112 # content generators. 113 my $user = $r->param("user"); 114 my $effectiveUser = $r->param("effectiveUser") || $user; 115 my $su_authorized = WeBWorK::Authz->new($r, $ce, $db)->hasPermissions($user, "become_student", $effectiveUser); 116 $effectiveUser = $user unless $su_authorized; 117 $r->param("effectiveUser", $effectiveUser); 118 119 my $arg = shift @components; 120 if (!defined $arg) { # We want the list of problem sets 121 return WeBWorK::ContentGenerator::ProblemSets->new($r, $ce, $db)->go; 122 } elsif ($arg eq "hardcopy") { 123 my $hardcopyArgument = shift @components; 124 $hardcopyArgument = "" unless defined $hardcopyArgument; 125 return WeBWorK::ContentGenerator::Hardcopy->new($r, $ce, $db)->go($hardcopyArgument); 126 } elsif ($arg eq "instructor") { 127 my $instructorArgument = shift @components; 128 if (!defined $instructorArgument) { 129 return WeBWorK::ContentGenerator::Instructor::Index->new($r, $ce, $db)->go; 130 } elsif ($instructorArgument eq "users") { 131 return WeBWorK::ContentGenerator::Instructor::UserList->new($r, $ce, $db)->go; 132 } elsif ($instructorArgument eq "sets") { 133 my $setID = shift @components; 134 if (defined $setID) { 135 my $setArg = shift @components; 136 if (!defined $setArg) { 137 return WeBWorK::ContentGenerator::Instructor::ProblemSetEditor->new($r, $ce, $db)->go($setID); 138 } elsif ($setArg eq "problems") { 139 return WeBWorK::ContentGenerator::Instructor::ProblemList->new($r, $ce, $db)->go($setID); 140 } elsif ($setArg eq "users") { 141 return WeBWorK::ContentGenerator::Instructor::UserList->new($r, $ce, $db)->go($setID); 142 } 143 } else { 144 return WeBWorK::ContentGenerator::Instructor::ProblemSetList->new($r, $ce, $db)->go; 145 } 146 } elsif ($instructorArgument eq "pgProblemEditor") { 147 return WeBWorK::ContentGenerator::Instructor::PGProblemEditor->new($r, $ce, $db)->go(@components); 148 } 149 } elsif ($arg eq "options") { 150 return WeBWorK::ContentGenerator::Options->new($r, $ce, $db)->go; 151 } elsif ($arg eq "feedback") { 152 return WeBWorK::ContentGenerator::Feedback->new($r, $ce, $db)->go; 153 } elsif ($arg eq "logout") { 154 return WeBWorK::ContentGenerator::Logout->new($r, $ce, $db)->go; 155 } elsif ($arg eq "test") { 156 return WeBWorK::ContentGenerator::Test->new($r, $ce, $db)->go; 157 } elsif ($arg eq "quiz_mode" ) { 158 # Gateway quiz capability -- very similar to problem set (initially) 159 return WeBWorK::ContentGenerator::GatewayQuiz->new($r, $ce, $db)->go(@components); 160 } else { # We've got the name of a problem set. 161 my $problem_set = $arg; 162 my $ps_arg = shift @components; 163 164 if (!defined $ps_arg) { 165 # list the problems in the problem set 166 return WeBWorK::ContentGenerator::ProblemSet->new($r, $ce, $db)->go($problem_set); 167 } else { 168 # We've got the name of a problem 169 my $problem = $ps_arg; 170 return WeBWorK::ContentGenerator::Problem->new($r, $ce, $db)->go($problem_set, $problem); 171 } 172 } 173 174 } 175 176 # If the dispatcher doesn't know any modules that want to handle 177 # the current path, it'll claim that the path does not exist by 178 # declining the request. 179 return DECLINED; 180 } 181 182 1;
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |