File:
[LON-CAPA] /
loncom /
interface /
lonblockingmenu.pm
Revision
1.4:
download - view:
text,
annotated -
select for diffs
Sat Mar 31 14:15:24 2012 UTC (12 years, 4 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Bug 6518.
- Exam blocks can also block access to specified folders and/or resources
for the duration of an exam.
- The start time for blocking can be based on activation of the timer for
a specific timed quiz item (map or resource specific). In this case,
the end time for blocking is the start time plus the duration of the
interval.
- Add documentation
1: # The LearningOnline Network with CAPA
2: # Routines for configuring blocking of access to collaborative functions,
3: # and specific resources during an exam
4: #
5: # $Id: lonblockingmenu.pm,v 1.4 2012/03/31 14:15:24 raeburn Exp $
6: #
7: # Copyright Michigan State University Board of Trustees
8: #
9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
10: #
11: # LON-CAPA is free software; you can redistribute it and/or modify
12: # it under the terms of the GNU General Public License as published by
13: # the Free Software Foundation; either version 2 of the License, or
14: # (at your option) any later version.
15: #
16: # LON-CAPA is distributed in the hope that it will be useful,
17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: # GNU General Public License for more details.
20: #
21: # You should have received a copy of the GNU General Public License
22: # along with LON-CAPA; if not, write to the Free Software
23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: #
25: # /home/httpd/html/adm/gpl.txt
26: #
27: # http://www.lon-capa.org/
28: #
29: ##############################################################
30: ##############################################################
31:
32: =pod
33:
34: =head1 NAME
35:
36: lonblockingmenu - Handler to set/modify exam blocks in a course.
37:
38: =head1 SYNOPSIS
39:
40: lonblockingmenu provides an interface for setting exam blocks in a course.
41:
42: =head1 DESCRIPTION
43:
44: This module is used to configure blocking of access to collaborative tools
45: and/or resources during an exam.
46:
47: =head1 OVERVIEW
48:
49: To support high-stakes testing, LON-CAPA provides Coordinators with the
50: ability to disable communication and collaborative features within the
51: system for the duration of an exam.
52:
53: Features which can be disabled include:
54: (a) those which a student could use to communicate with another student.
55: Messaging, discussion, chat, blogs, and some functionality in groups fall
56: into this category.
57: (b) those which a student could use to access materials prepared by the
58: student in advance of an exam, (e.g., for use during an online exam, to
59: gain an unfair advantage). Blogs and portfolio fall into this category.
60:
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:
101: =head1 INTERNAL SUBROUTINES
102:
103: =over
104:
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:
122: =item &blockstore()
123:
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:
159: =item &get_dates_from_form()
160:
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:
170: =item &get_blockdates()
171:
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:
181: =item &get_block_choices()
182:
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:
216: =item &display_blocker_status()
217:
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:
268: =item &display_addblocker_table()
269:
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:
363: =item &blocktype_text()
364:
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:
396: =back
397:
398: =cut
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();
407: use Apache::lonparmset();
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:
433: unless ((&Apache::lonnet::allowed('dcm',$env{'request.course.id'})) ||
434: (&Apache::lonnet::allowed('dcm',$env{'request.course.id'}.
435: '/'.$env{'request.course.sec'}))) {
436: $env{'user.error.msg'}=
437: "/adm/setblock:dcm:0:0:Cannot set blocking of communications in a course";
438: return HTTP_NOT_ACCEPTABLE;
439: }
440:
441: # -----------------------------Get action and calling context from query string
442:
443: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
444: ['action','caller','block']);
445:
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: }
485:
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
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',
509: text=>'Blocking communication/resource access'});
510:
511: my $js = &blockingmenu_javascript($blockcount);
512:
513: $r->print(
514: &Apache::loncommon::start_page('Blocking communication/content access',$js).
515: &Apache::lonhtmlcommon::breadcrumbs('Blocking communication/content access'));
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);
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',
535: );
536:
537: my %ltext = &Apache::lonlocal::texthash(
538: 'type' => 'Type',
539: 'defs' => 'Defined Start/End',
540: 'trig' => 'Triggered by Activating Timer',
541: 'setb' => 'Set by',
542: 'even' => 'Event',
543: 'blck' => 'Blocked?',
544: 'star' => 'Start',
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',
551: );
552:
553: $r->print('<h3>'.$lt{'cbds'}.'</h3>');
554:
555: # ---------------------------------------------------- Get Time Limit parameters
556: my %intervals = &get_timed_items();
557:
558: # -------------------------------------------- Display information about changes
559: if ($env{'form.action'} eq 'store') {
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".
568: '<li>'.&mt("accessing $lctype content in specified folders or resources").'</li>'.
569: '</ul>'.
570: '<p class="LC_warning">'.$lt{'blca'}.'<br />'.$lt{'pobl'}.'</p>'
571: );
572: }
573:
574: # ------------------------ Choose between modifying existing block or adding new
575: $r->print('<form name="blockform" method="post" action="/adm/setblock?action=store">');
576: if ($blockcount > 0) {
577: $r->print(<<"END");
578: <div class="LC_left_float">
579: <fieldset><legend>$lt{'actt'}</legend>
580: <span class="LC_nobreak">
581: <label><input type="radio" name="blockaction" value="modify" id="modifyaction"
582: onclick="toggleAddModify();" checked="checked" />$lt{'mexb'}</label>
583: </span>
584: <br />
585: <span class="LC_nobreak">
586: <label><input type="radio" name="blockaction" value="add" id="addaction"
587: onclick="toggleAddModify();" />$lt{'addn'}</label>
588: </span>
589: </fieldset>
590: </div>
591: <br clear="all" />
592: <div id="showadd" style="display:none">
593: END
594: } else {
595: $r->print($lt{'ncbc'}.'<br /><br />'.
596: '<h4>'.$lt{'addn'}.'</h4>'.
597: '<input type="hidden" name="blockaction" value="add" />');
598: }
599: my ($navmap,$errormsg) =
600: &Apache::loncourserespicker::get_navmap_object($crstype,'examblock');
601:
602: # --------------------------------------------- Interface for adding a new block
603: &display_addblocker_table($r,$blockcount,\%ltext,\%intervals,
604: $navmap,$errormsg);
605:
606: # ------------------------------------------------- Interface for existig blocks
607: if ($blockcount > 0) {
608: $r->print('</div>');
609: &display_blocker_status($r,\%records,\%ltext,\%intervals,
610: $navmap,$errormsg,$blockcount);
611: }
612: $r->print(<<"END");
613: <br />
614: <input type ="submit" value="$lt{'stor'}" />
615: </form>
616: END
617: $r->print(&Apache::loncommon::end_page());
618: return OK;
619: }
620:
621: sub get_timed_items {
622: my ($cdom,$cnum) = @_;
623: my ($cid,%intervals);
624: if ($cdom eq '' || $cnum eq '') {
625: $cid = $env{'request.course.id'};
626: $cdom = $env{'course.'.$cid.'.domain'};
627: $cnum = $env{'course.'.$cid.'.num'};
628: } else {
629: $cid = $cdom.'_'.$cnum;
630: }
631: if ($cid eq '') {
632: return %intervals;
633: }
634: my $resourcedata=&Apache::lonparmset::readdata($cnum,$cdom);
635: if (ref($resourcedata) eq 'HASH') {
636: foreach my $key (keys(%{$resourcedata})) {
637: if ($key =~ /^\Q$cid\E(.+)\.0\.interval$/) {
638: my $middle = $1;
639: if ($middle eq '') {
640: $intervals{'course'}{'all'} = $resourcedata->{$key};
641: } elsif ($middle =~ /^\.\[(\w+)\]$/) {
642: $intervals{'course'}{'secgrp'}{$1} = $resourcedata->{$key};
643: } elsif ($middle =~ /^\.\[useropt\:($match_username\:$match_domain)\]$/) {
644: $intervals{'course'}{'users'}{$1} = $resourcedata->{$key};
645: } elsif ($middle =~ /^\.(.+)\Q___(all)\E$/) {
646: my $inner = $1;
647: if ($inner =~ /^\[(\w+)\]\.([^\]]+)$/) {
648: $intervals{'map'}{$2}{'secgrp'}{$1} = $resourcedata->{$key};
649: } elsif ($inner =~ /^\[useropt\:($match_username\:$match_domain)\]\.([^\]]+)$/) {
650: $intervals{'map'}{$2}{'users'}{$1} = $resourcedata->{$key};
651: } else {
652: $intervals{'map'}{$inner}{'all'} = $resourcedata->{$key};
653: }
654: } elsif ($middle =~ /^\.\[(\w+)\]\.([^\]]+)$/) {
655: $intervals{'resource'}{$2}{'secgrp'}{$1} = $resourcedata->{$key};
656: } elsif ($middle =~ /^\.\[useropt\:($match_username\:$match_domain)\]\.([^\]]+)$/) {
657: $intervals{'resource'}{$2}{'users'}{$1} = $resourcedata->{$key};
658: } else {
659: my ($symb) = ($middle =~ /^\.(.+)$/);
660: $intervals{'resource'}{$symb}{'all'} = $resourcedata->{$key};
661: }
662: }
663: }
664: }
665: return %intervals;
666: }
667:
668: sub blockstore {
669: my ($crstype,$blockcount) = @_;
670: my %lt=&Apache::lonlocal::texthash(
671: 'tfcm' => 'The following changes were made',
672: 'ncwm' => 'No changes were made.',
673: 'unna' => 'Unable to retrieve contents of course.',
674: );
675: my %adds = ();
676: my %removals = ();
677: my %cancels = ();
678: my $modtotal = 0;
679: my $canceltotal = 0;
680: my $addtotal = 0;
681: my $changestotal = 0;
682: my $addtimer = 0;
683: my %blocking = ();
684: my (%map_url,%resource_symb,$output);
685: $output = '<h3>'.$lt{'head'}.'</h3>';
686: if ($env{'form.blockaction'} eq 'modify') {
687: foreach my $envkey (keys(%env)) {
688: if ($envkey =~ m/^form\.action_(\d+)$/) {
689: if ($env{$envkey} eq 'modify') {
690: $adds{$1} = 1;
691: $removals{$1} = 1;
692: } elsif ($env{$envkey} eq 'cancel') {
693: $cancels{$1} = $1;
694: unless ( defined($removals{$1}) ) {
695: $removals{$1} = 1;
696: $canceltotal ++;
697: }
698: }
699: }
700: }
701: } elsif ($env{'form.blockaction'} eq 'add') {
702: $adds{$blockcount} = 1;
703: }
704: my ($navmap,$errormsg) =
705: &Apache::loncourserespicker::get_navmap_object($crstype,'examblock');
706: unless (ref($navmap)) {
707: $output = $lt{'unna'}.' '.$lt{'ncwm'}.'</br>';
708: return ($changestotal,$output);
709: }
710: &enumerate_course_contents($navmap,\%map_url,\%resource_symb);
711: foreach my $key (keys(%removals)) {
712: my $hashkey = $env{'form.key_'.$key};
713: &Apache::lonnet::del('comm_block',["$hashkey"],
714: $env{'course.'.$env{'request.course.id'}.'.domain'},
715: $env{'course.'.$env{'request.course.id'}.'.num'}
716: );
717: }
718: foreach my $key (keys(%adds)) {
719: unless ( defined($cancels{$key}) ) {
720: my $newkey;
721: if ($env{'form.firstaccess_'.$key}) {
722: my $interval =
723: &HTML::Entities::decode($env{'form.firstaccess_'.$key});
724: if ($interval ne '') {
725: if ($interval eq 'course') {
726: $newkey = 'firstaccess____'.$interval;
727: } elsif ($interval =~ /___\d+___/) {
728: my ($map,$resid,$url) =
729: &Apache::lonnet::decode_symb($interval);
730: if (&Apache::lonnet::is_on_map($url)) {
731: $newkey = 'firstaccess____'.$interval;
732: }
733: } elsif (&Apache::lonnet::is_on_map($interval)) {
734: $newkey = 'firstaccess____'.$interval;
735: }
736: if ($newkey ne '') {
737: unless (defined($removals{$key})) {
738: $addtimer ++;
739: }
740: }
741: }
742: } else {
743: my ($newstart,$newend) = &get_dates_from_form($key);
744: $newkey = $newstart.'____'.$newend;
745: }
746: if ($newkey ne '') {
747: my ($blocktypes,$blockdocs) =
748: &get_block_choices($key,\%map_url,\%resource_symb);
749: $blocking{$newkey} = {
750: setter => $env{'user.name'}.':'.$env{'user.domain'},
751: event => &escape($env{'form.title_'.$key}),
752: blocks => $blocktypes,
753: };
754: if ($blockdocs) {
755: &check_release_required('docs');
756: }
757: if (exists($removals{$key})) {
758: $modtotal ++;
759: } else {
760: $addtotal ++;
761: }
762: } else {
763: if ($env{'form.toggle_'.$key} eq 'timer') {
764: $output .= '<p class="LC_warning">'.
765: &mt('Invalid trigger for new blocking event').
766: '</p>';
767: } else {
768: $output .= '<p class="LC_warning">'.
769: &mt('No date range found for new blocking event').
770: '</p>';
771: }
772: }
773: }
774: }
775: if ($addtotal + $modtotal > 0) {
776: &Apache::lonnet::put('comm_block',\%blocking,
777: $env{'course.'.$env{'request.course.id'}.'.domain'},
778: $env{'course.'.$env{'request.course.id'}.'.num'}
779: );
780: if ($addtimer) {
781: &check_release_required('timer');
782: }
783: }
784: $changestotal = $canceltotal + $modtotal + $addtotal;
785: if ($changestotal > 0) {
786: &Apache::lonnet::devalidate_cache_new('comm_block',
787: $env{'request.course.id'});
788: $output .= $lt{'tfcm'}.'<ul>';
789: if ($canceltotal > 0) {
790: $output .= '<li>'.
791: &mt('[quant,_1,blocking event was,blocking events were] removed.',
792: $canceltotal).
793: '</li>';
794: }
795: if ($modtotal > 0) {
796: $output .= '<li>'.
797: &mt('[quant,_1,blocking event was,blocking events were] modified.',
798: $modtotal).
799: '</li>';
800: }
801: if ($addtotal > 0) {
802: $output .= '<li>'.
803: &mt('[quant,_1,blocking event was,blocking events were] added.',
804: $addtotal).
805: '</li>';
806: }
807: $output .= '</ul>';
808: } else {
809: $output .= $lt{'ncwm'};
810: }
811: $output .= '<br />';
812: return ($changestotal,$output);
813: }
814:
815: sub enumerate_course_contents {
816: my ($navmap,$map_url,$resource_symb) = @_;
817: if ((ref($navmap)) && (ref($map_url) eq 'HASH') &&
818: (ref($resource_symb) eq 'HASH')) {
819: my $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
820: my $count = 0;
821: while (my $curRes = $it->next()) {
822: if (ref($curRes)) {
823: $count ++;
824: my $symb = $curRes->symb();
825: my $ressymb = $symb;
826: if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
827: unless ($ressymb =~ m|adm/wrapper/adm|) {
828: $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.
829: '/bulletinboard';
830: }
831: }
832: if (($curRes->is_sequence()) || ($curRes->is_page())) {
833: $map_url->{$count} = (&Apache::lonnet::decode_symb($symb))[2];
834: } else {
835: $resource_symb->{$count} = $ressymb;
836: }
837: }
838: }
839: }
840: return;
841: }
842:
843: sub get_dates_from_form {
844: my $item = shift;
845: my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$item);
846: my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$item);
847: return ($startdate,$enddate);
848: }
849:
850: sub get_blockdates {
851: my ($records) = @_;
852: my $blockcount = 0;
853: %{$records} = &Apache::lonnet::dump('comm_block',
854: $env{'course.'.$env{'request.course.id'}.'.domain'},
855: $env{'course.'.$env{'request.course.id'}.'.num'}
856: );
857: $blockcount = keys(%{$records});
858:
859: if ((keys(%{$records}))[0] =~ /^error: 2 /) {
860: $blockcount = 0;
861: }
862: return $blockcount;
863: }
864:
865: sub get_block_choices {
866: my ($item,$map_ref,$symb_ref) = @_;
867: my $blocklist;
868: my $blockdocs;
869: my ($typeorder,$types) = &blocktype_text();
870: foreach my $type (@{$typeorder}) {
871: if ($type eq 'docs') {
872: if ($env{'form.'.$type.'_'.$item}) {
873: $blocklist->{$type} = {};
874: if ($env{'form.docs_resources_'.$item}) {
875: $env{'form.docs_resources_'.$item} =~ s/,$//;
876: if (ref($symb_ref) eq 'HASH') {
877: my %resources = map { $symb_ref->{$_} => 1; }
878: (split(/,/,$env{'form.docs_resources_'.$item}));
879: $blocklist->{$type}->{resources} = \%resources;
880: if (keys(%resources) > 0) {
881: $blockdocs = 1;
882: }
883: }
884: }
885: if ($env{'form.docs_maps_'.$item}) {
886: $env{'form.docs_maps_'.$item} =~ s/,$//;
887: if (ref($map_ref) eq 'HASH') {
888: my %maps = map { $map_ref->{$_} => 1; }
889: (split(/,/,$env{'form.docs_maps_'.$item}));
890: $blocklist->{$type}->{maps} = \%maps;
891: if (keys(%maps) > 0) {
892: $blockdocs = 1;
893: }
894: }
895: }
896: }
897: } else {
898: if ($env{'form.'.$type.'_'.$item}) {
899: $blocklist->{$type} = 'on';
900: } else {
901: $blocklist->{$type} = 'off';
902: }
903: }
904: }
905: return ($blocklist,$blockdocs);
906: }
907:
908: sub check_release_required {
909: my ($value) = @_;
910: my $needsrelease = $Apache::lonnet::needsrelease{'course:commblock:'.$value};
911: if ($needsrelease) {
912: my $curr_required =
913: $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};
914: if ($curr_required eq '') {
915: &Apache::lonnet::update_released_required($needsrelease);
916: } else {
917: my ($currmajor,$currminor) = split(/\./,$curr_required);
918: my ($needsmajor,$needsminor) = split(/\./,$needsrelease);
919: if (($currmajor < $needsmajor) ||
920: ($currmajor == $needsmajor && $currminor < $needsminor)) {
921: &Apache::lonnet::update_released_required($needsrelease);
922: }
923: }
924: }
925: return;
926: }
927:
928: sub display_blocker_status {
929: my ($r,$records,$ltext,$intervals,$navmap,$errormsg,$blockcount) = @_;
930: my $parmcount = 0;
931: my (%map_url,%resource_symb,%lookups);
932: &enumerate_course_contents($navmap,\%map_url,\%resource_symb);
933: %{$lookups{'maps'}} = reverse(%map_url);
934: %{$lookups{'resources'}} = reverse(%resource_symb);
935: my %lt = &Apache::lonlocal::texthash(
936: 'modi' => 'Modify',
937: 'dele' => 'Delete',
938: 'noch' => 'No change',
939: );
940: $r->print('<div id="showmodify" style="display:block">'.
941: &Apache::loncommon::start_data_table());
942: $r->print(<<"END");
943: <tr>
944: <th></th>
945: <th>$ltext->{'type'}</th>
946: <th>$ltext->{'even'}</th>
947: <th>$ltext->{'blck'}</th>
948: </tr>
949: END
950: foreach my $record (sort(keys(%{$records}))) {
951: my $jschg =
952: 'javascript:window.document.forms['. "'blockform'".']'.
953: '.elements['."'action_$parmcount'".'][0].checked=true;';
954: my $onchange = 'onfocus="'.$jschg.'"';
955: my ($setuname,$setudom,$title,$blocks) =
956: &Apache::loncommon::parse_block_record($$records{$record});
957: $title = &HTML::Entities::encode($title,'"<>&');
958: my $blockid = &HTML::Entities::encode($record,'"<>&');
959: my $settername =
960: &Apache::loncommon::aboutmewrapper(
961: &Apache::loncommon::plainname($setuname,$setudom),
962: $setuname,$setudom);
963: $r->print(&Apache::loncommon::start_data_table_row());
964: $r->print(<<"ACT");
965:
966: <td valign="middle"><span class="LC_nobreak"><label>
967: <input type="radio" name="action_$parmcount" value="modify" />$lt{'modi'}
968: </label></span><br />
969: <span class="LC_nobreak"><label>
970: <input type="radio" name="action_$parmcount" value="cancel" />$lt{'dele'}
971: </label></span><br />
972: <span class="LC_nobreak"><label>
973: <input type="radio" name="action_$parmcount" id="nochange_$parmcount"
974: value="nochange" checked="checked" />$lt{'noch'}
975: </label></span>
976: </td>
977: ACT
978: my ($start,$end,$startform,$endform);
979: if ($record =~ /^(\d+)____(\d+)$/) {
980: ($start,$end) = split(/____/,$record);
981: $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.
982: $parmcount,$start,$onchange);
983: $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.
984: $parmcount,$end,$onchange);
985: $r->print('<td><fieldset><legend>'.$ltext->{'defs'}.'</legend>'.
986: $ltext->{'star'}.': '.$startform.'<br />'.
987: $ltext->{'endd'}.': '.$endform.'</fieldset></td>');
988: } elsif ($record =~ /^firstaccess____(.+)$/) {
989: my $item = $1;
990: my ($itemname,$iteminfo,$skipdetails);
991: my $type = 'map';
992: my $url;
993: if ($item eq 'course') {
994: $type = 'course';
995: } elsif ($item =~ /___\d+___/) {
996: $type = 'resource';
997: (my $map, my $resid, $url) = &Apache::lonnet::decode_symb($item);
998: } else {
999: $url = $item;
1000: }
1001: $r->print('<td><fieldset><legend>'.$ltext->{'trig'}.'</legend>');
1002: if ($type eq 'course') {
1003: $itemname = &mt('Timer for all items in course.');
1004: } else {
1005: if (&Apache::lonnet::is_on_map($url)) {
1006: if ($type eq 'map') {
1007: if (ref($navmap)) {
1008: my $res = $navmap->getResourceByUrl($item);
1009: my $title = $res->compTitle();
1010: $itemname = &mt('Timer for all items in folder: [_1]',
1011: '<span style="font-style:italic">'.
1012: $title.'</span>');
1013: }
1014: } else {
1015: if (ref($navmap)) {
1016: my $res = $navmap->getBySymb($item);
1017: my $title = $res->compTitle();
1018: $itemname = &mt('Timer for resource: [_1]',
1019: '<span style="font-style:italic">'.
1020: $title.'</span>');
1021: }
1022: }
1023: if (ref($navmap)) {
1024: my $path = &show_timer_path($type,$item);
1025: if ($path) {
1026: $iteminfo = ' <span style="font-size:90%;">'.
1027: &mt('(in: [_1])',$path).
1028: '</span>';
1029: }
1030: }
1031: } else {
1032: $skipdetails = 1;
1033: $itemname = '<span style="LC_warning">'.
1034: &mt('Timer folder/resource not in course').
1035: '</span>';
1036: }
1037: }
1038: if ((!$skipdetails) && (ref($intervals) eq 'HASH')) {
1039: if (ref($intervals->{$type}) eq 'HASH') {
1040: $iteminfo .= &trigger_details_toggle($parmcount).
1041: '<ul id="trigdetails_'.$parmcount.'" style="display:none">';
1042: if ($type eq 'course') {
1043: foreach my $scope (keys(%{$intervals->{$type}})) {
1044: if ($scope eq 'all') {
1045: $iteminfo .= '<li>'.&mt('All users -- time limit: [_1]',
1046: &convlim($intervals->{$type}->{$scope})).'</li>';
1047: } elsif ($scope eq 'secgrp') {
1048: if (ref($intervals->{$type}->{$scope}) eq 'HASH') {
1049: $iteminfo .= '<li>'.&mt('Sections/groups').'<ul>';
1050: foreach my $item (sort(keys(%{$intervals->{$type}->{$scope}}))) {
1051: $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',$item,
1052: &convlim($intervals->{$type}->{$scope}->{$item})).
1053: '</li>';
1054: }
1055: $iteminfo .= '</ul></li>';
1056: }
1057: } elsif ($scope eq 'users') {
1058: if (ref($intervals->{$type}->{$scope}) eq 'HASH') {
1059: $iteminfo .= '<li>'.&mt('Users').'<ul>';
1060: foreach my $item (sort(keys(%{$intervals->{$type}->{$scope}}))) {
1061: $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',
1062: &convlim($item,$intervals->{$type}->{$scope}->{$item})).
1063: '</li>';
1064: }
1065: $iteminfo .= '</ul></li>';
1066: }
1067: }
1068: }
1069: } elsif (($type eq 'map') || ($type eq 'resource')) {
1070: if (ref($intervals->{$type}->{$item}) eq 'HASH') {
1071: foreach my $scope (keys(%{$intervals->{$type}->{$item}})) {
1072: if ($scope eq 'all') {
1073: $iteminfo .= '<li>'.&mt('All users -- time limit: [_1]',
1074: &convlim($intervals->{$type}->{$item}->{$scope})).
1075: '</li>';
1076: } elsif ($scope eq 'secgrp') {
1077: if (ref($intervals->{$type}->{$item}->{$scope}) eq 'HASH') {
1078: $iteminfo .= '<li>'.&mt('Sections/groups').'<ul>';
1079: foreach my $sec (sort(keys(%{$intervals->{$type}->{$item}->{$scope}}))) {
1080: $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',$sec,
1081: &convlim($intervals->{$type}->{$item}->{$scope}->{$sec})).
1082: '</li>';
1083: }
1084: $iteminfo .= '</ul></li>';
1085: }
1086: } elsif ($scope eq 'users') {
1087: if (ref($intervals->{$type}->{$item}->{$scope}) eq 'HASH') {
1088: $iteminfo .= '<li>'.&mt('Users').'<ul>';
1089: foreach my $user (sort(keys(%{$intervals->{$type}->{$item}->{$scope}}))) {
1090: $iteminfo .= '<li>'.&mt('[_1] -- time limit: [_2]',$user,
1091: &convlim($intervals->{$type}->{$item}->{$scope}->{$user})).
1092: '</li>';
1093: }
1094: $iteminfo .= '</ul></li>';
1095: }
1096: }
1097: }
1098: }
1099: }
1100: $iteminfo .= '</ul>';
1101: }
1102: }
1103: $r->print(&create_interval_form($intervals,$parmcount,$navmap,$item,$jschg,
1104: $itemname,$iteminfo).'</fieldset></td>');
1105: }
1106: $r->print(<<"END");
1107: <td>
1108: <input type="text" name="title_$parmcount" size="15" value="$title" onfocus="$jschg" />
1109: <input type="hidden" name="key_$parmcount" value="$blockid" />
1110: <br />
1111: <br />
1112: $ltext->{'setb'}: $settername
1113: </td>
1114: END
1115: $r->print('<td>'.&blocker_checkboxes($parmcount,$blocks,$jschg,\%lookups).'</td>'.
1116: &Apache::loncommon::end_data_table_row());
1117: $parmcount++;
1118: }
1119: $r->print(<<"END");
1120: </table>
1121: </div>
1122: END
1123: return;
1124: }
1125:
1126: sub path_to_trigger {
1127: my ($navmap,$map,$type) = @_;
1128: my @pathitems;
1129: if (ref($navmap)) {
1130: my $mapres = $navmap->getResourceByUrl($map);
1131: if (ref($mapres)) {
1132: my $pcslist = $mapres->map_hierarchy();
1133: if ($pcslist ne '') {
1134: my @pcs = split(/,/,$pcslist);
1135: foreach my $pc (@pcs) {
1136: if ($pc == 1) {
1137: push(@pathitems,&mt('Main Course Documents'));
1138: } else {
1139: my $res = $navmap->getByMapPc($pc);
1140: if (ref($res)) {
1141: my $title = $res->compTitle();
1142: $title =~ s/\W+/_/g;
1143: if ($title ne '') {
1144: push(@pathitems,$title);
1145: }
1146: }
1147: }
1148: }
1149: }
1150: }
1151: if ($type eq 'resource') {
1152: if ($mapres->{ID} eq '0.0') {
1153: push(@pathitems,&mt('Main Course Documents'));
1154: } else {
1155: my $maptitle = $mapres->compTitle();
1156: $maptitle =~ s/\W+/_/g;
1157: if ($maptitle ne '') {
1158: push(@pathitems,$maptitle);
1159: }
1160: }
1161: }
1162: }
1163: return @pathitems;
1164: }
1165:
1166: sub convlim {
1167: my ($timelimit) = @_;
1168: my $output;
1169: my @order = ('days','hours','minutes','seconds');
1170: my %catlimits = (
1171: days => 86400,
1172: hours => 3600,
1173: minutes => 60,
1174: );
1175: my @toshow;
1176: foreach my $cat (@order) {
1177: if ($cat eq 'seconds') {
1178: last if ($timelimit <= 0);
1179: } elsif ($timelimit >= $catlimits{$cat}) {
1180: my $val = int($timelimit/$catlimits{$cat});
1181: if ($val > 0) {
1182: push(@toshow,&mt("[_1] $cat",$val));
1183: }
1184: $timelimit =- $val*$catlimits{$cat};
1185: }
1186: }
1187: my $output = join(', ',@toshow);
1188: return $output;
1189: }
1190:
1191: sub display_addblocker_table {
1192: my ($r,$parmcount,$ltext,$intervals,$navmap,$errormsg) = @_;
1193: return unless ((ref($ltext) eq 'HASH') && (ref($intervals) eq 'HASH'));
1194: my $start = time;
1195: my $end = $start + (60 * 60 * 2); #Default is an exam of 2 hours duration.
1196: my $onchange = 'onfocus="javascript:window.document.forms['.
1197: "'blockform'].elements['addaction'].".
1198: 'checked=true;"';
1199: my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.
1200: $parmcount,$start,$onchange);
1201: my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.
1202: $parmcount,$end,$onchange);
1203: my %lt = &Apache::lonlocal::texthash(
1204: 'exam' => 'e.g., Exam 1',
1205: );
1206: my $intervalform = &create_interval_form($intervals,$parmcount,$navmap);
1207: if ($intervalform ne '') {
1208: $intervalform = '<fieldset>'.
1209: '<legend>'.$ltext->{'chtr'}.'</legend>'.
1210: $intervalform.
1211: '</fieldset>';
1212: }
1213: $r->print(&Apache::loncommon::start_data_table());
1214: $r->print(<<"END");
1215: <tr>
1216: <th>$ltext->{'type'}</th>
1217: <th>$ltext->{'even'} $lt{'exam'}</th>
1218: <th>$ltext->{'blck'}</th>
1219: </tr>
1220: END
1221: $r->print(&Apache::loncommon::start_data_table_row().'<td>');
1222: $r->print(<<"END");
1223: <span class="LC_nobreak"><label><input type="radio" id="toggle_startstop"
1224: name="toggle_$parmcount" value="startstop" onclick="showBlockType();" checked="checked" />
1225: $ltext->{'defs'}</label></span>
1226: <span class="LC_nobreak"><label><input type="radio" id="toggle_timer" name="toggle_$parmcount"
1227: value="timer" onclick="showBlockType();" />$ltext->{'trig'}</label></span><br />
1228: <div id="show_startstop" style="display:block">
1229: <fieldset><legend>$ltext->{'chda'}</legend>
1230: $ltext->{'star'}: $startform<br />$ltext->{'endd'}: $endform</fieldset>
1231: <span class="LC_warning">$ltext->{'when'}</span></div>
1232: <div id="show_timer" style="display:none">$intervalform</div>
1233: </td>
1234: <td><input type="text" name="title_$parmcount" size="15" value="" /></td>
1235: END
1236: $r->print('<td>'.&blocker_checkboxes($parmcount).'</td>'.
1237: &Apache::loncommon::end_data_table_row().
1238: &Apache::loncommon::end_data_table()."\n".
1239: '<br />');
1240: return;
1241: }
1242:
1243: sub blocker_checkboxes {
1244: my ($parmcount,$blocks,$jschg,$lookups) = @_;
1245: my ($typeorder,$types) = &blocktype_text();
1246: my $numinrow = 2;
1247: my %currdocs;
1248: my $output = '<table>';
1249: for (my $i=0; $i<@{$typeorder}; $i++) {
1250: my $block = $typeorder->[$i];
1251: my ($clickaction,$blockstatus);
1252: if ($jschg) {
1253: $clickaction = $jschg;
1254: }
1255: if ($block eq 'docs') {
1256: if ((ref($blocks) eq 'HASH') && (ref($lookups) eq 'HASH')) {
1257: if (ref($blocks->{$block}) eq 'HASH') {
1258: if (keys(%{$blocks->{$block}}) > 0) {
1259: $blockstatus = 'checked="checked"';
1260: foreach my $key (sort(keys(%{$blocks->{$block}}))) {
1261: if (ref($blocks->{$block}{$key}) eq 'HASH') {
1262: my @current = ();
1263: foreach my $item (keys(%{$blocks->{$block}{$key}})) {
1264: if ($lookups->{$key}{$item}) {
1265: push(@current,$lookups->{$key}{$item});
1266: }
1267: }
1268: if (@current > 0) {
1269: @current=sort { $a <=> $b } (@current);
1270: $currdocs{$key} = join(',',@current);
1271: }
1272: }
1273: }
1274: }
1275: }
1276: }
1277: $clickaction .= 'javascript:resblockinfo('."'$parmcount'".');';
1278: } else {
1279: if (ref($blocks) eq 'HASH') {
1280: if ($blocks->{$block} eq 'on') {
1281: $blockstatus = 'checked="checked"';
1282: }
1283: }
1284: }
1285: my $rem = $i%($numinrow);
1286: if ($rem == 0) {
1287: if ($i > 0) {
1288: $output .= '</tr>';
1289: }
1290: $output .= '<tr>';
1291: }
1292: if ($i == scalar(@{$typeorder})-1) {
1293: my $colsleft = $numinrow-$rem;
1294: if ($colsleft > 1) {
1295: $output .= '<td colspan="'.$colsleft.'">';
1296: } else {
1297: $output .= '<td>';
1298: }
1299: } else {
1300: $output .= '<td>';
1301: }
1302: my $item = $block.'_'.$parmcount;
1303: if ($clickaction) {
1304: $clickaction = ' onclick="'.$clickaction.'"';
1305: }
1306: if ($blockstatus) {
1307: $blockstatus = ' '.$blockstatus;
1308: }
1309: $output .= '<span class="LC_nobreak"><label>'."\n".
1310: '<input type="checkbox" id="'.$item.'" name="'.$item.'"'.
1311: $blockstatus.$clickaction.' value="1" />'.
1312: $types->{$block}.'</label></span>'."\n";
1313: if ($block eq 'docs') {
1314: if ($blockstatus ne '') {
1315: $output .= ' <a href="javascript:resblockinfo('."'$parmcount'".')">'.
1316: &mt('Details').'</a>';
1317: }
1318: }
1319: $output .= '<br /></td>';
1320: }
1321: $output .= '</tr></table>'.
1322: '<input type="hidden" name="docs_maps_'.$parmcount.'"'.
1323: ' id="docs_maps_'.$parmcount.'" value="'.$currdocs{'maps'}.'" />'.
1324: '<input type="hidden" name="docs_resources_'.$parmcount.'"'.
1325: ' id="docs_resources_'.$parmcount.'" value="'.$currdocs{'resources'}.'" />';
1326: return $output;
1327: }
1328:
1329: sub create_interval_form {
1330: my ($intervals,$parmcount,$navmap,$currkey,$jschg,$itemname,$iteminfo) = @_;
1331: return unless ((ref($intervals) eq 'HASH') && (ref($navmap)));
1332: my $intervalform;
1333: if (keys(%{$intervals}) > 0) {
1334: foreach my $type (sort(keys(%{$intervals}))) {
1335: if ($type eq 'course') {
1336: my ($checked,$clickaction);
1337: if ($currkey eq 'course') {
1338: $checked = ' checked="checked"';
1339: } elsif ($jschg) {
1340: $clickaction = ' onclick="'.$jschg.'"';
1341: }
1342: $intervalform .= '<label><input type="radio" name="firstaccess_'.$parmcount.
1343: '" value="course"'.$checked.$clickaction.' />';
1344: if ($currkey eq 'course') {
1345: $intervalform .= $itemname;
1346: } else {
1347: $intervalform .= &mt('Timer for all items in course');
1348: }
1349: $intervalform .= '</label>';
1350: if ($currkey eq 'course') {
1351: $intervalform .= $iteminfo;
1352: }
1353: $intervalform .= '<br />';
1354: } elsif ($type eq 'map') {
1355: if (ref($intervals->{$type}) eq 'HASH') {
1356: if (ref($navmap)) {
1357: foreach my $map (sort(keys(%{$intervals->{$type}}))) {
1358: my ($checked,$clickaction);
1359: if ($currkey eq $map) {
1360: $checked = ' checked="checked"';
1361: } elsif ($jschg) {
1362: $clickaction = ' onclick="'.$jschg.'"';
1363: }
1364: $intervalform .= '<label><input type="radio" name="firstaccess_'.$parmcount.
1365: '" value="'.&HTML::Entities::encode($map,'"<>&').'"'.
1366: $checked.$clickaction.' />';
1367: if ($currkey eq $map) {
1368: $intervalform .= $itemname.'</label>';
1369: } else {
1370: my $res = $navmap->getResourceByUrl($map);
1371: my $title = $res->compTitle();
1372: my $path;
1373: my $hierarchy = &show_timer_path($type,$map,$navmap);
1374: if ($hierarchy) {
1375: $path = ' <span style="font-size:90%;">'.
1376: &mt('(in: [_1])',$hierarchy).
1377: '</span>';
1378: }
1379: $intervalform .= &mt('Timer for all items in folder: [_1]',
1380: '<i>'.$title.'</i>').
1381: '</label>'.$path;
1382: }
1383: if ($currkey eq $map) {
1384: $intervalform .= $iteminfo;
1385: }
1386: $intervalform .= '<br />';
1387: }
1388: }
1389: }
1390: } elsif ($type eq 'resource') {
1391: if (ref($intervals->{$type}) eq 'HASH') {
1392: if (ref($navmap)) {
1393: foreach my $resource (sort(keys(%{$intervals->{$type}}))) {
1394: my ($checked,$clickaction);
1395: if ($currkey eq $resource) {
1396: $checked = ' checked="checked"';
1397: } elsif ($jschg) {
1398: $clickaction = ' onclick="'.$jschg.'"';
1399: }
1400: $intervalform .= '<label><input type="radio" name="firstaccess_'.$parmcount.
1401: '" value="'.&HTML::Entities::encode($resource,'"<>&').'"'.
1402: $checked.$clickaction.' />';
1403: if ($currkey eq $resource) {
1404: $intervalform .= $itemname.'</label>';
1405: } else {
1406: my $res = $navmap->getBySymb($resource);
1407: my $title = $res->compTitle();
1408: my $path;
1409: my $hierarchy = &show_timer_path($type,$resource,$navmap);
1410: if ($hierarchy) {
1411: $path = ' <span style="font-size:90%;">'.
1412: &mt('(in: [_1])',$hierarchy).
1413: '</span>';
1414: }
1415: $intervalform .= &mt('Timer for resource: [_1]','<i>'.$title.'</i>').
1416: '</label>'.
1417: $path;
1418: }
1419: if ($currkey eq $resource) {
1420: $intervalform .= $iteminfo;
1421: }
1422: $intervalform .= '<br />';
1423: }
1424: }
1425: }
1426: }
1427: }
1428: } else {
1429: if ($currkey ne '') {
1430: $intervalform = '<input type="radio" name="firstaccess_'.$parmcount.
1431: '" checked="checked" value="'.
1432: &HTML::Entities::encode($currkey,'"<>&').' />'.
1433: $itemname.'<br />';
1434: } else {
1435: $intervalform = &mt('No timed items defined.').' '.
1436: &mt('Use [_1]Settings[_2] to assign a timer, then return here.',
1437: '<a href="/adm/parmset">','</a>');
1438: }
1439: }
1440: return $intervalform;
1441: }
1442:
1443: sub trigger_details_toggle {
1444: my ($parmcount) = @_;
1445: return ' <span id="toggletext_'.$parmcount.'" class="LC_cusr_subheading LC_nobreak">'.
1446: '<a href="javascript:showTriggerDetails('."'$parmcount'".');" '.
1447: 'style="text-decoration: none;"><b>'.&mt('(More ...)').'</b></a></span>';
1448: }
1449:
1450: sub show_timer_path {
1451: my ($type,$item,$navmap) = @_;
1452: return unless(ref($navmap));
1453: my @pathitems;
1454: if ($type eq 'map') {
1455: @pathitems = &path_to_trigger($navmap,$item,$type);
1456: } elsif ($type eq 'resource') {
1457: my ($map,$id,$resource) = &Apache::lonnet::decode_symb($item);
1458: @pathitems = &path_to_trigger($navmap,$map,$type);
1459: }
1460: if (@pathitems) {
1461: return join(' » ',@pathitems);
1462: }
1463: return;
1464: }
1465:
1466: sub blocktype_text {
1467: my %types = &Apache::lonlocal::texthash(
1468: 'com' => 'Messaging',
1469: 'chat' => 'Chat Room',
1470: 'boards' => 'Discussion',
1471: 'port' => 'Portfolio',
1472: 'groups' => 'Groups',
1473: 'blogs' => 'Blogs',
1474: 'docs' => 'Content',
1475: );
1476: my $typeorder = ['com','chat','boards','port','groups','blogs','docs'];
1477: return ($typeorder,\%types);
1478: }
1479:
1480: sub blockingmenu_javascript {
1481: my ($blockcount) = @_;
1482: my %lt = &Apache::lonlocal::texthash (
1483: more => 'More ...',
1484: less => 'Less ...',
1485: );
1486: return <<ENDSCRIPT;
1487: <script type="text/javascript">
1488: // <![CDATA[
1489: function resblockinfo(blockid) {
1490: if (document.getElementById('docs_'+blockid).checked) {
1491: var resblockwin = null;
1492: var url = '/adm/setblock?action=showdocs&block='+blockid;
1493: if (!resblockwin || resblockwin.closed) {
1494: resblockwin=window.open(url,'blockingwin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
1495: }
1496: resblockwin.focus();
1497: } else {
1498: document.getElementById('docs_resources_'+blockid).value = '';
1499: document.getElementById('docs_maps_'+blockid).value = '';
1500: }
1501: return;
1502: }
1503:
1504: function showBlockType() {
1505: if (document.getElementById('toggle_startstop').checked == true) {
1506: document.getElementById('show_startstop').style.display='block';
1507: } else {
1508: document.getElementById('show_startstop').style.display='none';
1509: }
1510: if (document.getElementById('toggle_timer').checked == true) {
1511: document.getElementById('show_timer').style.display='block';
1512: } else {
1513: document.getElementById('show_timer').style.display='none';
1514: }
1515: return;
1516: }
1517:
1518: function toggleAddModify() {
1519: for (var i=0; i<document.blockform.blockaction.length; i++) {
1520: if (document.blockform.blockaction[i].checked) {
1521: if (document.blockform.blockaction[i].value == 'add') {
1522: document.getElementById('showadd').style.display='block';
1523: document.getElementById('showmodify').style.display='none';
1524: var blocktotal = $blockcount;
1525: if (blocktotal > 0) {
1526: for (var i=0; i<blocktotal; i++) {
1527: document.getElementById('nochange_'+i).checked = true;
1528: }
1529: }
1530: document.getElementById('showmodify').style.display='none';
1531: document.getElementById('showadd').style.display='block';
1532: } else {
1533: document.getElementById('showadd').style.display='none';
1534: document.getElementById('showmodify').style.display='block';
1535: }
1536: }
1537: }
1538: return;
1539: }
1540:
1541: function showTriggerDetails(item) {
1542: document.getElementById('trigdetails_'+item).style.display='block';
1543: document.getElementById('trigdetails_'+item).style.textAlign='left';
1544: document.getElementById('trigdetails_'+item).style.textFace='normal';
1545: document.getElementById('toggletext_'+item).innerHTML = '<a href="javascript:hideTriggerDetails('+item+');" style="text-decoration: none;"><b>($lt{'less'})</b></a>';
1546: return;
1547: }
1548:
1549: function hideTriggerDetails(item) {
1550: document.getElementById('trigdetails_'+item).style.display='none';
1551: document.getElementById('toggletext_'+item).innerHTML = '<a href="javascript:showTriggerDetails('+item+');" style="text-decoration: none;"><b>($lt{'more'})</b></a>';
1552: return;
1553: }
1554:
1555: // ]]>
1556: </script>
1557: ENDSCRIPT
1558:
1559: }
1560:
1561: 1;
1562:
1563: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>