--- loncom/interface/lonpickcourse.pm 2009/03/16 16:05:40 1.77
+++ loncom/interface/lonpickcourse.pm 2014/03/17 13:38:57 1.113
@@ -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.113 2014/03/17 13:38:57 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -31,11 +31,12 @@ 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 LONCAPA;
+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,$typeelement,
+ $lastaction,$autosubmit,$submitopener,$cloneruname,$clonerudom);
- 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
@@ -75,6 +75,20 @@ sub handler {
$submitopener = &processpick();
$autosubmit = 'process_pick("'.$roledom.'")';
}
+ if ($env{'form.typeelement'} ne '') {
+ $typeelement = '';
+ }
+
+ # 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)$/);
+ }
+
+ # 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
@@ -83,11 +97,21 @@ 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'} .= 'setDefaultCredits();setRoles();setSections();';
+ }
+ if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) && (!$onlyown)) {
+ $loaditem{'onload'} .= 'hideSearching(); ';
}
- $r->print(&Apache::loncommon::start_page($title,undef,
+ my $js = &Apache::loncommon::js_changer();
+ $r->print(&Apache::loncommon::start_page($title,$js,
{'add_entries' => \%loaditem,
'no_nav_bar' => 1, }));
@@ -108,32 +132,128 @@ 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(&Apache::lonhtmlcommon::scripttag($jscript));
$r->print($submitopener);
# ------------------------------------------ Display of filters to limit search
my $filter = {};
my $action = '/adm/pickcourse';
- if (!$onlyown) {
- my $filterlist = ['domainfilter','descriptfilter',
- 'instcodefilter','ownerfilter',
- 'ownerdomfilter'];
+ 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','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') {
+ $nohost = 1;
+ } else {
+ $showroles = 1;
+ }
+ }
+ } else {
+ push(@{$filterlist},('ownerfilter','ownerdomfilter'));
+ }
# 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));
+ if ($cloneruname ne '' && $clonerudom ne '') {
+ push(@{$filterlist},'cloneableonly');
+ }
+ 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'} || $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 $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('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].',
+ ''.$filter->{'personfilter'}.'',
+ ''.$filter->{'persondomfilter'}.'').'');
+ } else {
+ &display_matched_courses($r,$type,$multiple,$action,$showroles,$cloneruname,
+ $clonerudom,%courses);
+ }
}
$r->print(&Apache::loncommon::end_page());
return OK;
@@ -155,7 +275,12 @@ ENDONE
$process_pick .= <<"ENDTWO";
if (pickedDomain == dom) {
if (pickedCourse != '') {
- var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
+ var ccrole = "cc";
+ var pickedType = "$env{'form.type'}";
+ if (pickedType == "Community") {
+ ccrole = "co";
+ }
+ var courseTarget = ccrole+"./"+pickedDomain+"/"+pickedCourse
opener.document.title='Role selected. Please stand by.';
opener.status='Role selected. Please stand by.';
opener.document.rolechoice.newrole.value=courseTarget
@@ -187,7 +312,19 @@ sub create_user_javascript {
my $output;
#javascript for reporting sections and groups then closing
if ($env{'form.pickedcourse'}) {
- my ($cdom,$cnum) = split/_/,$env{'form.pickedcourse'};
+ my %coursedescription =
+ &Apache::lonnet::coursedescription($env{'form.pickedcourse'},
+ {'one_time' => '1'});
+ my $cdom = $coursedescription{'domain'};
+ my $cnum = $coursedescription{'num'};
+ my $crstype = $coursedescription{'type'};
+ my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
+ my ($showcredits,$credits);
+ if (($crstype ne 'Community') &&
+ (($domdefs{'officialcredits'} || $domdefs{'unofficialcredits'} || $domdefs{'textbookcredits'}))) {
+ $showcredits = 1;
+ $credits = $coursedescription{'internal.defaultcredits'};
+ }
my $sec_element = 'currsec';
my $grplist_element = 'groups';
my ($sections,$groups) =
@@ -198,20 +335,33 @@ sub create_user_javascript {
my $groupslist = join(',',@{$groups});
$output = qq|
|;
-;
}
return $output;
}
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';
}
@@ -219,27 +369,37 @@ sub display_matched_courses {
$r->print('\n");
return;
}
-
sub multiples_tag {
my $jscript = &Apache::loncommon::check_uncheck_jscript();
my $multelement = '';
return ($jscript,$multelement);
}
-sub build_filters {
- my ($filterlist,$type,$roleelement,$multelement,$filter,$action,
- $caller) = @_;
- my $list;
- my $formname;
- if (defined($env{'form.form'})) {
- $formname = $env{'form.form'};
+sub get_coordinator_cloneable {
+ my ($cloneruname,$clonerudom,$type) = @_;
+ if (($cloneruname!~/\w/) || ($clonerudom!~/\w/)) {
+ my $warning = ''.&mt('Intended course owner not specified').
+ '
';
+ return ('',$warning);
+ } elsif (&Apache::lonnet::homeserver($cloneruname,$clonerudom) eq 'no_host') {
+ my $warning = ''.&mt('Intended course owner does not exist').
+ '
';
+ return ('',$warning);
} else {
- $formname = $caller;
- }
- my ($domainselectform,$sincefilterform,$ownerdomselectform,
- $instcodeform,$typeselectform);
- foreach my $item (@{$filterlist}) {
- $filter->{$item} = $env{'form.'.$item};
- if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
- if ($item eq 'domainfilter' || $item eq 'ownerdomfilter') {
- $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});
- } 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;
- }
- $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);
- } else {
- $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
+ my ($cc_clone,$ccrole);
+ if ($type eq 'Community') {
+ $ccrole = 'co';
+ } elsif ($type eq 'Course') {
+ $ccrole = 'cc';
+ }
+ my %ccroles = &Apache::lonnet::get_my_roles($cloneruname,$clonerudom,
+ 'userroles',['active'], [$ccrole]);
+ foreach my $key (sort(keys(%ccroles))) {
+ my ($cnum,$cdom,$role) = split(':',$key);
+ $cc_clone .= $cdom.':'.$cnum.'&';
}
+ $cc_clone =~ s/\&$//;
+ return ($cc_clone);
}
-
- # last course activity filter and selection
- $filter->{'sincefilter'} = $env{'form.sincefilter'};
- $filter->{'sincefilter'} =~ s/[^\d-]//g;
- if (!$filter->{'sincefilter'}) { $filter->{'sincefilter'}=-1; }
- $sincefilterform=&Apache::loncommon::select_form($filter->{'sincefilter'},
- 'sincefilter',('-1'=>'',
- '86400' => 'today',
- '604800' => 'last week',
- '2592000' => 'last month',
- '7776000' => 'last three months',
- '15552000' => 'last six months',
- '31104000' => 'last year',
- 'select_form_order' =>
- ['-1','86400','604800','2592000','7776000',
- '15552000','31104000']));
-
- my %lt = (
- '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"),
- 'cog' => &mt('Course Type')
- );
-
- $typeselectform = '";
- my $output = qq|
-'."\n".'
'."\n";
- return $output;
-}
-
-sub search_courses {
- my ($r,$type,$onlyown,$filter) = @_;
- my %courses;
- 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','instcodefilter','coursefilter',
- 'combownerfilter') {
- if (!$filter->{$item}) {
- $filter->{$item}='.';
- }
- }
- if ($type eq '') { $type = '.'; }
- my $timefilter =
- ($filter->{'sincefilter'}==-1?1:time-$filter->{'sincefilter'});
- %courses =
- &Apache::lonnet::courseiddump($filter->{'domainfilter'},
- $filter->{'descriptfilter'},
- $timefilter,
- $filter->{'instcodefilter'},
- $filter->{'combownerfilter'},
- $filter->{'coursefilter'},
- undef,undef,$type);
- } 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) = @_;
+ my ($multiple,$cdom,$cnum,$cleandesc,$canclone) = @_;
my $output;
if ($multiple) {
$output = '