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