--- loncom/interface/lonsupportreq.pm 2007/12/04 04:43:21 1.45 +++ loncom/interface/lonsupportreq.pm 2010/11/10 14:44:50 1.58 @@ -1,5 +1,5 @@ # -# $Id: lonsupportreq.pm,v 1.45 2007/12/04 04:43:21 raeburn Exp $ +# $Id: lonsupportreq.pm,v 1.58 2010/11/10 14:44:50 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -77,8 +77,11 @@ sub print_request_form { $browser = $env{'browser.type'}; $bversion = $env{'browser.version'}; $uhost = $env{'request.host'}; - $uname = $env{'user.name'}; - $udom = $env{'user.domain'}; + my ($uname,$udom); + if (($env{'user.name'} ne 'public') && ($env{'user.domain'} ne 'public')) { + $uname = $env{'user.name'}; + $udom = $env{'user.domain'}; + } $uhome = $env{'user.home'}; $urole = $env{'request.role'}; $usec = $env{'request.course.sec'}; @@ -99,7 +102,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', @@ -237,9 +241,12 @@ function initialize_codes() { if ($r->uri eq '/adm/helpdesk') { &print_header($r,$origurl); } + my @css = ('LC_evenrow_value','LC_oddrow_value'); + my $num = 1; + my $i = $num%2; $r->print('
'."\n"); my $output = &Apache::lonhtmlcommon::start_pick_box(). - &Apache::lonhtmlcommon::row_title($lt{'name'},undef,'LC_oddrow_value')."\n"; + &Apache::lonhtmlcommon::row_title($lt{'name'},undef,$css[$num])."\n"; my $fullname = ''; if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) { $fullname = "$firstname $lastname"; @@ -253,12 +260,23 @@ function initialize_codes() { $output .= '&').'" />'; } $output .= '      '. - &Apache::lonhtmlcommon::row_closure()."\n". - &Apache::lonhtmlcommon::row_title($lt{'emad'},undef,'LC_evenrow_value'). - '&').'" />
'."\n". - &Apache::lonhtmlcommon::row_closure(). - &Apache::lonhtmlcommon::row_title("$lt{'unme'}/$lt{'doma'}",undef,'LC_oddrow_value'); + &Apache::lonhtmlcommon::row_closure()."\n"; + $num ++; + $i = $num%2; + $output .= &Apache::lonhtmlcommon::row_title($lt{'emad'},undef,$css[$i]). + '&').'" />
'."\n". + &Apache::lonhtmlcommon::row_closure(); + $num ++; + $i = $num%2; + if (defined($uname)) { + $output .= &Apache::lonhtmlcommon::row_title($lt{'emac'},undef,$css[$i]). + '
'."\n". + &Apache::lonhtmlcommon::row_closure(); + $num ++; + $i = $num%2; + } + $output .= &Apache::lonhtmlcommon::row_title("$lt{'unme'}/$lt{'doma'}",undef,$css[$i]); 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_closure(); + $num ++; + $i = $num%2; + $output .= &Apache::lonhtmlcommon::row_title("$lt{'crsd'}$details_title",undef,$css[$i]); + if ($cnum) { if ($coursecodes{$cnum}) { foreach my $item (@codetitles) { $output .= ''.$item.': '.$codes{$cnum}{$item}.'; '; @@ -316,12 +338,13 @@ function initialize_codes() { $output .= $lt{'enin'}.':  '; } else { + my @standardnames = &Apache::loncommon::get_standard_codeitems(); my $lasttitle = $numtitles; if ($numtitles > 4) { $lasttitle = 4; } $output .= ''; for (my $i=1; $i<$numtitles; $i++) { $output .= ''."\n"; @@ -358,7 +381,7 @@ function initialize_codes() { $output .= '
'.$codetitles[0].'
'."\n". - ''."\n". '
'.$codetitles[$i].'
'."\n". - ''."\n". ''."\n". ''."\n". '
'; if ($numtitles > 4) { $output .= '

