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