version 1.117, 2016/04/02 04:30:21
|
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 is selecting a course |
# if called when a DC, DH or DA is selecting a course |
my $roledom = $env{'form.roleelement'}; |
my ($roledom,$rolename) = split(/:/,$env{'form.roleelement'}); |
if ($roledom) { |
if ($roledom) { |
$roleelement = '<input type="hidden" name="roleelement" value="'.$roledom.'" />'; |
$roleelement = '<input type="hidden" name="roleelement" value="'.$env{'form.roleelement'}.'" />'; |
$submitopener = &processpick(); |
$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"; |
|
<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 288 sub processpick {
|
Line 328 sub processpick {
|
} |
} |
my $process_pick = <<"ENDONE"; |
my $process_pick = <<"ENDONE"; |
<script type="text/javascript"> |
<script type="text/javascript"> |
function process_pick(dom) { |
function process_pick(dom,rolename) { |
var pickedCourse=opener.document.$openerform.$env{'form.cnumelement'}.value; |
var pickedCourse=opener.document.$openerform.$env{'form.cnumelement'}.value; |
var pickedDomain=opener.document.$openerform.$env{'form.cdomelement'}.value; |
var pickedDomain=opener.document.$openerform.$env{'form.cdomelement'}.value; |
var okDomain = 0; |
var okDomain = 0; |
Line 297 ENDONE
|
Line 337 ENDONE
|
$process_pick .= <<"ENDTWO"; |
$process_pick .= <<"ENDTWO"; |
if (pickedDomain == dom) { |
if (pickedDomain == dom) { |
if (pickedCourse != '') { |
if (pickedCourse != '') { |
var ccrole = "cc"; |
var courseTarget; |
var pickedType = "$env{'form.type'}"; |
if (rolename == 'cc') { |
if (pickedType == "Community") { |
var ccrole = "cc"; |
ccrole = "co"; |
var pickedType = "$env{'form.type'}"; |
} |
if (pickedType == "Community") { |
var courseTarget = ccrole+"./"+pickedDomain+"/"+pickedCourse |
ccrole = "co"; |
opener.document.title='Role selected. Please stand by.'; |
} |
opener.status='Role selected. Please stand by.'; |
courseTarget = ccrole+"./"+pickedDomain+"/"+pickedCourse; |
opener.document.rolechoice.newrole.value=courseTarget |
} else { |
opener.document.rolechoice.submit(); |
if (!/\\W/.test(rolename)) { |
|
courseTarget = "cr/"+pickedDomain+"/"+pickedDomain+"-domainconfig/"+rolename+"./"+pickedDomain+"/"+pickedCourse; |
|
} |
|
} |
|
if ((courseTarget != '') && (courseTarget != undefined)) { |
|
opener.document.title='Role selected. Please stand by.'; |
|
opener.status='Role selected. Please stand by.'; |
|
opener.document.rolechoice.newrole.value=courseTarget; |
|
opener.document.rolechoice.submit(); |
|
} else { |
|
alert("Invalid role selection"); |
|
return; |
|
} |
} |
} |
} |
} |
else { |
else { |
alert("You may only use this screen to select courses in the current domain: "+dom+"\\nPlease return to the roles page window and click the 'Select Course' link for domain: "+pickedDomain+",\\n if you are a Domain Coordinator in that domain, and wish to become a Course Coordinator in a course in the domain"); |
alert("You may only use this screen to select courses in the current domain: "+dom+"\\nPlease return to the roles page window and click the 'Select Course' link for domain: "+pickedDomain+",\\n if you are a Domain Coordinator in that domain, and wish to become a Course Coordinator in a course in the domain"); |
} |
} |
Line 388 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 398 sub display_matched_courses {
|
Line 450 sub display_matched_courses {
|
my $cctitle = &Apache::lonnet::plaintext($ccrole,$type); |
my $cctitle = &Apache::lonnet::plaintext($ccrole,$type); |
my $dctitle = &Apache::lonnet::plaintext('dc'); |
my $dctitle = &Apache::lonnet::plaintext('dc'); |
my $ccrolechk = ' '; |
my $ccrolechk = ' '; |
|
my $possrole; |
my $menuchk = ' checked="checked" '; |
my $menuchk = ' checked="checked" '; |
$r->print( |
$r->print( |
'<div class="LC_left_float">' |
'<div class="LC_left_float">' |
.'<fieldset>' |
.'<fieldset>' |
.'<legend>'.&mt('Pick action').'</legend>' |
.'<legend>'.&mt('Pick action').'</legend>'); |
.'<span class="LC_nobreak"><label>' |
my $roleradio = '<span class="LC_nobreak"><label>'. |
.'<input type="radio" name="phase" value="ccrole"'.$ccrolechk.'/>' |
'<input type="radio" name="phase" value="adhocrole"'.$ccrolechk.'/>'.' '; |
.' '); |
if (&Apache::lonnet::allowed('ccc',$crsdom)) { |
if ($type eq 'Community') { |
$possrole = 1; |
$r->print(&mt('Enter the community with the role of [_1].',$cctitle)); |
$r->print($roleradio); |
} else { |
if ($type eq 'Community') { |
$r->print(&mt('Enter the course with the role of [_1].',$cctitle)); |
$r->print(&mt('Enter the community with the role of [_1].',$cctitle)); |
|
} elsif ($type eq 'Placement') { |
|
$r->print(&mt('Enter the placement test with the role of [_1].',$cctitle)); |
|
} else { |
|
$r->print(&mt('Enter the course with the role of [_1].',$cctitle)); |
|
} |
|
} elsif (&Apache::lonnet::allowed('rar',$crsdom)) { |
|
my ($roles_by_num,$description,$accessref,$accessinfo) = &Apache::lonnet::get_all_adhocroles($crsdom); |
|
if ((ref($roles_by_num) eq 'ARRAY') && (ref($description) eq 'HASH')) { |
|
if (@{$roles_by_num} > 1) { |
|
$r->print($roleradio); |
|
if ($type eq 'Community') { |
|
$r->print(&mt('Enter the community with one of the available ad hoc roles.')); |
|
} elsif ($type eq 'Placement') { |
|
$r->print(&mt('Enter the placement test with one of the available ad hoc roles.')); |
|
} else { |
|
$r->print(&mt('Enter the course with one of the available ad hoc roles.')); |
|
} |
|
$possrole = 1; |
|
} elsif (@{$roles_by_num} == 1) { |
|
$r->print($roleradio); |
|
my $rolename = $description->{$roles_by_num->[0]}; |
|
if ($type eq 'Community') { |
|
$r->print(&mt('Enter the community with the ad hoc role of: [_1]',$rolename)); |
|
} elsif ($type eq 'Placement') { |
|
$r->print(&mt('Enter the placement test with the ad hoc role of: [_1]',$rolename)); |
|
} else { |
|
$r->print(&mt('Enter the course with the ad hoc role of: [_1]',$rolename)); |
|
} |
|
$possrole = 1; |
|
} |
|
if ($possrole) { |
|
$r->print('<input type="hidden" name="adhocrole" value="" />'); |
|
} |
|
} |
} |
} |
$r->print('</label></span><br />' |
if ($possrole) { |
.'<span class="LC_nobreak"><label>' |
$r->print('</label></span><br />'); |
.'<input type="radio" name="phase" value="menu"'.$menuchk.'/> '); |
} |
if ($type eq 'Community') { |
$r->print('<span class="LC_nobreak"><label>' |
$r->print(&mt('View or modify community settings which only a [_1] may modify.',$dctitle)); |
.'<input type="radio" name="phase" value="menu"'.$menuchk.'/> '); |
} else { |
if (&Apache::lonnet::allowed('ccc',$crsdom)) { |
$r->print(&mt('View or modify course settings which only a [_1] may modify.',$dctitle)); |
if ($type eq 'Community') { |
|
$r->print(&mt('View or modify community settings which only a [_1] may modify.',$dctitle)); |
|
} elsif ($type eq 'Placement') { |
|
$r->print(&mt('View or modify placement test settings which only a [_1] may modify.',$dctitle)); |
|
} else { |
|
$r->print(&mt('View or modify course settings which only a [_1] may modify.',$dctitle)); |
|
} |
|
} elsif (&Apache::lonnet::allowed('rar',$crsdom)) { |
|
if ($type eq 'Community') { |
|
$r->print(&mt('View community settings which only a [_1] may modify.',$dctitle)); |
|
} elsif ($type eq 'Placement') { |
|
$r->print(&mt('View placement test settings which only a [_1] may modify.',$dctitle)); |
|
} else { |
|
$r->print(&mt('View course settings which only a [_1] may modify.',$dctitle)); |
|
} |
} |
} |
$r->print('</label></span>' |
$r->print('</label></span>' |
.'</fieldset></div>' |
.'</fieldset></div>' |
.'<br clear="all" />' |
.'<br clear="all" />' |
); |
); |
} |
} |
} |
} |
my %by_descrip; |
my %by_descrip; |
Line 662 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 739 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 757 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 835 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 974 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 |
|
|