Annotation of loncom/interface/lonblockingmenu.pm, revision 1.15
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.15 ! 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>'.
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}));
1.14 raeburn 916: if (exists($resources{''})) {
917: delete($resources{''});
918: }
1.4 raeburn 919: $blocklist->{$type}->{resources} = \%resources;
920: if (keys(%resources) > 0) {
921: $blockdocs = 1;
922: }
923: }
924: }
925: if ($env{'form.docs_maps_'.$item}) {
926: $env{'form.docs_maps_'.$item} =~ s/,$//;
927: if (ref($map_ref) eq 'HASH') {
928: my %maps = map { $map_ref->{$_} => 1; }
929: (split(/,/,$env{'form.docs_maps_'.$item}));
1.14 raeburn 930: if (exists($maps{''})) {
931: delete($maps{''});
932: }
1.4 raeburn 933: $blocklist->{$type}->{maps} = \%maps;
934: if (keys(%maps) > 0) {
935: $blockdocs = 1;
936: }
937: }
938: }
939: }
940: } else {
941: if ($env{'form.'.$type.'_'.$item}) {
942: $blocklist->{$type} = 'on';
943: } else {
944: $blocklist->{$type} = 'off';
945: }
946: }
947: }
948: return ($blocklist,$blockdocs);
949: }
950:
951: sub check_release_required {
1.12 raeburn 952: my ($value,$chomemajor,$chomeminor) = @_;
1.15 ! raeburn 953: my $needsrelease = $Apache::lonnet::needsrelease{'course:commblock:'.$value.':'};
1.4 raeburn 954: if ($needsrelease) {
1.12 raeburn 955: my ($needsmajor,$needsminor) = split(/\./,$needsrelease);
956: if (($chomemajor < $needsmajor) ||
957: (($chomemajor == $needsmajor) && ($chomeminor < $needsminor))) {
958: return ('fail',$needsrelease);
959: }
960: my $curr_required =
1.4 raeburn 961: $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};
962: if ($curr_required eq '') {
963: &Apache::lonnet::update_released_required($needsrelease);
1.1 raeburn 964: } else {
1.4 raeburn 965: my ($currmajor,$currminor) = split(/\./,$curr_required);
966: my ($needsmajor,$needsminor) = split(/\./,$needsrelease);
967: if (($currmajor < $needsmajor) ||
968: ($currmajor == $needsmajor && $currminor < $needsminor)) {
969: &Apache::lonnet::update_released_required($needsrelease);
970: }
1.1 raeburn 971: }
972: }
1.12 raeburn 973: return ('ok',$needsrelease);
1.1 raeburn 974: }
975:
976: sub display_blocker_status {
1.4 raeburn 977: my ($r,$records,$ltext,$intervals,$navmap,$errormsg,$blockcount) = @_;
1.1 raeburn 978: my $parmcount = 0;
1.10 raeburn 979: my (%map_url,%resource_symb,%titles,%lookups);
980: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%map_url,\%resource_symb,\%titles,'examblock');
1.4 raeburn 981: %{$lookups{'maps'}} = reverse(%map_url);
982: %{$lookups{'resources'}} = reverse(%resource_symb);
1.1 raeburn 983: my %lt = &Apache::lonlocal::texthash(
984: 'modi' => 'Modify',
1.4 raeburn 985: 'dele' => 'Delete',
986: 'noch' => 'No change',
1.1 raeburn 987: );
1.4 raeburn 988: $r->print('<div id="showmodify" style="display:block">'.
989: &Apache::loncommon::start_data_table());
1.1 raeburn 990: $r->print(<<"END");
991: <tr>
1.4 raeburn 992: <th></th>
993: <th>$ltext->{'type'}</th>
1.1 raeburn 994: <th>$ltext->{'even'}</th>
995: <th>$ltext->{'blck'}</th>
996: </tr>
997: END
998: foreach my $record (sort(keys(%{$records}))) {
1.4 raeburn 999: my $jschg =
1000: 'javascript:window.document.forms['. "'blockform'".']'.
1001: '.elements['."'action_$parmcount'".'][0].checked=true;';
1002: my $onchange = 'onfocus="'.$jschg.'"';
1.1 raeburn 1003: my ($setuname,$setudom,$title,$blocks) =
1004: &Apache::loncommon::parse_block_record($$records{$record});
1005: $title = &HTML::Entities::encode($title,'"<>&');
1.4 raeburn 1006: my $blockid = &HTML::Entities::encode($record,'"<>&');
1.1 raeburn 1007: my $settername =
1008: &Apache::loncommon::aboutmewrapper(
1009: &Apache::loncommon::plainname($setuname,$setudom),
1010: $setuname,$setudom);
1011: $r->print(&Apache::loncommon::start_data_table_row());
1.4 raeburn 1012: $r->print(<<"ACT");
1013:
1014: <td valign="middle"><span class="LC_nobreak"><label>
1015: <input type="radio" name="action_$parmcount" value="modify" />$lt{'modi'}
1016: </label></span><br />
1017: <span class="LC_nobreak"><label>
1018: <input type="radio" name="action_$parmcount" value="cancel" />$lt{'dele'}
1019: </label></span><br />
1020: <span class="LC_nobreak"><label>
1021: <input type="radio" name="action_$parmcount" id="nochange_$parmcount"
1022: value="nochange" checked="checked" />$lt{'noch'}
1023: </label></span>
1024: </td>
1025: ACT
1026: my ($start,$end,$startform,$endform);
1027: if ($record =~ /^(\d+)____(\d+)$/) {
1028: ($start,$end) = split(/____/,$record);
1029: $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.
1030: $parmcount,$start,$onchange);
1031: $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.
1032: $parmcount,$end,$onchange);
1033: $r->print('<td><fieldset><legend>'.$ltext->{'defs'}.'</legend>'.
1034: $ltext->{'star'}.': '.$startform.'<br />'.
1035: $ltext->{'endd'}.': '.$endform.'</fieldset></td>');
1036: } elsif ($record =~ /^firstaccess____(.+)$/) {
1037: my $item = $1;
1038: my ($itemname,$iteminfo,$skipdetails);
1039: my $type = 'map';
1040: my $url;
1041: if ($item eq 'course') {
1042: $type = 'course';
1043: } elsif ($item =~ /___\d+___/) {
1044: $type = 'resource';
1045: (my $map, my $resid, $url) = &Apache::lonnet::decode_symb($item);
1046: } else {
1047: $url = $item;
1048: }
1049: $r->print('<td><fieldset><legend>'.$ltext->{'trig'}.'</legend>');
1050: if ($type eq 'course') {
1051: $itemname = &mt('Timer for all items in course.');
1052: } else {
1053: if (&Apache::lonnet::is_on_map($url)) {
1054: if ($type eq 'map') {
1055: if (ref($navmap)) {
1.13 raeburn 1056: my $title;
1057: my $resobj = $navmap->getResourceByUrl($item);
1058: if (ref($resobj)) {
1059: $title = $resobj->compTitle();
1060: } else {
1061: $title = &Apache::lonnet::gettitle($item);
1062: }
1.4 raeburn 1063: $itemname = &mt('Timer for all items in folder: [_1]',
1064: '<span style="font-style:italic">'.
1065: $title.'</span>');
1066: }
1067: } else {
1068: if (ref($navmap)) {
1.13 raeburn 1069: my $title;
1070: my $resobj = $navmap->getBySymb($item);
1071: if (ref($resobj)) {
1072: $title = $resobj->compTitle();
1073: } else {
1074: $title = &Apache::lonnet::gettitle($item);
1075: }
1.4 raeburn 1076: $itemname = &mt('Timer for resource: [_1]',
1077: '<span style="font-style:italic">'.
1078: $title.'</span>');
1079: }
1080: }
1081: if (ref($navmap)) {
1082: my $path = &show_timer_path($type,$item);
1083: if ($path) {
1084: $iteminfo = ' <span style="font-size:90%;">'.
1085: &mt('(in: [_1])',$path).
1086: '</span>';
1087: }
1088: }
1089: } else {
1090: $skipdetails = 1;
1091: $itemname = '<span style="LC_warning">'.
1092: &mt('Timer folder/resource not in course').
1093: '</span>';
1094: }
1095: }
1096: if ((!$skipdetails) && (ref($intervals) eq 'HASH')) {
1097: if (ref($intervals->{$type}) eq 'HASH') {
1098: $iteminfo .= &trigger_details_toggle($parmcount).
1099: '<ul id="trigdetails_'.$parmcount.'" style="display:none">';
1100: if ($type eq 'course') {
1101: foreach my $scope (keys(%{$intervals->{$type}})) {
1102: if ($scope eq 'all') {
1103: $iteminfo .= '<li>'.&mt('All users -- time limit: [_1]',
1104: &convlim($intervals->{$type}->{$scope})).'</li>';
1105: } elsif ($scope eq 'secgrp') {
1106: if (ref($intervals->{$type}->{$scope}) eq 'HASH') {
1107: $iteminfo .= '<li>'.&mt('Sections/groups').'<ul>';
1108: foreach my $item (sort(keys(%{$intervals->{$type}->{$scope}}))) {
1109: $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',$item,
1110: &convlim($intervals->{$type}->{$scope}->{$item})).
1111: '</li>';
1112: }
1113: $iteminfo .= '</ul></li>';
1114: }
1115: } elsif ($scope eq 'users') {
1116: if (ref($intervals->{$type}->{$scope}) eq 'HASH') {
1117: $iteminfo .= '<li>'.&mt('Users').'<ul>';
1118: foreach my $item (sort(keys(%{$intervals->{$type}->{$scope}}))) {
1119: $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',
1120: &convlim($item,$intervals->{$type}->{$scope}->{$item})).
1121: '</li>';
1122: }
1123: $iteminfo .= '</ul></li>';
1124: }
1125: }
1126: }
1127: } elsif (($type eq 'map') || ($type eq 'resource')) {
1128: if (ref($intervals->{$type}->{$item}) eq 'HASH') {
1129: foreach my $scope (keys(%{$intervals->{$type}->{$item}})) {
1130: if ($scope eq 'all') {
1131: $iteminfo .= '<li>'.&mt('All users -- time limit: [_1]',
1132: &convlim($intervals->{$type}->{$item}->{$scope})).
1133: '</li>';
1134: } elsif ($scope eq 'secgrp') {
1135: if (ref($intervals->{$type}->{$item}->{$scope}) eq 'HASH') {
1136: $iteminfo .= '<li>'.&mt('Sections/groups').'<ul>';
1137: foreach my $sec (sort(keys(%{$intervals->{$type}->{$item}->{$scope}}))) {
1138: $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',$sec,
1139: &convlim($intervals->{$type}->{$item}->{$scope}->{$sec})).
1140: '</li>';
1141: }
1142: $iteminfo .= '</ul></li>';
1143: }
1144: } elsif ($scope eq 'users') {
1145: if (ref($intervals->{$type}->{$item}->{$scope}) eq 'HASH') {
1146: $iteminfo .= '<li>'.&mt('Users').'<ul>';
1147: foreach my $user (sort(keys(%{$intervals->{$type}->{$item}->{$scope}}))) {
1148: $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',$user,
1149: &convlim($intervals->{$type}->{$item}->{$scope}->{$user})).
1150: '</li>';
1151: }
1152: $iteminfo .= '</ul></li>';
1153: }
1154: }
1155: }
1156: }
1157: }
1158: $iteminfo .= '</ul>';
1159: }
1.1 raeburn 1160: }
1.4 raeburn 1161: $r->print(&create_interval_form($intervals,$parmcount,$navmap,$item,$jschg,
1162: $itemname,$iteminfo).'</fieldset></td>');
1.1 raeburn 1163: }
1164: $r->print(<<"END");
1.4 raeburn 1165: <td>
1166: <input type="text" name="title_$parmcount" size="15" value="$title" onfocus="$jschg" />
1167: <input type="hidden" name="key_$parmcount" value="$blockid" />
1168: <br />
1169: <br />
1170: $ltext->{'setb'}: $settername
1171: </td>
1.1 raeburn 1172: END
1.4 raeburn 1173: $r->print('<td>'.&blocker_checkboxes($parmcount,$blocks,$jschg,\%lookups).'</td>'.
1174: &Apache::loncommon::end_data_table_row());
1.1 raeburn 1175: $parmcount++;
1176: }
1177: $r->print(<<"END");
1178: </table>
1.4 raeburn 1179: </div>
1.1 raeburn 1180: END
1.4 raeburn 1181: return;
1182: }
1183:
1184: sub convlim {
1185: my ($timelimit) = @_;
1186: my @order = ('days','hours','minutes','seconds');
1187: my %catlimits = (
1188: days => 86400,
1189: hours => 3600,
1190: minutes => 60,
1191: );
1192: my @toshow;
1193: foreach my $cat (@order) {
1194: if ($cat eq 'seconds') {
1.7 raeburn 1195: if ($timelimit > 0) {
1196: push(@toshow,&mt("[_1] $cat",$timelimit));
1197: }
1.4 raeburn 1198: } elsif ($timelimit >= $catlimits{$cat}) {
1199: my $val = int($timelimit/$catlimits{$cat});
1200: if ($val > 0) {
1201: push(@toshow,&mt("[_1] $cat",$val));
1202: }
1.9 raeburn 1203: $timelimit -= $val*$catlimits{$cat};
1.4 raeburn 1204: }
1205: }
1206: my $output = join(', ',@toshow);
1207: return $output;
1.1 raeburn 1208: }
1209:
1210: sub display_addblocker_table {
1.4 raeburn 1211: my ($r,$parmcount,$ltext,$intervals,$navmap,$errormsg) = @_;
1212: return unless ((ref($ltext) eq 'HASH') && (ref($intervals) eq 'HASH'));
1.1 raeburn 1213: my $start = time;
1214: my $end = $start + (60 * 60 * 2); #Default is an exam of 2 hours duration.
1.4 raeburn 1215: my $onchange = 'onfocus="javascript:window.document.forms['.
1216: "'blockform'].elements['addaction'].".
1.1 raeburn 1217: 'checked=true;"';
1.4 raeburn 1218: my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.
1219: $parmcount,$start,$onchange);
1220: my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.
1221: $parmcount,$end,$onchange);
1.1 raeburn 1222: my %lt = &Apache::lonlocal::texthash(
1223: 'exam' => 'e.g., Exam 1',
1224: );
1.4 raeburn 1225: my $intervalform = &create_interval_form($intervals,$parmcount,$navmap);
1226: if ($intervalform ne '') {
1227: $intervalform = '<fieldset>'.
1228: '<legend>'.$ltext->{'chtr'}.'</legend>'.
1229: $intervalform.
1230: '</fieldset>';
1231: }
1.1 raeburn 1232: $r->print(&Apache::loncommon::start_data_table());
1233: $r->print(<<"END");
1234: <tr>
1.4 raeburn 1235: <th>$ltext->{'type'}</th>
1.1 raeburn 1236: <th>$ltext->{'even'} $lt{'exam'}</th>
1237: <th>$ltext->{'blck'}</th>
1238: </tr>
1239: END
1.4 raeburn 1240: $r->print(&Apache::loncommon::start_data_table_row().'<td>');
1.1 raeburn 1241: $r->print(<<"END");
1.4 raeburn 1242: <span class="LC_nobreak"><label><input type="radio" id="toggle_startstop"
1243: name="toggle_$parmcount" value="startstop" onclick="showBlockType();" checked="checked" />
1244: $ltext->{'defs'}</label></span>
1245: <span class="LC_nobreak"><label><input type="radio" id="toggle_timer" name="toggle_$parmcount"
1246: value="timer" onclick="showBlockType();" />$ltext->{'trig'}</label></span><br />
1247: <div id="show_startstop" style="display:block">
1248: <fieldset><legend>$ltext->{'chda'}</legend>
1249: $ltext->{'star'}: $startform<br />$ltext->{'endd'}: $endform</fieldset>
1250: <span class="LC_warning">$ltext->{'when'}</span></div>
1251: <div id="show_timer" style="display:none">$intervalform</div>
1252: </td>
1.1 raeburn 1253: <td><input type="text" name="title_$parmcount" size="15" value="" /></td>
1254: END
1.4 raeburn 1255: $r->print('<td>'.&blocker_checkboxes($parmcount).'</td>'.
1256: &Apache::loncommon::end_data_table_row().
1257: &Apache::loncommon::end_data_table()."\n".
1258: '<br />');
1259: return;
1260: }
1261:
1262: sub blocker_checkboxes {
1263: my ($parmcount,$blocks,$jschg,$lookups) = @_;
1264: my ($typeorder,$types) = &blocktype_text();
1265: my $numinrow = 2;
1266: my %currdocs;
1267: my $output = '<table>';
1268: for (my $i=0; $i<@{$typeorder}; $i++) {
1269: my $block = $typeorder->[$i];
1270: my ($clickaction,$blockstatus);
1271: if ($jschg) {
1272: $clickaction = $jschg;
1273: }
1274: if ($block eq 'docs') {
1275: if ((ref($blocks) eq 'HASH') && (ref($lookups) eq 'HASH')) {
1276: if (ref($blocks->{$block}) eq 'HASH') {
1277: if (keys(%{$blocks->{$block}}) > 0) {
1278: $blockstatus = 'checked="checked"';
1279: foreach my $key (sort(keys(%{$blocks->{$block}}))) {
1280: if (ref($blocks->{$block}{$key}) eq 'HASH') {
1281: my @current = ();
1282: foreach my $item (keys(%{$blocks->{$block}{$key}})) {
1283: if ($lookups->{$key}{$item}) {
1284: push(@current,$lookups->{$key}{$item});
1285: }
1286: }
1287: if (@current > 0) {
1288: @current=sort { $a <=> $b } (@current);
1289: $currdocs{$key} = join(',',@current);
1290: }
1291: }
1292: }
1293: }
1294: }
1295: }
1296: $clickaction .= 'javascript:resblockinfo('."'$parmcount'".');';
1297: } else {
1298: if (ref($blocks) eq 'HASH') {
1299: if ($blocks->{$block} eq 'on') {
1300: $blockstatus = 'checked="checked"';
1301: }
1302: }
1303: }
1304: my $rem = $i%($numinrow);
1305: if ($rem == 0) {
1306: if ($i > 0) {
1307: $output .= '</tr>';
1308: }
1309: $output .= '<tr>';
1310: }
1311: if ($i == scalar(@{$typeorder})-1) {
1312: my $colsleft = $numinrow-$rem;
1313: if ($colsleft > 1) {
1314: $output .= '<td colspan="'.$colsleft.'">';
1315: } else {
1316: $output .= '<td>';
1317: }
1318: } else {
1319: $output .= '<td>';
1320: }
1321: my $item = $block.'_'.$parmcount;
1322: if ($clickaction) {
1323: $clickaction = ' onclick="'.$clickaction.'"';
1324: }
1325: if ($blockstatus) {
1326: $blockstatus = ' '.$blockstatus;
1327: }
1328: $output .= '<span class="LC_nobreak"><label>'."\n".
1329: '<input type="checkbox" id="'.$item.'" name="'.$item.'"'.
1330: $blockstatus.$clickaction.' value="1" />'.
1331: $types->{$block}.'</label></span>'."\n";
1332: if ($block eq 'docs') {
1333: if ($blockstatus ne '') {
1334: $output .= ' <a href="javascript:resblockinfo('."'$parmcount'".')">'.
1335: &mt('Details').'</a>';
1336: }
1337: }
1338: $output .= '<br /></td>';
1339: }
1340: $output .= '</tr></table>'.
1341: '<input type="hidden" name="docs_maps_'.$parmcount.'"'.
1342: ' id="docs_maps_'.$parmcount.'" value="'.$currdocs{'maps'}.'" />'.
1343: '<input type="hidden" name="docs_resources_'.$parmcount.'"'.
1344: ' id="docs_resources_'.$parmcount.'" value="'.$currdocs{'resources'}.'" />';
1345: return $output;
1346: }
1347:
1348: sub create_interval_form {
1349: my ($intervals,$parmcount,$navmap,$currkey,$jschg,$itemname,$iteminfo) = @_;
1350: return unless ((ref($intervals) eq 'HASH') && (ref($navmap)));
1351: my $intervalform;
1352: if (keys(%{$intervals}) > 0) {
1353: foreach my $type (sort(keys(%{$intervals}))) {
1354: if ($type eq 'course') {
1355: my ($checked,$clickaction);
1356: if ($currkey eq 'course') {
1357: $checked = ' checked="checked"';
1358: } elsif ($jschg) {
1359: $clickaction = ' onclick="'.$jschg.'"';
1360: }
1361: $intervalform .= '<label><input type="radio" name="firstaccess_'.$parmcount.
1362: '" value="course"'.$checked.$clickaction.' />';
1363: if ($currkey eq 'course') {
1364: $intervalform .= $itemname;
1365: } else {
1366: $intervalform .= &mt('Timer for all items in course');
1367: }
1368: $intervalform .= '</label>';
1369: if ($currkey eq 'course') {
1370: $intervalform .= $iteminfo;
1371: }
1372: $intervalform .= '<br />';
1373: } elsif ($type eq 'map') {
1374: if (ref($intervals->{$type}) eq 'HASH') {
1375: if (ref($navmap)) {
1376: foreach my $map (sort(keys(%{$intervals->{$type}}))) {
1.13 raeburn 1377: next if ((!&Apache::lonnet::is_on_map($map)) &&
1378: ($currkey ne $map));
1.4 raeburn 1379: my ($checked,$clickaction);
1380: if ($currkey eq $map) {
1381: $checked = ' checked="checked"';
1382: } elsif ($jschg) {
1383: $clickaction = ' onclick="'.$jschg.'"';
1384: }
1385: $intervalform .= '<label><input type="radio" name="firstaccess_'.$parmcount.
1386: '" value="'.&HTML::Entities::encode($map,'"<>&').'"'.
1387: $checked.$clickaction.' />';
1388: if ($currkey eq $map) {
1.13 raeburn 1389: $intervalform .= $itemname.'</label>'.$iteminfo;
1.4 raeburn 1390: } else {
1.13 raeburn 1391: my ($resobj,$title,$path,$hierarchy);
1392: $resobj = $navmap->getResourceByUrl($map);
1393: if (ref($resobj)) {
1394: $title = $resobj->compTitle();
1395: } else {
1396: $title = &Apache::lonnet::gettitle($map);
1397: }
1398: $hierarchy = &show_timer_path($type,$map,$navmap);
1.4 raeburn 1399: if ($hierarchy) {
1400: $path = ' <span style="font-size:90%;">'.
1401: &mt('(in: [_1])',$hierarchy).
1402: '</span>';
1403: }
1404: $intervalform .= &mt('Timer for all items in folder: [_1]',
1405: '<i>'.$title.'</i>').
1406: '</label>'.$path;
1407: }
1408: $intervalform .= '<br />';
1409: }
1410: }
1411: }
1412: } elsif ($type eq 'resource') {
1413: if (ref($intervals->{$type}) eq 'HASH') {
1414: if (ref($navmap)) {
1415: foreach my $resource (sort(keys(%{$intervals->{$type}}))) {
1.13 raeburn 1416: my ($checked,$clickaction,$resobj);
1.4 raeburn 1417: if ($currkey eq $resource) {
1418: $checked = ' checked="checked"';
1.13 raeburn 1419: } else {
1420: $resobj = $navmap->getBySymb($resource);
1421: next unless(ref($resobj));
1422: if ($jschg) {
1423: $clickaction = ' onclick="'.$jschg.'"';
1424: }
1.4 raeburn 1425: }
1426: $intervalform .= '<label><input type="radio" name="firstaccess_'.$parmcount.
1427: '" value="'.&HTML::Entities::encode($resource,'"<>&').'"'.
1428: $checked.$clickaction.' />';
1429: if ($currkey eq $resource) {
1.13 raeburn 1430: $intervalform .= $itemname.'</label>'.$iteminfo;
1.4 raeburn 1431: } else {
1.13 raeburn 1432: my ($title,$path,$hierarchy);
1433: if (ref($resobj)) {
1434: $title = $resobj->compTitle();
1435: } else {
1436: $title = &Apache::lonnet::gettitle($resource);
1437: }
1438: $hierarchy = &show_timer_path($type,$resource,$navmap);
1.4 raeburn 1439: if ($hierarchy) {
1440: $path = ' <span style="font-size:90%;">'.
1441: &mt('(in: [_1])',$hierarchy).
1442: '</span>';
1443: }
1444: $intervalform .= &mt('Timer for resource: [_1]','<i>'.$title.'</i>').
1445: '</label>'.
1446: $path;
1447: }
1448: $intervalform .= '<br />';
1449: }
1450: }
1451: }
1452: }
1453: }
1454: } else {
1455: if ($currkey ne '') {
1456: $intervalform = '<input type="radio" name="firstaccess_'.$parmcount.
1457: '" checked="checked" value="'.
1458: &HTML::Entities::encode($currkey,'"<>&').' />'.
1459: $itemname.'<br />';
1460: } else {
1461: $intervalform = &mt('No timed items defined.').' '.
1462: &mt('Use [_1]Settings[_2] to assign a timer, then return here.',
1463: '<a href="/adm/parmset">','</a>');
1464: }
1465: }
1466: return $intervalform;
1467: }
1468:
1469: sub trigger_details_toggle {
1470: my ($parmcount) = @_;
1471: return ' <span id="toggletext_'.$parmcount.'" class="LC_cusr_subheading LC_nobreak">'.
1472: '<a href="javascript:showTriggerDetails('."'$parmcount'".');" '.
1473: 'style="text-decoration: none;"><b>'.&mt('(More ...)').'</b></a></span>';
1474: }
1475:
1476: sub show_timer_path {
1477: my ($type,$item,$navmap) = @_;
1478: return unless(ref($navmap));
1479: my @pathitems;
1480: if ($type eq 'map') {
1.8 raeburn 1481: @pathitems =
1482: &Apache::loncommon::get_folder_hierarchy($navmap,$item);
1.4 raeburn 1483: } elsif ($type eq 'resource') {
1484: my ($map,$id,$resource) = &Apache::lonnet::decode_symb($item);
1.8 raeburn 1485: @pathitems =
1486: &Apache::loncommon::get_folder_hierarchy($navmap,$map,1);
1.4 raeburn 1487: }
1488: if (@pathitems) {
1489: return join(' » ',@pathitems);
1490: }
1.1 raeburn 1491: return;
1492: }
1493:
1494: sub blocktype_text {
1495: my %types = &Apache::lonlocal::texthash(
1496: 'com' => 'Messaging',
1497: 'chat' => 'Chat Room',
1498: 'boards' => 'Discussion',
1499: 'port' => 'Portfolio',
1500: 'groups' => 'Groups',
1501: 'blogs' => 'Blogs',
1.5 raeburn 1502: 'docs' => 'Content',
1503: 'printout' => 'Printouts',
1.1 raeburn 1504: );
1.5 raeburn 1505: my $typeorder = ['com','chat','boards','port','groups','blogs','printout','docs'];
1.1 raeburn 1506: return ($typeorder,\%types);
1507: }
1508:
1.4 raeburn 1509: sub blockingmenu_javascript {
1510: my ($blockcount) = @_;
1511: my %lt = &Apache::lonlocal::texthash (
1512: more => 'More ...',
1513: less => 'Less ...',
1514: );
1515: return <<ENDSCRIPT;
1516: <script type="text/javascript">
1517: // <![CDATA[
1518: function resblockinfo(blockid) {
1519: if (document.getElementById('docs_'+blockid).checked) {
1520: var resblockwin = null;
1521: var url = '/adm/setblock?action=showdocs&block='+blockid;
1522: if (!resblockwin || resblockwin.closed) {
1523: resblockwin=window.open(url,'blockingwin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
1524: }
1525: resblockwin.focus();
1526: } else {
1527: document.getElementById('docs_resources_'+blockid).value = '';
1528: document.getElementById('docs_maps_'+blockid).value = '';
1529: }
1530: return;
1531: }
1532:
1533: function showBlockType() {
1534: if (document.getElementById('toggle_startstop').checked == true) {
1535: document.getElementById('show_startstop').style.display='block';
1536: } else {
1537: document.getElementById('show_startstop').style.display='none';
1538: }
1539: if (document.getElementById('toggle_timer').checked == true) {
1540: document.getElementById('show_timer').style.display='block';
1541: } else {
1542: document.getElementById('show_timer').style.display='none';
1543: }
1544: return;
1545: }
1546:
1547: function toggleAddModify() {
1548: for (var i=0; i<document.blockform.blockaction.length; i++) {
1549: if (document.blockform.blockaction[i].checked) {
1550: if (document.blockform.blockaction[i].value == 'add') {
1551: document.getElementById('showadd').style.display='block';
1552: document.getElementById('showmodify').style.display='none';
1553: var blocktotal = $blockcount;
1554: if (blocktotal > 0) {
1555: for (var i=0; i<blocktotal; i++) {
1556: document.getElementById('nochange_'+i).checked = true;
1557: }
1558: }
1559: document.getElementById('showmodify').style.display='none';
1560: document.getElementById('showadd').style.display='block';
1561: } else {
1562: document.getElementById('showadd').style.display='none';
1563: document.getElementById('showmodify').style.display='block';
1564: }
1565: }
1566: }
1567: return;
1568: }
1569:
1570: function showTriggerDetails(item) {
1571: document.getElementById('trigdetails_'+item).style.display='block';
1572: document.getElementById('trigdetails_'+item).style.textAlign='left';
1573: document.getElementById('trigdetails_'+item).style.textFace='normal';
1574: document.getElementById('toggletext_'+item).innerHTML = '<a href="javascript:hideTriggerDetails('+item+');" style="text-decoration: none;"><b>($lt{'less'})</b></a>';
1575: return;
1576: }
1577:
1578: function hideTriggerDetails(item) {
1579: document.getElementById('trigdetails_'+item).style.display='none';
1580: document.getElementById('toggletext_'+item).innerHTML = '<a href="javascript:showTriggerDetails('+item+');" style="text-decoration: none;"><b>($lt{'more'})</b></a>';
1581: return;
1582: }
1583:
1584: // ]]>
1585: </script>
1586: ENDSCRIPT
1587:
1588: }
1589:
1.1 raeburn 1590: 1;
1591:
1592: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>