Annotation of loncom/interface/courseclassifier.pm, revision 1.17
1.5 raeburn 1: # The LearningOnline Network with CAPA
2: # Utilities for classifying courses based on institutional code
3: #
1.17 ! raeburn 4: # $Id: courseclassifier.pm,v 1.16 2014/03/11 21:42:18 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: }
151: foreach my $cid (sort keys %{$codes}) {
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]}} = ();
172: foreach my $key_a (keys %{$idarrays{$$codetitles[1]}}) {
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]}} = ();
190: foreach my $key_a (keys %{$idarrays{$$codetitles[2]}}) {
191: %{$$idlist{$$codetitles[2]}{$key_a}} = ();
192: %{$$idlist_titles{$$codetitles[2]}{$key_a}} = ();
193: foreach my $key_b (keys %{$idarrays{$$codetitles[2]}{$key_a}}) {
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]}} = ();
211: foreach my $key_a (keys %{$idarrays{$$codetitles[3]}}) {
212: %{$$idlist{$$codetitles[3]}{$key_a}} = ();
213: foreach my $key_b (keys %{$idarrays{$$codetitles[3]}{$key_a}}) {
214: %{$$idlist{$$codetitles[3]}{$key_a}{$key_b}} = ();
215: foreach my $key_c (keys %{$idarrays{$$codetitles[3]}{$key_a}{$key_b}}) {
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]}} = ();
234: foreach my $key_a (keys %{$idarrays{$$codetitles[4]}}) {
235: %{$$idlist{$$codetitles[4]}{$key_a}} = ();
236: foreach my $key_b (keys %{$idarrays{$$codetitles[4]}{$key_a}}) {
237: %{$$idlist{$$codetitles[4]}{$key_a}{$key_b}} = ();
238: foreach my $key_c (keys %{$idarrays{$$codetitles[4]}{$key_a}{$key_b}}) {
239: %{$$idlist{$$codetitles[4]}{$key_a}{$key_b}{$key_c}} = ();
240: foreach my $key_d (keys %{$idarrays{$$codetitles[4]}{$key_a}{$key_b}{$key_c}}) {
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:
492: function toggleOfficial() {';
493: for (my $i=0; $i<@{$codetitles}-1; $i++) {
494: $jscript .= '
495: document.'.$formname.'.'.$codetitles->[$i].'.selectedIndex = 0;';
496: }
497: $jscript .= '
498: }
499:
500: function setOfficial(caller) {
1.8 raeburn 501: if (typeof(caller) != "undefined") {
502: if (caller.options[caller.selectedIndex].value != 0) {
503: if (document.'.$formname.'.official.length > 0) {
504: for (var j=0; j<document.'.$formname.'.official.length; j++) {
505: if (document.'.$formname.'.official[j].value == "on") {
506: document.'.$formname.'.official[j].checked = true;
507: }
508: }
1.7 raeburn 509: }
510: }
511: }
512: return;
513: }
514:
515: ';
516:
517: $officialjs = 'setOfficial(caller);';
518: }
519: $jscript .= &javascript_select_filler($formname,$scripttext,$codetitles,$longtitles_str,$allidlist,$officialjs);
1.6 raeburn 520: if ($env{'form.state'} eq 'listing') {
1.12 raeburn 521: my @standardnames = &Apache::loncommon::get_standard_codeitems();
522: my %local_to_standard;
523: if (ref($codetitles) eq 'ARRAY') {
524: for (my $i=0; $i<@{$codetitles}; $i++) {
525: $local_to_standard{$codetitles->[$i]} = $standardnames[$i];
526: }
527: }
1.6 raeburn 528: $jscript .= '
529: function setElements() {
530: ';
531: for (my $i=0; $i<@{$codetitles}-1; $i++) {
1.12 raeburn 532: my $item = $local_to_standard{$codetitles->[$i]};
533: if ($env{'form.'.$item} != -1) {
1.6 raeburn 534: $jscript .= '
1.12 raeburn 535: for (var j=0; j<document.'.$formname.'.'.$item.'.length; j++) {
536: if (document.'.$formname.'.'.$item.'[j].value == "'.$env{'form.'.$item}.'") {
537: document.'.$formname.'.'.$item.'.selectedIndex = j;
1.6 raeburn 538: }
539: }
540: ';
541: }
542: }
543: $jscript .= ' courseSet()'."\n";
1.12 raeburn 544: my $lastcodetitle = $local_to_standard{$codetitles->[-1]};
545: if ($env{'form.'.$lastcodetitle} != -1) {
1.6 raeburn 546: $jscript .= '
1.12 raeburn 547: for (var j=0; j<document.'.$formname.'.'.$lastcodetitle.'.length; j++) {
548: if (document.'.$formname.'.'.$lastcodetitle.'[j].value == "'.$env{'form.'.$lastcodetitle}.'") {
549: document.'.$formname.'.'.$lastcodetitle.'.selectedIndex = j;
1.6 raeburn 550: }
551: }
552: ';
553: }
554: $jscript .= '}';
555: }
556: }
557: }
558: }
559: return ($jscript,$totcodes,$numtitles,$lasttitle);
560: }
561:
562: sub build_instcode_selectors {
563: my ($numtitles,$lasttitle,$cat_items,$codetitles,$cat_titles,$cat_order) = @_;
564: my $output;
1.10 raeburn 565: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1.6 raeburn 566: if ($numtitles > 0) {
567: $output .= '<table><tr>';
568: for (my $k=0; $k<$lasttitle-1; $k++) {
569: my (@items,@unsorted);
570: if (ref($cat_items->{$codetitles->[$k]}) eq 'ARRAY') {
571: @unsorted = @{$cat_items->{$codetitles->[$k]}};
572: }
573: &sort_cats($k,$cat_order,$codetitles,\@unsorted,\@items);
574: my @longitems;
575: if (defined($cat_titles->{$codetitles->[$k]})) {
576: foreach my $item (@items) {
577: push(@longitems,$cat_titles->{$codetitles->[$k]}{$item});
578: }
579: } else {
580: @longitems = @items;
581: }
582: $output .= '<td align="center">'.$codetitles->[$k].'<br />'."\n".
1.15 bisitz 583: '<select name="'.$standardnames[$k].'" onchange="courseSet(this)"'.
1.9 raeburn 584: '>'."\n".'<option value="0">'.&mt('All').'</option>'."\n";
1.6 raeburn 585: for (my $i=0; $i<@items; $i++) {
586: if ($longitems[$i] eq '') {
587: $longitems[$i] = $items[$i];
588: }
589: $output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>';
590: }
591: $output .= '</select></td>';
592: }
593: $output .= '<td align="center">'.$codetitles->[$lasttitle-1].'<br />'."\n".
1.9 raeburn 594: '<select name="'.$standardnames[$lasttitle-1].'">'."\n".
1.6 raeburn 595: '<option value="0">'.&mt('All')."\n".
596: '</option>'."\n".'</select>'."\n".
597: '</td></tr></table>'."\n";
598: if ($numtitles > 4) {
599: $output .= '<br /><br />'.$codetitles->[$numtitles-1].'<br />'."\n".
1.9 raeburn 600: '<input type="text" name="'.$standardnames[$numtitles-1].
1.6 raeburn 601: '" /><br />'."\n";
602: }
603: $output .= '<br />';
604: }
605: return $output;
606: }
607:
1.16 raeburn 608: sub instcode_selectors {
609: my ($codedom,$formname,$officialjs,$codetitles) = @_;
610: my ($output,%cat_titles,%cat_order,%cat_items);
611: my ($jscript,$totcodes,$numtitles,$lasttitle) =
612: &instcode_selectors_data($codedom,$formname,\%cat_items,$codetitles,
613: \%cat_titles,\%cat_order,$officialjs);
614: if ($numtitles > 0) {
615: my $official = ' checked="checked" ';
616: my $unofficial = '';
617: if ($env{'form.official'} eq 'off') {
618: $unofficial = $official;
619: $official = '';
620: }
621: $output .= '<span class="LC_nobreak">'.&mt('Official course:').' <label>'.
622: '<input type="radio" name="official" value="on"'.$official.' />'.
623: &mt('Yes').'</label>'.(' 'x3).'<label>'.
624: '<input type="radio" name="official" value="off"'.$unofficial.
625: ' onclick="toggleOfficial();" />'.&mt('No').'</label></span><br />'.
626: &build_instcode_selectors($numtitles,$lasttitle,\%cat_items,$codetitles,
627: \%cat_titles,\%cat_order)."\n".
628: '<input type="hidden" name="numtitles" value="'.$numtitles.'" />'."\n".
629: '<input type="hidden" name="state" value="listing" />'."\n";
630: }
631: return ($output,$jscript,$numtitles);
632: }
633:
1.6 raeburn 634: sub recurse_options {
635: my ($currkey,$currlist,$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept) = @_;
636: if (ref($currlist) eq 'HASH') {
637: $level ++;
638: foreach my $key (sort(keys(%{$currlist}))) {
639: $$data[$level-1]= $key;
640: &recurse_options($key,$currlist->{$key},$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept);
641: }
642: } else {
643: $level --;
644: my @contents = split(/","/,$currlist);
645: foreach my $item (@contents) {
646: if (!grep(/^\Q$item\E$/,@{$cat_options->{$cat}})) {
647: push(@{$cat_options->{$cat}},$item);
648: }
649: if ($level == 3) {
650: if (!grep/^\Q$item\E$/,@{$by_year->{$data->[1]}->{$currkey}}) {
651: push(@{$by_year->{$data->[1]}->{$currkey}},$item);
652: }
653: if (!grep/^\Q$item\E$/,@{$by_sem->{$data->[2]}->{$currkey}}) {
654: push(@{$by_sem->{$data->[2]}->{$currkey}},$item);
655: }
656: if (!grep/^\Q$item\E$/,@{$by_dept->{$currkey}}) {
657: push(@{$by_dept->{$currkey}},$item);
658: }
659:
660: }
661: }
662: }
663: return $level;
664: }
665:
666: sub build_javascript {
667: my ($by_year,$by_sem,$by_dept,$cat_order,$codetitles) = @_;
668: my @unsorted = keys(%{$by_year});
669: my @sorted_yrs;
670: &sort_cats('0',$cat_order,$codetitles,\@unsorted,\@sorted_yrs); my $output = 'var idcse_by_yr_year = new Array("'.join('","',@sorted_yrs).'");'."\n".
671: 'var idcse_by_yr_dept = new Array('.scalar(@sorted_yrs).');'."\n".
672: 'var idcse_by_yr_num = new Array('.scalar(@sorted_yrs).');'."\n";
673: for (my $i=0; $i<@sorted_yrs; $i++) {
674: my $numkeys = keys(%{$by_year->{$sorted_yrs[$i]}});
675: $output .= " idcse_by_yr_num[$i] = new Array($numkeys);\n";
676: if (ref($by_year->{$sorted_yrs[$i]}) eq 'HASH') {
677: @unsorted = keys(%{$by_year->{$sorted_yrs[$i]}});
678: my @sorted_depts;
679: &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts);
680: $output .= qq| idcse_by_yr_dept[$i] = new Array ("|.join('","',@sorted_depts).'");'."\n";
681: for (my $j=0; $j<@sorted_depts; $j++) {
682: $output .= qq| idcse_by_yr_num[$i][$j] = new Array ("|;
683: $output .= join('","',sort(@{$by_year->{$sorted_yrs[$i]}->{$sorted_depts[$j]}})).'");'."\n";
684: }
685: }
686: }
687: @unsorted = keys(%{$by_sem});
688: my @sorted_sems;
689: &sort_cats('1',$cat_order,$codetitles,\@unsorted,\@sorted_sems);
690: $output .= 'idcse_by_sem_sems = new Array("'.join('","',@sorted_sems).'");'."\n".
691: 'idcse_by_sem_dept = new Array('.scalar(@sorted_sems).');'."\n".
692: 'idcse_by_sem_num = new Array('.scalar(@sorted_sems).');'."\n";
693: for (my $i=0; $i<@sorted_sems; $i++) {
694: my $numkeys = keys(%{$by_sem->{$sorted_sems[$i]}});
695: $output .= " idcse_by_sem_num[$i] = new Array($numkeys);\n";
696: if (ref($by_sem->{$sorted_sems[$i]}) eq 'HASH') {
697: @unsorted = keys(%{$by_sem->{$sorted_sems[$i]}});
698: my @sorted_depts;
699: &sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts);
700: $output .= qq| idcse_by_sem_dept[$i] = new Array("|.join('","',@sorted_depts).'");'."\n";
701: for (my $j=0; $j<@sorted_depts; $j++) {
702: $output .= qq| idcse_by_sem_num[$i][$j] = new Array ("|.join('","',sort(@{$by_sem->{$sorted_sems[$i]}->{$sorted_depts[$j]}})).'");'."\n";
703: }
704: }
705: }
706: @unsorted = keys(%{$by_dept});
707: my @sorted_deps;
708: &sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_deps);
709: $output .= 'idcse_by_dep = new Array('.scalar(@sorted_deps).');'."\n";
710: for (my $k=0; $k<@sorted_deps; $k++) {
711: $output .= qq| idcse_by_dep[$k] = new Array ("|.join('","',sort(@{$by_dept->{$sorted_deps[$k]}})).'");'."\n";
712: }
713: return $output;
714: }
715:
716: sub javascript_select_filler {
1.7 raeburn 717: my ($formname,$scripttext,$codetitles,$longtitles_str,$allidlist,$officialjs) = @_;
1.13 raeburn 718: my $all = &mt('All');
719: my $nocrs = &mt('No courses');
1.6 raeburn 720: my $output = <<END;
721:
1.7 raeburn 722: function courseSet(caller) {
1.6 raeburn 723: var longtitles = new Array ("$longtitles_str");
724: var valyr = document.$formname.Year.options[document.$formname.Year.selectedIndex].value
725: var valsem = document.$formname.Semester.options[document.$formname.Semester.selectedIndex].value
726: var valdept = document.$formname.Department.options[document.$formname.Department.selectedIndex].value
727: var valclass = document.$formname.Number.options[document.$formname.Number.selectedIndex].value
728: var idyears = new Array("$allidlist");
729: var idyr = -1;
730: var idsem = -1;
731: var iddept = -1;
732: document.$formname.Number.length = 0;
733:
734: $scripttext
735:
736: selYear = document.$formname.Year.selectedIndex-1;
737: selSemester = document.$formname.Semester.selectedIndex-1;
738: selDepartment = document.$formname.Department.selectedIndex-1;
739: if (selYear == -1) {
740: if (selSemester == -1) {
741: if (selDepartment > -1) {
1.13 raeburn 742: document.$formname.Number.options[0] = new Option('$all','0',false,false);
1.6 raeburn 743: for (var k=0; k<idcse_by_dep[selDepartment].length; k++) {
744: document.$formname.Number.options[k+1] = new Option(idcse_by_dep[selDepartment][k],idcse_by_dep[selDepartment][k],false,false);
745:
746: }
747: }
748: else {
1.13 raeburn 749: document.$formname.Number.options[0] = new Option('$all','0',true,true);
1.6 raeburn 750: }
751: }
752: else {
753: if (selDepartment > -1) {
754: for (var i=0; i<idcse_by_sem_sems.length; i++) {
755: if (idcse_by_sem_sems[i] == valsem) {
756: idsem = i;
757: }
758: }
759: if (idsem != -1) {
760: for (var i=0; i<idcse_by_sem_dept[idsem].length; i++) {
761: if (idcse_by_sem_dept[idsem][i] == valdept) {
762: iddept = i;
763: }
764: }
765: }
766: if (iddept != -1) {
1.13 raeburn 767: document.$formname.Number.options[0] = new Option('$all','0',false,false);
1.6 raeburn 768: for (var k=0; k<idcse_by_sem_num[idsem][iddept].length; k++) {
769: document.$formname.Number.options[k+1] = new Option(idcse_by_sem_num[idsem][iddept][k],idcse_by_sem_num[idsem][iddept][k],false,false);
770: }
771: }
772: else {
1.13 raeburn 773: document.$formname.Number.options[0] = new Option('$nocrs','0',true,true);
1.6 raeburn 774: }
775: }
776: else {
1.13 raeburn 777: document.$formname.Number.options[0] = new Option('$all','0',true,true);
1.6 raeburn 778: }
779: }
780: }
781: else {
782: if (selSemester == -1) {
783: if (selDepartment > -1) {
784: for (var i=0; i<idcse_by_yr_year.length; i++) {
785: if (idcse_by_yr_year[i] == valyr) {
786: idyr = i;
787: }
788: }
789: if (idyr != -1) {
790: for (var i=0; i<idcse_by_yr_dept[idyr].length; i++) {
791: if (idcse_by_yr_dept[idyr][i] == valdept) {
792: iddept = i;
793: }
794: }
795: }
796: if (iddept != -1) {
1.13 raeburn 797: document.$formname.Number.options[0] = new Option('$all','0',false,false);
1.6 raeburn 798: for (var k=0; k<idcse_by_yr_num[idyr][iddept].length; k++) {
799: document.$formname.Number.options[k+1] = new Option(idcse_by_yr_num[idyr][iddept][k],idcse_by_yr_num[idyr][iddept][k],false,false);
800: }
801: }
802: else {
1.13 raeburn 803: document.$formname.Number.options[0] = new Option('$nocrs','0',true,true);
1.6 raeburn 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 k=0; k<idyears.length; k++) {
813: if (idyears[k] == valyr) {
814: idyr = k;
815: }
816: }
817: if (idyr != -1) {
818: for (var k=0; k<idsems[idyr].length; k++) {
819: if (idsems[idyr][k] == valsem) {
820: idsem = k;
821: }
822: }
823: }
824: if (idsem != -1) {
825: for (var k=0; k<idcodes[idyr][idsem].length; k++) {
826: if (idcodes[idyr][idsem][k] == valdept) {
827: iddept = k;
828: }
829: }
830: }
831: if (iddept != -1) {
1.17 ! raeburn 832: document.$formname.Number.options[0] = new Option('$all','0',false,false);
1.6 raeburn 833: for (var i=0; i<idcourses[idyr][idsem][iddept].length; i++) {
834: var display = idcourses[idyr][idsem][iddept][i];
835: if (longtitles[3] == 1) {
836: if (idcourseslongs[idyr][idsem][iddept][i] != "") {
837: display = idcourseslongs[idyr][idsem][iddept][i]
838: }
839: }
840: document.$formname.Number.options[i+1] = new Option(display,idcourses[idyr][idsem][iddept][i],false,false)
841: }
842: }
843: else {
1.13 raeburn 844: document.$formname.Number.options[0] = new Option('$nocrs','0',true,true);
1.6 raeburn 845: }
846: }
847: else {
1.13 raeburn 848: document.$formname.Number.options[0] = new Option('$all','0',true,true);
1.6 raeburn 849: }
850: }
851: document.$formname.Number.selectedIndex = 0
852: }
1.7 raeburn 853: $officialjs
1.6 raeburn 854: }
855: END
856: return $output;
857: }
858:
859: sub instcode_search_str {
1.9 raeburn 860: my ($domain,$numtitles,$codetitles) = @_;
1.6 raeburn 861: my $instcode;
862: if (defined($numtitles) && $numtitles == 0) {
863: $instcode = '.+';
864: } else {
865: my (%codedefaults,@code_order);
866: my $defaults_result =
867: &Apache::lonnet::auto_instcode_defaults($domain,\%codedefaults,
868: \@code_order);
1.10 raeburn 869: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1.9 raeburn 870: my %local_to_standard;
871: if (ref($codetitles) eq 'ARRAY') {
872: for (my $i=0; $i<@{$codetitles}; $i++) {
873: $local_to_standard{$codetitles->[$i]} = $standardnames[$i];
874: }
875: }
1.6 raeburn 876: if ($defaults_result eq 'ok') {
877: $instcode ='^';
1.9 raeburn 878: foreach my $loctitle (@code_order) {
879: my $item = $local_to_standard{$loctitle};
880: if ($item ne '') {
881: if ($env{'form.'.$item} eq '0' ) {
1.12 raeburn 882: $instcode .= $codedefaults{$loctitle};
1.9 raeburn 883: } else {
884: $instcode .= $env{'form.'.$item};
885: }
1.6 raeburn 886: } else {
1.9 raeburn 887: $instcode .= '.+';
1.6 raeburn 888: }
889: }
890: $instcode .= '$';
891: } else {
892: $instcode = '.+';
893: }
894: }
895: return $instcode;
896: }
897:
1.10 raeburn 898: sub instcode_from_selectors {
1.14 raeburn 899: my ($cdom,$noregexps) = @_;
1.10 raeburn 900: my $instcode;
901: my $caller = 'global';
902: my (%coursecodes,%codes,@codetitles,%cat_titles,%cat_order,
903: %codedefaults,@code_order);
904: my $format_reply =
905: &Apache::lonnet::auto_instcode_format($caller,$cdom,\%coursecodes,
906: \%codes,\@codetitles,\%cat_titles,\%cat_order);
907: my $defaults_result =
908: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
909: \@code_order);
910: if (($defaults_result eq 'ok') && ($format_reply eq 'ok')) {
911: my @standardnames = &Apache::loncommon::get_standard_codeitems();
912: my %local_to_standard;
913: for (my $i=0; $i<@codetitles; $i++) {
914: $local_to_standard{$codetitles[$i]} = $standardnames[$i];
915: }
916: foreach my $loctitle (@code_order) {
917: my $category = $local_to_standard{$loctitle};
918: if ($category ne '') {
919: if ($env{'form.'.$category} eq '-1' ) {
1.14 raeburn 920: if ($noregexps) {
921: $instcode .= ' ';
922: } else {
923: $instcode .= $codedefaults{$category};
924: }
1.10 raeburn 925: } else {
926: $instcode .= $env{'form.'.$category};
927: }
928: } else {
929: $instcode .= '.+';
930: }
931: }
932: }
933: return $instcode;
1.9 raeburn 934: }
935:
1.1 raeburn 936: 1;
937:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>