--- loncom/interface/lonpickcourse.pm 2013/07/15 14:32:45 1.108
+++ loncom/interface/lonpickcourse.pm 2016/11/02 22:41:18 1.122
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Pick a course
#
-# $Id: lonpickcourse.pm,v 1.108 2013/07/15 14:32:45 bisitz Exp $
+# $Id: lonpickcourse.pm,v 1.122 2016/11/02 22:41:18 raeburn 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 {
@@ -51,11 +50,12 @@ sub handler {
&Apache::loncommon::get_unprocessed_cgi
($ENV{'QUERY_STRING'},['domainfilter','form','cnumelement',
'cdomelement','cnameelement','roleelement',
- 'multiple','type','setroles','fixeddom','cloner']);
+ 'multiple','type','setroles','fixeddom','cloner',
+ 'crscode','crsdom']);
my ($type,$title,$jscript,$multelement,$multiple,$roleelement,$typeelement,
- $lastaction,$autosubmit,$submitopener,$cloneruname,$clonerudom);
+ $lastaction,$autosubmit,$submitopener,$cloneruname,$clonerudom,$crscode,$crsdom);
- # Get course type - Course or Community.
+ # Get course type - Course, Community or Placement.
$type = $env{'form.type'};
if (!defined($env{'form.type'})) {
$type = 'Course';
@@ -69,12 +69,12 @@ sub handler {
$title = 'Selecting '.$type.'(s)';
}
- # if called when a DC is selecting a course
- my $roledom = $env{'form.roleelement'};
+ # if called when a DC or DH is selecting a course
+ my ($roledom,$rolename) = split(/:/,$env{'form.roleelement'});
if ($roledom) {
- $roleelement = '';
+ $roleelement = '';
$submitopener = &processpick();
- $autosubmit = 'process_pick("'.$roledom.'")';
+ $autosubmit = 'process_pick("'.$roledom.'","'.$rolename.'")';
}
if ($env{'form.typeelement'} ne '') {
$typeelement = '';
@@ -83,12 +83,16 @@ sub handler {
# 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)$/);
+ $crscode = $env{'form.crscode'};
+ $crsdom = $env{'request.role.domain'};
}
# if called when requesting a course
if ($env{'form.form'} eq 'requestcrs') {
$cloneruname = $env{'user.name'};
$clonerudom = $env{'user.domain'};
+ $crscode = $env{'form.crscode'};
+ $crsdom = $env{'form.crsdom'};
}
my $onlyown = 0;
@@ -106,9 +110,22 @@ sub handler {
if ((($env{'form.form'} eq 'cu') || ($env{'form.form'} eq 'studentform')) &&
($env{'form.pickedcourse'})) {
- $loaditem{'onload'} .= 'setDefaultCredits();setRoles();setSections();';
+ 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();';
+ }
+ if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) && (!$onlyown)) {
+ $loaditem{'onload'} .= 'hideSearching(); ';
}
- my $js = &js_changer();
+ my $js = &Apache::loncommon::js_changer();
$r->print(&Apache::loncommon::start_page($title,$js,
{'add_entries' => \%loaditem,
'no_nav_bar' => 1, }));
@@ -141,8 +158,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 +171,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 +189,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 +199,46 @@ 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 .= '';
+ }
+ if ($crscode ne '') {
+ $clonetext .= '';
+ }
+ if ($crsdom ne '') {
+ $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 +251,22 @@ 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'},
+ $crsdom,$crscode);
+ } 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].',
@@ -199,29 +274,13 @@ sub handler {
''.$filter->{'persondomfilter'}.'').'');
} else {
&display_matched_courses($r,$type,$multiple,$action,$showroles,$cloneruname,
- $clonerudom,%courses);
+ $clonerudom,$crsdom,$crscode,%courses);
}
}
$r->print(&Apache::loncommon::end_page());
return OK;
}
-sub js_changer {
- return <
-//
-
-
-ENDJS
-}
-
sub processpick {
my $openerform = 'rolechoice';
if ($env{'form.form'} eq 'studentform') {
@@ -229,7 +288,7 @@ sub processpick {
}
my $process_pick = <<"ENDONE";
'."\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/)) {
@@ -859,7 +770,7 @@ sub get_coordinator_cloneable {
my ($cc_clone,$ccrole);
if ($type eq 'Community') {
$ccrole = 'co';
- } elsif ($type eq 'Course') {
+ } else {
$ccrole = 'cc';
}
my %ccroles = &Apache::lonnet::get_my_roles($cloneruname,$clonerudom,
@@ -873,129 +784,6 @@ sub get_coordinator_cloneable {
}
}
-sub instcode_selectors {
- my ($codedom,$formname,$officialjs,$codetitles) = @_;
- my ($output,%cat_titles,%cat_order,%cat_items);
- my ($jscript,$totcodes,$numtitles,$lasttitle) =
- &Apache::courseclassifier::instcode_selectors_data($codedom,$formname,
- \%cat_items,$codetitles,\%cat_titles,\%cat_order,$officialjs);
- if ($numtitles > 0) {
- my $official = ' checked="checked" ';
- my $unofficial = '';
- if ($env{'form.official'} eq 'off') {
- $unofficial = $official;
- $official = '';
- }
- $output .= ''.&mt('Official course:').' '.(' 'x3).'
'.
- &Apache::courseclassifier::build_instcode_selectors($numtitles,
- $lasttitle,\%cat_items,$codetitles,\%cat_titles,\%cat_order)."\n".
- ''."\n".
- ''."\n";
-
- }
- return ($output,$jscript,$numtitles);
-}
-
-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;
@@ -1003,7 +791,7 @@ sub course_chooser {
$output = '