--- loncom/interface/lonpickcourse.pm 2009/03/16 16:05:40 1.77
+++ loncom/interface/lonpickcourse.pm 2009/07/25 23:16:04 1.83
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Pick a course
#
-# $Id: lonpickcourse.pm,v 1.77 2009/03/16 16:05:40 bisitz Exp $
+# $Id: lonpickcourse.pm,v 1.83 2009/07/25 23:16:04 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -35,6 +35,7 @@ use Apache::loncoursedata;
use Apache::lonnet;
use Apache::lonlocal;
use Apache::longroup;
+use Apache::courseclassifier;
use LONCAPA;
sub handler {
@@ -49,23 +50,22 @@ sub handler {
&Apache::loncommon::get_unprocessed_cgi
($ENV{'QUERY_STRING'},['domainfilter','form','cnumelement',
'cdomelement','cnameelement','roleelement',
- 'multiple','type','setroles']);
-
+ 'multiple','type','setroles','fixeddom']);
my ($type,$title,$jscript,$multelement,$multiple,$roleelement,
$lastaction,$autosubmit,$submitopener);
- # Get course type - Course or Non-standard Course.
+ # Get course type - Course or Community.
$type = $env{'form.type'};
if (!defined($env{'form.type'})) {
$type = 'Course';
}
- $title = &mt('Selecting a [_1]',$type);
+ $title = 'Selecting a '.$type;
# Setup for multiple course selections, if flag for multiples set.
$multiple = $env{'form.multiple'};
if ($multiple) {
($jscript,$multelement) = &multiples_tag();
- $title = &mt('Selecting [_1](s)',lc($type));
+ $title = 'Selecting '.$type.'(s)';
}
# if called when a DC is selecting a course
@@ -83,9 +83,13 @@ sub handler {
}
my %loaditem;
+ if ($env{'form.numtitles'}) {
+ $loaditem{'onload'} = 'setElements(); ';
+ }
+
if ((($env{'form.form'} eq 'cu') || ($env{'form.form'} eq 'studentform')) &&
($env{'form.pickedcourse'})) {
- $loaditem{'onload'} ="setSections()";
+ $loaditem{'onload'} .= 'setSections()';
}
$r->print(&Apache::loncommon::start_page($title,undef,
{'add_entries' => \%loaditem,
@@ -111,29 +115,50 @@ sub handler {
if ($env{'form.gosearch'} || $onlyown) {
$r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction));
}
- $r->print('');
+ $r->print('');
$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','ownerfilter',
- 'ownerdomfilter'];
+ 'instcodefilter'];
+ if ($env{'form.form'} eq 'rules') {
+ push(@{$filterlist},'personfilter');
+ if (($env{'form.personfilter'} ne '') && ($env{'form.persondomfilter'} ne '')) {
+ if (&Apache::lonnet::homeserver($env{'form.personfilter'},
+ $env{'form.persondomfilter'}) eq 'no_host') {
+ $nohost = 1;
+ } else {
+ $showroles = 1;
+ }
+ }
+ } else {
+ push(@{$filterlist},'ownerfilter');
+ }
# course ID filter for DCs only
if ($env{'user.adv'} && $env{'form.domainfilter'} &&
exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})) {
push(@{$filterlist},'coursefilter');
}
$r->print(&build_filters($filterlist,$type,$roleelement,$multelement,
- $filter,$action));
+ $filter,$action,\$numtitles));
}
# ---------------------------------------------------------------- Get the data
if ($env{'form.gosearch'} || $onlyown) {
- my %courses = &search_courses($r,$type,$onlyown,$filter);
- &display_matched_courses($r,$type,$multiple,$action,%courses);
+ my %courses = &search_courses($r,$type,$onlyown,$filter,$numtitles);
+ if ($nohost) {
+ $r->print (''.
+ &mt('User does not exist - username: [_1], domain: [_2].',
+ ''.$filter->{'personfilter'}.'',
+ ''.$filter->{'persondomfilter'}.'').'');
+ } else {
+ &display_matched_courses($r,$type,$multiple,$action,$showroles,%courses);
+ }
}
$r->print(&Apache::loncommon::end_page());
return OK;
@@ -211,7 +236,7 @@ function setSections() {
}
sub display_matched_courses {
- my ($r,$type,$multiple,$action,%courses) = @_;
+ my ($r,$type,$multiple,$action,$showroles,%courses) = @_;
if ($env{'form.form'} eq 'portform') {
$action = '/adm/portfolio';
}
@@ -275,6 +300,11 @@ sub display_matched_courses {
.'
'.&mt('Owner/Co-owner(s)').' | '
.''.&mt('Type').' | '
);
+ if ($showroles) {
+ $r->print(''.&mt("Role(s) for [_1]",
+ &Apache::loncommon::plainname($env{'form.personfilter'},
+ $env{'form.persondomfilter'},'firstname')).' | ');
+ }
$r->print(&Apache::loncommon::end_data_table_header_row());
}
foreach my $description (sort { lc($a) cmp lc($b) } (keys(%by_descrip))) {
@@ -321,6 +351,23 @@ sub display_matched_courses {
$r->print(' ');
}
$r->print('');
+ if ($showroles) {
+ $r->print('');
+ my $rolestr;
+ if (ref($courses{$course}{'roles'}) eq 'ARRAY') {
+ my @roles = sort(@{$courses{$course}{'roles'}});
+ foreach my $role (@roles) {
+ if ($role =~ /^cr/) {
+ my (undef,$crdom,$crname,$crtitle) = split('/',$role);
+ $rolestr .= $crtitle.', ';
+ } else {
+ $rolestr .= &Apache::lonnet::plaintext($role,$ttype).', ';
+ }
+ }
+ $rolestr =~ s/\, $//;
+ }
+ $r->print($rolestr.' | ');
+ }
if ($multiple) { $r->print("\n"); }
$r->print(&Apache::loncommon::end_data_table_row());
# $r->print("
\n");
@@ -348,18 +395,25 @@ sub display_matched_courses {
$r->print('');
$r->print('');
} elsif ($env{'form.form'} eq 'modifycourse') {
- $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form']));
+ $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form','numtitles','state']));
} else {
$r->print(''."\n".
''."\n");
}
+ if ((exists($env{'form.fixeddom'})) && ($env{'form.form'} eq 'rules')) {
+ $r->print('');
+ }
+ if ($env{'form.numtitles'}) {
+ $r->print('');
+ }
$r->print("\n");
return;
}
-
sub multiples_tag {
my $jscript = &Apache::loncommon::check_uncheck_jscript();
my $multelement = '';
@@ -368,25 +422,44 @@ sub multiples_tag {
sub build_filters {
my ($filterlist,$type,$roleelement,$multelement,$filter,$action,
- $caller) = @_;
+ $numtitlesref,$caller) = @_;
my $list;
my $formname;
+ my ($fixeddom,$codedom,$jscript);
if (defined($env{'form.form'})) {
- $formname = $env{'form.form'};
+ $formname = $env{'form.form'};
} else {
- $formname = $caller;
+ $formname = $caller;
}
- my ($domainselectform,$sincefilterform,$ownerdomselectform,
- $instcodeform,$typeselectform);
+ my ($domainselectform,$sincefilterform,$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' || $item eq 'ownerdomfilter') {
+ 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;
}
@@ -403,13 +476,19 @@ sub build_filters {
$filter->{$item} ||= $env{'request.role.domain'};
$allow_blank=0;
}
- $domainselectform =
- &Apache::loncommon::select_dom_form($filter->{$item},
- 'domainfilter',
- $allow_blank);
- } elsif ($item eq 'ownerdomfilter') {
- $ownerdomselectform =
- &Apache::loncommon::select_dom_form($filter->{$item},'ownerdomfilter',1);
+ 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);
+ $codedom = $filter->{'domainfilter'};
+ }
} else {
$list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
}
@@ -435,19 +514,38 @@ sub build_filters {
'cac' => &mt("$type Activity"),
'cde' => &mt("$type Title"),
'cdo' => &mt("$type Domain"),
- 'cin' => &mt('Course Institutional Code'),
- 'cow' => &mt("$type Owner's Username"),
- 'cod' => &mt("$type Owner's Domain"),
+ 'ins' => &mt('Institutional Code'),
+ 'inc' => &mt('Institutional Categorization'),
+ 'cow' => &mt("$type Owner/Co-owner"),
+ 'cop' => &mt("$type Personnel Includes"),
'cog' => &mt('Course Type')
);
$typeselectform = '