--- loncom/interface/coursecatalog.pm 2008/05/29 04:29:33 1.28 +++ loncom/interface/coursecatalog.pm 2008/06/30 04:07:06 1.33 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler for displaying the course catalog interface # -# $Id: coursecatalog.pm,v 1.28 2008/05/29 04:29:33 raeburn Exp $ +# $Id: coursecatalog.pm,v 1.33 2008/06/30 04:07:06 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -84,6 +84,17 @@ function setCatDepth(depth) { } ENDSCRIPT + if ($env{'form.state'} eq 'listing') { + $catjs .= qq| +function changeSort(caller) { + document.$formname.sortby.value = caller; + document.$formname.submit(); +} +function setCourseId(caller) { + document.$formname.coursenum.value = caller; + document.$formname.submit(); +}\n|; + } my $numtitles; if ($env{'form.currcat_0'} eq 'instcode::0') { $numtitles = &instcode_course_selector($r,$codedom,$formname,$domdesc, @@ -96,11 +107,29 @@ ENDSCRIPT $catjs = ''; &cat_header($r,$codedom,$catjs,\%add_entries,$catlinks); if ($env{'form.currcat_0'} ne '') { + $r->print('
'. + &additional_filters($codedom)."\n"); + my ($currdepth,$deeper) = &get_depth_values(); + $r->print(''."\n"); + for (my $i=0; $i<$deeper; $i++) { + $r->print(''."\n"); + } + $r->print(''."\n". + ''."\n". + ''."\n". + ''. + '


'); + } + if ($env{'form.state'} eq 'listing') { $r->print(&print_course_listing($codedom)); } } } - $r->print(&Apache::loncommon::end_page()); + $r->print('
'.&Apache::loncommon::end_page()); return OK; } @@ -154,6 +183,9 @@ sub instcode_course_selector { my $totcodes = 0; my $jscript = ''; my ($numtitles,$lasttitle); + my %add_entries = (topmargin => "0", + marginheight => "0",); + my $js; $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom); if ($totcodes > 0) { $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order); @@ -209,33 +241,21 @@ function setElements() { $jscript .= '}'; } } - if ($env{'form.state'} eq 'listing') { - $jscript .= qq| -function changeSort(caller) { - document.$formname.sortby.value = caller; - document.$formname.submit(); -} -function setCourseId(caller) { - document.$formname.coursenum.value = caller; - document.$formname.submit(); -}\n|; - } } - my $js = ''; - my %add_entries = (topmargin => "0", - marginheight => "0",); + $js = ''; if (($env{'form.state'} eq 'listing') && ($numtitles > 0)) { $add_entries{'onLoad'} = 'setElements()'; } &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles); my $cat_maxdepth = $env{'form.catalog_maxdepth'}; $r->print('
'. - ''. - ''. - ''); + ''."\n". + ''."\n". + ''. + &additional_filters($codedom)); if ($numtitles > 0) { - $r->print('
'.&mt('Choose which course(s) to list.').'
'); + $r->print(''.&mt('Choose which course(s) to list.').'
'); $r->print(''); for (my $k=0; $k<$lasttitle-1; $k++) { my (@items,@unsorted); @@ -266,39 +286,32 @@ function setCourseId(caller) { ''."\n". - '' - ); - my $show_selfenroll_status; - if ($env{'form.showselfenroll'}) { - $show_selfenroll_status = 'checked="checked" '; - } - if (&user_is_dc($codedom)) { - my $showdetails_status; - if ($env{'form.showdetails'}) { - $showdetails_status = 'checked="checked" '; - } - $r->print(''); - } else { - $r->print(''); - } - $r->print('


'); + ''."\n"); if ($numtitles > 4) { $r->print('

