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