--- loncom/interface/lonblockingmenu.pm 2021/01/04 17:24:13 1.14.2.3.4.4 +++ loncom/interface/lonblockingmenu.pm 2015/09/13 21:48:05 1.15 @@ -2,7 +2,7 @@ # Routines for configuring blocking of access to collaborative functions, # and specific resources during an exam # -# $Id: lonblockingmenu.pm,v 1.14.2.3.4.4 2021/01/04 17:24:13 raeburn Exp $ +# $Id: lonblockingmenu.pm,v 1.15 2015/09/13 21:48:05 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -105,19 +105,6 @@ 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 @@ -235,7 +222,7 @@ Side Effects: &update_released_required( Generates web form elements used to display, cancel, or modify existing blocking events. -Inputs: 8 +Inputs: 7 - $r - Apache request object - $records - Reference to hash of current blocks @@ -251,9 +238,6 @@ Inputs: 8 - $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. @@ -318,16 +302,13 @@ Creates web form elements used to select items in the course for use in an exam block of type: "Triggered by Activating Timer". -Inputs: 8 (four required, last four optional) +Inputs: 7 (three required, last four optional) - $intervals - Reference to hash of parameters for timed intervals - $parmcount - numeric ID of current block - $navmap - navmaps object - - $context - this will be "accesstimes" if called by lonaccesstimes.pm, - or "blocking" if called internally by lonblockingmenu.pm - - $currkey - current interval (where this is a block already using an interval-based trigger). @@ -342,34 +323,6 @@ Inputs: 8 (four required, last four opti Outputs: 1 - $intervalform - web form elements used to select a time interval -=item &interval_details() - -Creates name/scope of current interval and expandable/collapsible -showing which interval parameters apply to the current folder/resource - -Inputs: 6 - - - $item - course, map url, or resource symb - - - $type - course, map, or resource - - - $url - url of item (null if item is course). - - - $navmap - navmaps object - - - $intervals - Reference to hash of parameters for timed intervals - - - $parmcount - unique ID for current element. - - -Outputs: 2 - - - $itemname - name/scope of interval (timer) parameter - - - $iteminfo - Expandable/collapsible block showing which interval - (timer) parameters affect the current folder or resource. - - =item &trigger_details_toggle() Creates link used to expand item showing information about timer for current @@ -379,7 +332,6 @@ Inputs: 1 - $parmcount - numericID of ex Outputs: 1 - returns HTML for link to display contents of information item - =item &show_timer_path() Display hierarchy of names of folders/sub-folders containing the current @@ -424,21 +376,12 @@ Output: 1 - Javascript (with tags) for functions used to: - toggle visibility of unordered list for display of detailed - information about intervals. - -=back +=back =cut @@ -479,10 +422,11 @@ sub handler { # ----------------------------------------------------------- Permissions check - my ($readonly,$allowed) = &get_permission(); - unless ($allowed) { + unless ((&Apache::lonnet::allowed('dcm',$env{'request.course.id'})) || + (&Apache::lonnet::allowed('dcm',$env{'request.course.id'}. + '/'.$env{'request.course.sec'}))) { $env{'user.error.msg'}= - "/adm/setblock:dcm:0:0:Cannot view/set blocking of communications in a course"; + "/adm/setblock:dcm:0:0:Cannot set blocking of communications in a course"; return HTTP_NOT_ACCEPTABLE; } @@ -527,7 +471,7 @@ sub handler { $r->print(&Apache::loncourserespicker::create_picker($navmap, 'examblock','resourceblocks',$crstype, \%blockedmaps,\%blockedresources, - $env{'form.block'},'','',undef,undef,$readonly)); + $env{'form.block'})); } else { $r->print($errormsg); } @@ -536,12 +480,10 @@ sub handler { # -------------------------- Store changes and retrieve latest block information my $storeresult; - unless ($readonly) { - if ($env{'form.action'} eq 'store') { - (my $numchanges,$storeresult) = &blockstore($r,$crstype,$blockcount,\%records); - if ($numchanges > 0) { - $blockcount = &get_blockdates(\%records); - } + if ($env{'form.action'} eq 'store') { + (my $numchanges,$storeresult) = &blockstore($r,$crstype,$blockcount,\%records); + if ($numchanges > 0) { + $blockcount = &get_blockdates(\%records); } } @@ -561,8 +503,7 @@ sub handler { ({href=>'/adm/setblock', text=>'Blocking communication/content access'}); - my $js = &blockingmenu_javascript($blockcount). - &details_javascript(); + my $js = &blockingmenu_javascript($blockcount); $r->print( &Apache::loncommon::start_page('Blocking communication/content access',$js). @@ -578,7 +519,6 @@ sub handler { my %lt=&Apache::lonlocal::texthash ( 'cbds' => 'Blocking communication and/or content access during exams', 'prev' => "For the duration of an exam, or a timed quiz, students in this course can be prevented from:", - 'flow' => "For the duration of an exam, or a timed quiz, event-driven interruptions to a student's workflow can be suppressed:", 'blca' => "Blocks can potentially interrupt legitimate communication between $usertype who are also both enrolled in a different LON-CAPA $lctype.", 'pobl' => "Portfolio blocking can impact a student's ability to complete assignments in courses besides your own. Please use this feature wisely.", 'actt' => "Action to take:", @@ -618,17 +558,9 @@ sub handler { ''. - $lt{'flow'}. - ''. '

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

