--- loncom/interface/lonpickcourse.pm 2009/03/16 16:05:40 1.77
+++ loncom/interface/lonpickcourse.pm 2017/04/08 14:28:56 1.127
@@ -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.127 2017/04/08 14:28:56 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -31,49 +31,107 @@ 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);
+use JSON::DWIW;
sub handler {
my $r = shift;
+ if ($env{'form.context'} eq 'adhoc') {
+ &Apache::loncommon::content_type($r,'application/json');
+ $r->send_http_header;
+ my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($env{'form.cid'},1);
+ if ((ref($possroles) eq 'ARRAY') && (ref($description) eq 'HASH')) {
+ my $response = [];
+ if (@{$possroles}) {
+ foreach my $role (@{$possroles}) {
+ push(@{$response},
+ { name => $role,
+ desc => $description->{$role},
+ });
+ }
+ }
+ $r->print(JSON::DWIW->to_json({roles => $response}));
+ }
+ return OK;
+ }
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
return OK if $r->header_only;
-
+
# ------------------------------------------------------------ Print the screen
# Get parameters from query string
&Apache::loncommon::get_unprocessed_cgi
($ENV{'QUERY_STRING'},['domainfilter','form','cnumelement',
'cdomelement','cnameelement','roleelement',
- 'multiple','type','setroles']);
+ 'multiple','type','setroles','fixeddom','cloner',
+ 'crscode','crsdom']);
+ my ($type,$title,$jscript,$multelement,$multiple,$roleelement,$typeelement,
+ $lastaction,$autosubmit,$submitopener,$cloneruname,$clonerudom,$crscode,
+ $crsdom,$rolechooser);
- my ($type,$title,$jscript,$multelement,$multiple,$roleelement,
- $lastaction,$autosubmit,$submitopener);
-
- # Get course type - Course or Non-standard Course.
+ # Get course type - Course, Community or Placement.
$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
- my $roledom = $env{'form.roleelement'};
+ # if called when a DC, DH or DA 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 (($rolename eq 'dh') || ($rolename eq 'da')) {
+ my %lt = &Apache::lonlocal::texthash(
+ title => 'Ad hoc role selection',
+ preamble => 'Please choose an ad hoc role in the course.',
+ cancel => 'Click "OK" to enter the course, or "Cancel" to choose a different course.',
+ );
+
+ $rolechooser = <<"END";
+
+
$lt{'preamble'}
+
+
$lt{'cancel'}
+
+END
+ }
+ }
+ 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)$/);
+ $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;
@@ -83,11 +141,31 @@ 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()";
+ 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(); ';
}
- $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 +186,136 @@ sub handler {
}
# print javascript functions for choosing a course
- if ($env{'form.gosearch'} || $onlyown) {
- $r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction));
+ if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) ||
+ $onlyown) {
+ $r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction,
+ $rolename,$rolechooser));
}
- $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 .= '';
+ }
+ 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
- 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'},
+ $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].',
+ ''.$filter->{'personfilter'}.'',
+ ''.$filter->{'persondomfilter'}.'').'');
+ } else {
+ &display_matched_courses($r,$type,$multiple,$action,$showroles,$cloneruname,
+ $clonerudom,$crsdom,$crscode,%courses);
+ }
}
$r->print(&Apache::loncommon::end_page());
return OK;
@@ -146,7 +328,7 @@ sub processpick {
}
my $process_pick = <<"ENDONE";
|;
-;
}
return $output;
}
sub display_matched_courses {
- my ($r,$type,$multiple,$action,%courses) = @_;
+ my ($r,$type,$multiple,$action,$showroles,$cloneruname,$clonerudom,$crsdom,$crscode,%courses) = @_;
if ($env{'form.form'} eq 'portform') {
$action = '/adm/portfolio';
}
my $numcourses = keys(%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 = '