[system] / trunk / webwork2 / lib / WeBWorK / ContentGenerator / Instructor / SendMail.pm Repository:
ViewVC logotype

Diff of /trunk/webwork2/lib/WeBWorK/ContentGenerator/Instructor/SendMail.pm

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

Revision 1950 Revision 2035
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.21 2004/04/05 19:33:03 gage Exp $ 4# $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/SendMail.pm,v 1.25 2004/05/05 01:53:51 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.
155# Determine the file name to save message into 155# Determine the file name to save message into
156################################################################# 156#################################################################
157 my $output_file = 'FIXME no output file specified'; 157 my $output_file = 'FIXME no output file specified';
158 if (defined($action) and $action eq 'Save as Default') { 158 if (defined($action) and $action eq 'Save as Default') {
159 $output_file = $default_msg_file; 159 $output_file = $default_msg_file;
160 } elsif ( defined($action) and ($action =~/save/i) and defined($savefilename) ){ 160 } elsif ( defined($action) and ($action =~/save/i) and defined($savefilename) and $savefilename ){
161 $output_file = $savefilename; 161 $output_file = $savefilename;
162 } elsif ( defined($input_file) ) { 162 } elsif ( defined($input_file) ) {
163 $output_file = $input_file; 163 $output_file = $input_file;
164 } 164 }
165# warn "FIXME savefilename $savefilename output file $output_file"; 165
166 ################################################################# 166 #################################################################
167 # Sanity check on save file name 167 # Sanity check on save file name
168 ################################################################# 168 #################################################################
169 169
170 if ($output_file =~ /^[~.]/ || $output_file =~ /\.\./) { 170 if ($output_file =~ /^[~.]/ || $output_file =~ /\.\./) {
186 186
187############################################################################################# 187#############################################################################################
188# Determine input source 188# Determine input source
189############################################################################################# 189#############################################################################################
190 my $input_source = ( defined( $r->param('body') ) and $action ne 'Open' ) ? 'form' : 'file'; 190 my $input_source = ( defined( $r->param('body') ) and $action ne 'Open' ) ? 'form' : 'file';
191# warn "FIXME input source is $input_source from $input_file"; 191
192############################################################################################# 192#############################################################################################
193# Get inputs 193# Get inputs
194############################################################################################# 194#############################################################################################
195 my($from, $replyTo, $r_text, $subject); 195 my($from, $replyTo, $r_text, $subject);
196 if ($input_source eq 'file') { 196 if ($input_source eq 'file') {
197# warn "FIXME obtaining source from $emailDirectory/$input_file"; 197
198 ($from, $replyTo,$subject,$r_text) = $self->read_input_file("$emailDirectory/$input_file"); 198 ($from, $replyTo,$subject,$r_text) = $self->read_input_file("$emailDirectory/$input_file");
199# warn "FIXME Done reading source"; 199
200 200
201 } elsif ($input_source eq 'form') { 201 } elsif ($input_source eq 'form') {
202 # read info from the form 202 # read info from the form
203 # bail if there is no message body 203 # bail if there is no message body
204 204
249 my $script_action = ''; 249 my $script_action = '';
250 250
251 251
252 if(not defined($action) or $action eq 'Open' or $action eq $REFRESH_RESIZE_BUTTON or $action eq 'Sort by' 252 if(not defined($action) or $action eq 'Open' or $action eq $REFRESH_RESIZE_BUTTON or $action eq 'Sort by'
253 or $action eq 'Set merge file to:' ){ 253 or $action eq 'Set merge file to:' ){
254# warn "FIXME action is |$action| no further initialization required"; 254
255 return ''; 255 return '';
256 } 256 }
257 257
258 258
259 259
299 } 299 }
300 ################################################################# 300 #################################################################
301 # Save the message 301 # Save the message
302 ################################################################# 302 #################################################################
303 $self->saveProblem($temp_body, "${emailDirectory}/$output_file" ); 303 $self->saveProblem($temp_body, "${emailDirectory}/$output_file" );
304 unless ( $self->{submitError} or not -w "${emailDirectory}/$output_file" ) { # if there are no errors report success
304 $self->{message} .= "Message saved to file <code>${emailDirectory}/$output_file</code>."; 305 $self->{message} .= "Message saved to file <code>${emailDirectory}/$output_file</code>.";
305# warn "FIXME saving to ${emailDirectory}/$output_file"; 306 }
307
306 } elsif ($action eq 'Preview') { 308 } elsif ($action eq 'Preview') {
307 $self->{response} = 'preview'; 309 $self->{response} = 'preview';
308 310
309 } elsif ($action eq 'Send Email') { 311 } elsif ($action eq 'Send Email') {
310 $self->{response} = 'send_email'; 312 $self->{response} = 'send_email';
311 313
312 my @recipients = @{$self->{ra_send_to}}; 314 my @recipients = @{$self->{ra_send_to}};
315 $self->addmessage(CGI::div({class=>'ResultsWithError'},
313 warn "No recipients selected " unless @recipients; 316 "No recipients selected")) unless @recipients;
314 # get merge file 317 # get merge file
315 my $merge_file = ( defined($self->{merge_file}) ) ? $self->{merge_file} : 'None'; 318 my $merge_file = ( defined($self->{merge_file}) ) ? $self->{merge_file} : 'None';
316 my $delimiter = ','; 319 my $delimiter = ',';
317 my $rh_merge_data = $self->read_scoring_file("$merge_file", "$delimiter"); 320 my $rh_merge_data = $self->read_scoring_file("$merge_file", "$delimiter");
318 unless (ref($rh_merge_data) ) { 321 unless (ref($rh_merge_data) ) {
325 foreach my $recipient (@recipients) { 328 foreach my $recipient (@recipients) {
326 #warn "FIXME sending email to $recipient"; 329 #warn "FIXME sending email to $recipient";
327 my $ur = $self->{db}->getUser($recipient); #checked 330 my $ur = $self->{db}->getUser($recipient); #checked
328 die "record for user $recipient not found" unless $ur; 331 die "record for user $recipient not found" unless $ur;
329 unless ($ur->email_address) { 332 unless ($ur->email_address) {
333 $self->addmessage(CGI::div({class=>'ResultsWithError'},
330 warn "user $recipient does not have an email address -- skipping"; 334 "user $recipient does not have an email address -- skipping"));
331 next; 335 next;
332 } 336 }
333 my ($msg, $preview_header); 337 my ($msg, $preview_header);
334 eval{ ($msg,$preview_header) = $self->process_message($ur,$rh_merge_data); }; 338 eval{ ($msg,$preview_header) = $self->process_message($ur,$rh_merge_data); };
335 warn "There were errors in processing user $ur, merge file $merge_file. $@" if $@; 339 warn "There were errors in processing user $ur, merge file $merge_file. $@" if $@;
699 # last field is empty, the last element of the returned 703 # last field is empty, the last element of the returned
700 # array is also empty (unlike what the perl split command 704 # array is also empty (unlike what the perl split command
701 # would return). E.G. @lineArray=&getRecord(\$delimitedLine). 705 # would return). E.G. @lineArray=&getRecord(\$delimitedLine).
702 706
703 my(@lineArray); 707 my(@lineArray);
704 $line.=$delimiter; # add 'A' to end of line so that 708 $line.="${delimiter}___"; # add final field which must be non-empty
705 # last field is never empty
706 @lineArray = split(/\s*${delimiter}\s*/,$line); 709 @lineArray = split(/\s*${delimiter}\s*/,$line); # split line into fields
707 $lineArray[0] =~s/^\s*//; # remove white space from first element 710 $lineArray[0] =~s/^\s*//; # remove white space from first element
711 pop @lineArray; # remove the last artificial field
708 @lineArray; 712 @lineArray;
709} 713}
710 714
711sub process_message { 715sub process_message {
712 my $self = shift; 716 my $self = shift;

Legend:
Removed from v.1950  
changed lines
  Added in v.2035

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9