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