Annotation of loncom/interface/lonsupportreq.pm, revision 1.55.4.1
1.24 albertel 1: #
1.55.4.1! raeburn 2: # $Id: lonsupportreq.pm,v 1.55 2009/10/22 13:41:41 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'};
1.54 raeburn 569: $descrip = &cleanup_html($descrip);
570: $descrip =~ s|[\n\r\f]|<br />|g;
1.44 raeburn 571: $displaymsg .=
572: '<span class="LC_helpform_receipt_cat">'.
573: "$lt{$item}</span>: $descrip<br />\n";
574: } elsif ($item eq 'sourceurl') {
575: my $showurl = $env{'form.sourceurl'};
576: $showurl =~ s/\?.*$//;
1.54 raeburn 577: $showurl = &cleanup_html($showurl);
1.44 raeburn 578: $displaymsg .=
579: '<span class="LC_helpform_receipt_cat">'.
580: "$lt{$item}</span>: $showurl<br />\n";
1.46 raeburn 581: } elsif ($item eq 'cc') {
582: $displaymsg .=
583: '<span class="LC_helpform_receipt_cat">'.
584: "$lt{$item}</span>: $okcclist<br />\n";
1.44 raeburn 585: } else {
1.54 raeburn 586: my $showitem = $env{'form.'.$item};
587: $showitem = &cleanup_html($showitem);
1.44 raeburn 588: $displaymsg .=
589: '<span class="LC_helpform_receipt_cat">'.
1.54 raeburn 590: "$lt{$item}</span>: $showitem<br />\n";
1.44 raeburn 591: }
592: }
593: }
594: $displaymsg .= '<span class="LC_helpform_receipt_cat">'.
595: $lt{'date'}.'</span>: '.$reporttime.'<br />'."\n";
1.32 albertel 596:
597: my $start_page =
598: &Apache::loncommon::start_page('Support request recorded',undef,
1.33 albertel 599: {'function' => $function,
600: 'add_entries' => {
601: topmargin => "0",
602: marginheight => "0",
603: },
604: 'only_body' => 1,});
1.32 albertel 605:
1.14 raeburn 606: $r->print(<<"END");
1.32 albertel 607: $start_page
1.16 raeburn 608: <form name="logproblem">
1.44 raeburn 609: <input type="hidden" name="command" value="result" />
1.16 raeburn 610: </form>
1.1 raeburn 611: END
1.14 raeburn 612: if ($r->uri eq '/adm/helpdesk') {
613: &print_header($r,$url,'process');
614: }
1.45 raeburn 615: my $bad_email = 0;
616: if ($to =~ /,/) {
617: my @ok_email;
618: foreach my $email (split(/,/,$to)) {
619: if ($email =~ m/^[^\@]+\@[^\@]+$/) {
1.46 raeburn 620: if (!grep(/^\Q$email\E$/,@ok_email)) {
621: push(@ok_email,$email);
622: }
1.45 raeburn 623: }
624: }
625: if (@ok_email > 0) {
626: $to = join(',',@ok_email);
627: } elsif ($admin =~ m/^[^\@]+\@[^\@]+$/) {
628: $to = $admin;
629: } else {
630: $bad_email = 1;
631: }
632: } elsif ($to !~ m/^[^\@]+\@[^\@]+$/) {
633: if ($admin =~ m/^[^\@]+\@[^\@]+$/) {
634: $to = $admin;
1.9 raeburn 635: } else {
1.45 raeburn 636: $bad_email = 1;
637: }
638: }
639: if ($bad_email) {
640: $r->print('
1.40 raeburn 641: <h3>'.$lt{'warn'}.'</h3>'.
642: &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 643: $to = 'helpdesk@lon-capa.org';
1.45 raeburn 644: } else {
645: $r->print('<h3>'.$lt{'asup'}.' '.$to.'</h3>');
1.1 raeburn 646: }
1.25 albertel 647: if (defined($env{'form.email'})) {
1.46 raeburn 648: $env{'form.email'} =~ s/^\s+//;
649: $env{'form.email'} =~ s/\s+$//;
1.25 albertel 650: if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
651: $from = $env{'form.email'};
1.5 raeburn 652: }
653: }
654:
1.46 raeburn 655: if (defined($env{'form.cc'})) {
656: if ($badccmsg) {
657: $displaymsg .= $badccmsg;
658: }
659: }
660:
1.25 albertel 661: my $subject = $env{'form.subject'};
1.44 raeburn 662: $subject =~ s/(`)/'/g;
663: $subject =~ s/\$/\(\$\)/g;
664: $supportmsg =~ s/(`)/'/g;
665: $supportmsg =~ s/\$/\(\$\)/g;
666: $displaymsg =~ s/(`)/'/g;
667: $displaymsg =~ s/\$/\(\$\)/g;
1.5 raeburn 668: my $fname;
669:
670: my $attachmentpath = '';
671: my $attachmentsize = '';
1.25 albertel 672: if (defined($env{'user.name'})) {
673: if ($env{'form.screenshot.filename'}) {
674: $attachmentsize = length($env{'form.screenshot'});
1.5 raeburn 675: if ($attachmentsize > 131072) {
1.40 raeburn 676: $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 677: } else {
678: $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
679: }
680: }
681: }
682:
1.40 raeburn 683: my %cookies;
1.27 raeburn 684: my $cookie=CGI::Cookie->parse($r->header_in('Cookie'));
1.39 albertel 685: if ($$cookie{'lonID'} =~ /lonID=($LONCAPA::handle_re);/) {
1.27 raeburn 686: $cookies{'lonID'} = $1;
687: }
688:
1.5 raeburn 689: if ($attachmentpath =~ m-/([^/]+)$-) {
690: $fname = $1;
1.51 bisitz 691: $displaymsg .= '<br />'
692: .&mt('An uploaded screenshot file [_1] ([_2] bytes) was included in the request sent by [_3].'
693: ,'<span class="LC_filename">'.$fname.'<span>'
694: ,$attachmentsize
695: ,$env{'user.name'}.':'.$env{'user.domain'}
696: );
1.5 raeburn 697: $supportmsg .= "\n";
1.40 raeburn 698: foreach my $var (@cookievars) {
699: $supportmsg .= "$var: $cookies{$var}\n";
1.27 raeburn 700: }
1.40 raeburn 701: foreach my $var(@ENVvars) {
702: $supportmsg .= "$var: $ENV{$var}\n";
1.26 raeburn 703: }
1.40 raeburn 704: foreach my $var (@envvars) {
705: $supportmsg .= "$var: $env{$var}\n";
1.5 raeburn 706: }
707: }
708:
709: my $msg = MIME::Lite->new(
710: From => $from,
711: To => $to,
712: Subject => $subject,
713: Type =>'TEXT',
714: Data => $supportmsg,
715: );
1.46 raeburn 716: if (@ok_ccs > 0) {
717: my $cc_string = join(', ',@ok_ccs);
718: $msg->add("Cc" => $cc_string);
719: }
1.5 raeburn 720:
721: if ($attachmentpath) {
722: my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath);
723: $msg->attach(Type => $type,
724: Path => $attachmentpath,
725: Filename => $fname
726: );
727:
728: } else {
729: my $envdata = '';
1.40 raeburn 730: foreach my $var (@cookievars) {
731: $envdata .= "$var: $cookies{$var}\n";
1.27 raeburn 732: }
1.40 raeburn 733: foreach my $var (@ENVvars) {
734: $envdata .= "$var: $ENV{$var}\n";
1.26 raeburn 735: }
1.40 raeburn 736: foreach my $var (@envvars) {
737: $envdata .= "$var: $env{$var}\n";
1.5 raeburn 738: }
1.40 raeburn 739: foreach my $var (@loncvars) {
740: $envdata .= "$var: $env{$var}\n";
1.5 raeburn 741: }
742: $msg->attach(Type => 'TEXT',
743: Data => $envdata);
744: }
745:
746: ### Send it:
747: $msg->send('sendmail');
748:
1.44 raeburn 749: if ($attachmentpath =~ m|$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+|) {
1.5 raeburn 750: unlink($attachmentpath);
751: }
1.44 raeburn 752: $r->print('<b>'.$lt{'your'}.'</b>:<br /><br />'."\n");
1.55 bisitz 753: $r->print('<div style="width:620px;">'.
754: &Apache::lonhtmlcommon::start_pick_box().
1.44 raeburn 755: &Apache::lonhtmlcommon::row_title($lt{'info'},undef,'LC_oddrow_value')."\n".$displaymsg."\n".
756: &Apache::lonhtmlcommon::row_closure().
757: &Apache::lonhtmlcommon::row_title($lt{'adin'},undef,'LC_evenrow_value'));
758: my $envmsg;
1.40 raeburn 759: foreach my $var (@cookievars) {
1.44 raeburn 760: if ($cookies{$var} ne '') {
761: $envmsg.= '<span class="LC_helpform_receipt_cat">'.
762: $var.'</span>: '.$cookies{$var}.', ';
1.27 raeburn 763: }
764: }
1.40 raeburn 765: foreach my $var (@ENVvars) {
1.44 raeburn 766: if ($ENV{$var} ne '') {
767: $envmsg .= '<span class="LC_helpform_receipt_cat">'.
768: $var.'</span>: '.$ENV{$var}.', ';
1.26 raeburn 769: }
770: }
1.40 raeburn 771: foreach my $var (@envvars) {
1.44 raeburn 772: if ($env{$var} ne '') {
773: $envmsg .= '<span class="LC_helpform_receipt_cat">'.
774: $var.'</span>: '.$env{$var}.', ';
1.5 raeburn 775: }
1.1 raeburn 776: }
1.44 raeburn 777: $envmsg =~ s/, $//;
778: $r->print($envmsg."\n".
779: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.55 bisitz 780: &Apache::lonhtmlcommon::end_pick_box().
781: "</div>\n".
1.44 raeburn 782: &Apache::loncommon::end_page());
1.1 raeburn 783: }
784:
1.14 raeburn 785: sub print_header {
1.44 raeburn 786: my ($r,$origurl,$command) = @_;
1.14 raeburn 787: my $location=&Apache::loncommon::lonhttpdurl("/adm");
788: my ($component_url);
789: my $helpdesk_link = '<a href="javascript:validate()">';
1.44 raeburn 790: if ($command eq 'process') {
1.14 raeburn 791: $helpdesk_link = '<a href="/adm/helpdesk">';
792: }
793: my %lt = &Apache::lonlocal::texthash (
794: login => 'Log-in help',
795: ask => 'Ask helpdesk',
796: getst => 'Getting started guide',
1.47 bisitz 797: back => 'Back to last location',
798: headline => 'help/support',
1.21 raeburn 799: );
1.47 bisitz 800: my ($getstartlink,$reviewtext);
1.21 raeburn 801: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/gettingstarted.html') {
802: $getstartlink = qq|<td align="center"> <b><a href="/adm/gettingstarted.html">$lt{'getst'}</a></td>|;
1.47 bisitz 803: $reviewtext = &mt('Please review the information in "Log-in help" and the "Getting started" guide if you are unable to log-in.');
804: } else {
805: $reviewtext = &mt('Please review the information in "Log-in help" if you are unable to log-in.');
1.21 raeburn 806: }
1.14 raeburn 807: $r->print(<<END);
808: <table width="620" border="0" cellspacing="0" cellpadding="0" height="55"> <tr height="50"> <td width='5'> </td>
809: <td>
1.53 bisitz 810: <fieldset>
811: <legend>
812: <img src="$location/lonIcons/minilogo.gif" height="20" width="29" valign="bottom" />
1.55.4.1! raeburn 813: <b>LON-CAPA $lt{'headline'}</b>
1.53 bisitz 814: </legend>
1.44 raeburn 815: <table id="LC_helpmenu_links">
816: <tr>
1.49 raeburn 817: <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 818: <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
819: <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>
820: </tr>
1.14 raeburn 821: </table>
822: </fieldset>
823: </td>
824: <td width='5'> </td>
825: </tr>
826: <tr height='5'>
827: <td colspan='3' height='5'> </td>
828: </tr>
829: END
1.44 raeburn 830: if ($command ne 'process') {
1.14 raeburn 831: $r->print('
832: <tr>
1.47 bisitz 833: <td colspan="3">'.$reviewtext.' '
834: .&mt('If your problem is still unresolved, the form below can be used to send a question to the LON-CAPA helpdesk.').'<br />'
835: .'<font size="-1"><b>'.&mt('Students').'</b>: '.&mt('Do <b>not</b> use this form to ask questions about course content.').' '
836: .&mt('Contact your instructor instead.')
837: .'</font><br /><br />
1.14 raeburn 838: </td>
839: </tr>');
840: }
841: $r->print('
842: </table>');
843: return;
844: }
845:
1.45 raeburn 846: sub get_domain {
847: my $codedom;
848: if (exists($env{'form.codedom'})) {
849: $codedom = $env{'form.codedom'};
850: } elsif ($env{'request.course.id'}) {
851: $codedom = $env{'course.'.$env{'request.course.id'}.'.domain'};
852: } elsif ($env{'request.role.domain'}) {
853: $codedom = $env{'request.role.domain'};
854: } else {
1.54 raeburn 855: $codedom = &Apache::lonnet::default_login_domain();
1.45 raeburn 856: }
857: return $codedom;
858: }
859:
1.54 raeburn 860: sub cleanup_html {
861: my ($incoming) = @_;
862: my $outgoing;
863: if ($incoming ne '') {
864: $outgoing = $incoming;
865: $outgoing =~ s/\#/#/g;
866: $outgoing =~ s/\&/&/g;
867: $outgoing =~ s/</</g;
868: $outgoing =~ s/>/>/g;
869: $outgoing =~ s/\(/(/g;
870: $outgoing =~ s/\)/)/g;
871: $outgoing =~ s/"/"/g;
872: $outgoing =~ s/'/'/g;
873: $outgoing =~ s/\$/$/g;
874: }
875: return $outgoing;
876: }
877:
1.1 raeburn 878: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>