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