--- loncom/interface/lonsupportreq.pm 2010/12/03 04:56:56 1.55.6.4 +++ loncom/interface/lonsupportreq.pm 2012/02/08 17:49:01 1.66.6.1 @@ -1,5 +1,5 @@ # -# $Id: lonsupportreq.pm,v 1.55.6.4 2010/12/03 04:56:56 raeburn Exp $ +# $Id: lonsupportreq.pm,v 1.66.6.1 2012/02/08 17:49:01 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -36,8 +36,8 @@ use Apache::lonhtmlcommon; use Apache::lonnet; use Apache::lonlocal; use Apache::lonacc(); -use Apache::courseclassifier; -use LONCAPA qw(:DEFAULT :match); +use LONCAPA qw(:DEFAULT :match); + sub handler { my ($r) = @_; @@ -69,9 +69,8 @@ sub handler { sub print_request_form { my ($r,$origurl,$function) = @_; - my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$urole,$usec,$email,$cid, - $cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server, - $formname,$public); + my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$email, + $lastname,$firstname,$server,$formname,$public); $function = &Apache::loncommon::get_users_function() if (!$function); $ccode = ''; $os = $env{'browser.os'}; @@ -85,9 +84,6 @@ sub print_request_form { $udom = $env{'user.domain'}; } $uhome = $env{'user.home'}; - $urole = $env{'request.role'}; - $usec = $env{'request.course.sec'}; - $cid = $env{'request.course.id'}; $formname = 'logproblem'; my $machine = &Apache::lonnet::absolute_url(); if ($origurl =~ m-^https?://-) { @@ -113,14 +109,7 @@ sub print_request_form { entr => 'Enter the username you use to log-in to LON-CAPA, and your domain.', urlp => 'URL of page', phon => 'Phone', - crsd => 'Course Details', - enin => 'Enter institutional course code', pick => 'Pick', - enct => 'Enter course title', - secn => 'Section Number', - sele => 'Select', - titl => 'Title', - lsec => 'LON-CAPA sec', subj => 'Subject', detd => 'Detailed Description', opfi => 'Optional file upload', @@ -147,16 +136,6 @@ function validate() { END $scripttag .= &Apache::lonhtmlcommon::javascript_valid_email(); - if ($cid) { - $cdom = $env{'course.'.$cid.'.domain'}; - $cnum = $env{'course.'.$cid.'.num'}; - } - if ($cdom && $cnum) { - my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum); - $ctitle = $csettings{'description'}; - $ccode = $csettings{'internal.coursecode'}; - $sectionlist = $csettings{'internal.sectionnums'}; - } if ($env{'environment.permanentemail'}) { $email = $env{'environment.permanentemail'}; @@ -171,12 +150,7 @@ END if ($env{'environment.firstname'}) { $firstname = $env{'environment.firstname'}; } - my @sections = split(/,/,$sectionlist); - my %groupid; - foreach my $section (@sections) { - my ($sec,$grp) = split(/:/,$section); - $groupid{$sec} = $grp; - } + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['codedom', 'useremail','useraccount']); if ($env{'form.origurl'} eq '/adm/createaccount') { @@ -192,62 +166,14 @@ END } } my $codedom = &get_domain(); - my $details_title; - if ($codedom) { - $details_title = '
('.$codedom.')'; - } - my %coursecodes; - my %codes; - my @codetitles; - my %cat_titles; - my %cat_order; - my %idlist; - my %idnums; - my %idlist_titles; my $caller = 'global'; - my $totcodes = 0; my $format_reply; my $jscript = ''; - my $loaditems = qq| -function initialize_codes() { - return; -} - |; - if ($cnum) { - $coursecodes{$cnum} = $ccode; - if ($ccode eq '') { - $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom,$totcodes); - } else { - $coursecodes{$cnum} = $ccode; - $caller = $cnum; - $totcodes ++; - } - } else { - $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom,$totcodes); - } - if ($totcodes > 0) { - if ($ccode eq '') { - $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order); - if ($format_reply eq 'ok') { - my $numtypes = @codetitles; - &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles); - my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles); - my $longtitles_str = join('","',@{$longtitles}); - my $allidlist = $idlist{$codetitles[0]}; - $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist); - $jscript .= $scripttext; - $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,@codetitles); - $loaditems = ''; - } - } - } - my $js = ''; + ''; my %add_entries = (topmargin => "0", marginheight => "0", - onLoad =>"initialize_codes()",); - + ); $r->print(&Apache::loncommon::start_page('Support Request',$js, { 'function' => $function, @@ -296,7 +222,7 @@ function initialize_codes() { &HTML::Entities::encode($udom,'"<>&').'" />'; my $uname_input = '&').'" />'; - if (($env{'user.name'} =~ /^$match_username$/) && + if (($env{'user.name'} =~ /^$match_username$/) && ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) { $output .= ''.$lt{'unme'}.': '.$uname.'  '.$lt{'doma'}.': '.$udom.$udom_input.$uname_input; } else { @@ -304,7 +230,7 @@ function initialize_codes() { my $unameform = ''; if (($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) { $output .= $lt{'entu'}; - } elsif (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { + } elsif (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { $output .= $lt{'chdo'}; } else { $output .= $lt{'entr'}; @@ -332,117 +258,13 @@ function initialize_codes() { $output .= &Apache::lonhtmlcommon::row_title("$lt{'urlp'}",undef,$css[$i]). $showserver.'&').'" />'. + &Apache::lonhtmlcommon::row_closure(). + $num ++; + $i = $num%2; + $output .= &Apache::lonhtmlcommon::row_title("$lt{'phon'}",undef, + 'LC_evenrow_value'). + '
'. &Apache::lonhtmlcommon::row_closure(); - if (&Apache::loncommon::check_for_gci_dc()) { - $output .= &Apache::lonhtmlcommon::row_title("$lt{'phon'}",undef, - 'LC_evenrow_value'). - '
'. - &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}.'; '; - } - $output .= ' &').'" />'; - } else { - $output .= $lt{'enin'}.':  - '; - } - } else { - if ($totcodes > 0) { - my $numtitles = @codetitles; - if ($numtitles == 0) { - $output .= $lt{'enin'}.':  - '; - } else { - my $lasttitle = $numtitles; - if ($numtitles > 4) { - $lasttitle = 4; - } - $output .= ''; - for (my $i=1; $i<$numtitles; $i++) { - $output .= ''."\n"; - } - $output .= '
'.$codetitles[0].'
'."\n". - '
'.$codetitles[$i].'
'."\n". - ''."\n". - '
'; - if ($numtitles > 4) { - $output .= '

