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