Annotation of loncom/interface/lonsupportreq.pm, revision 1.106
1.86 raeburn 1: # The LearningOnline Network with CAPA
2: # Helpdesk request form
1.24 albertel 3: #
1.106 ! raeburn 4: # $Id: lonsupportreq.pm,v 1.105 2023/07/26 01:03:58 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.44 raeburn 333:
334: $r->print(&Apache::loncommon::start_page('Support Request',$js,
1.31 albertel 335: { 'function' => $function,
1.33 albertel 336: 'add_entries' => \%add_entries,
1.44 raeburn 337: 'only_body' => 1,}));
1.15 raeburn 338: if ($r->uri eq '/adm/helpdesk') {
1.14 raeburn 339: &print_header($r,$origurl);
340: }
1.50 raeburn 341: my @css = ('LC_evenrow_value','LC_oddrow_value');
342: my $num = 1;
343: my $i = $num%2;
1.67 raeburn 344: my $formtype;
345: if ($homeserver) {
346: $formtype = ' enctype="multipart/form-data"';
347: }
1.86 raeburn 348: my $topsubmit = ' <input type="button" value="'.$html_lt{'subm'}.'" onclick="validate()" /> ';
349: my $shownsubmit;
1.67 raeburn 350: $r->print('<form method="post" action="" name="logproblem"'.$formtype.'>'."\n");
1.44 raeburn 351: my $output = &Apache::lonhtmlcommon::start_pick_box().
1.78 bisitz 352: &Apache::lonhtmlcommon::row_headline().
353: '<span class="LC_info">'.
354: &mt('(All fields marked with * are required.)').
355: '</span>'.
1.86 raeburn 356: &Apache::lonhtmlcommon::row_closure();
357: unless ($helpform{'username'} eq 'no') {
358: my ($reqd,$namefield,$fullname);
359: if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) {
1.89 raeburn 360: $fullname = "$firstname $lastname";
1.86 raeburn 361: $namefield = $fullname.'<input type="hidden" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
362: } else {
363: if (defined($firstname) && $firstname ne '') {
364: $fullname = $firstname;
365: } elsif (defined($lastname) && $lastname ne '') {
366: $fullname = " $lastname";
367: }
368: $namefield = '<input type="text" size="20" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
369: if ($helpform{'username'} eq 'req') {
370: $reqd = '<span class="LC_info">*</span>';
371: }
1.1 raeburn 372: }
1.86 raeburn 373: $output .= &Apache::lonhtmlcommon::row_title($html_lt{'name'}.$reqd,undef,$css[$num])."\n".$namefield.
374: $topsubmit.
375: &Apache::lonhtmlcommon::row_closure()."\n";
376: $shownsubmit = 1;
377: $num ++;
378: $i = $num%2;
1.1 raeburn 379: }
1.78 bisitz 380: $output .= &Apache::lonhtmlcommon::row_title(
381: '<span title="'.&mt('required').'">'.
1.79 damieng 382: $html_lt{'emad'}.' <span class="LC_info">*</span></span>'
1.78 bisitz 383: ,undef,$css[$i]).
1.50 raeburn 384: '<input type="text" size="20" name="email" value="'.
1.86 raeburn 385: &HTML::Entities::encode($email,'"<>&').'" />'."\n";
386: unless ($shownsubmit) {
387: $output .= $topsubmit;
1.89 raeburn 388: }
1.86 raeburn 389: $output .= &Apache::lonhtmlcommon::row_closure();
1.50 raeburn 390: $num ++;
391: $i = $num%2;
1.82 raeburn 392: if ($knownuser) {
393: if ($homeserver) {
1.104 raeburn 394: my $ip = &Apache::lonnet::get_requestor_ip($r);
395: my %setters;
396: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
397: &Apache::loncommon::blockcheck(\%setters,'com',$ip);
398: unless (($helpform{'cc'} eq 'no') || ($by_ip)) {
1.86 raeburn 399: $output .= &Apache::lonhtmlcommon::row_title($html_lt{'emac'},undef,$css[$i]).
400: '<input type="text" size="50" name="cc" value="" /><br />'."\n".
401: &Apache::lonhtmlcommon::row_closure();
402: $num ++;
403: $i = $num%2;
404: }
1.67 raeburn 405: }
1.50 raeburn 406: }
1.95 raeburn 407: unless (($helpform{'user'} eq 'no') || ($env{'request.lti.login'})) {
1.86 raeburn 408: $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'unme'}/$html_lt{'doma'}",undef,$css[$i]);
409: my $udom_input = '<input type="hidden" name="udom" value="'.
410: &HTML::Entities::encode($udom,'"<>&').'" />'."\n";
411: my $uname_input = '<input type="hidden" name="uname" value="'.
412: &HTML::Entities::encode($uname,'"<>&').'" />'."\n";
413: if ($knownuser) {
414: $output .= '<i>'.$html_lt{'unme'}.'</i>: '.$uname.' <i>'.$html_lt{'doma'}.'</i>: '.$udom.$udom_input.$uname_input;
1.44 raeburn 415: } else {
1.86 raeburn 416: my $udomform = '';
417: my $unameform = '';
418: if (($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
419: $output .= $html_lt{'entu'};
420: } elsif (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
421: $output .= $html_lt{'chdo'};
422: } else {
423: $output .= $html_lt{'entr'};
424: }
425: $output .= '<br />'."\n";
426: if (!$public) {
427: if ($env{'user.domain'} =~ /^$match_domain$/) {
428: $udomform = '<i>'.$html_lt{'doma'}.'</i>: '.$udom.$udom_input;
429: } elsif ($env{'user.name'} =~ /^$match_username$/) {
430: $unameform = '<i>'.$html_lt{'unme'}.'</i>: '.$uname.' '.$uname_input;
431: }
432: }
433: if ($udomform eq '') {
434: $udomform = '<i>'.$html_lt{'doma'}.'</i>: ';
435: $udomform .= &Apache::loncommon::select_dom_form($codedom,'udom')."\n";
436: }
437: if ($unameform eq '') {
438: $unameform= '<i>'.$html_lt{'unme'}.'</i>: <input type="text" size="20" name="uname" value="'.$uname.'" /> ';
1.60 raeburn 439: }
1.86 raeburn 440: $output .= $unameform.$udomform;
1.1 raeburn 441: }
1.86 raeburn 442: $output .= &Apache::lonhtmlcommon::row_closure();
443: $num ++;
1.95 raeburn 444: $i = $num%2;
445: }
446: unless ($env{'request.lti.login'}) {
447: $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'urlp'}",undef,$css[$i]).
448: $server."\n".'<input type="hidden" name="sourceurl" value="'.
449: &HTML::Entities::encode($sourceurl,'"<>&').'" />'."\n".
450: &Apache::lonhtmlcommon::row_closure();
1.1 raeburn 451: }
1.86 raeburn 452: unless ($helpform{'phone'} eq 'no') {
453: my $reqd;
454: if ($helpform{'phone'} eq 'req') {
455: $reqd = '<span class="LC_info">*</span>';
456: }
457: $output .= &Apache::lonhtmlcommon::row_title($html_lt{'phon'}.$reqd,undef,'LC_evenrow_value').
458: '<input type="text" size="15" name="phone" /><br />'."\n".
459: &Apache::lonhtmlcommon::row_closure();
460: $num ++;
461: $i = $num%2;
462: }
1.95 raeburn 463: unless (($helpform{'course'} eq 'no') || ($env{'request.lti.login'})) {
1.86 raeburn 464: $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'crsd'}$details_title",undef,$css[$i]);
1.10 raeburn 465: if ($totcodes > 0) {
466: my $numtitles = @codetitles;
467: if ($numtitles == 0) {
1.79 damieng 468: $output .= $html_lt{'enin'}.':
1.105 raeburn 469: <input type="text" name="coursecode" size="15" value="'.&HTML::Entities::encode($ccode,'\'"&<>').'" />'."\n";
1.10 raeburn 470: } else {
1.57 raeburn 471: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1.10 raeburn 472: my $lasttitle = $numtitles;
473: if ($numtitles > 4) {
474: $lasttitle = 4;
1.86 raeburn 475: }
476: my $onchange;
477: if ($sectionlist) {
478: $onchange = 'toggleSecVis()';
479: }
1.44 raeburn 480: $output .= '<table><tr><td>'.$codetitles[0].'<br />'."\n".
1.86 raeburn 481: '<select name="'.$standardnames[0].'" onchange="courseSet('."'$codetitles[0]'".');'.$onchange.'">'."\n".
1.79 damieng 482: ' <option value="-1">'.$html_lt{'sele'}."</option>\n";
1.10 raeburn 483: my @items = ();
1.20 raeburn 484: my @longitems = ();
1.10 raeburn 485: if ($idlist{$codetitles[0]} =~ /","/) {
1.40 raeburn 486: @items = split(/","/,$idlist{$codetitles[0]});
1.10 raeburn 487: } else {
488: $items[0] = $idlist{$codetitles[0]};
489: }
1.20 raeburn 490: if (defined($idlist_titles{$codetitles[0]})) {
491: if ($idlist_titles{$codetitles[0]} =~ /","/) {
1.40 raeburn 492: @longitems = split(/","/,$idlist_titles{$codetitles[0]});
1.20 raeburn 493: } else {
494: $longitems[0] = $idlist_titles{$codetitles[0]};
495: }
1.22 raeburn 496: for (my $i=0; $i<@longitems; $i++) {
497: if ($longitems[$i] eq '') {
498: $longitems[$i] = $items[$i];
499: }
500: }
1.20 raeburn 501: } else {
502: @longitems = @items;
503: }
504: for (my $i=0; $i<@items; $i++) {
1.44 raeburn 505: $output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>'."\n";
1.10 raeburn 506: }
1.44 raeburn 507: $output .= '</select></td>';
1.10 raeburn 508: for (my $i=1; $i<$numtitles; $i++) {
1.44 raeburn 509: $output .= '<td>'.$codetitles[$i].'<br />'."\n".
1.86 raeburn 510: '<select name="'.$standardnames[$i].'" onchange="courseSet('."'$codetitles[$i]'".');'.$onchange.'">'."\n".
1.79 damieng 511: '<option value="-1"><-'.$html_lt{'pick'}.' '.$codetitles[$i-1].'</option>'."\n".
1.10 raeburn 512: '</select>'."\n".
1.44 raeburn 513: '</td>'."\n";
1.10 raeburn 514: }
1.44 raeburn 515: $output .= '</tr></table>';
1.10 raeburn 516: if ($numtitles > 4) {
1.44 raeburn 517: $output .= '<br /><br />'.$codetitles[$numtitles].'<br />'."\n".
1.86 raeburn 518: '<select name="'.$standardnames[$numtitles].'" onchange="courseSet('."'$codetitles[$numtitles]'".');'.$onchange.'">'."\n".
1.79 damieng 519: '<option value="-1"><-'.$html_lt{'pick'}.' '.$codetitles[$numtitles-1].'</option>'."\n".
1.44 raeburn 520: '</select>'."\n";
1.10 raeburn 521: }
522: }
523: } else {
1.79 damieng 524: $output .= $html_lt{'enin'}.':
1.67 raeburn 525: <input type="text" name="coursecode" size="15" value="" />'."\n";
1.10 raeburn 526: }
1.86 raeburn 527: my $reqd;
528: if ($helpform{'course'} eq 'req') {
529: $reqd = '<span class="LC_info">*</span>';
530: }
531: $output .= '<br />'.$html_lt{'enct'}.$reqd.':
532: <input type="text" name="title" size="25" value="'.
1.44 raeburn 533: &HTML::Entities::encode($ctitle,'"<>&').'" />'."\n";
1.86 raeburn 534: $output .= &Apache::lonhtmlcommon::row_closure();
535: $num ++;
536: $i = $num%2;
537: }
1.95 raeburn 538: unless (($helpform{'section'} eq 'no') || ($env{'request.lti.login'})) {
1.86 raeburn 539: $output .= &Apache::lonhtmlcommon::row_title($html_lt{'secn'},undef,$css[$i]);
540: if ($sectionlist) {
541: $output .= "<div id=\"LC_helpdesk_sectionlist\"><select name=\"sectionsel\">\n".
542: " <option value=\"\" selected=\"selected\">$html_lt{'sele'}</option>\n";
543: foreach my $id (sort(keys(%groupid))) {
544: if ($id eq $groupid{$id} || $groupid{$id} eq '') {
545: $output .= " <option value=".
546: &HTML::Entities::encode($id,'"<>&').
547: " >$id</option>\n";
548: } else {
549: $output .= " <option value=".
550: &HTML::Entities::encode($id,'"<>&').
551: " >$id - ($html_lt{'lsec'}: $groupid{$id})</option>\n";
552: }
1.1 raeburn 553: }
1.86 raeburn 554: $output .= '</select></div>'."\n".
555: '<div id="LC_helpdesk_section" style="display:none">'.
556: '<input type="text" name="sectiontxt" size="10" /></div>'."\n";
1.89 raeburn 557: } else {
1.86 raeburn 558: $output .= '<input type="text" name="section" size="10" />'."\n";
559: }
560: $output .= &Apache::lonhtmlcommon::row_closure();
561: $num ++;
562: $i = $num%2;
1.1 raeburn 563: }
1.78 bisitz 564: $output .= &Apache::lonhtmlcommon::row_title(
565: '<span title="'.&mt('required').'">'.
1.79 damieng 566: $html_lt{'subj'}.' <span class="LC_info">*</span></span>'
1.78 bisitz 567: ,undef,'LC_oddrow_value').
568: '<input type="text" size="40" name="subject" />'."\n".
1.44 raeburn 569: &Apache::lonhtmlcommon::row_closure().
1.78 bisitz 570: &Apache::lonhtmlcommon::row_title(
571: '<span title="'.&mt('required').'">'.
1.79 damieng 572: $html_lt{'detd'}.' <span class="LC_info">*</span></span>'
1.78 bisitz 573: ,undef,'LC_evenrow_value').
574: '<textarea rows="10" cols="45" name="description" style="word-wrap:normal;">'.
1.67 raeburn 575: '</textarea>'."\n".
1.44 raeburn 576: &Apache::lonhtmlcommon::row_closure();
1.50 raeburn 577: $num ++;
578: $i = $num%2;
1.82 raeburn 579: if ($knownuser) {
1.67 raeburn 580: if ($homeserver) {
1.86 raeburn 581: unless ($helpform{'screenshot'} eq 'no') {
582: my $max = 1048576;
1.87 raeburn 583: my $showmax = 1.00;
1.86 raeburn 584: if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) {
1.89 raeburn 585: $max *= $helpform{'maxsize'};
1.87 raeburn 586: $showmax = $helpform{'maxsize'};
1.86 raeburn 587: }
1.87 raeburn 588: $showmax = ' ('.sprintf("%.2f",$showmax).' '.&mt('MB max.').')';
1.86 raeburn 589: $output .= &Apache::lonhtmlcommon::row_title($html_lt{'opfi'},undef,$css[$i])
1.97 raeburn 590: .' <input type="file" name="screenshot" class="LC_flUpload" size="20" />'
1.98 raeburn 591: .'<input type="hidden" id="LC_free_space" value="'.$max.'" />'
1.87 raeburn 592: .'<br />'."\n".$html_lt{'uplf'}.$showmax."\n"
1.86 raeburn 593: .&Apache::lonhtmlcommon::row_closure();
594: $num ++;
595: $i = $num%2;
596: }
1.67 raeburn 597: }
1.69 raeburn 598: } else {
1.82 raeburn 599: if ($captcha_form) {
1.78 bisitz 600: $output .= &Apache::lonhtmlcommon::row_title(
601: '<span title="'.&mt('required').'">'.
602: &mt('Validation').
603: ' <span class="LC_info">*</span></span>'
604: ,undef,$css[$i]).
1.82 raeburn 605: $captcha_form."\n".
1.69 raeburn 606: &Apache::lonhtmlcommon::row_closure();
607: $num ++;
608: $i = $num%2;
609: }
1.5 raeburn 610: }
1.79 damieng 611: $output .= &Apache::lonhtmlcommon::row_title($html_lt{'fini'},undef,$css[$i]);
1.44 raeburn 612: $output .= <<END;
1.1 raeburn 613: <table border="0" cellpadding="8" cellspacing="0">
614: <tr>
615: <td>
1.44 raeburn 616: <input type="hidden" name="command" value="process" />
1.79 damieng 617: <input type="button" value="$html_lt{'subm'}" onclick="validate()" />
1.1 raeburn 618: </td>
619: <td> </td>
620: <td>
1.79 damieng 621: <input type="reset" value="$html_lt{'clfm'}" />
1.1 raeburn 622: </td>
623: </tr>
624: </table>
1.44 raeburn 625: END
626: $output .= &Apache::lonhtmlcommon::row_closure(1);
627: $output .= &Apache::lonhtmlcommon::end_pick_box();
628: $r->print(<<END);
629: $output
1.14 raeburn 630: </form>
1.44 raeburn 631: <br />
1.1 raeburn 632: END
1.30 albertel 633: $r->print(&Apache::loncommon::end_page());
1.5 raeburn 634: return;
1.1 raeburn 635: }
636:
637: sub print_request_receipt {
638: my ($r,$url,$function) = @_;
1.69 raeburn 639: my $public;
640: if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
641: $public = 1;
642: }
1.89 raeburn 643: my $lonhost = $r->dir_config('lonHostID');
1.69 raeburn 644: unless (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
645: my ($captcha_chk,$captcha_error) =
646: &Apache::loncommon::captcha_response('login',$lonhost);
647: if ($captcha_chk != 1) {
648: $r->print(&Apache::loncommon::start_page('Support request failed',undef,
649: {'function' => $function,
650: 'add_entries' => {
651: topmargin => "0",
652: marginheight => "0",
653: },
654: 'only_body' => 1,}));
655: if ($r->uri eq '/adm/helpdesk') {
656: &print_header($r,$url,'process');
657: }
1.75 bisitz 658: $r->print(
659: '<h2>'.&mt('Support request failed').'</h2>'.
660: &Apache::lonhtmlcommon::confirm_success(
661: &mt('Validation of the code you entered failed.'),1).
662: '<br /><br />'.
663: &Apache::lonhtmlcommon::actionbox([
664: &mt('[_1]Go back[_2] and try again',
665: '<a href="javascript:history.go(-1)">','</a>')]).
1.69 raeburn 666: &Apache::loncommon::end_page());
667: return;
668: }
669: }
1.104 raeburn 670: my $ip = &Apache::lonnet::get_requestor_ip($r);
671: my %setters;
672: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
673: &Apache::loncommon::blockcheck(\%setters,'com',$ip);
1.101 raeburn 674: my @ENVvars = ('HTTP_HOST','HTTP_USER_AGENT','SERVER_ADDR','SERVER_NAME');
1.26 raeburn 675: my @envvars = ('browser.os','browser.type','browser.version','user.home','request.role');
1.5 raeburn 676: my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');
1.91 raeburn 677: my @cookievars;
678: if ($ENV{'SERVER_PORT'} == 443) {
679: @cookievars = ('lonLinkID');
680: } else {
681: @cookievars = ('lonID');
682: }
1.5 raeburn 683:
684: my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
1.45 raeburn 685: my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
686: my $defdom = &get_domain();
1.5 raeburn 687: my $from = $admin;
1.86 raeburn 688: my %helpform;
1.56 raeburn 689: my %domconfig =
690: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
691: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.86 raeburn 692: if (ref($domconfig{'contacts'}{'helpform'}) eq 'HASH') {
693: %helpform = %{$domconfig{'contacts'}{'helpform'}};
1.56 raeburn 694: }
695: }
1.1 raeburn 696: my $reporttime = &Apache::lonlocal::locallocaltime(time);
1.86 raeburn 697: my %formvars = (
698: email => 1,
699: sourceurl => 1,
700: subject => 1,
701: description => 1,
702: );
703: unless ($helpform{'username'} eq 'no') {
704: $formvars{'username'} = 1;
705: }
706: unless ($helpform{'user'} eq 'no') {
707: $formvars{'uname'} = 1;
708: $formvars{'udom'} = 1;
709: }
710: unless ($helpform{'phone'} eq 'no') {
711: $formvars{'phone'} = 1;
712: }
1.95 raeburn 713: unless (($helpform{'section'} eq 'no') || ($env{'request.lti.login'})) {
1.86 raeburn 714: $formvars{'section'} = 1;
715: }
1.95 raeburn 716: unless (($helpform{'course'} eq 'no') || ($env{'request.lti.login'})) {
1.86 raeburn 717: $formvars{'course'} = 1;
718: }
1.104 raeburn 719: unless (($helpform{'cc'} eq 'no') || ($by_ip)) {
1.86 raeburn 720: $formvars{'cc'} = 1;
721: }
722: unless ($helpform{'screenshot'} eq 'no') {
723: $formvars{'screenshot'} = 1;
724: }
1.95 raeburn 725: my ($coursecode,$sourceurl);
1.86 raeburn 726: if ($formvars{'course'}) {
727: $coursecode = $env{'form.coursecode'};
1.57 raeburn 728: if ($coursecode eq '') {
1.86 raeburn 729: my $totcodes = 0;
1.96 raeburn 730: my $instcats = &Apache::lonnet::get_dom_instcats($defdom);
731: if (ref($instcats) eq 'HASH') {
732: if (ref($instcats->{'codes'}) eq 'HASH') {
733: $totcodes = scalar(keys(%{$instcats->{'codes'}}));
734: }
735: }
1.86 raeburn 736: my @standardnames = &Apache::loncommon::get_standard_codeitems();
737: if ($totcodes > 0) {
738: my $noregexps = 1;
739: $coursecode =
740: &Apache::courseclassifier::instcode_from_selectors($defdom,$noregexps);
741: }
742: if ($coursecode eq '') {
743: foreach my $item (@standardnames) {
744: if ((defined($env{'form.'.$item})) && ($env{'form.'.$item} ne '-1')) {
745: $coursecode .= $env{'form.'.$item};
746: }
1.57 raeburn 747: }
748: }
1.19 raeburn 749: }
750: }
1.40 raeburn 751: my %lt = &Apache::lonlocal::texthash (
1.44 raeburn 752: username => 'Name',
1.52 schafran 753: email => 'E-mail',
1.46 raeburn 754: cc => 'Cc',
1.44 raeburn 755: user => 'Username/domain',
756: phone => 'Phone',
757: crsi => 'Course Information',
758: subject => 'Subject',
759: description => 'Description',
760: sourceurl => 'URL',
761: date => 'Date/Time',
762: secn => 'Section',
763: warn => 'Warning: Problem with support e-mail address',
764: your => 'Your support request contained the following information',
1.106 ! raeburn 765: belo => 'Below is your support request which could not be sent',
! 766: 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 767: sect => 'section',
768: info => 'Information supplied',
769: adin => 'Additional information recorded',
1.40 raeburn 770: );
1.46 raeburn 771:
1.72 raeburn 772: my (@ok_ccs,@bad_ccs,$badccmsg,$okcclist,$homeserver);
773: unless ($public) {
1.67 raeburn 774: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
775: $homeserver = &Apache::lonnet::homeserver($env{'user.name'},
776: $env{'user.domain'});
777: }
778: }
1.86 raeburn 779: my ($cid,$cdom,$cnum,$sectionlist,$ccode);
780: if ($homeserver) {
781: $cid = $env{'request.course.id'};
782: }
783: if ($cid) {
784: $cdom = $env{'course.'.$cid.'.domain'};
785: $cnum = $env{'course.'.$cid.'.num'};
786: }
787: if ($cdom && $cnum) {
788: my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
789: $ccode = $csettings{'internal.coursecode'};
790: $sectionlist = $csettings{'internal.sectionnums'};
791: }
792: if (($homeserver) && (defined($env{'form.cc'})) && ($formvars{'cc'})) {
1.46 raeburn 793: my @ccs;
794: if ($env{'form.cc'} =~ /,/) {
795: @ccs = split(/,/,$env{'form.cc'});
796: } else {
797: $env{'form.cc'} =~ s/^\s+//;
798: $env{'form.cc'} =~ s/\s+$//;
799: @ccs = $env{'form.cc'};
800: }
801: foreach my $cc (@ccs) {
802: $cc =~ s/^\s+//g;
803: $cc =~ s/\s+$//g;
804: if ($cc =~ m/^[^\@]+\@[^\@]+$/) {
805: if (!(grep(/^\Q$cc\E$/,@ok_ccs))) {
806: push(@ok_ccs,$cc);
807: }
1.57 raeburn 808: } elsif ($cc ne '') {
1.46 raeburn 809: if (!(grep(/^\Q$cc\E$/,@bad_ccs))) {
810: push(@bad_ccs,$cc);
811: }
812: }
813: }
814: if (@ok_ccs > 0) {
815: $okcclist = join(', ',@ok_ccs);
816: }
817: if (@bad_ccs == 1) {
1.71 raeburn 818: if ($bad_ccs[0] ne '') {
1.74 raeburn 819: $badccmsg .= '<br />'.&mt('The following Cc e-mail address is invalid: ').&Apache::loncommon::cleanup_html($bad_ccs[0]);
1.71 raeburn 820: }
1.46 raeburn 821: } elsif (@bad_ccs > 1) {
1.74 raeburn 822: $badccmsg .= '<br />'.&mt('The following Cc e-mail addresses are invalid: '). &Apache::loncommon::cleanup_html(join(', ',@bad_ccs));
1.46 raeburn 823: }
824: }
1.95 raeburn 825: if ($env{'request.lti.login'}) {
826: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
827: $env{'form.user'} = "'".$env{'user.name'}.':'.$env{'user.domain'}."'";
828: }
829: $sourceurl = &Apache::lonnet::absolute_url().$url;
830: } else {
831: $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'";
832: $sourceurl = $env{'form.sourceurl'};
833: }
1.86 raeburn 834: if ($formvars{'course'}) {
835: $env{'form.crsi'} = $env{'form.title'};
836: if ($coursecode ne '') {
837: $env{'form.crsi'} .= ' - '.$coursecode;
838: }
839: }
840: if ($formvars{'section'}) {
841: my $section;
842: if ($sectionlist) {
843: if ($coursecode eq $ccode) {
844: $section = $env{'form.sectionsel'}
845: } else {
846: $section = $env{'form.sectiontxt'};
847: }
848: } else {
849: $section = $env{'form.section'};
850: }
851: $env{'form.crsi'} .= ' - '.$lt{'sect'}.': '.$section;
852: }
853: my $supportmsg;
854: if ($formvars{'username'}) {
855: $supportmsg .= "$lt{'username'}: $env{'form.username'}\n";
856: }
857: $supportmsg .= "$lt{'email'}: $env{'form.email'}\n";
858: if (($homeserver) && (defined($env{'form.cc'})) && ($formvars{'cc'})) {
859: $supportmsg .= "$lt{'cc'}: $okcclist\n";
860: }
861: if ($formvars{'user'}) {
862: $supportmsg .= "$lt{'user'}: $env{'form.user'}\n";
863: }
864: if ($formvars{'phone'}) {
865: $supportmsg .= "$lt{'phone'}: $env{'form.phone'}\n";
866: }
867: if ($formvars{'course'}) {
868: $supportmsg .= "$lt{'crsi'}: $env{'form.crsi'}\n";
1.89 raeburn 869: }
1.86 raeburn 870: $supportmsg .= "$lt{'subject'}: $env{'form.subject'}
1.44 raeburn 871: $lt{'description'}: $env{'form.description'}
1.95 raeburn 872: $lt{'sourceurl'}: $sourceurl
1.40 raeburn 873: $lt{'date'}: $reporttime
1.86 raeburn 874: ";
1.1 raeburn 875:
1.44 raeburn 876: my $displaymsg;
1.46 raeburn 877: foreach my $item ('username','email','cc','user','phone','crsi','subject','description','sourceurl') {
1.44 raeburn 878: if ($env{'form.'.$item} ne '') {
879: if ($item eq 'description') {
880: my $descrip = $env{'form.description'};
1.74 raeburn 881: $descrip = &Apache::loncommon::cleanup_html($descrip);
1.54 raeburn 882: $descrip =~ s|[\n\r\f]|<br />|g;
1.44 raeburn 883: $displaymsg .=
884: '<span class="LC_helpform_receipt_cat">'.
885: "$lt{$item}</span>: $descrip<br />\n";
886: } elsif ($item eq 'sourceurl') {
887: my $showurl = $env{'form.sourceurl'};
888: $showurl =~ s/\?.*$//;
1.74 raeburn 889: $showurl = &Apache::loncommon::cleanup_html($showurl);
1.44 raeburn 890: $displaymsg .=
891: '<span class="LC_helpform_receipt_cat">'.
892: "$lt{$item}</span>: $showurl<br />\n";
1.46 raeburn 893: } elsif ($item eq 'cc') {
1.86 raeburn 894: next if ($helpform{'cc'} eq 'no');
1.71 raeburn 895: if ($okcclist) {
1.74 raeburn 896: my $showcclist = &Apache::loncommon::cleanup_html($okcclist);
1.71 raeburn 897: $displaymsg .=
898: '<span class="LC_helpform_receipt_cat">'.
899: "$lt{$item}</span>: $showcclist<br />\n";
900: }
1.44 raeburn 901: } else {
1.86 raeburn 902: if (($item eq 'username') || ($item eq 'user') || ($item eq 'phone')) {
903: next if ($helpform{$item} eq 'no');
904: }
905: next if (($item eq 'crsi') && ($helpform{'course'} eq 'no'));
1.95 raeburn 906: next if (($item eq 'user') && ($env{'request.lti.login'}));
1.54 raeburn 907: my $showitem = $env{'form.'.$item};
1.74 raeburn 908: $showitem = &Apache::loncommon::cleanup_html($showitem);
1.44 raeburn 909: $displaymsg .=
910: '<span class="LC_helpform_receipt_cat">'.
1.54 raeburn 911: "$lt{$item}</span>: $showitem<br />\n";
1.44 raeburn 912: }
913: }
914: }
1.93 raeburn 915:
916: my ($requname,$requdom,$reqemail);
917: foreach my $field ('uname','udom','email') {
918: $env{'form.'.$field} =~ s/^\s+//;
919: $env{'form.'.$field} =~ s/\s+$//;
920: }
921: if ($env{'form.uname'} =~ /^$match_username$/) {
1.94 raeburn 922: $requname = $env{'form.uname'};
1.93 raeburn 923: }
924: if ($env{'form.udom'} =~ /^$match_domain$/) {
925: $requdom = $env{'form.udom'};
926: }
927: if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
928: $reqemail = $env{'form.email'};
929: }
930:
931: my $dom_in_effect;
932: unless ($env{'user.domain'} eq 'public') {
933: $dom_in_effect = $env{'user.domain'};
934: }
935: if ($dom_in_effect eq '') {
936: $dom_in_effect = $requdom;
937: }
938: if ($dom_in_effect eq '') {
939: $dom_in_effect = $defdom;
940: }
941:
1.44 raeburn 942: $displaymsg .= '<span class="LC_helpform_receipt_cat">'.
943: $lt{'date'}.'</span>: '.$reporttime.'<br />'."\n";
1.32 albertel 944:
945: my $start_page =
946: &Apache::loncommon::start_page('Support request recorded',undef,
1.33 albertel 947: {'function' => $function,
948: 'add_entries' => {
949: topmargin => "0",
950: marginheight => "0",
951: },
952: 'only_body' => 1,});
1.32 albertel 953:
1.14 raeburn 954: $r->print(<<"END");
1.32 albertel 955: $start_page
1.73 bisitz 956: <form name="logproblem" action="">
1.44 raeburn 957: <input type="hidden" name="command" value="result" />
1.16 raeburn 958: </form>
1.1 raeburn 959: END
1.14 raeburn 960: if ($r->uri eq '/adm/helpdesk') {
961: &print_header($r,$url,'process');
962: }
1.45 raeburn 963: my $bad_email = 0;
1.93 raeburn 964: my ($to,$bcc,$addtext) =
965: &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
966: $dom_in_effect,$origmail,
967: $requname,$requdom,
968: $reqemail);
1.45 raeburn 969: if ($to =~ /,/) {
970: my @ok_email;
971: foreach my $email (split(/,/,$to)) {
972: if ($email =~ m/^[^\@]+\@[^\@]+$/) {
1.46 raeburn 973: if (!grep(/^\Q$email\E$/,@ok_email)) {
974: push(@ok_email,$email);
975: }
1.45 raeburn 976: }
977: }
978: if (@ok_email > 0) {
979: $to = join(',',@ok_email);
980: } elsif ($admin =~ m/^[^\@]+\@[^\@]+$/) {
981: $to = $admin;
982: } else {
983: $bad_email = 1;
984: }
985: } elsif ($to !~ m/^[^\@]+\@[^\@]+$/) {
986: if ($admin =~ m/^[^\@]+\@[^\@]+$/) {
987: $to = $admin;
1.9 raeburn 988: } else {
1.45 raeburn 989: $bad_email = 1;
990: }
991: }
1.66 bisitz 992:
993: my $message;
994: if (!$bad_email) {
1.106 ! raeburn 995: $message = &mt('A support request has been sent to [_1]','<tt>'.$to.'</tt>');
1.66 bisitz 996: } else {
1.106 ! raeburn 997: $message = $lt{'warn'}.'<br />';
! 998: if ($to eq '') {
! 999: $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>');
! 1000: } else {
! 1001: $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>');
! 1002: }
1.1 raeburn 1003: }
1.106 ! raeburn 1004: $r->print(&Apache::loncommon::confirmwrapper(&Apache::lonhtmlcommon::confirm_success($message,$bad_email)));
1.66 bisitz 1005:
1.93 raeburn 1006: if ($reqemail ne '') {
1007: $from = $reqemail;
1.5 raeburn 1008: }
1009:
1.46 raeburn 1010: if (defined($env{'form.cc'})) {
1011: if ($badccmsg) {
1012: $displaymsg .= $badccmsg;
1013: }
1014: }
1015:
1.25 albertel 1016: my $subject = $env{'form.subject'};
1.44 raeburn 1017: $subject =~ s/(`)/'/g;
1018: $subject =~ s/\$/\(\$\)/g;
1019: $supportmsg =~ s/(`)/'/g;
1020: $supportmsg =~ s/\$/\(\$\)/g;
1021: $displaymsg =~ s/(`)/'/g;
1022: $displaymsg =~ s/\$/\(\$\)/g;
1.5 raeburn 1023: my $fname;
1024:
1025: my $attachmentpath = '';
1.88 raeburn 1026: my $showsize = '';
1.89 raeburn 1027:
1.72 raeburn 1028: if ((defined($env{'user.name'})) && (!$public)) {
1.67 raeburn 1029: if ($homeserver && $env{'form.screenshot.filename'}) {
1.86 raeburn 1030: unless ($helpform{'screenshot'} eq 'no') {
1.88 raeburn 1031: my $attachmentsize = length($env{'form.screenshot'});
1.86 raeburn 1032: my $max = 1048576;
1.87 raeburn 1033: my $showmax = 1.00;
1.86 raeburn 1034: if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) {
1035: $max *= $helpform{'maxsize'};
1.87 raeburn 1036: $showmax = $helpform{'maxsize'};
1.86 raeburn 1037: }
1.89 raeburn 1038: $showmax = '('.sprintf("%.2f",$showmax).' MB)';
1.88 raeburn 1039: $showsize = $attachmentsize/1048576;
1040: $showsize = '('.sprintf("%.2f",$showsize).' MB)';
1.86 raeburn 1041: if ($attachmentsize > $max) {
1042: $displaymsg .= '<br /><span class="LC_warning">'.
1.87 raeburn 1043: &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 1044: } else {
1045: $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
1046: }
1.5 raeburn 1047: }
1048: }
1049: }
1050:
1.40 raeburn 1051: my %cookies;
1.27 raeburn 1052: my $cookie=CGI::Cookie->parse($r->header_in('Cookie'));
1.39 albertel 1053: if ($$cookie{'lonID'} =~ /lonID=($LONCAPA::handle_re);/) {
1.27 raeburn 1054: $cookies{'lonID'} = $1;
1055: }
1.91 raeburn 1056: if ($$cookie{'lonLinkID'} =~ /lonLinkID=([a-f0-9]+_linked);/) {
1057: $cookies{'lonLinkID'} = $1;
1058: }
1.95 raeburn 1059: my $lti_info;
1060: if (($env{'request.lti.login'}) && ($env{'request.course.id'})) {
1061: my $ltidom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1062: if ($ltidom) {
1063: my %lti = &Apache::lonnet::get_domain_lti($ltidom,'provider');
1064: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
1065: if ($lti{$env{'request.lti.login'}}{'consumer'}) {
1066: $lti_info = "LTI consumer: ".$lti{$env{'request.lti.login'}}{'consumer'}."\n";
1067: }
1068: }
1069: }
1070: }
1.5 raeburn 1071: if ($attachmentpath =~ m-/([^/]+)$-) {
1072: $fname = $1;
1.51 bisitz 1073: $displaymsg .= '<br />'
1.88 raeburn 1074: .&mt('An uploaded screenshot file [_1] was included in the request sent by [_2].'
1075: ,'<span class="LC_filename">'.$fname.'</span> '.$showsize,
1.51 bisitz 1076: ,$env{'user.name'}.':'.$env{'user.domain'}
1077: );
1.5 raeburn 1078: $supportmsg .= "\n";
1.40 raeburn 1079: foreach my $var (@cookievars) {
1080: $supportmsg .= "$var: $cookies{$var}\n";
1.27 raeburn 1081: }
1.40 raeburn 1082: foreach my $var(@ENVvars) {
1083: $supportmsg .= "$var: $ENV{$var}\n";
1.26 raeburn 1084: }
1.101 raeburn 1085: $supportmsg .= "REMOTE_ADDR: $ip\n";
1.40 raeburn 1086: foreach my $var (@envvars) {
1087: $supportmsg .= "$var: $env{$var}\n";
1.5 raeburn 1088: }
1.95 raeburn 1089: if ($lti_info) {
1090: $supportmsg .= $lti_info;
1091: }
1.5 raeburn 1092: }
1.89 raeburn 1093:
1.81 musolffc 1094: my $cc_string;
1.67 raeburn 1095: if ($homeserver) {
1096: if (@ok_ccs > 0) {
1.81 musolffc 1097: $cc_string = join(', ',@ok_ccs);
1.67 raeburn 1098: }
1.46 raeburn 1099: }
1.5 raeburn 1100:
1.90 raeburn 1101: my $attachment_text = '';
1.81 musolffc 1102: unless ($homeserver && $attachmentpath) {
1.40 raeburn 1103: foreach my $var (@cookievars) {
1.90 raeburn 1104: $attachment_text .= "$var: $cookies{$var}\n";
1.27 raeburn 1105: }
1.40 raeburn 1106: foreach my $var (@ENVvars) {
1.90 raeburn 1107: $attachment_text .= "$var: $ENV{$var}\n";
1.26 raeburn 1108: }
1.101 raeburn 1109: $attachment_text .= "REMOTE_ADDR: $ip\n";
1.40 raeburn 1110: foreach my $var (@envvars) {
1.90 raeburn 1111: $attachment_text .= "$var: $env{$var}\n";
1.5 raeburn 1112: }
1.40 raeburn 1113: foreach my $var (@loncvars) {
1.90 raeburn 1114: $attachment_text .= "$var: $env{$var}\n";
1.5 raeburn 1115: }
1.95 raeburn 1116: if ($lti_info) {
1117: $attachment_text .= $lti_info;
1118: }
1.5 raeburn 1119: }
1.86 raeburn 1120:
1121: if ($addtext) {
1122: my ($addloc,$addstr) = split(/:/,$addtext,2);
1123: $addstr = &unescape($addstr);
1124: if ($addloc eq 's') {
1125: $subject = $addstr.' '.$subject;
1126: } elsif ($addloc eq 'b') {
1127: $supportmsg = $addstr."\n".$supportmsg;
1128: }
1129: }
1130:
1.106 ! raeburn 1131: if ($bad_email) {
! 1132: $r->print('<b>'.$lt{'belo'}.'</b><br />'.
! 1133: $lt{'ifyk'}.'<br /><br />'."\n");
! 1134: } else {
! 1135: # Compose and send a MIME email
! 1136: &Apache::loncommon::mime_email($from,'',$to,$subject,$supportmsg,$cc_string,
! 1137: $bcc,$attachmentpath,$fname,$attachment_text);
! 1138: $r->print('<b>'.$lt{'your'}.'</b>:<br /><br />'."\n");
! 1139: }
1.44 raeburn 1140: if ($attachmentpath =~ m|$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+|) {
1.5 raeburn 1141: unlink($attachmentpath);
1142: }
1.55 bisitz 1143: $r->print('<div style="width:620px;">'.
1144: &Apache::lonhtmlcommon::start_pick_box().
1.44 raeburn 1145: &Apache::lonhtmlcommon::row_title($lt{'info'},undef,'LC_oddrow_value')."\n".$displaymsg."\n".
1146: &Apache::lonhtmlcommon::row_closure().
1147: &Apache::lonhtmlcommon::row_title($lt{'adin'},undef,'LC_evenrow_value'));
1148: my $envmsg;
1.40 raeburn 1149: foreach my $var (@cookievars) {
1.44 raeburn 1150: if ($cookies{$var} ne '') {
1151: $envmsg.= '<span class="LC_helpform_receipt_cat">'.
1152: $var.'</span>: '.$cookies{$var}.', ';
1.27 raeburn 1153: }
1154: }
1.40 raeburn 1155: foreach my $var (@ENVvars) {
1.44 raeburn 1156: if ($ENV{$var} ne '') {
1157: $envmsg .= '<span class="LC_helpform_receipt_cat">'.
1158: $var.'</span>: '.$ENV{$var}.', ';
1.26 raeburn 1159: }
1160: }
1.101 raeburn 1161: if ($ip ne '') {
1162: $envmsg .= '<span class="LC_helpform_receipt_cat">'.
1.102 raeburn 1163: 'REMOTE_ADDR</span>: '.$ip.', ';
1164: }
1.40 raeburn 1165: foreach my $var (@envvars) {
1.44 raeburn 1166: if ($env{$var} ne '') {
1167: $envmsg .= '<span class="LC_helpform_receipt_cat">'.
1168: $var.'</span>: '.$env{$var}.', ';
1.5 raeburn 1169: }
1.1 raeburn 1170: }
1.44 raeburn 1171: $envmsg =~ s/, $//;
1172: $r->print($envmsg."\n".
1173: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.55 bisitz 1174: &Apache::lonhtmlcommon::end_pick_box().
1175: "</div>\n".
1.44 raeburn 1176: &Apache::loncommon::end_page());
1.1 raeburn 1177: }
1178:
1.14 raeburn 1179: sub print_header {
1.44 raeburn 1180: my ($r,$origurl,$command) = @_;
1.14 raeburn 1181: my $location=&Apache::loncommon::lonhttpdurl("/adm");
1182: my ($component_url);
1183: my $helpdesk_link = '<a href="javascript:validate()">';
1.44 raeburn 1184: if ($command eq 'process') {
1.14 raeburn 1185: $helpdesk_link = '<a href="/adm/helpdesk">';
1186: }
1187: my %lt = &Apache::lonlocal::texthash (
1.67 raeburn 1188: login => 'Log-in help',
1189: ask => 'Ask helpdesk',
1190: getst => 'Getting started guide',
1.86 raeburn 1191: back => 'Back to last location',
1.47 bisitz 1192: headline => 'help/support',
1.67 raeburn 1193: stud => 'Students',
1194: ifyo => 'If your problem is still unresolved, the form below can be used to send a question to the LON-CAPA helpdesk.',
1195: cont => 'Contact your instructor instead.',
1.21 raeburn 1196: );
1.47 bisitz 1197: my ($getstartlink,$reviewtext);
1.21 raeburn 1198: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/gettingstarted.html') {
1199: $getstartlink = qq|<td align="center"> <b><a href="/adm/gettingstarted.html">$lt{'getst'}</a></td>|;
1.47 bisitz 1200: $reviewtext = &mt('Please review the information in "Log-in help" and the "Getting started" guide if you are unable to log-in.');
1201: } else {
1202: $reviewtext = &mt('Please review the information in "Log-in help" if you are unable to log-in.');
1.21 raeburn 1203: }
1.70 raeburn 1204: my $linkback;
1.59 raeburn 1205: if ($origurl eq '') {
1.70 raeburn 1206: $linkback = 'javascript:history.go(-1)';
1207: } else {
1208: $linkback = &HTML::Entities::encode($origurl,'"<>&');
1.59 raeburn 1209: }
1.68 raeburn 1210: my $loginhelp = &Apache::lonauth::loginhelpdisplay();
1211: if ($loginhelp eq '') {
1212: $loginhelp = '/adm/loginproblems.html';
1213: }
1.67 raeburn 1214: $r->print(<<"END");
1215: <table width="620" border="0" cellspacing="0" cellpadding="0" style="height: 55px;">
1216: <tr>
1217: <td width="5" height="50"> </td>
1218: <td height="50">
1.53 bisitz 1219: <fieldset>
1220: <legend>
1.67 raeburn 1221: <img src="$location/lonIcons/minilogo.gif" height="20" width="29" alt="logo" style="vertical-align:bottom" />
1.53 bisitz 1222: LON-CAPA $lt{'headline'}
1223: </legend>
1.44 raeburn 1224: <table id="LC_helpmenu_links">
1225: <tr>
1.68 raeburn 1226: <td align="center"><span class="LC_nobreak"><img src="$location/help/help.png" border="0" alt="($lt{'login'})" style="vertical-align:middle" /> <b><a href="$loginhelp">$lt{'login'}</a></b> </span></td>
1.67 raeburn 1227: <td align="center"><span class="LC_nobreak"> <b>$helpdesk_link<img src="$location/lonIcons/helpdesk.gif" border="0" alt="($lt{'ask'})" style="vertical-align:middle" /> $lt{'ask'}</a></b> </span></td>$getstartlink
1.70 raeburn 1228: <td align="center"><span class="LC_nobreak"> <b><a href="$linkback" target="_top"><img src="$location/lonIcons/move_up.gif" border="0" alt="($lt{'back'})" style="vertical-align:middle" /> $lt{'back'}</a></b> </span></td>
1.44 raeburn 1229: </tr>
1.14 raeburn 1230: </table>
1231: </fieldset>
1232: </td>
1.67 raeburn 1233: <td width="5"> </td>
1.14 raeburn 1234: </tr>
1.67 raeburn 1235: <tr>
1236: <td colspan="3" height="5"> </td>
1.14 raeburn 1237: </tr>
1238: END
1.44 raeburn 1239: if ($command ne 'process') {
1.67 raeburn 1240: my $stuwarn = &mt('Do [_1]not[_2] use this form to ask about course content.',
1241: '<b>','</b>');
1242: $r->print(<<"END");
1.14 raeburn 1243: <tr>
1.67 raeburn 1244: <td colspan="3">$reviewtext
1.76 bisitz 1245: $lt{'ifyo'}
1246: <p class="LC_info">
1247: <b>$lt{'stud'}:</b>
1248: $stuwarn $lt{'cont'}
1249: </p><br />
1.14 raeburn 1250: </td>
1.67 raeburn 1251: </tr>
1252: END
1.14 raeburn 1253: }
1254: $r->print('
1255: </table>');
1256: return;
1257: }
1258:
1.45 raeburn 1259: sub get_domain {
1260: my $codedom;
1261: if (exists($env{'form.codedom'})) {
1.70 raeburn 1262: if (&Apache::lonnet::domain($env{'form.codedom'}) ne '') {
1263: return $env{'form.codedom'};
1264: }
1265: }
1266: if ($env{'request.course.id'}) {
1.45 raeburn 1267: $codedom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1268: } elsif ($env{'request.role.domain'}) {
1269: $codedom = $env{'request.role.domain'};
1270: } else {
1.54 raeburn 1271: $codedom = &Apache::lonnet::default_login_domain();
1.45 raeburn 1272: }
1273: return $codedom;
1274: }
1275:
1.1 raeburn 1276: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>