Annotation of loncom/interface/lonsupportreq.pm, revision 1.31
1.24 albertel 1: #
1.31 ! albertel 2: # $Id: lonsupportreq.pm,v 1.30 2006/03/15 19:41:26 albertel 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;
30: use lib qw(/home/httpd/lib/perl);
1.5 raeburn 31: use MIME::Types;
32: use MIME::Lite;
1.27 raeburn 33: use CGI::Cookie();
1.1 raeburn 34: use Apache::Constants qw(:common);
1.2 albertel 35: use Apache::loncommon();
1.24 albertel 36: use Apache::lonnet;
1.1 raeburn 37: use Apache::lonlocal;
38:
39: sub handler {
1.2 albertel 40: my ($r) = @_;
41: &Apache::loncommon::content_type($r,'text/html');
1.1 raeburn 42: $r->send_http_header;
43:
44: if ($r->header_only) {
45: return OK;
46: }
1.12 raeburn 47: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['origurl','function']);
48: if ($r->uri eq '/adm/helpdesk') {
49: &Apache::loncommon::get_posted_cgi($r);
50: }
1.25 albertel 51: my $function = $env{'form.function'};
52: my $origurl = &Apache::lonnet::unescape($env{'form.origurl'});
53: my $action = $env{'form.action'};
1.12 raeburn 54:
1.1 raeburn 55: if ($action eq 'process') {
56: &print_request_receipt($r,$origurl,$function);
57: } else {
58: &print_request_form($r,$origurl,$function);
59: }
60: return OK;
61: }
62:
63: sub print_request_form {
64: my ($r,$origurl,$function) = @_;
1.29 raeburn 65: my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$urole,$usec,$email,$cid,$cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server,$formname);
1.1 raeburn 66: my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');
1.5 raeburn 67: if (($tablecolor eq '') || ($tablecolor eq '#FFFFFF')) {
1.14 raeburn 68: $tablecolor = '#EEEE99';
1.5 raeburn 69: }
1.10 raeburn 70: $ccode = '';
1.25 albertel 71: $os = $env{'browser.os'};
72: $browser = $env{'browser.type'};
73: $bversion = $env{'browser.version'};
74: $uhost = $env{'request.host'};
75: $uname = $env{'user.name'};
76: $udom = $env{'user.domain'};
77: $uhome = $env{'user.home'};
78: $urole = $env{'request.role'};
79: $usec = $env{'request.course.sec'};
80: $cid = $env{'request.course.id'};
1.29 raeburn 81: $formname = 'logproblem';
1.21 raeburn 82: if ($origurl =~ m-^http://-) {
83: $server = $origurl;
84: } else {
85: $server = 'http://'.$ENV{'SERVER_NAME'}.$origurl;
86: }
1.13 raeburn 87: my $scripttag = (<<'END');
1.5 raeburn 88: function validate() {
1.13 raeburn 89: if (validmail(document.logproblem.email) == false) {
90: alert("The e-mail address you entered: "+document.logproblem.email.value+" is not a valid e-mail address.");
91: return;
1.5 raeburn 92: }
93: document.logproblem.submit();
94: }
1.13 raeburn 95:
96: function validmail(field) {
97: var str = field.value;
98: if (window.RegExp) {
99: var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
1.31 ! albertel 100: var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"; //"
1.13 raeburn 101: var reg1 = new RegExp(reg1str);
102: var reg2 = new RegExp(reg2str);
103: if (!reg1.test(str) && reg2.test(str)) {
104: return true;
105: }
106: return false;
107: }
108: else
109: {
110: if(str.indexOf("@") >= 0) {
111: return true;
112: }
113: return false;
114: }
115: }
1.5 raeburn 116: END
1.31 ! albertel 117:
1.1 raeburn 118: if ($cid =~ m/_/) {
119: ($cdom,$cnum) = split/_/,$cid;
120: }
121: if ($cdom && $cnum) {
122: my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
123: $ctitle = $csettings{'description'};
124: $ccode = $csettings{'internal.coursecode'};
125: $sectionlist = $csettings{'internal.sectionnums'};
126: }
1.25 albertel 127: if ($env{'environment.critnotification'}) {
128: $email = $env{'environment.critnotification'};
1.1 raeburn 129: }
1.25 albertel 130: if (!$email && $env{'environment.notification'}) {
131: $email = $env{'environment.notification'};
1.1 raeburn 132: }
1.25 albertel 133: if ($env{'environment.lastname'}) {
134: $lastname = $env{'environment.lastname'};
1.1 raeburn 135: }
1.25 albertel 136: if ($env{'environment.firstname'}) {
137: $firstname = $env{'environment.firstname'};
1.1 raeburn 138: }
139: my @sections = split/,/,$sectionlist;
140: my %groupid = ();
141: foreach (@sections) {
142: my ($sec,$grp) = split/:/,$_;
143: $groupid{$sec} = $grp;
144: }
1.19 raeburn 145: my $codedom = $Apache::lonnet::perlvar{'lonDefDomain'};
146: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['codedom']);
1.25 albertel 147: if (exists($env{'form.codedom'})) {
148: $codedom = $env{'form.codedom'};
1.19 raeburn 149: }
1.21 raeburn 150: my $details_title;
151: if ($codedom) {
152: $details_title = '<br />('.$codedom.')';
153: }
1.1 raeburn 154: my %coursecodes = ();
155: my %codes = ();
156: my @codetitles = ();
157: my %cat_titles = ();
158: my %cat_order = ();
1.6 raeburn 159: my %idlist = ();
160: my %idnums = ();
161: my %idlist_titles = ();
1.1 raeburn 162: my $caller = 'global';
163: my $totcodes = 0;
164: my $format_reply;
1.6 raeburn 165: my $jscript = '';
1.22 raeburn 166: my $loaditems = qq|
167: function initialize_codes() {
168: return;
169: }
170: |;
1.1 raeburn 171: if ($cdom) {
172: $codedom = $cdom;
173: }
174: if ($cnum) {
175: $coursecodes{$cnum} = $ccode;
176: if ($ccode eq '') {
177: $totcodes = &retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
178: } else {
179: $coursecodes{$cnum} = $ccode;
180: $caller = $cnum;
181: $totcodes ++;
182: }
183: } else {
184: $totcodes = &retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
185: }
186: if ($totcodes > 0) {
1.6 raeburn 187: if ($ccode eq '') {
1.22 raeburn 188: $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
189: if ($format_reply eq 'ok') {
190: my $numtypes = @codetitles;
191: &build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
1.29 raeburn 192: &javascript_code_selections($formname,$numtypes,\%cat_titles,\$jscript,\%idlist,\%idnums,\%idlist_titles,\@codetitles);
1.22 raeburn 193: $loaditems = '';
194: }
1.6 raeburn 195: }
1.1 raeburn 196: }
1.30 albertel 197:
1.31 ! albertel 198: my $js = '<script type"text/javascript">'."\n$scripttag\n$jscript\n".
! 199: '</script>';
! 200: my $add_entries =
! 201: 'topmargin="0" marginheight="0" onLoad="initialize_codes()"',
! 202: my $start_page =
! 203: &Apache::loncommon::start_page('Support Request',$js,
! 204: { 'function' => $function,
! 205: 'add_entries' => $add_entries,
! 206: 'only_body' => 1,});
! 207: $r->print($start_page);
! 208:
1.15 raeburn 209: if ($r->uri eq '/adm/helpdesk') {
1.14 raeburn 210: &print_header($r,$origurl);
211: }
212: $r->print(<<"END");
1.15 raeburn 213: <form method="post" name="logproblem" enctype="multipart/form-data">
1.1 raeburn 214: <table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
215: <tr>
216: <td>
217: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
218: <tr>
219: <td>
220: <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
221: <tr>
222: <td>
223: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
224: <tr>
225: <td width="140" bgcolor="$tablecolor">
226: <table width="140" border="0" cellpadding="8" cellspacing="0">
227: <tr>
228: <td align="right"><b>Name:</b>
229: </td>
230: </tr>
231: </table>
232: </td>
233: <td width="100%" valign="top">
234: <table width="100%" border="0" cellpadding="8" cellspacing="0">
235: <tr>
236: <td>
237: END
238: my $fullname = '';
239: if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) {
240: $fullname = "$firstname $lastname";
241: $r->print("$fullname<input type=\"hidden\" name=\"username\" value=\"$fullname\" />");
242: } else {
243: if (defined($firstname) && $firstname ne '') {
244: $fullname = $firstname;
245: } elsif (defined($lastname) && $lastname ne '') {
246: $fullname= " $lastname";
247: }
1.17 raeburn 248: $r->print('<input type="text" size="20" name="username" value="'.$fullname.'" />');
1.1 raeburn 249: }
250: $r->print(<<END);
1.18 raeburn 251: <input type="button" value="Submit Request" onClick="validate()" />
1.1 raeburn 252: </td>
253: </tr>
254: </table>
255: </td>
256: </tr>
257: <tr>
258: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 259: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 260: </td>
261: </tr>
262: <tr>
263: <td width="140" bgcolor="$tablecolor">
264: <table width="140" border="0" cellpadding="8" cellspacing="0">
265: <tr>
266: <td align="right"><b>E-mail address:</b>
267: </td>
268: </tr>
269: </table>
270: </td>
271: <td width="100%" valign="top">
272: <table width="100%" border="0" cellpadding="8" cellspacing="0">
273: <tr>
274: <td>
275: <input type="text" size="20" name="email" value="$email" /><br />
276: </td>
277: </tr>
278: </table>
279: </td>
280: </tr>
281: <tr>
282: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 283: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 284: </td>
285: </tr>
286: <tr>
287: <td width="140" bgcolor="$tablecolor">
288: <table width="140" border="0" cellpadding="8" cellspacing="0">
289: <tr>
290: <td align="right"><b>username/domain:</b>
291: </td>
292: </tr>
293: </table>
294: </td>
295: <td width="100%" valign="top">
296: <table width="100%" border="0" cellpadding="8" cellspacing="0">
297: <tr>
298: <td>
299: END
300: my $udom_input = '<input type="hidden" name="udom" value="'.$udom.'" />';
301: my $uname_input = '<input type="hidden" name="uname" value="'.$uname.'" />';
302: if (defined($uname) && defined($udom)) {
303: $r->print('<i>username</i>: '.$uname.' <i>domain</i>: '.$udom.$udom_input.$uname_input);
304: } else {
305: my $udomform = '';
306: my $unameform = '';
307: if (defined($udom)) {
308: $udomform = '<i>domain</i>: '.$udom.$udom_input;
309: } elsif (defined($uname)) {
310: $unameform = '<i>username</i>: '.$uname.' '.$uname_input;
311: }
312: if ($udomform eq '') {
313: $udomform = '<i>domain</i>: ';
1.19 raeburn 314: $udomform .= &Apache::loncommon::select_dom_form($codedom,'udom');
1.1 raeburn 315: }
316: if ($unameform eq '') {
1.19 raeburn 317: $unameform= '<i>username</i>: <input type="text" size="12" name="uname" value="'.$uname.'" /> ';
1.1 raeburn 318: }
319: $r->print($unameform.$udomform.'<br />Enter the username you use to log-in to your LON-CAPA system, and choose your domain.');
320: }
321: $r->print(<<END);
322: </td>
323: </tr>
324: </table>
325: </td>
326: </tr>
327: <tr>
328: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 329: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 330: </td>
331: </tr>
332: <tr>
333: <td width="140" bgcolor="$tablecolor">
334: <table width="140" border="0" cellpadding="8" cellspacing="0">
335: <tr>
336: <td align="right"><b>URL of page:</b>
337: </td>
338: </tr>
339: </table>
340: </td>
341: <td width="100%" valign="top">
342: <table width="100%" border="0" cellpadding="8" cellspacing="0">
343: <tr>
344: <td>
1.21 raeburn 345: $server<input type="hidden" name="sourceurl" value="$server" />
1.1 raeburn 346: </td>
347: </tr>
348: </table>
349: </td>
350: </tr>
351: <tr>
352: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 353: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 354: </td>
355: </tr>
356: <tr>
357: <td width="140" bgcolor="$tablecolor">
358: <table width="140" border="0" cellpadding="8" cellspacing="0">
359: <tr>
360: <td align="right"><b>Phone #:</b>
361: </td>
362: </tr>
363: </table>
364: </td>
365: <td width="100%" valign="top">
366: <table width="100%" border="0" cellpadding="8" cellspacing="0">
367: <tr>
368: <td>
369: <input type="text" size="15" name="phone"><br>
370: </td>
371: </tr>
372: </table>
373: </td>
374: </tr>
375: <tr>
376: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 377: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 378: </td>
379: </tr>
380: <tr>
381: <td width="140" bgcolor="$tablecolor">
382: <table width="140" border="0" cellpadding="8" cellspacing="0">
383: <tr>
1.21 raeburn 384: <td align="right"><b>Course Details:</b>$details_title
1.1 raeburn 385: </td>
386: </tr>
387: </table>
388: </td>
389: <td width="100%" valign="top">
390: <table border="0" cellpadding="3" cellspacing="3">
391: <tr>
392: <td>
393: END
1.10 raeburn 394: if ($cnum) {
395: if ($coursecodes{$cnum}) {
396: foreach (@codetitles) {
397: $r->print('<i>'.$_.'</i>: '.$codes{$cnum}{$_}.'; ');
398: }
399: $r->print(' <input type="hidden" name="coursecode" value="'.$coursecodes{$cnum}.'" />');
400: } else {
401: $r->print('Enter institutional course code:
402: <input type="text" name="coursecode" size="15" value="" />');
1.1 raeburn 403: }
404: } else {
1.10 raeburn 405: if ($totcodes > 0) {
406: my $numtitles = @codetitles;
407: if ($numtitles == 0) {
408: $r->print('Enter institutional course code:
1.1 raeburn 409: <input type="text" name="coursecode" size="15" value="" />');
1.10 raeburn 410: } else {
411: my $lasttitle = $numtitles;
412: if ($numtitles > 4) {
413: $lasttitle = 4;
414: }
415: $r->print('<table><tr><td>'.$codetitles[0].'<br />'."\n".
416: '<select name="'.$codetitles[0].'" onChange="courseSet('."'$codetitles[0]'".')">'."\n".
417: ' <option value="-1" />Select'."\n");
418: my @items = ();
1.20 raeburn 419: my @longitems = ();
1.10 raeburn 420: if ($idlist{$codetitles[0]} =~ /","/) {
421: @items = split/","/,$idlist{$codetitles[0]};
422: } else {
423: $items[0] = $idlist{$codetitles[0]};
424: }
1.20 raeburn 425: if (defined($idlist_titles{$codetitles[0]})) {
426: if ($idlist_titles{$codetitles[0]} =~ /","/) {
427: @longitems = split/","/,$idlist_titles{$codetitles[0]};
428: } else {
429: $longitems[0] = $idlist_titles{$codetitles[0]};
430: }
1.22 raeburn 431: for (my $i=0; $i<@longitems; $i++) {
432: if ($longitems[$i] eq '') {
433: $longitems[$i] = $items[$i];
434: }
435: }
1.20 raeburn 436: } else {
437: @longitems = @items;
438: }
439: for (my $i=0; $i<@items; $i++) {
440: $r->print(' <option value="'.$items[$i].'">'.$longitems[$i].'</option>');
1.10 raeburn 441: }
442: $r->print('</select></td>');
443: for (my $i=1; $i<$numtitles; $i++) {
444: $r->print('<td>'.$codetitles[$i].'<br />'."\n".
445: '<select name="'.$codetitles[$i].'" onChange="courseSet('."'$codetitles[$i]'".')">'."\n".
446: '<option value="-1"><-Pick '.$codetitles[$i-1].'</option>'."\n".
447: '</select>'."\n".
448: '</td>'
449: );
450: }
451: $r->print('</tr></table>');
452: if ($numtitles > 4) {
453: $r->print('<br /><br />'.$codetitles[$numtitles].'<br />'."\n".
454: '<select name="'.$codetitles[$numtitles].'" onChange="courseSet('."'$codetitles[$numtitles]'".')">'."\n".
455: '<option value="-1"><-Pick '.$codetitles[$numtitles-1].'</option>'."\n".
456: '</select>'."\n");
457: }
458: }
459: } else {
460: $r->print('Enter institutional course code:
461: <input type="text" name="coursecode" size="15" value="" />');
462: }
1.1 raeburn 463: }
464: if ($ctitle) {
465: $r->print('<br /><i>Title</i>: '.$ctitle.'<input type="hidden" name="title" value="'.$ctitle.'" />');
466: } else {
467: $r->print('<br />Enter course title:
1.10 raeburn 468: <input type="text" name="title" size="25" value="" />');
1.1 raeburn 469: }
470: $r->print(<<END);
471: </td>
472: </tr>
473: </table>
474: </td>
475: </tr>
476: <tr>
477: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 478: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 479: </td>
480: </tr>
481: <tr>
482: <td width="140" bgcolor="$tablecolor">
483: <table width="140" border="0" cellpadding="8" cellspacing="0">
484: <tr>
485: <td align="right"><b>Section Number: </b>
486: </td>
487: </tr>
488: </table>
489: </td>
490: <td width="100%" valign="top">
491: <table width="100%" border="0" cellpadding="8" cellspacing="0">
492: <tr>
493: <td>
494: END
495: if ($sectionlist) {
1.22 raeburn 496: $r->print("<select name=\"section\"\n>".
497: " <option value=\"\" selected=\"selected\">Select</option>\n");
1.1 raeburn 498: foreach (sort keys %groupid) {
499: if ($_ eq $groupid{$_} || $groupid{$_} eq '') {
1.22 raeburn 500: $r->print(" <option value=\"$_\" >$_</option>\n");
1.1 raeburn 501: } else {
1.22 raeburn 502: $r->print(" <option value=\"$_\" >$_ - (LON-CAPA sec: $groupid{$_})</option>\n");
1.1 raeburn 503: }
504: }
505: $r->print("</select>");
506: } else {
507: $r->print("<input type=\"text\" name=\"section\" size=\"10\"/>");
508: }
509: $r->print(<<END);
510: </td>
511: </tr>
512: </table>
513: </td>
514: </tr>
515: <tr>
516: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 517: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 518: </td>
519: </tr>
520: <tr>
521: <td width="140" bgcolor="$tablecolor">
522: <table width="140" border="0" cellpadding="8" cellspacing="0">
523: <tr>
524: <td align="right"><b>Subject</b>
525: </td>
526: </tr>
527: </table>
528: </td>
529: <td width="100%" valign="top">
530: <table width="100%" border="0" cellpadding="8" cellspacing="0">
531: <tr>
532: <td>
533: <input type="text" size="40" name="subject">
534: </td>
535: </tr>
536: </table>
537: </td>
538: </tr>
539: <tr>
540: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 541: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 542: </td>
543: </tr>
544: <tr>
545: <td width="140" bgcolor="$tablecolor">
546: <table width="140" border="0" cellpadding="8" cellspacing="0">
547: <tr>
548: <td align="right"><b>Detailed description:</b>
549: </td>
550: </tr>
551: </table>
552: </td>
553: <td width="100%" valign="top">
554: <table width="100%" border="0" cellpadding="8" cellspacing="0">
555: <tr>
556: <td>
557: <textarea rows="10" cols="45" name="description" wrap="virtual"></textarea>
558: </td>
559: </tr>
560: </table>
561: </td>
562: </tr>
563: <tr>
564: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 565: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 566: </td>
567: </tr>
1.5 raeburn 568: END
1.25 albertel 569: if (defined($env{'user.name'})) {
1.5 raeburn 570: $r->print(<<END);
571: <tr>
572: <td width="140" bgcolor="$tablecolor">
573: <table width="140" border="0" cellpadding="8" cellspacing="0">
574: <tr>
575: <td align="right"><b>Optional file upload:</b>
576: </td>
577: </tr>
578: </table>
579: </td>
580: <td width="100%" valign="top">
581: <table width="100%" border="0" cellpadding="8" cellspacing="0">
582: <tr>
583: <td>
584: <input type="file" name="screenshot" size="20" /><br />Upload a file (e.g., a screenshot) relevant to your support request (128 KB max. size).
585: </td>
586: </tr>
587: </table>
588: </td>
589: </tr>
590: <tr>
591: <td width="100%" colspan="2" bgcolor="#000000">
592: <img src="/adm/lonMisc/blackdot.gif" /><br />
593: </td>
594: </tr>
595: END
596: }
1.30 albertel 597:
1.5 raeburn 598: $r->print(<<END);
1.1 raeburn 599: <tr>
600: <td width="140" bgcolor="$tablecolor">
601: <table width="140" border="0" cellpadding="8" cellspacing="0">
602: <tr>
603: <td align="right"><b>Finish:</b>
604: </td>
605: </tr>
606: </table>
607: </td>
608: <td width="100%" valign="top">
609: <table border="0" cellpadding="8" cellspacing="0">
610: <tr>
611: <td>
612: <input type="hidden" name="action" value="process" />
1.15 raeburn 613: <input type="button" value="Submit Request" onClick="validate()"/>
1.1 raeburn 614: </td>
615: <td> </td>
616: <td>
617: <input type="reset" value="Clear Form">
618: </td>
619: </tr>
620: </table>
621: </td>
622: </tr>
623: </table>
624: </td>
625: </tr>
626: </table>
627: </td>
628: </tr>
629: </table>
630: </td>
631: </tr>
632: </table>
1.14 raeburn 633: </form>
1.1 raeburn 634: END
1.30 albertel 635: $r->print(&Apache::loncommon::end_page());
1.5 raeburn 636: return;
1.1 raeburn 637: }
638:
639: sub print_request_receipt {
640: my ($r,$url,$function) = @_;
1.26 raeburn 641: my @ENVvars = ('HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME');
642: my @envvars = ('browser.os','browser.type','browser.version','user.home','request.role');
1.5 raeburn 643: my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');
1.27 raeburn 644: my @cookievars = ('lonID');
1.5 raeburn 645:
1.1 raeburn 646: my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0" marginheight="0"',1);
1.5 raeburn 647: my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
1.1 raeburn 648: my $to = $Apache::lonnet::perlvar{'lonSupportEMail'};
1.5 raeburn 649: my $from = $admin;
1.1 raeburn 650: my $reporttime = &Apache::lonlocal::locallocaltime(time);
651: my $fontcolor = &Apache::loncommon::designparm($function.'.font');
652: my $vlinkcolor = &Apache::loncommon::designparm($function.'.vlink');
653: my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');
1.14 raeburn 654: my @formvars = ('username','email','uname','udom','sourceurl','phone','section','coursecode','title','subject','description','screenshot');
1.20 raeburn 655:
1.1 raeburn 656: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);
1.25 albertel 657: my $coursecode = $env{'form.coursecode'};
1.19 raeburn 658: if ($coursecode eq '') {
1.25 albertel 659: if (defined($env{'form.Year'})) {
660: $coursecode .= $env{'form.Year'};
1.19 raeburn 661: }
1.25 albertel 662: if (defined($env{'form.Semester'})) {
663: $coursecode .= $env{'form.Semester'};
1.19 raeburn 664: }
1.25 albertel 665: if (defined($env{'form.Department'})) {
666: $coursecode .= $env{'form.Department'};
1.19 raeburn 667: }
1.25 albertel 668: if (defined($env{'form.Number'})) {
669: $coursecode .= $env{'form.Number'};
1.19 raeburn 670: }
671: }
1.1 raeburn 672: my $supportmsg = qq|
1.25 albertel 673: Name: $env{'form.username'}
674: Email: $env{'form.email'}
675: Username/domain: $env{'form.uname'} - $env{'form.udom'}
676: Tel: $env{'form.phone'}
677: Course Information: $env{'form.title'} - $coursecode - section: $env{'form.section'}
678: Subject: $env{'form.subject'}
679: Description: $env{'form.description'}
680: URL: $env{'form.sourceurl'}
1.1 raeburn 681: Date/Time: $reporttime
682:
683: |;
1.25 albertel 684: my $descrip = $env{'form.description'};
1.5 raeburn 685: $descrip =~ s#\n#<br />#g;
686: my $displaymsg = qq|
1.25 albertel 687: <font color="$fontcolor">Name:</font><font color="$vlinkcolor"> $env{'form.username'}</font><br />
688: <font color="$fontcolor">Email: </font><font color="$vlinkcolor">$env{'form.email'}</font><br />
689: <font color="$fontcolor">Username/domain: </font><font color="$vlinkcolor">$env{'form.uname'} - $env{'form.udom'}</font><br />
690: <font color="$fontcolor">Tel: </font><font color="$vlinkcolor">$env{'form.phone'}</font><br />
691: <font color="$fontcolor">Course Information: </font><font color="$vlinkcolor">$env{'form.title'} - $coursecode - section: $env{'form.section'}</font><br />
692: <font color="$fontcolor">Subject: </font><font color="$vlinkcolor">$env{'form.subject'}</font><br />
1.5 raeburn 693: <font color="$fontcolor">Description: </font><font color="$vlinkcolor">$descrip</font><br />
1.25 albertel 694: <font color="$fontcolor">URL: </font><font color="$vlinkcolor">$env{'form.sourceurl'}</font><br />
1.5 raeburn 695: <font color="$fontcolor">Date/Time: </font><font color="$vlinkcolor">$reporttime</font><br />
696: |;
1.23 albertel 697: my $html=&Apache::lonxml::xmlbegin();
1.30 albertel 698: my $head = &Apache::loncommon::head('LON-CAPA support request recorded');
1.14 raeburn 699: $r->print(<<"END");
1.23 albertel 700: $html
1.30 albertel 701: $head
1.1 raeburn 702: $bodytag
1.16 raeburn 703: <form name="logproblem">
1.18 raeburn 704: <input type="hidden" name="action" value="result" />
1.16 raeburn 705: </form>
1.1 raeburn 706: END
1.14 raeburn 707: if ($r->uri eq '/adm/helpdesk') {
708: &print_header($r,$url,'process');
709: }
710: if ($to =~ m/^[^\@]+\@[^\@]+$/) {
711: $r->print("<h3>A support request has been sent to $to</h3>");
1.9 raeburn 712: } else {
713: $to = $admin;
714: if ($to =~ m/^[^\@]+\@[^\@]+$/) {
1.14 raeburn 715: $r->print("<h3>A support request has been sent to $to</h3>");
1.9 raeburn 716: END
717: } else {
718: $r->print(<<END);
1.1 raeburn 719: <h3>Warning: Problem with support e-mail address</h3>
1.9 raeburn 720: As the e-mail address provided for this LON-CAPA server ($to) 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. Instead a copy has been sent to the LON-CAPA support team at Michigan State University.
1.1 raeburn 721: END
1.9 raeburn 722: $to = 'helpdesk@lon-capa.org';
723: }
1.1 raeburn 724: }
1.25 albertel 725: if (defined($env{'form.email'})) {
726: if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
727: $from = $env{'form.email'};
1.5 raeburn 728: }
729: }
730:
1.25 albertel 731: my $subject = $env{'form.subject'};
1.5 raeburn 732: $subject =~ s#(`)#'#g;
733: $subject =~ s#\$#\(\$\)#g;
734: $supportmsg =~ s#(`)#'#g;
735: $supportmsg =~ s#\$#\(\$\)#g;
736: $displaymsg =~ s#(`)#'#g;
737: $displaymsg =~ s#\$#\(\$\)#g;
738: my $fname;
739:
740: my $attachmentpath = '';
741: my $attachmentsize = '';
1.25 albertel 742: if (defined($env{'user.name'})) {
743: if ($env{'form.screenshot.filename'}) {
744: $attachmentsize = length($env{'form.screenshot'});
1.5 raeburn 745: if ($attachmentsize > 131072) {
746: $displaymsg .= "<br />The uploaded screenshot file ($attachmentsize bytes) included with your request exceeded the maximum allowed size - 128 KB, and has therefore been discarded.";
747: } else {
748: $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
749: }
750: }
751: }
752:
1.27 raeburn 753: my %cookies = ();
754: my $cookie=CGI::Cookie->parse($r->header_in('Cookie'));
755: if ($$cookie{'lonID'} =~ /lonID=(\w+);/) {
756: $cookies{'lonID'} = $1;
757: }
758:
1.5 raeburn 759: if ($attachmentpath =~ m-/([^/]+)$-) {
760: $fname = $1;
1.25 albertel 761: $displaymsg .= "<br />An uploaded screenshot file - $fname ($attachmentsize bytes) was included in the request sent by $env{'user.name'} from LON-CAPA domain: $env{'user.domain'}";
1.5 raeburn 762: $supportmsg .= "\n";
1.27 raeburn 763: foreach (@cookievars) {
764: $supportmsg .= "$_: $cookies{$_}\n";
765: }
1.26 raeburn 766: foreach (@ENVvars) {
767: $supportmsg .= "$_: $ENV{$_}\n";
768: }
1.5 raeburn 769: foreach (@envvars) {
1.25 albertel 770: $supportmsg .= "$_: $env{$_}\n";
1.5 raeburn 771: }
772: }
773:
774: my $msg = MIME::Lite->new(
775: From => $from,
776: To => $to,
777: Subject => $subject,
778: Type =>'TEXT',
779: Data => $supportmsg,
780: );
781:
782: if ($attachmentpath) {
783: my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath);
784: $msg->attach(Type => $type,
785: Path => $attachmentpath,
786: Filename => $fname
787: );
788:
789: } else {
790: my $envdata = '';
1.27 raeburn 791: foreach (@cookievars) {
792: $envdata .= "$_: $cookies{$_}\n";
793: }
1.26 raeburn 794: foreach (@ENVvars) {
795: $envdata .= "$_: $ENV{$_}\n";
796: }
1.5 raeburn 797: foreach (@envvars) {
1.25 albertel 798: $envdata .= "$_: $env{$_}\n";
1.5 raeburn 799: }
800: foreach (@loncvars) {
1.25 albertel 801: $envdata .= "$_: $env{$_}\n";
1.5 raeburn 802: }
803: $msg->attach(Type => 'TEXT',
804: Data => $envdata);
805: }
806:
807: ### Send it:
808: $msg->send('sendmail');
809:
810: if ($attachmentpath =~ m#$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+#) {
811: unlink($attachmentpath);
812: }
813: $r->print(qq|
1.1 raeburn 814: <b>Your support request contained the following information</b>:<br /><br />
815: <table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
816: <tr>
817: <td>
818: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
819: <tr>
820: <td>
821: <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
822: <tr>
823: <td>
824: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
825: <tr>
826: <td width="140" bgcolor="$tablecolor">
827: <table width="140" border="0" cellpadding="8" cellspacing="0">
828: <tr>
829: <td align="right"><b>Information supplied</b>
830: </td>
831: </tr>
832: </table>
833: </td>
834: <td width="100%" valign="top">
835: <table width="100%" border="0" cellpadding="8" cellspacing="0">
836: <tr>
1.5 raeburn 837: <td>$displaymsg</td>
1.1 raeburn 838: </tr>
839: </table>
840: </td>
841: </tr>
842: <tr>
1.5 raeburn 843: <td width="100%" colspan="2" bgcolor="#000000">
844: <img src="/adm/lonMisc/blackdot.gif" /><br />
845: </td>
846: </tr>
847: <tr>
848: <td width="140" bgcolor="$tablecolor">
849: <table width="140" border="0" cellpadding="8" cellspacing="0">
1.1 raeburn 850: <tr>
851: <td align="right"><b>Additional information recorded</b>
852: </td>
853: </tr>
854: </table>
855: </td>
856: <td width="100%" valign="top">
857: <table width="100%" border="0" cellpadding="8" cellspacing="0">
858: <tr>
859: <td>
1.5 raeburn 860: |);
1.27 raeburn 861: foreach (@cookievars) {
862: unless($cookies{$_} eq '') {
863: $r->print("$_: <font color='$vlinkcolor'>$cookies{$_}</font>, ");
864: }
865: }
1.26 raeburn 866: foreach (@ENVvars) {
867: unless($ENV{$_} eq '') {
868: $r->print("$_: <font color='$vlinkcolor'>$ENV{$_}</font>, ");
869: }
870: }
1.1 raeburn 871: foreach (@envvars) {
1.25 albertel 872: unless($env{$_} eq '') {
873: $r->print("$_: <font color='$vlinkcolor'>$env{$_}</font>, ");
1.5 raeburn 874: }
1.1 raeburn 875: }
876: $r->print("
877: </td>
878: </tr>
879: </table>
880: </td>
881: </tr>
882: </table>
883: </td>
884: </tr>
885: </table>
886: </td>
887: </tr>
888: </table>
889: </td>
890: </tr>
891: </table>
892: ");
1.30 albertel 893: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 894: }
895:
1.14 raeburn 896: sub print_header {
897: my ($r,$origurl,$action) = @_;
898: my $location=&Apache::loncommon::lonhttpdurl("/adm");
899: my $tablecolor = '#EEEE99';
900: my ($component_url);
901: my $helpdesk_link = '<a href="javascript:validate()">';
902: if ($action eq 'process') {
903: $helpdesk_link = '<a href="/adm/helpdesk">';
904: }
905: my %lt = &Apache::lonlocal::texthash (
906: login => 'Log-in help',
907: ask => 'Ask helpdesk',
908: getst => 'Getting started guide',
909: back => 'Back to last location'
1.21 raeburn 910: );
911: my ($getstartlink,$getstarttext);
912: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/gettingstarted.html') {
913: $getstartlink = qq|<td align="center"> <b><a href="/adm/gettingstarted.html">$lt{'getst'}</a></td>|;
914: $getstarttext = ' '.&mt('and the "Getting started" guide').' ';
915: }
1.14 raeburn 916: $r->print(<<END);
917: <table width="620" border="0" cellspacing="0" cellpadding="0" height="55"> <tr height="50"> <td width='5'> </td>
918: <td>
919: <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>
920: <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
921: <tr>
922: <td>
923: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
924: <tr>
925: <td>
926: <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
927: <tr>
928: <td>
929: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
930: <tr bgcolor="$tablecolor">
931: <td align="center"><img src="$location/help/gif/smallHelp.gif" border="0" alt="(Login help)" valign="middle" /> <b><a href="/adm/loginproblems.html">$lt{'login'}</a></td>
1.21 raeburn 932: <td align="center"> <b>$helpdesk_link<img src="$location/lonIcons/helpdesk.gif" border="0" alt="(Ask helpdesk)" valign="middle" /> $lt{'ask'}</a></b> </td>$getstartlink
1.14 raeburn 933: <td align="center"> <b><a href="$origurl" target="_top"><img src="$location/lonIcons/move_up.gif" border="0" alt="(Back to last location)" valign="middle" /> $lt{'back'}</a></b> </td>
934: </tr>
935: </table>
936: </td>
937: </tr>
938: </table>
939: </td>
940: </tr>
941: </table>
942: </td>
943: </tr>
944: </table>
945: </fieldset>
946: </td>
947: <td width='5'> </td>
948: </tr>
949: <tr height='5'>
950: <td colspan='3' height='5'> </td>
951: </tr>
952: END
953: unless ($action eq 'process') {
954: $r->print('
955: <tr>
956: <td colspan="3">'.&mt('
1.21 raeburn 957: 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('Note').':</b> '.&mt('Student questions about course content should be directed to the course instructor').'.</font><br /><br />
1.14 raeburn 958: </td>
959: </tr>');
960: }
961: $r->print('
962: </table>');
963: return;
964: }
965:
1.1 raeburn 966: sub retrieve_instcodes {
967: my ($coursecodes,$codedom,$totcodes) = @_;
1.28 raeburn 968: my %courses = &Apache::lonnet::courseiddump($codedom,'.',1,'.','.','.');
1.1 raeburn 969: foreach my $course (keys %courses) {
1.11 raeburn 970: if ($courses{$course} =~ m/^[^:]*:([^:]+)/) {
1.1 raeburn 971: $$coursecodes{$course} = &Apache::lonnet::unescape($1);
972: $totcodes ++;
973: }
974: }
975: return $totcodes;
976: }
977:
1.6 raeburn 978: sub build_code_selections {
979: my ($codes,$codetitles,$cat_titles,$cat_order,$idlist,$idnums,$idlist_titles) = @_;
980: my %idarrays = ();
981: for (my $i=1; $i<@{$codetitles}; $i++) {
982: %{$idarrays{$$codetitles[$i]}} = ();
983: }
984: foreach my $cid (sort keys %{$codes}) {
985: &recurse_list($cid,$codetitles,$codes,0,\%idarrays);
986: }
987: for (my $num=0; $num<@{$codetitles}; $num++) {
988: if ($num == 0) {
989: my @contents = ();
990: my @contents_titles = ();
991: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[0]}},\@contents);
992: if (defined($$cat_titles{$$codetitles[0]})) {
993: foreach (@contents) {
994: push @contents_titles, $$cat_titles{$$codetitles[0]}{$_};
995: }
996: }
997: $$idlist{$$codetitles[0]} = join('","',@contents);
998: $$idnums{$$codetitles[0]} = scalar(@contents);
999: if (defined($$cat_titles{$$codetitles[0]})) {
1000: $$idlist_titles{$$codetitles[0]} = join('","',@contents_titles);
1001: }
1002: } elsif ($num == 1) {
1003: %{$$idlist{$$codetitles[1]}} = ();
1004: %{$$idlist_titles{$$codetitles[1]}} = ();
1005: foreach my $key_a (keys %{$idarrays{$$codetitles[1]}}) {
1006: my @sorted_a = ();
1007: my @sorted_a_titles = ();
1008: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[1]}{$key_a}},\@sorted_a);
1009: if (defined($$cat_titles{$$codetitles[1]})) {
1010: foreach (@sorted_a) {
1011: push @sorted_a_titles, $$cat_titles{$$codetitles[1]}{$_};
1012: }
1013: }
1014: $$idlist{$$codetitles[1]}{$key_a} = join('","',@sorted_a);
1015: $$idnums{$$codetitles[1]}{$key_a} = scalar(@sorted_a);
1016: if (defined($$cat_titles{$$codetitles[1]})) {
1017: $$idlist_titles{$$codetitles[1]}{$key_a} = join('","',@sorted_a_titles);
1018: }
1019: }
1020: } elsif ($num == 2) {
1021: %{$$idlist{$$codetitles[2]}} = ();
1022: %{$$idlist_titles{$$codetitles[2]}} = ();
1023: foreach my $key_a (keys %{$idarrays{$$codetitles[2]}}) {
1024: %{$$idlist{$$codetitles[2]}{$key_a}} = ();
1025: %{$$idlist_titles{$$codetitles[2]}{$key_a}} = ();
1026: foreach my $key_b (keys %{$idarrays{$$codetitles[2]}{$key_a}}) {
1027: my @sorted_b = ();
1028: my @sorted_b_titles = ();
1029: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[2]}{$key_a}{$key_b}},\@sorted_b);
1.19 raeburn 1030: if (defined($$cat_titles{$$codetitles[2]})) {
1.6 raeburn 1031: foreach (@sorted_b) {
1.19 raeburn 1032: push @sorted_b_titles, $$cat_titles{$$codetitles[2]}{$_};
1.6 raeburn 1033: }
1034: }
1035: $$idlist{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_b);
1036: $$idnums{$$codetitles[2]}{$key_a}{$key_b} = scalar(@sorted_b);
1037: if (defined($$cat_titles{$$codetitles[2]})) {
1038: $$idlist_titles{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_b_titles);
1039: }
1040: }
1041: }
1042: } elsif ($num == 3) {
1043: %{$$idlist{$$codetitles[3]}} = ();
1044: foreach my $key_a (keys %{$idarrays{$$codetitles[3]}}) {
1045: %{$$idlist{$$codetitles[3]}{$key_a}} = ();
1046: foreach my $key_b (keys %{$idarrays{$$codetitles[3]}{$key_a}}) {
1047: %{$$idlist{$$codetitles[3]}{$key_a}{$key_b}} = ();
1048: foreach my $key_c (keys %{$idarrays{$$codetitles[3]}{$key_a}{$key_b}}) {
1049: my @sorted_c = ();
1.20 raeburn 1050: my @sorted_c_titles = ();
1.6 raeburn 1051: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[3]}{$key_a}{$key_b}{$key_c}},\@sorted_c);
1.20 raeburn 1052: if (defined($$cat_titles{$$codetitles[3]})) {
1053: foreach (@sorted_c) {
1054: push @sorted_c_titles, $$cat_titles{$$codetitles[3]}{$_};
1055: }
1056: }
1.6 raeburn 1057: $$idlist{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = join('","',@sorted_c);
1058: $$idnums{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = scalar(@sorted_c);
1.20 raeburn 1059: if (defined($$cat_titles{$$codetitles[3]})) {
1060: $$idlist_titles{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_c_titles);
1061: }
1.6 raeburn 1062: }
1063: }
1064: }
1065: } elsif ($num == 4) {
1066: %{$$idlist{$$codetitles[4]}} = ();
1067: foreach my $key_a (keys %{$idarrays{$$codetitles[4]}}) {
1068: %{$$idlist{$$codetitles[4]}{$key_a}} = ();
1069: foreach my $key_b (keys %{$idarrays{$$codetitles[4]}{$key_a}}) {
1070: %{$$idlist{$$codetitles[4]}{$key_a}{$key_b}} = ();
1071: foreach my $key_c (keys %{$idarrays{$$codetitles[4]}{$key_a}{$key_b}}) {
1072: %{$$idlist{$$codetitles[4]}{$key_a}{$key_b}{$key_c}} = ();
1073: foreach my $key_d (keys %{$idarrays{$$codetitles[4]}{$key_a}{$key_b}{$key_c}}) {
1074: my @sorted_d = ();
1.20 raeburn 1075: my @sorted_d_titles = ();
1.6 raeburn 1076: &sort_cats($num,$cat_order,$codetitles,$idarrays{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d},\@sorted_d);
1.20 raeburn 1077: if (defined($$cat_titles{$$codetitles[4]})) {
1078: foreach (@sorted_d) {
1079: push @sorted_d_titles, $$cat_titles{$$codetitles[4]}{$_};
1080: }
1081: }
1.6 raeburn 1082: $$idlist{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d} = join('","',@sorted_d);
1083: $$idnums{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d} = scalar(@sorted_d);
1084: }
1085: }
1086: }
1087: }
1088: }
1089: }
1090: }
1091:
1092: sub sort_cats {
1093: my ($num,$cat_order,$codetitles,$idsarrayref,$sorted) = @_;
1094: my @unsorted = @{$idsarrayref};
1095: if (defined($$cat_order{$$codetitles[$num]})) {
1096: foreach (@{$$cat_order{$$codetitles[$num]}}) {
1097: if (grep/^$_$/,@unsorted) {
1098: push @{$sorted}, $_;
1099: }
1100: }
1101: } else {
1102: @{$sorted} = sort (@unsorted);
1103: }
1104: }
1105:
1106:
1107: sub recurse_list {
1108: my ($cid,$codetitles,$codes,$num,$idarrays) = @_;
1109: if ($num == 0) {
1110: if (!grep/^$$codes{$cid}{$$codetitles[0]}$/,@{$$idarrays{$$codetitles[0]}}) {
1111: push @{$$idarrays{$$codetitles[0]}}, $$codes{$cid}{$$codetitles[0]};
1112: }
1113: } elsif ($num == 1) {
1114: if (defined($$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}})) {
1115: if (!grep/^$$codes{$cid}{$$codetitles[1]}$/,@{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}}) {
1116: push @{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}}, $$codes{$cid}{$$codetitles[1]};
1117: }
1118: } else {
1119: @{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}} = ("$$codes{$cid}{$$codetitles[1]}");
1120: }
1121: } elsif ($num == 2) {
1122: if (defined($$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}})) {
1123: if (defined($$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
1124: if (!grep/^$$codes{$cid}{$$codetitles[2]}$/,@{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}}) {
1125: push @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}}, $$codes{$cid}{$$codetitles[2]};
1126: }
1127: } else {
1128: @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ("$$codes{$cid}{$$codetitles[2]}");
1129: }
1130: } else {
1131: %{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}} = ();
1132: @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ("$$codes{$cid}{$$codetitles[2]}");
1133: }
1134: } elsif ($num == 3) {
1135: if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}})) {
1136: if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
1137: if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}})) {
1138: if (!grep/^$$codes{$cid}{$$codetitles[3]}$/,@{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}}) {
1139: push @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}}, $$codes{$cid}{$$codetitles[3]};
1140: }
1141: } else {
1142: @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
1143: }
1144: } else {
1145: %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
1146: @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
1147: }
1148: } else {
1149: %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}} = ();
1150: %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
1151: @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
1152: }
1153: } elsif ($num == 4) {
1154: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}})) {
1155: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
1156: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}})) {
1157: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}})) {
1158: if (!grep/^$$codes{$cid}{$$codetitles[4]}$/,@{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}}) {
1159: push @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}}, $$codes{$cid}{$$codetitles[4]};
1160: }
1161: } else {
1162: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
1163: }
1164: } else {
1165: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
1166: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
1167: }
1168: } else {
1169: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
1170: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
1171: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
1172: }
1173: } else {
1174: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}} = ();
1175: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
1176: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
1177: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[3]}");
1178: }
1179: }
1180: $num ++;
1181: if ($num <@{$codetitles}) {
1182: &recurse_list($cid,$codetitles,$codes,$num,$idarrays);
1183: }
1184: }
1185:
1186: sub javascript_code_selections {
1.29 raeburn 1187: my ($formname,$numcats,$cat_titles,$script_tag,$idlist,$idnums,$idlist_titles,$codetitles) = @_;
1.10 raeburn 1188: my $numtitles = @{$codetitles};
1.20 raeburn 1189: my @seltitles = ();
1.10 raeburn 1190: for (my $j=0; $j<$numtitles; $j++) {
1191: $seltitles[$j] = 'id'.$$codetitles[$j];
1192: }
1193: my $seltitle_str = join('","',@seltitles);
1.20 raeburn 1194: my @longtitles = ();
1195: for (my $i=0; $i<$numtitles; $i++) {
1196: if (defined($$cat_titles{$$codetitles[$i]})) {
1197: $longtitles[$i] = 1;
1198: } else {
1199: $longtitles[$i] = 0;
1200: }
1201: }
1202: my $longtitles_str = join('","',@longtitles);
1.6 raeburn 1203: $$script_tag .= <<END;
1204: function courseSet(caller) {
1.10 raeburn 1205: var ids = new Array ("$seltitle_str");
1206: var formitems = new Array ($numtitles);
1.20 raeburn 1207: var longtitles = new Array ("$longtitles_str");
1.29 raeburn 1208: var idyr = document.$formname.Year.selectedIndex
1209: var idsem = document.$formname.Semester.selectedIndex
1210: var iddept = document.$formname.Department.selectedIndex
1211: var idclass = document.$formname.Number.selectedIndex
1.6 raeburn 1212: var idyears = new Array("$$idlist{$$codetitles[0]}");
1213: END
1.20 raeburn 1214: if ($longtitles[0]) {
1215: $$script_tag .=
1216: qq| var idyearslongs = new Array("$$idlist_titles{$$codetitles[0]}")\n|;
1217: }
1218: $$script_tag .=
1219: " var idsems = new Array ($$idnums{$$codetitles[0]})\n";
1220: if ($longtitles[1]) {
1221: $$script_tag .=
1222: " var idsemslongs = new Array ($$idnums{$$codetitles[0]})\n";
1223: }
1224: $$script_tag .=
1225: " var idcodes = new Array ($$idnums{$$codetitles[0]})\n";
1226: if ($longtitles[2]) {
1227: $$script_tag .=
1228: " var idcodeslongs = new Array ($$idnums{$$codetitles[0]})\n";
1229: }
1230: $$script_tag .=
1231: " var idcourses = new Array ($$idnums{$$codetitles[0]})\n";
1232: if ($longtitles[3]) {
1233: $$script_tag .=
1234: " var idcourseslongs = new Array ($$idnums{$$codetitles[0]})\n";
1235: }
1236: my @sort_a = split/","/,$$idlist{$$codetitles[0]};
1.6 raeburn 1237: for (my $j=0; $j<@sort_a; $j++) {
1238: $$script_tag .= qq| idsems[$j] = new Array("$$idlist{$$codetitles[1]}{$sort_a[$j]}")\n|;
1.20 raeburn 1239: if ($longtitles[1]) {
1240: $$script_tag .= qq| idsemslongs[$j] = new Array("$$idlist_titles{$$codetitles[1]}{$sort_a[$j]}")\n|;
1241: }
1.6 raeburn 1242: $$script_tag .= qq| idcodes[$j] = new Array($$idnums{$$codetitles[1]}{$sort_a[$j]})\n|;
1.20 raeburn 1243: if ($longtitles[2]) {
1244: $$script_tag .= qq| idcodeslongs[$j] = new Array($$idnums{$$codetitles[1]}{$sort_a[$j]})\n|;
1245: }
1.6 raeburn 1246: $$script_tag .= qq| idcourses[$j] = new Array($$idnums{$$codetitles[1]}{$sort_a[$j]})\n|;
1.20 raeburn 1247: if ($longtitles[3]) {
1248: $$script_tag .= qq| idcourseslongs[$j] = new Array($$idnums{$$codetitles[1]}{$sort_a[$j]})\n|;
1249: }
1.6 raeburn 1250: my @sort_b = split/","/,$$idlist{$$codetitles[1]}{$sort_a[$j]};
1251: for (my $k=0; $k<@sort_b; $k++) {
1252: my $idcode_entry = $$idlist{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]};
1253: $$script_tag .= qq| idcodes[$j][$k] = new Array("$idcode_entry")\n|;
1.20 raeburn 1254: if ($longtitles[2]) {
1255: my $idcodelong_entry = $$idlist_titles{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]};
1256: $$script_tag .= qq| idcodeslongs[$j][$k] = new Array("$idcodelong_entry")\n|;
1257: }
1.6 raeburn 1258: $$script_tag .= qq| idcourses[$j][$k] = new Array($$idnums{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]})\n|;
1.20 raeburn 1259: if ($longtitles[3]) {
1260: $$script_tag .= qq| idcourseslongs[$j][$k] = new Array($$idnums{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]})\n|;
1261: }
1.6 raeburn 1262: my @sort_c = split/","/,$$idlist{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]};
1263: for (my $l=0; $l<@sort_c; $l++) {
1264: my $idcourse_entry = $$idlist{$$codetitles[3]}{$sort_a[$j]}{$sort_b[$k]}{$sort_c[$l]};
1265: $$script_tag .= qq| idcourses[$j][$k][$l] = new Array("$idcourse_entry")\n|;
1.20 raeburn 1266: if ($longtitles[3]) {
1267: my $idcourselong_entry = $$idlist_titles{$$codetitles[3]}{$sort_a[$j]}{$sort_b[$k]}{$sort_c[$l]};
1268: $$script_tag .= qq| idcourseslongs[$j][$k][$l] = new Array("$idcourselong_entry")\n|;
1269: }
1.6 raeburn 1270: }
1271: }
1272: }
1273: $$script_tag .= (<<END_OF_BLOCK);
1.22 raeburn 1274: var display = new Array($numtitles)
1.29 raeburn 1275: if (caller == "" || caller == "$$codetitles[0]") {
1276: if (caller == "") {
1277: document.$formname.Year.length = 0
1278: document.$formname.Year.options[0] = new Option("Select","-1",true,true)
1279: display[0] = new Array(idyears.length)
1280: for (var i=0; i<idyears.length; i++) {
1281: display[0][i] = idyears[i]
1282: if (longtitles[0] == 1) {
1283: if (idyearslongs[i] != "") {
1284: display[0][i] = idyearslongs[i]
1285: }
1286: }
1287: else {
1288: if (idyearslongs[i] != "") {
1289: display[0][i] = idyears[i]
1290: }
1291: }
1292: document.$formname.Year.options[i+1] = new Option(display[0][i],idyears[i],false,false)
1293: }
1294: document.$formname.Year.selectedIndex = 0;
1295: }
1296: document.$formname.Semester.length = 0
1297: document.$formname.Department.length = 0;
1298: document.$formname.Number.length = 0
1299: document.$formname.Department.options[0] = new Option("<-Pick $$codetitles[1]","-1",true,true)
1300: document.$formname.Number.options[0] = new Option("<-Pick $$codetitles[2]","-1",true,true)
1301: if (idyr == 0 || caller == "") {
1302: document.$formname.Semester.options[0] = new Option("<-Pick $$codetitles[0]","-1",true,true)
1303: }
1304: else {
1305: document.$formname.Semester.options[0] = new Option("Select","-1",true,true)
1306: display[1] = new Array(idsems[idyr-1].length)
1307: for (var i=0; i<idsems[idyr-1].length; i++) {
1308: display[1][i] = idsems[idyr-1][i]
1309: if (longtitles[1] == 1) {
1310: if (idsemslongs[idyr-1][i] != "") {
1311: display[1][i] = idsemslongs[idyr-1][i]
1312: }
1313: }
1314: document.$formname.Semester.options[i+1] = new Option(display[1][i],idsems[idyr-1][i],false,false)
1315: }
1316: }
1317: document.$formname.Semester.selectedIndex = 0;
1.6 raeburn 1318: }
1.19 raeburn 1319: if (caller == "$$codetitles[1]") {
1.29 raeburn 1320: document.$formname.Department.length = 0
1321: document.$formname.Number.length = 0
1322: document.$formname.Number.options[0] = new Option("<-Pick $$codetitles[2]","-1",true,true)
1.6 raeburn 1323: if (idsem == 0) {
1.29 raeburn 1324: document.$formname.Department.options[0] = new Option("<-Pick $$codetitles[1]","-1",true,true)
1.6 raeburn 1325: }
1326: else {
1.29 raeburn 1327: document.$formname.Department.options[0] = new Option("Select","-1",true,true)
1.22 raeburn 1328: display[2] = new Array(idcodes[idyr-1][idsem-1].length)
1.6 raeburn 1329: for (var i=0; i<idcodes[idyr-1][idsem-1].length; i++) {
1.22 raeburn 1330: display[2][i] = idcodes[idyr-1][idsem-1][i]
1.20 raeburn 1331: if (longtitles[2] == 1) {
1.22 raeburn 1332: if (idcodeslongs[idyr-1][idsem-1][i] != "") {
1333: display[2][i] = idcodeslongs[idyr-1][idsem-1][i]
1334: }
1.20 raeburn 1335: }
1.29 raeburn 1336: document.$formname.Department.options[i+1] = new Option(display[2][i],idcodes[idyr-1][idsem-1][i],false,false)
1.6 raeburn 1337: }
1338: }
1.29 raeburn 1339: document.$formname.Department.selectedIndex = 0
1.6 raeburn 1340: }
1.19 raeburn 1341: if (caller == "$$codetitles[2]") {
1.29 raeburn 1342: document.$formname.Number.length = 0
1.6 raeburn 1343: if (iddept == 0) {
1.29 raeburn 1344: document.$formname.Number.options[0] = new Option("<-Pick $$codetitles[2]","-1",true,true)
1.6 raeburn 1345: }
1346: else {
1.29 raeburn 1347: document.$formname.Number.options[0] = new Option("Select","-1",true,true)
1.22 raeburn 1348: display[3] = new Array (idcourses[idyr-1][idsem-1][iddept-1].length)
1.6 raeburn 1349: for (var i=0; i<idcourses[idyr-1][idsem-1][iddept-1].length; i++) {
1.22 raeburn 1350: display[3][i] = idcourses[idyr-1][idsem-1][iddept-1][i]
1.20 raeburn 1351: if (longtitles[3] == 1) {
1.22 raeburn 1352: if (idcourseslongs[idyr-1][idsem-1][iddept-1][i] != "") {
1353: display[3][i] = idcourseslongs[idyr-1][idsem-1][iddept-1][i]
1354: }
1.20 raeburn 1355: }
1.29 raeburn 1356: document.$formname.Number.options[i+1] = new Option(display[3][i],idcourses[idyr-1][idsem-1][iddept-1][i],false,false)
1.6 raeburn 1357: }
1358: }
1.29 raeburn 1359: document.$formname.Number.selectedIndex = 0
1.6 raeburn 1360: }
1361: }
1.22 raeburn 1362:
1363: function initialize_codes() {
1364: courseSet();
1365: return;
1366: }
1.6 raeburn 1367: END_OF_BLOCK
1368: }
1369:
1.1 raeburn 1370: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>