Annotation of loncom/interface/lonsupportreq.pm, revision 1.107
1.86 raeburn 1: # The LearningOnline Network with CAPA
2: # Helpdesk request form
1.24 albertel 3: #
1.107 ! raeburn 4: # $Id: lonsupportreq.pm,v 1.106 2024/07/15 17:12:40 raeburn Exp $
1.24 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
1.1 raeburn 29: package Apache::lonsupportreq;
30:
31: use strict;
1.27 raeburn 32: use CGI::Cookie();
1.1 raeburn 33: use Apache::Constants qw(:common);
1.2 albertel 34: use Apache::loncommon();
1.43 raeburn 35: use Apache::lonhtmlcommon;
1.24 albertel 36: use Apache::lonnet;
1.1 raeburn 37: use Apache::lonlocal;
1.34 albertel 38: use Apache::lonacc();
1.68 raeburn 39: use Apache::lonauth();
1.38 raeburn 40: use Apache::courseclassifier;
1.60 raeburn 41: use LONCAPA qw(:DEFAULT :match);
1.70 raeburn 42: use HTML::Entities;
1.1 raeburn 43:
44: sub handler {
1.2 albertel 45: my ($r) = @_;
46: &Apache::loncommon::content_type($r,'text/html');
1.1 raeburn 47: $r->send_http_header;
48:
49: if ($r->header_only) {
50: return OK;
51: }
1.42 albertel 52: if ($r->uri eq '/adm/helpdesk') {
53: &Apache::lonlocal::get_language_handle($r);
54: }
55:
1.12 raeburn 56: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['origurl','function']);
57: if ($r->uri eq '/adm/helpdesk') {
1.34 albertel 58: &Apache::lonacc::get_posted_cgi($r);
1.12 raeburn 59: }
1.70 raeburn 60: my $function;
61: if ($env{'form.function'}) {
62: if (($env{'form.function'} eq 'norole') ||
63: ($env{'form.function'} eq 'student') ||
64: ($env{'form.function'} eq 'admin') ||
65: ($env{'form.function'} eq 'author')) {
66: $function = $env{'form.function'};
67: }
68: }
1.60 raeburn 69: my $origurl = $env{'form.origurl'};
1.94 raeburn 70: if ($origurl =~ m{^https?://[^/]+(.*)$}) {
1.103 raeburn 71: $origurl = $1;
1.94 raeburn 72: }
1.70 raeburn 73: $origurl =~ s/(`)//g;
74: $origurl =~ s/\$/\(\$\)/g;
1.44 raeburn 75: my $command = $env{'form.command'};
1.12 raeburn 76:
1.44 raeburn 77: if ($command eq 'process') {
1.1 raeburn 78: &print_request_receipt($r,$origurl,$function);
79: } else {
80: &print_request_form($r,$origurl,$function);
81: }
82: return OK;
83: }
1.89 raeburn 84:
1.1 raeburn 85: sub print_request_form {
86: my ($r,$origurl,$function) = @_;
1.83 raeburn 87: my ($os,$browser,$bversion,$uname,$udom,$uhome,$urole,$usec,$email,$cid,
1.61 raeburn 88: $cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server,
1.82 raeburn 89: $formname,$public,$homeserver,$knownuser,$captcha_form,$captcha_error,
1.86 raeburn 90: $captcha,$recaptcha_version,$extra_validations,%groupid);
1.44 raeburn 91: $function = &Apache::loncommon::get_users_function() if (!$function);
1.10 raeburn 92: $ccode = '';
1.25 albertel 93: $os = $env{'browser.os'};
94: $browser = $env{'browser.type'};
95: $bversion = $env{'browser.version'};
1.60 raeburn 96: if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
97: $public = 1;
98: } else {
1.67 raeburn 99: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
100: $homeserver = &Apache::lonnet::homeserver($env{'user.name'},
101: $env{'user.domain'});
102: if ($homeserver eq 'no_host') {
103: undef($homeserver);
104: } else {
105: $uname = $env{'user.name'};
106: $udom = $env{'user.domain'};
107: }
108: }
109: }
1.89 raeburn 110: if (($env{'user.name'} =~ /^$match_username$/) &&
1.82 raeburn 111: ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
112: $knownuser = 1;
113: } else {
114: my $lonhost = $r->dir_config('lonHostID');
115: ($captcha_form,$captcha_error,$captcha,$recaptcha_version) =
116: &Apache::loncommon::captcha_display('login',$lonhost);
117: }
1.86 raeburn 118: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['codedom',
119: 'useremail','useraccount']);
120:
1.67 raeburn 121: if ($homeserver) {
122: $uhome = $env{'user.home'};
123: $urole = $env{'request.role'};
124: $usec = $env{'request.course.sec'};
125: $cid = $env{'request.course.id'};
1.56 raeburn 126: }
1.86 raeburn 127: if ($cid) {
128: $cdom = $env{'course.'.$cid.'.domain'};
129: $cnum = $env{'course.'.$cid.'.num'};
130: }
131: if ($cdom && $cnum) {
132: my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
133: $ctitle = $csettings{'description'};
134: $ccode = $csettings{'internal.coursecode'};
135: $sectionlist = $csettings{'internal.sectionnums'};
136: my @sections = split(/,/,$sectionlist);
137: foreach my $section (@sections) {
138: my ($sec,$grp) = split(/:/,$section);
139: $groupid{$sec} = $grp;
140: }
141: }
142:
1.29 raeburn 143: $formname = 'logproblem';
1.86 raeburn 144: my $codedom = &get_domain();
145: my %helpform;
146: my %domconfig =
147: &Apache::lonnet::get_dom('configuration',['contacts'],$codedom);
148: if (ref($domconfig{'contacts'}) eq 'HASH') {
149: if (ref($domconfig{'contacts'}{'helpform'}) eq 'HASH') {
150: %helpform = %{$domconfig{'contacts'}{'helpform'}};
151: }
152: }
153:
154: my %codes;
155: my @codetitles;
156: my %cat_titles;
157: my %cat_order;
158: my %idlist;
159: my %idnums;
160: my %idlist_titles;
161: my $totcodes = 0;
162: my $jscript = '';
163: my $loaditems = qq|
164: function initialize_codes() {
165: return;
166: }
167: |;
168: unless ($helpform{'course'} eq 'no') {
1.96 raeburn 169: my $instcats = &Apache::lonnet::get_dom_instcats($codedom);
170: if (ref($instcats) eq 'HASH') {
171: if ((ref($instcats->{'codetitles'}) eq 'ARRAY') && (ref($instcats->{'codes'}) eq 'HASH') &&
172: (ref($instcats->{'cat_titles'}) eq 'HASH') && (ref($instcats->{'cat_order'}) eq 'HASH')) {
173: %codes = %{$instcats->{'codes'}};
174: @codetitles = @{$instcats->{'codetitles'}};
175: %cat_titles = %{$instcats->{'cat_titles'}};
176: %cat_order = %{$instcats->{'cat_order'}};
177: $totcodes = scalar(keys(%codes));
178: }
179: if ($totcodes > 0) {
1.86 raeburn 180: my $numtypes = @codetitles;
181: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
182: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
183: my $longtitles_str = join('","',@{$longtitles});
184: my $allidlist = $idlist{$codetitles[0]};
185: my $knowncodes;
186: if (($ccode ne '') && ($cnum ne '')) {
187: my (%singlecodes,@singlecodetitles,%singlecat_titles,%singlecat_order);
188: my $crscode_reply = &Apache::lonnet::auto_instcode_format($cnum,$codedom,{ $cnum => $ccode },\%singlecodes,
189: \@singlecodetitles,\%singlecat_titles,\%singlecat_order);
190: if (ref($singlecodes{$cnum}) eq 'HASH') {
191: $knowncodes = $singlecodes{$cnum};
192: }
193: }
194: $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
195: $jscript .= $scripttext;
196: $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,\@codetitles,$knowncodes,$sectionlist);
197: $loaditems = '';
198: }
199: }
200: }
201: my %missing = &Apache::lonlocal::texthash(
202: username => 'You must include a name.',
203: phone => 'You must include a phone.',
204: );
205: &js_escape(\%missing);
206: if (keys(%helpform)) {
207: foreach my $key (keys(%helpform)) {
208: if (($helpform{$key} eq 'req') && ($missing{$key} ne '')) {
209: next if (($key eq 'username') && (($knownuser) ||
210: (($env{'user.name'} =~ /^$match_username$/) && (!$public))));
211: $extra_validations .= <<"END";
212:
213: if (document.$formname.$key.value == '') {
214: alert("$missing{$key}");
215: return;
216: }
217:
218: END
219: }
220: }
221: }
1.40 raeburn 222: my $machine = &Apache::lonnet::absolute_url();
1.70 raeburn 223: my $sourceurl = $machine.$origurl;
1.74 raeburn 224: $server = $machine.&Apache::loncommon::cleanup_html($origurl);
1.70 raeburn 225: $server =~ s/\?.*$//;
1.79 damieng 226: my %js_lt = &Apache::lonlocal::texthash (
1.40 raeburn 227: email => 'The e-mail address you entered',
228: notv => 'is not a valid e-mail address',
229: rsub => 'You must include a subject',
230: rdes => 'You must include a description',
1.79 damieng 231: );
232: my %html_lt = &Apache::lonlocal::texthash (
1.40 raeburn 233: name => 'Name',
234: subm => 'Submit Request',
1.46 raeburn 235: emad => 'Your e-mail address',
1.86 raeburn 236: emac => 'Cc',
1.40 raeburn 237: unme => 'username',
238: doma => 'domain',
1.44 raeburn 239: entu => 'Enter the username you use to log-in to LON-CAPA',
240: chdo => 'Choose your LON-CAPA domain',
241: entr => 'Enter the username you use to log-in to LON-CAPA, and your domain.',
1.40 raeburn 242: urlp => 'URL of page',
243: phon => 'Phone',
244: crsd => 'Course Details',
245: enin => 'Enter institutional course code',
246: pick => 'Pick',
247: enct => 'Enter course title',
248: secn => 'Section Number',
249: sele => 'Select',
250: titl => 'Title',
251: lsec => 'LON-CAPA sec',
252: subj => 'Subject',
253: detd => 'Detailed Description',
254: opfi => 'Optional file upload',
1.87 raeburn 255: uplf => 'Upload a file (e.g., a screenshot) relevant to your help request',
1.40 raeburn 256: fini => 'Finish',
257: clfm => 'Clear Form',
258: );
1.79 damieng 259: &js_escape(\%js_lt);
260: &html_escape(\%html_lt);
1.40 raeburn 261: my $scripttag = (<<"END");
1.5 raeburn 262: function validate() {
1.13 raeburn 263: if (validmail(document.logproblem.email) == false) {
1.79 damieng 264: alert("$js_lt{'email'}: "+document.logproblem.email.value+" $js_lt{'notv'}.");
1.40 raeburn 265: return;
266: }
267: if (document.logproblem.subject.value == '') {
1.79 damieng 268: alert("$js_lt{'rsub'}.");
1.40 raeburn 269: return;
270: }
271: if (document.logproblem.description.value == '') {
1.79 damieng 272: alert("$js_lt{'rdes'}.");
1.13 raeburn 273: return;
1.5 raeburn 274: }
1.86 raeburn 275: $extra_validations
1.5 raeburn 276: document.logproblem.submit();
277: }
1.13 raeburn 278:
1.40 raeburn 279: END
1.43 raeburn 280: $scripttag .= &Apache::lonhtmlcommon::javascript_valid_email();
1.44 raeburn 281:
1.67 raeburn 282: if ($homeserver) {
283: if ($env{'environment.permanentemail'}) {
284: $email = $env{'environment.permanentemail'};
285: } elsif ($env{'environment.critnotification'}) {
286: $email = $env{'environment.critnotification'};
287: } elsif ($env{'environment.notification'}) {
288: $email = $env{'environment.notification'};
289: }
290: if ($env{'environment.lastname'}) {
291: $lastname = $env{'environment.lastname'};
292: }
293: if ($env{'environment.firstname'}) {
294: $firstname = $env{'environment.firstname'};
295: }
1.1 raeburn 296: }
1.60 raeburn 297: if ($env{'form.origurl'} eq '/adm/createaccount') {
298: if ($email eq '') {
299: if ($env{'form.useremail'} =~ /^[^\@]+\@[^\@]+$/) {
300: $email = &HTML::Entities::encode($env{'form.useremail'},'"<>&');
301: }
302: }
303: if ($uname eq '') {
304: if ($env{'form.useraccount'} =~ /^$match_username$/) {
305: $uname = &HTML::Entities::encode($env{'form.useraccount'},'"<>&');
306: }
307: }
308: }
1.21 raeburn 309: my $details_title;
310: if ($codedom) {
311: $details_title = '<br />('.$codedom.')';
312: }
1.86 raeburn 313:
1.67 raeburn 314: my $js = <<"ENDJS";
315: <script type="text/javascript">
316: // <![CDATA[
317: $scripttag
318: $jscript
319: $loaditems
320: // ]]>
321: </script>
322: ENDJS
1.99 raeburn 323: if ($knownuser) {
324: $js .="\n".'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>';
325: } elsif ($recaptcha_version >=2) {
1.82 raeburn 326: $js.= "\n".'<script src="https://www.google.com/recaptcha/api.js"></script>'."\n";
327: }
1.67 raeburn 328: my %add_entries = (
329: style => "margin-top:0px;margin-bottom:0px;",
330: onload => "initialize_codes();",
331: );
1.33 albertel 332:
1.107 ! raeburn 333: my $args = { 'function' => $function,
! 334: 'add_entries' => \%add_entries,
! 335: 'only_body' => 1,};
! 336: unless (($knownuser) || ($public)) {
! 337: (undef,undef,undef,my $clientmathml,my $clientunicode) =
! 338: &Apache::loncommon::decode_user_agent();
! 339: if ($clientunicode && !$clientmathml) {
! 340: $args->{'browser.unicode'} = 1;
! 341: }
! 342: }
! 343: $r->print(&Apache::loncommon::start_page('Support Request',$js,$args));
1.15 raeburn 344: if ($r->uri eq '/adm/helpdesk') {
1.14 raeburn 345: &print_header($r,$origurl);
346: }
1.50 raeburn 347: my @css = ('LC_evenrow_value','LC_oddrow_value');
348: my $num = 1;
349: my $i = $num%2;
1.67 raeburn 350: my $formtype;
351: if ($homeserver) {
352: $formtype = ' enctype="multipart/form-data"';
353: }
1.86 raeburn 354: my $topsubmit = ' <input type="button" value="'.$html_lt{'subm'}.'" onclick="validate()" /> ';
355: my $shownsubmit;
1.107 ! raeburn 356: $r->print('<div class="LC_landmark" role="main">'."\n".
! 357: '<form method="post" action="" name="logproblem"'.$formtype.'>'."\n");
1.44 raeburn 358: my $output = &Apache::lonhtmlcommon::start_pick_box().
1.78 bisitz 359: &Apache::lonhtmlcommon::row_headline().
360: '<span class="LC_info">'.
1.107 ! raeburn 361: &mt('(All fields marked with [_1]*[_2] are required.)',
! 362: '<span class="LC_parm_part">','</span>').
1.78 bisitz 363: '</span>'.
1.86 raeburn 364: &Apache::lonhtmlcommon::row_closure();
365: unless ($helpform{'username'} eq 'no') {
366: my ($reqd,$namefield,$fullname);
367: if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) {
1.89 raeburn 368: $fullname = "$firstname $lastname";
1.107 ! raeburn 369: $namefield = $fullname.'<input type="hidden" name="username" id="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
1.86 raeburn 370: } else {
371: if (defined($firstname) && $firstname ne '') {
372: $fullname = $firstname;
373: } elsif (defined($lastname) && $lastname ne '') {
374: $fullname = " $lastname";
375: }
1.107 ! raeburn 376: $namefield = '<input type="text" size="20" name="username" id="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
1.86 raeburn 377: if ($helpform{'username'} eq 'req') {
1.107 ! raeburn 378: $reqd = '<span class="LC_parm_part">*</span>';
1.86 raeburn 379: }
1.1 raeburn 380: }
1.107 ! raeburn 381: my $title = '<label for="username">'.$html_lt{'name'}.'</label>';
! 382: $output .= &Apache::lonhtmlcommon::row_title($title.$reqd,undef,$css[$num])."\n".$namefield.
1.86 raeburn 383: $topsubmit.
384: &Apache::lonhtmlcommon::row_closure()."\n";
385: $shownsubmit = 1;
386: $num ++;
387: $i = $num%2;
1.1 raeburn 388: }
1.78 bisitz 389: $output .= &Apache::lonhtmlcommon::row_title(
390: '<span title="'.&mt('required').'">'.
1.107 ! raeburn 391: '<label for="email">'.$html_lt{'emad'}.
! 392: '</label><span class="LC_parm_part">*</span></span>'
1.78 bisitz 393: ,undef,$css[$i]).
1.107 ! raeburn 394: '<input type="text" size="20" name="email" id="email" value="'.
1.86 raeburn 395: &HTML::Entities::encode($email,'"<>&').'" />'."\n";
396: unless ($shownsubmit) {
397: $output .= $topsubmit;
1.89 raeburn 398: }
1.86 raeburn 399: $output .= &Apache::lonhtmlcommon::row_closure();
1.50 raeburn 400: $num ++;
401: $i = $num%2;
1.82 raeburn 402: if ($knownuser) {
403: if ($homeserver) {
1.104 raeburn 404: my $ip = &Apache::lonnet::get_requestor_ip($r);
405: my %setters;
406: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
407: &Apache::loncommon::blockcheck(\%setters,'com',$ip);
408: unless (($helpform{'cc'} eq 'no') || ($by_ip)) {
1.107 ! raeburn 409: $output .= &Apache::lonhtmlcommon::row_title('<label for="cc">'.$html_lt{'emac'}.'</label>',
! 410: undef,$css[$i]).
! 411: '<input type="text" size="50" name="cc" id="cc" value="" /><br />'."\n".
1.86 raeburn 412: &Apache::lonhtmlcommon::row_closure();
413: $num ++;
414: $i = $num%2;
415: }
1.67 raeburn 416: }
1.50 raeburn 417: }
1.95 raeburn 418: unless (($helpform{'user'} eq 'no') || ($env{'request.lti.login'})) {
1.86 raeburn 419: $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'unme'}/$html_lt{'doma'}",undef,$css[$i]);
420: my $udom_input = '<input type="hidden" name="udom" value="'.
421: &HTML::Entities::encode($udom,'"<>&').'" />'."\n";
422: my $uname_input = '<input type="hidden" name="uname" value="'.
423: &HTML::Entities::encode($uname,'"<>&').'" />'."\n";
424: if ($knownuser) {
1.107 ! raeburn 425: $output .= '<span class="LC_nobreak"><span class="LC_cusr_emph">'.$html_lt{'unme'}
! 426: .'</span>: '.$uname.' <span class="LC_cusr_emph">'
! 427: .$html_lt{'doma'}.'</span>: '.$udom.$udom_input.$uname_input.'</span>';
1.44 raeburn 428: } else {
1.86 raeburn 429: my $udomform = '';
430: my $unameform = '';
431: if (($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
432: $output .= $html_lt{'entu'};
433: } elsif (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
434: $output .= $html_lt{'chdo'};
435: } else {
436: $output .= $html_lt{'entr'};
437: }
438: $output .= '<br />'."\n";
439: if (!$public) {
440: if ($env{'user.domain'} =~ /^$match_domain$/) {
1.107 ! raeburn 441: $udomform = '<span class="LC_cusr_emph">'.$html_lt{'doma'}.'</span>: '.$udom.$udom_input;
1.86 raeburn 442: } elsif ($env{'user.name'} =~ /^$match_username$/) {
1.107 ! raeburn 443: $unameform = '<span class="LC_cusr_emph">'.$html_lt{'unme'}.'</span>: '.$uname.' '.$uname_input;
1.86 raeburn 444: }
445: }
446: if ($udomform eq '') {
1.107 ! raeburn 447: $udomform = '<span class="LC_nobreak"><span class="LC_cusr_emph"><label for="udom">'
! 448: .$html_lt{'doma'}.'</label></span>: '
! 449: .&Apache::loncommon::select_dom_form($codedom,'udom','','','','','','','udom')."</span>\n";
1.86 raeburn 450: }
451: if ($unameform eq '') {
1.107 ! raeburn 452: $unameform= '<span class="LC_nobreak"><span class="LC_cusr_emph"><label for="uname">'
! 453: .$html_lt{'unme'}.'</label></span>: '
! 454: .'<input type="text" size="20" name="uname" id="uname" value="'.$uname.'" />'
! 455: .' </span>';
1.60 raeburn 456: }
1.86 raeburn 457: $output .= $unameform.$udomform;
1.1 raeburn 458: }
1.86 raeburn 459: $output .= &Apache::lonhtmlcommon::row_closure();
460: $num ++;
1.95 raeburn 461: $i = $num%2;
462: }
463: unless ($env{'request.lti.login'}) {
464: $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'urlp'}",undef,$css[$i]).
465: $server."\n".'<input type="hidden" name="sourceurl" value="'.
466: &HTML::Entities::encode($sourceurl,'"<>&').'" />'."\n".
467: &Apache::lonhtmlcommon::row_closure();
1.1 raeburn 468: }
1.86 raeburn 469: unless ($helpform{'phone'} eq 'no') {
470: my $reqd;
471: if ($helpform{'phone'} eq 'req') {
1.107 ! raeburn 472: $reqd = '<span class="LC_parm_part">*</span>';
1.86 raeburn 473: }
1.107 ! raeburn 474: $output .= &Apache::lonhtmlcommon::row_title('<label for="phone">'.$html_lt{'phon'}.'</label>'.$reqd,undef,'LC_evenrow_value').
! 475: '<input type="text" size="15" name="phone" id="phone" /><br />'."\n".
1.86 raeburn 476: &Apache::lonhtmlcommon::row_closure();
477: $num ++;
478: $i = $num%2;
479: }
1.95 raeburn 480: unless (($helpform{'course'} eq 'no') || ($env{'request.lti.login'})) {
1.86 raeburn 481: $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'crsd'}$details_title",undef,$css[$i]);
1.10 raeburn 482: if ($totcodes > 0) {
483: my $numtitles = @codetitles;
484: if ($numtitles == 0) {
1.107 ! raeburn 485: $output .= '<label>'.$html_lt{'enin'}.':
! 486: <input type="text" name="coursecode" size="15" value="'.&HTML::Entities::encode($ccode,'\'"&<>').'" /></label>'."\n";
1.10 raeburn 487: } else {
1.57 raeburn 488: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1.10 raeburn 489: my $lasttitle = $numtitles;
490: if ($numtitles > 4) {
491: $lasttitle = 4;
1.86 raeburn 492: }
493: my $onchange;
494: if ($sectionlist) {
495: $onchange = 'toggleSecVis()';
496: }
1.107 ! raeburn 497: $output .= '<table><tr>';
! 498: for (my $i=0; $i<$lasttitle; $i++) {
! 499: $output .= '<th><label for="'.$standardnames[$i].'_'.$i.'">'.$codetitles[0].'</label></th>';
! 500: }
! 501: $output .= '</tr>';
! 502: $output .= '<tr><td>'.
! 503: '<select name="'.$standardnames[0].'" id="'.$standardnames[0].'_0" onchange="courseSet('."'$codetitles[0]'".');'.$onchange.'">'."\n".
1.79 damieng 504: ' <option value="-1">'.$html_lt{'sele'}."</option>\n";
1.10 raeburn 505: my @items = ();
1.20 raeburn 506: my @longitems = ();
1.10 raeburn 507: if ($idlist{$codetitles[0]} =~ /","/) {
1.40 raeburn 508: @items = split(/","/,$idlist{$codetitles[0]});
1.10 raeburn 509: } else {
510: $items[0] = $idlist{$codetitles[0]};
511: }
1.20 raeburn 512: if (defined($idlist_titles{$codetitles[0]})) {
513: if ($idlist_titles{$codetitles[0]} =~ /","/) {
1.40 raeburn 514: @longitems = split(/","/,$idlist_titles{$codetitles[0]});
1.20 raeburn 515: } else {
516: $longitems[0] = $idlist_titles{$codetitles[0]};
517: }
1.22 raeburn 518: for (my $i=0; $i<@longitems; $i++) {
519: if ($longitems[$i] eq '') {
520: $longitems[$i] = $items[$i];
521: }
522: }
1.20 raeburn 523: } else {
524: @longitems = @items;
525: }
526: for (my $i=0; $i<@items; $i++) {
1.44 raeburn 527: $output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>'."\n";
1.10 raeburn 528: }
1.44 raeburn 529: $output .= '</select></td>';
1.107 ! raeburn 530: for (my $i=1; $i<$lasttitle; $i++) {
! 531: $output .= '<td>'."\n".
! 532: '<select name="'.$standardnames[$i].'" id="'.$standardnames[$i].'_'.$i.'" onchange="courseSet('."'$codetitles[$i]'".');'.$onchange.'">'."\n".
1.79 damieng 533: '<option value="-1"><-'.$html_lt{'pick'}.' '.$codetitles[$i-1].'</option>'."\n".
1.10 raeburn 534: '</select>'."\n".
1.44 raeburn 535: '</td>'."\n";
1.10 raeburn 536: }
1.44 raeburn 537: $output .= '</tr></table>';
1.10 raeburn 538: if ($numtitles > 4) {
1.107 ! raeburn 539: $output .= '<br /><br /><label>'.$codetitles[$numtitles].'<br />'."\n".
1.86 raeburn 540: '<select name="'.$standardnames[$numtitles].'" onchange="courseSet('."'$codetitles[$numtitles]'".');'.$onchange.'">'."\n".
1.79 damieng 541: '<option value="-1"><-'.$html_lt{'pick'}.' '.$codetitles[$numtitles-1].'</option>'."\n".
1.107 ! raeburn 542: '</select></label>'."\n";
1.10 raeburn 543: }
544: }
545: } else {
1.107 ! raeburn 546: $output .= '<label>'.$html_lt{'enin'}.':
! 547: <input type="text" name="coursecode" size="15" value="" /></label>'."\n";
1.10 raeburn 548: }
1.86 raeburn 549: my $reqd;
550: if ($helpform{'course'} eq 'req') {
1.107 ! raeburn 551: $reqd = '<span class="LC_parm_part">*</span>';
1.86 raeburn 552: }
1.107 ! raeburn 553: $output .= '<br /><div><label>'.$html_lt{'enct'}.$reqd.':
1.86 raeburn 554: <input type="text" name="title" size="25" value="'.
1.107 ! raeburn 555: &HTML::Entities::encode($ctitle,'"<>&').'" /></label></div>'."\n";
1.86 raeburn 556: $output .= &Apache::lonhtmlcommon::row_closure();
557: $num ++;
558: $i = $num%2;
559: }
1.95 raeburn 560: unless (($helpform{'section'} eq 'no') || ($env{'request.lti.login'})) {
1.107 ! raeburn 561: $output .= &Apache::lonhtmlcommon::row_title('<label for="section">'.$html_lt{'secn'}.'</label>',
! 562: undef,$css[$i]);
1.86 raeburn 563: if ($sectionlist) {
1.107 ! raeburn 564: $output .= "<div id=\"LC_helpdesk_sectionlist\">\n".
! 565: "<select name=\"sectionsel\" id=\"section\">\n".
1.86 raeburn 566: " <option value=\"\" selected=\"selected\">$html_lt{'sele'}</option>\n";
567: foreach my $id (sort(keys(%groupid))) {
568: if ($id eq $groupid{$id} || $groupid{$id} eq '') {
569: $output .= " <option value=".
570: &HTML::Entities::encode($id,'"<>&').
571: " >$id</option>\n";
572: } else {
573: $output .= " <option value=".
574: &HTML::Entities::encode($id,'"<>&').
575: " >$id - ($html_lt{'lsec'}: $groupid{$id})</option>\n";
576: }
1.1 raeburn 577: }
1.86 raeburn 578: $output .= '</select></div>'."\n".
579: '<div id="LC_helpdesk_section" style="display:none">'.
1.107 ! raeburn 580: '<input type="text" name="sectiontxt" id="notinuse" size="10" /></div>'."\n";
1.89 raeburn 581: } else {
1.107 ! raeburn 582: $output .= '<input type="text" name="section" id="section" size="10" />'."\n";
1.86 raeburn 583: }
584: $output .= &Apache::lonhtmlcommon::row_closure();
585: $num ++;
586: $i = $num%2;
1.1 raeburn 587: }
1.78 bisitz 588: $output .= &Apache::lonhtmlcommon::row_title(
589: '<span title="'.&mt('required').'">'.
1.107 ! raeburn 590: '<label for="subject">'.$html_lt{'subj'}.'</label>'.
! 591: '<span class="LC_parm_part">*</span></span>'
1.78 bisitz 592: ,undef,'LC_oddrow_value').
1.107 ! raeburn 593: '<input type="text" size="40" name="subject" id="subject" />'."\n".
1.44 raeburn 594: &Apache::lonhtmlcommon::row_closure().
1.78 bisitz 595: &Apache::lonhtmlcommon::row_title(
596: '<span title="'.&mt('required').'">'.
1.107 ! raeburn 597: '<label for="description">'.$html_lt{'detd'}.'</label>'.
! 598: '<span class="LC_parm_part">*</span></span>'
1.78 bisitz 599: ,undef,'LC_evenrow_value').
1.107 ! raeburn 600: '<textarea rows="10" cols="45" name="description" id="description" style="word-wrap:normal;">'.
1.67 raeburn 601: '</textarea>'."\n".
1.44 raeburn 602: &Apache::lonhtmlcommon::row_closure();
1.50 raeburn 603: $num ++;
604: $i = $num%2;
1.82 raeburn 605: if ($knownuser) {
1.67 raeburn 606: if ($homeserver) {
1.86 raeburn 607: unless ($helpform{'screenshot'} eq 'no') {
608: my $max = 1048576;
1.87 raeburn 609: my $showmax = 1.00;
1.86 raeburn 610: if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) {
1.89 raeburn 611: $max *= $helpform{'maxsize'};
1.87 raeburn 612: $showmax = $helpform{'maxsize'};
1.86 raeburn 613: }
1.87 raeburn 614: $showmax = ' ('.sprintf("%.2f",$showmax).' '.&mt('MB max.').')';
1.86 raeburn 615: $output .= &Apache::lonhtmlcommon::row_title($html_lt{'opfi'},undef,$css[$i])
1.107 ! raeburn 616: .'<input type="file" name="screenshot" id="screenshot" class="LC_flUpload" size="20" />'
1.98 raeburn 617: .'<input type="hidden" id="LC_free_space" value="'.$max.'" />'
1.107 ! raeburn 618: .'<br />'."\n".'<label for="screenshot">'.$html_lt{'uplf'}.'</label>'.$showmax."\n"
1.86 raeburn 619: .&Apache::lonhtmlcommon::row_closure();
620: $num ++;
621: $i = $num%2;
622: }
1.67 raeburn 623: }
1.69 raeburn 624: } else {
1.82 raeburn 625: if ($captcha_form) {
1.78 bisitz 626: $output .= &Apache::lonhtmlcommon::row_title(
627: '<span title="'.&mt('required').'">'.
628: &mt('Validation').
1.107 ! raeburn 629: '<span class="LC_parm_part">*</span></span>'
1.78 bisitz 630: ,undef,$css[$i]).
1.82 raeburn 631: $captcha_form."\n".
1.69 raeburn 632: &Apache::lonhtmlcommon::row_closure();
633: $num ++;
634: $i = $num%2;
635: }
1.5 raeburn 636: }
1.79 damieng 637: $output .= &Apache::lonhtmlcommon::row_title($html_lt{'fini'},undef,$css[$i]);
1.44 raeburn 638: $output .= <<END;
1.107 ! raeburn 639: <div>
! 640: <div class="LC_floatleft" style="padding-top:0, padding-left:8px; padding-right:8px; padding-bottom:0; margin:0">
1.44 raeburn 641: <input type="hidden" name="command" value="process" />
1.79 damieng 642: <input type="button" value="$html_lt{'subm'}" onclick="validate()" />
1.107 ! raeburn 643: </div>
! 644: <div class="LC_floatleft" style="padding-top:0, padding-left:8px; padding-right:8px; padding-bottom:0; margin:0">
1.79 damieng 645: <input type="reset" value="$html_lt{'clfm'}" />
1.107 ! raeburn 646: </div>
! 647: </div>
! 648: <div style="padding:0;clear:both;margin:0;border:0"></div>
1.44 raeburn 649: END
650: $output .= &Apache::lonhtmlcommon::row_closure(1);
651: $output .= &Apache::lonhtmlcommon::end_pick_box();
652: $r->print(<<END);
653: $output
1.14 raeburn 654: </form>
1.44 raeburn 655: <br />
1.107 ! raeburn 656: </div>
1.1 raeburn 657: END
1.30 albertel 658: $r->print(&Apache::loncommon::end_page());
1.5 raeburn 659: return;
1.1 raeburn 660: }
661:
662: sub print_request_receipt {
663: my ($r,$url,$function) = @_;
1.69 raeburn 664: my $public;
1.107 ! raeburn 665: my $args;
1.69 raeburn 666: if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
667: $public = 1;
668: }
1.89 raeburn 669: my $lonhost = $r->dir_config('lonHostID');
1.69 raeburn 670: unless (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
671: my ($captcha_chk,$captcha_error) =
672: &Apache::loncommon::captcha_response('login',$lonhost);
673: if ($captcha_chk != 1) {
1.107 ! raeburn 674: $args = {
! 675: 'function' => $function,
! 676: 'add_entries' => {
! 677: topmargin => "0",
! 678: marginheight => "0",
! 679: },
! 680: 'only_body' => 1,};
! 681: (undef,undef,undef,my $clientmathml,my $clientunicode) =
! 682: &Apache::loncommon::decode_user_agent();
! 683: if ($clientunicode && !$clientmathml) {
! 684: $args->{'browser.unicode' => 1};
! 685: }
! 686: $r->print(&Apache::loncommon::start_page('Support request failed',undef,$args));
1.69 raeburn 687: if ($r->uri eq '/adm/helpdesk') {
688: &print_header($r,$url,'process');
689: }
1.75 bisitz 690: $r->print(
1.107 ! raeburn 691: '<div class="LC_landmark" role="main">'.
! 692: '<h2 class="LC_heading_2">'.&mt('Support request failed').'</h2>'.
1.75 bisitz 693: &Apache::lonhtmlcommon::confirm_success(
694: &mt('Validation of the code you entered failed.'),1).
695: '<br /><br />'.
696: &Apache::lonhtmlcommon::actionbox([
697: &mt('[_1]Go back[_2] and try again',
698: '<a href="javascript:history.go(-1)">','</a>')]).
1.107 ! raeburn 699: '</div>'.
! 700: &Apache::loncommon::end_page());
1.69 raeburn 701: return;
702: }
703: }
1.104 raeburn 704: my $ip = &Apache::lonnet::get_requestor_ip($r);
705: my %setters;
706: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
707: &Apache::loncommon::blockcheck(\%setters,'com',$ip);
1.101 raeburn 708: my @ENVvars = ('HTTP_HOST','HTTP_USER_AGENT','SERVER_ADDR','SERVER_NAME');
1.26 raeburn 709: my @envvars = ('browser.os','browser.type','browser.version','user.home','request.role');
1.5 raeburn 710: my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');
1.91 raeburn 711: my @cookievars;
712: if ($ENV{'SERVER_PORT'} == 443) {
713: @cookievars = ('lonLinkID');
714: } else {
715: @cookievars = ('lonID');
716: }
1.5 raeburn 717:
718: my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
1.45 raeburn 719: my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
720: my $defdom = &get_domain();
1.5 raeburn 721: my $from = $admin;
1.86 raeburn 722: my %helpform;
1.56 raeburn 723: my %domconfig =
724: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
725: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.86 raeburn 726: if (ref($domconfig{'contacts'}{'helpform'}) eq 'HASH') {
727: %helpform = %{$domconfig{'contacts'}{'helpform'}};
1.56 raeburn 728: }
729: }
1.1 raeburn 730: my $reporttime = &Apache::lonlocal::locallocaltime(time);
1.86 raeburn 731: my %formvars = (
732: email => 1,
733: sourceurl => 1,
734: subject => 1,
735: description => 1,
736: );
737: unless ($helpform{'username'} eq 'no') {
738: $formvars{'username'} = 1;
739: }
740: unless ($helpform{'user'} eq 'no') {
741: $formvars{'uname'} = 1;
742: $formvars{'udom'} = 1;
743: }
744: unless ($helpform{'phone'} eq 'no') {
745: $formvars{'phone'} = 1;
746: }
1.95 raeburn 747: unless (($helpform{'section'} eq 'no') || ($env{'request.lti.login'})) {
1.86 raeburn 748: $formvars{'section'} = 1;
749: }
1.95 raeburn 750: unless (($helpform{'course'} eq 'no') || ($env{'request.lti.login'})) {
1.86 raeburn 751: $formvars{'course'} = 1;
752: }
1.104 raeburn 753: unless (($helpform{'cc'} eq 'no') || ($by_ip)) {
1.86 raeburn 754: $formvars{'cc'} = 1;
755: }
756: unless ($helpform{'screenshot'} eq 'no') {
757: $formvars{'screenshot'} = 1;
758: }
1.95 raeburn 759: my ($coursecode,$sourceurl);
1.86 raeburn 760: if ($formvars{'course'}) {
761: $coursecode = $env{'form.coursecode'};
1.57 raeburn 762: if ($coursecode eq '') {
1.86 raeburn 763: my $totcodes = 0;
1.96 raeburn 764: my $instcats = &Apache::lonnet::get_dom_instcats($defdom);
765: if (ref($instcats) eq 'HASH') {
766: if (ref($instcats->{'codes'}) eq 'HASH') {
767: $totcodes = scalar(keys(%{$instcats->{'codes'}}));
768: }
769: }
1.86 raeburn 770: my @standardnames = &Apache::loncommon::get_standard_codeitems();
771: if ($totcodes > 0) {
772: my $noregexps = 1;
773: $coursecode =
774: &Apache::courseclassifier::instcode_from_selectors($defdom,$noregexps);
775: }
776: if ($coursecode eq '') {
777: foreach my $item (@standardnames) {
778: if ((defined($env{'form.'.$item})) && ($env{'form.'.$item} ne '-1')) {
779: $coursecode .= $env{'form.'.$item};
780: }
1.57 raeburn 781: }
782: }
1.19 raeburn 783: }
784: }
1.40 raeburn 785: my %lt = &Apache::lonlocal::texthash (
1.44 raeburn 786: username => 'Name',
1.52 schafran 787: email => 'E-mail',
1.46 raeburn 788: cc => 'Cc',
1.44 raeburn 789: user => 'Username/domain',
790: phone => 'Phone',
791: crsi => 'Course Information',
792: subject => 'Subject',
793: description => 'Description',
794: sourceurl => 'URL',
795: date => 'Date/Time',
796: secn => 'Section',
797: warn => 'Warning: Problem with support e-mail address',
798: your => 'Your support request contained the following information',
1.106 raeburn 799: belo => 'Below is your support request which could not be sent',
800: ifyk => 'If you know an IT support address for your institution, you could copy this information and send it to that email address.',
1.44 raeburn 801: sect => 'section',
802: info => 'Information supplied',
803: adin => 'Additional information recorded',
1.40 raeburn 804: );
1.46 raeburn 805:
1.72 raeburn 806: my (@ok_ccs,@bad_ccs,$badccmsg,$okcclist,$homeserver);
807: unless ($public) {
1.67 raeburn 808: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
809: $homeserver = &Apache::lonnet::homeserver($env{'user.name'},
810: $env{'user.domain'});
811: }
812: }
1.86 raeburn 813: my ($cid,$cdom,$cnum,$sectionlist,$ccode);
814: if ($homeserver) {
815: $cid = $env{'request.course.id'};
816: }
817: if ($cid) {
818: $cdom = $env{'course.'.$cid.'.domain'};
819: $cnum = $env{'course.'.$cid.'.num'};
820: }
821: if ($cdom && $cnum) {
822: my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
823: $ccode = $csettings{'internal.coursecode'};
824: $sectionlist = $csettings{'internal.sectionnums'};
825: }
826: if (($homeserver) && (defined($env{'form.cc'})) && ($formvars{'cc'})) {
1.46 raeburn 827: my @ccs;
828: if ($env{'form.cc'} =~ /,/) {
829: @ccs = split(/,/,$env{'form.cc'});
830: } else {
831: $env{'form.cc'} =~ s/^\s+//;
832: $env{'form.cc'} =~ s/\s+$//;
833: @ccs = $env{'form.cc'};
834: }
835: foreach my $cc (@ccs) {
836: $cc =~ s/^\s+//g;
837: $cc =~ s/\s+$//g;
838: if ($cc =~ m/^[^\@]+\@[^\@]+$/) {
839: if (!(grep(/^\Q$cc\E$/,@ok_ccs))) {
840: push(@ok_ccs,$cc);
841: }
1.57 raeburn 842: } elsif ($cc ne '') {
1.46 raeburn 843: if (!(grep(/^\Q$cc\E$/,@bad_ccs))) {
844: push(@bad_ccs,$cc);
845: }
846: }
847: }
848: if (@ok_ccs > 0) {
849: $okcclist = join(', ',@ok_ccs);
850: }
851: if (@bad_ccs == 1) {
1.71 raeburn 852: if ($bad_ccs[0] ne '') {
1.74 raeburn 853: $badccmsg .= '<br />'.&mt('The following Cc e-mail address is invalid: ').&Apache::loncommon::cleanup_html($bad_ccs[0]);
1.71 raeburn 854: }
1.46 raeburn 855: } elsif (@bad_ccs > 1) {
1.74 raeburn 856: $badccmsg .= '<br />'.&mt('The following Cc e-mail addresses are invalid: '). &Apache::loncommon::cleanup_html(join(', ',@bad_ccs));
1.46 raeburn 857: }
858: }
1.95 raeburn 859: if ($env{'request.lti.login'}) {
860: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
861: $env{'form.user'} = "'".$env{'user.name'}.':'.$env{'user.domain'}."'";
862: }
863: $sourceurl = &Apache::lonnet::absolute_url().$url;
864: } else {
865: $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'";
866: $sourceurl = $env{'form.sourceurl'};
867: }
1.86 raeburn 868: if ($formvars{'course'}) {
869: $env{'form.crsi'} = $env{'form.title'};
870: if ($coursecode ne '') {
871: $env{'form.crsi'} .= ' - '.$coursecode;
872: }
873: }
874: if ($formvars{'section'}) {
875: my $section;
876: if ($sectionlist) {
877: if ($coursecode eq $ccode) {
878: $section = $env{'form.sectionsel'}
879: } else {
880: $section = $env{'form.sectiontxt'};
881: }
882: } else {
883: $section = $env{'form.section'};
884: }
885: $env{'form.crsi'} .= ' - '.$lt{'sect'}.': '.$section;
886: }
887: my $supportmsg;
888: if ($formvars{'username'}) {
889: $supportmsg .= "$lt{'username'}: $env{'form.username'}\n";
890: }
891: $supportmsg .= "$lt{'email'}: $env{'form.email'}\n";
892: if (($homeserver) && (defined($env{'form.cc'})) && ($formvars{'cc'})) {
893: $supportmsg .= "$lt{'cc'}: $okcclist\n";
894: }
895: if ($formvars{'user'}) {
896: $supportmsg .= "$lt{'user'}: $env{'form.user'}\n";
897: }
898: if ($formvars{'phone'}) {
899: $supportmsg .= "$lt{'phone'}: $env{'form.phone'}\n";
900: }
901: if ($formvars{'course'}) {
902: $supportmsg .= "$lt{'crsi'}: $env{'form.crsi'}\n";
1.89 raeburn 903: }
1.86 raeburn 904: $supportmsg .= "$lt{'subject'}: $env{'form.subject'}
1.44 raeburn 905: $lt{'description'}: $env{'form.description'}
1.95 raeburn 906: $lt{'sourceurl'}: $sourceurl
1.40 raeburn 907: $lt{'date'}: $reporttime
1.86 raeburn 908: ";
1.1 raeburn 909:
1.44 raeburn 910: my $displaymsg;
1.46 raeburn 911: foreach my $item ('username','email','cc','user','phone','crsi','subject','description','sourceurl') {
1.44 raeburn 912: if ($env{'form.'.$item} ne '') {
913: if ($item eq 'description') {
914: my $descrip = $env{'form.description'};
1.74 raeburn 915: $descrip = &Apache::loncommon::cleanup_html($descrip);
1.54 raeburn 916: $descrip =~ s|[\n\r\f]|<br />|g;
1.44 raeburn 917: $displaymsg .=
918: '<span class="LC_helpform_receipt_cat">'.
919: "$lt{$item}</span>: $descrip<br />\n";
920: } elsif ($item eq 'sourceurl') {
921: my $showurl = $env{'form.sourceurl'};
922: $showurl =~ s/\?.*$//;
1.74 raeburn 923: $showurl = &Apache::loncommon::cleanup_html($showurl);
1.44 raeburn 924: $displaymsg .=
925: '<span class="LC_helpform_receipt_cat">'.
926: "$lt{$item}</span>: $showurl<br />\n";
1.46 raeburn 927: } elsif ($item eq 'cc') {
1.86 raeburn 928: next if ($helpform{'cc'} eq 'no');
1.71 raeburn 929: if ($okcclist) {
1.74 raeburn 930: my $showcclist = &Apache::loncommon::cleanup_html($okcclist);
1.71 raeburn 931: $displaymsg .=
932: '<span class="LC_helpform_receipt_cat">'.
933: "$lt{$item}</span>: $showcclist<br />\n";
934: }
1.44 raeburn 935: } else {
1.86 raeburn 936: if (($item eq 'username') || ($item eq 'user') || ($item eq 'phone')) {
937: next if ($helpform{$item} eq 'no');
938: }
939: next if (($item eq 'crsi') && ($helpform{'course'} eq 'no'));
1.95 raeburn 940: next if (($item eq 'user') && ($env{'request.lti.login'}));
1.54 raeburn 941: my $showitem = $env{'form.'.$item};
1.74 raeburn 942: $showitem = &Apache::loncommon::cleanup_html($showitem);
1.44 raeburn 943: $displaymsg .=
944: '<span class="LC_helpform_receipt_cat">'.
1.54 raeburn 945: "$lt{$item}</span>: $showitem<br />\n";
1.44 raeburn 946: }
947: }
948: }
1.93 raeburn 949:
950: my ($requname,$requdom,$reqemail);
951: foreach my $field ('uname','udom','email') {
952: $env{'form.'.$field} =~ s/^\s+//;
953: $env{'form.'.$field} =~ s/\s+$//;
954: }
955: if ($env{'form.uname'} =~ /^$match_username$/) {
1.94 raeburn 956: $requname = $env{'form.uname'};
1.93 raeburn 957: }
958: if ($env{'form.udom'} =~ /^$match_domain$/) {
959: $requdom = $env{'form.udom'};
960: }
961: if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
962: $reqemail = $env{'form.email'};
963: }
964:
965: my $dom_in_effect;
966: unless ($env{'user.domain'} eq 'public') {
967: $dom_in_effect = $env{'user.domain'};
968: }
969: if ($dom_in_effect eq '') {
970: $dom_in_effect = $requdom;
971: }
972: if ($dom_in_effect eq '') {
973: $dom_in_effect = $defdom;
974: }
975:
1.44 raeburn 976: $displaymsg .= '<span class="LC_helpform_receipt_cat">'.
977: $lt{'date'}.'</span>: '.$reporttime.'<br />'."\n";
1.107 ! raeburn 978: my $args = {'function' => $function,
! 979: 'add_entries' => {
! 980: topmargin => "0",
! 981: marginheight => "0",
! 982: },
! 983: 'only_body' => 1,};
! 984: (undef,undef,undef,my $clientmathml,my $clientunicode) =
! 985: &Apache::loncommon::decode_user_agent();
! 986: if ($clientunicode && !$clientmathml) {
! 987: $args->{'browser.unicode'} = 1;
! 988: }
! 989: $r->print(&Apache::loncommon::start_page('Support request recorded',undef,$args));
1.14 raeburn 990: $r->print(<<"END");
1.73 bisitz 991: <form name="logproblem" action="">
1.44 raeburn 992: <input type="hidden" name="command" value="result" />
1.16 raeburn 993: </form>
1.1 raeburn 994: END
1.14 raeburn 995: if ($r->uri eq '/adm/helpdesk') {
996: &print_header($r,$url,'process');
997: }
1.45 raeburn 998: my $bad_email = 0;
1.93 raeburn 999: my ($to,$bcc,$addtext) =
1000: &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
1001: $dom_in_effect,$origmail,
1002: $requname,$requdom,
1003: $reqemail);
1.45 raeburn 1004: if ($to =~ /,/) {
1005: my @ok_email;
1006: foreach my $email (split(/,/,$to)) {
1007: if ($email =~ m/^[^\@]+\@[^\@]+$/) {
1.46 raeburn 1008: if (!grep(/^\Q$email\E$/,@ok_email)) {
1009: push(@ok_email,$email);
1010: }
1.45 raeburn 1011: }
1012: }
1013: if (@ok_email > 0) {
1014: $to = join(',',@ok_email);
1015: } elsif ($admin =~ m/^[^\@]+\@[^\@]+$/) {
1016: $to = $admin;
1017: } else {
1018: $bad_email = 1;
1019: }
1020: } elsif ($to !~ m/^[^\@]+\@[^\@]+$/) {
1021: if ($admin =~ m/^[^\@]+\@[^\@]+$/) {
1022: $to = $admin;
1.9 raeburn 1023: } else {
1.45 raeburn 1024: $bad_email = 1;
1025: }
1026: }
1.66 bisitz 1027:
1028: my $message;
1029: if (!$bad_email) {
1.106 raeburn 1030: $message = &mt('A support request has been sent to [_1]','<tt>'.$to.'</tt>');
1.66 bisitz 1031: } else {
1.106 raeburn 1032: $message = $lt{'warn'}.'<br />';
1033: if ($to eq '') {
1034: $message .= &mt('For this LON-CAPA server no e-mail address has been configured to receive support requests, so your support request has [_1]not[_2] been sent to the LON-CAPA support staff or administrator at your institution.','<b>','</b>');
1035: } else {
1036: $message .= &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.','<tt>'.$to.'</tt>','<b>','</b>');
1037: }
1.1 raeburn 1038: }
1.107 ! raeburn 1039: $r->print('<div class="LC_landmark" role="main">');
! 1040: if ($bad_email) {
! 1041: $r->print(&Apache::loncommon::confirmwrapper(&Apache::lonhtmlcommon::confirm_success($message,$bad_email)).'<br />');
! 1042: }
1.93 raeburn 1043: if ($reqemail ne '') {
1044: $from = $reqemail;
1.5 raeburn 1045: }
1046:
1.46 raeburn 1047: if (defined($env{'form.cc'})) {
1048: if ($badccmsg) {
1049: $displaymsg .= $badccmsg;
1050: }
1051: }
1052:
1.25 albertel 1053: my $subject = $env{'form.subject'};
1.44 raeburn 1054: $subject =~ s/(`)/'/g;
1055: $subject =~ s/\$/\(\$\)/g;
1056: $supportmsg =~ s/(`)/'/g;
1057: $supportmsg =~ s/\$/\(\$\)/g;
1058: $displaymsg =~ s/(`)/'/g;
1059: $displaymsg =~ s/\$/\(\$\)/g;
1.5 raeburn 1060: my $fname;
1061:
1062: my $attachmentpath = '';
1.88 raeburn 1063: my $showsize = '';
1.89 raeburn 1064:
1.72 raeburn 1065: if ((defined($env{'user.name'})) && (!$public)) {
1.67 raeburn 1066: if ($homeserver && $env{'form.screenshot.filename'}) {
1.86 raeburn 1067: unless ($helpform{'screenshot'} eq 'no') {
1.88 raeburn 1068: my $attachmentsize = length($env{'form.screenshot'});
1.86 raeburn 1069: my $max = 1048576;
1.87 raeburn 1070: my $showmax = 1.00;
1.86 raeburn 1071: if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) {
1072: $max *= $helpform{'maxsize'};
1.87 raeburn 1073: $showmax = $helpform{'maxsize'};
1.86 raeburn 1074: }
1.89 raeburn 1075: $showmax = '('.sprintf("%.2f",$showmax).' MB)';
1.88 raeburn 1076: $showsize = $attachmentsize/1048576;
1077: $showsize = '('.sprintf("%.2f",$showsize).' MB)';
1.86 raeburn 1078: if ($attachmentsize > $max) {
1079: $displaymsg .= '<br /><span class="LC_warning">'.
1.87 raeburn 1080: &mt('The uploaded screenshot file [_1] included with your request exceeded the maximum allowed size [_2], and has therefore been discarded.',$showsize,$showmax).'</span>';
1.86 raeburn 1081: } else {
1082: $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
1083: }
1.5 raeburn 1084: }
1085: }
1086: }
1087:
1.40 raeburn 1088: my %cookies;
1.27 raeburn 1089: my $cookie=CGI::Cookie->parse($r->header_in('Cookie'));
1.39 albertel 1090: if ($$cookie{'lonID'} =~ /lonID=($LONCAPA::handle_re);/) {
1.27 raeburn 1091: $cookies{'lonID'} = $1;
1092: }
1.91 raeburn 1093: if ($$cookie{'lonLinkID'} =~ /lonLinkID=([a-f0-9]+_linked);/) {
1094: $cookies{'lonLinkID'} = $1;
1095: }
1.95 raeburn 1096: my $lti_info;
1097: if (($env{'request.lti.login'}) && ($env{'request.course.id'})) {
1098: my $ltidom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1099: if ($ltidom) {
1100: my %lti = &Apache::lonnet::get_domain_lti($ltidom,'provider');
1101: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
1102: if ($lti{$env{'request.lti.login'}}{'consumer'}) {
1103: $lti_info = "LTI consumer: ".$lti{$env{'request.lti.login'}}{'consumer'}."\n";
1104: }
1105: }
1106: }
1107: }
1.5 raeburn 1108: if ($attachmentpath =~ m-/([^/]+)$-) {
1109: $fname = $1;
1.51 bisitz 1110: $displaymsg .= '<br />'
1.88 raeburn 1111: .&mt('An uploaded screenshot file [_1] was included in the request sent by [_2].'
1112: ,'<span class="LC_filename">'.$fname.'</span> '.$showsize,
1.51 bisitz 1113: ,$env{'user.name'}.':'.$env{'user.domain'}
1114: );
1.5 raeburn 1115: $supportmsg .= "\n";
1.40 raeburn 1116: foreach my $var (@cookievars) {
1117: $supportmsg .= "$var: $cookies{$var}\n";
1.27 raeburn 1118: }
1.40 raeburn 1119: foreach my $var(@ENVvars) {
1120: $supportmsg .= "$var: $ENV{$var}\n";
1.26 raeburn 1121: }
1.101 raeburn 1122: $supportmsg .= "REMOTE_ADDR: $ip\n";
1.40 raeburn 1123: foreach my $var (@envvars) {
1124: $supportmsg .= "$var: $env{$var}\n";
1.5 raeburn 1125: }
1.95 raeburn 1126: if ($lti_info) {
1127: $supportmsg .= $lti_info;
1128: }
1.5 raeburn 1129: }
1.89 raeburn 1130:
1.81 musolffc 1131: my $cc_string;
1.67 raeburn 1132: if ($homeserver) {
1133: if (@ok_ccs > 0) {
1.81 musolffc 1134: $cc_string = join(', ',@ok_ccs);
1.67 raeburn 1135: }
1.46 raeburn 1136: }
1.5 raeburn 1137:
1.90 raeburn 1138: my $attachment_text = '';
1.81 musolffc 1139: unless ($homeserver && $attachmentpath) {
1.40 raeburn 1140: foreach my $var (@cookievars) {
1.90 raeburn 1141: $attachment_text .= "$var: $cookies{$var}\n";
1.27 raeburn 1142: }
1.40 raeburn 1143: foreach my $var (@ENVvars) {
1.90 raeburn 1144: $attachment_text .= "$var: $ENV{$var}\n";
1.26 raeburn 1145: }
1.101 raeburn 1146: $attachment_text .= "REMOTE_ADDR: $ip\n";
1.40 raeburn 1147: foreach my $var (@envvars) {
1.90 raeburn 1148: $attachment_text .= "$var: $env{$var}\n";
1.5 raeburn 1149: }
1.40 raeburn 1150: foreach my $var (@loncvars) {
1.90 raeburn 1151: $attachment_text .= "$var: $env{$var}\n";
1.5 raeburn 1152: }
1.95 raeburn 1153: if ($lti_info) {
1154: $attachment_text .= $lti_info;
1155: }
1.5 raeburn 1156: }
1.86 raeburn 1157:
1158: if ($addtext) {
1159: my ($addloc,$addstr) = split(/:/,$addtext,2);
1160: $addstr = &unescape($addstr);
1161: if ($addloc eq 's') {
1162: $subject = $addstr.' '.$subject;
1163: } elsif ($addloc eq 'b') {
1164: $supportmsg = $addstr."\n".$supportmsg;
1165: }
1166: }
1167:
1.106 raeburn 1168: if ($bad_email) {
1169: $r->print('<b>'.$lt{'belo'}.'</b><br />'.
1.107 ! raeburn 1170: $lt{'ifyk'}."\n");
1.106 raeburn 1171: } else {
1172: # Compose and send a MIME email
1173: &Apache::loncommon::mime_email($from,'',$to,$subject,$supportmsg,$cc_string,
1174: $bcc,$attachmentpath,$fname,$attachment_text);
1.107 ! raeburn 1175: $r->print('<b>'.$lt{'your'}.'</b>:'."\n");
1.106 raeburn 1176: }
1.44 raeburn 1177: if ($attachmentpath =~ m|$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+|) {
1.5 raeburn 1178: unlink($attachmentpath);
1179: }
1.55 bisitz 1180: $r->print('<div style="width:620px;">'.
1181: &Apache::lonhtmlcommon::start_pick_box().
1.44 raeburn 1182: &Apache::lonhtmlcommon::row_title($lt{'info'},undef,'LC_oddrow_value')."\n".$displaymsg."\n".
1183: &Apache::lonhtmlcommon::row_closure().
1184: &Apache::lonhtmlcommon::row_title($lt{'adin'},undef,'LC_evenrow_value'));
1185: my $envmsg;
1.40 raeburn 1186: foreach my $var (@cookievars) {
1.44 raeburn 1187: if ($cookies{$var} ne '') {
1188: $envmsg.= '<span class="LC_helpform_receipt_cat">'.
1189: $var.'</span>: '.$cookies{$var}.', ';
1.27 raeburn 1190: }
1191: }
1.40 raeburn 1192: foreach my $var (@ENVvars) {
1.44 raeburn 1193: if ($ENV{$var} ne '') {
1194: $envmsg .= '<span class="LC_helpform_receipt_cat">'.
1195: $var.'</span>: '.$ENV{$var}.', ';
1.26 raeburn 1196: }
1197: }
1.101 raeburn 1198: if ($ip ne '') {
1199: $envmsg .= '<span class="LC_helpform_receipt_cat">'.
1.102 raeburn 1200: 'REMOTE_ADDR</span>: '.$ip.', ';
1201: }
1.40 raeburn 1202: foreach my $var (@envvars) {
1.44 raeburn 1203: if ($env{$var} ne '') {
1204: $envmsg .= '<span class="LC_helpform_receipt_cat">'.
1205: $var.'</span>: '.$env{$var}.', ';
1.5 raeburn 1206: }
1.1 raeburn 1207: }
1.44 raeburn 1208: $envmsg =~ s/, $//;
1209: $r->print($envmsg."\n".
1210: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.55 bisitz 1211: &Apache::lonhtmlcommon::end_pick_box().
1.107 ! raeburn 1212: '</div>');
! 1213: unless ($bad_email) {
! 1214: $r->print('<p><br />'.&Apache::loncommon::confirmwrapper(&Apache::lonhtmlcommon::confirm_success($message)).'</p>');
! 1215: }
! 1216: $r->print("</div>\n".
1.44 raeburn 1217: &Apache::loncommon::end_page());
1.1 raeburn 1218: }
1219:
1.14 raeburn 1220: sub print_header {
1.44 raeburn 1221: my ($r,$origurl,$command) = @_;
1.14 raeburn 1222: my $location=&Apache::loncommon::lonhttpdurl("/adm");
1223: my ($component_url);
1.107 ! raeburn 1224: my $helpicon_link = '<a href="javascript:validate();" tabindex="-1">';
! 1225: if ($command eq 'process') {
! 1226: $helpicon_link = '<a href="/adm/helpdesk" tabindex="-1">';
! 1227: }
! 1228: my $helpdesk_link = '<a href="javascript:validate();">';
1.44 raeburn 1229: if ($command eq 'process') {
1.14 raeburn 1230: $helpdesk_link = '<a href="/adm/helpdesk">';
1231: }
1232: my %lt = &Apache::lonlocal::texthash (
1.67 raeburn 1233: login => 'Log-in help',
1234: ask => 'Ask helpdesk',
1235: getst => 'Getting started guide',
1.86 raeburn 1236: back => 'Back to last location',
1.47 bisitz 1237: headline => 'help/support',
1.67 raeburn 1238: stud => 'Students',
1239: ifyo => 'If your problem is still unresolved, the form below can be used to send a question to the LON-CAPA helpdesk.',
1240: cont => 'Contact your instructor instead.',
1.21 raeburn 1241: );
1.47 bisitz 1242: my ($getstartlink,$reviewtext);
1.21 raeburn 1243: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/gettingstarted.html') {
1.107 ! raeburn 1244: $getstartlink = qq|<div class="LC_helpdesk_links LC_nobreak"><div class="LC_helpdesk_img" aria-hidden="true"> </div><div class="LC_helpdesk_text"><a href="/adm/gettingstarted.html">$lt{'getst'}</a> </div></div>|;
1.47 bisitz 1245: $reviewtext = &mt('Please review the information in "Log-in help" and the "Getting started" guide if you are unable to log-in.');
1246: } else {
1247: $reviewtext = &mt('Please review the information in "Log-in help" if you are unable to log-in.');
1.21 raeburn 1248: }
1.70 raeburn 1249: my $linkback;
1.59 raeburn 1250: if ($origurl eq '') {
1.70 raeburn 1251: $linkback = 'javascript:history.go(-1)';
1252: } else {
1253: $linkback = &HTML::Entities::encode($origurl,'"<>&');
1.59 raeburn 1254: }
1.68 raeburn 1255: my $loginhelp = &Apache::lonauth::loginhelpdisplay();
1256: if ($loginhelp eq '') {
1257: $loginhelp = '/adm/loginproblems.html';
1258: }
1.67 raeburn 1259: $r->print(<<"END");
1.107 ! raeburn 1260: <div class="LC_landmark" style="display: inline-block;" role="navigation">
! 1261: <div class="LC_helpdesk_headbox">
! 1262: <h1 class="LC_helpdesk_legend">
! 1263: <img src="$location/lonIcons/minilogo.gif" height="20" width="29" alt="LONCAPA logo" style="vertical-align: middle" />
! 1264: LON-CAPA $lt{'headline'}
! 1265: </h1>
! 1266: <div style="border:0; padding:0; margin: 1em 0 0.5em;">
! 1267: <div class="LC_helpdesk_links LC_nobreak"><div class="LC_helpdesk_img" aria-hidden="true"> <a href="$loginhelp" tabindex="-1"><img src="$location/help/help.png" border="0" alt="($lt{'login'})" style="vertical-align:middle" /> </a></div><div class="LC_helpdesk_text"><a href="$loginhelp">$lt{'login'}</a> </div></div>
! 1268: <div class="LC_helpdesk_links LC_nobreak"><div class="LC_helpdesk_img" aria-hidden="true"> $helpicon_link<img src="$location/lonIcons/helpdesk.gif" border="0" alt="($lt{'ask'})" style="vertical-align:top" /> </a></div><div class="LC_helpdesk_text">$helpdesk_link$lt{'ask'}</a> </div></div>$getstartlink
! 1269: <div class="LC_helpdesk_links LC_nobreak"><div class="LC_helpdesk_img" aria-hidden="true"> <a href="$linkback" target="_top" tabindex="-1"><img src="$location/lonIcons/move_up.gif" border="0" alt="($lt{'back'})" style="vertical-align:middle" /> </a></div><div class="LC_helpdesk_text"><a href="$linkback" target="_top">$lt{'back'}</a> </div></div>
! 1270: </div>
! 1271: </div>
! 1272: </div>
1.14 raeburn 1273: END
1.44 raeburn 1274: if ($command ne 'process') {
1.67 raeburn 1275: my $stuwarn = &mt('Do [_1]not[_2] use this form to ask about course content.',
1276: '<b>','</b>');
1277: $r->print(<<"END");
1.107 ! raeburn 1278: <div style="border:0; padding:0; margin: 0; max-width: 600px;" role="complementary">
! 1279: $reviewtext
1.76 bisitz 1280: $lt{'ifyo'}
1.107 ! raeburn 1281: <p class="LC_info">
! 1282: <b>$lt{'stud'}:</b>
! 1283: $stuwarn $lt{'cont'}
! 1284: </p>
! 1285: </div>
1.67 raeburn 1286: END
1.14 raeburn 1287: }
1288: return;
1289: }
1290:
1.45 raeburn 1291: sub get_domain {
1292: my $codedom;
1293: if (exists($env{'form.codedom'})) {
1.70 raeburn 1294: if (&Apache::lonnet::domain($env{'form.codedom'}) ne '') {
1295: return $env{'form.codedom'};
1296: }
1297: }
1298: if ($env{'request.course.id'}) {
1.45 raeburn 1299: $codedom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1300: } elsif ($env{'request.role.domain'}) {
1301: $codedom = $env{'request.role.domain'};
1302: } else {
1.54 raeburn 1303: $codedom = &Apache::lonnet::default_login_domain();
1.45 raeburn 1304: }
1305: return $codedom;
1306: }
1307:
1.1 raeburn 1308: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>