File:
[LON-CAPA] /
loncom /
interface /
lonblockingmenu.pm
Revision
1.13:
download - view:
text,
annotated -
select for diffs
Thu Jun 12 00:33:41 2014 UTC (10 years, 2 months ago) by
raeburn
Branches:
MAIN
CVS tags:
version_2_11_0,
HEAD
- Check $item retrieved by $navmap->getResourceByUrl() and
$navmap->getBySymb() is an object before calling compTitle() method.
- Skip items with interval parameter set where corresponding map or resource
is a zombie to avoid ISEs in the case where an interval parameter exists
for a (now) deleted map or resource.
1: # The LearningOnline Network with CAPA
2: # Routines for configuring blocking of access to collaborative functions,
3: # and specific resources during an exam
4: #
5: # $Id: lonblockingmenu.pm,v 1.13 2014/06/12 00:33:41 raeburn Exp $
6: #
7: # Copyright Michigan State University Board of Trustees
8: #
9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
10: #
11: # LON-CAPA is free software; you can redistribute it and/or modify
12: # it under the terms of the GNU General Public License as published by
13: # the Free Software Foundation; either version 2 of the License, or
14: # (at your option) any later version.
15: #
16: # LON-CAPA is distributed in the hope that it will be useful,
17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: # GNU General Public License for more details.
20: #
21: # You should have received a copy of the GNU General Public License
22: # along with LON-CAPA; if not, write to the Free Software
23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: #
25: # /home/httpd/html/adm/gpl.txt
26: #
27: # http://www.lon-capa.org/
28: #
29: ##############################################################
30: ##############################################################
31:
32: =pod
33:
34: =head1 NAME
35:
36: lonblockingmenu - Handler to set/modify exam blocks in a course.
37:
38: =head1 SYNOPSIS
39:
40: lonblockingmenu provides an interface for setting exam blocks in a course.
41:
42: =head1 DESCRIPTION
43:
44: This module is used to configure blocking of access to collaborative tools
45: and/or resources during an exam.
46:
47: =head1 OVERVIEW
48:
49: To support high-stakes testing, LON-CAPA provides Coordinators with the
50: ability to disable communication and collaborative features within the
51: system for the duration of an exam.
52:
53: Features which can be disabled include:
54: (a) those which a student could use to communicate with another student.
55: Messaging, discussion, chat, blogs, and some functionality in groups fall
56: into this category.
57: (b) those which a student could use to access materials prepared by the
58: student in advance of an exam, (e.g., for use during an online exam, to
59: gain an unfair advantage). Blogs and portfolio fall into this category.
60: (c) those which a student could use to display or save content within
61: the course itself (outside the exam folder). Printouts and resources
62: fall into this category.
63:
64: For communication blocking to be truly effective in preventing unwanted
65: communication, or access to online materials, online testing needs to
66: take place in a lab setting where use of tools outside LON-CAPA, and use
67: of web sites beyond LON-CAPA are unavailable.
68:
69: Access to specified folder(s) and/or resources in the course contents
70: can be restricted for the duration of an exam.
71:
72: Exam blocks are of two types:
73: (a) Blocks with a defined start and end date.
74: (b) Blocks associated with a timed interval set for a specific folder,
75: or resource.
76:
77: When a student attempts to use a collaboration or communication feature
78: which is currently blocked, information will be available about the
79: duration of the block, and the identity of the Course Coordinator who
80: set the block.
81:
82: Although LON-CAPA communication can be blocked during an exam, course
83: personnel with the 'evb' (evade blocking) privilege will continue to
84: receive LON-CAPA messages sent from students in a course with an active
85: block on messaging. Students will not be able to view messages sent by
86: other students in the same course for the duration of the blocking event.
87:
88: Because students may be enrolled in more than one LON-CAPA course at a time
89: it is important to use reasonable time windows for blocking events, or, in
90: the case of blocks triggered by clicking a button to start a timed quiz,
91: quiz durations that are of limited duration. This is especially important
92: when blocking prtfolio access, as other courses may require students to use
93: the portfolio as a mechanism for submitting assignments.
94:
95: Information about blocks in a course will be cached for 10 minutes, so,
96: as with parameters set for resources, it can take up to 10 minutes for
97: new blocks, or changes to existing blocks, to propagate to other servers.
98:
99: Changes to existing blocks on the server hosting your current session
100: are available immediately, as cached data on blocks is devalidated
101: automatically on the current server whenever a change is made to a
102: block (including deletion), or when a new block is added.
103:
104: =head1 INTERNAL SUBROUTINES
105:
106: =over
107:
108: =item &get_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:
125: =item &blockstore()
126:
127: Stores changes to exam blocks in comm_block.db file for course.
128: Processes deletions, modifications and additions.
129:
130: Inputs: 4
131: $r = request object
132:
133: $crstype - Container type: Course or Community.
134:
135: $blockcount - Total number of blocking events in course.
136:
137: $currblockrecs - Ref to hash of current blocks in course.
138:
139: Outputs: 2
140: $changestotal - Total number of changes made.
141:
142: $output - Information about changes made.
143:
144:
145: =item &get_dates_from_form()
146:
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:
156: =item &get_blockdates()
157:
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:
167: =item &get_block_choices()
168:
169: Extract information from web form about which communication/
170: collaboration features are to be blocked, for a particular event,
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:
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.
197:
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
212:
213: Side Effects: &update_released_required() called in lonnet, if
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.
218:
219:
220: =item &display_blocker_status()
221:
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:
255: =item &display_addblocker_table()
256:
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:
350: =item &blocktype_text()
351:
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:
365: Inputs: 1 - $blockcount - Total number of blocks in course's comm_block.db
366: database file.
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:
384: =back
385:
386: =cut
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();
395: use Apache::lonparmset();
396: use Apache::loncourserespicker();
397: use HTML::Entities();
398: use Apache::lonlocal;
399: use lib '/home/httpd/lib/perl/';
400: use LONCAPA qw(:DEFAULT :match);
401:
402: my $registered_cleanup;
403: my $modified_courses;
404:
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:
425: unless ((&Apache::lonnet::allowed('dcm',$env{'request.course.id'})) ||
426: (&Apache::lonnet::allowed('dcm',$env{'request.course.id'}.
427: '/'.$env{'request.course.sec'}))) {
428: $env{'user.error.msg'}=
429: "/adm/setblock:dcm:0:0:Cannot set blocking of communications in a course";
430: return HTTP_NOT_ACCEPTABLE;
431: }
432:
433: # -----------------------------Get action and calling context from query string
434:
435: $registered_cleanup=0;
436: @{$modified_courses}=();
437:
438: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
439: ['action','caller','block']);
440:
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: }
480:
481: # -------------------------- Store changes and retrieve latest block information
482: my $storeresult;
483: if ($env{'form.action'} eq 'store') {
484: (my $numchanges,$storeresult) = &blockstore($r,$crstype,$blockcount,\%records);
485: if ($numchanges > 0) {
486: $blockcount = &get_blockdates(\%records);
487: }
488: }
489:
490: # ------------------------------------------------------------------ Breadcrumbs
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',
504: text=>'Blocking communication/content access'});
505:
506: my $js = &blockingmenu_javascript($blockcount);
507:
508: $r->print(
509: &Apache::loncommon::start_page('Blocking communication/content access',$js).
510: &Apache::lonhtmlcommon::breadcrumbs('Blocking communication/content access'));
511:
512: my $usertype;
513: if ($crstype eq 'Community') {
514: $usertype = 'members';
515: } else {
516: $usertype = 'students';
517: }
518: my $lctype = lc($crstype);
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.",
523: 'pobl' => "Portfolio blocking can impact a student's ability to complete assignments in courses besides your own. Please use this feature wisely.",
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',
529: );
530:
531: my %ltext = &Apache::lonlocal::texthash(
532: 'type' => 'Type',
533: 'defs' => 'Defined Start/End',
534: 'trig' => 'Triggered by Activating Timer',
535: 'setb' => 'Set by',
536: 'even' => 'Event',
537: 'blck' => 'Blocked?',
538: 'star' => 'Start',
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',
545: );
546:
547: $r->print('<h3>'.$lt{'cbds'}.'</h3>');
548:
549: # ---------------------------------------------------- Get Time Limit parameters
550: my %intervals = &get_timed_items();
551:
552: # -------------------------------------------- Display information about changes
553: if ($env{'form.action'} eq 'store') {
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".
562: '<li>'.&mt("generating printouts of $lctype content").'</li>'.
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: );
567: }
568:
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');
596:
597: # --------------------------------------------- Interface for adding a new block
598: &display_addblocker_table($r,$blockcount,\%ltext,\%intervals,
599: $navmap,$errormsg);
600:
601: # ------------------------------------------------- Interface for existig blocks
602: if ($blockcount > 0) {
603: $r->print('</div>');
604: &display_blocker_status($r,\%records,\%ltext,\%intervals,
605: $navmap,$errormsg,$blockcount);
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:
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:
663: sub blockstore {
664: my ($r,$crstype,$blockcount,$currblockrecs) = @_;
665: my %lt=&Apache::lonlocal::texthash(
666: 'tfcm' => 'The following changes were made',
667: 'ncwm' => 'No changes were made.',
668: 'unna' => 'Unable to retrieve contents of course.',
669: );
670: my %adds = ();
671: my %removals = ();
672: my %cancels = ();
673: my $modtotal = 0;
674: my $canceltotal = 0;
675: my $addtotal = 0;
676: my $changestotal = 0;
677: my $addtimer = 0;
678: my %blocking = ();
679: my (%map_url,%resource_symb,%titles,$output);
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: }
695: }
696: } elsif ($env{'form.blockaction'} eq 'add') {
697: $adds{$blockcount} = 1;
698: }
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: }
705: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%map_url,\%resource_symb,\%titles,'examblock');
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:
715: foreach my $key (keys(%removals)) {
716: my $hashkey = $env{'form.key_'.$key};
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: }
738: }
739: foreach my $key (keys(%adds)) {
740: unless ( defined($cancels{$key}) ) {
741: my ($newkey,$status,$needsrelease);;
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})) {
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: }
766: }
767: }
768: }
769: } else {
770: my ($newstart,$newend) = &get_dates_from_form($key);
771: $newkey = $newstart.'____'.$newend;
772: }
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: }
777: if ($newkey ne '') {
778: my ($blocktypes,$blockdocs) =
779: &get_block_choices($key,\%map_url,\%resource_symb);
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: }
800: $blocking{$newkey} = {
801: setter => $env{'user.name'}.':'.$env{'user.domain'},
802: event => &escape($env{'form.title_'.$key}),
803: blocks => $blocktypes,
804: };
805: if (exists($removals{$key})) {
806: $modtotal ++;
807: } else {
808: $addtotal ++;
809: }
810: } else {
811: if ($env{'form.toggle_'.$key} eq 'timer') {
812: unless ($status eq 'fail') {
813: $output .= '<p class="LC_warning">'.
814: &mt('Invalid trigger for new blocking event').
815: '</p>';
816: }
817: } else {
818: $output .= '<p class="LC_warning">'.
819: &mt('No date range found for new blocking event').
820: '</p>';
821: }
822: }
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: }
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>';
836: if ($canceltotal > 0) {
837: $output .= '<li>'.
838: &mt('[quant,_1,blocking event was,blocking events were] removed.',
839: $canceltotal).
840: '</li>';
841: }
842: if ($modtotal > 0) {
843: $output .= '<li>'.
844: &mt('[quant,_1,blocking event was,blocking events were] modified.',
845: $modtotal).
846: '</li>';
847: }
848: if ($addtotal > 0) {
849: $output .= '<li>'.
850: &mt('[quant,_1,blocking event was,blocking events were] added.',
851: $addtotal).
852: '</li>';
853: }
854: $output .= '</ul>';
855: } else {
856: $output .= $lt{'ncwm'};
857: }
858: $output .= '<br />';
859: return ($changestotal,$output);
860: }
861:
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:
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 {
888: my ($records) = @_;
889: my $blockcount = 0;
890: %{$records} = &Apache::lonnet::dump('comm_block',
891: $env{'course.'.$env{'request.course.id'}.'.domain'},
892: $env{'course.'.$env{'request.course.id'}.'.num'}
893: );
894: $blockcount = keys(%{$records});
895:
896: if ((keys(%{$records}))[0] =~ /^error: 2 /) {
897: $blockcount = 0;
898: }
899: return $blockcount;
900: }
901:
902: sub get_block_choices {
903: my ($item,$map_ref,$symb_ref) = @_;
904: my $blocklist;
905: my $blockdocs;
906: my ($typeorder,$types) = &blocktype_text();
907: foreach my $type (@{$typeorder}) {
908: if ($type eq 'docs') {
909: if ($env{'form.'.$type.'_'.$item}) {
910: $blocklist->{$type} = {};
911: if ($env{'form.docs_resources_'.$item}) {
912: $env{'form.docs_resources_'.$item} =~ s/,$//;
913: if (ref($symb_ref) eq 'HASH') {
914: my %resources = map { $symb_ref->{$_} => 1; }
915: (split(/,/,$env{'form.docs_resources_'.$item}));
916: $blocklist->{$type}->{resources} = \%resources;
917: if (keys(%resources) > 0) {
918: $blockdocs = 1;
919: }
920: }
921: }
922: if ($env{'form.docs_maps_'.$item}) {
923: $env{'form.docs_maps_'.$item} =~ s/,$//;
924: if (ref($map_ref) eq 'HASH') {
925: my %maps = map { $map_ref->{$_} => 1; }
926: (split(/,/,$env{'form.docs_maps_'.$item}));
927: $blocklist->{$type}->{maps} = \%maps;
928: if (keys(%maps) > 0) {
929: $blockdocs = 1;
930: }
931: }
932: }
933: }
934: } else {
935: if ($env{'form.'.$type.'_'.$item}) {
936: $blocklist->{$type} = 'on';
937: } else {
938: $blocklist->{$type} = 'off';
939: }
940: }
941: }
942: return ($blocklist,$blockdocs);
943: }
944:
945: sub check_release_required {
946: my ($value,$chomemajor,$chomeminor) = @_;
947: my $needsrelease = $Apache::lonnet::needsrelease{'course:commblock:'.$value};
948: if ($needsrelease) {
949: my ($needsmajor,$needsminor) = split(/\./,$needsrelease);
950: if (($chomemajor < $needsmajor) ||
951: (($chomemajor == $needsmajor) && ($chomeminor < $needsminor))) {
952: return ('fail',$needsrelease);
953: }
954: my $curr_required =
955: $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};
956: if ($curr_required eq '') {
957: &Apache::lonnet::update_released_required($needsrelease);
958: } else {
959: my ($currmajor,$currminor) = split(/\./,$curr_required);
960: my ($needsmajor,$needsminor) = split(/\./,$needsrelease);
961: if (($currmajor < $needsmajor) ||
962: ($currmajor == $needsmajor && $currminor < $needsminor)) {
963: &Apache::lonnet::update_released_required($needsrelease);
964: }
965: }
966: }
967: return ('ok',$needsrelease);
968: }
969:
970: sub display_blocker_status {
971: my ($r,$records,$ltext,$intervals,$navmap,$errormsg,$blockcount) = @_;
972: my $parmcount = 0;
973: my (%map_url,%resource_symb,%titles,%lookups);
974: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%map_url,\%resource_symb,\%titles,'examblock');
975: %{$lookups{'maps'}} = reverse(%map_url);
976: %{$lookups{'resources'}} = reverse(%resource_symb);
977: my %lt = &Apache::lonlocal::texthash(
978: 'modi' => 'Modify',
979: 'dele' => 'Delete',
980: 'noch' => 'No change',
981: );
982: $r->print('<div id="showmodify" style="display:block">'.
983: &Apache::loncommon::start_data_table());
984: $r->print(<<"END");
985: <tr>
986: <th></th>
987: <th>$ltext->{'type'}</th>
988: <th>$ltext->{'even'}</th>
989: <th>$ltext->{'blck'}</th>
990: </tr>
991: END
992: foreach my $record (sort(keys(%{$records}))) {
993: my $jschg =
994: 'javascript:window.document.forms['. "'blockform'".']'.
995: '.elements['."'action_$parmcount'".'][0].checked=true;';
996: my $onchange = 'onfocus="'.$jschg.'"';
997: my ($setuname,$setudom,$title,$blocks) =
998: &Apache::loncommon::parse_block_record($$records{$record});
999: $title = &HTML::Entities::encode($title,'"<>&');
1000: my $blockid = &HTML::Entities::encode($record,'"<>&');
1001: my $settername =
1002: &Apache::loncommon::aboutmewrapper(
1003: &Apache::loncommon::plainname($setuname,$setudom),
1004: $setuname,$setudom);
1005: $r->print(&Apache::loncommon::start_data_table_row());
1006: $r->print(<<"ACT");
1007:
1008: <td valign="middle"><span class="LC_nobreak"><label>
1009: <input type="radio" name="action_$parmcount" value="modify" />$lt{'modi'}
1010: </label></span><br />
1011: <span class="LC_nobreak"><label>
1012: <input type="radio" name="action_$parmcount" value="cancel" />$lt{'dele'}
1013: </label></span><br />
1014: <span class="LC_nobreak"><label>
1015: <input type="radio" name="action_$parmcount" id="nochange_$parmcount"
1016: value="nochange" checked="checked" />$lt{'noch'}
1017: </label></span>
1018: </td>
1019: ACT
1020: my ($start,$end,$startform,$endform);
1021: if ($record =~ /^(\d+)____(\d+)$/) {
1022: ($start,$end) = split(/____/,$record);
1023: $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.
1024: $parmcount,$start,$onchange);
1025: $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.
1026: $parmcount,$end,$onchange);
1027: $r->print('<td><fieldset><legend>'.$ltext->{'defs'}.'</legend>'.
1028: $ltext->{'star'}.': '.$startform.'<br />'.
1029: $ltext->{'endd'}.': '.$endform.'</fieldset></td>');
1030: } elsif ($record =~ /^firstaccess____(.+)$/) {
1031: my $item = $1;
1032: my ($itemname,$iteminfo,$skipdetails);
1033: my $type = 'map';
1034: my $url;
1035: if ($item eq 'course') {
1036: $type = 'course';
1037: } elsif ($item =~ /___\d+___/) {
1038: $type = 'resource';
1039: (my $map, my $resid, $url) = &Apache::lonnet::decode_symb($item);
1040: } else {
1041: $url = $item;
1042: }
1043: $r->print('<td><fieldset><legend>'.$ltext->{'trig'}.'</legend>');
1044: if ($type eq 'course') {
1045: $itemname = &mt('Timer for all items in course.');
1046: } else {
1047: if (&Apache::lonnet::is_on_map($url)) {
1048: if ($type eq 'map') {
1049: if (ref($navmap)) {
1050: my $title;
1051: my $resobj = $navmap->getResourceByUrl($item);
1052: if (ref($resobj)) {
1053: $title = $resobj->compTitle();
1054: } else {
1055: $title = &Apache::lonnet::gettitle($item);
1056: }
1057: $itemname = &mt('Timer for all items in folder: [_1]',
1058: '<span style="font-style:italic">'.
1059: $title.'</span>');
1060: }
1061: } else {
1062: if (ref($navmap)) {
1063: my $title;
1064: my $resobj = $navmap->getBySymb($item);
1065: if (ref($resobj)) {
1066: $title = $resobj->compTitle();
1067: } else {
1068: $title = &Apache::lonnet::gettitle($item);
1069: }
1070: $itemname = &mt('Timer for resource: [_1]',
1071: '<span style="font-style:italic">'.
1072: $title.'</span>');
1073: }
1074: }
1075: if (ref($navmap)) {
1076: my $path = &show_timer_path($type,$item);
1077: if ($path) {
1078: $iteminfo = ' <span style="font-size:90%;">'.
1079: &mt('(in: [_1])',$path).
1080: '</span>';
1081: }
1082: }
1083: } else {
1084: $skipdetails = 1;
1085: $itemname = '<span style="LC_warning">'.
1086: &mt('Timer folder/resource not in course').
1087: '</span>';
1088: }
1089: }
1090: if ((!$skipdetails) && (ref($intervals) eq 'HASH')) {
1091: if (ref($intervals->{$type}) eq 'HASH') {
1092: $iteminfo .= &trigger_details_toggle($parmcount).
1093: '<ul id="trigdetails_'.$parmcount.'" style="display:none">';
1094: if ($type eq 'course') {
1095: foreach my $scope (keys(%{$intervals->{$type}})) {
1096: if ($scope eq 'all') {
1097: $iteminfo .= '<li>'.&mt('All users -- time limit: [_1]',
1098: &convlim($intervals->{$type}->{$scope})).'</li>';
1099: } elsif ($scope eq 'secgrp') {
1100: if (ref($intervals->{$type}->{$scope}) eq 'HASH') {
1101: $iteminfo .= '<li>'.&mt('Sections/groups').'<ul>';
1102: foreach my $item (sort(keys(%{$intervals->{$type}->{$scope}}))) {
1103: $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',$item,
1104: &convlim($intervals->{$type}->{$scope}->{$item})).
1105: '</li>';
1106: }
1107: $iteminfo .= '</ul></li>';
1108: }
1109: } elsif ($scope eq 'users') {
1110: if (ref($intervals->{$type}->{$scope}) eq 'HASH') {
1111: $iteminfo .= '<li>'.&mt('Users').'<ul>';
1112: foreach my $item (sort(keys(%{$intervals->{$type}->{$scope}}))) {
1113: $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',
1114: &convlim($item,$intervals->{$type}->{$scope}->{$item})).
1115: '</li>';
1116: }
1117: $iteminfo .= '</ul></li>';
1118: }
1119: }
1120: }
1121: } elsif (($type eq 'map') || ($type eq 'resource')) {
1122: if (ref($intervals->{$type}->{$item}) eq 'HASH') {
1123: foreach my $scope (keys(%{$intervals->{$type}->{$item}})) {
1124: if ($scope eq 'all') {
1125: $iteminfo .= '<li>'.&mt('All users -- time limit: [_1]',
1126: &convlim($intervals->{$type}->{$item}->{$scope})).
1127: '</li>';
1128: } elsif ($scope eq 'secgrp') {
1129: if (ref($intervals->{$type}->{$item}->{$scope}) eq 'HASH') {
1130: $iteminfo .= '<li>'.&mt('Sections/groups').'<ul>';
1131: foreach my $sec (sort(keys(%{$intervals->{$type}->{$item}->{$scope}}))) {
1132: $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',$sec,
1133: &convlim($intervals->{$type}->{$item}->{$scope}->{$sec})).
1134: '</li>';
1135: }
1136: $iteminfo .= '</ul></li>';
1137: }
1138: } elsif ($scope eq 'users') {
1139: if (ref($intervals->{$type}->{$item}->{$scope}) eq 'HASH') {
1140: $iteminfo .= '<li>'.&mt('Users').'<ul>';
1141: foreach my $user (sort(keys(%{$intervals->{$type}->{$item}->{$scope}}))) {
1142: $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',$user,
1143: &convlim($intervals->{$type}->{$item}->{$scope}->{$user})).
1144: '</li>';
1145: }
1146: $iteminfo .= '</ul></li>';
1147: }
1148: }
1149: }
1150: }
1151: }
1152: $iteminfo .= '</ul>';
1153: }
1154: }
1155: $r->print(&create_interval_form($intervals,$parmcount,$navmap,$item,$jschg,
1156: $itemname,$iteminfo).'</fieldset></td>');
1157: }
1158: $r->print(<<"END");
1159: <td>
1160: <input type="text" name="title_$parmcount" size="15" value="$title" onfocus="$jschg" />
1161: <input type="hidden" name="key_$parmcount" value="$blockid" />
1162: <br />
1163: <br />
1164: $ltext->{'setb'}: $settername
1165: </td>
1166: END
1167: $r->print('<td>'.&blocker_checkboxes($parmcount,$blocks,$jschg,\%lookups).'</td>'.
1168: &Apache::loncommon::end_data_table_row());
1169: $parmcount++;
1170: }
1171: $r->print(<<"END");
1172: </table>
1173: </div>
1174: END
1175: return;
1176: }
1177:
1178: sub convlim {
1179: my ($timelimit) = @_;
1180: my @order = ('days','hours','minutes','seconds');
1181: my %catlimits = (
1182: days => 86400,
1183: hours => 3600,
1184: minutes => 60,
1185: );
1186: my @toshow;
1187: foreach my $cat (@order) {
1188: if ($cat eq 'seconds') {
1189: if ($timelimit > 0) {
1190: push(@toshow,&mt("[_1] $cat",$timelimit));
1191: }
1192: } elsif ($timelimit >= $catlimits{$cat}) {
1193: my $val = int($timelimit/$catlimits{$cat});
1194: if ($val > 0) {
1195: push(@toshow,&mt("[_1] $cat",$val));
1196: }
1197: $timelimit -= $val*$catlimits{$cat};
1198: }
1199: }
1200: my $output = join(', ',@toshow);
1201: return $output;
1202: }
1203:
1204: sub display_addblocker_table {
1205: my ($r,$parmcount,$ltext,$intervals,$navmap,$errormsg) = @_;
1206: return unless ((ref($ltext) eq 'HASH') && (ref($intervals) eq 'HASH'));
1207: my $start = time;
1208: my $end = $start + (60 * 60 * 2); #Default is an exam of 2 hours duration.
1209: my $onchange = 'onfocus="javascript:window.document.forms['.
1210: "'blockform'].elements['addaction'].".
1211: 'checked=true;"';
1212: my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.
1213: $parmcount,$start,$onchange);
1214: my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.
1215: $parmcount,$end,$onchange);
1216: my %lt = &Apache::lonlocal::texthash(
1217: 'exam' => 'e.g., Exam 1',
1218: );
1219: my $intervalform = &create_interval_form($intervals,$parmcount,$navmap);
1220: if ($intervalform ne '') {
1221: $intervalform = '<fieldset>'.
1222: '<legend>'.$ltext->{'chtr'}.'</legend>'.
1223: $intervalform.
1224: '</fieldset>';
1225: }
1226: $r->print(&Apache::loncommon::start_data_table());
1227: $r->print(<<"END");
1228: <tr>
1229: <th>$ltext->{'type'}</th>
1230: <th>$ltext->{'even'} $lt{'exam'}</th>
1231: <th>$ltext->{'blck'}</th>
1232: </tr>
1233: END
1234: $r->print(&Apache::loncommon::start_data_table_row().'<td>');
1235: $r->print(<<"END");
1236: <span class="LC_nobreak"><label><input type="radio" id="toggle_startstop"
1237: name="toggle_$parmcount" value="startstop" onclick="showBlockType();" checked="checked" />
1238: $ltext->{'defs'}</label></span>
1239: <span class="LC_nobreak"><label><input type="radio" id="toggle_timer" name="toggle_$parmcount"
1240: value="timer" onclick="showBlockType();" />$ltext->{'trig'}</label></span><br />
1241: <div id="show_startstop" style="display:block">
1242: <fieldset><legend>$ltext->{'chda'}</legend>
1243: $ltext->{'star'}: $startform<br />$ltext->{'endd'}: $endform</fieldset>
1244: <span class="LC_warning">$ltext->{'when'}</span></div>
1245: <div id="show_timer" style="display:none">$intervalform</div>
1246: </td>
1247: <td><input type="text" name="title_$parmcount" size="15" value="" /></td>
1248: END
1249: $r->print('<td>'.&blocker_checkboxes($parmcount).'</td>'.
1250: &Apache::loncommon::end_data_table_row().
1251: &Apache::loncommon::end_data_table()."\n".
1252: '<br />');
1253: return;
1254: }
1255:
1256: sub blocker_checkboxes {
1257: my ($parmcount,$blocks,$jschg,$lookups) = @_;
1258: my ($typeorder,$types) = &blocktype_text();
1259: my $numinrow = 2;
1260: my %currdocs;
1261: my $output = '<table>';
1262: for (my $i=0; $i<@{$typeorder}; $i++) {
1263: my $block = $typeorder->[$i];
1264: my ($clickaction,$blockstatus);
1265: if ($jschg) {
1266: $clickaction = $jschg;
1267: }
1268: if ($block eq 'docs') {
1269: if ((ref($blocks) eq 'HASH') && (ref($lookups) eq 'HASH')) {
1270: if (ref($blocks->{$block}) eq 'HASH') {
1271: if (keys(%{$blocks->{$block}}) > 0) {
1272: $blockstatus = 'checked="checked"';
1273: foreach my $key (sort(keys(%{$blocks->{$block}}))) {
1274: if (ref($blocks->{$block}{$key}) eq 'HASH') {
1275: my @current = ();
1276: foreach my $item (keys(%{$blocks->{$block}{$key}})) {
1277: if ($lookups->{$key}{$item}) {
1278: push(@current,$lookups->{$key}{$item});
1279: }
1280: }
1281: if (@current > 0) {
1282: @current=sort { $a <=> $b } (@current);
1283: $currdocs{$key} = join(',',@current);
1284: }
1285: }
1286: }
1287: }
1288: }
1289: }
1290: $clickaction .= 'javascript:resblockinfo('."'$parmcount'".');';
1291: } else {
1292: if (ref($blocks) eq 'HASH') {
1293: if ($blocks->{$block} eq 'on') {
1294: $blockstatus = 'checked="checked"';
1295: }
1296: }
1297: }
1298: my $rem = $i%($numinrow);
1299: if ($rem == 0) {
1300: if ($i > 0) {
1301: $output .= '</tr>';
1302: }
1303: $output .= '<tr>';
1304: }
1305: if ($i == scalar(@{$typeorder})-1) {
1306: my $colsleft = $numinrow-$rem;
1307: if ($colsleft > 1) {
1308: $output .= '<td colspan="'.$colsleft.'">';
1309: } else {
1310: $output .= '<td>';
1311: }
1312: } else {
1313: $output .= '<td>';
1314: }
1315: my $item = $block.'_'.$parmcount;
1316: if ($clickaction) {
1317: $clickaction = ' onclick="'.$clickaction.'"';
1318: }
1319: if ($blockstatus) {
1320: $blockstatus = ' '.$blockstatus;
1321: }
1322: $output .= '<span class="LC_nobreak"><label>'."\n".
1323: '<input type="checkbox" id="'.$item.'" name="'.$item.'"'.
1324: $blockstatus.$clickaction.' value="1" />'.
1325: $types->{$block}.'</label></span>'."\n";
1326: if ($block eq 'docs') {
1327: if ($blockstatus ne '') {
1328: $output .= ' <a href="javascript:resblockinfo('."'$parmcount'".')">'.
1329: &mt('Details').'</a>';
1330: }
1331: }
1332: $output .= '<br /></td>';
1333: }
1334: $output .= '</tr></table>'.
1335: '<input type="hidden" name="docs_maps_'.$parmcount.'"'.
1336: ' id="docs_maps_'.$parmcount.'" value="'.$currdocs{'maps'}.'" />'.
1337: '<input type="hidden" name="docs_resources_'.$parmcount.'"'.
1338: ' id="docs_resources_'.$parmcount.'" value="'.$currdocs{'resources'}.'" />';
1339: return $output;
1340: }
1341:
1342: sub create_interval_form {
1343: my ($intervals,$parmcount,$navmap,$currkey,$jschg,$itemname,$iteminfo) = @_;
1344: return unless ((ref($intervals) eq 'HASH') && (ref($navmap)));
1345: my $intervalform;
1346: if (keys(%{$intervals}) > 0) {
1347: foreach my $type (sort(keys(%{$intervals}))) {
1348: if ($type eq 'course') {
1349: my ($checked,$clickaction);
1350: if ($currkey eq 'course') {
1351: $checked = ' checked="checked"';
1352: } elsif ($jschg) {
1353: $clickaction = ' onclick="'.$jschg.'"';
1354: }
1355: $intervalform .= '<label><input type="radio" name="firstaccess_'.$parmcount.
1356: '" value="course"'.$checked.$clickaction.' />';
1357: if ($currkey eq 'course') {
1358: $intervalform .= $itemname;
1359: } else {
1360: $intervalform .= &mt('Timer for all items in course');
1361: }
1362: $intervalform .= '</label>';
1363: if ($currkey eq 'course') {
1364: $intervalform .= $iteminfo;
1365: }
1366: $intervalform .= '<br />';
1367: } elsif ($type eq 'map') {
1368: if (ref($intervals->{$type}) eq 'HASH') {
1369: if (ref($navmap)) {
1370: foreach my $map (sort(keys(%{$intervals->{$type}}))) {
1371: next if ((!&Apache::lonnet::is_on_map($map)) &&
1372: ($currkey ne $map));
1373: my ($checked,$clickaction);
1374: if ($currkey eq $map) {
1375: $checked = ' checked="checked"';
1376: } elsif ($jschg) {
1377: $clickaction = ' onclick="'.$jschg.'"';
1378: }
1379: $intervalform .= '<label><input type="radio" name="firstaccess_'.$parmcount.
1380: '" value="'.&HTML::Entities::encode($map,'"<>&').'"'.
1381: $checked.$clickaction.' />';
1382: if ($currkey eq $map) {
1383: $intervalform .= $itemname.'</label>'.$iteminfo;
1384: } else {
1385: my ($resobj,$title,$path,$hierarchy);
1386: $resobj = $navmap->getResourceByUrl($map);
1387: if (ref($resobj)) {
1388: $title = $resobj->compTitle();
1389: } else {
1390: $title = &Apache::lonnet::gettitle($map);
1391: }
1392: $hierarchy = &show_timer_path($type,$map,$navmap);
1393: if ($hierarchy) {
1394: $path = ' <span style="font-size:90%;">'.
1395: &mt('(in: [_1])',$hierarchy).
1396: '</span>';
1397: }
1398: $intervalform .= &mt('Timer for all items in folder: [_1]',
1399: '<i>'.$title.'</i>').
1400: '</label>'.$path;
1401: }
1402: $intervalform .= '<br />';
1403: }
1404: }
1405: }
1406: } elsif ($type eq 'resource') {
1407: if (ref($intervals->{$type}) eq 'HASH') {
1408: if (ref($navmap)) {
1409: foreach my $resource (sort(keys(%{$intervals->{$type}}))) {
1410: my ($checked,$clickaction,$resobj);
1411: if ($currkey eq $resource) {
1412: $checked = ' checked="checked"';
1413: } else {
1414: $resobj = $navmap->getBySymb($resource);
1415: next unless(ref($resobj));
1416: if ($jschg) {
1417: $clickaction = ' onclick="'.$jschg.'"';
1418: }
1419: }
1420: $intervalform .= '<label><input type="radio" name="firstaccess_'.$parmcount.
1421: '" value="'.&HTML::Entities::encode($resource,'"<>&').'"'.
1422: $checked.$clickaction.' />';
1423: if ($currkey eq $resource) {
1424: $intervalform .= $itemname.'</label>'.$iteminfo;
1425: } else {
1426: my ($title,$path,$hierarchy);
1427: if (ref($resobj)) {
1428: $title = $resobj->compTitle();
1429: } else {
1430: $title = &Apache::lonnet::gettitle($resource);
1431: }
1432: $hierarchy = &show_timer_path($type,$resource,$navmap);
1433: if ($hierarchy) {
1434: $path = ' <span style="font-size:90%;">'.
1435: &mt('(in: [_1])',$hierarchy).
1436: '</span>';
1437: }
1438: $intervalform .= &mt('Timer for resource: [_1]','<i>'.$title.'</i>').
1439: '</label>'.
1440: $path;
1441: }
1442: $intervalform .= '<br />';
1443: }
1444: }
1445: }
1446: }
1447: }
1448: } else {
1449: if ($currkey ne '') {
1450: $intervalform = '<input type="radio" name="firstaccess_'.$parmcount.
1451: '" checked="checked" value="'.
1452: &HTML::Entities::encode($currkey,'"<>&').' />'.
1453: $itemname.'<br />';
1454: } else {
1455: $intervalform = &mt('No timed items defined.').' '.
1456: &mt('Use [_1]Settings[_2] to assign a timer, then return here.',
1457: '<a href="/adm/parmset">','</a>');
1458: }
1459: }
1460: return $intervalform;
1461: }
1462:
1463: sub trigger_details_toggle {
1464: my ($parmcount) = @_;
1465: return ' <span id="toggletext_'.$parmcount.'" class="LC_cusr_subheading LC_nobreak">'.
1466: '<a href="javascript:showTriggerDetails('."'$parmcount'".');" '.
1467: 'style="text-decoration: none;"><b>'.&mt('(More ...)').'</b></a></span>';
1468: }
1469:
1470: sub show_timer_path {
1471: my ($type,$item,$navmap) = @_;
1472: return unless(ref($navmap));
1473: my @pathitems;
1474: if ($type eq 'map') {
1475: @pathitems =
1476: &Apache::loncommon::get_folder_hierarchy($navmap,$item);
1477: } elsif ($type eq 'resource') {
1478: my ($map,$id,$resource) = &Apache::lonnet::decode_symb($item);
1479: @pathitems =
1480: &Apache::loncommon::get_folder_hierarchy($navmap,$map,1);
1481: }
1482: if (@pathitems) {
1483: return join(' » ',@pathitems);
1484: }
1485: return;
1486: }
1487:
1488: sub blocktype_text {
1489: my %types = &Apache::lonlocal::texthash(
1490: 'com' => 'Messaging',
1491: 'chat' => 'Chat Room',
1492: 'boards' => 'Discussion',
1493: 'port' => 'Portfolio',
1494: 'groups' => 'Groups',
1495: 'blogs' => 'Blogs',
1496: 'docs' => 'Content',
1497: 'printout' => 'Printouts',
1498: );
1499: my $typeorder = ['com','chat','boards','port','groups','blogs','printout','docs'];
1500: return ($typeorder,\%types);
1501: }
1502:
1503: sub blockingmenu_javascript {
1504: my ($blockcount) = @_;
1505: my %lt = &Apache::lonlocal::texthash (
1506: more => 'More ...',
1507: less => 'Less ...',
1508: );
1509: return <<ENDSCRIPT;
1510: <script type="text/javascript">
1511: // <![CDATA[
1512: function resblockinfo(blockid) {
1513: if (document.getElementById('docs_'+blockid).checked) {
1514: var resblockwin = null;
1515: var url = '/adm/setblock?action=showdocs&block='+blockid;
1516: if (!resblockwin || resblockwin.closed) {
1517: resblockwin=window.open(url,'blockingwin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
1518: }
1519: resblockwin.focus();
1520: } else {
1521: document.getElementById('docs_resources_'+blockid).value = '';
1522: document.getElementById('docs_maps_'+blockid).value = '';
1523: }
1524: return;
1525: }
1526:
1527: function showBlockType() {
1528: if (document.getElementById('toggle_startstop').checked == true) {
1529: document.getElementById('show_startstop').style.display='block';
1530: } else {
1531: document.getElementById('show_startstop').style.display='none';
1532: }
1533: if (document.getElementById('toggle_timer').checked == true) {
1534: document.getElementById('show_timer').style.display='block';
1535: } else {
1536: document.getElementById('show_timer').style.display='none';
1537: }
1538: return;
1539: }
1540:
1541: function toggleAddModify() {
1542: for (var i=0; i<document.blockform.blockaction.length; i++) {
1543: if (document.blockform.blockaction[i].checked) {
1544: if (document.blockform.blockaction[i].value == 'add') {
1545: document.getElementById('showadd').style.display='block';
1546: document.getElementById('showmodify').style.display='none';
1547: var blocktotal = $blockcount;
1548: if (blocktotal > 0) {
1549: for (var i=0; i<blocktotal; i++) {
1550: document.getElementById('nochange_'+i).checked = true;
1551: }
1552: }
1553: document.getElementById('showmodify').style.display='none';
1554: document.getElementById('showadd').style.display='block';
1555: } else {
1556: document.getElementById('showadd').style.display='none';
1557: document.getElementById('showmodify').style.display='block';
1558: }
1559: }
1560: }
1561: return;
1562: }
1563:
1564: function showTriggerDetails(item) {
1565: document.getElementById('trigdetails_'+item).style.display='block';
1566: document.getElementById('trigdetails_'+item).style.textAlign='left';
1567: document.getElementById('trigdetails_'+item).style.textFace='normal';
1568: document.getElementById('toggletext_'+item).innerHTML = '<a href="javascript:hideTriggerDetails('+item+');" style="text-decoration: none;"><b>($lt{'less'})</b></a>';
1569: return;
1570: }
1571:
1572: function hideTriggerDetails(item) {
1573: document.getElementById('trigdetails_'+item).style.display='none';
1574: document.getElementById('toggletext_'+item).innerHTML = '<a href="javascript:showTriggerDetails('+item+');" style="text-decoration: none;"><b>($lt{'more'})</b></a>';
1575: return;
1576: }
1577:
1578: // ]]>
1579: </script>
1580: ENDSCRIPT
1581:
1582: }
1583:
1584: 1;
1585:
1586: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>