--- loncom/interface/lonblockingmenu.pm 2015/09/13 21:48:05 1.15 +++ loncom/interface/lonblockingmenu.pm 2016/10/22 01:49:10 1.20 @@ -2,7 +2,7 @@ # Routines for configuring blocking of access to collaborative functions, # and specific resources during an exam # -# $Id: lonblockingmenu.pm,v 1.15 2015/09/13 21:48:05 raeburn Exp $ +# $Id: lonblockingmenu.pm,v 1.20 2016/10/22 01:49:10 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -105,6 +105,19 @@ block (including deletion), or when a ne =over +=item &get_permission() + +Returns information about permission user has to set/modify exam +blocking events. + +Inputs: None + +Outputs: 2 + $readonly - true if modification of blocking events is prohibited. + + $allowed - true if blocking events information can be shown. + + =item &get_timed_items() Provides perl data structure with information about timed interval @@ -222,7 +235,7 @@ Side Effects: &update_released_required( Generates web form elements used to display, cancel, or modify existing blocking events. -Inputs: 7 +Inputs: 8 - $r - Apache request object - $records - Reference to hash of current blocks @@ -238,6 +251,9 @@ Inputs: 7 - $blockcount - number of existing blocking events in course + - $readonly - if true, modification not allowed. + + Output: None Side Effects: prints web form elements (in a table) for current blocks. @@ -422,11 +438,10 @@ sub handler { # ----------------------------------------------------------- Permissions check - unless ((&Apache::lonnet::allowed('dcm',$env{'request.course.id'})) || - (&Apache::lonnet::allowed('dcm',$env{'request.course.id'}. - '/'.$env{'request.course.sec'}))) { + my ($readonly,$allowed) = &get_permission(); + unless ($allowed) { $env{'user.error.msg'}= - "/adm/setblock:dcm:0:0:Cannot set blocking of communications in a course"; + "/adm/setblock:dcm:0:0:Cannot view/set blocking of communications in a course"; return HTTP_NOT_ACCEPTABLE; } @@ -471,7 +486,7 @@ sub handler { $r->print(&Apache::loncourserespicker::create_picker($navmap, 'examblock','resourceblocks',$crstype, \%blockedmaps,\%blockedresources, - $env{'form.block'})); + $env{'form.block'},'','',undef,$readonly)); } else { $r->print($errormsg); } @@ -480,10 +495,12 @@ sub handler { # -------------------------- Store changes and retrieve latest block information my $storeresult; - if ($env{'form.action'} eq 'store') { - (my $numchanges,$storeresult) = &blockstore($r,$crstype,$blockcount,\%records); - if ($numchanges > 0) { - $blockcount = &get_blockdates(\%records); + unless ($readonly) { + if ($env{'form.action'} eq 'store') { + (my $numchanges,$storeresult) = &blockstore($r,$crstype,$blockcount,\%records); + if ($numchanges > 0) { + $blockcount = &get_blockdates(\%records); + } } } @@ -561,6 +578,7 @@ sub handler { '
  • '.&mt('accessing content in LON-CAPA portfolios or blogs').'
  • '."\n". '
  • '.&mt("generating printouts of $lctype content").'
  • '. '
  • '.&mt("accessing $lctype content in specified folders or resources").'
  • '. + '
  • '.&mt("changing user's own password").'
  • '. ''. '

    '.$lt{'blca'}.'
    '.$lt{'pobl'}.'

    ' ); @@ -568,8 +586,10 @@ sub handler { # ------------------------ Choose between modifying existing block or adding new $r->print('
    '); - if ($blockcount > 0) { - $r->print(<<"END"); + + unless ($readonly) { + if ($blockcount > 0) { + $r->print(<<"END");
    $lt{'actt'} @@ -586,33 +606,62 @@ onclick="toggleAddModify();" />$lt{'addn
    '); + } + } -# ------------------------------------------------- Interface for existig blocks +# ------------------------------------------------ Interface for existing blocks if ($blockcount > 0) { - $r->print('
    '); &display_blocker_status($r,\%records,\%ltext,\%intervals, - $navmap,$errormsg,$blockcount); + $navmap,$errormsg,$blockcount,$readonly); } - $r->print(<<"END"); + unless ($readonly) { + $r->print(<<"END");
    -
    END - $r->print(&Apache::loncommon::end_page()); + } + $r->print(''. + &Apache::loncommon::end_page()); return OK; } +sub get_permission { + my %permission; + my $allowed = 0; + my $readonly = 0; + return ($readonly,$allowed) unless ($env{'request.course.id'}); + if ((&Apache::lonnet::allowed('dcm',$env{'request.course.id'})) || + (&Apache::lonnet::allowed('dcm',$env{'request.course.id'}.'/'. + $env{'request.course.sec'}))) { + $allowed = 1; + } elsif ((&Apache::lonnet::allowed('vcb',$env{'request.course.id'})) || + (&Apache::lonnet::allowed('vcb',$env{'request.course.id'}.'/'. + $env{'request.course.sec'}))) { + $readonly = 1; + $allowed = 1; + } + return ($readonly,$allowed); +} + sub get_timed_items { my ($cdom,$cnum) = @_; my ($cid,%intervals); @@ -629,7 +678,7 @@ sub get_timed_items { my $resourcedata=&Apache::lonparmset::readdata($cnum,$cdom); if (ref($resourcedata) eq 'HASH') { foreach my $key (keys(%{$resourcedata})) { - if ($key =~ /^\Q$cid\E(.+)\.0\.interval$/) { + if ($key =~ /^\Q$cid\E(.*)\.0\.interval$/) { my $middle = $1; if ($middle eq '') { $intervals{'course'}{'all'} = $resourcedata->{$key}; @@ -950,7 +999,7 @@ sub get_block_choices { sub check_release_required { my ($value,$chomemajor,$chomeminor) = @_; - my $needsrelease = $Apache::lonnet::needsrelease{'course:commblock:'.$value.':'}; + my $needsrelease = $Apache::lonnet::needsrelease{'course:commblock:'.$value}; if ($needsrelease) { my ($needsmajor,$needsminor) = split(/\./,$needsrelease); if (($chomemajor < $needsmajor) || @@ -974,9 +1023,9 @@ sub check_release_required { } sub display_blocker_status { - my ($r,$records,$ltext,$intervals,$navmap,$errormsg,$blockcount) = @_; + my ($r,$records,$ltext,$intervals,$navmap,$errormsg,$blockcount,$readonly) = @_; my $parmcount = 0; - my (%map_url,%resource_symb,%titles,%lookups); + my (%map_url,%resource_symb,%titles,%lookups,$disabled); &Apache::loncourserespicker::enumerate_course_contents($navmap,\%map_url,\%resource_symb,\%titles,'examblock'); %{$lookups{'maps'}} = reverse(%map_url); %{$lookups{'resources'}} = reverse(%resource_symb); @@ -986,10 +1035,13 @@ sub display_blocker_status { 'noch' => 'No change', ); $r->print('
    '. - &Apache::loncommon::start_data_table()); + &Apache::loncommon::start_data_table().''); + if ($readonly) { + $disabled = ' disabled="disabled"'; + } else { + $r->print(''); + } $r->print(<<"END"); - - $ltext->{'type'} $ltext->{'even'} $ltext->{'blck'} @@ -1008,8 +1060,12 @@ END &Apache::loncommon::aboutmewrapper( &Apache::loncommon::plainname($setuname,$setudom), $setuname,$setudom); + my $state = ''; $r->print(&Apache::loncommon::start_data_table_row()); - $r->print(<<"ACT"); + if ($readonly) { + $state = 'disabled'; + } else { + $r->print(<<"ACT"); ACT + } my ($start,$end,$startform,$endform); if ($record =~ /^(\d+)____(\d+)$/) { ($start,$end) = split(/____/,$record); $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'. - $parmcount,$start,$onchange); + $parmcount,$start,$onchange, + undef,$state); $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'. - $parmcount,$end,$onchange); + $parmcount,$end,$onchange, + undef,$state); $r->print('
    '.$ltext->{'defs'}.''. $ltext->{'star'}.': '.$startform.'
    '. $ltext->{'endd'}.':  '.$endform.'
    '); @@ -1159,18 +1218,18 @@ ACT } } $r->print(&create_interval_form($intervals,$parmcount,$navmap,$item,$jschg, - $itemname,$iteminfo).''); + $itemname,$iteminfo,$disabled).''); } $r->print(<<"END"); - +

    $ltext->{'setb'}: $settername END - $r->print(''.&blocker_checkboxes($parmcount,$blocks,$jschg,\%lookups).''. + $r->print(''.&blocker_checkboxes($parmcount,$blocks,$jschg,\%lookups,$disabled).''. &Apache::loncommon::end_data_table_row()); $parmcount++; } @@ -1260,7 +1319,7 @@ END } sub blocker_checkboxes { - my ($parmcount,$blocks,$jschg,$lookups) = @_; + my ($parmcount,$blocks,$jschg,$lookups,$disabled) = @_; my ($typeorder,$types) = &blocktype_text(); my $numinrow = 2; my %currdocs; @@ -1327,7 +1386,7 @@ sub blocker_checkboxes { } $output .= ''."\n"; if ($block eq 'docs') { if ($blockstatus ne '') { @@ -1346,7 +1405,7 @@ sub blocker_checkboxes { } sub create_interval_form { - my ($intervals,$parmcount,$navmap,$currkey,$jschg,$itemname,$iteminfo) = @_; + my ($intervals,$parmcount,$navmap,$currkey,$jschg,$itemname,$iteminfo,$disabled) = @_; return unless ((ref($intervals) eq 'HASH') && (ref($navmap))); my $intervalform; if (keys(%{$intervals}) > 0) { @@ -1359,7 +1418,7 @@ sub create_interval_form { $clickaction = ' onclick="'.$jschg.'"'; } $intervalform .= '