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