Annotation of loncom/interface/courseclassifier.pm, revision 1.30
1.5 raeburn 1: # The LearningOnline Network with CAPA
2: # Utilities for classifying courses based on institutional code
3: #
1.30 ! raeburn 4: # $Id: courseclassifier.pm,v 1.29 2023/03/15 14:37:12 raeburn Exp $
1.1 raeburn 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27:
28: package Apache::courseclassifier;
29:
30: use strict;
31: use lib '/home/httpd/lib/perl/';
32: use Apache::lonnet;
1.10 raeburn 33: use Apache::loncommon;
1.6 raeburn 34: use Apache::lonlocal;
1.1 raeburn 35: use LONCAPA;
36:
37: sub sort_cats {
38: my ($num,$cat_order,$codetitles,$idsarrayref,$sorted) = @_;
39: my @unsorted = @{$idsarrayref};
40: if (defined($$cat_order{$$codetitles[$num]})) {
41: foreach my $item (@{$$cat_order{$$codetitles[$num]}}) {
42: if (grep/^\Q$item\E$/,@unsorted) {
1.12 raeburn 43: push(@{$sorted},$item);
1.1 raeburn 44: }
45: }
46: } else {
47: @{$sorted} = sort (@unsorted);
48: }
49: }
50:
51: sub recurse_list {
52: my ($cid,$codetitles,$codes,$num,$idarrays) = @_;
53: if ($num == 0) {
54: if (!grep/^$$codes{$cid}{$$codetitles[0]}$/,@{$$idarrays{$$codetitles[0]}}) {
55: push @{$$idarrays{$$codetitles[0]}}, $$codes{$cid}{$$codetitles[0]};
56: }
57: } elsif ($num == 1) {
58: if (defined($$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}})) {
59: if (!grep/^$$codes{$cid}{$$codetitles[1]}$/,@{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}}) {
60: push @{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}}, $$codes{$cid}{$$codetitles[1]};
61: }
62: } else {
63: @{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}} = ("$$codes{$cid}{$$codetitles[1]}");
64: }
65: } elsif ($num == 2) {
66: if (defined($$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}})) {
67: if (defined($$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
68: if (!grep/^$$codes{$cid}{$$codetitles[2]}$/,@{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}}) {
69: push @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}}, $$codes{$cid}{$$codetitles[2]};
70: }
71: } else {
1.29 raeburn 72: @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ("$$codes{$cid}{$$codetitles[2]}");
73: }
1.1 raeburn 74: } else {
75: %{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}} = ();
76: @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ("$$codes{$cid}{$$codetitles[2]}");
77: }
78: } elsif ($num == 3) {
79: if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}})) {
80: if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
81: if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}})) {
82: if (!grep/^$$codes{$cid}{$$codetitles[3]}$/,@{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}}) {
83: push @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}}, $$codes{$cid}{$$codetitles[3]};
84: }
85: } else {
86: @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
87: }
88: } else {
89: %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
90: @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
91: }
92: } else {
93: %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}} = ();
94: %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
95: @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
96: }
97: } elsif ($num == 4) {
98: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}})) {
99: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
100: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}})) {
101: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}})) {
102: 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]}}}) {
103: push @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}}, $$codes{$cid}{$$codetitles[4]};
104: }
105: } else {
106: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
107: }
108: } else {
109: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
110: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
111: }
112: } else {
113: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
1.4 raeburn 114: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
115: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
1.1 raeburn 116: }
117: } else {
118: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}} = ();
119: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
120: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
121: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[3]}");
122: }
123: }
124: $num ++;
125: if ($num <@{$codetitles}) {
126: &recurse_list($cid,$codetitles,$codes,$num,$idarrays);
127: }
128: }
129:
130: sub build_code_selections {
131: my ($codes,$codetitles,$cat_titles,$cat_order,$idlist,$idnums,$idlist_titles) = @_;
132: my %idarrays = ();
133: for (my $i=1; $i<@{$codetitles}; $i++) {
134: %{$idarrays{$$codetitles[$i]}} = ();
135: }
1.20 raeburn 136: foreach my $cid (sort(keys(%{$codes}))) {
1.1 raeburn 137: &recurse_list($cid,$codetitles,$codes,0,\%idarrays);
138: }
139: for (my $num=0; $num<@{$codetitles}; $num++) {
140: if ($num == 0) {
141: my @contents = ();
142: my @contents_titles = ();
143: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[0]}},\@contents);
144: if (defined($$cat_titles{$$codetitles[0]})) {
145: foreach (@contents) {
146: push @contents_titles, $$cat_titles{$$codetitles[0]}{$_};
147: }
148: }
149: $$idlist{$$codetitles[0]} = join('","',@contents);
150: $$idnums{$$codetitles[0]} = scalar(@contents);
151: if (defined($$cat_titles{$$codetitles[0]})) {
152: $$idlist_titles{$$codetitles[0]} = join('","',@contents_titles);
153: }
154: } elsif ($num == 1) {
155: %{$$idlist{$$codetitles[1]}} = ();
156: %{$$idlist_titles{$$codetitles[1]}} = ();
1.20 raeburn 157: foreach my $key_a (keys(%{$idarrays{$$codetitles[1]}})) {
1.1 raeburn 158: my @sorted_a = ();
159: my @sorted_a_titles = ();
160: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[1]}{$key_a}},\@sorted_a);
161: if (defined($$cat_titles{$$codetitles[1]})) {
162: foreach (@sorted_a) {
163: push @sorted_a_titles, $$cat_titles{$$codetitles[1]}{$_};
164: }
165: }
166: $$idlist{$$codetitles[1]}{$key_a} = join('","',@sorted_a);
167: $$idnums{$$codetitles[1]}{$key_a} = scalar(@sorted_a);
168: if (defined($$cat_titles{$$codetitles[1]})) {
169: $$idlist_titles{$$codetitles[1]}{$key_a} = join('","',@sorted_a_titles);
170: }
171: }
172: } elsif ($num == 2) {
173: %{$$idlist{$$codetitles[2]}} = ();
174: %{$$idlist_titles{$$codetitles[2]}} = ();
1.20 raeburn 175: foreach my $key_a (keys(%{$idarrays{$$codetitles[2]}})) {
1.1 raeburn 176: %{$$idlist{$$codetitles[2]}{$key_a}} = ();
177: %{$$idlist_titles{$$codetitles[2]}{$key_a}} = ();
1.20 raeburn 178: foreach my $key_b (keys(%{$idarrays{$$codetitles[2]}{$key_a}})) {
1.1 raeburn 179: my @sorted_b = ();
180: my @sorted_b_titles = ();
181: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[2]}{$key_a}{$key_b}},\@sorted_b);
182: if (defined($$cat_titles{$$codetitles[2]})) {
183: foreach (@sorted_b) {
184: push @sorted_b_titles, $$cat_titles{$$codetitles[2]}{$_};
185: }
186: }
187: $$idlist{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_b);
188: $$idnums{$$codetitles[2]}{$key_a}{$key_b} = scalar(@sorted_b);
189: if (defined($$cat_titles{$$codetitles[2]})) {
190: $$idlist_titles{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_b_titles);
191: }
192: }
193: }
194: } elsif ($num == 3) {
195: %{$$idlist{$$codetitles[3]}} = ();
1.20 raeburn 196: foreach my $key_a (keys(%{$idarrays{$$codetitles[3]}})) {
1.1 raeburn 197: %{$$idlist{$$codetitles[3]}{$key_a}} = ();
1.20 raeburn 198: foreach my $key_b (keys(%{$idarrays{$$codetitles[3]}{$key_a}})) {
1.1 raeburn 199: %{$$idlist{$$codetitles[3]}{$key_a}{$key_b}} = ();
1.20 raeburn 200: foreach my $key_c (keys(%{$idarrays{$$codetitles[3]}{$key_a}{$key_b}})) {
1.1 raeburn 201: my @sorted_c = ();
202: my @sorted_c_titles = ();
203: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[3]}{$key_a}{$key_b}{$key_c}},\@sorted_c);
204: if (defined($$cat_titles{$$codetitles[3]})) {
205: foreach (@sorted_c) {
206: push @sorted_c_titles, $$cat_titles{$$codetitles[3]}{$_};
207: }
208: }
209: $$idlist{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = join('","',@sorted_c);
210: $$idnums{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = scalar(@sorted_c);
211: if (defined($$cat_titles{$$codetitles[3]})) {
1.4 raeburn 212: $$idlist_titles{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = join('","',@sorted_c_titles);
1.1 raeburn 213: }
214: }
215: }
216: }
217: } elsif ($num == 4) {
218: %{$$idlist{$$codetitles[4]}} = ();
1.20 raeburn 219: foreach my $key_a (keys(%{$idarrays{$$codetitles[4]}})) {
1.1 raeburn 220: %{$$idlist{$$codetitles[4]}{$key_a}} = ();
1.20 raeburn 221: foreach my $key_b (keys(%{$idarrays{$$codetitles[4]}{$key_a}})) {
1.1 raeburn 222: %{$$idlist{$$codetitles[4]}{$key_a}{$key_b}} = ();
1.20 raeburn 223: foreach my $key_c (keys(%{$idarrays{$$codetitles[4]}{$key_a}{$key_b}})) {
1.1 raeburn 224: %{$$idlist{$$codetitles[4]}{$key_a}{$key_b}{$key_c}} = ();
1.20 raeburn 225: foreach my $key_d (keys(%{$idarrays{$$codetitles[4]}{$key_a}{$key_b}{$key_c}})) {
1.1 raeburn 226: my @sorted_d = ();
227: my @sorted_d_titles = ();
228: &sort_cats($num,$cat_order,$codetitles,$idarrays{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d},\@sorted_d);
229: if (defined($$cat_titles{$$codetitles[4]})) {
230: foreach (@sorted_d) {
231: push @sorted_d_titles, $$cat_titles{$$codetitles[4]}{$_};
232: }
233: }
234: $$idlist{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d} = join('","',@sorted_d);
235: $$idnums{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d} = scalar(@sorted_d);
1.4 raeburn 236: if (defined($$cat_titles{$$codetitles[4]})) {
237: $$idlist_titles{$$codetitles[3]}{$key_a}{$key_b}{$key_c}{$key_d} = join('","',@sorted_d_titles);
238: }
1.1 raeburn 239: }
240: }
241: }
242: }
243: }
244: }
245: }
246:
247: sub javascript_code_selections {
1.26 raeburn 248: my ($formname,$codetitlesref,$knowncodes,$sectionlist) = @_;
1.25 raeburn 249: return unless (ref($codetitlesref) eq 'ARRAY');
250: my @codetitles = @{$codetitlesref};
1.1 raeburn 251: my $numtitles = @codetitles;
1.10 raeburn 252: my %lt = &Apache::lonlocal::texthash(
253: Select => 'Select',
254: Pick => 'Pick',
255: );
1.1 raeburn 256: my $output = (<<END_OF_BLOCK);
257: var display = new Array($numtitles)
258: if (caller == "" || caller == "$codetitles[0]") {
259: if (caller == "") {
260: document.$formname.Year.length = 0
1.10 raeburn 261: document.$formname.Year.options[0] = new Option("$lt{'Select'}","-1",true,true)
1.1 raeburn 262: display[0] = new Array(idyears.length)
263: for (var i=0; i<idyears.length; i++) {
264: display[0][i] = idyears[i]
265: if (longtitles[0] == 1) {
266: if (idyearslongs[i] != "") {
267: display[0][i] = idyearslongs[i]
268: }
269: }
270: else {
271: if (idyearslongs[i] != "") {
272: display[0][i] = idyears[i]
273: }
274: }
275: document.$formname.Year.options[i+1] = new Option(display[0][i],idyears[i],false,false)
276: }
277: document.$formname.Year.selectedIndex = 0;
278: }
279: document.$formname.Semester.length = 0
280: document.$formname.Department.length = 0;
281: document.$formname.Number.length = 0
1.10 raeburn 282: document.$formname.Department.options[0] = new Option("<-$lt{'Pick'} $codetitles[1]","-1",true,true)
283: document.$formname.Number.options[0] = new Option("<-$lt{'Pick'} $codetitles[2]","-1",true,true)
1.1 raeburn 284: if (idyr == 0 || caller == "") {
1.10 raeburn 285: document.$formname.Semester.options[0] = new Option("<-$lt{'Pick'} $codetitles[0]","-1",true,true)
1.1 raeburn 286: }
287: else {
1.10 raeburn 288: document.$formname.Semester.options[0] = new Option("$lt{'Select'}","-1",true,true)
1.1 raeburn 289: display[1] = new Array(idsems[idyr-1].length)
290: for (var i=0; i<idsems[idyr-1].length; i++) {
291: display[1][i] = idsems[idyr-1][i]
292: if (longtitles[1] == 1) {
293: if (idsemslongs[idyr-1][i] != "") {
294: display[1][i] = idsemslongs[idyr-1][i]
295: }
296: }
297: document.$formname.Semester.options[i+1] = new Option(display[1][i],idsems[idyr-1][i],false,false)
298: }
299: }
300: document.$formname.Semester.selectedIndex = 0;
301: }
302: if (caller == "$codetitles[1]") {
303: document.$formname.Department.length = 0
304: document.$formname.Number.length = 0
305: document.$formname.Number.options[0] = new Option("<-Pick $codetitles[2]","-1",true,true)
306: if (idsem == 0) {
1.10 raeburn 307: document.$formname.Department.options[0] = new Option("<-$lt{'Pick'} $codetitles[1]","-1",true,true)
1.1 raeburn 308: }
309: else {
1.10 raeburn 310: document.$formname.Department.options[0] = new Option("$lt{'Select'}","-1",true,true)
1.1 raeburn 311: display[2] = new Array(idcodes[idyr-1][idsem-1].length)
312: for (var i=0; i<idcodes[idyr-1][idsem-1].length; i++) {
313: display[2][i] = idcodes[idyr-1][idsem-1][i]
314: if (longtitles[2] == 1) {
315: if (idcodeslongs[idyr-1][idsem-1][i] != "") {
316: display[2][i] = idcodeslongs[idyr-1][idsem-1][i]
317: }
318: }
319: document.$formname.Department.options[i+1] = new Option(display[2][i],idcodes[idyr-1][idsem-1][i],false,false)
320: }
321: }
322: document.$formname.Department.selectedIndex = 0
323: }
324: if (caller == "$codetitles[2]") {
325: document.$formname.Number.length = 0
326: if (iddept == 0) {
1.10 raeburn 327: document.$formname.Number.options[0] = new Option("<-$lt{'Pick'} $codetitles[2]","-1",true,true)
1.1 raeburn 328: }
329: else {
330: document.$formname.Number.options[0] = new Option("Select","-1",true,true)
331: display[3] = new Array (idcourses[idyr-1][idsem-1][iddept-1].length)
332: for (var i=0; i<idcourses[idyr-1][idsem-1][iddept-1].length; i++) {
333: display[3][i] = idcourses[idyr-1][idsem-1][iddept-1][i]
334: if (longtitles[3] == 1) {
335: if (idcourseslongs[idyr-1][idsem-1][iddept-1][i] != "") {
336: display[3][i] = idcourseslongs[idyr-1][idsem-1][iddept-1][i]
337: }
338: }
339: document.$formname.Number.options[i+1] = new Option(display[3][i],idcourses[idyr-1][idsem-1][iddept-1][i],false,false)
340: }
341: }
342: document.$formname.Number.selectedIndex = 0
343: }
344: }
1.26 raeburn 345: END_OF_BLOCK
346:
347: if ((ref($knowncodes) eq 'HASH') && (keys(%{$knowncodes}) > 0)) {
348: my @standardnames = &Apache::loncommon::get_standard_codeitems();
349: my (%local_to_standard,$currstr);
350: for (my $i=0; $i<@codetitles; $i++) {
351: $local_to_standard{$codetitles[$i]} = $standardnames[$i];
352: }
353: $output .= <<"ENDJS";
354:
355: function initialize_codes() {
356: ENDJS
357: for (my $i=0; $i<@codetitles-1; $i++) {
358: my $item = $local_to_standard{$codetitles[$i]};
359: $currstr .= $knowncodes->{$codetitles[$i]};
360: if ($knowncodes->{$codetitles[$i]} != -1) {
361: $output .= '
362: for (var j=0; j<document.'.$formname.'.'.$item.'.length; j++) {
363: if (document.'.$formname.'.'.$item.'[j].value == "'.$knowncodes->{$codetitles[$i]}.'") {
364: document.'.$formname.'.'.$item.'.selectedIndex = j;
365: }
366: }
367: ';
368: }
369: $output .= ' courseSet('."'$codetitles[$i]'".')'."\n";
370: }
371: my $lastcodetitle = $local_to_standard{$codetitles[-1]};
372: $currstr .= $knowncodes->{$codetitles[-1]};
373: if ($knowncodes->{$codetitles[-1]} != -1) {
374: $output .= '
375: for (var j=0; j<document.'.$formname.'.'.$lastcodetitle.'.length; j++) {
376: if (document.'.$formname.'.'.$lastcodetitle.'[j].value == "'.$knowncodes->{$codetitles[-1]}.'") {
377: document.'.$formname.'.'.$lastcodetitle.'.selectedIndex = j;
378: }
379: }
380: ';
381: }
382: $output .= " return;\n}\n";
383: if ($sectionlist) {
384: $output .= '
385: function toggleSecVis() {
386: var currcode = "";
387: var crscode = '."'$currstr'".';
388: ';
389: for (my $i=0; $i<@codetitles-1; $i++) {
390: my $item = $local_to_standard{$codetitles[$i]};
391: $output .= 'currcode += document.'.$formname.'.'.$item.'.options[document.'.$formname.'.'.$item.'.selectedIndex].value;'."\n";
392: }
393: my $lastcodetitle = $local_to_standard{$codetitles[-1]};
394: if ($lastcodetitle ne '') {
395: if ($knowncodes->{$codetitles[-1]} != -1) {
396: $output .= 'currcode += document.'.$formname.'.'.$lastcodetitle.'.options[document.'.$formname.'.'.$lastcodetitle.'.selectedIndex].value;'."\n";
397: }
398: }
399: $output .= <<"ENDSEC";
400: var showlist = 'none';
401: var showbox = 'inline';
402: if ((crscode != '') && (currcode == crscode)) {
403: showlist = 'inline';
404: showbox = 'none';
405: }
406: if (document.getElementById('LC_helpdesk_sectionlist')) {
407: document.getElementById('LC_helpdesk_sectionlist').style.display = showlist;
408: }
409: if (document.getElementById('LC_helpdesk_section')) {
410: document.getElementById('LC_helpdesk_section').style.display = showbox;
411: }
412: return;
413: }
414:
415: ENDSEC
416:
417: }
418: } else {
419: $output .= <<"END_OF_JS";
1.1 raeburn 420:
421: function initialize_codes() {
422: courseSet();
423: return;
424: }
1.26 raeburn 425: END_OF_JS
426: }
427: return $output;
1.1 raeburn 428: }
429:
430: sub javascript_definitions {
431: my ($codetitles,$idlist,$idlist_titles,$idnums,$cat_titles) = @_;
432: my $numtitles = @{$codetitles};
433: my $longtitles = [];
434: for (my $i=0; $i<$numtitles; $i++) {
435: if (defined($cat_titles->{$codetitles->[$i]})) {
436: $longtitles->[$i] = 1;
437: } else {
438: $longtitles->[$i] = 0;
439: }
440: }
441: my $scripttext;
442: if ($longtitles->[0]) {
443: $scripttext =
444: qq| var idyearslongs = new Array("$idlist_titles->{$codetitles->[0]}")\n|;
445: }
446: $scripttext .=
447: " var idsems = new Array ($idnums->{$codetitles->[0]})\n";
448: if ($longtitles->[1]) {
449: $scripttext .=
450: " var idsemslongs = new Array ($idnums->{$codetitles->[0]})\n"; }
451: $scripttext .=
452: " var idcodes = new Array ($idnums->{$codetitles->[0]})\n";
453: if ($longtitles->[2]) {
454: $scripttext .=
455: " var idcodeslongs = new Array ($idnums->{$codetitles->[0]})\n";
456: }
457: $scripttext .=
458: " var idcourses = new Array ($idnums->{$codetitles->[0]})\n";
459: if ($longtitles->[3]) {
460: $scripttext .=
461: " var idcourseslongs = new Array ($idnums->{$codetitles->[0]})\n";
462: }
463: my @sort_a = split/","/,$idlist->{$codetitles->[0]};
464: for (my $j=0; $j<@sort_a; $j++) {
465: $scripttext .= qq| idsems[$j] = new Array("$idlist->{$codetitles->[1]}{$sort_a[$j]}")\n|;
466: if ($longtitles->[1]) {
467: $scripttext .= qq| idsemslongs[$j] = new Array("$idlist_titles->{$codetitles->[1]}{$sort_a[$j]}")\n|;
468: }
469: $scripttext .= qq| idcodes[$j] = new Array($idnums->{$codetitles->[1]}{$sort_a[$j]})\n|;
470: if ($longtitles->[2]) {
471: $scripttext .= qq| idcodeslongs[$j] = new Array($idnums->{$codetitles->[1]}{$sort_a[$j]})\n|;
472: }
473: $scripttext .= qq| idcourses[$j] = new Array($idnums->{$codetitles->[1]}{$sort_a[$j]})\n|;
474: if ($longtitles->[3]) {
475: $scripttext .= qq| idcourseslongs[$j] = new Array($idnums->{$codetitles->[1]}{$sort_a[$j]})\n|;
476: }
477: my @sort_b = split/","/,$idlist->{$codetitles->[1]}{$sort_a[$j]};
478: for (my $k=0; $k<@sort_b; $k++) {
479: my $idcode_entry = $idlist->{$codetitles->[2]}{$sort_a[$j]}{$sort_b[$k]};
480: $scripttext .= qq| idcodes[$j][$k] = new Array("$idcode_entry")\n|;
481: if ($longtitles->[2]) {
482: my $idcodelong_entry = $idlist_titles->{$codetitles->[2]}{$sort_a[$j]}{$sort_b[$k]};
483: $scripttext .= qq| idcodeslongs[$j][$k] = new Array("$idcodelong_entry")\n|;
484: }
485: $scripttext .= qq| idcourses[$j][$k] = new Array($idnums->{$codetitles->[2]}{$sort_a[$j]}{$sort_b[$k]})\n|;
486: if ($longtitles->[3]) {
487: $scripttext .= qq| idcourseslongs[$j][$k] = new Array($idnums->{$codetitles->[2]}{$sort_a[$j]}{$sort_b[$k]})\n|;
488: }
489: my @sort_c = split/","/,$idlist->{$codetitles->[2]}{$sort_a[$j]}{$sort_b[$k]};
490: for (my $l=0; $l<@sort_c; $l++) {
491: my $idcourse_entry = $idlist->{$codetitles->[3]}{$sort_a[$j]}{$sort_b[$k]}{$sort_c[$l]};
492: $scripttext .= qq| idcourses[$j][$k][$l] = new Array("$idcourse_entry")\n|;
493: if ($longtitles->[3]) {
494: my $idcourselong_entry = $idlist_titles->{$codetitles->[3]}{$sort_a[$j]}{$sort_b[$k]}{$sort_c[$l]};
495: $scripttext .= qq| idcourseslongs[$j][$k][$l] = new Array("$idcourselong_entry")\n|;
496: }
497: }
498: }
499: }
500: return ($scripttext,$longtitles);
501: }
502:
503: sub courseset_js_start {
504: my ($formname,$longtitles_str,$allidlist) = @_;
505: my $output = <<END;
1.6 raeburn 506:
1.1 raeburn 507: function courseSet(caller) {
508: var longtitles = new Array ("$longtitles_str");
509: var idyr = document.$formname.Year.selectedIndex
510: var idsem = document.$formname.Semester.selectedIndex
511: var iddept = document.$formname.Department.selectedIndex
512: var idclass = document.$formname.Number.selectedIndex
513: var idyears = new Array("$allidlist");
514: END
515: return $output;
516: }
517:
1.6 raeburn 518: sub instcode_selectors_data {
1.7 raeburn 519: my ($codedom,$formname,$cat_items,$codetitles,$cat_titles,$cat_order,$officialjs) = @_;
1.27 raeburn 520: my ($jscript,$codes,%idlist,%idnums,%idlist_titles,%by_year,%by_sem,%by_dept);
521: my ($numtitles,$lasttitle,$totcodes);
522: my $instcats = &Apache::lonnet::get_dom_instcats($codedom);
523: if (ref($instcats) eq 'HASH') {
524: if ((ref($instcats->{'codetitles'}) eq 'ARRAY') && (ref($instcats->{'codes'}) eq 'HASH') &&
525: (ref($instcats->{'cat_titles'}) eq 'HASH') && (ref($instcats->{'cat_order'}) eq 'HASH')) {
526: %{$codes} = %{$instcats->{'codes'}};
527: @{$codetitles} = @{$instcats->{'codetitles'}};
528: %{$cat_titles} = %{$instcats->{'cat_titles'}};
529: %{$cat_order} = %{$instcats->{'cat_order'}};
530: $totcodes = scalar(keys(%{$codes}));
1.28 raeburn 531: if ((!$totcodes) && (exists($instcats->{'totcodes'}))) {
1.29 raeburn 532: $totcodes = $instcats->{'totcodes'};
1.28 raeburn 533: }
1.27 raeburn 534: &build_code_selections($codes,$codetitles,$cat_titles,$cat_order,
1.6 raeburn 535: \%idlist,\%idnums,\%idlist_titles);
1.29 raeburn 536: my ($scripttext,$longtitles) =
1.6 raeburn 537: &javascript_definitions($codetitles,\%idlist,\%idlist_titles,
538: \%idnums,$cat_titles);
539: my $longtitles_str = join('","',@{$longtitles});
540: my $allidlist = $idlist{$codetitles->[0]};
541: $numtitles = @{$codetitles};
542: $lasttitle = $numtitles;
543: if ($numtitles > 4) {
544: $lasttitle = 4;
545: }
546: if ($numtitles == 0) {
547: if (!defined($env{'form.state'})) {
548: $env{'form.state'} = 'listing';
549: }
550: } else {
551: my @data = ('top');
552: for (my $k=0; $k<$lasttitle; $k++) {
553: my $cat = $codetitles->[$k];
554: my $level = 1;
555: $level = &recurse_options($codetitles->[$k],$idlist{$codetitles->[$k]},$level,$cat,$cat_items,\@data,\%by_year,\%by_sem,\%by_dept);
556: }
557: $scripttext .= &build_javascript(\%by_year,\%by_sem,\%by_dept,$cat_order,$codetitles);
1.7 raeburn 558: if ($officialjs) {
559: $jscript .= '
560:
1.18 raeburn 561: function toggleOfficial() {
562: var choice;
563: for (var i=0; i<document.'.$formname.'.official.length; i++) {
564: if (document.'.$formname.'.official[i].checked) {
565: choice = document.'.$formname.'.official[i].value;
566: }
567: }
568: if (choice == "off") {
569: if (document.getElementById("instcodes")) {
570: document.getElementById("instcodes").style.display = "none";
571: }';
1.7 raeburn 572: for (my $i=0; $i<@{$codetitles}-1; $i++) {
573: $jscript .= '
1.18 raeburn 574: document.'.$formname.'.'.$codetitles->[$i].'.selectedIndex = 0;';
1.7 raeburn 575: }
1.18 raeburn 576: $jscript .= '
577: } else {
578: if (document.getElementById("instcodes")) {
579: document.getElementById("instcodes").style.display = "block";
580: }
581: }
1.7 raeburn 582: }
583:
584: function setOfficial(caller) {
1.8 raeburn 585: if (typeof(caller) != "undefined") {
586: if (caller.options[caller.selectedIndex].value != 0) {
587: if (document.'.$formname.'.official.length > 0) {
588: for (var j=0; j<document.'.$formname.'.official.length; j++) {
589: if (document.'.$formname.'.official[j].value == "on") {
590: document.'.$formname.'.official[j].checked = true;
591: }
592: }
1.7 raeburn 593: }
594: }
595: }
596: return;
597: }
598:
599: ';
600:
601: $officialjs = 'setOfficial(caller);';
602: }
603: $jscript .= &javascript_select_filler($formname,$scripttext,$codetitles,$longtitles_str,$allidlist,$officialjs);
1.6 raeburn 604: if ($env{'form.state'} eq 'listing') {
1.12 raeburn 605: my @standardnames = &Apache::loncommon::get_standard_codeitems();
606: my %local_to_standard;
607: if (ref($codetitles) eq 'ARRAY') {
608: for (my $i=0; $i<@{$codetitles}; $i++) {
609: $local_to_standard{$codetitles->[$i]} = $standardnames[$i];
610: }
611: }
1.6 raeburn 612: $jscript .= '
613: function setElements() {
614: ';
615: for (my $i=0; $i<@{$codetitles}-1; $i++) {
1.12 raeburn 616: my $item = $local_to_standard{$codetitles->[$i]};
617: if ($env{'form.'.$item} != -1) {
1.6 raeburn 618: $jscript .= '
1.12 raeburn 619: for (var j=0; j<document.'.$formname.'.'.$item.'.length; j++) {
620: if (document.'.$formname.'.'.$item.'[j].value == "'.$env{'form.'.$item}.'") {
621: document.'.$formname.'.'.$item.'.selectedIndex = j;
1.6 raeburn 622: }
623: }
624: ';
625: }
626: }
627: $jscript .= ' courseSet()'."\n";
1.12 raeburn 628: my $lastcodetitle = $local_to_standard{$codetitles->[-1]};
629: if ($env{'form.'.$lastcodetitle} != -1) {
1.6 raeburn 630: $jscript .= '
1.12 raeburn 631: for (var j=0; j<document.'.$formname.'.'.$lastcodetitle.'.length; j++) {
632: if (document.'.$formname.'.'.$lastcodetitle.'[j].value == "'.$env{'form.'.$lastcodetitle}.'") {
633: document.'.$formname.'.'.$lastcodetitle.'.selectedIndex = j;
1.6 raeburn 634: }
635: }
636: ';
637: }
638: $jscript .= '}';
639: }
640: }
641: }
642: }
643: return ($jscript,$totcodes,$numtitles,$lasttitle);
644: }
645:
646: sub build_instcode_selectors {
1.24 raeburn 647: my ($numtitles,$lasttitle,$cat_items,$codetitles,$cat_titles,$cat_order,$official,$class,$id,$noedit) = @_;
1.6 raeburn 648: my $output;
1.10 raeburn 649: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1.6 raeburn 650: if ($numtitles > 0) {
1.18 raeburn 651: my $style;
1.22 raeburn 652: if ($official eq 'off') {
1.18 raeburn 653: $style = ' style="display: none"';
654: }
1.22 raeburn 655: if ($id eq '') {
656: $id = 'instcodes';
657: }
1.24 raeburn 658: my $disabled;
659: if ($noedit) {
660: $disabled = ' disabled="disabled"';
661: }
1.22 raeburn 662: $output .= '<div id="'.$id.'"'.$style.'><table><tr>';
1.6 raeburn 663: for (my $k=0; $k<$lasttitle-1; $k++) {
664: my (@items,@unsorted);
665: if (ref($cat_items->{$codetitles->[$k]}) eq 'ARRAY') {
666: @unsorted = @{$cat_items->{$codetitles->[$k]}};
667: }
668: &sort_cats($k,$cat_order,$codetitles,\@unsorted,\@items);
669: my @longitems;
670: if (defined($cat_titles->{$codetitles->[$k]})) {
671: foreach my $item (@items) {
672: push(@longitems,$cat_titles->{$codetitles->[$k]}{$item});
673: }
674: } else {
675: @longitems = @items;
676: }
677: $output .= '<td align="center">'.$codetitles->[$k].'<br />'."\n".
1.22 raeburn 678: '<select name="'.$standardnames[$k].'" onchange="courseSet(this)"';
679: if ($class) {
680: $output .= ' class="'.$class.'"';
681: }
1.24 raeburn 682: $output .= $disabled.'>'."\n".'<option value="0">'.&mt('All').'</option>'."\n";
1.6 raeburn 683: for (my $i=0; $i<@items; $i++) {
684: if ($longitems[$i] eq '') {
685: $longitems[$i] = $items[$i];
686: }
687: $output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>';
688: }
689: $output .= '</select></td>';
690: }
691: $output .= '<td align="center">'.$codetitles->[$lasttitle-1].'<br />'."\n".
1.23 raeburn 692: '<select name="'.$standardnames[$lasttitle-1].'"';
693: if ($class) {
694: $output .= ' class="'.$class.'"';
695: }
1.24 raeburn 696: $output .= $disabled.'>'."\n".
1.6 raeburn 697: '<option value="0">'.&mt('All')."\n".
698: '</option>'."\n".'</select>'."\n".
699: '</td></tr></table>'."\n";
700: if ($numtitles > 4) {
701: $output .= '<br /><br />'.$codetitles->[$numtitles-1].'<br />'."\n".
1.9 raeburn 702: '<input type="text" name="'.$standardnames[$numtitles-1].
1.24 raeburn 703: '"'.$disabled.' /><br />'."\n";
1.6 raeburn 704: }
1.18 raeburn 705: $output .= '</div>';
1.6 raeburn 706: }
707: return $output;
708: }
709:
1.16 raeburn 710: sub instcode_selectors {
711: my ($codedom,$formname,$officialjs,$codetitles) = @_;
712: my ($output,%cat_titles,%cat_order,%cat_items);
713: my ($jscript,$totcodes,$numtitles,$lasttitle) =
714: &instcode_selectors_data($codedom,$formname,\%cat_items,$codetitles,
715: \%cat_titles,\%cat_order,$officialjs);
716: if ($numtitles > 0) {
717: my $official = ' checked="checked" ';
718: my $unofficial = '';
1.18 raeburn 719: if (($formname eq 'filterpicker') && ($env{'form.official'} eq 'off')) {
1.16 raeburn 720: $unofficial = $official;
721: $official = '';
722: }
723: $output .= '<span class="LC_nobreak">'.&mt('Official course:').' <label>'.
1.18 raeburn 724: '<input type="radio" name="official" value="on"'.$official.
725: ' onclick="toggleOfficial();" />'.&mt('Yes').'</label>'.
726: (' 'x3).'<label>'.
1.16 raeburn 727: '<input type="radio" name="official" value="off"'.$unofficial.
728: ' onclick="toggleOfficial();" />'.&mt('No').'</label></span><br />'.
729: &build_instcode_selectors($numtitles,$lasttitle,\%cat_items,$codetitles,
1.22 raeburn 730: \%cat_titles,\%cat_order,$env{'form.official'})."\n".
1.16 raeburn 731: '<input type="hidden" name="numtitles" value="'.$numtitles.'" />'."\n".
732: '<input type="hidden" name="state" value="listing" />'."\n";
733: }
734: return ($output,$jscript,$numtitles);
735: }
736:
1.6 raeburn 737: sub recurse_options {
738: my ($currkey,$currlist,$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept) = @_;
739: if (ref($currlist) eq 'HASH') {
740: $level ++;
741: foreach my $key (sort(keys(%{$currlist}))) {
742: $$data[$level-1]= $key;
743: &recurse_options($key,$currlist->{$key},$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept);
744: }
745: } else {
746: $level --;
747: my @contents = split(/","/,$currlist);
748: foreach my $item (@contents) {
749: if (!grep(/^\Q$item\E$/,@{$cat_options->{$cat}})) {
750: push(@{$cat_options->{$cat}},$item);
751: }
752: if ($level == 3) {
753: if (!grep/^\Q$item\E$/,@{$by_year->{$data->[1]}->{$currkey}}) {
754: push(@{$by_year->{$data->[1]}->{$currkey}},$item);
755: }
756: if (!grep/^\Q$item\E$/,@{$by_sem->{$data->[2]}->{$currkey}}) {
757: push(@{$by_sem->{$data->[2]}->{$currkey}},$item);
758: }
759: if (!grep/^\Q$item\E$/,@{$by_dept->{$currkey}}) {
760: push(@{$by_dept->{$currkey}},$item);
761: }
762:
763: }
764: }
765: }
766: return $level;
767: }
768:
769: sub build_javascript {
770: my ($by_year,$by_sem,$by_dept,$cat_order,$codetitles) = @_;
771: my @unsorted = keys(%{$by_year});
772: my @sorted_yrs;
1.21 raeburn 773: &sort_cats('0',$cat_order,$codetitles,\@unsorted,\@sorted_yrs);
774: my $output = 'var idcse_by_yr_year = new Array("'.join('","',@sorted_yrs).'");'."\n".
1.6 raeburn 775: 'var idcse_by_yr_dept = new Array('.scalar(@sorted_yrs).');'."\n".
776: 'var idcse_by_yr_num = new Array('.scalar(@sorted_yrs).');'."\n";
777: for (my $i=0; $i<@sorted_yrs; $i++) {
778: my $numkeys = keys(%{$by_year->{$sorted_yrs[$i]}});
779: $output .= " idcse_by_yr_num[$i] = new Array($numkeys);\n";
780: if (ref($by_year->{$sorted_yrs[$i]}) eq 'HASH') {
781: @unsorted = keys(%{$by_year->{$sorted_yrs[$i]}});
782: my @sorted_depts;
783: &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts);
784: $output .= qq| idcse_by_yr_dept[$i] = new Array ("|.join('","',@sorted_depts).'");'."\n";
785: for (my $j=0; $j<@sorted_depts; $j++) {
786: $output .= qq| idcse_by_yr_num[$i][$j] = new Array ("|;
787: $output .= join('","',sort(@{$by_year->{$sorted_yrs[$i]}->{$sorted_depts[$j]}})).'");'."\n";
788: }
789: }
790: }
791: @unsorted = keys(%{$by_sem});
792: my @sorted_sems;
793: &sort_cats('1',$cat_order,$codetitles,\@unsorted,\@sorted_sems);
794: $output .= 'idcse_by_sem_sems = new Array("'.join('","',@sorted_sems).'");'."\n".
795: 'idcse_by_sem_dept = new Array('.scalar(@sorted_sems).');'."\n".
796: 'idcse_by_sem_num = new Array('.scalar(@sorted_sems).');'."\n";
797: for (my $i=0; $i<@sorted_sems; $i++) {
798: my $numkeys = keys(%{$by_sem->{$sorted_sems[$i]}});
799: $output .= " idcse_by_sem_num[$i] = new Array($numkeys);\n";
800: if (ref($by_sem->{$sorted_sems[$i]}) eq 'HASH') {
801: @unsorted = keys(%{$by_sem->{$sorted_sems[$i]}});
802: my @sorted_depts;
803: &sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts);
804: $output .= qq| idcse_by_sem_dept[$i] = new Array("|.join('","',@sorted_depts).'");'."\n";
805: for (my $j=0; $j<@sorted_depts; $j++) {
806: $output .= qq| idcse_by_sem_num[$i][$j] = new Array ("|.join('","',sort(@{$by_sem->{$sorted_sems[$i]}->{$sorted_depts[$j]}})).'");'."\n";
807: }
808: }
809: }
810: @unsorted = keys(%{$by_dept});
811: my @sorted_deps;
812: &sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_deps);
813: $output .= 'idcse_by_dep = new Array('.scalar(@sorted_deps).');'."\n";
814: for (my $k=0; $k<@sorted_deps; $k++) {
815: $output .= qq| idcse_by_dep[$k] = new Array ("|.join('","',sort(@{$by_dept->{$sorted_deps[$k]}})).'");'."\n";
816: }
817: return $output;
818: }
819:
820: sub javascript_select_filler {
1.7 raeburn 821: my ($formname,$scripttext,$codetitles,$longtitles_str,$allidlist,$officialjs) = @_;
1.13 raeburn 822: my $all = &mt('All');
823: my $nocrs = &mt('No courses');
1.6 raeburn 824: my $output = <<END;
825:
1.19 musolffc 826: function courseSet(caller, onload) {
1.6 raeburn 827: var longtitles = new Array ("$longtitles_str");
1.19 musolffc 828: var valyr = '';
829: var valsem = '';
830: var valdept = '';
831: var valclass = '';
832: if (onload) {
833: valyr = "$env{'form.Year'}";
834: valsem = "$env{'form.Semester'}";
835: valdept = "$env{'form.Department'}";
836: valclass = "$env{'form.Number'}";
837: } else {
838: valyr = document.$formname.Year.options[document.$formname.Year.selectedIndex].value;
839: valsem = document.$formname.Semester.options[document.$formname.Semester.selectedIndex].value;
840: valdept = document.$formname.Department.options[document.$formname.Department.selectedIndex].value;
841: valclass = document.$formname.Number.options[document.$formname.Number.selectedIndex].value;
842: }
1.6 raeburn 843: var idyears = new Array("$allidlist");
844: var idyr = -1;
845: var idsem = -1;
846: var iddept = -1;
847: document.$formname.Number.length = 0;
848:
849: $scripttext
850:
1.19 musolffc 851: if (onload) {
852: if (document.$formname.Year.options.length > 0) {
853: for (var i = 0; i< document.$formname.Year.options.length; i++) {
854: if (document.$formname.Year.options[i].value == "$env{'form.Year'}") {
855: document.$formname.Year.selectedIndex = i;
856: break;
857: }
858: }
859: }
860: if (document.$formname.Department.options.length > 0) {
861: for (var i = 0; i< document.$formname.Department.options.length; i++) {
862: if (document.$formname.Department.options[i].value == "$env{'form.Department'}") {
863: document.$formname.Department.selectedIndex = i;
864: break;
865: }
866: }
867: }
868: if (document.$formname.Semester.options.length > 0) {
869: for (var i = 0; i< document.$formname.Semester.options.length; i++) {
870: if (document.$formname.Semester.options[i].value == "$env{'form.Semester'}") {
871: document.$formname.Semester.selectedIndex = i;
872: break;
873: }
874: }
875: }
876: }
877:
878: var selYear = document.$formname.Year.selectedIndex-1;
879: var selSemester = document.$formname.Semester.selectedIndex-1;
880: var selDepartment = document.$formname.Department.selectedIndex-1;
1.6 raeburn 881: if (selYear == -1) {
882: if (selSemester == -1) {
883: if (selDepartment > -1) {
1.13 raeburn 884: document.$formname.Number.options[0] = new Option('$all','0',false,false);
1.6 raeburn 885: for (var k=0; k<idcse_by_dep[selDepartment].length; k++) {
886: document.$formname.Number.options[k+1] = new Option(idcse_by_dep[selDepartment][k],idcse_by_dep[selDepartment][k],false,false);
887:
888: }
889: }
890: else {
1.13 raeburn 891: document.$formname.Number.options[0] = new Option('$all','0',true,true);
1.6 raeburn 892: }
893: }
894: else {
895: if (selDepartment > -1) {
896: for (var i=0; i<idcse_by_sem_sems.length; i++) {
897: if (idcse_by_sem_sems[i] == valsem) {
898: idsem = i;
899: }
900: }
901: if (idsem != -1) {
902: for (var i=0; i<idcse_by_sem_dept[idsem].length; i++) {
903: if (idcse_by_sem_dept[idsem][i] == valdept) {
904: iddept = i;
905: }
906: }
907: }
908: if (iddept != -1) {
1.13 raeburn 909: document.$formname.Number.options[0] = new Option('$all','0',false,false);
1.6 raeburn 910: for (var k=0; k<idcse_by_sem_num[idsem][iddept].length; k++) {
911: document.$formname.Number.options[k+1] = new Option(idcse_by_sem_num[idsem][iddept][k],idcse_by_sem_num[idsem][iddept][k],false,false);
912: }
913: }
914: else {
1.13 raeburn 915: document.$formname.Number.options[0] = new Option('$nocrs','0',true,true);
1.6 raeburn 916: }
917: }
918: else {
1.13 raeburn 919: document.$formname.Number.options[0] = new Option('$all','0',true,true);
1.6 raeburn 920: }
921: }
922: }
923: else {
924: if (selSemester == -1) {
925: if (selDepartment > -1) {
926: for (var i=0; i<idcse_by_yr_year.length; i++) {
927: if (idcse_by_yr_year[i] == valyr) {
928: idyr = i;
929: }
930: }
931: if (idyr != -1) {
932: for (var i=0; i<idcse_by_yr_dept[idyr].length; i++) {
933: if (idcse_by_yr_dept[idyr][i] == valdept) {
934: iddept = i;
935: }
936: }
937: }
938: if (iddept != -1) {
1.13 raeburn 939: document.$formname.Number.options[0] = new Option('$all','0',false,false);
1.6 raeburn 940: for (var k=0; k<idcse_by_yr_num[idyr][iddept].length; k++) {
941: document.$formname.Number.options[k+1] = new Option(idcse_by_yr_num[idyr][iddept][k],idcse_by_yr_num[idyr][iddept][k],false,false);
942: }
943: }
944: else {
1.13 raeburn 945: document.$formname.Number.options[0] = new Option('$nocrs','0',true,true);
1.6 raeburn 946: }
947: }
948: else {
1.13 raeburn 949: document.$formname.Number.options[0] = new Option('$all','0',true,true);
1.6 raeburn 950: }
951: }
952: else {
953: if (selDepartment > -1) {
954: for (var k=0; k<idyears.length; k++) {
955: if (idyears[k] == valyr) {
956: idyr = k;
957: }
958: }
959: if (idyr != -1) {
960: for (var k=0; k<idsems[idyr].length; k++) {
961: if (idsems[idyr][k] == valsem) {
962: idsem = k;
963: }
964: }
965: }
966: if (idsem != -1) {
967: for (var k=0; k<idcodes[idyr][idsem].length; k++) {
968: if (idcodes[idyr][idsem][k] == valdept) {
969: iddept = k;
970: }
971: }
972: }
973: if (iddept != -1) {
1.17 raeburn 974: document.$formname.Number.options[0] = new Option('$all','0',false,false);
1.6 raeburn 975: for (var i=0; i<idcourses[idyr][idsem][iddept].length; i++) {
976: var display = idcourses[idyr][idsem][iddept][i];
977: if (longtitles[3] == 1) {
978: if (idcourseslongs[idyr][idsem][iddept][i] != "") {
979: display = idcourseslongs[idyr][idsem][iddept][i]
980: }
981: }
982: document.$formname.Number.options[i+1] = new Option(display,idcourses[idyr][idsem][iddept][i],false,false)
983: }
984: }
985: else {
1.13 raeburn 986: document.$formname.Number.options[0] = new Option('$nocrs','0',true,true);
1.6 raeburn 987: }
988: }
989: else {
1.13 raeburn 990: document.$formname.Number.options[0] = new Option('$all','0',true,true);
1.6 raeburn 991: }
992: }
993: document.$formname.Number.selectedIndex = 0
994: }
1.19 musolffc 995: if (onload) {
996: if (document.$formname.Number.options.length > 0) {
997: for (var i = 0; i< document.$formname.Number.options.length; i++) {
998: if (document.$formname.Number.options[i].value == "$env{'form.Number'}") {
999: document.$formname.Number.selectedIndex = i;
1000: break;
1001: }
1002: }
1003: }
1004: } else {
1005: $officialjs
1006: }
1.6 raeburn 1007: }
1008: END
1009: return $output;
1010: }
1011:
1012: sub instcode_search_str {
1.9 raeburn 1013: my ($domain,$numtitles,$codetitles) = @_;
1.6 raeburn 1014: my $instcode;
1015: if (defined($numtitles) && $numtitles == 0) {
1016: $instcode = '.+';
1017: } else {
1018: my (%codedefaults,@code_order);
1019: my $defaults_result =
1020: &Apache::lonnet::auto_instcode_defaults($domain,\%codedefaults,
1021: \@code_order);
1.10 raeburn 1022: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1.9 raeburn 1023: my %local_to_standard;
1024: if (ref($codetitles) eq 'ARRAY') {
1025: for (my $i=0; $i<@{$codetitles}; $i++) {
1026: $local_to_standard{$codetitles->[$i]} = $standardnames[$i];
1027: }
1028: }
1.6 raeburn 1029: if ($defaults_result eq 'ok') {
1030: $instcode ='^';
1.9 raeburn 1031: foreach my $loctitle (@code_order) {
1032: my $item = $local_to_standard{$loctitle};
1033: if ($item ne '') {
1034: if ($env{'form.'.$item} eq '0' ) {
1.12 raeburn 1035: $instcode .= $codedefaults{$loctitle};
1.9 raeburn 1036: } else {
1037: $instcode .= $env{'form.'.$item};
1038: }
1.6 raeburn 1039: } else {
1.9 raeburn 1040: $instcode .= '.+';
1.6 raeburn 1041: }
1042: }
1043: $instcode .= '$';
1044: } else {
1045: $instcode = '.+';
1046: }
1047: }
1048: return $instcode;
1049: }
1050:
1.10 raeburn 1051: sub instcode_from_selectors {
1.14 raeburn 1052: my ($cdom,$noregexps) = @_;
1.10 raeburn 1053: my $instcode;
1.27 raeburn 1054: my (@codetitles,%codedefaults,@code_order);
1055: my $instcats = &Apache::lonnet::get_dom_instcats($cdom);
1056: if (ref($instcats) eq 'HASH') {
1057: if (ref($instcats->{'codetitles'}) eq 'ARRAY') {
1058: @codetitles = @{$instcats->{'codetitles'}};
1059: }
1060: }
1.10 raeburn 1061: my $defaults_result =
1062: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
1063: \@code_order);
1.27 raeburn 1064: if (($defaults_result eq 'ok') && (@codetitles > 0)) {
1.10 raeburn 1065: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1066: my %local_to_standard;
1067: for (my $i=0; $i<@codetitles; $i++) {
1068: $local_to_standard{$codetitles[$i]} = $standardnames[$i];
1069: }
1070: foreach my $loctitle (@code_order) {
1071: my $category = $local_to_standard{$loctitle};
1072: if ($category ne '') {
1073: if ($env{'form.'.$category} eq '-1' ) {
1.14 raeburn 1074: if ($noregexps) {
1075: $instcode .= ' ';
1076: } else {
1077: $instcode .= $codedefaults{$category};
1078: }
1.10 raeburn 1079: } else {
1080: $instcode .= $env{'form.'.$category};
1081: }
1082: } else {
1083: $instcode .= '.+';
1084: }
1085: }
1086: }
1087: return $instcode;
1.9 raeburn 1088: }
1089:
1.1 raeburn 1090: 1;
1091:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>