Annotation of loncom/interface/lonblockingmenu.pm, revision 1.14.2.1
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.14.2.1! raeburn 5: # $Id: lonblockingmenu.pm,v 1.14 2015/04/15 03:28:19 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.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>'.
1.14.2.1! raeburn 564: '<li>'.&mt("changing user's own password").'</li>'.
1.4 raeburn 565: '</ul>'.
566: '<p class="LC_warning">'.$lt{'blca'}.'<br />'.$lt{'pobl'}.'</p>'
567: );
1.1 raeburn 568: }
569:
1.4 raeburn 570: # ------------------------ Choose between modifying existing block or adding new
571: $r->print('<form name="blockform" method="post" action="/adm/setblock?action=store">');
572: if ($blockcount > 0) {
573: $r->print(<<"END");
574: <div class="LC_left_float">
575: <fieldset><legend>$lt{'actt'}</legend>
576: <span class="LC_nobreak">
577: <label><input type="radio" name="blockaction" value="modify" id="modifyaction"
578: onclick="toggleAddModify();" checked="checked" />$lt{'mexb'}</label>
579: </span>
580: <br />
581: <span class="LC_nobreak">
582: <label><input type="radio" name="blockaction" value="add" id="addaction"
583: onclick="toggleAddModify();" />$lt{'addn'}</label>
584: </span>
585: </fieldset>
586: </div>
587: <br clear="all" />
588: <div id="showadd" style="display:none">
589: END
590: } else {
591: $r->print($lt{'ncbc'}.'<br /><br />'.
592: '<h4>'.$lt{'addn'}.'</h4>'.
593: '<input type="hidden" name="blockaction" value="add" />');
594: }
595: my ($navmap,$errormsg) =
596: &Apache::loncourserespicker::get_navmap_object($crstype,'examblock');
1.1 raeburn 597:
1.4 raeburn 598: # --------------------------------------------- Interface for adding a new block
599: &display_addblocker_table($r,$blockcount,\%ltext,\%intervals,
600: $navmap,$errormsg);
601:
602: # ------------------------------------------------- Interface for existig blocks
1.1 raeburn 603: if ($blockcount > 0) {
1.4 raeburn 604: $r->print('</div>');
605: &display_blocker_status($r,\%records,\%ltext,\%intervals,
606: $navmap,$errormsg,$blockcount);
1.1 raeburn 607: }
608: $r->print(<<"END");
609: <br />
610: <input type ="submit" value="$lt{'stor'}" />
611: </form>
612: END
613: $r->print(&Apache::loncommon::end_page());
614: return OK;
615: }
616:
1.4 raeburn 617: sub get_timed_items {
618: my ($cdom,$cnum) = @_;
619: my ($cid,%intervals);
620: if ($cdom eq '' || $cnum eq '') {
621: $cid = $env{'request.course.id'};
622: $cdom = $env{'course.'.$cid.'.domain'};
623: $cnum = $env{'course.'.$cid.'.num'};
624: } else {
625: $cid = $cdom.'_'.$cnum;
626: }
627: if ($cid eq '') {
628: return %intervals;
629: }
630: my $resourcedata=&Apache::lonparmset::readdata($cnum,$cdom);
631: if (ref($resourcedata) eq 'HASH') {
632: foreach my $key (keys(%{$resourcedata})) {
633: if ($key =~ /^\Q$cid\E(.+)\.0\.interval$/) {
634: my $middle = $1;
635: if ($middle eq '') {
636: $intervals{'course'}{'all'} = $resourcedata->{$key};
637: } elsif ($middle =~ /^\.\[(\w+)\]$/) {
638: $intervals{'course'}{'secgrp'}{$1} = $resourcedata->{$key};
639: } elsif ($middle =~ /^\.\[useropt\:($match_username\:$match_domain)\]$/) {
640: $intervals{'course'}{'users'}{$1} = $resourcedata->{$key};
641: } elsif ($middle =~ /^\.(.+)\Q___(all)\E$/) {
642: my $inner = $1;
643: if ($inner =~ /^\[(\w+)\]\.([^\]]+)$/) {
644: $intervals{'map'}{$2}{'secgrp'}{$1} = $resourcedata->{$key};
645: } elsif ($inner =~ /^\[useropt\:($match_username\:$match_domain)\]\.([^\]]+)$/) {
646: $intervals{'map'}{$2}{'users'}{$1} = $resourcedata->{$key};
647: } else {
648: $intervals{'map'}{$inner}{'all'} = $resourcedata->{$key};
649: }
650: } elsif ($middle =~ /^\.\[(\w+)\]\.([^\]]+)$/) {
651: $intervals{'resource'}{$2}{'secgrp'}{$1} = $resourcedata->{$key};
652: } elsif ($middle =~ /^\.\[useropt\:($match_username\:$match_domain)\]\.([^\]]+)$/) {
653: $intervals{'resource'}{$2}{'users'}{$1} = $resourcedata->{$key};
654: } else {
655: my ($symb) = ($middle =~ /^\.(.+)$/);
656: $intervals{'resource'}{$symb}{'all'} = $resourcedata->{$key};
657: }
658: }
659: }
660: }
661: return %intervals;
662: }
663:
1.1 raeburn 664: sub blockstore {
1.12 raeburn 665: my ($r,$crstype,$blockcount,$currblockrecs) = @_;
1.1 raeburn 666: my %lt=&Apache::lonlocal::texthash(
667: 'tfcm' => 'The following changes were made',
1.4 raeburn 668: 'ncwm' => 'No changes were made.',
669: 'unna' => 'Unable to retrieve contents of course.',
1.1 raeburn 670: );
671: my %adds = ();
672: my %removals = ();
673: my %cancels = ();
674: my $modtotal = 0;
675: my $canceltotal = 0;
676: my $addtotal = 0;
1.4 raeburn 677: my $changestotal = 0;
678: my $addtimer = 0;
1.1 raeburn 679: my %blocking = ();
1.10 raeburn 680: my (%map_url,%resource_symb,%titles,$output);
1.4 raeburn 681: $output = '<h3>'.$lt{'head'}.'</h3>';
682: if ($env{'form.blockaction'} eq 'modify') {
683: foreach my $envkey (keys(%env)) {
684: if ($envkey =~ m/^form\.action_(\d+)$/) {
685: if ($env{$envkey} eq 'modify') {
686: $adds{$1} = 1;
687: $removals{$1} = 1;
688: } elsif ($env{$envkey} eq 'cancel') {
689: $cancels{$1} = $1;
690: unless ( defined($removals{$1}) ) {
691: $removals{$1} = 1;
692: $canceltotal ++;
693: }
694: }
695: }
1.1 raeburn 696: }
1.4 raeburn 697: } elsif ($env{'form.blockaction'} eq 'add') {
698: $adds{$blockcount} = 1;
1.1 raeburn 699: }
1.4 raeburn 700: my ($navmap,$errormsg) =
701: &Apache::loncourserespicker::get_navmap_object($crstype,'examblock');
702: unless (ref($navmap)) {
703: $output = $lt{'unna'}.' '.$lt{'ncwm'}.'</br>';
704: return ($changestotal,$output);
705: }
1.10 raeburn 706: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%map_url,\%resource_symb,\%titles,'examblock');
1.12 raeburn 707: my $do_releasereq_update;
708: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
709: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
710: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
711: my $chostname = &Apache::lonnet::hostname($chome);
712: my ($chomemajor,$chomeminor) =
713: split(/\./,&Apache::lonnet::get_server_loncaparev($cdom,$chome));
714:
715:
1.1 raeburn 716: foreach my $key (keys(%removals)) {
717: my $hashkey = $env{'form.key_'.$key};
1.12 raeburn 718: if ($hashkey =~ /firstaccess____/) {
719: $do_releasereq_update = 1;
720: }
721: if (ref($currblockrecs->{$hashkey}) eq 'HASH') {
722: if (ref($currblockrecs->{$hashkey}->{'blocks'}) eq 'HASH') {
723: foreach my $type ('docs','printout') {
724: if (exists($currblockrecs->{$hashkey}->{'blocks'}->{$type})) {
725: $do_releasereq_update = 1;
726: }
727: }
728: }
729: }
730: &Apache::lonnet::del('comm_block',["$hashkey"],$cdom,$cnum);
731: }
732: if ($do_releasereq_update) {
733: push(@{$modified_courses},[$cdom,$cnum,$chome,$crstype]);
734: unless ($registered_cleanup) {
735: my $handlers = $r->get_handlers('PerlCleanupHandler');
736: $r->set_handlers('PerlCleanupHandler' => [\&update_releasereq,@{$handlers}]);
737: $registered_cleanup=1;
738: }
1.1 raeburn 739: }
740: foreach my $key (keys(%adds)) {
741: unless ( defined($cancels{$key}) ) {
1.12 raeburn 742: my ($newkey,$status,$needsrelease);;
1.4 raeburn 743: if ($env{'form.firstaccess_'.$key}) {
744: my $interval =
745: &HTML::Entities::decode($env{'form.firstaccess_'.$key});
746: if ($interval ne '') {
747: if ($interval eq 'course') {
748: $newkey = 'firstaccess____'.$interval;
749: } elsif ($interval =~ /___\d+___/) {
750: my ($map,$resid,$url) =
751: &Apache::lonnet::decode_symb($interval);
752: if (&Apache::lonnet::is_on_map($url)) {
753: $newkey = 'firstaccess____'.$interval;
754: }
755: } elsif (&Apache::lonnet::is_on_map($interval)) {
756: $newkey = 'firstaccess____'.$interval;
757: }
758: if ($newkey ne '') {
759: unless (defined($removals{$key})) {
1.12 raeburn 760: ($status,$needsrelease) = &check_release_required('timer',$chomemajor,$chomeminor);
761: if ($status eq 'fail') {
762: $newkey = '';
763: $output .= '<p class="LC_warning">'.
764: &mt('Triggering of blocking events not allowed for [_1]',
765: &escape($env{'form.title_'.$key})).'<br />';
766: }
1.4 raeburn 767: }
768: }
769: }
770: } else {
771: my ($newstart,$newend) = &get_dates_from_form($key);
772: $newkey = $newstart.'____'.$newend;
773: }
1.12 raeburn 774: if ($status eq 'fail') {
775: $output .= &mt('LON-CAPA version ([_1]) installed on home server ([_2]) does not meet version requirements ([_3] or newer).',
776: $chomemajor.'.'.$chomeminor,$chostname,$needsrelease).'</p>';
777: }
1.4 raeburn 778: if ($newkey ne '') {
779: my ($blocktypes,$blockdocs) =
780: &get_block_choices($key,\%map_url,\%resource_symb);
1.12 raeburn 781: if (ref($blocktypes) eq 'HASH') {
782: if ($blocktypes->{'printout'} eq 'on') {
783: ($status,$needsrelease) = &check_release_required('printout',$chomemajor,$chomeminor);
784: if ($status eq 'fail') {
785: $blocktypes->{'printout'} = 'off';
786: $output .= '<p class="LC_warning">'.
787: &mt('Printout blocking not allowed for [_1]',
788: &escape($env{'form.title_'.$key})).'<br />';
789: }
790: }
791: }
792: if ($blockdocs) {
793: ($status,$needsrelease) = &check_release_required('docs',$chomemajor,$chomeminor);
794: if ($status eq 'fail') {
795: delete($blocktypes->{'docs'});
796: $output .= '<p class="LC_warning">'.
797: &mt('Content blocking not allowed for [_1]',
798: &escape($env{'form.title_'.$key})).'<br />';
799: }
800: }
1.4 raeburn 801: $blocking{$newkey} = {
1.1 raeburn 802: setter => $env{'user.name'}.':'.$env{'user.domain'},
803: event => &escape($env{'form.title_'.$key}),
804: blocks => $blocktypes,
805: };
1.4 raeburn 806: if (exists($removals{$key})) {
807: $modtotal ++;
808: } else {
809: $addtotal ++;
810: }
811: } else {
812: if ($env{'form.toggle_'.$key} eq 'timer') {
1.12 raeburn 813: unless ($status eq 'fail') {
814: $output .= '<p class="LC_warning">'.
815: &mt('Invalid trigger for new blocking event').
816: '</p>';
817: }
1.4 raeburn 818: } else {
819: $output .= '<p class="LC_warning">'.
820: &mt('No date range found for new blocking event').
821: '</p>';
822: }
823: }
1.1 raeburn 824: }
825: }
826: if ($addtotal + $modtotal > 0) {
827: &Apache::lonnet::put('comm_block',\%blocking,
828: $env{'course.'.$env{'request.course.id'}.'.domain'},
829: $env{'course.'.$env{'request.course.id'}.'.num'}
830: );
831: }
1.4 raeburn 832: $changestotal = $canceltotal + $modtotal + $addtotal;
833: if ($changestotal > 0) {
834: &Apache::lonnet::devalidate_cache_new('comm_block',
835: $env{'request.course.id'});
836: $output .= $lt{'tfcm'}.'<ul>';
1.1 raeburn 837: if ($canceltotal > 0) {
1.4 raeburn 838: $output .= '<li>'.
839: &mt('[quant,_1,blocking event was,blocking events were] removed.',
840: $canceltotal).
841: '</li>';
1.1 raeburn 842: }
843: if ($modtotal > 0) {
1.4 raeburn 844: $output .= '<li>'.
845: &mt('[quant,_1,blocking event was,blocking events were] modified.',
846: $modtotal).
847: '</li>';
1.1 raeburn 848: }
849: if ($addtotal > 0) {
1.4 raeburn 850: $output .= '<li>'.
851: &mt('[quant,_1,blocking event was,blocking events were] added.',
852: $addtotal).
853: '</li>';
1.1 raeburn 854: }
1.4 raeburn 855: $output .= '</ul>';
1.1 raeburn 856: } else {
1.4 raeburn 857: $output .= $lt{'ncwm'};
858: }
859: $output .= '<br />';
860: return ($changestotal,$output);
861: }
862:
1.12 raeburn 863: sub update_releasereq {
864: my $readmap = 1;
865: my $getrelreq = 1;
866: if (ref($modified_courses) eq 'ARRAY') {
867: foreach my $item (@{$modified_courses}) {
868: if (ref($item) eq 'ARRAY') {
869: my ($cdom,$cnum,$chome,$crstype) = @{$item};
870: &Apache::lonrelrequtils::modify_course_relreq(undef,undef,$cnum,$cdom,
871: $chome,$crstype,$cdom.'_'.$cnum,
872: $readmap,$getrelreq);
873: }
874: }
875: $modified_courses = [];
876: }
877: undef($registered_cleanup);
878: return;
879: }
880:
1.1 raeburn 881: sub get_dates_from_form {
882: my $item = shift;
883: my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$item);
884: my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$item);
885: return ($startdate,$enddate);
886: }
887:
888: sub get_blockdates {
1.4 raeburn 889: my ($records) = @_;
890: my $blockcount = 0;
1.1 raeburn 891: %{$records} = &Apache::lonnet::dump('comm_block',
892: $env{'course.'.$env{'request.course.id'}.'.domain'},
893: $env{'course.'.$env{'request.course.id'}.'.num'}
894: );
1.4 raeburn 895: $blockcount = keys(%{$records});
1.1 raeburn 896:
897: if ((keys(%{$records}))[0] =~ /^error: 2 /) {
1.4 raeburn 898: $blockcount = 0;
1.1 raeburn 899: }
1.4 raeburn 900: return $blockcount;
1.1 raeburn 901: }
902:
903: sub get_block_choices {
1.4 raeburn 904: my ($item,$map_ref,$symb_ref) = @_;
1.1 raeburn 905: my $blocklist;
1.4 raeburn 906: my $blockdocs;
1.1 raeburn 907: my ($typeorder,$types) = &blocktype_text();
908: foreach my $type (@{$typeorder}) {
1.4 raeburn 909: if ($type eq 'docs') {
910: if ($env{'form.'.$type.'_'.$item}) {
911: $blocklist->{$type} = {};
912: if ($env{'form.docs_resources_'.$item}) {
913: $env{'form.docs_resources_'.$item} =~ s/,$//;
914: if (ref($symb_ref) eq 'HASH') {
915: my %resources = map { $symb_ref->{$_} => 1; }
916: (split(/,/,$env{'form.docs_resources_'.$item}));
1.14 raeburn 917: if (exists($resources{''})) {
918: delete($resources{''});
919: }
1.4 raeburn 920: $blocklist->{$type}->{resources} = \%resources;
921: if (keys(%resources) > 0) {
922: $blockdocs = 1;
923: }
924: }
925: }
926: if ($env{'form.docs_maps_'.$item}) {
927: $env{'form.docs_maps_'.$item} =~ s/,$//;
928: if (ref($map_ref) eq 'HASH') {
929: my %maps = map { $map_ref->{$_} => 1; }
930: (split(/,/,$env{'form.docs_maps_'.$item}));
1.14 raeburn 931: if (exists($maps{''})) {
932: delete($maps{''});
933: }
1.4 raeburn 934: $blocklist->{$type}->{maps} = \%maps;
935: if (keys(%maps) > 0) {
936: $blockdocs = 1;
937: }
938: }
939: }
940: }
941: } else {
942: if ($env{'form.'.$type.'_'.$item}) {
943: $blocklist->{$type} = 'on';
944: } else {
945: $blocklist->{$type} = 'off';
946: }
947: }
948: }
949: return ($blocklist,$blockdocs);
950: }
951:
952: sub check_release_required {
1.12 raeburn 953: my ($value,$chomemajor,$chomeminor) = @_;
1.4 raeburn 954: my $needsrelease = $Apache::lonnet::needsrelease{'course:commblock:'.$value};
955: if ($needsrelease) {
1.12 raeburn 956: my ($needsmajor,$needsminor) = split(/\./,$needsrelease);
957: if (($chomemajor < $needsmajor) ||
958: (($chomemajor == $needsmajor) && ($chomeminor < $needsminor))) {
959: return ('fail',$needsrelease);
960: }
961: my $curr_required =
1.4 raeburn 962: $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};
963: if ($curr_required eq '') {
964: &Apache::lonnet::update_released_required($needsrelease);
1.1 raeburn 965: } else {
1.4 raeburn 966: my ($currmajor,$currminor) = split(/\./,$curr_required);
967: my ($needsmajor,$needsminor) = split(/\./,$needsrelease);
968: if (($currmajor < $needsmajor) ||
969: ($currmajor == $needsmajor && $currminor < $needsminor)) {
970: &Apache::lonnet::update_released_required($needsrelease);
971: }
1.1 raeburn 972: }
973: }
1.12 raeburn 974: return ('ok',$needsrelease);
1.1 raeburn 975: }
976:
977: sub display_blocker_status {
1.4 raeburn 978: my ($r,$records,$ltext,$intervals,$navmap,$errormsg,$blockcount) = @_;
1.1 raeburn 979: my $parmcount = 0;
1.10 raeburn 980: my (%map_url,%resource_symb,%titles,%lookups);
981: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%map_url,\%resource_symb,\%titles,'examblock');
1.4 raeburn 982: %{$lookups{'maps'}} = reverse(%map_url);
983: %{$lookups{'resources'}} = reverse(%resource_symb);
1.1 raeburn 984: my %lt = &Apache::lonlocal::texthash(
985: 'modi' => 'Modify',
1.4 raeburn 986: 'dele' => 'Delete',
987: 'noch' => 'No change',
1.1 raeburn 988: );
1.4 raeburn 989: $r->print('<div id="showmodify" style="display:block">'.
990: &Apache::loncommon::start_data_table());
1.1 raeburn 991: $r->print(<<"END");
992: <tr>
1.4 raeburn 993: <th></th>
994: <th>$ltext->{'type'}</th>
1.1 raeburn 995: <th>$ltext->{'even'}</th>
996: <th>$ltext->{'blck'}</th>
997: </tr>
998: END
999: foreach my $record (sort(keys(%{$records}))) {
1.4 raeburn 1000: my $jschg =
1001: 'javascript:window.document.forms['. "'blockform'".']'.
1002: '.elements['."'action_$parmcount'".'][0].checked=true;';
1003: my $onchange = 'onfocus="'.$jschg.'"';
1.1 raeburn 1004: my ($setuname,$setudom,$title,$blocks) =
1005: &Apache::loncommon::parse_block_record($$records{$record});
1006: $title = &HTML::Entities::encode($title,'"<>&');
1.4 raeburn 1007: my $blockid = &HTML::Entities::encode($record,'"<>&');
1.1 raeburn 1008: my $settername =
1009: &Apache::loncommon::aboutmewrapper(
1010: &Apache::loncommon::plainname($setuname,$setudom),
1011: $setuname,$setudom);
1012: $r->print(&Apache::loncommon::start_data_table_row());
1.4 raeburn 1013: $r->print(<<"ACT");
1014:
1015: <td valign="middle"><span class="LC_nobreak"><label>
1016: <input type="radio" name="action_$parmcount" value="modify" />$lt{'modi'}
1017: </label></span><br />
1018: <span class="LC_nobreak"><label>
1019: <input type="radio" name="action_$parmcount" value="cancel" />$lt{'dele'}
1020: </label></span><br />
1021: <span class="LC_nobreak"><label>
1022: <input type="radio" name="action_$parmcount" id="nochange_$parmcount"
1023: value="nochange" checked="checked" />$lt{'noch'}
1024: </label></span>
1025: </td>
1026: ACT
1027: my ($start,$end,$startform,$endform);
1028: if ($record =~ /^(\d+)____(\d+)$/) {
1029: ($start,$end) = split(/____/,$record);
1030: $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.
1031: $parmcount,$start,$onchange);
1032: $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.
1033: $parmcount,$end,$onchange);
1034: $r->print('<td><fieldset><legend>'.$ltext->{'defs'}.'</legend>'.
1035: $ltext->{'star'}.': '.$startform.'<br />'.
1036: $ltext->{'endd'}.': '.$endform.'</fieldset></td>');
1037: } elsif ($record =~ /^firstaccess____(.+)$/) {
1038: my $item = $1;
1039: my ($itemname,$iteminfo,$skipdetails);
1040: my $type = 'map';
1041: my $url;
1042: if ($item eq 'course') {
1043: $type = 'course';
1044: } elsif ($item =~ /___\d+___/) {
1045: $type = 'resource';
1046: (my $map, my $resid, $url) = &Apache::lonnet::decode_symb($item);
1047: } else {
1048: $url = $item;
1049: }
1050: $r->print('<td><fieldset><legend>'.$ltext->{'trig'}.'</legend>');
1051: if ($type eq 'course') {
1052: $itemname = &mt('Timer for all items in course.');
1053: } else {
1054: if (&Apache::lonnet::is_on_map($url)) {
1055: if ($type eq 'map') {
1056: if (ref($navmap)) {
1.13 raeburn 1057: my $title;
1058: my $resobj = $navmap->getResourceByUrl($item);
1059: if (ref($resobj)) {
1060: $title = $resobj->compTitle();
1061: } else {
1062: $title = &Apache::lonnet::gettitle($item);
1063: }
1.4 raeburn 1064: $itemname = &mt('Timer for all items in folder: [_1]',
1065: '<span style="font-style:italic">'.
1066: $title.'</span>');
1067: }
1068: } else {
1069: if (ref($navmap)) {
1.13 raeburn 1070: my $title;
1071: my $resobj = $navmap->getBySymb($item);
1072: if (ref($resobj)) {
1073: $title = $resobj->compTitle();
1074: } else {
1075: $title = &Apache::lonnet::gettitle($item);
1076: }
1.4 raeburn 1077: $itemname = &mt('Timer for resource: [_1]',
1078: '<span style="font-style:italic">'.
1079: $title.'</span>');
1080: }
1081: }
1082: if (ref($navmap)) {
1083: my $path = &show_timer_path($type,$item);
1084: if ($path) {
1085: $iteminfo = ' <span style="font-size:90%;">'.
1086: &mt('(in: [_1])',$path).
1087: '</span>';
1088: }
1089: }
1090: } else {
1091: $skipdetails = 1;
1092: $itemname = '<span style="LC_warning">'.
1093: &mt('Timer folder/resource not in course').
1094: '</span>';
1095: }
1096: }
1097: if ((!$skipdetails) && (ref($intervals) eq 'HASH')) {
1098: if (ref($intervals->{$type}) eq 'HASH') {
1099: $iteminfo .= &trigger_details_toggle($parmcount).
1100: '<ul id="trigdetails_'.$parmcount.'" style="display:none">';
1101: if ($type eq 'course') {
1102: foreach my $scope (keys(%{$intervals->{$type}})) {
1103: if ($scope eq 'all') {
1104: $iteminfo .= '<li>'.&mt('All users -- time limit: [_1]',
1105: &convlim($intervals->{$type}->{$scope})).'</li>';
1106: } elsif ($scope eq 'secgrp') {
1107: if (ref($intervals->{$type}->{$scope}) eq 'HASH') {
1108: $iteminfo .= '<li>'.&mt('Sections/groups').'<ul>';
1109: foreach my $item (sort(keys(%{$intervals->{$type}->{$scope}}))) {
1110: $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',$item,
1111: &convlim($intervals->{$type}->{$scope}->{$item})).
1112: '</li>';
1113: }
1114: $iteminfo .= '</ul></li>';
1115: }
1116: } elsif ($scope eq 'users') {
1117: if (ref($intervals->{$type}->{$scope}) eq 'HASH') {
1118: $iteminfo .= '<li>'.&mt('Users').'<ul>';
1119: foreach my $item (sort(keys(%{$intervals->{$type}->{$scope}}))) {
1120: $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',
1121: &convlim($item,$intervals->{$type}->{$scope}->{$item})).
1122: '</li>';
1123: }
1124: $iteminfo .= '</ul></li>';
1125: }
1126: }
1127: }
1128: } elsif (($type eq 'map') || ($type eq 'resource')) {
1129: if (ref($intervals->{$type}->{$item}) eq 'HASH') {
1130: foreach my $scope (keys(%{$intervals->{$type}->{$item}})) {
1131: if ($scope eq 'all') {
1132: $iteminfo .= '<li>'.&mt('All users -- time limit: [_1]',
1133: &convlim($intervals->{$type}->{$item}->{$scope})).
1134: '</li>';
1135: } elsif ($scope eq 'secgrp') {
1136: if (ref($intervals->{$type}->{$item}->{$scope}) eq 'HASH') {
1137: $iteminfo .= '<li>'.&mt('Sections/groups').'<ul>';
1138: foreach my $sec (sort(keys(%{$intervals->{$type}->{$item}->{$scope}}))) {
1139: $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',$sec,
1140: &convlim($intervals->{$type}->{$item}->{$scope}->{$sec})).
1141: '</li>';
1142: }
1143: $iteminfo .= '</ul></li>';
1144: }
1145: } elsif ($scope eq 'users') {
1146: if (ref($intervals->{$type}->{$item}->{$scope}) eq 'HASH') {
1147: $iteminfo .= '<li>'.&mt('Users').'<ul>';
1148: foreach my $user (sort(keys(%{$intervals->{$type}->{$item}->{$scope}}))) {
1149: $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',$user,
1150: &convlim($intervals->{$type}->{$item}->{$scope}->{$user})).
1151: '</li>';
1152: }
1153: $iteminfo .= '</ul></li>';
1154: }
1155: }
1156: }
1157: }
1158: }
1159: $iteminfo .= '</ul>';
1160: }
1.1 raeburn 1161: }
1.4 raeburn 1162: $r->print(&create_interval_form($intervals,$parmcount,$navmap,$item,$jschg,
1163: $itemname,$iteminfo).'</fieldset></td>');
1.1 raeburn 1164: }
1165: $r->print(<<"END");
1.4 raeburn 1166: <td>
1167: <input type="text" name="title_$parmcount" size="15" value="$title" onfocus="$jschg" />
1168: <input type="hidden" name="key_$parmcount" value="$blockid" />
1169: <br />
1170: <br />
1171: $ltext->{'setb'}: $settername
1172: </td>
1.1 raeburn 1173: END
1.4 raeburn 1174: $r->print('<td>'.&blocker_checkboxes($parmcount,$blocks,$jschg,\%lookups).'</td>'.
1175: &Apache::loncommon::end_data_table_row());
1.1 raeburn 1176: $parmcount++;
1177: }
1178: $r->print(<<"END");
1179: </table>
1.4 raeburn 1180: </div>
1.1 raeburn 1181: END
1.4 raeburn 1182: return;
1183: }
1184:
1185: sub convlim {
1186: my ($timelimit) = @_;
1187: my @order = ('days','hours','minutes','seconds');
1188: my %catlimits = (
1189: days => 86400,
1190: hours => 3600,
1191: minutes => 60,
1192: );
1193: my @toshow;
1194: foreach my $cat (@order) {
1195: if ($cat eq 'seconds') {
1.7 raeburn 1196: if ($timelimit > 0) {
1197: push(@toshow,&mt("[_1] $cat",$timelimit));
1198: }
1.4 raeburn 1199: } elsif ($timelimit >= $catlimits{$cat}) {
1200: my $val = int($timelimit/$catlimits{$cat});
1201: if ($val > 0) {
1202: push(@toshow,&mt("[_1] $cat",$val));
1203: }
1.9 raeburn 1204: $timelimit -= $val*$catlimits{$cat};
1.4 raeburn 1205: }
1206: }
1207: my $output = join(', ',@toshow);
1208: return $output;
1.1 raeburn 1209: }
1210:
1211: sub display_addblocker_table {
1.4 raeburn 1212: my ($r,$parmcount,$ltext,$intervals,$navmap,$errormsg) = @_;
1213: return unless ((ref($ltext) eq 'HASH') && (ref($intervals) eq 'HASH'));
1.1 raeburn 1214: my $start = time;
1215: my $end = $start + (60 * 60 * 2); #Default is an exam of 2 hours duration.
1.4 raeburn 1216: my $onchange = 'onfocus="javascript:window.document.forms['.
1217: "'blockform'].elements['addaction'].".
1.1 raeburn 1218: 'checked=true;"';
1.4 raeburn 1219: my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.
1220: $parmcount,$start,$onchange);
1221: my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.
1222: $parmcount,$end,$onchange);
1.1 raeburn 1223: my %lt = &Apache::lonlocal::texthash(
1224: 'exam' => 'e.g., Exam 1',
1225: );
1.4 raeburn 1226: my $intervalform = &create_interval_form($intervals,$parmcount,$navmap);
1227: if ($intervalform ne '') {
1228: $intervalform = '<fieldset>'.
1229: '<legend>'.$ltext->{'chtr'}.'</legend>'.
1230: $intervalform.
1231: '</fieldset>';
1232: }
1.1 raeburn 1233: $r->print(&Apache::loncommon::start_data_table());
1234: $r->print(<<"END");
1235: <tr>
1.4 raeburn 1236: <th>$ltext->{'type'}</th>
1.1 raeburn 1237: <th>$ltext->{'even'} $lt{'exam'}</th>
1238: <th>$ltext->{'blck'}</th>
1239: </tr>
1240: END
1.4 raeburn 1241: $r->print(&Apache::loncommon::start_data_table_row().'<td>');
1.1 raeburn 1242: $r->print(<<"END");
1.4 raeburn 1243: <span class="LC_nobreak"><label><input type="radio" id="toggle_startstop"
1244: name="toggle_$parmcount" value="startstop" onclick="showBlockType();" checked="checked" />
1245: $ltext->{'defs'}</label></span>
1246: <span class="LC_nobreak"><label><input type="radio" id="toggle_timer" name="toggle_$parmcount"
1247: value="timer" onclick="showBlockType();" />$ltext->{'trig'}</label></span><br />
1248: <div id="show_startstop" style="display:block">
1249: <fieldset><legend>$ltext->{'chda'}</legend>
1250: $ltext->{'star'}: $startform<br />$ltext->{'endd'}: $endform</fieldset>
1251: <span class="LC_warning">$ltext->{'when'}</span></div>
1252: <div id="show_timer" style="display:none">$intervalform</div>
1253: </td>
1.1 raeburn 1254: <td><input type="text" name="title_$parmcount" size="15" value="" /></td>
1255: END
1.4 raeburn 1256: $r->print('<td>'.&blocker_checkboxes($parmcount).'</td>'.
1257: &Apache::loncommon::end_data_table_row().
1258: &Apache::loncommon::end_data_table()."\n".
1259: '<br />');
1260: return;
1261: }
1262:
1263: sub blocker_checkboxes {
1264: my ($parmcount,$blocks,$jschg,$lookups) = @_;
1265: my ($typeorder,$types) = &blocktype_text();
1266: my $numinrow = 2;
1267: my %currdocs;
1268: my $output = '<table>';
1269: for (my $i=0; $i<@{$typeorder}; $i++) {
1270: my $block = $typeorder->[$i];
1271: my ($clickaction,$blockstatus);
1272: if ($jschg) {
1273: $clickaction = $jschg;
1274: }
1275: if ($block eq 'docs') {
1276: if ((ref($blocks) eq 'HASH') && (ref($lookups) eq 'HASH')) {
1277: if (ref($blocks->{$block}) eq 'HASH') {
1278: if (keys(%{$blocks->{$block}}) > 0) {
1279: $blockstatus = 'checked="checked"';
1280: foreach my $key (sort(keys(%{$blocks->{$block}}))) {
1281: if (ref($blocks->{$block}{$key}) eq 'HASH') {
1282: my @current = ();
1283: foreach my $item (keys(%{$blocks->{$block}{$key}})) {
1284: if ($lookups->{$key}{$item}) {
1285: push(@current,$lookups->{$key}{$item});
1286: }
1287: }
1288: if (@current > 0) {
1289: @current=sort { $a <=> $b } (@current);
1290: $currdocs{$key} = join(',',@current);
1291: }
1292: }
1293: }
1294: }
1295: }
1296: }
1297: $clickaction .= 'javascript:resblockinfo('."'$parmcount'".');';
1298: } else {
1299: if (ref($blocks) eq 'HASH') {
1300: if ($blocks->{$block} eq 'on') {
1301: $blockstatus = 'checked="checked"';
1302: }
1303: }
1304: }
1305: my $rem = $i%($numinrow);
1306: if ($rem == 0) {
1307: if ($i > 0) {
1308: $output .= '</tr>';
1309: }
1310: $output .= '<tr>';
1311: }
1312: if ($i == scalar(@{$typeorder})-1) {
1313: my $colsleft = $numinrow-$rem;
1314: if ($colsleft > 1) {
1315: $output .= '<td colspan="'.$colsleft.'">';
1316: } else {
1317: $output .= '<td>';
1318: }
1319: } else {
1320: $output .= '<td>';
1321: }
1322: my $item = $block.'_'.$parmcount;
1323: if ($clickaction) {
1324: $clickaction = ' onclick="'.$clickaction.'"';
1325: }
1326: if ($blockstatus) {
1327: $blockstatus = ' '.$blockstatus;
1328: }
1329: $output .= '<span class="LC_nobreak"><label>'."\n".
1330: '<input type="checkbox" id="'.$item.'" name="'.$item.'"'.
1331: $blockstatus.$clickaction.' value="1" />'.
1332: $types->{$block}.'</label></span>'."\n";
1333: if ($block eq 'docs') {
1334: if ($blockstatus ne '') {
1335: $output .= ' <a href="javascript:resblockinfo('."'$parmcount'".')">'.
1336: &mt('Details').'</a>';
1337: }
1338: }
1339: $output .= '<br /></td>';
1340: }
1341: $output .= '</tr></table>'.
1342: '<input type="hidden" name="docs_maps_'.$parmcount.'"'.
1343: ' id="docs_maps_'.$parmcount.'" value="'.$currdocs{'maps'}.'" />'.
1344: '<input type="hidden" name="docs_resources_'.$parmcount.'"'.
1345: ' id="docs_resources_'.$parmcount.'" value="'.$currdocs{'resources'}.'" />';
1346: return $output;
1347: }
1348:
1349: sub create_interval_form {
1350: my ($intervals,$parmcount,$navmap,$currkey,$jschg,$itemname,$iteminfo) = @_;
1351: return unless ((ref($intervals) eq 'HASH') && (ref($navmap)));
1352: my $intervalform;
1353: if (keys(%{$intervals}) > 0) {
1354: foreach my $type (sort(keys(%{$intervals}))) {
1355: if ($type eq 'course') {
1356: my ($checked,$clickaction);
1357: if ($currkey eq 'course') {
1358: $checked = ' checked="checked"';
1359: } elsif ($jschg) {
1360: $clickaction = ' onclick="'.$jschg.'"';
1361: }
1362: $intervalform .= '<label><input type="radio" name="firstaccess_'.$parmcount.
1363: '" value="course"'.$checked.$clickaction.' />';
1364: if ($currkey eq 'course') {
1365: $intervalform .= $itemname;
1366: } else {
1367: $intervalform .= &mt('Timer for all items in course');
1368: }
1369: $intervalform .= '</label>';
1370: if ($currkey eq 'course') {
1371: $intervalform .= $iteminfo;
1372: }
1373: $intervalform .= '<br />';
1374: } elsif ($type eq 'map') {
1375: if (ref($intervals->{$type}) eq 'HASH') {
1376: if (ref($navmap)) {
1377: foreach my $map (sort(keys(%{$intervals->{$type}}))) {
1.13 raeburn 1378: next if ((!&Apache::lonnet::is_on_map($map)) &&
1379: ($currkey ne $map));
1.4 raeburn 1380: my ($checked,$clickaction);
1381: if ($currkey eq $map) {
1382: $checked = ' checked="checked"';
1383: } elsif ($jschg) {
1384: $clickaction = ' onclick="'.$jschg.'"';
1385: }
1386: $intervalform .= '<label><input type="radio" name="firstaccess_'.$parmcount.
1387: '" value="'.&HTML::Entities::encode($map,'"<>&').'"'.
1388: $checked.$clickaction.' />';
1389: if ($currkey eq $map) {
1.13 raeburn 1390: $intervalform .= $itemname.'</label>'.$iteminfo;
1.4 raeburn 1391: } else {
1.13 raeburn 1392: my ($resobj,$title,$path,$hierarchy);
1393: $resobj = $navmap->getResourceByUrl($map);
1394: if (ref($resobj)) {
1395: $title = $resobj->compTitle();
1396: } else {
1397: $title = &Apache::lonnet::gettitle($map);
1398: }
1399: $hierarchy = &show_timer_path($type,$map,$navmap);
1.4 raeburn 1400: if ($hierarchy) {
1401: $path = ' <span style="font-size:90%;">'.
1402: &mt('(in: [_1])',$hierarchy).
1403: '</span>';
1404: }
1405: $intervalform .= &mt('Timer for all items in folder: [_1]',
1406: '<i>'.$title.'</i>').
1407: '</label>'.$path;
1408: }
1409: $intervalform .= '<br />';
1410: }
1411: }
1412: }
1413: } elsif ($type eq 'resource') {
1414: if (ref($intervals->{$type}) eq 'HASH') {
1415: if (ref($navmap)) {
1416: foreach my $resource (sort(keys(%{$intervals->{$type}}))) {
1.13 raeburn 1417: my ($checked,$clickaction,$resobj);
1.4 raeburn 1418: if ($currkey eq $resource) {
1419: $checked = ' checked="checked"';
1.13 raeburn 1420: } else {
1421: $resobj = $navmap->getBySymb($resource);
1422: next unless(ref($resobj));
1423: if ($jschg) {
1424: $clickaction = ' onclick="'.$jschg.'"';
1425: }
1.4 raeburn 1426: }
1427: $intervalform .= '<label><input type="radio" name="firstaccess_'.$parmcount.
1428: '" value="'.&HTML::Entities::encode($resource,'"<>&').'"'.
1429: $checked.$clickaction.' />';
1430: if ($currkey eq $resource) {
1.13 raeburn 1431: $intervalform .= $itemname.'</label>'.$iteminfo;
1.4 raeburn 1432: } else {
1.13 raeburn 1433: my ($title,$path,$hierarchy);
1434: if (ref($resobj)) {
1435: $title = $resobj->compTitle();
1436: } else {
1437: $title = &Apache::lonnet::gettitle($resource);
1438: }
1439: $hierarchy = &show_timer_path($type,$resource,$navmap);
1.4 raeburn 1440: if ($hierarchy) {
1441: $path = ' <span style="font-size:90%;">'.
1442: &mt('(in: [_1])',$hierarchy).
1443: '</span>';
1444: }
1445: $intervalform .= &mt('Timer for resource: [_1]','<i>'.$title.'</i>').
1446: '</label>'.
1447: $path;
1448: }
1449: $intervalform .= '<br />';
1450: }
1451: }
1452: }
1453: }
1454: }
1455: } else {
1456: if ($currkey ne '') {
1457: $intervalform = '<input type="radio" name="firstaccess_'.$parmcount.
1458: '" checked="checked" value="'.
1459: &HTML::Entities::encode($currkey,'"<>&').' />'.
1460: $itemname.'<br />';
1461: } else {
1462: $intervalform = &mt('No timed items defined.').' '.
1463: &mt('Use [_1]Settings[_2] to assign a timer, then return here.',
1464: '<a href="/adm/parmset">','</a>');
1465: }
1466: }
1467: return $intervalform;
1468: }
1469:
1470: sub trigger_details_toggle {
1471: my ($parmcount) = @_;
1472: return ' <span id="toggletext_'.$parmcount.'" class="LC_cusr_subheading LC_nobreak">'.
1473: '<a href="javascript:showTriggerDetails('."'$parmcount'".');" '.
1474: 'style="text-decoration: none;"><b>'.&mt('(More ...)').'</b></a></span>';
1475: }
1476:
1477: sub show_timer_path {
1478: my ($type,$item,$navmap) = @_;
1479: return unless(ref($navmap));
1480: my @pathitems;
1481: if ($type eq 'map') {
1.8 raeburn 1482: @pathitems =
1483: &Apache::loncommon::get_folder_hierarchy($navmap,$item);
1.4 raeburn 1484: } elsif ($type eq 'resource') {
1485: my ($map,$id,$resource) = &Apache::lonnet::decode_symb($item);
1.8 raeburn 1486: @pathitems =
1487: &Apache::loncommon::get_folder_hierarchy($navmap,$map,1);
1.4 raeburn 1488: }
1489: if (@pathitems) {
1490: return join(' » ',@pathitems);
1491: }
1.1 raeburn 1492: return;
1493: }
1494:
1495: sub blocktype_text {
1496: my %types = &Apache::lonlocal::texthash(
1497: 'com' => 'Messaging',
1498: 'chat' => 'Chat Room',
1499: 'boards' => 'Discussion',
1500: 'port' => 'Portfolio',
1501: 'groups' => 'Groups',
1502: 'blogs' => 'Blogs',
1.5 raeburn 1503: 'docs' => 'Content',
1504: 'printout' => 'Printouts',
1.14.2.1! raeburn 1505: 'passwd' => 'Password',
1.1 raeburn 1506: );
1.14.2.1! raeburn 1507: my $typeorder = ['com','chat','boards','port','groups','blogs','printout','docs','passwd'];
1.1 raeburn 1508: return ($typeorder,\%types);
1509: }
1510:
1.4 raeburn 1511: sub blockingmenu_javascript {
1512: my ($blockcount) = @_;
1513: my %lt = &Apache::lonlocal::texthash (
1514: more => 'More ...',
1515: less => 'Less ...',
1516: );
1517: return <<ENDSCRIPT;
1518: <script type="text/javascript">
1519: // <![CDATA[
1520: function resblockinfo(blockid) {
1521: if (document.getElementById('docs_'+blockid).checked) {
1522: var resblockwin = null;
1523: var url = '/adm/setblock?action=showdocs&block='+blockid;
1524: if (!resblockwin || resblockwin.closed) {
1525: resblockwin=window.open(url,'blockingwin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
1526: }
1527: resblockwin.focus();
1528: } else {
1529: document.getElementById('docs_resources_'+blockid).value = '';
1530: document.getElementById('docs_maps_'+blockid).value = '';
1531: }
1532: return;
1533: }
1534:
1535: function showBlockType() {
1536: if (document.getElementById('toggle_startstop').checked == true) {
1537: document.getElementById('show_startstop').style.display='block';
1538: } else {
1539: document.getElementById('show_startstop').style.display='none';
1540: }
1541: if (document.getElementById('toggle_timer').checked == true) {
1542: document.getElementById('show_timer').style.display='block';
1543: } else {
1544: document.getElementById('show_timer').style.display='none';
1545: }
1546: return;
1547: }
1548:
1549: function toggleAddModify() {
1550: for (var i=0; i<document.blockform.blockaction.length; i++) {
1551: if (document.blockform.blockaction[i].checked) {
1552: if (document.blockform.blockaction[i].value == 'add') {
1553: document.getElementById('showadd').style.display='block';
1554: document.getElementById('showmodify').style.display='none';
1555: var blocktotal = $blockcount;
1556: if (blocktotal > 0) {
1557: for (var i=0; i<blocktotal; i++) {
1558: document.getElementById('nochange_'+i).checked = true;
1559: }
1560: }
1561: document.getElementById('showmodify').style.display='none';
1562: document.getElementById('showadd').style.display='block';
1563: } else {
1564: document.getElementById('showadd').style.display='none';
1565: document.getElementById('showmodify').style.display='block';
1566: }
1567: }
1568: }
1569: return;
1570: }
1571:
1572: function showTriggerDetails(item) {
1573: document.getElementById('trigdetails_'+item).style.display='block';
1574: document.getElementById('trigdetails_'+item).style.textAlign='left';
1575: document.getElementById('trigdetails_'+item).style.textFace='normal';
1576: document.getElementById('toggletext_'+item).innerHTML = '<a href="javascript:hideTriggerDetails('+item+');" style="text-decoration: none;"><b>($lt{'less'})</b></a>';
1577: return;
1578: }
1579:
1580: function hideTriggerDetails(item) {
1581: document.getElementById('trigdetails_'+item).style.display='none';
1582: document.getElementById('toggletext_'+item).innerHTML = '<a href="javascript:showTriggerDetails('+item+');" style="text-decoration: none;"><b>($lt{'more'})</b></a>';
1583: return;
1584: }
1585:
1586: // ]]>
1587: </script>
1588: ENDSCRIPT
1589:
1590: }
1591:
1.1 raeburn 1592: 1;
1593:
1594: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>