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