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