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