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