Diff for /loncom/interface/lonblockingmenu.pm between versions 1.5 and 1.29

version 1.5, 2012/04/04 21:04:56 version 1.29, 2021/01/02 21:07:36
Line 57  into this category. Line 57  into this category.
 (b) those which a student could use to access materials prepared by the  (b) those which a student could use to access materials prepared by the
 student in advance of an exam, (e.g., for use during an online exam, to  student in advance of an exam, (e.g., for use during an online exam, to
 gain an unfair advantage). Blogs and portfolio fall into this category.  gain an unfair advantage). Blogs and portfolio fall into this category.
   (c) those which a student could use to display or save content within
   the course itself (outside the exam folder). Printouts and resources
   fall into this category.
   
 For communication blocking to be truly effective in preventing unwanted  For communication blocking to be truly effective in preventing unwanted
 communication, or access to online materials, online testing needs to  communication, or access to online materials, online testing needs to
Line 64  take place in a lab setting where use of Line 67  take place in a lab setting where use of
 of web sites beyond LON-CAPA are unavailable.  of web sites beyond LON-CAPA are unavailable.
   
 Access to specified folder(s) and/or resources in the course contents   Access to specified folder(s) and/or resources in the course contents 
 can also be restricted for the duration of an exam.  can be restricted for the duration of an exam.
   
 Exam blocks are of two types:  Exam blocks are of two types:
 (a) Blocks with a defined start and end date.  (a) Blocks with a defined start and end date.
Line 87  it is important to use reasonable time w Line 90  it is important to use reasonable time w
 the case of blocks triggered by clicking a button to start a timed quiz,   the case of blocks triggered by clicking a button to start a timed quiz, 
 quiz durations that are of limited duration. This is especially important  quiz durations that are of limited duration. This is especially important
 when blocking prtfolio access, as other courses may require students to use  when blocking prtfolio access, as other courses may require students to use
 the portfolio as a mechanism for submitting assigments.  the portfolio as a mechanism for submitting assignments.
   
 Information about blocks in a course will be cached for 10 minutes, so,  Information about blocks in a course will be cached for 10 minutes, so,
 as with parameters set for resources, it can take up to 10 minutes for  as with parameters set for resources, it can take up to 10 minutes for
Line 102  block (including deletion), or when a ne Line 105  block (including deletion), or when a ne
   
 =over  =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()  =item &get_timed_items()
   
 Provides perl data structure with information about timed interval  Provides perl data structure with information about timed interval
Line 124  Output: 1 Hash Line 140  Output: 1 Hash
 Stores changes to exam blocks in comm_block.db file for course.  Stores changes to exam blocks in comm_block.db file for course.
 Processes deletions, modifications and additions.  Processes deletions, modifications and additions.
   
 Inputs: 2  Inputs: 4
         $r = request object
   
       $crstype - Container type: Course or Community.        $crstype - Container type: Course or Community.
   
       $blockcount - Total number of blocking events in course.        $blockcount - Total number of blocking events in course.
   
         $currblockrecs - Ref to hash of current blocks in course.
   
 Outputs: 2  Outputs: 2
       $changestotal - Total number of changes made.        $changestotal - Total number of changes made.
   
       $output - Information about changes made.        $output - Information about changes made.
   
   
 =item &enumerate_course_contents()  
   
 Create hashes of maps (for folders/pages) and symbs (for resources) in  
 a course, where keys are numbers (starting with 1) and values are  
 map url, or symb, for an iteration through the course, as seen by  
 a Course Coordinator. Used to generate numerical IDs to facilitate  
 storage of lists of maps or resources to be blocked during an exam.     
   
 Inputs: 3  
       $navmap - navmaps object  
   
       $map_url - reference to hash to contain URLs of maps in course  
   
       $resource_symb - reference to hash to contain symbs for  
                        resources in course  
   
 Outputs: None  
   
 Side Effects: $map_url and $resource_symb hashrefs are populated.  
   
   
 =item &get_dates_from_form()  =item &get_dates_from_form()
   
 Extract start and end dates from web form input for blocks with  Extract start and end dates from web form input for blocks with
Line 181  Side Effects: populates records hashref. Line 180  Side Effects: populates records hashref.
 =item &get_block_choices()  =item &get_block_choices()
   
 Extract information from web form about which communication/  Extract information from web form about which communication/
 collaboration features are to be blocked, for a partilcuar event,  collaboration features are to be blocked, for a particular event,
 and also which content areas will have access blocked for the  and also which content areas will have access blocked for the
 duration of the block.  duration of the block.
   
Line 205  Update LON-CAPA version requirements for Line 204  Update LON-CAPA version requirements for
 (content) or blocking type (triggered by student starting timer)  (content) or blocking type (triggered by student starting timer)
 require specific LON-CAPA version (i.e., 2.11).  require specific LON-CAPA version (i.e., 2.11).
   
 Inputs: 1 - type of constraint (currently: 'docs' or 'timer').   Inputs: 3 - $value - type of constraint (currently: 'docs', 'printout' or 'timer'),
               $chomemajor - course's home server LON-CAPA major version number.
               $chomeminor - course's home server LON-CAPA minor version number.
   
 Outputs: None  Outputs: 2 - status ('ok' or 'fail') and LON-CAPA version needed.
   
   =over
   
                A status of 'fail' will be returned if the 
                LON-CAPA version installed on the course's 
                home server is older than the version 
                requirement for the blocking type.
                For a trigger type event, the requested
                blocking event will not be added if 
                the course's home server version is old to
                support that type of block.
   
   =back
   
 Side Effects: &update_released_required() called in lonnet, if  Side Effects: &update_released_required() called in lonnet, if
               needed to update version requirements for course.                   course's home server version is requied version or 
                 newer; will update version requirements for course to
                 a more recent version requirement than currently in
                 effect.
   
   
 =item &display_blocker_status()  =item &display_blocker_status()
