File:  [LON-CAPA] / loncom / interface / lonblockingmenu.pm
Revision 1.21: download - view: text, annotated - select for diffs
Sat Oct 22 02:03:31 2016 UTC (7 years, 8 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Users with vgr priv can display first access times for students for
  course, map/folder, or resource with interval (timer) parameter set.

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

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