--- loncom/interface/coursecatalog.pm 2008/05/29 04:29:33 1.28 +++ loncom/interface/coursecatalog.pm 2008/07/04 15:40:04 1.34 @@ -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.34 2008/07/04 15:40:04 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; } @@ -328,13 +341,12 @@ sub cat_header { text=>"Select courses"}); $r->print(&Apache::lonhtmlcommon::breadcrumbs('Select courses')); } - $r->print(''. - ''. - '
'.&mt('Domain:').''. + $r->print(''. + ''. + ' 
'.&mt('Domain:').''. &Apache::loncommon::select_dom_form($codedom,'showdom','',1). - ' 
'. '
'. - $catlinks.'
'); + ''.$catlinks.'
'); return; } @@ -342,17 +354,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 .= ''; @@ -371,7 +382,7 @@ sub category_breadcrumbs { 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 { $catlinks .= ''."\n". - ' '; + ' '; } } else { $catlinks .= &mt('Official courses (with institutional codes)'). - ''; + ''; $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 +439,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 +615,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 +630,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 +662,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 +677,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; @@ -777,7 +859,7 @@ sub build_courseinfo_hash { if ( defined($coursehash{'default_enrollment_end_date'}) ) { $endaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_end_date'}); if ($coursehash{'default_enrollment_end_date'} == 0) { - $endaccess = "No ending date"; + $endaccess = &mt('No ending date'); } } if ($startaccess) { @@ -786,6 +868,33 @@ sub build_courseinfo_hash { if ($endaccess) { $accessdates .= &mt('To: ').$endaccess.'
'; } + if (($selfenroll_types ne '') && + ($selfenroll_end > 0 && $selfenroll_end > $now)) { + my ($selfenroll_start_access,$selfenroll_end_access); + if (($coursehash{'default_enrollment_start_date'} ne + $coursehash{'internal.selfenroll_start_access'}) || + ($coursehash{'default_enrollment_end_date'} ne + $coursehash{'internal.selfenroll_end_access'})) { + if ( defined($coursehash{'internal.selfenroll_start_access'}) ) { + $selfenroll_start_access = &Apache::lonlocal::locallocaltime($coursehash{'internal.selfenroll_start_access'}); + } + if ( defined($coursehash{'default_enrollment_end_date'}) ) { + $selfenroll_end_access = &Apache::lonlocal::locallocaltime($coursehash{'internal.selfenroll_end_access'}); + if ($coursehash{'internal.selfenroll_end_access'} == 0) { + $selfenroll_end_access = &mt('No ending date'); + } + } + if ($selfenroll_start_access || $selfenroll_end_access) { + $accessdates .= '

'.&mt('Self-enrollers:').'
'; + if ($selfenroll_start_access) { + $accessdates .= &mt('From: ').$selfenroll_start_access.'
'; + } + if ($selfenroll_end_access) { + $accessdates .= &mt('To: ').$selfenroll_end_access.'
'; + } + } + } + } $courseinfo{$course}{'access'} = $accessdates; } if ($xlist_items eq '') {