--- loncom/interface/lonpickcourse.pm 2014/03/11 21:42:18 1.110
+++ loncom/interface/lonpickcourse.pm 2014/04/25 17:56:43 1.114
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Pick a course
#
-# $Id: lonpickcourse.pm,v 1.110 2014/03/11 21:42:18 raeburn Exp $
+# $Id: lonpickcourse.pm,v 1.114 2014/04/25 17:56:43 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -36,7 +36,6 @@ use Apache::loncoursedata;
use Apache::lonnet;
use Apache::lonlocal;
use Apache::longroup;
-use Apache::courseclassifier;
use LONCAPA qw(:DEFAULT :match);
sub handler {
@@ -108,7 +107,10 @@ sub handler {
($env{'form.pickedcourse'})) {
$loaditem{'onload'} .= 'setDefaultCredits();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, }));
@@ -141,8 +143,8 @@ sub handler {
my $filter = {};
my $action = '/adm/pickcourse';
my ($numtitles,$showroles,$nohost,@codetitles);
- if (!$onlyown) {
- my $filterlist = ['domainfilter'];
+ 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'}.'/'})
@@ -154,7 +156,15 @@ sub handler {
}
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') {
@@ -164,7 +174,7 @@ sub handler {
}
}
} else {
- push(@{$filterlist},'ownerfilter');
+ push(@{$filterlist},('ownerfilter','ownerdomfilter'));
}
# course ID filter for DCs only
if ($env{'user.adv'} && $env{'form.domainfilter'} &&
@@ -174,10 +184,40 @@ 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,\@codetitles));
+ 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
@@ -190,8 +230,21 @@ sub handler {
$domcloner = 1;
}
}
- my %courses = &search_courses($r,$type,$onlyown,$filter,$numtitles,
- $cloneruname,$clonerudom,$domcloner,\@codetitles);
+ my %courses;
+ if (!$onlyown) {
+ $r->print('
'.&mt('Searching ...').'
');
+ $r->rflush();
+ my $srchdom = $filter->{'domainfilter'};
+ %courses = &Apache::loncommon::search_courses($srchdom,$type,$filter,$numtitles,
+ $cloneruname,$clonerudom,$domcloner,
+ \@codetitles,$env{'form.cc_clone'});
+ } else {
+ $r->print('
');
+ my %coursehash = &Apache::loncommon::findallcourses();
+ foreach my $cid (sort(keys(%coursehash))) {
+ $courses{$cid}{'description'} = $env{'course.'.$cid.'.description'};
+ }
+ }
if ($nohost) {
$r->print (''.
&mt('User does not exist - username: [_1], domain: [_2].',
@@ -206,22 +259,6 @@ sub handler {
return OK;
}
-sub js_changer {
- return <
-//
-
-
-ENDJS
-}
-
sub processpick {
my $openerform = 'rolechoice';
if ($env{'form.form'} eq 'studentform') {
@@ -558,294 +595,6 @@ sub multiples_tag {
return ($jscript,$multelement);
}
-sub build_filters {
- my ($filterlist,$type,$roleelement,$multelement,$filter,$action,
- $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,$codetitlesref) = @_;
- my ($list,$formname,$fixeddom,$codedom,$jscript);
- $codedom = $env{'request.role.domain'};
- if (defined($env{'form.form'})) {
- $formname = $env{'form.form'};
- } else {
- $formname = $caller;
- }
- my $onchange = 'javascript:updateFilters(this)';
- my ($domainselectform,$sincefilterform,$createdfilterform,
- $ownerdomselectform,$persondomselectform,$instcodeform,
- $typeselectform,$instcodetitle);
- foreach my $item (@{$filterlist}) {
- $filter->{$item} = $env{'form.'.$item};
- if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
- if ($item eq 'domainfilter') {
- $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
- } elsif ($item eq 'coursefilter') {
- $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
- } elsif ($item eq 'ownerfilter') {
- $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
- $filter->{'ownerdomfilter'} =
- &LONCAPA::clean_domain($env{'form.ownerdomfilter'});
- $ownerdomselectform =
- &Apache::loncommon::select_dom_form($filter->{'ownerdomfilter'},
- 'ownerdomfilter',1);
- } elsif ($item eq 'personfilter') {
- $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
- if ($env{'form.persondomfilter'} eq '') {
- unless ($env{'form.gosearch'}) {
- $filter->{'persondomfilter'} = $env{'request.role.domain'};
- }
- } else {
- $filter->{'persondomfilter'} =
- &LONCAPA::clean_domain($env{'form.persondomfilter'});
- }
- $persondomselectform =
- &Apache::loncommon::select_dom_form($filter->{'persondomfilter'},
- 'persondomfilter',1);
- } else {
- $filter->{$item} =~ s/\W//g;
- }
- if (!$filter->{$item}) {
- $filter->{$item} = '';
- }
- }
- if ($item eq 'domainfilter') {
- my $allow_blank = 1;
- if ($formname eq 'portform') {
- $filter->{$item} ||= $env{'user.domain'};
- $allow_blank=0;
- } elsif ($formname eq 'studentform') {
- $filter->{$item} ||= $env{'request.role.domain'};
- $allow_blank=0;
- }
- if ($env{'form.fixeddom'}) {
- $domainselectform = ''.
- &Apache::lonnet::domain($env{'request.role.domain'},
- 'description');
- $codedom = $env{'request.role.domain'};
- } else {
- $domainselectform =
- &Apache::loncommon::select_dom_form($filter->{$item},
- 'domainfilter',
- $allow_blank,'',$onchange);
- $codedom = $filter->{'domainfilter'};
- }
- } else {
- $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
- }
- }
-
- # last course activity filter and selection
- $sincefilterform = &timebased_select_form('sincefilter',$filter);
-
- # course created filter and selection
- if (exists($filter->{'createdfilter'})) {
- $createdfilterform = &timebased_select_form('createdfilter',$filter);
- }
-
- my %lt = &Apache::lonlocal::texthash(
- 'cac' => "$type Activity",
- 'ccr' => "$type Created",
- 'cde' => "$type Title",
- 'cdo' => "$type Domain",
- 'ins' => 'Institutional Code',
- 'inc' => 'Institutional Categorization',
- 'cow' => "$type Owner/Co-owner",
- 'cop' => "$type Personnel Includes",
- 'cog' => 'Type',
- );
-
- if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
- my $typeval = 'Course';
- if ($type eq 'Community') {
- $typeval = 'Community';
- }
- $typeselectform = '';
- } else {
- $typeselectform = '";
- }
-
- my ($cloneableonlyform,$cloneabletitle);
- if (exists($filter->{'cloneableonly'})) {
- my $cloneableon = '';
- my $cloneableoff = ' checked="checked"';
- if ($filter->{'cloneableonly'}) {
- $cloneableon = $cloneableoff;
- $cloneableoff = '';
- }
- $cloneableonlyform = ''.(' 'x3).'';
- if ($env{'form.form'} eq 'ccrs') {
- $cloneabletitle = &mt('Cloneable for').' '.$cloneruname.':'.$clonerudom;
- } else {
- $cloneabletitle = &mt('Cloneable by you');
- }
- }
- my $officialjs;
- if ($type eq 'Course') {
- if (exists($filter->{'instcodefilter'})) {
- if (($env{'form.fixeddom'}) || ($formname eq 'requestcrs')
- || ($formname eq 'modifycourse')) {
- $officialjs = 1;
- ($instcodeform,$jscript,$$numtitlesref) =
- &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
- $officialjs,$codetitlesref);
- if ($jscript) {
- $jscript = ''."\n";
- }
- }
- if ($instcodeform eq '') {
- $instcodeform =
- '';
- $instcodetitle = $lt{'ins'};
- } else {
- $instcodetitle = $lt{'inc'};
- }
- if ($env{'form.fixeddom'}) {
- $instcodetitle .= '
('.$codedom.')';
- }
- }
- }
-
- my $output = qq|
-'."\n".'
'."\n";
- return $jscript.$warning.$output;
-}
-
-sub timebased_select_form {
- my ($item,$filter) = @_;
- if (ref($filter) eq 'HASH') {
- $filter->{$item} = $env{'form.'.$item};
- $filter->{$item} =~ s/[^\d-]//g;
- if (!$filter->{$item}) { $filter->{$item}=-1; }
- return &Apache::loncommon::select_form(
- $filter->{$item},
- $item,
- { '-1' => '',
- '86400' => &mt('today'),
- '604800' => &mt('last week'),
- '2592000' => &mt('last month'),
- '7776000' => &mt('last three months'),
- '15552000' => &mt('last six months'),
- '31104000' => &mt('last year'),
- 'select_form_order' =>
- ['-1','86400','604800','2592000','7776000',
- '15552000','31104000']});
- }
-}
-
sub get_coordinator_cloneable {
my ($cloneruname,$clonerudom,$type) = @_;
if (($cloneruname!~/\w/) || ($clonerudom!~/\w/)) {
@@ -874,102 +623,6 @@ sub get_coordinator_cloneable {
}
}
-sub search_courses {
- my ($r,$type,$onlyown,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles) = @_;
- my (%courses,%showcourses,$cloner,$ccrole);
- if ($type eq 'Community') {
- $ccrole = 'co';
- } else {
- $ccrole = 'cc';
- }
- if (!$onlyown) {
- $r->print(''.&mt('Searching ...').'
');
- $r->rflush();
- if (($filter->{'ownerfilter'} ne '') ||
- ($filter->{'ownerdomfilter'} ne '')) {
- $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
- $filter->{'ownerdomfilter'};
- }
- foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
- if (!$filter->{$item}) {
- $filter->{$item}='.';
- }
- }
- my $now = time;
- my $timefilter =
- ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
- my ($createdbefore,$createdafter);
- if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
- $createdbefore = $now;
- $createdafter = $now-$filter->{'createdfilter'};
- }
- my ($instcodefilter,$regexpok);
- if ($numtitles) {
- if ($env{'form.official'} eq 'on') {
- $instcodefilter =
- &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},$numtitles,$codetitles);
- $regexpok = 1;
- } elsif ($env{'form.official'} eq 'off') {
- $instcodefilter = &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},$numtitles,$codetitles);
- unless ($instcodefilter eq '') {
- $regexpok = -1;
- }
- }
- } else {
- $instcodefilter = $filter->{'instcodefilter'};
- }
- if ($instcodefilter eq '') { $instcodefilter = '.'; }
- if ($type eq '') { $type = '.'; }
-
- if (($clonerudom ne '') && ($cloneruname ne '')) {
- $cloner = $cloneruname.':'.$clonerudom;
- }
- %courses =
- &Apache::lonnet::courseiddump($filter->{'domainfilter'},
- $filter->{'descriptfilter'},
- $timefilter,
- $instcodefilter,
- $filter->{'combownerfilter'},
- $filter->{'coursefilter'},
- undef,undef,$type,$regexpok,undef,undef,
- undef,undef,$cloner,$env{'form.cc_clone'},
- $filter->{'cloneableonly'},
- $createdbefore,$createdafter,undef,
- $domcloner);
- if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
- my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
- $filter->{'persondomfilter'},
- 'userroles',undef,
- [$ccrole,'in','ad','ep','ta','cr'],
- $filter->{'domainfilter'});
- foreach my $role (keys(%rolehash)) {
- my ($cnum,$cdom,$courserole) = split(':',$role);
- my $cid = $cdom.'_'.$cnum;
- if (exists($courses{$cid})) {
- if (ref($courses{$cid}) eq 'HASH') {
- if (ref($courses{$cid}{roles}) eq 'ARRAY') {
- if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
- push (@{$courses{$cid}{roles}},$courserole);
- }
- } else {
- $courses{$cid}{roles} = [$courserole];
- }
- $showcourses{$cid} = $courses{$cid};
- }
- }
- }
- %courses = %showcourses;
- }
- } else {
- $r->print('
');
- my %coursehash = &Apache::loncommon::findallcourses();
- foreach my $cid (sort(keys(%coursehash))) {
- $courses{$cid}{'description'} = $env{'course.'.$cid.'.description'};
- }
- }
- return %courses;
-}
-
sub course_chooser {
my ($multiple,$cdom,$cnum,$cleandesc,$canclone) = @_;
my $output;
@@ -977,7 +630,7 @@ sub course_chooser {
$output = '