Line 218  Side Effects: &update_released_required( Line 235  Side Effects: &update_released_required(
 Generates web form elements used to display, cancel, or modify   Generates web form elements used to display, cancel, or modify 
 existing blocking events.   existing blocking events. 
   
 Inputs: 7   Inputs: 8 
       - $r - Apache request object        - $r - Apache request object
   
       - $records - Reference to hash of current blocks        - $records - Reference to hash of current blocks
Line 234  Inputs: 7 Line 251  Inputs: 7
   
       - $blockcount - number of existing blocking events in course        - $blockcount - number of existing blocking events in course
   
 Output: None        - $readonly - if true, modification not allowed.
   
 Side Effects: prints web form elements (in a table) for current blocks.   
   
 =item &path_to_trigger()  Output: None
   
 Provides hierarchy of names of folders/sub-folders containing the current  
 item identified as an item with an interval timer set, to be used as a   
 trigger.   
   
 Inputs: 3   
      - $navmap - navmaps object  
   
      - $map - url for map (either the trigger itself, or map containing  
                            the resource, which is the trigger).   
   
      - $type - type of trigger: map or resource.  
   
 Outputs: 1 @pathitems - array of folder/subfolder names.    
   
   Side Effects: prints web form elements (in a table) for current blocks. 
   
 =item &convlim()  =item &convlim()
   
Line 315  Creates web form elements used to select Line 318  Creates web form elements used to select
 items in the course for use in an exam block of type: "Triggered by   items in the course for use in an exam block of type: "Triggered by 
 Activating Timer".  Activating Timer".
   
 Inputs: 7 (three required, last four optional)  Inputs: 8 (four required, last four optional)
    - $intervals - Reference to hash of parameters for timed intervals     - $intervals - Reference to hash of parameters for timed intervals
   
    - $parmcount - numeric ID of current block     - $parmcount - numeric ID of current block
   
    - $navmap - navmaps object     - $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     - $currkey - current interval (where this is a block already using
                 an interval-based trigger).                    an interval-based trigger).  
   
Line 336  Inputs: 7 (three required, last four opt Line 342  Inputs: 7 (three required, last four opt
 Outputs: 1 - $intervalform - web form elements used to select a time interval  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()  =item &trigger_details_toggle()
     
 Creates link used to expand item showing information about timer for current  Creates link used to expand item showing information about timer for current
Line 345  Inputs: 1 - $parmcount - numericID of ex Line 379  Inputs: 1 - $parmcount - numericID of ex
   
 Outputs: 1 - returns HTML for link to display contents of information item   Outputs: 1 - returns HTML for link to display contents of information item 
   
   
 =item &show_timer_path()  =item &show_timer_path()
   
 Display hierarchy of names of folders/sub-folders containing the current  Display hierarchy of names of folders/sub-folders containing the current
Line 375  Output: 2 Line 410  Output: 2
 Create Javascript used to launch pop-up used for content selection, and to  Create Javascript used to launch pop-up used for content selection, and to
 toggle visibility of a number of expandable/collapsible divs.  toggle visibility of a number of expandable/collapsible divs.
   
 Inputs: 1 - $blockcount -   Inputs: 1 - $blockcount - Total number of blocks in course's comm_block.db
                             database file. 
   
 Output: 1 - Javascript (with <script></script> tags) for functions used to:  Output: 1 - Javascript (with <script></script> tags) for functions used to:
             (a) launch pop-up window for selection of course content to which              (a) launch pop-up window for selection of course content to which
Line 388  Output: 1 - Javascript (with <script></s Line 424  Output: 1 - Javascript (with <script></s
   
 =item *  for action to take -- add or modify block  =item *  for action to take -- add or modify block
   
 =item *  for display of detailed information about intervals   
   
 =back  =back
   
   
 =back    =item &details_javascript()
   
   Create Javascript to toggle visibility of unordered list item
   containing details about item with timed interval parameter.
   
   Inputs: none
   
   Output: 1 Javascript (with <script></script> tags) for functions used to:
             toggle visibility of unordered list for display of detailed
             information about intervals.
   
   =back
   
 =cut  =cut
   
Line 405  use Apache::Constants qw(:common :http); Line 450  use Apache::Constants qw(:common :http);
 use Apache::loncommon();  use Apache::loncommon();
 use Apache::lonhtmlcommon();  use Apache::lonhtmlcommon();
 use Apache::lonparmset();  use Apache::lonparmset();
   use Apache::loncourserespicker();
 use HTML::Entities();  use HTML::Entities();
 use Apache::lonlocal;  use Apache::lonlocal;
 use lib '/home/httpd/lib/perl/';  use lib '/home/httpd/lib/perl/';
 use LONCAPA qw(:DEFAULT :match);  use LONCAPA qw(:DEFAULT :match);
   
   my $registered_cleanup;
   my $modified_courses;
   
 sub handler {  sub handler {
     my $r=shift;      my $r=shift;
   
Line 430  sub handler { Line 479  sub handler {
   
 # ----------------------------------------------------------- Permissions check  # ----------------------------------------------------------- Permissions check
   
     unless ((&Apache::lonnet::allowed('dcm',$env{'request.course.id'})) ||      my ($readonly,$allowed) = &get_permission();
             (&Apache::lonnet::allowed('dcm',$env{'request.course.id'}.      unless ($allowed) {
                                       '/'.$env{'request.course.sec'}))) {  
         $env{'user.error.msg'}=          $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;          return HTTP_NOT_ACCEPTABLE;
     }      }
   
 # -----------------------------Get action and calling context from query string  # -----------------------------Get action and calling context from query string
   
       $registered_cleanup=0;
       @{$modified_courses}=();
   
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                                             ['action','caller','block']);                                              ['action','caller','block']);
   
Line 476  sub handler { Line 527  sub handler {
             $r->print(&Apache::loncourserespicker::create_picker($navmap,              $r->print(&Apache::loncourserespicker::create_picker($navmap,
                                      'examblock','resourceblocks',$crstype,                                       'examblock','resourceblocks',$crstype,
                                      \%blockedmaps,\%blockedresources,                                       \%blockedmaps,\%blockedresources,
                                      $env{'form.block'}));                                       $env{'form.block'},'','',undef,undef,$readonly));
         } else {          } else {
             $r->print($errormsg);              $r->print($errormsg);
         }          }
Line 485  sub handler { Line 536  sub handler {
   
 # -------------------------- Store changes and retrieve latest block information  # -------------------------- Store changes and retrieve latest block information
     my $storeresult;      my $storeresult;
     if ($env{'form.action'} eq 'store') {      unless ($readonly) {
         (my $numchanges,$storeresult) = &blockstore($crstype,$blockcount);          if ($env{'form.action'} eq 'store') {
         if ($numchanges > 0) {              (my $numchanges,$storeresult) = &blockstore($r,$crstype,$blockcount,\%records);
             $blockcount = &get_blockdates(\%records);              if ($numchanges > 0) {
                   $blockcount = &get_blockdates(\%records);
               }
         }          }
     }      }
   
Line 506  sub handler { Line 559  sub handler {
     }      }
     &Apache::lonhtmlcommon::add_breadcrumb      &Apache::lonhtmlcommon::add_breadcrumb
         ({href=>'/adm/setblock',          ({href=>'/adm/setblock',
           text=>'Blocking communication/resource access'});            text=>'Blocking communication/content access'});
   
     my $js = &blockingmenu_javascript($blockcount);      my $js = &blockingmenu_javascript($blockcount).
                &details_javascript();
   
     $r->print(      $r->print(
         &Apache::loncommon::start_page('Blocking communication/content access',$js).          &Apache::loncommon::start_page('Blocking communication/content access',$js).
         &Apache::lonhtmlcommon::breadcrumbs('Blocking communication/content access'));          &Apache::lonhtmlcommon::breadcrumbs('Blocking communication/content access'));
   
     my $usertype;      my $usertype;
     my $crstype = &Apache::loncommon::course_type();  
     if ($crstype eq 'Community') {      if ($crstype eq 'Community') {
         $usertype = 'members';          $usertype = 'members';
     } else {      } else {
Line 525  sub handler { Line 578  sub handler {
     my %lt=&Apache::lonlocal::texthash (      my %lt=&Apache::lonlocal::texthash (
             'cbds' => 'Blocking communication and/or content access during exams',              '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:",              '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.",              '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 assigments in courses besides your own. Please use this feature wisely.",              '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:",              'actt' => "Action to take:",
             'addn' => 'Add new blocking event',              'addn' => 'Add new blocking event',
             'mexb' => 'Modify existing blocking event(s)',               'mexb' => 'Modify existing blocking event(s)', 
Line 564  sub handler { Line 618  sub handler {
             '<ul>'."\n".              '<ul>'."\n".
             '<li>'.&mt("displaying LON-CAPA messages sent by other $usertype in the $lctype").'</li>'."\n".              '<li>'.&mt("displaying LON-CAPA messages sent by other $usertype in the $lctype").'</li>'."\n".
             '<li>'.&mt("displaying or posting to LON-CAPA discussion boards or live chat in the $lctype").'</li>'."\n".              '<li>'.&mt("displaying or posting to LON-CAPA discussion boards or live chat in the $lctype").'</li>'."\n".
             '<li>'.&mt('accessing content in LON-CAPA portfolios or blogs').'</li>'."\n".              '<li>'.&mt('accessing content in LON-CAPA portfolios, blogs, or user information pages').'</li>'."\n".
               '<li>'.&mt("generating printouts of $lctype content").'</li>'.
               '<li>'.&mt("displaying the LON-CAPA gradebook in the $lctype").'</li>'.
               '<li>'.&mt("searching $lctype content by keyword").'</li>'.  
             '<li>'.&mt("accessing $lctype content in specified folders or resources").'</li>'.              '<li>'.&mt("accessing $lctype content in specified folders or resources").'</li>'.
               '<li>'.&mt("changing user's own password").'</li>'.
               '</ul>'.
               $lt{'flow'}.
               '<ul>'."\n".
               '<li>'.&mt("re-initialization of cached course structure, when a change has been made to $lctype content by a Coordinator").'</li>'.
               '<li>'.&mt('display of Critical Messages when navigation arrows used to move to the adjacent resource').'</li>'.
             '</ul>'.              '</ul>'.
             '<p class="LC_warning">'.$lt{'blca'}.'<br />'.$lt{'pobl'}.'</p>'              '<p class="LC_warning">'.$lt{'blca'}.'<br />'.$lt{'pobl'}.'</p>'
         );          );
Line 573  sub handler { Line 636  sub handler {
   
 # ------------------------ Choose between modifying existing block or adding new  # ------------------------ Choose between modifying existing block or adding new
     $r->print('<form name="blockform" method="post" action="/adm/setblock?action=store">');      $r->print('<form name="blockform" method="post" action="/adm/setblock?action=store">');
     if ($blockcount > 0) {  
          $r->print(<<"END");      unless ($readonly) {
           if ($blockcount > 0) {
               $r->print(<<"END");
 <div class="LC_left_float">  <div class="LC_left_float">
 <fieldset><legend>$lt{'actt'}</legend>  <fieldset><legend>$lt{'actt'}</legend>
 <span class="LC_nobreak">  <span class="LC_nobreak">
Line 591  onclick="toggleAddModify();" />$lt{'addn Line 656  onclick="toggleAddModify();" />$lt{'addn
 <br clear="all" />  <br clear="all" />
 <div id="showadd" style="display:none">  <div id="showadd" style="display:none">
 END  END
     } else {          } else {
         $r->print($lt{'ncbc'}.'<br /><br />'.              $r->print($lt{'ncbc'}.'<br /><br />'.
                   '<h4>'.$lt{'addn'}.'</h4>'.                        '<h4>'.$lt{'addn'}.'</h4>'.
                   '<input type="hidden" name="blockaction" value="add" />');                        '<input type="hidden" name="blockaction" value="add" />');
           }
     }      }
     my ($navmap,$errormsg) =      my ($navmap,$errormsg) =
         &Apache::loncourserespicker::get_navmap_object($crstype,'examblock');          &Apache::loncourserespicker::get_navmap_object($crstype,'examblock');
   
 # --------------------------------------------- Interface for adding a new block  # --------------------------------------------- Interface for adding a new block
     &display_addblocker_table($r,$blockcount,\%ltext,\%intervals,      unless ($readonly) {
                               $navmap,$errormsg);          &display_addblocker_table($r,$blockcount,\%ltext,\%intervals,
                                     $navmap,$errormsg);
 # ------------------------------------------------- Interface for existig blocks          if ($blockcount > 0) {
     if ($blockcount > 0) {              $r->print('</div>');
         $r->print('</div>');          }
       }
   # ------------------------------------------------ Interface for existing blocks
       if (!$blockcount) {
           if ($readonly) {
               $r->print($lt{'ncbc'}.'<br />');
           }
       } else {
         &display_blocker_status($r,\%records,\%ltext,\%intervals,          &display_blocker_status($r,\%records,\%ltext,\%intervals,
                                 $navmap,$errormsg,$blockcount);                                  $navmap,$errormsg,$blockcount,$readonly);
     }      }
     $r->print(<<"END");      unless ($readonly) {
           $r->print(<<"END");
 <br />  <br />
 <input type ="submit" value="$lt{'stor'}" />  <input type ="submit" value="$lt{'stor'}" />
 </form>  
 END  END
     $r->print(&Apache::loncommon::end_page());      }
       $r->print('</form>'.
                 &Apache::loncommon::end_page());
     return OK;      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 {  sub get_timed_items {
     my ($cdom,$cnum) = @_;      my ($cdom,$cnum) = @_;
     my ($cid,%intervals);      my ($cid,%intervals);
Line 634  sub get_timed_items { Line 727  sub get_timed_items {
     my $resourcedata=&Apache::lonparmset::readdata($cnum,$cdom);      my $resourcedata=&Apache::lonparmset::readdata($cnum,$cdom);
     if (ref($resourcedata) eq 'HASH') {      if (ref($resourcedata) eq 'HASH') {
         foreach my $key (keys(%{$resourcedata})) {          foreach my $key (keys(%{$resourcedata})) {
             if ($key =~ /^\Q$cid\E(.+)\.0\.interval$/) {              if ($key =~ /^\Q$cid\E(.*)\.0\.interval$/) {
                 my $middle = $1;                  my $middle = $1;
                 if ($middle eq '') {                  if ($middle eq '') {
                     $intervals{'course'}{'all'} = $resourcedata->{$key};                      $intervals{'course'}{'all'} = $resourcedata->{$key};
Line 666  sub get_timed_items { Line 759  sub get_timed_items {
 }  }
   
 sub blockstore {  sub blockstore {
     my ($crstype,$blockcount) = @_;      my ($r,$crstype,$blockcount,$currblockrecs) = @_;
     my %lt=&Apache::lonlocal::texthash(      my %lt=&Apache::lonlocal::texthash(
             'tfcm' => 'The following changes were made',              'tfcm' => 'The following changes were made',
             'ncwm' => 'No changes were made.',              'ncwm' => 'No changes were made.',
Line 681  sub blockstore { Line 774  sub blockstore {
     my $changestotal = 0;      my $changestotal = 0;
     my $addtimer = 0;      my $addtimer = 0;
     my %blocking = ();      my %blocking = ();
     my (%map_url,%resource_symb,$output);      my (%map_url,%resource_symb,%titles,$output);
     $output = '<h3>'.$lt{'head'}.'</h3>';      $output = '<h3>'.$lt{'head'}.'</h3>';
     if ($env{'form.blockaction'} eq 'modify') {      if ($env{'form.blockaction'} eq 'modify') {
         foreach my $envkey (keys(%env)) {          foreach my $envkey (keys(%env)) {
Line 707  sub blockstore { Line 800  sub blockstore {
         $output = $lt{'unna'}.' '.$lt{'ncwm'}.'</br>';          $output = $lt{'unna'}.' '.$lt{'ncwm'}.'</br>';
         return ($changestotal,$output);          return ($changestotal,$output);
     }      }
     &enumerate_course_contents($navmap,\%map_url,\%resource_symb);      &Apache::loncourserespicker::enumerate_course_contents($navmap,\%map_url,\%resource_symb,\%titles,'examblock');
       my $do_releasereq_update;
       my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
       my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
       my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
       my $chostname = &Apache::lonnet::hostname($chome);
       my ($chomemajor,$chomeminor) =
           split(/\./,&Apache::lonnet::get_server_loncaparev($cdom,$chome));
   
   
     foreach my $key (keys(%removals)) {      foreach my $key (keys(%removals)) {
         my $hashkey = $env{'form.key_'.$key};          my $hashkey = $env{'form.key_'.$key};
         &Apache::lonnet::del('comm_block',["$hashkey"],          if ($hashkey =~ /firstaccess____/) {
                          $env{'course.'.$env{'request.course.id'}.'.domain'},             $do_releasereq_update = 1;
                          $env{'course.'.$env{'request.course.id'}.'.num'}          }
                          );          if (ref($currblockrecs->{$hashkey}) eq 'HASH') {
               if (ref($currblockrecs->{$hashkey}->{'blocks'}) eq 'HASH') {
                   foreach my $type ('docs','printout') {
                       if (exists($currblockrecs->{$hashkey}->{'blocks'}->{$type})) {
                           $do_releasereq_update = 1;
                       }
                   }
               }
           }
           &Apache::lonnet::del('comm_block',["$hashkey"],$cdom,$cnum);
       }
       if ($do_releasereq_update) {
           push(@{$modified_courses},[$cdom,$cnum,$chome,$crstype]);
           unless ($registered_cleanup) {
               my $handlers = $r->get_handlers('PerlCleanupHandler');
               $r->set_handlers('PerlCleanupHandler' => [\&update_releasereq,@{$handlers}]);
               $registered_cleanup=1;
           }
     }      }
     foreach my $key (keys(%adds)) {      foreach my $key (keys(%adds)) {
         unless ( defined($cancels{$key}) ) {          unless ( defined($cancels{$key}) ) {
             my $newkey;              my ($newkey,$status,$needsrelease);;
             if ($env{'form.firstaccess_'.$key}) {              if ($env{'form.firstaccess_'.$key}) {
                 my $interval =                   my $interval = 
                     &HTML::Entities::decode($env{'form.firstaccess_'.$key});                      &HTML::Entities::decode($env{'form.firstaccess_'.$key});
Line 735  sub blockstore { Line 854  sub blockstore {
                     }                      }
                     if ($newkey ne '') {                      if ($newkey ne '') {
                         unless (defined($removals{$key})) {                          unless (defined($removals{$key})) {
                             $addtimer ++;                              ($status,$needsrelease) = &check_release_required('timer',$chomemajor,$chomeminor);
                               if ($status eq 'fail') {
                                   $newkey = '';
                                   $output .= '<p class="LC_warning">'.
                                              &mt('Triggering of blocking events not allowed for [_1]',
                                                  &escape($env{'form.title_'.$key})).'<br />';
                               }
                         }                          }
                     }                      }
                 }                  }
Line 743  sub blockstore { Line 868  sub blockstore {
                 my ($newstart,$newend) = &get_dates_from_form($key);                  my ($newstart,$newend) = &get_dates_from_form($key);
                 $newkey = $newstart.'____'.$newend;                  $newkey = $newstart.'____'.$newend;
             }              }
               if ($status eq 'fail') {
                   $output .=  &mt('LON-CAPA version ([_1]) installed on home server ([_2]) does not meet version requirements ([_3] or newer).',
                                   $chomemajor.'.'.$chomeminor,$chostname,$needsrelease).'</p>';
               }
             if ($newkey ne '') {              if ($newkey ne '') {
                 my ($blocktypes,$blockdocs) =                   my ($blocktypes,$blockdocs) = 
                     &get_block_choices($key,\%map_url,\%resource_symb);                      &get_block_choices($key,\%map_url,\%resource_symb);
                   if (ref($blocktypes) eq 'HASH') {
                       if ($blocktypes->{'printout'} eq 'on') {
                           ($status,$needsrelease) = &check_release_required('printout',$chomemajor,$chomeminor);
                           if ($status eq 'fail') {
                               $blocktypes->{'printout'} = 'off';
                               $output .= '<p class="LC_warning">'.
                                          &mt('Printout blocking not allowed for [_1]',
                                              &escape($env{'form.title_'.$key})).'<br />';
                           }
                       }
                       if ($blocktypes->{'alert'} eq 'on') {
                           ($status,$needsrelease) = &check_release_required('alert',$chomemajor,$chomeminor);
                           if ($status eq 'fail') {
                               $blocktypes->{'alert'} = 'off';
                               $output .= '<p class="LC_warning">'.
                                          &mt('Message Alert blocking not allowed for [_1]',
                                              &escape($env{'form.title_'.$key})).'<br />';
                           }
                       }
                       if ($blocktypes->{'reinit'} eq 'on') {
                           ($status,$needsrelease) = &check_release_required('reinit',$chomemajor,$chomeminor);
                           if ($status eq 'fail') {
                               $blocktypes->{'reinit'} = 'off';
                               $output .= '<p class="LC_warning">'.
                                          &mt('Course Re-initialization blocking not allowed for [_1]',
                                              &escape($env{'form.title_'.$key})).'<br />';
                           }
                       }
                   }
                   if ($blockdocs) {
                       ($status,$needsrelease) = &check_release_required('docs',$chomemajor,$chomeminor);
                       if ($status eq 'fail') {
                           delete($blocktypes->{'docs'});
                           $output .= '<p class="LC_warning">'.
                                      &mt('Content blocking not allowed for [_1]',
                                          &escape($env{'form.title_'.$key})).'<br />';
                       }
                   }
                 $blocking{$newkey} = {                  $blocking{$newkey} = {
                           setter => $env{'user.name'}.':'.$env{'user.domain'},                            setter => $env{'user.name'}.':'.$env{'user.domain'},
                           event  => &escape($env{'form.title_'.$key}),                            event  => &escape($env{'form.title_'.$key}),
                           blocks => $blocktypes,                            blocks => $blocktypes,
                         };                          };
                 if ($blockdocs) {  
                     &check_release_required('docs');  
                 }  
                 if (ref($blocktypes) eq 'HASH') {  
                     if ($blocktypes->{'printout'} eq 'on') {  
                         &check_release_required('printout');  
                     }  
                 }  
                 if (exists($removals{$key})) {                  if (exists($removals{$key})) {
                     $modtotal ++;                      $modtotal ++;
                 } else {                  } else {
Line 766  sub blockstore { Line 925  sub blockstore {
                 }                  }
             } else {              } else {
                 if ($env{'form.toggle_'.$key} eq 'timer') {                  if ($env{'form.toggle_'.$key} eq 'timer') {
                     $output .= '<p class="LC_warning">'.                      unless ($status eq 'fail') {
                                &mt('Invalid trigger for new blocking event').                          $output .= '<p class="LC_warning">'.
                                '</p>';                                     &mt('Invalid trigger for new blocking event').
                                      '</p>';
                       }
                 } else {                  } else {
                     $output .= '<p class="LC_warning">'.                      $output .= '<p class="LC_warning">'.
                                &mt('No date range found for new blocking event').                                 &mt('No date range found for new blocking event').
Line 782  sub blockstore { Line 943  sub blockstore {
                      $env{'course.'.$env{'request.course.id'}.'.domain'},                       $env{'course.'.$env{'request.course.id'}.'.domain'},
                      $env{'course.'.$env{'request.course.id'}.'.num'}                       $env{'course.'.$env{'request.course.id'}.'.num'}
                      );                       );
         if ($addtimer) {  
             &check_release_required('timer');  
         }  
     }      }
     $changestotal = $canceltotal + $modtotal + $addtotal;      $changestotal = $canceltotal + $modtotal + $addtotal;
     if ($changestotal > 0) {      if ($changestotal > 0) {
Line 817  sub blockstore { Line 975  sub blockstore {
     return ($changestotal,$output);      return ($changestotal,$output);
 }  }
   
 sub enumerate_course_contents {  sub update_releasereq {
     my ($navmap,$map_url,$resource_symb) = @_;      my $readmap = 1;
     if ((ref($navmap)) && (ref($map_url) eq 'HASH') &&       my $getrelreq = 1;
         (ref($resource_symb) eq 'HASH')) {      if (ref($modified_courses) eq 'ARRAY') {
         my $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);          foreach my $item (@{$modified_courses}) {
         my $count = 0;              if (ref($item) eq 'ARRAY') {
         while (my $curRes = $it->next()) {                  my ($cdom,$cnum,$chome,$crstype) = @{$item};
             if (ref($curRes)) {                  &Apache::lonrelrequtils::modify_course_relreq(undef,undef,$cnum,$cdom,
                 $count ++;                                                                $chome,$crstype,$cdom.'_'.$cnum,
                 my $symb = $curRes->symb();                                                                $readmap,$getrelreq);
                 my $ressymb = $symb;  
                 if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {  
                     unless ($ressymb =~ m|adm/wrapper/adm|) {  
                         $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.  
                                    '/bulletinboard';  
                     }  
                 }  
                 if (($curRes->is_sequence()) || ($curRes->is_page())) {  
                     $map_url->{$count} = (&Apache::lonnet::decode_symb($symb))[2];  
                 } else {  
                     $resource_symb->{$count} = $ressymb;  
                 }  
             }              }
         }          }
           $modified_courses = [];
     }      }
       undef($registered_cleanup);
     return;      return;
 }  }
   
Line 881  sub get_block_choices { Line 1029  sub get_block_choices {
                     if (ref($symb_ref) eq 'HASH') {                      if (ref($symb_ref) eq 'HASH') {
                         my %resources = map { $symb_ref->{$_} => 1; }                           my %resources = map { $symb_ref->{$_} => 1; } 
                                             (split(/,/,$env{'form.docs_resources_'.$item}));                                              (split(/,/,$env{'form.docs_resources_'.$item}));
                           if (exists($resources{''})) {
                               delete($resources{''});
                           }
                         $blocklist->{$type}->{resources} = \%resources;                          $blocklist->{$type}->{resources} = \%resources;
                         if (keys(%resources) > 0) {                          if (keys(%resources) > 0) {
                             $blockdocs = 1;                              $blockdocs = 1;
Line 892  sub get_block_choices { Line 1043  sub get_block_choices {
                     if (ref($map_ref) eq 'HASH') {                      if (ref($map_ref) eq 'HASH') {
                         my %maps = map { $map_ref->{$_} => 1; }                                                       my %maps = map { $map_ref->{$_} => 1; }                             
                                        (split(/,/,$env{'form.docs_maps_'.$item}));                                         (split(/,/,$env{'form.docs_maps_'.$item}));
                           if (exists($maps{''})) {
                               delete($maps{''});
                           }
                         $blocklist->{$type}->{maps} = \%maps;                          $blocklist->{$type}->{maps} = \%maps;
                         if (keys(%maps) > 0) {                          if (keys(%maps) > 0) {
                             $blockdocs = 1;                              $blockdocs = 1;
Line 911  sub get_block_choices { Line 1065  sub get_block_choices {
 }  }
   
 sub check_release_required {  sub check_release_required {
     my ($value) = @_;       my ($value,$chomemajor,$chomeminor) = @_; 
     my $needsrelease = $Apache::lonnet::needsrelease{'course:commblock:'.$value};      my $needsrelease = $Apache::lonnet::needsrelease{'course:commblock:'.$value};
     if ($needsrelease) {      if ($needsrelease) {
         my $curr_required =           my ($needsmajor,$needsminor) = split(/\./,$needsrelease);
           if (($chomemajor < $needsmajor) || 
               (($chomemajor == $needsmajor) && ($chomeminor < $needsminor))) {
               return ('fail',$needsrelease);
           }
           my $curr_required =
             $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};              $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};
         if ($curr_required eq '') {          if ($curr_required eq '') {
             &Apache::lonnet::update_released_required($needsrelease);              &Apache::lonnet::update_released_required($needsrelease);
Line 927  sub check_release_required { Line 1086  sub check_release_required {
             }              }
         }          }
     }      }
     return;      return ('ok',$needsrelease);
 }  }
   
 sub display_blocker_status {  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 $parmcount = 0;
     my (%map_url,%resource_symb,%lookups);      my (%map_url,%resource_symb,%titles,%lookups,$disabled);
     &enumerate_course_contents($navmap,\%map_url,\%resource_symb);      &Apache::loncourserespicker::enumerate_course_contents($navmap,\%map_url,\%resource_symb,\%titles,'examblock');
     %{$lookups{'maps'}} = reverse(%map_url);      %{$lookups{'maps'}} = reverse(%map_url);
     %{$lookups{'resources'}} = reverse(%resource_symb);      %{$lookups{'resources'}} = reverse(%resource_symb);
     my %lt = &Apache::lonlocal::texthash(      my %lt = &Apache::lonlocal::texthash(
Line 943  sub display_blocker_status { Line 1102  sub display_blocker_status {
         'noch' => 'No change',          'noch' => 'No change',
     );      );
     $r->print('<div id="showmodify" style="display:block">'.      $r->print('<div id="showmodify" style="display:block">'.
               &Apache::loncommon::start_data_table());                &Apache::loncommon::start_data_table().'<tr>');
       if ($readonly) {
           $disabled = ' disabled="disabled"';
       } else {
           $r->print('<th></th>');
       }
     $r->print(<<"END");      $r->print(<<"END");
   <tr>  
     <th></th>  
     <th>$ltext->{'type'}</th>      <th>$ltext->{'type'}</th>
     <th>$ltext->{'even'}</th>      <th>$ltext->{'even'}</th>
     <th>$ltext->{'blck'}</th>      <th>$ltext->{'blck'}</th>
Line 965  END Line 1127  END
            &Apache::loncommon::aboutmewrapper(             &Apache::loncommon::aboutmewrapper(
                            &Apache::loncommon::plainname($setuname,$setudom),                             &Apache::loncommon::plainname($setuname,$setudom),
                            $setuname,$setudom);                             $setuname,$setudom);
           my $state = '';
         $r->print(&Apache::loncommon::start_data_table_row());          $r->print(&Apache::loncommon::start_data_table_row());
         $r->print(<<"ACT");          if ($readonly) {
               $state = 'disabled';
           } else {
               $r->print(<<"ACT");
   
         <td valign="middle"><span class="LC_nobreak"><label>          <td valign="middle"><span class="LC_nobreak"><label>
         <input type="radio" name="action_$parmcount" value="modify" />$lt{'modi'}          <input type="radio" name="action_$parmcount" value="modify" />$lt{'modi'}
Line 980  END Line 1146  END
         </label></span>          </label></span>
         </td>          </td>
 ACT  ACT
           }
         my ($start,$end,$startform,$endform);           my ($start,$end,$startform,$endform); 
         if ($record =~ /^(\d+)____(\d+)$/) {          if ($record =~ /^(\d+)____(\d+)$/) {
             ($start,$end) = split(/____/,$record);              ($start,$end) = split(/____/,$record);
             $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.              $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.
                                                              $parmcount,$start,$onchange);                                                               $parmcount,$start,$onchange,
                                                                undef,$state);
             $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.              $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.
                                                            $parmcount,$end,$onchange);                                                             $parmcount,$end,$onchange,
                                                              undef,$state);
             $r->print('<td><fieldset><legend>'.$ltext->{'defs'}.'</legend>'.              $r->print('<td><fieldset><legend>'.$ltext->{'defs'}.'</legend>'.
                       $ltext->{'star'}.':&nbsp;'.$startform.'<br />'.                        $ltext->{'star'}.':&nbsp;'.$startform.'<br />'.
                       $ltext->{'endd'}.':&nbsp;&nbsp;'.$endform.'</fieldset></td>');                        $ltext->{'endd'}.':&nbsp;&nbsp;'.$endform.'</fieldset></td>');
         } elsif ($record =~ /^firstaccess____(.+)$/) {          } elsif ($record =~ /^firstaccess____(.+)$/) {
             my $item = $1;              my $item = $1;
             my ($itemname,$iteminfo,$skipdetails);  
             my $type = 'map';              my $type = 'map';
             my $url;              my $url;
             if ($item eq 'course') {              if ($item eq 'course') {
Line 1004  ACT Line 1172  ACT
                 $url = $item;                  $url = $item;
             }              }
             $r->print('<td><fieldset><legend>'.$ltext->{'trig'}.'</legend>');              $r->print('<td><fieldset><legend>'.$ltext->{'trig'}.'</legend>');
             if ($type eq 'course') {              my ($itemname,$iteminfo) = &interval_details($item,$type,$url,$navmap,$intervals,$parmcount);
                 $itemname = &mt('Timer for all items in course.');              $r->print(&create_interval_form($intervals,$parmcount,$navmap,'blocking',$item,$jschg,
             } else {                                              $itemname,$iteminfo,$disabled).'</fieldset></td>');
                 if (&Apache::lonnet::is_on_map($url)) {   
                     if ($type eq 'map') {  
                         if (ref($navmap)) {  
                             my $res = $navmap->getResourceByUrl($item);  
                             my $title = $res->compTitle();  
                             $itemname = &mt('Timer for all items in folder: [_1]',  
                                             '<span style="font-style:italic">'.  
                                             $title.'</span>');  
                         }  
                     } else {  
                         if (ref($navmap)) {  
                             my $res = $navmap->getBySymb($item);  
                             my $title = $res->compTitle();  
                             $itemname = &mt('Timer for resource: [_1]',  
                                              '<span style="font-style:italic">'.  
                                              $title.'</span>');  
                         }  
                     }  
                     if (ref($navmap)) {  
                         my $path = &show_timer_path($type,$item);  
                         if ($path) {  
                             $iteminfo  = ' <span style="font-size:90%;">'.  
                                          &mt('(in: [_1])',$path).  
                                          '</span>';  
                         }  
                     }  
                 } else {  
                     $skipdetails = 1;  
                     $itemname = '<span style="LC_warning">'.  
                                 &mt('Timer folder/resource not in course').  
                                 '</span>';    
                 }  
             }  
             if ((!$skipdetails) && (ref($intervals) eq 'HASH')) {  
                 if (ref($intervals->{$type}) eq 'HASH') {  
                     $iteminfo .= &trigger_details_toggle($parmcount).  
                                 '<ul id="trigdetails_'.$parmcount.'" style="display:none">';  
                     if ($type eq 'course') {  
                         foreach my $scope (keys(%{$intervals->{$type}})) {  
                             if ($scope eq 'all') {  
                                 $iteminfo .= '<li>'.&mt('All users -- time limit: [_1]',  
                                          &convlim($intervals->{$type}->{$scope})).'</li>';  
                             } elsif ($scope eq 'secgrp') {  
                                 if (ref($intervals->{$type}->{$scope}) eq 'HASH') {  
                                     $iteminfo .= '<li>'.&mt('Sections/groups').'<ul>';  
                                     foreach my $item (sort(keys(%{$intervals->{$type}->{$scope}}))) {  
                                         $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',$item,  
                                                      &convlim($intervals->{$type}->{$scope}->{$item})).  
                                                      '</li>';  
                                     }  
                                     $iteminfo .= '</ul></li>';  
                                 }  
                             } elsif ($scope eq 'users') {  
                                 if (ref($intervals->{$type}->{$scope}) eq 'HASH') {  
                                     $iteminfo .= '<li>'.&mt('Users').'<ul>';   
                                     foreach my $item (sort(keys(%{$intervals->{$type}->{$scope}}))) {  
                                         $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',  
                                                      &convlim($item,$intervals->{$type}->{$scope}->{$item})).  
                                                      '</li>';  
                                     }  
                                     $iteminfo .= '</ul></li>';  
                                 }  
                             }  
                         }  
                     } elsif (($type eq 'map') || ($type eq 'resource')) {  
                         if (ref($intervals->{$type}->{$item}) eq 'HASH') {   
                             foreach my $scope (keys(%{$intervals->{$type}->{$item}})) {  
                                 if ($scope eq 'all') {  
                                     $iteminfo .= '<li>'.&mt('All users -- time limit: [_1]',  
                                                   &convlim($intervals->{$type}->{$item}->{$scope})).  
                                                   '</li>';  
                                 } elsif ($scope eq 'secgrp') {  
                                     if (ref($intervals->{$type}->{$item}->{$scope}) eq 'HASH') {  
                                         $iteminfo .= '<li>'.&mt('Sections/groups').'<ul>';  
                                         foreach my $sec (sort(keys(%{$intervals->{$type}->{$item}->{$scope}}))) {  
                                             $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',$sec,  
                                                          &convlim($intervals->{$type}->{$item}->{$scope}->{$sec})).  
                                                          '</li>';  
                                         }  
                                         $iteminfo .= '</ul></li>';   
                                     }  
                                 } elsif ($scope eq 'users') {  
                                     if (ref($intervals->{$type}->{$item}->{$scope}) eq 'HASH') {  
                                         $iteminfo .= '<li>'.&mt('Users').'<ul>';  
                                         foreach my $user (sort(keys(%{$intervals->{$type}->{$item}->{$scope}}))) {  
                                             $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',$user,  
                                                          &convlim($intervals->{$type}->{$item}->{$scope}->{$user})).  
                                                          '</li>';  
                                         }  
                                         $iteminfo .= '</ul></li>';  
                                     }  
                                 }  
                             }  
                         }  
                     }  
                     $iteminfo .= '</ul>';  
                 }  
             }  
             $r->print(&create_interval_form($intervals,$parmcount,$navmap,$item,$jschg,  
                                             $itemname,$iteminfo).'</fieldset></td>');  
         }          }
         $r->print(<<"END");          $r->print(<<"END");
         <td>          <td>
          <input type="text" name="title_$parmcount" size="15" value="$title" onfocus="$jschg" />           <input type="text" name="title_$parmcount" size="15" value="$title" onfocus="$jschg" $disabled />
          <input type="hidden" name="key_$parmcount" value="$blockid" />           <input type="hidden" name="key_$parmcount" value="$blockid" />
          <br />           <br />
          <br />           <br />
          $ltext->{'setb'}: $settername           $ltext->{'setb'}: $settername
         </td>          </td>
 END  END
         $r->print('<td>'.&blocker_checkboxes($parmcount,$blocks,$jschg,\%lookups).'</td>'.          $r->print('<td>'.&blocker_checkboxes($parmcount,$blocks,$jschg,\%lookups,$disabled).'</td>'.
                   &Apache::loncommon::end_data_table_row());                    &Apache::loncommon::end_data_table_row());
         $parmcount++;          $parmcount++;
     }      }
Line 1128  END Line 1196  END
     return;      return;
 }  }
   
 sub path_to_trigger {  
     my ($navmap,$map,$type) = @_;  
     my @pathitems;  
     if (ref($navmap)) {  
         my $mapres = $navmap->getResourceByUrl($map);  
         if (ref($mapres)) {  
             my $pcslist = $mapres->map_hierarchy();  
             if ($pcslist ne '') {  
                 my @pcs = split(/,/,$pcslist);  
                 foreach my $pc (@pcs) {      
                     if ($pc == 1) {  
                         push(@pathitems,&mt('Main Course Documents'));  
                     } else {  
                         my $res = $navmap->getByMapPc($pc);  
                         if (ref($res)) {  
                             my $title = $res->compTitle();  
                             $title =~ s/\W+/_/g;  
                             if ($title ne '') {  
                                 push(@pathitems,$title);  
                             }  
                         }  
                     }  
                 }  
             }  
         }  
         if ($type eq 'resource') {  
             if ($mapres->{ID} eq '0.0') {  
                 push(@pathitems,&mt('Main Course Documents'));  
             } else {  
                 my $maptitle = $mapres->compTitle();  
                 $maptitle =~ s/\W+/_/g;  
                 if ($maptitle ne '') {  
                     push(@pathitems,$maptitle);  
                 }  
             }  
         }  
     }  
     return @pathitems;  
 }  
   
 sub convlim {  sub convlim {
     my ($timelimit) = @_;      my ($timelimit) = @_;
     my $output;  
     my @order = ('days','hours','minutes','seconds');      my @order = ('days','hours','minutes','seconds');
     my %catlimits = (       my %catlimits = ( 
                       days    => 86400,                        days    => 86400,
Line 1180  sub convlim { Line 1207  sub convlim {
     my @toshow;      my @toshow;
     foreach my $cat (@order) {      foreach my $cat (@order) {
         if ($cat eq 'seconds') {          if ($cat eq 'seconds') {
             last if ($timelimit <= 0);              if ($timelimit > 0) {
                   push(@toshow,&mt("[_1] $cat",$timelimit));
               }
         } elsif ($timelimit >= $catlimits{$cat}) {          } elsif ($timelimit >= $catlimits{$cat}) {
             my $val = int($timelimit/$catlimits{$cat});              my $val = int($timelimit/$catlimits{$cat});
             if ($val > 0) {              if ($val > 0) {
                 push(@toshow,&mt("[_1] $cat",$val));                  push(@toshow,&mt("[_1] $cat",$val));
             }              }
             $timelimit =- $val*$catlimits{$cat};              $timelimit -= $val*$catlimits{$cat};
         }          }
     }      }
     my $output = join(', ',@toshow);      my $output = join(', ',@toshow);
Line 1208  sub display_addblocker_table { Line 1237  sub display_addblocker_table {
     my %lt = &Apache::lonlocal::texthash(      my %lt = &Apache::lonlocal::texthash(
         'exam' => 'e.g., Exam 1',          'exam' => 'e.g., Exam 1',
     );      );
     my $intervalform = &create_interval_form($intervals,$parmcount,$navmap);      my $intervalform = &create_interval_form($intervals,$parmcount,$navmap,'blocking');
     if ($intervalform ne '') {      if ($intervalform ne '') {
         $intervalform = '<fieldset>'.          $intervalform = '<fieldset>'.
                         '<legend>'.$ltext->{'chtr'}.'</legend>'.                          '<legend>'.$ltext->{'chtr'}.'</legend>'.
Line 1246  END Line 1275  END
 }  }
   
 sub blocker_checkboxes {  sub blocker_checkboxes {
     my ($parmcount,$blocks,$jschg,$lookups) = @_;      my ($parmcount,$blocks,$jschg,$lookups,$disabled) = @_;
     my ($typeorder,$types) = &blocktype_text();      my ($typeorder,$types) = &blocktype_text();
     my $numinrow = 2;      my $numinrow = 2;
     my %currdocs;      my %currdocs;
Line 1313  sub blocker_checkboxes { Line 1342  sub blocker_checkboxes {
         }           } 
         $output .= '<span class="LC_nobreak"><label>'."\n".          $output .= '<span class="LC_nobreak"><label>'."\n".
                    '<input type="checkbox" id="'.$item.'" name="'.$item.'"'.                     '<input type="checkbox" id="'.$item.'" name="'.$item.'"'.
                    $blockstatus.$clickaction.' value="1" />'.                     $blockstatus.$clickaction.' value="1"'.$disabled.' />'.
                    $types->{$block}.'</label></span>'."\n";                     $types->{$block}.'</label></span>'."\n";
         if ($block eq 'docs') {          if ($block eq 'docs') {
             if ($blockstatus ne '') {              if ($blockstatus ne '') {
Line 1332  sub blocker_checkboxes { Line 1361  sub blocker_checkboxes {
 }  }
   
 sub create_interval_form {  sub create_interval_form {
     my ($intervals,$parmcount,$navmap,$currkey,$jschg,$itemname,$iteminfo) = @_;      my ($intervals,$parmcount,$navmap,$context,$currkey,$jschg,$itemname,$iteminfo,$disabled) = @_;
     return unless ((ref($intervals) eq 'HASH') && (ref($navmap)));      return unless ((ref($intervals) eq 'HASH') && (ref($navmap)));
     my $intervalform;      my $intervalform;
       my $counter = 0;
     if (keys(%{$intervals}) > 0) {      if (keys(%{$intervals}) > 0) {
         foreach my $type (sort(keys(%{$intervals}))) {          foreach my $type (sort(keys(%{$intervals}))) {
             if ($type eq 'course') {              if ($type eq 'course') {
Line 1345  sub create_interval_form { Line 1375  sub create_interval_form {
                     $clickaction = ' onclick="'.$jschg.'"';                      $clickaction = ' onclick="'.$jschg.'"';
                 }                  }
                 $intervalform .= '<label><input type="radio" name="firstaccess_'.$parmcount.                  $intervalform .= '<label><input type="radio" name="firstaccess_'.$parmcount.
                                  '" value="course"'.$checked.$clickaction.' />';                                   '" value="course"'.$checked.$clickaction.$disabled.' />';
                 if ($currkey eq 'course') {                  if ($currkey eq 'course') {
                     $intervalform .= $itemname;                      $intervalform .= $itemname;
                 } else {                  } else {
Line 1354  sub create_interval_form { Line 1384  sub create_interval_form {
                 $intervalform .= '</label>';                  $intervalform .= '</label>';
                 if ($currkey eq 'course') {                  if ($currkey eq 'course') {
                     $intervalform .= $iteminfo;                      $intervalform .= $iteminfo;
                   } elsif ($context eq 'accesstimes') {
                       (undef,$iteminfo) = &interval_details('course',$type,'',$navmap,$intervals,$counter);
                       if ($iteminfo) {
                           $intervalform .= ' '.$iteminfo;
                       }
                 }                  }
                 $intervalform .= '<br />';                  $intervalform .= '<br />';
                   $counter ++;
             } elsif ($type eq 'map') {              } elsif ($type eq 'map') {
                 if (ref($intervals->{$type}) eq 'HASH') {                  if (ref($intervals->{$type}) eq 'HASH') {
                     if (ref($navmap)) {                      if (ref($navmap)) {
                         foreach my $map (sort(keys(%{$intervals->{$type}}))) {                          foreach my $map (sort(keys(%{$intervals->{$type}}))) {
                               next if ((!&Apache::lonnet::is_on_map($map)) &&
                                        ($currkey ne $map));
                             my ($checked,$clickaction);                              my ($checked,$clickaction);
                             if ($currkey eq $map) {                              if ($currkey eq $map) {
                                 $checked = ' checked="checked"';                                  $checked = ' checked="checked"';
Line 1368  sub create_interval_form { Line 1406  sub create_interval_form {
                             }                              }
                             $intervalform .= '<label><input type="radio" name="firstaccess_'.$parmcount.                              $intervalform .= '<label><input type="radio" name="firstaccess_'.$parmcount.
                                              '" value="'.&HTML::Entities::encode($map,'"<>&').'"'.                                               '" value="'.&HTML::Entities::encode($map,'"<>&').'"'.
                                              $checked.$clickaction.' />';                                               $checked.$clickaction.$disabled.' />';
                             if ($currkey eq $map) {                              if ($currkey eq $map) {
                                 $intervalform .= $itemname.'</label>';                                  $intervalform .= $itemname.'</label>'.$iteminfo;
                             } else {                              } else {
                                 my $res = $navmap->getResourceByUrl($map);                                  my ($resobj,$title,$path,$hierarchy);
                                 my $title = $res->compTitle();                                  $resobj = $navmap->getResourceByUrl($map);
                                 my $path;                                  if (ref($resobj)) {
                                 my $hierarchy = &show_timer_path($type,$map,$navmap);                                      $title = $resobj->compTitle();
                                   } else {
                                       $title = &Apache::lonnet::gettitle($map);
                                   }
                                   $hierarchy = &show_timer_path($type,$map,$navmap);
                                 if ($hierarchy) {                                  if ($hierarchy) {
                                     $path = ' <span style="font-size:90%;">'.                                      $path = ' <span style="font-size:90%;">'.
                                             &mt('(in: [_1])',$hierarchy).                                              &mt('(in: [_1])',$hierarchy).
Line 1384  sub create_interval_form { Line 1426  sub create_interval_form {
                                 $intervalform .= &mt('Timer for all items in folder: [_1]',                                  $intervalform .= &mt('Timer for all items in folder: [_1]',
                                                      '<i>'.$title.'</i>').                                                       '<i>'.$title.'</i>').
                                                  '</label>'.$path;                                                   '</label>'.$path;
                             }                                  if ($context eq 'accesstimes') {
                             if ($currkey eq $map) {                                      (undef,$iteminfo) = &interval_details($map,$type,$map,$navmap,$intervals,$counter);
                                 $intervalform .= $iteminfo;                                      if ($iteminfo) {
                                           $intervalform .= ' '.$iteminfo;
                                       }
                                   }
                             }                              }
                             $intervalform .= '<br />';                              $intervalform .= '<br />';
                               $counter ++;
                         }                          }
                     }                      }
                 }                  }
Line 1396  sub create_interval_form { Line 1442  sub create_interval_form {
                 if (ref($intervals->{$type}) eq 'HASH') {                  if (ref($intervals->{$type}) eq 'HASH') {
                     if (ref($navmap)) {                      if (ref($navmap)) {
                         foreach my $resource (sort(keys(%{$intervals->{$type}}))) {                          foreach my $resource (sort(keys(%{$intervals->{$type}}))) {
                             my ($checked,$clickaction);                              my ($checked,$clickaction,$resobj);
                             if ($currkey eq $resource) {                              if ($currkey eq $resource) {
                                 $checked = ' checked="checked"';                                  $checked = ' checked="checked"';
                             } elsif ($jschg) {                              } else {
                                 $clickaction = ' onclick="'.$jschg.'"';                                  $resobj = $navmap->getBySymb($resource);
                                   next unless(ref($resobj));
                                   if ($jschg) {
                                       $clickaction = ' onclick="'.$jschg.'"';
                                   }
                             }                              }
                             $intervalform .= '<label><input type="radio" name="firstaccess_'.$parmcount.                              $intervalform .= '<label><input type="radio" name="firstaccess_'.$parmcount.
                                              '" value="'.&HTML::Entities::encode($resource,'"<>&').'"'.                                               '" value="'.&HTML::Entities::encode($resource,'"<>&').'"'.
                                              $checked.$clickaction.' />';                                               $checked.$clickaction.$disabled.' />';
                             if ($currkey eq $resource) {                              if ($currkey eq $resource) {
                                 $intervalform .= $itemname.'</label>';                                  $intervalform .= $itemname.'</label>'.$iteminfo;
                             } else {                              } else {
                                 my $res = $navmap->getBySymb($resource);                                  my ($title,$path,$hierarchy);
                                 my $title = $res->compTitle();                                  if (ref($resobj)) {
                                 my $path;                                      $title = $resobj->compTitle();
                                 my $hierarchy = &show_timer_path($type,$resource,$navmap);                                  }
                                   if ($title eq '') {
                                       $title = &Apache::lonnet::gettitle($resource);
                                   }
                                   $hierarchy = &show_timer_path($type,$resource,$navmap);
                                 if ($hierarchy) {                                  if ($hierarchy) {
                                     $path = ' <span style="font-size:90%;">'.                                      $path = ' <span style="font-size:90%;">'.
                                             &mt('(in: [_1])',$hierarchy).                                              &mt('(in: [_1])',$hierarchy).
Line 1420  sub create_interval_form { Line 1474  sub create_interval_form {
                                 $intervalform .= &mt('Timer for resource: [_1]','<i>'.$title.'</i>').                                  $intervalform .= &mt('Timer for resource: [_1]','<i>'.$title.'</i>').
                                                  '</label>'.                                                   '</label>'.
                                                  $path;                                                   $path;
                             }                                  if ($context eq 'accesstimes') {
                             if ($currkey eq $resource) {                                      if (ref($resobj)) {
                                 $intervalform .= $iteminfo;                                          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 .= '<br />';                              $intervalform .= '<br />';
                               $counter ++;
                         }                          }
                     }                      }
                 }                  }
Line 1434  sub create_interval_form { Line 1496  sub create_interval_form {
         if ($currkey ne '') {          if ($currkey ne '') {
             $intervalform = '<input type="radio" name="firstaccess_'.$parmcount.              $intervalform = '<input type="radio" name="firstaccess_'.$parmcount.
                             '" checked="checked" value="'.                              '" checked="checked" value="'.
                             &HTML::Entities::encode($currkey,'"<>&').' />'.                              &HTML::Entities::encode($currkey,'"<>&').'"'.$disabled.' />'.
                             $itemname.'<br />';                              $itemname.'<br />';
         } else {          } else {
             $intervalform = &mt('No timed items defined.').' '.              $intervalform = &mt('No timed items defined.').' '.
Line 1452  sub trigger_details_toggle { Line 1514  sub trigger_details_toggle {
            'style="text-decoration: none;"><b>'.&mt('(More ...)').'</b></a></span>';             'style="text-decoration: none;"><b>'.&mt('(More ...)').'</b></a></span>';
 }  }
   
   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]',
                                       '<span style="font-style:italic">'.
                                       $title.'</span>');
                   }
               } 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]',
                                       '<span style="font-style:italic">'.
                                       $title.'</span>');
                   }
               }
               if (ref($navmap)) {
                   my $path = &show_timer_path($type,$item);
                   if ($path) {
                      $iteminfo  = ' <span style="font-size:90%;">'.
                                     &mt('(in: [_1])',$path).
                                     '</span>';
                   }
               }
           } else {
               $skipdetails = 1;
               $itemname = '<span style="LC_warning">'.
                           &mt('Timer folder/resource not in course').
                           '</span>';
           }
       }
       if ((!$skipdetails) && (ref($intervals) eq 'HASH') && (ref($intervals->{$type}) eq 'HASH')) {
           $iteminfo = &trigger_details_toggle($parmcount).
                       '<ul id="trigdetails_'.$parmcount.'" style="display:none">';
           if ($type eq 'course') {
               foreach my $scope (keys(%{$intervals->{$type}})) {
                   if ($scope eq 'all') {
                       $iteminfo .= '<li>'.&mt('All users -- time limit: [_1]',
                                    &convlim($intervals->{$type}->{$scope})).'</li>';
                   } elsif ($scope eq 'secgrp') {
                       if (ref($intervals->{$type}->{$scope}) eq 'HASH') {
                           $iteminfo .= '<li>'.&mt('Sections/groups').'<ul>';
                           foreach my $item (sort(keys(%{$intervals->{$type}->{$scope}}))) {
                               $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',$item,
                                            &convlim($intervals->{$type}->{$scope}->{$item})).
                                            '</li>';
                           }
                           $iteminfo .= '</ul></li>';
                       }
                   } elsif ($scope eq 'users') {
                       if (ref($intervals->{$type}->{$scope}) eq 'HASH') {
                           $iteminfo .= '<li>'.&mt('Users').'<ul>';
                           foreach my $item (sort(keys(%{$intervals->{$type}->{$scope}}))) {
                               $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',
                                            &convlim($item,$intervals->{$type}->{$scope}->{$item})).
                                            '</li>';
                           }
                           $iteminfo .= '</ul></li>';
                       }
                   }
               }
           } elsif (($type eq 'map') || ($type eq 'resource')) {
               if (ref($intervals->{$type}->{$item}) eq 'HASH') {
                   foreach my $scope (keys(%{$intervals->{$type}->{$item}})) {
                       if ($scope eq 'all') {
                           $iteminfo .= '<li>'.&mt('All users -- time limit: [_1]',
                                        &convlim($intervals->{$type}->{$item}->{$scope})).
                                        '</li>';
                       } elsif ($scope eq 'secgrp') {
                           if (ref($intervals->{$type}->{$item}->{$scope}) eq 'HASH') {
                               $iteminfo .= '<li>'.&mt('Sections/groups').'<ul>';
                               foreach my $sec (sort(keys(%{$intervals->{$type}->{$item}->{$scope}}))) {
                                   $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',$sec,
                                                &convlim($intervals->{$type}->{$item}->{$scope}->{$sec})).
                                               '</li>';
                               }
                               $iteminfo .= '</ul></li>';
                           }
                       } elsif ($scope eq 'users') {
                           if (ref($intervals->{$type}->{$item}->{$scope}) eq 'HASH') {
                               $iteminfo .= '<li>'.&mt('Users').'<ul>';
                               foreach my $user (sort(keys(%{$intervals->{$type}->{$item}->{$scope}}))) {
                                   $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',$user,
                                                &convlim($intervals->{$type}->{$item}->{$scope}->{$user})).
                                                '</li>';
                               }
                               $iteminfo .= '</ul></li>';
                           }
                       }
                   }
               }
           }
           $iteminfo .= '</ul>';
       }
       return ($itemname,$iteminfo);
   }
   
 sub show_timer_path {  sub show_timer_path {
     my ($type,$item,$navmap) = @_;      my ($type,$item,$navmap) = @_;
     return unless(ref($navmap));      return unless(ref($navmap));
     my @pathitems;      my @pathitems;
     if ($type eq 'map') {      if ($type eq 'map') {
         @pathitems = &path_to_trigger($navmap,$item,$type);          @pathitems = 
               &Apache::loncommon::get_folder_hierarchy($navmap,$item);
     } elsif ($type eq 'resource') {      } elsif ($type eq 'resource') {
         my ($map,$id,$resource) = &Apache::lonnet::decode_symb($item);          my ($map,$id,$resource) = &Apache::lonnet::decode_symb($item);
         @pathitems = &path_to_trigger($navmap,$map,$type);          @pathitems = 
               &Apache::loncommon::get_folder_hierarchy($navmap,$map,1);
     }      }
     if (@pathitems) {      if (@pathitems) {
         return join(' &raquo; ',@pathitems);          return join(' &raquo; ',@pathitems);
Line 1476  sub blocktype_text { Line 1655  sub blocktype_text {
         'port' => 'Portfolio',          'port' => 'Portfolio',
         'groups' => 'Groups',          'groups' => 'Groups',
         'blogs' => 'Blogs',          'blogs' => 'Blogs',
           'about' => 'User Information',
         'docs' => 'Content',          'docs' => 'Content',
         'printout' => 'Printouts',          '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','printout','docs'];      my $typeorder = ['com','chat','boards','port','groups','blogs','about','printout','docs','grades','search','alert','reinit','passwd'];
     return ($typeorder,\%types);      return ($typeorder,\%types);
 }  }
   
 sub blockingmenu_javascript {  sub blockingmenu_javascript {
     my ($blockcount) = @_;      my ($blockcount) = @_;
     my %lt = &Apache::lonlocal::texthash (  
                                            more => 'More ...',  
                                            less => 'Less ...',  
                                          );  
     return <<ENDSCRIPT;      return <<ENDSCRIPT;
 <script type="text/javascript">  <script type="text/javascript">
 // <![CDATA[  // <![CDATA[
Line 1544  function toggleAddModify() { Line 1725  function toggleAddModify() {
     return;      return;
 }  }
   
   // ]]>
   </script>
   ENDSCRIPT
   
   }
   
   sub details_javascript {
       my %lt = &Apache::lonlocal::texthash (
                                              more => 'More ...',
                                              less => 'Less ...',
                                            );
       return <<ENDSCRIPT;
   
   <script type="text/javascript">
   // <![CDATA[
   
 function showTriggerDetails(item) {  function showTriggerDetails(item) {
     document.getElementById('trigdetails_'+item).style.display='block';      document.getElementById('trigdetails_'+item).style.display='block';
     document.getElementById('trigdetails_'+item).style.textAlign='left';      document.getElementById('trigdetails_'+item).style.textAlign='left';

Removed from v.1.5  
changed lines
  Added in v.1.29


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>