'.$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]});
+ $r->print(''.&mt('Choose which course(s) to list.').' ');
+ $r->print('');
+ for (my $k=0; $k<$lasttitle-1; $k++) {
+ my (@items,@unsorted);
+ if (ref($cat_items{$codetitles[$k]}) eq 'ARRAY') {
+ @unsorted = @{$cat_items{$codetitles[$k]}};
+ }
+ &Apache::courseclassifier::sort_cats($k,\%cat_order,\@codetitles,\@unsorted,\@items);
+ my @longitems;
+ if (defined($cat_titles{$codetitles[$k]})) {
+ foreach my $item (@items) {
+ push(@longitems,$cat_titles{$codetitles[$k]}{$item});
+ }
} else {
- $longitems[0] = $idlist_titles{$codetitles[0]};
+ @longitems = @items;
}
- for (my $i=0; $i<@longitems; $i++) {
+ $r->print(''.$codetitles[$k].' '."\n".
+ 'print('>'."\n".' All'."\n");
+ for (my $i=0; $i<@items; $i++) {
if ($longitems[$i] eq '') {
$longitems[$i] = $items[$i];
}
+ $r->print(' '.$longitems[$i].' ');
}
+ $r->print(' ');
+ }
+ $r->print(''.$codetitles[$lasttitle-1].' '."\n".
+ ''."\n".
+ 'All'."\n".
+ ' '."\n".' '."\n".
+ '
'."\n");
+ if ($numtitles > 4) {
+ $r->print(' '.$codetitles[$numtitles-1].' '."\n".
+ ' '."\n");
+ }
+ $r->print(' ');
+ }
+ $r->print(' '."\n".
+ ' '."\n".
+ ' '."\n".
+ ' '."\n".
+ ' '.
+ ' ');
+ if (($numtitles > 0) && ($env{'form.state'} eq 'listing')) {
+ $r->print(' ');
+ }
+ } else {
+ &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles);
+ my $cat_maxdepth = $env{'form.catalog_maxdepth'};
+ $r->print('');
+ }
+ return $numtitles;
+}
+
+sub cat_header {
+ my ($r,$codedom,$js,$add_entries,$catlinks,$numtitles) = @_;
+ my $start_page =
+ &Apache::loncommon::start_page('Course Catalog',$js,
+ {
+ 'add_entries' => $add_entries,
+ 'no_inline_link' => 1,});
+ $r->print($start_page);
+ if ($env{'form.state'} eq 'listing') {
+ if ($numtitles > 0) {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"/adm/coursecatalog",
+ text=>"Select courses"},
+ {text=>"Course listing"});
+ } else {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({text=>"Course listing"});
+ }
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Listing'));
+ } else {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"/adm/coursecatalog",
+ text=>"Select courses"});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Select courses'));
+ }
+ $r->print('');
+ return;
+}
+
+sub category_breadcrumbs {
+ my ($dom) = @_;
+ my %domconfig =
+ &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
+ my (@cats,@trails,%allitems,%idx,@jsarray,$cathash);
+ if (ref($domconfig{'coursecategories'}) eq 'HASH') {
+ $cathash = $domconfig{'coursecategories'}{'cats'};
+ } else {
+ $cathash = {};
+ }
+ &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,
+ \@jsarray);
+ my ($currdepth,$deeper) = &get_depth_values();
+ my $currcat_str = ' ';
+ my $catlinks = ''.&mt('Catalog:').' ';
+ for (my $i=0; $i<$deeper; $i++) {
+ $currcat_str .= ' ';
+ my ($cattitle,$shallower);
+ if ($i == 0) {
+ $cattitle = &mt('Main Categories');
+ } else {
+ $shallower = $i-1;
+ my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
+ $cattitle = $cat;
+ }
+ $catlinks .= ''.$cattitle.' -> ';
+ }
+ if ($deeper == 0) {
+ $catlinks .= ''.&mt('Main Categories').': ';
+ if (ref($cats[0]) eq 'ARRAY') {
+ if ((@{$cats[0]} == 1) && ($cats[0][0] eq 'instcode')) {
+ $catlinks .= &mt('Official courses (with institutional codes)').
+ ' ';
+ $env{'form.currcat_0'} = 'instcode::0';
} else {
- @longitems = @items;
+ $catlinks .= ''."\n";
+ if (@{$cats[0]} > 1) {
+ my $selstr;
+ if ($env{'form.currcat_0'} eq '') {
+ $selstr = ' selected="selected" ';
+ }
+ $catlinks .= ''.&mt('Select').' '."\n";
+ }
+ for (my $i=0; $i<@{$cats[0]}; $i++) {
+ my $name = $cats[0][$i];
+ my $item = &escape($name).'::0';
+ my $selstr;
+ if ($env{'form.currcat_'.$i} eq $item) {
+ $selstr = ' selected="selected" ';
+ }
+ $catlinks .= '';
+ if ($name eq 'instcode') {
+ $catlinks .= &mt('Official courses (with institutional codes)');
+ } else {
+ $catlinks .= $name;
+ }
+ $catlinks .= ' '."\n";
+ }
+ $catlinks .= ' '."\n".
+ ' ';
+ }
+ } else {
+ $catlinks .= &mt('Official courses (with institutional codes)').
+ ' ';
+ $env{'form.currcat_0'} = 'instcode::0';
+ }
+ } else {
+ my ($cat,$container,$depth);
+ if ($env{'form.currcat_'.$currdepth} eq '') {
+ my $shallower = $currdepth - 1;
+ ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
+ } else {
+ ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$currdepth});
+ }
+ my $deeper = $depth +1;
+ my $currcat = $cat;
+ if ($cat eq 'instcode') {
+ $currcat = &mt('Official courses (with institutional codes)');
+ }
+ $catlinks .= ' '.$currcat;
+ if (ref($cats[$deeper]{$cat}) eq 'ARRAY') {
+ $catlinks .= ': '.
+ ''.&mt('Select').' ';
+ for (my $k=0; $k<@{$cats[$deeper]{$cat}}; $k++) {
+ my $name = $cats[$deeper]{$cat}[$k];
+ my $item = &escape($name).':'.&escape($cat).':'.$deeper;
+ $catlinks .= ''.$name.' '."\n";
+ }
+ $catlinks .= ' '."\n".
+ ' ';
+ }
+ }
+ $catlinks .= $currcat_str.'
';
+ return $catlinks;
+}
+
+sub get_depth_values {
+ my $currdepth = 0;
+ my $deeper = 0;
+ if ($env{'form.catalog_maxdepth'} ne '') {
+ $currdepth = $env{'form.catalog_maxdepth'};
+ if ($env{'form.currcat_'.$currdepth} eq '') {
+ $deeper = $currdepth;
+ } else {
+ $deeper = $currdepth + 1;
+ }
+ }
+ return ($currdepth,$deeper);
+}
+
+sub additional_filters {
+ my ($codedom) = @_;
+ my $output = ' ';
+ return $output;
+}
+
+sub user_is_dc {
+ my ($codedom) = @_;
+ if (exists($env{'user.role.dc./'.$codedom.'/'})) {
+ my $livedc = 1;
+ my $now = time;
+ my ($start,$end)=split(/\./,$env{'user.role.dc./'.$codedom.'/'});
+ if ($start && $start>$now) { $livedc = 0; }
+ if ($end && $end <$now) { $livedc = 0; }
+ return $livedc;
+ }
+ return;
+}
+
+sub recurse_options {
+ my ($currkey,$currlist,$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept) = @_;
+ if (ref($currlist) eq 'HASH') {
+ $level ++;
+ foreach my $key (sort(keys(%{$currlist}))) {
+ $$data[$level-1]= $key;
+ &recurse_options($key,$currlist->{$key},$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept);
+ }
+ } else {
+ $level --;
+ my @contents = split(/","/,$currlist);
+ foreach my $item (@contents) {
+ if (!grep(/^\Q$item\E$/,@{$cat_options->{$cat}})) {
+ push(@{$cat_options->{$cat}},$item);
}
- for (my $i=0; $i<@items; $i++) {
- $r->print(' '.$longitems[$i].' ');
+ if ($level == 3) {
+ if (!grep/^\Q$item\E$/,@{$by_year->{$data->[1]}->{$currkey}}) {
+ push(@{$by_year->{$data->[1]}->{$currkey}},$item);
+ }
+ if (!grep/^\Q$item\E$/,@{$by_sem->{$data->[2]}->{$currkey}}) {
+ push(@{$by_sem->{$data->[2]}->{$currkey}},$item);
+ }
+ if (!grep/^\Q$item\E$/,@{$by_dept->{$currkey}}) {
+ push(@{$by_dept->{$currkey}},$item);
+ }
+
}
- $r->print(' ');
- for (my $i=1; $i<$numtitles; $i++) {
- $r->print(''.$codetitles[$i].' '."\n".
- ''."\n".
- '<-Pick '.$codetitles[$i-1].' '."\n".
- ' '."\n".
- ' '
- );
+ }
+ }
+ return $level;
+}
+
+sub build_javascript {
+ my ($by_year,$by_sem,$by_dept,$cat_order,$codetitles) = @_;
+ my @unsorted = keys(%{$by_year});
+ my @sorted_yrs;
+ &Apache::courseclassifier::sort_cats('0',$cat_order,$codetitles,\@unsorted,\@sorted_yrs);
+ my $output = 'var idcse_by_yr_year = new Array("'.join('","',@sorted_yrs).'");'."\n".
+ 'var idcse_by_yr_dept = new Array('.scalar(@sorted_yrs).');'."\n".
+ 'var idcse_by_yr_num = new Array('.scalar(@sorted_yrs).');'."\n";
+ for (my $i=0; $i<@sorted_yrs; $i++) {
+ my $numkeys = keys(%{$by_year->{$sorted_yrs[$i]}});
+ $output .= " idcse_by_yr_num[$i] = new Array($numkeys);\n";
+ if (ref($by_year->{$sorted_yrs[$i]}) eq 'HASH') {
+ @unsorted = keys(%{$by_year->{$sorted_yrs[$i]}});
+ my @sorted_depts;
+ &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts);
+ $output .= qq| idcse_by_yr_dept[$i] = new Array ("|.join('","',@sorted_depts).'");'."\n";
+ for (my $j=0; $j<@sorted_depts; $j++) {
+ $output .= qq| idcse_by_yr_num[$i][$j] = new Array ("|;
+ $output .= join('","',sort(@{$by_year->{$sorted_yrs[$i]}->{$sorted_depts[$j]}})).'");'."\n";
}
- $r->print('