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