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