version 1.122, 2016/11/02 22:41:18
|
version 1.126, 2017/01/28 03:48:44
|
Line 37 use Apache::lonnet;
|
Line 37 use Apache::lonnet;
|
use Apache::lonlocal; |
use Apache::lonlocal; |
use Apache::longroup; |
use Apache::longroup; |
use LONCAPA qw(:DEFAULT :match); |
use LONCAPA qw(:DEFAULT :match); |
|
use JSON::DWIW; |
|
|
sub handler { |
sub handler { |
my $r = shift; |
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'); |
&Apache::loncommon::content_type($r,'text/html'); |
$r->send_http_header; |
$r->send_http_header; |
return OK if $r->header_only; |
return OK if $r->header_only; |
|
|
# ------------------------------------------------------------ Print the screen |
# ------------------------------------------------------------ Print the screen |
|
|
# Get parameters from query string |
# Get parameters from query string |
Line 53 sub handler {
|
Line 72 sub handler {
|
'multiple','type','setroles','fixeddom','cloner', |
'multiple','type','setroles','fixeddom','cloner', |
'crscode','crsdom']); |
'crscode','crsdom']); |
my ($type,$title,$jscript,$multelement,$multiple,$roleelement,$typeelement, |
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. |
# Get course type - Course, Community or Placement. |
$type = $env{'form.type'}; |
$type = $env{'form.type'}; |
Line 69 sub handler {
|
Line 89 sub handler {
|
$title = 'Selecting '.$type.'(s)'; |
$title = 'Selecting '.$type.'(s)'; |
} |
} |
|
|
# if called when a DC or DH is selecting a course |
# if called when a DC, DH or DA is selecting a course |
my ($roledom,$rolename) = split(/:/,$env{'form.roleelement'}); |
my ($roledom,$rolename) = split(/:/,$env{'form.roleelement'}); |
if ($roledom) { |
if ($roledom) { |
$roleelement = '<input type="hidden" name="roleelement" value="'.$env{'form.roleelement'}.'" />'; |
$roleelement = '<input type="hidden" name="roleelement" value="'.$env{'form.roleelement'}.'" />'; |
$submitopener = &processpick(); |
$submitopener = &processpick(); |
$autosubmit = 'process_pick("'.$roledom.'","'.$rolename.'")'; |
$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"; |
|
<div id="LC_adhocrole_chooser" title="$lt{'title'}"> |
|
<p>$lt{'preamble'}</p> |
|
<form name="LChelpdeskadhoc" id="LChelpdeskpicker" action=""> |
|
<div id="LC_choose_adhoc"> |
|
</div> |
|
<input type="submit" tabindex="-1" style="position:absolute; top:-1000px" /> |
|
</form> |
|
<p>$lt{'cancel'}</p> |
|
</div> |
|
END |
|
} |
} |
} |
if ($env{'form.typeelement'} ne '') { |
if ($env{'form.typeelement'} ne '') { |
$typeelement = '<input type="hidden" name="typeelement" value="'.$env{'form.typeelement'}.'" />'; |
$typeelement = '<input type="hidden" name="typeelement" value="'.$env{'form.typeelement'}.'" />'; |
Line 149 sub handler {
|
Line 188 sub handler {
|
# print javascript functions for choosing a course |
# print javascript functions for choosing a course |
if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) || |
if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) || |
$onlyown) { |
$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(&Apache::lonhtmlcommon::scripttag($jscript)); |
$r->print($submitopener); |
$r->print($submitopener); |
Line 400 sub display_matched_courses {
|
Line 440 sub display_matched_courses {
|
$action = '/adm/portfolio'; |
$action = '/adm/portfolio'; |
} |
} |
my $numcourses = keys(%courses); |
my $numcourses = keys(%courses); |
$r->print('<form name="courselist" method="post" action="'.$action.'">'); |
$r->print('<form name="courselist" method="post" action="'.$action.'" id="LCcoursepicker">'); |
if ($env{'form.form'} eq 'modifycourse') { |
if ($env{'form.form'} eq 'modifycourse') { |
if ($numcourses > 0) { |
if ($numcourses > 0) { |
my $ccrole = 'cc'; |
my $ccrole = 'cc'; |
Line 429 sub display_matched_courses {
|
Line 469 sub display_matched_courses {
|
$r->print(&mt('Enter the course with the role of [_1].',$cctitle)); |
$r->print(&mt('Enter the course with the role of [_1].',$cctitle)); |
} |
} |
} elsif (&Apache::lonnet::allowed('rar',$crsdom)) { |
} elsif (&Apache::lonnet::allowed('rar',$crsdom)) { |
my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'}, |
my ($roles_by_num,$description,$accessref,$accessinfo) = &Apache::lonnet::get_all_adhocroles($crsdom); |
'adhocroles.'.$crsdom); |
if ((ref($roles_by_num) eq 'ARRAY') && (ref($description) eq 'HASH')) { |
if ($adhocroles{'adhocroles.'.$crsdom} ne '') { |
if (@{$roles_by_num} > 1) { |
$possrole = 1; |
$r->print($roleradio); |
$r->print($roleradio); |
|
my @adhoc = split(/,/,$adhocroles{'adhocroles.'.$crsdom}); |
|
if (@adhoc > 1) { |
|
my %adhochash; |
|
map { $adhochash{$_} = $_; } @adhoc; |
|
my $selector = &Apache::loncommon::select_form($adhoc[0],'adhocrole',\%adhochash); |
|
if ($type eq 'Community') { |
if ($type eq 'Community') { |
$r->print(&mt('Enter the community with one of the available ad hoc roles: [_1].', |
$r->print(&mt('Enter the community with one of the available ad hoc roles.')); |
$selector)); |
|
} elsif ($type eq 'Placement') { |
} elsif ($type eq 'Placement') { |
$r->print(&mt('Enter the placement test with one of the available ad hoc roles: [_1].', |
$r->print(&mt('Enter the placement test with one of the available ad hoc roles.')); |
$selector)); |
|
} else { |
} else { |
$r->print(&mt('Enter the course with one of the available ad hoc roles: [_1].', |
$r->print(&mt('Enter the course with one of the available ad hoc roles.')); |
$selector)); |
|
} |
} |
} else { |
$possrole = 1; |
|
} elsif (@{$roles_by_num} == 1) { |
|
$r->print($roleradio); |
|
my $rolename = $description->{$roles_by_num->[0]}; |
if ($type eq 'Community') { |
if ($type eq 'Community') { |
$r->print(&mt('Enter the community with the ad hoc role of: [_1]',$adhoc[0])); |
$r->print(&mt('Enter the community with the ad hoc role of: [_1]',$rolename)); |
} elsif ($type eq 'Placement') { |
} elsif ($type eq 'Placement') { |
$r->print(&mt('Enter the placement test with the ad hoc role of: [_1]',$adhoc[0])); |
$r->print(&mt('Enter the placement test with the ad hoc role of: [_1]',$rolename)); |
} else { |
} else { |
$r->print(&mt('Enter the course with the ad hoc role of: [_1]',$adhoc[0])); |
$r->print(&mt('Enter the course with the ad hoc role of: [_1]',$rolename)); |
} |
} |
$r->print('<input type="hidden" name="adhocrole" value="'.$adhoc[0].'" />'); |
$possrole = 1; |
|
} |
|
if ($possrole) { |
|
$r->print('<input type="hidden" name="adhocrole" value="" />'); |
} |
} |
} |
} |
} |
} |
if ($possrole) { |
if ($possrole) { |
$r->print('</label></span><br />'); |
$r->print('</label></span><br />'); |
} |
} |
$r->print('<span class="LC_nobreak"><label>' |
$r->print('<span class="LC_nobreak"><label>' |
Line 726 sub display_matched_courses {
|
Line 763 sub display_matched_courses {
|
$r->print('<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />'); |
$r->print('<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />'); |
$r->print('<input type="hidden" name="action" value="rolepicker" />'); |
$r->print('<input type="hidden" name="action" value="rolepicker" />'); |
} elsif ($env{'form.form'} eq 'modifycourse') { |
} elsif ($env{'form.form'} eq 'modifycourse') { |
$r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form','numtitles','state'])); |
$r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form','numtitles','state','adhocrole'])); |
} else { |
} else { |
$r->print('<input type="hidden" name="cnumelement" value="'. |
$r->print('<input type="hidden" name="cnumelement" value="'. |
$env{'form.cnumelement'}.'" />'."\n". |
$env{'form.cnumelement'}.'" />'."\n". |
Line 803 sub course_chooser {
|
Line 840 sub course_chooser {
|
} |
} |
|
|
sub gochoose_javascript { |
sub gochoose_javascript { |
my ($type,$multiple,$autosubmit,$lastaction) = @_; |
my ($type,$multiple,$autosubmit,$lastaction,$rolename,$rolechooser) = @_; |
my %elements = ( |
my %elements = ( |
'Course' => { |
'Course' => { |
name => 'coursepick', |
name => 'coursepick', |
Line 821 sub gochoose_javascript {
|
Line 858 sub gochoose_javascript {
|
list => 'courselist', |
list => 'courselist', |
}, |
}, |
); |
); |
my $output = qq| |
|
|
my %lt = &Apache::lonlocal::texthash ( |
|
none => 'You are not eligible to use an ad hoc role for the selected course', |
|
ok => 'OK', |
|
exit => 'Cancel', |
|
); |
|
&js_escape(\%lt); |
|
|
|
my $output; |
|
if ($rolechooser) { |
|
$output .= qq| |
|
\$(document).ready(function(){ |
|
\$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false }); |
|
}); |
|
|; |
|
} |
|
$output .= qq| |
function gochoose(cname,cdom,cdesc) { |
function gochoose(cname,cdom,cdesc) { |
var openerForm = "$env{'form.form'}"; |
var openerForm = "$env{'form.form'}"; |
|
var openerRole = "$rolename"; |
courseCount = 0; |
courseCount = 0; |
var courses = ''; |
var courses = ''; |
|; |
|; |
Line 899 ENDNAMECODE
|
Line 953 ENDNAMECODE
|
} |
} |
|; |
|; |
} |
} |
$output .= qq| |
$output .= <<ENDJS; |
if (openerForm == 'portform') { |
if (openerForm == 'portform') { |
document.courselist.cnum.value = cname; |
document.courselist.cnum.value = cname; |
document.courselist.cdom.value = cdom; |
document.courselist.cdom.value = cdom; |
} |
} |
$autosubmit |
if ((openerForm == 'rolechoice') && ((openerRole == 'dh') || (openerRole == 'da'))) { |
$lastaction |
\$("#LC_choose_adhoc").empty(); |
|
var http = new XMLHttpRequest(); |
|
var url = "/adm/pickcourse"; |
|
var params = "cid="+cdom+"_"+cname+"&context=adhoc"; |
|
http.open("POST", url, true); |
|
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
|
http.onreadystatechange = function() { |
|
if(http.readyState == 4 && http.status == 200) { |
|
var data = \$.parseJSON(http.responseText); |
|
var len = data.roles.length; |
|
if (len == '' || len == null || len == 0) { |
|
alert('$lt{none}'); |
|
} else { |
|
if (len == 1) { |
|
process_pick(cdom,data.roles[0].name); |
|
$lastaction; |
|
} else { |
|
var str = ''; |
|
for (var i=0; i<data.roles.length; i++) { |
|
\$("<label><input type='radio' value='"+data.roles[i].name+"' name='LC_get_role' id='LC_get_role_"+i+"' />"+data.roles[i].desc+"</label><span> </span>") |
|
.appendTo("#LC_choose_adhoc"); |
|
} |
|
\$( "#LC_get_role_0").prop("checked", true); |
|
\$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false }); |
|
\$( "#LC_adhocrole_chooser" ).dialog("open"); |
|
\$( "#LC_adhocrole_chooser" ).dialog({ |
|
height: 400, |
|
width: 500, |
|
modal: true, |
|
resizable: false, |
|
buttons: [ |
|
{ |
|
text: "$lt{'ok'}", |
|
click: function() { |
|
var rolename = \$('input[name=LC_get_role]:checked', '#LChelpdeskpicker').val(); |
|
process_pick(cdom,rolename); |
|
\$("#LC_adhocrole_chooser").dialog( "close" ); |
|
$lastaction; |
|
} |
|
}, |
|
{ |
|
text: "$lt{'exit'}", |
|
click: function() { |
|
\$("#LC_adhocrole_chooser").dialog( "close" ); |
|
} |
|
} |
|
], |
|
}); |
|
\$( "#LC_adhocrole_chooser" ).find( "form" ).on( "submit", function( event ) { |
|
event.preventDefault(); |
|
var rolename = \$('input[name=LC_get_role]:checked', '#LChelpdeskpicker').val() |
|
process_pick(cdom,rolename); |
|
\$("#LC_adhocrole_chooser").dialog( "close" ); |
|
$lastaction; |
|
}); |
|
} |
|
} |
|
} |
} |
} |
|; |
http.send(params); |
return &Apache::lonhtmlcommon::scripttag($output); |
} else { |
|
$autosubmit |
|
$lastaction |
|
} |
|
} |
|
|
|
ENDJS |
|
return $rolechooser.&Apache::lonhtmlcommon::scripttag($output); |
} |
} |
|
|
1; |
1; |
Line 1038 Side Effects: None
|
Line 1156 Side Effects: None
|
|
|
=item * |
=item * |
X<gochoose_javascript()> |
X<gochoose_javascript()> |
B<gochoose_javascript($type,$multiple,$autosubmit,$lastaction)>: |
B<gochoose_javascript($type,$multiple,$autosubmit,$lastaction,$rolename)>: |
|
|
Input: 4 - course type; single (0) or multiple courses (1); in context of DC selecting a CC role in a course: javascript code from &processpick(); final action to take after user chooses course(s): either close window, or submit form for display of next page etc. |
Input: 5 - course type; single (0) or multiple courses (1); in context of DC selecting a CC role in a course: javascript code from &processpick(); final action to take after user chooses course(s): either close window, or submit form for display of next page etc.; rolename (e.g., dh) of user's current role. |
|
|
Output: 1 $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags |
Output: 1 $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags |
|
|