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

Diff of /trunk/webwork2/lib/WeBWorK.pm

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

Revision 1173 Revision 1377
11 11
12=cut 12=cut
13 13
14use strict; 14use strict;
15use warnings; 15use warnings;
16use Apache::Constants qw(:common REDIRECT); 16use Apache::Constants qw(:common REDIRECT DONE);
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::SendMail;
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#}
66 unless (substr($current_uri,-1) eq '/') { 67 unless (substr($current_uri,-1) eq '/') {
67 $r->header_out(Location => "$current_uri/" . ($args ? "?$args" : "")); 68 $r->header_out(Location => "$current_uri/" . ($args ? "?$args" : ""));
68 return REDIRECT; 69 return REDIRECT;
69 # *** any post data gets lost here -- fix that. 70 # *** any post data gets lost here -- fix that.
70 # (actually, it's not a problem, since all URLs generated 71 # (actually, it's not a problem, since all URLs generated
71 # from within the system have trailing slashes, and we don't 72 # from within the system have trailing slashes, and we don't
72 # need POST data from outside the system anyway!) 73 # need POST data from outside the system anyway!)
73 } 74 }
74 75
75 # Create the @components array, which contains the path specified in the URL 76 # Create the @components array, which contains the path specified in the URL
76 my($junk, @components) = split "/", $path_info; 77 my($junk, @components) = split "/", $path_info;
101 # to be passed to content generators, when we clean this file up). 102 # to be passed to content generators, when we clean this file up).
102 my $db = WeBWorK::DB->new($ce); 103 my $db = WeBWorK::DB->new($ce);
103 104
104 ### Begin dispatching ### 105 ### Begin dispatching ###
105 106
107 #my $dispatchTimer = WeBWorK::Timing->new(__PACKAGE__."::dispatch");
108 #$dispatchTimer->start;
109
110 my $result;
106 # WeBWorK::Authen::verify erases the passwd field and sets the key field 111 # WeBWorK::Authen::verify erases the passwd field and sets the key field
107 # if login is successful. 112 # if login is successful.
108 if (!WeBWorK::Authen->new($r, $ce, $db)->verify) { 113 if (!WeBWorK::Authen->new($r, $ce, $db)->verify) {
109 return WeBWorK::ContentGenerator::Login->new($r, $ce, $db)->go; 114 $result = WeBWorK::ContentGenerator::Login->new($r, $ce, $db)->go;
110 } else { 115 } else {
111 # After we are authenticated, there are some things that need to be 116 # After we are authenticated, there are some things that need to be
112 # sorted out, Authorization-wize, before we start dispatching to individual 117 # sorted out, Authorization-wize, before we start dispatching to individual
113 # content generators. 118 # content generators.
114 my $user = $r->param("user"); 119 my $user = $r->param("user");
117 $effectiveUser = $user unless $su_authorized; 122 $effectiveUser = $user unless $su_authorized;
118 $r->param("effectiveUser", $effectiveUser); 123 $r->param("effectiveUser", $effectiveUser);
119 124
120 my $arg = shift @components; 125 my $arg = shift @components;
121 if (!defined $arg) { # We want the list of problem sets 126 if (!defined $arg) { # We want the list of problem sets
122 return WeBWorK::ContentGenerator::ProblemSets->new($r, $ce, $db)->go; 127 $result = WeBWorK::ContentGenerator::ProblemSets->new($r, $ce, $db)->go;
123 } elsif ($arg eq "hardcopy") { 128 } elsif ($arg eq "hardcopy") {
129
124 my $hardcopyArgument = shift @components; 130 my $hardcopyArgument = shift @components;
125 $hardcopyArgument = "" unless defined $hardcopyArgument; 131 $hardcopyArgument = "" unless defined $hardcopyArgument;
132 $WeBWorK::timer1 = WeBWorK::Timing->new("hardcopy: $hardcopyArgument");
133 $WeBWorK::timer1->start;
134
126 return WeBWorK::ContentGenerator::Hardcopy->new($r, $ce, $db)->go($hardcopyArgument); 135 my $result = WeBWorK::ContentGenerator::Hardcopy->new($r, $ce, $db)->go($hardcopyArgument);
136 $WeBWorK::timer1 ->stop;
137 $WeBWorK::timer1 ->save;
138 return $result;
127 } elsif ($arg eq "instructor") { 139 } elsif ($arg eq "instructor") {
128 my $instructorArgument = shift @components; 140 my $instructorArgument = shift @components;
129 if (!defined $instructorArgument) { 141 if (!defined $instructorArgument) {
130 return WeBWorK::ContentGenerator::Instructor::Index->new($r, $ce, $db)->go; 142 $result = WeBWorK::ContentGenerator::Instructor::Index->new($r, $ce, $db)->go;
131 } elsif ($instructorArgument eq "users") { 143 } elsif ($instructorArgument eq "users") {
132 return WeBWorK::ContentGenerator::Instructor::UserList->new($r, $ce, $db)->go; 144 $result = WeBWorK::ContentGenerator::Instructor::UserList->new($r, $ce, $db)->go;
133 } elsif ($instructorArgument eq "sets") { 145 } elsif ($instructorArgument eq "sets") {
134 my $setID = shift @components; 146 my $setID = shift @components;
135 if (defined $setID) { 147 if (defined $setID) {
136 my $setArg = shift @components; 148 my $setArg = shift @components;
137 if (!defined $setArg) { 149 if (!defined $setArg) {
138 return WeBWorK::ContentGenerator::Instructor::ProblemSetEditor->new($r, $ce, $db)->go($setID); 150 $result = WeBWorK::ContentGenerator::Instructor::ProblemSetEditor->new($r, $ce, $db)->go($setID);
139 } elsif ($setArg eq "problems") { 151 } elsif ($setArg eq "problems") {
140 return WeBWorK::ContentGenerator::Instructor::ProblemList->new($r, $ce, $db)->go($setID); 152 $result = WeBWorK::ContentGenerator::Instructor::ProblemList->new($r, $ce, $db)->go($setID);
141 } elsif ($setArg eq "users") { 153 } elsif ($setArg eq "users") {
142 return WeBWorK::ContentGenerator::Instructor::Assigner->new($r, $ce, $db)->go($setID); 154 $result = WeBWorK::ContentGenerator::Instructor::Assigner->new($r, $ce, $db)->go($setID);
143 } 155 }
144 } else { 156 } else {
145 return WeBWorK::ContentGenerator::Instructor::ProblemSetList->new($r, $ce, $db)->go; 157 $result = WeBWorK::ContentGenerator::Instructor::ProblemSetList->new($r, $ce, $db)->go;
146 } 158 }
147 } elsif ($instructorArgument eq "pgProblemEditor") { 159 } elsif ($instructorArgument eq "pgProblemEditor") {
148 return WeBWorK::ContentGenerator::Instructor::PGProblemEditor->new($r, $ce, $db)->go(@components); 160 $result = WeBWorK::ContentGenerator::Instructor::PGProblemEditor->new($r, $ce, $db)->go(@components);
161 } elsif ($instructorArgument eq "send_mail") {
162 $result = WeBWorK::ContentGenerator::Instructor::SendMail->new($r, $ce, $db)->go(@components);
149 } 163 }
150 } elsif ($arg eq "options") { 164 } elsif ($arg eq "options") {
151 return WeBWorK::ContentGenerator::Options->new($r, $ce, $db)->go; 165 $result = WeBWorK::ContentGenerator::Options->new($r, $ce, $db)->go;
152 } elsif ($arg eq "feedback") { 166 } elsif ($arg eq "feedback") {
153 return WeBWorK::ContentGenerator::Feedback->new($r, $ce, $db)->go; 167 $result = WeBWorK::ContentGenerator::Feedback->new($r, $ce, $db)->go;
154 } elsif ($arg eq "logout") { 168 } elsif ($arg eq "logout") {
155 return WeBWorK::ContentGenerator::Logout->new($r, $ce, $db)->go; 169 $result = WeBWorK::ContentGenerator::Logout->new($r, $ce, $db)->go;
156 } elsif ($arg eq "test") { 170 } elsif ($arg eq "test") {
157 return WeBWorK::ContentGenerator::Test->new($r, $ce, $db)->go; 171 $result = WeBWorK::ContentGenerator::Test->new($r, $ce, $db)->go;
158 } elsif ($arg eq "quiz_mode" ) { 172 } elsif ($arg eq "quiz_mode" ) {
159 # Gateway quiz capability -- very similar to problem set (initially) 173 # Gateway quiz capability -- very similar to problem set (initially)
160 return WeBWorK::ContentGenerator::GatewayQuiz->new($r, $ce, $db)->go(@components); 174 $result = WeBWorK::ContentGenerator::GatewayQuiz->new($r, $ce, $db)->go(@components);
161 } else { # We've got the name of a problem set. 175 } else { # We've got the name of a problem set.
162 my $problem_set = $arg; 176 my $problem_set = $arg;
163 my $ps_arg = shift @components; 177 my $ps_arg = shift @components;
164 178
165 if (!defined $ps_arg) { 179 if (!defined $ps_arg) {
166 # list the problems in the problem set 180 # list the problems in the problem set
181 $WeBWorK::timer0 = WeBWorK::Timing->new("Problem $course:$problem_set");
182 $WeBWorK::timer0->start;
167 return WeBWorK::ContentGenerator::ProblemSet->new($r, $ce, $db)->go($problem_set); 183 $result = WeBWorK::ContentGenerator::ProblemSet->new($r, $ce, $db)->go($problem_set);
184 $WeBWorK::timer0->continue("problem set listing is done");
185 $WeBWorK::timer0->stop;
186 $WeBWorK::timer0->save;
168 } else { 187 } else {
169 # We've got the name of a problem 188 # We've got the name of a problem
170 my $problem = $ps_arg; 189 my $problem = $ps_arg;
190
191 $WeBWorK::timer0 = WeBWorK::Timing->new("Problem $course:$problem_set/$problem");
192 $WeBWorK::timer0->start;
193 my $pid = fork();
194# if ($pid) {
195# wait;
196# } else {
171 return WeBWorK::ContentGenerator::Problem->new($r, $ce, $db)->go($problem_set, $problem); 197 my $result = WeBWorK::ContentGenerator::Problem->new($r, $ce, $db)->go($problem_set, $problem);
198# $WeBWorK::timer0->continue("Exiting child process");
199# #$WeBWorK::timer0->stop;
200# #$WeBWorK::timer0->save;
201# eval{ APACHE::exit(0);} || warn "Error in leaving child |$@|";
202# # We REALLY REALLY want this grandchild to exit. But not the child. How to do this
203# # cleanly???? FIXME
204# }
205 $WeBWorK::timer0->continue("Parent done waiting (teenagers!!! -- sigh)");
206 $WeBWorK::timer0->stop;
207 $WeBWorK::timer0->save;
208 return $result;
209
210
172 } 211 }
173 } 212 }
174
175 } 213 }
176 214
177 # If the dispatcher doesn't know any modules that want to handle 215 #$dispatchTimer->stop;
178 # the current path, it'll claim that the path does not exist by 216
179 # declining the request. 217 return $result;
180 return DECLINED;
181} 218}
182 219
1831; 2201;

Legend:
Removed from v.1173  
changed lines
  Added in v.1377

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9