--- loncom/interface/lonsupportreq.pm 2004/12/18 23:58:34 1.14 +++ loncom/interface/lonsupportreq.pm 2011/03/03 17:29:29 1.66 @@ -1,13 +1,44 @@ +# +# $Id: lonsupportreq.pm,v 1.66 2011/03/03 17:29:29 bisitz Exp $ +# +# Copyright Michigan State University Board of Trustees +# +# This file is part of the LearningOnline Network with CAPA (LON-CAPA). +# +# LON-CAPA is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# LON-CAPA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with LON-CAPA; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# /home/httpd/html/adm/gpl.txt +# +# http://www.lon-capa.org/ +# + package Apache::lonsupportreq; use strict; -use lib qw(/home/httpd/lib/perl); use MIME::Types; use MIME::Lite; +use CGI::Cookie(); use Apache::Constants qw(:common); use Apache::loncommon(); -use Apache::lonnet(); +use Apache::lonhtmlcommon; +use Apache::lonnet; use Apache::lonlocal; +use Apache::lonacc(); +use Apache::courseclassifier; +use LONCAPA qw(:DEFAULT :match); + sub handler { my ($r) = @_; @@ -17,15 +48,19 @@ sub handler { if ($r->header_only) { return OK; } + if ($r->uri eq '/adm/helpdesk') { + &Apache::lonlocal::get_language_handle($r); + } + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['origurl','function']); if ($r->uri eq '/adm/helpdesk') { - &Apache::loncommon::get_posted_cgi($r); + &Apache::lonacc::get_posted_cgi($r); } - my $function = $ENV{'form.function'}; - my $origurl = &Apache::lonnet::unescape($ENV{'form.origurl'}); - my $action = $ENV{'form.action'}; + my $function = $env{'form.function'}; + my $origurl = $env{'form.origurl'}; + my $command = $env{'form.command'}; - if ($action eq 'process') { + if ($command eq 'process') { &print_request_receipt($r,$origurl,$function); } else { &print_request_form($r,$origurl,$function); @@ -35,56 +70,87 @@ 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); - my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0",marginheight="0"',1); - my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg'); - if (($tablecolor eq '') || ($tablecolor eq '#FFFFFF')) { - $tablecolor = '#EEEE99'; - } + my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$urole,$usec,$email,$cid, + $cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server, + $formname,$public); + $function = &Apache::loncommon::get_users_function() if (!$function); $ccode = ''; - $os = $ENV{'browser.os'}; - $browser = $ENV{'browser.type'}; - $bversion = $ENV{'browser.version'}; - $uhost = $ENV{'request.host'}; - $uname = $ENV{'user.name'}; - $udom = $ENV{'user.domain'}; - $uhome = $ENV{'user.home'}; - $urole = $ENV{'request.role'}; - $usec = $ENV{'request.course.sec'}; - $cid = $ENV{'request.course.id'}; - $server = $ENV{'SERVER_NAME'}; - my $scripttag = (<<'END'); + $os = $env{'browser.os'}; + $browser = $env{'browser.type'}; + $bversion = $env{'browser.version'}; + $uhost = $env{'request.host'}; + if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) { + $public = 1; + } else { + $uname = $env{'user.name'}; + $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?://-) { + $server = $origurl; + } else { + $server = $machine.$origurl; + } + my $showserver = $server; + $showserver =~ s/\?.*$//; + my %lt = &Apache::lonlocal::texthash ( + email => 'The e-mail address you entered', + notv => 'is not a valid e-mail address', + rsub => 'You must include a subject', + rdes => 'You must include a description', + name => 'Name', + subm => 'Submit Request', + emad => 'Your e-mail address', + emac => 'Cc', + unme => 'username', + doma => 'domain', + entu => 'Enter the username you use to log-in to LON-CAPA', + chdo => 'Choose your LON-CAPA domain', + 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', + uplf => 'Upload a file (e.g., a screenshot) relevant to your help request (128 KB max.)', + fini => 'Finish', + clfm => 'Clear Form', + ); + my $scripttag = (<<"END"); function validate() { if (validmail(document.logproblem.email) == false) { - alert("The e-mail address you entered: "+document.logproblem.email.value+" is not a valid e-mail address."); + alert("$lt{'email'}: "+document.logproblem.email.value+" $lt{'notv'}."); + return; + } + if (document.logproblem.subject.value == '') { + alert("$lt{'rsub'}."); + return; + } + if (document.logproblem.description.value == '') { + alert("$lt{'rdes'}."); return; } document.logproblem.submit(); } -function validmail(field) { - var str = field.value; - if (window.RegExp) { - var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)"; - var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"; - var reg1 = new RegExp(reg1str); - var reg2 = new RegExp(reg2str); - if (!reg1.test(str) && reg2.test(str)) { - return true; - } - return false; - } - else - { - if(str.indexOf("@") >= 0) { - return true; - } - return false; - } -} END - if ($cid =~ m/_/) { - ($cdom,$cnum) = split/_/,$cid; + $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); @@ -92,586 +158,610 @@ END $ccode = $csettings{'internal.coursecode'}; $sectionlist = $csettings{'internal.sectionnums'}; } - if ($ENV{'environment.critnotification'}) { - $email = $ENV{'environment.critnotification'}; - } - if (!$email && $ENV{'environment.notification'}) { - $email = $ENV{'environment.notification'}; - } - if ($ENV{'environment.lastname'}) { - $lastname = $ENV{'environment.lastname'}; - } - if ($ENV{'environment.firstname'}) { - $firstname = $ENV{'environment.firstname'}; - } - my @sections = split/,/,$sectionlist; - my %groupid = (); - foreach (@sections) { - my ($sec,$grp) = split/:/,$_; + + if ($env{'environment.permanentemail'}) { + $email = $env{'environment.permanentemail'}; + } elsif ($env{'environment.critnotification'}) { + $email = $env{'environment.critnotification'}; + } elsif ($env{'environment.notification'}) { + $email = $env{'environment.notification'}; + } + if ($env{'environment.lastname'}) { + $lastname = $env{'environment.lastname'}; + } + 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; } - my $defdom = $Apache::lonnet::perlvar{'lonDefDomain'}; - my $codedom = $defdom; - my %coursecodes = (); - my %codes = (); - my @codetitles = (); - my %cat_titles = (); - my %cat_order = (); - my %idlist = (); - my %idnums = (); - my %idlist_titles = (); + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['codedom', + 'useremail','useraccount']); + if ($env{'form.origurl'} eq '/adm/createaccount') { + if ($email eq '') { + if ($env{'form.useremail'} =~ /^[^\@]+\@[^\@]+$/) { + $email = &HTML::Entities::encode($env{'form.useremail'},'"<>&'); + } + } + if ($uname eq '') { + if ($env{'form.useraccount'} =~ /^$match_username$/) { + $uname = &HTML::Entities::encode($env{'form.useraccount'},'"<>&'); + } + } + } + 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 = ''; - - if ($cdom) { - $codedom = $cdom; - } + my $loaditems = qq| +function initialize_codes() { + return; +} + |; if ($cnum) { $coursecodes{$cnum} = $ccode; if ($ccode eq '') { - $totcodes = &retrieve_instcodes(\%coursecodes,$codedom,$totcodes); + $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom,$totcodes); } else { $coursecodes{$cnum} = $ccode; $caller = $cnum; $totcodes ++; } } else { - $totcodes = &retrieve_instcodes(\%coursecodes,$codedom,$totcodes); + $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom,$totcodes); } if ($totcodes > 0) { - $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order); if ($ccode eq '') { - my $numtypes = @codetitles; - &build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles); - &javascript_code_selections($numtypes,\$jscript,\%idlist,\%idnums,\%idlist_titles,\@codetitles); - } - } - $r->print(< - - LON-CAPA support request - - -$bodytag -ENDHEAD - if ($r->uri() eq '/adm/helpdesk') { + $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, + 'add_entries' => \%add_entries, + 'only_body' => 1,})); + if ($r->uri eq '/adm/helpdesk') { &print_header($r,$origurl); } - $r->print(<<"END"); - - - - - - - - - - - - - - - - Name: - - - - - - - - -END + 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,$css[$num])."\n"; my $fullname = ''; if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) { $fullname = "$firstname $lastname"; - $r->print("$fullname"); + $output .= $fullname.'&').'" />'; } else { if (defined($firstname) && $firstname ne '') { $fullname = $firstname; } elsif (defined($lastname) && $lastname ne '') { - $fullname= " $lastname"; + $fullname = " $lastname"; } - $r->print(''); + $output .= '&').'" />'; } - $r->print(< - - - - - - - - - - - - - - E-mail address: - - - - - - - - - - - - - - - - - - - - - - - - username/domain: - - - - - - - - -END - my $udom_input = ''; - my $uname_input = ''; - if (defined($uname) && defined($udom)) { - $r->print('username: '.$uname.' domain: '.$udom.$udom_input.$uname_input); + $output .= ' '. + &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 (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { + $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 = '&').'" />'; + if (($env{'user.name'} =~ /^$match_username$/) && + ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) { + $output .= ''.$lt{'unme'}.': '.$uname.' '.$lt{'doma'}.': '.$udom.$udom_input.$uname_input; } else { my $udomform = ''; my $unameform = ''; - if (defined($udom)) { - $udomform = 'domain: '.$udom.$udom_input; - } elsif (defined($uname)) { - $unameform = 'username: '.$uname.' '.$uname_input; + if (($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) { + $output .= $lt{'entu'}; + } elsif (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { + $output .= $lt{'chdo'}; + } else { + $output .= $lt{'entr'}; + } + $output .= ''; + if (!$public) { + if ($env{'user.domain'} =~ /^$match_domain$/) { + $udomform = ''.$lt{'doma'}.': '.$udom.$udom_input; + } elsif ($env{'user.name'} =~ /^$match_username$/) { + $unameform = ''.$lt{'unme'}.': '.$uname.' '.$uname_input; + } } if ($udomform eq '') { - $udomform = 'domain: '; - $udomform .= &Apache::loncommon::select_dom_form('','udom'); + $udomform = ''.$lt{'doma'}.': '; + $udomform .= &Apache::loncommon::select_dom_form($codedom,'udom'); } if ($unameform eq '') { - $unameform= 'username: '; + $unameform= ''.$lt{'unme'}.': '; } - $r->print($unameform.$udomform.'Enter the username you use to log-in to your LON-CAPA system, and choose your domain.'); + $output .= $unameform.$udomform; } - $r->print(< - - - - - - - - - - - - - - URL of page: - - - - - - - - - http://$server$origurl - - - - - - - - - - - - - - - Phone #: - - - - - - - - - - - - - - - - - - - - - - - - Course Details: - - - - - - - - -END - if ($cnum) { + $output .= &Apache::lonhtmlcommon::row_closure(); + $num ++; + $i = $num%2; + $output .= &Apache::lonhtmlcommon::row_title("$lt{'urlp'}",undef,$css[$i]). + $showserver.'&').'" />'. + &Apache::lonhtmlcommon::row_closure(). + &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 (@codetitles) { - $r->print(''.$_.': '.$codes{$cnum}{$_}.'; '); + foreach my $item (@codetitles) { + $output .= ''.$item.': '.$codes{$cnum}{$item}.'; '; } - $r->print(' '); + $output .= ' &').'" />'; } else { - $r->print('Enter institutional course code: - '); + $output .= $lt{'enin'}.': + '; } } else { if ($totcodes > 0) { my $numtitles = @codetitles; if ($numtitles == 0) { - $r->print('Enter institutional course code: - '); + $output .= $lt{'enin'}.': + '; } else { + my @standardnames = &Apache::loncommon::get_standard_codeitems(); my $lasttitle = $numtitles; if ($numtitles > 4) { $lasttitle = 4; } - $r->print(''.$codetitles[0].''."\n". - ''."\n". - ' Select'."\n"); + $output .= ''.$codetitles[0].''."\n". + ''."\n". + ' '.$lt{'sele'}."\n"; my @items = (); + my @longitems = (); if ($idlist{$codetitles[0]} =~ /","/) { - @items = split/","/,$idlist{$codetitles[0]}; + @items = split(/","/,$idlist{$codetitles[0]}); } else { $items[0] = $idlist{$codetitles[0]}; } - foreach (@items) { - $r->print(' '.$_); + if (defined($idlist_titles{$codetitles[0]})) { + if ($idlist_titles{$codetitles[0]} =~ /","/) { + @longitems = split(/","/,$idlist_titles{$codetitles[0]}); + } else { + $longitems[0] = $idlist_titles{$codetitles[0]}; + } + for (my $i=0; $i<@longitems; $i++) { + if ($longitems[$i] eq '') { + $longitems[$i] = $items[$i]; + } + } + } else { + @longitems = @items; } - $r->print(''); + for (my $i=0; $i<@items; $i++) { + $output .= ' '.$longitems[$i].''."\n"; + } + $output .= ''; for (my $i=1; $i<$numtitles; $i++) { - $r->print(''.$codetitles[$i].''."\n". - ''."\n". - '<-Pick '.$codetitles[$i-1].''."\n". + $output .= ''.$codetitles[$i].''."\n". + ''."\n". + '<-'.$lt{'pick'}.' '.$codetitles[$i-1].''."\n". ''."\n". - '' - ); + ''."\n"; } - $r->print(''); + $output .= ''; if ($numtitles > 4) { - $r->print(''.$codetitles[$numtitles].''."\n". - ''."\n". - '<-Pick '.$codetitles[$numtitles-1].''."\n". - ''."\n"); + $output .= ''.$codetitles[$numtitles].''."\n". + ''."\n". + '<-'.$lt{'pick'}.' '.$codetitles[$numtitles-1].''."\n". + ''."\n"; } } } else { - $r->print('Enter institutional course code: - '); + $output .= $lt{'enin'}.': + '; } } if ($ctitle) { - $r->print('Title: '.$ctitle.''); + $output .= ''.$lt{'titl'}.': '.$ctitle. + '&').'" />'."\n"; } else { - $r->print('Enter course title: - '); + $output .= ''.$lt{'enct'}.': + '."\n"; } - $r->print(< - - - - - - - - - - - - - - Section Number: - - - - - - - - -END + $output .= &Apache::lonhtmlcommon::row_closure(); + $num ++; + $i = $num%2; + $output .= &Apache::lonhtmlcommon::row_title($lt{'secn'},undef,$css[$i]); if ($sectionlist) { - $r->print(""); - foreach (sort keys %groupid) { - if ($_ eq $groupid{$_} || $groupid{$_} eq '') { - $r->print("$_"); + $output .= "". + " $lt{'sele'}\n"; + foreach my $id (sort(keys(%groupid))) { + if ($id eq $groupid{$id} || $groupid{$id} eq '') { + $output .= " &'). + " >$id\n"; } else { - $r->print("$_ - (LON-CAPA sec: $groupid{$_})"); + $output .= " &'). + " >$id - ($lt{'lsec'}: $groupid{$id})\n"; } } - $r->print(""); + $output .= ""; } else { - $r->print(""); + $output .= ''; } - $r->print(< - - - - - - - - - - - - - - Subject - - - - - - - - - - - - - - - - - - - - - - - - Detailed description: - - - - - - - - - - - - - - - - - - - -END - if (defined($ENV{'user.name'})) { - $r->print(< - - - - Optional file upload: - - - - - - - - - Upload a file (e.g., a screenshot) relevant to your support request (128 KB max. size). - - - - - - - - - - -END + $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_evenrow_value'). + ' '. + &Apache::lonhtmlcommon::row_closure(); + $num ++; + $i = $num%2; + if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { + $output .= &Apache::lonhtmlcommon::row_title($lt{'opfi'},undef,$css[$i]). + ' '.$lt{'uplf'}."\n". + &Apache::lonhtmlcommon::row_closure(); + $num ++; + $i = $num%2; } - $r->print(< - - - - Finish: - - - - - + $output .= &Apache::lonhtmlcommon::row_title($lt{'fini'},undef,$css[$i]); + $output .= < - - + + - + - - - - - - - - - - - - +END + $output .= &Apache::lonhtmlcommon::row_closure(1); + $output .= &Apache::lonhtmlcommon::end_pick_box(); + $r->print(< -