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

Annotation of /branches/rel-2-3-dev/webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/SendMail.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4934 - (view) (download) (as text)

1 : sh002i 1663 ################################################################################
2 :     # WeBWorK Online Homework Delivery System
3 : sh002i 3973 # Copyright © 2000-2006 The WeBWorK Project, http://openwebwork.sf.net/
4 : sh002i 4629 # $CVSHeader$
5 : sh002i 1663 #
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
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.
10 :     #
11 :     # This program is distributed in the hope that it will be useful, but WITHOUT
12 :     # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 :     # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the
14 :     # Artistic License for more details.
15 :     ################################################################################
16 :    
17 : gage 1368 package WeBWorK::ContentGenerator::Instructor::SendMail;
18 :     use base qw(WeBWorK::ContentGenerator::Instructor);
19 :    
20 :     =head1 NAME
21 :    
22 :     WeBWorK::ContentGenerator::Instructor::SendMail - Entry point for User-specific data editing
23 :    
24 :     =cut
25 :    
26 :     use strict;
27 :     use warnings;
28 : gage 4234 #use CGI qw(-nosticky );
29 :     use WeBWorK::CGI;
30 :     use HTML::Entities;
31 : gage 1373 use Mail::Sender;
32 : sh002i 4629 use Socket qw/unpack_sockaddr_in inet_ntoa/; # for remote host/port info
33 : gage 3329 use Text::Wrap qw(wrap);
34 : mschmitt 2203 use WeBWorK::HTML::ScrollingRecordList qw/scrollingRecordList/;
35 : mschmitt 2207 use WeBWorK::Utils::FilterRecords qw/filterRecords/;
36 : gage 1368
37 : sh002i 4629 use mod_perl;
38 :     use constant MP2 => ( exists $ENV{MOD_PERL_API_VERSION} and $ENV{MOD_PERL_API_VERSION} >= 2 );
39 :    
40 : gage 3041 #my $REFRESH_RESIZE_BUTTON = "Set preview to: "; # handle submit value idiocy
41 :     my $UPDATE_SETTINGS_BUTTON = "Update settings and refresh page"; # handle submit value idiocy
42 : gage 1368 sub initialize {
43 :     my ($self) = @_;
44 : gage 1928 my $r = $self->r;
45 :     my $db = $r->db;
46 :     my $ce = $r->ce;
47 :     my $authz = $r->authz;
48 :     my $user = $r->param('user');
49 : gage 1368
50 : mschmitt 2207 my @selected_filters;
51 :     if (defined ($r->param('classList!filter'))){ @selected_filters = $r->param('classList!filter');}
52 :     else {@selected_filters = ("all");}
53 :    
54 : toenail 2320
55 :     # Check permissions
56 :     return unless $authz->hasPermissions($user, "access_instructor_tools");
57 :     return unless $authz->hasPermissions($user, "send_mail");
58 :    
59 : gage 1369 #############################################################################################
60 :     # gather directory data
61 :     #############################################################################################
62 :     my $emailDirectory = $ce->{courseDirs}->{email};
63 :     my $scoringDirectory = $ce->{courseDirs}->{scoring};
64 :     my $templateDirectory = $ce->{courseDirs}->{templates};
65 : gage 1368
66 : mschmitt 2203 my $action = $r->param('action') ;
67 : gage 1369 my $openfilename = $r->param('openfilename');
68 :     my $savefilename = $r->param('savefilename');
69 : gage 1370
70 :    
71 :     #FIXME get these values from global course environment (see subroutines as well)
72 :     my $default_msg_file = 'default.msg';
73 :     my $old_default_msg_file = 'old_default.msg';
74 :    
75 : gage 1372
76 : dpvc 2388 # get user record
77 :     my $ur = $self->{db}->getUser($user);
78 :    
79 : gage 1370 # store data
80 : dpvc 2388 $self->{defaultFrom} = $ur->email_address . " (".$ur->first_name." ".$ur->last_name.")";
81 :     $self->{defaultReply} = $ur->email_address;
82 :     $self->{defaultSubject} = $self->r->urlpath->arg("courseID") . " notice";
83 :    
84 : gage 1370 $self->{rows} = (defined($r->param('rows'))) ? $r->param('rows') : $ce->{mail}->{editor_window_rows};
85 :     $self->{columns} = (defined($r->param('columns'))) ? $r->param('columns') : $ce->{mail}->{editor_window_columns};
86 :     $self->{default_msg_file} = $default_msg_file;
87 :     $self->{old_default_msg_file} = $old_default_msg_file;
88 : gage 1372 $self->{merge_file} = (defined($r->param('merge_file' ))) ? $r->param('merge_file') : 'None';
89 : gage 3041 #$self->{preview_user} = (defined($r->param('preview_user'))) ? $r->param('preview_user') : $user;
90 :     # an expermiment -- share the scrolling list for preivew and sendTo actions.
91 :     my @classList = (defined($r->param('classList'))) ? $r->param('classList') : ($user);
92 :     $self->{preview_user} = $classList[0] || $user;
93 : gage 1372
94 :     #############################################################################################
95 :     # gather database data
96 :     #############################################################################################
97 :     # FIXME this might be better done in body? We don't always need all of this data. or do we?
98 : gage 1773 my @users = $db->listUsers;
99 : mschmitt 2203 my @Users = $db->getUsers(@users);
100 : sh002i 4453 # filter out users who don't get included in email (fixes bug #938)
101 :     @Users = grep { $ce->status_abbrev_has_behavior($_->status, "include_in_email") } @Users;
102 : gage 1372 my @user_records = ();
103 : mschmitt 2203
104 :     ## Mark's code to prefilter userlist
105 :    
106 :    
107 :     my (@viewable_sections,@viewable_recitations);
108 :    
109 :     if (defined @{$ce->{viewable_sections}->{$user}})
110 :     {@viewable_sections = @{$ce->{viewable_sections}->{$user}};}
111 :     if (defined @{$ce->{viewable_recitations}->{$user}})
112 :     {@viewable_recitations = @{$ce->{viewable_recitations}->{$user}};}
113 :    
114 :     if (@viewable_sections or @viewable_recitations){
115 :     foreach my $student (@Users){
116 :     my $keep = 0;
117 :     foreach my $sec (@viewable_sections){
118 :     if ($student->section() eq $sec){$keep = 1;}
119 :     }
120 :     foreach my $rec (@viewable_recitations){
121 :     if ($student->recitation() eq $rec){$keep = 1;}
122 :     }
123 :     if ($keep) {push @user_records, $student;}
124 :     }
125 : gage 1667 }
126 : mschmitt 2203 else {@user_records = @Users;}
127 :    
128 :     ## End Mark's code
129 :    
130 :     # foreach my $userName (@users) {
131 :     # my $userRecord = $db->getUser($userName); # checked
132 :     # die "record for user $userName not found" unless $userRecord;
133 :     # push(@user_records, $userRecord);
134 :     # }
135 : gage 1720 ###########################
136 :     # Sort the users for presentation in the select list
137 :     ###########################
138 : mschmitt 2203 # if (defined $r->param("sort_by") ) {
139 :     # my $sort_method = $r->param("sort_by");
140 :     # if ($sort_method eq 'section') {
141 :     # @user_records = sort { (lc($a->section) cmp lc($b->section)) || (lc($a->last_name) cmp lc($b->last_name)) } @user_records;
142 :     # } elsif ($sort_method eq 'recitation') {
143 :     # @user_records = sort { (lc($a->recitation) cmp lc($b->recitation)) || (lc($a->last_name) cmp lc($b->last_name)) } @user_records;
144 :     # } elsif ($sort_method eq 'alphabetical') {
145 :     # @user_records = sort { (lc($a->last_name) cmp lc($b->last_name)) } @user_records;
146 :     # } elsif ($sort_method eq 'id' ) {
147 :     # @user_records = sort { $a->user_id cmp $b->user_id } @user_records;
148 :     # }
149 :     # } else {
150 :     # @user_records = sort { $a->user_id cmp $b->user_id } @user_records;
151 :     # }
152 : gage 1372
153 : gage 1720
154 :     # replace the user names by a sorted version.
155 :     @users = map {$_->user_id} @user_records;
156 : gage 1372 # store data
157 :     $self->{ra_users} = \@users;
158 :     $self->{ra_user_records} = \@user_records;
159 :    
160 :     #############################################################################################
161 :     # gather list of recipients
162 :     #############################################################################################
163 :     my @send_to = ();
164 :     #FIXME this (radio) is a lousy name
165 :     my $recipients = $r->param('radio');
166 : gage 1375 if (defined($recipients) and $recipients eq 'all_students') { #only active students #FIXME status check??
167 : mschmitt 2207
168 :     ## Add code so that only people who pass the current filters are added to our list of recipients.
169 :     # @user_records = filterRecords({filter=\@selected_filters},@user_records);
170 :     # I wasn't able to make this work
171 :     # I edited the selection button to make that clear.
172 :     #
173 :    
174 : gage 1372 foreach my $ur (@user_records) {
175 : sh002i 3690 push(@send_to,$ur->user_id)
176 :     if $ce->status_abbrev_has_behavior($ur->status, "include_in_email")
177 :     and not $ur->user_id =~ /practice/;
178 : gage 1372 }
179 : gage 1375 } elsif (defined($recipients) and $recipients eq 'studentID' ) {
180 : gage 1372 @send_to = $r->param('classList');
181 :     } else {
182 : gage 1375 # no recipients have been defined -- probably the first time on the page
183 : gage 1372 }
184 :     $self->{ra_send_to} = \@send_to;
185 : gage 1370 #################################################################
186 :     # Check the validity of the input file name
187 :     #################################################################
188 :     my $input_file = '';
189 :     #make sure an input message file was submitted and exists
190 :     #else use the default message
191 :     if ( defined($openfilename) ) {
192 :     if ( -e "${emailDirectory}/$openfilename") {
193 :     if ( -R "${emailDirectory}/$openfilename") {
194 :     $input_file = $openfilename;
195 : gage 1369 } else {
196 : toenail 2320 $self->addbadmessage(CGI::p(join("",
197 : gage 1370 "The file ${emailDirectory}/$openfilename is not readable by the webserver.",CGI::br(),
198 :     "Check that it's permissions are set correctly.",
199 : toenail 2320 )));
200 : gage 1369 }
201 :     } else {
202 : gage 1370 $input_file = $default_msg_file;
203 : toenail 2320 $self->addbadmessage(CGI::p(join("",
204 : gage 1370 "The file ${emailDirectory}/$openfilename cannot be found.",CGI::br(),
205 :     "Check whether it exists and whether the directory $emailDirectory can be read by the webserver.",CGI::br(),
206 :     "Using contents of the default message $default_msg_file instead.",
207 : toenail 2320 )));
208 : gage 1369 }
209 : gage 1370 } else {
210 : gage 1372 $input_file = $default_msg_file;
211 : gage 1370 }
212 : gage 1372 $self->{input_file} =$input_file;
213 : gage 1370
214 :     #################################################################
215 :     # Determine the file name to save message into
216 :     #################################################################
217 : gage 1371 my $output_file = 'FIXME no output file specified';
218 : gage 1370 if (defined($action) and $action eq 'Save as Default') {
219 :     $output_file = $default_msg_file;
220 : toenail 2084 } elsif ( defined($action) and ($action =~/save/i)) {
221 :     if (defined($savefilename) and $savefilename ) {
222 :     $output_file = $savefilename;
223 :     } else {
224 : toenail 2320 $self->addbadmessage(CGI::p("No filename was specified for saving! The message was not saved."));
225 : toenail 2084 }
226 : gage 1370 } elsif ( defined($input_file) ) {
227 :     $output_file = $input_file;
228 :     }
229 : gage 1953
230 : gage 1370 #################################################################
231 :     # Sanity check on save file name
232 :     #################################################################
233 :    
234 :     if ($output_file =~ /^[~.]/ || $output_file =~ /\.\./) {
235 : toenail 2320 $self->addbadmessage(CGI::p("For security reasons, you cannot specify a message file from a directory",
236 : toenail 2084 "higher than the email directory (you can't use ../blah/blah for example). ",
237 : toenail 2320 "Please specify a different file or move the needed file to the email directory",));
238 : toenail 2084 }
239 : gage 1371 unless ($output_file =~ m|\.msg$| ) {
240 : toenail 2320 $self->addbadmessage(CGI::p("Invalid file name.",
241 : gage 1371 "The file name \"$output_file\" does not have a \".msg\" extension",
242 :     "All email file names must end in the extension \".msg\"",
243 :     "choose a file name with a \".msg\" extension.",
244 : toenail 2320 "The message was not saved.",));
245 : gage 1371 }
246 : toenail 2084
247 : gage 1371 $self->{output_file} = $output_file; # this is ok. It will be put back in the text input box for re-editing.
248 : gage 1370
249 : toenail 2084
250 : gage 1370 #############################################################################################
251 :     # Determine input source
252 :     #############################################################################################
253 : mschmitt 2203 #warn "Action = $action";
254 :     my $input_source;
255 :     if ($action){
256 :     $input_source = ( defined( $r->param('body') ) and $action ne 'Open' ) ? 'form' : 'file';}
257 :     else { $input_source = ( defined($r->param('body')) ) ? 'form' : 'file';}
258 : gage 1953
259 : gage 1370 #############################################################################################
260 :     # Get inputs
261 :     #############################################################################################
262 :     my($from, $replyTo, $r_text, $subject);
263 :     if ($input_source eq 'file') {
264 : gage 1953
265 : gage 1370 ($from, $replyTo,$subject,$r_text) = $self->read_input_file("$emailDirectory/$input_file");
266 :    
267 : gage 1953
268 : gage 1370 } elsif ($input_source eq 'form') {
269 :     # read info from the form
270 :     # bail if there is no message body
271 : gage 1369
272 : gage 1370 $from = $r->param('from');
273 :     $replyTo = $r->param('replyTo');
274 :     $subject = $r->param('subject');
275 : gage 3329 my $body = $r->param('body');
276 : gage 1370 # Sanity check: body must contain non-white space
277 : toenail 2320 $self->addbadmessage(CGI::p('You didn\'t enter any message.')) unless ($r->param('body') =~ /\S/);
278 : gage 1370 $r_text = \$body;
279 : gage 1369
280 : gage 1370 }
281 : sh002i 4629
282 :     my $remote_host;
283 :     if (MP2) {
284 :     $remote_host = $r->connection->remote_addr->ip_get || "UNKNOWN";
285 :     } else {
286 :     (undef, $remote_host) = unpack_sockaddr_in($r->connection->remote_addr);
287 :     $remote_host = defined $remote_host ? inet_ntoa($remote_host) : "UNKNOWN";
288 :     }
289 :    
290 : gage 1370 # store data
291 :     $self->{from} = $from;
292 :     $self->{replyTo} = $replyTo;
293 :     $self->{subject} = $subject;
294 : sh002i 4629 $self->{remote_host} = $remote_host;
295 : gage 1370 $self->{r_text} = $r_text;
296 :    
297 :    
298 : gage 1372
299 :     ###################################################################################
300 :     #Determine the appropriate script action from the buttons
301 :     ###################################################################################
302 :     # first time actions
303 :     # open new file
304 :     # open default file
305 :     # choose merge file actions
306 :     # chose merge button
307 :     # option actions
308 :     # 'reset rows'
309 :    
310 :     # save actions
311 :     # "save" button
312 :     # "save as" button
313 :     # "save as default" button
314 :     # preview actions
315 :     # 'preview' button
316 :     # email actions
317 :     # 'entire class'
318 :     # 'selected studentIDs'
319 :     # error actions (various)
320 :    
321 :    
322 : gage 1369 #############################################################################################
323 : gage 1370 # if no form is submitted, gather data needed to produce the mail form and return
324 : gage 1369 #############################################################################################
325 : gage 1372 my $to = $r->param('To');
326 :     my $script_action = '';
327 :    
328 :    
329 : gage 3041 if(not defined($action) or $action eq 'Open'
330 :     or $action eq $UPDATE_SETTINGS_BUTTON ){
331 : gage 1953
332 : gage 1369 return '';
333 :     }
334 :    
335 :    
336 :    
337 :    
338 :    
339 :     #############################################################################################
340 : gage 1370 # If form is submitted deal with filled out forms
341 : gage 1369 # and various actions resulting from different buttons
342 :     #############################################################################################
343 :    
344 : gage 1372
345 : gage 1370 if ($action eq 'Save' or $action eq 'Save as:' or $action eq 'Save as Default') {
346 :    
347 :     # warn "FIXME Saving files action = $action outputFileName=$output_file";
348 : gage 1369
349 : gage 1370 #################################################################
350 :     # construct message body
351 :     #################################################################
352 :     my $temp_body = ${ $r_text };
353 :     $temp_body =~ s/\r\n/\n/g;
354 :     $temp_body = join("",
355 :     "From: $from \nReply-To: $replyTo\n" ,
356 :     "Subject: $subject\n" ,
357 :     "Message: \n $temp_body");
358 :     # warn "FIXME from $from | subject $subject |reply $replyTo|msg $temp_body";
359 :     #################################################################
360 :     # overwrite protection
361 :     #################################################################
362 :     if ($action eq 'Save as:' and -e "$emailDirectory/$output_file") {
363 : toenail 2320 $self->addbadmessage(CGI::p("The file $emailDirectory/$output_file already exists and cannot be overwritten",
364 :     "The message was not saved"));
365 : toenail 2084 return;
366 : gage 1370 }
367 :    
368 :     #################################################################
369 :     # Back up existing file?
370 :     #################################################################
371 : gage 1371 if ($action eq 'Save as Default' and -e "$emailDirectory/$default_msg_file") {
372 :     rename("$emailDirectory/$default_msg_file","$emailDirectory/$old_default_msg_file") or
373 :     die "Can't rename $emailDirectory/$default_msg_file to $emailDirectory/$old_default_msg_file ",
374 :     "Check permissions for webserver on directory $emailDirectory. $!";
375 : toenail 2320 $self->addgoodmessage(CGI::p("Backup file <code>$emailDirectory/$old_default_msg_file</code> created." . CGI::br()));
376 : gage 1370 }
377 :     #################################################################
378 :     # Save the message
379 :     #################################################################
380 : toenail 2084 $self->saveProblem($temp_body, "${emailDirectory}/$output_file" ) unless ($output_file =~ /^[~.]/ || $output_file =~ /\.\./ || not $output_file =~ m|\.msg$|);
381 :     unless ( $self->{submit_message} or not -w "${emailDirectory}/$output_file" ) { # if there are no errors report success
382 : toenail 2320 $self->addgoodmessage(CGI::p("Message saved to file <code>${emailDirectory}/$output_file</code>."));
383 : gage 1953 }
384 :    
385 : gage 2050 } elsif ($action eq 'Preview message') {
386 : gage 1372 $self->{response} = 'preview';
387 : gage 1370
388 :     } elsif ($action eq 'Send Email') {
389 : gage 1373 $self->{response} = 'send_email';
390 : gage 3329
391 :     # check that recipients have been selected.
392 : gage 1373 my @recipients = @{$self->{ra_send_to}};
393 : gage 3611 if (@recipients) {
394 : sh002i 4934 # get merge file
395 :     my $merge_file = ( defined($self->{merge_file}) ) ? $self->{merge_file} : 'None';
396 :     my $delimiter = ',';
397 :     my $rh_merge_data = $self->read_scoring_file("$merge_file", "$delimiter");
398 :     unless (ref($rh_merge_data) ) {
399 :     $self->addbadmessage(CGI::p("No merge data file"));
400 :     $self->addbadmessage(CGI::p("Can't read merge file $merge_file. No message sent"));
401 :     return;
402 :     } ;
403 :     if (@recipients) {
404 :     $self->{rh_merge_data} = $rh_merge_data;
405 :     $self->{smtpServer} = $ce->{mail}->{smtpServer};
406 :     my $post_connection_action = sub {
407 :     my $r = shift;
408 :     my $result_message = $self->mail_message_to_recipients();
409 :     $self->email_notification($result_message);
410 :     };
411 :     if (MP2) {
412 :     $r->connection->pool->cleanup_register($post_connection_action);
413 :     } else {
414 :     $r->post_connection($post_connection_action);
415 :     }
416 : sh002i 4629 }
417 : sh002i 4934 } else {
418 :     $self->addbadmessage(CGI::p("No recipients selected. Please select one or more recipients from the list below."));
419 : gage 3611 }
420 :     # foreach my $recipient (@recipients) {
421 :     # #warn "FIXME sending email to $recipient";
422 :     # my $ur = $self->{db}->getUser($recipient); #checked
423 :     # die "record for user $recipient not found" unless $ur;
424 :     # unless ($ur->email_address) {
425 :     # $self->addbadmessage(CGI::p("user $recipient does not have an email address -- skipping"));
426 :     # next;
427 :     # }
428 :     # my ($msg, $preview_header);
429 :     # eval{ ($msg,$preview_header) = $self->process_message($ur,$rh_merge_data); };
430 :     # $self->addbadmessage(CGI::p("There were errors in processing user $ur, merge file $merge_file. $@")) if $@;
431 :     # my $mailer = Mail::Sender->new({
432 :     # from => $from,
433 :     # to => $ur->email_address,
434 :     # smtp => $ce->{mail}->{smtpServer},
435 :     # subject => $subject,
436 :     # headers => "X-Remote-Host: ".$r->get_remote_host(),
437 :     # });
438 :     # unless (ref $mailer) {
439 :     # $self->addbadmessage(CGI::p("Failed to create a mailer for user $recipient: $Mail::Sender::Error"));
440 :     # next;
441 :     # }
442 :     # unless (ref $mailer->Open()) {
443 :     # $self->addbadmessage(CGI::p("Failed to open the mailer for user $recipient: $Mail::Sender::Error"));
444 :     # next;
445 :     # }
446 :     # my $MAIL = $mailer->GetHandle() or $self->addbadmessage(CGI::p("Couldn't get handle"));
447 :     # print $MAIL $msg || $self->addbadmessage(CGI::p("Couldn't print to $MAIL"));
448 :     # close $MAIL || $self->addbadmessage(CGI::p("Couldn't close $MAIL"));
449 :     # #warn "FIXME mailed to ", $ur->email_address, "from $from subject $subject";
450 :     #
451 :     # }
452 : gage 1373
453 : gage 1370 } else {
454 : toenail 2320 $self->addbadmessage(CGI::p("Didn't recognize button $action"));
455 : gage 1370 }
456 : gage 1369
457 :    
458 : toenail 2084
459 : gage 1369 } #end initialize
460 :    
461 : gage 1368
462 :    
463 :    
464 : gage 1928
465 : gage 1368 sub body {
466 : gage 1928 my ($self) = @_;
467 :     my $r = $self->r;
468 :     my $urlpath = $r->urlpath;
469 : toenail 2320 my $authz = $r->authz;
470 : gage 1928 my $setID = $urlpath->arg("setID");
471 : gage 1372 my $response = (defined($self->{response}))? $self->{response} : '';
472 : toenail 2320 my $user = $r->param('user');
473 :    
474 :     # Check permissions
475 :     return CGI::div({class=>"ResultsWithError"}, CGI::p("You are not authorized to access instructor tools"))
476 :     unless $authz->hasPermissions($user, "access_instructor_tools");
477 :    
478 :     return CGI::div({class=>"ResultsWithError"}, CGI::p("You are not authorized to send mail to students"))
479 :     unless $authz->hasPermissions($user, "send_mail");
480 :    
481 : gage 1372 if ($response eq 'preview') {
482 :     $self->print_preview($setID);
483 : sh002i 4934 } elsif ($response eq 'send_email' and $self->{ra_send_to} and @{$self->{ra_send_to}}){
484 :     my $message = CGI::i("Email is being sent to ". scalar(@{$self->{ra_send_to}})." recipient(s). You will be notified"
485 : apizer 3766 ." by email when the task is completed. This may take several minutes if the class is large."
486 : gage 3611 );
487 :     $self->addgoodmessage($message);
488 :     $self->{message} .= $message;
489 :    
490 : gage 1372 $self->print_form($setID);
491 : gage 1375 } else {
492 :     $self->print_form($setID);
493 : gage 1372 }
494 :    
495 :     }
496 :     sub print_preview {
497 : gage 1928 my ($self) = @_;
498 :     my $r = $self->r;
499 :     my $urlpath = $r->urlpath;
500 :     my $setID = $urlpath->arg("setID");
501 :    
502 : gage 1372 # get preview user
503 : gage 1928 my $ur = $r->db->getUser($self->{preview_user}); #checked
504 : gage 1667 die "record for preview user ".$self->{preview_user}. " not found." unless $ur;
505 : gage 1372
506 :     # get merge file
507 :     my $merge_file = ( defined($self->{merge_file}) ) ? $self->{merge_file} : 'None';
508 :     my $delimiter = ',';
509 : gage 1397 my $rh_merge_data = $self->read_scoring_file("$merge_file", "$delimiter");
510 : gage 1372
511 : sh002i 4629 my ($msg, $preview_header) = $self->process_message($ur,$rh_merge_data,1); # 1 == for preview
512 : gage 1372
513 :     my $recipients = join(" ",@{$self->{ra_send_to} });
514 : toenail 2084 my $errorMessage = defined($self->{submit_message}) ? CGI::i($self->{submit_message} ) : '' ;
515 : gage 1373 $msg = join("",
516 :     $errorMessage,
517 :     $preview_header,
518 :     "To: " , $ur->email_address,"\n",
519 :     "From: " , $self->{from} , "\n" ,
520 :     "Reply-To: " , $self->{replyTo} , "\n" ,
521 :     "Subject: " , $self->{subject} , "\n" ,"\n" ,
522 :     $msg , "\n"
523 :     );
524 : gage 1372
525 : gage 1373 return join("", '<pre>',$msg,"\n","\n",
526 : gage 1372 '</pre>',
527 :     CGI::p('Use browser back button to return from preview mode'),
528 :     CGI::h3('Emails to be sent to the following:'),
529 :     $recipients, "\n",
530 :    
531 :     );
532 :    
533 :     }
534 :     sub print_form {
535 : gage 1928 my ($self) = @_;
536 :     my $r = $self->r;
537 :     my $urlpath = $r->urlpath;
538 :     my $authz = $r->authz;
539 :     my $db = $r->db;
540 :     my $ce = $r->ce;
541 :     my $courseName = $urlpath->arg("courseID");
542 :     my $setID = $urlpath->arg("setID");
543 :     my $user = $r->param('user');
544 :    
545 : gage 1938 my $root = $ce->{webworkURLs}->{root};
546 :     my $sendMailPage = $urlpath->newFromModule($urlpath->module,courseID=>$courseName);
547 :     my $sendMailURL = $self->systemLink($sendMailPage, authen => 0);
548 : gage 1368
549 : toenail 2084 return CGI::em("You are not authorized to access the Instructor tools.") unless $authz->hasPermissions($user, "access_instructor_tools");
550 : gage 1368
551 :     my $userTemplate = $db->newUser;
552 :     my $permissionLevelTemplate = $db->newPermissionLevel;
553 :    
554 :     # This code will require changing if the permission and user tables ever have different keys.
555 : gage 3041 my @users = sort @{ $self->{ra_users} };
556 : gage 1372 my $ra_user_records = $self->{ra_user_records};
557 :     my %classlistLabels = ();# %$hr_classlistLabels;
558 :     foreach my $ur (@{ $ra_user_records }) {
559 : gage 1720 $classlistLabels{$ur->user_id} = $ur->user_id.': '.$ur->last_name. ', '. $ur->first_name.' -- '.$ur->section." / ".$ur->recitation;
560 : gage 1372 }
561 : gage 1368
562 : mschmitt 2203 ## Mark edit define scrolling list
563 :     my $scrolling_user_list = scrollingRecordList({
564 :     name => "classList", ## changed from classList to action
565 :     request => $r,
566 :     default_sort => "lnfn",
567 :     default_format => "lnfn_uid",
568 :     default_filters => ["all"],
569 :     size => 5,
570 :     multiple => 1,
571 : gage 3041 refresh_button_name =>'Update settings and refresh page',
572 : mschmitt 2203 }, @{$ra_user_records});
573 : gage 1368
574 :     ##############################################################################################################
575 :    
576 : gage 1372
577 : gage 1369 my $from = $self->{from};
578 :     my $subject = $self->{subject};
579 :     my $replyTo = $self->{replyTo};
580 :     my $columns = $self->{columns};
581 :     my $rows = $self->{rows};
582 : gage 1370 my $text = defined($self->{r_text}) ? ${ $self->{r_text} }: 'FIXME no text was produced by initialization!!';
583 :     my $input_file = $self->{input_file};
584 :     my $output_file = $self->{output_file};
585 : gage 1371 my @sorted_messages = $self->get_message_file_names;
586 :     my @sorted_merge_files = $self->get_merge_file_names;
587 :     my $merge_file = ( defined($self->{merge_file}) ) ? $self->{merge_file} : 'None';
588 : gage 1372 my $delimiter = ',';
589 : gage 1397 my $rh_merge_data = $self->read_scoring_file("$merge_file", "$delimiter");
590 : gage 1372 my @merge_keys = keys %$rh_merge_data;
591 :     my $preview_user = $self->{preview_user};
592 : gage 1667 my $preview_record = $db->getUser($preview_user); # checked
593 :     die "record for preview user ".$self->{preview_user}. " not found." unless $preview_record;
594 : gage 1372
595 : gage 1667
596 : gage 1372 #############################################################################################
597 :    
598 : gage 1938 print CGI::start_form({method=>"post", action=>$sendMailURL});
599 : gage 1372 print $self->hidden_authen_fields();
600 :     #############################################################################################
601 :     # begin upper table
602 :     #############################################################################################
603 :    
604 : gage 1368 print CGI::start_table({-border=>'2', -cellpadding=>'4'});
605 : gage 1720 print CGI::Tr({-align=>'left',-valign=>'top'},
606 : gage 1372 #############################################################################################
607 :     # first column
608 :     #############################################################################################
609 :    
610 : gage 4269 CGI::td({},
611 :     CGI::strong("Message file: "), $input_file,"\n",CGI::br(),
612 : gage 1371 CGI::submit(-name=>'action', -value=>'Open'), '&nbsp;&nbsp;&nbsp;&nbsp;',"\n",
613 :     CGI::popup_menu(-name=>'openfilename',
614 :     -values=>\@sorted_messages,
615 :     -default=>$input_file
616 : gage 3041 ),
617 :     "\n",CGI::br(),
618 :     CGI::strong("Save file to: "), $output_file,
619 :     "\n",CGI::br(),
620 :     CGI::strong('Merge file: '), $merge_file,
621 :     CGI::br(),
622 :     CGI::popup_menu(-name=>'merge_file',
623 :     -values=>\@sorted_merge_files,
624 :     -default=>$merge_file,
625 :     ), "\n",
626 :     "\n",
627 :     #CGI::hr(),
628 :     CGI::div({style=>"background-color: #CCCCCC"},
629 :     "\n", 'From:','&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', CGI::textfield(-name=>"from", -size=>30, -value=>$from, -override=>1),
630 :     "\n", CGI::br(),'Reply-To: ', CGI::textfield(-name=>"replyTo", -size=>30, -value=>$replyTo, -override=>1),
631 : gage 4234 "\n", CGI::br(),'Subject: ', CGI::br(), CGI::textarea(-name=>'subject', -default=>$subject, -rows=>3,-cols=>30, -override=>1),
632 : gage 3041 ),
633 :     #CGI::hr(),
634 :     CGI::submit(-name=>'action', -value=>$UPDATE_SETTINGS_BUTTON),
635 :    
636 : gage 1370 ),
637 : gage 1372 #############################################################################################
638 :     # second column
639 :     #############################################################################################
640 : gage 4269
641 : mschmitt 2203 ## Edit by Mark to insert scrolling list
642 : gage 4269 CGI::td({-style=>"width:33%"},
643 :     CGI::strong("Send to:"),
644 :     CGI::radio_group(-name=>'radio',
645 :     -values=>['all_students','studentID'],
646 :     -labels=>{all_students=>'All students in course',studentID => 'Selected students'},
647 :     -default=>'studentID', -linebreak=>0),
648 : gage 3041 CGI::br(),$scrolling_user_list,
649 :     CGI::i("Preview set to: "), $preview_record->last_name,
650 :     CGI::submit(-name=>'action', -value=>'preview',-label=>'Preview message'),'&nbsp;&nbsp;',
651 :     ),
652 :    
653 : mschmitt 2203 ## Edit here to insert filtering
654 :     ## be sure to fail GRACEFULLY!
655 :     #
656 :     #
657 :     # CGI::input({type=>'submit',value=>'Sort by',name=>'action'}),,
658 :     # CGI::radio_group(-name=>'sort_by', -values=>['id','alphabetical','section','recitation'],
659 :     # -labels=>{id=>'Login',alphabetical=>'Alph.',section => 'Sec.',recitation=>'Rec.'},
660 :     # -default=>defined($r->param("sort_by")) ? $r->param("sort_by") : 'id',
661 :     # -linebreak=>0
662 :     # ),
663 :     #
664 :     # CGI::br(),CGI::br(),
665 :     # CGI::popup_menu(-name=>'classList',
666 :     # -values=>\@users,
667 :     # -labels=>\%classlistLabels,
668 :     # -size => 10,
669 :     # -multiple => 1,
670 :     # -default=>$user
671 :     # ),
672 :     # ),
673 : gage 1720
674 : mschmitt 2203
675 : gage 1720
676 : mschmitt 2203
677 : gage 1372 #############################################################################################
678 :     # third column
679 :     #############################################################################################
680 : gage 1370 CGI::td({align=>'left'},
681 : gage 4269
682 : gage 1370 " Rows: ", CGI::textfield(-name=>'rows', -size=>3, -value=>$rows),
683 :     " Columns: ", CGI::textfield(-name=>'columns', -size=>3, -value=>$columns),
684 : gage 3041 CGI::br(),
685 :     # CGI::i('Press any action button to update display'),CGI::br(),
686 : gage 1370 #show available macros
687 :     CGI::popup_menu(
688 :     -name=>'dummyName',
689 :     -values=>['', '$SID', '$FN', '$LN', '$SECTION', '$RECITATION','$STATUS', '$EMAIL', '$LOGIN', '$COL[3]', '$COL[-1]'],
690 :     -labels=>{''=>'list of insertable macros',
691 :     '$SID'=>'$SID - Student ID',
692 :     '$FN'=>'$FN - First name',
693 :     '$LN'=>'$LN - Last name',
694 : gage 1372 '$SECTION'=>'$SECTION',
695 : gage 1370 '$RECITATION'=>'$RECITATION',
696 :     '$STATUS'=>'$STATUS - C, Audit, Drop, etc.',
697 :     '$EMAIL'=>'$EMAIL - Email address',
698 :     '$LOGIN'=>'$LOGIN - Login',
699 : gage 1372 '$COL[3]'=>'$COL[3] - 3rd col',
700 : gage 1370 '$COL[-1]'=>'$COL[-1] - Last column'
701 :     }
702 :     ), "\n",
703 :     ),
704 : gage 1368
705 : gage 1370 ); # end Tr
706 : gage 1372 print CGI::end_table();
707 :     #############################################################################################
708 :     # end upper table
709 :     #############################################################################################
710 :    
711 :     # show merge file
712 :     # print "<pre>",(map {$_ =~s/\s/\./g;$_} map {sprintf('%-8.8s',$_);} 0..8),"</pre>";
713 :     # print CGI::popup_menu(
714 :     # -name=>'dummyName2',
715 :     # -values=>\@merge_keys,
716 :     # -labels=>$rh_merge_data,
717 :     # -multiple=>1,
718 :     # -size =>2,
719 :     #
720 :     # ), "\n",CGI::br();
721 :     # warn "merge keys ", join( " ",@merge_keys);
722 :     #############################################################################################
723 :     # merge file fragment and message text area field
724 :     #############################################################################################
725 : gage 1373 my @tmp2;
726 : gage 1667 eval{ @tmp2= @{$rh_merge_data->{ $db->getUser($preview_user)->student_id } };}; # checked
727 : gage 1730 if ($@ and $merge_file ne 'None') {
728 : gage 1381 print "No merge data for $preview_user in merge file: &lt;$merge_file&gt;",CGI::br();
729 : gage 1373 } else {
730 : apizer 2786 print CGI::pre("",data_format(1..($#tmp2+1)),"<br>", data_format2(@tmp2));
731 : gage 1373 }
732 : gage 1368 #create a textbox with the subject and a textarea with the message
733 :     #print actual body of message
734 : gage 1369
735 : gage 1370 print "\n", CGI::p( $self->{message}) if defined($self->{message});
736 : gage 4234 print "\n", CGI::p( CGI::textarea(-name=>'body', -default=>$text, -rows=>$rows, -cols=>$columns, -override=>1));
737 : gage 1372
738 :     #############################################################################################
739 :     # action button table
740 :     #############################################################################################
741 : gage 1370 print CGI::table( { -border=>2,-cellpadding=>4},
742 : gage 4269 CGI::Tr( {},
743 :     CGI::td({}, CGI::submit(-name=>'action', -value=>'Send Email') ), "\n",
744 :     CGI::td({}, CGI::submit(-name=>'action', -value=>'Save')," to $output_file"), " \n",
745 :     CGI::td({}, CGI::submit(-name=>'action', -value=>'Save as:'),
746 : gage 1370 CGI::textfield(-name=>'savefilename', -size => 20, -value=> "$output_file", -override=>1)
747 :     ), "\n",
748 :     CGI::td(CGI::submit(-name=>'action', -value=>'Save as Default')),
749 :     )
750 :     );
751 : gage 1368
752 :     ##############################################################################################################
753 : gage 1369
754 :     print CGI::end_form();
755 : gage 1368 return "";
756 :     }
757 :    
758 : gage 1369 ##############################################################################
759 :     # Utility methods
760 :     ##############################################################################
761 :    
762 : gage 1370 sub saveProblem {
763 :     my $self = shift;
764 :     my ($body, $probFileName)= @_;
765 :     local(*PROBLEM);
766 :     open (PROBLEM, ">$probFileName") ||
767 : toenail 2320 $self->addbadmessage(CGI::p("Could not open $probFileName for writing.
768 :     Check that the permissions for this problem are 660 (-rw-rw----)"));
769 : toenail 2084 print PROBLEM $body if -w $probFileName;
770 : gage 1370 close PROBLEM;
771 :     chmod 0660, "$probFileName" ||
772 : toenail 2320 $self->addbadmessage(CGI::p("CAN'T CHANGE PERMISSIONS ON FILE $probFileName"));
773 : gage 1370 }
774 :    
775 :     sub read_input_file {
776 :     my $self = shift;
777 :     my $filePath = shift;
778 :     my ($text, @text);
779 :     my $header = '';
780 :     my ($subject, $from, $replyTo);
781 :     local(*FILE);
782 : gage 1371 if (-e "$filePath" and -r "$filePath") {
783 : toenail 2320 open FILE, "$filePath" || do { $self->addbadmessage(CGI::p("Can't open $filePath")); return};
784 : gage 1371 while ($header !~ s/Message:\s*$//m and not eof(FILE)) {
785 : gage 1370 $header .= <FILE>;
786 :     }
787 :     $text = join( '', <FILE>);
788 :     $text =~ s/^\s*//; # remove initial white space if any.
789 :     $header =~ /^From:\s(.*)$/m;
790 :     $from = $1 or $from = $self->{defaultFrom};
791 :    
792 :     $header =~ /^Reply-To:\s(.*)$/m;
793 :     $replyTo = $1 or $replyTo = $self->{defaultReply};
794 :    
795 :     $header =~ /^Subject:\s(.*)$/m;
796 :     $subject = $1;
797 :    
798 :     } else {
799 :     $from = $self->{defaultFrom};
800 :     $replyTo = $self->{defaultReply};
801 : gage 1371 $text = (-e "$filePath") ? "FIXME file $filePath can't be read" :"FIXME file $filePath doesn't exist";
802 : dpvc 2388 $subject = $self->{defaultSubject};
803 : gage 1370 }
804 :     return ($from, $replyTo, $subject, \$text);
805 :     }
806 : gage 1371
807 :    
808 : gage 1397 sub get_message_file_names {
809 :     my $self = shift;
810 :     return $self->read_dir($self->{ce}->{courseDirs}->{email}, '\\.msg$');
811 : gage 1371 }
812 : gage 1397 sub get_merge_file_names {
813 :     my $self = shift;
814 : gage 1730 return 'None', $self->read_dir($self->{ce}->{courseDirs}->{scoring}, '\\.csv$'); #FIXME ? check that only readable files are listed.
815 : gage 1371 }
816 : gage 1372
817 : gage 3329 sub mail_message_to_recipients {
818 :     my $self = shift;
819 : sh002i 4629 my $r = $self->r;
820 : sh002i 4783 my $ce = $r->ce;
821 : gage 3329 my $subject = $self->{subject};
822 :     my $from = $self->{from};
823 :     my @recipients = @{$self->{ra_send_to}};
824 :     my $rh_merge_data = $self->{rh_merge_data};
825 :     my $merge_file = $self->{merge_file};
826 :     my $result_message = '';
827 :     my $failed_messages = 0;
828 :     foreach my $recipient (@recipients) {
829 :     # warn "FIXME sending email to $recipient";
830 :     my $error_messages = '';
831 :     my $ur = $self->{db}->getUser($recipient); #checked
832 :     unless ($ur) {
833 :     $error_messages .= "Record for user $recipient not found\n";
834 :     next;
835 :     }
836 :     unless ($ur->email_address) {
837 :     $error_messages .="User $recipient does not have an email address -- skipping\n";
838 :     next;
839 :     }
840 : sh002i 4629 my $msg = eval { $self->process_message($ur,$rh_merge_data) };
841 :     $error_messages .= "There were errors in processing user $recipient, merge file $merge_file. \n$@\n" if $@;
842 : gage 3329 my $mailer = Mail::Sender->new({
843 : sh002i 4783 from => $ce->{mail}{smtpSender},
844 :     fake_from => $from,
845 :     to => $ur->email_address,
846 :     smtp => $self->{smtpServer},
847 :     subject => $subject,
848 :     headers => "X-Remote-Host: ".$self->{remote_host},
849 : gage 3329 });
850 :     unless (ref $mailer) {
851 :     $error_messages .= "Failed to create a mailer for user $recipient: $Mail::Sender::Error\n";
852 :     next;
853 :     }
854 :     unless (ref $mailer->Open()) {
855 :     $error_messages .= "Failed to open the mailer for user $recipient: $Mail::Sender::Error\n";
856 :     next;
857 :     }
858 :     my $MAIL = $mailer->GetHandle() || ($error_messages .= "Couldn't get mailer handle \n");
859 :     print $MAIL $msg || ($error_messages .= "Couldn't print to $MAIL");
860 :     close $MAIL || ($error_messages .= "Couldn't close $MAIL");
861 :     #warn "FIXME mailed to $recipient: ", $ur->email_address, " from $from subject $subject Errors: $error_messages";
862 :     $failed_messages++ if $error_messages;
863 :     $result_message .= $error_messages;
864 :     }
865 :     my $courseName = $self->r->urlpath->arg("courseID");
866 :     my $number_of_recipients = scalar(@recipients) - $failed_messages;
867 :     $result_message = <<EndText.$result_message;
868 :    
869 :     A message with the subject line
870 :     $subject
871 :     has been sent to
872 :     $number_of_recipients recipient(s) in the class $courseName.
873 :     There were $failed_messages message(s) that could not be delivered.
874 :    
875 :     EndText
876 : gage 1397
877 : gage 3329 }
878 :     sub email_notification {
879 :     my $self = shift;
880 :     my $result_message = shift;
881 :     # find info on mailer and sender
882 :     # use the defaultFrom address.
883 :    
884 :     # find info on instructor recipient and message
885 :     my $subject="WeBWorK email sent";
886 :    
887 :     my $mailing_errors = "";
888 :     # open MAIL handle
889 :     my $mailer = Mail::Sender->new({
890 :     from => $self->{defaultFrom},
891 :     to => $self->{defaultFrom},
892 :     smtp => $self->{smtpServer},
893 :     subject => $subject,
894 : sh002i 4629 headers => "X-Remote-Host: ".$self->{remote_host},
895 : gage 3329 });
896 :     unless (ref $mailer) {
897 :     $mailing_errors .= "Failed to create a mailer: $Mail::Sender::Error";
898 :     return "";
899 :     }
900 :     unless (ref $mailer->Open()) {
901 :     $mailing_errors .= "Failed to open the mailer: $Mail::Sender::Error";
902 :     return "";
903 :     }
904 :     my $MAIL = $mailer->GetHandle();
905 :     # print message
906 :     print $MAIL $result_message;
907 :     # clean up
908 :     close $MAIL;
909 :    
910 :     warn "instructor message sent to ", $self->{defaultFrom};
911 :    
912 :     }
913 : gage 1372 sub getRecord {
914 :     my $self = shift;
915 :     my $line = shift;
916 :     my $delimiter = shift;
917 :     $delimiter = ',' unless defined($delimiter);
918 :    
919 :     # Takes a delimited line as a parameter and returns an
920 :     # array. Note that all white space is removed. If the
921 :     # last field is empty, the last element of the returned
922 :     # array is also empty (unlike what the perl split command
923 :     # would return). E.G. @lineArray=&getRecord(\$delimitedLine).
924 :    
925 :     my(@lineArray);
926 : gage 2001 $line.="${delimiter}___"; # add final field which must be non-empty
927 :     @lineArray = split(/\s*${delimiter}\s*/,$line); # split line into fields
928 : gage 1372 $lineArray[0] =~s/^\s*//; # remove white space from first element
929 : gage 2001 pop @lineArray; # remove the last artificial field
930 : gage 1372 @lineArray;
931 :     }
932 :    
933 :     sub process_message {
934 :     my $self = shift;
935 :     my $ur = shift;
936 :     my $rh_merge_data = shift;
937 : sh002i 4629 my $for_preview = shift;
938 : gage 1372 my $text = defined($self->{r_text}) ? ${ $self->{r_text} }:
939 : gage 1730 'FIXME no text was produced by initialization!!';
940 :     my $merge_file = ( defined($self->{merge_file}) ) ? $self->{merge_file} : 'None';
941 : sh002i 3690
942 :     my $status_name = $self->r->ce->status_abbrev_to_name($ur->status);
943 :     $status_name = $ur->status unless defined $status_name;
944 :    
945 : gage 1372 #user macros that can be used in the email message
946 :     my $SID = $ur->student_id;
947 :     my $FN = $ur->first_name;
948 :     my $LN = $ur->last_name;
949 :     my $SECTION = $ur->section;
950 :     my $RECITATION = $ur->recitation;
951 : sh002i 3690 my $STATUS = $status_name;
952 : gage 1372 my $EMAIL = $ur->email_address;
953 :     my $LOGIN = $ur->user_id;
954 : gage 1730
955 : gage 1372 # get record from merge file
956 :     # FIXME this is inefficient. The info should be cached
957 : gage 1373 my @COL = defined($rh_merge_data->{$SID}) ? @{$rh_merge_data->{$SID} } : ();
958 : sh002i 4629 if ($merge_file ne 'None' and not defined($rh_merge_data->{$SID}) and $for_preview) {
959 : toenail 2320 $self->addbadmessage(CGI::p("No merge data for student id:$SID; name:$FN $LN; login:$LOGIN"));
960 : gage 1730 }
961 : apizer 2779 unshift(@COL,""); ## this makes COL[1] the first column
962 : gage 1372 my $endCol = @COL;
963 :     # for safety, only evaluate special variables
964 : gage 1373 my $msg = $text;
965 : apizer 2787 $msg =~ s/\$SID/$SID/ge;
966 :     $msg =~ s/\$LN/$LN/ge;
967 :     $msg =~ s/\$FN/$FN/ge;
968 :     $msg =~ s/\$STATUS/$STATUS/ge;
969 :     $msg =~ s/\$SECTION/$SECTION/ge;
970 :     $msg =~ s/\$RECITATION/$RECITATION/ge;
971 :     $msg =~ s/\$EMAIL/$EMAIL/ge;
972 :     $msg =~ s/\$LOGIN/$LOGIN/ge;
973 :     if (defined($COL[1])) { # prevents extraneous error messages.
974 :     $msg =~ s/\$COL\[(\-?\d+)\]/$COL[$1]/ge
975 :     }
976 :     else { # prevents extraneous $COL's in email message
977 :     $msg =~ s/\$COL\[(\-?\d+)\]//g
978 :     }
979 :    
980 : gage 1373 $msg =~ s/\r//g;
981 : apizer 2779
982 : sh002i 4629 if ($for_preview) {
983 :     my @preview_COL = @COL;
984 :     shift @preview_COL; ## shift back for preview
985 :     my $preview_header = CGI::pre({},data_format(1..($#COL)),"<br>", data_format2(@preview_COL)).
986 :     CGI::h3( "This sample mail would be sent to $EMAIL");
987 :     return $msg, $preview_header;
988 :     } else {
989 :     return $msg;
990 :     }
991 : gage 1372 }
992 : gage 1948
993 :    
994 : sh002i 3690 # Ý sub data_format {
995 : gage 1948 #
996 : sh002i 3690 # Ý Ý Ý Ý Ýmap {$_ =~s/\s/\./g;$_} Ý Ý map {sprintf('%-8.8s',$_);} Ý@_;
997 : gage 1372 sub data_format {
998 : gage 1948 map {"COL[$_]".'&nbsp;'x(3-length($_));} @_; # problems if $_ has length bigger than 4
999 : gage 1372 }
1000 : gage 1947 sub data_format2 {
1001 : gage 1948 map {$_ =~s/\s/&nbsp;/g;$_} map {sprintf('%-8.8s',$_);} @_;
1002 : gage 1947 }
1003 : gage 1368 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9