--- loncom/interface/lonpickcourse.pm 2014/04/25 17:56:43 1.114
+++ loncom/interface/lonpickcourse.pm 2017/01/03 17:47:57 1.124
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Pick a course
#
-# $Id: lonpickcourse.pm,v 1.114 2014/04/25 17:56:43 bisitz Exp $
+# $Id: lonpickcourse.pm,v 1.124 2017/01/03 17:47:57 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -37,24 +37,45 @@ use Apache::lonnet;
use Apache::lonlocal;
use Apache::longroup;
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'});
+ 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','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,$rolechooser);
- # Get course type - Course or Community.
+ # Get course type - Course, Community or Placement.
$type = $env{'form.type'};
if (!defined($env{'form.type'})) {
$type = 'Course';
@@ -68,12 +89,31 @@ 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 ($rolename eq 'dh') {
+ 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 = '';
@@ -82,12 +122,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;
@@ -105,7 +149,17 @@ 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(); ';
@@ -134,7 +188,8 @@ sub handler {
# print javascript functions for choosing a course
if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) ||
$onlyown) {
- $r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction));
+ $r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction,
+ $rolename,$rolechooser));
}
$r->print(&Apache::lonhtmlcommon::scripttag($jscript));
$r->print($submitopener);
@@ -210,6 +265,12 @@ sub handler {
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,
@@ -237,7 +298,8 @@ sub handler {
my $srchdom = $filter->{'domainfilter'};
%courses = &Apache::loncommon::search_courses($srchdom,$type,$filter,$numtitles,
$cloneruname,$clonerudom,$domcloner,
- \@codetitles,$env{'form.cc_clone'});
+ \@codetitles,$env{'form.cc_clone'},
+ $crsdom,$crscode);
} else {
$r->print(' ');
my %coursehash = &Apache::loncommon::findallcourses();
@@ -252,7 +314,7 @@ 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());
@@ -266,7 +328,7 @@ sub processpick {
}
my $process_pick = <<"ENDONE";