[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 1151 Revision 1382
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::Login; 31use WeBWorK::ContentGenerator::Login;
30use WeBWorK::ContentGenerator::Logout; 32use WeBWorK::ContentGenerator::Logout;
31use WeBWorK::ContentGenerator::Options; 33use WeBWorK::ContentGenerator::Options;
32use WeBWorK::ContentGenerator::Problem; 34use WeBWorK::ContentGenerator::Problem;
33use WeBWorK::ContentGenerator::ProblemSet; 35use WeBWorK::ContentGenerator::ProblemSet;
34use WeBWorK::ContentGenerator::GatewayQuiz;
35use WeBWorK::ContentGenerator::ProblemSets; 36use WeBWorK::ContentGenerator::ProblemSets;
36use WeBWorK::ContentGenerator::Test; 37use WeBWorK::ContentGenerator::Test;
37use WeBWorK::CourseEnvironment; 38use WeBWorK::CourseEnvironment;
38use WeBWorK::DB; 39use WeBWorK::DB;
40use WeBWorK::Timing;
39 41
40#sub dispatch($) { 42#sub dispatch($) {
41# print STDERR "Executing &WeBWorK::dispatch\n"; 43# print STDERR "Executing &WeBWorK::dispatch\n";
42# return DECLINED; 44# return DECLINED;
43#} 45#}
65 unless (substr($current_uri,-1) eq '/') { 67 unless (substr($current_uri,-1) eq '/') {
66 $r->header_out(Location => "$current_uri/" . ($args ? "?$args" : "")); 68 $r->header_out(Location => "$current_uri/" . ($args ? "?$args" : ""));
67 return REDIRECT; 69 return REDIRECT;
68 # *** any post data gets lost here -- fix that. 70 # *** any post data gets lost here -- fix that.
69 # (actually, it's not a problem, since all URLs generated 71 # (actually, it's not a problem, since all URLs generated
70 # from within the system have trailing slashes, and we don't 72 # from within the system have trailing slashes, and we don't
71 # need POST data from outside the system anyway!) 73 # need POST data from outside the system anyway!)
72 } 74 }
73 75
74 # 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
75 my($junk, @components) = split "/", $path_info; 77 my($junk, @components) = split "/", $path_info;
100 # 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).
101 my $db = WeBWorK::DB->new($ce); 103 my $db = WeBWorK::DB->new($ce);
102 104
103 ### Begin dispatching ### 105 ### Begin dispatching ###
104 106
107 #my $dispatchTimer = WeBWorK::Timing->new(__PACKAGE__."::dispatch");
108 #$dispatchTimer->start;
109
110 my $result;
105 # 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
106 # if login is successful. 112 # if login is successful.
107 if (!WeBWorK::Authen->new($r, $ce, $db)->verify) { 113 if (!WeBWorK::Authen->new($r, $ce, $db)->verify) {
108 return WeBWorK::ContentGenerator::Login->new($r, $ce, $db)->go; 114 $result = WeBWorK::ContentGenerator::Login->new($r, $ce, $db)->go;
109 } else { 115 } else {
110 # 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
111 # sorted out, Authorization-wize, before we start dispatching to individual 117 # sorted out, Authorization-wize, before we start dispatching to individual
112 # content generators. 118 # content generators.
113 my $user = $r->param("user"); 119 my $user = $r->param("user");
116 $effectiveUser = $user unless $su_authorized; 122 $effectiveUser = $user unless $su_authorized;
117 $r->param("effectiveUser", $effectiveUser); 123 $r->param("effectiveUser", $effectiveUser);
118 124
119 my $arg = shift @components; 125 my $arg = shift @components;
120 if (!defined $arg) { # We want the list of problem sets 126 if (!defined $arg) { # We want the list of problem sets
121 return WeBWorK::ContentGenerator::ProblemSets->new($r, $ce, $db)->go; 127 $result = WeBWorK::ContentGenerator::ProblemSets->new($r, $ce, $db)->go;
122 } elsif ($arg eq "hardcopy") { 128 } elsif ($arg eq "hardcopy") {
129
123 my $hardcopyArgument = shift @components; 130 my $hardcopyArgument = shift @components;
124 $hardcopyArgument = "" unless defined $hardcopyArgument; 131 $hardcopyArgument = "" unless defined $hardcopyArgument;
132 $WeBWorK::timer1 = WeBWorK::Timing->new("hardcopy: $hardcopyArgument");
133 $WeBWorK::timer1->start;
134
125 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;
126 } elsif ($arg eq "instructor") { 139 } elsif ($arg eq "instructor") {
127 my $instructorArgument = shift @components; 140 my $instructorArgument = shift @components;
128 if (!defined $instructorArgument) { 141 if (!defined $instructorArgument) {
129 return WeBWorK::ContentGenerator::Instructor::Index->new($r, $ce, $db)->go; 142 $result = WeBWorK::ContentGenerator::Instructor::Index->new($r, $ce, $db)->go;
130 } elsif ($instructorArgument eq "users") { 143 } elsif ($instructorArgument eq "users") {
131 return WeBWorK::ContentGenerator::Instructor::UserList->new($r, $ce, $db)->go; 144 $result = WeBWorK::ContentGenerator::Instructor::UserList->new($r, $ce, $db)->go;
132 } elsif ($instructorArgument eq "sets") { 145 } elsif ($instructorArgument eq "sets") {
133 my $setID = shift @components; 146 my $setID = shift @components;
134 if (defined $setID) { 147 if (defined $setID) {
135 my $setArg = shift @components; 148 my $setArg = shift @components;
136 if (!defined $setArg) { 149 if (!defined $setArg) {
137 return WeBWorK::ContentGenerator::Instructor::ProblemSetEditor->new($r, $ce, $db)->go($setID); 150 $result = WeBWorK::ContentGenerator::Instructor::ProblemSetEditor->new($r, $ce, $db)->go($setID);
138 } elsif ($setArg eq "problems") { 151 } elsif ($setArg eq "problems") {
139 return WeBWorK::ContentGenerator::Instructor::ProblemList->new($r, $ce, $db)->go($setID); 152 $result = WeBWorK::ContentGenerator::Instructor::ProblemList->new($r, $ce, $db)->go($setID);
140 } elsif ($setArg eq "users") { 153 } elsif ($setArg eq "users") {
141 return WeBWorK::ContentGenerator::Instructor::UserList->new($r, $ce, $db)->go($setID); 154 $result = WeBWorK::ContentGenerator::Instructor::Assigner->new($r, $ce, $db)->go($setID);
142 } 155 }
143 } else { 156 } else {
144 return WeBWorK::ContentGenerator::Instructor::ProblemSetList->new($r, $ce, $db)->go; 157 $result = WeBWorK::ContentGenerator::Instructor::ProblemSetList->new($r, $ce, $db)->go;
145 } 158 }
146 } elsif ($instructorArgument eq "pgProblemEditor") { 159 } elsif ($instructorArgument eq "pgProblemEditor") {
147 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);
148 } 163 }
149 } elsif ($arg eq "options") { 164 } elsif ($arg eq "options") {
150 return WeBWorK::ContentGenerator::Options->new($r, $ce, $db)->go; 165 $result = WeBWorK::ContentGenerator::Options->new($r, $ce, $db)->go;
151 } elsif ($arg eq "feedback") { 166 } elsif ($arg eq "feedback") {
152 return WeBWorK::ContentGenerator::Feedback->new($r, $ce, $db)->go; 167 $result = WeBWorK::ContentGenerator::Feedback->new($r, $ce, $db)->go;
153 } elsif ($arg eq "logout") { 168 } elsif ($arg eq "logout") {
154 return WeBWorK::ContentGenerator::Logout->new($r, $ce, $db)->go; 169 $result = WeBWorK::ContentGenerator::Logout->new($r, $ce, $db)->go;
155 } elsif ($arg eq "test") { 170 } elsif ($arg eq "test") {
156 return WeBWorK::ContentGenerator::Test->new($r, $ce, $db)->go; 171 $result = WeBWorK::ContentGenerator::Test->new($r, $ce, $db)->go;
157 } elsif ($arg eq "quiz_mode" ) { 172 } elsif ($arg eq "quiz_mode" ) {
158 # Gateway quiz capability -- very similar to problem set (initially) 173 # Gateway quiz capability -- very similar to problem set (initially)
159 return WeBWorK::ContentGenerator::GatewayQuiz->new($r, $ce, $db)->go(@components); 174 $result = WeBWorK::ContentGenerator::GatewayQuiz->new($r, $ce, $db)->go(@components);
160 } else { # We've got the name of a problem set. 175 } else { # We've got the name of a problem set.
161 my $problem_set = $arg; 176 my $problem_set = $arg;
162 my $ps_arg = shift @components; 177 my $ps_arg = shift @components;
163 178
164 if (!defined $ps_arg) { 179 if (!defined $ps_arg) {
165 # 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;
166 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;
167 } else { 187 } else {
168 # We've got the name of a problem 188 # We've got the name of a problem
169 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 {
170 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("Problem done)");
206 $WeBWorK::timer0->stop;
207 $WeBWorK::timer0->save;
208 return $result;
209
210
171 } 211 }
172 } 212 }
173
174 } 213 }
175 214
176 # If the dispatcher doesn't know any modules that want to handle 215 #$dispatchTimer->stop;
177 # the current path, it'll claim that the path does not exist by 216
178 # declining the request. 217 return $result;
179 return DECLINED;
180} 218}
181 219
1821; 2201;

Legend:
Removed from v.1151  
changed lines
  Added in v.1382

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9