[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 2787 Revision 4202
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-2006 The WeBWorK Project, http://openwebwork.sf.net/
4# $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/SendMail.pm,v 1.36 2004/09/14 18:55:58 apizer Exp $ 4# $CVSHeader: webwork2/lib/WeBWorK/ContentGenerator/Instructor/SendMail.pm,v 1.46 2006/01/25 23:13:53 sh002i 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.
23 23
24=cut 24=cut
25 25
26use strict; 26use strict;
27use warnings; 27use warnings;
28use CGI qw(); 28use CGI qw(-nosticky );
29#use HTML::Entities; 29#use HTML::Entities;
30use Mail::Sender; 30use Mail::Sender;
31use Text::Wrap qw(wrap);
31use WeBWorK::HTML::ScrollingRecordList qw/scrollingRecordList/; 32use WeBWorK::HTML::ScrollingRecordList qw/scrollingRecordList/;
32use WeBWorK::Utils::FilterRecords qw/filterRecords/; 33use WeBWorK::Utils::FilterRecords qw/filterRecords/;
33 34
34my $REFRESH_RESIZE_BUTTON = "Set preview to: "; # handle submit value idiocy 35#my $REFRESH_RESIZE_BUTTON = "Set preview to: "; # handle submit value idiocy
36my $UPDATE_SETTINGS_BUTTON = "Update settings and refresh page"; # handle submit value idiocy
35sub initialize { 37sub initialize {
36 my ($self) = @_; 38 my ($self) = @_;
37 my $r = $self->r; 39 my $r = $self->r;
38 my $db = $r->db; 40 my $db = $r->db;
39 my $ce = $r->ce; 41 my $ce = $r->ce;
77 $self->{rows} = (defined($r->param('rows'))) ? $r->param('rows') : $ce->{mail}->{editor_window_rows}; 79 $self->{rows} = (defined($r->param('rows'))) ? $r->param('rows') : $ce->{mail}->{editor_window_rows};
78 $self->{columns} = (defined($r->param('columns'))) ? $r->param('columns') : $ce->{mail}->{editor_window_columns}; 80 $self->{columns} = (defined($r->param('columns'))) ? $r->param('columns') : $ce->{mail}->{editor_window_columns};
79 $self->{default_msg_file} = $default_msg_file; 81 $self->{default_msg_file} = $default_msg_file;
80 $self->{old_default_msg_file} = $old_default_msg_file; 82 $self->{old_default_msg_file} = $old_default_msg_file;
81 $self->{merge_file} = (defined($r->param('merge_file' ))) ? $r->param('merge_file') : 'None'; 83 $self->{merge_file} = (defined($r->param('merge_file' ))) ? $r->param('merge_file') : 'None';
82 $self->{preview_user} = (defined($r->param('preview_user'))) ? $r->param('preview_user') : $user; 84 #$self->{preview_user} = (defined($r->param('preview_user'))) ? $r->param('preview_user') : $user;
83 85 # an expermiment -- share the scrolling list for preivew and sendTo actions.
86 my @classList = (defined($r->param('classList'))) ? $r->param('classList') : ($user);
87 $self->{preview_user} = $classList[0] || $user;
84 88
85############################################################################################# 89#############################################################################################
86# gather database data 90# gather database data
87############################################################################################# 91#############################################################################################
88 # FIXME this might be better done in body? We don't always need all of this data. or do we? 92 # FIXME this might be better done in body? We don't always need all of this data. or do we?
159# I wasn't able to make this work 163# I wasn't able to make this work
160# I edited the selection button to make that clear. 164# I edited the selection button to make that clear.
161# 165#
162 166
163 foreach my $ur (@user_records) { 167 foreach my $ur (@user_records) {
164 push(@send_to,$ur->user_id) if $ur->status eq 'C' and not($ur->user_id =~ /practice/); 168 push(@send_to,$ur->user_id)
169 if $ce->status_abbrev_has_behavior($ur->status, "include_in_email")
170 and not $ur->user_id =~ /practice/;
165 } 171 }
166 } elsif (defined($recipients) and $recipients eq 'studentID' ) { 172 } elsif (defined($recipients) and $recipients eq 'studentID' ) {
167 @send_to = $r->param('classList'); 173 @send_to = $r->param('classList');
168 } else { 174 } else {
169 # no recipients have been defined -- probably the first time on the page 175 # no recipients have been defined -- probably the first time on the page
257 # bail if there is no message body 263 # bail if there is no message body
258 264
259 $from = $r->param('from'); 265 $from = $r->param('from');
260 $replyTo = $r->param('replyTo'); 266 $replyTo = $r->param('replyTo');
261 $subject = $r->param('subject'); 267 $subject = $r->param('subject');
262 my $body = $r->param('body'); 268 my $body = $r->param('body');
263 # Sanity check: body must contain non-white space 269 # Sanity check: body must contain non-white space
264 $self->addbadmessage(CGI::p('You didn\'t enter any message.')) unless ($r->param('body') =~ /\S/); 270 $self->addbadmessage(CGI::p('You didn\'t enter any message.')) unless ($r->param('body') =~ /\S/);
265 $r_text = \$body; 271 $r_text = \$body;
266 272
267 } 273 }
301############################################################################################# 307#############################################################################################
302 my $to = $r->param('To'); 308 my $to = $r->param('To');
303 my $script_action = ''; 309 my $script_action = '';
304 310
305 311
306 if(not defined($action) or $action eq 'Open' or $action eq $REFRESH_RESIZE_BUTTON or $action eq 'Sort by' 312 if(not defined($action) or $action eq 'Open'
307 or $action eq 'Set merge file to:' ){ 313 or $action eq $UPDATE_SETTINGS_BUTTON ){
308 314
309 return ''; 315 return '';
310 } 316 }
311 317
312 318
362 } elsif ($action eq 'Preview message') { 368 } elsif ($action eq 'Preview message') {
363 $self->{response} = 'preview'; 369 $self->{response} = 'preview';
364 370
365 } elsif ($action eq 'Send Email') { 371 } elsif ($action eq 'Send Email') {
366 $self->{response} = 'send_email'; 372 $self->{response} = 'send_email';
367 373
374 # check that recipients have been selected.
368 my @recipients = @{$self->{ra_send_to}}; 375 my @recipients = @{$self->{ra_send_to}};
369 $self->addbadmessage(CGI::p("No recipients selected ")) unless @recipients; 376 $self->addbadmessage(CGI::p("No recipients selected ")) unless @recipients;
370 # get merge file 377 # get merge file
371 my $merge_file = ( defined($self->{merge_file}) ) ? $self->{merge_file} : 'None'; 378 my $merge_file = ( defined($self->{merge_file}) ) ? $self->{merge_file} : 'None';
372 my $delimiter = ','; 379 my $delimiter = ',';
374 unless (ref($rh_merge_data) ) { 381 unless (ref($rh_merge_data) ) {
375 $self->addbadmessage(CGI::p("No merge data file")); 382 $self->addbadmessage(CGI::p("No merge data file"));
376 $self->addbadmessage(CGI::p("Can't read merge file $merge_file. No message sent")); 383 $self->addbadmessage(CGI::p("Can't read merge file $merge_file. No message sent"));
377 return; 384 return;
378 } ; 385 } ;
386 if (@recipients) {
387 $self->{rh_merge_data} = $rh_merge_data;
388 $self->{smtpServer} = $ce->{mail}->{smtpServer};
389 my $post_connection_action = sub {
390 my $r = shift;
391 my $result_message = $self->mail_message_to_recipients();
392 $self->email_notification($result_message);
393 };
394 $r->post_connection($post_connection_action) ;
379 395 }
380
381 foreach my $recipient (@recipients) { 396# foreach my $recipient (@recipients) {
382 #warn "FIXME sending email to $recipient"; 397# #warn "FIXME sending email to $recipient";
383 my $ur = $self->{db}->getUser($recipient); #checked 398# my $ur = $self->{db}->getUser($recipient); #checked
384 die "record for user $recipient not found" unless $ur; 399# die "record for user $recipient not found" unless $ur;
385 unless ($ur->email_address) { 400# unless ($ur->email_address) {
386 $self->addbadmessage(CGI::p("user $recipient does not have an email address -- skipping")); 401# $self->addbadmessage(CGI::p("user $recipient does not have an email address -- skipping"));
387 next; 402# next;
388 } 403# }
389 my ($msg, $preview_header); 404# my ($msg, $preview_header);
390 eval{ ($msg,$preview_header) = $self->process_message($ur,$rh_merge_data); }; 405# eval{ ($msg,$preview_header) = $self->process_message($ur,$rh_merge_data); };
391 $self->addbadmessage(CGI::p("There were errors in processing user $ur, merge file $merge_file. $@")) if $@; 406# $self->addbadmessage(CGI::p("There were errors in processing user $ur, merge file $merge_file. $@")) if $@;
392 my $mailer = Mail::Sender->new({ 407# my $mailer = Mail::Sender->new({
393 from => $from, 408# from => $from,
394 to => $ur->email_address, 409# to => $ur->email_address,
395 smtp => $ce->{mail}->{smtpServer}, 410# smtp => $ce->{mail}->{smtpServer},
396 subject => $subject, 411# subject => $subject,
397 headers => "X-Remote-Host: ".$r->get_remote_host(), 412# headers => "X-Remote-Host: ".$r->get_remote_host(),
398 }); 413# });
399 unless (ref $mailer) { 414# unless (ref $mailer) {
400 $self->addbadmessage(CGI::p("Failed to create a mailer for user $recipient: $Mail::Sender::Error")); 415# $self->addbadmessage(CGI::p("Failed to create a mailer for user $recipient: $Mail::Sender::Error"));
401 next; 416# next;
402 } 417# }
403 unless (ref $mailer->Open()) { 418# unless (ref $mailer->Open()) {
404 $self->addbadmessage(CGI::p("Failed to open the mailer for user $recipient: $Mail::Sender::Error")); 419# $self->addbadmessage(CGI::p("Failed to open the mailer for user $recipient: $Mail::Sender::Error"));
405 next; 420# next;
406 } 421# }
407 my $MAIL = $mailer->GetHandle() or $self->addbadmessage(CGI::p("Couldn't get handle")); 422# my $MAIL = $mailer->GetHandle() or $self->addbadmessage(CGI::p("Couldn't get handle"));
408 print $MAIL $msg || $self->addbadmessage(CGI::p("Couldn't print to $MAIL")); 423# print $MAIL $msg || $self->addbadmessage(CGI::p("Couldn't print to $MAIL"));
409 close $MAIL || $self->addbadmessage(CGI::p("Couldn't close $MAIL")); 424# close $MAIL || $self->addbadmessage(CGI::p("Couldn't close $MAIL"));
410 #warn "FIXME mailed to ", $ur->email_address, "from $from subject $subject"; 425# #warn "FIXME mailed to ", $ur->email_address, "from $from subject $subject";
411 426#
412 } 427# }
413 428
414 } else { 429 } else {
415 $self->addbadmessage(CGI::p("Didn't recognize button $action")); 430 $self->addbadmessage(CGI::p("Didn't recognize button $action"));
416 } 431 }
417 432
440 unless $authz->hasPermissions($user, "send_mail"); 455 unless $authz->hasPermissions($user, "send_mail");
441 456
442 if ($response eq 'preview') { 457 if ($response eq 'preview') {
443 $self->print_preview($setID); 458 $self->print_preview($setID);
444 } elsif (($response eq 'send_email')){ 459 } elsif (($response eq 'send_email')){
445 $self->addgoodmessage(CGI::p("Email sent to ". scalar(@{$self->{ra_send_to}})." students.")); 460 my $message = CGI::i("Email is being sent to ". scalar(@{$self->{ra_send_to}})." recipients. You will be notified"
446 $self->{message} .= CGI::i("Email sent to ". scalar(@{$self->{ra_send_to}})." students."); 461 ." by email when the task is completed. This may take several minutes if the class is large."
462 );
463 $self->addgoodmessage($message);
464 $self->{message} .= $message;
465
447 $self->print_form($setID); 466 $self->print_form($setID);
448 } else { 467 } else {
449 $self->print_form($setID); 468 $self->print_form($setID);
450 } 469 }
451 470
507 526
508 my $userTemplate = $db->newUser; 527 my $userTemplate = $db->newUser;
509 my $permissionLevelTemplate = $db->newPermissionLevel; 528 my $permissionLevelTemplate = $db->newPermissionLevel;
510 529
511 # This code will require changing if the permission and user tables ever have different keys. 530 # This code will require changing if the permission and user tables ever have different keys.
512 my @users = @{ $self->{ra_users} }; 531 my @users = sort @{ $self->{ra_users} };
513 my $ra_user_records = $self->{ra_user_records}; 532 my $ra_user_records = $self->{ra_user_records};
514 my %classlistLabels = ();# %$hr_classlistLabels; 533 my %classlistLabels = ();# %$hr_classlistLabels;
515 foreach my $ur (@{ $ra_user_records }) { 534 foreach my $ur (@{ $ra_user_records }) {
516 $classlistLabels{$ur->user_id} = $ur->user_id.': '.$ur->last_name. ', '. $ur->first_name.' -- '.$ur->section." / ".$ur->recitation; 535 $classlistLabels{$ur->user_id} = $ur->user_id.': '.$ur->last_name. ', '. $ur->first_name.' -- '.$ur->section." / ".$ur->recitation;
517 } 536 }
523 default_sort => "lnfn", 542 default_sort => "lnfn",
524 default_format => "lnfn_uid", 543 default_format => "lnfn_uid",
525 default_filters => ["all"], 544 default_filters => ["all"],
526 size => 5, 545 size => 5,
527 multiple => 1, 546 multiple => 1,
547 refresh_button_name =>'Update settings and refresh page',
528 }, @{$ra_user_records}); 548 }, @{$ra_user_records});
529 549
530############################################################################################################## 550##############################################################################################################
531 551
532 552
561 print CGI::Tr({-align=>'left',-valign=>'top'}, 581 print CGI::Tr({-align=>'left',-valign=>'top'},
562############################################################################################# 582#############################################################################################
563# first column 583# first column
564############################################################################################# 584#############################################################################################
565 585
566 CGI::td(CGI::strong("Message file: $input_file"),"\n",CGI::br(), 586 CGI::td(CGI::strong("Message file: "), $input_file,"\n",CGI::br(),
567 CGI::submit(-name=>'action', -value=>'Open'), '    ',"\n", 587 CGI::submit(-name=>'action', -value=>'Open'), '    ',"\n",
568 CGI::popup_menu(-name=>'openfilename', 588 CGI::popup_menu(-name=>'openfilename',
569 -values=>\@sorted_messages, 589 -values=>\@sorted_messages,
570 -default=>$input_file 590 -default=>$input_file
591 ),
571 ), "\n",CGI::br(), 592 "\n",CGI::br(),
572 593 CGI::strong("Save file to: "), $output_file,
573 "Save file to: $output_file","\n",CGI::br(), 594 "\n",CGI::br(),
595 CGI::strong('Merge file: '), $merge_file,
596 CGI::br(),
597 CGI::popup_menu(-name=>'merge_file',
598 -values=>\@sorted_merge_files,
599 -default=>$merge_file,
600 ), "\n",
601 "\n",
602 #CGI::hr(),
603 CGI::div({style=>"background-color: #CCCCCC"},
574 "\n", 'From:','     ', CGI::textfield(-name=>"from", -size=>30, -value=>$from, -override=>1), 604 "\n", 'From:','     ', CGI::textfield(-name=>"from", -size=>30, -value=>$from, -override=>1),
575 "\n", CGI::br(),'Reply-To: ', CGI::textfield(-name=>"replyTo", -size=>30, -value=>$replyTo, -override=>1), 605 "\n", CGI::br(),'Reply-To: ', CGI::textfield(-name=>"replyTo", -size=>30, -value=>$replyTo, -override=>1),
576 "\n", CGI::br(),'Subject: ', CGI::br(), CGI::textarea(-name=>'subject', -default=>$subject, -rows=>3,-columns=>30, -override=>1), 606 "\n", CGI::br(),'Subject: ', CGI::br(), CGI::textarea(-name=>'subject', -default=>$subject, -rows=>3,-columns=>30, -override=>1),
607 ),
608 #CGI::hr(),
609 CGI::submit(-name=>'action', -value=>$UPDATE_SETTINGS_BUTTON),
610
577 ), 611 ),
578############################################################################################# 612#############################################################################################
579# second column 613# second column
580############################################################################################# 614#############################################################################################
581# CGI::td({-align=>'left',style=>'font-size:smaller'}, 615# CGI::td({-align=>'left',style=>'font-size:smaller'},
589## Edit by Mark to insert scrolling list 623## Edit by Mark to insert scrolling list
590 CGI::td({-style=>"width:33%"},CGI::strong("Send to:"), 624 CGI::td({-style=>"width:33%"},CGI::strong("Send to:"),
591 CGI::radio_group(-name=>'radio', -values=>['all_students','studentID'], 625 CGI::radio_group(-name=>'radio', -values=>['all_students','studentID'],
592 -labels=>{all_students=>'All students in course',studentID => 'Selected students'}, 626 -labels=>{all_students=>'All students in course',studentID => 'Selected students'},
593 -default=>'studentID', -linebreak=>0), 627 -default=>'studentID', -linebreak=>0),
594 CGI::br(),$scrolling_user_list), 628 CGI::br(),$scrolling_user_list,
629 CGI::i("Preview set to: "), $preview_record->last_name,
630 CGI::submit(-name=>'action', -value=>'preview',-label=>'Preview message'),'  ',
631 ),
632
595## Edit here to insert filtering 633## Edit here to insert filtering
596## be sure to fail GRACEFULLY! 634## be sure to fail GRACEFULLY!
597# 635#
598# 636#
599# CGI::input({type=>'submit',value=>'Sort by',name=>'action'}),, 637# CGI::input({type=>'submit',value=>'Sort by',name=>'action'}),,
618 656
619############################################################################################# 657#############################################################################################
620# third column 658# third column
621############################################################################################# 659#############################################################################################
622 CGI::td({align=>'left'}, 660 CGI::td({align=>'left'},
623 "<b>Merge file:</b> $merge_file", CGI::br(), 661# "<b>Merge file:</b> $merge_file", CGI::br(),
624 CGI::submit(-name=>'action', -value=>'Set merge file to:'),CGI::br(), 662# CGI::submit(-name=>'action', -value=>'Set merge file to:'),CGI::br(),
625 CGI::popup_menu(-name=>'merge_file', 663# CGI::popup_menu(-name=>'merge_file',
626 -values=>\@sorted_merge_files, 664# -values=>\@sorted_merge_files,
627 -default=>$merge_file, 665# -default=>$merge_file,
628 ), "\n",CGI::hr(), 666# ), "\n",
667# CGI::hr(),
629 CGI::b("Viewing email for: "), "$preview_user",CGI::br(), 668# CGI::b("Viewing email for: "), "$preview_user",CGI::br(),
630 CGI::submit(-name=>'action', -value=>'resize', -label=>$REFRESH_RESIZE_BUTTON),'&nbsp;', 669# CGI::submit(-name=>'action', -value=>'resize', -label=>$REFRESH_RESIZE_BUTTON),'&nbsp;',
631 CGI::popup_menu(-name=>'preview_user', 670# CGI::popup_menu(-name=>'preview_user',
632 -values=>\@users, 671# -values=>\@users,
633 #-labels=>\%classlistLabels, 672# #-labels=>\%classlistLabels,
634 -default=>$preview_user, 673# -default=>$preview_user,
635 ), 674# ),
636 CGI::br(), 675# CGI::br(),
637 CGI::submit(-name=>'action', -value=>'preview',-label=>'Preview message'),'&nbsp;&nbsp;', 676# CGI::submit(-name=>'action', -value=>'preview',-label=>'Preview message'),'&nbsp;&nbsp;',
638 677#
639 CGI::br(), 678# CGI::br(),
640 679#
641 CGI::hr(), 680# CGI::hr(),
642 " Rows: ", CGI::textfield(-name=>'rows', -size=>3, -value=>$rows), 681 " Rows: ", CGI::textfield(-name=>'rows', -size=>3, -value=>$rows),
643 " Columns: ", CGI::textfield(-name=>'columns', -size=>3, -value=>$columns), 682 " Columns: ", CGI::textfield(-name=>'columns', -size=>3, -value=>$columns),
683 CGI::br(),
644 CGI::br(),CGI::i('Press any action button to update display'),CGI::br(), 684# CGI::i('Press any action button to update display'),CGI::br(),
645 #show available macros 685 #show available macros
646 CGI::popup_menu( 686 CGI::popup_menu(
647 -name=>'dummyName', 687 -name=>'dummyName',
648 -values=>['', '$SID', '$FN', '$LN', '$SECTION', '$RECITATION','$STATUS', '$EMAIL', '$LOGIN', '$COL[3]', '$COL[-1]'], 688 -values=>['', '$SID', '$FN', '$LN', '$SECTION', '$RECITATION','$STATUS', '$EMAIL', '$LOGIN', '$COL[3]', '$COL[-1]'],
649 -labels=>{''=>'list of insertable macros', 689 -labels=>{''=>'list of insertable macros',
715} 755}
716 756
717############################################################################## 757##############################################################################
718# Utility methods 758# Utility methods
719############################################################################## 759##############################################################################
720sub submission_error {
721 my $self = shift;
722 my $msg = join( " ", @_);
723 $self->{submitError} .= CGI::br().$msg;
724 return;
725}
726 760
727sub saveProblem { 761sub saveProblem {
728 my $self = shift; 762 my $self = shift;
729 my ($body, $probFileName)= @_; 763 my ($body, $probFileName)= @_;
730 local(*PROBLEM); 764 local(*PROBLEM);
777sub get_merge_file_names { 811sub get_merge_file_names {
778 my $self = shift; 812 my $self = shift;
779 return 'None', $self->read_dir($self->{ce}->{courseDirs}->{scoring}, '\\.csv$'); #FIXME ? check that only readable files are listed. 813 return 'None', $self->read_dir($self->{ce}->{courseDirs}->{scoring}, '\\.csv$'); #FIXME ? check that only readable files are listed.
780} 814}
781 815
816sub mail_message_to_recipients {
817 my $self = shift;
818 my $subject = $self->{subject};
819 my $from = $self->{from};
820 my @recipients = @{$self->{ra_send_to}};
821 my $rh_merge_data = $self->{rh_merge_data};
822 my $merge_file = $self->{merge_file};
823 my $result_message = '';
824 my $failed_messages = 0;
825 foreach my $recipient (@recipients) {
826 # warn "FIXME sending email to $recipient";
827 my $error_messages = '';
828 my $ur = $self->{db}->getUser($recipient); #checked
829 unless ($ur) {
830 $error_messages .= "Record for user $recipient not found\n";
831 next;
832 }
833 unless ($ur->email_address) {
834 $error_messages .="User $recipient does not have an email address -- skipping\n";
835 next;
836 }
837 my ($msg, $preview_header);
838 eval{ ($msg,$preview_header) = $self->process_message($ur,$rh_merge_data); };
839 $error_messages .= "There were errors in processing user $ur, merge file $merge_file. \n$@\n" if $@;
840 my $mailer = Mail::Sender->new({
841 from => $from,
842 to => $ur->email_address,
843 smtp => $self->{smtpServer},
844 subject => $subject,
845 headers => "X-Remote-Host: ".$self->r->get_remote_host(),
846 });
847 unless (ref $mailer) {
848 $error_messages .= "Failed to create a mailer for user $recipient: $Mail::Sender::Error\n";
849 next;
850 }
851 unless (ref $mailer->Open()) {
852 $error_messages .= "Failed to open the mailer for user $recipient: $Mail::Sender::Error\n";
853 next;
854 }
855 my $MAIL = $mailer->GetHandle() || ($error_messages .= "Couldn't get mailer handle \n");
856 print $MAIL $msg || ($error_messages .= "Couldn't print to $MAIL");
857 close $MAIL || ($error_messages .= "Couldn't close $MAIL");
858 #warn "FIXME mailed to $recipient: ", $ur->email_address, " from $from subject $subject Errors: $error_messages";
859 $failed_messages++ if $error_messages;
860 $result_message .= $error_messages;
861 }
862 my $courseName = $self->r->urlpath->arg("courseID");
863 my $number_of_recipients = scalar(@recipients) - $failed_messages;
864 $result_message = <<EndText.$result_message;
865
866 A message with the subject line
867 $subject
868 has been sent to
869 $number_of_recipients recipient(s) in the class $courseName.
870 There were $failed_messages message(s) that could not be delivered.
871
872EndText
782 873
874}
875sub email_notification {
876 my $self = shift;
877 my $result_message = shift;
878 # find info on mailer and sender
879 # use the defaultFrom address.
880
881 # find info on instructor recipient and message
882 my $subject="WeBWorK email sent";
883
884 my $mailing_errors = "";
885 # open MAIL handle
886 my $mailer = Mail::Sender->new({
887 from => $self->{defaultFrom},
888 to => $self->{defaultFrom},
889 smtp => $self->{smtpServer},
890 subject => $subject,
891 headers => "X-Remote-Host: ".$self->r->get_remote_host(),
892 });
893 unless (ref $mailer) {
894 $mailing_errors .= "Failed to create a mailer: $Mail::Sender::Error";
895 return "";
896 }
897 unless (ref $mailer->Open()) {
898 $mailing_errors .= "Failed to open the mailer: $Mail::Sender::Error";
899 return "";
900 }
901 my $MAIL = $mailer->GetHandle();
902 # print message
903 print $MAIL $result_message;
904 # clean up
905 close $MAIL;
906
907 warn "instructor message sent to ", $self->{defaultFrom};
908
909}
783sub getRecord { 910sub getRecord {
784 my $self = shift; 911 my $self = shift;
785 my $line = shift; 912 my $line = shift;
786 my $delimiter = shift; 913 my $delimiter = shift;
787 $delimiter = ',' unless defined($delimiter); 914 $delimiter = ',' unless defined($delimiter);
805 my $ur = shift; 932 my $ur = shift;
806 my $rh_merge_data = shift; 933 my $rh_merge_data = shift;
807 my $text = defined($self->{r_text}) ? ${ $self->{r_text} }: 934 my $text = defined($self->{r_text}) ? ${ $self->{r_text} }:
808 'FIXME no text was produced by initialization!!'; 935 'FIXME no text was produced by initialization!!';
809 my $merge_file = ( defined($self->{merge_file}) ) ? $self->{merge_file} : 'None'; 936 my $merge_file = ( defined($self->{merge_file}) ) ? $self->{merge_file} : 'None';
937
938 my $status_name = $self->r->ce->status_abbrev_to_name($ur->status);
939 $status_name = $ur->status unless defined $status_name;
940
810 #user macros that can be used in the email message 941 #user macros that can be used in the email message
811 my $SID = $ur->student_id; 942 my $SID = $ur->student_id;
812 my $FN = $ur->first_name; 943 my $FN = $ur->first_name;
813 my $LN = $ur->last_name; 944 my $LN = $ur->last_name;
814 my $SECTION = $ur->section; 945 my $SECTION = $ur->section;
815 my $RECITATION = $ur->recitation; 946 my $RECITATION = $ur->recitation;
816 my $STATUS = $ur->status; 947 my $STATUS = $status_name;
817 my $EMAIL = $ur->email_address; 948 my $EMAIL = $ur->email_address;
818 my $LOGIN = $ur->user_id; 949 my $LOGIN = $ur->user_id;
819 950
820 # get record from merge file 951 # get record from merge file
821 # FIXME this is inefficient. The info should be cached 952 # FIXME this is inefficient. The info should be cached
851 982
852 return $msg, $preview_header; 983 return $msg, $preview_header;
853} 984}
854 985
855 986
856# Ê sub data_format { 987# Ý sub data_format {
857# 988#
858# Ê Ê Ê Ê Êmap {$_ =~s/\s/\./g;$_} Ê Ê map {sprintf('%-8.8s',$_);} Ê@_; 989# Ý Ý Ý Ý Ýmap {$_ =~s/\s/\./g;$_} Ý Ý map {sprintf('%-8.8s',$_);} Ý@_;
859 sub data_format { 990 sub data_format {
860 map {"COL[$_]".'&nbsp;'x(3-length($_));} @_; # problems if $_ has length bigger than 4 991 map {"COL[$_]".'&nbsp;'x(3-length($_));} @_; # problems if $_ has length bigger than 4
861 } 992 }
862 sub data_format2 { 993 sub data_format2 {
863 map {$_ =~s/\s/&nbsp;/g;$_} map {sprintf('%-8.8s',$_);} @_; 994 map {$_ =~s/\s/&nbsp;/g;$_} map {sprintf('%-8.8s',$_);} @_;

Legend:
Removed from v.2787  
changed lines
  Added in v.4202

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9