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