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