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