'.$codetitles[$numtitles].'
'."\n". - ''."\n". ''."\n". ''."\n"; } @@ -376,8 +399,10 @@ function initialize_codes() { $output .= '
'.$lt{'enct'}.':  '."\n"; } - $output .= &Apache::lonhtmlcommon::row_closure(). - &Apache::lonhtmlcommon::row_title($lt{'secn'},undef,'LC_oddrow_value'); + $output .= &Apache::lonhtmlcommon::row_closure(); + $num ++; + $i = $num%2; + $output .= &Apache::lonhtmlcommon::row_title($lt{'secn'},undef,$css[$i]); if ($sectionlist) { $output .= "'; } - $output .= &Apache::lonhtmlcommon::row_closure(). - &Apache::lonhtmlcommon::row_title($lt{'subj'},undef,'LC_evenrow_value'). + $output .= &Apache::lonhtmlcommon::row_closure(); + $num ++; + $i = $num%2; + $output .= &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'). + $num ++; + $i = $num%2; + if (defined($uname)) { + $output .= &Apache::lonhtmlcommon::row_title($lt{'opfi'},undef,$css[$i]). '
'.$lt{'uplf'}."\n". &Apache::lonhtmlcommon::row_closure(); - $lastrow = 'LC_oddrow_value'; + $num ++; + $i = $num%2; } - $output .= &Apache::lonhtmlcommon::row_title($lt{'fini'},undef,$lastrow); + $output .= &Apache::lonhtmlcommon::row_title($lt{'fini'},undef,$css[$i]); $output .= < @@ -449,28 +478,58 @@ sub print_request_receipt { my $to = &Apache::loncommon::build_recipient_list(undef,'helpdeskmail', $defdom,$origmail); my $from = $admin; + my $bcc; + my %domconfig = + &Apache::lonnet::get_dom('configuration',['contacts'],$defdom); + if (ref($domconfig{'contacts'}) eq 'HASH') { + if (exists($domconfig{'contacts'}{'helpdeskmail'})) { + if (ref($domconfig{'contacts'}{'helpdeskmail'}) eq 'HASH') { + my $bccmail = $domconfig{'contacts'}{'helpdeskmail'}{'bcc'}; + if ($bccmail ne '') { + my @bccs = split(/,/,$bccmail); + my @ok_bccs; + foreach my $bcc (@bccs) { + $bcc =~ s/^\s+//g; + $bcc =~ s/\s+$//g; + if ($bcc =~ m/^[^\@]+\@[^\@]+$/) { + if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) { + push(@ok_bccs,$bcc); + } + } + } + if (@ok_bccs > 0) { + $bcc = join(', ',@ok_bccs); + } + } + } + } + } my $reporttime = &Apache::lonlocal::locallocaltime(time); my @formvars = ('username','email','uname','udom','sourceurl','phone','section','coursecode','title','subject','description','screenshot'); &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars); my $coursecode = $env{'form.coursecode'}; if ($coursecode eq '') { - if (defined($env{'form.Year'})) { - $coursecode .= $env{'form.Year'}; - } - if (defined($env{'form.Semester'})) { - $coursecode .= $env{'form.Semester'}; - } - if (defined($env{'form.Department'})) { - $coursecode .= $env{'form.Department'}; - } - if (defined($env{'form.Number'})) { - $coursecode .= $env{'form.Number'}; + my $totcodes = 0; + my %coursecodes; + $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$defdom,$totcodes); + my $coursecode; + my @standardnames = &Apache::loncommon::get_standard_codeitems(); + if ($totcodes > 0) { + $coursecode = &Apache::courseclassifier::instcode_from_selectors($defdom); + } + if ($coursecode eq '') { + foreach my $item (@standardnames) { + if ((defined($env{'form.'.$item})) && ($env{'form.'.$item} ne '-1')) { + $coursecode .= $env{'form.'.$item}; + } + } } } my %lt = &Apache::lonlocal::texthash ( username => 'Name', - email => 'Email', + email => 'E-mail', + cc => 'Cc', user => 'Username/domain', phone => 'Phone', crsi => 'Course Information', @@ -486,15 +545,49 @@ sub print_request_receipt { info => 'Information supplied', adin => 'Additional information recorded', ); - + + my (@ok_ccs,@bad_ccs,$badccmsg,$okcclist); + if ((defined($env{'user.name'})) && (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); + } + } elsif ($cc ne '') { + 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'}; + $env{'form.crsi'} = $env{'form.title'}.' - '.$coursecode.' - '.$lt{'sect'}.': '.$env{'form.section'}; my $supportmsg = <|g; + $descrip = &cleanup_html($descrip); + $descrip =~ s|[\n\r\f]|
|g; $displaymsg .= ''. "$lt{$item}: $descrip
\n"; } elsif ($item eq 'sourceurl') { my $showurl = $env{'form.sourceurl'}; $showurl =~ s/\?.*$//; + $showurl = &cleanup_html($showurl); $displaymsg .= ''. "$lt{$item}: $showurl
\n"; + } elsif ($item eq 'cc') { + $displaymsg .= + ''. + "$lt{$item}: $okcclist
\n"; } else { + my $showitem = $env{'form.'.$item}; + $showitem = &cleanup_html($showitem); $displaymsg .= ''. - "$lt{$item}: $env{'form.'.$item}
\n"; + "$lt{$item}: $showitem
\n"; } } } @@ -549,7 +650,9 @@ END my @ok_email; foreach my $email (split(/,/,$to)) { if ($email =~ m/^[^\@]+\@[^\@]+$/) { - push(@ok_email,$email); + if (!grep(/^\Q$email\E$/,@ok_email)) { + push(@ok_email,$email); + } } } if (@ok_email > 0) { @@ -575,11 +678,19 @@ END $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; @@ -591,7 +702,8 @@ END my $attachmentpath = ''; my $attachmentsize = ''; - if (defined($env{'user.name'})) { + if ((defined($env{'user.name'})) && ($env{'user.name'} ne 'public') + && ($env{'user.domain'} ne 'public')) { if ($env{'form.screenshot.filename'}) { $attachmentsize = length($env{'form.screenshot'}); if ($attachmentsize > 131072) { @@ -610,7 +722,12 @@ END if ($attachmentpath =~ m-/([^/]+)$-) { $fname = $1; - $displaymsg .= '
'.&mt('An uploaded screenshot file \'[_1]\' ([_2] bytes) was included in the request sent by [_3].',$fname,$attachmentsize,$env{'user.name'}.': '.$env{'user.domain'}); + $displaymsg .= '
' + .&mt('An uploaded screenshot file [_1] ([_2] bytes) was included in the request sent by [_3].' + ,''.$fname.'' + ,$attachmentsize + ,$env{'user.name'}.':'.$env{'user.domain'} + ); $supportmsg .= "\n"; foreach my $var (@cookievars) { $supportmsg .= "$var: $cookies{$var}\n"; @@ -630,6 +747,14 @@ END Type =>'TEXT', Data => $supportmsg, ); + if (@ok_ccs > 0) { + my $cc_string = join(', ',@ok_ccs); + $msg->add("Cc" => $cc_string); + } + if ($bcc ne '') { + $msg->add("Bcc" => $bcc); + } + $msg->add('Content-type','text/plain; charset=UTF-8'); if ($attachmentpath) { my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath); @@ -663,7 +788,8 @@ END unlink($attachmentpath); } $r->print(''.$lt{'your'}.':

