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