[system] / branches / rel-2-3-dev / webwork2 / lib / WeBWorK / ContentGenerator / Instructor / SendMail.pm Repository:
ViewVC logotype

Diff of /branches/rel-2-3-dev/webwork2/lib/WeBWorK/ContentGenerator/Instructor/SendMail.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1729 Revision 1730
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.
27use warnings; 27use warnings;
28use CGI qw(); 28use CGI qw();
29#use HTML::Entities; 29#use HTML::Entities;
30use Mail::Sender; 30use Mail::Sender;
31 31
32my $REFRESH_RESIZE_BUTTON = "Refresh and Resize"; # handle submit value idiocy 32my $REFRESH_RESIZE_BUTTON = "Reorder, Resize and Update"; # handle submit value idiocy
33sub initialize { 33sub 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##############################################################################
634sub submission_error { 633sub 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 &quot;<B>Back</B>&quot; 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
645sub saveProblem { 640sub 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}
696sub get_merge_file_names { 691sub 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
702sub getRecord { 697sub getRecord {
703 my $self = shift; 698 my $self = shift;
722sub process_message { 717sub 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;

Legend:
Removed from v.1729  
changed lines
  Added in v.1730

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9