'.$codetitles[$numtitles-1].'
'."\n". '
'."\n"); } $r->print('
'); } - $r->print(''); - if ($numtitles > 0) { - $r->print(''); - } - $r->print('
'); + $r->print(''."\n". + ''."\n". + ''."\n". + ''."\n". + ''. + ''); if (($numtitles > 0) && ($env{'form.state'} eq 'listing')) { $r->print('
'); } } else { - $r->print('
'.&mt('No official courses to display for [_1].',$domdesc)); + &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles); + my $cat_maxdepth = $env{'form.catalog_maxdepth'}; + $r->print('
'. + ''. + ''. + ''); + $r->print('
'.&mt('No official courses to display for [_1].',$domdesc).'
'); } return $numtitles; } @@ -332,8 +345,8 @@ sub cat_header { '
'. ''.&mt('Domain:').''. &Apache::loncommon::select_dom_form($codedom,'showdom','',1). - ' 
'. - '
'. + ' 
'. + '
'. $catlinks.'
'); return; } @@ -342,17 +355,16 @@ sub category_breadcrumbs { my ($dom) = @_; my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom); - my (@cats,@trails,%allitems,%idx,@jsarray); - &Apache::loncommon::extract_categories($domconfig{'coursecategories'},\@cats,\@trails, - \%allitems,\%idx,\@jsarray); - my $currdepth = 0; - my $deeper = 0; - my $currcat_str; - if ($env{'form.catalog_maxdepth'} ne '') { - $currdepth = $env{'form.catalog_maxdepth'}; - $deeper = $currdepth + 1; + my (@cats,@trails,%allitems,%idx,@jsarray,$cathash); + if (ref($domconfig{'coursecategories'}) eq 'HASH') { + $cathash = $domconfig{'coursecategories'}{'cats'}; + } else { + $cathash = {}; } - $currcat_str = ''; + &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 .= ''; @@ -398,7 +410,7 @@ sub category_breadcrumbs { $catlinks .= ''."\n"; } $catlinks .= ''."\n". - ' '; + ' '; } } else { $catlinks .= &mt('Official courses (with institutional codes)'). @@ -406,7 +418,13 @@ sub category_breadcrumbs { $env{'form.currcat_0'} = 'instcode::0'; } } else { - my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$currdepth}); + 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') { @@ -422,13 +440,62 @@ sub category_breadcrumbs { $catlinks .= ''."\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 = ''; + my $show_selfenroll_status; + if ($env{'form.showselfenroll'}) { + $show_selfenroll_status = 'checked="checked" '; + } + if (&user_is_dc($codedom)) { + my $showdetails_status; + if ($env{'form.showdetails'}) { + $showdetails_status = 'checked="checked" '; + } + my $showhidden_status; + if ($env{'form.showhidden'}) { + $showhidden_status = 'checked="checked" '; + } + my $dc_title = &Apache::lonnet::plaintext('dc'); + $output .= ''; + } + $output .= '
'."\n". + ''."\n".'
'. + ''."\n".'
'. + '

'; + return $output; +} + sub user_is_dc { my ($codedom) = @_; if (exists($env{'user.role.dc./'.$codedom.'/'})) { @@ -549,9 +616,14 @@ sub search_official_courselist { $instcode = '.'; } } - my %courses = &Apache::lonnet::courseiddump($domain,'.',1,$instcode,'.','.', - undef,undef,'Course',1, - $env{'form.showselfenroll'}); + my $showhidden; + if (&user_is_dc($domain)) { + $showhidden = $env{'form.showhidden'}; + } + my %courses = + &Apache::lonnet::courseiddump($domain,'.',1,$instcode,'.','.',undef,undef, + 'Course',1,$env{'form.showselfenroll'},undef, + $showhidden,'coursecatalog'); return %courses; } @@ -559,11 +631,20 @@ sub search_courselist { my ($domain) = @_; my $cat_maxdepth = $env{'form.catalog_maxdepth'}; my $filter = $env{'form.currcat_'.$cat_maxdepth}; + if (($filter eq '') && ($cat_maxdepth > 0)) { + my $shallower = $cat_maxdepth - 1; + $filter = $env{'form.currcat_'.$shallower}; + } my %courses; if ($filter ne '') { - %courses = &Apache::lonnet::courseiddump($domain,'.',1,'.','.','.', - undef,undef,'Course',1, - $env{'form.showselfenroll'},$filter); + my $showhidden; + if (&user_is_dc($domain)) { + $showhidden = $env{'form.showhidden'}; + } + %courses = + &Apache::lonnet::courseiddump($domain,'.',1,'.','.','.',undef,undef, + '.',1,$env{'form.showselfenroll'}, + $filter,$showhidden,'coursecatalog'); } return %courses; } @@ -582,7 +663,7 @@ sub print_course_listing { if ($env{'form.coursenum'} ne '') { %courses = &Apache::lonnet::courseiddump($domain,'.',1,'.','.', $env{'form.coursenum'}, - undef,undef,'Course',1); + undef,undef,'.',1); if (keys(%courses) == 0) { $output .= &mt('The courseID provided does not match a course in this domain.'); return $output; @@ -597,8 +678,10 @@ sub print_course_listing { $output = &mt('No courses match the criteria you selected.'); return $output; } - if ($knownuser && !$env{'form.showdetails'}) { - $output = &mt('Note for students: If you are officially enrolled in a course but the course is not listed in your LON-CAPA courses, click the "Show more details" link for the specific course and check the default access dates and/or automated enrollment settings.

'); + if (($knownuser) && (!$env{'form.showdetails'}) && (!&user_is_dc($domain))) { + $output = ''.&mt('Note for students:').' ' + .&mt('If you are officially enrolled in a course but the course is not listed in your LON-CAPA courses, click the "Show more details" link for the specific course and check the default access dates and/or automated enrollment settings.') + .'

'; } } my $now = time;