| … | |
… | |
| 28 | # new(Apache::Request, WeBWorK::CourseEnvironment) - create a new instance of a |
28 | # new(Apache::Request, WeBWorK::CourseEnvironment) - create a new instance of a |
| 29 | # content generator. Usually only called by the dispatcher, although one might |
29 | # content generator. Usually only called by the dispatcher, although one might |
| 30 | # be able to use it for things like "sub-requests". Uh... uh... I have to think |
30 | # be able to use it for things like "sub-requests". Uh... uh... I have to think |
| 31 | # about that one. The dispatcher uses this idiom: |
31 | # about that one. The dispatcher uses this idiom: |
| 32 | # |
32 | # |
| 33 | # |
|
|
| 34 | # WeBWorK::ContentGenerator::WHATEVER->new($r, $ce)->go(@whatever); |
33 | # WeBWorK::ContentGenerator::WHATEVER->new($r, $ce)->go(@whatever); |
| 35 | # |
34 | # |
| 36 | # and throws away the result ;) |
35 | # and throws away the result ;) |
| 37 | # |
36 | # |
| 38 | sub new($$$) { |
37 | sub new($$$) { |
| 39 | my $invocant = shift; |
38 | my ($invocant, $r, $ce) = @_; |
| 40 | my $class = ref($invocant) || $invocant; |
39 | my $class = ref($invocant) || $invocant; |
| 41 | my $self = {}; |
40 | my $self = { |
| 42 | ($self->{r}, $self->{courseEnvironment}) = @_; |
41 | r => $r, |
|
|
42 | ce => $ce, |
|
|
43 | }; |
| 43 | bless $self, $class; |
44 | bless $self, $class; |
| 44 | return $self; |
45 | return $self; |
| 45 | } |
46 | } |
| 46 | |
47 | |
| 47 | ################################################################################ |
48 | ################################################################################ |
| … | |
… | |
| 63 | # the subclass. Generic implementations of &title and &body are provided. |
64 | # the subclass. Generic implementations of &title and &body are provided. |
| 64 | # |
65 | # |
| 65 | sub go { |
66 | sub go { |
| 66 | my $self = shift; |
67 | my $self = shift; |
| 67 | my $r = $self->{r}; |
68 | my $r = $self->{r}; |
| 68 | my $courseEnvironment = $self->{courseEnvironment}; |
69 | my $courseEnvironment = $self->{ce}; |
| 69 | |
70 | |
| 70 | $self->pre_header_initialize(@_) if $self->can("pre_header_initialize"); |
71 | $self->pre_header_initialize(@_) if $self->can("pre_header_initialize"); |
| 71 | $self->header(@_); |
72 | $self->header(@_); |
| 72 | return OK if $r->header_only; |
73 | return OK if $r->header_only; |
| 73 | |
74 | |
| … | |
… | |
| 87 | # parsed out of the escape itself (i.e. ARG1 => FOO, ARG2 => BAR) |
88 | # parsed out of the escape itself (i.e. ARG1 => FOO, ARG2 => BAR) |
| 88 | # |
89 | # |
| 89 | sub template { |
90 | sub template { |
| 90 | my ($self, $templateFile) = (shift, shift); |
91 | my ($self, $templateFile) = (shift, shift); |
| 91 | my $r = $self->{r}; |
92 | my $r = $self->{r}; |
| 92 | my $courseEnvironment = $self->{courseEnvironment}; |
93 | my $courseEnvironment = $self->{ce}; |
| 93 | my @ifstack = (1); # Start off in printing mode |
94 | my @ifstack = (1); # Start off in printing mode |
| 94 | # say $ifstack[-1] to get the result of the last <#!--if--> |
95 | # say $ifstack[-1] to get the result of the last <#!--if--> |
| 95 | |
96 | |
| 96 | # so even though the variable $/ APPEARS to contain a newline, |
97 | # so even though the variable $/ APPEARS to contain a newline, |
| 97 | # <TEMPLATE> is slurping the whole file into the first element of |
98 | # <TEMPLATE> is slurping the whole file into the first element of |
| … | |
… | |
| 242 | my $self = shift; |
243 | my $self = shift; |
| 243 | my %args = %{ shift() }; |
244 | my %args = %{ shift() }; |
| 244 | my $tail = shift; |
245 | my $tail = shift; |
| 245 | my @links = @_; |
246 | my @links = @_; |
| 246 | my $auth = $self->url_authen_args; |
247 | my $auth = $self->url_authen_args; |
| 247 | my $ce = $self->{courseEnvironment}; |
248 | my $ce = $self->{ce}; |
| 248 | my $prefix = $ce->{webworkURLs}->{htdocs}."/images"; |
249 | my $prefix = $ce->{webworkURLs}->{htdocs}."/images"; |
| 249 | my @result; |
250 | my @result; |
| 250 | while (@links) { |
251 | while (@links) { |
| 251 | my $name = shift @links; |
252 | my $name = shift @links; |
| 252 | my $url = shift @links; |
253 | my $url = shift @links; |
| … | |
… | |
| 273 | sub hidden_fields($;@) { |
274 | sub hidden_fields($;@) { |
| 274 | my $self = shift; |
275 | my $self = shift; |
| 275 | my $r = $self->{r}; |
276 | my $r = $self->{r}; |
| 276 | my @fields = @_; |
277 | my @fields = @_; |
| 277 | @fields or @fields = $r->param; |
278 | @fields or @fields = $r->param; |
| 278 | my $courseEnvironment = $self->{courseEnvironment}; |
279 | my $courseEnvironment = $self->{ce}; |
| 279 | my $html = ""; |
280 | my $html = ""; |
| 280 | |
281 | |
| 281 | foreach my $param (@fields) { |
282 | foreach my $param (@fields) { |
| 282 | my $value = $r->param($param); |
283 | my $value = $r->param($param); |
| 283 | $html .= CGI::input({-type=>"hidden",-name=>"$param",-value=>"$value"}); |
284 | $html .= CGI::input({-type=>"hidden",-name=>"$param",-value=>"$value"}); |
| … | |
… | |
| 300 | sub url_args($;@) { |
301 | sub url_args($;@) { |
| 301 | my $self = shift; |
302 | my $self = shift; |
| 302 | my $r = $self->{r}; |
303 | my $r = $self->{r}; |
| 303 | my @fields = @_; |
304 | my @fields = @_; |
| 304 | @fields or @fields = $r->param; |
305 | @fields or @fields = $r->param; |
| 305 | my $courseEnvironment = $self->{courseEnvironment}; |
306 | my $courseEnvironment = $self->{ce}; |
| 306 | |
307 | |
| 307 | my @pairs; |
308 | my @pairs; |
| 308 | foreach my $param (@fields) { |
309 | foreach my $param (@fields) { |
| 309 | my $value = $r->param($param) || ""; |
310 | my $value = $r->param($param) || ""; |
| 310 | push @pairs, uri_escape($param) . "=" . uri_escape($value); |
311 | push @pairs, uri_escape($param) . "=" . uri_escape($value); |
| … | |
… | |
| 428 | # *** drunk code. rewrite. |
429 | # *** drunk code. rewrite. |
| 429 | # also, this should be structured s.t. subclasses can add items to the links |
430 | # also, this should be structured s.t. subclasses can add items to the links |
| 430 | # area, i.e. "stacking" |
431 | # area, i.e. "stacking" |
| 431 | sub links { |
432 | sub links { |
| 432 | my $self = shift; |
433 | my $self = shift; |
| 433 | my $ce = $self->{courseEnvironment}; |
434 | my $ce = $self->{ce}; |
| 434 | my $userName = $self->{r}->param("user"); |
435 | my $userName = $self->{r}->param("user"); |
| 435 | my $courseName = $ce->{courseName}; |
436 | my $courseName = $ce->{courseName}; |
| 436 | my $root = $ce->{webworkURLs}->{root}; |
437 | my $root = $ce->{webworkURLs}->{root}; |
| 437 | my $permLevel = WeBWorK::DB::Auth->new($ce)->getPermissions($userName); |
438 | my $permLevel = WeBWorK::DB::Auth->new($ce)->getPermissions($userName); |
| 438 | my $key = WeBWorK::DB::Auth->new($ce)->getKey($userName); |
439 | my $key = WeBWorK::DB::Auth->new($ce)->getKey($userName); |