--- loncom/interface/lonpickcourse.pm 2016/10/05 13:59:46 1.119 +++ 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.119 2016/10/05 13:59:46 raeburn Exp $ +# $Id: lonpickcourse.pm,v 1.127 2017/04/08 14:28:56 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -37,13 +37,32 @@ 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'},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 @@ -53,7 +72,8 @@ sub handler { 'multiple','type','setroles','fixeddom','cloner', 'crscode','crsdom']); my ($type,$title,$jscript,$multelement,$multiple,$roleelement,$typeelement, - $lastaction,$autosubmit,$submitopener,$cloneruname,$clonerudom,$crscode,$crsdom); + $lastaction,$autosubmit,$submitopener,$cloneruname,$clonerudom,$crscode, + $crsdom,$rolechooser); # Get course type - Course, Community or Placement. $type = $env{'form.type'}; @@ -69,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, 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"; + +END + } } if ($env{'form.typeelement'} ne '') { $typeelement = ''; @@ -149,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); @@ -288,7 +328,7 @@ sub processpick { } my $process_pick = <<"ENDONE";