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