Annotation of loncom/interface/courseclassifier.pm, revision 1.28
1.5 raeburn 1: # The LearningOnline Network with CAPA
2: # Utilities for classifying courses based on institutional code
3: #
1.28 ! raeburn 4: # $Id: courseclassifier.pm,v 1.27 2019/07/23 13:58:53 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 {
72: @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ("$$codes{$cid}{$$codetitles[2]}"); }
73: } else {
74: %{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}} = ();
75: @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ("$$codes{$cid}{$$codetitles[2]}");
76: }
77: } elsif ($num == 3) {
78: if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}})) {
79: if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
80: if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}})) {
81: if (!grep/^$$codes{$cid}{$$codetitles[3]}$/,@{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}}) {
82: push @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}}, $$codes{$cid}{$$codetitles[3]};
83: }
84: } else {
85: @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
86: }
87: } else {
88: %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
89: @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
90: }
91: } else {
92: %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}} = ();
93: %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
94: @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
95: }
96: } elsif ($num == 4) {
97: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}})) {
98: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
99: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}})) {
100: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}})) {
101: 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]}}}) {
102: push @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}}, $$codes{$cid}{$$codetitles[4]};
103: }
104: } else {
105: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
106: }
107: } else {
108: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
109: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
110: }
111: } else {
112: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
1.4 raeburn 113: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
114: @{$$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 115: }
116: } else {
117: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}} = ();
118: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
119: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
120: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[3]}");
121: }
122: }
123: $num ++;
124: if ($num <@{$codetitles}) {
125: &recurse_list($cid,$codetitles,$codes,$num,$idarrays);
126: }
127: }
128:
129: sub build_code_selections {
130: my ($codes,$codetitles,$cat_titles,$cat_order,$idlist,$idnums,$idlist_titles) = @_;
131: my %idarrays = ();
132: for (my $i=1; $i<@{$codetitles}; $i++) {
133: %{$idarrays{$$codetitles[$i]}} = ();
134: }
1.20 raeburn 135: foreach my $cid (sort(keys(%{$codes}))) {
1.1 raeburn 136: &recurse_list($cid,$codetitles,$codes,0,\%idarrays);
137: }
138: for (my $num=0; $num<@{$codetitles}; $num++) {
139: if ($num == 0) {
140: my @contents = ();
141: my @contents_titles = ();
142: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[0]}},\@contents);
143: if (defined($$cat_titles{$$codetitles[0]})) {
144: foreach (@contents) {
145: push @contents_titles, $$cat_titles{$$codetitles[0]}{$_};
146: }
147: }
148: $$idlist{$$codetitles[0]} = join('","',@contents);
149: $$idnums{$$codetitles[0]} = scalar(@contents);
150: if (defined($$cat_titles{$$codetitles[0]})) {
151: $$idlist_titles{$$codetitles[0]} = join('","',@contents_titles);
152: }
153: } elsif ($num == 1) {
154: %{$$idlist{$$codetitles[1]}} = ();
155: %{$$idlist_titles{$$codetitles[1]}} = ();
1.20 raeburn 156: foreach my $key_a (keys(%{$idarrays{$$codetitles[1]}})) {
1.1 raeburn 157: my @sorted_a = ();
158: my @sorted_a_titles = ();
159: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[1]}{$key_a}},\@sorted_a);
160: if (defined($$cat_titles{$$codetitles[1]})) {
161: foreach (@sorted_a) {
162: push @sorted_a_titles, $$cat_titles{$$codetitles[1]}{$_};
163: }
164: }
165: $$idlist{$$codetitles[1]}{$key_a} = join('","',@sorted_a);
166: $$idnums{$$codetitles[1]}{$key_a} = scalar(@sorted_a);
167: if (defined($$cat_titles{$$codetitles[1]})) {
168: $$idlist_titles{$$codetitles[1]}{$key_a} = join('","',@sorted_a_titles);
169: }
170: }
171: } elsif ($num == 2) {
172: %{$$idlist{$$codetitles[2]}} = ();
173: %{$$idlist_titles{$$codetitles[2]}} = ();
1.20 raeburn 174: foreach my $key_a (keys(%{$idarrays{$$codetitles[2]}})) {
1.1 raeburn 175: %{$$idlist{$$codetitles[2]}{$key_a}} = ();
176: %{$$idlist_titles{$$codetitles[2]}{$key_a}} = ();
1.20 raeburn 177: foreach my $key_b (keys(%{$idarrays{$$codetitles[2]}{$key_a}})) {
1.1 raeburn 178: my @sorted_b = ();
179: my @sorted_b_titles = ();
180: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[2]}{$key_a}{$key_b}},\@sorted_b);
181: if (defined($$cat_titles{$$codetitles[2]})) {
182: foreach (@sorted_b) {
183: push @sorted_b_titles, $$cat_titles{$$codetitles[2]}{$_};
184: }
185: }
186: $$idlist{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_b);
187: $$idnums{$$codetitles[2]}{$key_a}{$key_b} = scalar(@sorted_b);
188: if (defined($$cat_titles{$$codetitles[2]})) {
189: $$idlist_titles{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_b_titles);
190: }
191: }
192: }
193: } elsif ($num == 3) {
194: %{$$idlist{$$codetitles[3]}} = ();
1.20 raeburn 195: foreach my $key_a (keys(%{$idarrays{$$codetitles[3]}})) {
1.1 raeburn 196: %{$$idlist{$$codetitles[3]}{$key_a}} = ();
1.20 raeburn 197: foreach my $key_b (keys(%{$idarrays{$$codetitles[3]}{$key_a}})) {
1.1 raeburn 198: %{$$idlist{$$codetitles[3]}{$key_a}{$key_b}} = ();
1.20 raeburn 199: foreach my $key_c (keys(%{$idarrays{$$codetitles[3]}{$key_a}{$key_b}})) {
1.1 raeburn 200: my @sorted_c = ();
201: my @sorted_c_titles = ();
202: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[3]}{$key_a}{$key_b}{$key_c}},\@sorted_c);
203: if (defined($$cat_titles{$$codetitles[3]})) {
204: foreach (@sorted_c) {
205: push @sorted_c_titles, $$cat_titles{$$codetitles[3]}{$_};
206: }
207: }
208: $$idlist{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = join('","',@sorted_c);
209: $$idnums{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = scalar(@sorted_c);
210: if (defined($$cat_titles{$$codetitles[3]})) {
1.4 raeburn 211: $$idlist_titles{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = join('","',@sorted_c_titles);
1.1 raeburn 212: }
213: }
214: }
215: }
216: } elsif ($num == 4) {
217: %{$$idlist{$$codetitles[4]}} = ();
1.20 raeburn 218: foreach my $key_a (keys(%{$idarrays{$$codetitles[4]}})) {
1.1 raeburn 219: %{$$idlist{$$codetitles[4]}{$key_a}} = ();
1.20 raeburn 220: foreach my $key_b (keys(%{$idarrays{$$codetitles[4]}{$key_a}})) {
1.1 raeburn 221: %{$$idlist{$$codetitles[4]}{$key_a}{$key_b}} = ();
1.20 raeburn 222: foreach my $key_c (keys(%{$idarrays{$$codetitles[4]}{$key_a}{$key_b}})) {
1.1 raeburn 223: %{$$idlist{$$codetitles[4]}{$key_a}{$key_b}{$key_c}} = ();
1.20 raeburn 224: foreach my $key_d (keys(%{$idarrays{$$codetitles[4]}{$key_a}{$key_b}{$key_c}})) {
1.1 raeburn 225: my @sorted_d = ();
226: my @sorted_d_titles = ();
227: &sort_cats($num,$cat_order,$codetitles,$idarrays{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d},\@sorted_d);
228: if (defined($$cat_titles{$$codetitles[4]})) {
229: foreach (@sorted_d) {
230: push @sorted_d_titles, $$cat_titles{$$codetitles[4]}{$_};
231: }
232: }
233: $$idlist{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d} = join('","',@sorted_d);
234: $$idnums{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d} = scalar(@sorted_d);
1.4 raeburn 235: if (defined($$cat_titles{$$codetitles[4]})) {
236: $$idlist_titles{$$codetitles[3]}{$key_a}{$key_b}{$key_c}{$key_d} = join('","',@sorted_d_titles);
237: }
1.1 raeburn 238: }
239: }
240: }
241: }
242: }
243: }
244: }
245:
246: sub javascript_code_selections {
1.26 raeburn 247: my ($formname,$codetitlesref,$knowncodes,$sectionlist) = @_;
1.25 raeburn 248: return unless (ref($codetitlesref) eq 'ARRAY');
249: my @codetitles = @{$codetitlesref};
1.1 raeburn 250: my $numtitles = @codetitles;
1.10 raeburn 251: my %lt = &Apache::lonlocal::texthash(
252: Select => 'Select',
253: Pick => 'Pick',
254: );
1.1 raeburn 255: my $output = (<<END_OF_BLOCK);
256: var display = new Array($numtitles)
257: if (caller == "" || caller == "$codetitles[0]") {
258: if (caller == "") {
259: document.$formname.Year.length = 0
1.10 raeburn 260: document.$formname.Year.options[0] = new Option("$lt{'Select'}","-1",true,true)
1.1 raeburn 261: display[0] = new Array(idyears.length)
262: for (var i=0; i<idyears.length; i++) {
263: display[0][i] = idyears[i]
264: if (longtitles[0] == 1) {
265: if (idyearslongs[i] != "") {
266: display[0][i] = idyearslongs[i]
267: }
268: }
269: else {
270: if (idyearslongs[i] != "") {
271: display[0][i] = idyears[i]
272: }
273: }
274: document.$formname.Year.options[i+1] = new Option(display[0][i],idyears[i],false,false)
275: }
276: document.$formname.Year.selectedIndex = 0;
277: }
278: document.$formname.Semester.length = 0
279: document.$formname.Department.length = 0;
280: document.$formname.Number.length = 0
1.10 raeburn 281: document.$formname.Department.options[0] = new Option("<-$lt{'Pick'} $codetitles[1]","-1",true,true)
282: document.$formname.Number.options[0] = new Option("<-$lt{'Pick'} $codetitles[2]","-1",true,true)
1.1 raeburn 283: if (idyr == 0 || caller == "") {
1.10 raeburn 284: document.$formname.Semester.options[0] = new Option("<-$lt{'Pick'} $codetitles[0]","-1",true,true)
1.1 raeburn 285: }
286: else {
1.10 raeburn 287: document.$formname.Semester.options[0] = new Option("$lt{'Select'}","-1",true,true)
1.1 raeburn 288: display[1] = new Array(idsems[idyr-1].length)
289: for (var i=0; i<idsems[idyr-1].length; i++) {
290: display[1][i] = idsems[idyr-1][i]
291: if (longtitles[1] == 1) {
292: if (idsemslongs[idyr-1][i] != "") {
293: display[1][i] = idsemslongs[idyr-1][i]
294: }
295: }
296: document.$formname.Semester.options[i+1] = new Option(display[1][i],idsems[idyr-1][i],false,false)
297: }
298: }
299: document.$formname.Semester.selectedIndex = 0;
300: }
301: if (caller == "$codetitles[1]") {
302: document.$formname.Department.length = 0
303: document.$formname.Number.length = 0
304: document.$formname.Number.options[0] = new Option("<-Pick $codetitles[2]","-1",true,true)
305: if (idsem == 0) {
1.10 raeburn 306: document.$formname.Department.options[0] = new Option("<-$lt{'Pick'} $codetitles[1]","-1",true,true)
1.1 raeburn 307: }
308: else {
1.10 raeburn 309: document.$formname.Department.options[0] = new Option("$lt{'Select'}","-1",true,true)
1.1 raeburn 310: display[2] = new Array(idcodes[idyr-1][idsem-1].length)
311: for (var i=0; i<idcodes[idyr-1][idsem-1].length; i++) {
312: display[2][i] = idcodes[idyr-1][idsem-1][i]
313: if (longtitles[2] == 1) {
314: if (idcodeslongs[idyr-1][idsem-1][i] != "") {
315: display[2][i] = idcodeslongs[idyr-1][idsem-1][i]
316: }
317: }
318: document.$formname.Department.options[i+1] = new Option(display[2][i],idcodes[idyr-1][idsem-1][i],false,false)
319: }
320: }
321: document.$formname.Department.selectedIndex = 0
322: }
323: if (caller == "$codetitles[2]") {
324: document.$formname.Number.length = 0
325: if (iddept == 0) {
1.10 raeburn 326: document.$formname.Number.options[0] = new Option("<-$lt{'Pick'} $codetitles[2]","-1",true,true)
1.1 raeburn 327: }
328: else {
329: document.$formname.Number.options[0] = new Option("Select","-1",true,true)
330: display[3] = new Array (idcourses[idyr-1][idsem-1][iddept-1].length)
331: for (var i=0; i<idcourses[idyr-1][idsem-1][iddept-1].length; i++) {
332: display[3][i] = idcourses[idyr-1][idsem-1][iddept-1][i]
333: if (longtitles[3] == 1) {
334: if (idcourseslongs[idyr-1][idsem-1][iddept-1][i] != "") {
335: display[3][i] = idcourseslongs[idyr-1][idsem-1][iddept-1][i]
336: }
337: }
338: document.$formname.Number.options[i+1] = new Option(display[3][i],idcourses[idyr-1][idsem-1][iddept-1][i],false,false)
339: }
340: }
341: document.$formname.Number.selectedIndex = 0
342: }
343: }
1.26 raeburn 344: END_OF_BLOCK
345:
346: if ((ref($knowncodes) eq 'HASH') && (keys(%{$knowncodes}) > 0)) {
347: my @standardnames = &Apache::loncommon::get_standard_codeitems();
348: my (%local_to_standard,$currstr);
349: for (my $i=0; $i<@codetitles; $i++) {
350: $local_to_standard{$codetitles[$i]} = $standardnames[$i];
351: }
352: $output .= <<"ENDJS";
353:
354: function initialize_codes() {
355: ENDJS
356: for (my $i=0; $i<@codetitles-1; $i++) {
357: my $item = $local_to_standard{$codetitles[$i]};
358: $currstr .= $knowncodes->{$codetitles[$i]};
359: if ($knowncodes->{$codetitles[$i]} != -1) {
360: $output .= '
361: for (var j=0; j<document.'.$formname.'.'.$item.'.length; j++) {
362: if (document.'.$formname.'.'.$item.'[j].value == "'.$knowncodes->{$codetitles[$i]}.'") {
363: document.'.$formname.'.'.$item.'.selectedIndex = j;
364: }
365: }
366: ';
367: }
368: $output .= ' courseSet('."'$codetitles[$i]'".')'."\n";
369: }
370: my $lastcodetitle = $local_to_standard{$codetitles[-1]};
371: $currstr .= $knowncodes->{$codetitles[-1]};
372: if ($knowncodes->{$codetitles[-1]} != -1) {
373: $output .= '
374: for (var j=0; j<document.'.$formname.'.'.$lastcodetitle.'.length; j++) {
375: if (document.'.$formname.'.'.$lastcodetitle.'[j].value == "'.$knowncodes->{$codetitles[-1]}.'") {
376: document.'.$formname.'.'.$lastcodetitle.'.selectedIndex = j;
377: }
378: }
379: ';
380: }
381: $output .= " return;\n}\n";
382: if ($sectionlist) {
383: $output .= '
384: function toggleSecVis() {
385: var currcode = "";
386: var crscode = '."'$currstr'".';
387: ';
388: for (my $i=0; $i<@codetitles-1; $i++) {
389: my $item = $local_to_standard{$codetitles[$i]};
390: $output .= 'currcode += document.'.$formname.'.'.$item.'.options[document.'.$formname.'.'.$item.'.selectedIndex].value;'."\n";
391: }
392: my $lastcodetitle = $local_to_standard{$codetitles[-1]};
393: if ($lastcodetitle ne '') {
394: if ($knowncodes->{$codetitles[-1]} != -1) {
395: $output .= 'currcode += document.'.$formname.'.'.$lastcodetitle.'.options[document.'.$formname.'.'.$lastcodetitle.'.selectedIndex].value;'."\n";
396: }
397: }
398: $output .= <<"ENDSEC";
399: var showlist = 'none';
400: var showbox = 'inline';
401: if ((crscode != '') && (currcode == crscode)) {
402: showlist = 'inline';
403: showbox = 'none';
404: }
405: alert("crscode is ||"+crscode+"|| and currcode is ||"+currcode+"|| and showlist is ||"+showlist+"|| and showbox is ||"+showbox+"||");
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'}))) {
! 532: $totcodes = $instcats->{'totcodes'};
! 533: }
1.27 raeburn 534: &build_code_selections($codes,$codetitles,$cat_titles,$cat_order,
1.6 raeburn 535: \%idlist,\%idnums,\%idlist_titles);
536: my ($scripttext,$longtitles) =
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>