File:  [LON-CAPA] / loncom / interface / lonblockingmenu.pm
Revision 1.11: download - view: text, annotated - select for diffs
Fri Feb 28 19:20:05 2014 UTC (10 years, 4 months ago) by bisitz
Branches: MAIN
CVS tags: version_2_11_0_RC3, HEAD
Fix wording typos

    1: # The LearningOnline Network with CAPA
    2: # Routines for configuring blocking of access to collaborative functions, 
    3: # and specific resources during an exam
    4: #
    5: # $Id: lonblockingmenu.pm,v 1.11 2014/02/28 19:20:05 bisitz Exp $
    6: #
    7: # Copyright Michigan State University Board of Trustees
    8: #
    9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
   10: #
   11: # LON-CAPA is free software; you can redistribute it and/or modify
   12: # it under the terms of the GNU General Public License as published by
   13: # the Free Software Foundation; either version 2 of the License, or
   14: # (at your option) any later version.
   15: #
   16: # LON-CAPA is distributed in the hope that it will be useful,
   17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19: # GNU General Public License for more details.
   20: #
   21: # You should have received a copy of the GNU General Public License
   22: # along with LON-CAPA; if not, write to the Free Software
   23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   24: #
   25: # /home/httpd/html/adm/gpl.txt
   26: #
   27: # http://www.lon-capa.org/
   28: #
   29: ##############################################################
   30: ##############################################################
   31: 
   32: =pod
   33: 
   34: =head1 NAME
   35: 
   36: lonblockingmenu - Handler to set/modify exam blocks in a course.
   37: 
   38: =head1 SYNOPSIS
   39: 
   40: lonblockingmenu provides an interface for setting exam blocks in a course.  
   41: 
   42: =head1 DESCRIPTION
   43: 
   44: This module is used to configure blocking of access to collaborative tools
   45: and/or resources during an exam.
   46: 
   47: =head1 OVERVIEW
   48: 
   49: To support high-stakes testing, LON-CAPA provides Coordinators with the
   50: ability to disable communication and collaborative features within the
   51: system for the duration of an exam.
   52: 
   53: Features which can be disabled include:
   54: (a) those which a student could use to communicate with another student.
   55: Messaging, discussion, chat, blogs, and some functionality in groups fall 
   56: into this category.
   57: (b) those which a student could use to access materials prepared by the
   58: student in advance of an exam, (e.g., for use during an online exam, to
   59: gain an unfair advantage). Blogs and portfolio fall into this category.
   60: 
   61: For communication blocking to be truly effective in preventing unwanted
   62: communication, or access to online materials, online testing needs to
   63: take place in a lab setting where use of tools outside LON-CAPA, and use
   64: of web sites beyond LON-CAPA are unavailable.
   65: 
   66: Access to specified folder(s) and/or resources in the course contents 
   67: can also be restricted for the duration of an exam.
   68: 
   69: Exam blocks are of two types:
   70: (a) Blocks with a defined start and end date.
   71: (b) Blocks associated with a timed interval set for a specific folder,
   72: or resource.
   73: 
   74: When a student attempts to use a collaboration or communication feature
   75: which is currently blocked, information will be available about the
   76: duration of the block, and the identity of the Course Coordinator who
   77: set the block.
   78: 
   79: Although LON-CAPA communication can be blocked during an exam, course
   80: personnel with the 'evb' (evade blocking) privilege will continue to
   81: receive LON-CAPA messages sent from students in a course with an active
   82: block on messaging. Students will not be able to view messages sent by
   83: other students in the same course for the duration of the blocking event.
   84: 
   85: Because students may be enrolled in more than one LON-CAPA course at a time
   86: it is important to use reasonable time windows for blocking events, or, in
   87: the case of blocks triggered by clicking a button to start a timed quiz, 
   88: quiz durations that are of limited duration. This is especially important
   89: when blocking prtfolio access, as other courses may require students to use
   90: the portfolio as a mechanism for submitting assignments.
   91: 
   92: Information about blocks in a course will be cached for 10 minutes, so,
   93: as with parameters set for resources, it can take up to 10 minutes for
   94: new blocks, or changes to existing blocks, to propagate to other servers.
   95: 
   96: Changes to existing blocks on the server hosting your current session
   97: are available immediately, as cached data on blocks is devalidated
   98: automatically on the current server whenever a change is made to a 
   99: block (including deletion), or when a new block is added. 
  100: 
  101: =head1 INTERNAL SUBROUTINES
  102: 
  103: =over
  104: 
  105: =item &get_timed_items()
  106: 
  107: Provides perl data structure with information about timed interval
  108: parameters set in a course.
  109: 
  110: Inputs: 2 (optional)
  111:        $cdom - course's domain
  112: 
  113:        $cnum - course's ID
  114: 
  115: Output: 1 Hash 
  116:        nested hashes containing information about timed interval
  117:        parameters in course). Top level keys are type: course,
  118:        map, resource. Next inner keys are map or symb. Next
  119:        inner keys are scope (all, section, group, users).
  120:        Values are interval (in seconds).
  121: 
  122: =item &blockstore()
  123: 
  124: Stores changes to exam blocks in comm_block.db file for course.
  125: Processes deletions, modifications and additions.
  126: 
  127: Inputs: 2
  128:       $crstype - Container type: Course or Community.
  129: 
  130:       $blockcount - Total number of blocking events in course.
  131: 
  132: Outputs: 2
  133:       $changestotal - Total number of changes made.
  134: 
  135:       $output - Information about changes made.
  136: 
  137: 
  138: =item &get_dates_from_form()
  139: 
  140: Extract start and end dates from web form input for blocks with
  141: defined start/end time.
  142: 
  143: Inputs: 1 - $item - numeric ID of current block.
  144: 
  145: Outputs: 2 - $startdate, $enddate (UNIX times for start and end times
  146:              for blocks with defined start/end   
  147: 
  148: 
  149: =item &get_blockdates()
  150: 
  151: Retrieves contents of comm_block.db file for a course.
  152: 
  153: Inputs: 1 - $records - reference to hash to contain blocks 
  154: 
  155: Outputs: 1 - $blockcount - number of blocks
  156: 
  157: Side Effects: populates records hashref.
  158: 
  159: 
  160: =item &get_block_choices()
  161: 
  162: Extract information from web form about which communication/
  163: collaboration features are to be blocked, for a partilcuar event,
  164: and also which content areas will have access blocked for the
  165: duration of the block.
  166: 
  167: Inputs: 3 
  168:     - $item - numeric ID of current block 
  169: 
  170:     - $map_ref - reference to hash mapping numeric IDs to map urls 
  171: 
  172:     - $symb_ref - reference to hash mapping numeric IDs to symbs
  173: 
  174: Outputs: 2
  175:     - $blocktypes - reference to hash of features to be blocked
  176: 
  177:     - $blockdocs - boolean - 0 if no blocking of content, 1 if blocking 
  178:                              of content access 
  179: 
  180: 
  181: =item &check_release_required()
  182: 
  183: Update LON-CAPA version requirements for course if blocked items
  184: (content) or blocking type (triggered by student starting timer)
  185: require specific LON-CAPA version (i.e., 2.11).
  186: 
  187: Inputs: 1 - type of constraint (currently: 'docs' or 'timer'). 
  188: 
  189: Outputs: None
  190: 
  191: Side Effects: &update_released_required() called in lonnet, if
  192:               needed to update version requirements for course.   
  193: 
  194: 
  195: =item &display_blocker_status()
  196: 
  197: Generates web form elements used to display, cancel, or modify 
  198: existing blocking events. 
  199: 
  200: Inputs: 7 
  201:       - $r - Apache request object
  202: 
  203:       - $records - Reference to hash of current blocks
  204: 
  205:       - $ltext - Reference to hash of phrases (localized)
  206: 
  207:       - $intervals - Reference to hash of parameters for timed intervals
  208: 
  209:       - $navmap - navmaps object.
  210: 
  211:       - $errormsg - error message for display, if navmaps object
  212:                     could not be instantiated
  213: 
  214:       - $blockcount - number of existing blocking events in course
  215: 
  216: Output: None
  217: 
  218: Side Effects: prints web form elements (in a table) for current blocks. 
  219: 
  220: =item &convlim()
  221: 
  222: Convert a time interval used for a timed quiz (in seconds) to
  223: days, hours. minutes and seconds.
  224: 
  225: Inputs: 1 - $timelimit  - time interval in seconds
  226: 
  227: Outputs: 1 - $output - time in format: DD days, HH hours, MM minutes, SS seconds  
  228: 
  229: 
  230: =item &display_addblocker_table()
  231: 
  232: Generate web form elements used to define a new blocking event. 
  233: 
  234: Inputs: 6
  235:     - $r - Apache resource object
  236: 
  237:     - $parmcount - current ID for block (same as number of current blocks,
  238:                    block IDs in web form have zero-based index)
  239: 
  240:     - $ltext - reference to hash of phrases (localized)
  241: 
  242:     - $intervals - Reference to hash of parameters for timed intervals
  243: 
  244:     - $navmap - navmaps object
  245: 
  246:     - $errormsg - error message for display, if navmaps object
  247:                   could not be instantiated
  248: 
  249: Outputs: None
  250:  
  251: Side Effects: prints web form elements (in a table) for adding a new block.
  252: 
  253: 
  254: =item &blocker_checkboxes()
  255: 
  256: Generates web form elements in a table for checkboxes used to indicate
  257: which types of communication/collaboration and/or content should be blocked.
  258: 
  259: Inputs: 4 
  260:     - $parmcount - numeric ID of current block
  261: 
  262:     - $blocks - reference to hash of functionalities to block 
  263: 
  264:     - $jschg - text of javascript call to execute when checkbox clicked  
  265:                use within a box via 'onclick="$jchg"'
  266:  
  267:     - $lookups - reference to hash to map urls or symbs to numeric IDs
  268:                  used to populate hodden form elements containing list
  269:                  of resources and folders with access blocking currently set.
  270: 
  271: Output: 1 - HTML for table of checkboxes for current block  
  272: 
  273: 
  274: =item &create_interval_form()
  275: 
  276: Creates web form elements used to select one of the defined timed interval 
  277: items in the course for use in an exam block of type: "Triggered by 
  278: Activating Timer".
  279: 
  280: Inputs: 7 (three required, last four optional)
  281:    - $intervals - Reference to hash of parameters for timed intervals
  282: 
  283:    - $parmcount - numeric ID of current block
  284: 
  285:    - $navmap - navmaps object
  286: 
  287:    - $currkey - current interval (where this is a block already using
  288:                 an interval-based trigger).  
  289: 
  290:    - $jschg - text of javascript call to execute when radiobutton clicked
  291:               use within a box via 'onclick="$jchg"'
  292: 
  293:    - $itemname - name/scope of current interval used for this block 
  294: 
  295:    - $iteminfo - Expandable/collapsible block showing which users are
  296:                  able to activate the timer using the current trigger item.
  297: 
  298: Outputs: 1 - $intervalform - web form elements used to select a time interval
  299: 
  300: 
  301: =item &trigger_details_toggle()
  302:  
  303: Creates link used to expand item showing information about timer for current
  304: trigger for exam block. 
  305: 
  306: Inputs: 1 - $parmcount - numericID of exam block in web form. 
  307: 
  308: Outputs: 1 - returns HTML for link to display contents of information item 
  309: 
  310: =item &show_timer_path()
  311: 
  312: Display hierarchy of names of folders/sub-folders containing the current
  313: item identified as an item with an interval timer set.
  314: 
  315: Inputs: 3
  316:     - $type - map or resource
  317: 
  318:     - $item - map URL or resource symb
  319: 
  320:     - $navmap - navmaps object
  321: 
  322: Outputs: 1 - HTML containing hierarchy of folders/subfolders (raquo entity separated).  
  323: 
  324: 
  325: =item &blocktype_text()
  326: 
  327: Inputs: None
  328: 
  329: Output: 2 
  330:      - $typeorder - reference to array of blockable communication/collaboration/content
  331: 
  332:      - $types -reference to hash of descriptions (localized) of blockable types.
  333:  
  334: 
  335: =item &blockingmenu_javascript()
  336: 
  337: Create Javascript used to launch pop-up used for content selection, and to
  338: toggle visibility of a number of expandable/collapsible divs.
  339: 
  340: Inputs: 1 - $blockcount - 
  341: 
  342: Output: 1 - Javascript (with <script></script> tags) for functions used to:
  343:             (a) launch pop-up window for selection of course content to which
  344:             access could be blocked. 
  345:             (b) toggle visibility of a number of divs:
  346: 
  347: =over 
  348: 
  349: =item *  for block type - defined dates or timer activated
  350: 
  351: =item *  for action to take -- add or modify block
  352: 
  353: =item *  for display of detailed information about intervals 
  354: 
  355: =back
  356: 
  357: 
  358: =back  
  359: 
  360: =cut
  361: 
  362: package Apache::lonblockingmenu;
  363: 
  364: use strict;
  365: use Apache::lonnet;
  366: use Apache::Constants qw(:common :http);
  367: use Apache::loncommon();
  368: use Apache::lonhtmlcommon();
  369: use Apache::lonparmset();
  370: use Apache::loncourserespicker();
  371: use HTML::Entities();
  372: use Apache::lonlocal;
  373: use lib '/home/httpd/lib/perl/';
  374: use LONCAPA qw(:DEFAULT :match);
  375: 
  376: sub handler {
  377:     my $r=shift;
  378: 
  379: # ----------------------------------------------------------- Set document type
  380: 
  381:     &Apache::loncommon::content_type($r,'text/html');
  382:     $r->send_http_header;
  383: 
  384:     return OK if $r->header_only;
  385: 
  386:     #  Needs to be in a course
  387:     if (! ($env{'request.course.fn'})) {
  388:         # Not in a course
  389:         $env{'user.error.msg'}=
  390:      "/adm/setblock:dcm:0:0:Cannot set blocking of communications in a course";
  391:         return HTTP_NOT_ACCEPTABLE;
  392:     }
  393: 
  394: # ----------------------------------------------------------- Permissions check
  395: 
  396:     unless ((&Apache::lonnet::allowed('dcm',$env{'request.course.id'})) ||
  397:             (&Apache::lonnet::allowed('dcm',$env{'request.course.id'}.
  398:                                       '/'.$env{'request.course.sec'}))) {
  399:         $env{'user.error.msg'}=
  400:      "/adm/setblock:dcm:0:0:Cannot set blocking of communications in a course";
  401:         return HTTP_NOT_ACCEPTABLE;
  402:     }
  403: 
  404: # -----------------------------Get action and calling context from query string
  405: 
  406:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  407:                                             ['action','caller','block']);
  408: 
  409:     my $crstype = &Apache::loncommon::course_type();
  410:     my $action = $env{'form.action'};
  411:     my %records = ();
  412:     my $blockcount = 0;
  413: 
  414: # ------------------------------------------------------ Retrieve current blocks
  415:     $blockcount = &get_blockdates(\%records);
  416: 
  417: # -------------------- Generate display for pop-up of Maps and Resources blocked   
  418:     if ($action eq 'showdocs') {
  419:         my ($navmap,$errormsg) = 
  420:             &Apache::loncourserespicker::get_navmap_object($crstype,'examblock');
  421:         if (ref($navmap)) {
  422:             my (%blockedmaps,%blockedresources);
  423:             if ($env{'form.block'} =~ /^\d+$/) {
  424:                 my @currblocks = sort(keys(%records));
  425:                 my $block = $currblocks[$env{'form.block'}];
  426:                 if (($block ne '') && (ref($records{$block}) eq 'HASH')) {
  427:                     if (ref($records{$block}{'blocks'}) eq 'HASH') {
  428:                         if (ref($records{$block}{'blocks'}{'docs'}) eq 'HASH') {
  429:                             if (ref($records{$block}{'blocks'}{'docs'}{'maps'}) eq 'HASH') {
  430:                                 %blockedmaps = %{$records{$block}{'blocks'}{'docs'}{'maps'}};
  431:                             }
  432:                             if (ref($records{$block}{'blocks'}{'docs'}{'resources'}) eq 'HASH') {
  433:                                 %blockedresources = %{$records{$block}{'blocks'}{'docs'}{'resources'}};
  434:                             }
  435:                         }
  436:                     }
  437:                 }
  438:             }
  439:             $r->print(&Apache::loncourserespicker::create_picker($navmap,
  440:                                      'examblock','resourceblocks',$crstype,
  441:                                      \%blockedmaps,\%blockedresources,
  442:                                      $env{'form.block'}));
  443:         } else {
  444:             $r->print($errormsg);
  445:         }
  446:         return OK;
  447:     }
  448: 
  449: # -------------------------- Store changes and retrieve latest block information
  450:     my $storeresult;
  451:     if ($env{'form.action'} eq 'store') {
  452:         (my $numchanges,$storeresult) = &blockstore($crstype,$blockcount);
  453:         if ($numchanges > 0) {
  454:             $blockcount = &get_blockdates(\%records);
  455:         }
  456:     }
  457: 
  458: # ------------------------------------------------------------------ Breadcrumbs
  459:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  460:     if ($env{'form.caller'} eq 'email') {  
  461:         &Apache::lonhtmlcommon::add_breadcrumb
  462:             ({href=>'/adm/communicate',
  463:               text=>'Communication/Messages',
  464:               faq=>12,bug=>'Communication Tools',});
  465:     } else {
  466:         &Apache::lonhtmlcommon::add_breadcrumb
  467:             ({href=>'/adm/parmset',
  468:               text=>'Content and Problem Settings'});
  469:     }
  470:     &Apache::lonhtmlcommon::add_breadcrumb
  471:         ({href=>'/adm/setblock',
  472:           text=>'Blocking communication/content access'});
  473: 
  474:     my $js = &blockingmenu_javascript($blockcount);
  475: 
  476:     $r->print(
  477:         &Apache::loncommon::start_page('Blocking communication/content access',$js).
  478:         &Apache::lonhtmlcommon::breadcrumbs('Blocking communication/content access'));
  479: 
  480:     my $usertype;
  481:     if ($crstype eq 'Community') {
  482:         $usertype = 'members';
  483:     } else {
  484:         $usertype = 'students';
  485:     }
  486:     my $lctype = lc($crstype);
  487:     my %lt=&Apache::lonlocal::texthash (
  488:             'cbds' => 'Blocking communication and/or content access during exams',
  489:             'prev' => "For the duration of an exam, or a timed quiz, students in this course can be prevented from:",
  490:             'blca' => "Blocks can potentially interrupt legitimate communication between $usertype who are also both enrolled in a different LON-CAPA $lctype.",
  491:             'pobl' => "Portfolio blocking can impact a student's ability to complete assignments in courses besides your own. Please use this feature wisely.",
  492:             'actt' => "Action to take:",
  493:             'addn' => 'Add new blocking event',
  494:             'mexb' => 'Modify existing blocking event(s)', 
  495:             'ncbc' => 'There are no blocking events currently saved.',
  496:             'stor' => 'Save',
  497:     );
  498: 
  499:     my %ltext = &Apache::lonlocal::texthash(
  500:             'type' => 'Type',
  501:             'defs' => 'Defined Start/End',
  502:             'trig' => 'Triggered by Activating Timer', 
  503:             'setb' => 'Set by',
  504:             'even' => 'Event',
  505:             'blck' => 'Blocked?',
  506:             'star' => 'Start',
  507:             'endd' => 'End',
  508:             'chda' => 'Choose dates',
  509:             'chtr' => 'Choose trigger',
  510:             'when' => 'When using defined start/end times for an event, please set dates carefully.',
  511:             'yes'  => 'Yes',
  512:             'no'   => 'No',
  513:     );
  514: 
  515:     $r->print('<h3>'.$lt{'cbds'}.'</h3>');
  516: 
  517: # ---------------------------------------------------- Get Time Limit parameters
  518:     my %intervals = &get_timed_items();
  519: 
  520: # -------------------------------------------- Display information about changes 
  521:     if ($env{'form.action'} eq 'store') {
  522:         $r->print($storeresult);
  523:     } else {
  524:         $r->print(
  525:             $lt{'prev'}.
  526:             '<ul>'."\n".
  527:             '<li>'.&mt("displaying LON-CAPA messages sent by other $usertype in the $lctype").'</li>'."\n".
  528:             '<li>'.&mt("displaying or posting to LON-CAPA discussion boards or live chat in the $lctype").'</li>'."\n".
  529:             '<li>'.&mt('accessing content in LON-CAPA portfolios or blogs').'</li>'."\n".
  530:             '<li>'.&mt("generating printouts of $lctype content").'</li>'.
  531:             '<li>'.&mt("accessing $lctype content in specified folders or resources").'</li>'.
  532:             '</ul>'.
  533:             '<p class="LC_warning">'.$lt{'blca'}.'<br />'.$lt{'pobl'}.'</p>'
  534:         );
  535:     }
  536: 
  537: # ------------------------ Choose between modifying existing block or adding new
  538:     $r->print('<form name="blockform" method="post" action="/adm/setblock?action=store">');
  539:     if ($blockcount > 0) {
  540:          $r->print(<<"END");
  541: <div class="LC_left_float">
  542: <fieldset><legend>$lt{'actt'}</legend>
  543: <span class="LC_nobreak">
  544: <label><input type="radio" name="blockaction" value="modify" id="modifyaction" 
  545: onclick="toggleAddModify();" checked="checked" />$lt{'mexb'}</label>
  546: </span>
  547: <br />
  548: <span class="LC_nobreak">
  549: <label><input type="radio" name="blockaction" value="add" id="addaction" 
  550: onclick="toggleAddModify();" />$lt{'addn'}</label>
  551: </span>
  552: </fieldset>
  553: </div>
  554: <br clear="all" />
  555: <div id="showadd" style="display:none">
  556: END
  557:     } else {
  558:         $r->print($lt{'ncbc'}.'<br /><br />'.
  559:                   '<h4>'.$lt{'addn'}.'</h4>'.
  560:                   '<input type="hidden" name="blockaction" value="add" />');
  561:     }
  562:     my ($navmap,$errormsg) =
  563:         &Apache::loncourserespicker::get_navmap_object($crstype,'examblock');
  564: 
  565: # --------------------------------------------- Interface for adding a new block
  566:     &display_addblocker_table($r,$blockcount,\%ltext,\%intervals,
  567:                               $navmap,$errormsg);
  568: 
  569: # ------------------------------------------------- Interface for existig blocks
  570:     if ($blockcount > 0) {
  571:         $r->print('</div>');
  572:         &display_blocker_status($r,\%records,\%ltext,\%intervals,
  573:                                 $navmap,$errormsg,$blockcount);
  574:     }
  575:     $r->print(<<"END");
  576: <br />
  577: <input type ="submit" value="$lt{'stor'}" />
  578: </form>
  579: END
  580:     $r->print(&Apache::loncommon::end_page());
  581:     return OK;
  582: }
  583: 
  584: sub get_timed_items {
  585:     my ($cdom,$cnum) = @_;
  586:     my ($cid,%intervals);
  587:     if ($cdom eq '' || $cnum eq '') {
  588:         $cid = $env{'request.course.id'};
  589:         $cdom = $env{'course.'.$cid.'.domain'};
  590:         $cnum = $env{'course.'.$cid.'.num'};
  591:     } else {
  592:         $cid = $cdom.'_'.$cnum;
  593:     }
  594:     if ($cid eq '') {
  595:         return %intervals;
  596:     }
  597:     my $resourcedata=&Apache::lonparmset::readdata($cnum,$cdom);
  598:     if (ref($resourcedata) eq 'HASH') {
  599:         foreach my $key (keys(%{$resourcedata})) {
  600:             if ($key =~ /^\Q$cid\E(.+)\.0\.interval$/) {
  601:                 my $middle = $1;
  602:                 if ($middle eq '') {
  603:                     $intervals{'course'}{'all'} = $resourcedata->{$key};
  604:                 } elsif ($middle =~ /^\.\[(\w+)\]$/) {
  605:                     $intervals{'course'}{'secgrp'}{$1} = $resourcedata->{$key};
  606:                 } elsif ($middle =~ /^\.\[useropt\:($match_username\:$match_domain)\]$/) {
  607:                     $intervals{'course'}{'users'}{$1} = $resourcedata->{$key};
  608:                 } elsif ($middle =~ /^\.(.+)\Q___(all)\E$/) {
  609:                     my $inner = $1;
  610:                     if ($inner =~ /^\[(\w+)\]\.([^\]]+)$/) {
  611:                         $intervals{'map'}{$2}{'secgrp'}{$1} = $resourcedata->{$key};
  612:                     } elsif ($inner =~ /^\[useropt\:($match_username\:$match_domain)\]\.([^\]]+)$/) {
  613:                         $intervals{'map'}{$2}{'users'}{$1} = $resourcedata->{$key};
  614:                     } else {
  615:                         $intervals{'map'}{$inner}{'all'} = $resourcedata->{$key};
  616:                     }
  617:                 } elsif ($middle =~ /^\.\[(\w+)\]\.([^\]]+)$/) {
  618:                     $intervals{'resource'}{$2}{'secgrp'}{$1} = $resourcedata->{$key}; 
  619:                 } elsif ($middle =~ /^\.\[useropt\:($match_username\:$match_domain)\]\.([^\]]+)$/) {
  620:                     $intervals{'resource'}{$2}{'users'}{$1} = $resourcedata->{$key};
  621:                 } else {
  622:                     my ($symb) = ($middle =~ /^\.(.+)$/);
  623:                     $intervals{'resource'}{$symb}{'all'} = $resourcedata->{$key};
  624:                 }
  625:             }
  626:         }
  627:     }
  628:     return %intervals;
  629: }
  630: 
  631: sub blockstore {
  632:     my ($crstype,$blockcount) = @_;
  633:     my %lt=&Apache::lonlocal::texthash(
  634:             'tfcm' => 'The following changes were made',
  635:             'ncwm' => 'No changes were made.',
  636:             'unna' => 'Unable to retrieve contents of course.', 
  637:     );
  638:     my %adds = ();
  639:     my %removals = ();
  640:     my %cancels = ();
  641:     my $modtotal = 0;
  642:     my $canceltotal = 0;
  643:     my $addtotal = 0;
  644:     my $changestotal = 0;
  645:     my $addtimer = 0;
  646:     my %blocking = ();
  647:     my (%map_url,%resource_symb,%titles,$output);
  648:     $output = '<h3>'.$lt{'head'}.'</h3>';
  649:     if ($env{'form.blockaction'} eq 'modify') {
  650:         foreach my $envkey (keys(%env)) {
  651:             if ($envkey =~ m/^form\.action_(\d+)$/) {
  652:                 if ($env{$envkey} eq 'modify') {
  653:                     $adds{$1} = 1;
  654:                     $removals{$1} = 1;
  655:                 } elsif ($env{$envkey} eq 'cancel') {
  656:                     $cancels{$1} = $1;
  657:                     unless ( defined($removals{$1}) ) {
  658:                         $removals{$1} = 1;
  659:                         $canceltotal ++;
  660:                     }
  661:                 }
  662:             }
  663:         }
  664:     } elsif ($env{'form.blockaction'} eq 'add') {
  665:         $adds{$blockcount} = 1;
  666:     }
  667:     my ($navmap,$errormsg) =
  668:         &Apache::loncourserespicker::get_navmap_object($crstype,'examblock');
  669:     unless (ref($navmap)) {
  670:         $output = $lt{'unna'}.' '.$lt{'ncwm'}.'</br>';
  671:         return ($changestotal,$output);
  672:     }
  673:     &Apache::loncourserespicker::enumerate_course_contents($navmap,\%map_url,\%resource_symb,\%titles,'examblock');
  674:     foreach my $key (keys(%removals)) {
  675:         my $hashkey = $env{'form.key_'.$key};
  676:         &Apache::lonnet::del('comm_block',["$hashkey"],
  677:                          $env{'course.'.$env{'request.course.id'}.'.domain'},
  678:                          $env{'course.'.$env{'request.course.id'}.'.num'}
  679:                          );
  680:     }
  681:     foreach my $key (keys(%adds)) {
  682:         unless ( defined($cancels{$key}) ) {
  683:             my $newkey;
  684:             if ($env{'form.firstaccess_'.$key}) {
  685:                 my $interval = 
  686:                     &HTML::Entities::decode($env{'form.firstaccess_'.$key});
  687:                 if ($interval ne '') {
  688:                     if ($interval eq 'course') {
  689:                         $newkey = 'firstaccess____'.$interval;
  690:                     } elsif ($interval =~ /___\d+___/) {
  691:                         my ($map,$resid,$url) = 
  692:                             &Apache::lonnet::decode_symb($interval);
  693:                         if (&Apache::lonnet::is_on_map($url)) {
  694:                             $newkey = 'firstaccess____'.$interval;
  695:                         }
  696:                     } elsif (&Apache::lonnet::is_on_map($interval)) {
  697:                         $newkey = 'firstaccess____'.$interval;
  698:                     }
  699:                     if ($newkey ne '') {
  700:                         unless (defined($removals{$key})) {
  701:                             $addtimer ++;
  702:                         }
  703:                     }
  704:                 }
  705:             } else {
  706:                 my ($newstart,$newend) = &get_dates_from_form($key);
  707:                 $newkey = $newstart.'____'.$newend;
  708:             }
  709:             if ($newkey ne '') {
  710:                 my ($blocktypes,$blockdocs) = 
  711:                     &get_block_choices($key,\%map_url,\%resource_symb);
  712:                 $blocking{$newkey} = {
  713:                           setter => $env{'user.name'}.':'.$env{'user.domain'},
  714:                           event  => &escape($env{'form.title_'.$key}),
  715:                           blocks => $blocktypes,
  716:                         };
  717:                 if ($blockdocs) {
  718:                     &check_release_required('docs');
  719:                 }
  720:                 if (ref($blocktypes) eq 'HASH') {
  721:                     if ($blocktypes->{'printout'} eq 'on') {
  722:                         &check_release_required('printout');
  723:                     }
  724:                 }
  725:                 if (exists($removals{$key})) {
  726:                     $modtotal ++;
  727:                 } else {
  728:                     $addtotal ++;
  729:                 }
  730:             } else {
  731:                 if ($env{'form.toggle_'.$key} eq 'timer') {
  732:                     $output .= '<p class="LC_warning">'.
  733:                                &mt('Invalid trigger for new blocking event').
  734:                                '</p>';
  735:                 } else {
  736:                     $output .= '<p class="LC_warning">'.
  737:                                &mt('No date range found for new blocking event').
  738:                                '</p>';
  739:                 }
  740:             }
  741:         }
  742:     }
  743:     if ($addtotal + $modtotal > 0) {
  744:         &Apache::lonnet::put('comm_block',\%blocking,
  745:                      $env{'course.'.$env{'request.course.id'}.'.domain'},
  746:                      $env{'course.'.$env{'request.course.id'}.'.num'}
  747:                      );
  748:         if ($addtimer) {
  749:             &check_release_required('timer');
  750:         }
  751:     }
  752:     $changestotal = $canceltotal + $modtotal + $addtotal;
  753:     if ($changestotal > 0) {
  754:         &Apache::lonnet::devalidate_cache_new('comm_block',
  755:                                               $env{'request.course.id'});
  756:         $output .= $lt{'tfcm'}.'<ul>';
  757:         if ($canceltotal > 0) {
  758:             $output .= '<li>'.
  759:                        &mt('[quant,_1,blocking event was,blocking events were] removed.',
  760:                            $canceltotal).
  761:                        '</li>';
  762:         }
  763:         if ($modtotal > 0) {
  764:             $output .= '<li>'.
  765:                        &mt('[quant,_1,blocking event was,blocking events were] modified.',
  766:                            $modtotal).
  767:                        '</li>';
  768:         }
  769:         if ($addtotal > 0) {
  770:             $output .= '<li>'.
  771:                        &mt('[quant,_1,blocking event was,blocking events were] added.',
  772:                            $addtotal).
  773:                        '</li>';
  774:         }
  775:         $output .= '</ul>';
  776:     } else {
  777:         $output .= $lt{'ncwm'};
  778:     }
  779:     $output .= '<br />';
  780:     return ($changestotal,$output);
  781: }
  782: 
  783: sub get_dates_from_form {
  784:     my $item = shift;
  785:     my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$item);
  786:     my $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$item);
  787:     return ($startdate,$enddate);
  788: }
  789: 
  790: sub get_blockdates {
  791:     my ($records) = @_;
  792:     my $blockcount = 0;
  793:     %{$records} = &Apache::lonnet::dump('comm_block',
  794:                          $env{'course.'.$env{'request.course.id'}.'.domain'},
  795:                          $env{'course.'.$env{'request.course.id'}.'.num'}
  796:                          );
  797:     $blockcount = keys(%{$records});
  798: 
  799:     if ((keys(%{$records}))[0] =~ /^error: 2 /) {
  800:         $blockcount = 0;
  801:     }
  802:     return $blockcount;
  803: }
  804: 
  805: sub get_block_choices {
  806:     my ($item,$map_ref,$symb_ref) = @_;
  807:     my $blocklist;
  808:     my $blockdocs;
  809:     my ($typeorder,$types) = &blocktype_text();
  810:     foreach my $type (@{$typeorder}) {
  811:         if ($type eq 'docs') {
  812:             if ($env{'form.'.$type.'_'.$item}) {
  813:                 $blocklist->{$type} = {};
  814:                 if ($env{'form.docs_resources_'.$item}) {
  815:                     $env{'form.docs_resources_'.$item} =~ s/,$//;
  816:                     if (ref($symb_ref) eq 'HASH') {
  817:                         my %resources = map { $symb_ref->{$_} => 1; } 
  818:                                             (split(/,/,$env{'form.docs_resources_'.$item}));
  819:                         $blocklist->{$type}->{resources} = \%resources;
  820:                         if (keys(%resources) > 0) {
  821:                             $blockdocs = 1;
  822:                         }
  823:                     }
  824:                 }
  825:                 if ($env{'form.docs_maps_'.$item}) {
  826:                     $env{'form.docs_maps_'.$item} =~ s/,$//;
  827:                     if (ref($map_ref) eq 'HASH') {
  828:                         my %maps = map { $map_ref->{$_} => 1; }                             
  829:                                        (split(/,/,$env{'form.docs_maps_'.$item}));
  830:                         $blocklist->{$type}->{maps} = \%maps;
  831:                         if (keys(%maps) > 0) {
  832:                             $blockdocs = 1;
  833:                         }
  834:                     }
  835:                 }
  836:             }
  837:         } else {
  838:             if ($env{'form.'.$type.'_'.$item}) {
  839:                 $blocklist->{$type} = 'on';
  840:             } else {
  841:                 $blocklist->{$type} = 'off';
  842:             }
  843:         }
  844:     }
  845:     return ($blocklist,$blockdocs);
  846: }
  847: 
  848: sub check_release_required {
  849:     my ($value) = @_; 
  850:     my $needsrelease = $Apache::lonnet::needsrelease{'course:commblock:'.$value};
  851:     if ($needsrelease) {
  852:         my $curr_required = 
  853:             $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};
  854:         if ($curr_required eq '') {
  855:             &Apache::lonnet::update_released_required($needsrelease);
  856:         } else {
  857:             my ($currmajor,$currminor) = split(/\./,$curr_required);
  858:             my ($needsmajor,$needsminor) = split(/\./,$needsrelease);
  859:             if (($currmajor < $needsmajor) || 
  860:                 ($currmajor == $needsmajor && $currminor < $needsminor)) {
  861:                 &Apache::lonnet::update_released_required($needsrelease);
  862:             }
  863:         }
  864:     }
  865:     return;
  866: }
  867: 
  868: sub display_blocker_status {
  869:     my ($r,$records,$ltext,$intervals,$navmap,$errormsg,$blockcount) = @_;
  870:     my $parmcount = 0;
  871:     my (%map_url,%resource_symb,%titles,%lookups);
  872:     &Apache::loncourserespicker::enumerate_course_contents($navmap,\%map_url,\%resource_symb,\%titles,'examblock');
  873:     %{$lookups{'maps'}} = reverse(%map_url);
  874:     %{$lookups{'resources'}} = reverse(%resource_symb);
  875:     my %lt = &Apache::lonlocal::texthash(
  876:         'modi' => 'Modify',
  877:         'dele' => 'Delete',
  878:         'noch' => 'No change',
  879:     );
  880:     $r->print('<div id="showmodify" style="display:block">'.
  881:               &Apache::loncommon::start_data_table());
  882:     $r->print(<<"END");
  883:   <tr>
  884:     <th></th>
  885:     <th>$ltext->{'type'}</th>
  886:     <th>$ltext->{'even'}</th>
  887:     <th>$ltext->{'blck'}</th>
  888:   </tr>
  889: END
  890:     foreach my $record (sort(keys(%{$records}))) {
  891:         my $jschg = 
  892:             'javascript:window.document.forms['. "'blockform'".']'.
  893:             '.elements['."'action_$parmcount'".'][0].checked=true;';
  894:         my $onchange = 'onfocus="'.$jschg.'"';
  895:         my ($setuname,$setudom,$title,$blocks) =
  896:             &Apache::loncommon::parse_block_record($$records{$record});
  897:         $title = &HTML::Entities::encode($title,'"<>&');
  898:         my $blockid = &HTML::Entities::encode($record,'"<>&');
  899:         my $settername =
  900:            &Apache::loncommon::aboutmewrapper(
  901:                            &Apache::loncommon::plainname($setuname,$setudom),
  902:                            $setuname,$setudom);
  903:         $r->print(&Apache::loncommon::start_data_table_row());
  904:         $r->print(<<"ACT");
  905: 
  906:         <td valign="middle"><span class="LC_nobreak"><label>
  907:         <input type="radio" name="action_$parmcount" value="modify" />$lt{'modi'}
  908:         </label></span><br />
  909:         <span class="LC_nobreak"><label>
  910:         <input type="radio" name="action_$parmcount" value="cancel" />$lt{'dele'}
  911:         </label></span><br />
  912:         <span class="LC_nobreak"><label>
  913:         <input type="radio" name="action_$parmcount" id="nochange_$parmcount" 
  914:          value="nochange" checked="checked" />$lt{'noch'}
  915:         </label></span>
  916:         </td>
  917: ACT
  918:         my ($start,$end,$startform,$endform); 
  919:         if ($record =~ /^(\d+)____(\d+)$/) {
  920:             ($start,$end) = split(/____/,$record);
  921:             $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.
  922:                                                              $parmcount,$start,$onchange);
  923:             $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.
  924:                                                            $parmcount,$end,$onchange);
  925:             $r->print('<td><fieldset><legend>'.$ltext->{'defs'}.'</legend>'.
  926:                       $ltext->{'star'}.':&nbsp;'.$startform.'<br />'.
  927:                       $ltext->{'endd'}.':&nbsp;&nbsp;'.$endform.'</fieldset></td>');
  928:         } elsif ($record =~ /^firstaccess____(.+)$/) {
  929:             my $item = $1;
  930:             my ($itemname,$iteminfo,$skipdetails);
  931:             my $type = 'map';
  932:             my $url;
  933:             if ($item eq 'course') {
  934:                 $type = 'course';
  935:             } elsif ($item =~ /___\d+___/) {
  936:                 $type = 'resource';
  937:                 (my $map, my $resid, $url) = &Apache::lonnet::decode_symb($item);  
  938:             } else {
  939:                 $url = $item;
  940:             }
  941:             $r->print('<td><fieldset><legend>'.$ltext->{'trig'}.'</legend>');
  942:             if ($type eq 'course') {
  943:                 $itemname = &mt('Timer for all items in course.');
  944:             } else {
  945:                 if (&Apache::lonnet::is_on_map($url)) { 
  946:                     if ($type eq 'map') {
  947:                         if (ref($navmap)) {
  948:                             my $res = $navmap->getResourceByUrl($item);
  949:                             my $title = $res->compTitle();
  950:                             $itemname = &mt('Timer for all items in folder: [_1]',
  951:                                             '<span style="font-style:italic">'.
  952:                                             $title.'</span>');
  953:                         }
  954:                     } else {
  955:                         if (ref($navmap)) {
  956:                             my $res = $navmap->getBySymb($item);
  957:                             my $title = $res->compTitle();
  958:                             $itemname = &mt('Timer for resource: [_1]',
  959:                                              '<span style="font-style:italic">'.
  960:                                              $title.'</span>');
  961:                         }
  962:                     }
  963:                     if (ref($navmap)) {
  964:                         my $path = &show_timer_path($type,$item);
  965:                         if ($path) {
  966:                             $iteminfo  = ' <span style="font-size:90%;">'.
  967:                                          &mt('(in: [_1])',$path).
  968:                                          '</span>';
  969:                         }
  970:                     }
  971:                 } else {
  972:                     $skipdetails = 1;
  973:                     $itemname = '<span style="LC_warning">'.
  974:                                 &mt('Timer folder/resource not in course').
  975:                                 '</span>';  
  976:                 }
  977:             }
  978:             if ((!$skipdetails) && (ref($intervals) eq 'HASH')) {
  979:                 if (ref($intervals->{$type}) eq 'HASH') {
  980:                     $iteminfo .= &trigger_details_toggle($parmcount).
  981:                                 '<ul id="trigdetails_'.$parmcount.'" style="display:none">';
  982:                     if ($type eq 'course') {
  983:                         foreach my $scope (keys(%{$intervals->{$type}})) {
  984:                             if ($scope eq 'all') {
  985:                                 $iteminfo .= '<li>'.&mt('All users -- time limit: [_1]',
  986:                                          &convlim($intervals->{$type}->{$scope})).'</li>';
  987:                             } elsif ($scope eq 'secgrp') {
  988:                                 if (ref($intervals->{$type}->{$scope}) eq 'HASH') {
  989:                                     $iteminfo .= '<li>'.&mt('Sections/groups').'<ul>';
  990:                                     foreach my $item (sort(keys(%{$intervals->{$type}->{$scope}}))) {
  991:                                         $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',$item,
  992:                                                      &convlim($intervals->{$type}->{$scope}->{$item})).
  993:                                                      '</li>';
  994:                                     }
  995:                                     $iteminfo .= '</ul></li>';
  996:                                 }
  997:                             } elsif ($scope eq 'users') {
  998:                                 if (ref($intervals->{$type}->{$scope}) eq 'HASH') {
  999:                                     $iteminfo .= '<li>'.&mt('Users').'<ul>'; 
 1000:                                     foreach my $item (sort(keys(%{$intervals->{$type}->{$scope}}))) {
 1001:                                         $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',
 1002:                                                      &convlim($item,$intervals->{$type}->{$scope}->{$item})).
 1003:                                                      '</li>';
 1004:                                     }
 1005:                                     $iteminfo .= '</ul></li>';
 1006:                                 }
 1007:                             }
 1008:                         }
 1009:                     } elsif (($type eq 'map') || ($type eq 'resource')) {
 1010:                         if (ref($intervals->{$type}->{$item}) eq 'HASH') { 
 1011:                             foreach my $scope (keys(%{$intervals->{$type}->{$item}})) {
 1012:                                 if ($scope eq 'all') {
 1013:                                     $iteminfo .= '<li>'.&mt('All users -- time limit: [_1]',
 1014:                                                   &convlim($intervals->{$type}->{$item}->{$scope})).
 1015:                                                   '</li>';
 1016:                                 } elsif ($scope eq 'secgrp') {
 1017:                                     if (ref($intervals->{$type}->{$item}->{$scope}) eq 'HASH') {
 1018:                                         $iteminfo .= '<li>'.&mt('Sections/groups').'<ul>';
 1019:                                         foreach my $sec (sort(keys(%{$intervals->{$type}->{$item}->{$scope}}))) {
 1020:                                             $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',$sec,
 1021:                                                          &convlim($intervals->{$type}->{$item}->{$scope}->{$sec})).
 1022:                                                          '</li>';
 1023:                                         }
 1024:                                         $iteminfo .= '</ul></li>'; 
 1025:                                     }
 1026:                                 } elsif ($scope eq 'users') {
 1027:                                     if (ref($intervals->{$type}->{$item}->{$scope}) eq 'HASH') {
 1028:                                         $iteminfo .= '<li>'.&mt('Users').'<ul>';
 1029:                                         foreach my $user (sort(keys(%{$intervals->{$type}->{$item}->{$scope}}))) {
 1030:                                             $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',$user,
 1031:                                                          &convlim($intervals->{$type}->{$item}->{$scope}->{$user})).
 1032:                                                          '</li>';
 1033:                                         }
 1034:                                         $iteminfo .= '</ul></li>';
 1035:                                     }
 1036:                                 }
 1037:                             }
 1038:                         }
 1039:                     }
 1040:                     $iteminfo .= '</ul>';
 1041:                 }
 1042:             }
 1043:             $r->print(&create_interval_form($intervals,$parmcount,$navmap,$item,$jschg,
 1044:                                             $itemname,$iteminfo).'</fieldset></td>');
 1045:         }
 1046:         $r->print(<<"END");
 1047:         <td>
 1048:          <input type="text" name="title_$parmcount" size="15" value="$title" onfocus="$jschg" />
 1049:          <input type="hidden" name="key_$parmcount" value="$blockid" />
 1050:          <br />
 1051:          <br />
 1052:          $ltext->{'setb'}: $settername
 1053:         </td>
 1054: END
 1055:         $r->print('<td>'.&blocker_checkboxes($parmcount,$blocks,$jschg,\%lookups).'</td>'.
 1056:                   &Apache::loncommon::end_data_table_row());
 1057:         $parmcount++;
 1058:     }
 1059:     $r->print(<<"END");
 1060: </table>
 1061: </div>
 1062: END
 1063:     return;
 1064: }
 1065: 
 1066: sub convlim {
 1067:     my ($timelimit) = @_;
 1068:     my @order = ('days','hours','minutes','seconds');
 1069:     my %catlimits = ( 
 1070:                       days    => 86400,
 1071:                       hours   => 3600,
 1072:                       minutes => 60,
 1073:                     );
 1074:     my @toshow;
 1075:     foreach my $cat (@order) {
 1076:         if ($cat eq 'seconds') {
 1077:             if ($timelimit > 0) {
 1078:                 push(@toshow,&mt("[_1] $cat",$timelimit));
 1079:             }
 1080:         } elsif ($timelimit >= $catlimits{$cat}) {
 1081:             my $val = int($timelimit/$catlimits{$cat});
 1082:             if ($val > 0) {
 1083:                 push(@toshow,&mt("[_1] $cat",$val));
 1084:             }
 1085:             $timelimit -= $val*$catlimits{$cat};
 1086:         }
 1087:     }
 1088:     my $output = join(', ',@toshow);
 1089:     return $output;
 1090: }
 1091: 
 1092: sub display_addblocker_table {
 1093:     my ($r,$parmcount,$ltext,$intervals,$navmap,$errormsg) = @_;
 1094:     return unless ((ref($ltext) eq 'HASH') && (ref($intervals) eq 'HASH'));
 1095:     my $start = time;
 1096:     my $end = $start + (60 * 60 * 2); #Default is an exam of 2 hours duration.
 1097:     my $onchange = 'onfocus="javascript:window.document.forms['.
 1098:                    "'blockform'].elements['addaction'].".
 1099:                    'checked=true;"';
 1100:     my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.
 1101:                                                         $parmcount,$start,$onchange);
 1102:     my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.
 1103:                                                       $parmcount,$end,$onchange);
 1104:     my %lt = &Apache::lonlocal::texthash(
 1105:         'exam' => 'e.g., Exam 1',
 1106:     );
 1107:     my $intervalform = &create_interval_form($intervals,$parmcount,$navmap);
 1108:     if ($intervalform ne '') {
 1109:         $intervalform = '<fieldset>'.
 1110:                         '<legend>'.$ltext->{'chtr'}.'</legend>'.
 1111:                         $intervalform.
 1112:                         '</fieldset>';
 1113:     }
 1114:     $r->print(&Apache::loncommon::start_data_table());
 1115:     $r->print(<<"END");
 1116:    <tr>
 1117:      <th>$ltext->{'type'}</th>
 1118:      <th>$ltext->{'even'} $lt{'exam'}</th>
 1119:      <th>$ltext->{'blck'}</th>
 1120:    </tr>
 1121: END
 1122:     $r->print(&Apache::loncommon::start_data_table_row().'<td>');
 1123:     $r->print(<<"END");
 1124:      <span class="LC_nobreak"><label><input type="radio" id="toggle_startstop" 
 1125:      name="toggle_$parmcount" value="startstop" onclick="showBlockType();" checked="checked" />
 1126:      $ltext->{'defs'}</label></span>&nbsp;&nbsp; 
 1127:      <span class="LC_nobreak"><label><input type="radio" id="toggle_timer" name="toggle_$parmcount" 
 1128:      value="timer" onclick="showBlockType();" />$ltext->{'trig'}</label></span><br />
 1129:      <div id="show_startstop" style="display:block">
 1130:      <fieldset><legend>$ltext->{'chda'}</legend>
 1131:      $ltext->{'star'}:&nbsp;$startform<br />$ltext->{'endd'}:&nbsp;&nbsp;$endform</fieldset>
 1132:      <span class="LC_warning">$ltext->{'when'}</span></div>
 1133:      <div id="show_timer" style="display:none">$intervalform</div>
 1134:      </td>
 1135:      <td><input type="text" name="title_$parmcount" size="15" value="" /></td>
 1136: END
 1137:     $r->print('<td>'.&blocker_checkboxes($parmcount).'</td>'.
 1138:               &Apache::loncommon::end_data_table_row().
 1139:               &Apache::loncommon::end_data_table()."\n".
 1140:               '<br />');
 1141:     return;
 1142: }
 1143: 
 1144: sub blocker_checkboxes {
 1145:     my ($parmcount,$blocks,$jschg,$lookups) = @_;
 1146:     my ($typeorder,$types) = &blocktype_text();
 1147:     my $numinrow = 2;
 1148:     my %currdocs;
 1149:     my $output = '<table>';
 1150:     for (my $i=0; $i<@{$typeorder}; $i++) {
 1151:         my $block = $typeorder->[$i];
 1152:         my ($clickaction,$blockstatus);
 1153:         if ($jschg) {
 1154:             $clickaction = $jschg;
 1155:         } 
 1156:         if ($block eq 'docs') {
 1157:             if ((ref($blocks) eq 'HASH') && (ref($lookups) eq 'HASH')) {
 1158:                 if (ref($blocks->{$block}) eq 'HASH') {
 1159:                     if (keys(%{$blocks->{$block}}) > 0) {
 1160:                         $blockstatus = 'checked="checked"';
 1161:                         foreach my $key (sort(keys(%{$blocks->{$block}}))) {
 1162:                             if (ref($blocks->{$block}{$key}) eq 'HASH') {
 1163:                                 my @current = ();
 1164:                                 foreach my $item (keys(%{$blocks->{$block}{$key}})) {
 1165:                                     if ($lookups->{$key}{$item}) {
 1166:                                         push(@current,$lookups->{$key}{$item});
 1167:                                     }
 1168:                                 }
 1169:                                 if (@current > 0) {
 1170:                                     @current=sort { $a <=> $b } (@current);
 1171:                                     $currdocs{$key} = join(',',@current);
 1172:                                 }
 1173:                             }
 1174:                         }
 1175:                     }
 1176:                 }
 1177:             }
 1178:             $clickaction .= 'javascript:resblockinfo('."'$parmcount'".');';
 1179:         } else {
 1180:             if (ref($blocks) eq 'HASH') { 
 1181:                 if ($blocks->{$block} eq 'on') {
 1182:                     $blockstatus = 'checked="checked"';
 1183:                 }
 1184:             }
 1185:         }
 1186:         my $rem = $i%($numinrow);
 1187:         if ($rem == 0) {
 1188:             if ($i > 0) {
 1189:                 $output .= '</tr>';
 1190:             }
 1191:             $output .= '<tr>';
 1192:         }
 1193:         if ($i == scalar(@{$typeorder})-1) {
 1194:             my $colsleft = $numinrow-$rem;
 1195:             if ($colsleft > 1) {
 1196:                 $output .= '<td colspan="'.$colsleft.'">';
 1197:             } else {
 1198:                 $output .= '<td>';
 1199:             }
 1200:         } else {
 1201:             $output .= '<td>';
 1202:         }
 1203:         my $item = $block.'_'.$parmcount;
 1204:         if ($clickaction) {
 1205:             $clickaction = ' onclick="'.$clickaction.'"';
 1206:         }
 1207:         if ($blockstatus) {
 1208:             $blockstatus = ' '.$blockstatus;
 1209:         } 
 1210:         $output .= '<span class="LC_nobreak"><label>'."\n".
 1211:                    '<input type="checkbox" id="'.$item.'" name="'.$item.'"'.
 1212:                    $blockstatus.$clickaction.' value="1" />'.
 1213:                    $types->{$block}.'</label></span>'."\n";
 1214:         if ($block eq 'docs') {
 1215:             if ($blockstatus ne '') {
 1216:                 $output .= '&nbsp;<a href="javascript:resblockinfo('."'$parmcount'".')">'.
 1217:                             &mt('Details').'</a>';
 1218:             }
 1219:         }
 1220:         $output .= '<br /></td>';
 1221:     }
 1222:     $output .= '</tr></table>'.
 1223:                '<input type="hidden" name="docs_maps_'.$parmcount.'"'.
 1224:                ' id="docs_maps_'.$parmcount.'" value="'.$currdocs{'maps'}.'" />'.
 1225:                '<input type="hidden" name="docs_resources_'.$parmcount.'"'.
 1226:                ' id="docs_resources_'.$parmcount.'" value="'.$currdocs{'resources'}.'" />';
 1227:     return $output;
 1228: }
 1229: 
 1230: sub create_interval_form {
 1231:     my ($intervals,$parmcount,$navmap,$currkey,$jschg,$itemname,$iteminfo) = @_;
 1232:     return unless ((ref($intervals) eq 'HASH') && (ref($navmap)));
 1233:     my $intervalform;
 1234:     if (keys(%{$intervals}) > 0) {
 1235:         foreach my $type (sort(keys(%{$intervals}))) {
 1236:             if ($type eq 'course') {
 1237:                 my ($checked,$clickaction);
 1238:                 if ($currkey eq 'course') {
 1239:                     $checked = ' checked="checked"';
 1240:                 } elsif ($jschg) {
 1241:                     $clickaction = ' onclick="'.$jschg.'"';
 1242:                 }
 1243:                 $intervalform .= '<label><input type="radio" name="firstaccess_'.$parmcount.
 1244:                                  '" value="course"'.$checked.$clickaction.' />';
 1245:                 if ($currkey eq 'course') {
 1246:                     $intervalform .= $itemname;
 1247:                 } else {
 1248:                     $intervalform .= &mt('Timer for all items in course');
 1249:                 }
 1250:                 $intervalform .= '</label>';
 1251:                 if ($currkey eq 'course') {
 1252:                     $intervalform .= $iteminfo;
 1253:                 }
 1254:                 $intervalform .= '<br />';
 1255:             } elsif ($type eq 'map') {
 1256:                 if (ref($intervals->{$type}) eq 'HASH') {
 1257:                     if (ref($navmap)) {
 1258:                         foreach my $map (sort(keys(%{$intervals->{$type}}))) {
 1259:                             my ($checked,$clickaction);
 1260:                             if ($currkey eq $map) {
 1261:                                 $checked = ' checked="checked"';
 1262:                             } elsif ($jschg) {
 1263:                                 $clickaction = ' onclick="'.$jschg.'"';
 1264:                             }
 1265:                             $intervalform .= '<label><input type="radio" name="firstaccess_'.$parmcount.
 1266:                                              '" value="'.&HTML::Entities::encode($map,'"<>&').'"'.
 1267:                                              $checked.$clickaction.' />';
 1268:                             if ($currkey eq $map) {
 1269:                                 $intervalform .= $itemname.'</label>';
 1270:                             } else {
 1271:                                 my $res = $navmap->getResourceByUrl($map);
 1272:                                 my $title = $res->compTitle();
 1273:                                 my $path;
 1274:                                 my $hierarchy = &show_timer_path($type,$map,$navmap);
 1275:                                 if ($hierarchy) {
 1276:                                     $path = ' <span style="font-size:90%;">'.
 1277:                                             &mt('(in: [_1])',$hierarchy).
 1278:                                             '</span>';
 1279:                                 }
 1280:                                 $intervalform .= &mt('Timer for all items in folder: [_1]',
 1281:                                                      '<i>'.$title.'</i>').
 1282:                                                  '</label>'.$path;
 1283:                             }
 1284:                             if ($currkey eq $map) {
 1285:                                 $intervalform .= $iteminfo;
 1286:                             }
 1287:                             $intervalform .= '<br />';
 1288:                         }
 1289:                     }
 1290:                 }
 1291:             } elsif ($type eq 'resource') {
 1292:                 if (ref($intervals->{$type}) eq 'HASH') {
 1293:                     if (ref($navmap)) {
 1294:                         foreach my $resource (sort(keys(%{$intervals->{$type}}))) {
 1295:                             my ($checked,$clickaction);
 1296:                             if ($currkey eq $resource) {
 1297:                                 $checked = ' checked="checked"';
 1298:                             } elsif ($jschg) {
 1299:                                 $clickaction = ' onclick="'.$jschg.'"';
 1300:                             }
 1301:                             $intervalform .= '<label><input type="radio" name="firstaccess_'.$parmcount.
 1302:                                              '" value="'.&HTML::Entities::encode($resource,'"<>&').'"'.
 1303:                                              $checked.$clickaction.' />';
 1304:                             if ($currkey eq $resource) {
 1305:                                 $intervalform .= $itemname.'</label>';
 1306:                             } else {
 1307:                                 my $res = $navmap->getBySymb($resource);
 1308:                                 my $title = $res->compTitle();
 1309:                                 my $path;
 1310:                                 my $hierarchy = &show_timer_path($type,$resource,$navmap);
 1311:                                 if ($hierarchy) {
 1312:                                     $path = ' <span style="font-size:90%;">'.
 1313:                                             &mt('(in: [_1])',$hierarchy).
 1314:                                             '</span>';
 1315:                                 }
 1316:                                 $intervalform .= &mt('Timer for resource: [_1]','<i>'.$title.'</i>').
 1317:                                                  '</label>'.
 1318:                                                  $path;
 1319:                             }
 1320:                             if ($currkey eq $resource) {
 1321:                                 $intervalform .= $iteminfo;
 1322:                             }
 1323:                             $intervalform .= '<br />';
 1324:                         }
 1325:                     }
 1326:                 }
 1327:             }
 1328:         }
 1329:     } else {
 1330:         if ($currkey ne '') {
 1331:             $intervalform = '<input type="radio" name="firstaccess_'.$parmcount.
 1332:                             '" checked="checked" value="'.
 1333:                             &HTML::Entities::encode($currkey,'"<>&').' />'.
 1334:                             $itemname.'<br />';
 1335:         } else {
 1336:             $intervalform = &mt('No timed items defined.').' '.
 1337:                             &mt('Use [_1]Settings[_2] to assign a timer, then return here.',
 1338:                                 '<a href="/adm/parmset">','</a>');
 1339:         }
 1340:     }
 1341:     return $intervalform;
 1342: }
 1343: 
 1344: sub trigger_details_toggle {
 1345:     my ($parmcount) = @_;
 1346:     return ' <span id="toggletext_'.$parmcount.'" class="LC_cusr_subheading LC_nobreak">'.
 1347:            '<a href="javascript:showTriggerDetails('."'$parmcount'".');" '.
 1348:            'style="text-decoration: none;"><b>'.&mt('(More ...)').'</b></a></span>';
 1349: }
 1350: 
 1351: sub show_timer_path {
 1352:     my ($type,$item,$navmap) = @_;
 1353:     return unless(ref($navmap));
 1354:     my @pathitems;
 1355:     if ($type eq 'map') {
 1356:         @pathitems = 
 1357:             &Apache::loncommon::get_folder_hierarchy($navmap,$item);
 1358:     } elsif ($type eq 'resource') {
 1359:         my ($map,$id,$resource) = &Apache::lonnet::decode_symb($item);
 1360:         @pathitems = 
 1361:             &Apache::loncommon::get_folder_hierarchy($navmap,$map,1);
 1362:     }
 1363:     if (@pathitems) {
 1364:         return join(' &raquo; ',@pathitems);
 1365:     }
 1366:     return;
 1367: }
 1368: 
 1369: sub blocktype_text {
 1370:     my %types = &Apache::lonlocal::texthash(
 1371:         'com' => 'Messaging',
 1372:         'chat' => 'Chat Room',
 1373:         'boards' => 'Discussion',
 1374:         'port' => 'Portfolio',
 1375:         'groups' => 'Groups',
 1376:         'blogs' => 'Blogs',
 1377:         'docs' => 'Content',
 1378:         'printout' => 'Printouts',
 1379:     );
 1380:     my $typeorder = ['com','chat','boards','port','groups','blogs','printout','docs'];
 1381:     return ($typeorder,\%types);
 1382: }
 1383: 
 1384: sub blockingmenu_javascript {
 1385:     my ($blockcount) = @_;
 1386:     my %lt = &Apache::lonlocal::texthash (
 1387:                                            more => 'More ...',
 1388:                                            less => 'Less ...',
 1389:                                          );
 1390:     return <<ENDSCRIPT;
 1391: <script type="text/javascript">
 1392: // <![CDATA[
 1393: function resblockinfo(blockid) {
 1394:     if (document.getElementById('docs_'+blockid).checked) {
 1395:         var resblockwin = null;
 1396:         var url = '/adm/setblock?action=showdocs&block='+blockid;
 1397:         if (!resblockwin || resblockwin.closed) {
 1398:             resblockwin=window.open(url,'blockingwin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
 1399:         }
 1400:         resblockwin.focus();
 1401:     } else {
 1402:         document.getElementById('docs_resources_'+blockid).value = '';
 1403:         document.getElementById('docs_maps_'+blockid).value = '';
 1404:     }
 1405:     return;
 1406: }
 1407: 
 1408: function showBlockType() {
 1409:     if (document.getElementById('toggle_startstop').checked == true) {
 1410:         document.getElementById('show_startstop').style.display='block';
 1411:     } else {
 1412:         document.getElementById('show_startstop').style.display='none';
 1413:     }
 1414:     if (document.getElementById('toggle_timer').checked == true) {
 1415:         document.getElementById('show_timer').style.display='block';
 1416:     } else {
 1417:         document.getElementById('show_timer').style.display='none';
 1418:     }
 1419:     return;
 1420: }
 1421: 
 1422: function toggleAddModify() {
 1423:     for (var i=0; i<document.blockform.blockaction.length; i++) {
 1424:         if (document.blockform.blockaction[i].checked) {
 1425:             if (document.blockform.blockaction[i].value == 'add') {
 1426:                document.getElementById('showadd').style.display='block';
 1427:                document.getElementById('showmodify').style.display='none';
 1428:                var blocktotal = $blockcount;
 1429:                if (blocktotal > 0) {
 1430:                    for (var i=0; i<blocktotal; i++) {
 1431:                        document.getElementById('nochange_'+i).checked = true;
 1432:                    }
 1433:                }
 1434:                document.getElementById('showmodify').style.display='none';
 1435:                document.getElementById('showadd').style.display='block';
 1436:             } else {
 1437:                document.getElementById('showadd').style.display='none';
 1438:                document.getElementById('showmodify').style.display='block';
 1439:             }
 1440:         }
 1441:     }
 1442:     return;
 1443: }
 1444: 
 1445: function showTriggerDetails(item) {
 1446:     document.getElementById('trigdetails_'+item).style.display='block';
 1447:     document.getElementById('trigdetails_'+item).style.textAlign='left';
 1448:     document.getElementById('trigdetails_'+item).style.textFace='normal';
 1449:     document.getElementById('toggletext_'+item).innerHTML = '<a href="javascript:hideTriggerDetails('+item+');" style="text-decoration: none;"><b>($lt{'less'})</b></a>';
 1450:     return;
 1451: }
 1452: 
 1453: function hideTriggerDetails(item) {
 1454:     document.getElementById('trigdetails_'+item).style.display='none';
 1455:     document.getElementById('toggletext_'+item).innerHTML = '<a href="javascript:showTriggerDetails('+item+');" style="text-decoration: none;"><b>($lt{'more'})</b></a>';
 1456:     return;
 1457: }
 1458: 
 1459: // ]]>
 1460: </script>
 1461: ENDSCRIPT
 1462: 
 1463: }
 1464: 
 1465: 1;
 1466: 
 1467: __END__

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