--- loncom/interface/lonpickcourse.pm 2008/01/20 22:47:37 1.67.2.3
+++ loncom/interface/lonpickcourse.pm 2009/08/19 19:51:22 1.86
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Pick a course
#
-# $Id: lonpickcourse.pm,v 1.67.2.3 2008/01/20 22:47:37 raeburn Exp $
+# $Id: lonpickcourse.pm,v 1.86 2009/08/19 19:51:22 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -35,7 +35,8 @@ use Apache::loncoursedata;
use Apache::lonnet;
use Apache::lonlocal;
use Apache::longroup;
-use LONCAPA;
+use Apache::courseclassifier;
+use LONCAPA qw(:DEFAULT :match);
sub handler {
my $r = shift;
@@ -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','cloner']);
my ($type,$title,$jscript,$multelement,$multiple,$roleelement,
- $lastaction,$autosubmit,$submitopener);
+ $lastaction,$autosubmit,$submitopener,$cloneruname,$clonerudom);
- # 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
@@ -76,6 +76,17 @@ sub handler {
$autosubmit = 'process_pick("'.$roledom.'")';
}
+ # if called when a DC is creating a course
+ if ($env{'form.form'} eq 'ccrs') {
+ ($cloneruname,$clonerudom) = ($env{'form.cloner'} =~ /^($match_username):($match_domain)$/);
+ }
+
+ # if called when requesting a course
+ if ($env{'form.form'} eq 'requestcrs') {
+ $cloneruname = $env{'user.name'};
+ $clonerudom = $env{'user.domain'};
+ }
+
my $onlyown = 0;
# if called to assign course-based portfolio access control
if ((($env{'form.form'} eq 'portform') && (!$env{'user.adv'}))) {
@@ -83,11 +94,18 @@ sub handler {
}
my %loaditem;
+ if (($env{'form.type'} eq 'Course') && ($env{'form.numtitles'})) {
+ if (($env{'form.official'} eq 'on') && ($env{'form.state'} eq 'listing')) {
+ $loaditem{'onload'} = 'setElements(document.filterpicker); ';
+ }
+ }
+
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,
+ my $js = &js_changer();
+ $r->print(&Apache::loncommon::start_page($title,$js,
{'add_entries' => \%loaditem,
'no_nav_bar' => 1, }));
@@ -108,37 +126,84 @@ sub handler {
}
# print javascript functions for choosing a course
- if ($env{'form.gosearch'} || $onlyown) {
+ if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) ||
+ $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');
}
+ if ($cloneruname ne '' && $clonerudom ne '') {
+ push(@{$filterlist},'cloneableonly');
+ }
+
$r->print(&build_filters($filterlist,$type,$roleelement,$multelement,
- $filter,$action));
+ $filter,$action,\$numtitles,undef,$cloneruname,
+ $clonerudom));
}
# ---------------------------------------------------------------- Get the data
- if ($env{'form.gosearch'} || $onlyown) {
- my %courses = &search_courses($r,$type,$onlyown,$filter);
- &display_matched_courses($r,$type,$multiple,$action,%courses);
+ if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) ||
+ $onlyown) {
+ my %courses = &search_courses($r,$type,$onlyown,$filter,$numtitles,
+ $cloneruname,$clonerudom);
+ 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,$cloneruname,
+ $clonerudom,%courses);
+ }
}
$r->print(&Apache::loncommon::end_page());
return OK;
}
+sub js_changer {
+ return <<"ENDJS";
+
+
+ENDJS
+
+}
+
sub processpick {
my $openerform = 'rolechoice';
if ($env{'form.form'} eq 'studentform') {
@@ -211,7 +276,7 @@ function setSections() {
}
sub display_matched_courses {
- my ($r,$type,$multiple,$action,%courses) = @_;
+ my ($r,$type,$multiple,$action,$showroles,$cloneruname,$clonerudom,%courses) = @_;
if ($env{'form.form'} eq 'portform') {
$action = '/adm/portfolio';
}
@@ -228,14 +293,19 @@ sub display_matched_courses {
$menuchk = ' checked="checked" ';
}
$r->print(
- ''.(' 'x3).'
'.
- '
');
+ '
'
+ .'
'
+ );
}
}
my %by_descrip;
@@ -251,6 +321,7 @@ sub display_matched_courses {
my $description = $descr;
push (@{$by_descrip{$description}}, $course);
}
+
if ($numcourses > 1 && $multiple) {
$r->print('
@@ -258,16 +329,50 @@ sub display_matched_courses {
onclick="javascript:uncheckAll(document.courselist.course_id)" />
');
}
+
+ if (%courses) {
+ $r->print(&Apache::loncommon::start_data_table());
+ $r->print(&Apache::loncommon::start_data_table_header_row());
+ $r->print(''.&mt('Select').' | '
+ .''.&mt('Course Title').' | '
+ .''.&mt('Domain').' | '
+ .''.&mt('Course Code').' | '
+ .''.&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))) {
foreach my $course (@{$by_descrip{$description}}) {
+ $r->print(&Apache::loncommon::start_data_table_row());
my $cleandesc=&HTML::Entities::encode($description,'<>&"');
$cleandesc=~s/'/\\'/g;
my ($cdom,$cnum)=split(/\_/,$course);
- my ($descr,$instcode,$ttype,@owners);
+ my ($descr,$instcode,$ttype,$canclone,@owners);
if (ref($courses{$course}) eq 'HASH') {
$descr = $courses{$course}{'description'};
- $instcode = $courses{$course}{'inst_code'};
- $ttype = $courses{$course}{'type'};
+ $instcode = $courses{$course}{'inst_code'};
+ $ttype = $courses{$course}{'type'};
+ if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
+ my $cloners = $courses{$course}{'cloners'};
+ if ($cloners ne '') {
+ my @cloneable = split(',',$cloners);
+ if (grep(/^\*$/,@cloneable)) {
+ $canclone = 1;
+ }
+ if (grep(/^\*:\Q$env{'form.clonerudom'}\E$/,@cloneable)) {
+ $canclone = 1;
+ }
+ if (grep(/^\Q$cloneruname\E:\Q$clonerudom\E$/,@cloneable)) {
+ $canclone = 1;
+ }
+ }
+ }
push(@owners,&unescape($courses{$course}{'owner'}));
if (ref($courses{$course}{'co-owners'}) eq 'ARRAY') {
foreach my $item (@{$courses{$course}{'co-owners'}}) {
@@ -279,26 +384,54 @@ sub display_matched_courses {
($descr,$instcode,$singleowner,$ttype)=split(/:/,$courses{$course});
push(@owners,&unescape($singleowner));
}
- my $owner = join(', ',@owners);
- $r->print(&course_chooser($multiple,$cdom,$cnum,$cleandesc));
- $r->print($description.' ('.
- (&Apache::lonnet::domain($cdom,'description')?
- &Apache::lonnet::domain($cdom,'description'):$cdom).")");
+ my $ownerstr = join(', ',@owners);
+ $r->print(''.&course_chooser($multiple,$cdom,$cnum,$cleandesc,$canclone).' | ');
+ $r->print(''.$description.' | ');
+ $r->print('');
+ $r->print(&Apache::lonnet::domain($cdom,'description')?
+ $cdom.' ('.&Apache::lonnet::domain($cdom,'description').')':$cdom);
+ $r->print(' | ');
+ $r->print('');
if ($instcode ne '') {
- $r->print(" - ".&unescape($instcode));
- }
- if (@owners > 1) {
- $r->print(', '.&mt('owners').' - ',join(', ',@owners));
- } elsif (@owners == 1) {
- $r->print(', '.&mt('owner').' - '.$owner);
+ $r->print(&unescape($instcode));
+ } else {
+ $r->print(' ');
}
+ $r->print(' | ');
+ $r->print(''.$ownerstr.' | ');
+ $r->print('');
if ($ttype ne '') {
- $r->print(' ('.&unescape($ttype).')');
+ $r->print(&mt(&unescape($ttype)));
+ } else {
+ $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("
\n");
+ $r->print(&Apache::loncommon::end_data_table_row());
+ # $r->print("
\n");
}
}
+ if (%courses) {
+ $r->print(&Apache::loncommon::end_data_table());
+ }
+
if (!%courses) {
$r->print(&mt('None found'));
} elsif ($multiple) {
@@ -317,18 +450,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 = '';
@@ -337,25 +477,47 @@ sub multiples_tag {
sub build_filters {
my ($filterlist,$type,$roleelement,$multelement,$filter,$action,
- $caller) = @_;
- my $list;
- my $formname;
+ $numtitlesref,$caller,$cloneruname,$clonerudom) = @_;
+ my ($list,$formname,$fixeddom,$codedom,$jscript);
+ $codedom = $env{'request.role.domain'};
if (defined($env{'form.form'})) {
- $formname = $env{'form.form'};
+ $formname = $env{'form.form'};
} else {
- $formname = $caller;
+ $formname = $caller;
+ }
+ my $onchange;
+ unless ($env{'form.interface'} eq 'textual') {
+ $onchange = 'javascript:updateFilters(this)';
}
- 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;
}
@@ -372,13 +534,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,'',$onchange);
+ $codedom = $filter->{'domainfilter'};
+ }
} else {
$list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
}
@@ -401,24 +569,67 @@ sub build_filters {
'15552000','31104000']));
my %lt = (
- 'cac' => &mt('[_1] Activity',$type),
- 'cde' => &mt('[_1] Description',$type),
- 'cdo' => &mt('[_1] Domain',$type),
- 'cin' => &mt('Course Institutional Code'),
- 'cow' => &mt("[_1] Owner's Username",$type),
- 'cod' => &mt("[_1] Owner's Domain", $type),
- 'cog' => &mt('Course Type')
+ 'cac' => &mt("$type Activity"),
+ 'cde' => &mt("$type Title"),
+ 'cdo' => &mt("$type Domain"),
+ 'ins' => &mt('Institutional Code'),
+ 'inc' => &mt('Institutional Categorization'),
+ 'cow' => &mt("$type Owner/Co-owner"),
+ 'cop' => &mt("$type Personnel Includes"),
+ 'cog' => &mt('Type')
);
- $typeselectform = '