--- loncom/interface/lonsupportreq.pm 2007/09/05 05:46:19 1.44 +++ loncom/interface/lonsupportreq.pm 2008/01/13 16:53:46 1.46 @@ -1,5 +1,5 @@ # -# $Id: lonsupportreq.pm,v 1.44 2007/09/05 05:46:19 raeburn Exp $ +# $Id: lonsupportreq.pm,v 1.46 2008/01/13 16:53:46 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -99,7 +99,8 @@ sub print_request_form { rdes => 'You must include a description', name => 'Name', subm => 'Submit Request', - emad => 'E-mail address', + emad => 'Your e-mail address', + emac => 'Cc', unme => 'username', doma => 'domain', entu => 'Enter the username you use to log-in to LON-CAPA', @@ -171,11 +172,8 @@ END my ($sec,$grp) = split(/:/,$section); $groupid{$sec} = $grp; } - my $codedom = $Apache::lonnet::perlvar{'lonDefDomain'}; &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['codedom']); - if (exists($env{'form.codedom'})) { - $codedom = $env{'form.codedom'}; - } + my $codedom = &get_domain(); my $details_title; if ($codedom) { $details_title = '
('.$codedom.')'; @@ -197,9 +195,6 @@ function initialize_codes() { return; } |; - if ($cdom) { - $codedom = $cdom; - } if ($cnum) { $coursecodes{$cnum} = $ccode; if ($ccode eq '') { @@ -264,7 +259,10 @@ function initialize_codes() { '&').'" />
'."\n". &Apache::lonhtmlcommon::row_closure(). - &Apache::lonhtmlcommon::row_title("$lt{'unme'}/$lt{'doma'}",undef,'LC_oddrow_value'); + &Apache::lonhtmlcommon::row_title($lt{'emac'},undef,'LC_oddrow_value'). + '
'."\n". + &Apache::lonhtmlcommon::row_closure(). + &Apache::lonhtmlcommon::row_title("$lt{'unme'}/$lt{'doma'}",undef,'LC_evenrow_value'); my $udom_input = '&').'" />'; my $uname_input = '&').'" />'. &Apache::lonhtmlcommon::row_closure(). - &Apache::lonhtmlcommon::row_title("$lt{'phon'}",undef,'LC_oddrow_value'). + &Apache::lonhtmlcommon::row_title("$lt{'phon'}",undef,'LC_evenrow_value'). '
'. &Apache::lonhtmlcommon::row_closure(). - &Apache::lonhtmlcommon::row_title("$lt{'crsd'}$details_title",undef,'LC_evenrow_value'); - if ($cnum) { + &Apache::lonhtmlcommon::row_title("$lt{'crsd'}$details_title",undef,'LC_oddrow_value'); + if ($cnum) { if ($coursecodes{$cnum}) { foreach my $item (@codetitles) { $output .= ''.$item.': '.$codes{$cnum}{$item}.'; '; @@ -383,7 +381,7 @@ function initialize_codes() { '."\n"; } $output .= &Apache::lonhtmlcommon::row_closure(). - &Apache::lonhtmlcommon::row_title($lt{'secn'},undef,'LC_oddrow_value'); + &Apache::lonhtmlcommon::row_title($lt{'secn'},undef,'LC_evenrow_value'); if ($sectionlist) { $output .= "'; } $output .= &Apache::lonhtmlcommon::row_closure(). - &Apache::lonhtmlcommon::row_title($lt{'subj'},undef,'LC_evenrow_value'). + &Apache::lonhtmlcommon::row_title($lt{'subj'},undef,'LC_oddrow_value'). ' '."\n". &Apache::lonhtmlcommon::row_closure(). - &Apache::lonhtmlcommon::row_title($lt{'detd'},undef,'LC_oddrow_value'). + &Apache::lonhtmlcommon::row_title($lt{'detd'},undef,'LC_evenrow_value'). ' '. &Apache::lonhtmlcommon::row_closure(); my $lastrow = 'LC_evenrow_value'; if (defined($env{'user.name'})) { - $output .= &Apache::lonhtmlcommon::row_title($lt{'opfi'},undef,'LC_evenrow_value'). + $output .= &Apache::lonhtmlcommon::row_title($lt{'opfi'},undef,'LC_oddrow_value'). '
'.$lt{'uplf'}."\n". &Apache::lonhtmlcommon::row_closure(); $lastrow = 'LC_oddrow_value'; @@ -450,7 +448,10 @@ sub print_request_receipt { my @cookievars = ('lonID'); my $admin = $Apache::lonnet::perlvar{'lonAdminMail'}; - my $to = $Apache::lonnet::perlvar{'lonSupportEMail'}; + my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'}; + my $defdom = &get_domain(); + my $to = &Apache::loncommon::build_recipient_list(undef,'helpdeskmail', + $defdom,$origmail); my $from = $admin; my $reporttime = &Apache::lonlocal::locallocaltime(time); my @formvars = ('username','email','uname','udom','sourceurl','phone','section','coursecode','title','subject','description','screenshot'); @@ -474,6 +475,7 @@ sub print_request_receipt { my %lt = &Apache::lonlocal::texthash ( username => 'Name', email => 'Email', + cc => 'Cc', user => 'Username/domain', phone => 'Phone', crsi => 'Course Information', @@ -489,12 +491,46 @@ sub print_request_receipt { info => 'Information supplied', adin => 'Additional information recorded', ); - + + my (@ok_ccs,@bad_ccs,$badccmsg,$okcclist); + if (defined($env{'form.cc'})) { + my @ccs; + if ($env{'form.cc'} =~ /,/) { + @ccs = split(/,/,$env{'form.cc'}); + } else { + $env{'form.cc'} =~ s/^\s+//; + $env{'form.cc'} =~ s/\s+$//; + @ccs = $env{'form.cc'}; + } + foreach my $cc (@ccs) { + $cc =~ s/^\s+//g; + $cc =~ s/\s+$//g; + if ($cc =~ m/^[^\@]+\@[^\@]+$/) { + if (!(grep(/^\Q$cc\E$/,@ok_ccs))) { + push(@ok_ccs,$cc); + } + } else { + if (!(grep(/^\Q$cc\E$/,@bad_ccs))) { + push(@bad_ccs,$cc); + } + } + } + if (@ok_ccs > 0) { + $okcclist = join(', ',@ok_ccs); + } + if (@bad_ccs == 1) { + $badccmsg .= '
'.&mt('The following Cc e-mail address is invalid: ').$bad_ccs[0]; + } elsif (@bad_ccs > 1) { + my $bad_cc_string = join(', ',@bad_ccs); + $badccmsg .= '
'.&mt('The following Cc e-mail addresses are invalid: ').$bad_cc_string; + } + } $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'"; $env{'form.csri'} = $env{'form.title'}.' - '.$coursecode.' - '.$lt{'sect'}.': '.$env{'form.section'}; my $supportmsg = <: $showurl
\n"; + } elsif ($item eq 'cc') { + $displaymsg .= + ''. + "$lt{$item}: $okcclist
\n"; } else { $displaymsg .= ''. @@ -547,25 +587,52 @@ END if ($r->uri eq '/adm/helpdesk') { &print_header($r,$url,'process'); } - if ($to =~ m/^[^\@]+\@[^\@]+$/) { - $r->print('

'.$lt{'asup'}.' '.$to.'

'); - } else { - $to = $admin; - if ($to =~ m/^[^\@]+\@[^\@]+$/) { - $r->print('

'.$lt{'asup'}.' '.$to.'

'); + my $bad_email = 0; + if ($to =~ /,/) { + my @ok_email; + foreach my $email (split(/,/,$to)) { + if ($email =~ m/^[^\@]+\@[^\@]+$/) { + if (!grep(/^\Q$email\E$/,@ok_email)) { + push(@ok_email,$email); + } + } + } + if (@ok_email > 0) { + $to = join(',',@ok_email); + } elsif ($admin =~ m/^[^\@]+\@[^\@]+$/) { + $to = $admin; } else { - $r->print(' + $bad_email = 1; + } + } elsif ($to !~ m/^[^\@]+\@[^\@]+$/) { + if ($admin =~ m/^[^\@]+\@[^\@]+$/) { + $to = $admin; + } else { + $bad_email = 1; + } + } + if ($bad_email) { + $r->print('

'.$lt{'warn'}.'

'. &mt('As the e-mail address provided for this LON-CAPA server ([_1]) does not appear to be a valid e-mail address, your support request has not been sent to the LON-CAPA support staff or administrator at your institution.',$to).' '.&mt('Instead a copy has been sent to the LON-CAPA support team at Michigan State University.')); $to = 'helpdesk@lon-capa.org'; - } + } else { + $r->print('

'.$lt{'asup'}.' '.$to.'

'); } if (defined($env{'form.email'})) { + $env{'form.email'} =~ s/^\s+//; + $env{'form.email'} =~ s/\s+$//; if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) { $from = $env{'form.email'}; } } + if (defined($env{'form.cc'})) { + if ($badccmsg) { + $displaymsg .= $badccmsg; + } + } + my $subject = $env{'form.subject'}; $subject =~ s/(`)/'/g; $subject =~ s/\$/\(\$\)/g; @@ -616,6 +683,10 @@ END Type =>'TEXT', Data => $supportmsg, ); + if (@ok_ccs > 0) { + my $cc_string = join(', ',@ok_ccs); + $msg->add("Cc" => $cc_string); + } if ($attachmentpath) { my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath); @@ -730,4 +801,18 @@ Please review the information in "Log-in return; } +sub get_domain { + my $codedom; + if (exists($env{'form.codedom'})) { + $codedom = $env{'form.codedom'}; + } elsif ($env{'request.course.id'}) { + $codedom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + } elsif ($env{'request.role.domain'}) { + $codedom = $env{'request.role.domain'}; + } else { + $codedom = $Apache::lonnet::perlvar{'lonDefDomain'}; + } + return $codedom; +} + 1;