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