Annotation of loncom/interface/courseclassifier.pm, revision 1.29
1.5 raeburn 1: # The LearningOnline Network with CAPA
2: # Utilities for classifying courses based on institutional code
3: #
1.29 ! raeburn 4: # $Id: courseclassifier.pm,v 1.28 2022/11/05 06:00:07 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: alert("crscode is ||"+crscode+"|| and currcode is ||"+currcode+"|| and showlist is ||"+showlist+"|| and showbox is ||"+showbox+"||");
407: if (document.getElementById('LC_helpdesk_sectionlist')) {
408: document.getElementById('LC_helpdesk_sectionlist').style.display = showlist;
409: }
410: if (document.getElementById('LC_helpdesk_section')) {
411: document.getElementById('LC_helpdesk_section').style.display = showbox;
412: }
413: return;
414: }
415:
416: ENDSEC
417:
418: }
419: } else {
420: $output .= <<"END_OF_JS";
1.1 raeburn 421:
422: function initialize_codes() {
423: courseSet();
424: return;
425: }
1.26 raeburn 426: END_OF_JS
427: }
428: return $output;
1.1 raeburn 429: }
430:
431: sub javascript_definitions {
432: my ($codetitles,$idlist,$idlist_titles,$idnums,$cat_titles) = @_;
433: my $numtitles = @{$codetitles};
434: my $longtitles = [];
435: for (my $i=0; $i<$numtitles; $i++) {
436: if (defined($cat_titles->{$codetitles->[$i]})) {
437: $longtitles->[$i] = 1;
438: } else {
439: $longtitles->[$i] = 0;
440: }
441: }
442: my $scripttext;
443: if ($longtitles->[0]) {
444: $scripttext =
445: qq| var idyearslongs = new Array("$idlist_titles->{$codetitles->[0]}")\n|;
446: }
447: $scripttext .=
448: " var idsems = new Array ($idnums->{$codetitles->[0]})\n";
449: if ($longtitles->[1]) {
450: $scripttext .=
451: " var idsemslongs = new Array ($idnums->{$codetitles->[0]})\n"; }
452: $scripttext .=
453: " var idcodes = new Array ($idnums->{$codetitles->[0]})\n";
454: if ($longtitles->[2]) {
455: $scripttext .=
456: " var idcodeslongs = new Array ($idnums->{$codetitles->[0]})\n";
457: }
458: $scripttext .=
459: " var idcourses = new Array ($idnums->{$codetitles->[0]})\n";
460: if ($longtitles->[3]) {
461: $scripttext .=
462: " var idcourseslongs = new Array ($idnums->{$codetitles->[0]})\n";
463: }
464: my @sort_a = split/","/,$idlist->{$codetitles->[0]};
465: for (my $j=0; $j<@sort_a; $j++) {
466: $scripttext .= qq| idsems[$j] = new Array("$idlist->{$codetitles->[1]}{$sort_a[$j]}")\n|;
467: if ($longtitles->[1]) {
468: $scripttext .= qq| idsemslongs[$j] = new Array("$idlist_titles->{$codetitles->[1]}{$sort_a[$j]}")\n|;
469: }
470: $scripttext .= qq| idcodes[$j] = new Array($idnums->{$codetitles->[1]}{$sort_a[$j]})\n|;
471: if ($longtitles->[2]) {
472: $scripttext .= qq| idcodeslongs[$j] = new Array($idnums->{$codetitles->[1]}{$sort_a[$j]})\n|;
473: }
474: $scripttext .= qq| idcourses[$j] = new Array($idnums->{$codetitles->[1]}{$sort_a[$j]})\n|;
475: if ($longtitles->[3]) {
476: $scripttext .= qq| idcourseslongs[$j] = new Array($idnums->{$codetitles->[1]}{$sort_a[$j]})\n|;
477: }
478: my @sort_b = split/","/,$idlist->{$codetitles->[1]}{$sort_a[$j]};
479: for (my $k=0; $k<@sort_b; $k++) {
480: my $idcode_entry = $idlist->{$codetitles->[2]}{$sort_a[$j]}{$sort_b[$k]};
481: $scripttext .= qq| idcodes[$j][$k] = new Array("$idcode_entry")\n|;
482: if ($longtitles->[2]) {
483: my $idcodelong_entry = $idlist_titles->{$codetitles->[2]}{$sort_a[$j]}{$sort_b[$k]};
484: $scripttext .= qq| idcodeslongs[$j][$k] = new Array("$idcodelong_entry")\n|;
485: }
486: $scripttext .= qq| idcourses[$j][$k] = new Array($idnums->{$codetitles->[2]}{$sort_a[$j]}{$sort_b[$k]})\n|;
487: if ($longtitles->[3]) {
488: $scripttext .= qq| idcourseslongs[$j][$k] = new Array($idnums->{$codetitles->[2]}{$sort_a[$j]}{$sort_b[$k]})\n|;
489: }
490: my @sort_c = split/","/,$idlist->{$codetitles->[2]}{$sort_a[$j]}{$sort_b[$k]};
491: for (my $l=0; $l<@sort_c; $l++) {
492: my $idcourse_entry = $idlist->{$codetitles->[3]}{$sort_a[$j]}{$sort_b[$k]}{$sort_c[$l]};
493: $scripttext .= qq| idcourses[$j][$k][$l] = new Array("$idcourse_entry")\n|;
494: if ($longtitles->[3]) {
495: my $idcourselong_entry = $idlist_titles->{$codetitles->[3]}{$sort_a[$j]}{$sort_b[$k]}{$sort_c[$l]};
496: $scripttext .= qq| idcourseslongs[$j][$k][$l] = new Array("$idcourselong_entry")\n|;
497: }
498: }
499: }
500: }
501: return ($scripttext,$longtitles);
502: }
503:
504: sub courseset_js_start {
505: my ($formname,$longtitles_str,$allidlist) = @_;
506: my $output = <<END;
1.6 raeburn 507:
1.1 raeburn 508: function courseSet(caller) {
509: var longtitles = new Array ("$longtitles_str");
510: var idyr = document.$formname.Year.selectedIndex
511: var idsem = document.$formname.Semester.selectedIndex
512: var iddept = document.$formname.Department.selectedIndex
513: var idclass = document.$formname.Number.selectedIndex
514: var idyears = new Array("$allidlist");
515: END
516: return $output;
517: }
518:
1.6 raeburn 519: sub instcode_selectors_data {
1.7 raeburn 520: my ($codedom,$formname,$cat_items,$codetitles,$cat_titles,$cat_order,$officialjs) = @_;
1.27 raeburn 521: my ($jscript,$codes,%idlist,%idnums,%idlist_titles,%by_year,%by_sem,%by_dept);
522: my ($numtitles,$lasttitle,$totcodes);
523: my $instcats = &Apache::lonnet::get_dom_instcats($codedom);
524: if (ref($instcats) eq 'HASH') {
525: if ((ref($instcats->{'codetitles'}) eq 'ARRAY') && (ref($instcats->{'codes'}) eq 'HASH') &&
526: (ref($instcats->{'cat_titles'}) eq 'HASH') && (ref($instcats->{'cat_order'}) eq 'HASH')) {
527: %{$codes} = %{$instcats->{'codes'}};
528: @{$codetitles} = @{$instcats->{'codetitles'}};
529: %{$cat_titles} = %{$instcats->{'cat_titles'}};
530: %{$cat_order} = %{$instcats->{'cat_order'}};
531: $totcodes = scalar(keys(%{$codes}));
1.28 raeburn 532: if ((!$totcodes) && (exists($instcats->{'totcodes'}))) {
1.29 ! raeburn 533: $totcodes = $instcats->{'totcodes'};
1.28 raeburn 534: }
1.27 raeburn 535: &build_code_selections($codes,$codetitles,$cat_titles,$cat_order,
1.6 raeburn 536: \%idlist,\%idnums,\%idlist_titles);
1.29 ! raeburn 537: my ($scripttext,$longtitles) =
1.6 raeburn 538: &javascript_definitions($codetitles,\%idlist,\%idlist_titles,
539: \%idnums,$cat_titles);
540: my $longtitles_str = join('","',@{$longtitles});
541: my $allidlist = $idlist{$codetitles->[0]};
542: $numtitles = @{$codetitles};
543: $lasttitle = $numtitles;
544: if ($numtitles > 4) {
545: $lasttitle = 4;
546: }
547: if ($numtitles == 0) {
548: if (!defined($env{'form.state'})) {
549: $env{'form.state'} = 'listing';
550: }
551: } else {
552: my @data = ('top');
553: for (my $k=0; $k<$lasttitle; $k++) {
554: my $cat = $codetitles->[$k];
555: my $level = 1;
556: $level = &recurse_options($codetitles->[$k],$idlist{$codetitles->[$k]},$level,$cat,$cat_items,\@data,\%by_year,\%by_sem,\%by_dept);
557: }
558: $scripttext .= &build_javascript(\%by_year,\%by_sem,\%by_dept,$cat_order,$codetitles);
1.7 raeburn 559: if ($officialjs) {
560: $jscript .= '
561:
1.18 raeburn 562: function toggleOfficial() {
563: var choice;
564: for (var i=0; i<document.'.$formname.'.official.length; i++) {
565: if (document.'.$formname.'.official[i].checked) {
566: choice = document.'.$formname.'.official[i].value;
567: }
568: }
569: if (choice == "off") {
570: if (document.getElementById("instcodes")) {
571: document.getElementById("instcodes").style.display = "none";
572: }';
1.7 raeburn 573: for (my $i=0; $i<@{$codetitles}-1; $i++) {
574: $jscript .= '
1.18 raeburn 575: document.'.$formname.'.'.$codetitles->[$i].'.selectedIndex = 0;';
1.7 raeburn 576: }
1.18 raeburn 577: $jscript .= '
578: } else {
579: if (document.getElementById("instcodes")) {
580: document.getElementById("instcodes").style.display = "block";
581: }
582: }
1.7 raeburn 583: }
584:
585: function setOfficial(caller) {
1.8 raeburn 586: if (typeof(caller) != "undefined") {
587: if (caller.options[caller.selectedIndex].value != 0) {
588: if (document.'.$formname.'.official.length > 0) {
589: for (var j=0; j<document.'.$formname.'.official.length; j++) {
590: if (document.'.$formname.'.official[j].value == "on") {
591: document.'.$formname.'.official[j].checked = true;
592: }
593: }
1.7 raeburn 594: }
595: }
596: }
597: return;
598: }
599:
600: ';
601:
602: $officialjs = 'setOfficial(caller);';
603: }
604: $jscript .= &javascript_select_filler($formname,$scripttext,$codetitles,$longtitles_str,$allidlist,$officialjs);
1.6 raeburn 605: if ($env{'form.state'} eq 'listing') {
1.12 raeburn 606: my @standardnames = &Apache::loncommon::get_standard_codeitems();
607: my %local_to_standard;
608: if (ref($codetitles) eq 'ARRAY') {
609: for (my $i=0; $i<@{$codetitles}; $i++) {
610: $local_to_standard{$codetitles->[$i]} = $standardnames[$i];
611: }
612: }
1.6 raeburn 613: $jscript .= '
614: function setElements() {
615: ';
616: for (my $i=0; $i<@{$codetitles}-1; $i++) {
1.12 raeburn 617: my $item = $local_to_standard{$codetitles->[$i]};
618: if ($env{'form.'.$item} != -1) {
1.6 raeburn 619: $jscript .= '
1.12 raeburn 620: for (var j=0; j<document.'.$formname.'.'.$item.'.length; j++) {
621: if (document.'.$formname.'.'.$item.'[j].value == "'.$env{'form.'.$item}.'") {
622: document.'.$formname.'.'.$item.'.selectedIndex = j;
1.6 raeburn 623: }
624: }
625: ';
626: }
627: }
628: $jscript .= ' courseSet()'."\n";
1.12 raeburn 629: my $lastcodetitle = $local_to_standard{$codetitles->[-1]};
630: if ($env{'form.'.$lastcodetitle} != -1) {
1.6 raeburn 631: $jscript .= '
1.12 raeburn 632: for (var j=0; j<document.'.$formname.'.'.$lastcodetitle.'.length; j++) {
633: if (document.'.$formname.'.'.$lastcodetitle.'[j].value == "'.$env{'form.'.$lastcodetitle}.'") {
634: document.'.$formname.'.'.$lastcodetitle.'.selectedIndex = j;
1.6 raeburn 635: }
636: }
637: ';
638: }
639: $jscript .= '}';
640: }
641: }
642: }
643: }
644: return ($jscript,$totcodes,$numtitles,$lasttitle);
645: }
646:
647: sub build_instcode_selectors {
1.24 raeburn 648: my ($numtitles,$lasttitle,$cat_items,$codetitles,$cat_titles,$cat_order,$official,$class,$id,$noedit) = @_;
1.6 raeburn 649: my $output;
1.10 raeburn 650: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1.6 raeburn 651: if ($numtitles > 0) {
1.18 raeburn 652: my $style;
1.22 raeburn 653: if ($official eq 'off') {
1.18 raeburn 654: $style = ' style="display: none"';
655: }
1.22 raeburn 656: if ($id eq '') {
657: $id = 'instcodes';
658: }
1.24 raeburn 659: my $disabled;
660: if ($noedit) {
661: $disabled = ' disabled="disabled"';
662: }
1.22 raeburn 663: $output .= '<div id="'.$id.'"'.$style.'><table><tr>';
1.6 raeburn 664: for (my $k=0; $k<$lasttitle-1; $k++) {
665: my (@items,@unsorted);
666: if (ref($cat_items->{$codetitles->[$k]}) eq 'ARRAY') {
667: @unsorted = @{$cat_items->{$codetitles->[$k]}};
668: }
669: &sort_cats($k,$cat_order,$codetitles,\@unsorted,\@items);
670: my @longitems;
671: if (defined($cat_titles->{$codetitles->[$k]})) {
672: foreach my $item (@items) {
673: push(@longitems,$cat_titles->{$codetitles->[$k]}{$item});
674: }
675: } else {
676: @longitems = @items;
677: }
678: $output .= '<td align="center">'.$codetitles->[$k].'<br />'."\n".
1.22 raeburn 679: '<select name="'.$standardnames[$k].'" onchange="courseSet(this)"';
680: if ($class) {
681: $output .= ' class="'.$class.'"';
682: }
1.24 raeburn 683: $output .= $disabled.'>'."\n".'<option value="0">'.&mt('All').'</option>'."\n";
1.6 raeburn 684: for (my $i=0; $i<@items; $i++) {
685: if ($longitems[$i] eq '') {
686: $longitems[$i] = $items[$i];
687: }
688: $output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>';
689: }
690: $output .= '</select></td>';
691: }
692: $output .= '<td align="center">'.$codetitles->[$lasttitle-1].'<br />'."\n".
1.23 raeburn 693: '<select name="'.$standardnames[$lasttitle-1].'"';
694: if ($class) {
695: $output .= ' class="'.$class.'"';
696: }
1.24 raeburn 697: $output .= $disabled.'>'."\n".
1.6 raeburn 698: '<option value="0">'.&mt('All')."\n".
699: '</option>'."\n".'</select>'."\n".
700: '</td></tr></table>'."\n";
701: if ($numtitles > 4) {
702: $output .= '<br /><br />'.$codetitles->[$numtitles-1].'<br />'."\n".
1.9 raeburn 703: '<input type="text" name="'.$standardnames[$numtitles-1].
1.24 raeburn 704: '"'.$disabled.' /><br />'."\n";
1.6 raeburn 705: }
1.18 raeburn 706: $output .= '</div>';
1.6 raeburn 707: }
708: return $output;
709: }
710:
1.16 raeburn 711: sub instcode_selectors {
712: my ($codedom,$formname,$officialjs,$codetitles) = @_;
713: my ($output,%cat_titles,%cat_order,%cat_items);
714: my ($jscript,$totcodes,$numtitles,$lasttitle) =
715: &instcode_selectors_data($codedom,$formname,\%cat_items,$codetitles,
716: \%cat_titles,\%cat_order,$officialjs);
717: if ($numtitles > 0) {
718: my $official = ' checked="checked" ';
719: my $unofficial = '';
1.18 raeburn 720: if (($formname eq 'filterpicker') && ($env{'form.official'} eq 'off')) {
1.16 raeburn 721: $unofficial = $official;
722: $official = '';
723: }
724: $output .= '<span class="LC_nobreak">'.&mt('Official course:').' <label>'.
1.18 raeburn 725: '<input type="radio" name="official" value="on"'.$official.
726: ' onclick="toggleOfficial();" />'.&mt('Yes').'</label>'.
727: (' 'x3).'<label>'.
1.16 raeburn 728: '<input type="radio" name="official" value="off"'.$unofficial.
729: ' onclick="toggleOfficial();" />'.&mt('No').'</label></span><br />'.
730: &build_instcode_selectors($numtitles,$lasttitle,\%cat_items,$codetitles,
1.22 raeburn 731: \%cat_titles,\%cat_order,$env{'form.official'})."\n".
1.16 raeburn 732: '<input type="hidden" name="numtitles" value="'.$numtitles.'" />'."\n".
733: '<input type="hidden" name="state" value="listing" />'."\n";
734: }
735: return ($output,$jscript,$numtitles);
736: }
737:
1.6 raeburn 738: sub recurse_options {
739: my ($currkey,$currlist,$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept) = @_;
740: if (ref($currlist) eq 'HASH') {
741: $level ++;
742: foreach my $key (sort(keys(%{$currlist}))) {
743: $$data[$level-1]= $key;
744: &recurse_options($key,$currlist->{$key},$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept);
745: }
746: } else {
747: $level --;
748: my @contents = split(/","/,$currlist);
749: foreach my $item (@contents) {
750: if (!grep(/^\Q$item\E$/,@{$cat_options->{$cat}})) {
751: push(@{$cat_options->{$cat}},$item);
752: }
753: if ($level == 3) {
754: if (!grep/^\Q$item\E$/,@{$by_year->{$data->[1]}->{$currkey}}) {
755: push(@{$by_year->{$data->[1]}->{$currkey}},$item);
756: }
757: if (!grep/^\Q$item\E$/,@{$by_sem->{$data->[2]}->{$currkey}}) {
758: push(@{$by_sem->{$data->[2]}->{$currkey}},$item);
759: }
760: if (!grep/^\Q$item\E$/,@{$by_dept->{$currkey}}) {
761: push(@{$by_dept->{$currkey}},$item);
762: }
763:
764: }
765: }
766: }
767: return $level;
768: }
769:
770: sub build_javascript {
771: my ($by_year,$by_sem,$by_dept,$cat_order,$codetitles) = @_;
772: my @unsorted = keys(%{$by_year});
773: my @sorted_yrs;
1.21 raeburn 774: &sort_cats('0',$cat_order,$codetitles,\@unsorted,\@sorted_yrs);
775: my $output = 'var idcse_by_yr_year = new Array("'.join('","',@sorted_yrs).'");'."\n".
1.6 raeburn 776: 'var idcse_by_yr_dept = new Array('.scalar(@sorted_yrs).');'."\n".
777: 'var idcse_by_yr_num = new Array('.scalar(@sorted_yrs).');'."\n";
778: for (my $i=0; $i<@sorted_yrs; $i++) {
779: my $numkeys = keys(%{$by_year->{$sorted_yrs[$i]}});
780: $output .= " idcse_by_yr_num[$i] = new Array($numkeys);\n";
781: if (ref($by_year->{$sorted_yrs[$i]}) eq 'HASH') {
782: @unsorted = keys(%{$by_year->{$sorted_yrs[$i]}});
783: my @sorted_depts;
784: &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts);
785: $output .= qq| idcse_by_yr_dept[$i] = new Array ("|.join('","',@sorted_depts).'");'."\n";
786: for (my $j=0; $j<@sorted_depts; $j++) {
787: $output .= qq| idcse_by_yr_num[$i][$j] = new Array ("|;
788: $output .= join('","',sort(@{$by_year->{$sorted_yrs[$i]}->{$sorted_depts[$j]}})).'");'."\n";
789: }
790: }
791: }
792: @unsorted = keys(%{$by_sem});
793: my @sorted_sems;
794: &sort_cats('1',$cat_order,$codetitles,\@unsorted,\@sorted_sems);
795: $output .= 'idcse_by_sem_sems = new Array("'.join('","',@sorted_sems).'");'."\n".
796: 'idcse_by_sem_dept = new Array('.scalar(@sorted_sems).');'."\n".
797: 'idcse_by_sem_num = new Array('.scalar(@sorted_sems).');'."\n";
798: for (my $i=0; $i<@sorted_sems; $i++) {
799: my $numkeys = keys(%{$by_sem->{$sorted_sems[$i]}});
800: $output .= " idcse_by_sem_num[$i] = new Array($numkeys);\n";
801: if (ref($by_sem->{$sorted_sems[$i]}) eq 'HASH') {
802: @unsorted = keys(%{$by_sem->{$sorted_sems[$i]}});
803: my @sorted_depts;
804: &sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts);
805: $output .= qq| idcse_by_sem_dept[$i] = new Array("|.join('","',@sorted_depts).'");'."\n";
806: for (my $j=0; $j<@sorted_depts; $j++) {
807: $output .= qq| idcse_by_sem_num[$i][$j] = new Array ("|.join('","',sort(@{$by_sem->{$sorted_sems[$i]}->{$sorted_depts[$j]}})).'");'."\n";
808: }
809: }
810: }
811: @unsorted = keys(%{$by_dept});
812: my @sorted_deps;
813: &sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_deps);
814: $output .= 'idcse_by_dep = new Array('.scalar(@sorted_deps).');'."\n";
815: for (my $k=0; $k<@sorted_deps; $k++) {
816: $output .= qq| idcse_by_dep[$k] = new Array ("|.join('","',sort(@{$by_dept->{$sorted_deps[$k]}})).'");'."\n";
817: }
818: return $output;
819: }
820:
821: sub javascript_select_filler {
1.7 raeburn 822: my ($formname,$scripttext,$codetitles,$longtitles_str,$allidlist,$officialjs) = @_;
1.13 raeburn 823: my $all = &mt('All');
824: my $nocrs = &mt('No courses');
1.6 raeburn 825: my $output = <<END;
826:
1.19 musolffc 827: function courseSet(caller, onload) {
1.6 raeburn 828: var longtitles = new Array ("$longtitles_str");
1.19 musolffc 829: var valyr = '';
830: var valsem = '';
831: var valdept = '';
832: var valclass = '';
833: if (onload) {
834: valyr = "$env{'form.Year'}";
835: valsem = "$env{'form.Semester'}";
836: valdept = "$env{'form.Department'}";
837: valclass = "$env{'form.Number'}";
838: } else {
839: valyr = document.$formname.Year.options[document.$formname.Year.selectedIndex].value;
840: valsem = document.$formname.Semester.options[document.$formname.Semester.selectedIndex].value;
841: valdept = document.$formname.Department.options[document.$formname.Department.selectedIndex].value;
842: valclass = document.$formname.Number.options[document.$formname.Number.selectedIndex].value;
843: }
1.6 raeburn 844: var idyears = new Array("$allidlist");
845: var idyr = -1;
846: var idsem = -1;
847: var iddept = -1;
848: document.$formname.Number.length = 0;
849:
850: $scripttext
851:
1.19 musolffc 852: if (onload) {
853: if (document.$formname.Year.options.length > 0) {
854: for (var i = 0; i< document.$formname.Year.options.length; i++) {
855: if (document.$formname.Year.options[i].value == "$env{'form.Year'}") {
856: document.$formname.Year.selectedIndex = i;
857: break;
858: }
859: }
860: }
861: if (document.$formname.Department.options.length > 0) {
862: for (var i = 0; i< document.$formname.Department.options.length; i++) {
863: if (document.$formname.Department.options[i].value == "$env{'form.Department'}") {
864: document.$formname.Department.selectedIndex = i;
865: break;
866: }
867: }
868: }
869: if (document.$formname.Semester.options.length > 0) {
870: for (var i = 0; i< document.$formname.Semester.options.length; i++) {
871: if (document.$formname.Semester.options[i].value == "$env{'form.Semester'}") {
872: document.$formname.Semester.selectedIndex = i;
873: break;
874: }
875: }
876: }
877: }
878:
879: var selYear = document.$formname.Year.selectedIndex-1;
880: var selSemester = document.$formname.Semester.selectedIndex-1;
881: var selDepartment = document.$formname.Department.selectedIndex-1;
1.6 raeburn 882: if (selYear == -1) {
883: if (selSemester == -1) {
884: if (selDepartment > -1) {
1.13 raeburn 885: document.$formname.Number.options[0] = new Option('$all','0',false,false);
1.6 raeburn 886: for (var k=0; k<idcse_by_dep[selDepartment].length; k++) {
887: document.$formname.Number.options[k+1] = new Option(idcse_by_dep[selDepartment][k],idcse_by_dep[selDepartment][k],false,false);
888:
889: }
890: }
891: else {
1.13 raeburn 892: document.$formname.Number.options[0] = new Option('$all','0',true,true);
1.6 raeburn 893: }
894: }
895: else {
896: if (selDepartment > -1) {
897: for (var i=0; i<idcse_by_sem_sems.length; i++) {
898: if (idcse_by_sem_sems[i] == valsem) {
899: idsem = i;
900: }
901: }
902: if (idsem != -1) {
903: for (var i=0; i<idcse_by_sem_dept[idsem].length; i++) {
904: if (idcse_by_sem_dept[idsem][i] == valdept) {
905: iddept = i;
906: }
907: }
908: }
909: if (iddept != -1) {
1.13 raeburn 910: document.$formname.Number.options[0] = new Option('$all','0',false,false);
1.6 raeburn 911: for (var k=0; k<idcse_by_sem_num[idsem][iddept].length; k++) {
912: document.$formname.Number.options[k+1] = new Option(idcse_by_sem_num[idsem][iddept][k],idcse_by_sem_num[idsem][iddept][k],false,false);
913: }
914: }
915: else {
1.13 raeburn 916: document.$formname.Number.options[0] = new Option('$nocrs','0',true,true);
1.6 raeburn 917: }
918: }
919: else {
1.13 raeburn 920: document.$formname.Number.options[0] = new Option('$all','0',true,true);
1.6 raeburn 921: }
922: }
923: }
924: else {
925: if (selSemester == -1) {
926: if (selDepartment > -1) {
927: for (var i=0; i<idcse_by_yr_year.length; i++) {
928: if (idcse_by_yr_year[i] == valyr) {
929: idyr = i;
930: }
931: }
932: if (idyr != -1) {
933: for (var i=0; i<idcse_by_yr_dept[idyr].length; i++) {
934: if (idcse_by_yr_dept[idyr][i] == valdept) {
935: iddept = i;
936: }
937: }
938: }
939: if (iddept != -1) {
1.13 raeburn 940: document.$formname.Number.options[0] = new Option('$all','0',false,false);
1.6 raeburn 941: for (var k=0; k<idcse_by_yr_num[idyr][iddept].length; k++) {
942: document.$formname.Number.options[k+1] = new Option(idcse_by_yr_num[idyr][iddept][k],idcse_by_yr_num[idyr][iddept][k],false,false);
943: }
944: }
945: else {
1.13 raeburn 946: document.$formname.Number.options[0] = new Option('$nocrs','0',true,true);
1.6 raeburn 947: }
948: }
949: else {
1.13 raeburn 950: document.$formname.Number.options[0] = new Option('$all','0',true,true);
1.6 raeburn 951: }
952: }
953: else {
954: if (selDepartment > -1) {
955: for (var k=0; k<idyears.length; k++) {
956: if (idyears[k] == valyr) {
957: idyr = k;
958: }
959: }
960: if (idyr != -1) {
961: for (var k=0; k<idsems[idyr].length; k++) {
962: if (idsems[idyr][k] == valsem) {
963: idsem = k;
964: }
965: }
966: }
967: if (idsem != -1) {
968: for (var k=0; k<idcodes[idyr][idsem].length; k++) {
969: if (idcodes[idyr][idsem][k] == valdept) {
970: iddept = k;
971: }
972: }
973: }
974: if (iddept != -1) {
1.17 raeburn 975: document.$formname.Number.options[0] = new Option('$all','0',false,false);
1.6 raeburn 976: for (var i=0; i<idcourses[idyr][idsem][iddept].length; i++) {
977: var display = idcourses[idyr][idsem][iddept][i];
978: if (longtitles[3] == 1) {
979: if (idcourseslongs[idyr][idsem][iddept][i] != "") {
980: display = idcourseslongs[idyr][idsem][iddept][i]
981: }
982: }
983: document.$formname.Number.options[i+1] = new Option(display,idcourses[idyr][idsem][iddept][i],false,false)
984: }
985: }
986: else {
1.13 raeburn 987: document.$formname.Number.options[0] = new Option('$nocrs','0',true,true);
1.6 raeburn 988: }
989: }
990: else {
1.13 raeburn 991: document.$formname.Number.options[0] = new Option('$all','0',true,true);
1.6 raeburn 992: }
993: }
994: document.$formname.Number.selectedIndex = 0
995: }
1.19 musolffc 996: if (onload) {
997: if (document.$formname.Number.options.length > 0) {
998: for (var i = 0; i< document.$formname.Number.options.length; i++) {
999: if (document.$formname.Number.options[i].value == "$env{'form.Number'}") {
1000: document.$formname.Number.selectedIndex = i;
1001: break;
1002: }
1003: }
1004: }
1005: } else {
1006: $officialjs
1007: }
1.6 raeburn 1008: }
1009: END
1010: return $output;
1011: }
1012:
1013: sub instcode_search_str {
1.9 raeburn 1014: my ($domain,$numtitles,$codetitles) = @_;
1.6 raeburn 1015: my $instcode;
1016: if (defined($numtitles) && $numtitles == 0) {
1017: $instcode = '.+';
1018: } else {
1019: my (%codedefaults,@code_order);
1020: my $defaults_result =
1021: &Apache::lonnet::auto_instcode_defaults($domain,\%codedefaults,
1022: \@code_order);
1.10 raeburn 1023: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1.9 raeburn 1024: my %local_to_standard;
1025: if (ref($codetitles) eq 'ARRAY') {
1026: for (my $i=0; $i<@{$codetitles}; $i++) {
1027: $local_to_standard{$codetitles->[$i]} = $standardnames[$i];
1028: }
1029: }
1.6 raeburn 1030: if ($defaults_result eq 'ok') {
1031: $instcode ='^';
1.9 raeburn 1032: foreach my $loctitle (@code_order) {
1033: my $item = $local_to_standard{$loctitle};
1034: if ($item ne '') {
1035: if ($env{'form.'.$item} eq '0' ) {
1.12 raeburn 1036: $instcode .= $codedefaults{$loctitle};
1.9 raeburn 1037: } else {
1038: $instcode .= $env{'form.'.$item};
1039: }
1.6 raeburn 1040: } else {
1.9 raeburn 1041: $instcode .= '.+';
1.6 raeburn 1042: }
1043: }
1044: $instcode .= '$';
1045: } else {
1046: $instcode = '.+';
1047: }
1048: }
1049: return $instcode;
1050: }
1051:
1.10 raeburn 1052: sub instcode_from_selectors {
1.14 raeburn 1053: my ($cdom,$noregexps) = @_;
1.10 raeburn 1054: my $instcode;
1.27 raeburn 1055: my (@codetitles,%codedefaults,@code_order);
1056: my $instcats = &Apache::lonnet::get_dom_instcats($cdom);
1057: if (ref($instcats) eq 'HASH') {
1058: if (ref($instcats->{'codetitles'}) eq 'ARRAY') {
1059: @codetitles = @{$instcats->{'codetitles'}};
1060: }
1061: }
1.10 raeburn 1062: my $defaults_result =
1063: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
1064: \@code_order);
1.27 raeburn 1065: if (($defaults_result eq 'ok') && (@codetitles > 0)) {
1.10 raeburn 1066: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1067: my %local_to_standard;
1068: for (my $i=0; $i<@codetitles; $i++) {
1069: $local_to_standard{$codetitles[$i]} = $standardnames[$i];
1070: }
1071: foreach my $loctitle (@code_order) {
1072: my $category = $local_to_standard{$loctitle};
1073: if ($category ne '') {
1074: if ($env{'form.'.$category} eq '-1' ) {
1.14 raeburn 1075: if ($noregexps) {
1076: $instcode .= ' ';
1077: } else {
1078: $instcode .= $codedefaults{$category};
1079: }
1.10 raeburn 1080: } else {
1081: $instcode .= $env{'form.'.$category};
1082: }
1083: } else {
1084: $instcode .= '.+';
1085: }
1086: }
1087: }
1088: return $instcode;
1.9 raeburn 1089: }
1090:
1.1 raeburn 1091: 1;
1092:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>