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