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