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