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