' ); @@ -636,10 +568,8 @@ sub handler { # ------------------------ Choose between modifying existing block or adding new $r->print('
'); - - unless ($readonly) { - if ($blockcount > 0) { - $r->print(<<"END"); + if ($blockcount > 0) { + $r->print(<<"END");
$lt{'actt'} @@ -656,61 +586,33 @@ onclick="toggleAddModify();" />$lt{'addn
'); - } - } -# ------------------------------------------------ Interface for existing blocks - if (!$blockcount) { - if ($readonly) { - $r->print($lt{'ncbc'}.'
'); - } - } else { + &display_addblocker_table($r,$blockcount,\%ltext,\%intervals, + $navmap,$errormsg); + +# ------------------------------------------------- Interface for existig blocks + if ($blockcount > 0) { + $r->print('
'); &display_blocker_status($r,\%records,\%ltext,\%intervals, - $navmap,$errormsg,$blockcount,$readonly); + $navmap,$errormsg,$blockcount); } - unless ($readonly) { - $r->print(<<"END"); + $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); @@ -727,7 +629,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}; @@ -885,24 +787,6 @@ sub blockstore { &escape($env{'form.title_'.$key})).'
'; } } - if ($blocktypes->{'alert'} eq 'on') { - ($status,$needsrelease) = &check_release_required('alert',$chomemajor,$chomeminor); - if ($status eq 'fail') { - $blocktypes->{'alert'} = 'off'; - $output .= '

'. - &mt('Message Alert blocking not allowed for [_1]', - &escape($env{'form.title_'.$key})).'
'; - } - } - if ($blocktypes->{'reinit'} eq 'on') { - ($status,$needsrelease) = &check_release_required('reinit',$chomemajor,$chomeminor); - if ($status eq 'fail') { - $blocktypes->{'reinit'} = 'off'; - $output .= '

'. - &mt('Course Re-initialization blocking not allowed for [_1]', - &escape($env{'form.title_'.$key})).'
'; - } - } } if ($blockdocs) { ($status,$needsrelease) = &check_release_required('docs',$chomemajor,$chomeminor); @@ -1066,7 +950,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) || @@ -1090,9 +974,9 @@ sub check_release_required { } sub display_blocker_status { - my ($r,$records,$ltext,$intervals,$navmap,$errormsg,$blockcount,$readonly) = @_; + my ($r,$records,$ltext,$intervals,$navmap,$errormsg,$blockcount) = @_; my $parmcount = 0; - my (%map_url,%resource_symb,%titles,%lookups,$disabled); + my (%map_url,%resource_symb,%titles,%lookups); &Apache::loncourserespicker::enumerate_course_contents($navmap,\%map_url,\%resource_symb,\%titles,'examblock'); %{$lookups{'maps'}} = reverse(%map_url); %{$lookups{'resources'}} = reverse(%resource_symb); @@ -1102,13 +986,10 @@ sub display_blocker_status { 'noch' => 'No change', ); $r->print('

'. - &Apache::loncommon::start_data_table().''); - if ($readonly) { - $disabled = ' disabled="disabled"'; - } else { - $r->print(''); - } + &Apache::loncommon::start_data_table()); $r->print(<<"END"); + + $ltext->{'type'} $ltext->{'even'} $ltext->{'blck'} @@ -1127,12 +1008,8 @@ END &Apache::loncommon::aboutmewrapper( &Apache::loncommon::plainname($setuname,$setudom), $setuname,$setudom); - my $state = ''; $r->print(&Apache::loncommon::start_data_table_row()); - if ($readonly) { - $state = 'disabled'; - } else { - $r->print(<<"ACT"); + $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, - undef,$state); + $parmcount,$start,$onchange); $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'. - $parmcount,$end,$onchange, - undef,$state); + $parmcount,$end,$onchange); $r->print('
'.$ltext->{'defs'}.''. $ltext->{'star'}.': '.$startform.'
'. $ltext->{'endd'}.':  '.$endform.'
'); } elsif ($record =~ /^firstaccess____(.+)$/) { my $item = $1; + my ($itemname,$iteminfo,$skipdetails); my $type = 'map'; my $url; if ($item eq 'course') { @@ -1172,20 +1047,130 @@ ACT $url = $item; } $r->print('
'.$ltext->{'trig'}.''); - my ($itemname,$iteminfo) = &interval_details($item,$type,$url,$navmap,$intervals,$parmcount); - $r->print(&create_interval_form($intervals,$parmcount,$navmap,'blocking',$item,$jschg, - $itemname,$iteminfo,$disabled).'
'); + if ($type eq 'course') { + $itemname = &mt('Timer for all items in course.'); + } else { + if (&Apache::lonnet::is_on_map($url)) { + if ($type eq 'map') { + if (ref($navmap)) { + my $title; + my $resobj = $navmap->getResourceByUrl($item); + if (ref($resobj)) { + $title = $resobj->compTitle(); + } else { + $title = &Apache::lonnet::gettitle($item); + } + $itemname = &mt('Timer for all items in folder: [_1]', + ''. + $title.''); + } + } else { + if (ref($navmap)) { + my $title; + my $resobj = $navmap->getBySymb($item); + if (ref($resobj)) { + $title = $resobj->compTitle(); + } else { + $title = &Apache::lonnet::gettitle($item); + } + $itemname = &mt('Timer for resource: [_1]', + ''. + $title.''); + } + } + if (ref($navmap)) { + my $path = &show_timer_path($type,$item); + if ($path) { + $iteminfo = ' '. + &mt('(in: [_1])',$path). + ''; + } + } + } else { + $skipdetails = 1; + $itemname = ''. + &mt('Timer folder/resource not in course'). + ''; + } + } + if ((!$skipdetails) && (ref($intervals) eq 'HASH')) { + if (ref($intervals->{$type}) eq 'HASH') { + $iteminfo .= &trigger_details_toggle($parmcount). + ''; + } + } + $r->print(&create_interval_form($intervals,$parmcount,$navmap,$item,$jschg, + $itemname,$iteminfo).''); } $r->print(<<"END"); - +

$ltext->{'setb'}: $settername END - $r->print(''.&blocker_checkboxes($parmcount,$blocks,$jschg,\%lookups,$disabled).''. + $r->print(''.&blocker_checkboxes($parmcount,$blocks,$jschg,\%lookups).''. &Apache::loncommon::end_data_table_row()); $parmcount++; } @@ -1237,7 +1222,7 @@ sub display_addblocker_table { my %lt = &Apache::lonlocal::texthash( 'exam' => 'e.g., Exam 1', ); - my $intervalform = &create_interval_form($intervals,$parmcount,$navmap,'blocking'); + my $intervalform = &create_interval_form($intervals,$parmcount,$navmap); if ($intervalform ne '') { $intervalform = '
'. ''.$ltext->{'chtr'}.''. @@ -1275,7 +1260,7 @@ END } sub blocker_checkboxes { - my ($parmcount,$blocks,$jschg,$lookups,$disabled) = @_; + my ($parmcount,$blocks,$jschg,$lookups) = @_; my ($typeorder,$types) = &blocktype_text(); my $numinrow = 2; my %currdocs; @@ -1342,7 +1327,7 @@ sub blocker_checkboxes { } $output .= ''."\n"; if ($block eq 'docs') { if ($blockstatus ne '') { @@ -1361,10 +1346,9 @@ sub blocker_checkboxes { } sub create_interval_form { - my ($intervals,$parmcount,$navmap,$context,$currkey,$jschg,$itemname,$iteminfo,$disabled) = @_; + my ($intervals,$parmcount,$navmap,$currkey,$jschg,$itemname,$iteminfo) = @_; return unless ((ref($intervals) eq 'HASH') && (ref($navmap))); my $intervalform; - my $counter = 0; if (keys(%{$intervals}) > 0) { foreach my $type (sort(keys(%{$intervals}))) { if ($type eq 'course') { @@ -1375,7 +1359,7 @@ sub create_interval_form { $clickaction = ' onclick="'.$jschg.'"'; } $intervalform .= ''; if ($currkey eq 'course') { $intervalform .= $iteminfo; - } elsif ($context eq 'accesstimes') { - (undef,$iteminfo) = &interval_details('course',$type,'',$navmap,$intervals,$counter); - if ($iteminfo) { - $intervalform .= ' '.$iteminfo; - } } $intervalform .= '
'; - $counter ++; } elsif ($type eq 'map') { if (ref($intervals->{$type}) eq 'HASH') { if (ref($navmap)) { @@ -1406,7 +1384,7 @@ sub create_interval_form { } $intervalform .= ''.$iteminfo; } else { @@ -1426,15 +1404,8 @@ sub create_interval_form { $intervalform .= &mt('Timer for all items in folder: [_1]', ''.$title.''). ''.$path; - if ($context eq 'accesstimes') { - (undef,$iteminfo) = &interval_details($map,$type,$map,$navmap,$intervals,$counter); - if ($iteminfo) { - $intervalform .= ' '.$iteminfo; - } - } } $intervalform .= '
'; - $counter ++; } } } @@ -1454,15 +1425,14 @@ sub create_interval_form { } $intervalform .= ''.$iteminfo; } else { my ($title,$path,$hierarchy); if (ref($resobj)) { $title = $resobj->compTitle(); - } - if ($title eq '') { + } else { $title = &Apache::lonnet::gettitle($resource); } $hierarchy = &show_timer_path($type,$resource,$navmap); @@ -1474,19 +1444,8 @@ sub create_interval_form { $intervalform .= &mt('Timer for resource: [_1]',''.$title.''). ''. $path; - if ($context eq 'accesstimes') { - if (ref($resobj)) { - my $url = $resobj->src(); - if ($url eq '') { - (my $map, my $resid, $url) = &Apache::lonnet::decode_symb($resource); - } - ($itemname,$iteminfo) = &interval_details($resource,$type,$url,$navmap,$intervals,$counter); - $intervalform .= ' '.$iteminfo; - } - } } $intervalform .= '
'; - $counter ++; } } } @@ -1496,7 +1455,7 @@ sub create_interval_form { if ($currkey ne '') { $intervalform = '&').'"'.$disabled.' />'. + &HTML::Entities::encode($currkey,'"<>&').' />'. $itemname.'
'; } else { $intervalform = &mt('No timed items defined.').' '. @@ -1514,121 +1473,6 @@ sub trigger_details_toggle { 'style="text-decoration: none;">'.&mt('(More ...)').''; } -sub interval_details { - my ($item,$type,$url,$navmap,$intervals,$parmcount) = @_; - my ($itemname,$iteminfo,$skipdetails); - if ($type eq 'course') { - $itemname = &mt('Timer for all items in course.'); - } else { - if (&Apache::lonnet::is_on_map($url)) { - if ($type eq 'map') { - if (ref($navmap)) { - my $title; - my $resobj = $navmap->getResourceByUrl($item); - if (ref($resobj)) { - $title = $resobj->compTitle(); - } else { - $title = &Apache::lonnet::gettitle($item); - } - $itemname = &mt('Timer for all items in folder: [_1]', - ''. - $title.''); - } - } else { - if (ref($navmap)) { - my $title; - my $resobj = $navmap->getBySymb($item); - if (ref($resobj)) { - $title = $resobj->compTitle(); - } else { - $title = &Apache::lonnet::gettitle($item); - } - $itemname = &mt('Timer for resource: [_1]', - ''. - $title.''); - } - } - if (ref($navmap)) { - my $path = &show_timer_path($type,$item); - if ($path) { - $iteminfo = ' '. - &mt('(in: [_1])',$path). - ''; - } - } - } else { - $skipdetails = 1; - $itemname = ''. - &mt('Timer folder/resource not in course'). - ''; - } - } - if ((!$skipdetails) && (ref($intervals) eq 'HASH') && (ref($intervals->{$type}) eq 'HASH')) { - $iteminfo = &trigger_details_toggle($parmcount). - ''; - } - return ($itemname,$iteminfo); -} - sub show_timer_path { my ($type,$item,$navmap) = @_; return unless(ref($navmap)); @@ -1655,21 +1499,19 @@ sub blocktype_text { 'port' => 'Portfolio', 'groups' => 'Groups', 'blogs' => 'Blogs', - 'about' => 'User Information', 'docs' => 'Content', 'printout' => 'Printouts', - 'passwd' => 'Change Password', - 'grades' => 'Gradebook', - 'search' => 'Content Search', - 'alert' => 'Critical Alert', - 'reinit' => 'Course Re-init', ); - my $typeorder = ['com','chat','boards','port','groups','blogs','about','printout','docs','grades','search','alert','reinit','passwd']; + my $typeorder = ['com','chat','boards','port','groups','blogs','printout','docs']; return ($typeorder,\%types); } sub blockingmenu_javascript { my ($blockcount) = @_; + my %lt = &Apache::lonlocal::texthash ( + more => 'More ...', + less => 'Less ...', + ); return < // - -ENDSCRIPT - -} - -sub details_javascript { - my %lt = &Apache::lonlocal::texthash ( - more => 'More ...', - less => 'Less ...', - ); - return < -//