'.$codetitles[$numtitles].'
'."\n". - ''."\n"; - } - } - } else { - $output .= $lt{'enin'}.':  - '; - } - } - $output .= '
'; - if ($ctitle) { - $output .= ''.$lt{'titl'}.': '.$ctitle. - '&').'" />'."\n"; - } else { - $output .= $lt{'enct'}.':  - '."\n"; - } - $output .= &Apache::lonhtmlcommon::row_closure(); - $num ++; - $i = $num%2; - $output .= &Apache::lonhtmlcommon::row_title($lt{'secn'},undef,$css[$i]); - if ($sectionlist) { - $output .= ""; - } else { - $output .= ''; - } - $output .= &Apache::lonhtmlcommon::row_closure(); - } $num ++; $i = $num%2; $output .= &Apache::lonhtmlcommon::row_title($lt{'subj'},undef,'LC_oddrow_value'). @@ -453,7 +275,7 @@ function initialize_codes() { &Apache::lonhtmlcommon::row_closure(); $num ++; $i = $num%2; - if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { + if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { $output .= &Apache::lonhtmlcommon::row_title($lt{'opfi'},undef,$css[$i]). '
'.$lt{'uplf'}."\n". &Apache::lonhtmlcommon::row_closure(); @@ -499,46 +321,48 @@ sub print_request_receipt { 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'); - if (&Apache::loncommon::check_for_gci_dc()) { - push(@formvars,('phone','section','coursecode','title')); - } - push(@formvars,('subject','description','screenshot')); - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars); - my $coursecode = $env{'form.coursecode'}; - if (&Apache::loncommon::check_for_gci_dc()) { - 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 $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', + 'subject','description','screenshot'); + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars); my %lt = &Apache::lonlocal::texthash ( username => 'Name', email => 'E-mail', cc => 'Cc', user => 'Username/domain', phone => 'Phone', - crsi => 'Course Information', subject => 'Subject', description => 'Description', sourceurl => 'URL', date => 'Date/Time', - secn => 'Section', - asup => 'A support request has been sent to', warn => 'Warning: Problem with support e-mail address', your => 'Your support request contained the following information', - sect => 'section', info => 'Information supplied', adin => 'Additional information recorded', ); @@ -560,7 +384,7 @@ sub print_request_receipt { if (!(grep(/^\Q$cc\E$/,@ok_ccs))) { push(@ok_ccs,$cc); } - } else { + } elsif ($cc ne '') { if (!(grep(/^\Q$cc\E$/,@bad_ccs))) { push(@bad_ccs,$cc); } @@ -577,22 +401,12 @@ sub print_request_receipt { } } $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'"; - if (&Apache::loncommon::check_for_gci_dc()) { - $env{'form.csri'} = $env{'form.title'}.' - '.$coursecode.' - '.$lt{'sect'}.': '.$env{'form.section'}; - } my $supportmsg = <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'; + + my $message; + if (!$bad_email) { + $message = &Apache::lonhtmlcommon::confirm_success( + &mt('A support request has been sent to [_1]',''.$to.'')); } else { - $r->print('

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

'); + $message = &Apache::lonhtmlcommon::confirm_success( + $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 [_2]not[_3] 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.'),1); + $to = 'helpdesk@lon-capa.org'; } + $r->print(&Apache::loncommon::confirmwrapper($message)); + if (defined($env{'form.email'})) { $env{'form.email'} =~ s/^\s+//; $env{'form.email'} =~ s/\s+$//; @@ -712,7 +528,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) { @@ -733,7 +550,7 @@ END $fname = $1; $displaymsg .= '
' .&mt('An uploaded screenshot file [_1] ([_2] bytes) was included in the request sent by [_3].' - ,''.$fname.'' + ,''.$fname.'' ,$attachmentsize ,$env{'user.name'}.':'.$env{'user.domain'} ); @@ -760,6 +577,11 @@ END my $cc_string = join(', ',@ok_ccs); $msg->add("Cc" => $cc_string); } + if ($bcc ne '') { + $msg->add("Bcc" => $bcc); + } + $msg->attr("content-type" => "text/plain"); + $msg->attr("content-type.charset" => "UTF-8"); if ($attachmentpath) { my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath);