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