Annotation of loncom/interface/lonsupportreq.pm, revision 1.4
1.1 raeburn 1: package Apache::lonsupportreq;
2:
3: use strict;
4: use lib qw(/home/httpd/lib/perl);
5: use Apache::Constants qw(:common);
1.2 albertel 6: use Apache::loncommon();
7: use Apache::lonnet();
1.1 raeburn 8: use localenroll;
9: use Apache::lonlocal;
10:
11: use Mail::Send;
12: # use MIME::Lite;
13: # use MIME::Types;
14:
15: sub handler {
1.2 albertel 16: my ($r) = @_;
17: &Apache::loncommon::content_type($r,'text/html');
1.1 raeburn 18: $r->send_http_header;
19:
20: if ($r->header_only) {
21: return OK;
22: }
23:
24: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','origurl','function']);
25: my $action = $ENV{'form.action'};
26: my $function = $ENV{'form.function'};
27: my $origurl = &Apache::lonnet::unescape($ENV{'form.origurl'});
28: if ($action eq 'process') {
29: &print_request_receipt($r,$origurl,$function);
30: } else {
31: &print_request_form($r,$origurl,$function);
32: }
33: return OK;
34: }
35:
36: sub print_request_form {
37: my ($r,$origurl,$function) = @_;
38: my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$urole,$usec,$email,$cid,$cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server);
39: my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0",marginheight="0"',1);
40: my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');
41: $os = $ENV{'browser.os'};
42: $browser = $ENV{'browser.type'};
43: $bversion = $ENV{'browser.version'};
44: $uhost = $ENV{'request.host'};
45: $uname = $ENV{'user.name'};
46: $udom = $ENV{'user.domain'};
47: $uhome = $ENV{'user.home'};
48: $urole = $ENV{'request.role'};
49: $usec = $ENV{'request.course.sec'};
50: $cid = $ENV{'request.course.id'};
51: $server = $ENV{'SERVER_NAME'};
52: my $scripttag;
53: if ($cid =~ m/_/) {
54: ($cdom,$cnum) = split/_/,$cid;
55: }
56: if ($cdom && $cnum) {
57: my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
58: $ctitle = $csettings{'description'};
59: $ccode = $csettings{'internal.coursecode'};
60: $sectionlist = $csettings{'internal.sectionnums'};
61: }
62: if ($ENV{'environment.critnotification'}) {
63: $email = $ENV{'environment.critnotification'};
64: }
65: if (!$email && $ENV{'environment.notification'}) {
66: $email = $ENV{'environment.notification'};
67: }
68: if ($ENV{'environment.lastname'}) {
69: $lastname = $ENV{'environment.lastname'};
70: }
71: if ($ENV{'environment.firstname'}) {
72: $firstname = $ENV{'environment.firstname'};
73: }
74: my @sections = split/,/,$sectionlist;
75: my %groupid = ();
76: foreach (@sections) {
77: my ($sec,$grp) = split/:/,$_;
78: $groupid{$sec} = $grp;
79: }
80: $r->print(<<END);
81: <html>
82: <head>
83: <title>LON-CAPA support request</title>
84: END
85: my $defdom = $Apache::lonnet::perlvar{'lonDefDomain'};
86: my $codedom = $defdom;
87: my %coursecodes = ();
88: my %codes = ();
89: my @codetitles = ();
90: my %cat_titles = ();
91: my %cat_order = ();
92: my $caller = 'global';
93: my $totcodes = 0;
94: my $format_reply;
95:
96: if ($cdom) {
97: $codedom = $cdom;
98: }
99: if ($cnum) {
100: $coursecodes{$cnum} = $ccode;
101: if ($ccode eq '') {
102: $totcodes = &retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
103: } else {
104: $coursecodes{$cnum} = $ccode;
105: $caller = $cnum;
106: $totcodes ++;
107: }
108: } else {
109: $totcodes = &retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
110: }
111: if ($totcodes > 0) {
112: $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
113: }
114: $r->print(<<END);
115: <html>
116: <head>
117: <title>LON-CAPA support request</title>
118: $scripttag
119: </head>
120: $bodytag
121: <table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
122: <tr>
123: <td>
124: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
125: <tr>
126: <td>
127: <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
128: <tr>
129: <td>
130: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
131: <form method="post" name="logproblem" onSubmit="return validate()">
132: <tr>
133: <td width="140" bgcolor="$tablecolor">
134: <table width="140" border="0" cellpadding="8" cellspacing="0">
135: <tr>
136: <td align="right"><b>Name:</b>
137: </td>
138: </tr>
139: </table>
140: </td>
141: <td width="100%" valign="top">
142: <table width="100%" border="0" cellpadding="8" cellspacing="0">
143: <tr>
144: <td>
145: END
146: my $fullname = '';
147: if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) {
148: $fullname = "$firstname $lastname";
149: $r->print("$fullname<input type=\"hidden\" name=\"username\" value=\"$fullname\" />");
150: } else {
151: if (defined($firstname) && $firstname ne '') {
152: $fullname = $firstname;
153: } elsif (defined($lastname) && $lastname ne '') {
154: $fullname= " $lastname";
155: }
156: $r->print('<input type="text" size="20" name="username" value="'.$fullname.'" /><br />');
157: }
158: $r->print(<<END);
159: </td>
160: </tr>
161: </table>
162: </td>
163: </tr>
164: <tr>
165: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 166: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 167: </td>
168: </tr>
169: <tr>
170: <td width="140" bgcolor="$tablecolor">
171: <table width="140" border="0" cellpadding="8" cellspacing="0">
172: <tr>
173: <td align="right"><b>E-mail address:</b>
174: </td>
175: </tr>
176: </table>
177: </td>
178: <td width="100%" valign="top">
179: <table width="100%" border="0" cellpadding="8" cellspacing="0">
180: <tr>
181: <td>
182: <input type="text" size="20" name="email" value="$email" /><br />
183: </td>
184: </tr>
185: </table>
186: </td>
187: </tr>
188: <tr>
189: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 190: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 191: </td>
192: </tr>
193: <tr>
194: <td width="140" bgcolor="$tablecolor">
195: <table width="140" border="0" cellpadding="8" cellspacing="0">
196: <tr>
197: <td align="right"><b>username/domain:</b>
198: </td>
199: </tr>
200: </table>
201: </td>
202: <td width="100%" valign="top">
203: <table width="100%" border="0" cellpadding="8" cellspacing="0">
204: <tr>
205: <td>
206: END
207: my $udom_input = '<input type="hidden" name="udom" value="'.$udom.'" />';
208: my $uname_input = '<input type="hidden" name="uname" value="'.$uname.'" />';
209: if (defined($uname) && defined($udom)) {
210: $r->print('<i>username</i>: '.$uname.' <i>domain</i>: '.$udom.$udom_input.$uname_input);
211: } else {
212: my $udomform = '';
213: my $unameform = '';
214: if (defined($udom)) {
215: $udomform = '<i>domain</i>: '.$udom.$udom_input;
216: } elsif (defined($uname)) {
217: $unameform = '<i>username</i>: '.$uname.' '.$uname_input;
218: }
219: if ($udomform eq '') {
220: $udomform = '<i>domain</i>: ';
221: $udomform .= &Apache::loncommon::select_dom_form('','udom');
222: }
223: if ($unameform eq '') {
224: $unameform= '<i>username</i>: <input type="text" size="20" name="loncname" value="'.$uname.'" /> ';
225: }
226: $r->print($unameform.$udomform.'<br />Enter the username you use to log-in to your LON-CAPA system, and choose your domain.');
227: }
228: $r->print(<<END);
229: </td>
230: </tr>
231: </table>
232: </td>
233: </tr>
234: <tr>
235: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 236: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 237: </td>
238: </tr>
239: <tr>
240: <td width="140" bgcolor="$tablecolor">
241: <table width="140" border="0" cellpadding="8" cellspacing="0">
242: <tr>
243: <td align="right"><b>URL of page:</b>
244: </td>
245: </tr>
246: </table>
247: </td>
248: <td width="100%" valign="top">
249: <table width="100%" border="0" cellpadding="8" cellspacing="0">
250: <tr>
251: <td>
252: $server$origurl<input type="hidden" name="origurl" value="$server$origurl" />
253: </td>
254: </tr>
255: </table>
256: </td>
257: </tr>
258: <tr>
259: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 260: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 261: </td>
262: </tr>
263: <tr>
264: <td width="140" bgcolor="$tablecolor">
265: <table width="140" border="0" cellpadding="8" cellspacing="0">
266: <tr>
267: <td align="right"><b>Phone #:</b>
268: </td>
269: </tr>
270: </table>
271: </td>
272: <td width="100%" valign="top">
273: <table width="100%" border="0" cellpadding="8" cellspacing="0">
274: <tr>
275: <td>
276: <input type="text" size="15" name="phone"><br>
277: </td>
278: </tr>
279: </table>
280: </td>
281: </tr>
282: <tr>
283: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 284: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 285: </td>
286: </tr>
287: <tr>
288: <td width="140" bgcolor="$tablecolor">
289: <table width="140" border="0" cellpadding="8" cellspacing="0">
290: <tr>
291: <td align="right"><b>Course Details:</b>
292: </td>
293: </tr>
294: </table>
295: </td>
296: <td width="100%" valign="top">
297: <table border="0" cellpadding="3" cellspacing="3">
298: <tr>
299: <td>
300: END
301: if ($coursecodes{$cnum}) {
302: foreach (@codetitles) {
303: $r->print('<i>'.$_.'</i>: '.$codes{$cnum}{$_});
304: }
305: $r->print('. <input type="hidden" name="coursecode" value="'.$coursecodes{$cnum}.'" />');
306: } else {
307: $r->print('Enter institutional course code:
308: <input type="text" name="coursecode" size="15" value="" />');
309: }
310: if ($ctitle) {
311: $r->print('<br /><i>Title</i>: '.$ctitle.'<input type="hidden" name="title" value="'.$ctitle.'" />');
312: } else {
313: $r->print('<br />Enter course title:
314: <input type="text" name="title" size="15" value="" />');
315: }
316: $r->print(<<END);
317: </td>
318: </tr>
319: </table>
320: </td>
321: </tr>
322: <tr>
323: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 324: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 325: </td>
326: </tr>
327: <tr>
328: <td width="140" bgcolor="$tablecolor">
329: <table width="140" border="0" cellpadding="8" cellspacing="0">
330: <tr>
331: <td align="right"><b>Section Number: </b>
332: </td>
333: </tr>
334: </table>
335: </td>
336: <td width="100%" valign="top">
337: <table width="100%" border="0" cellpadding="8" cellspacing="0">
338: <tr>
339: <td>
340: END
341: if ($sectionlist) {
342: $r->print("<select name=\"section\">");
343: foreach (sort keys %groupid) {
344: if ($_ eq $groupid{$_} || $groupid{$_} eq '') {
345: $r->print("<option value=\"$_\" />$_");
346: } else {
347: $r->print("<option value=\"$_\" />$_ - (LON-CAPA sec: $groupid{$_}");
348: }
349: }
350: $r->print("</select>");
351: } else {
352: $r->print("<input type=\"text\" name=\"section\" size=\"10\"/>");
353: }
354: $r->print(<<END);
355: </td>
356: </tr>
357: </table>
358: </td>
359: </tr>
360: <tr>
361: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 362: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 363: </td>
364: </tr>
365: <tr>
366: <td width="140" bgcolor="$tablecolor">
367: <table width="140" border="0" cellpadding="8" cellspacing="0">
368: <tr>
369: <td align="right"><b>Subject</b>
370: </td>
371: </tr>
372: </table>
373: </td>
374: <td width="100%" valign="top">
375: <table width="100%" border="0" cellpadding="8" cellspacing="0">
376: <tr>
377: <td>
378: <input type="text" size="40" name="subject">
379: </td>
380: </tr>
381: </table>
382: </td>
383: </tr>
384: <tr>
385: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 386: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 387: </td>
388: </tr>
389: <tr>
390: <td width="140" bgcolor="$tablecolor">
391: <table width="140" border="0" cellpadding="8" cellspacing="0">
392: <tr>
393: <td align="right"><b>Detailed description:</b>
394: </td>
395: </tr>
396: </table>
397: </td>
398: <td width="100%" valign="top">
399: <table width="100%" border="0" cellpadding="8" cellspacing="0">
400: <tr>
401: <td>
402: <textarea rows="10" cols="45" name="description" wrap="virtual"></textarea>
403: </td>
404: </tr>
405: </table>
406: </td>
407: </tr>
408: <tr>
409: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 410: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 411: </td>
412: </tr>
413: <tr>
414: <td width="140" bgcolor="$tablecolor">
415: <table width="140" border="0" cellpadding="8" cellspacing="0">
416: <tr>
417: <td align="right"><b>Finish:</b>
418: </td>
419: </tr>
420: </table>
421: </td>
422: <td width="100%" valign="top">
423: <table border="0" cellpadding="8" cellspacing="0">
424: <tr>
425: <td>
426: <input type="hidden" name="action" value="process" />
427: <input type="submit" value="Submit Request Form" />
428: </td>
429: <td> </td>
430: <td>
431: <input type="reset" value="Clear Form">
432: </td>
433: </tr>
434: </table>
435: </td>
436: </tr>
437: </table>
438: </td>
439: </tr>
440: </table>
441: </td>
442: </tr>
443: </table>
444: </td>
445: </tr>
446: </table>
447: END
448:
449:
450: # What do we know about this user?
451: # foreach (sort keys %ENV) {
452: # if ($_ =~ m/^browser/) {
453: # $r->print("key is $_, value is $ENV{$_}");
454: # } elsif ($_ =~ m/^environment/) {
455: # $r->print("key is $_, value is $ENV{$_}");
456: # } elsif ($_ =~ m/^request/) {
457: # $r->print("key is $_, value is $ENV{$_}");
458: # } elsif ($_ =~ m/^user\.(domain|home|name)/) {
459: # $r->print("key is $_, value is $ENV{$_}");
460: # } elsif ($_ =~ /^[A-Z]/) {
461: # $r->print("key is $_, value is $ENV{$_}");
462: # }
463: # }
464: return
465: }
466:
467: sub print_request_receipt {
468: my ($r,$url,$function) = @_;
469: my @envvars = ('lonID','HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME','browser.os','browser.type','browser.version','user.home','request.role');
470: my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0" marginheight="0"',1);
471: my $to = $Apache::lonnet::perlvar{'lonSupportEMail'};
472: my $reporttime = &Apache::lonlocal::locallocaltime(time);
473: my $fontcolor = &Apache::loncommon::designparm($function.'.font');
474: my $vlinkcolor = &Apache::loncommon::designparm($function.'.vlink');
475: my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');
476: my @formvars = ('username','email','uname','udom','origurl','phone','section','coursecode','title','subject','description');
477: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);
478:
479: # if ($ENV{'request.course.fn'}) {
480: # my $formdatafile = $ENV{'request.course.fn'}.'.formdata';
481: # if (-e $formdatafile) {
482: # open(FILE,"<$formdatafile");
483: # my @buffer =<FILE>;
484: # close(FILE);
485: # foreach (@buffer) {
486: # print STDERR $_;
487: # }
488: # }
489: # }
490:
491: my $supportmsg = qq|
492: Name: $ENV{'form.username'}
493: Email: $ENV{'form.email'}
494: Username/domain: $ENV{'form.uname'} - $ENV{'form.udom'}
495: Tel: $ENV{'form.phone'}
496: Course Information: $ENV{'form.title'} - $ENV{'form.coursecode'} - section: $ENV{'form.section'}
497: Subject: $ENV{'form.subject'}
498: Description: $ENV{'form.description'}
499: URL: $ENV{'form.origurl'}
500: Date/Time: $reporttime
501:
502: |;
503: if ($to =~ m/^[^\@]+\@[^\@]+$/) {
504: $r->print(<<END);
505: <html>
506: <head>
507: <title>LON-CAPA support request recorded</title>
508: </head>
509: $bodytag
510: <h3>A support request has been sent to $to</h3>
511: END
512: } else {
513: $to = 'helpdesk@lon-capa.org';
514: $r->print(<<END);
515: <html>
516: <head>
517: <title>LON-CAPA support request recorded</title>
518: </head>
519: $bodytag
520: <h3>Warning: Problem with support e-mail address</h3>
521: As the e-mail address provided for this LON-CAPA server ($to) does not appear to be a valid e-mail address, your support request has not been sent to the LON-CAPA support staff at your institution. Instead a copy has been sent to the LON-CAPA support team at Michigan State University.
522: END
523: }
524: my $msg = new Mail::Send;
525: $msg->to($to);
526: # if (defined($ENV{'form.email'})) {
527: # if ($ENV{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
528: # $msg->from($ENV{'form.email'});
529: # }
530: # }
531: $msg->subject('[LON-CAPA] - support request');
1.4 ! albertel 532: # ->open can cause an sh launch which can pass all of %ENV allong
! 533: # which can be to large for /bin/sh's little mind
! 534: my %oldENV=%ENV;
! 535: undef(%ENV);
1.1 raeburn 536: if (my $fh = $msg->open()) {
1.4 ! albertel 537: print $fh $supportmsg;
1.1 raeburn 538: $fh->close;
539: }
1.4 ! albertel 540: %ENV=%oldENV;
! 541: undef(%oldENV);
1.1 raeburn 542: $r->print(<<END);
543: <b>Your support request contained the following information</b>:<br /><br />
544: <table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
545: <tr>
546: <td>
547: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
548: <tr>
549: <td>
550: <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
551: <tr>
552: <td>
553: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
554: <tr>
555: <td width="140" bgcolor="$tablecolor">
556: <table width="140" border="0" cellpadding="8" cellspacing="0">
557: <tr>
558: <td align="right"><b>Information supplied</b>
559: </td>
560: </tr>
561: </table>
562: </td>
563: <td width="100%" valign="top">
564: <table width="100%" border="0" cellpadding="8" cellspacing="0">
565: <tr>
566: <td>
567: END
568: my @textmsg = split/\n/,$supportmsg;
569: foreach my $line (@textmsg) {
570: $line =~ s|^|<font color="$fontcolor">|;
571: $line =~ s|:|:</font><font color="$vlinkcolor">|;
572: $r->print("$line</font><br />");
573: }
574: $r->print('</td>
575: </tr>
576: </table>
577: </td>
578: </tr>
579: <tr>
580: <td width="130" bgcolor="'.$tablecolor.'">
581: <table width="130" border="0" cellpadding="8" cellspacing="0">
582: <tr>
583: <td align="right"><b>Additional information recorded</b>
584: </td>
585: </tr>
586: </table>
587: </td>
588: <td width="100%" valign="top">
589: <table width="100%" border="0" cellpadding="8" cellspacing="0">
590: <tr>
591: <td>
592: ');
593: foreach (@envvars) {
594: $r->print("$_: <font color='$vlinkcolor>$ENV{$_}</font>, ");
595: $supportmsg .= "$_: $ENV{$_}\n";
596: }
597: $r->print("
598: </td>
599: </tr>
600: </table>
601: </td>
602: </tr>
603: </table>
604: </td>
605: </tr>
606: </table>
607: </td>
608: </tr>
609: </table>
610: </td>
611: </tr>
612: </table>
613: ");
614: }
615:
616: sub retrieve_instcodes {
617: my ($coursecodes,$codedom,$totcodes) = @_;
618: my %courses = &Apache::lonnet::courseiddump($codedom,'.',1);
619: foreach my $course (keys %courses) {
620: if ($courses{$course} =~ m/^[^:]*:([^:]+)$/) {
621: $$coursecodes{$course} = &Apache::lonnet::unescape($1);
622: $totcodes ++;
623: }
624: }
625: return $totcodes;
626: }
627:
628: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>