Annotation of loncom/interface/lonsupportreq.pm, revision 1.44
1.24 albertel 1: #
1.44 ! raeburn 2: # $Id: lonsupportreq.pm,v 1.43 2007/05/07 14:02:45 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.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',
102: emad => 'E-mail address',
103: unme => 'username',
104: doma => 'domain',
1.44 ! raeburn 105: entu => 'Enter the username you use to log-in to LON-CAPA',
! 106: chdo => 'Choose your LON-CAPA domain',
! 107: entr => 'Enter the username you use to log-in to LON-CAPA, and your domain.',
1.40 raeburn 108: urlp => 'URL of page',
109: phon => 'Phone',
110: crsd => 'Course Details',
111: enin => 'Enter institutional course code',
112: pick => 'Pick',
113: enct => 'Enter course title',
114: secn => 'Section Number',
115: sele => 'Select',
116: titl => 'Title',
117: lsec => 'LON-CAPA sec',
118: subj => 'Subject',
119: detd => 'Detailed Description',
120: opfi => 'Optional file upload',
1.44 ! raeburn 121: uplf => 'Upload a file (e.g., a screenshot) relevant to your help request (128 KB max.)',
1.40 raeburn 122: fini => 'Finish',
123: clfm => 'Clear Form',
124: );
125: my $scripttag = (<<"END");
1.5 raeburn 126: function validate() {
1.13 raeburn 127: if (validmail(document.logproblem.email) == false) {
1.40 raeburn 128: alert("$lt{'email'}: "+document.logproblem.email.value+" $lt{'notv'}.");
129: return;
130: }
131: if (document.logproblem.subject.value == '') {
132: alert("$lt{'rsub'}.");
133: return;
134: }
135: if (document.logproblem.description.value == '') {
136: alert("$lt{'rdes'}.");
1.13 raeburn 137: return;
1.5 raeburn 138: }
139: document.logproblem.submit();
140: }
1.13 raeburn 141:
1.40 raeburn 142: END
1.43 raeburn 143: $scripttag .= &Apache::lonhtmlcommon::javascript_valid_email();
1.44 ! raeburn 144: if ($cid) {
! 145: $cdom = $env{'course.'.$cid.'.domain'};
! 146: $cnum = $env{'course.'.$cid.'.num'};
1.1 raeburn 147: }
148: if ($cdom && $cnum) {
149: my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
150: $ctitle = $csettings{'description'};
151: $ccode = $csettings{'internal.coursecode'};
152: $sectionlist = $csettings{'internal.sectionnums'};
153: }
1.44 ! raeburn 154:
! 155: if ($env{'environment.permanentemail'}) {
! 156: $email = $env{'environment.permanentemail'};
! 157: } elsif ($env{'environment.critnotification'}) {
1.25 albertel 158: $email = $env{'environment.critnotification'};
1.44 ! raeburn 159: } elsif ($env{'environment.notification'}) {
1.25 albertel 160: $email = $env{'environment.notification'};
1.1 raeburn 161: }
1.25 albertel 162: if ($env{'environment.lastname'}) {
163: $lastname = $env{'environment.lastname'};
1.1 raeburn 164: }
1.25 albertel 165: if ($env{'environment.firstname'}) {
166: $firstname = $env{'environment.firstname'};
1.1 raeburn 167: }
1.40 raeburn 168: my @sections = split(/,/,$sectionlist);
169: my %groupid;
170: foreach my $section (@sections) {
171: my ($sec,$grp) = split(/:/,$section);
1.1 raeburn 172: $groupid{$sec} = $grp;
173: }
1.19 raeburn 174: my $codedom = $Apache::lonnet::perlvar{'lonDefDomain'};
175: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['codedom']);
1.25 albertel 176: if (exists($env{'form.codedom'})) {
177: $codedom = $env{'form.codedom'};
1.19 raeburn 178: }
1.21 raeburn 179: my $details_title;
180: if ($codedom) {
181: $details_title = '<br />('.$codedom.')';
182: }
1.40 raeburn 183: my %coursecodes;
184: my %codes;
185: my @codetitles;
186: my %cat_titles;
187: my %cat_order;
188: my %idlist;
189: my %idnums;
190: my %idlist_titles;
1.1 raeburn 191: my $caller = 'global';
192: my $totcodes = 0;
193: my $format_reply;
1.6 raeburn 194: my $jscript = '';
1.22 raeburn 195: my $loaditems = qq|
196: function initialize_codes() {
197: return;
198: }
199: |;
1.1 raeburn 200: if ($cdom) {
201: $codedom = $cdom;
202: }
203: if ($cnum) {
204: $coursecodes{$cnum} = $ccode;
205: if ($ccode eq '') {
1.38 raeburn 206: $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
1.1 raeburn 207: } else {
208: $coursecodes{$cnum} = $ccode;
209: $caller = $cnum;
210: $totcodes ++;
211: }
212: } else {
1.38 raeburn 213: $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
1.1 raeburn 214: }
215: if ($totcodes > 0) {
1.6 raeburn 216: if ($ccode eq '') {
1.22 raeburn 217: $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
218: if ($format_reply eq 'ok') {
219: my $numtypes = @codetitles;
1.38 raeburn 220: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
221: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
222: my $longtitles_str = join('","',@{$longtitles});
223: my $allidlist = $idlist{$codetitles[0]};
224: $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
225: $jscript .= $scripttext;
226: $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,@codetitles);
1.22 raeburn 227: $loaditems = '';
228: }
1.6 raeburn 229: }
1.1 raeburn 230: }
1.30 albertel 231:
1.44 ! raeburn 232: my $js = '<script type="text/javascript">'."\n$scripttag\n$jscript\n".
1.31 albertel 233: '</script>';
1.33 albertel 234: my %add_entries = (topmargin => "0",
235: marginheight => "0",
236: onLoad =>"initialize_codes()",);
237:
1.44 ! raeburn 238:
! 239: $r->print(&Apache::loncommon::start_page('Support Request',$js,
1.31 albertel 240: { 'function' => $function,
1.33 albertel 241: 'add_entries' => \%add_entries,
1.44 ! raeburn 242: 'only_body' => 1,}));
1.15 raeburn 243: if ($r->uri eq '/adm/helpdesk') {
1.14 raeburn 244: &print_header($r,$origurl);
245: }
1.44 ! raeburn 246: $r->print('<form method="post" name="logproblem" enctype="multipart/form-data">'."\n");
! 247: my $output = &Apache::lonhtmlcommon::start_pick_box().
! 248: &Apache::lonhtmlcommon::row_title($lt{'name'},undef,'LC_oddrow_value')."\n";
1.1 raeburn 249: my $fullname = '';
250: if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) {
251: $fullname = "$firstname $lastname";
1.44 ! raeburn 252: $output .= $fullname.'<input type="hidden" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />';
1.1 raeburn 253: } else {
254: if (defined($firstname) && $firstname ne '') {
255: $fullname = $firstname;
256: } elsif (defined($lastname) && $lastname ne '') {
1.44 ! raeburn 257: $fullname = " $lastname";
1.1 raeburn 258: }
1.44 ! raeburn 259: $output .= '<input type="text" size="20" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />';
1.1 raeburn 260: }
1.44 ! raeburn 261: $output .= ' <input type="button" value="'.$lt{'subm'}.'" onclick="validate()" /> '.
! 262: &Apache::lonhtmlcommon::row_closure()."\n".
! 263: &Apache::lonhtmlcommon::row_title($lt{'emad'},undef,'LC_evenrow_value').
! 264: '<input type="text" size="20" name="email" value="'.
! 265: &HTML::Entities::encode($email,'"<>&').'" /><br />'."\n".
! 266: &Apache::lonhtmlcommon::row_closure().
! 267: &Apache::lonhtmlcommon::row_title("$lt{'unme'}/$lt{'doma'}",undef,'LC_oddrow_value');
! 268: my $udom_input = '<input type="hidden" name="udom" value="'.
! 269: &HTML::Entities::encode($udom,'"<>&').'" />';
! 270: my $uname_input = '<input type="hidden" name="uname" value="'.
! 271: &HTML::Entities::encode($uname,'"<>&').'" />';
1.1 raeburn 272: if (defined($uname) && defined($udom)) {
1.44 ! raeburn 273: $output .= '<i>'.$lt{'unme'}.'</i>: '.$uname.' <i>'.$lt{'doma'}.'</i>: '.$udom.$udom_input.$uname_input;
1.1 raeburn 274: } else {
275: my $udomform = '';
276: my $unameform = '';
277: if (defined($udom)) {
1.44 ! raeburn 278: $output .= $lt{'entu'};
! 279: } elsif (defined($uname)) {
! 280: $output .= $lt{'chdo'};
! 281: } else {
! 282: $output .= $lt{'entr'};
! 283: }
! 284: $output .= '<br />';
! 285: if (defined($udom)) {
1.40 raeburn 286: $udomform = '<i>'.$lt{'doma'}.'</i>: '.$udom.$udom_input;
1.1 raeburn 287: } elsif (defined($uname)) {
1.40 raeburn 288: $unameform = '<i>'.$lt{'unme'}.'</i>: '.$uname.' '.$uname_input;
1.1 raeburn 289: }
290: if ($udomform eq '') {
1.40 raeburn 291: $udomform = '<i>'.$lt{'doma'}.'</i>: ';
1.19 raeburn 292: $udomform .= &Apache::loncommon::select_dom_form($codedom,'udom');
1.1 raeburn 293: }
294: if ($unameform eq '') {
1.40 raeburn 295: $unameform= '<i>'.$lt{'unme'}.'</i>: <input type="text" size="12" name="uname" value="'.$uname.'" /> ';
1.1 raeburn 296: }
1.44 ! raeburn 297: $output .= $unameform.$udomform;
1.1 raeburn 298: }
1.44 ! raeburn 299: $output .= &Apache::lonhtmlcommon::row_closure().
! 300: &Apache::lonhtmlcommon::row_title("$lt{'urlp'}",undef,'LC_evenrow_value').
! 301: $showserver.'<input type="hidden" name="sourceurl" value="'.
! 302: &HTML::Entities::encode($server,'"<>&').'" />'.
! 303: &Apache::lonhtmlcommon::row_closure().
! 304: &Apache::lonhtmlcommon::row_title("$lt{'phon'}",undef,'LC_oddrow_value').
! 305: '<input type="text" size="15" name="phone" /><br />'.
! 306: &Apache::lonhtmlcommon::row_closure().
! 307: &Apache::lonhtmlcommon::row_title("$lt{'crsd'}$details_title",undef,'LC_evenrow_value');
1.10 raeburn 308: if ($cnum) {
309: if ($coursecodes{$cnum}) {
1.40 raeburn 310: foreach my $item (@codetitles) {
1.44 ! raeburn 311: $output .= '<i>'.$item.'</i>: '.$codes{$cnum}{$item}.'; ';
1.10 raeburn 312: }
1.44 ! raeburn 313: $output .= ' <input type="hidden" name="coursecode" value="'.&HTML::Entities::encode($coursecodes{$cnum},'"<>&').'" />';
1.10 raeburn 314: } else {
1.44 ! raeburn 315: $output .= $lt{'enin'}.':
! 316: <input type="text" name="coursecode" size="15" value="" />';
1.1 raeburn 317: }
318: } else {
1.10 raeburn 319: if ($totcodes > 0) {
320: my $numtitles = @codetitles;
321: if ($numtitles == 0) {
1.44 ! raeburn 322: $output .= $lt{'enin'}.':
! 323: <input type="text" name="coursecode" size="15" value="" />';
1.10 raeburn 324: } else {
325: my $lasttitle = $numtitles;
326: if ($numtitles > 4) {
327: $lasttitle = 4;
328: }
1.44 ! raeburn 329: $output .= '<table><tr><td>'.$codetitles[0].'<br />'."\n".
! 330: '<select name="'.$codetitles[0].'" onchange="courseSet('."'$codetitles[0]'".')">'."\n".
! 331: ' <option value="-1" />'.$lt{'sele'}."\n";
1.10 raeburn 332: my @items = ();
1.20 raeburn 333: my @longitems = ();
1.10 raeburn 334: if ($idlist{$codetitles[0]} =~ /","/) {
1.40 raeburn 335: @items = split(/","/,$idlist{$codetitles[0]});
1.10 raeburn 336: } else {
337: $items[0] = $idlist{$codetitles[0]};
338: }
1.20 raeburn 339: if (defined($idlist_titles{$codetitles[0]})) {
340: if ($idlist_titles{$codetitles[0]} =~ /","/) {
1.40 raeburn 341: @longitems = split(/","/,$idlist_titles{$codetitles[0]});
1.20 raeburn 342: } else {
343: $longitems[0] = $idlist_titles{$codetitles[0]};
344: }
1.22 raeburn 345: for (my $i=0; $i<@longitems; $i++) {
346: if ($longitems[$i] eq '') {
347: $longitems[$i] = $items[$i];
348: }
349: }
1.20 raeburn 350: } else {
351: @longitems = @items;
352: }
353: for (my $i=0; $i<@items; $i++) {
1.44 ! raeburn 354: $output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>'."\n";
1.10 raeburn 355: }
1.44 ! raeburn 356: $output .= '</select></td>';
1.10 raeburn 357: for (my $i=1; $i<$numtitles; $i++) {
1.44 ! raeburn 358: $output .= '<td>'.$codetitles[$i].'<br />'."\n".
! 359: '<select name="'.$codetitles[$i].'" onchange="courseSet('."'$codetitles[$i]'".')">'."\n".
1.40 raeburn 360: '<option value="-1"><-'.$lt{'pick'}.' '.$codetitles[$i-1].'</option>'."\n".
1.10 raeburn 361: '</select>'."\n".
1.44 ! raeburn 362: '</td>'."\n";
1.10 raeburn 363: }
1.44 ! raeburn 364: $output .= '</tr></table>';
1.10 raeburn 365: if ($numtitles > 4) {
1.44 ! raeburn 366: $output .= '<br /><br />'.$codetitles[$numtitles].'<br />'."\n".
! 367: '<select name="'.$codetitles[$numtitles].'" onchange="courseSet('."'$codetitles[$numtitles]'".')">'."\n".
1.40 raeburn 368: '<option value="-1"><-'.$lt{'pick'}.' '.$codetitles[$numtitles-1].'</option>'."\n".
1.44 ! raeburn 369: '</select>'."\n";
1.10 raeburn 370: }
371: }
372: } else {
1.44 ! raeburn 373: $output .= $lt{'enin'}.':
! 374: <input type="text" name="coursecode" size="15" value="" />';
1.10 raeburn 375: }
1.1 raeburn 376: }
377: if ($ctitle) {
1.44 ! raeburn 378: $output .= '<br /><i>'.$lt{'titl'}.'</i>: '.$ctitle.
! 379: '<input type="hidden" name="title" value="'.
! 380: &HTML::Entities::encode($ctitle,'"<>&').'" />'."\n";
1.1 raeburn 381: } else {
1.44 ! raeburn 382: $output .= '<br />'.$lt{'enct'}.':
! 383: <input type="text" name="title" size="25" value="" />'."\n";
1.1 raeburn 384: }
1.44 ! raeburn 385: $output .= &Apache::lonhtmlcommon::row_closure().
! 386: &Apache::lonhtmlcommon::row_title($lt{'secn'},undef,'LC_oddrow_value');
1.1 raeburn 387: if ($sectionlist) {
1.44 ! raeburn 388: $output .= "<select name=\"section\"\n>".
! 389: " <option value=\"\" selected=\"selected\">$lt{'sele'}</option>\n";
1.40 raeburn 390: foreach my $id (sort(keys(%groupid))) {
391: if ($id eq $groupid{$id} || $groupid{$id} eq '') {
1.44 ! raeburn 392: $output .= " <option value=".
! 393: &HTML::Entities::encode($id,'"<>&').
! 394: " >$id</option>\n";
1.1 raeburn 395: } else {
1.44 ! raeburn 396: $output .= " <option value=".
! 397: &HTML::Entities::encode($id,'"<>&').
! 398: " >$id - ($lt{'lsec'}: $groupid{$id})</option>\n";
1.1 raeburn 399: }
400: }
1.44 ! raeburn 401: $output .= "</select>";
1.1 raeburn 402: } else {
1.44 ! raeburn 403: $output .= '<input type="text" name="section" size="10" />';
1.1 raeburn 404: }
1.44 ! raeburn 405: $output .= &Apache::lonhtmlcommon::row_closure().
! 406: &Apache::lonhtmlcommon::row_title($lt{'subj'},undef,'LC_evenrow_value').
! 407: ' <input type="text" size="40" name="subject" />'."\n".
! 408: &Apache::lonhtmlcommon::row_closure().
! 409: &Apache::lonhtmlcommon::row_title($lt{'detd'},undef,'LC_oddrow_value').
! 410: ' <textarea rows="10" cols="45" name="description" wrap="virtual"></textarea>'.
! 411: &Apache::lonhtmlcommon::row_closure();
! 412: my $lastrow = 'LC_evenrow_value';
1.25 albertel 413: if (defined($env{'user.name'})) {
1.44 ! raeburn 414: $output .= &Apache::lonhtmlcommon::row_title($lt{'opfi'},undef,'LC_evenrow_value').
! 415: ' <input type="file" name="screenshot" size="20" /><br />'.$lt{'uplf'}."\n".
! 416: &Apache::lonhtmlcommon::row_closure();
! 417: $lastrow = 'LC_oddrow_value';
1.5 raeburn 418: }
1.44 ! raeburn 419: $output .= &Apache::lonhtmlcommon::row_title($lt{'fini'},undef,$lastrow);
! 420: $output .= <<END;
1.1 raeburn 421: <table border="0" cellpadding="8" cellspacing="0">
422: <tr>
423: <td>
1.44 ! raeburn 424: <input type="hidden" name="command" value="process" />
! 425: <input type="button" value="$lt{'subm'}" onclick="validate()" />
1.1 raeburn 426: </td>
427: <td> </td>
428: <td>
1.44 ! raeburn 429: <input type="reset" value="$lt{'clfm'}" />
1.1 raeburn 430: </td>
431: </tr>
432: </table>
1.44 ! raeburn 433: END
! 434: $output .= &Apache::lonhtmlcommon::row_closure(1);
! 435: $output .= &Apache::lonhtmlcommon::end_pick_box();
! 436: $r->print(<<END);
! 437: $output
1.14 raeburn 438: </form>
1.44 ! raeburn 439: <br />
1.1 raeburn 440: END
1.30 albertel 441: $r->print(&Apache::loncommon::end_page());
1.5 raeburn 442: return;
1.1 raeburn 443: }
444:
445: sub print_request_receipt {
446: my ($r,$url,$function) = @_;
1.26 raeburn 447: my @ENVvars = ('HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME');
448: my @envvars = ('browser.os','browser.type','browser.version','user.home','request.role');
1.5 raeburn 449: my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');
1.27 raeburn 450: my @cookievars = ('lonID');
1.5 raeburn 451:
452: my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
1.1 raeburn 453: my $to = $Apache::lonnet::perlvar{'lonSupportEMail'};
1.5 raeburn 454: my $from = $admin;
1.1 raeburn 455: my $reporttime = &Apache::lonlocal::locallocaltime(time);
1.14 raeburn 456: my @formvars = ('username','email','uname','udom','sourceurl','phone','section','coursecode','title','subject','description','screenshot');
1.20 raeburn 457:
1.1 raeburn 458: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);
1.25 albertel 459: my $coursecode = $env{'form.coursecode'};
1.19 raeburn 460: if ($coursecode eq '') {
1.25 albertel 461: if (defined($env{'form.Year'})) {
462: $coursecode .= $env{'form.Year'};
1.19 raeburn 463: }
1.25 albertel 464: if (defined($env{'form.Semester'})) {
465: $coursecode .= $env{'form.Semester'};
1.19 raeburn 466: }
1.25 albertel 467: if (defined($env{'form.Department'})) {
468: $coursecode .= $env{'form.Department'};
1.19 raeburn 469: }
1.25 albertel 470: if (defined($env{'form.Number'})) {
471: $coursecode .= $env{'form.Number'};
1.19 raeburn 472: }
473: }
1.40 raeburn 474: my %lt = &Apache::lonlocal::texthash (
1.44 ! raeburn 475: username => 'Name',
! 476: email => 'Email',
! 477: user => 'Username/domain',
! 478: phone => 'Phone',
! 479: crsi => 'Course Information',
! 480: subject => 'Subject',
! 481: description => 'Description',
! 482: sourceurl => 'URL',
! 483: date => 'Date/Time',
! 484: secn => 'Section',
! 485: asup => 'A support request has been sent to',
! 486: warn => 'Warning: Problem with support e-mail address',
! 487: your => 'Your support request contained the following information',
! 488: sect => 'section',
! 489: info => 'Information supplied',
! 490: adin => 'Additional information recorded',
1.40 raeburn 491: );
1.44 ! raeburn 492:
! 493: $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'";
! 494: $env{'form.csri'} = $env{'form.title'}.' - '.$coursecode.' - '.$lt{'sect'}.': '.$env{'form.section'};
! 495: my $supportmsg = <<END;
! 496: $lt{'username'}: $env{'form.username'}
1.40 raeburn 497: $lt{'email'}: $env{'form.email'}
1.44 ! raeburn 498: $lt{'user'}: $env{'form.user'}
! 499: $lt{'phone'}: $env{'form.phone'}
! 500: $lt{'crsi'}: $env{'form.csri'}
! 501: $lt{'subject'}: $env{'form.subject'}
! 502: $lt{'description'}: $env{'form.description'}
! 503: $lt{'sourceurl'}: $env{'form.sourceurl'}
1.40 raeburn 504: $lt{'date'}: $reporttime
1.1 raeburn 505:
1.44 ! raeburn 506: END
! 507: my $displaymsg;
! 508: foreach my $item ('username','email','user','phone','crsi','subject','description','sourceurl') {
! 509: if ($env{'form.'.$item} ne '') {
! 510: if ($item eq 'description') {
! 511: my $descrip = $env{'form.description'};
! 512: $descrip =~ s|\n|<br />|g;
! 513: $displaymsg .=
! 514: '<span class="LC_helpform_receipt_cat">'.
! 515: "$lt{$item}</span>: $descrip<br />\n";
! 516: } elsif ($item eq 'sourceurl') {
! 517: my $showurl = $env{'form.sourceurl'};
! 518: $showurl =~ s/\?.*$//;
! 519: $displaymsg .=
! 520: '<span class="LC_helpform_receipt_cat">'.
! 521: "$lt{$item}</span>: $showurl<br />\n";
! 522: } else {
! 523: $displaymsg .=
! 524: '<span class="LC_helpform_receipt_cat">'.
! 525: "$lt{$item}</span>: $env{'form.'.$item}<br />\n";
! 526: }
! 527: }
! 528: }
! 529: $displaymsg .= '<span class="LC_helpform_receipt_cat">'.
! 530: $lt{'date'}.'</span>: '.$reporttime.'<br />'."\n";
1.32 albertel 531:
532: my $start_page =
533: &Apache::loncommon::start_page('Support request recorded',undef,
1.33 albertel 534: {'function' => $function,
535: 'add_entries' => {
536: topmargin => "0",
537: marginheight => "0",
538: },
539: 'only_body' => 1,});
1.32 albertel 540:
1.14 raeburn 541: $r->print(<<"END");
1.32 albertel 542: $start_page
1.16 raeburn 543: <form name="logproblem">
1.44 ! raeburn 544: <input type="hidden" name="command" value="result" />
1.16 raeburn 545: </form>
1.1 raeburn 546: END
1.14 raeburn 547: if ($r->uri eq '/adm/helpdesk') {
548: &print_header($r,$url,'process');
549: }
550: if ($to =~ m/^[^\@]+\@[^\@]+$/) {
1.40 raeburn 551: $r->print('<h3>'.$lt{'asup'}.' '.$to.'</h3>');
1.9 raeburn 552: } else {
553: $to = $admin;
554: if ($to =~ m/^[^\@]+\@[^\@]+$/) {
1.40 raeburn 555: $r->print('<h3>'.$lt{'asup'}.' '.$to.'</h3>');
1.9 raeburn 556: } else {
1.40 raeburn 557: $r->print('
558: <h3>'.$lt{'warn'}.'</h3>'.
559: &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 560: $to = 'helpdesk@lon-capa.org';
561: }
1.1 raeburn 562: }
1.25 albertel 563: if (defined($env{'form.email'})) {
564: if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
565: $from = $env{'form.email'};
1.5 raeburn 566: }
567: }
568:
1.25 albertel 569: my $subject = $env{'form.subject'};
1.44 ! raeburn 570: $subject =~ s/(`)/'/g;
! 571: $subject =~ s/\$/\(\$\)/g;
! 572: $supportmsg =~ s/(`)/'/g;
! 573: $supportmsg =~ s/\$/\(\$\)/g;
! 574: $displaymsg =~ s/(`)/'/g;
! 575: $displaymsg =~ s/\$/\(\$\)/g;
1.5 raeburn 576: my $fname;
577:
578: my $attachmentpath = '';
579: my $attachmentsize = '';
1.25 albertel 580: if (defined($env{'user.name'})) {
581: if ($env{'form.screenshot.filename'}) {
582: $attachmentsize = length($env{'form.screenshot'});
1.5 raeburn 583: if ($attachmentsize > 131072) {
1.40 raeburn 584: $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 585: } else {
586: $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
587: }
588: }
589: }
590:
1.40 raeburn 591: my %cookies;
1.27 raeburn 592: my $cookie=CGI::Cookie->parse($r->header_in('Cookie'));
1.39 albertel 593: if ($$cookie{'lonID'} =~ /lonID=($LONCAPA::handle_re);/) {
1.27 raeburn 594: $cookies{'lonID'} = $1;
595: }
596:
1.5 raeburn 597: if ($attachmentpath =~ m-/([^/]+)$-) {
598: $fname = $1;
1.44 ! raeburn 599: $displaymsg .= '<br />'.&mt('An uploaded screenshot file \'[_1]\' ([_2] bytes) was included in the request sent by [_3].',$fname,$attachmentsize,$env{'user.name'}.': '.$env{'user.domain'});
1.5 raeburn 600: $supportmsg .= "\n";
1.40 raeburn 601: foreach my $var (@cookievars) {
602: $supportmsg .= "$var: $cookies{$var}\n";
1.27 raeburn 603: }
1.40 raeburn 604: foreach my $var(@ENVvars) {
605: $supportmsg .= "$var: $ENV{$var}\n";
1.26 raeburn 606: }
1.40 raeburn 607: foreach my $var (@envvars) {
608: $supportmsg .= "$var: $env{$var}\n";
1.5 raeburn 609: }
610: }
611:
612: my $msg = MIME::Lite->new(
613: From => $from,
614: To => $to,
615: Subject => $subject,
616: Type =>'TEXT',
617: Data => $supportmsg,
618: );
619:
620: if ($attachmentpath) {
621: my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath);
622: $msg->attach(Type => $type,
623: Path => $attachmentpath,
624: Filename => $fname
625: );
626:
627: } else {
628: my $envdata = '';
1.40 raeburn 629: foreach my $var (@cookievars) {
630: $envdata .= "$var: $cookies{$var}\n";
1.27 raeburn 631: }
1.40 raeburn 632: foreach my $var (@ENVvars) {
633: $envdata .= "$var: $ENV{$var}\n";
1.26 raeburn 634: }
1.40 raeburn 635: foreach my $var (@envvars) {
636: $envdata .= "$var: $env{$var}\n";
1.5 raeburn 637: }
1.40 raeburn 638: foreach my $var (@loncvars) {
639: $envdata .= "$var: $env{$var}\n";
1.5 raeburn 640: }
641: $msg->attach(Type => 'TEXT',
642: Data => $envdata);
643: }
644:
645: ### Send it:
646: $msg->send('sendmail');
647:
1.44 ! raeburn 648: if ($attachmentpath =~ m|$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+|) {
1.5 raeburn 649: unlink($attachmentpath);
650: }
1.44 ! raeburn 651: $r->print('<b>'.$lt{'your'}.'</b>:<br /><br />'."\n");
! 652: $r->print(&Apache::lonhtmlcommon::start_pick_box('LC_helpform_receipt').
! 653: &Apache::lonhtmlcommon::row_title($lt{'info'},undef,'LC_oddrow_value')."\n".$displaymsg."\n".
! 654: &Apache::lonhtmlcommon::row_closure().
! 655: &Apache::lonhtmlcommon::row_title($lt{'adin'},undef,'LC_evenrow_value'));
! 656: my $envmsg;
1.40 raeburn 657: foreach my $var (@cookievars) {
1.44 ! raeburn 658: if ($cookies{$var} ne '') {
! 659: $envmsg.= '<span class="LC_helpform_receipt_cat">'.
! 660: $var.'</span>: '.$cookies{$var}.', ';
1.27 raeburn 661: }
662: }
1.40 raeburn 663: foreach my $var (@ENVvars) {
1.44 ! raeburn 664: if ($ENV{$var} ne '') {
! 665: $envmsg .= '<span class="LC_helpform_receipt_cat">'.
! 666: $var.'</span>: '.$ENV{$var}.', ';
1.26 raeburn 667: }
668: }
1.40 raeburn 669: foreach my $var (@envvars) {
1.44 ! raeburn 670: if ($env{$var} ne '') {
! 671: $envmsg .= '<span class="LC_helpform_receipt_cat">'.
! 672: $var.'</span>: '.$env{$var}.', ';
1.5 raeburn 673: }
1.1 raeburn 674: }
1.44 ! raeburn 675: $envmsg =~ s/, $//;
! 676: $r->print($envmsg."\n".
! 677: &Apache::lonhtmlcommon::row_closure(1)."\n".
! 678: &Apache::lonhtmlcommon::end_pick_box()."\n".
! 679: &Apache::loncommon::end_page());
1.1 raeburn 680: }
681:
1.14 raeburn 682: sub print_header {
1.44 ! raeburn 683: my ($r,$origurl,$command) = @_;
1.14 raeburn 684: my $location=&Apache::loncommon::lonhttpdurl("/adm");
685: my ($component_url);
686: my $helpdesk_link = '<a href="javascript:validate()">';
1.44 ! raeburn 687: if ($command eq 'process') {
1.14 raeburn 688: $helpdesk_link = '<a href="/adm/helpdesk">';
689: }
690: my %lt = &Apache::lonlocal::texthash (
691: login => 'Log-in help',
692: ask => 'Ask helpdesk',
693: getst => 'Getting started guide',
694: back => 'Back to last location'
1.21 raeburn 695: );
696: my ($getstartlink,$getstarttext);
697: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/gettingstarted.html') {
698: $getstartlink = qq|<td align="center"> <b><a href="/adm/gettingstarted.html">$lt{'getst'}</a></td>|;
699: $getstarttext = ' '.&mt('and the "Getting started" guide').' ';
700: }
1.14 raeburn 701: $r->print(<<END);
702: <table width="620" border="0" cellspacing="0" cellpadding="0" height="55"> <tr height="50"> <td width='5'> </td>
703: <td>
704: <fieldset><legend><img src="$location/lonIcons/minilogo.gif" height='20' width='29' valign='bottom' /> <b><font size="+1">LON-CAPA help/support</font></b></legend>
1.44 ! raeburn 705: <table id="LC_helpmenu_links">
! 706: <tr>
! 707: <td align="center"><span class="LC_nobreak"><img src="$location/help/gif/smallHelp.gif" border="0" alt="($lt{'login'})" valign="middle" /> <b><a href="/adm/loginproblems.html">$lt{'login'}</a></b> </span></td>
! 708: <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
! 709: <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>
! 710: </tr>
1.14 raeburn 711: </table>
712: </fieldset>
713: </td>
714: <td width='5'> </td>
715: </tr>
716: <tr height='5'>
717: <td colspan='3' height='5'> </td>
718: </tr>
719: END
1.44 ! raeburn 720: if ($command ne 'process') {
1.14 raeburn 721: $r->print('
722: <tr>
723: <td colspan="3">'.&mt('
1.44 ! raeburn 724: Please review the information in "Log-in help"').$getstarttext.' '.&mt('if you are unable to log-in').'. '.&mt('If your problem is still unresolved, the form below can be used to send a question to the LON-CAPA helpdesk').'.<br /><font size="-1"><b>'.&mt('Students').'</b>: '.&mt('Do <b>not</b> use this form to ask questions about course content.').' '.&mt('Contact your instructor instead.').'</font><br /><br />
1.14 raeburn 725: </td>
726: </tr>');
727: }
728: $r->print('
729: </table>');
730: return;
731: }
732:
1.1 raeburn 733: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>