File:  [LON-CAPA] / loncom / interface / lonblockingmenu.pm
Revision 1.14.2.3.2.1: download - view: text, annotated - select for diffs
Wed Feb 6 15:40:22 2019 UTC (5 years, 3 months ago) by raeburn
Branches: version_2_11_2_msu
Diff to branchpoint 1.14.2.3: preferred, unified
- For 2.11 (modified)
  Include changes in 1.26

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

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