File:
[LON-CAPA] /
loncom /
interface /
coursecatalog.pm
Revision
1.6:
download - view:
text,
annotated -
select for diffs
Thu Oct 12 23:15:33 2006 UTC (17 years, 10 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
Using routines from courseclassifier instead of lonsupportreq. All ipossible values are now displayed in select boxes for Year, Semester and Department. Options available in "Number" select box are set dynamically if a specific Department is selected. Choices will vary depending on current selections for Year and Semester.
1: #
2: # Copyright Michigan State University Board of Trustees
3: #
4: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
5: #
6: # LON-CAPA is free software; you can redistribute it and/or modify
7: # it under the terms of the GNU General Public License as published by
8: # the Free Software Foundation; either version 2 of the License, or
9: # (at your option) any later version.
10: #
11: # LON-CAPA is distributed in the hope that it will be useful,
12: # but WITHOUT ANY WARRANTY; without even the implied warranty of
13: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: # GNU General Public License for more details.
15: #
16: # You should have received a copy of the GNU General Public License
17: # along with LON-CAPA; if not, write to the Free Software
18: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: #
20: # /home/httpd/html/adm/gpl.txt
21: #
22: # http://www.lon-capa.org/
23: #
24:
25: package Apache::coursecatalog;
26:
27: use strict;
28: use lib qw(/home/httpd/lib/perl);
29: use Apache::Constants qw(:common);
30: use Apache::loncommon;
31: use Apache::lonnet;
32: use Apache::lonlocal;
33: use Apache::courseclassifier;
34: use Apache::lonacc;
35: use lib '/home/httpd/lib/perl/';
36: use LONCAPA;
37:
38: sub handler {
39: my ($r) = @_;
40: &Apache::loncommon::content_type($r,'text/html');
41: $r->send_http_header;
42: if ($r->header_only) {
43: return OK;
44: }
45: &Apache::lonacc::get_posted_cgi($r);
46: &Apache::lonlocal::get_language_handle($r);
47: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['sortby']);
48: my $codedom = $Apache::lonnet::perlvar{'lonDefDomain'};
49: my %coursecodes = ();
50: my %codes = ();
51: my @codetitles = ();
52: my %cat_titles = ();
53: my %cat_order = ();
54: my %idlist = ();
55: my %idnums = ();
56: my %idlist_titles = ();
57: my %by_year;
58: my %by_sem;
59: my %by_dept;
60: my %cat_items;
61: my $caller = 'global';
62: my $format_reply;
63: my $totcodes = 0;
64: my $jscript = '';
65: my ($numtitles,$lasttitle);
66: my $formname = 'coursecatalog';
67: my $domdesc = $Apache::lonnet::domaindescription{$codedom};
68: $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
69: if ($totcodes > 0) {
70: $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
71: if ($format_reply eq 'ok') {
72: my $numtypes = @codetitles;
73: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
74: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
75: my $longtitles_str = join('","',@{$longtitles});
76: my $allidlist = $idlist{$codetitles[0]};
77: $numtitles = @codetitles;
78: $lasttitle = $numtitles;
79: if ($numtitles > 4) {
80: $lasttitle = 4;
81: }
82: my @data = ('top');
83: for (my $k=0; $k<$lasttitle; $k++) {
84: my $cat = $codetitles[$k];
85: my $level = 1;
86: $level = &recurse_options($codetitles[$k],$idlist{$codetitles[$k]},$level,$cat,\%cat_items,\@data,\%by_year,\%by_sem,\%by_dept); }
87: $scripttext .= &build_javascript(\%by_year,\%by_sem,\%by_dept,\%cat_order,\@codetitles);
88: $jscript .= &javascript_select_filler($formname,$scripttext,\@codetitles,$longtitles_str,$allidlist);
89: }
90: if ($env{'form.state'} eq 'listing') {
91: $jscript .= '
92: function setElements() {
93: ';
94: for (my $i=0; $i<@codetitles-1; $i++) {
95: if ($env{'form.'.$codetitles[$i]} != -1) {
96: $jscript .= '
97: for (var j=0; j<document.'.$formname.'.'.$codetitles[$i].'.length; j++) {
98: if (document.'.$formname.'.'.$codetitles[$i].'[j].value == "'.$env{'form.'.$codetitles[$i]}.'") {
99: document.'.$formname.'.'.$codetitles[$i].'.selectedIndex = j;
100: }
101: }
102: ';
103: }
104: }
105: $jscript .= ' courseSet()'."\n";
106: if ($env{'form.'.$codetitles[-1]} != -1) {
107: $jscript .= '
108: for (var j=0; j<document.'.$formname.'.'.$codetitles[-1].'.length; j++) {
109: if (document.'.$formname.'.'.$codetitles[-1].'[j].value == "'.$env{'form.'.$codetitles[-1]}.'") {
110: document.'.$formname.'.'.$codetitles[-1].'.selectedIndex = j;
111: }
112: }
113: ';
114: }
115: $jscript .= '}';
116: $jscript .= qq|
117: function changeSort(caller) {
118: document.coursecatalog.sortby.value = caller;
119: document.coursecatalog.submit();
120: }\n|;
121: }
122: my $js = '<script type"text/javascript">'."\n$jscript\n".
123: '</script>';
124: my %add_entries = (topmargin => "0",
125: marginheight => "0",
126: onLoad =>"setElements()",);
127: my $start_page =
128: &Apache::loncommon::start_page('Course Catalog',$js,
129: {
130: 'add_entries' => \%add_entries,
131: 'no_inline_link' => 1,});
132: $r->print($start_page);
133:
134: $r->print('<h3>'.&mt('Display information about official [_1] classes for which LON-CAPA courses have been created:',$domdesc).'</h3>');
135: $r->print(&mt('<b>Choose which course(s) to list.</b><br />'));
136: $r->print('<form name="coursecatalog" method="post">');
137: if ($numtitles > 0) {
138: $r->print('<table><tr>');
139: for (my $k=0; $k<$lasttitle-1; $k++) {
140: my @unsorted = @{$cat_items{$codetitles[$k]}};
141: my @items;
142: &Apache::courseclassifier::sort_cats($k,\%cat_order,\@codetitles,\@unsorted,\@items);
143: my @longitems;
144: if (defined($cat_titles{$codetitles[$k]})) {
145: foreach my $item (@items) {
146: push(@longitems,$cat_titles{$codetitles[$k]}{$item});
147: }
148: } else {
149: @longitems = @items;
150: }
151: $r->print('<td align="center">'.$codetitles[$k].'<br />'."\n".
152: '<select name="'.$codetitles[$k].'" onChange="courseSet()"');
153: $r->print('>'."\n".'<option value="0" />All'."\n");
154: for (my $i=0; $i<@items; $i++) {
155: if ($longitems[$i] eq '') {
156: $longitems[$i] = $items[$i];
157: }
158: $r->print(' <option value="'.$items[$i].'">'.$longitems[$i].'</option>');
159: }
160: $r->print('</select></td>');
161: }
162: $r->print('<td align="center">'.$codetitles[$lasttitle-1].'<br />'."\n".
163: '<select name="'.$codetitles[$lasttitle-1].'">'."\n".
164: '<option value="0">All'."\n".
165: '</option>'."\n".'</select>'."\n".
166: '</td>'
167: );
168: $r->print('</tr></table>');
169: if ($numtitles > 4) {
170: $r->print('<br /><br />'.$codetitles[$numtitles-1].'<br />'."\n".
171: '<input type="text" name="'.$codetitles[$numtitles-1].'" /><br />'."\n");
172: }
173: }
174: $r->print('<br /><input type="hidden" name="state" value="listing" /><input type="hidden" name="sortby" value="" /><input type="submit" name="catalogfilter" value="'.&mt('Display courses').'" /></form>');
175: } else {
176: $r->print(&Apache::loncommon::start_page('Course Catalog','',
177: {
178: 'no_inline_link' => 1,}));
179: $r->print('<br />'.&mt('No official courses to display for [_1].',$domdesc));
180: }
181: if ($env{'form.state'} eq 'listing') {
182: $r->print('<br /><br />'.&print_course_listing($codedom).'<br />');
183: }
184: $r->print(&Apache::loncommon::end_page());
185: return OK;
186: }
187:
188: sub recurse_options {
189: my ($currkey,$currlist,$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept) = @_;
190: if (ref($currlist) eq 'HASH') {
191: $level ++;
192: foreach my $key (sort(keys(%{$currlist}))) {
193: $$data[$level-1]= $key;
194: &recurse_options($key,$currlist->{$key},$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept);
195: }
196: } else {
197: $level --;
198: my @contents = split(/","/,$currlist);
199: foreach my $item (@contents) {
200: if (!grep(/^\Q$item\E$/,@{$cat_options->{$cat}})) {
201: push(@{$cat_options->{$cat}},$item);
202: }
203: if ($level == 3) {
204: if (!grep/^\Q$item\E$/,@{$by_year->{$data->[1]}->{$currkey}}) {
205: push(@{$by_year->{$data->[1]}->{$currkey}},$item);
206: }
207: if (!grep/^\Q$item\E$/,@{$by_sem->{$data->[2]}->{$currkey}}) {
208: push(@{$by_sem->{$data->[2]}->{$currkey}},$item);
209: }
210: if (!grep/^\Q$item\E$/,@{$by_dept->{$currkey}}) {
211: push(@{$by_dept->{$currkey}},$item);
212: }
213:
214: }
215: }
216: }
217: return $level;
218: }
219:
220: sub build_javascript {
221: my ($by_year,$by_sem,$by_dept,$cat_order,$codetitles) = @_;
222: my @unsorted = keys(%{$by_year});
223: my @sorted_yrs;
224: &Apache::courseclassifier::sort_cats('0',$cat_order,$codetitles,\@unsorted,\@sorted_yrs);
225: my $output = 'var idcse_by_yr_year = new Array("'.join('","',@sorted_yrs).'");'."\n".
226: 'var idcse_by_yr_dept = new Array('.scalar(@sorted_yrs).');'."\n".
227: 'var idcse_by_yr_num = new Array('.scalar(@sorted_yrs).');'."\n";
228: for (my $i=0; $i<@sorted_yrs; $i++) {
229: my $numkeys = keys(%{$by_year->{$sorted_yrs[$i]}});
230: $output .= " idcse_by_yr_num[$i] = new Array($numkeys);\n";
231: if (ref($by_year->{$sorted_yrs[$i]}) eq 'HASH') {
232: @unsorted = keys(%{$by_year->{$sorted_yrs[$i]}});
233: my @sorted_depts;
234: &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts);
235: $output .= qq| idcse_by_yr_dept[$i] = new Array ("|.join('","',@sorted_depts).'");'."\n";
236: for (my $j=0; $j<@sorted_depts; $j++) {
237: $output .= qq| idcse_by_yr_num[$i][$j] = new Array ("|;
238: $output .= join('","',sort(@{$by_year->{$sorted_yrs[$i]}->{$sorted_depts[$j]}})).'");'."\n";
239: }
240: }
241: }
242: @unsorted = keys(%{$by_sem});
243: my @sorted_sems;
244: &Apache::courseclassifier::sort_cats('1',$cat_order,$codetitles,\@unsorted,\@sorted_sems);
245: $output .= 'idcse_by_sem_sems = new Array("'.join('","',@sorted_sems).'");'."\n".
246: 'idcse_by_sem_dept = new Array('.scalar(@sorted_sems).');'."\n".
247: 'idcse_by_sem_num = new Array('.scalar(@sorted_sems).');'."\n";
248: for (my $i=0; $i<@sorted_sems; $i++) {
249: my $numkeys = keys(%{$by_sem->{$sorted_sems[$i]}});
250: $output .= " idcse_by_sem_num[$i] = new Array($numkeys);\n";
251: if (ref($by_sem->{$sorted_sems[$i]}) eq 'HASH') {
252: @unsorted = keys(%{$by_sem->{$sorted_sems[$i]}});
253: my @sorted_depts;
254: &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts);
255: $output .= qq| idcse_by_sem_dept[$i] = new Array("|.join('","',@sorted_depts).'");'."\n";
256: for (my $j=0; $j<@sorted_depts; $j++) {
257: $output .= qq| idcse_by_sem_num[$i][$j] = new Array ("|.join('","',sort(@{$by_sem->{$sorted_sems[$i]}->{$sorted_depts[$j]}})).'");'."\n";
258: }
259: }
260: }
261: @unsorted = keys(%{$by_dept});
262: my @sorted_deps;
263: &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_deps);
264: $output .= 'idcse_by_dep = new Array('.scalar(@sorted_deps).');'."\n";
265: for (my $k=0; $k<@sorted_deps; $k++) {
266: $output .= qq| idcse_by_dep[$k] = new Array ("|.join('","',sort(@{$by_dept->{$sorted_deps[$k]}})).'");'."\n";
267: }
268: return $output;
269: }
270:
271:
272: sub print_course_listing {
273: my ($domain) = @_;
274: my $output;
275: my $year = $env{'form.Year'};
276: my $sem = $env{'form.Semester'};
277: my $dept = $env{'form.Department'};
278: my $coursenum = $env{'form.Number'};
279: my $instcode;
280: if ($sem eq '0' ) {
281: $instcode .= '^[sfu]s';
282: } else {
283: $instcode .= '^'.$sem;
284: }
285: if ($year eq '0') {
286: $instcode .= '\d{2}';
287: } else {
288: $instcode .= $year;
289: }
290: if ($dept eq '0') {
291: $instcode .= '\w{2,3}';
292: } else {
293: $instcode .= $dept;
294: }
295: if ($coursenum ne '0' && $coursenum != -1) {
296: $instcode .= $coursenum.'$';
297: }
298: my %courses = &Apache::lonnet::courseiddump($domain,'.',1,$instcode,'.','.',
299: undef,undef,'Course',1);
300: if (keys(%courses) == 0) {
301: $output = &mt('No courses match the criteria you selected.');
302: return $output;
303: }
304: $output = &mt('<b>Note for students:</b> If you are officially enrolled in a course but there is no student role for the course in your LON-CAPA roles screen, check the default access dates and/or auto-enrollment settings for the course below. Your roles screen displays only currently accessible roles.<br /><br />');
305: $output .= &Apache::loncommon::start_data_table().
306: &Apache::loncommon::start_data_table_header_row().
307: '<th><a href="javascript:changeSort('."'code'".')">'.&mt('Code').'</a></th>'.
308: '<th>'.&mt('Sections').'</th>'.
309: '<th>'.&mt('Crosslisted').'</th>'.
310: '<th><a href="javascript:changeSort('."'title'".')">'.&mt('Title').'</a></th>'.
311: '<th><a href="javascript:changeSort('."'owner'".')">'.&mt('Owner').'</a></th>'.
312: '<th>'.&mt('Student Status').'</th>'.
313: '<th>'.&mt('Default Access Dates').'</th>'.
314: '<th>'.&mt('Auto-enrollment').'</th>'.
315: &Apache::loncommon::end_data_table_header_row();
316: my %courseinfo;
317: foreach my $course (keys(%courses)) {
318: my $descr;
319: if ($courses{$course} =~ m/^([^:]*):/i) {
320: $descr = &unescape($1);
321: } else {
322: $descr = &unescape($courses{$course});
323: }
324: my $cleandesc=&HTML::Entities::encode($descr,'<>&"');
325: $cleandesc=~s/'/\\'/g;
326: my ($cdom,$cnum)=split(/\_/,$course);
327:
328: my ($desc,$instcode,$owner,$ttype) = split(/:/,$courses{$course});
329: $owner = &unescape($owner);
330: my ($ownername,$ownerdom);
331: if ($owner =~ /:/) {
332: ($ownername,$ownerdom) = split(/:/,$owner);
333: } else {
334: $ownername = $owner;
335: if ($owner ne '') {
336: $ownerdom = $cdom;
337: }
338: }
339: my %ownernames;
340: if ($ownername ne '' && $ownerdom ne '') {
341: %ownernames = &Apache::loncommon::getnames($ownername,$ownerdom);
342: }
343: $courseinfo{$course}{'cdom'} = $cdom;
344: $courseinfo{$course}{'cnum'} = $cnum;
345: $courseinfo{$course}{'code'} = $instcode;
346: $courseinfo{$course}{'ownerlastname'} = $ownernames{'lastname'};
347: $courseinfo{$course}{'title'} = $cleandesc;
348: $courseinfo{$course}{'owner'} = $owner;
349: }
350: my %Sortby;
351: foreach my $course (sort(keys(%courses))) {
352: if ($env{'form.sortby'} eq 'code') {
353: push(@{$Sortby{$courseinfo{$course}{'code'}}},$course);
354: } elsif ($env{'form.sortby'} eq 'owner') {
355: push(@{$Sortby{$courseinfo{$course}{'ownerlastname'}}},$course);
356: } else {
357: push(@{$Sortby{$courseinfo{$course}{'title'}}},$course);
358: }
359: }
360: my @sorted_courses;
361: if (($env{'form.sortby'} eq 'code') || ($env{'form.sortby'} eq 'owner')) {
362: @sorted_courses = sort(keys(%Sortby));
363: } else {
364: @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
365: }
366: foreach my $item (@sorted_courses) {
367: foreach my $course (@{$Sortby{$item}}) {
368: $output.=&Apache::loncommon::start_data_table_row();
369: $output.=&courseinfo_row($courseinfo{$course});
370: $output.=&Apache::loncommon::end_data_table_row();
371: }
372: }
373: $output .= &Apache::loncommon::end_data_table();
374: return $output;
375: }
376:
377: sub courseinfo_row {
378: my ($info) = @_;
379: my ($cdom,$cnum,$title,$ownerlast,$code,$owner,$output);
380: if (ref($info) eq 'HASH') {
381: $cdom = $info->{'cdom'};
382: $cnum = $info->{'cnum'};
383: $title = $info->{'title'};
384: $ownerlast = $info->{'ownerlastname'};
385: $code = $info->{'code'};
386: $owner = $info->{'owner'};
387: } else {
388: $output = '<td colspan="8">'.&mt('No information available for [_1].',
389: $code).'</td>';
390: return $output;
391: }
392: my %coursehash = &Apache::lonnet::dump('environment',$cdom,$cnum);
393: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
394: my %idx;
395: my @classids;
396: my @crosslistings;
397: $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
398: my %status_title = &Apache::lonlocal::texthash(
399: Expired => 'Previous access',
400: Active => 'Current access',
401: Future => 'Future access',
402: );
403: my %student_count = (
404: Expired => 0,
405: Active => 0,
406: Future => 0,
407: );
408: while (my ($student,$data) = each(%$classlist)) {
409: $student_count{$data->[$idx{'status'}]} ++;
410: }
411: my $seclist = &identify_sections($coursehash{'internal.sectionnums'});
412: my $xlist_items = &identify_sections($coursehash{'internal.crosslistings'});
413: my $countslist;
414: my $startaccess = '';
415: my $endaccess = '';
416: my $now;
417: my ($accessdates,$autoenrolldates,$showsyllabus);
418: if ( defined($coursehash{'default_enrollment_start_date'}) ) {
419: $startaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_start_date'});
420: }
421: if ( defined($coursehash{'default_enrollment_end_date'}) ) {
422: $endaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_end_date'});
423: if ($coursehash{'default_enrollment_end_date'} == 0) {
424: $endaccess = "No ending date";
425: }
426: }
427: if ($startaccess) {
428: $accessdates .= &mt('From: ').$startaccess.'<br />';
429: }
430: if ($endaccess) {
431: $accessdates .= &mt('To: ').$endaccess.'<br />';
432: }
433: $autoenrolldates = &mt('Not enabled');
434: if (defined($coursehash{'internal.autoadds'}) && $coursehash{'internal.autoadds'} == 1) {
435: my ($autostart,$autoend);
436: if ( defined($coursehash{'internal.autostart'}) ) {
437: $autostart = &Apache::lonlocal::locallocaltime($coursehash{'internal.autostart'});
438: }
439: if ( defined($coursehash{'internal.autoend'}) ) {
440: $autoend = &Apache::lonlocal::locallocaltime($coursehash{'internal.autoend'});
441: }
442: if ($coursehash{'internal.autostart'} > $now) {
443: if ($coursehash{'internal.autoend'} && $coursehash{'internal.autoend'} < $now) {
444: $autoenrolldates = &mt('Not enabled');
445: } else {
446: my $valid_classes = &get_valid_classes($seclist,$xlist_items,
447: $code,$owner,$cdom,$cnum);
448: if ($valid_classes ne '') {
449: $autoenrolldates = &mt('Not enabled<br />Starts: ').
450: $autostart.'<br />'.$valid_classes;
451: }
452: }
453: } else {
454: if ($coursehash{'internal.autoend'} && $coursehash{'internal.autoend'} < $now) {
455: $autoenrolldates = &mt('Not enabled<br />Ended: ').$autoend;
456: } else {
457: my $valid_classes = &get_valid_classes($seclist,$xlist_items,
458: $code,$owner,$cdom,$cnum);
459: if ($valid_classes ne '') {
460: $autoenrolldates = &mt('Currently enabled<br />').
461: $valid_classes;
462: }
463: }
464: }
465: }
466: if (defined($coursehash{'showsyllabus'})) {
467: $showsyllabus = $coursehash{'showsyllabus'};
468: }
469: foreach my $status ('Active','Future','Expired') {
470: $countslist .= '<nobr>'.$status_title{$status}.': '.
471: $student_count{$status}.'</nobr><br />';
472: }
473: if ($xlist_items eq '') {
474: $xlist_items = &mt('No');
475: }
476: $output = '<td>'.$coursehash{'internal.coursecode'}.'</td>'.
477: '<td>'.$seclist.'</td>'.
478: '<td>'.$xlist_items.'</td>'.
479: '<td>'.$title.' <font size="-2">';
480: if ($showsyllabus) {
481: $output .= &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$cnum,$cdom);
482: }
483: $output .= '</font></td>'.
484: '<td>'.$ownerlast.'</td>'.
485: '<td>'.$countslist.'</td>'.
486: '<td>'.$accessdates.'</td>'.
487: '<td>'.$autoenrolldates.'</td>';
488: return $output;
489: }
490:
491: sub identify_sections {
492: my ($seclist) = @_;
493: my @secnums;
494: if ($seclist =~ /,/) {
495: my @sections = split(/,/,$seclist);
496: foreach my $sec (@sections) {
497: $sec =~ s/:[^:]*$//;
498: push(@secnums,$sec);
499: }
500: } else {
501: if ($seclist =~ m/^([^:]+):/) {
502: my $sec = $1;
503: if (!grep(/^\Q$sec\E$/,@secnums)) {
504: push(@secnums,$sec);
505: }
506: }
507: }
508: @secnums = sort {$a <=> $b} @secnums;
509: my $seclist = join(', ',@secnums);
510: return $seclist;
511: }
512:
513: sub get_valid_classes {
514: my ($seclist,$xlist_items,$crscode,$owner,$cdom,$cnum) = @_;
515: my $response;
516: my %validations;
517: @{$validations{'sections'}} = ();
518: @{$validations{'xlists'}} = ();
519: my $totalitems = 0;
520: if ($seclist) {
521: foreach my $sec (split(',',$seclist)) {
522: my $class = $crscode.$sec;
523: if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owner,
524: $class) eq 'ok') {
525: if (!grep(/^\Q$sec$\E/,@{$validations{'sections'}})) {
526: push(@{$validations{'sections'}},$sec);
527: $totalitems ++;
528: }
529: }
530: }
531: }
532: if ($xlist_items) {
533: foreach my $item (split(',',$xlist_items)) {
534: if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owner,
535: $item) eq 'ok') {
536: if (!grep(/^\Q$item$\E/,@{$validations{'xlists'}})) {
537: push(@{$validations{'xlists'}},$item);
538: $totalitems ++;
539: }
540: }
541: }
542: }
543: if ($totalitems > 0) {
544: if (@{$validations{'sections'}}) {
545: $response = &mt('Sections: ').
546: join(',',@{$validations{'sections'}}).'<br />';
547: }
548: if (@{$validations{'xlists'}}) {
549: $response .= &mt('Courses: ').
550: join(',',@{$validations{'xlists'}});
551: }
552: }
553: return $response;
554: }
555:
556: sub javascript_select_filler {
557: my ($formname,$scripttext,$codetitles,$longtitles_str,$allidlist) = @_;
558: my $output = <<END;
559: function courseSet() {
560: var longtitles = new Array ("$longtitles_str");
561: var valyr = document.$formname.Year.options[document.$formname.Year.selectedIndex].value
562: var valsem = document.$formname.Semester.options[document.$formname.Semester.selectedIndex].value
563: var valdept = document.$formname.Department.options[document.$formname.Department.selectedIndex].value
564: var valclass = document.$formname.Number.options[document.$formname.Number.selectedIndex].value
565: var idyears = new Array("$allidlist");
566: var idyr = -1;
567: var idsem = -1;
568: var iddept = -1;
569: document.$formname.Number.length = 0;
570:
571: $scripttext
572:
573: selYear = document.$formname.Year.selectedIndex-1;
574: selSemester = document.$formname.Semester.selectedIndex-1;
575: selDepartment = document.$formname.Department.selectedIndex-1;
576: if (selYear == -1) {
577: if (selSemester == -1) {
578: if (selDepartment > -1) {
579: document.$formname.Number.options[0] = new Option('All','0',false,false);
580: for (var k=0; k<idcse_by_dep[selDepartment].length; k++) {
581: document.$formname.Number.options[k+1] = new Option(idcse_by_dep[selDepartment][k],idcse_by_dep[selDepartment][k],false,false);
582:
583: }
584: }
585: else {
586: document.$formname.Number.options[0] = new Option("All","0",true,true);
587: }
588: }
589: else {
590: if (selDepartment > -1) {
591: for (var i=0; i<idcse_by_sem_sems.length; i++) {
592: if (idcse_by_sem_sems[i] == valsem) {
593: idsem = i;
594: }
595: }
596: if (idsem != -1) {
597: for (var i=0; i<idcse_by_sem_dept[idsem].length; i++) {
598: if (idcse_by_sem_dept[idsem][i] == valdept) {
599: iddept = i;
600: }
601: }
602: }
603: if (iddept != -1) {
604: document.$formname.Number.options[0] = new Option('All','0',false,false);
605: for (var k=0; k<idcse_by_sem_num[idsem][iddept].length; k++) {
606: document.$formname.Number.options[k+1] = new Option(idcse_by_sem_num[idsem][iddept][k],idcse_by_sem_num[idsem][iddept][k],false,false);
607: }
608: }
609: else {
610: document.$formname.Number.options[0] = new Option('No courses','0',true,true);
611: }
612: }
613: else {
614: document.$formname.Number.options[0] = new Option("All","0",true,true);
615: }
616: }
617: }
618: else {
619: if (selSemester == -1) {
620: if (selDepartment > -1) {
621: for (var i=0; i<idcse_by_yr_year.length; i++) {
622: if (idcse_by_yr_year[i] == valyr) {
623: idyr = i;
624: }
625: }
626: if (idyr != -1) {
627: for (var i=0; i<idcse_by_yr_dept[idyr].length; i++) {
628: if (idcse_by_yr_dept[idyr][i] == valdept) {
629: iddept = i;
630: }
631: }
632: }
633: if (iddept != -1) {
634: document.$formname.Number.options[0] = new Option('All','0',false,false);
635: for (var k=0; k<idcse_by_yr_num[idyr][iddept].length; k++) {
636: document.$formname.Number.options[k+1] = new Option(idcse_by_yr_num[idyr][iddept][k],idcse_by_yr_num[idyr][iddept][k],false,false);
637: }
638: }
639: else {
640: document.$formname.Number.options[0] = new Option('No courses','0',true,true);
641: }
642: }
643: else {
644: document.$formname.Number.options[0] = new Option("All","0",true,true);
645: }
646: }
647: else {
648: for (var k=0; k<idyears.length; k++) {
649: if (idyears[k] == valyr) {
650: idyr = k;
651: }
652: }
653: if (idyr != -1) {
654: for (var k=0; k<idsems[idyr].length; k++) {
655: if (idsems[idyr][k] == valsem) {
656: idsem = k;
657: }
658: }
659: }
660: if (idsem != -1) {
661: for (var k=0; k<idcodes[idyr][idsem].length; k++) {
662: if (idcodes[idyr][idsem][k] == valdept) {
663: iddept = k;
664: }
665: }
666: }
667: if (iddept != -1) {
668: document.$formname.Number.options[0] = new Option('All','0',false,false);
669: for (var i=0; i<idcourses[idyr][idsem][iddept].length; i++) {
670: var display = idcourses[idyr][idsem][iddept][i];
671: if (longtitles[3] == 1) {
672: if (idcourseslongs[idyr][idsem][iddept][i] != "") {
673: display = idcourseslongs[idyr][idsem][iddept][i]
674: }
675: }
676: document.$formname.Number.options[i+1] = new Option(display,idcourses[idyr][idsem][iddept][i],false,false)
677: }
678: }
679: else {
680: document.$formname.Number.options[0] = new Option('No courses','0',true,true);
681: }
682: }
683: document.$formname.Number.selectedIndex = 0
684: }
685: }
686: END
687: return $output;
688: }
689:
690: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>