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