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

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9