'.$codetitles[0].' '."\n".
- ''."\n".
- ' Select'."\n");
- my @items = ();
- my @longitems = ();
- if ($idlist{$codetitles[0]} =~ /","/) {
- @items = split/","/,$idlist{$codetitles[0]};
- } else {
- $items[0] = $idlist{$codetitles[0]};
- }
- if (defined($idlist_titles{$codetitles[0]})) {
- if ($idlist_titles{$codetitles[0]} =~ /","/) {
- @longitems = split/","/,$idlist_titles{$codetitles[0]};
+ document.$formname.sortby.value = caller;
+ document.$formname.submit();
+}
+
+function setCourseId(caller) {
+ document.$formname.coursenum.value = caller;
+ document.$formname.submit();
+}
+
+ENDSCRIPT
+ $catjs .= &courselink_javascript($hostname);
+ if (&user_is_dc($codedom) || $canviewall) {
+ $catjs .= <print(&print_course_listing($codedom,$numtitles,undef,undef,undef,
+ \@codetitles,$canviewall,$hostname));
+ }
+ } else {
+ my (%add_entries);
+ my ($currdepth,$deeper) = &get_depth_values();
+ if ($selitem) {
+ my $alert = &mt('Choose a subcategory to display');
+ if (!$deeper) {
+ $alert = &mt('Choose a category to display');
+ }
+ &js_escape(\$alert);
+ $catjs .= <'."\n".$catjs."\n".'';
+ &cat_header($r,$codedom,$catjs,\%add_entries,$catlinks,undef,$cattype);
+ if ($env{'form.currcat_0'} ne '') {
+ $r->print(' ');
+ }
+ if ($env{'form.state'} eq 'listing') {
+ $r->print(&print_course_listing($codedom,undef,\@trails,\%allitems,$subcats,\@codetitles,
+ $canviewall,$hostname));
+ }
+ }
+ }
+ $r->print(' '.&Apache::loncommon::end_page());
+ return OK;
+}
+
+sub validate_input {
+ my ($codedom,$cats,$maxd,$crscatsref) = @_;
+ my $currcat = '';
+ my $depth = 0;
+ if ($env{'form.catalog_maxdepth'} ne '') {
+ $env{'form.catalog_maxdepth'} =~ s{\D}{}g;
+ }
+ if ((ref($cats) eq 'ARRAY') && (ref($maxd) eq 'HASH')) {
+ if (ref($cats->[0]) eq 'ARRAY') {
+ if (@{$cats->[0]} == 1) {
+ if ($cats->[0][0] eq 'instcode') {
+ $currcat = 'instcode::0';
+ } elsif ($cats->[0][0] eq 'communities') {
+ $currcat = 'communities::0';
+ } elsif ($cats->[0][0] eq 'placement') {
+ $currcat = 'placement::0';
} else {
- $longitems[0] = $idlist_titles{$codetitles[0]};
+ my $name = $cats->[0][0];
+ $currcat = &escape($name).'::0';
}
- for (my $i=0; $i<@longitems; $i++) {
- if ($longitems[$i] eq '') {
- $longitems[$i] = $items[$i];
+ if (exists($maxd->{$cats->[0][0]})) {
+ if ($env{'form.catalog_maxdepth'} <= $maxd->{$cats->[0][0]}) {
+ $depth = $env{'form.catalog_maxdepth'};
+ } else {
+ $depth = $maxd->{$cats->[0][0]};
}
}
+ } elsif ((@{$cats->[0]} > 1) && ($env{'form.currcat_0'} ne '')) {
+ my ($escname) = ($env{'form.currcat_0'} =~ /^([^:]+)\:\:0$/);
+ if ($escname =~ /^instcode|communities|placement$/) {
+ $currcat = $env{'form.currcat_0'};
+ if (exists($maxd->{$escname})) {
+ if ($env{'form.catalog_maxdepth'} <= $maxd->{$escname}) {
+ $depth = $env{'form.catalog_maxdepth'};
+ } else {
+ $depth = $maxd->{$escname};
+ }
+ } else {
+ $depth = 1;
+ }
+ } elsif ($escname ne '') {
+ my $name = &unescape($escname);
+ if (grep(/^\Q$name\E$/,@{$cats->[0]})) {
+ $currcat = $env{'form.currcat_0'};
+ if (exists($maxd->{$name})) {
+ if ($env{'form.catalog_maxdepth'} <= $maxd->{$name}) {
+ $depth = $env{'form.catalog_maxdepth'};
+ } else {
+ $depth = $maxd->{$name};
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ $env{'form.currcat_0'} = $currcat;
+ $env{'form.catalog_maxdepth'} = $depth;
+
+ my %possibles = (
+ backto => 1,
+ catalogfilter => 1,
+ catalog_maxdepth => 1,
+ courseid => 1,
+ coursenum => 1,
+ currcat_0 => 1,
+ numtitles => 1,
+ Year => 1,
+ Semester => 1,
+ Department => 1,
+ Number => 1,
+ showdom => 1,
+ sortby => 1,
+ showcounts => 1,
+ showdetails => 1,
+ showhidden => 1,
+ showselfenroll => 1,
+ state => 1,
+ uniquecode => 1,
+ wasactive => 1,
+ wasactiveon_day => 1,
+ wasactiveon_month => 1,
+ wasactiveon_year => 1,
+ withsubcats => 1,
+ );
+ my %currcats;
+ if ($env{'form.catalog_maxdepth'} > 0) {
+ for (my $i=1; $i<=$env{'form.catalog_maxdepth'}; $i++) {
+ $currcats{'currcat_'.$i} = 1;
+ $possibles{'currcat_'.$i} = 1;
+ }
+ }
+
+ foreach my $key (sort(keys(%env))) {
+ if ($key =~ /^form\.(.+)$/) {
+ unless ($possibles{$1}) {
+ delete($env{$key});
+ }
+ }
+ }
+ if (exists($env{'form.backto'})) {
+ unless ($env{'form.backto'} eq 'coursecatalog') {
+ delete($env{'form.backto'});
+ }
+ }
+ if (exists($env{'form.catalogfilter'})) {
+ unless (($env{'form.catalogfilter'} eq &mt('Display courses')) ||
+ ($env{'form.catalogfilter'} eq &mt('Display communities')) ||
+ ($env{'form.catalogfilter'} eq &mt('Display placement tests'))) {
+ delete($env{'form.catalogfilter'});
+ }
+ }
+ if (exists($env{'form.courseid'})) {
+ if ($env{'form.courseid'} ne '') {
+ unless ($env{'form.courseid'} =~ /^\Q$codedom\E_$LONCAPA::match_courseid$/) {
+ $env{'form.courseid'} = '';
+ }
+ }
+ }
+ if (exists($env{'form.coursenum'})) {
+ unless ($env{'form.coursenum'} =~ /^$LONCAPA::match_courseid$/) {
+ $env{'form.coursenum'} = '';
+ }
+ }
+ if (exists($env{'form.currcat_0'})) {
+ unless ($env{'form.currcat_0'} =~ /^(instcode|communities|placement)\Q::0\E$/) {
+ if ($env{'form.currcat_0'} =~ /^.+\Q::0\E$/) {
+ if (ref($crscatsref) eq 'HASH') {
+ unless (exists($crscatsref->{$env{'form.currcat_0'}})) {
+ delete($env{'form.currcat_0'});
+ }
+ } else {
+ delete($env{'form.currcat_0'});
+ }
} else {
- @longitems = @items;
+ delete($env{'form.currcat_0'});
+ }
+ }
+ }
+ if (exists($env{'form.numtitles'})) {
+ unless ($env{'form.numtitles'} =~ /^\d+$/) {
+ delete($env{'form.numtitles'});
+ }
+ }
+ my ($gotcodes,%possvals);
+ foreach my $item ('Year','Semester','Department','Number') {
+ if (exists($env{'form.'.$item})) {
+ unless ($env{'form.'.$item} eq '0') {
+ unless ($gotcodes) {
+ $gotcodes = &get_instcode_allowable($codedom,\%possvals);
+ }
+ if (ref($possvals{$item}) eq 'HASH') {
+ unless (exists($possvals{$item}{$env{'form.'.$item}})) {
+ delete($env{'form.'.$item});
+ }
+ } else {
+ delete($env{'form.'.$item});
+ }
+ }
+ }
+ }
+ if (exists($env{'form.showdom'})) {
+ unless ($env{'form.showdom'} =~ /^$LONCAPA::match_domain$/) {
+ delete($env{'form.showdom'});
+ }
+ }
+ if (exists($env{'form.sortby'})) {
+ unless ($env{'form.sortby'} =~ /^(title|code|owner|cats)$/) {
+ delete($env{'form.sortby'});
+ }
+ }
+ if (exists($env{'form.showcounts'})) {
+ if (ref($env{'form.showcounts'}) eq 'ARRAY') {
+ foreach my $item (@{$env{'form.showcounts'}}) {
+ unless ($item =~ /^(Active|Future|Previous)$/) {
+ delete($env{'form.showcounts'});
+ last;
+ }
}
- for (my $i=0; $i<@items; $i++) {
- $r->print(' '.$longitems[$i].' ');
+ } else {
+ unless ($env{'form.showcounts'} =~ /^(Active|Future|Previous)$/) {
+ delete($env{'form.showcounts'});
}
- $r->print(' ');
- for (my $i=1; $i<$numtitles; $i++) {
- $r->print(''.$codetitles[$i].' '."\n".
- ''."\n".
- '<-Pick '.$codetitles[$i-1].' '."\n".
- ' '."\n".
- ' '
- );
+ }
+ }
+ foreach my $item ('showhidden','showdetails','showselfenroll','withsubcats') {
+ if (exists($env{'form.'.$item})) {
+ unless ($env{'form.'.$item} eq '1') {
+ delete($env{'form.'.$item});
}
- $r->print('