[system] / branches / rel-2-4-dev / webwork2 / lib / WeBWorK.pm Repository:
ViewVC logotype

Diff of /branches/rel-2-4-dev/webwork2/lib/WeBWorK.pm

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

Revision 1194 Revision 1195
16use Apache::Constants qw(:common REDIRECT); 16use Apache::Constants qw(:common REDIRECT);
17use Apache::Request; 17use Apache::Request;
18use WeBWorK::Authen; 18use WeBWorK::Authen;
19use WeBWorK::Authz; 19use WeBWorK::Authz;
20use WeBWorK::ContentGenerator::Feedback; 20use WeBWorK::ContentGenerator::Feedback;
21use WeBWorK::ContentGenerator::GatewayQuiz;
21use WeBWorK::ContentGenerator::Hardcopy; 22use WeBWorK::ContentGenerator::Hardcopy;
23use WeBWorK::ContentGenerator::Instructor::Assigner;
22use WeBWorK::ContentGenerator::Instructor::Index; 24use WeBWorK::ContentGenerator::Instructor::Index;
23use WeBWorK::ContentGenerator::Instructor::PGProblemEditor; 25use WeBWorK::ContentGenerator::Instructor::PGProblemEditor;
26use WeBWorK::ContentGenerator::Instructor::ProblemList;
24use WeBWorK::ContentGenerator::Instructor::ProblemSetEditor; 27use WeBWorK::ContentGenerator::Instructor::ProblemSetEditor;
25use WeBWorK::ContentGenerator::Instructor::ProblemSetList; 28use WeBWorK::ContentGenerator::Instructor::ProblemSetList;
26use WeBWorK::ContentGenerator::Instructor::UserList; 29use WeBWorK::ContentGenerator::Instructor::UserList;
27use WeBWorK::ContentGenerator::Instructor::ProblemList;
28use WeBWorK::ContentGenerator::Instructor::UserList; 30use WeBWorK::ContentGenerator::Instructor::UserList;
29use WeBWorK::ContentGenerator::Instructor::Assigner;
30use WeBWorK::ContentGenerator::Login; 31use WeBWorK::ContentGenerator::Login;
31use WeBWorK::ContentGenerator::Logout; 32use WeBWorK::ContentGenerator::Logout;
32use WeBWorK::ContentGenerator::Options; 33use WeBWorK::ContentGenerator::Options;
33use WeBWorK::ContentGenerator::Problem; 34use WeBWorK::ContentGenerator::Problem;
34use WeBWorK::ContentGenerator::ProblemSet; 35use WeBWorK::ContentGenerator::ProblemSet;
35use WeBWorK::ContentGenerator::GatewayQuiz;
36use WeBWorK::ContentGenerator::ProblemSets; 36use WeBWorK::ContentGenerator::ProblemSets;
37use WeBWorK::ContentGenerator::Test; 37use WeBWorK::ContentGenerator::Test;
38use WeBWorK::CourseEnvironment; 38use WeBWorK::CourseEnvironment;
39use WeBWorK::DB; 39use WeBWorK::DB;
40use WeBWorK::Timing;
40 41
41#sub dispatch($) { 42#sub dispatch($) {
42# print STDERR "Executing &WeBWorK::dispatch\n"; 43# print STDERR "Executing &WeBWorK::dispatch\n";
43# return DECLINED; 44# return DECLINED;
44#} 45#}
76 my($junk, @components) = split "/", $path_info; 77 my($junk, @components) = split "/", $path_info;
77 my $webwork_root = $r->dir_config('webwork_root'); # From a PerlSetVar in httpd.conf 78 my $webwork_root = $r->dir_config('webwork_root'); # From a PerlSetVar in httpd.conf
78 my $pg_root = $r->dir_config('pg_root'); # From a PerlSetVar in httpd.conf 79 my $pg_root = $r->dir_config('pg_root'); # From a PerlSetVar in httpd.conf
79 my $course = shift @components; 80 my $course = shift @components;
80 81
82 my $ceTimer = WeBWorK::Timing->new(__PACKAGE__."::dispatch get ce");
83 $ceTimer->start;
84
81 # Try to get the course environment. 85 # Try to get the course environment.
82 my $ce = eval {WeBWorK::CourseEnvironment->new($webwork_root, $urlRoot, $pg_root, $course);}; 86 my $ce = eval {WeBWorK::CourseEnvironment->new($webwork_root, $urlRoot, $pg_root, $course);};
83 if ($@) { # If there was an error getting the requested course 87 if ($@) { # If there was an error getting the requested course
84 die "Failed to read course environment for $course: $@"; 88 die "Failed to read course environment for $course: $@";
85 } 89 }
90
91 $ceTimer->stop;
86 92
87 # If no course was specified, redirect to the home URL 93 # If no course was specified, redirect to the home URL
88 unless (defined $course) { 94 unless (defined $course) {
89 $r->header_out(Location => $ce->{webworkURLs}->{home}); 95 $r->header_out(Location => $ce->{webworkURLs}->{home});
90 return REDIRECT; 96 return REDIRECT;
95 my $courseDir = $ce->{webworkDirs}->{courses} . "/$course"; 101 my $courseDir = $ce->{webworkDirs}->{courses} . "/$course";
96 unless (-e $courseDir) { 102 unless (-e $courseDir) {
97 die "Course directory for $course ($courseDir) not found. Perhaps the course does not exist?"; 103 die "Course directory for $course ($courseDir) not found. Perhaps the course does not exist?";
98 } 104 }
99 105
106 my $dbTimer = WeBWorK::Timing->new(__PACKAGE__."::dispatch init db");
107 $dbTimer->start;
108
100 # Bring up a connection to the database (for Authen/Authz, and eventually 109 # Bring up a connection to the database (for Authen/Authz, and eventually
101 # to be passed to content generators, when we clean this file up). 110 # to be passed to content generators, when we clean this file up).
102 my $db = WeBWorK::DB->new($ce); 111 my $db = WeBWorK::DB->new($ce);
103 112
113 $dbTimer->stop;
114
104 ### Begin dispatching ### 115 ### Begin dispatching ###
105 116
117 my $dispatchTimer = WeBWorK::Timing->new(__PACKAGE__."::dispatch begin dispatching");
118 $dispatchTimer->start;
119
120 my $result;
106 # WeBWorK::Authen::verify erases the passwd field and sets the key field 121 # WeBWorK::Authen::verify erases the passwd field and sets the key field
107 # if login is successful. 122 # if login is successful.
108 if (!WeBWorK::Authen->new($r, $ce, $db)->verify) { 123 if (!WeBWorK::Authen->new($r, $ce, $db)->verify) {
109 return WeBWorK::ContentGenerator::Login->new($r, $ce, $db)->go; 124 $result = WeBWorK::ContentGenerator::Login->new($r, $ce, $db)->go;
110 } else { 125 } else {
111 # After we are authenticated, there are some things that need to be 126 # After we are authenticated, there are some things that need to be
112 # sorted out, Authorization-wize, before we start dispatching to individual 127 # sorted out, Authorization-wize, before we start dispatching to individual
113 # content generators. 128 # content generators.
114 my $user = $r->param("user"); 129 my $user = $r->param("user");
117 $effectiveUser = $user unless $su_authorized; 132 $effectiveUser = $user unless $su_authorized;
118 $r->param("effectiveUser", $effectiveUser); 133 $r->param("effectiveUser", $effectiveUser);
119 134
120 my $arg = shift @components; 135 my $arg = shift @components;
121 if (!defined $arg) { # We want the list of problem sets 136 if (!defined $arg) { # We want the list of problem sets
122 return WeBWorK::ContentGenerator::ProblemSets->new($r, $ce, $db)->go; 137 $result = WeBWorK::ContentGenerator::ProblemSets->new($r, $ce, $db)->go;
123 } elsif ($arg eq "hardcopy") { 138 } elsif ($arg eq "hardcopy") {
124 my $hardcopyArgument = shift @components; 139 my $hardcopyArgument = shift @components;
125 $hardcopyArgument = "" unless defined $hardcopyArgument; 140 $hardcopyArgument = "" unless defined $hardcopyArgument;
126 return WeBWorK::ContentGenerator::Hardcopy->new($r, $ce, $db)->go($hardcopyArgument); 141 $result = WeBWorK::ContentGenerator::Hardcopy->new($r, $ce, $db)->go($hardcopyArgument);
127 } elsif ($arg eq "instructor") { 142 } elsif ($arg eq "instructor") {
128 my $instructorArgument = shift @components; 143 my $instructorArgument = shift @components;
129 if (!defined $instructorArgument) { 144 if (!defined $instructorArgument) {
130 return WeBWorK::ContentGenerator::Instructor::Index->new($r, $ce, $db)->go; 145 $result = WeBWorK::ContentGenerator::Instructor::Index->new($r, $ce, $db)->go;
131 } elsif ($instructorArgument eq "users") { 146 } elsif ($instructorArgument eq "users") {
132 return WeBWorK::ContentGenerator::Instructor::UserList->new($r, $ce, $db)->go; 147 $result = WeBWorK::ContentGenerator::Instructor::UserList->new($r, $ce, $db)->go;
133 } elsif ($instructorArgument eq "sets") { 148 } elsif ($instructorArgument eq "sets") {
134 my $setID = shift @components; 149 my $setID = shift @components;
135 if (defined $setID) { 150 if (defined $setID) {
136 my $setArg = shift @components; 151 my $setArg = shift @components;
137 if (!defined $setArg) { 152 if (!defined $setArg) {
138 return WeBWorK::ContentGenerator::Instructor::ProblemSetEditor->new($r, $ce, $db)->go($setID); 153 $result = WeBWorK::ContentGenerator::Instructor::ProblemSetEditor->new($r, $ce, $db)->go($setID);
139 } elsif ($setArg eq "problems") { 154 } elsif ($setArg eq "problems") {
140 return WeBWorK::ContentGenerator::Instructor::ProblemList->new($r, $ce, $db)->go($setID); 155 $result = WeBWorK::ContentGenerator::Instructor::ProblemList->new($r, $ce, $db)->go($setID);
141 } elsif ($setArg eq "users") { 156 } elsif ($setArg eq "users") {
142 return WeBWorK::ContentGenerator::Instructor::Assigner->new($r, $ce, $db)->go($setID); 157 $result = WeBWorK::ContentGenerator::Instructor::Assigner->new($r, $ce, $db)->go($setID);
143 } 158 }
144 } else { 159 } else {
145 return WeBWorK::ContentGenerator::Instructor::ProblemSetList->new($r, $ce, $db)->go; 160 $result = WeBWorK::ContentGenerator::Instructor::ProblemSetList->new($r, $ce, $db)->go;
146 } 161 }
147 } elsif ($instructorArgument eq "pgProblemEditor") { 162 } elsif ($instructorArgument eq "pgProblemEditor") {
148 return WeBWorK::ContentGenerator::Instructor::PGProblemEditor->new($r, $ce, $db)->go(@components); 163 $result = WeBWorK::ContentGenerator::Instructor::PGProblemEditor->new($r, $ce, $db)->go(@components);
149 } 164 }
150 } elsif ($arg eq "options") { 165 } elsif ($arg eq "options") {
151 return WeBWorK::ContentGenerator::Options->new($r, $ce, $db)->go; 166 $result = WeBWorK::ContentGenerator::Options->new($r, $ce, $db)->go;
152 } elsif ($arg eq "feedback") { 167 } elsif ($arg eq "feedback") {
153 return WeBWorK::ContentGenerator::Feedback->new($r, $ce, $db)->go; 168 $result = WeBWorK::ContentGenerator::Feedback->new($r, $ce, $db)->go;
154 } elsif ($arg eq "logout") { 169 } elsif ($arg eq "logout") {
155 return WeBWorK::ContentGenerator::Logout->new($r, $ce, $db)->go; 170 $result = WeBWorK::ContentGenerator::Logout->new($r, $ce, $db)->go;
156 } elsif ($arg eq "test") { 171 } elsif ($arg eq "test") {
157 return WeBWorK::ContentGenerator::Test->new($r, $ce, $db)->go; 172 $result = WeBWorK::ContentGenerator::Test->new($r, $ce, $db)->go;
158 } elsif ($arg eq "quiz_mode" ) { 173 } elsif ($arg eq "quiz_mode" ) {
159 # Gateway quiz capability -- very similar to problem set (initially) 174 # Gateway quiz capability -- very similar to problem set (initially)
160 return WeBWorK::ContentGenerator::GatewayQuiz->new($r, $ce, $db)->go(@components); 175 $result = WeBWorK::ContentGenerator::GatewayQuiz->new($r, $ce, $db)->go(@components);
161 } else { # We've got the name of a problem set. 176 } else { # We've got the name of a problem set.
162 my $problem_set = $arg; 177 my $problem_set = $arg;
163 my $ps_arg = shift @components; 178 my $ps_arg = shift @components;
164 179
165 if (!defined $ps_arg) { 180 if (!defined $ps_arg) {
166 # list the problems in the problem set 181 # list the problems in the problem set
167 return WeBWorK::ContentGenerator::ProblemSet->new($r, $ce, $db)->go($problem_set); 182 $result = WeBWorK::ContentGenerator::ProblemSet->new($r, $ce, $db)->go($problem_set);
168 } else { 183 } else {
169 # We've got the name of a problem 184 # We've got the name of a problem
170 my $problem = $ps_arg; 185 my $problem = $ps_arg;
171 return WeBWorK::ContentGenerator::Problem->new($r, $ce, $db)->go($problem_set, $problem); 186 $result = WeBWorK::ContentGenerator::Problem->new($r, $ce, $db)->go($problem_set, $problem);
172 } 187 }
173 } 188 }
174
175 } 189 }
176 190
177 # If the dispatcher doesn't know any modules that want to handle 191 $dispatchTimer->stop;
178 # the current path, it'll claim that the path does not exist by 192
179 # declining the request. 193 return $result;
180 return DECLINED;
181} 194}
182 195
1831; 1961;

Legend:
Removed from v.1194  
changed lines
  Added in v.1195

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9