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