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