Annotation of loncom/interface/lonsupportreq.pm, revision 1.66.6.1
1.24 albertel 1: #
1.66.6.1! raeburn 2: # $Id: lonsupportreq.pm,v 1.66 2011/03/03 17:29:29 bisitz Exp $
1.24 albertel 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:
1.1 raeburn 27: package Apache::lonsupportreq;
28:
29: use strict;
1.5 raeburn 30: use MIME::Types;
31: use MIME::Lite;
1.27 raeburn 32: use CGI::Cookie();
1.1 raeburn 33: use Apache::Constants qw(:common);
1.2 albertel 34: use Apache::loncommon();
1.43 raeburn 35: use Apache::lonhtmlcommon;
1.24 albertel 36: use Apache::lonnet;
1.1 raeburn 37: use Apache::lonlocal;
1.34 albertel 38: use Apache::lonacc();
1.60 raeburn 39: use LONCAPA qw(:DEFAULT :match);
1.35 www 40:
1.1 raeburn 41:
42: sub handler {
1.2 albertel 43: my ($r) = @_;
44: &Apache::loncommon::content_type($r,'text/html');
1.1 raeburn 45: $r->send_http_header;
46:
47: if ($r->header_only) {
48: return OK;
49: }
1.42 albertel 50: if ($r->uri eq '/adm/helpdesk') {
51: &Apache::lonlocal::get_language_handle($r);
52: }
53:
1.12 raeburn 54: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['origurl','function']);
55: if ($r->uri eq '/adm/helpdesk') {
1.34 albertel 56: &Apache::lonacc::get_posted_cgi($r);
1.12 raeburn 57: }
1.25 albertel 58: my $function = $env{'form.function'};
1.60 raeburn 59: my $origurl = $env{'form.origurl'};
1.44 raeburn 60: my $command = $env{'form.command'};
1.12 raeburn 61:
1.44 raeburn 62: if ($command eq 'process') {
1.1 raeburn 63: &print_request_receipt($r,$origurl,$function);
64: } else {
65: &print_request_form($r,$origurl,$function);
66: }
67: return OK;
68: }
69:
70: sub print_request_form {
71: my ($r,$origurl,$function) = @_;
1.66.6.1! raeburn 72: my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$email,
! 73: $lastname,$firstname,$server,$formname,$public);
1.44 raeburn 74: $function = &Apache::loncommon::get_users_function() if (!$function);
1.10 raeburn 75: $ccode = '';
1.25 albertel 76: $os = $env{'browser.os'};
77: $browser = $env{'browser.type'};
78: $bversion = $env{'browser.version'};
79: $uhost = $env{'request.host'};
1.60 raeburn 80: if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
81: $public = 1;
82: } else {
1.56 raeburn 83: $uname = $env{'user.name'};
84: $udom = $env{'user.domain'};
85: }
1.25 albertel 86: $uhome = $env{'user.home'};
1.29 raeburn 87: $formname = 'logproblem';
1.40 raeburn 88: my $machine = &Apache::lonnet::absolute_url();
89: if ($origurl =~ m-^https?://-) {
1.21 raeburn 90: $server = $origurl;
91: } else {
1.40 raeburn 92: $server = $machine.$origurl;
1.21 raeburn 93: }
1.44 raeburn 94: my $showserver = $server;
95: $showserver =~ s/\?.*$//;
1.40 raeburn 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',
1.46 raeburn 103: emad => 'Your e-mail address',
104: emac => 'Cc',
1.40 raeburn 105: unme => 'username',
106: doma => 'domain',
1.44 raeburn 107: entu => 'Enter the username you use to log-in to LON-CAPA',
108: chdo => 'Choose your LON-CAPA domain',
109: entr => 'Enter the username you use to log-in to LON-CAPA, and your domain.',
1.40 raeburn 110: urlp => 'URL of page',
111: phon => 'Phone',
112: pick => 'Pick',
113: subj => 'Subject',
114: detd => 'Detailed Description',
115: opfi => 'Optional file upload',
1.44 raeburn 116: uplf => 'Upload a file (e.g., a screenshot) relevant to your help request (128 KB max.)',
1.40 raeburn 117: fini => 'Finish',
118: clfm => 'Clear Form',
119: );
120: my $scripttag = (<<"END");
1.5 raeburn 121: function validate() {
1.13 raeburn 122: if (validmail(document.logproblem.email) == false) {
1.40 raeburn 123: alert("$lt{'email'}: "+document.logproblem.email.value+" $lt{'notv'}.");
124: return;
125: }
126: if (document.logproblem.subject.value == '') {
127: alert("$lt{'rsub'}.");
128: return;
129: }
130: if (document.logproblem.description.value == '') {
131: alert("$lt{'rdes'}.");
1.13 raeburn 132: return;
1.5 raeburn 133: }
134: document.logproblem.submit();
135: }
1.13 raeburn 136:
1.40 raeburn 137: END
1.43 raeburn 138: $scripttag .= &Apache::lonhtmlcommon::javascript_valid_email();
1.44 raeburn 139:
140: if ($env{'environment.permanentemail'}) {
141: $email = $env{'environment.permanentemail'};
142: } elsif ($env{'environment.critnotification'}) {
1.25 albertel 143: $email = $env{'environment.critnotification'};
1.44 raeburn 144: } elsif ($env{'environment.notification'}) {
1.25 albertel 145: $email = $env{'environment.notification'};
1.1 raeburn 146: }
1.25 albertel 147: if ($env{'environment.lastname'}) {
148: $lastname = $env{'environment.lastname'};
1.1 raeburn 149: }
1.25 albertel 150: if ($env{'environment.firstname'}) {
151: $firstname = $env{'environment.firstname'};
1.1 raeburn 152: }
1.66.6.1! raeburn 153:
1.60 raeburn 154: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['codedom',
155: 'useremail','useraccount']);
156: if ($env{'form.origurl'} eq '/adm/createaccount') {
157: if ($email eq '') {
158: if ($env{'form.useremail'} =~ /^[^\@]+\@[^\@]+$/) {
159: $email = &HTML::Entities::encode($env{'form.useremail'},'"<>&');
160: }
161: }
162: if ($uname eq '') {
163: if ($env{'form.useraccount'} =~ /^$match_username$/) {
164: $uname = &HTML::Entities::encode($env{'form.useraccount'},'"<>&');
165: }
166: }
167: }
1.45 raeburn 168: my $codedom = &get_domain();
1.1 raeburn 169: my $caller = 'global';
170: my $format_reply;
1.6 raeburn 171: my $jscript = '';
1.44 raeburn 172: my $js = '<script type="text/javascript">'."\n$scripttag\n$jscript\n".
1.66.6.1! raeburn 173: '</script>';
1.33 albertel 174: my %add_entries = (topmargin => "0",
175: marginheight => "0",
1.66.6.1! raeburn 176: );
1.44 raeburn 177:
178: $r->print(&Apache::loncommon::start_page('Support Request',$js,
1.31 albertel 179: { 'function' => $function,
1.33 albertel 180: 'add_entries' => \%add_entries,
1.44 raeburn 181: 'only_body' => 1,}));
1.15 raeburn 182: if ($r->uri eq '/adm/helpdesk') {
1.14 raeburn 183: &print_header($r,$origurl);
184: }
1.50 raeburn 185: my @css = ('LC_evenrow_value','LC_oddrow_value');
186: my $num = 1;
187: my $i = $num%2;
1.44 raeburn 188: $r->print('<form method="post" name="logproblem" enctype="multipart/form-data">'."\n");
189: my $output = &Apache::lonhtmlcommon::start_pick_box().
1.50 raeburn 190: &Apache::lonhtmlcommon::row_title($lt{'name'},undef,$css[$num])."\n";
1.1 raeburn 191: my $fullname = '';
192: if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) {
193: $fullname = "$firstname $lastname";
1.44 raeburn 194: $output .= $fullname.'<input type="hidden" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />';
1.1 raeburn 195: } else {
196: if (defined($firstname) && $firstname ne '') {
197: $fullname = $firstname;
198: } elsif (defined($lastname) && $lastname ne '') {
1.44 raeburn 199: $fullname = " $lastname";
1.1 raeburn 200: }
1.44 raeburn 201: $output .= '<input type="text" size="20" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />';
1.1 raeburn 202: }
1.44 raeburn 203: $output .= ' <input type="button" value="'.$lt{'subm'}.'" onclick="validate()" /> '.
1.50 raeburn 204: &Apache::lonhtmlcommon::row_closure()."\n";
205: $num ++;
206: $i = $num%2;
207: $output .= &Apache::lonhtmlcommon::row_title($lt{'emad'},undef,$css[$i]).
208: '<input type="text" size="20" name="email" value="'.
209: &HTML::Entities::encode($email,'"<>&').'" /><br />'."\n".
210: &Apache::lonhtmlcommon::row_closure();
211: $num ++;
212: $i = $num%2;
1.60 raeburn 213: if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
1.50 raeburn 214: $output .= &Apache::lonhtmlcommon::row_title($lt{'emac'},undef,$css[$i]).
215: '<input type="text" size="50" name="cc" value="" /><br />'."\n".
216: &Apache::lonhtmlcommon::row_closure();
217: $num ++;
218: $i = $num%2;
219: }
220: $output .= &Apache::lonhtmlcommon::row_title("$lt{'unme'}/$lt{'doma'}",undef,$css[$i]);
1.44 raeburn 221: my $udom_input = '<input type="hidden" name="udom" value="'.
222: &HTML::Entities::encode($udom,'"<>&').'" />';
223: my $uname_input = '<input type="hidden" name="uname" value="'.
224: &HTML::Entities::encode($uname,'"<>&').'" />';
1.60 raeburn 225: if (($env{'user.name'} =~ /^$match_username$/) &&
226: ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
1.44 raeburn 227: $output .= '<i>'.$lt{'unme'}.'</i>: '.$uname.' <i>'.$lt{'doma'}.'</i>: '.$udom.$udom_input.$uname_input;
1.1 raeburn 228: } else {
229: my $udomform = '';
230: my $unameform = '';
1.60 raeburn 231: if (($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
1.44 raeburn 232: $output .= $lt{'entu'};
1.60 raeburn 233: } elsif (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
1.44 raeburn 234: $output .= $lt{'chdo'};
235: } else {
236: $output .= $lt{'entr'};
237: }
238: $output .= '<br />';
1.60 raeburn 239: if (!$public) {
240: if ($env{'user.domain'} =~ /^$match_domain$/) {
241: $udomform = '<i>'.$lt{'doma'}.'</i>: '.$udom.$udom_input;
242: } elsif ($env{'user.name'} =~ /^$match_username$/) {
243: $unameform = '<i>'.$lt{'unme'}.'</i>: '.$uname.' '.$uname_input;
244: }
1.1 raeburn 245: }
246: if ($udomform eq '') {
1.40 raeburn 247: $udomform = '<i>'.$lt{'doma'}.'</i>: ';
1.19 raeburn 248: $udomform .= &Apache::loncommon::select_dom_form($codedom,'udom');
1.1 raeburn 249: }
250: if ($unameform eq '') {
1.60 raeburn 251: $unameform= '<i>'.$lt{'unme'}.'</i>: <input type="text" size="20" name="uname" value="'.$uname.'" /> ';
1.1 raeburn 252: }
1.44 raeburn 253: $output .= $unameform.$udomform;
1.1 raeburn 254: }
1.50 raeburn 255: $output .= &Apache::lonhtmlcommon::row_closure();
256: $num ++;
257: $i = $num%2;
258: $output .= &Apache::lonhtmlcommon::row_title("$lt{'urlp'}",undef,$css[$i]).
1.44 raeburn 259: $showserver.'<input type="hidden" name="sourceurl" value="'.
260: &HTML::Entities::encode($server,'"<>&').'" />'.
261: &Apache::lonhtmlcommon::row_closure().
1.66.6.1! raeburn 262: $num ++;
! 263: $i = $num%2;
! 264: $output .= &Apache::lonhtmlcommon::row_title("$lt{'phon'}",undef,
! 265: 'LC_evenrow_value').
1.44 raeburn 266: '<input type="text" size="15" name="phone" /><br />'.
1.50 raeburn 267: &Apache::lonhtmlcommon::row_closure();
268: $num ++;
269: $i = $num%2;
270: $output .= &Apache::lonhtmlcommon::row_title($lt{'subj'},undef,'LC_oddrow_value').
1.44 raeburn 271: ' <input type="text" size="40" name="subject" />'."\n".
272: &Apache::lonhtmlcommon::row_closure().
1.46 raeburn 273: &Apache::lonhtmlcommon::row_title($lt{'detd'},undef,'LC_evenrow_value').
1.44 raeburn 274: ' <textarea rows="10" cols="45" name="description" wrap="virtual"></textarea>'.
275: &Apache::lonhtmlcommon::row_closure();
1.50 raeburn 276: $num ++;
277: $i = $num%2;
1.60 raeburn 278: if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
1.50 raeburn 279: $output .= &Apache::lonhtmlcommon::row_title($lt{'opfi'},undef,$css[$i]).
1.44 raeburn 280: ' <input type="file" name="screenshot" size="20" /><br />'.$lt{'uplf'}."\n".
281: &Apache::lonhtmlcommon::row_closure();
1.50 raeburn 282: $num ++;
283: $i = $num%2;
1.5 raeburn 284: }
1.50 raeburn 285: $output .= &Apache::lonhtmlcommon::row_title($lt{'fini'},undef,$css[$i]);
1.44 raeburn 286: $output .= <<END;
1.1 raeburn 287: <table border="0" cellpadding="8" cellspacing="0">
288: <tr>
289: <td>
1.44 raeburn 290: <input type="hidden" name="command" value="process" />
291: <input type="button" value="$lt{'subm'}" onclick="validate()" />
1.1 raeburn 292: </td>
293: <td> </td>
294: <td>
1.44 raeburn 295: <input type="reset" value="$lt{'clfm'}" />
1.1 raeburn 296: </td>
297: </tr>
298: </table>
1.44 raeburn 299: END
300: $output .= &Apache::lonhtmlcommon::row_closure(1);
301: $output .= &Apache::lonhtmlcommon::end_pick_box();
302: $r->print(<<END);
303: $output
1.14 raeburn 304: </form>
1.44 raeburn 305: <br />
1.1 raeburn 306: END
1.30 albertel 307: $r->print(&Apache::loncommon::end_page());
1.5 raeburn 308: return;
1.1 raeburn 309: }
310:
311: sub print_request_receipt {
312: my ($r,$url,$function) = @_;
1.26 raeburn 313: my @ENVvars = ('HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME');
314: my @envvars = ('browser.os','browser.type','browser.version','user.home','request.role');
1.5 raeburn 315: my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');
1.27 raeburn 316: my @cookievars = ('lonID');
1.5 raeburn 317:
318: my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
1.45 raeburn 319: my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
320: my $defdom = &get_domain();
321: my $to = &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
322: $defdom,$origmail);
1.5 raeburn 323: my $from = $admin;
1.56 raeburn 324: my $bcc;
325: my %domconfig =
326: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
327: if (ref($domconfig{'contacts'}) eq 'HASH') {
328: if (exists($domconfig{'contacts'}{'helpdeskmail'})) {
329: if (ref($domconfig{'contacts'}{'helpdeskmail'}) eq 'HASH') {
330: my $bccmail = $domconfig{'contacts'}{'helpdeskmail'}{'bcc'};
331: if ($bccmail ne '') {
332: my @bccs = split(/,/,$bccmail);
333: my @ok_bccs;
334: foreach my $bcc (@bccs) {
335: $bcc =~ s/^\s+//g;
336: $bcc =~ s/\s+$//g;
337: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
338: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
339: push(@ok_bccs,$bcc);
340: }
341: }
342: }
343: if (@ok_bccs > 0) {
344: $bcc = join(', ',@ok_bccs);
345: }
346: }
347: }
348: }
349: }
1.1 raeburn 350: my $reporttime = &Apache::lonlocal::locallocaltime(time);
1.66.6.1! raeburn 351: my @formvars = ('username','email','uname','udom','sourceurl','phone',
! 352: 'subject','description','screenshot');
1.1 raeburn 353: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);
1.40 raeburn 354: my %lt = &Apache::lonlocal::texthash (
1.44 raeburn 355: username => 'Name',
1.52 schafran 356: email => 'E-mail',
1.46 raeburn 357: cc => 'Cc',
1.44 raeburn 358: user => 'Username/domain',
359: phone => 'Phone',
360: subject => 'Subject',
361: description => 'Description',
362: sourceurl => 'URL',
363: date => 'Date/Time',
364: warn => 'Warning: Problem with support e-mail address',
365: your => 'Your support request contained the following information',
366: info => 'Information supplied',
367: adin => 'Additional information recorded',
1.40 raeburn 368: );
1.46 raeburn 369:
370: my (@ok_ccs,@bad_ccs,$badccmsg,$okcclist);
1.50 raeburn 371: if ((defined($env{'user.name'})) && (defined($env{'form.cc'}))) {
1.46 raeburn 372: my @ccs;
373: if ($env{'form.cc'} =~ /,/) {
374: @ccs = split(/,/,$env{'form.cc'});
375: } else {
376: $env{'form.cc'} =~ s/^\s+//;
377: $env{'form.cc'} =~ s/\s+$//;
378: @ccs = $env{'form.cc'};
379: }
380: foreach my $cc (@ccs) {
381: $cc =~ s/^\s+//g;
382: $cc =~ s/\s+$//g;
383: if ($cc =~ m/^[^\@]+\@[^\@]+$/) {
384: if (!(grep(/^\Q$cc\E$/,@ok_ccs))) {
385: push(@ok_ccs,$cc);
386: }
1.57 raeburn 387: } elsif ($cc ne '') {
1.46 raeburn 388: if (!(grep(/^\Q$cc\E$/,@bad_ccs))) {
389: push(@bad_ccs,$cc);
390: }
391: }
392: }
393: if (@ok_ccs > 0) {
394: $okcclist = join(', ',@ok_ccs);
395: }
396: if (@bad_ccs == 1) {
397: $badccmsg .= '<br />'.&mt('The following Cc e-mail address is invalid: ').$bad_ccs[0];
398: } elsif (@bad_ccs > 1) {
399: my $bad_cc_string = join(', ',@bad_ccs);
400: $badccmsg .= '<br />'.&mt('The following Cc e-mail addresses are invalid: ').$bad_cc_string;
401: }
402: }
1.44 raeburn 403: $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'";
404: my $supportmsg = <<END;
405: $lt{'username'}: $env{'form.username'}
1.40 raeburn 406: $lt{'email'}: $env{'form.email'}
1.46 raeburn 407: $lt{'cc'}: $okcclist
1.44 raeburn 408: $lt{'user'}: $env{'form.user'}
409: $lt{'phone'}: $env{'form.phone'}
410: $lt{'subject'}: $env{'form.subject'}
411: $lt{'description'}: $env{'form.description'}
412: $lt{'sourceurl'}: $env{'form.sourceurl'}
1.40 raeburn 413: $lt{'date'}: $reporttime
1.1 raeburn 414:
1.44 raeburn 415: END
416: my $displaymsg;
1.66.6.1! raeburn 417: foreach my $item ('username','email','cc','user','phone','subject',
! 418: 'description','sourceurl') {
1.44 raeburn 419: if ($env{'form.'.$item} ne '') {
420: if ($item eq 'description') {
421: my $descrip = $env{'form.description'};
1.54 raeburn 422: $descrip = &cleanup_html($descrip);
423: $descrip =~ s|[\n\r\f]|<br />|g;
1.44 raeburn 424: $displaymsg .=
425: '<span class="LC_helpform_receipt_cat">'.
426: "$lt{$item}</span>: $descrip<br />\n";
427: } elsif ($item eq 'sourceurl') {
428: my $showurl = $env{'form.sourceurl'};
429: $showurl =~ s/\?.*$//;
1.54 raeburn 430: $showurl = &cleanup_html($showurl);
1.44 raeburn 431: $displaymsg .=
432: '<span class="LC_helpform_receipt_cat">'.
433: "$lt{$item}</span>: $showurl<br />\n";
1.46 raeburn 434: } elsif ($item eq 'cc') {
435: $displaymsg .=
436: '<span class="LC_helpform_receipt_cat">'.
437: "$lt{$item}</span>: $okcclist<br />\n";
1.44 raeburn 438: } else {
1.54 raeburn 439: my $showitem = $env{'form.'.$item};
440: $showitem = &cleanup_html($showitem);
1.44 raeburn 441: $displaymsg .=
442: '<span class="LC_helpform_receipt_cat">'.
1.54 raeburn 443: "$lt{$item}</span>: $showitem<br />\n";
1.44 raeburn 444: }
445: }
446: }
447: $displaymsg .= '<span class="LC_helpform_receipt_cat">'.
448: $lt{'date'}.'</span>: '.$reporttime.'<br />'."\n";
1.32 albertel 449:
450: my $start_page =
451: &Apache::loncommon::start_page('Support request recorded',undef,
1.33 albertel 452: {'function' => $function,
453: 'add_entries' => {
454: topmargin => "0",
455: marginheight => "0",
456: },
457: 'only_body' => 1,});
1.32 albertel 458:
1.14 raeburn 459: $r->print(<<"END");
1.32 albertel 460: $start_page
1.16 raeburn 461: <form name="logproblem">
1.44 raeburn 462: <input type="hidden" name="command" value="result" />
1.16 raeburn 463: </form>
1.1 raeburn 464: END
1.14 raeburn 465: if ($r->uri eq '/adm/helpdesk') {
466: &print_header($r,$url,'process');
467: }
1.45 raeburn 468: my $bad_email = 0;
469: if ($to =~ /,/) {
470: my @ok_email;
471: foreach my $email (split(/,/,$to)) {
472: if ($email =~ m/^[^\@]+\@[^\@]+$/) {
1.46 raeburn 473: if (!grep(/^\Q$email\E$/,@ok_email)) {
474: push(@ok_email,$email);
475: }
1.45 raeburn 476: }
477: }
478: if (@ok_email > 0) {
479: $to = join(',',@ok_email);
480: } elsif ($admin =~ m/^[^\@]+\@[^\@]+$/) {
481: $to = $admin;
482: } else {
483: $bad_email = 1;
484: }
485: } elsif ($to !~ m/^[^\@]+\@[^\@]+$/) {
486: if ($admin =~ m/^[^\@]+\@[^\@]+$/) {
487: $to = $admin;
1.9 raeburn 488: } else {
1.45 raeburn 489: $bad_email = 1;
490: }
491: }
1.66 bisitz 492:
493: my $message;
494: if (!$bad_email) {
495: $message = &Apache::lonhtmlcommon::confirm_success(
496: &mt('A support request has been sent to [_1]','<tt>'.$to.'</tt>'));
497: } else {
498: $message = &Apache::lonhtmlcommon::confirm_success(
499: $lt{'warn'}.'<br />'
500: .&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>')
501: .' '.&mt('Instead a copy has been sent to the LON-CAPA support team at Michigan State University.'),1);
502: $to = 'helpdesk@lon-capa.org';
1.1 raeburn 503: }
1.66 bisitz 504: $r->print(&Apache::loncommon::confirmwrapper($message));
505:
1.25 albertel 506: if (defined($env{'form.email'})) {
1.46 raeburn 507: $env{'form.email'} =~ s/^\s+//;
508: $env{'form.email'} =~ s/\s+$//;
1.25 albertel 509: if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
510: $from = $env{'form.email'};
1.5 raeburn 511: }
512: }
513:
1.46 raeburn 514: if (defined($env{'form.cc'})) {
515: if ($badccmsg) {
516: $displaymsg .= $badccmsg;
517: }
518: }
519:
1.25 albertel 520: my $subject = $env{'form.subject'};
1.44 raeburn 521: $subject =~ s/(`)/'/g;
522: $subject =~ s/\$/\(\$\)/g;
523: $supportmsg =~ s/(`)/'/g;
524: $supportmsg =~ s/\$/\(\$\)/g;
525: $displaymsg =~ s/(`)/'/g;
526: $displaymsg =~ s/\$/\(\$\)/g;
1.5 raeburn 527: my $fname;
528:
529: my $attachmentpath = '';
530: my $attachmentsize = '';
1.56 raeburn 531: if ((defined($env{'user.name'})) && ($env{'user.name'} ne 'public')
532: && ($env{'user.domain'} ne 'public')) {
1.25 albertel 533: if ($env{'form.screenshot.filename'}) {
534: $attachmentsize = length($env{'form.screenshot'});
1.5 raeburn 535: if ($attachmentsize > 131072) {
1.40 raeburn 536: $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);
1.5 raeburn 537: } else {
538: $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
539: }
540: }
541: }
542:
1.40 raeburn 543: my %cookies;
1.27 raeburn 544: my $cookie=CGI::Cookie->parse($r->header_in('Cookie'));
1.39 albertel 545: if ($$cookie{'lonID'} =~ /lonID=($LONCAPA::handle_re);/) {
1.27 raeburn 546: $cookies{'lonID'} = $1;
547: }
548:
1.5 raeburn 549: if ($attachmentpath =~ m-/([^/]+)$-) {
550: $fname = $1;
1.51 bisitz 551: $displaymsg .= '<br />'
552: .&mt('An uploaded screenshot file [_1] ([_2] bytes) was included in the request sent by [_3].'
1.66 bisitz 553: ,'<span class="LC_filename">'.$fname.'</span>'
1.51 bisitz 554: ,$attachmentsize
555: ,$env{'user.name'}.':'.$env{'user.domain'}
556: );
1.5 raeburn 557: $supportmsg .= "\n";
1.40 raeburn 558: foreach my $var (@cookievars) {
559: $supportmsg .= "$var: $cookies{$var}\n";
1.27 raeburn 560: }
1.40 raeburn 561: foreach my $var(@ENVvars) {
562: $supportmsg .= "$var: $ENV{$var}\n";
1.26 raeburn 563: }
1.40 raeburn 564: foreach my $var (@envvars) {
565: $supportmsg .= "$var: $env{$var}\n";
1.5 raeburn 566: }
567: }
568:
569: my $msg = MIME::Lite->new(
570: From => $from,
571: To => $to,
572: Subject => $subject,
573: Type =>'TEXT',
574: Data => $supportmsg,
575: );
1.46 raeburn 576: if (@ok_ccs > 0) {
577: my $cc_string = join(', ',@ok_ccs);
578: $msg->add("Cc" => $cc_string);
579: }
1.56 raeburn 580: if ($bcc ne '') {
581: $msg->add("Bcc" => $bcc);
582: }
1.65 raeburn 583: $msg->attr("content-type" => "text/plain");
584: $msg->attr("content-type.charset" => "UTF-8");
1.5 raeburn 585:
586: if ($attachmentpath) {
587: my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath);
588: $msg->attach(Type => $type,
589: Path => $attachmentpath,
590: Filename => $fname
591: );
592:
593: } else {
594: my $envdata = '';
1.40 raeburn 595: foreach my $var (@cookievars) {
596: $envdata .= "$var: $cookies{$var}\n";
1.27 raeburn 597: }
1.40 raeburn 598: foreach my $var (@ENVvars) {
599: $envdata .= "$var: $ENV{$var}\n";
1.26 raeburn 600: }
1.40 raeburn 601: foreach my $var (@envvars) {
602: $envdata .= "$var: $env{$var}\n";
1.5 raeburn 603: }
1.40 raeburn 604: foreach my $var (@loncvars) {
605: $envdata .= "$var: $env{$var}\n";
1.5 raeburn 606: }
607: $msg->attach(Type => 'TEXT',
608: Data => $envdata);
609: }
610:
611: ### Send it:
612: $msg->send('sendmail');
613:
1.44 raeburn 614: if ($attachmentpath =~ m|$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+|) {
1.5 raeburn 615: unlink($attachmentpath);
616: }
1.44 raeburn 617: $r->print('<b>'.$lt{'your'}.'</b>:<br /><br />'."\n");
1.55 bisitz 618: $r->print('<div style="width:620px;">'.
619: &Apache::lonhtmlcommon::start_pick_box().
1.44 raeburn 620: &Apache::lonhtmlcommon::row_title($lt{'info'},undef,'LC_oddrow_value')."\n".$displaymsg."\n".
621: &Apache::lonhtmlcommon::row_closure().
622: &Apache::lonhtmlcommon::row_title($lt{'adin'},undef,'LC_evenrow_value'));
623: my $envmsg;
1.40 raeburn 624: foreach my $var (@cookievars) {
1.44 raeburn 625: if ($cookies{$var} ne '') {
626: $envmsg.= '<span class="LC_helpform_receipt_cat">'.
627: $var.'</span>: '.$cookies{$var}.', ';
1.27 raeburn 628: }
629: }
1.40 raeburn 630: foreach my $var (@ENVvars) {
1.44 raeburn 631: if ($ENV{$var} ne '') {
632: $envmsg .= '<span class="LC_helpform_receipt_cat">'.
633: $var.'</span>: '.$ENV{$var}.', ';
1.26 raeburn 634: }
635: }
1.40 raeburn 636: foreach my $var (@envvars) {
1.44 raeburn 637: if ($env{$var} ne '') {
638: $envmsg .= '<span class="LC_helpform_receipt_cat">'.
639: $var.'</span>: '.$env{$var}.', ';
1.5 raeburn 640: }
1.1 raeburn 641: }
1.44 raeburn 642: $envmsg =~ s/, $//;
643: $r->print($envmsg."\n".
644: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.55 bisitz 645: &Apache::lonhtmlcommon::end_pick_box().
646: "</div>\n".
1.44 raeburn 647: &Apache::loncommon::end_page());
1.1 raeburn 648: }
649:
1.14 raeburn 650: sub print_header {
1.44 raeburn 651: my ($r,$origurl,$command) = @_;
1.14 raeburn 652: my $location=&Apache::loncommon::lonhttpdurl("/adm");
653: my ($component_url);
654: my $helpdesk_link = '<a href="javascript:validate()">';
1.44 raeburn 655: if ($command eq 'process') {
1.14 raeburn 656: $helpdesk_link = '<a href="/adm/helpdesk">';
657: }
658: my %lt = &Apache::lonlocal::texthash (
659: login => 'Log-in help',
660: ask => 'Ask helpdesk',
661: getst => 'Getting started guide',
1.47 bisitz 662: back => 'Back to last location',
663: headline => 'help/support',
1.21 raeburn 664: );
1.47 bisitz 665: my ($getstartlink,$reviewtext);
1.21 raeburn 666: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/gettingstarted.html') {
667: $getstartlink = qq|<td align="center"> <b><a href="/adm/gettingstarted.html">$lt{'getst'}</a></td>|;
1.47 bisitz 668: $reviewtext = &mt('Please review the information in "Log-in help" and the "Getting started" guide if you are unable to log-in.');
669: } else {
670: $reviewtext = &mt('Please review the information in "Log-in help" if you are unable to log-in.');
1.21 raeburn 671: }
1.59 raeburn 672: if ($origurl eq '') {
673: $origurl = 'javascript:history.go(-1)';
674: }
1.14 raeburn 675: $r->print(<<END);
676: <table width="620" border="0" cellspacing="0" cellpadding="0" height="55"> <tr height="50"> <td width='5'> </td>
677: <td>
1.53 bisitz 678: <fieldset>
679: <legend>
680: <img src="$location/lonIcons/minilogo.gif" height="20" width="29" valign="bottom" />
681: LON-CAPA $lt{'headline'}
682: </legend>
1.44 raeburn 683: <table id="LC_helpmenu_links">
684: <tr>
1.49 raeburn 685: <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>
1.44 raeburn 686: <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
687: <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>
688: </tr>
1.14 raeburn 689: </table>
690: </fieldset>
691: </td>
692: <td width='5'> </td>
693: </tr>
694: <tr height='5'>
695: <td colspan='3' height='5'> </td>
696: </tr>
697: END
1.44 raeburn 698: if ($command ne 'process') {
1.14 raeburn 699: $r->print('
700: <tr>
1.47 bisitz 701: <td colspan="3">'.$reviewtext.' '
702: .&mt('If your problem is still unresolved, the form below can be used to send a question to the LON-CAPA helpdesk.').'<br />'
703: .'<font size="-1"><b>'.&mt('Students').'</b>: '.&mt('Do <b>not</b> use this form to ask questions about course content.').' '
704: .&mt('Contact your instructor instead.')
705: .'</font><br /><br />
1.14 raeburn 706: </td>
707: </tr>');
708: }
709: $r->print('
710: </table>');
711: return;
712: }
713:
1.45 raeburn 714: sub get_domain {
715: my $codedom;
716: if (exists($env{'form.codedom'})) {
717: $codedom = $env{'form.codedom'};
718: } elsif ($env{'request.course.id'}) {
719: $codedom = $env{'course.'.$env{'request.course.id'}.'.domain'};
720: } elsif ($env{'request.role.domain'}) {
721: $codedom = $env{'request.role.domain'};
722: } else {
1.54 raeburn 723: $codedom = &Apache::lonnet::default_login_domain();
1.45 raeburn 724: }
725: return $codedom;
726: }
727:
1.54 raeburn 728: sub cleanup_html {
729: my ($incoming) = @_;
730: my $outgoing;
731: if ($incoming ne '') {
732: $outgoing = $incoming;
733: $outgoing =~ s/\#/#/g;
734: $outgoing =~ s/\&/&/g;
735: $outgoing =~ s/</</g;
736: $outgoing =~ s/>/>/g;
737: $outgoing =~ s/\(/(/g;
738: $outgoing =~ s/\)/)/g;
739: $outgoing =~ s/"/"/g;
740: $outgoing =~ s/'/'/g;
741: $outgoing =~ s/\$/$/g;
742: }
743: return $outgoing;
744: }
745:
1.1 raeburn 746: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>