Annotation of loncom/interface/courseclassifier.pm, revision 1.16
1.5 raeburn 1: # The LearningOnline Network with CAPA
2: # Utilities for classifying courses based on institutional code
3: #
1.16 ! raeburn 4: # $Id: courseclassifier.pm,v 1.15 2013/07/15 14:32:45 bisitz 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.1 raeburn 40: my %courses = &Apache::lonnet::courseiddump($codedom,'.',1,'.','.','.', undef,undef,'Course');
1.2 raeburn 41: foreach my $course (keys(%courses)) {
42: if (ref($courses{$course}) eq 'HASH') {
1.11 raeburn 43: if ($courses{$course}{'inst_code'} ne '') {
44: $$coursecodes{$course} = $courses{$course}{'inst_code'};
45: $totcodes ++;
46: }
1.1 raeburn 47: }
48: }
49: return $totcodes;
50: }
51:
52: sub sort_cats {
53: my ($num,$cat_order,$codetitles,$idsarrayref,$sorted) = @_;
54: my @unsorted = @{$idsarrayref};
55: if (defined($$cat_order{$$codetitles[$num]})) {
56: foreach my $item (@{$$cat_order{$$codetitles[$num]}}) {
57: if (grep/^\Q$item\E$/,@unsorted) {
1.12 raeburn 58: push(@{$sorted},$item);
1.1 raeburn 59: }
60: }
61: } else {
62: @{$sorted} = sort (@unsorted);
63: }
64: }
65:
66: sub recurse_list {
67: my ($cid,$codetitles,$codes,$num,$idarrays) = @_;
68: if ($num == 0) {
69: if (!grep/^$$codes{$cid}{$$codetitles[0]}$/,@{$$idarrays{$$codetitles[0]}}) {
70: push @{$$idarrays{$$codetitles[0]}}, $$codes{$cid}{$$codetitles[0]};
71: }
72: } elsif ($num == 1) {
73: if (defined($$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}})) {
74: if (!grep/^$$codes{$cid}{$$codetitles[1]}$/,@{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}}) {
75: push @{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}}, $$codes{$cid}{$$codetitles[1]};
76: }
77: } else {
78: @{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}} = ("$$codes{$cid}{$$codetitles[1]}");
79: }
80: } elsif ($num == 2) {
81: if (defined($$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}})) {
82: if (defined($$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
83: if (!grep/^$$codes{$cid}{$$codetitles[2]}$/,@{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}}) {
84: push @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}}, $$codes{$cid}{$$codetitles[2]};
85: }
86: } else {
87: @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ("$$codes{$cid}{$$codetitles[2]}"); }
88: } else {
89: %{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}} = ();
90: @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ("$$codes{$cid}{$$codetitles[2]}");
91: }
92: } elsif ($num == 3) {
93: if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}})) {
94: if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
95: if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}})) {
96: if (!grep/^$$codes{$cid}{$$codetitles[3]}$/,@{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}}) {
97: push @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}}, $$codes{$cid}{$$codetitles[3]};
98: }
99: } else {
100: @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
101: }
102: } else {
103: %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
104: @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
105: }
106: } else {
107: %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}} = ();
108: %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
109: @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
110: }
111: } elsif ($num == 4) {
112: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}})) {
113: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
114: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}})) {
115: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}})) {
116: 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]}}}) {
117: push @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}}, $$codes{$cid}{$$codetitles[4]};
118: }
119: } else {
120: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
121: }
122: } else {
123: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
124: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
125: }
126: } else {
127: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
1.4 raeburn 128: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
129: @{$$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 130: }
131: } else {
132: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}} = ();
133: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
134: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
135: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[3]}");
136: }
137: }
138: $num ++;
139: if ($num <@{$codetitles}) {
140: &recurse_list($cid,$codetitles,$codes,$num,$idarrays);
141: }
142: }
143:
144: sub build_code_selections {
145: my ($codes,$codetitles,$cat_titles,$cat_order,$idlist,$idnums,$idlist_titles) = @_;
146: my %idarrays = ();
147: for (my $i=1; $i<@{$codetitles}; $i++) {
148: %{$idarrays{$$codetitles[$i]}} = ();
149: }
150: foreach my $cid (sort keys %{$codes}) {
151: &recurse_list($cid,$codetitles,$codes,0,\%idarrays);
152: }
153: for (my $num=0; $num<@{$codetitles}; $num++) {
154: if ($num == 0) {
155: my @contents = ();
156: my @contents_titles = ();
157: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[0]}},\@contents);
158: if (defined($$cat_titles{$$codetitles[0]})) {
159: foreach (@contents) {
160: push @contents_titles, $$cat_titles{$$codetitles[0]}{$_};
161: }
162: }
163: $$idlist{$$codetitles[0]} = join('","',@contents);
164: $$idnums{$$codetitles[0]} = scalar(@contents);
165: if (defined($$cat_titles{$$codetitles[0]})) {
166: $$idlist_titles{$$codetitles[0]} = join('","',@contents_titles);
167: }
168: } elsif ($num == 1) {
169: %{$$idlist{$$codetitles[1]}} = ();
170: %{$$idlist_titles{$$codetitles[1]}} = ();
171: foreach my $key_a (keys %{$idarrays{$$codetitles[1]}}) {
172: my @sorted_a = ();
173: my @sorted_a_titles = ();
174: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[1]}{$key_a}},\@sorted_a);
175: if (defined($$cat_titles{$$codetitles[1]})) {
176: foreach (@sorted_a) {
177: push @sorted_a_titles, $$cat_titles{$$codetitles[1]}{$_};
178: }
179: }
180: $$idlist{$$codetitles[1]}{$key_a} = join('","',@sorted_a);
181: $$idnums{$$codetitles[1]}{$key_a} = scalar(@sorted_a);
182: if (defined($$cat_titles{$$codetitles[1]})) {
183: $$idlist_titles{$$codetitles[1]}{$key_a} = join('","',@sorted_a_titles);
184: }
185: }
186: } elsif ($num == 2) {
187: %{$$idlist{$$codetitles[2]}} = ();
188: %{$$idlist_titles{$$codetitles[2]}} = ();
189: foreach my $key_a (keys %{$idarrays{$$codetitles[2]}}) {
190: %{$$idlist{$$codetitles[2]}{$key_a}} = ();
191: %{$$idlist_titles{$$codetitles[2]}{$key_a}} = ();
192: foreach my $key_b (keys %{$idarrays{$$codetitles[2]}{$key_a}}) {
193: my @sorted_b = ();
194: my @sorted_b_titles = ();
195: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[2]}{$key_a}{$key_b}},\@sorted_b);
196: if (defined($$cat_titles{$$codetitles[2]})) {
197: foreach (@sorted_b) {
198: push @sorted_b_titles, $$cat_titles{$$codetitles[2]}{$_};
199: }
200: }
201: $$idlist{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_b);
202: $$idnums{$$codetitles[2]}{$key_a}{$key_b} = scalar(@sorted_b);
203: if (defined($$cat_titles{$$codetitles[2]})) {
204: $$idlist_titles{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_b_titles);
205: }
206: }
207: }
208: } elsif ($num == 3) {
209: %{$$idlist{$$codetitles[3]}} = ();
210: foreach my $key_a (keys %{$idarrays{$$codetitles[3]}}) {
211: %{$$idlist{$$codetitles[3]}{$key_a}} = ();
212: foreach my $key_b (keys %{$idarrays{$$codetitles[3]}{$key_a}}) {
213: %{$$idlist{$$codetitles[3]}{$key_a}{$key_b}} = ();
214: foreach my $key_c (keys %{$idarrays{$$codetitles[3]}{$key_a}{$key_b}}) {
215: my @sorted_c = ();
216: my @sorted_c_titles = ();
217: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[3]}{$key_a}{$key_b}{$key_c}},\@sorted_c);
218: if (defined($$cat_titles{$$codetitles[3]})) {
219: foreach (@sorted_c) {
220: push @sorted_c_titles, $$cat_titles{$$codetitles[3]}{$_};
221: }
222: }
223: $$idlist{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = join('","',@sorted_c);
224: $$idnums{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = scalar(@sorted_c);
225: if (defined($$cat_titles{$$codetitles[3]})) {
1.4 raeburn 226: $$idlist_titles{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = join('","',@sorted_c_titles);
1.1 raeburn 227: }
228: }
229: }
230: }
231: } elsif ($num == 4) {
232: %{$$idlist{$$codetitles[4]}} = ();
233: foreach my $key_a (keys %{$idarrays{$$codetitles[4]}}) {
234: %{$$idlist{$$codetitles[4]}{$key_a}} = ();
235: foreach my $key_b (keys %{$idarrays{$$codetitles[4]}{$key_a}}) {
236: %{$$idlist{$$codetitles[4]}{$key_a}{$key_b}} = ();
237: foreach my $key_c (keys %{$idarrays{$$codetitles[4]}{$key_a}{$key_b}}) {
238: %{$$idlist{$$codetitles[4]}{$key_a}{$key_b}{$key_c}} = ();
239: foreach my $key_d (keys %{$idarrays{$$codetitles[4]}{$key_a}{$key_b}{$key_c}}) {
240: my @sorted_d = ();
241: my @sorted_d_titles = ();
242: &sort_cats($num,$cat_order,$codetitles,$idarrays{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d},\@sorted_d);
243: if (defined($$cat_titles{$$codetitles[4]})) {
244: foreach (@sorted_d) {
245: push @sorted_d_titles, $$cat_titles{$$codetitles[4]}{$_};
246: }
247: }
248: $$idlist{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d} = join('","',@sorted_d);
249: $$idnums{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d} = scalar(@sorted_d);
1.4 raeburn 250: if (defined($$cat_titles{$$codetitles[4]})) {
251: $$idlist_titles{$$codetitles[3]}{$key_a}{$key_b}{$key_c}{$key_d} = join('","',@sorted_d_titles);
252: }
1.1 raeburn 253: }
254: }
255: }
256: }
257: }
258: }
259: }
260:
261: sub javascript_code_selections {
262: my ($formname,@codetitles) = @_;
263: my $numtitles = @codetitles;
1.10 raeburn 264: my %lt = &Apache::lonlocal::texthash(
265: Select => 'Select',
266: Pick => 'Pick',
267: );
1.1 raeburn 268: my $output = (<<END_OF_BLOCK);
269: var display = new Array($numtitles)
270: if (caller == "" || caller == "$codetitles[0]") {
271: if (caller == "") {
272: document.$formname.Year.length = 0
1.10 raeburn 273: document.$formname.Year.options[0] = new Option("$lt{'Select'}","-1",true,true)
1.1 raeburn 274: display[0] = new Array(idyears.length)
275: for (var i=0; i<idyears.length; i++) {
276: display[0][i] = idyears[i]
277: if (longtitles[0] == 1) {
278: if (idyearslongs[i] != "") {
279: display[0][i] = idyearslongs[i]
280: }
281: }
282: else {
283: if (idyearslongs[i] != "") {
284: display[0][i] = idyears[i]
285: }
286: }
287: document.$formname.Year.options[i+1] = new Option(display[0][i],idyears[i],false,false)
288: }
289: document.$formname.Year.selectedIndex = 0;
290: }
291: document.$formname.Semester.length = 0
292: document.$formname.Department.length = 0;
293: document.$formname.Number.length = 0
1.10 raeburn 294: document.$formname.Department.options[0] = new Option("<-$lt{'Pick'} $codetitles[1]","-1",true,true)
295: document.$formname.Number.options[0] = new Option("<-$lt{'Pick'} $codetitles[2]","-1",true,true)
1.1 raeburn 296: if (idyr == 0 || caller == "") {
1.10 raeburn 297: document.$formname.Semester.options[0] = new Option("<-$lt{'Pick'} $codetitles[0]","-1",true,true)
1.1 raeburn 298: }
299: else {
1.10 raeburn 300: document.$formname.Semester.options[0] = new Option("$lt{'Select'}","-1",true,true)
1.1 raeburn 301: display[1] = new Array(idsems[idyr-1].length)
302: for (var i=0; i<idsems[idyr-1].length; i++) {
303: display[1][i] = idsems[idyr-1][i]
304: if (longtitles[1] == 1) {
305: if (idsemslongs[idyr-1][i] != "") {
306: display[1][i] = idsemslongs[idyr-1][i]
307: }
308: }
309: document.$formname.Semester.options[i+1] = new Option(display[1][i],idsems[idyr-1][i],false,false)
310: }
311: }
312: document.$formname.Semester.selectedIndex = 0;
313: }
314: if (caller == "$codetitles[1]") {
315: document.$formname.Department.length = 0
316: document.$formname.Number.length = 0
317: document.$formname.Number.options[0] = new Option("<-Pick $codetitles[2]","-1",true,true)
318: if (idsem == 0) {
1.10 raeburn 319: document.$formname.Department.options[0] = new Option("<-$lt{'Pick'} $codetitles[1]","-1",true,true)
1.1 raeburn 320: }
321: else {
1.10 raeburn 322: document.$formname.Department.options[0] = new Option("$lt{'Select'}","-1",true,true)
1.1 raeburn 323: display[2] = new Array(idcodes[idyr-1][idsem-1].length)
324: for (var i=0; i<idcodes[idyr-1][idsem-1].length; i++) {
325: display[2][i] = idcodes[idyr-1][idsem-1][i]
326: if (longtitles[2] == 1) {
327: if (idcodeslongs[idyr-1][idsem-1][i] != "") {
328: display[2][i] = idcodeslongs[idyr-1][idsem-1][i]
329: }
330: }
331: document.$formname.Department.options[i+1] = new Option(display[2][i],idcodes[idyr-1][idsem-1][i],false,false)
332: }
333: }
334: document.$formname.Department.selectedIndex = 0
335: }
336: if (caller == "$codetitles[2]") {
337: document.$formname.Number.length = 0
338: if (iddept == 0) {
1.10 raeburn 339: document.$formname.Number.options[0] = new Option("<-$lt{'Pick'} $codetitles[2]","-1",true,true)
1.1 raeburn 340: }
341: else {
342: document.$formname.Number.options[0] = new Option("Select","-1",true,true)
343: display[3] = new Array (idcourses[idyr-1][idsem-1][iddept-1].length)
344: for (var i=0; i<idcourses[idyr-1][idsem-1][iddept-1].length; i++) {
345: display[3][i] = idcourses[idyr-1][idsem-1][iddept-1][i]
346: if (longtitles[3] == 1) {
347: if (idcourseslongs[idyr-1][idsem-1][iddept-1][i] != "") {
348: display[3][i] = idcourseslongs[idyr-1][idsem-1][iddept-1][i]
349: }
350: }
351: document.$formname.Number.options[i+1] = new Option(display[3][i],idcourses[idyr-1][idsem-1][iddept-1][i],false,false)
352: }
353: }
354: document.$formname.Number.selectedIndex = 0
355: }
356: }
357:
358: function initialize_codes() {
359: courseSet();
360: return;
361: }
362: END_OF_BLOCK
363: }
364:
365:
366: sub javascript_definitions {
367: my ($codetitles,$idlist,$idlist_titles,$idnums,$cat_titles) = @_;
368: my $numtitles = @{$codetitles};
369: my $longtitles = [];
370: for (my $i=0; $i<$numtitles; $i++) {
371: if (defined($cat_titles->{$codetitles->[$i]})) {
372: $longtitles->[$i] = 1;
373: } else {
374: $longtitles->[$i] = 0;
375: }
376: }
377: my $scripttext;
378: if ($longtitles->[0]) {
379: $scripttext =
380: qq| var idyearslongs = new Array("$idlist_titles->{$codetitles->[0]}")\n|;
381: }
382: $scripttext .=
383: " var idsems = new Array ($idnums->{$codetitles->[0]})\n";
384: if ($longtitles->[1]) {
385: $scripttext .=
386: " var idsemslongs = new Array ($idnums->{$codetitles->[0]})\n"; }
387: $scripttext .=
388: " var idcodes = new Array ($idnums->{$codetitles->[0]})\n";
389: if ($longtitles->[2]) {
390: $scripttext .=
391: " var idcodeslongs = new Array ($idnums->{$codetitles->[0]})\n";
392: }
393: $scripttext .=
394: " var idcourses = new Array ($idnums->{$codetitles->[0]})\n";
395: if ($longtitles->[3]) {
396: $scripttext .=
397: " var idcourseslongs = new Array ($idnums->{$codetitles->[0]})\n";
398: }
399: my @sort_a = split/","/,$idlist->{$codetitles->[0]};
400: for (my $j=0; $j<@sort_a; $j++) {
401: $scripttext .= qq| idsems[$j] = new Array("$idlist->{$codetitles->[1]}{$sort_a[$j]}")\n|;
402: if ($longtitles->[1]) {
403: $scripttext .= qq| idsemslongs[$j] = new Array("$idlist_titles->{$codetitles->[1]}{$sort_a[$j]}")\n|;
404: }
405: $scripttext .= qq| idcodes[$j] = new Array($idnums->{$codetitles->[1]}{$sort_a[$j]})\n|;
406: if ($longtitles->[2]) {
407: $scripttext .= qq| idcodeslongs[$j] = new Array($idnums->{$codetitles->[1]}{$sort_a[$j]})\n|;
408: }
409: $scripttext .= qq| idcourses[$j] = new Array($idnums->{$codetitles->[1]}{$sort_a[$j]})\n|;
410: if ($longtitles->[3]) {
411: $scripttext .= qq| idcourseslongs[$j] = new Array($idnums->{$codetitles->[1]}{$sort_a[$j]})\n|;
412: }
413: my @sort_b = split/","/,$idlist->{$codetitles->[1]}{$sort_a[$j]};
414: for (my $k=0; $k<@sort_b; $k++) {
415: my $idcode_entry = $idlist->{$codetitles->[2]}{$sort_a[$j]}{$sort_b[$k]};
416: $scripttext .= qq| idcodes[$j][$k] = new Array("$idcode_entry")\n|;
417: if ($longtitles->[2]) {
418: my $idcodelong_entry = $idlist_titles->{$codetitles->[2]}{$sort_a[$j]}{$sort_b[$k]};
419: $scripttext .= qq| idcodeslongs[$j][$k] = new Array("$idcodelong_entry")\n|;
420: }
421: $scripttext .= qq| idcourses[$j][$k] = new Array($idnums->{$codetitles->[2]}{$sort_a[$j]}{$sort_b[$k]})\n|;
422: if ($longtitles->[3]) {
423: $scripttext .= qq| idcourseslongs[$j][$k] = new Array($idnums->{$codetitles->[2]}{$sort_a[$j]}{$sort_b[$k]})\n|;
424: }
425: my @sort_c = split/","/,$idlist->{$codetitles->[2]}{$sort_a[$j]}{$sort_b[$k]};
426: for (my $l=0; $l<@sort_c; $l++) {
427: my $idcourse_entry = $idlist->{$codetitles->[3]}{$sort_a[$j]}{$sort_b[$k]}{$sort_c[$l]};
428: $scripttext .= qq| idcourses[$j][$k][$l] = new Array("$idcourse_entry")\n|;
429: if ($longtitles->[3]) {
430: my $idcourselong_entry = $idlist_titles->{$codetitles->[3]}{$sort_a[$j]}{$sort_b[$k]}{$sort_c[$l]};
431: $scripttext .= qq| idcourseslongs[$j][$k][$l] = new Array("$idcourselong_entry")\n|;
432: }
433: }
434: }
435: }
436: return ($scripttext,$longtitles);
437: }
438:
439: sub courseset_js_start {
440: my ($formname,$longtitles_str,$allidlist) = @_;
441: my $output = <<END;
1.6 raeburn 442:
1.1 raeburn 443: function courseSet(caller) {
444: var longtitles = new Array ("$longtitles_str");
445: var idyr = document.$formname.Year.selectedIndex
446: var idsem = document.$formname.Semester.selectedIndex
447: var iddept = document.$formname.Department.selectedIndex
448: var idclass = document.$formname.Number.selectedIndex
449: var idyears = new Array("$allidlist");
450: END
451: return $output;
452: }
453:
1.6 raeburn 454: sub instcode_selectors_data {
1.7 raeburn 455: my ($codedom,$formname,$cat_items,$codetitles,$cat_titles,$cat_order,$officialjs) = @_;
1.6 raeburn 456: my ($jscript,%coursecodes,%codes,%idlist,%idnums,%idlist_titles,
457: %by_year,%by_sem,%by_dept);
458: my ($numtitles,$lasttitle);
459: my $caller = 'global';
460: my $totcodes = &retrieve_instcodes(\%coursecodes,$codedom);
461: if ($totcodes > 0) {
462: if (&Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,
463: \%codes,$codetitles,$cat_titles,$cat_order) eq 'ok') {
464: &build_code_selections(\%codes,$codetitles,$cat_titles,$cat_order,
465: \%idlist,\%idnums,\%idlist_titles);
466: my ($scripttext,$longtitles) =
467: &javascript_definitions($codetitles,\%idlist,\%idlist_titles,
468: \%idnums,$cat_titles);
469: my $longtitles_str = join('","',@{$longtitles});
470: my $allidlist = $idlist{$codetitles->[0]};
471: $numtitles = @{$codetitles};
472: $lasttitle = $numtitles;
473: if ($numtitles > 4) {
474: $lasttitle = 4;
475: }
476: if ($numtitles == 0) {
477: if (!defined($env{'form.state'})) {
478: $env{'form.state'} = 'listing';
479: }
480: } else {
481: my @data = ('top');
482: for (my $k=0; $k<$lasttitle; $k++) {
483: my $cat = $codetitles->[$k];
484: my $level = 1;
485: $level = &recurse_options($codetitles->[$k],$idlist{$codetitles->[$k]},$level,$cat,$cat_items,\@data,\%by_year,\%by_sem,\%by_dept);
486: }
487: $scripttext .= &build_javascript(\%by_year,\%by_sem,\%by_dept,$cat_order,$codetitles);
1.7 raeburn 488: if ($officialjs) {
489: $jscript .= '
490:
491: function toggleOfficial() {';
492: for (my $i=0; $i<@{$codetitles}-1; $i++) {
493: $jscript .= '
494: document.'.$formname.'.'.$codetitles->[$i].'.selectedIndex = 0;';
495: }
496: $jscript .= '
497: }
498:
499: function setOfficial(caller) {
1.8 raeburn 500: if (typeof(caller) != "undefined") {
501: if (caller.options[caller.selectedIndex].value != 0) {
502: if (document.'.$formname.'.official.length > 0) {
503: for (var j=0; j<document.'.$formname.'.official.length; j++) {
504: if (document.'.$formname.'.official[j].value == "on") {
505: document.'.$formname.'.official[j].checked = true;
506: }
507: }
1.7 raeburn 508: }
509: }
510: }
511: return;
512: }
513:
514: ';
515:
516: $officialjs = 'setOfficial(caller);';
517: }
518: $jscript .= &javascript_select_filler($formname,$scripttext,$codetitles,$longtitles_str,$allidlist,$officialjs);
1.6 raeburn 519: if ($env{'form.state'} eq 'listing') {
1.12 raeburn 520: my @standardnames = &Apache::loncommon::get_standard_codeitems();
521: my %local_to_standard;
522: if (ref($codetitles) eq 'ARRAY') {
523: for (my $i=0; $i<@{$codetitles}; $i++) {
524: $local_to_standard{$codetitles->[$i]} = $standardnames[$i];
525: }
526: }
1.6 raeburn 527: $jscript .= '
528: function setElements() {
529: ';
530: for (my $i=0; $i<@{$codetitles}-1; $i++) {
1.12 raeburn 531: my $item = $local_to_standard{$codetitles->[$i]};
532: if ($env{'form.'.$item} != -1) {
1.6 raeburn 533: $jscript .= '
1.12 raeburn 534: for (var j=0; j<document.'.$formname.'.'.$item.'.length; j++) {
535: if (document.'.$formname.'.'.$item.'[j].value == "'.$env{'form.'.$item}.'") {
536: document.'.$formname.'.'.$item.'.selectedIndex = j;
1.6 raeburn 537: }
538: }
539: ';
540: }
541: }
542: $jscript .= ' courseSet()'."\n";
1.12 raeburn 543: my $lastcodetitle = $local_to_standard{$codetitles->[-1]};
544: if ($env{'form.'.$lastcodetitle} != -1) {
1.6 raeburn 545: $jscript .= '
1.12 raeburn 546: for (var j=0; j<document.'.$formname.'.'.$lastcodetitle.'.length; j++) {
547: if (document.'.$formname.'.'.$lastcodetitle.'[j].value == "'.$env{'form.'.$lastcodetitle}.'") {
548: document.'.$formname.'.'.$lastcodetitle.'.selectedIndex = j;
1.6 raeburn 549: }
550: }
551: ';
552: }
553: $jscript .= '}';
554: }
555: }
556: }
557: }
558: return ($jscript,$totcodes,$numtitles,$lasttitle);
559: }
560:
561: sub build_instcode_selectors {
562: my ($numtitles,$lasttitle,$cat_items,$codetitles,$cat_titles,$cat_order) = @_;
563: my $output;
1.10 raeburn 564: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1.6 raeburn 565: if ($numtitles > 0) {
566: $output .= '<table><tr>';
567: for (my $k=0; $k<$lasttitle-1; $k++) {
568: my (@items,@unsorted);
569: if (ref($cat_items->{$codetitles->[$k]}) eq 'ARRAY') {
570: @unsorted = @{$cat_items->{$codetitles->[$k]}};
571: }
572: &sort_cats($k,$cat_order,$codetitles,\@unsorted,\@items);
573: my @longitems;
574: if (defined($cat_titles->{$codetitles->[$k]})) {
575: foreach my $item (@items) {
576: push(@longitems,$cat_titles->{$codetitles->[$k]}{$item});
577: }
578: } else {
579: @longitems = @items;
580: }
581: $output .= '<td align="center">'.$codetitles->[$k].'<br />'."\n".
1.15 bisitz 582: '<select name="'.$standardnames[$k].'" onchange="courseSet(this)"'.
1.9 raeburn 583: '>'."\n".'<option value="0">'.&mt('All').'</option>'."\n";
1.6 raeburn 584: for (my $i=0; $i<@items; $i++) {
585: if ($longitems[$i] eq '') {
586: $longitems[$i] = $items[$i];
587: }
588: $output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>';
589: }
590: $output .= '</select></td>';
591: }
592: $output .= '<td align="center">'.$codetitles->[$lasttitle-1].'<br />'."\n".
1.9 raeburn 593: '<select name="'.$standardnames[$lasttitle-1].'">'."\n".
1.6 raeburn 594: '<option value="0">'.&mt('All')."\n".
595: '</option>'."\n".'</select>'."\n".
596: '</td></tr></table>'."\n";
597: if ($numtitles > 4) {
598: $output .= '<br /><br />'.$codetitles->[$numtitles-1].'<br />'."\n".
1.9 raeburn 599: '<input type="text" name="'.$standardnames[$numtitles-1].
1.6 raeburn 600: '" /><br />'."\n";
601: }
602: $output .= '<br />';
603: }
604: return $output;
605: }
606:
1.16 ! raeburn 607: sub instcode_selectors {
! 608: my ($codedom,$formname,$officialjs,$codetitles) = @_;
! 609: my ($output,%cat_titles,%cat_order,%cat_items);
! 610: my ($jscript,$totcodes,$numtitles,$lasttitle) =
! 611: &instcode_selectors_data($codedom,$formname,\%cat_items,$codetitles,
! 612: \%cat_titles,\%cat_order,$officialjs);
! 613: if ($numtitles > 0) {
! 614: my $official = ' checked="checked" ';
! 615: my $unofficial = '';
! 616: if ($env{'form.official'} eq 'off') {
! 617: $unofficial = $official;
! 618: $official = '';
! 619: }
! 620: $output .= '<span class="LC_nobreak">'.&mt('Official course:').' <label>'.
! 621: '<input type="radio" name="official" value="on"'.$official.' />'.
! 622: &mt('Yes').'</label>'.(' 'x3).'<label>'.
! 623: '<input type="radio" name="official" value="off"'.$unofficial.
! 624: ' onclick="toggleOfficial();" />'.&mt('No').'</label></span><br />'.
! 625: &build_instcode_selectors($numtitles,$lasttitle,\%cat_items,$codetitles,
! 626: \%cat_titles,\%cat_order)."\n".
! 627: '<input type="hidden" name="numtitles" value="'.$numtitles.'" />'."\n".
! 628: '<input type="hidden" name="state" value="listing" />'."\n";
! 629: }
! 630: return ($output,$jscript,$numtitles);
! 631: }
! 632:
1.6 raeburn 633: sub recurse_options {
634: my ($currkey,$currlist,$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept) = @_;
635: if (ref($currlist) eq 'HASH') {
636: $level ++;
637: foreach my $key (sort(keys(%{$currlist}))) {
638: $$data[$level-1]= $key;
639: &recurse_options($key,$currlist->{$key},$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept);
640: }
641: } else {
642: $level --;
643: my @contents = split(/","/,$currlist);
644: foreach my $item (@contents) {
645: if (!grep(/^\Q$item\E$/,@{$cat_options->{$cat}})) {
646: push(@{$cat_options->{$cat}},$item);
647: }
648: if ($level == 3) {
649: if (!grep/^\Q$item\E$/,@{$by_year->{$data->[1]}->{$currkey}}) {
650: push(@{$by_year->{$data->[1]}->{$currkey}},$item);
651: }
652: if (!grep/^\Q$item\E$/,@{$by_sem->{$data->[2]}->{$currkey}}) {
653: push(@{$by_sem->{$data->[2]}->{$currkey}},$item);
654: }
655: if (!grep/^\Q$item\E$/,@{$by_dept->{$currkey}}) {
656: push(@{$by_dept->{$currkey}},$item);
657: }
658:
659: }
660: }
661: }
662: return $level;
663: }
664:
665: sub build_javascript {
666: my ($by_year,$by_sem,$by_dept,$cat_order,$codetitles) = @_;
667: my @unsorted = keys(%{$by_year});
668: my @sorted_yrs;
669: &sort_cats('0',$cat_order,$codetitles,\@unsorted,\@sorted_yrs); my $output = 'var idcse_by_yr_year = new Array("'.join('","',@sorted_yrs).'");'."\n".
670: 'var idcse_by_yr_dept = new Array('.scalar(@sorted_yrs).');'."\n".
671: 'var idcse_by_yr_num = new Array('.scalar(@sorted_yrs).');'."\n";
672: for (my $i=0; $i<@sorted_yrs; $i++) {
673: my $numkeys = keys(%{$by_year->{$sorted_yrs[$i]}});
674: $output .= " idcse_by_yr_num[$i] = new Array($numkeys);\n";
675: if (ref($by_year->{$sorted_yrs[$i]}) eq 'HASH') {
676: @unsorted = keys(%{$by_year->{$sorted_yrs[$i]}});
677: my @sorted_depts;
678: &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts);
679: $output .= qq| idcse_by_yr_dept[$i] = new Array ("|.join('","',@sorted_depts).'");'."\n";
680: for (my $j=0; $j<@sorted_depts; $j++) {
681: $output .= qq| idcse_by_yr_num[$i][$j] = new Array ("|;
682: $output .= join('","',sort(@{$by_year->{$sorted_yrs[$i]}->{$sorted_depts[$j]}})).'");'."\n";
683: }
684: }
685: }
686: @unsorted = keys(%{$by_sem});
687: my @sorted_sems;
688: &sort_cats('1',$cat_order,$codetitles,\@unsorted,\@sorted_sems);
689: $output .= 'idcse_by_sem_sems = new Array("'.join('","',@sorted_sems).'");'."\n".
690: 'idcse_by_sem_dept = new Array('.scalar(@sorted_sems).');'."\n".
691: 'idcse_by_sem_num = new Array('.scalar(@sorted_sems).');'."\n";
692: for (my $i=0; $i<@sorted_sems; $i++) {
693: my $numkeys = keys(%{$by_sem->{$sorted_sems[$i]}});
694: $output .= " idcse_by_sem_num[$i] = new Array($numkeys);\n";
695: if (ref($by_sem->{$sorted_sems[$i]}) eq 'HASH') {
696: @unsorted = keys(%{$by_sem->{$sorted_sems[$i]}});
697: my @sorted_depts;
698: &sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts);
699: $output .= qq| idcse_by_sem_dept[$i] = new Array("|.join('","',@sorted_depts).'");'."\n";
700: for (my $j=0; $j<@sorted_depts; $j++) {
701: $output .= qq| idcse_by_sem_num[$i][$j] = new Array ("|.join('","',sort(@{$by_sem->{$sorted_sems[$i]}->{$sorted_depts[$j]}})).'");'."\n";
702: }
703: }
704: }
705: @unsorted = keys(%{$by_dept});
706: my @sorted_deps;
707: &sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_deps);
708: $output .= 'idcse_by_dep = new Array('.scalar(@sorted_deps).');'."\n";
709: for (my $k=0; $k<@sorted_deps; $k++) {
710: $output .= qq| idcse_by_dep[$k] = new Array ("|.join('","',sort(@{$by_dept->{$sorted_deps[$k]}})).'");'."\n";
711: }
712: return $output;
713: }
714:
715: sub javascript_select_filler {
1.7 raeburn 716: my ($formname,$scripttext,$codetitles,$longtitles_str,$allidlist,$officialjs) = @_;
1.13 raeburn 717: my $all = &mt('All');
718: my $nocrs = &mt('No courses');
1.6 raeburn 719: my $output = <<END;
720:
1.7 raeburn 721: function courseSet(caller) {
1.6 raeburn 722: var longtitles = new Array ("$longtitles_str");
723: var valyr = document.$formname.Year.options[document.$formname.Year.selectedIndex].value
724: var valsem = document.$formname.Semester.options[document.$formname.Semester.selectedIndex].value
725: var valdept = document.$formname.Department.options[document.$formname.Department.selectedIndex].value
726: var valclass = document.$formname.Number.options[document.$formname.Number.selectedIndex].value
727: var idyears = new Array("$allidlist");
728: var idyr = -1;
729: var idsem = -1;
730: var iddept = -1;
731: document.$formname.Number.length = 0;
732:
733: $scripttext
734:
735: selYear = document.$formname.Year.selectedIndex-1;
736: selSemester = document.$formname.Semester.selectedIndex-1;
737: selDepartment = document.$formname.Department.selectedIndex-1;
738: if (selYear == -1) {
739: if (selSemester == -1) {
740: if (selDepartment > -1) {
1.13 raeburn 741: document.$formname.Number.options[0] = new Option('$all','0',false,false);
1.6 raeburn 742: for (var k=0; k<idcse_by_dep[selDepartment].length; k++) {
743: document.$formname.Number.options[k+1] = new Option(idcse_by_dep[selDepartment][k],idcse_by_dep[selDepartment][k],false,false);
744:
745: }
746: }
747: else {
1.13 raeburn 748: document.$formname.Number.options[0] = new Option('$all','0',true,true);
1.6 raeburn 749: }
750: }
751: else {
752: if (selDepartment > -1) {
753: for (var i=0; i<idcse_by_sem_sems.length; i++) {
754: if (idcse_by_sem_sems[i] == valsem) {
755: idsem = i;
756: }
757: }
758: if (idsem != -1) {
759: for (var i=0; i<idcse_by_sem_dept[idsem].length; i++) {
760: if (idcse_by_sem_dept[idsem][i] == valdept) {
761: iddept = i;
762: }
763: }
764: }
765: if (iddept != -1) {
1.13 raeburn 766: document.$formname.Number.options[0] = new Option('$all','0',false,false);
1.6 raeburn 767: for (var k=0; k<idcse_by_sem_num[idsem][iddept].length; k++) {
768: document.$formname.Number.options[k+1] = new Option(idcse_by_sem_num[idsem][iddept][k],idcse_by_sem_num[idsem][iddept][k],false,false);
769: }
770: }
771: else {
1.13 raeburn 772: document.$formname.Number.options[0] = new Option('$nocrs','0',true,true);
1.6 raeburn 773: }
774: }
775: else {
1.13 raeburn 776: document.$formname.Number.options[0] = new Option('$all','0',true,true);
1.6 raeburn 777: }
778: }
779: }
780: else {
781: if (selSemester == -1) {
782: if (selDepartment > -1) {
783: for (var i=0; i<idcse_by_yr_year.length; i++) {
784: if (idcse_by_yr_year[i] == valyr) {
785: idyr = i;
786: }
787: }
788: if (idyr != -1) {
789: for (var i=0; i<idcse_by_yr_dept[idyr].length; i++) {
790: if (idcse_by_yr_dept[idyr][i] == valdept) {
791: iddept = i;
792: }
793: }
794: }
795: if (iddept != -1) {
1.13 raeburn 796: document.$formname.Number.options[0] = new Option('$all','0',false,false);
1.6 raeburn 797: for (var k=0; k<idcse_by_yr_num[idyr][iddept].length; k++) {
798: document.$formname.Number.options[k+1] = new Option(idcse_by_yr_num[idyr][iddept][k],idcse_by_yr_num[idyr][iddept][k],false,false);
799: }
800: }
801: else {
1.13 raeburn 802: document.$formname.Number.options[0] = new Option('$nocrs','0',true,true);
1.6 raeburn 803: }
804: }
805: else {
1.13 raeburn 806: document.$formname.Number.options[0] = new Option('$all','0',true,true);
1.6 raeburn 807: }
808: }
809: else {
810: if (selDepartment > -1) {
811: for (var k=0; k<idyears.length; k++) {
812: if (idyears[k] == valyr) {
813: idyr = k;
814: }
815: }
816: if (idyr != -1) {
817: for (var k=0; k<idsems[idyr].length; k++) {
818: if (idsems[idyr][k] == valsem) {
819: idsem = k;
820: }
821: }
822: }
823: if (idsem != -1) {
824: for (var k=0; k<idcodes[idyr][idsem].length; k++) {
825: if (idcodes[idyr][idsem][k] == valdept) {
826: iddept = k;
827: }
828: }
829: }
830: if (iddept != -1) {
1.13 raeburn 831: document.$formname.Number.options[0] = new Option('$all','0',false,false);
1.6 raeburn 832: for (var i=0; i<idcourses[idyr][idsem][iddept].length; i++) {
833: var display = idcourses[idyr][idsem][iddept][i];
834: if (longtitles[3] == 1) {
835: if (idcourseslongs[idyr][idsem][iddept][i] != "") {
836: display = idcourseslongs[idyr][idsem][iddept][i]
837: }
838: }
839: document.$formname.Number.options[i+1] = new Option(display,idcourses[idyr][idsem][iddept][i],false,false)
840: }
841: }
842: else {
1.13 raeburn 843: document.$formname.Number.options[0] = new Option('$nocrs','0',true,true);
1.6 raeburn 844: }
845: }
846: else {
1.13 raeburn 847: document.$formname.Number.options[0] = new Option('$all','0',true,true);
1.6 raeburn 848: }
849: }
850: document.$formname.Number.selectedIndex = 0
851: }
1.7 raeburn 852: $officialjs
1.6 raeburn 853: }
854: END
855: return $output;
856: }
857:
858: sub instcode_search_str {
1.9 raeburn 859: my ($domain,$numtitles,$codetitles) = @_;
1.6 raeburn 860: my $instcode;
861: if (defined($numtitles) && $numtitles == 0) {
862: $instcode = '.+';
863: } else {
864: my (%codedefaults,@code_order);
865: my $defaults_result =
866: &Apache::lonnet::auto_instcode_defaults($domain,\%codedefaults,
867: \@code_order);
1.10 raeburn 868: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1.9 raeburn 869: my %local_to_standard;
870: if (ref($codetitles) eq 'ARRAY') {
871: for (my $i=0; $i<@{$codetitles}; $i++) {
872: $local_to_standard{$codetitles->[$i]} = $standardnames[$i];
873: }
874: }
1.6 raeburn 875: if ($defaults_result eq 'ok') {
876: $instcode ='^';
1.9 raeburn 877: foreach my $loctitle (@code_order) {
878: my $item = $local_to_standard{$loctitle};
879: if ($item ne '') {
880: if ($env{'form.'.$item} eq '0' ) {
1.12 raeburn 881: $instcode .= $codedefaults{$loctitle};
1.9 raeburn 882: } else {
883: $instcode .= $env{'form.'.$item};
884: }
1.6 raeburn 885: } else {
1.9 raeburn 886: $instcode .= '.+';
1.6 raeburn 887: }
888: }
889: $instcode .= '$';
890: } else {
891: $instcode = '.+';
892: }
893: }
894: return $instcode;
895: }
896:
1.10 raeburn 897: sub instcode_from_selectors {
1.14 raeburn 898: my ($cdom,$noregexps) = @_;
1.10 raeburn 899: my $instcode;
900: my $caller = 'global';
901: my (%coursecodes,%codes,@codetitles,%cat_titles,%cat_order,
902: %codedefaults,@code_order);
903: my $format_reply =
904: &Apache::lonnet::auto_instcode_format($caller,$cdom,\%coursecodes,
905: \%codes,\@codetitles,\%cat_titles,\%cat_order);
906: my $defaults_result =
907: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
908: \@code_order);
909: if (($defaults_result eq 'ok') && ($format_reply eq 'ok')) {
910: my @standardnames = &Apache::loncommon::get_standard_codeitems();
911: my %local_to_standard;
912: for (my $i=0; $i<@codetitles; $i++) {
913: $local_to_standard{$codetitles[$i]} = $standardnames[$i];
914: }
915: foreach my $loctitle (@code_order) {
916: my $category = $local_to_standard{$loctitle};
917: if ($category ne '') {
918: if ($env{'form.'.$category} eq '-1' ) {
1.14 raeburn 919: if ($noregexps) {
920: $instcode .= ' ';
921: } else {
922: $instcode .= $codedefaults{$category};
923: }
1.10 raeburn 924: } else {
925: $instcode .= $env{'form.'.$category};
926: }
927: } else {
928: $instcode .= '.+';
929: }
930: }
931: }
932: return $instcode;
1.9 raeburn 933: }
934:
1.1 raeburn 935: 1;
936:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>