Annotation of loncom/interface/lonsupportreq.pm, revision 1.55.6.4
1.24 albertel 1: #
1.55.6.4! raeburn 2: # $Id: lonsupportreq.pm,v 1.55.6.3 2010/12/02 23:18:37 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.55.6.3 raeburn 40: use LONCAPA qw(:DEFAULT :match);
1.1 raeburn 41:
42: sub handler {
1.2 albertel 43: my ($r) = @_;
44: &Apache::loncommon::content_type($r,'text/html');
1.1 raeburn 45: $r->send_http_header;
46:
47: if ($r->header_only) {
48: return OK;
49: }
1.42 albertel 50: if ($r->uri eq '/adm/helpdesk') {
51: &Apache::lonlocal::get_language_handle($r);
52: }
53:
1.12 raeburn 54: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['origurl','function']);
55: if ($r->uri eq '/adm/helpdesk') {
1.34 albertel 56: &Apache::lonacc::get_posted_cgi($r);
1.12 raeburn 57: }
1.25 albertel 58: my $function = $env{'form.function'};
1.55.6.3 raeburn 59: my $origurl = $env{'form.origurl'};
1.44 raeburn 60: my $command = $env{'form.command'};
1.12 raeburn 61:
1.44 raeburn 62: if ($command eq 'process') {
1.1 raeburn 63: &print_request_receipt($r,$origurl,$function);
64: } else {
65: &print_request_form($r,$origurl,$function);
66: }
67: return OK;
68: }
69:
70: sub print_request_form {
71: my ($r,$origurl,$function) = @_;
1.55.6.3 raeburn 72: my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$urole,$usec,$email,$cid,
73: $cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server,
74: $formname,$public);
1.44 raeburn 75: $function = &Apache::loncommon::get_users_function() if (!$function);
1.10 raeburn 76: $ccode = '';
1.25 albertel 77: $os = $env{'browser.os'};
78: $browser = $env{'browser.type'};
79: $bversion = $env{'browser.version'};
80: $uhost = $env{'request.host'};
1.55.6.3 raeburn 81: if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
82: $public = 1;
83: } else {
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.55.6.3 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.55.6.4! raeburn 246: $loaditems.'</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.55.6.3 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.55.6.3 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.55.6.3 raeburn 305: if (($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
1.44 raeburn 306: $output .= $lt{'entu'};
1.55.6.3 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.55.6.3 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.55.6.3 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,'"<>&').'" />'.
1.50 raeburn 335: &Apache::lonhtmlcommon::row_closure();
1.55.6.1 raeburn 336: if (&Apache::loncommon::check_for_gci_dc()) {
337: $output .= &Apache::lonhtmlcommon::row_title("$lt{'phon'}",undef,
338: 'LC_evenrow_value').
339: '<input type="text" size="15" name="phone" /><br />'.
340: &Apache::lonhtmlcommon::row_closure();
341: $num ++;
342: $i = $num%2;
343: $output .= &Apache::lonhtmlcommon::row_title("$lt{'crsd'}$details_title",undef,$css[$i]);
344: if ($cnum) {
345: if ($coursecodes{$cnum}) {
346: foreach my $item (@codetitles) {
347: $output .= '<i>'.$item.'</i>: '.$codes{$cnum}{$item}.'; ';
348: }
349: $output .= ' <input type="hidden" name="coursecode" value="'.&HTML::Entities::encode($coursecodes{$cnum},'"<>&').'" />';
350: } else {
351: $output .= $lt{'enin'}.':
352: <input type="text" name="coursecode" size="15" value="" />';
1.10 raeburn 353: }
354: } else {
1.55.6.1 raeburn 355: if ($totcodes > 0) {
356: my $numtitles = @codetitles;
357: if ($numtitles == 0) {
358: $output .= $lt{'enin'}.':
359: <input type="text" name="coursecode" size="15" value="" />';
1.10 raeburn 360: } else {
1.55.6.1 raeburn 361: my $lasttitle = $numtitles;
362: if ($numtitles > 4) {
363: $lasttitle = 4;
364: }
365: $output .= '<table><tr><td>'.$codetitles[0].'<br />'."\n".
366: '<select name="'.$codetitles[0].'" onchange="courseSet('."'$codetitles[0]'".')">'."\n".
367: ' <option value="-1" />'.$lt{'sele'}."\n";
368: my @items = ();
369: my @longitems = ();
370: if ($idlist{$codetitles[0]} =~ /","/) {
371: @items = split(/","/,$idlist{$codetitles[0]});
1.20 raeburn 372: } else {
1.55.6.1 raeburn 373: $items[0] = $idlist{$codetitles[0]};
1.20 raeburn 374: }
1.55.6.1 raeburn 375: if (defined($idlist_titles{$codetitles[0]})) {
376: if ($idlist_titles{$codetitles[0]} =~ /","/) {
377: @longitems = split(/","/,$idlist_titles{$codetitles[0]});
378: } else {
379: $longitems[0] = $idlist_titles{$codetitles[0]};
1.22 raeburn 380: }
1.55.6.1 raeburn 381: for (my $i=0; $i<@longitems; $i++) {
382: if ($longitems[$i] eq '') {
383: $longitems[$i] = $items[$i];
384: }
385: }
386: } else {
387: @longitems = @items;
388: }
389: for (my $i=0; $i<@items; $i++) {
390: $output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>'."\n";
391: }
392: $output .= '</select></td>';
393: for (my $i=1; $i<$numtitles; $i++) {
394: $output .= '<td>'.$codetitles[$i].'<br />'."\n".
395: '<select name="'.$codetitles[$i].'" onchange="courseSet('."'$codetitles[$i]'".')">'."\n".
396: '<option value="-1"><-'.$lt{'pick'}.' '.$codetitles[$i-1].'</option>'."\n".
397: '</select>'."\n".
398: '</td>'."\n";
399: }
400: $output .= '</tr></table>';
401: if ($numtitles > 4) {
402: $output .= '<br /><br />'.$codetitles[$numtitles].'<br />'."\n".
403: '<select name="'.$codetitles[$numtitles].'" onchange="courseSet('."'$codetitles[$numtitles]'".')">'."\n".
404: '<option value="-1"><-'.$lt{'pick'}.' '.$codetitles[$numtitles-1].'</option>'."\n".
405: '</select>'."\n";
1.22 raeburn 406: }
1.10 raeburn 407: }
1.55.6.1 raeburn 408: } else {
409: $output .= $lt{'enin'}.':
410: <input type="text" name="coursecode" size="15" value="" />';
1.10 raeburn 411: }
1.55.6.1 raeburn 412: }
413: $output .= '<br />';
414: if ($ctitle) {
415: $output .= '<i>'.$lt{'titl'}.'</i>: '.$ctitle.
416: '<input type="hidden" name="title" value="'.
417: &HTML::Entities::encode($ctitle,'"<>&').'" />'."\n";
1.10 raeburn 418: } else {
1.55.6.1 raeburn 419: $output .= $lt{'enct'}.':
420: <input type="text" name="title" size="25" value="" />'."\n";
1.10 raeburn 421: }
1.55.6.1 raeburn 422: $output .= &Apache::lonhtmlcommon::row_closure();
423: $num ++;
424: $i = $num%2;
425: $output .= &Apache::lonhtmlcommon::row_title($lt{'secn'},undef,$css[$i]);
426: if ($sectionlist) {
427: $output .= "<select name=\"section\"\n>".
428: " <option value=\"\" selected=\"selected\">$lt{'sele'}</option>\n";
429: foreach my $id (sort(keys(%groupid))) {
430: if ($id eq $groupid{$id} || $groupid{$id} eq '') {
431: $output .= " <option value=".
432: &HTML::Entities::encode($id,'"<>&').
433: " >$id</option>\n";
434: } else {
435: $output .= " <option value=".
436: &HTML::Entities::encode($id,'"<>&').
437: " >$id - ($lt{'lsec'}: $groupid{$id})</option>\n";
438: }
1.1 raeburn 439: }
1.55.6.1 raeburn 440: $output .= "</select>";
441: } else {
442: $output .= '<input type="text" name="section" size="10" />';
1.1 raeburn 443: }
1.55.6.1 raeburn 444: $output .= &Apache::lonhtmlcommon::row_closure();
1.1 raeburn 445: }
1.50 raeburn 446: $num ++;
1.55.6.1 raeburn 447: $i = $num%2;
1.50 raeburn 448: $output .= &Apache::lonhtmlcommon::row_title($lt{'subj'},undef,'LC_oddrow_value').
1.44 raeburn 449: ' <input type="text" size="40" name="subject" />'."\n".
450: &Apache::lonhtmlcommon::row_closure().
1.46 raeburn 451: &Apache::lonhtmlcommon::row_title($lt{'detd'},undef,'LC_evenrow_value').
1.44 raeburn 452: ' <textarea rows="10" cols="45" name="description" wrap="virtual"></textarea>'.
453: &Apache::lonhtmlcommon::row_closure();
1.50 raeburn 454: $num ++;
455: $i = $num%2;
1.55.6.3 raeburn 456: if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
1.50 raeburn 457: $output .= &Apache::lonhtmlcommon::row_title($lt{'opfi'},undef,$css[$i]).
1.44 raeburn 458: ' <input type="file" name="screenshot" size="20" /><br />'.$lt{'uplf'}."\n".
459: &Apache::lonhtmlcommon::row_closure();
1.50 raeburn 460: $num ++;
461: $i = $num%2;
1.5 raeburn 462: }
1.50 raeburn 463: $output .= &Apache::lonhtmlcommon::row_title($lt{'fini'},undef,$css[$i]);
1.44 raeburn 464: $output .= <<END;
1.1 raeburn 465: <table border="0" cellpadding="8" cellspacing="0">
466: <tr>
467: <td>
1.44 raeburn 468: <input type="hidden" name="command" value="process" />
469: <input type="button" value="$lt{'subm'}" onclick="validate()" />
1.1 raeburn 470: </td>
471: <td> </td>
472: <td>
1.44 raeburn 473: <input type="reset" value="$lt{'clfm'}" />
1.1 raeburn 474: </td>
475: </tr>
476: </table>
1.44 raeburn 477: END
478: $output .= &Apache::lonhtmlcommon::row_closure(1);
479: $output .= &Apache::lonhtmlcommon::end_pick_box();
480: $r->print(<<END);
481: $output
1.14 raeburn 482: </form>
1.44 raeburn 483: <br />
1.1 raeburn 484: END
1.30 albertel 485: $r->print(&Apache::loncommon::end_page());
1.5 raeburn 486: return;
1.1 raeburn 487: }
488:
489: sub print_request_receipt {
490: my ($r,$url,$function) = @_;
1.26 raeburn 491: my @ENVvars = ('HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME');
492: my @envvars = ('browser.os','browser.type','browser.version','user.home','request.role');
1.5 raeburn 493: my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');
1.27 raeburn 494: my @cookievars = ('lonID');
1.5 raeburn 495:
496: my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
1.45 raeburn 497: my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
498: my $defdom = &get_domain();
499: my $to = &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
500: $defdom,$origmail);
1.5 raeburn 501: my $from = $admin;
1.1 raeburn 502: my $reporttime = &Apache::lonlocal::locallocaltime(time);
1.55.6.1 raeburn 503: my @formvars = ('username','email','uname','udom','sourceurl');
504: if (&Apache::loncommon::check_for_gci_dc()) {
505: push(@formvars,('phone','section','coursecode','title'));
506: }
507: push(@formvars,('subject','description','screenshot'));
1.1 raeburn 508: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);
1.25 albertel 509: my $coursecode = $env{'form.coursecode'};
1.55.6.1 raeburn 510: if (&Apache::loncommon::check_for_gci_dc()) {
511: if ($coursecode eq '') {
512: if (defined($env{'form.Year'})) {
513: $coursecode .= $env{'form.Year'};
514: }
515: if (defined($env{'form.Semester'})) {
516: $coursecode .= $env{'form.Semester'};
517: }
518: if (defined($env{'form.Department'})) {
519: $coursecode .= $env{'form.Department'};
520: }
521: if (defined($env{'form.Number'})) {
522: $coursecode .= $env{'form.Number'};
523: }
1.19 raeburn 524: }
525: }
1.40 raeburn 526: my %lt = &Apache::lonlocal::texthash (
1.44 raeburn 527: username => 'Name',
1.52 schafran 528: email => 'E-mail',
1.46 raeburn 529: cc => 'Cc',
1.44 raeburn 530: user => 'Username/domain',
531: phone => 'Phone',
532: crsi => 'Course Information',
533: subject => 'Subject',
534: description => 'Description',
535: sourceurl => 'URL',
536: date => 'Date/Time',
537: secn => 'Section',
538: asup => 'A support request has been sent to',
539: warn => 'Warning: Problem with support e-mail address',
540: your => 'Your support request contained the following information',
541: sect => 'section',
542: info => 'Information supplied',
543: adin => 'Additional information recorded',
1.40 raeburn 544: );
1.46 raeburn 545:
546: my (@ok_ccs,@bad_ccs,$badccmsg,$okcclist);
1.50 raeburn 547: if ((defined($env{'user.name'})) && (defined($env{'form.cc'}))) {
1.46 raeburn 548: my @ccs;
549: if ($env{'form.cc'} =~ /,/) {
550: @ccs = split(/,/,$env{'form.cc'});
551: } else {
552: $env{'form.cc'} =~ s/^\s+//;
553: $env{'form.cc'} =~ s/\s+$//;
554: @ccs = $env{'form.cc'};
555: }
556: foreach my $cc (@ccs) {
557: $cc =~ s/^\s+//g;
558: $cc =~ s/\s+$//g;
559: if ($cc =~ m/^[^\@]+\@[^\@]+$/) {
560: if (!(grep(/^\Q$cc\E$/,@ok_ccs))) {
561: push(@ok_ccs,$cc);
562: }
563: } else {
564: if (!(grep(/^\Q$cc\E$/,@bad_ccs))) {
565: push(@bad_ccs,$cc);
566: }
567: }
568: }
569: if (@ok_ccs > 0) {
570: $okcclist = join(', ',@ok_ccs);
571: }
572: if (@bad_ccs == 1) {
573: $badccmsg .= '<br />'.&mt('The following Cc e-mail address is invalid: ').$bad_ccs[0];
574: } elsif (@bad_ccs > 1) {
575: my $bad_cc_string = join(', ',@bad_ccs);
576: $badccmsg .= '<br />'.&mt('The following Cc e-mail addresses are invalid: ').$bad_cc_string;
577: }
578: }
1.44 raeburn 579: $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'";
1.55.6.1 raeburn 580: if (&Apache::loncommon::check_for_gci_dc()) {
581: $env{'form.csri'} = $env{'form.title'}.' - '.$coursecode.' - '.$lt{'sect'}.': '.$env{'form.section'};
582: }
1.44 raeburn 583: my $supportmsg = <<END;
584: $lt{'username'}: $env{'form.username'}
1.40 raeburn 585: $lt{'email'}: $env{'form.email'}
1.46 raeburn 586: $lt{'cc'}: $okcclist
1.44 raeburn 587: $lt{'user'}: $env{'form.user'}
1.55.6.1 raeburn 588: END
589: if (&Apache::loncommon::check_for_gci_dc()) {
590: $supportmsg .= <<END
1.44 raeburn 591: $lt{'phone'}: $env{'form.phone'}
592: $lt{'crsi'}: $env{'form.csri'}
1.55.6.1 raeburn 593: END
594: }
595: $supportmsg = <<END;
1.44 raeburn 596: $lt{'subject'}: $env{'form.subject'}
597: $lt{'description'}: $env{'form.description'}
598: $lt{'sourceurl'}: $env{'form.sourceurl'}
1.40 raeburn 599: $lt{'date'}: $reporttime
1.1 raeburn 600:
1.44 raeburn 601: END
602: my $displaymsg;
1.55.6.1 raeburn 603: my @items = ('username','email','cc','user');
604: if (&Apache::loncommon::check_for_gci_dc()) {
605: push(@items,'phone','crsi');
606: }
607: push(@items,('subject','description','sourceurl'));
608: foreach my $item (@items) {
1.44 raeburn 609: if ($env{'form.'.$item} ne '') {
610: if ($item eq 'description') {
611: my $descrip = $env{'form.description'};
1.54 raeburn 612: $descrip = &cleanup_html($descrip);
613: $descrip =~ s|[\n\r\f]|<br />|g;
1.44 raeburn 614: $displaymsg .=
615: '<span class="LC_helpform_receipt_cat">'.
616: "$lt{$item}</span>: $descrip<br />\n";
617: } elsif ($item eq 'sourceurl') {
618: my $showurl = $env{'form.sourceurl'};
619: $showurl =~ s/\?.*$//;
1.54 raeburn 620: $showurl = &cleanup_html($showurl);
1.44 raeburn 621: $displaymsg .=
622: '<span class="LC_helpform_receipt_cat">'.
623: "$lt{$item}</span>: $showurl<br />\n";
1.46 raeburn 624: } elsif ($item eq 'cc') {
625: $displaymsg .=
626: '<span class="LC_helpform_receipt_cat">'.
627: "$lt{$item}</span>: $okcclist<br />\n";
1.44 raeburn 628: } else {
1.54 raeburn 629: my $showitem = $env{'form.'.$item};
630: $showitem = &cleanup_html($showitem);
1.44 raeburn 631: $displaymsg .=
632: '<span class="LC_helpform_receipt_cat">'.
1.54 raeburn 633: "$lt{$item}</span>: $showitem<br />\n";
1.44 raeburn 634: }
635: }
636: }
637: $displaymsg .= '<span class="LC_helpform_receipt_cat">'.
638: $lt{'date'}.'</span>: '.$reporttime.'<br />'."\n";
1.32 albertel 639:
640: my $start_page =
641: &Apache::loncommon::start_page('Support request recorded',undef,
1.33 albertel 642: {'function' => $function,
643: 'add_entries' => {
644: topmargin => "0",
645: marginheight => "0",
646: },
647: 'only_body' => 1,});
1.32 albertel 648:
1.14 raeburn 649: $r->print(<<"END");
1.32 albertel 650: $start_page
1.16 raeburn 651: <form name="logproblem">
1.44 raeburn 652: <input type="hidden" name="command" value="result" />
1.16 raeburn 653: </form>
1.1 raeburn 654: END
1.14 raeburn 655: if ($r->uri eq '/adm/helpdesk') {
656: &print_header($r,$url,'process');
657: }
1.45 raeburn 658: my $bad_email = 0;
659: if ($to =~ /,/) {
660: my @ok_email;
661: foreach my $email (split(/,/,$to)) {
662: if ($email =~ m/^[^\@]+\@[^\@]+$/) {
1.46 raeburn 663: if (!grep(/^\Q$email\E$/,@ok_email)) {
664: push(@ok_email,$email);
665: }
1.45 raeburn 666: }
667: }
668: if (@ok_email > 0) {
669: $to = join(',',@ok_email);
670: } elsif ($admin =~ m/^[^\@]+\@[^\@]+$/) {
671: $to = $admin;
672: } else {
673: $bad_email = 1;
674: }
675: } elsif ($to !~ m/^[^\@]+\@[^\@]+$/) {
676: if ($admin =~ m/^[^\@]+\@[^\@]+$/) {
677: $to = $admin;
1.9 raeburn 678: } else {
1.45 raeburn 679: $bad_email = 1;
680: }
681: }
682: if ($bad_email) {
683: $r->print('
1.40 raeburn 684: <h3>'.$lt{'warn'}.'</h3>'.
685: &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 686: $to = 'helpdesk@lon-capa.org';
1.45 raeburn 687: } else {
688: $r->print('<h3>'.$lt{'asup'}.' '.$to.'</h3>');
1.1 raeburn 689: }
1.25 albertel 690: if (defined($env{'form.email'})) {
1.46 raeburn 691: $env{'form.email'} =~ s/^\s+//;
692: $env{'form.email'} =~ s/\s+$//;
1.25 albertel 693: if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
694: $from = $env{'form.email'};
1.5 raeburn 695: }
696: }
697:
1.46 raeburn 698: if (defined($env{'form.cc'})) {
699: if ($badccmsg) {
700: $displaymsg .= $badccmsg;
701: }
702: }
703:
1.25 albertel 704: my $subject = $env{'form.subject'};
1.44 raeburn 705: $subject =~ s/(`)/'/g;
706: $subject =~ s/\$/\(\$\)/g;
707: $supportmsg =~ s/(`)/'/g;
708: $supportmsg =~ s/\$/\(\$\)/g;
709: $displaymsg =~ s/(`)/'/g;
710: $displaymsg =~ s/\$/\(\$\)/g;
1.5 raeburn 711: my $fname;
712:
713: my $attachmentpath = '';
714: my $attachmentsize = '';
1.25 albertel 715: if (defined($env{'user.name'})) {
716: if ($env{'form.screenshot.filename'}) {
717: $attachmentsize = length($env{'form.screenshot'});
1.5 raeburn 718: if ($attachmentsize > 131072) {
1.40 raeburn 719: $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 720: } else {
721: $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
722: }
723: }
724: }
725:
1.40 raeburn 726: my %cookies;
1.27 raeburn 727: my $cookie=CGI::Cookie->parse($r->header_in('Cookie'));
1.39 albertel 728: if ($$cookie{'lonID'} =~ /lonID=($LONCAPA::handle_re);/) {
1.27 raeburn 729: $cookies{'lonID'} = $1;
730: }
731:
1.5 raeburn 732: if ($attachmentpath =~ m-/([^/]+)$-) {
733: $fname = $1;
1.51 bisitz 734: $displaymsg .= '<br />'
735: .&mt('An uploaded screenshot file [_1] ([_2] bytes) was included in the request sent by [_3].'
736: ,'<span class="LC_filename">'.$fname.'<span>'
737: ,$attachmentsize
738: ,$env{'user.name'}.':'.$env{'user.domain'}
739: );
1.5 raeburn 740: $supportmsg .= "\n";
1.40 raeburn 741: foreach my $var (@cookievars) {
742: $supportmsg .= "$var: $cookies{$var}\n";
1.27 raeburn 743: }
1.40 raeburn 744: foreach my $var(@ENVvars) {
745: $supportmsg .= "$var: $ENV{$var}\n";
1.26 raeburn 746: }
1.40 raeburn 747: foreach my $var (@envvars) {
748: $supportmsg .= "$var: $env{$var}\n";
1.5 raeburn 749: }
750: }
751:
752: my $msg = MIME::Lite->new(
753: From => $from,
754: To => $to,
755: Subject => $subject,
756: Type =>'TEXT',
757: Data => $supportmsg,
758: );
1.46 raeburn 759: if (@ok_ccs > 0) {
760: my $cc_string = join(', ',@ok_ccs);
761: $msg->add("Cc" => $cc_string);
762: }
1.5 raeburn 763:
764: if ($attachmentpath) {
765: my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath);
766: $msg->attach(Type => $type,
767: Path => $attachmentpath,
768: Filename => $fname
769: );
770:
771: } else {
772: my $envdata = '';
1.40 raeburn 773: foreach my $var (@cookievars) {
774: $envdata .= "$var: $cookies{$var}\n";
1.27 raeburn 775: }
1.40 raeburn 776: foreach my $var (@ENVvars) {
777: $envdata .= "$var: $ENV{$var}\n";
1.26 raeburn 778: }
1.40 raeburn 779: foreach my $var (@envvars) {
780: $envdata .= "$var: $env{$var}\n";
1.5 raeburn 781: }
1.40 raeburn 782: foreach my $var (@loncvars) {
783: $envdata .= "$var: $env{$var}\n";
1.5 raeburn 784: }
785: $msg->attach(Type => 'TEXT',
786: Data => $envdata);
787: }
788:
789: ### Send it:
790: $msg->send('sendmail');
791:
1.44 raeburn 792: if ($attachmentpath =~ m|$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+|) {
1.5 raeburn 793: unlink($attachmentpath);
794: }
1.44 raeburn 795: $r->print('<b>'.$lt{'your'}.'</b>:<br /><br />'."\n");
1.55 bisitz 796: $r->print('<div style="width:620px;">'.
797: &Apache::lonhtmlcommon::start_pick_box().
1.44 raeburn 798: &Apache::lonhtmlcommon::row_title($lt{'info'},undef,'LC_oddrow_value')."\n".$displaymsg."\n".
799: &Apache::lonhtmlcommon::row_closure().
800: &Apache::lonhtmlcommon::row_title($lt{'adin'},undef,'LC_evenrow_value'));
801: my $envmsg;
1.40 raeburn 802: foreach my $var (@cookievars) {
1.44 raeburn 803: if ($cookies{$var} ne '') {
804: $envmsg.= '<span class="LC_helpform_receipt_cat">'.
805: $var.'</span>: '.$cookies{$var}.', ';
1.27 raeburn 806: }
807: }
1.40 raeburn 808: foreach my $var (@ENVvars) {
1.44 raeburn 809: if ($ENV{$var} ne '') {
810: $envmsg .= '<span class="LC_helpform_receipt_cat">'.
811: $var.'</span>: '.$ENV{$var}.', ';
1.26 raeburn 812: }
813: }
1.40 raeburn 814: foreach my $var (@envvars) {
1.44 raeburn 815: if ($env{$var} ne '') {
816: $envmsg .= '<span class="LC_helpform_receipt_cat">'.
817: $var.'</span>: '.$env{$var}.', ';
1.5 raeburn 818: }
1.1 raeburn 819: }
1.44 raeburn 820: $envmsg =~ s/, $//;
821: $r->print($envmsg."\n".
822: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.55 bisitz 823: &Apache::lonhtmlcommon::end_pick_box().
824: "</div>\n".
1.44 raeburn 825: &Apache::loncommon::end_page());
1.1 raeburn 826: }
827:
1.14 raeburn 828: sub print_header {
1.44 raeburn 829: my ($r,$origurl,$command) = @_;
1.14 raeburn 830: my $location=&Apache::loncommon::lonhttpdurl("/adm");
831: my ($component_url);
832: my $helpdesk_link = '<a href="javascript:validate()">';
1.44 raeburn 833: if ($command eq 'process') {
1.14 raeburn 834: $helpdesk_link = '<a href="/adm/helpdesk">';
835: }
836: my %lt = &Apache::lonlocal::texthash (
837: login => 'Log-in help',
838: ask => 'Ask helpdesk',
839: getst => 'Getting started guide',
1.47 bisitz 840: back => 'Back to last location',
841: headline => 'help/support',
1.21 raeburn 842: );
1.47 bisitz 843: my ($getstartlink,$reviewtext);
1.21 raeburn 844: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/gettingstarted.html') {
845: $getstartlink = qq|<td align="center"> <b><a href="/adm/gettingstarted.html">$lt{'getst'}</a></td>|;
1.47 bisitz 846: $reviewtext = &mt('Please review the information in "Log-in help" and the "Getting started" guide if you are unable to log-in.');
847: } else {
848: $reviewtext = &mt('Please review the information in "Log-in help" if you are unable to log-in.');
1.21 raeburn 849: }
1.55.6.2 raeburn 850: if ($origurl eq '') {
851: $origurl = 'javascript:history.go(-1)';
852: }
1.14 raeburn 853: $r->print(<<END);
854: <table width="620" border="0" cellspacing="0" cellpadding="0" height="55"> <tr height="50"> <td width='5'> </td>
855: <td>
1.53 bisitz 856: <fieldset>
857: <legend>
858: <img src="$location/lonIcons/minilogo.gif" height="20" width="29" valign="bottom" />
859: LON-CAPA $lt{'headline'}
860: </legend>
1.44 raeburn 861: <table id="LC_helpmenu_links">
862: <tr>
1.49 raeburn 863: <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 864: <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
865: <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>
866: </tr>
1.14 raeburn 867: </table>
868: </fieldset>
869: </td>
870: <td width='5'> </td>
871: </tr>
872: <tr height='5'>
873: <td colspan='3' height='5'> </td>
874: </tr>
875: END
1.44 raeburn 876: if ($command ne 'process') {
1.14 raeburn 877: $r->print('
878: <tr>
1.47 bisitz 879: <td colspan="3">'.$reviewtext.' '
880: .&mt('If your problem is still unresolved, the form below can be used to send a question to the LON-CAPA helpdesk.').'<br />'
881: .'<font size="-1"><b>'.&mt('Students').'</b>: '.&mt('Do <b>not</b> use this form to ask questions about course content.').' '
882: .&mt('Contact your instructor instead.')
883: .'</font><br /><br />
1.14 raeburn 884: </td>
885: </tr>');
886: }
887: $r->print('
888: </table>');
889: return;
890: }
891:
1.45 raeburn 892: sub get_domain {
893: my $codedom;
894: if (exists($env{'form.codedom'})) {
895: $codedom = $env{'form.codedom'};
896: } elsif ($env{'request.course.id'}) {
897: $codedom = $env{'course.'.$env{'request.course.id'}.'.domain'};
898: } elsif ($env{'request.role.domain'}) {
899: $codedom = $env{'request.role.domain'};
900: } else {
1.54 raeburn 901: $codedom = &Apache::lonnet::default_login_domain();
1.45 raeburn 902: }
903: return $codedom;
904: }
905:
1.54 raeburn 906: sub cleanup_html {
907: my ($incoming) = @_;
908: my $outgoing;
909: if ($incoming ne '') {
910: $outgoing = $incoming;
911: $outgoing =~ s/\#/#/g;
912: $outgoing =~ s/\&/&/g;
913: $outgoing =~ s/</</g;
914: $outgoing =~ s/>/>/g;
915: $outgoing =~ s/\(/(/g;
916: $outgoing =~ s/\)/)/g;
917: $outgoing =~ s/"/"/g;
918: $outgoing =~ s/'/'/g;
919: $outgoing =~ s/\$/$/g;
920: }
921: return $outgoing;
922: }
923:
1.1 raeburn 924: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>