--- loncom/interface/lonpickcourse.pm 2009/11/04 14:12:19 1.90 +++ loncom/interface/lonpickcourse.pm 2014/05/30 01:50:05 1.115 @@ -1,7 +1,7 @@ # The LearningOnline Network # Pick a course # -# $Id: lonpickcourse.pm,v 1.90 2009/11/04 14:12:19 raeburn Exp $ +# $Id: lonpickcourse.pm,v 1.115 2014/05/30 01:50:05 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -31,11 +31,11 @@ package Apache::lonpickcourse; use strict; use Apache::Constants qw(:common); use Apache::loncommon; +use Apache::lonhtmlcommon; use Apache::loncoursedata; use Apache::lonnet; use Apache::lonlocal; use Apache::longroup; -use Apache::courseclassifier; use LONCAPA qw(:DEFAULT :match); sub handler { @@ -79,7 +79,7 @@ sub handler { $typeelement = ''; } - # if called when a DC is creating a course + # if called when a DC is creating a course for another user. if ($env{'form.form'} eq 'ccrs') { ($cloneruname,$clonerudom) = ($env{'form.cloner'} =~ /^($match_username):($match_domain)$/); } @@ -105,9 +105,22 @@ sub handler { if ((($env{'form.form'} eq 'cu') || ($env{'form.form'} eq 'studentform')) && ($env{'form.pickedcourse'})) { + if ($type ne 'Community') { + my %coursedescription = + &Apache::lonnet::coursedescription($env{'form.pickedcourse'}, + {'one_time' => '1'}); + my $cdom = $coursedescription{'domain'}; + my %domdefs = &Apache::lonnet::get_domain_defaults($cdom); + if (($domdefs{'officialcredits'} || $domdefs{'unofficialcredits'} || $domdefs{'textbookcredits'})) { + $loaditem{'onload'} .= 'setDefaultCredits();'; + } + } $loaditem{'onload'} .= 'setRoles();setSections();'; } - my $js = &js_changer(); + if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) && (!$onlyown)) { + $loaditem{'onload'} .= 'hideSearching(); '; + } + my $js = &Apache::loncommon::js_changer(); $r->print(&Apache::loncommon::start_page($title,$js, {'add_entries' => \%loaditem, 'no_nav_bar' => 1, })); @@ -133,19 +146,35 @@ sub handler { $onlyown) { $r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction)); } - $r->print(''); + $r->print(&Apache::lonhtmlcommon::scripttag($jscript)); $r->print($submitopener); # ------------------------------------------ Display of filters to limit search my $filter = {}; my $action = '/adm/pickcourse'; - my ($numtitles,$showroles,$nohost); - if (!$onlyown) { - my $filterlist = ['domainfilter','descriptfilter', - 'instcodefilter']; + my ($numtitles,$showroles,$nohost,@codetitles); + unless ($onlyown) { + my $filterlist = ['domainfilter','sincefilter']; + # created filter for DCs only + if ($env{'user.adv'} && $env{'form.domainfilter'} && + exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'}) + && $env{'form.form'} ne 'portform') { + my $loncaparev = &Apache::lonnet::get_server_loncaparev($env{'form.domainfilter'}); + if ($loncaparev ne 'unknown_cmd') { + push(@{$filterlist},'createdfilter'); + } + } + push(@{$filterlist},('descriptfilter','instcodefilter')); if ($env{'form.form'} eq 'rules') { - push(@{$filterlist},'personfilter'); + push(@{$filterlist},('personfilter','persondomfilter')); + if ($env{'form.persondomfilter'} eq '') { + unless ($env{'form.gosearch'}) { + $filter->{'persondomfilter'} = $env{'request.role.domain'}; + } + } else { + $filter->{'persondomfilter'} = + &LONCAPA::clean_domain($env{'form.persondomfilter'}); + } if (($env{'form.personfilter'} ne '') && ($env{'form.persondomfilter'} ne '')) { if (&Apache::lonnet::homeserver($env{'form.personfilter'}, $env{'form.persondomfilter'}) eq 'no_host') { @@ -155,7 +184,7 @@ sub handler { } } } else { - push(@{$filterlist},'ownerfilter'); + push(@{$filterlist},('ownerfilter','ownerdomfilter')); } # course ID filter for DCs only if ($env{'user.adv'} && $env{'form.domainfilter'} && @@ -165,17 +194,67 @@ sub handler { if ($cloneruname ne '' && $clonerudom ne '') { push(@{$filterlist},'cloneableonly'); } - - $r->print(&build_filters($filterlist,$type,$roleelement,$multelement, - $filter,$action,\$numtitles,undef,$cloneruname, - $clonerudom,$typeelement)); + if ((ref($filterlist) eq 'ARRAY') && (ref($filter) eq 'HASH')) { + foreach my $item (@{$filterlist}) { + $filter->{$item} = $env{'form.'.$item}; + } + } + if ($env{'form.form'} eq 'portform') { + $filter->{'domainfilter'} ||= $env{'user.domain'}; + } elsif ($env{'form.form'} eq 'studentform') { + $filter->{'domainfilter'} ||= $env{'request.role.domain'}; + } + my $codedom; + if ($env{'form.fixeddom'}) { + $codedom = $env{'request.role.domain'}; + } else { + $codedom = $filter->{'domainfilter'}; + } + my ($clonetext,$clonewarning); + if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) { + (my $coord_cloneable,$clonewarning) = + &get_coordinator_cloneable($cloneruname,$clonerudom,$type); + if ($env{'form.form'} eq 'ccrs') { + $clonetext = ''."\n"; + } + if ($coord_cloneable) { + $clonetext .= ''; + } + } + $r->print(&Apache::loncommon::build_filters($filterlist,$type,$roleelement,$multelement, + $filter,$action,\$numtitles,undef,$cloneruname, + $clonerudom,$typeelement,\@codetitles,$codedom, + $env{'form.form'},$env{'form.fixeddom'}, + $env{'form.prevphase'},$env{'form.cnameelement'}, + $env{'form.cnumelement'},$env{'form.cdomelement'}, + $env{'form.setroles'},$clonetext,$clonewarning)); } # ---------------------------------------------------------------- Get the data if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) || $onlyown) { - my %courses = &search_courses($r,$type,$onlyown,$filter,$numtitles, - $cloneruname,$clonerudom); + my $domcloner; + if ($env{'form.form'} eq 'ccrs') { + if (($env{'request.role.domain'} eq $env{'form.domainfilter'}) && + (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) { + $domcloner = 1; + } + } + my %courses; + if (!$onlyown) { + $r->print('
'.&mt('None found').'
'; - my $warning; - if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) { - my $cloneruhome=&Apache::lonnet::homeserver($cloneruname,$clonerudom); - my $cc_clone; - if ($cloneruhome eq 'no_host') { - $warning = '