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