| 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.15 2003/12/18 23:15:34 sh002i Exp $ |
4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/SendMail.pm,v 1.16 2004/01/17 19:30:22 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. |
| … | |
… | |
| 27 | use warnings; |
27 | use warnings; |
| 28 | use CGI qw(); |
28 | use CGI qw(); |
| 29 | #use HTML::Entities; |
29 | #use HTML::Entities; |
| 30 | use Mail::Sender; |
30 | use Mail::Sender; |
| 31 | |
31 | |
| 32 | my $REFRESH_RESIZE_BUTTON = "Refresh and Resize"; # 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 = $self->{db}; |
| 37 | my $ce = $self->{ce}; |
37 | my $ce = $self->{ce}; |
| … | |
… | |
| 162 | ################################################################# |
162 | ################################################################# |
| 163 | # Sanity check on save file name |
163 | # Sanity check on save file name |
| 164 | ################################################################# |
164 | ################################################################# |
| 165 | |
165 | |
| 166 | if ($output_file =~ /^[~.]/ || $output_file =~ /\.\./) { |
166 | if ($output_file =~ /^[~.]/ || $output_file =~ /\.\./) { |
| 167 | $self->submission_error("For security reasons, you cannot specify a merge file from a directory", |
167 | $self->submission_error("For security reasons, you cannot specify a message file from a directory", |
| 168 | "higher than the email directory (you can't use ../blah/blah). ", |
168 | "higher than the email directory (you can't use ../blah/blah for example). ", |
| 169 | "Please specify a different file or move the needed file to the email directory", |
169 | "Please specify a different file or move the needed file to the email directory", |
| 170 | ); |
170 | ); |
| 171 | } |
171 | } |
| 172 | unless ($output_file =~ m|\.msg$| ) { |
172 | unless ($output_file =~ m|\.msg$| ) { |
| 173 | $self->submission_error("Invalid file name.", |
173 | $self->submission_error("Invalid file name.", |
| … | |
… | |
| 594 | ############################################################################################# |
594 | ############################################################################################# |
| 595 | # merge file fragment and message text area field |
595 | # merge file fragment and message text area field |
| 596 | ############################################################################################# |
596 | ############################################################################################# |
| 597 | my @tmp2; |
597 | my @tmp2; |
| 598 | eval{ @tmp2= @{$rh_merge_data->{ $db->getUser($preview_user)->student_id } };}; # checked |
598 | eval{ @tmp2= @{$rh_merge_data->{ $db->getUser($preview_user)->student_id } };}; # checked |
| 599 | if ($@) { |
599 | if ($@ and $merge_file ne 'None') { |
| 600 | # print CGI::p( "Couldn't get merge data for $preview_user", CGI::br(), $@) ; |
|
|
| 601 | print "No merge data for $preview_user in merge file: <$merge_file>",CGI::br(); |
600 | print "No merge data for $preview_user in merge file: <$merge_file>",CGI::br(); |
| 602 | } else { |
601 | } else { |
| 603 | print CGI::pre("",data_format(0..($#tmp2)),"\n", data_format(@tmp2)); |
602 | print CGI::pre("",data_format(0..($#tmp2)),"\n", data_format(@tmp2)); |
| 604 | } |
603 | } |
| 605 | #create a textbox with the subject and a textarea with the message |
604 | #create a textbox with the subject and a textarea with the message |
| … | |
… | |
| 632 | # Utility methods |
631 | # Utility methods |
| 633 | ############################################################################## |
632 | ############################################################################## |
| 634 | sub submission_error { |
633 | sub submission_error { |
| 635 | my $self = shift; |
634 | my $self = shift; |
| 636 | my $msg = join( " ", @_); |
635 | my $msg = join( " ", @_); |
| 637 | $self->{submitError} .= CGI::br().$msg; #CGI::b(HTML::Entities::encode($msg)); |
636 | $self->{submitError} .= CGI::br().$msg; |
| 638 | # qq{Please hit the "<B>Back</B>" button on your browser to |
|
|
| 639 | # try again, or notify your web master |
|
|
| 640 | # if you believe this message is in error. |
|
|
| 641 | # }; |
|
|
| 642 | return; |
637 | return; |
| 643 | } |
638 | } |
| 644 | |
639 | |
| 645 | sub saveProblem { |
640 | sub saveProblem { |
| 646 | my $self = shift; |
641 | my $self = shift; |
| … | |
… | |
| 693 | my $self = shift; |
688 | my $self = shift; |
| 694 | return $self->read_dir($self->{ce}->{courseDirs}->{email}, '\\.msg$'); |
689 | return $self->read_dir($self->{ce}->{courseDirs}->{email}, '\\.msg$'); |
| 695 | } |
690 | } |
| 696 | sub get_merge_file_names { |
691 | sub get_merge_file_names { |
| 697 | my $self = shift; |
692 | my $self = shift; |
| 698 | return 'None', $self->read_dir($self->{ce}->{courseDirs}->{scoring}, '\\.csv$'); |
693 | return 'None', $self->read_dir($self->{ce}->{courseDirs}->{scoring}, '\\.csv$'); #FIXME ? check that only readable files are listed. |
| 699 | } |
694 | } |
| 700 | |
695 | |
| 701 | |
696 | |
| 702 | sub getRecord { |
697 | sub getRecord { |
| 703 | my $self = shift; |
698 | my $self = shift; |
| … | |
… | |
| 722 | sub process_message { |
717 | sub process_message { |
| 723 | my $self = shift; |
718 | my $self = shift; |
| 724 | my $ur = shift; |
719 | my $ur = shift; |
| 725 | my $rh_merge_data = shift; |
720 | my $rh_merge_data = shift; |
| 726 | my $text = defined($self->{r_text}) ? ${ $self->{r_text} }: |
721 | my $text = defined($self->{r_text}) ? ${ $self->{r_text} }: |
| 727 | 'FIXME no text was produced by initialization!!'; |
722 | 'FIXME no text was produced by initialization!!'; |
|
|
723 | my $merge_file = ( defined($self->{merge_file}) ) ? $self->{merge_file} : 'None'; |
| 728 | #user macros that can be used in the email message |
724 | #user macros that can be used in the email message |
| 729 | my $SID = $ur->student_id; |
725 | my $SID = $ur->student_id; |
| 730 | my $FN = $ur->first_name; |
726 | my $FN = $ur->first_name; |
| 731 | my $LN = $ur->last_name; |
727 | my $LN = $ur->last_name; |
| 732 | my $SECTION = $ur->section; |
728 | my $SECTION = $ur->section; |
| 733 | my $RECITATION = $ur->recitation; |
729 | my $RECITATION = $ur->recitation; |
| 734 | my $STATUS = $ur->status; |
730 | my $STATUS = $ur->status; |
| 735 | my $EMAIL = $ur->email_address; |
731 | my $EMAIL = $ur->email_address; |
| 736 | my $LOGIN = $ur->user_id; |
732 | my $LOGIN = $ur->user_id; |
|
|
733 | |
| 737 | # get record from merge file |
734 | # get record from merge file |
| 738 | # FIXME this is inefficient. The info should be cached |
735 | # FIXME this is inefficient. The info should be cached |
| 739 | my @COL = defined($rh_merge_data->{$SID}) ? @{$rh_merge_data->{$SID} } : (); |
736 | my @COL = defined($rh_merge_data->{$SID}) ? @{$rh_merge_data->{$SID} } : (); |
|
|
737 | if ($merge_file ne 'None' && not defined($rh_merge_data->{$SID}) ) { |
| 740 | $self->submission_error( "No merge data for $SID $FN $LN $LOGIN") unless defined($rh_merge_data->{$SID}); |
738 | $self->submission_error( "No merge data for $SID $FN $LN $LOGIN"); |
|
|
739 | } |
| 741 | |
740 | |
| 742 | my $endCol = @COL; |
741 | my $endCol = @COL; |
| 743 | # for safety, only evaluate special variables |
742 | # for safety, only evaluate special variables |
| 744 | my $msg = $text; |
743 | my $msg = $text; |
| 745 | $msg =~ s/(\$SID)/eval($1)/ge; |
744 | $msg =~ s/(\$SID)/eval($1)/ge; |