| 1 | ################################################################################ |
1 | ################################################################################ |
| 2 | # WeBWorK Online Homework Delivery System |
2 | # WeBWorK Online Homework Delivery System |
| 3 | # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ |
3 | # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ |
| 4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/SendMail.pm,v 1.17 2004/01/21 01:16:15 gage Exp $ |
4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/SendMail.pm,v 1.18 2004/02/03 00:53:31 gage Exp $ |
| 5 | # |
5 | # |
| 6 | # This program is free software; you can redistribute it and/or modify it under |
6 | # This program is free software; you can redistribute it and/or modify it under |
| 7 | # the terms of either: (a) the GNU General Public License as published by the |
7 | # the terms of either: (a) the GNU General Public License as published by the |
| 8 | # Free Software Foundation; either version 2, or (at your option) any later |
8 | # Free Software Foundation; either version 2, or (at your option) any later |
| 9 | # version, or (b) the "Artistic License" which comes with this package. |
9 | # version, or (b) the "Artistic License" which comes with this package. |
| … | |
… | |
| 30 | use Mail::Sender; |
30 | use Mail::Sender; |
| 31 | |
31 | |
| 32 | my $REFRESH_RESIZE_BUTTON = "Reorder, Resize and Update"; # handle submit value idiocy |
32 | my $REFRESH_RESIZE_BUTTON = "Reorder, Resize and Update"; # handle submit value idiocy |
| 33 | sub initialize { |
33 | sub initialize { |
| 34 | my ($self) = @_; |
34 | my ($self) = @_; |
| 35 | my $r = $self->{r}; |
35 | my $r = $self->r; |
| 36 | my $db = $self->{db}; |
36 | my $db = $r->db; |
| 37 | my $ce = $self->{ce}; |
37 | my $ce = $r->ce; |
| 38 | my $authz = $self->{authz}; |
38 | my $authz = $r->authz; |
| 39 | my $user = $r->param('user'); |
39 | my $user = $r->param('user'); |
| 40 | |
40 | |
| 41 | unless ($authz->hasPermissions($user, "send_mail")) { |
41 | unless ($authz->hasPermissions($user, "send_mail")) { |
| 42 | $self->{submitError} = "You are not authorized to send mail to students."; |
42 | $self->{submitError} = "You are not authorized to send mail to students."; |
| 43 | return; |
43 | return; |
| 44 | } |
44 | } |
| … | |
… | |
| 362 | |
362 | |
| 363 | |
363 | |
| 364 | } #end initialize |
364 | } #end initialize |
| 365 | |
365 | |
| 366 | |
366 | |
| 367 | sub title { |
|
|
| 368 | my $self = shift; |
|
|
| 369 | return 'Mail Merge'; |
|
|
| 370 | } |
|
|
| 371 | |
367 | |
| 372 | sub path { |
368 | |
| 373 | my $self = shift; |
|
|
| 374 | my $args = $_[-1]; |
|
|
| 375 | |
|
|
| 376 | my $ce = $self->{ce}; |
|
|
| 377 | my $root = $ce->{webworkURLs}->{root}; |
|
|
| 378 | my $courseName = $ce->{courseName}; |
|
|
| 379 | return $self->pathMacro($args, |
|
|
| 380 | "Home" => "$root", |
|
|
| 381 | $courseName => "$root/$courseName", |
|
|
| 382 | 'Instructor Tools' => "$root/$courseName/instructor", |
|
|
| 383 | "Mail Merge" => '', # "$root/$courseName/instructor/send_mail", |
|
|
| 384 | ); |
|
|
| 385 | } |
|
|
| 386 | |
369 | |
| 387 | sub body { |
370 | sub body { |
| 388 | my ($self, $setID) = @_; |
371 | my ($self) = @_; |
|
|
372 | my $r = $self->r; |
|
|
373 | my $urlpath = $r->urlpath; |
|
|
374 | my $setID = $urlpath->arg("setID"); |
| 389 | my $response = (defined($self->{response}))? $self->{response} : ''; |
375 | my $response = (defined($self->{response}))? $self->{response} : ''; |
| 390 | if ($response eq 'preview') { |
376 | if ($response eq 'preview') { |
| 391 | $self->print_preview($setID); |
377 | $self->print_preview($setID); |
| 392 | } elsif (($response eq 'send_email')){ |
378 | } elsif (($response eq 'send_email')){ |
| 393 | $self->{message} .= CGI::h3("Email sent to "). join(" ", @{$self->{ra_send_to}}); |
379 | $self->{message} .= CGI::h3("Email sent to "). join(" ", @{$self->{ra_send_to}}); |
| … | |
… | |
| 396 | $self->print_form($setID); |
382 | $self->print_form($setID); |
| 397 | } |
383 | } |
| 398 | |
384 | |
| 399 | } |
385 | } |
| 400 | sub print_preview { |
386 | sub print_preview { |
| 401 | my ($self, $setID) = @_; |
387 | my ($self) = @_; |
|
|
388 | my $r = $self->r; |
|
|
389 | my $urlpath = $r->urlpath; |
|
|
390 | my $setID = $urlpath->arg("setID"); |
|
|
391 | |
| 402 | # get preview user |
392 | # get preview user |
| 403 | my $ur = $self->{db}->getUser($self->{preview_user}); #checked |
393 | my $ur = $r->db->getUser($self->{preview_user}); #checked |
| 404 | die "record for preview user ".$self->{preview_user}. " not found." unless $ur; |
394 | die "record for preview user ".$self->{preview_user}. " not found." unless $ur; |
| 405 | |
395 | |
| 406 | # get merge file |
396 | # get merge file |
| 407 | my $merge_file = ( defined($self->{merge_file}) ) ? $self->{merge_file} : 'None'; |
397 | my $merge_file = ( defined($self->{merge_file}) ) ? $self->{merge_file} : 'None'; |
| 408 | my $delimiter = ','; |
398 | my $delimiter = ','; |
| … | |
… | |
| 430 | |
420 | |
| 431 | ); |
421 | ); |
| 432 | |
422 | |
| 433 | } |
423 | } |
| 434 | sub print_form { |
424 | sub print_form { |
| 435 | my ($self, $setID) = @_; |
425 | my ($self) = @_; |
| 436 | my $r = $self->{r}; |
426 | my $r = $self->r; |
| 437 | my $authz = $self->{authz}; |
427 | my $urlpath = $r->urlpath; |
|
|
428 | my $authz = $r->authz; |
|
|
429 | my $db = $r->db; |
|
|
430 | my $ce = $r->ce; |
|
|
431 | my $courseName = $urlpath->arg("courseID"); |
|
|
432 | my $setID = $urlpath->arg("setID"); |
| 438 | my $user = $r->param('user'); |
433 | my $user = $r->param('user'); |
| 439 | my $db = $self->{db}; |
434 | |
| 440 | my $ce = $self->{ce}; |
|
|
| 441 | my $root = $ce->{webworkURLs}->{root}; |
435 | my $root = $ce->{webworkURLs}->{root}; |
| 442 | my $courseName = $ce->{courseName}; |
436 | |
| 443 | |
437 | |
| 444 | return CGI::em("You are not authorized to access the Instructor tools.") unless $authz->hasPermissions($user, "access_instructor_tools"); |
438 | return CGI::em("You are not authorized to access the Instructor tools.") unless $authz->hasPermissions($user, "access_instructor_tools"); |
| 445 | |
439 | |
| 446 | my $userTemplate = $db->newUser; |
440 | my $userTemplate = $db->newUser; |
| 447 | my $permissionLevelTemplate = $db->newPermissionLevel; |
441 | my $permissionLevelTemplate = $db->newPermissionLevel; |