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