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