'."\n"); - $r->print(&Apache::lonhtmlcommon::start_pick_box('LC_helpform_receipt'). + $r->print('
'. + &Apache::lonhtmlcommon::start_pick_box(). &Apache::lonhtmlcommon::row_title($lt{'info'},undef,'LC_oddrow_value')."\n".$displaymsg."\n". &Apache::lonhtmlcommon::row_closure(). &Apache::lonhtmlcommon::row_title($lt{'adin'},undef,'LC_evenrow_value')); @@ -689,7 +815,8 @@ END $envmsg =~ s/, $//; $r->print($envmsg."\n". &Apache::lonhtmlcommon::row_closure(1)."\n". - &Apache::lonhtmlcommon::end_pick_box()."\n". + &Apache::lonhtmlcommon::end_pick_box(). + "
\n". &Apache::loncommon::end_page()); } @@ -705,20 +832,27 @@ sub print_header { login => 'Log-in help', ask => 'Ask helpdesk', getst => 'Getting started guide', - back => 'Back to last location' + back => 'Back to last location', + headline => 'help/support', ); - my ($getstartlink,$getstarttext); + my ($getstartlink,$reviewtext); if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/gettingstarted.html') { $getstartlink = qq| $lt{'getst'}|; - $getstarttext = ' '.&mt('and the "Getting started" guide').' '; + $reviewtext = &mt('Please review the information in "Log-in help" and the "Getting started" guide if you are unable to log-in.'); + } else { + $reviewtext = &mt('Please review the information in "Log-in help" if you are unable to log-in.'); } $r->print(<   -
  LON-CAPA help/support +
+ + + LON-CAPA $lt{'headline'} + - + $getstartlink @@ -734,8 +868,11 @@ END if ($command ne 'process') { $r->print(' - '); } @@ -753,9 +890,27 @@ sub get_domain { } elsif ($env{'request.role.domain'}) { $codedom = $env{'request.role.domain'}; } else { - $codedom = $Apache::lonnet::perlvar{'lonDefDomain'}; + $codedom = &Apache::lonnet::default_login_domain(); } return $codedom; } +sub cleanup_html { + my ($incoming) = @_; + my $outgoing; + if ($incoming ne '') { + $outgoing = $incoming; + $outgoing =~ s/\#/#/g; + $outgoing =~ s/\&/&/g; + $outgoing =~ s//>/g; + $outgoing =~ s/\(/(/g; + $outgoing =~ s/\)/)/g; + $outgoing =~ s/"/"/g; + $outgoing =~ s/'/'/g; + $outgoing =~ s/\$/$/g; + } + return $outgoing; +} + 1;