--- loncom/interface/lonsupportreq.pm 2004/12/18 23:58:34 1.14 +++ loncom/interface/lonsupportreq.pm 2005/04/07 06:56:23 1.25 @@ -1,3 +1,29 @@ +# +# $Id: lonsupportreq.pm,v 1.25 2005/04/07 06:56:23 albertel 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; @@ -6,7 +32,7 @@ use MIME::Types; use MIME::Lite; use Apache::Constants qw(:common); use Apache::loncommon(); -use Apache::lonnet(); +use Apache::lonnet; use Apache::lonlocal; sub handler { @@ -21,9 +47,9 @@ sub handler { if ($r->uri eq '/adm/helpdesk') { &Apache::loncommon::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 = &Apache::lonnet::unescape($env{'form.origurl'}); + my $action = $env{'form.action'}; if ($action eq 'process') { &print_request_receipt($r,$origurl,$function); @@ -36,23 +62,27 @@ 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 $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0" marginheight="0" onLoad="initialize_codes()"',1); my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg'); if (($tablecolor eq '') || ($tablecolor eq '#FFFFFF')) { $tablecolor = '#EEEE99'; } $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'}; + $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'}; + if ($origurl =~ m-^http://-) { + $server = $origurl; + } else { + $server = 'http://'.$ENV{'SERVER_NAME'}.$origurl; + } my $scripttag = (<<'END'); function validate() { if (validmail(document.logproblem.email) == false) { @@ -83,6 +113,7 @@ function validmail(field) { } } END + #" stupid emacs if ($cid =~ m/_/) { ($cdom,$cnum) = split/_/,$cid; } @@ -92,17 +123,17 @@ END $ccode = $csettings{'internal.coursecode'}; $sectionlist = $csettings{'internal.sectionnums'}; } - if ($ENV{'environment.critnotification'}) { - $email = $ENV{'environment.critnotification'}; + if ($env{'environment.critnotification'}) { + $email = $env{'environment.critnotification'}; } - if (!$email && $ENV{'environment.notification'}) { - $email = $ENV{'environment.notification'}; + if (!$email && $env{'environment.notification'}) { + $email = $env{'environment.notification'}; } - if ($ENV{'environment.lastname'}) { - $lastname = $ENV{'environment.lastname'}; + if ($env{'environment.lastname'}) { + $lastname = $env{'environment.lastname'}; } - if ($ENV{'environment.firstname'}) { - $firstname = $ENV{'environment.firstname'}; + if ($env{'environment.firstname'}) { + $firstname = $env{'environment.firstname'}; } my @sections = split/,/,$sectionlist; my %groupid = (); @@ -110,8 +141,15 @@ END my ($sec,$grp) = split/:/,$_; $groupid{$sec} = $grp; } - my $defdom = $Apache::lonnet::perlvar{'lonDefDomain'}; - my $codedom = $defdom; + 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 $details_title; + if ($codedom) { + $details_title = '
('.$codedom.')'; + } my %coursecodes = (); my %codes = (); my @codetitles = (); @@ -124,7 +162,11 @@ END my $totcodes = 0; my $format_reply; my $jscript = ''; - + my $loaditems = qq| +function initialize_codes() { + return; +} + |; if ($cdom) { $codedom = $cdom; } @@ -141,28 +183,33 @@ END $totcodes = &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); + $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order); + if ($format_reply eq 'ok') { + my $numtypes = @codetitles; + &build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles); + &javascript_code_selections($numtypes,\%cat_titles,\$jscript,\%idlist,\%idnums,\%idlist_titles,\@codetitles); + $loaditems = ''; + } } } + my $html=&Apache::lonxml::xmlbegin(); $r->print(< +$html LON-CAPA support request - $bodytag ENDHEAD - if ($r->uri() eq '/adm/helpdesk') { + if ($r->uri eq '/adm/helpdesk') { &print_header($r,$origurl); } $r->print(<<"END"); +
@@ -173,7 +220,6 @@ ENDHEAD
- '); for (my $i=1; $i<$numtitles; $i++) { @@ -430,12 +492,13 @@ END END - if (defined($ENV{'user.name'})) { + if (defined($env{'user.name'})) { $r->print(< |; + $getstarttext = ' '.&mt('and the "Getting started" guide').' '; + } $r->print(< '); } @@ -918,9 +1000,9 @@ sub build_code_selections { my @sorted_b = (); my @sorted_b_titles = (); &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[2]}{$key_a}{$key_b}},\@sorted_b); - if (defined($$cat_titles{$$codetitles[1]})) { + if (defined($$cat_titles{$$codetitles[2]})) { foreach (@sorted_b) { - push @sorted_b_titles, $$cat_titles{$$codetitles[1]}{$_}; + push @sorted_b_titles, $$cat_titles{$$codetitles[2]}{$_}; } } $$idlist{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_b); @@ -938,9 +1020,18 @@ sub build_code_selections { %{$$idlist{$$codetitles[3]}{$key_a}{$key_b}} = (); foreach my $key_c (keys %{$idarrays{$$codetitles[3]}{$key_a}{$key_b}}) { my @sorted_c = (); + my @sorted_c_titles = (); &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[3]}{$key_a}{$key_b}{$key_c}},\@sorted_c); + if (defined($$cat_titles{$$codetitles[3]})) { + foreach (@sorted_c) { + push @sorted_c_titles, $$cat_titles{$$codetitles[3]}{$_}; + } + } $$idlist{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = join('","',@sorted_c); $$idnums{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = scalar(@sorted_c); + if (defined($$cat_titles{$$codetitles[3]})) { + $$idlist_titles{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_c_titles); + } } } } @@ -954,7 +1045,13 @@ sub build_code_selections { %{$$idlist{$$codetitles[4]}{$key_a}{$key_b}{$key_c}} = (); foreach my $key_d (keys %{$idarrays{$$codetitles[4]}{$key_a}{$key_b}{$key_c}}) { my @sorted_d = (); + my @sorted_d_titles = (); &sort_cats($num,$cat_order,$codetitles,$idarrays{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d},\@sorted_d); + if (defined($$cat_titles{$$codetitles[4]})) { + foreach (@sorted_d) { + push @sorted_d_titles, $$cat_titles{$$codetitles[4]}{$_}; + } + } $$idlist{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d} = join('","',@sorted_d); $$idnums{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d} = scalar(@sorted_d); } @@ -1060,94 +1157,182 @@ sub recurse_list { } sub javascript_code_selections { - my ($numcats,$script_tag,$idlist,$idnums,$idlist_titles,$codetitles) = @_; + my ($numcats,$cat_titles,$script_tag,$idlist,$idnums,$idlist_titles,$codetitles) = @_; my $numtitles = @{$codetitles}; - my @seltitles = (); + my @seltitles = (); for (my $j=0; $j<$numtitles; $j++) { $seltitles[$j] = 'id'.$$codetitles[$j]; } my $seltitle_str = join('","',@seltitles); + my @longtitles = (); + for (my $i=0; $i<$numtitles; $i++) { + if (defined($$cat_titles{$$codetitles[$i]})) { + $longtitles[$i] = 1; + } else { + $longtitles[$i] = 0; + } + } + my $longtitles_str = join('","',@longtitles); $$script_tag .= <
@@ -198,9 +244,10 @@ END } elsif (defined($lastname) && $lastname ne '') { $fullname= " $lastname"; } - $r->print('
'); + $r->print(''); } $r->print(< 
@@ -263,10 +310,10 @@ END } if ($udomform eq '') { $udomform = 'domain: '; - $udomform .= &Apache::loncommon::select_dom_form('','udom'); + $udomform .= &Apache::loncommon::select_dom_form($codedom,'udom'); } if ($unameform eq '') { - $unameform= 'username  '; + $unameform= 'username  '; } $r->print($unameform.$udomform.'
Enter the username you use to log-in to your LON-CAPA system, and choose your domain.'); } @@ -294,7 +341,7 @@ END
- http://$server$origurl + $server
@@ -333,7 +380,7 @@ END
-
Course Details: + Course Details:$details_title
@@ -368,13 +415,28 @@ END '
END if ($sectionlist) { - $r->print("". + " \n"); foreach (sort keys %groupid) { if ($_ eq $groupid{$_} || $groupid{$_} eq '') { - $r->print("\n"); } else { - $r->print("\n"); } } $r->print(""); @@ -502,7 +565,7 @@ END
@@ -545,7 +608,7 @@ END
-   +     @@ -586,39 +649,58 @@ sub print_request_receipt { my $vlinkcolor = &Apache::loncommon::designparm($function.'.vlink'); my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg'); my @formvars = ('username','email','uname','udom','sourceurl','phone','section','coursecode','title','subject','description','screenshot'); - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars); + &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 $supportmsg = qq| -Name: $ENV{'form.username'} -Email: $ENV{'form.email'} -Username/domain: $ENV{'form.uname'} - $ENV{'form.udom'} -Tel: $ENV{'form.phone'} -Course Information: $ENV{'form.title'} - $ENV{'form.coursecode'} - section: $ENV{'form.section'} -Subject: $ENV{'form.subject'} -Description: $ENV{'form.description'} -URL: $ENV{'form.sourceurl'} +Name: $env{'form.username'} +Email: $env{'form.email'} +Username/domain: $env{'form.uname'} - $env{'form.udom'} +Tel: $env{'form.phone'} +Course Information: $env{'form.title'} - $coursecode - section: $env{'form.section'} +Subject: $env{'form.subject'} +Description: $env{'form.description'} +URL: $env{'form.sourceurl'} Date/Time: $reporttime |; - my $descrip = $ENV{'form.description'}; + my $descrip = $env{'form.description'}; $descrip =~ s#\n#
#g; my $displaymsg = qq| -Name: $ENV{'form.username'}
-Email: $ENV{'form.email'}
-Username/domain: $ENV{'form.uname'} - $ENV{'form.udom'}
-Tel: $ENV{'form.phone'}
-Course Information: $ENV{'form.title'} - $ENV{'form.coursecode'} - section: $ENV{'form.section'}
-Subject: $ENV{'form.subject'}
+Name: $env{'form.username'}
+Email: $env{'form.email'}
+Username/domain: $env{'form.uname'} - $env{'form.udom'}
+Tel: $env{'form.phone'}
+Course Information: $env{'form.title'} - $coursecode - section: $env{'form.section'}
+Subject: $env{'form.subject'}
Description: $descrip
-URL: $ENV{'form.sourceurl'}
+URL: $env{'form.sourceurl'}
Date/Time: $reporttime
|; + my $html=&Apache::lonxml::xmlbegin(); $r->print(<<"END"); - +$html LON-CAPA support request recorded $bodytag + + + END if ($r->uri eq '/adm/helpdesk') { &print_header($r,$url,'process'); @@ -638,13 +720,13 @@ END $to = 'helpdesk@lon-capa.org'; } } - if (defined($ENV{'form.email'})) { - if ($ENV{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) { - $from = $ENV{'form.email'}; + if (defined($env{'form.email'})) { + if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) { + $from = $env{'form.email'}; } } - my $subject = $ENV{'form.subject'}; + my $subject = $env{'form.subject'}; $subject =~ s#(`)#'#g; $subject =~ s#\$#\(\$\)#g; $supportmsg =~ s#(`)#'#g; @@ -655,9 +737,9 @@ END my $attachmentpath = ''; my $attachmentsize = ''; - if (defined($ENV{'user.name'})) { - if ($ENV{'form.screenshot.filename'}) { - $attachmentsize = length($ENV{'form.screenshot'}); + if (defined($env{'user.name'})) { + if ($env{'form.screenshot.filename'}) { + $attachmentsize = length($env{'form.screenshot'}); if ($attachmentsize > 131072) { $displaymsg .= "
The uploaded screenshot file ($attachmentsize bytes) included with your request exceeded the maximum allowed size - 128 KB, and has therefore been discarded."; } else { @@ -668,10 +750,10 @@ END if ($attachmentpath =~ m-/([^/]+)$-) { $fname = $1; - $displaymsg .= "
An uploaded screenshot file - $fname ($attachmentsize bytes) was included in the request sent by $ENV{'user.name'} from LON-CAPA domain: $ENV{'user.domain'}"; + $displaymsg .= "
An uploaded screenshot file - $fname ($attachmentsize bytes) was included in the request sent by $env{'user.name'} from LON-CAPA domain: $env{'user.domain'}"; $supportmsg .= "\n"; foreach (@envvars) { - $supportmsg .= "$_: $ENV{$_}\n"; + $supportmsg .= "$_: $env{$_}\n"; } } @@ -693,23 +775,19 @@ END } else { my $envdata = ''; foreach (@envvars) { - $envdata .= "$_: $ENV{$_}\n"; + $envdata .= "$_: $env{$_}\n"; } foreach (@loncvars) { - $envdata .= "$_: $ENV{$_}\n"; + $envdata .= "$_: $env{$_}\n"; } $msg->attach(Type => 'TEXT', Data => $envdata); } ### Send it: - # ->send can cause an sh launch which can pass all of %ENV along + # ->send can cause an sh launch which can pass all of %env along # which can be to large for /bin/sh's little mind - my %oldENV=%ENV; - undef(%ENV); $msg->send('sendmail'); - %ENV=%oldENV; - undef(%oldENV); if ($attachmentpath =~ m#$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+#) { unlink($attachmentpath); @@ -763,8 +841,8 @@ END
|); foreach (@envvars) { - unless($ENV{$_} eq '') { - $r->print("$_: $ENV{$_}, "); + unless($env{$_} eq '') { + $r->print("$_: $env{$_}, "); } } $r->print(" @@ -802,7 +880,12 @@ sub print_header { ask => 'Ask helpdesk', getst => 'Getting started guide', back => 'Back to last location' - ); + ); + my ($getstartlink,$getstarttext); + if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/gettingstarted.html') { + $getstartlink = qq| $lt{'getst'}
  @@ -819,8 +902,7 @@ sub print_header { - - + $getstartlink
(Login help) $lt{'login'} $helpdesk_link(Ask helpdesk) $lt{'ask'}  $lt{'getst'} $helpdesk_link(Ask helpdesk) $lt{'ask'}  (Back to last location) $lt{'back'} 
@@ -845,7 +927,7 @@ END $r->print('
'.&mt(' -Please read the "Log-in help" and "Getting started guide" if you can not log-in').'. '.&mt('If your problem is still unresolved, the form below can be used to send a question to the LON-CAPA helpdesk').'.
'.&mt('Note').': '.&mt('Student questions about course content should be directed to the course instructor').'.

+Please review the information in "Log-in help"').$getstarttext.' '.&mt('if you are unable to log-in').'. '.&mt('If your problem is still unresolved, the form below can be used to send a question to the LON-CAPA helpdesk').'.
'.&mt('Note').': '.&mt('Student questions about course content should be directed to the course instructor').'.