1: #
2: # $Id: lonsupportreq.pm,v 1.79.2.2 2017/01/23 01:56:26 raeburn Exp $
3: #
4: # Copyright Michigan State University Board of Trustees
5: #
6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
7: #
8: # LON-CAPA is free software; you can redistribute it and/or modify
9: # it under the terms of the GNU General Public License as published by
10: # the Free Software Foundation; either version 2 of the License, or
11: # (at your option) any later version.
12: #
13: # LON-CAPA is distributed in the hope that it will be useful,
14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: # GNU General Public License for more details.
17: #
18: # You should have received a copy of the GNU General Public License
19: # along with LON-CAPA; if not, write to the Free Software
20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21: #
22: # /home/httpd/html/adm/gpl.txt
23: #
24: # http://www.lon-capa.org/
25: #
26:
27: package Apache::lonsupportreq;
28:
29: use strict;
30: use MIME::Types;
31: use MIME::Lite;
32: use CGI::Cookie();
33: use Apache::Constants qw(:common);
34: use Apache::loncommon();
35: use Apache::lonhtmlcommon;
36: use Apache::lonnet;
37: use Apache::lonlocal;
38: use Apache::lonacc();
39: use Apache::lonauth();
40: use Apache::courseclassifier;
41: use LONCAPA qw(:DEFAULT :match);
42: use HTML::Entities;
43:
44: sub handler {
45: my ($r) = @_;
46: &Apache::loncommon::content_type($r,'text/html');
47: $r->send_http_header;
48:
49: if ($r->header_only) {
50: return OK;
51: }
52: if ($r->uri eq '/adm/helpdesk') {
53: &Apache::lonlocal::get_language_handle($r);
54: }
55:
56: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['origurl','function']);
57: if ($r->uri eq '/adm/helpdesk') {
58: &Apache::lonacc::get_posted_cgi($r);
59: }
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: }
69: my $origurl = $env{'form.origurl'};
70: $origurl =~ s{^https?://}{};
71: $origurl =~ s/(`)//g;
72: $origurl =~ s/\$/\(\$\)/g;
73: my $command = $env{'form.command'};
74:
75: if ($command eq 'process') {
76: &print_request_receipt($r,$origurl,$function);
77: } else {
78: &print_request_form($r,$origurl,$function);
79: }
80: return OK;
81: }
82:
83: sub print_request_form {
84: my ($r,$origurl,$function) = @_;
85: my ($os,$browser,$bversion,$uname,$udom,$uhome,$urole,$usec,$email,$cid,
86: $cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server,
87: $formname,$public,$homeserver,$knownuser,$captcha_form,$captcha_error,
88: $captcha,$recaptcha_version);
89: $function = &Apache::loncommon::get_users_function() if (!$function);
90: $ccode = '';
91: $os = $env{'browser.os'};
92: $browser = $env{'browser.type'};
93: $bversion = $env{'browser.version'};
94: if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
95: $public = 1;
96: } else {
97: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
98: $homeserver = &Apache::lonnet::homeserver($env{'user.name'},
99: $env{'user.domain'});
100: if ($homeserver eq 'no_host') {
101: undef($homeserver);
102: } else {
103: $uname = $env{'user.name'};
104: $udom = $env{'user.domain'};
105: }
106: }
107: }
108: if (($env{'user.name'} =~ /^$match_username$/) &&
109: ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
110: $knownuser = 1;
111: } else {
112: my $lonhost = $r->dir_config('lonHostID');
113: ($captcha_form,$captcha_error,$captcha,$recaptcha_version) =
114: &Apache::loncommon::captcha_display('login',$lonhost);
115: }
116: if ($homeserver) {
117: $uhome = $env{'user.home'};
118: $urole = $env{'request.role'};
119: $usec = $env{'request.course.sec'};
120: $cid = $env{'request.course.id'};
121: }
122: $formname = 'logproblem';
123: my $machine = &Apache::lonnet::absolute_url();
124: my $sourceurl = $machine.$origurl;
125: $server = $machine.&Apache::loncommon::cleanup_html($origurl);
126: $server =~ s/\?.*$//;
127: my %js_lt = &Apache::lonlocal::texthash (
128: email => 'The e-mail address you entered',
129: notv => 'is not a valid e-mail address',
130: rsub => 'You must include a subject',
131: rdes => 'You must include a description',
132: );
133: my %html_lt = &Apache::lonlocal::texthash (
134: name => 'Name',
135: subm => 'Submit Request',
136: emad => 'Your e-mail address',
137: emac => 'Cc',
138: unme => 'username',
139: doma => 'domain',
140: entu => 'Enter the username you use to log-in to LON-CAPA',
141: chdo => 'Choose your LON-CAPA domain',
142: entr => 'Enter the username you use to log-in to LON-CAPA, and your domain.',
143: urlp => 'URL of page',
144: phon => 'Phone',
145: crsd => 'Course Details',
146: enin => 'Enter institutional course code',
147: pick => 'Pick',
148: enct => 'Enter course title',
149: secn => 'Section Number',
150: sele => 'Select',
151: titl => 'Title',
152: lsec => 'LON-CAPA sec',
153: subj => 'Subject',
154: detd => 'Detailed Description',
155: opfi => 'Optional file upload',
156: uplf => 'Upload a file (e.g., a screenshot) relevant to your help request (128 KB max.)',
157: fini => 'Finish',
158: clfm => 'Clear Form',
159: );
160: &js_escape(\%js_lt);
161: &html_escape(\%html_lt);
162: my $scripttag = (<<"END");
163: function validate() {
164: if (validmail(document.logproblem.email) == false) {
165: alert("$js_lt{'email'}: "+document.logproblem.email.value+" $js_lt{'notv'}.");
166: return;
167: }
168: if (document.logproblem.subject.value == '') {
169: alert("$js_lt{'rsub'}.");
170: return;
171: }
172: if (document.logproblem.description.value == '') {
173: alert("$js_lt{'rdes'}.");
174: return;
175: }
176: document.logproblem.submit();
177: }
178:
179: END
180: $scripttag .= &Apache::lonhtmlcommon::javascript_valid_email();
181: if ($cid) {
182: $cdom = $env{'course.'.$cid.'.domain'};
183: $cnum = $env{'course.'.$cid.'.num'};
184: }
185: if ($cdom && $cnum) {
186: my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
187: $ctitle = $csettings{'description'};
188: $ccode = $csettings{'internal.coursecode'};
189: $sectionlist = $csettings{'internal.sectionnums'};
190: }
191:
192: if ($homeserver) {
193: if ($env{'environment.permanentemail'}) {
194: $email = $env{'environment.permanentemail'};
195: } elsif ($env{'environment.critnotification'}) {
196: $email = $env{'environment.critnotification'};
197: } elsif ($env{'environment.notification'}) {
198: $email = $env{'environment.notification'};
199: }
200: if ($env{'environment.lastname'}) {
201: $lastname = $env{'environment.lastname'};
202: }
203: if ($env{'environment.firstname'}) {
204: $firstname = $env{'environment.firstname'};
205: }
206: }
207: my @sections = split(/,/,$sectionlist);
208: my %groupid;
209: foreach my $section (@sections) {
210: my ($sec,$grp) = split(/:/,$section);
211: $groupid{$sec} = $grp;
212: }
213: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['codedom',
214: 'useremail','useraccount']);
215: if ($env{'form.origurl'} eq '/adm/createaccount') {
216: if ($email eq '') {
217: if ($env{'form.useremail'} =~ /^[^\@]+\@[^\@]+$/) {
218: $email = &HTML::Entities::encode($env{'form.useremail'},'"<>&');
219: }
220: }
221: if ($uname eq '') {
222: if ($env{'form.useraccount'} =~ /^$match_username$/) {
223: $uname = &HTML::Entities::encode($env{'form.useraccount'},'"<>&');
224: }
225: }
226: }
227: my $codedom = &get_domain();
228: my $details_title;
229: if ($codedom) {
230: $details_title = '<br />('.$codedom.')';
231: }
232: my %coursecodes;
233: my %codes;
234: my @codetitles;
235: my %cat_titles;
236: my %cat_order;
237: my %idlist;
238: my %idnums;
239: my %idlist_titles;
240: my $caller = 'global';
241: my $totcodes = 0;
242: my $format_reply;
243: my $jscript = '';
244: my $loaditems = qq|
245: function initialize_codes() {
246: return;
247: }
248: |;
249: if ($cnum) {
250: $coursecodes{$cnum} = $ccode;
251: if ($ccode eq '') {
252: $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
253: } else {
254: $coursecodes{$cnum} = $ccode;
255: $caller = $cnum;
256: $totcodes ++;
257: }
258: } else {
259: $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
260: }
261: if ($totcodes > 0) {
262: if ($ccode eq '') {
263: $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
264: if ($format_reply eq 'ok') {
265: my $numtypes = @codetitles;
266: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
267: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
268: my $longtitles_str = join('","',@{$longtitles});
269: my $allidlist = $idlist{$codetitles[0]};
270: $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
271: $jscript .= $scripttext;
272: $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,\@codetitles);
273: $loaditems = '';
274: }
275: }
276: }
277:
278: my $js = <<"ENDJS";
279: <script type="text/javascript">
280: // <![CDATA[
281: $scripttag
282: $jscript
283: $loaditems
284: // ]]>
285: </script>
286: ENDJS
287: if ($recaptcha_version >=2) {
288: $js.= "\n".'<script src="https://www.google.com/recaptcha/api.js"></script>'."\n";
289: }
290: my %add_entries = (
291: style => "margin-top:0px;margin-bottom:0px;",
292: onload => "initialize_codes();",
293: );
294:
295:
296: $r->print(&Apache::loncommon::start_page('Support Request',$js,
297: { 'function' => $function,
298: 'add_entries' => \%add_entries,
299: 'only_body' => 1,}));
300: if ($r->uri eq '/adm/helpdesk') {
301: &print_header($r,$origurl);
302: }
303: my @css = ('LC_evenrow_value','LC_oddrow_value');
304: my $num = 1;
305: my $i = $num%2;
306: my $formtype;
307: if ($homeserver) {
308: $formtype = ' enctype="multipart/form-data"';
309: }
310: $r->print('<form method="post" action="" name="logproblem"'.$formtype.'>'."\n");
311: my $output = &Apache::lonhtmlcommon::start_pick_box().
312: &Apache::lonhtmlcommon::row_headline().
313: '<span class="LC_info">'.
314: &mt('(All fields marked with * are required.)').
315: '</span>'.
316: &Apache::lonhtmlcommon::row_closure().
317: &Apache::lonhtmlcommon::row_title($html_lt{'name'},undef,$css[$num])."\n";
318: my $fullname = '';
319: if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) {
320: $fullname = "$firstname $lastname";
321: $output .= $fullname.'<input type="hidden" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
322: } else {
323: if (defined($firstname) && $firstname ne '') {
324: $fullname = $firstname;
325: } elsif (defined($lastname) && $lastname ne '') {
326: $fullname = " $lastname";
327: }
328: $output .= '<input type="text" size="20" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
329: }
330: $output .= ' <input type="button" value="'.$html_lt{'subm'}.'" onclick="validate()" /> '.
331: &Apache::lonhtmlcommon::row_closure()."\n";
332: $num ++;
333: $i = $num%2;
334: $output .= &Apache::lonhtmlcommon::row_title(
335: '<span title="'.&mt('required').'">'.
336: $html_lt{'emad'}.' <span class="LC_info">*</span></span>'
337: ,undef,$css[$i]).
338: '<input type="text" size="20" name="email" value="'.
339: &HTML::Entities::encode($email,'"<>&').'" /><br />'."\n".
340: &Apache::lonhtmlcommon::row_closure();
341: $num ++;
342: $i = $num%2;
343: if ($knownuser) {
344: if ($homeserver) {
345: $output .= &Apache::lonhtmlcommon::row_title($html_lt{'emac'},undef,$css[$i]).
346: '<input type="text" size="50" name="cc" value="" /><br />'."\n".
347: &Apache::lonhtmlcommon::row_closure();
348: $num ++;
349: $i = $num%2;
350: }
351: }
352: $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'unme'}/$html_lt{'doma'}",undef,$css[$i]);
353: my $udom_input = '<input type="hidden" name="udom" value="'.
354: &HTML::Entities::encode($udom,'"<>&').'" />'."\n";
355: my $uname_input = '<input type="hidden" name="uname" value="'.
356: &HTML::Entities::encode($uname,'"<>&').'" />'."\n";
357: if ($knownuser) {
358: $output .= '<i>'.$html_lt{'unme'}.'</i>: '.$uname.' <i>'.$html_lt{'doma'}.'</i>: '.$udom.$udom_input.$uname_input;
359: } else {
360: my $udomform = '';
361: my $unameform = '';
362: if (($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
363: $output .= $html_lt{'entu'};
364: } elsif (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
365: $output .= $html_lt{'chdo'};
366: } else {
367: $output .= $html_lt{'entr'};
368: }
369: $output .= '<br />'."\n";
370: if (!$public) {
371: if ($env{'user.domain'} =~ /^$match_domain$/) {
372: $udomform = '<i>'.$html_lt{'doma'}.'</i>: '.$udom.$udom_input;
373: } elsif ($env{'user.name'} =~ /^$match_username$/) {
374: $unameform = '<i>'.$html_lt{'unme'}.'</i>: '.$uname.' '.$uname_input;
375: }
376: }
377: if ($udomform eq '') {
378: $udomform = '<i>'.$html_lt{'doma'}.'</i>: ';
379: $udomform .= &Apache::loncommon::select_dom_form($codedom,'udom')."\n";
380: }
381: if ($unameform eq '') {
382: $unameform= '<i>'.$html_lt{'unme'}.'</i>: <input type="text" size="20" name="uname" value="'.$uname.'" /> ';
383: }
384: $output .= $unameform.$udomform;
385: }
386: $output .= &Apache::lonhtmlcommon::row_closure();
387: $num ++;
388: $i = $num%2;
389: $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'urlp'}",undef,$css[$i]).
390: $server."\n".'<input type="hidden" name="sourceurl" value="'.
391: &HTML::Entities::encode($sourceurl,'"<>&').'" />'."\n".
392: &Apache::lonhtmlcommon::row_closure().
393: &Apache::lonhtmlcommon::row_title("$html_lt{'phon'}",undef,'LC_evenrow_value').
394: '<input type="text" size="15" name="phone" /><br />'."\n".
395: &Apache::lonhtmlcommon::row_closure();
396: $num ++;
397: $i = $num%2;
398: $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'crsd'}$details_title",undef,$css[$i]);
399: if ($cnum) {
400: if ($coursecodes{$cnum}) {
401: foreach my $item (@codetitles) {
402: $output .= '<i>'.$item.'</i>: '.$codes{$cnum}{$item}.'; ';
403: }
404: $output .= ' <input type="hidden" name="coursecode" value="'.&HTML::Entities::encode($coursecodes{$cnum},'"<>&').'" />'."\n";
405: } else {
406: $output .= $html_lt{'enin'}.':
407: <input type="text" name="coursecode" size="15" value="" />'."\n";
408: }
409: } else {
410: if ($totcodes > 0) {
411: my $numtitles = @codetitles;
412: if ($numtitles == 0) {
413: $output .= $html_lt{'enin'}.':
414: <input type="text" name="coursecode" size="15" value="" />'."\n";
415: } else {
416: my @standardnames = &Apache::loncommon::get_standard_codeitems();
417: my $lasttitle = $numtitles;
418: if ($numtitles > 4) {
419: $lasttitle = 4;
420: }
421: $output .= '<table><tr><td>'.$codetitles[0].'<br />'."\n".
422: '<select name="'.$standardnames[0].'" onchange="courseSet('."'$codetitles[0]'".')">'."\n".
423: ' <option value="-1">'.$html_lt{'sele'}."</option>\n";
424: my @items = ();
425: my @longitems = ();
426: if ($idlist{$codetitles[0]} =~ /","/) {
427: @items = split(/","/,$idlist{$codetitles[0]});
428: } else {
429: $items[0] = $idlist{$codetitles[0]};
430: }
431: if (defined($idlist_titles{$codetitles[0]})) {
432: if ($idlist_titles{$codetitles[0]} =~ /","/) {
433: @longitems = split(/","/,$idlist_titles{$codetitles[0]});
434: } else {
435: $longitems[0] = $idlist_titles{$codetitles[0]};
436: }
437: for (my $i=0; $i<@longitems; $i++) {
438: if ($longitems[$i] eq '') {
439: $longitems[$i] = $items[$i];
440: }
441: }
442: } else {
443: @longitems = @items;
444: }
445: for (my $i=0; $i<@items; $i++) {
446: $output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>'."\n";
447: }
448: $output .= '</select></td>';
449: for (my $i=1; $i<$numtitles; $i++) {
450: $output .= '<td>'.$codetitles[$i].'<br />'."\n".
451: '<select name="'.$standardnames[$i].'" onchange="courseSet('."'$codetitles[$i]'".')">'."\n".
452: '<option value="-1"><-'.$html_lt{'pick'}.' '.$codetitles[$i-1].'</option>'."\n".
453: '</select>'."\n".
454: '</td>'."\n";
455: }
456: $output .= '</tr></table>';
457: if ($numtitles > 4) {
458: $output .= '<br /><br />'.$codetitles[$numtitles].'<br />'."\n".
459: '<select name="'.$standardnames[$numtitles].'" onchange="courseSet('."'$codetitles[$numtitles]'".')">'."\n".
460: '<option value="-1"><-'.$html_lt{'pick'}.' '.$codetitles[$numtitles-1].'</option>'."\n".
461: '</select>'."\n";
462: }
463: }
464: } else {
465: $output .= $html_lt{'enin'}.':
466: <input type="text" name="coursecode" size="15" value="" />'."\n";
467: }
468: }
469: if ($ctitle) {
470: $output .= '<br /><i>'.$html_lt{'titl'}.'</i>: '.$ctitle.
471: '<input type="hidden" name="title" value="'.
472: &HTML::Entities::encode($ctitle,'"<>&').'" />'."\n";
473: } else {
474: $output .= '<br />'.$html_lt{'enct'}.':
475: <input type="text" name="title" size="25" value="" />'."\n";
476: }
477: $output .= &Apache::lonhtmlcommon::row_closure();
478: $num ++;
479: $i = $num%2;
480: $output .= &Apache::lonhtmlcommon::row_title($html_lt{'secn'},undef,$css[$i]);
481: if ($sectionlist) {
482: $output .= "<select name=\"section\"\n>".
483: " <option value=\"\" selected=\"selected\">$html_lt{'sele'}</option>\n";
484: foreach my $id (sort(keys(%groupid))) {
485: if ($id eq $groupid{$id} || $groupid{$id} eq '') {
486: $output .= " <option value=".
487: &HTML::Entities::encode($id,'"<>&').
488: " >$id</option>\n";
489: } else {
490: $output .= " <option value=".
491: &HTML::Entities::encode($id,'"<>&').
492: " >$id - ($html_lt{'lsec'}: $groupid{$id})</option>\n";
493: }
494: }
495: $output .= "</select>";
496: } else {
497: $output .= '<input type="text" name="section" size="10" />'."\n";
498: }
499: $output .= &Apache::lonhtmlcommon::row_closure();
500: $num ++;
501: $i = $num%2;
502: $output .= &Apache::lonhtmlcommon::row_title(
503: '<span title="'.&mt('required').'">'.
504: $html_lt{'subj'}.' <span class="LC_info">*</span></span>'
505: ,undef,'LC_oddrow_value').
506: '<input type="text" size="40" name="subject" />'."\n".
507: &Apache::lonhtmlcommon::row_closure().
508: &Apache::lonhtmlcommon::row_title(
509: '<span title="'.&mt('required').'">'.
510: $html_lt{'detd'}.' <span class="LC_info">*</span></span>'
511: ,undef,'LC_evenrow_value').
512: '<textarea rows="10" cols="45" name="description" style="word-wrap:normal;">'.
513: '</textarea>'."\n".
514: &Apache::lonhtmlcommon::row_closure();
515: $num ++;
516: $i = $num%2;
517: if ($knownuser) {
518: if ($homeserver) {
519: $output .= &Apache::lonhtmlcommon::row_title($html_lt{'opfi'},undef,$css[$i]).
520: ' <input type="file" name="screenshot" size="20" /><br />'.
521: "\n".$html_lt{'uplf'}."\n".
522: &Apache::lonhtmlcommon::row_closure();
523: $num ++;
524: $i = $num%2;
525: }
526: } else {
527: if ($captcha_form) {
528: $output .= &Apache::lonhtmlcommon::row_title(
529: '<span title="'.&mt('required').'">'.
530: &mt('Validation').
531: ' <span class="LC_info">*</span></span>'
532: ,undef,$css[$i]).
533: $captcha_form."\n".
534: &Apache::lonhtmlcommon::row_closure();
535: $num ++;
536: $i = $num%2;
537: }
538: }
539: $output .= &Apache::lonhtmlcommon::row_title($html_lt{'fini'},undef,$css[$i]);
540: $output .= <<END;
541: <table border="0" cellpadding="8" cellspacing="0">
542: <tr>
543: <td>
544: <input type="hidden" name="command" value="process" />
545: <input type="button" value="$html_lt{'subm'}" onclick="validate()" />
546: </td>
547: <td> </td>
548: <td>
549: <input type="reset" value="$html_lt{'clfm'}" />
550: </td>
551: </tr>
552: </table>
553: END
554: $output .= &Apache::lonhtmlcommon::row_closure(1);
555: $output .= &Apache::lonhtmlcommon::end_pick_box();
556: $r->print(<<END);
557: $output
558: </form>
559: <br />
560: END
561: $r->print(&Apache::loncommon::end_page());
562: return;
563: }
564:
565: sub print_request_receipt {
566: my ($r,$url,$function) = @_;
567: my $public;
568: if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
569: $public = 1;
570: }
571: unless (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
572: my $lonhost = $r->dir_config('lonHostID');
573: my ($captcha_chk,$captcha_error) =
574: &Apache::loncommon::captcha_response('login',$lonhost);
575: if ($captcha_chk != 1) {
576: $r->print(&Apache::loncommon::start_page('Support request failed',undef,
577: {'function' => $function,
578: 'add_entries' => {
579: topmargin => "0",
580: marginheight => "0",
581: },
582: 'only_body' => 1,}));
583: if ($r->uri eq '/adm/helpdesk') {
584: &print_header($r,$url,'process');
585: }
586: $r->print(
587: '<h2>'.&mt('Support request failed').'</h2>'.
588: &Apache::lonhtmlcommon::confirm_success(
589: &mt('Validation of the code you entered failed.'),1).
590: '<br /><br />'.
591: &Apache::lonhtmlcommon::actionbox([
592: &mt('[_1]Go back[_2] and try again',
593: '<a href="javascript:history.go(-1)">','</a>')]).
594: &Apache::loncommon::end_page());
595: return;
596: }
597: }
598: my @ENVvars = ('HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME');
599: my @envvars = ('browser.os','browser.type','browser.version','user.home','request.role');
600: my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');
601: my @cookievars = ('lonID');
602:
603: my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
604: my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
605: my $defdom = &get_domain();
606: my $to = &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
607: $defdom,$origmail);
608: my $from = $admin;
609: my $bcc;
610: my %domconfig =
611: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
612: if (ref($domconfig{'contacts'}) eq 'HASH') {
613: if (exists($domconfig{'contacts'}{'helpdeskmail'})) {
614: if (ref($domconfig{'contacts'}{'helpdeskmail'}) eq 'HASH') {
615: my $bccmail = $domconfig{'contacts'}{'helpdeskmail'}{'bcc'};
616: if ($bccmail ne '') {
617: my @bccs = split(/,/,$bccmail);
618: my @ok_bccs;
619: foreach my $bcc (@bccs) {
620: $bcc =~ s/^\s+//g;
621: $bcc =~ s/\s+$//g;
622: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
623: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
624: push(@ok_bccs,$bcc);
625: }
626: }
627: }
628: if (@ok_bccs > 0) {
629: $bcc = join(', ',@ok_bccs);
630: }
631: }
632: }
633: }
634: }
635: my $reporttime = &Apache::lonlocal::locallocaltime(time);
636: my @formvars = ('username','email','uname','udom','sourceurl','phone','section','coursecode','title','subject','description','screenshot');
637:
638: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);
639: my $coursecode = $env{'form.coursecode'};
640: if ($coursecode eq '') {
641: my $totcodes = 0;
642: my %coursecodes;
643: $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$defdom,$totcodes);
644: my @standardnames = &Apache::loncommon::get_standard_codeitems();
645: if ($totcodes > 0) {
646: my $noregexps = 1;
647: $coursecode =
648: &Apache::courseclassifier::instcode_from_selectors($defdom,$noregexps);
649: }
650: if ($coursecode eq '') {
651: foreach my $item (@standardnames) {
652: if ((defined($env{'form.'.$item})) && ($env{'form.'.$item} ne '-1')) {
653: $coursecode .= $env{'form.'.$item};
654: }
655: }
656: }
657: }
658: my %lt = &Apache::lonlocal::texthash (
659: username => 'Name',
660: email => 'E-mail',
661: cc => 'Cc',
662: user => 'Username/domain',
663: phone => 'Phone',
664: crsi => 'Course Information',
665: subject => 'Subject',
666: description => 'Description',
667: sourceurl => 'URL',
668: date => 'Date/Time',
669: secn => 'Section',
670: warn => 'Warning: Problem with support e-mail address',
671: your => 'Your support request contained the following information',
672: sect => 'section',
673: info => 'Information supplied',
674: adin => 'Additional information recorded',
675: );
676:
677: my (@ok_ccs,@bad_ccs,$badccmsg,$okcclist,$homeserver);
678: unless ($public) {
679: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
680: $homeserver = &Apache::lonnet::homeserver($env{'user.name'},
681: $env{'user.domain'});
682: }
683: }
684:
685: if (($homeserver) && (defined($env{'form.cc'}))) {
686: my @ccs;
687: if ($env{'form.cc'} =~ /,/) {
688: @ccs = split(/,/,$env{'form.cc'});
689: } else {
690: $env{'form.cc'} =~ s/^\s+//;
691: $env{'form.cc'} =~ s/\s+$//;
692: @ccs = $env{'form.cc'};
693: }
694: foreach my $cc (@ccs) {
695: $cc =~ s/^\s+//g;
696: $cc =~ s/\s+$//g;
697: if ($cc =~ m/^[^\@]+\@[^\@]+$/) {
698: if (!(grep(/^\Q$cc\E$/,@ok_ccs))) {
699: push(@ok_ccs,$cc);
700: }
701: } elsif ($cc ne '') {
702: if (!(grep(/^\Q$cc\E$/,@bad_ccs))) {
703: push(@bad_ccs,$cc);
704: }
705: }
706: }
707: if (@ok_ccs > 0) {
708: $okcclist = join(', ',@ok_ccs);
709: }
710: if (@bad_ccs == 1) {
711: if ($bad_ccs[0] ne '') {
712: $badccmsg .= '<br />'.&mt('The following Cc e-mail address is invalid: ').&Apache::loncommon::cleanup_html($bad_ccs[0]);
713: }
714: } elsif (@bad_ccs > 1) {
715: $badccmsg .= '<br />'.&mt('The following Cc e-mail addresses are invalid: '). &Apache::loncommon::cleanup_html(join(', ',@bad_ccs));
716: }
717: }
718: $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'";
719: $env{'form.crsi'} = $env{'form.title'}.' - '.$coursecode.' - '.$lt{'sect'}.': '.$env{'form.section'};
720: my $supportmsg = <<END;
721: $lt{'username'}: $env{'form.username'}
722: $lt{'email'}: $env{'form.email'}
723: $lt{'cc'}: $okcclist
724: $lt{'user'}: $env{'form.user'}
725: $lt{'phone'}: $env{'form.phone'}
726: $lt{'crsi'}: $env{'form.crsi'}
727: $lt{'subject'}: $env{'form.subject'}
728: $lt{'description'}: $env{'form.description'}
729: $lt{'sourceurl'}: $env{'form.sourceurl'}
730: $lt{'date'}: $reporttime
731:
732: END
733: my $displaymsg;
734: foreach my $item ('username','email','cc','user','phone','crsi','subject','description','sourceurl') {
735: if ($env{'form.'.$item} ne '') {
736: if ($item eq 'description') {
737: my $descrip = $env{'form.description'};
738: $descrip = &Apache::loncommon::cleanup_html($descrip);
739: $descrip =~ s|[\n\r\f]|<br />|g;
740: $displaymsg .=
741: '<span class="LC_helpform_receipt_cat">'.
742: "$lt{$item}</span>: $descrip<br />\n";
743: } elsif ($item eq 'sourceurl') {
744: my $showurl = $env{'form.sourceurl'};
745: $showurl =~ s/\?.*$//;
746: $showurl = &Apache::loncommon::cleanup_html($showurl);
747: $displaymsg .=
748: '<span class="LC_helpform_receipt_cat">'.
749: "$lt{$item}</span>: $showurl<br />\n";
750: } elsif ($item eq 'cc') {
751: if ($okcclist) {
752: my $showcclist = &Apache::loncommon::cleanup_html($okcclist);
753: $displaymsg .=
754: '<span class="LC_helpform_receipt_cat">'.
755: "$lt{$item}</span>: $showcclist<br />\n";
756: }
757: } else {
758: my $showitem = $env{'form.'.$item};
759: $showitem = &Apache::loncommon::cleanup_html($showitem);
760: $displaymsg .=
761: '<span class="LC_helpform_receipt_cat">'.
762: "$lt{$item}</span>: $showitem<br />\n";
763: }
764: }
765: }
766: $displaymsg .= '<span class="LC_helpform_receipt_cat">'.
767: $lt{'date'}.'</span>: '.$reporttime.'<br />'."\n";
768:
769: my $start_page =
770: &Apache::loncommon::start_page('Support request recorded',undef,
771: {'function' => $function,
772: 'add_entries' => {
773: topmargin => "0",
774: marginheight => "0",
775: },
776: 'only_body' => 1,});
777:
778: $r->print(<<"END");
779: $start_page
780: <form name="logproblem" action="">
781: <input type="hidden" name="command" value="result" />
782: </form>
783: END
784: if ($r->uri eq '/adm/helpdesk') {
785: &print_header($r,$url,'process');
786: }
787: my $bad_email = 0;
788: if ($to =~ /,/) {
789: my @ok_email;
790: foreach my $email (split(/,/,$to)) {
791: if ($email =~ m/^[^\@]+\@[^\@]+$/) {
792: if (!grep(/^\Q$email\E$/,@ok_email)) {
793: push(@ok_email,$email);
794: }
795: }
796: }
797: if (@ok_email > 0) {
798: $to = join(',',@ok_email);
799: } elsif ($admin =~ m/^[^\@]+\@[^\@]+$/) {
800: $to = $admin;
801: } else {
802: $bad_email = 1;
803: }
804: } elsif ($to !~ m/^[^\@]+\@[^\@]+$/) {
805: if ($admin =~ m/^[^\@]+\@[^\@]+$/) {
806: $to = $admin;
807: } else {
808: $bad_email = 1;
809: }
810: }
811:
812: my $message;
813: if (!$bad_email) {
814: $message = &Apache::lonhtmlcommon::confirm_success(
815: &mt('A support request has been sent to [_1]','<tt>'.$to.'</tt>'));
816: } else {
817: $message = &Apache::lonhtmlcommon::confirm_success(
818: $lt{'warn'}.'<br />'
819: .&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>')
820: .' '.&mt('Instead a copy has been sent to the LON-CAPA support team at Michigan State University.'),1);
821: $to = 'helpdesk@lon-capa.org';
822: }
823: $r->print(&Apache::loncommon::confirmwrapper($message));
824:
825: if (defined($env{'form.email'})) {
826: $env{'form.email'} =~ s/^\s+//;
827: $env{'form.email'} =~ s/\s+$//;
828: if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
829: $from = $env{'form.email'};
830: }
831: }
832:
833: if (defined($env{'form.cc'})) {
834: if ($badccmsg) {
835: $displaymsg .= $badccmsg;
836: }
837: }
838:
839: my $subject = $env{'form.subject'};
840: $subject =~ s/(`)/'/g;
841: $subject =~ s/\$/\(\$\)/g;
842: $supportmsg =~ s/(`)/'/g;
843: $supportmsg =~ s/\$/\(\$\)/g;
844: $displaymsg =~ s/(`)/'/g;
845: $displaymsg =~ s/\$/\(\$\)/g;
846: my $fname;
847:
848: my $attachmentpath = '';
849: my $attachmentsize = '';
850: if ((defined($env{'user.name'})) && (!$public)) {
851: if ($homeserver && $env{'form.screenshot.filename'}) {
852: $attachmentsize = length($env{'form.screenshot'});
853: if ($attachmentsize > 131072) {
854: $displaymsg .= '<br /><span class="LC_warning">'.
855: &mt('The uploaded screenshot file ([_1] bytes) included with your request exceeded the maximum allowed size - 128 KB, and has therefore been discarded.',$attachmentsize).'</span>';
856: } else {
857: $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
858: }
859: }
860: }
861:
862: my %cookies;
863: my $cookie=CGI::Cookie->parse($r->header_in('Cookie'));
864: if ($$cookie{'lonID'} =~ /lonID=($LONCAPA::handle_re);/) {
865: $cookies{'lonID'} = $1;
866: }
867:
868: if ($attachmentpath =~ m-/([^/]+)$-) {
869: $fname = $1;
870: $displaymsg .= '<br />'
871: .&mt('An uploaded screenshot file [_1] ([_2] bytes) was included in the request sent by [_3].'
872: ,'<span class="LC_filename">'.$fname.'</span>'
873: ,$attachmentsize
874: ,$env{'user.name'}.':'.$env{'user.domain'}
875: );
876: $supportmsg .= "\n";
877: foreach my $var (@cookievars) {
878: $supportmsg .= "$var: $cookies{$var}\n";
879: }
880: foreach my $var(@ENVvars) {
881: $supportmsg .= "$var: $ENV{$var}\n";
882: }
883: foreach my $var (@envvars) {
884: $supportmsg .= "$var: $env{$var}\n";
885: }
886: }
887:
888: my $msg = MIME::Lite->new(
889: From => $from,
890: To => $to,
891: Subject => $subject,
892: Type =>'TEXT',
893: Data => $supportmsg,
894: );
895: if ($homeserver) {
896: if (@ok_ccs > 0) {
897: my $cc_string = join(', ',@ok_ccs);
898: $msg->add("Cc" => $cc_string);
899: }
900: }
901: if ($bcc ne '') {
902: $msg->add("Bcc" => $bcc);
903: }
904: $msg->attr("content-type" => "text/plain");
905: $msg->attr("content-type.charset" => "UTF-8");
906:
907: if ($homeserver && $attachmentpath) {
908: my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath);
909: $msg->attach(Type => $type,
910: Path => $attachmentpath,
911: Filename => $fname
912: );
913:
914: } else {
915: my $envdata = '';
916: foreach my $var (@cookievars) {
917: $envdata .= "$var: $cookies{$var}\n";
918: }
919: foreach my $var (@ENVvars) {
920: $envdata .= "$var: $ENV{$var}\n";
921: }
922: foreach my $var (@envvars) {
923: $envdata .= "$var: $env{$var}\n";
924: }
925: foreach my $var (@loncvars) {
926: $envdata .= "$var: $env{$var}\n";
927: }
928: $msg->attach(Type => 'TEXT',
929: Data => $envdata);
930: }
931:
932: ### Send it:
933: $msg->send('sendmail');
934:
935: if ($attachmentpath =~ m|$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+|) {
936: unlink($attachmentpath);
937: }
938: $r->print('<b>'.$lt{'your'}.'</b>:<br /><br />'."\n");
939: $r->print('<div style="width:620px;">'.
940: &Apache::lonhtmlcommon::start_pick_box().
941: &Apache::lonhtmlcommon::row_title($lt{'info'},undef,'LC_oddrow_value')."\n".$displaymsg."\n".
942: &Apache::lonhtmlcommon::row_closure().
943: &Apache::lonhtmlcommon::row_title($lt{'adin'},undef,'LC_evenrow_value'));
944: my $envmsg;
945: foreach my $var (@cookievars) {
946: if ($cookies{$var} ne '') {
947: $envmsg.= '<span class="LC_helpform_receipt_cat">'.
948: $var.'</span>: '.$cookies{$var}.', ';
949: }
950: }
951: foreach my $var (@ENVvars) {
952: if ($ENV{$var} ne '') {
953: $envmsg .= '<span class="LC_helpform_receipt_cat">'.
954: $var.'</span>: '.$ENV{$var}.', ';
955: }
956: }
957: foreach my $var (@envvars) {
958: if ($env{$var} ne '') {
959: $envmsg .= '<span class="LC_helpform_receipt_cat">'.
960: $var.'</span>: '.$env{$var}.', ';
961: }
962: }
963: $envmsg =~ s/, $//;
964: $r->print($envmsg."\n".
965: &Apache::lonhtmlcommon::row_closure(1)."\n".
966: &Apache::lonhtmlcommon::end_pick_box().
967: "</div>\n".
968: &Apache::loncommon::end_page());
969: }
970:
971: sub print_header {
972: my ($r,$origurl,$command) = @_;
973: my $location=&Apache::loncommon::lonhttpdurl("/adm");
974: my ($component_url);
975: my $helpdesk_link = '<a href="javascript:validate()">';
976: if ($command eq 'process') {
977: $helpdesk_link = '<a href="/adm/helpdesk">';
978: }
979: my %lt = &Apache::lonlocal::texthash (
980: login => 'Log-in help',
981: ask => 'Ask helpdesk',
982: getst => 'Getting started guide',
983: back => 'Back to last location',
984: headline => 'help/support',
985: stud => 'Students',
986: ifyo => 'If your problem is still unresolved, the form below can be used to send a question to the LON-CAPA helpdesk.',
987: cont => 'Contact your instructor instead.',
988: );
989: my ($getstartlink,$reviewtext);
990: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/gettingstarted.html') {
991: $getstartlink = qq|<td align="center"> <b><a href="/adm/gettingstarted.html">$lt{'getst'}</a></td>|;
992: $reviewtext = &mt('Please review the information in "Log-in help" and the "Getting started" guide if you are unable to log-in.');
993: } else {
994: $reviewtext = &mt('Please review the information in "Log-in help" if you are unable to log-in.');
995: }
996: my $linkback;
997: if ($origurl eq '') {
998: $linkback = 'javascript:history.go(-1)';
999: } else {
1000: $linkback = &HTML::Entities::encode($origurl,'"<>&');
1001: }
1002: my $loginhelp = &Apache::lonauth::loginhelpdisplay();
1003: if ($loginhelp eq '') {
1004: $loginhelp = '/adm/loginproblems.html';
1005: }
1006: $r->print(<<"END");
1007: <table width="620" border="0" cellspacing="0" cellpadding="0" style="height: 55px;">
1008: <tr>
1009: <td width="5" height="50"> </td>
1010: <td height="50">
1011: <fieldset>
1012: <legend>
1013: <img src="$location/lonIcons/minilogo.gif" height="20" width="29" alt="logo" style="vertical-align:bottom" />
1014: LON-CAPA $lt{'headline'}
1015: </legend>
1016: <table id="LC_helpmenu_links">
1017: <tr>
1018: <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>
1019: <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
1020: <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>
1021: </tr>
1022: </table>
1023: </fieldset>
1024: </td>
1025: <td width="5"> </td>
1026: </tr>
1027: <tr>
1028: <td colspan="3" height="5"> </td>
1029: </tr>
1030: END
1031: if ($command ne 'process') {
1032: my $stuwarn = &mt('Do [_1]not[_2] use this form to ask about course content.',
1033: '<b>','</b>');
1034: $r->print(<<"END");
1035: <tr>
1036: <td colspan="3">$reviewtext
1037: $lt{'ifyo'}
1038: <p class="LC_info">
1039: <b>$lt{'stud'}:</b>
1040: $stuwarn $lt{'cont'}
1041: </p><br />
1042: </td>
1043: </tr>
1044: END
1045: }
1046: $r->print('
1047: </table>');
1048: return;
1049: }
1050:
1051: sub get_domain {
1052: my $codedom;
1053: if (exists($env{'form.codedom'})) {
1054: if (&Apache::lonnet::domain($env{'form.codedom'}) ne '') {
1055: return $env{'form.codedom'};
1056: }
1057: }
1058: if ($env{'request.course.id'}) {
1059: $codedom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1060: } elsif ($env{'request.role.domain'}) {
1061: $codedom = $env{'request.role.domain'};
1062: } else {
1063: $codedom = &Apache::lonnet::default_login_domain();
1064: }
1065: return $codedom;
1066: }
1067:
1068: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>