File:
[LON-CAPA] /
loncom /
interface /
lonsupportreq.pm
Revision
1.28:
download - view:
text,
annotated -
select for diffs
Tue Apr 12 00:20:00 2005 UTC (19 years, 4 months ago) by
raeburn
Branches:
MAIN
CVS tags:
version_2_0_X,
version_2_0_2,
version_2_0_1,
version_2_0_0,
version_1_99_3,
version_1_99_2,
version_1_99_1_tmcc,
version_1_99_1,
version_1_99_0_tmcc,
version_1_99_0,
HEAD
Bug 3912. DCs can use courseID (e.g., 257472759ae4061msul1) as a filter when using pickcourse.
1: #
2: # $Id: lonsupportreq.pm,v 1.28 2005/04/12 00:20:00 raeburn Exp $
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:
27: package Apache::lonsupportreq;
28:
29: use strict;
30: use lib qw(/home/httpd/lib/perl);
31: use MIME::Types;
32: use MIME::Lite;
33: use CGI::Cookie();
34: use Apache::Constants qw(:common);
35: use Apache::loncommon();
36: use Apache::lonnet;
37: use Apache::lonlocal;
38:
39: sub handler {
40: my ($r) = @_;
41: &Apache::loncommon::content_type($r,'text/html');
42: $r->send_http_header;
43:
44: if ($r->header_only) {
45: return OK;
46: }
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: }
51: my $function = $env{'form.function'};
52: my $origurl = &Apache::lonnet::unescape($env{'form.origurl'});
53: my $action = $env{'form.action'};
54:
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) = @_;
65: my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$urole,$usec,$email,$cid,$cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server);
66: my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0" marginheight="0" onLoad="initialize_codes()"',1);
67: my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');
68: if (($tablecolor eq '') || ($tablecolor eq '#FFFFFF')) {
69: $tablecolor = '#EEEE99';
70: }
71: $ccode = '';
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'};
82: if ($origurl =~ m-^http://-) {
83: $server = $origurl;
84: } else {
85: $server = 'http://'.$ENV{'SERVER_NAME'}.$origurl;
86: }
87: my $scripttag = (<<'END');
88: function validate() {
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;
92: }
93: document.logproblem.submit();
94: }
95:
96: function validmail(field) {
97: var str = field.value;
98: if (window.RegExp) {
99: var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
100: var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
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: }
116: END
117: #" stupid emacs
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: }
127: if ($env{'environment.critnotification'}) {
128: $email = $env{'environment.critnotification'};
129: }
130: if (!$email && $env{'environment.notification'}) {
131: $email = $env{'environment.notification'};
132: }
133: if ($env{'environment.lastname'}) {
134: $lastname = $env{'environment.lastname'};
135: }
136: if ($env{'environment.firstname'}) {
137: $firstname = $env{'environment.firstname'};
138: }
139: my @sections = split/,/,$sectionlist;
140: my %groupid = ();
141: foreach (@sections) {
142: my ($sec,$grp) = split/:/,$_;
143: $groupid{$sec} = $grp;
144: }
145: my $codedom = $Apache::lonnet::perlvar{'lonDefDomain'};
146: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['codedom']);
147: if (exists($env{'form.codedom'})) {
148: $codedom = $env{'form.codedom'};
149: }
150: my $details_title;
151: if ($codedom) {
152: $details_title = '<br />('.$codedom.')';
153: }
154: my %coursecodes = ();
155: my %codes = ();
156: my @codetitles = ();
157: my %cat_titles = ();
158: my %cat_order = ();
159: my %idlist = ();
160: my %idnums = ();
161: my %idlist_titles = ();
162: my $caller = 'global';
163: my $totcodes = 0;
164: my $format_reply;
165: my $jscript = '';
166: my $loaditems = qq|
167: function initialize_codes() {
168: return;
169: }
170: |;
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) {
187: if ($ccode eq '') {
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);
192: &javascript_code_selections($numtypes,\%cat_titles,\$jscript,\%idlist,\%idnums,\%idlist_titles,\@codetitles);
193: $loaditems = '';
194: }
195: }
196: }
197: my $html=&Apache::lonxml::xmlbegin();
198: $r->print(<<ENDHEAD);
199: $html
200: <head>
201: <title>LON-CAPA support request</title>
202: <script type"text/javascript">
203: $scripttag
204: $jscript
205: </script>
206: </head>
207: $bodytag
208: ENDHEAD
209: if ($r->uri eq '/adm/helpdesk') {
210: &print_header($r,$origurl);
211: }
212: $r->print(<<"END");
213: <form method="post" name="logproblem" enctype="multipart/form-data">
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: }
248: $r->print('<input type="text" size="20" name="username" value="'.$fullname.'" />');
249: }
250: $r->print(<<END);
251: <input type="button" value="Submit Request" onClick="validate()" />
252: </td>
253: </tr>
254: </table>
255: </td>
256: </tr>
257: <tr>
258: <td width="100%" colspan="2" bgcolor="#000000">
259: <img src="/adm/lonMisc/blackdot.gif" /><br />
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">
283: <img src="/adm/lonMisc/blackdot.gif" /><br />
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>: ';
314: $udomform .= &Apache::loncommon::select_dom_form($codedom,'udom');
315: }
316: if ($unameform eq '') {
317: $unameform= '<i>username</i>: <input type="text" size="12" name="uname" value="'.$uname.'" /> ';
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">
329: <img src="/adm/lonMisc/blackdot.gif" /><br />
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>
345: $server<input type="hidden" name="sourceurl" value="$server" />
346: </td>
347: </tr>
348: </table>
349: </td>
350: </tr>
351: <tr>
352: <td width="100%" colspan="2" bgcolor="#000000">
353: <img src="/adm/lonMisc/blackdot.gif" /><br />
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">
377: <img src="/adm/lonMisc/blackdot.gif" /><br />
378: </td>
379: </tr>
380: <tr>
381: <td width="140" bgcolor="$tablecolor">
382: <table width="140" border="0" cellpadding="8" cellspacing="0">
383: <tr>
384: <td align="right"><b>Course Details:</b>$details_title
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
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="" />');
403: }
404: } else {
405: if ($totcodes > 0) {
406: my $numtitles = @codetitles;
407: if ($numtitles == 0) {
408: $r->print('Enter institutional course code:
409: <input type="text" name="coursecode" size="15" value="" />');
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 = ();
419: my @longitems = ();
420: if ($idlist{$codetitles[0]} =~ /","/) {
421: @items = split/","/,$idlist{$codetitles[0]};
422: } else {
423: $items[0] = $idlist{$codetitles[0]};
424: }
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: }
431: for (my $i=0; $i<@longitems; $i++) {
432: if ($longitems[$i] eq '') {
433: $longitems[$i] = $items[$i];
434: }
435: }
436: } else {
437: @longitems = @items;
438: }
439: for (my $i=0; $i<@items; $i++) {
440: $r->print(' <option value="'.$items[$i].'">'.$longitems[$i].'</option>');
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: }
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:
468: <input type="text" name="title" size="25" value="" />');
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">
478: <img src="/adm/lonMisc/blackdot.gif" /><br />
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) {
496: $r->print("<select name=\"section\"\n>".
497: " <option value=\"\" selected=\"selected\">Select</option>\n");
498: foreach (sort keys %groupid) {
499: if ($_ eq $groupid{$_} || $groupid{$_} eq '') {
500: $r->print(" <option value=\"$_\" >$_</option>\n");
501: } else {
502: $r->print(" <option value=\"$_\" >$_ - (LON-CAPA sec: $groupid{$_})</option>\n");
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">
517: <img src="/adm/lonMisc/blackdot.gif" /><br />
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">
541: <img src="/adm/lonMisc/blackdot.gif" /><br />
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">
565: <img src="/adm/lonMisc/blackdot.gif" /><br />
566: </td>
567: </tr>
568: END
569: if (defined($env{'user.name'})) {
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: }
597: $r->print(<<END);
598: <tr>
599: <td width="140" bgcolor="$tablecolor">
600: <table width="140" border="0" cellpadding="8" cellspacing="0">
601: <tr>
602: <td align="right"><b>Finish:</b>
603: </td>
604: </tr>
605: </table>
606: </td>
607: <td width="100%" valign="top">
608: <table border="0" cellpadding="8" cellspacing="0">
609: <tr>
610: <td>
611: <input type="hidden" name="action" value="process" />
612: <input type="button" value="Submit Request" onClick="validate()"/>
613: </td>
614: <td> </td>
615: <td>
616: <input type="reset" value="Clear Form">
617: </td>
618: </tr>
619: </table>
620: </td>
621: </tr>
622: </table>
623: </td>
624: </tr>
625: </table>
626: </td>
627: </tr>
628: </table>
629: </td>
630: </tr>
631: </table>
632: </form>
633: </body>
634: </html>
635: END
636: return;
637: }
638:
639: sub print_request_receipt {
640: my ($r,$url,$function) = @_;
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');
643: my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');
644: my @cookievars = ('lonID');
645:
646: my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0" marginheight="0"',1);
647: my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
648: my $to = $Apache::lonnet::perlvar{'lonSupportEMail'};
649: my $from = $admin;
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');
654: my @formvars = ('username','email','uname','udom','sourceurl','phone','section','coursecode','title','subject','description','screenshot');
655:
656: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);
657: my $coursecode = $env{'form.coursecode'};
658: if ($coursecode eq '') {
659: if (defined($env{'form.Year'})) {
660: $coursecode .= $env{'form.Year'};
661: }
662: if (defined($env{'form.Semester'})) {
663: $coursecode .= $env{'form.Semester'};
664: }
665: if (defined($env{'form.Department'})) {
666: $coursecode .= $env{'form.Department'};
667: }
668: if (defined($env{'form.Number'})) {
669: $coursecode .= $env{'form.Number'};
670: }
671: }
672: my $supportmsg = qq|
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'}
681: Date/Time: $reporttime
682:
683: |;
684: my $descrip = $env{'form.description'};
685: $descrip =~ s#\n#<br />#g;
686: my $displaymsg = qq|
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 />
693: <font color="$fontcolor">Description: </font><font color="$vlinkcolor">$descrip</font><br />
694: <font color="$fontcolor">URL: </font><font color="$vlinkcolor">$env{'form.sourceurl'}</font><br />
695: <font color="$fontcolor">Date/Time: </font><font color="$vlinkcolor">$reporttime</font><br />
696: |;
697: my $html=&Apache::lonxml::xmlbegin();
698: $r->print(<<"END");
699: $html
700: <head>
701: <title>LON-CAPA support request recorded</title>
702: </head>
703: $bodytag
704: <form name="logproblem">
705: <input type="hidden" name="action" value="result" />
706: </form>
707: END
708: if ($r->uri eq '/adm/helpdesk') {
709: &print_header($r,$url,'process');
710: }
711: if ($to =~ m/^[^\@]+\@[^\@]+$/) {
712: $r->print("<h3>A support request has been sent to $to</h3>");
713: } else {
714: $to = $admin;
715: if ($to =~ m/^[^\@]+\@[^\@]+$/) {
716: $r->print("<h3>A support request has been sent to $to</h3>");
717: END
718: } else {
719: $r->print(<<END);
720: <h3>Warning: Problem with support e-mail address</h3>
721: 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.
722: END
723: $to = 'helpdesk@lon-capa.org';
724: }
725: }
726: if (defined($env{'form.email'})) {
727: if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
728: $from = $env{'form.email'};
729: }
730: }
731:
732: my $subject = $env{'form.subject'};
733: $subject =~ s#(`)#'#g;
734: $subject =~ s#\$#\(\$\)#g;
735: $supportmsg =~ s#(`)#'#g;
736: $supportmsg =~ s#\$#\(\$\)#g;
737: $displaymsg =~ s#(`)#'#g;
738: $displaymsg =~ s#\$#\(\$\)#g;
739: my $fname;
740:
741: my $attachmentpath = '';
742: my $attachmentsize = '';
743: if (defined($env{'user.name'})) {
744: if ($env{'form.screenshot.filename'}) {
745: $attachmentsize = length($env{'form.screenshot'});
746: if ($attachmentsize > 131072) {
747: $displaymsg .= "<br />The uploaded screenshot file ($attachmentsize bytes) included with your request exceeded the maximum allowed size - 128 KB, and has therefore been discarded.";
748: } else {
749: $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
750: }
751: }
752: }
753:
754: my %cookies = ();
755: my $cookie=CGI::Cookie->parse($r->header_in('Cookie'));
756: if ($$cookie{'lonID'} =~ /lonID=(\w+);/) {
757: $cookies{'lonID'} = $1;
758: }
759:
760: if ($attachmentpath =~ m-/([^/]+)$-) {
761: $fname = $1;
762: $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'}";
763: $supportmsg .= "\n";
764: foreach (@cookievars) {
765: $supportmsg .= "$_: $cookies{$_}\n";
766: }
767: foreach (@ENVvars) {
768: $supportmsg .= "$_: $ENV{$_}\n";
769: }
770: foreach (@envvars) {
771: $supportmsg .= "$_: $env{$_}\n";
772: }
773: }
774:
775: my $msg = MIME::Lite->new(
776: From => $from,
777: To => $to,
778: Subject => $subject,
779: Type =>'TEXT',
780: Data => $supportmsg,
781: );
782:
783: if ($attachmentpath) {
784: my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath);
785: $msg->attach(Type => $type,
786: Path => $attachmentpath,
787: Filename => $fname
788: );
789:
790: } else {
791: my $envdata = '';
792: foreach (@cookievars) {
793: $envdata .= "$_: $cookies{$_}\n";
794: }
795: foreach (@ENVvars) {
796: $envdata .= "$_: $ENV{$_}\n";
797: }
798: foreach (@envvars) {
799: $envdata .= "$_: $env{$_}\n";
800: }
801: foreach (@loncvars) {
802: $envdata .= "$_: $env{$_}\n";
803: }
804: $msg->attach(Type => 'TEXT',
805: Data => $envdata);
806: }
807:
808: ### Send it:
809: $msg->send('sendmail');
810:
811: if ($attachmentpath =~ m#$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+#) {
812: unlink($attachmentpath);
813: }
814: $r->print(qq|
815: <b>Your support request contained the following information</b>:<br /><br />
816: <table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
817: <tr>
818: <td>
819: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
820: <tr>
821: <td>
822: <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
823: <tr>
824: <td>
825: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
826: <tr>
827: <td width="140" bgcolor="$tablecolor">
828: <table width="140" border="0" cellpadding="8" cellspacing="0">
829: <tr>
830: <td align="right"><b>Information supplied</b>
831: </td>
832: </tr>
833: </table>
834: </td>
835: <td width="100%" valign="top">
836: <table width="100%" border="0" cellpadding="8" cellspacing="0">
837: <tr>
838: <td>$displaymsg</td>
839: </tr>
840: </table>
841: </td>
842: </tr>
843: <tr>
844: <td width="100%" colspan="2" bgcolor="#000000">
845: <img src="/adm/lonMisc/blackdot.gif" /><br />
846: </td>
847: </tr>
848: <tr>
849: <td width="140" bgcolor="$tablecolor">
850: <table width="140" border="0" cellpadding="8" cellspacing="0">
851: <tr>
852: <td align="right"><b>Additional information recorded</b>
853: </td>
854: </tr>
855: </table>
856: </td>
857: <td width="100%" valign="top">
858: <table width="100%" border="0" cellpadding="8" cellspacing="0">
859: <tr>
860: <td>
861: |);
862: foreach (@cookievars) {
863: unless($cookies{$_} eq '') {
864: $r->print("$_: <font color='$vlinkcolor'>$cookies{$_}</font>, ");
865: }
866: }
867: foreach (@ENVvars) {
868: unless($ENV{$_} eq '') {
869: $r->print("$_: <font color='$vlinkcolor'>$ENV{$_}</font>, ");
870: }
871: }
872: foreach (@envvars) {
873: unless($env{$_} eq '') {
874: $r->print("$_: <font color='$vlinkcolor'>$env{$_}</font>, ");
875: }
876: }
877: $r->print("
878: </td>
879: </tr>
880: </table>
881: </td>
882: </tr>
883: </table>
884: </td>
885: </tr>
886: </table>
887: </td>
888: </tr>
889: </table>
890: </td>
891: </tr>
892: </table>
893: </body>
894: </html>
895: ");
896: }
897:
898: sub print_header {
899: my ($r,$origurl,$action) = @_;
900: my $location=&Apache::loncommon::lonhttpdurl("/adm");
901: my $tablecolor = '#EEEE99';
902: my ($component_url);
903: my $helpdesk_link = '<a href="javascript:validate()">';
904: if ($action eq 'process') {
905: $helpdesk_link = '<a href="/adm/helpdesk">';
906: }
907: my %lt = &Apache::lonlocal::texthash (
908: login => 'Log-in help',
909: ask => 'Ask helpdesk',
910: getst => 'Getting started guide',
911: back => 'Back to last location'
912: );
913: my ($getstartlink,$getstarttext);
914: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/gettingstarted.html') {
915: $getstartlink = qq|<td align="center"> <b><a href="/adm/gettingstarted.html">$lt{'getst'}</a></td>|;
916: $getstarttext = ' '.&mt('and the "Getting started" guide').' ';
917: }
918: $r->print(<<END);
919: <table width="620" border="0" cellspacing="0" cellpadding="0" height="55"> <tr height="50"> <td width='5'> </td>
920: <td>
921: <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>
922: <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
923: <tr>
924: <td>
925: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
926: <tr>
927: <td>
928: <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
929: <tr>
930: <td>
931: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
932: <tr bgcolor="$tablecolor">
933: <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>
934: <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
935: <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>
936: </tr>
937: </table>
938: </td>
939: </tr>
940: </table>
941: </td>
942: </tr>
943: </table>
944: </td>
945: </tr>
946: </table>
947: </fieldset>
948: </td>
949: <td width='5'> </td>
950: </tr>
951: <tr height='5'>
952: <td colspan='3' height='5'> </td>
953: </tr>
954: END
955: unless ($action eq 'process') {
956: $r->print('
957: <tr>
958: <td colspan="3">'.&mt('
959: 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 />
960: </td>
961: </tr>');
962: }
963: $r->print('
964: </table>');
965: return;
966: }
967:
968: sub retrieve_instcodes {
969: my ($coursecodes,$codedom,$totcodes) = @_;
970: my %courses = &Apache::lonnet::courseiddump($codedom,'.',1,'.','.','.');
971: foreach my $course (keys %courses) {
972: if ($courses{$course} =~ m/^[^:]*:([^:]+)/) {
973: $$coursecodes{$course} = &Apache::lonnet::unescape($1);
974: $totcodes ++;
975: }
976: }
977: return $totcodes;
978: }
979:
980: sub build_code_selections {
981: my ($codes,$codetitles,$cat_titles,$cat_order,$idlist,$idnums,$idlist_titles) = @_;
982: my %idarrays = ();
983: for (my $i=1; $i<@{$codetitles}; $i++) {
984: %{$idarrays{$$codetitles[$i]}} = ();
985: }
986: foreach my $cid (sort keys %{$codes}) {
987: &recurse_list($cid,$codetitles,$codes,0,\%idarrays);
988: }
989: for (my $num=0; $num<@{$codetitles}; $num++) {
990: if ($num == 0) {
991: my @contents = ();
992: my @contents_titles = ();
993: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[0]}},\@contents);
994: if (defined($$cat_titles{$$codetitles[0]})) {
995: foreach (@contents) {
996: push @contents_titles, $$cat_titles{$$codetitles[0]}{$_};
997: }
998: }
999: $$idlist{$$codetitles[0]} = join('","',@contents);
1000: $$idnums{$$codetitles[0]} = scalar(@contents);
1001: if (defined($$cat_titles{$$codetitles[0]})) {
1002: $$idlist_titles{$$codetitles[0]} = join('","',@contents_titles);
1003: }
1004: } elsif ($num == 1) {
1005: %{$$idlist{$$codetitles[1]}} = ();
1006: %{$$idlist_titles{$$codetitles[1]}} = ();
1007: foreach my $key_a (keys %{$idarrays{$$codetitles[1]}}) {
1008: my @sorted_a = ();
1009: my @sorted_a_titles = ();
1010: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[1]}{$key_a}},\@sorted_a);
1011: if (defined($$cat_titles{$$codetitles[1]})) {
1012: foreach (@sorted_a) {
1013: push @sorted_a_titles, $$cat_titles{$$codetitles[1]}{$_};
1014: }
1015: }
1016: $$idlist{$$codetitles[1]}{$key_a} = join('","',@sorted_a);
1017: $$idnums{$$codetitles[1]}{$key_a} = scalar(@sorted_a);
1018: if (defined($$cat_titles{$$codetitles[1]})) {
1019: $$idlist_titles{$$codetitles[1]}{$key_a} = join('","',@sorted_a_titles);
1020: }
1021: }
1022: } elsif ($num == 2) {
1023: %{$$idlist{$$codetitles[2]}} = ();
1024: %{$$idlist_titles{$$codetitles[2]}} = ();
1025: foreach my $key_a (keys %{$idarrays{$$codetitles[2]}}) {
1026: %{$$idlist{$$codetitles[2]}{$key_a}} = ();
1027: %{$$idlist_titles{$$codetitles[2]}{$key_a}} = ();
1028: foreach my $key_b (keys %{$idarrays{$$codetitles[2]}{$key_a}}) {
1029: my @sorted_b = ();
1030: my @sorted_b_titles = ();
1031: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[2]}{$key_a}{$key_b}},\@sorted_b);
1032: if (defined($$cat_titles{$$codetitles[2]})) {
1033: foreach (@sorted_b) {
1034: push @sorted_b_titles, $$cat_titles{$$codetitles[2]}{$_};
1035: }
1036: }
1037: $$idlist{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_b);
1038: $$idnums{$$codetitles[2]}{$key_a}{$key_b} = scalar(@sorted_b);
1039: if (defined($$cat_titles{$$codetitles[2]})) {
1040: $$idlist_titles{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_b_titles);
1041: }
1042: }
1043: }
1044: } elsif ($num == 3) {
1045: %{$$idlist{$$codetitles[3]}} = ();
1046: foreach my $key_a (keys %{$idarrays{$$codetitles[3]}}) {
1047: %{$$idlist{$$codetitles[3]}{$key_a}} = ();
1048: foreach my $key_b (keys %{$idarrays{$$codetitles[3]}{$key_a}}) {
1049: %{$$idlist{$$codetitles[3]}{$key_a}{$key_b}} = ();
1050: foreach my $key_c (keys %{$idarrays{$$codetitles[3]}{$key_a}{$key_b}}) {
1051: my @sorted_c = ();
1052: my @sorted_c_titles = ();
1053: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[3]}{$key_a}{$key_b}{$key_c}},\@sorted_c);
1054: if (defined($$cat_titles{$$codetitles[3]})) {
1055: foreach (@sorted_c) {
1056: push @sorted_c_titles, $$cat_titles{$$codetitles[3]}{$_};
1057: }
1058: }
1059: $$idlist{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = join('","',@sorted_c);
1060: $$idnums{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = scalar(@sorted_c);
1061: if (defined($$cat_titles{$$codetitles[3]})) {
1062: $$idlist_titles{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_c_titles);
1063: }
1064: }
1065: }
1066: }
1067: } elsif ($num == 4) {
1068: %{$$idlist{$$codetitles[4]}} = ();
1069: foreach my $key_a (keys %{$idarrays{$$codetitles[4]}}) {
1070: %{$$idlist{$$codetitles[4]}{$key_a}} = ();
1071: foreach my $key_b (keys %{$idarrays{$$codetitles[4]}{$key_a}}) {
1072: %{$$idlist{$$codetitles[4]}{$key_a}{$key_b}} = ();
1073: foreach my $key_c (keys %{$idarrays{$$codetitles[4]}{$key_a}{$key_b}}) {
1074: %{$$idlist{$$codetitles[4]}{$key_a}{$key_b}{$key_c}} = ();
1075: foreach my $key_d (keys %{$idarrays{$$codetitles[4]}{$key_a}{$key_b}{$key_c}}) {
1076: my @sorted_d = ();
1077: my @sorted_d_titles = ();
1078: &sort_cats($num,$cat_order,$codetitles,$idarrays{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d},\@sorted_d);
1079: if (defined($$cat_titles{$$codetitles[4]})) {
1080: foreach (@sorted_d) {
1081: push @sorted_d_titles, $$cat_titles{$$codetitles[4]}{$_};
1082: }
1083: }
1084: $$idlist{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d} = join('","',@sorted_d);
1085: $$idnums{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d} = scalar(@sorted_d);
1086: }
1087: }
1088: }
1089: }
1090: }
1091: }
1092: }
1093:
1094: sub sort_cats {
1095: my ($num,$cat_order,$codetitles,$idsarrayref,$sorted) = @_;
1096: my @unsorted = @{$idsarrayref};
1097: if (defined($$cat_order{$$codetitles[$num]})) {
1098: foreach (@{$$cat_order{$$codetitles[$num]}}) {
1099: if (grep/^$_$/,@unsorted) {
1100: push @{$sorted}, $_;
1101: }
1102: }
1103: } else {
1104: @{$sorted} = sort (@unsorted);
1105: }
1106: }
1107:
1108:
1109: sub recurse_list {
1110: my ($cid,$codetitles,$codes,$num,$idarrays) = @_;
1111: if ($num == 0) {
1112: if (!grep/^$$codes{$cid}{$$codetitles[0]}$/,@{$$idarrays{$$codetitles[0]}}) {
1113: push @{$$idarrays{$$codetitles[0]}}, $$codes{$cid}{$$codetitles[0]};
1114: }
1115: } elsif ($num == 1) {
1116: if (defined($$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}})) {
1117: if (!grep/^$$codes{$cid}{$$codetitles[1]}$/,@{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}}) {
1118: push @{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}}, $$codes{$cid}{$$codetitles[1]};
1119: }
1120: } else {
1121: @{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}} = ("$$codes{$cid}{$$codetitles[1]}");
1122: }
1123: } elsif ($num == 2) {
1124: if (defined($$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}})) {
1125: if (defined($$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
1126: if (!grep/^$$codes{$cid}{$$codetitles[2]}$/,@{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}}) {
1127: push @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}}, $$codes{$cid}{$$codetitles[2]};
1128: }
1129: } else {
1130: @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ("$$codes{$cid}{$$codetitles[2]}");
1131: }
1132: } else {
1133: %{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}} = ();
1134: @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ("$$codes{$cid}{$$codetitles[2]}");
1135: }
1136: } elsif ($num == 3) {
1137: if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}})) {
1138: if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
1139: if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}})) {
1140: if (!grep/^$$codes{$cid}{$$codetitles[3]}$/,@{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}}) {
1141: push @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}}, $$codes{$cid}{$$codetitles[3]};
1142: }
1143: } else {
1144: @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
1145: }
1146: } else {
1147: %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
1148: @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
1149: }
1150: } else {
1151: %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}} = ();
1152: %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
1153: @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
1154: }
1155: } elsif ($num == 4) {
1156: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}})) {
1157: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
1158: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}})) {
1159: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}})) {
1160: 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]}}}) {
1161: push @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}}, $$codes{$cid}{$$codetitles[4]};
1162: }
1163: } else {
1164: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
1165: }
1166: } else {
1167: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
1168: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
1169: }
1170: } else {
1171: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
1172: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
1173: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
1174: }
1175: } else {
1176: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}} = ();
1177: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
1178: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
1179: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[3]}");
1180: }
1181: }
1182: $num ++;
1183: if ($num <@{$codetitles}) {
1184: &recurse_list($cid,$codetitles,$codes,$num,$idarrays);
1185: }
1186: }
1187:
1188: sub javascript_code_selections {
1189: my ($numcats,$cat_titles,$script_tag,$idlist,$idnums,$idlist_titles,$codetitles) = @_;
1190: my $numtitles = @{$codetitles};
1191: my @seltitles = ();
1192: for (my $j=0; $j<$numtitles; $j++) {
1193: $seltitles[$j] = 'id'.$$codetitles[$j];
1194: }
1195: my $seltitle_str = join('","',@seltitles);
1196: my @longtitles = ();
1197: for (my $i=0; $i<$numtitles; $i++) {
1198: if (defined($$cat_titles{$$codetitles[$i]})) {
1199: $longtitles[$i] = 1;
1200: } else {
1201: $longtitles[$i] = 0;
1202: }
1203: }
1204: my $longtitles_str = join('","',@longtitles);
1205: $$script_tag .= <<END;
1206: function courseSet(caller) {
1207: var ids = new Array ("$seltitle_str");
1208: var formitems = new Array ($numtitles);
1209: var longtitles = new Array ("$longtitles_str");
1210: var idyr = document.logproblem.Year.selectedIndex
1211: var idsem = document.logproblem.Semester.selectedIndex
1212: var iddept = document.logproblem.Department.selectedIndex
1213: var idclass = document.logproblem.Number.selectedIndex
1214: var idyears = new Array("$$idlist{$$codetitles[0]}");
1215: END
1216: if ($longtitles[0]) {
1217: $$script_tag .=
1218: qq| var idyearslongs = new Array("$$idlist_titles{$$codetitles[0]}")\n|;
1219: }
1220: $$script_tag .=
1221: " var idsems = new Array ($$idnums{$$codetitles[0]})\n";
1222: if ($longtitles[1]) {
1223: $$script_tag .=
1224: " var idsemslongs = new Array ($$idnums{$$codetitles[0]})\n";
1225: }
1226: $$script_tag .=
1227: " var idcodes = new Array ($$idnums{$$codetitles[0]})\n";
1228: if ($longtitles[2]) {
1229: $$script_tag .=
1230: " var idcodeslongs = new Array ($$idnums{$$codetitles[0]})\n";
1231: }
1232: $$script_tag .=
1233: " var idcourses = new Array ($$idnums{$$codetitles[0]})\n";
1234: if ($longtitles[3]) {
1235: $$script_tag .=
1236: " var idcourseslongs = new Array ($$idnums{$$codetitles[0]})\n";
1237: }
1238: my @sort_a = split/","/,$$idlist{$$codetitles[0]};
1239: for (my $j=0; $j<@sort_a; $j++) {
1240: $$script_tag .= qq| idsems[$j] = new Array("$$idlist{$$codetitles[1]}{$sort_a[$j]}")\n|;
1241: if ($longtitles[1]) {
1242: $$script_tag .= qq| idsemslongs[$j] = new Array("$$idlist_titles{$$codetitles[1]}{$sort_a[$j]}")\n|;
1243: }
1244: $$script_tag .= qq| idcodes[$j] = new Array($$idnums{$$codetitles[1]}{$sort_a[$j]})\n|;
1245: if ($longtitles[2]) {
1246: $$script_tag .= qq| idcodeslongs[$j] = new Array($$idnums{$$codetitles[1]}{$sort_a[$j]})\n|;
1247: }
1248: $$script_tag .= qq| idcourses[$j] = new Array($$idnums{$$codetitles[1]}{$sort_a[$j]})\n|;
1249: if ($longtitles[3]) {
1250: $$script_tag .= qq| idcourseslongs[$j] = new Array($$idnums{$$codetitles[1]}{$sort_a[$j]})\n|;
1251: }
1252: my @sort_b = split/","/,$$idlist{$$codetitles[1]}{$sort_a[$j]};
1253: for (my $k=0; $k<@sort_b; $k++) {
1254: my $idcode_entry = $$idlist{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]};
1255: $$script_tag .= qq| idcodes[$j][$k] = new Array("$idcode_entry")\n|;
1256: if ($longtitles[2]) {
1257: my $idcodelong_entry = $$idlist_titles{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]};
1258: $$script_tag .= qq| idcodeslongs[$j][$k] = new Array("$idcodelong_entry")\n|;
1259: }
1260: $$script_tag .= qq| idcourses[$j][$k] = new Array($$idnums{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]})\n|;
1261: if ($longtitles[3]) {
1262: $$script_tag .= qq| idcourseslongs[$j][$k] = new Array($$idnums{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]})\n|;
1263: }
1264: my @sort_c = split/","/,$$idlist{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]};
1265: for (my $l=0; $l<@sort_c; $l++) {
1266: my $idcourse_entry = $$idlist{$$codetitles[3]}{$sort_a[$j]}{$sort_b[$k]}{$sort_c[$l]};
1267: $$script_tag .= qq| idcourses[$j][$k][$l] = new Array("$idcourse_entry")\n|;
1268: if ($longtitles[3]) {
1269: my $idcourselong_entry = $$idlist_titles{$$codetitles[3]}{$sort_a[$j]}{$sort_b[$k]}{$sort_c[$l]};
1270: $$script_tag .= qq| idcourseslongs[$j][$k][$l] = new Array("$idcourselong_entry")\n|;
1271: }
1272: }
1273: }
1274: }
1275: $$script_tag .= (<<END_OF_BLOCK);
1276: var display = new Array($numtitles)
1277: if (caller == "") {
1278: document.logproblem.Year.length = 0
1279: document.logproblem.Year.options[0] = new Option("Select","-1",true,true)
1280: display[0] = new Array(idyears.length)
1281: for (var i=0; i<idyears.length; i++) {
1282: display[0][i] = idyears[i]
1283: if (longtitles[0] == 1) {
1284: if (idyearslongs[i] != "") {
1285: display[0][i] = idyearslongs[i]
1286: }
1287: }
1288: document.logproblem.Year.options[i+1] = new Option(display[0][i],idyears[i],false,false)
1289: }
1290: document.logproblem.Year.selectedIndex = 0;
1291: }
1292: if (caller == "$$codetitles[0]") {
1293: document.logproblem.Department.length = 0
1294: document.logproblem.Number.length = 0
1295: document.logproblem.Department.options[0] = new Option("<-Pick $$codetitles[1]","-1",true,true)
1296: document.logproblem.Number.options[0] = new Option("<-Pick $$codetitles[2]","-1",true,true)
1297: if (idyr == 0) {
1298: document.logproblem.Semester.length = 0
1299: document.logproblem.Semester.options[0] = new Option("<-Pick $$codetitles[0]","-1",true,true)
1300: }
1301: else {
1302: document.logproblem.Semester.length = 0
1303: document.logproblem.Semester.options[0] = new Option("Select","-1",true,true)
1304: display[1] = new Array(idsems[idyr-1].length)
1305: for (var i=0; i<idsems[idyr-1].length; i++) {
1306: display[1][i] = idsems[idyr-1][i]
1307: if (longtitles[1] == 1) {
1308: if (idsemslongs[idyr-1][i] != "") {
1309: display[1][i] = idsemslongs[idyr-1][i]
1310: }
1311: }
1312: document.logproblem.Semester.options[i+1] = new Option(display[1][i],idsems[idyr-1][i],false,false)
1313: }
1314: }
1315: document.logproblem.Semester.selectedIndex = 0;
1316: }
1317: if (caller == "$$codetitles[1]") {
1318: document.logproblem.Department.length = 0
1319: document.logproblem.Number.length = 0
1320: document.logproblem.Number.options[0] = new Option("<-Pick $$codetitles[2]","-1",true,true)
1321: if (idsem == 0) {
1322: document.logproblem.Department.options[0] = new Option("<-Pick $$codetitles[1]","-1",true,true)
1323: }
1324: else {
1325: document.logproblem.Department.options[0] = new Option("Select","-1",true,true)
1326: display[2] = new Array(idcodes[idyr-1][idsem-1].length)
1327: for (var i=0; i<idcodes[idyr-1][idsem-1].length; i++) {
1328: display[2][i] = idcodes[idyr-1][idsem-1][i]
1329: if (longtitles[2] == 1) {
1330: if (idcodeslongs[idyr-1][idsem-1][i] != "") {
1331: display[2][i] = idcodeslongs[idyr-1][idsem-1][i]
1332: }
1333: }
1334: document.logproblem.Department.options[i+1] = new Option(display[2][i],idcodes[idyr-1][idsem-1][i],false,false)
1335: }
1336: }
1337: document.logproblem.Department.selectedIndex = 0
1338: }
1339: if (caller == "$$codetitles[2]") {
1340: document.logproblem.Number.length = 0
1341: if (iddept == 0) {
1342: document.logproblem.Number.options[0] = new Option("<-Pick $$codetitles[2]","-1",true,true)
1343: }
1344: else {
1345: document.logproblem.Number.options[0] = new Option("Select","-1",true,true)
1346: display[3] = new Array (idcourses[idyr-1][idsem-1][iddept-1].length)
1347: for (var i=0; i<idcourses[idyr-1][idsem-1][iddept-1].length; i++) {
1348: display[3][i] = idcourses[idyr-1][idsem-1][iddept-1][i]
1349: if (longtitles[3] == 1) {
1350: if (idcourseslongs[idyr-1][idsem-1][iddept-1][i] != "") {
1351: display[3][i] = idcourseslongs[idyr-1][idsem-1][iddept-1][i]
1352: }
1353: }
1354: document.logproblem.Number.options[i+1] = new Option(display[3][i],idcourses[idyr-1][idsem-1][iddept-1][i],false,false)
1355: }
1356: }
1357: document.logproblem.Number.selectedIndex = 0
1358: }
1359: }
1360:
1361: function initialize_codes() {
1362: courseSet();
1363: return;
1364: }
1365: END_OF_BLOCK
1366: }
1367:
1368: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>