--- loncom/interface/lonsupportreq.pm 2006/10/12 22:47:31 1.38
+++ loncom/interface/lonsupportreq.pm 2007/05/07 14:02:45 1.43
@@ -1,5 +1,5 @@
#
-# $Id: lonsupportreq.pm,v 1.38 2006/10/12 22:47:31 raeburn Exp $
+# $Id: lonsupportreq.pm,v 1.43 2007/05/07 14:02:45 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -27,17 +27,16 @@
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::lonhtmlcommon;
use Apache::lonnet;
use Apache::lonlocal;
use Apache::lonacc();
use Apache::courseclassifier;
-use lib '/home/httpd/lib/perl/';
use LONCAPA;
@@ -49,6 +48,10 @@ 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::lonacc::get_posted_cgi($r);
@@ -84,44 +87,61 @@ sub print_request_form {
$usec = $env{'request.course.sec'};
$cid = $env{'request.course.id'};
$formname = 'logproblem';
- if ($origurl =~ m-^http://-) {
+ my $machine = &Apache::lonnet::absolute_url();
+ if ($origurl =~ m-^https?://-) {
$server = $origurl;
} else {
- $server = 'http://'.$ENV{'SERVER_NAME'}.$origurl;
+ $server = $machine.$origurl;
}
- my $scripttag = (<<'END');
+ 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 => 'E-mail address',
+ unme => 'username',
+ doma => 'domain',
+ entr => 'Enter the username you use to log-in to your LON-CAPA system, and choose 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 support request (128 KB max. size)',
+ 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
-
+ $scripttag .= &Apache::lonhtmlcommon::javascript_valid_email();
if ($cid =~ m/_/) {
- ($cdom,$cnum) = split/_/,$cid;
+ ($cdom,$cnum) = split(/_/,$cid);
}
if ($cdom && $cnum) {
my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
@@ -141,10 +161,10 @@ END
if ($env{'environment.firstname'}) {
$firstname = $env{'environment.firstname'};
}
- my @sections = split/,/,$sectionlist;
- my %groupid = ();
- foreach (@sections) {
- my ($sec,$grp) = split/:/,$_;
+ my @sections = split(/,/,$sectionlist);
+ my %groupid;
+ foreach my $section (@sections) {
+ my ($sec,$grp) = split(/:/,$section);
$groupid{$sec} = $grp;
}
my $codedom = $Apache::lonnet::perlvar{'lonDefDomain'};
@@ -156,14 +176,14 @@ END
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 %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;
@@ -237,7 +257,7 @@ function initialize_codes() {
@@ -260,7 +280,7 @@ END
$r->print(' ');
}
$r->print(<
+
@@ -275,7 +295,7 @@ END
- E-mail address:
+ $lt{'emad'}:
@@ -299,7 +319,7 @@ END
- username/domain:
+ $lt{'unme'}/$lt{'doma'}:
@@ -312,23 +332,23 @@ END
my $udom_input = ' ';
my $uname_input = ' ';
if (defined($uname) && defined($udom)) {
- $r->print('username : '.$uname.' domain : '.$udom.$udom_input.$uname_input);
+ $r->print(''.$lt{'unme'}.' : '.$uname.' '.$lt{'doma'}.' : '.$udom.$udom_input.$uname_input);
} else {
my $udomform = '';
my $unameform = '';
if (defined($udom)) {
- $udomform = 'domain : '.$udom.$udom_input;
+ $udomform = ''.$lt{'doma'}.' : '.$udom.$udom_input;
} elsif (defined($uname)) {
- $unameform = 'username : '.$uname.' '.$uname_input;
+ $unameform = ''.$lt{'unme'}.' : '.$uname.' '.$uname_input;
}
if ($udomform eq '') {
- $udomform = 'domain : ';
+ $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.');
+ $r->print($unameform.$udomform.' '.$lt{'entr'});
}
$r->print(<
@@ -345,7 +365,7 @@ END
- URL of page:
+ $lt{'urlp'}:
@@ -369,7 +389,7 @@ END
- Phone #:
+ $lt{'phon'} #:
@@ -393,7 +413,7 @@ END
- Course Details: $details_title
+ $lt{'crsd'}: $details_title
@@ -405,19 +425,19 @@ END
END
if ($cnum) {
if ($coursecodes{$cnum}) {
- foreach (@codetitles) {
- $r->print(''.$_.' : '.$codes{$cnum}{$_}.'; ');
+ foreach my $item (@codetitles) {
+ $r->print(''.$item.' : '.$codes{$cnum}{$item}.'; ');
}
$r->print(' ');
} else {
- $r->print('Enter institutional course code:
+ $r->print($lt{'enin'}.':
');
}
} else {
if ($totcodes > 0) {
my $numtitles = @codetitles;
if ($numtitles == 0) {
- $r->print('Enter institutional course code:
+ $r->print($lt{'enin'}.':
');
} else {
my $lasttitle = $numtitles;
@@ -426,17 +446,17 @@ END
}
$r->print(''.$codetitles[0].' '."\n".
''."\n".
- ' Select'."\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]};
}
if (defined($idlist_titles{$codetitles[0]})) {
if ($idlist_titles{$codetitles[0]} =~ /","/) {
- @longitems = split/","/,$idlist_titles{$codetitles[0]};
+ @longitems = split(/","/,$idlist_titles{$codetitles[0]});
} else {
$longitems[0] = $idlist_titles{$codetitles[0]};
}
@@ -455,7 +475,7 @@ END
for (my $i=1; $i<$numtitles; $i++) {
$r->print(''.$codetitles[$i].' '."\n".
''."\n".
- '<-Pick '.$codetitles[$i-1].' '."\n".
+ '<-'.$lt{'pick'}.' '.$codetitles[$i-1].' '."\n".
' '."\n".
' '
);
@@ -464,19 +484,19 @@ END
if ($numtitles > 4) {
$r->print(' '.$codetitles[$numtitles].' '."\n".
''."\n".
- '<-Pick '.$codetitles[$numtitles-1].' '."\n".
+ '<-'.$lt{'pick'}.' '.$codetitles[$numtitles-1].' '."\n".
' '."\n");
}
}
} else {
- $r->print('Enter institutional course code:
+ $r->print($lt{'enin'}.':
');
}
}
if ($ctitle) {
- $r->print('Title : '.$ctitle.' ');
+ $r->print(''.$lt{'titl'}.' : '.$ctitle.' ');
} else {
- $r->print(' Enter course title:
+ $r->print(' '.$lt{'enct'}.':
');
}
$r->print(<
- Section Number:
+ $lt{'secn'}:
@@ -506,12 +526,12 @@ END
END
if ($sectionlist) {
$r->print("".
- " Select \n");
- foreach (sort keys %groupid) {
- if ($_ eq $groupid{$_} || $groupid{$_} eq '') {
- $r->print(" $_ \n");
+ " $lt{'sele'} \n");
+ foreach my $id (sort(keys(%groupid))) {
+ if ($id eq $groupid{$id} || $groupid{$id} eq '') {
+ $r->print(" $id \n");
} else {
- $r->print(" $_ - (LON-CAPA sec: $groupid{$_}) \n");
+ $r->print(" $id - ($lt{'lsec'}: $groupid{$id}) \n");
}
}
$r->print(" ");
@@ -533,7 +553,7 @@ END
@@ -557,7 +577,7 @@ END
- Detailed description:
+ $lt{'detd'}:
@@ -584,7 +604,7 @@ END
- Optional file upload:
+ $lt{'opfi'}:
@@ -593,7 +613,7 @@ END
@@ -612,7 +632,7 @@ END
@@ -622,11 +642,11 @@ END
-
+
-
+
@@ -680,30 +700,48 @@ sub print_request_receipt {
$coursecode .= $env{'form.Number'};
}
}
+ my %lt = &Apache::lonlocal::texthash (
+ name => 'Name',
+ email => 'Email',
+ unme => 'Username/domain',
+ tel => 'Tel',
+ crsi => 'Course Information',
+ subj => 'Subject',
+ desc => 'Description',
+ 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',
+ );
+
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'} - $coursecode - section: $env{'form.section'}
-Subject: $env{'form.subject'}
-Description: $env{'form.description'}
+$lt{'name'}: $env{'form.username'}
+$lt{'email'}: $env{'form.email'}
+$lt{'unme'}: $env{'form.uname'} - $env{'form.udom'}
+$lt{'tel'}: $env{'form.phone'}
+$lt{'crsi'}: $env{'form.title'} - $coursecode - $lt{'secn'}: $env{'form.section'}
+$lt{'subj'}: $env{'form.subject'}
+$lt{'desc'}: $env{'form.description'}
URL: $env{'form.sourceurl'}
-Date/Time: $reporttime
+$lt{'date'}: $reporttime
|;
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'} - $coursecode - section: $env{'form.section'}
-Subject: $env{'form.subject'}
-Description: $descrip
+$lt{'name'}: $env{'form.username'}
+$lt{'email'}: $env{'form.email'}
+$lt{'unme'}: $env{'form.uname'} - $env{'form.udom'}
+$lt{'tel'}: $env{'form.phone'}
+$lt{'crsi'}: $env{'form.title'} - $coursecode - $lt{'sect'}: $env{'form.section'}
+$lt{'subj'}: $env{'form.subject'}
+$lt{'desc'}: $descrip
URL: $env{'form.sourceurl'}
-Date/Time: $reporttime
+$lt{'date'}: $reporttime
|;
my $start_page =
@@ -725,17 +763,15 @@ END
&print_header($r,$url,'process');
}
if ($to =~ m/^[^\@]+\@[^\@]+$/) {
- $r->print("A support request has been sent to $to ");
+ $r->print(''.$lt{'asup'}.' '.$to.' ');
} else {
$to = $admin;
if ($to =~ m/^[^\@]+\@[^\@]+$/) {
- $r->print("A support request has been sent to $to ");
-END
+ $r->print(''.$lt{'asup'}.' '.$to.' ');
} else {
- $r->print(<Warning: Problem with support e-mail address
-As the e-mail address provided for this LON-CAPA server ($to) 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. Instead a copy has been sent to the LON-CAPA support team at Michigan State University.
-END
+ $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';
}
}
@@ -760,31 +796,31 @@ END
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.";
+ $displaymsg .= ' '.&mt('The uploaded screenshot file ([_1] bytes) included with your request exceeded the maximum allowed size - 128 KB, and has therefore been discarded.',$attachmentsize);
} else {
$attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
}
}
}
- my %cookies = ();
+ my %cookies;
my $cookie=CGI::Cookie->parse($r->header_in('Cookie'));
- if ($$cookie{'lonID'} =~ /lonID=(\w+);/) {
+ if ($$cookie{'lonID'} =~ /lonID=($LONCAPA::handle_re);/) {
$cookies{'lonID'} = $1;
}
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 .= ' '.&mt('An uploaded screenshot file - [_1] ([_2] bytes) was included in the request sent by [_3] from LON-CAPA domain',$fname,$attachmentsize,$env{'user.name'}.': '.$env{'user.domain'});
$supportmsg .= "\n";
- foreach (@cookievars) {
- $supportmsg .= "$_: $cookies{$_}\n";
+ foreach my $var (@cookievars) {
+ $supportmsg .= "$var: $cookies{$var}\n";
}
- foreach (@ENVvars) {
- $supportmsg .= "$_: $ENV{$_}\n";
+ foreach my $var(@ENVvars) {
+ $supportmsg .= "$var: $ENV{$var}\n";
}
- foreach (@envvars) {
- $supportmsg .= "$_: $env{$_}\n";
+ foreach my $var (@envvars) {
+ $supportmsg .= "$var: $env{$var}\n";
}
}
@@ -805,17 +841,17 @@ END
} else {
my $envdata = '';
- foreach (@cookievars) {
- $envdata .= "$_: $cookies{$_}\n";
+ foreach my $var (@cookievars) {
+ $envdata .= "$var: $cookies{$var}\n";
}
- foreach (@ENVvars) {
- $envdata .= "$_: $ENV{$_}\n";
+ foreach my $var (@ENVvars) {
+ $envdata .= "$var: $ENV{$var}\n";
}
- foreach (@envvars) {
- $envdata .= "$_: $env{$_}\n";
+ foreach my $var (@envvars) {
+ $envdata .= "$var: $env{$var}\n";
}
- foreach (@loncvars) {
- $envdata .= "$_: $env{$_}\n";
+ foreach my $var (@loncvars) {
+ $envdata .= "$var: $env{$var}\n";
}
$msg->attach(Type => 'TEXT',
Data => $envdata);
@@ -828,7 +864,7 @@ END
unlink($attachmentpath);
}
$r->print(qq|
- Your support request contained the following information :
+ $lt{'your'} :
@@ -843,7 +879,7 @@ END
- Information supplied
+ $lt{'info'}
@@ -865,7 +901,7 @@ END
- Additional information recorded
+ $lt{'adin'}
@@ -875,19 +911,19 @@ END
|);
- foreach (@cookievars) {
- unless($cookies{$_} eq '') {
- $r->print("$_: $cookies{$_} , ");
+ foreach my $var (@cookievars) {
+ unless($cookies{$var} eq '') {
+ $r->print("$var: $cookies{$var} , ");
}
}
- foreach (@ENVvars) {
- unless($ENV{$_} eq '') {
- $r->print("$_: $ENV{$_} , ");
+ foreach my $var (@ENVvars) {
+ unless($ENV{$var} eq '') {
+ $r->print("$var: $ENV{$var} , ");
}
}
- foreach (@envvars) {
- unless($env{$_} eq '') {
- $r->print("$_: $env{$_} , ");
+ foreach my $var (@envvars) {
+ unless($env{$var} eq '') {
+ $r->print("$var: $env{$var} , ");
}
}
$r->print("
@@ -945,9 +981,9 @@ sub print_header {