Annotation of loncom/interface/lonsupportreq.pm, revision 1.79.2.11
1.79.2.3 raeburn 1: # The LearningOnline Network with CAPA
2: # Helpdesk request form
1.24 albertel 3: #
1.79.2.11! raeburn 4: # $Id: lonsupportreq.pm,v 1.79.2.10 2022/01/19 13:57:19 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.5 raeburn 32: use MIME::Types;
33: use MIME::Lite;
1.27 raeburn 34: use CGI::Cookie();
1.1 raeburn 35: use Apache::Constants qw(:common);
1.2 albertel 36: use Apache::loncommon();
1.43 raeburn 37: use Apache::lonhtmlcommon;
1.24 albertel 38: use Apache::lonnet;
1.1 raeburn 39: use Apache::lonlocal;
1.34 albertel 40: use Apache::lonacc();
1.68 raeburn 41: use Apache::lonauth();
1.38 raeburn 42: use Apache::courseclassifier;
1.60 raeburn 43: use LONCAPA qw(:DEFAULT :match);
1.70 raeburn 44: use HTML::Entities;
1.1 raeburn 45:
46: sub handler {
1.2 albertel 47: my ($r) = @_;
48: &Apache::loncommon::content_type($r,'text/html');
1.1 raeburn 49: $r->send_http_header;
50:
51: if ($r->header_only) {
52: return OK;
53: }
1.42 albertel 54: if ($r->uri eq '/adm/helpdesk') {
55: &Apache::lonlocal::get_language_handle($r);
56: }
57:
1.12 raeburn 58: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['origurl','function']);
59: if ($r->uri eq '/adm/helpdesk') {
1.34 albertel 60: &Apache::lonacc::get_posted_cgi($r);
1.12 raeburn 61: }
1.70 raeburn 62: my $function;
63: if ($env{'form.function'}) {
64: if (($env{'form.function'} eq 'norole') ||
65: ($env{'form.function'} eq 'student') ||
66: ($env{'form.function'} eq 'admin') ||
67: ($env{'form.function'} eq 'author')) {
68: $function = $env{'form.function'};
69: }
70: }
1.60 raeburn 71: my $origurl = $env{'form.origurl'};
1.79.2.4 raeburn 72: if ($origurl =~ m{^https?://[^/]+(.*)$}) {
1.79.2.9 raeburn 73: $origurl = $1;
1.79.2.4 raeburn 74: }
1.70 raeburn 75: $origurl =~ s/(`)//g;
76: $origurl =~ s/\$/\(\$\)/g;
1.44 raeburn 77: my $command = $env{'form.command'};
1.12 raeburn 78:
1.44 raeburn 79: if ($command eq 'process') {
1.1 raeburn 80: &print_request_receipt($r,$origurl,$function);
81: } else {
82: &print_request_form($r,$origurl,$function);
83: }
84: return OK;
85: }
1.79.2.2 raeburn 86:
1.1 raeburn 87: sub print_request_form {
88: my ($r,$origurl,$function) = @_;
1.79.2.2 raeburn 89: my ($os,$browser,$bversion,$uname,$udom,$uhome,$urole,$usec,$email,$cid,
1.61 raeburn 90: $cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server,
1.79.2.1 raeburn 91: $formname,$public,$homeserver,$knownuser,$captcha_form,$captcha_error,
1.79.2.3 raeburn 92: $captcha,$recaptcha_version,$extra_validations,%groupid);
1.44 raeburn 93: $function = &Apache::loncommon::get_users_function() if (!$function);
1.10 raeburn 94: $ccode = '';
1.25 albertel 95: $os = $env{'browser.os'};
96: $browser = $env{'browser.type'};
97: $bversion = $env{'browser.version'};
1.60 raeburn 98: if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
99: $public = 1;
100: } else {
1.67 raeburn 101: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
102: $homeserver = &Apache::lonnet::homeserver($env{'user.name'},
103: $env{'user.domain'});
104: if ($homeserver eq 'no_host') {
105: undef($homeserver);
106: } else {
107: $uname = $env{'user.name'};
108: $udom = $env{'user.domain'};
109: }
110: }
111: }
1.79.2.1 raeburn 112: if (($env{'user.name'} =~ /^$match_username$/) &&
113: ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
114: $knownuser = 1;
115: } else {
116: my $lonhost = $r->dir_config('lonHostID');
117: ($captcha_form,$captcha_error,$captcha,$recaptcha_version) =
118: &Apache::loncommon::captcha_display('login',$lonhost);
119: }
1.79.2.3 raeburn 120: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['codedom',
121: 'useremail','useraccount']);
122:
1.67 raeburn 123: if ($homeserver) {
124: $uhome = $env{'user.home'};
125: $urole = $env{'request.role'};
126: $usec = $env{'request.course.sec'};
127: $cid = $env{'request.course.id'};
1.56 raeburn 128: }
1.79.2.3 raeburn 129: if ($cid) {
130: $cdom = $env{'course.'.$cid.'.domain'};
131: $cnum = $env{'course.'.$cid.'.num'};
132: }
133: if ($cdom && $cnum) {
134: my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
135: $ctitle = $csettings{'description'};
136: $ccode = $csettings{'internal.coursecode'};
137: $sectionlist = $csettings{'internal.sectionnums'};
138: my @sections = split(/,/,$sectionlist);
139: foreach my $section (@sections) {
140: my ($sec,$grp) = split(/:/,$section);
141: $groupid{$sec} = $grp;
142: }
143: }
144:
1.29 raeburn 145: $formname = 'logproblem';
1.79.2.3 raeburn 146: my $codedom = &get_domain();
147: my %helpform;
148: my %domconfig =
149: &Apache::lonnet::get_dom('configuration',['contacts'],$codedom);
150: if (ref($domconfig{'contacts'}) eq 'HASH') {
151: if (ref($domconfig{'contacts'}{'helpform'}) eq 'HASH') {
152: %helpform = %{$domconfig{'contacts'}{'helpform'}};
153: }
154: }
155:
156: my %codes;
157: my @codetitles;
158: my %cat_titles;
159: my %cat_order;
160: my %idlist;
161: my %idnums;
162: my %idlist_titles;
163: my $totcodes = 0;
164: my $jscript = '';
165: my $loaditems = qq|
166: function initialize_codes() {
167: return;
168: }
169: |;
170: unless ($helpform{'course'} eq 'no') {
1.79.2.4 raeburn 171: my $instcats = &Apache::lonnet::get_dom_instcats($codedom);
172: if (ref($instcats) eq 'HASH') {
173: if ((ref($instcats->{'codetitles'}) eq 'ARRAY') && (ref($instcats->{'codes'}) eq 'HASH') &&
174: (ref($instcats->{'cat_titles'}) eq 'HASH') && (ref($instcats->{'cat_order'}) eq 'HASH')) {
175: %codes = %{$instcats->{'codes'}};
176: @codetitles = @{$instcats->{'codetitles'}};
177: %cat_titles = %{$instcats->{'cat_titles'}};
178: %cat_order = %{$instcats->{'cat_order'}};
179: $totcodes = scalar(keys(%codes));
180: }
181: if ($totcodes > 0) {
1.79.2.3 raeburn 182: my $numtypes = @codetitles;
183: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
184: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
185: my $longtitles_str = join('","',@{$longtitles});
186: my $allidlist = $idlist{$codetitles[0]};
187: my $knowncodes;
188: if (($ccode ne '') && ($cnum ne '')) {
189: my (%singlecodes,@singlecodetitles,%singlecat_titles,%singlecat_order);
190: my $crscode_reply = &Apache::lonnet::auto_instcode_format($cnum,$codedom,{ $cnum => $ccode },\%singlecodes,
191: \@singlecodetitles,\%singlecat_titles,\%singlecat_order);
192: if (ref($singlecodes{$cnum}) eq 'HASH') {
193: $knowncodes = $singlecodes{$cnum};
194: }
195: }
196: $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
197: $jscript .= $scripttext;
198: $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,\@codetitles,$knowncodes,$sectionlist);
199: $loaditems = '';
200: }
201: }
202: }
203: my %missing = &Apache::lonlocal::texthash(
204: username => 'You must include a name.',
205: phone => 'You must include a phone.',
206: );
207: &js_escape(\%missing);
208: if (keys(%helpform)) {
209: foreach my $key (keys(%helpform)) {
210: if (($helpform{$key} eq 'req') && ($missing{$key} ne '')) {
211: next if (($key eq 'username') && (($knownuser) ||
212: (($env{'user.name'} =~ /^$match_username$/) && (!$public))));
213: $extra_validations .= <<"END";
214:
215: if (document.$formname.$key.value == '') {
216: alert("$missing{$key}");
217: return;
218: }
219:
220: END
221: }
222: }
223: }
1.40 raeburn 224: my $machine = &Apache::lonnet::absolute_url();
1.70 raeburn 225: my $sourceurl = $machine.$origurl;
1.74 raeburn 226: $server = $machine.&Apache::loncommon::cleanup_html($origurl);
1.70 raeburn 227: $server =~ s/\?.*$//;
1.79 damieng 228: my %js_lt = &Apache::lonlocal::texthash (
1.40 raeburn 229: email => 'The e-mail address you entered',
230: notv => 'is not a valid e-mail address',
231: rsub => 'You must include a subject',
232: rdes => 'You must include a description',
1.79 damieng 233: );
234: my %html_lt = &Apache::lonlocal::texthash (
1.40 raeburn 235: name => 'Name',
236: subm => 'Submit Request',
1.46 raeburn 237: emad => 'Your e-mail address',
1.79.2.3 raeburn 238: emac => 'Cc',
1.40 raeburn 239: unme => 'username',
240: doma => 'domain',
1.44 raeburn 241: entu => 'Enter the username you use to log-in to LON-CAPA',
242: chdo => 'Choose your LON-CAPA domain',
243: entr => 'Enter the username you use to log-in to LON-CAPA, and your domain.',
1.40 raeburn 244: urlp => 'URL of page',
245: phon => 'Phone',
246: crsd => 'Course Details',
247: enin => 'Enter institutional course code',
248: pick => 'Pick',
249: enct => 'Enter course title',
250: secn => 'Section Number',
251: sele => 'Select',
252: titl => 'Title',
253: lsec => 'LON-CAPA sec',
254: subj => 'Subject',
255: detd => 'Detailed Description',
256: opfi => 'Optional file upload',
1.79.2.3 raeburn 257: uplf => 'Upload a file (e.g., a screenshot) relevant to your help request',
1.40 raeburn 258: fini => 'Finish',
259: clfm => 'Clear Form',
260: );
1.79 damieng 261: &js_escape(\%js_lt);
262: &html_escape(\%html_lt);
1.40 raeburn 263: my $scripttag = (<<"END");
1.5 raeburn 264: function validate() {
1.13 raeburn 265: if (validmail(document.logproblem.email) == false) {
1.79 damieng 266: alert("$js_lt{'email'}: "+document.logproblem.email.value+" $js_lt{'notv'}.");
1.40 raeburn 267: return;
268: }
269: if (document.logproblem.subject.value == '') {
1.79 damieng 270: alert("$js_lt{'rsub'}.");
1.40 raeburn 271: return;
272: }
273: if (document.logproblem.description.value == '') {
1.79 damieng 274: alert("$js_lt{'rdes'}.");
1.13 raeburn 275: return;
1.5 raeburn 276: }
1.79.2.3 raeburn 277: $extra_validations
1.5 raeburn 278: document.logproblem.submit();
279: }
1.13 raeburn 280:
1.40 raeburn 281: END
1.43 raeburn 282: $scripttag .= &Apache::lonhtmlcommon::javascript_valid_email();
1.44 raeburn 283:
1.67 raeburn 284: if ($homeserver) {
285: if ($env{'environment.permanentemail'}) {
286: $email = $env{'environment.permanentemail'};
287: } elsif ($env{'environment.critnotification'}) {
288: $email = $env{'environment.critnotification'};
289: } elsif ($env{'environment.notification'}) {
290: $email = $env{'environment.notification'};
291: }
292: if ($env{'environment.lastname'}) {
293: $lastname = $env{'environment.lastname'};
294: }
295: if ($env{'environment.firstname'}) {
296: $firstname = $env{'environment.firstname'};
297: }
1.1 raeburn 298: }
1.60 raeburn 299: if ($env{'form.origurl'} eq '/adm/createaccount') {
300: if ($email eq '') {
301: if ($env{'form.useremail'} =~ /^[^\@]+\@[^\@]+$/) {
302: $email = &HTML::Entities::encode($env{'form.useremail'},'"<>&');
303: }
304: }
305: if ($uname eq '') {
306: if ($env{'form.useraccount'} =~ /^$match_username$/) {
307: $uname = &HTML::Entities::encode($env{'form.useraccount'},'"<>&');
308: }
309: }
310: }
1.21 raeburn 311: my $details_title;
312: if ($codedom) {
313: $details_title = '<br />('.$codedom.')';
314: }
1.79.2.3 raeburn 315:
1.67 raeburn 316: my $js = <<"ENDJS";
317: <script type="text/javascript">
318: // <![CDATA[
319: $scripttag
320: $jscript
321: $loaditems
322: // ]]>
323: </script>
324: ENDJS
1.79.2.6 raeburn 325: if ($knownuser) {
326: $js .="\n".'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>';
327: } elsif ($recaptcha_version >=2) {
1.79.2.1 raeburn 328: $js.= "\n".'<script src="https://www.google.com/recaptcha/api.js"></script>'."\n";
329: }
1.67 raeburn 330: my %add_entries = (
331: style => "margin-top:0px;margin-bottom:0px;",
332: onload => "initialize_codes();",
333: );
1.33 albertel 334:
1.44 raeburn 335:
336: $r->print(&Apache::loncommon::start_page('Support Request',$js,
1.31 albertel 337: { 'function' => $function,
1.33 albertel 338: 'add_entries' => \%add_entries,
1.44 raeburn 339: 'only_body' => 1,}));
1.15 raeburn 340: if ($r->uri eq '/adm/helpdesk') {
1.14 raeburn 341: &print_header($r,$origurl);
342: }
1.50 raeburn 343: my @css = ('LC_evenrow_value','LC_oddrow_value');
344: my $num = 1;
345: my $i = $num%2;
1.67 raeburn 346: my $formtype;
347: if ($homeserver) {
348: $formtype = ' enctype="multipart/form-data"';
349: }
1.79.2.3 raeburn 350: my $topsubmit = ' <input type="button" value="'.$html_lt{'subm'}.'" onclick="validate()" /> ';
351: my $shownsubmit;
1.67 raeburn 352: $r->print('<form method="post" action="" name="logproblem"'.$formtype.'>'."\n");
1.44 raeburn 353: my $output = &Apache::lonhtmlcommon::start_pick_box().
1.78 bisitz 354: &Apache::lonhtmlcommon::row_headline().
355: '<span class="LC_info">'.
356: &mt('(All fields marked with * are required.)').
357: '</span>'.
1.79.2.3 raeburn 358: &Apache::lonhtmlcommon::row_closure();
359: unless ($helpform{'username'} eq 'no') {
360: my ($reqd,$namefield,$fullname);
361: if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) {
362: $fullname = "$firstname $lastname";
363: $namefield = $fullname.'<input type="hidden" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
364: } else {
365: if (defined($firstname) && $firstname ne '') {
366: $fullname = $firstname;
367: } elsif (defined($lastname) && $lastname ne '') {
368: $fullname = " $lastname";
369: }
370: $namefield = '<input type="text" size="20" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
371: if ($helpform{'username'} eq 'req') {
372: $reqd = '<span class="LC_info">*</span>';
373: }
1.1 raeburn 374: }
1.79.2.3 raeburn 375: $output .= &Apache::lonhtmlcommon::row_title($html_lt{'name'}.$reqd,undef,$css[$num])."\n".$namefield.
376: $topsubmit.
377: &Apache::lonhtmlcommon::row_closure()."\n";
378: $shownsubmit = 1;
379: $num ++;
380: $i = $num%2;
1.1 raeburn 381: }
1.78 bisitz 382: $output .= &Apache::lonhtmlcommon::row_title(
383: '<span title="'.&mt('required').'">'.
1.79 damieng 384: $html_lt{'emad'}.' <span class="LC_info">*</span></span>'
1.78 bisitz 385: ,undef,$css[$i]).
1.50 raeburn 386: '<input type="text" size="20" name="email" value="'.
1.79.2.3 raeburn 387: &HTML::Entities::encode($email,'"<>&').'" />'."\n";
388: unless ($shownsubmit) {
389: $output .= $topsubmit;
390: }
391: $output .= &Apache::lonhtmlcommon::row_closure();
1.50 raeburn 392: $num ++;
393: $i = $num%2;
1.79.2.1 raeburn 394: if ($knownuser) {
1.79.2.3 raeburn 395: if ($homeserver) {
1.79.2.10 raeburn 396: my $ip = &Apache::lonnet::get_requestor_ip($r);
397: my %setters;
398: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
399: &Apache::loncommon::blockcheck(\%setters,'com',$ip);
400: unless (($helpform{'cc'} eq 'no') || ($by_ip)) {
1.79.2.3 raeburn 401: $output .= &Apache::lonhtmlcommon::row_title($html_lt{'emac'},undef,$css[$i]).
402: '<input type="text" size="50" name="cc" value="" /><br />'."\n".
403: &Apache::lonhtmlcommon::row_closure();
404: $num ++;
405: $i = $num%2;
406: }
1.67 raeburn 407: }
1.50 raeburn 408: }
1.79.2.3 raeburn 409: unless ($helpform{'user'} eq 'no') {
410: $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'unme'}/$html_lt{'doma'}",undef,$css[$i]);
411: my $udom_input = '<input type="hidden" name="udom" value="'.
412: &HTML::Entities::encode($udom,'"<>&').'" />'."\n";
413: my $uname_input = '<input type="hidden" name="uname" value="'.
414: &HTML::Entities::encode($uname,'"<>&').'" />'."\n";
415: if ($knownuser) {
416: $output .= '<i>'.$html_lt{'unme'}.'</i>: '.$uname.' <i>'.$html_lt{'doma'}.'</i>: '.$udom.$udom_input.$uname_input;
1.44 raeburn 417: } else {
1.79.2.3 raeburn 418: my $udomform = '';
419: my $unameform = '';
420: if (($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
421: $output .= $html_lt{'entu'};
422: } elsif (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
423: $output .= $html_lt{'chdo'};
424: } else {
425: $output .= $html_lt{'entr'};
1.60 raeburn 426: }
1.79.2.3 raeburn 427: $output .= '<br />'."\n";
428: if (!$public) {
429: if ($env{'user.domain'} =~ /^$match_domain$/) {
430: $udomform = '<i>'.$html_lt{'doma'}.'</i>: '.$udom.$udom_input;
431: } elsif ($env{'user.name'} =~ /^$match_username$/) {
432: $unameform = '<i>'.$html_lt{'unme'}.'</i>: '.$uname.' '.$uname_input;
433: }
434: }
435: if ($udomform eq '') {
436: $udomform = '<i>'.$html_lt{'doma'}.'</i>: ';
437: $udomform .= &Apache::loncommon::select_dom_form($codedom,'udom')."\n";
438: }
439: if ($unameform eq '') {
440: $unameform= '<i>'.$html_lt{'unme'}.'</i>: <input type="text" size="20" name="uname" value="'.$uname.'" /> ';
441: }
442: $output .= $unameform.$udomform;
1.1 raeburn 443: }
1.79.2.3 raeburn 444: $output .= &Apache::lonhtmlcommon::row_closure();
445: $num ++;
1.1 raeburn 446: }
1.50 raeburn 447: $i = $num%2;
1.79 damieng 448: $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'urlp'}",undef,$css[$i]).
1.70 raeburn 449: $server."\n".'<input type="hidden" name="sourceurl" value="'.
450: &HTML::Entities::encode($sourceurl,'"<>&').'" />'."\n".
1.50 raeburn 451: &Apache::lonhtmlcommon::row_closure();
1.79.2.3 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: }
463: unless ($helpform{'course'} eq 'no') {
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.79.2.11! 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.79.2.3 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.79.2.3 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.79.2.3 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.79.2.3 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.79.2.3 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.79.2.3 raeburn 534: $output .= &Apache::lonhtmlcommon::row_closure();
535: $num ++;
536: $i = $num%2;
537: }
538: unless ($helpform{'section'} eq 'no') {
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.79.2.3 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";
557: } else {
558: $output .= '<input type="text" name="section" size="10" />'."\n";
1.1 raeburn 559: }
1.79.2.3 raeburn 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.79.2.1 raeburn 579: if ($knownuser) {
1.67 raeburn 580: if ($homeserver) {
1.79.2.3 raeburn 581: unless ($helpform{'screenshot'} eq 'no') {
582: my $max = 1048576;
583: my $showmax = 1.00;
584: if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) {
585: $max *= $helpform{'maxsize'};
586: $showmax = $helpform{'maxsize'};
587: }
588: $showmax = ' ('.sprintf("%.2f",$showmax).' '.&mt('MB max.').')';
1.79.2.6 raeburn 589: $output .= &Apache::lonhtmlcommon::row_title($html_lt{'opfi'},undef,$css[$i])
590: .' <input type="file" name="screenshot" class="LC_flUpload" size="20" />'
591: .'<input type="hidden" id="LC_free_space" value="'.$max.'" />'
592: .'<br />'."\n".$html_lt{'uplf'}.$showmax."\n"
593: .&Apache::lonhtmlcommon::row_closure();
1.79.2.3 raeburn 594: $num ++;
595: $i = $num%2;
596: }
1.67 raeburn 597: }
1.69 raeburn 598: } else {
1.79.2.1 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.79.2.1 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.79.2.3 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.79.2.10 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.79.2.8 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.79.2.5 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.79.2.3 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.79.2.3 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.79.2.3 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: }
713: unless ($helpform{'section'} eq 'no') {
714: $formvars{'section'} = 1;
715: }
716: unless ($helpform{'course'} eq 'no') {
717: $formvars{'course'} = 1;
718: }
1.79.2.10 raeburn 719: unless (($helpform{'cc'} eq 'no') || ($by_ip)) {
1.79.2.3 raeburn 720: $formvars{'cc'} = 1;
721: }
722: unless ($helpform{'screenshot'} eq 'no') {
723: $formvars{'screenshot'} = 1;
724: }
725: my $coursecode;
726: if ($formvars{'course'}) {
727: $coursecode = $env{'form.coursecode'};
1.57 raeburn 728: if ($coursecode eq '') {
1.79.2.3 raeburn 729: my $totcodes = 0;
1.79.2.4 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.79.2.3 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',
765: sect => 'section',
766: info => 'Information supplied',
767: adin => 'Additional information recorded',
1.40 raeburn 768: );
1.46 raeburn 769:
1.72 raeburn 770: my (@ok_ccs,@bad_ccs,$badccmsg,$okcclist,$homeserver);
771: unless ($public) {
1.67 raeburn 772: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
773: $homeserver = &Apache::lonnet::homeserver($env{'user.name'},
774: $env{'user.domain'});
775: }
776: }
1.79.2.3 raeburn 777: my ($cid,$cdom,$cnum,$sectionlist,$ccode);
778: if ($homeserver) {
779: $cid = $env{'request.course.id'};
780: }
781: if ($cid) {
782: $cdom = $env{'course.'.$cid.'.domain'};
783: $cnum = $env{'course.'.$cid.'.num'};
784: }
785: if ($cdom && $cnum) {
786: my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
787: $ccode = $csettings{'internal.coursecode'};
788: $sectionlist = $csettings{'internal.sectionnums'};
789: }
790: if (($homeserver) && (defined($env{'form.cc'})) && ($formvars{'cc'})) {
1.46 raeburn 791: my @ccs;
792: if ($env{'form.cc'} =~ /,/) {
793: @ccs = split(/,/,$env{'form.cc'});
794: } else {
795: $env{'form.cc'} =~ s/^\s+//;
796: $env{'form.cc'} =~ s/\s+$//;
797: @ccs = $env{'form.cc'};
798: }
799: foreach my $cc (@ccs) {
800: $cc =~ s/^\s+//g;
801: $cc =~ s/\s+$//g;
802: if ($cc =~ m/^[^\@]+\@[^\@]+$/) {
803: if (!(grep(/^\Q$cc\E$/,@ok_ccs))) {
804: push(@ok_ccs,$cc);
805: }
1.57 raeburn 806: } elsif ($cc ne '') {
1.46 raeburn 807: if (!(grep(/^\Q$cc\E$/,@bad_ccs))) {
808: push(@bad_ccs,$cc);
809: }
810: }
811: }
812: if (@ok_ccs > 0) {
813: $okcclist = join(', ',@ok_ccs);
814: }
815: if (@bad_ccs == 1) {
1.71 raeburn 816: if ($bad_ccs[0] ne '') {
1.74 raeburn 817: $badccmsg .= '<br />'.&mt('The following Cc e-mail address is invalid: ').&Apache::loncommon::cleanup_html($bad_ccs[0]);
1.71 raeburn 818: }
1.46 raeburn 819: } elsif (@bad_ccs > 1) {
1.74 raeburn 820: $badccmsg .= '<br />'.&mt('The following Cc e-mail addresses are invalid: '). &Apache::loncommon::cleanup_html(join(', ',@bad_ccs));
1.46 raeburn 821: }
822: }
1.44 raeburn 823: $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'";
1.79.2.3 raeburn 824: if ($formvars{'course'}) {
825: $env{'form.crsi'} = $env{'form.title'};
826: if ($coursecode ne '') {
827: $env{'form.crsi'} .= ' - '.$coursecode;
828: }
829: }
830: if ($formvars{'section'}) {
831: my $section;
832: if ($sectionlist) {
833: if ($coursecode eq $ccode) {
834: $section = $env{'form.sectionsel'}
835: } else {
836: $section = $env{'form.sectiontxt'};
837: }
838: } else {
839: $section = $env{'form.section'};
840: }
841: $env{'form.crsi'} .= ' - '.$lt{'sect'}.': '.$section;
842: }
843: my $supportmsg;
844: if ($formvars{'username'}) {
845: $supportmsg .= "$lt{'username'}: $env{'form.username'}\n";
846: }
847: $supportmsg .= "$lt{'email'}: $env{'form.email'}\n";
848: if (($homeserver) && (defined($env{'form.cc'})) && ($formvars{'cc'})) {
849: $supportmsg .= "$lt{'cc'}: $okcclist\n";
850: }
851: if ($formvars{'user'}) {
852: $supportmsg .= "$lt{'user'}: $env{'form.user'}\n";
853: }
854: if ($formvars{'phone'}) {
855: $supportmsg .= "$lt{'phone'}: $env{'form.phone'}\n";
856: }
857: if ($formvars{'course'}) {
858: $supportmsg .= "$lt{'crsi'}: $env{'form.crsi'}\n";
859: }
860: $supportmsg .= "$lt{'subject'}: $env{'form.subject'}
1.44 raeburn 861: $lt{'description'}: $env{'form.description'}
862: $lt{'sourceurl'}: $env{'form.sourceurl'}
1.40 raeburn 863: $lt{'date'}: $reporttime
1.79.2.3 raeburn 864: ";
1.1 raeburn 865:
1.44 raeburn 866: my $displaymsg;
1.46 raeburn 867: foreach my $item ('username','email','cc','user','phone','crsi','subject','description','sourceurl') {
1.44 raeburn 868: if ($env{'form.'.$item} ne '') {
869: if ($item eq 'description') {
870: my $descrip = $env{'form.description'};
1.74 raeburn 871: $descrip = &Apache::loncommon::cleanup_html($descrip);
1.54 raeburn 872: $descrip =~ s|[\n\r\f]|<br />|g;
1.44 raeburn 873: $displaymsg .=
874: '<span class="LC_helpform_receipt_cat">'.
875: "$lt{$item}</span>: $descrip<br />\n";
876: } elsif ($item eq 'sourceurl') {
877: my $showurl = $env{'form.sourceurl'};
878: $showurl =~ s/\?.*$//;
1.74 raeburn 879: $showurl = &Apache::loncommon::cleanup_html($showurl);
1.44 raeburn 880: $displaymsg .=
881: '<span class="LC_helpform_receipt_cat">'.
882: "$lt{$item}</span>: $showurl<br />\n";
1.46 raeburn 883: } elsif ($item eq 'cc') {
1.79.2.3 raeburn 884: next if ($helpform{'cc'} eq 'no');
1.71 raeburn 885: if ($okcclist) {
1.74 raeburn 886: my $showcclist = &Apache::loncommon::cleanup_html($okcclist);
1.71 raeburn 887: $displaymsg .=
888: '<span class="LC_helpform_receipt_cat">'.
889: "$lt{$item}</span>: $showcclist<br />\n";
890: }
1.44 raeburn 891: } else {
1.79.2.3 raeburn 892: if (($item eq 'username') || ($item eq 'user') || ($item eq 'phone')) {
893: next if ($helpform{$item} eq 'no');
894: }
895: next if (($item eq 'crsi') && ($helpform{'course'} eq 'no'));
1.54 raeburn 896: my $showitem = $env{'form.'.$item};
1.74 raeburn 897: $showitem = &Apache::loncommon::cleanup_html($showitem);
1.44 raeburn 898: $displaymsg .=
899: '<span class="LC_helpform_receipt_cat">'.
1.54 raeburn 900: "$lt{$item}</span>: $showitem<br />\n";
1.44 raeburn 901: }
902: }
903: }
1.79.2.7 raeburn 904:
905: my ($requname,$requdom,$reqemail);
906: foreach my $field ('uname','udom','email') {
907: $env{'form.'.$field} =~ s/^\s+//;
908: $env{'form.'.$field} =~ s/\s+$//;
909: }
910: if ($env{'form.uname'} =~ /^$match_username$/) {
911: $requname = $env{'form.uname'};
912: }
913: if ($env{'form.udom'} =~ /^$match_domain$/) {
914: $requdom = $env{'form.udom'};
915: }
916: if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
917: $reqemail = $env{'form.email'};
918: }
919:
920: my $dom_in_effect;
921: unless ($env{'user.domain'} eq 'public') {
922: $dom_in_effect = $env{'user.domain'};
923: }
924: if ($dom_in_effect eq '') {
925: $dom_in_effect = $requdom;
926: }
927: if ($dom_in_effect eq '') {
928: $dom_in_effect = $defdom;
929: }
930:
1.44 raeburn 931: $displaymsg .= '<span class="LC_helpform_receipt_cat">'.
932: $lt{'date'}.'</span>: '.$reporttime.'<br />'."\n";
1.32 albertel 933:
934: my $start_page =
935: &Apache::loncommon::start_page('Support request recorded',undef,
1.33 albertel 936: {'function' => $function,
937: 'add_entries' => {
938: topmargin => "0",
939: marginheight => "0",
940: },
941: 'only_body' => 1,});
1.32 albertel 942:
1.14 raeburn 943: $r->print(<<"END");
1.32 albertel 944: $start_page
1.73 bisitz 945: <form name="logproblem" action="">
1.44 raeburn 946: <input type="hidden" name="command" value="result" />
1.16 raeburn 947: </form>
1.1 raeburn 948: END
1.14 raeburn 949: if ($r->uri eq '/adm/helpdesk') {
950: &print_header($r,$url,'process');
951: }
1.45 raeburn 952: my $bad_email = 0;
1.79.2.7 raeburn 953: my ($to,$bcc,$addtext) =
954: &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
955: $dom_in_effect,$origmail,
956: $requname,$requdom,
957: $reqemail);
1.45 raeburn 958: if ($to =~ /,/) {
959: my @ok_email;
960: foreach my $email (split(/,/,$to)) {
961: if ($email =~ m/^[^\@]+\@[^\@]+$/) {
1.46 raeburn 962: if (!grep(/^\Q$email\E$/,@ok_email)) {
963: push(@ok_email,$email);
964: }
1.45 raeburn 965: }
966: }
967: if (@ok_email > 0) {
968: $to = join(',',@ok_email);
969: } elsif ($admin =~ m/^[^\@]+\@[^\@]+$/) {
970: $to = $admin;
971: } else {
972: $bad_email = 1;
973: }
974: } elsif ($to !~ m/^[^\@]+\@[^\@]+$/) {
975: if ($admin =~ m/^[^\@]+\@[^\@]+$/) {
976: $to = $admin;
1.9 raeburn 977: } else {
1.45 raeburn 978: $bad_email = 1;
979: }
980: }
1.66 bisitz 981:
982: my $message;
983: if (!$bad_email) {
984: $message = &Apache::lonhtmlcommon::confirm_success(
985: &mt('A support request has been sent to [_1]','<tt>'.$to.'</tt>'));
986: } else {
987: $message = &Apache::lonhtmlcommon::confirm_success(
988: $lt{'warn'}.'<br />'
989: .&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>')
990: .' '.&mt('Instead a copy has been sent to the LON-CAPA support team at Michigan State University.'),1);
991: $to = 'helpdesk@lon-capa.org';
1.1 raeburn 992: }
1.66 bisitz 993: $r->print(&Apache::loncommon::confirmwrapper($message));
994:
1.79.2.7 raeburn 995: if ($reqemail ne '') {
996: $from = $reqemail;
1.5 raeburn 997: }
998:
1.46 raeburn 999: if (defined($env{'form.cc'})) {
1000: if ($badccmsg) {
1001: $displaymsg .= $badccmsg;
1002: }
1003: }
1004:
1.25 albertel 1005: my $subject = $env{'form.subject'};
1.44 raeburn 1006: $subject =~ s/(`)/'/g;
1007: $subject =~ s/\$/\(\$\)/g;
1008: $supportmsg =~ s/(`)/'/g;
1009: $supportmsg =~ s/\$/\(\$\)/g;
1010: $displaymsg =~ s/(`)/'/g;
1011: $displaymsg =~ s/\$/\(\$\)/g;
1.5 raeburn 1012: my $fname;
1013:
1014: my $attachmentpath = '';
1.79.2.3 raeburn 1015: my $showsize = '';
1016:
1.72 raeburn 1017: if ((defined($env{'user.name'})) && (!$public)) {
1.67 raeburn 1018: if ($homeserver && $env{'form.screenshot.filename'}) {
1.79.2.3 raeburn 1019: unless ($helpform{'screenshot'} eq 'no') {
1020: my $attachmentsize = length($env{'form.screenshot'});
1021: my $max = 1048576;
1022: my $showmax = 1.00;
1023: if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) {
1024: $max *= $helpform{'maxsize'};
1025: $showmax = $helpform{'maxsize'};
1026: }
1027: $showmax = '('.sprintf("%.2f",$showmax).' MB)';
1028: $showsize = $attachmentsize/1048576;
1029: $showsize = '('.sprintf("%.2f",$showsize).' MB)';
1030: if ($attachmentsize > $max) {
1031: $displaymsg .= '<br /><span class="LC_warning">'.
1032: &mt('The uploaded screenshot file [_1] included with your request exceeded the maximum allowed size [_2], and has therefore been discarded.',$showsize,$showmax).'</span>';
1033: } else {
1034: $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
1035: }
1.5 raeburn 1036: }
1037: }
1038: }
1039:
1.40 raeburn 1040: my %cookies;
1.27 raeburn 1041: my $cookie=CGI::Cookie->parse($r->header_in('Cookie'));
1.39 albertel 1042: if ($$cookie{'lonID'} =~ /lonID=($LONCAPA::handle_re);/) {
1.27 raeburn 1043: $cookies{'lonID'} = $1;
1044: }
1.79.2.5 raeburn 1045: if ($$cookie{'lonLinkID'} =~ /lonLinkID=([a-f0-9]+_linked);/) {
1046: $cookies{'lonLinkID'} = $1;
1047: }
1.5 raeburn 1048: if ($attachmentpath =~ m-/([^/]+)$-) {
1049: $fname = $1;
1.51 bisitz 1050: $displaymsg .= '<br />'
1.79.2.3 raeburn 1051: .&mt('An uploaded screenshot file [_1] was included in the request sent by [_2].'
1052: ,'<span class="LC_filename">'.$fname.'</span> '.$showsize,
1.51 bisitz 1053: ,$env{'user.name'}.':'.$env{'user.domain'}
1054: );
1.5 raeburn 1055: $supportmsg .= "\n";
1.40 raeburn 1056: foreach my $var (@cookievars) {
1057: $supportmsg .= "$var: $cookies{$var}\n";
1.27 raeburn 1058: }
1.40 raeburn 1059: foreach my $var(@ENVvars) {
1060: $supportmsg .= "$var: $ENV{$var}\n";
1.26 raeburn 1061: }
1.79.2.8 raeburn 1062: $supportmsg .= "REMOTE_ADDR: $ip\n";
1.40 raeburn 1063: foreach my $var (@envvars) {
1064: $supportmsg .= "$var: $env{$var}\n";
1.5 raeburn 1065: }
1066: }
1.79.2.3 raeburn 1067:
1068: my $cc_string;
1069: if ($homeserver) {
1070: if (@ok_ccs > 0) {
1071: $cc_string = join(', ',@ok_ccs);
1072: }
1073: }
1074:
1075: my $attachment_text = '';
1076: unless ($homeserver && $attachmentpath) {
1077: foreach my $var (@cookievars) {
1078: $attachment_text .= "$var: $cookies{$var}\n";
1079: }
1080: foreach my $var (@ENVvars) {
1081: $attachment_text .= "$var: $ENV{$var}\n";
1082: }
1.79.2.8 raeburn 1083: $attachment_text .= "REMOTE_ADDR: $ip\n";
1.79.2.3 raeburn 1084: foreach my $var (@envvars) {
1085: $attachment_text .= "$var: $env{$var}\n";
1086: }
1087: foreach my $var (@loncvars) {
1088: $attachment_text .= "$var: $env{$var}\n";
1089: }
1090: }
1091:
1092: if ($addtext) {
1093: my ($addloc,$addstr) = split(/:/,$addtext,2);
1094: $addstr = &unescape($addstr);
1095: if ($addloc eq 's') {
1096: $subject = $addstr.' '.$subject;
1097: } elsif ($addloc eq 'b') {
1098: $supportmsg = $addstr."\n".$supportmsg;
1099: }
1100: }
1101:
1.5 raeburn 1102: my $msg = MIME::Lite->new(
1103: From => $from,
1104: To => $to,
1105: Subject => $subject,
1106: Type =>'TEXT',
1107: Data => $supportmsg,
1108: );
1.67 raeburn 1109: if ($homeserver) {
1110: if (@ok_ccs > 0) {
1111: my $cc_string = join(', ',@ok_ccs);
1112: $msg->add("Cc" => $cc_string);
1113: }
1.46 raeburn 1114: }
1.56 raeburn 1115: if ($bcc ne '') {
1116: $msg->add("Bcc" => $bcc);
1117: }
1.65 raeburn 1118: $msg->attr("content-type" => "text/plain");
1119: $msg->attr("content-type.charset" => "UTF-8");
1.5 raeburn 1120:
1.67 raeburn 1121: if ($homeserver && $attachmentpath) {
1.5 raeburn 1122: my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath);
1123: $msg->attach(Type => $type,
1124: Path => $attachmentpath,
1125: Filename => $fname
1126: );
1127:
1.79.2.3 raeburn 1128: } elsif ($attachment_text ne '') {
1.5 raeburn 1129: $msg->attach(Type => 'TEXT',
1.79.2.3 raeburn 1130: Data => $attachment_text);
1.5 raeburn 1131: }
1132:
1133: ### Send it:
1134: $msg->send('sendmail');
1135:
1.44 raeburn 1136: if ($attachmentpath =~ m|$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+|) {
1.5 raeburn 1137: unlink($attachmentpath);
1138: }
1.44 raeburn 1139: $r->print('<b>'.$lt{'your'}.'</b>:<br /><br />'."\n");
1.55 bisitz 1140: $r->print('<div style="width:620px;">'.
1141: &Apache::lonhtmlcommon::start_pick_box().
1.44 raeburn 1142: &Apache::lonhtmlcommon::row_title($lt{'info'},undef,'LC_oddrow_value')."\n".$displaymsg."\n".
1143: &Apache::lonhtmlcommon::row_closure().
1144: &Apache::lonhtmlcommon::row_title($lt{'adin'},undef,'LC_evenrow_value'));
1145: my $envmsg;
1.40 raeburn 1146: foreach my $var (@cookievars) {
1.44 raeburn 1147: if ($cookies{$var} ne '') {
1148: $envmsg.= '<span class="LC_helpform_receipt_cat">'.
1149: $var.'</span>: '.$cookies{$var}.', ';
1.27 raeburn 1150: }
1151: }
1.40 raeburn 1152: foreach my $var (@ENVvars) {
1.44 raeburn 1153: if ($ENV{$var} ne '') {
1154: $envmsg .= '<span class="LC_helpform_receipt_cat">'.
1155: $var.'</span>: '.$ENV{$var}.', ';
1.26 raeburn 1156: }
1157: }
1.79.2.8 raeburn 1158: if ($ip ne '') {
1159: $envmsg .= '<span class="LC_helpform_receipt_cat">'.
1160: 'REMOTE_ADDR</span>: '.$ip.', ';
1161: }
1.40 raeburn 1162: foreach my $var (@envvars) {
1.44 raeburn 1163: if ($env{$var} ne '') {
1164: $envmsg .= '<span class="LC_helpform_receipt_cat">'.
1165: $var.'</span>: '.$env{$var}.', ';
1.5 raeburn 1166: }
1.1 raeburn 1167: }
1.44 raeburn 1168: $envmsg =~ s/, $//;
1169: $r->print($envmsg."\n".
1170: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.55 bisitz 1171: &Apache::lonhtmlcommon::end_pick_box().
1172: "</div>\n".
1.44 raeburn 1173: &Apache::loncommon::end_page());
1.1 raeburn 1174: }
1175:
1.14 raeburn 1176: sub print_header {
1.44 raeburn 1177: my ($r,$origurl,$command) = @_;
1.14 raeburn 1178: my $location=&Apache::loncommon::lonhttpdurl("/adm");
1179: my ($component_url);
1180: my $helpdesk_link = '<a href="javascript:validate()">';
1.44 raeburn 1181: if ($command eq 'process') {
1.14 raeburn 1182: $helpdesk_link = '<a href="/adm/helpdesk">';
1183: }
1184: my %lt = &Apache::lonlocal::texthash (
1.67 raeburn 1185: login => 'Log-in help',
1186: ask => 'Ask helpdesk',
1187: getst => 'Getting started guide',
1.79.2.3 raeburn 1188: back => 'Back to last location',
1.47 bisitz 1189: headline => 'help/support',
1.67 raeburn 1190: stud => 'Students',
1191: ifyo => 'If your problem is still unresolved, the form below can be used to send a question to the LON-CAPA helpdesk.',
1192: cont => 'Contact your instructor instead.',
1.21 raeburn 1193: );
1.47 bisitz 1194: my ($getstartlink,$reviewtext);
1.21 raeburn 1195: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/gettingstarted.html') {
1196: $getstartlink = qq|<td align="center"> <b><a href="/adm/gettingstarted.html">$lt{'getst'}</a></td>|;
1.47 bisitz 1197: $reviewtext = &mt('Please review the information in "Log-in help" and the "Getting started" guide if you are unable to log-in.');
1198: } else {
1199: $reviewtext = &mt('Please review the information in "Log-in help" if you are unable to log-in.');
1.21 raeburn 1200: }
1.70 raeburn 1201: my $linkback;
1.59 raeburn 1202: if ($origurl eq '') {
1.70 raeburn 1203: $linkback = 'javascript:history.go(-1)';
1204: } else {
1205: $linkback = &HTML::Entities::encode($origurl,'"<>&');
1.59 raeburn 1206: }
1.68 raeburn 1207: my $loginhelp = &Apache::lonauth::loginhelpdisplay();
1208: if ($loginhelp eq '') {
1209: $loginhelp = '/adm/loginproblems.html';
1210: }
1.67 raeburn 1211: $r->print(<<"END");
1212: <table width="620" border="0" cellspacing="0" cellpadding="0" style="height: 55px;">
1213: <tr>
1214: <td width="5" height="50"> </td>
1215: <td height="50">
1.53 bisitz 1216: <fieldset>
1217: <legend>
1.67 raeburn 1218: <img src="$location/lonIcons/minilogo.gif" height="20" width="29" alt="logo" style="vertical-align:bottom" />
1.53 bisitz 1219: LON-CAPA $lt{'headline'}
1220: </legend>
1.44 raeburn 1221: <table id="LC_helpmenu_links">
1222: <tr>
1.68 raeburn 1223: <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 1224: <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 1225: <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 1226: </tr>
1.14 raeburn 1227: </table>
1228: </fieldset>
1229: </td>
1.67 raeburn 1230: <td width="5"> </td>
1.14 raeburn 1231: </tr>
1.67 raeburn 1232: <tr>
1233: <td colspan="3" height="5"> </td>
1.14 raeburn 1234: </tr>
1235: END
1.44 raeburn 1236: if ($command ne 'process') {
1.67 raeburn 1237: my $stuwarn = &mt('Do [_1]not[_2] use this form to ask about course content.',
1238: '<b>','</b>');
1239: $r->print(<<"END");
1.14 raeburn 1240: <tr>
1.67 raeburn 1241: <td colspan="3">$reviewtext
1.76 bisitz 1242: $lt{'ifyo'}
1243: <p class="LC_info">
1244: <b>$lt{'stud'}:</b>
1245: $stuwarn $lt{'cont'}
1246: </p><br />
1.14 raeburn 1247: </td>
1.67 raeburn 1248: </tr>
1249: END
1.14 raeburn 1250: }
1251: $r->print('
1252: </table>');
1253: return;
1254: }
1255:
1.45 raeburn 1256: sub get_domain {
1257: my $codedom;
1258: if (exists($env{'form.codedom'})) {
1.70 raeburn 1259: if (&Apache::lonnet::domain($env{'form.codedom'}) ne '') {
1260: return $env{'form.codedom'};
1261: }
1262: }
1263: if ($env{'request.course.id'}) {
1.45 raeburn 1264: $codedom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1265: } elsif ($env{'request.role.domain'}) {
1266: $codedom = $env{'request.role.domain'};
1267: } else {
1.54 raeburn 1268: $codedom = &Apache::lonnet::default_login_domain();
1.45 raeburn 1269: }
1270: return $codedom;
1271: }
1272:
1.1 raeburn 1273: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>