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