1: # The LearningOnline Network with CAPA
2: # Handler for requesting to have slots added to a students record
3: #
4: # $Id: slotrequest.pm,v 1.125.2.7 2019/06/22 19:18:28 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###
29:
30: package Apache::slotrequest;
31:
32: use strict;
33: use Apache::Constants qw(:common :http :methods);
34: use Apache::loncommon();
35: use Apache::lonlocal;
36: use Apache::lonnet;
37: use Apache::lonnavmaps();
38: use Date::Manip;
39: use lib '/home/httpd/lib/perl/';
40: use LONCAPA qw(:DEFAULT :match);
41:
42: sub fail {
43: my ($r,$code)=@_;
44: if ($code eq 'not_valid') {
45: $r->print('<p>'.&mt('Unable to understand what resource you wanted to sign up for.').'</p>');
46: } elsif ($code eq 'not_available') {
47: $r->print('<p>'.&mt('No slots are available.').'</p>');
48: } elsif ($code eq 'not_allowed') {
49: $r->print('<p>'.&mt('Not allowed to sign up or change reservations at this time.').'</p>');
50: } else {
51: $r->print('<p>'.&mt('Failed.').'</p>');
52: }
53:
54: &return_link($r);
55: &end_page($r);
56: }
57:
58: sub start_page {
59: my ($r,$title,$brcrum,$js)=@_;
60: my $args;
61: if (ref($brcrum) eq 'ARRAY') {
62: $args = {bread_crumbs => $brcrum};
63: }
64: if (($env{'form.requestattempt'}) || ($env{'form.command'} eq 'manageresv')) {
65: my %loaditems = (
66: onload => 'javascript:uncheckSlotRadio();',
67: );
68: if (ref($args) eq 'HASH') {
69: $args->{'add_entries'} = \%loaditems;
70: } else {
71: $args = { 'add_entries' => \%loaditems };
72: }
73: }
74: $r->print(&Apache::loncommon::start_page($title,$js,$args));
75: }
76:
77: sub end_page {
78: my ($r)=@_;
79: $r->print(&Apache::loncommon::end_page());
80: }
81:
82: sub reservation_js {
83: my ($slots,$consumed_uniqueperiods,$available,$got_slots,$symb) = @_;
84: return unless ((ref($slots) eq 'HASH') && (ref($available) eq 'ARRAY'));
85: my $toskip;
86: if ($symb eq '') {
87: $toskip = { symb => 1, };
88: }
89: my ($i,$j) = (0,0);
90: my $js;
91: foreach my $slot (sort
92: { return $slots->{$a}->{'starttime'} <=> $slots->{$b}->{'starttime'} }
93: (keys(%{$slots}))) {
94:
95: next if (!&allowed_slot($slot,$slots->{$slot},$symb,$slots,
96: $consumed_uniqueperiods,$toskip));
97: $js .= " slotstart[$i]='$slots->{$slot}->{'starttime'}';\n".
98: " slotend[$i]='$slots->{$slot}->{'endtime'}';\n".
99: " slotname[$i]='$slot';\n";
100: if (($symb) && (ref($got_slots) eq 'ARRAY')) {
101: if (grep(/^\Q$slot\E$/,@{$got_slots})) {
102: $js .= " currslot[$j]='$slot';\n";
103: $j++;
104: }
105: }
106: $i++;
107: push(@{$available},$slot);
108: }
109: if ($j) {
110: $js = " var currslot = new Array($j);\n\n$js";
111: }
112: my %alerts = &Apache::lonlocal::texthash (
113: none => 'No reservable time slots found',
114: invalid => 'Invalid date format',
115: );
116: return <<"ENDSCRIPT";
117: <script type="text/javascript">
118: // <![CDATA[
119: function updateSlotDisplay(form,num,slotpickradio) {
120: var slotstart = new Array($i);
121: var slotend = new Array($i);
122: var slotname = new Array($i);
123: $js
124:
125: if (slotpickradio == 'all') {
126: for (var i=0; i<$i; i++) {
127: if (document.getElementById('LC_slotrow_'+num+'_'+slotname[i])) {
128: document.getElementById('LC_slotrow_'+num+'_'+slotname[i]).style.display = '';
129: }
130: if (document.getElementById('LC_slotsearch_'+num)) {
131: document.getElementById('LC_slotsearch_'+num).style.display = 'block';
132: }
133: }
134: } else {
135: if (slotpickradio == 'show') {
136: for (var i=0; i<$i; i++) {
137: if (document.getElementById('LC_slotrow_'+num+'_'+slotname[i])) {
138: document.getElementById('LC_slotrow_'+num+'_'+slotname[i]).style.display = 'none';
139: }
140: }
141: for (var j=0; j<$j; j++) {
142: if (document.getElementById('LC_slotrow_'+num+'_'+currslot[j])) {
143: document.getElementById('LC_slotrow_'+num+'_'+currslot[j]).style.display = '';
144: }
145: }
146: if (document.getElementById('LC_slotsearch_'+num)) {
147: document.getElementById('LC_slotsearch_'+num).style.display = 'block';
148: }
149: } else {
150: var numberRegExp = /^[0-9]+\$/;
151: var startm = form.start_month.options[form.start_month.selectedIndex].value;
152: var startd = form.start_day.value;
153: startd=startd.trim();
154: var starty = form.start_year.value;
155: starty=starty.trim();
156: var endm = form.end_month.options[form.end_month.selectedIndex].value;
157: var endd = form.end_day.value;
158: endd=endd.trim();
159: var endy = form.end_year.value;
160: endy=endy.trim();
161: if (numberRegExp.test(endd) && numberRegExp.test(endy) && numberRegExp.test(startd) && numberRegExp.test(starty)) {
162: var startdate = startm+"/"+startd+"/"+starty;
163: var starttime = new Date(startdate).getTime();
164: starttime = starttime/1000;
165: var starth = form.start_hour.options[form.start_hour.selectedIndex].value;
166: if (numberRegExp.test(starth)) {
167: starth = parseInt(starth);
168: if (starth > 0 && starth <= 23) {
169: starttime += 3600 * starth;
170: }
171: }
172: var enddate = endm+"/"+endd+"/"+endy;
173: var endtime = new Date(enddate).getTime();
174: endtime = endtime/1000;
175: var endh = form.end_hour.options[form.end_hour.selectedIndex].value;
176: if (numberRegExp.test(endh)) {
177: endh = parseInt(endh);
178: if (endh > 0 && endh <= 23) {
179: endtime += 3600 * endh;
180: }
181: }
182:
183: var shown = 0;
184: for (var i=0; i<$i; i++) {
185: if ((slotstart[i] >= starttime) && (slotend[i] <= endtime)) {
186: if (document.getElementById('LC_slotrow_'+num+'_'+slotname[i])) {
187: document.getElementById('LC_slotrow_'+num+'_'+slotname[i]).style.display = '';
188: shown ++;
189: }
190: } else {
191: if (document.getElementById('LC_slotrow_'+num+'_'+slotname[i])) {
192: document.getElementById('LC_slotrow_'+num+'_'+slotname[i]).style.display = 'none';
193: }
194: }
195: }
196: if (document.getElementById('LC_slotsearch_'+num)) {
197: if (shown) {
198: document.getElementById('LC_slotsearch_'+num).style.display = 'block';
199: } else {
200: document.getElementById('LC_slotsearch_'+num).style.display = 'none';
201: }
202: }
203: if (shown == 0) {
204: alert('$alerts{"none"}');
205: }
206: } else {
207: alert('$alerts{"invalid"}');
208: }
209: }
210: }
211: return;
212: }
213:
214: function toggleSlotDisplay(form,num) {
215: if (form.slotpick.length) {
216: for (var i=0; i<form.slotpick.length; i++) {
217: if (form.slotpick[i].checked) {
218: var val = form.slotpick[i].value;
219: if (document.getElementById('LC_slotfilter_'+num)) {
220: document.getElementById('LC_slotsearch_'+num).style.display = 'none';
221: if (val == 'filter') {
222: document.getElementById('LC_slotfilter_'+num).style.display = 'block';
223: } else {
224: document.getElementById('LC_slotfilter_'+num).style.display = 'none';
225: if (val == 'all') {
226: updateSlotDisplay(form,num,val);
227: } else {
228: updateSlotDisplay(form,num,val);
229: }
230: }
231: }
232: break;
233: }
234: }
235: }
236: return false;
237: }
238:
239: if (!document.getElementsByClassName) {
240: function getElementsByClassName(node, classname) {
241: var a = [];
242: var re = new RegExp('(^| )'+classname+'( |$)');
243: var els = node.getElementsByTagName("*");
244: for(var i=0,j=els.length; i<j; i++)
245: if(re.test(els[i].className))a.push(els[i]);
246: return a;
247: }
248: }
249:
250: function uncheckSlotRadio() {
251: var slotpicks;
252: if (document.getElementsByClassName) {
253: slotpicks = document.getElementsByClassName('LC_slotpick_radio');
254: } else {
255: slotpicks = getElementsByClassName(document.body,'LC_slotpick_radio');
256: }
257: if (slotpicks.length) {
258: for (var i=0; i<slotpicks.length; i++) {
259: slotpicks[i].checked = false;
260: }
261: }
262: }
263: // ]]>
264: </script>
265: ENDSCRIPT
266:
267: }
268:
269:
270: =pod
271:
272: slot_reservations db
273: - keys are
274: - slotname\0id -> value is an hashref of
275: name -> user@domain of holder
276: timestamp -> timestamp of reservation
277: symb -> symb of resource that it is reserved for
278:
279: =cut
280:
281: sub get_course {
282: (undef,my $courseid)=&Apache::lonnet::whichuser();
283: my $cdom=$env{'course.'.$courseid.'.domain'};
284: my $cnum=$env{'course.'.$courseid.'.num'};
285: return ($cnum,$cdom);
286: }
287:
288: sub get_reservation_ids {
289: my ($slot_name)=@_;
290:
291: my ($cnum,$cdom)=&get_course();
292:
293: my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
294: "^$slot_name\0");
295: if (&Apache::lonnet::error(%consumed)) {
296: return 'error: Unable to determine current status';
297: }
298: my ($tmp)=%consumed;
299: if ($tmp=~/^error: 2 / ) {
300: return 0;
301: }
302: return keys(%consumed);
303: }
304:
305: sub space_available {
306: my ($slot_name,$slot)=@_;
307: my $max=$slot->{'maxspace'};
308:
309: if (!defined($max)) { return 1; }
310:
311: my $consumed=scalar(&get_reservation_ids($slot_name));
312: if ($consumed < $max) {
313: return 1
314: }
315: return 0;
316: }
317:
318: sub check_for_reservation {
319: my ($symb,$mode)=@_;
320: my $student = &Apache::lonnet::EXT("resource.0.availablestudent", $symb,
321: $env{'user.domain'}, $env{'user.name'});
322: my $course = &Apache::lonnet::EXT("resource.0.available", $symb,
323: $env{'user.domain'}, $env{'user.name'});
324: my @slots = (split(/:/,$student), split(/:/, $course));
325:
326: &Apache::lonxml::debug(" slot list is ".join(':',@slots));
327:
328: my ($cnum,$cdom)=&get_course();
329: my %slots=&Apache::lonnet::get('slots', [@slots], $cdom, $cnum);
330:
331: if (&Apache::lonnet::error($student)
332: || &Apache::lonnet::error($course)
333: || &Apache::lonnet::error(%slots)) {
334: return 'error: Unable to determine current status';
335: }
336: my @got;
337: my @sorted_slots = &Apache::loncommon::sorted_slots(\@slots,\%slots,'starttime');
338: foreach my $slot_name (@sorted_slots) {
339: next if (!defined($slots{$slot_name}) ||
340: !ref($slots{$slot_name}));
341: &Apache::lonxml::debug(time." $slot_name ".
342: $slots{$slot_name}->{'starttime'}." -- ".
343: $slots{$slot_name}->{'startreserve'}." -- ".
344: $slots{$slot_name}->{'endreserve'});
345: if (($slots{$slot_name}->{'endtime'} > time) &&
346: ($slots{$slot_name}->{'startreserve'} < time) &&
347: ((!$slots{$slot_name}->{'endreserve'}) ||
348: ($slots{$slot_name}->{'endreserve'} > time))) {
349: # between start of reservation time and end of reservation time
350: # and before end of slot
351: if ($mode eq 'allslots') {
352: push(@got,$slot_name);
353: } else {
354: return($slot_name, $slots{$slot_name});
355: }
356: }
357: }
358: if ($mode eq 'allslots' && @got) {
359: return @got;
360: }
361: return (undef,undef);
362: }
363:
364: sub get_consumed_uniqueperiods {
365: my ($slots) = @_;
366: my $navmap=Apache::lonnavmaps::navmap->new;
367: if (!defined($navmap)) {
368: return 'error: Unable to determine current status';
369: }
370: my @problems = $navmap->retrieveResources(undef,
371: sub { $_[0]->is_problem() },1,0);
372: my %used_slots;
373: foreach my $problem (@problems) {
374: my $symb = $problem->symb();
375: my $student = &Apache::lonnet::EXT("resource.0.availablestudent",
376: $symb, $env{'user.domain'},
377: $env{'user.name'});
378: my $course = &Apache::lonnet::EXT("resource.0.available",
379: $symb, $env{'user.domain'},
380: $env{'user.name'});
381: if (&Apache::lonnet::error($student)
382: || &Apache::lonnet::error($course)) {
383: return 'error: Unable to determine current status';
384: }
385: foreach my $slot (split(/:/,$student), split(/:/, $course)) {
386: $used_slots{$slot}=1;
387: }
388: }
389:
390: if (!ref($slots)) {
391: my ($cnum,$cdom)=&get_course();
392: my %slots=&Apache::lonnet::get('slots', [keys(%used_slots)], $cdom, $cnum);
393: if (&Apache::lonnet::error(%slots)) {
394: return 'error: Unable to determine current status';
395: }
396: $slots = \%slots;
397: }
398:
399: my %consumed_uniqueperiods;
400: foreach my $slot_name (keys(%used_slots)) {
401: next if (!defined($slots->{$slot_name}) ||
402: !ref($slots->{$slot_name}));
403:
404: next if (!defined($slots->{$slot_name}{'uniqueperiod'}) ||
405: !ref($slots->{$slot_name}{'uniqueperiod'}));
406: $consumed_uniqueperiods{$slot_name} =
407: $slots->{$slot_name}{'uniqueperiod'};
408: }
409: return \%consumed_uniqueperiods;
410: }
411:
412: sub check_for_conflict {
413: my ($symb,$new_slot_name,$new_slot,$slots,$consumed_uniqueperiods)=@_;
414:
415: if (!defined($new_slot->{'uniqueperiod'})) { return undef; }
416:
417: if (!ref($consumed_uniqueperiods)) {
418: if ($consumed_uniqueperiods =~ /^error: /) {
419: return $consumed_uniqueperiods;
420: } else {
421: $consumed_uniqueperiods = &get_consumed_uniqueperiods($slots);
422: if (ref($consumed_uniqueperiods) eq 'HASH') {
423: if (&Apache::lonnet::error(%$consumed_uniqueperiods)) {
424: return 'error: Unable to determine current status';
425: }
426: } else {
427: return 'error: Unable to determine current status';
428: }
429: }
430: }
431: my ($new_uniq_start,$new_uniq_end) = @{$new_slot->{'uniqueperiod'}};
432: foreach my $slot_name (keys(%$consumed_uniqueperiods)) {
433: my ($start,$end)=@{$consumed_uniqueperiods->{$slot_name}};
434: if (!
435: ($start < $new_uniq_start && $end < $new_uniq_start) ||
436: ($start > $new_uniq_end && $end > $new_uniq_end )) {
437: return $slot_name;
438: }
439: }
440: return undef;
441: }
442:
443: sub make_reservation {
444: my ($slot_name,$slot,$symb,$cnum,$cdom)=@_;
445:
446: my $value=&Apache::lonnet::EXT("resource.0.availablestudent",$symb,
447: $env{'user.domain'},$env{'user.name'});
448: &Apache::lonxml::debug("value is $value<br />");
449:
450: my $use_slots = &Apache::lonnet::EXT("resource.0.useslots",$symb,
451: $env{'user.domain'},$env{'user.name'});
452: &Apache::lonxml::debug("use_slots is $use_slots<br />");
453:
454: if (&Apache::lonnet::error($value)
455: || &Apache::lonnet::error($use_slots)) {
456: return 'error: Unable to determine current status';
457: }
458:
459: my $parm_symb = $symb;
460: my $parm_level = 1;
461: if ($use_slots eq 'map' || $use_slots eq 'map_map') {
462: my ($map) = &Apache::lonnet::decode_symb($symb);
463: $parm_symb = &Apache::lonnet::symbread($map);
464: $parm_level = 2;
465: }
466:
467: foreach my $other_slot (split(/:/, $value)) {
468: if ($other_slot eq $slot_name) {
469: my %consumed=&Apache::lonnet::dump('slot_reservations', $cdom,
470: $cnum, "^$slot_name\0");
471: if (&Apache::lonnet::error($value)) {
472: return 'error: Unable to determine current status';
473: }
474: my $me=$env{'user.name'}.':'.$env{'user.domain'};
475: foreach my $key (keys(%consumed)) {
476: if ($consumed{$key}->{'name'} eq $me) {
477: my $num=(split('\0',$key))[1];
478: return -$num;
479: }
480: }
481: }
482: }
483:
484: my $max=$slot->{'maxspace'};
485: if (!defined($max)) { $max=99999; }
486:
487: my (@ids)=&get_reservation_ids($slot_name);
488: if (&Apache::lonnet::error(@ids)) {
489: return 'error: Unable to determine current status';
490: }
491: my $last=0;
492: foreach my $id (@ids) {
493: my $num=(split('\0',$id))[1];
494: if ($num > $last) { $last=$num; }
495: }
496:
497: my $wanted=$last+1;
498: &Apache::lonxml::debug("wanted $wanted<br />");
499: if (scalar(@ids) >= $max) {
500: # full up
501: return undef;
502: }
503:
504: my %reservation=('name' => $env{'user.name'}.':'.$env{'user.domain'},
505: 'timestamp' => time,
506: 'symb' => $parm_symb);
507:
508: my $success=&Apache::lonnet::newput('slot_reservations',
509: {"$slot_name\0$wanted" =>
510: \%reservation},
511: $cdom, $cnum);
512:
513: if ($success eq 'ok') {
514: my $new_value=$slot_name;
515: if ($value) {
516: $new_value=$value.':'.$new_value;
517: }
518: &store_slot_parm($symb,$slot_name,$parm_level,$new_value,$cnum,$cdom);
519: return $wanted;
520: }
521:
522: # someone else got it
523: return undef;
524: }
525:
526: sub store_slot_parm {
527: my ($symb,$slot_name,$parm_level,$new_value,$cnum,$cdom) = @_;
528: my $result=&Apache::lonparmset::storeparm_by_symb($symb,
529: '0_availablestudent',
530: $parm_level, $new_value,
531: 'string',
532: $env{'user.name'},
533: $env{'user.domain'});
534: &Apache::lonxml::debug("hrrm $result");
535: my %storehash = (
536: symb => $symb,
537: slot => $slot_name,
538: action => 'reserve',
539: context => $env{'form.context'},
540: );
541:
542: &Apache::lonnet::write_log('course','slotreservationslog',\%storehash,
543: '',$env{'user.name'},$env{'user.domain'},
544: $cnum,$cdom);
545: &Apache::lonnet::write_log('course',$cdom.'_'.$cnum.'_slotlog',\%storehash,
546: 1,$env{'user.name'},$env{'user.domain'},
547: $env{'user.name'},$env{'user.domain'});
548:
549: return;
550: }
551:
552: sub remove_registration {
553: my ($r) = @_;
554: if ($env{'form.entry'} ne 'remove all') {
555: return &remove_registration_user($r);
556: }
557: my $slot_name = $env{'form.slotname'};
558: my %slot=&Apache::lonnet::get_slot($slot_name);
559:
560: my ($cnum,$cdom)=&get_course();
561: my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
562: "^$slot_name\0");
563: if (&Apache::lonnet::error(%consumed)) {
564: $r->print("<p><span class=\"LC_error\">".&mt('A network error has occurred.').'</span></p>');
565: return;
566: }
567: if (!%consumed) {
568: $r->print('<p>'.&mt('Slot [_1] has no reservations.',
569: '<tt>'.$slot_name.'</tt>').'</p>');
570: return;
571: }
572:
573: my @names = map { $consumed{$_}{'name'} } (sort(keys(%consumed)));
574: my $names = join(' ',@names);
575:
576: my $msg = &mt('Remove all of [_1] from slot [_2]?',$names,$slot_name);
577: &remove_registration_confirmation($r,$msg,['entry','slotname','context']);
578: }
579:
580: sub remove_registration_user {
581: my ($r) = @_;
582:
583: my $slot_name = $env{'form.slotname'};
584:
585: my $name = &Apache::loncommon::plainname($env{'form.uname'},
586: $env{'form.udom'});
587:
588: my $title = &Apache::lonnet::gettitle($env{'form.symb'});
589:
590: my $msg = &mt('Remove [_1] from slot [_2] for [_3]',
591: $name,$slot_name,$title);
592:
593: &remove_registration_confirmation($r,$msg,['uname','udom','slotname',
594: 'entry','symb','context']);
595: }
596:
597: sub remove_registration_confirmation {
598: my ($r,$msg,$inputs) =@_;
599:
600: my $hidden_input;
601: foreach my $parm (@{$inputs}) {
602: $hidden_input .=
603: '<input type="hidden" name="'.$parm.'" value="'
604: .&HTML::Entities::encode($env{'form.'.$parm},'"<>&\'').'" />'."\n";
605: }
606: my %lt = &Apache::lonlocal::texthash(
607: 'yes' => 'Yes',
608: 'no' => 'No',
609: );
610: $r->print(<<"END_CONFIRM");
611: <p> $msg </p>
612: <form action="/adm/slotrequest" method="post">
613: <input type="hidden" name="command" value="release" />
614: <input type="hidden" name="button" value="yes" />
615: $hidden_input
616: <input type="submit" value="$lt{'yes'}" />
617: </form>
618: <form action="/adm/slotrequest" method="post">
619: <input type="hidden" name="command" value="showslots" />
620: <input type="submit" value="$lt{'no'}" />
621: </form>
622: END_CONFIRM
623:
624: }
625:
626: sub release_all_slot {
627: my ($r,$mgr)=@_;
628:
629: my $slot_name = $env{'form.slotname'};
630:
631: my ($cnum,$cdom)=&get_course();
632:
633: my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
634: "^$slot_name\0");
635:
636: $r->print('<p>'.&mt('Releasing reservations').'</p>');
637:
638: foreach my $entry (sort { $consumed{$a}{'name'} cmp
639: $consumed{$b}{'name'} } (keys(%consumed))) {
640: my ($uname,$udom) = split(':',$consumed{$entry}{'name'});
641: my ($result,$msg) =
642: &release_reservation($slot_name,$uname,$udom,
643: $consumed{$entry}{'symb'},$mgr);
644: if (!$result) {
645: $r->print('<p><span class="LC_error">'.&mt($msg).'</span></p>');
646: } else {
647: $r->print("<p>$msg</p>");
648: }
649: $r->rflush();
650: }
651: $r->print('<p><a href="/adm/slotrequest?command=showslots">'.
652: &mt('Return to slot list').'</a></p>');
653: &return_link($r);
654: }
655:
656: sub release_slot {
657: my ($r,$symb,$slot_name,$inhibit_return_link,$mgr)=@_;
658:
659: if ($slot_name eq '') { $slot_name=$env{'form.slotname'}; }
660:
661: my ($uname,$udom) = ($env{'user.name'}, $env{'user.domain'});
662: if ($mgr eq 'F'
663: && defined($env{'form.uname'}) && defined($env{'form.udom'})) {
664: ($uname,$udom) = ($env{'form.uname'}, $env{'form.udom'});
665: }
666:
667: if ($mgr eq 'F'
668: && defined($env{'form.symb'})) {
669: $symb = &unescape($env{'form.symb'});
670: }
671:
672: my ($result,$msg) =
673: &release_reservation($slot_name,$uname,$udom,$symb,$mgr);
674: if (!$result) {
675: $r->print('<p><span class="LC_error">'.&mt($msg).'</span></p>');
676: } else {
677: $r->print("<p>$msg</p>");
678: }
679:
680: if ($mgr eq 'F') {
681: $r->print('<p><a href="/adm/slotrequest?command=showslots">'.
682: &mt('Return to slot list').'</a></p>');
683: }
684:
685: if (!$inhibit_return_link) { &return_link($r); }
686: return $result;
687: }
688:
689: sub release_reservation {
690: my ($slot_name,$uname,$udom,$symb,$mgr) = @_;
691: my %slot=&Apache::lonnet::get_slot($slot_name);
692: my $description=&get_description($slot_name,\%slot);
693:
694: if ($mgr ne 'F') {
695: if ($slot{'starttime'} < time) {
696: return (0,&mt('Not allowed to release Reservation: [_1], as it has already ended.',$description));
697: }
698: }
699:
700: # if the reservation symb is for a map get a resource in that map
701: # to check slot parameters on
702: my $navmap=Apache::lonnavmaps::navmap->new;
703: if (!defined($navmap)) {
704: return (0,'error: Unable to determine current status');
705: }
706: my $passed_resource = $navmap->getBySymb($symb);
707: if (ref($passed_resource)) {
708: if ($passed_resource->is_map()) {
709: my ($a_resource) =
710: $navmap->retrieveResources($passed_resource,
711: sub {$_[0]->is_problem()},0,1);
712: $symb = $a_resource->symb();
713: }
714: } else {
715: unless ($mgr eq 'F') {
716: return (0,'error: Unable to determine current status');
717: }
718: }
719:
720: # get parameter string, check for existence, rebuild string with the slot
721: my $student = &Apache::lonnet::EXT("resource.0.availablestudent",
722: $symb,$udom,$uname);
723: my @slots = split(/:/,$student);
724:
725: my @new_slots;
726: foreach my $exist_slot (@slots) {
727: if ($exist_slot eq $slot_name) { next; }
728: push(@new_slots,$exist_slot);
729: }
730: my $new_param = join(':',@new_slots);
731:
732: # Get value of useslots parameter in effect for this user.
733: # If value is map or map_map, then the parm level is 2 (i.e.,
734: # non-recursive enclosing map/folder level for specific user)
735: # and the symb for this reservation in slot_reservations.db
736: # will be the symb of the map itself.
737:
738: my $use_slots = &Apache::lonnet::EXT("resource.0.useslots",
739: $symb,$udom,$uname);
740: &Apache::lonxml::debug("use_slots is $use_slots<br />");
741:
742: if (&Apache::lonnet::error($use_slots)) {
743: return (0,'error: Unable to determine current status');
744: }
745:
746: my $parm_level = 1;
747: my $parm_symb = $passed_resource->symb();
748: if ($use_slots eq 'map' || $use_slots eq 'map_map') {
749: $parm_level = 2;
750: unless ($passed_resource->is_map()) {
751: my ($map) = &Apache::lonnet::decode_symb($parm_symb);
752: $parm_symb = &Apache::lonnet::symbread($map);
753: }
754: }
755:
756: my ($cnum,$cdom)=&get_course();
757:
758: # get slot reservations, check if user has one for the
759: # correct symb, and if so, remove the reservation
760: my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
761: "^$slot_name\0");
762: foreach my $entry (keys(%consumed)) {
763: if (($consumed{$entry}->{'name'} eq $uname.':'.$udom) &&
764: ($consumed{$entry}->{'symb'} eq $parm_symb)) {
765: &Apache::lonnet::del('slot_reservations',[$entry],
766: $cdom,$cnum);
767: my %storehash = (
768: symb => $symb,
769: slot => $slot_name,
770: action => 'release',
771: context => $env{'form.context'},
772: );
773: &Apache::lonnet::write_log('course','slotreservationslog',
774: \%storehash,1,$uname,$udom,$cnum,$cdom);
775: &Apache::lonnet::write_log('course',$cdom.'_'.$cnum.'_slotlog',
776: \%storehash,1,$uname,$udom,$uname,$udom);
777: }
778: }
779:
780: # store new parameter string
781: my $result=&Apache::lonparmset::storeparm_by_symb($symb,
782: '0_availablestudent',
783: $parm_level, $new_param,
784: 'string', $uname, $udom);
785: my $msg;
786: if ($mgr eq 'F') {
787: $msg = &mt('Released Reservation for user: [_1]',"$uname:$udom");
788: } else {
789: $msg = '<span style="font-weight: bold;">'.&mt('Released reservation: [_1]',$description).'</span><br /><br />';
790: my $person = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
791: my $subject = &mt('Reservation change: [_1]',$description);
792: my $msgbody = &mt('Reservation released by [_1] for [_2].',$person,$description);
793: $msg .= &slot_change_messaging($slot{'reservationmsg'},$subject,$msgbody,'release');
794: }
795: return (1,$msg);
796: }
797:
798: sub delete_slot {
799: my ($r)=@_;
800:
801: my $slot_name = $env{'form.slotname'};
802: my %slot=&Apache::lonnet::get_slot($slot_name);
803:
804: my ($cnum,$cdom)=&get_course();
805: my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
806: "^$slot_name\0");
807: my ($tmp) = %consumed;
808: if ($tmp =~ /error: 2/) { undef(%consumed); }
809:
810: if (%slot && !%consumed) {
811: $slot{'type'} = 'deleted';
812: my $ret = &Apache::lonnet::cput('slots', {$slot_name => \%slot},
813: $cdom, $cnum);
814: if ($ret eq 'ok') {
815: $r->print('<p>'.&mt('Slot [_1] marked as deleted.','<tt>'.$slot_name.'</tt>').'</p>');
816: } else {
817: $r->print('<p><span class="LC_error">'.&mt('An error occurred when attempting to delete slot: [_1]','<tt>'.$slot_name.'</tt>')." ($ret)</span></p>");
818: }
819: } else {
820: if (%consumed) {
821: $r->print('<p>'.&mt('Slot [_1] has active reservations.','<tt>'.$slot_name.'</tt>').'</p>');
822: } else {
823: $r->print('<p>'.&mt('Slot [_1] does not exist.','<tt>'.$slot_name.'</tt>').'</p>');
824: }
825: }
826: $r->print('<p><a href="/adm/slotrequest?command=showslots">'.
827: &mt('Return to slot list').'</a></p>');
828: &return_link($r);
829: }
830:
831: sub return_link {
832: my ($r) = @_;
833: if (($env{'form.command'} eq 'manageresv') || ($env{'form.context'} eq 'usermanage')) {
834: $r->print('<p><a href="/adm/slotrequest?command=manageresv">'.
835: &mt('Return to reservations'));
836: } else {
837: $r->print('<p><a href="/adm/flip?postdata=return:">'.
838: &mt('Return to last resource').'</a></p>');
839: }
840: }
841:
842: sub get_slot {
843: my ($r,$symb,$conflictable_slot,$inhibit_return_link)=@_;
844:
845: my %slot=&Apache::lonnet::get_slot($env{'form.slotname'});
846: my $slot_name=&check_for_conflict($symb,$env{'form.slotname'},\%slot);
847:
848: if ($slot_name =~ /^error: (.*)/) {
849: $r->print('<p><span class="LC_error">'
850: .&mt('An error occurred while attempting to make a reservation. ([_1])',$1)
851: .'</span></p>');
852: &return_link($r);
853: return 0;
854: }
855: if ($slot_name && $slot_name ne $conflictable_slot) {
856: my %slot=&Apache::lonnet::get_slot($slot_name);
857: my $description1=&get_description($slot_name,\%slot);
858: my $slottype1=$slot{'type'};
859: %slot=&Apache::lonnet::get_slot($env{'form.slotname'});
860: my $description2=&get_description($env{'form.slotname'},\%slot);
861: if ($slottype1 eq 'preassigned') {
862: $r->print('<p>'.&mt('You already have a reservation: "[_1]", assigned by your instructor.',
863: $description1).'</p>'.
864: '<p>'.&mt('Your instructor must unassign it before you can make a new reservation.').
865: '</p>');
866: } elsif ($slot_name ne $env{'form.slotname'}) {
867: $r->print(<<STUFF);
868: <form method="post" action="/adm/slotrequest">
869: <input type="hidden" name="symb" value="$env{'form.symb'}" />
870: <input type="hidden" name="slotname" value="$env{'form.slotname'}" />
871: <input type="hidden" name="releaseslot" value="$slot_name" />
872: <input type="hidden" name="command" value="change" />
873: STUFF
874: $r->print('<p class="LC_error">'.&mt('Reservation currently unchanged').'</p>');
875: if ($slot_name ne '') {
876: $r->print('<p>'.&mt('To complete the transaction you [_1]must confirm[_2] you want to [_3]process the change[_4] to [_5].'
877: ,'<b>','</b>','<i>','</i>','<b>'.$description2.'</b>')
878: .'<br />'
879: .&mt('Or you can choose to [_1]make no change[_2] and continue[_2] with the reservation you already had: [_3].'
880: ,'<i>','</i>','<b>'.$description1.'</b>')
881: .'</p><p><span class="LC_nobreak">'
882: .'<input type="submit" name="change" value="'.&mt('Process the change').'" />'
883: .(' 'x3)
884: .'<input type="submit" name="nochange" value="'.&mt('Make no change').'" />'
885: .'</span></p>');
886: }
887: $r->print(<<STUFF);
888: </form>
889: STUFF
890: } else {
891: $r->print('<p>'.&mt('Already have a reservation: [_1].',$description1).'</p>');
892: &return_link($r);
893: }
894: return 0;
895: }
896:
897: my ($cnum,$cdom)=&get_course();
898: my $reserved=&make_reservation($env{'form.slotname'},
899: \%slot,$symb,$cnum,$cdom);
900: my $description=&get_description($env{'form.slotname'},\%slot);
901: if (defined($reserved)) {
902: my $retvalue = 0;
903: if ($slot_name =~ /^error: (.*)/) {
904: $r->print('<p><span class="LC_error">'
905: .&mt('An error occurred while attempting to make a reservation. ([_1])',$1)
906: .'</span></p>');
907: } elsif ($reserved > -1) {
908: $r->print('<p style="font-weight: bold;">'.&mt('Successfully signed up: [_1]',$description).'</p>');
909: $retvalue = 1;
910: my $person = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
911: my $subject = &mt('Reservation change: [_1]',$description);
912: my $msgbody = &mt('Successful reservation by [_1] for [_2].',$person,$description);
913: my $msg = &slot_change_messaging($slot{'reservationmsg'},$subject,$msgbody,'reserve');
914: if ($msg) {
915: $r->print($msg);
916: }
917: } elsif ($reserved < 0) {
918: $r->print('<p>'.&mt('Already reserved: [_1]',$description).'</p>');
919: }
920: if (!$inhibit_return_link) { &return_link($r); }
921: return 1;
922: }
923:
924: my %lt = &Apache::lonlocal::texthash(
925: 'request' => 'Availability list',
926: 'try' => 'Try again?',
927: 'or' => 'or',
928: );
929:
930: my $extra_input;
931: if ($conflictable_slot) {
932: $extra_input='<input type="hidden" name="releaseslot" value="'.$env{'form.slotname'}.'" />';
933: }
934:
935: $r->print('<p>'.&mt('[_1]Failed[_2] to reserve a slot for [_3].','<span class="LC_warning">','</span>',$description).'</p>');
936: $r->print(<<STUFF);
937: <p>
938: <form method="post" action="/adm/slotrequest">
939: <input type="submit" name="Try Again" value="$lt{'try'}" />
940: <input type="hidden" name="symb" value="$env{'form.symb'}" />
941: <input type="hidden" name="slotname" value="$env{'form.slotname'}" />
942: <input type="hidden" name="command" value="$env{'form.command'}" />
943: $extra_input
944: </form>
945: </p>
946: <p>
947: $lt{'or'}
948: <form method="post" action="/adm/slotrequest">
949: <input type="hidden" name="symb" value="$env{'form.symb'}" />
950: <input type="submit" name="requestattempt" value="$lt{'request'}" />
951: </form>
952: STUFF
953:
954: if (!$inhibit_return_link) {
955: $r->print(&mt('or').'</p>');
956: &return_link($r);
957: } else {
958: $r->print('</p>');
959: }
960: return 0;
961: }
962:
963: sub allowed_slot {
964: my ($slot_name,$slot,$symb,$slots,$consumed_uniqueperiods,$toskip)=@_;
965:
966: #already started
967: if ($slot->{'starttime'} < time) {
968: return 0;
969: }
970: &Apache::lonxml::debug("$slot_name starttime good");
971:
972: #already ended
973: if ($slot->{'endtime'} < time) {
974: return 0;
975: }
976: &Apache::lonxml::debug("$slot_name endtime good");
977:
978: # not allowed to pick this one
979: if (defined($slot->{'type'})
980: && $slot->{'type'} ne 'schedulable_student') {
981: return 0;
982: }
983: &Apache::lonxml::debug("$slot_name type good");
984:
985: # reserve time not yet started
986: if ($slot->{'startreserve'} > time) {
987: return 0;
988: }
989: # reserve time ended
990: if (($slot->{'endreserve'}) &&
991: ($slot->{'endreserve'} < time)) {
992: return 0;
993: }
994: &Apache::lonxml::debug("$slot_name reserve good");
995:
996: my $userallowed=0;
997: # its for a different set of users
998: if (defined($slot->{'allowedsections'})) {
999: if (!defined($env{'request.role.sec'})
1000: && grep(/^No section assigned$/,
1001: split(',',$slot->{'allowedsections'}))) {
1002: $userallowed=1;
1003: }
1004: if (defined($env{'request.role.sec'})
1005: && grep(/^\Q$env{'request.role.sec'}\E$/,
1006: split(',',$slot->{'allowedsections'}))) {
1007: $userallowed=1;
1008: }
1009: if (defined($env{'request.course.groups'})) {
1010: my @groups = split(/:/,$env{'request.course.groups'});
1011: my @allowed_sec = split(',',$slot->{'allowedsections'});
1012: foreach my $group (@groups) {
1013: if (grep {$_ eq $group} (@allowed_sec)) {
1014: $userallowed=1;
1015: last;
1016: }
1017: }
1018: }
1019: }
1020: &Apache::lonxml::debug("$slot_name sections is $userallowed");
1021:
1022: # its for a different set of users
1023: if (defined($slot->{'allowedusers'})
1024: && grep(/^\Q$env{'user.name'}:$env{'user.domain'}\E$/,
1025: split(',',$slot->{'allowedusers'}))) {
1026: $userallowed=1;
1027: }
1028:
1029: if (!defined($slot->{'allowedusers'})
1030: && !defined($slot->{'allowedsections'})) {
1031: $userallowed=1;
1032: }
1033:
1034: &Apache::lonxml::debug("$slot_name user is $userallowed");
1035: return 0 if (!$userallowed);
1036:
1037: # not allowed for this resource
1038: if (defined($slot->{'symb'})
1039: && $slot->{'symb'} ne $symb) {
1040: unless ((ref($toskip) eq 'HASH') && ($toskip->{'symb'})) {
1041: return 0;
1042: }
1043: }
1044:
1045: my $conflict = &check_for_conflict($symb,$slot_name,$slot,$slots,
1046: $consumed_uniqueperiods);
1047: if ($conflict =~ /^error: /) {
1048: return 0;
1049: } elsif ($conflict ne '') {
1050: if ($slots->{$conflict}{'starttime'} < time) {
1051: return 0;
1052: }
1053: }
1054: &Apache::lonxml::debug("$slot_name symb good");
1055: return 1;
1056: }
1057:
1058: sub get_description {
1059: my ($slot_name,$slot)=@_;
1060: my $description=$slot->{'description'};
1061: if (!defined($description)) {
1062: $description=&mt('[_1] From [_2] to [_3]',$slot_name,
1063: &Apache::lonlocal::locallocaltime($slot->{'starttime'}),
1064: &Apache::lonlocal::locallocaltime($slot->{'endtime'}));
1065: }
1066: return $description;
1067: }
1068:
1069: sub show_choices {
1070: my ($r,$symb,$formname,$num,$slots,$consumed_uniqueperiods,$available,$got_slots)=@_;
1071: my $output;
1072: &Apache::lonxml::debug("Checking Slots");
1073: if (!ref($available) eq 'ARRAY') {
1074: return;
1075: }
1076: if (!@{$available}) {
1077: $output = '<span class="LC_info">'.&mt('No available times.').'</span>';
1078: if ($env{'form.command'} ne 'manageresv') {
1079: $output .= ' <a href="/adm/flip?postdata=return:">'.
1080: &mt('Return to last resource').'</a>';
1081: }
1082: $r->print($output);
1083: return;
1084: }
1085: if (@{$available} > 1) {
1086: my $numavailable = scalar(@{$available});
1087: my $numreserved = 0;
1088: my $js;
1089: my $j = 0;
1090: foreach my $got (@{$got_slots}) {
1091: unless (($got eq '') || (!defined($got))) {
1092: $numreserved ++;
1093: if ($env{'form.command'} eq 'manageresv') {
1094: $js .= " currslot[$j]='$got';\n";
1095: $j++;
1096: }
1097: }
1098: }
1099: my $showfilter = 'none';
1100: $output .= '<fieldset><legend>'.&mt('Actions').'</legend>'."\n".
1101: '<form method="post" name="reservationdisplay_'.$num.
1102: '" action="" onsubmit="toggleSlotDisplay(this.form,'."'$num'".');">';
1103: my @options = ('all','filter');
1104: if ($numreserved) {
1105: unshift(@options,'show');
1106: }
1107: my %resmenu = &Apache::lonlocal::texthash (
1108: show => 'Show current reservation',
1109: all => 'Show all',
1110: filter => 'Search by date',
1111: );
1112: foreach my $option (@options) {
1113: my $onclick = "toggleSlotDisplay(this.form,'$num');";
1114: if (($option eq 'show') && ($env{'form.command'} eq 'manageresv')) {
1115: $onclick .= "currSlotDisplay$num(this.form,'$num');";
1116: }
1117: $output .= '<span class="LC_nobreak"><label>'.
1118: '<input type="radio" class="LC_slotpick_radio" name="slotpick" value="'.
1119: $option.'" onclick="'.$onclick.'" />'.
1120: $resmenu{$option}.
1121: '</label></span>'.(' ' x3)."\n";
1122: }
1123: $output .= '</form>';
1124: my $chooserform = 'reservationchooser_'.$num;
1125: my $starttime = $slots->{$available->[0]}->{'starttime'};
1126: my $endtime = $slots->{$available->[-1]}->{'starttime'};
1127: if ($env{'form.command'} eq 'manageresv') {
1128: $output .= <<"ENDSCRIPT";
1129:
1130: <script type="text/javascript">
1131: // <![CDATA[
1132: function currSlotDisplay$num() {
1133: var currslot = new Array($numreserved);
1134: $js
1135: for (var j=0; j<$numreserved; j++) {
1136: if (document.getElementById('LC_slotrow_$num\_'+currslot[j])) {
1137: document.getElementById('LC_slotrow_$num\_'+currslot[j]).style.display = '';
1138: }
1139: }
1140: }
1141: // ]]>
1142: </script>
1143:
1144: ENDSCRIPT
1145: }
1146: $output .=
1147: '<div id="LC_slotfilter_'.$num.'" style="display:'.$showfilter.'">'.
1148: '<form method="post" name="'.$chooserform.'" action="">'.
1149: '<table><tr><td>'.&mt('Open after').'</td><td>'.
1150: &Apache::lonhtmlcommon::date_setter($chooserform,'start',$starttime,'','','','','','','',1,1).
1151: '</td></tr><tr><td>'.&mt('Closed before').'</td><td>'.
1152: &Apache::lonhtmlcommon::date_setter($chooserform,'end',$endtime,'','','','','','','',1,1).
1153: '</td></tr></table><br />'.
1154: '<input type="button" name="slotfilter" value="Search for reservable slots" onclick="updateSlotDisplay(this.form,'."'$num'".');" />'.
1155: '</form></div><div id="LC_slotsearch_'.$num.'" style="display:none"><hr />';
1156: }
1157: if ($env{'form.command'} eq 'manageresv') {
1158: $output .= '<table border="0">';
1159: } else {
1160: $output .= &Apache::loncommon::start_data_table();
1161: }
1162: foreach my $slot (@{$available}) {
1163: my $description=&get_description($slot,$slots->{$slot});
1164: my $form;
1165: if ((grep(/^\Q$slot\E$/,@{$got_slots})) ||
1166: &space_available($slot,$slots->{$slot},$symb)) {
1167: my $text=&mt('Select');
1168: my $command='get';
1169: if (grep(/^\Q$slot\E$/,@{$got_slots})) {
1170: $text=&mt('Drop Reservation');
1171: $command='release';
1172: } else {
1173: my $conflict = &check_for_conflict($symb,$slot,$slots->{$slot},
1174: $slots,$consumed_uniqueperiods);
1175: if ($conflict) {
1176: if ($conflict =~ /^error: /) {
1177: $form = '<span class="LC_error">'.
1178: &mt('Slot: [_1] has unknown status.',$description).
1179: '</span>';
1180: } else {
1181: $text=&mt('Change Reservation');
1182: $command='get';
1183: }
1184: }
1185: }
1186: my $escsymb=&escape($symb);
1187: if (!$form) {
1188: my $name;
1189: if ($formname) {
1190: $name = 'name="'.$formname.'"';
1191: }
1192: my $context = 'user';
1193: if ($env{'form.command'} eq 'manageresv') {
1194: $context = 'usermanage';
1195: }
1196: $form=<<STUFF;
1197: <form method="post" action="/adm/slotrequest" $name>
1198: <input type="submit" name="Select" value="$text" />
1199: <input type="hidden" name="symb" value="$escsymb" />
1200: <input type="hidden" name="slotname" value="$slot" />
1201: <input type="hidden" name="command" value="$command" />
1202: <input type="hidden" name="context" value="$context" />
1203: </form>
1204: STUFF
1205: }
1206: } else {
1207: $form = &mt('Unavailable');
1208: }
1209: if ($env{'form.command'} eq 'manageresv') {
1210: $output .= '<tr id="LC_slotrow_'.$num.'_'.$slot.'" >';
1211: } else {
1212: $output .= &Apache::loncommon::start_data_table_row('','LC_slotrow_'.$num.'_'.$slot);
1213: }
1214: $output .= "
1215: <td>$form</td>
1216: <td>$description</td>\n";
1217: if ($env{'form.command'} eq 'manageresv') {
1218: $output .= '</tr>';
1219: } else {
1220: $output .= &Apache::loncommon::end_data_table_row();
1221: }
1222: }
1223: if ($env{'form.command'} eq 'manageresv') {
1224: $output .= '</table>';
1225: } else {
1226: $output .= &Apache::loncommon::end_data_table();
1227: }
1228: if (@{$available} > 1) {
1229: $output .= '</div></fieldset>';
1230: }
1231: $r->print($output);
1232: return;
1233: }
1234:
1235: sub to_show {
1236: my ($slotname,$slot,$when,$deleted,$name) = @_;
1237: my $time=time;
1238: my $week=60*60*24*7;
1239:
1240: if ($deleted eq 'hide' && $slot->{'type'} eq 'deleted') {
1241: return 0;
1242: }
1243:
1244: if ($name && $name->{'value'} =~ /\w/) {
1245: if ($name->{'type'} eq 'substring') {
1246: if ($slotname !~ /\Q$name->{'value'}\E/) {
1247: return 0;
1248: }
1249: }
1250: if ($name->{'type'} eq 'exact') {
1251: if ($slotname eq $name->{'value'}) {
1252: return 0;
1253: }
1254: }
1255: }
1256:
1257: if ($when eq 'any') {
1258: return 1;
1259: } elsif ($when eq 'now') {
1260: if ($time > $slot->{'starttime'} &&
1261: $time < $slot->{'endtime'}) {
1262: return 1;
1263: }
1264: return 0;
1265: } elsif ($when eq 'nextweek') {
1266: if ( ($time < $slot->{'starttime'} &&
1267: ($time+$week) > $slot->{'starttime'})
1268: ||
1269: ($time < $slot->{'endtime'} &&
1270: ($time+$week) > $slot->{'endtime'}) ) {
1271: return 1;
1272: }
1273: return 0;
1274: } elsif ($when eq 'lastweek') {
1275: if ( ($time > $slot->{'starttime'} &&
1276: ($time-$week) < $slot->{'starttime'})
1277: ||
1278: ($time > $slot->{'endtime'} &&
1279: ($time-$week) < $slot->{'endtime'}) ) {
1280: return 1;
1281: }
1282: return 0;
1283: } elsif ($when eq 'willopen') {
1284: if ($time < $slot->{'starttime'}) {
1285: return 1;
1286: }
1287: return 0;
1288: } elsif ($when eq 'wereopen') {
1289: if ($time > $slot->{'endtime'}) {
1290: return 1;
1291: }
1292: return 0;
1293: }
1294:
1295: return 1;
1296: }
1297:
1298: sub remove_link {
1299: my ($slotname,$entry,$uname,$udom,$symb) = @_;
1300:
1301: my $remove = &mt('Remove');
1302:
1303: if ($entry eq 'remove all') {
1304: $remove = &mt('Remove All');
1305: undef($uname);
1306: undef($udom);
1307: }
1308:
1309: $slotname = &escape($slotname);
1310: $entry = &escape($entry);
1311: $uname = &escape($uname);
1312: $udom = &escape($udom);
1313: $symb = &escape($symb);
1314:
1315: return <<"END_LINK";
1316: <a href="/adm/slotrequest?command=remove_registration&slotname=$slotname&entry=$entry&uname=$uname&udom=$udom&symb=$symb&context=manage"
1317: >($remove)</a>
1318: END_LINK
1319:
1320: }
1321:
1322: sub show_table {
1323: my ($r,$mgr)=@_;
1324:
1325: my ($cnum,$cdom)=&get_course();
1326: my $crstype=&Apache::loncommon::course_type($cdom.'_'.$cnum);
1327: my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
1328: if ( (keys(%slots))[0] =~ /^error: 2 /) {
1329: undef(%slots);
1330: }
1331: my $available;
1332: if ($mgr eq 'F') {
1333: # FIXME: This line should be deleted once Slots uses breadcrumbs
1334: $r->print('<br />'.&Apache::loncommon::help_open_topic(
1335: 'Slot About', &mt('Help on slots')));
1336:
1337: $r->print('<div>');
1338: $r->print('<form method="post" action="/adm/slotrequest">
1339: <input type="hidden" name="command" value="uploadstart" />
1340: <input type="submit" name="start" value="'.&mt('Upload Slot List').'" />
1341: </form>');
1342: $r->print(&Apache::loncommon::help_open_topic('Slot CommaDelimited'));
1343: $r->print('<form method="post" action="/adm/helper/newslot.helper">
1344: <input type="submit" name="newslot" value="'.&mt('Create a New Slot').'" />
1345: </form>');
1346: $r->print(&Apache::loncommon::help_open_topic('Slot AddInterface'));
1347: $r->print('</div>');
1348: }
1349:
1350: if (!keys(%slots)) {
1351: $r->print(
1352: '<p class="LC_info">'
1353: .&mt('No slots have been created in this '.lc($crstype).'.')
1354: .'</p>'
1355: );
1356: return;
1357: }
1358:
1359: my %Saveable_Parameters = ('show' => 'array',
1360: 'when' => 'scalar',
1361: 'order' => 'scalar',
1362: 'deleted' => 'scalar',
1363: 'name_filter_type' => 'scalar',
1364: 'name_filter_value' => 'scalar',
1365: );
1366: &Apache::loncommon::store_course_settings('slotrequest',
1367: \%Saveable_Parameters);
1368: &Apache::loncommon::restore_course_settings('slotrequest',
1369: \%Saveable_Parameters);
1370: &Apache::grades::init_perm();
1371: my ($classlist,$section,$fullname)=&Apache::grades::getclasslist('all');
1372: &Apache::grades::reset_perm();
1373:
1374: # what to display filtering
1375: my %show_fields=&Apache::lonlocal::texthash(
1376: 'name' => 'Slot Name',
1377: 'description' => 'Description',
1378: 'type' => 'Type',
1379: 'starttime' => 'Start time',
1380: 'endtime' => 'End Time',
1381: 'startreserve' => 'Time students can start reserving',
1382: 'endreserve' => 'Time students can no longer reserve',
1383: 'reservationmsg' => 'Message triggered by reservation',
1384: 'secret' => 'Secret Word',
1385: 'space' => '# of students/max',
1386: 'ip' => 'IP or DNS restrictions',
1387: 'symb' => 'Resource slot is restricted to.',
1388: 'allowedsections' => 'Sections slot is restricted to.',
1389: 'allowedusers' => 'Users slot is restricted to.',
1390: 'uniqueperiod' => 'Period of time slot is unique',
1391: 'scheduled' => 'Scheduled Students',
1392: 'proctor' => 'List of proctors');
1393: if ($crstype eq 'Community') {
1394: $show_fields{'startreserve'} = &mt('Time members can start reserving');
1395: $show_fields{'endreserve'} = &mt('Time members can no longer reserve');
1396: $show_fields{'scheduled'} = &mt('Scheduled Members');
1397: }
1398: my @show_order=('name','description','type','starttime','endtime',
1399: 'startreserve','endreserve','reservationmsg','secret','space',
1400: 'ip','symb','allowedsections','allowedusers','uniqueperiod',
1401: 'scheduled','proctor');
1402: my @show =
1403: (exists($env{'form.show'})) ? &Apache::loncommon::get_env_multiple('form.show')
1404: : keys(%show_fields);
1405: my %show = map { $_ => 1 } (@show);
1406:
1407: #when filtering setup
1408: my %when_fields=&Apache::lonlocal::texthash(
1409: 'now' => 'Open now',
1410: 'nextweek' => 'Open within the next week',
1411: 'lastweek' => 'Were open last week',
1412: 'willopen' => 'Will open later',
1413: 'wereopen' => 'Were open',
1414: 'any' => 'Anytime',
1415: );
1416: my @when_order=('any','now','nextweek','lastweek','willopen','wereopen');
1417: $when_fields{'select_form_order'} = \@when_order;
1418: my $when = (exists($env{'form.when'})) ? $env{'form.when'}
1419: : 'now';
1420:
1421: #display of students setup
1422: my %stu_display_fields=
1423: &Apache::lonlocal::texthash('username' => 'User name',
1424: 'fullname' => 'Full name',
1425: );
1426: my @stu_display_order=('fullname','username');
1427: my @stu_display =
1428: (exists($env{'form.studisplay'})) ? &Apache::loncommon::get_env_multiple('form.studisplay')
1429: : keys(%stu_display_fields);
1430: my %stu_display = map { $_ => 1 } (@stu_display);
1431:
1432: #name filtering setup
1433: my %name_filter_type_fields=
1434: &Apache::lonlocal::texthash('substring' => 'Substring',
1435: 'exact' => 'Exact',
1436: #'reg' => 'Regular Expression',
1437: );
1438: my @name_filter_type_order=('substring','exact');
1439:
1440: $name_filter_type_fields{'select_form_order'} = \@name_filter_type_order;
1441: my $name_filter_type =
1442: (exists($env{'form.name_filter_type'})) ? $env{'form.name_filter_type'}
1443: : 'substring';
1444: my $name_filter = {'type' => $name_filter_type,
1445: 'value' => $env{'form.name_filter_value'},};
1446:
1447:
1448: #deleted slot filtering
1449: #default to hide if no value
1450: $env{'form.deleted'} ||= 'hide';
1451: my $hide_radio =
1452: &Apache::lonhtmlcommon::radio('deleted',$env{'form.deleted'},'hide');
1453: my $show_radio =
1454: &Apache::lonhtmlcommon::radio('deleted',$env{'form.deleted'},'show');
1455:
1456: $r->print('<form method="post" action="/adm/slotrequest">
1457: <input type="hidden" name="command" value="showslots" />');
1458: $r->print('<div>');
1459: $r->print('<table class="inline">
1460: <tr><th>'.&mt('Show').'</th>
1461: <th>'.&mt('Student Display').'</th>
1462: <th>'.&mt('Open').'</th>
1463: <th>'.&mt('Slot Name Filter').'</th>
1464: <th>'.&mt('Options').'</th>
1465: </tr>
1466: <tr><td valign="top">'.&Apache::loncommon::multiple_select_form('show',\@show,6,\%show_fields,\@show_order).
1467: '</td>
1468: <td valign="top">
1469: '.&Apache::loncommon::multiple_select_form('studisplay',\@stu_display,
1470: 6,\%stu_display_fields,
1471: \@stu_display_order).'
1472: </td>
1473: <td valign="top">'.&Apache::loncommon::select_form($when,'when',\%when_fields).
1474: '</td>
1475: <td valign="top">'.&Apache::loncommon::select_form($name_filter_type,
1476: 'name_filter_type',
1477: \%name_filter_type_fields).
1478: '<br />'.
1479: &Apache::lonhtmlcommon::textbox('name_filter_value',
1480: $env{'form.name_filter_value'},
1481: 15).
1482: '</td>
1483: <td valign="top">
1484: <table>
1485: <tr>
1486: <td rowspan="2">'.&mt('Deleted slots:').'</td>
1487: <td><label>'.$show_radio.&mt('Show').'</label></td>
1488: </tr>
1489: <tr>
1490: <td><label>'.$hide_radio.&mt('Hide').'</label></td>
1491: </tr>
1492: </table>
1493: </td>
1494: </tr>
1495: </table>');
1496: $r->print('</div>');
1497: $r->print('<p><input type="submit" name="start" value="'.&mt('Update Display').'" /></p>');
1498: my $linkstart='<a href="/adm/slotrequest?command=showslots&order=';
1499: my $tableheader = &Apache::loncommon::start_data_table().
1500: &Apache::loncommon::start_data_table_header_row().'
1501: <th></th>';
1502: foreach my $which (@show_order) {
1503: if ($which ne 'proctor' && exists($show{$which})) {
1504: $tableheader .= '<th>'.$linkstart.$which.'">'.$show_fields{$which}.'</a></th>';
1505: }
1506: }
1507: $tableheader .= &Apache::loncommon::end_data_table_header_row();
1508: my $shownheader = 0;
1509:
1510: my %name_cache;
1511: my $slotsort = sub {
1512: if ($env{'form.order'}=~/^(type|description|endtime|startreserve|endreserve|ip|symb|allowedsections|allowedusers|reservationmsg)$/) {
1513: if (lc($slots{$a}->{$env{'form.order'}})
1514: ne lc($slots{$b}->{$env{'form.order'}})) {
1515: return (lc($slots{$a}->{$env{'form.order'}})
1516: cmp lc($slots{$b}->{$env{'form.order'}}));
1517: }
1518: } elsif ($env{'form.order'} eq 'space') {
1519: if ($slots{$a}{'maxspace'} ne $slots{$b}{'maxspace'}) {
1520: return ($slots{$a}{'maxspace'} cmp $slots{$b}{'maxspace'});
1521: }
1522: } elsif ($env{'form.order'} eq 'name') {
1523: if (lc($a) cmp lc($b)) {
1524: return lc($a) cmp lc($b);
1525: }
1526: } elsif ($env{'form.order'} eq 'uniqueperiod') {
1527:
1528: if ($slots{$a}->{'uniqueperiod'}[0]
1529: ne $slots{$b}->{'uniqueperiod'}[0]) {
1530: return ($slots{$a}->{'uniqueperiod'}[0]
1531: cmp $slots{$b}->{'uniqueperiod'}[0]);
1532: }
1533: if ($slots{$a}->{'uniqueperiod'}[1]
1534: ne $slots{$b}->{'uniqueperiod'}[1]) {
1535: return ($slots{$a}->{'uniqueperiod'}[1]
1536: cmp $slots{$b}->{'uniqueperiod'}[1]);
1537: }
1538: }
1539: return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'};
1540: };
1541:
1542: my %consumed;
1543: if (exists($show{'scheduled'}) || exists($show{'space'}) ) {
1544: %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum);
1545: my ($tmp)=%consumed;
1546: if ($tmp =~ /^error: /) { undef(%consumed); }
1547: }
1548:
1549: my %msgops = &slot_reservationmsg_options();
1550:
1551: foreach my $slot (sort $slotsort (keys(%slots))) {
1552: if (!&to_show($slot,$slots{$slot},$when,
1553: $env{'form.deleted'},$name_filter)) { next; }
1554: my $reservemsg;
1555: if (defined($slots{$slot}->{'type'})
1556: && $slots{$slot}->{'type'} eq 'schedulable_student') {
1557: $reservemsg = $msgops{$slots{$slot}->{'reservationmsg'}};
1558: }
1559: my $description=&get_description($slot,$slots{$slot});
1560: my ($id_count,$ids);
1561:
1562: if (exists($show{'scheduled'}) || exists($show{'space'}) ) {
1563: my $re_str = "$slot\0";
1564: my @this_slot = grep(/^\Q$re_str\E/,keys(%consumed));
1565: $id_count = scalar(@this_slot);
1566: if (exists($show{'scheduled'})) {
1567: foreach my $entry (sort { $consumed{$a}{name} cmp
1568: $consumed{$b}{name} }
1569: (@this_slot)) {
1570: my (undef,$id)=split("\0",$entry);
1571: my ($uname,$udom) = split(':',$consumed{$entry}{'name'});
1572: $ids.= '<span class="LC_nobreak">';
1573: foreach my $item (@stu_display_order) {
1574: if ($stu_display{$item}) {
1575: if ($item eq 'fullname') {
1576: $ids.=$fullname->{"$uname:$udom"}.' ';
1577: } elsif ($item eq 'username') {
1578: $ids.="<tt>$uname:$udom</tt> ";
1579: }
1580: }
1581: }
1582: $ids.=&remove_link($slot,$entry,$uname,$udom,
1583: $consumed{$entry}{'symb'}).'</span><br />';
1584: }
1585: }
1586: }
1587:
1588: my $start=($slots{$slot}->{'starttime'}?
1589: &Apache::lonlocal::locallocaltime($slots{$slot}->{'starttime'}):'');
1590: my $end=($slots{$slot}->{'endtime'}?
1591: &Apache::lonlocal::locallocaltime($slots{$slot}->{'endtime'}):'');
1592: my $start_reserve=($slots{$slot}->{'startreserve'}?
1593: &Apache::lonlocal::locallocaltime($slots{$slot}->{'startreserve'}):'');
1594: my $end_reserve=($slots{$slot}->{'endreserve'}?
1595: &Apache::lonlocal::locallocaltime($slots{$slot}->{'endreserve'}):'');
1596:
1597: my $unique;
1598: if (ref($slots{$slot}{'uniqueperiod'})) {
1599: $unique=localtime($slots{$slot}{'uniqueperiod'}[0]).', '.
1600: localtime($slots{$slot}{'uniqueperiod'}[1]);
1601: }
1602:
1603: my $title;
1604: if (exists($slots{$slot}{'symb'})) {
1605: my (undef,undef,$res)=
1606: &Apache::lonnet::decode_symb($slots{$slot}{'symb'});
1607: $res = &Apache::lonnet::clutter($res);
1608: $title = &Apache::lonnet::gettitle($slots{$slot}{'symb'});
1609: $title='<a href="'.$res.'?symb='.$slots{$slot}{'symb'}.'">'.$title.'</a>';
1610: }
1611:
1612: my $allowedsections;
1613: if (exists($show{'allowedsections'})) {
1614: $allowedsections =
1615: join(', ',sort(split(/\s*,\s*/,
1616: $slots{$slot}->{'allowedsections'})));
1617: }
1618:
1619: my @allowedusers;
1620: if (exists($show{'allowedusers'})) {
1621: @allowedusers= map {
1622: my ($uname,$udom)=split(/:/,$_);
1623: my $fullname=$name_cache{$_};
1624: if (!defined($fullname)) {
1625: $fullname = &Apache::loncommon::plainname($uname,$udom);
1626: $fullname =~s/\s/ /g;
1627: $name_cache{$_} = $fullname;
1628: }
1629: &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
1630: } (sort(split(/\s*,\s*/,$slots{$slot}->{'allowedusers'})));
1631: }
1632: my $allowedusers=join(', ',@allowedusers);
1633:
1634: my @proctors;
1635: my $rowspan=1;
1636: my $colspan=1;
1637: if (exists($show{'proctor'})) {
1638: $rowspan=2;
1639: @proctors= map {
1640: my ($uname,$udom)=split(/:/,$_);
1641: my $fullname=$name_cache{$_};
1642: if (!defined($fullname)) {
1643: $fullname = &Apache::loncommon::plainname($uname,$udom);
1644: $fullname =~s/\s/ /g;
1645: $name_cache{$_} = $fullname;
1646: }
1647: &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
1648: } (sort(split(/\s*,\s*/,$slots{$slot}->{'proctor'})));
1649: }
1650: my $proctors=join(', ',@proctors);
1651:
1652: my %lt = &Apache::lonlocal::texthash (
1653: edit => 'Edit',
1654: delete => 'Delete',
1655: slotlog => 'History',
1656: );
1657: my ($edit,$delete,$showlog,$remove_all);
1658: if ($mgr) {
1659: $edit=(<<"EDITLINK");
1660: <a href="/adm/helper/newslot.helper?name=$slot">$lt{'edit'}</a>
1661: EDITLINK
1662:
1663: $delete=(<<"DELETELINK");
1664: <a href="/adm/slotrequest?command=delete&slotname=$slot">$lt{'delete'}</a>
1665: DELETELINK
1666:
1667: $remove_all=&remove_link($slot,'remove all').'<br />';
1668:
1669: if ($ids eq '') {
1670: undef($remove_all);
1671: } else {
1672: undef($delete);
1673: }
1674: }
1675:
1676: $showlog=(<<"LOGLINK");
1677: <a href="/adm/slotrequest?command=slotlog&slotname=$slot">$lt{'slotlog'}</a>
1678: LOGLINK
1679:
1680: if ($slots{$slot}{'type'} ne 'schedulable_student') {
1681: undef($showlog);
1682: undef($remove_all);
1683: }
1684:
1685: unless ($shownheader) {
1686: $r->print($tableheader);
1687: $shownheader = 1;
1688: }
1689:
1690: my $row_start=&Apache::loncommon::start_data_table_row();
1691: my $row_end=&Apache::loncommon::end_data_table_row();
1692: $r->print($row_start.
1693: "\n<td rowspan=\"$rowspan\">$edit $delete $showlog</td>\n");
1694: if (exists($show{'name'})) {
1695: $colspan++;$r->print("<td>$slot</td>");
1696: }
1697: if (exists($show{'description'})) {
1698: $colspan++;$r->print("<td>$description</td>\n");
1699: }
1700: if (exists($show{'type'})) {
1701: $colspan++;$r->print("<td>$slots{$slot}->{'type'}</td>\n");
1702: }
1703: if (exists($show{'starttime'})) {
1704: $colspan++;$r->print("<td>$start</td>\n");
1705: }
1706: if (exists($show{'endtime'})) {
1707: $colspan++;$r->print("<td>$end</td>\n");
1708: }
1709: if (exists($show{'startreserve'})) {
1710: $colspan++;$r->print("<td>$start_reserve</td>\n");
1711: }
1712: if (exists($show{'endreserve'})) {
1713: $colspan++;$r->print("<td>$end_reserve</td>\n");
1714: }
1715: if (exists($show{'reservationmsg'})) {
1716: $colspan++;$r->print("<td>$reservemsg</td>\n");
1717: }
1718: if (exists($show{'secret'})) {
1719: $colspan++;$r->print("<td>$slots{$slot}{'secret'}</td>\n");
1720: }
1721: if (exists($show{'space'})) {
1722: my $display = $id_count;
1723: if ($slots{$slot}{'maxspace'}>0) {
1724: $display.='/'.$slots{$slot}{'maxspace'};
1725: if ($slots{$slot}{'maxspace'} <= $id_count) {
1726: $display = '<strong>'.$display.' (full) </strong>';
1727: }
1728: }
1729: $colspan++;$r->print("<td>$display</td>\n");
1730: }
1731: if (exists($show{'ip'})) {
1732: $colspan++;$r->print("<td>$slots{$slot}{'ip'}</td>\n");
1733: }
1734: if (exists($show{'symb'})) {
1735: $colspan++;$r->print("<td>$title</td>\n");
1736: }
1737: if (exists($show{'allowedsections'})) {
1738: $colspan++;$r->print("<td>$allowedsections</td>\n");
1739: }
1740: if (exists($show{'allowedusers'})) {
1741: $colspan++;$r->print("<td>$allowedusers</td>\n");
1742: }
1743: if (exists($show{'uniqueperiod'})) {
1744: $colspan++;$r->print("<td>$unique</td>\n");
1745: }
1746: if (exists($show{'scheduled'})) {
1747: $colspan++;$r->print("<td>$remove_all $ids</td>\n");
1748: }
1749: $r->print("$row_end\n");
1750: if (exists($show{'proctor'})) {
1751: $r->print(<<STUFF);
1752: $row_start
1753: <td colspan="$colspan">$proctors</td>
1754: $row_end
1755: STUFF
1756: }
1757: }
1758: if ($shownheader) {
1759: $r->print(&Apache::loncommon::end_data_table());
1760: } else {
1761: $r->print('<p>'.&mt('No slots meet the criteria for display').'</p>');
1762: }
1763: $r->print('</form>');
1764: return;
1765: }
1766:
1767: sub manage_reservations {
1768: my ($r,$crstype,$slots,$consumed_uniqueperiods,$allavailable) = @_;
1769: my $navmap = Apache::lonnavmaps::navmap->new();
1770: $r->print('<p>'
1771: .&mt('Instructors may use a reservation system to place restrictions on when and where assignments can be worked on.')
1772: .'<br />'
1773: .&mt('One example is for management of laboratory space, which is only available at certain times, and has a limited number of seats.')
1774: .'</p>'
1775: );
1776: if (!defined($navmap)) {
1777: $r->print('<div class="LC_error">');
1778: if ($crstype eq 'Community') {
1779: $r->print(&mt('Unable to retrieve information about community contents'));
1780: } else {
1781: $r->print(&mt('Unable to retrieve information about course contents'));
1782: }
1783: $r->print('</div>');
1784: &Apache::lonnet::logthis('Manage Reservations - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1785: return;
1786: }
1787: if (ref($consumed_uniqueperiods) eq 'HASH') {
1788: if (&Apache::lonnet::error(%$consumed_uniqueperiods)) {
1789: $r->print('<span class="LC_error">'.
1790: &mt('An error occurred determining slot availability.').
1791: '</span>');
1792: return;
1793: }
1794: } elsif ($consumed_uniqueperiods =~ /^error: /) {
1795: $r->print('<span class="LC_error">'.
1796: &mt('An error occurred determining slot availability.').
1797: '</span>');
1798: return;
1799: }
1800: my (%parent,%shownparent,%container,%container_title,%contents);
1801: my ($depth,$count,$reservable,$lastcontainer,$rownum) = (0,0,0,0,0);
1802: my @backgrounds = ("LC_odd_row","LC_even_row");
1803: my $numcolors = scalar(@backgrounds);
1804: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/whitespace_21.gif");
1805: my $slotheader = '<p>'.
1806: &mt('Your reservation status for any such assignments is listed below:').
1807: '</p>'.
1808: '<table class="LC_data_table LC_tableOfContent">'."\n";
1809: my $shownheader = 0;
1810: my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
1811: while (my $resource = $it->next()) {
1812: if ($resource == $it->BEGIN_MAP()) {
1813: $depth++;
1814: $parent{$depth} = $lastcontainer;
1815: }
1816: if ($resource == $it->END_MAP()) {
1817: $depth--;
1818: $lastcontainer = $parent{$depth};
1819: }
1820: if (ref($resource)) {
1821: my $symb = $resource->symb();
1822: my $ressymb = $symb;
1823: $contents{$lastcontainer} ++;
1824: next if (!$resource->is_problem() && !$resource->is_sequence() &&
1825: !$resource->is_page());
1826: $count ++;
1827: if (($resource->is_sequence()) || ($resource->is_page())) {
1828: $lastcontainer = $count;
1829: $container{$lastcontainer} = $resource;
1830: $container_title{$lastcontainer} = $resource->compTitle();
1831: }
1832: if ($resource->is_problem()) {
1833: my ($useslots) = $resource->slot_control();
1834: next if (($useslots eq '') || ($useslots =~ /^\s*no\s*$/i));
1835: my ($msg,$get_choices,$slotdescription);
1836: my $title = $resource->compTitle();
1837: my $status = $resource->simpleStatus('0');
1838: my ($slot_status,$date,$slot_name) = $resource->check_for_slot('0');
1839: if ($slot_name ne '') {
1840: my %slot=&Apache::lonnet::get_slot($slot_name);
1841: $slotdescription=&get_description($slot_name,\%slot);
1842: }
1843: if ($slot_status == $resource->NOT_IN_A_SLOT) {
1844: $msg=&mt('No current reservation.');
1845: $get_choices = 1;
1846: } elsif ($slot_status == $resource->NEEDS_CHECKIN) {
1847: $msg='<span class="LC_nobreak">'.&mt('Reserved:').
1848: ' '.$slotdescription.'</span><br />'.
1849: &mt('Access requires proctor validation.');
1850: } elsif ($slot_status == $resource->WAITING_FOR_GRADE) {
1851: $msg=&mt('Submitted and currently in grading queue.');
1852: } elsif ($slot_status == $resource->CORRECT) {
1853: $msg=&mt('Problem is unavailable.');
1854: } elsif ($slot_status == $resource->RESERVED) {
1855: $msg='<span class="LC_nobreak">'.&mt('Reserved:').
1856: ' '.$slotdescription.'</span><br />'.
1857: &mt('Problem is currently available.');
1858: } elsif ($slot_status == $resource->RESERVED_LOCATION) {
1859: $msg='<span class="LC_nobreak">'.&mt('Reserved:').
1860: ' '.$slotdescription.'</span><br />'.
1861: &mt('Problem is available at a different location.');
1862: $get_choices = 1;
1863: } elsif ($slot_status == $resource->RESERVED_LATER) {
1864: $msg='<span class="LC_nobreak">'.&mt('Reserved:').
1865: ' '.$slotdescription.'</span><br />'.
1866: &mt('Problem will be available later.');
1867: $get_choices = 1;
1868: } elsif ($slot_status == $resource->RESERVABLE) {
1869: $msg=&mt('Reservation needed');
1870: $get_choices = 1;
1871: } elsif ($slot_status == $resource->RESERVABLE_LATER) {
1872: $msg=&mt('Reservation needed: will be reservable later.');
1873: } elsif ($slot_status == $resource->NOTRESERVABLE) {
1874: $msg=&mt('Reservation needed: none available.');
1875: } elsif ($slot_status == $resource->UNKNOWN) {
1876: $msg=&mt('Unable to determine status due to network problems.');
1877: } else {
1878: if ($status != $resource->OPEN) {
1879: $msg = &Apache::lonnavmaps::getDescription($resource,'0');
1880: }
1881: }
1882: $reservable ++;
1883: my $treelevel = $depth;
1884: my $higherup = $lastcontainer;
1885: if ($depth > 1) {
1886: my @maprows;
1887: while ($treelevel > 1) {
1888: if (ref($container{$higherup})) {
1889: my $res = $container{$higherup};
1890: last if (defined($shownparent{$higherup}));
1891: my $maptitle = $res->compTitle();
1892: my $type = 'sequence';
1893: if ($res->is_page()) {
1894: $type = 'page';
1895: }
1896: &show_map_row($treelevel,$location,$type,$maptitle,
1897: \@maprows);
1898: $shownparent{$higherup} = 1;
1899: }
1900: $treelevel --;
1901: $higherup = $parent{$treelevel};
1902: }
1903: foreach my $item (@maprows) {
1904: $rownum ++;
1905: my $bgcolor = $backgrounds[$rownum % $numcolors];
1906: if (!$shownheader) {
1907: $r->print($slotheader);
1908: $shownheader = 1;
1909: }
1910: $r->print('<tr class="'.$bgcolor.'">'.$item.'</tr>'."\n");
1911: }
1912: }
1913: $rownum ++;
1914: my $bgcolor = $backgrounds[$rownum % $numcolors];
1915: if (!$shownheader) {
1916: $r->print($slotheader);
1917: $shownheader = 1;
1918: }
1919: $r->print('<tr class="'.$bgcolor.'"><td>'."\n");
1920: for (my $i=0; $i<$depth; $i++) {
1921: $r->print('<img src="'.$location.'" alt="" />');
1922: }
1923: my $result = '<a href="'.$resource->src().'?symb='.$symb.'">'.
1924: '<img class="LC_contentImage" src="/adm/lonIcons/';
1925: if ($resource->is_task()) {
1926: $result .= 'task.gif" alt="'.&mt('Task');
1927: } else {
1928: $result .= 'problem.gif" alt="'.&mt('Problem');
1929: }
1930: $result .= '" /><b>'.$title.'</b></a>'.(' ' x6).'</td>';
1931: my $hasaction;
1932: if ($status == $resource->OPEN) {
1933: if ($get_choices) {
1934: $hasaction = 1;
1935: }
1936: }
1937: if ($hasaction) {
1938: $result .= '<td valign="top">'.$msg.'</td>'.
1939: '<td valign="top">';
1940: } else {
1941: $result .= '<td colspan="2" valign="middle">'.$msg.'</td>';
1942: }
1943: $r->print($result);
1944: if ($hasaction) {
1945: my @got_slots=&check_for_reservation($symb,'allslots');
1946: if ($got_slots[0] =~ /^error: /) {
1947: $r->print('<span class="LC_error">'.
1948: &mt('An error occurred determining slot availability.').
1949: '</span>');
1950: } else {
1951: my $formname = 'manageres_'.$reservable;
1952: if (ref($allavailable) eq 'ARRAY') {
1953: my @available;
1954: if (ref($slots) eq 'HASH') {
1955: foreach my $slot (@{$allavailable}) {
1956: # not allowed for this resource
1957: if (ref($slots->{$slot}) eq 'HASH') {
1958: if ((defined($slots->{$slot}->{'symb'})) &&
1959: ($slots->{$slot}->{'symb'} ne $symb)) {
1960: next;
1961: }
1962: }
1963: push(@available,$slot);
1964: }
1965: }
1966: &show_choices($r,$symb,$formname,$reservable,$slots,$consumed_uniqueperiods,
1967: \@available,\@got_slots);
1968: }
1969: }
1970: $r->print('</td>');
1971: }
1972: $r->print('</tr>');
1973: }
1974: }
1975: }
1976: if ($shownheader) {
1977: $r->print('</table>');
1978: }
1979: if (!$reservable) {
1980: $r->print('<span class="LC_info">');
1981: if ($crstype eq 'Community') {
1982: $r->print(&mt('No community items currently require a reservation to gain access.'));
1983: } else {
1984: $r->print(&mt('No course items currently require a reservation to gain access.'));
1985: }
1986: $r->print('</span>');
1987: }
1988: $r->print('<p><a href="/adm/slotrequest?command=showresv">'.
1989: &mt('Reservation History').'</a></p>');
1990: }
1991:
1992: sub show_map_row {
1993: my ($depth,$location,$type,$title,$maprows) = @_;
1994: my $output = '<td>';
1995: for (my $i=0; $i<$depth-1; $i++) {
1996: $output .= '<img src="'.$location.'" alt="" />';
1997: }
1998: if ($type eq 'page') {
1999: $output .= '<img src="/adm/lonIcons/navmap.page.open.gif" alt="" /> '."\n";
2000: } else {
2001: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n";
2002: }
2003: $output .= $title.'</td><td colspan="2"> </td>'."\n";
2004: unshift (@{$maprows},$output);
2005: return;
2006: }
2007:
2008: sub show_reservations {
2009: my ($r,$uname,$udom) = @_;
2010: if (!defined($uname)) {
2011: $uname = $env{'user.name'};
2012: }
2013: if (!defined($udom)) {
2014: $udom = $env{'user.domain'};
2015: }
2016: my $formname = 'slotlog';
2017: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2018: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2019: my $crstype = &Apache::loncommon::course_type();
2020: my %log=&Apache::lonnet::dump('nohist_'.$cdom.'_'.$cnum.'_slotlog',$udom,$uname);
2021: if ($env{'form.origin'} eq 'aboutme') {
2022: $r->print('<div class="LC_fontsize_large">');
2023: my $name = &Apache::loncommon::plainname($env{'form.uname'},$env{'form.udom'},
2024: 'firstname');
2025: if ($crstype eq 'Community') {
2026: $r->print(&mt('History of member-reservable slots for: [_1]',
2027: $name));
2028: } else {
2029: $r->print(&mt('History of student-reservable slots for: [_1]',
2030: $name));
2031:
2032: }
2033: $r->print('</div>');
2034: }
2035: $r->print('<form action="/adm/slotrequest" method="post" name="'.$formname.'">');
2036: # set defaults
2037: my $now = time();
2038: my $defstart = $now - (7*24*3600); #7 days ago
2039: my %defaults = (
2040: page => '1',
2041: show => '10',
2042: action => 'any',
2043: log_start_date => $defstart,
2044: log_end_date => $now,
2045: );
2046: my $more_records = 0;
2047:
2048: # set current
2049: my %curr;
2050: foreach my $item ('show','page','action') {
2051: $curr{$item} = $env{'form.'.$item};
2052: }
2053: my ($startdate,$enddate) =
2054: &Apache::lonuserutils::get_dates_from_form('log_start_date',
2055: 'log_end_date');
2056: $curr{'log_start_date'} = $startdate;
2057: $curr{'log_end_date'} = $enddate;
2058: foreach my $key (keys(%defaults)) {
2059: if ($curr{$key} eq '') {
2060: $curr{$key} = $defaults{$key};
2061: }
2062: }
2063: my ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
2064: $r->print(&display_filter($formname,$cdom,$cnum,\%curr,$version));
2065: my $showntablehdr = 0;
2066: my $tablehdr = &Apache::loncommon::start_data_table().
2067: &Apache::loncommon::start_data_table_header_row().
2068: '<th> </th><th>'.&mt('When').'</th><th>'.&mt('Action').'</th>'.
2069: '<th>'.&mt('Description').'</th><th>'.&mt('Start time').'</th>'.
2070: '<th>'.&mt('End time').'</th><th>'.&mt('Resource').'</th>'.
2071: &Apache::loncommon::end_data_table_header_row();
2072: my ($minshown,$maxshown);
2073: $minshown = 1;
2074: my $count = 0;
2075: if ($curr{'show'} ne &mt('all')) {
2076: $maxshown = $curr{'page'} * $curr{'show'};
2077: if ($curr{'page'} > 1) {
2078: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
2079: }
2080: }
2081: my (%titles,%maptitles);
2082: my %lt = &reservationlog_contexts($crstype);
2083: foreach my $id (sort { $log{$b}{'exe_time'}<=>$log{$a}{'exe_time'} } (keys(%log))) {
2084: next if (($log{$id}{'exe_time'} < $curr{'log_start_date'}) ||
2085: ($log{$id}{'exe_time'} > $curr{'log_end_date'}));
2086: if ($curr{'show'} ne &mt('all')) {
2087: if ($count >= $curr{'page'} * $curr{'show'}) {
2088: $more_records = 1;
2089: last;
2090: }
2091: }
2092: if ($curr{'action'} ne 'any') {
2093: next if ($log{$id}{'logentry'}{'action'} ne $curr{'action'});
2094: }
2095: $count ++;
2096: next if ($count < $minshown);
2097: if (!$showntablehdr) {
2098: $r->print($tablehdr);
2099: $showntablehdr = 1;
2100: }
2101: my $symb = $log{$id}{'logentry'}{'symb'};
2102: my $slot_name = $log{$id}{'logentry'}{'slot'};
2103: my %slot=&Apache::lonnet::get_slot($slot_name);
2104: my $description = $slot{'description'};
2105: my $start = ($slot{'starttime'}?
2106: &Apache::lonlocal::locallocaltime($slot{'starttime'}):'');
2107: my $end = ($slot{'endtime'}?
2108: &Apache::lonlocal::locallocaltime($slot{'endtime'}):'');
2109: my $title = &get_resource_title($symb,\%titles,\%maptitles);
2110: my $chgaction = $log{$id}{'logentry'}{'action'};
2111: if ($chgaction ne '' && $lt{$chgaction} ne '') {
2112: $chgaction = $lt{$chgaction};
2113: }
2114: $r->print(&Apache::loncommon::start_data_table_row().'<td>'.$count.'</td><td>'.&Apache::lonlocal::locallocaltime($log{$id}{'exe_time'}).'</td><td>'.$chgaction.'</td><td>'.$description.'</td><td>'.$start.'</td><td>'.$end.'</td><td>'.$title.'</td>'.&Apache::loncommon::end_data_table_row()."\n");
2115: }
2116: if ($showntablehdr) {
2117: $r->print(&Apache::loncommon::end_data_table().'<br />');
2118: if (($curr{'page'} > 1) || ($more_records)) {
2119: $r->print('<p>');
2120: if ($curr{'page'} > 1) {
2121: $r->print('<input type="button" onclick="javascript:chgPage('."'previous'".');" value="'.
2122: &mt('Previous [_1] changes',$curr{'show'}).'" />');
2123: }
2124: if ($more_records) {
2125: $r->print('<input type="button" onclick="javascript:chgPage('."'next'".');" value="'.
2126: &mt('Next [_1] changes',$curr{'show'}).'" />');
2127: }
2128: $r->print('</p>');
2129: $r->print(<<"ENDSCRIPT");
2130: <script type="text/javascript">
2131: // <![CDATA[
2132: function chgPage(caller) {
2133: if (caller == 'previous') {
2134: document.$formname.page.value --;
2135: }
2136: if (caller == 'next') {
2137: document.$formname.page.value ++;
2138: }
2139: document.$formname.submit();
2140: return;
2141: }
2142: // ]]>
2143: </script>
2144: ENDSCRIPT
2145: }
2146: } else {
2147: $r->print('<span class="LC_info">'
2148: .&mt('There are no transactions to display.')
2149: .'</span>'
2150: );
2151: }
2152: $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'."\n".
2153: '<input type="hidden" name="command" value="showresv" />'."\n");
2154: if ($env{'form.origin'} eq 'aboutme') {
2155: $r->print('<input type="hidden" name="origin" value="'.$env{'form.origin'}.'" />'."\n".
2156: '<input type="hidden" name="uname" value="'.$env{'form.uname'}.'" />'."\n".
2157: '<input type="hidden" name="udom" value="'.$env{'form.udom'}.'" />'."\n");
2158: }
2159: $r->print('</form>');
2160: return;
2161: }
2162:
2163: sub show_reservations_log {
2164: my ($r) = @_;
2165: my $badslot;
2166: my $crstype = &Apache::loncommon::course_type();
2167: if ($env{'form.slotname'} eq '') {
2168: $r->print('<div class="LC_warning">'.&mt('No slot name provided').'</div>');
2169: $badslot = 1;
2170: } else {
2171: my %slot=&Apache::lonnet::get_slot($env{'form.slotname'});
2172: if (keys(%slot) == 0) {
2173: $r->print('<div class="LC_warning">'.&mt('Invalid slot name: [_1]',$env{'form.slotname'}).'</div>');
2174: $badslot = 1;
2175: } elsif ($slot{type} ne 'schedulable_student') {
2176: my $description = &get_description($env{'form.slotname'},\%slot);
2177: $r->print('<div class="LC_warning">');
2178: if ($crstype eq 'Community') {
2179: $r->print(&mt('Reservation history unavailable for non-member-reservable slot: [_1].',$description));
2180: } else {
2181: $r->print(&mt('Reservation history unavailable for non-student-reservable slot: [_1].',$description));
2182: }
2183: $r->print('</div>');
2184: $badslot = 1;
2185: }
2186: }
2187: if ($badslot) {
2188: $r->print('<p><a href="/adm/slotrequest?command=showslots">'.
2189: &mt('Return to slot list').'</a></p>');
2190: return;
2191: }
2192: my $formname = 'reservationslog';
2193: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2194: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2195: my %slotlog=&Apache::lonnet::dump('nohist_slotreservationslog',$cdom,$cnum);
2196: if ((keys(%slotlog))[0]=~/^error\:/) { undef(%slotlog); }
2197:
2198: my (%log,@allsymbs);
2199: if (keys(%slotlog)) {
2200: foreach my $key (keys(%slotlog)) {
2201: if (ref($slotlog{$key}) eq 'HASH') {
2202: if (ref($slotlog{$key}{'logentry'}) eq 'HASH') {
2203: if ($slotlog{$key}{'logentry'}{'slot'} eq $env{'form.slotname'}) {
2204: $log{$key} = $slotlog{$key};
2205: if ($slotlog{$key}{'logentry'}{'symb'} ne '') {
2206: push(@allsymbs,$slotlog{$key}{'logentry'}{'symb'});
2207: }
2208: }
2209: }
2210: }
2211: }
2212: }
2213:
2214: $r->print('<form action="/adm/slotrequest" method="post" name="'.$formname.'">');
2215: my %saveable_parameters = ('show' => 'scalar',);
2216: &Apache::loncommon::store_course_settings('reservationslog',
2217: \%saveable_parameters);
2218: &Apache::loncommon::restore_course_settings('reservationslog',
2219: \%saveable_parameters);
2220: # set defaults
2221: my $now = time();
2222: my $defstart = $now - (7*24*3600); #7 days ago
2223: my %defaults = (
2224: page => '1',
2225: show => '10',
2226: chgcontext => 'any',
2227: action => 'any',
2228: symb => 'any',
2229: log_start_date => $defstart,
2230: log_end_date => $now,
2231: );
2232: my $more_records = 0;
2233:
2234: # set current
2235: my %curr;
2236: foreach my $item ('show','page','chgcontext','action','symb') {
2237: $curr{$item} = $env{'form.'.$item};
2238: }
2239: my ($startdate,$enddate) =
2240: &Apache::lonuserutils::get_dates_from_form('log_start_date',
2241: 'log_end_date');
2242: $curr{'log_start_date'} = $startdate;
2243: $curr{'log_end_date'} = $enddate;
2244: foreach my $key (keys(%defaults)) {
2245: if ($curr{$key} eq '') {
2246: $curr{$key} = $defaults{$key};
2247: }
2248: }
2249: my (%whodunit,%changed,$version);
2250: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
2251:
2252: my %slot=&Apache::lonnet::get_slot($env{'form.slotname'});
2253: my $description = $slot{'description'};
2254: $r->print('<span class="LC_fontsize_large">');
2255: if ($crstype eq 'Community') {
2256: $r->print(&mt('Reservation changes for member-reservable slot: [_1]',$description));
2257: } else {
2258: $r->print(&mt('Reservation changes for student-reservable slot: [_1]',$description));
2259: }
2260: $r->print('</span><br />');
2261: $r->print(&display_filter($formname,$cdom,$cnum,\%curr,$version,\@allsymbs));
2262: my $showntablehdr = 0;
2263: my $tablehdr = &Apache::loncommon::start_data_table().
2264: &Apache::loncommon::start_data_table_header_row().
2265: '<th> </th><th>'.&mt('When').'</th><th>'.&mt('Who made the change').
2266: '</th><th>'.&mt('Affected User').'</th><th>'.&mt('Action').'</th>'.
2267: '<th>'.&mt('Resource').'</th><th>'.&mt('Context').'</th>'.
2268: &Apache::loncommon::end_data_table_header_row();
2269: my ($minshown,$maxshown);
2270: $minshown = 1;
2271: my $count = 0;
2272: if ($curr{'show'} ne &mt('all')) {
2273: $maxshown = $curr{'page'} * $curr{'show'};
2274: if ($curr{'page'} > 1) {
2275: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
2276: }
2277: }
2278: my %lt = &reservationlog_contexts($crstype);
2279: my (%titles,%maptitles);
2280: foreach my $id (sort { $log{$b}{'exe_time'}<=>$log{$a}{'exe_time'} } (keys(%log))) {
2281: next if (($log{$id}{'exe_time'} < $curr{'log_start_date'}) ||
2282: ($log{$id}{'exe_time'} > $curr{'log_end_date'}));
2283: if ($curr{'show'} ne &mt('all')) {
2284: if ($count >= $curr{'page'} * $curr{'show'}) {
2285: $more_records = 1;
2286: last;
2287: }
2288: }
2289: if ($curr{'chgcontext'} ne 'any') {
2290: if ($curr{'chgcontext'} eq 'user') {
2291: next if (($log{$id}{'logentry'}{'context'} ne 'user') &&
2292: ($log{$id}{'logentry'}{'context'} ne 'usermanage'));
2293: } else {
2294: next if ($log{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
2295: }
2296: }
2297: if ($curr{'action'} ne 'any') {
2298: next if ($log{$id}{'logentry'}{'action'} ne $curr{'action'});
2299: }
2300: if ($curr{'symb'} ne 'any') {
2301: next if ($log{$id}{'logentry'}{'symb'} ne $curr{'symb'});
2302: }
2303: $count ++;
2304: next if ($count < $minshown);
2305: if (!$showntablehdr) {
2306: $r->print($tablehdr);
2307: $showntablehdr = 1;
2308: }
2309: if ($whodunit{$log{$id}{'exe_uname'}.':'.$log{$id}{'exe_udom'}} eq '') {
2310: $whodunit{$log{$id}{'exe_uname'}.':'.$log{$id}{'exe_udom'}} =
2311: &Apache::loncommon::plainname($log{$id}{'exe_uname'},$log{$id}{'exe_udom'});
2312: }
2313: if ($changed{$log{$id}{'uname'}.':'.$log{$id}{'udom'}} eq '') {
2314: $changed{$log{$id}{'uname'}.':'.$log{$id}{'udom'}} =
2315: &Apache::loncommon::plainname($log{$id}{'uname'},$log{$id}{'udom'});
2316: }
2317: my $symb = $log{$id}{'logentry'}{'symb'};
2318: my $title = &get_resource_title($symb,\%titles,\%maptitles);
2319: my $chgcontext = $log{$id}{'logentry'}{'context'};
2320: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
2321: $chgcontext = $lt{$chgcontext};
2322: }
2323: my $chgaction = $log{$id}{'logentry'}{'action'};
2324: if ($chgaction ne '' && $lt{$chgaction} ne '') {
2325: $chgaction = $lt{$chgaction};
2326: }
2327: $r->print(&Apache::loncommon::start_data_table_row().'<td>'.$count.'</td><td>'.&Apache::lonlocal::locallocaltime($log{$id}{'exe_time'}).'</td><td>'.$whodunit{$log{$id}{'exe_uname'}.':'.$log{$id}{'exe_udom'}}.'</td><td>'.$changed{$log{$id}{'uname'}.':'.$log{$id}{'udom'}}.'</td><td>'.$chgaction.'</td><td>'.$title.'</td><td>'.$chgcontext.'</td>'.&Apache::loncommon::end_data_table_row()."\n");
2328: }
2329: if ($showntablehdr) {
2330: $r->print(&Apache::loncommon::end_data_table().'<br />');
2331: if (($curr{'page'} > 1) || ($more_records)) {
2332: $r->print('<p>');
2333: if ($curr{'page'} > 1) {
2334: $r->print('<input type="button" onclick="javascript:chgPage('."'previous'".');" value="'.
2335: &mt('Previous [_1] changes',$curr{'show'}).'" />');
2336: }
2337: if ($more_records) {
2338: $r->print('<input type="button" onclick="javascript:chgPage('."'next'".');" value="'.
2339: &mt('Next [_1] changes',$curr{'show'}).'" />');
2340: }
2341: $r->print('</p>');
2342: $r->print(<<"ENDSCRIPT");
2343: <script type="text/javascript">
2344: function chgPage(caller) {
2345: if (caller == 'previous') {
2346: document.$formname.page.value --;
2347: }
2348: if (caller == 'next') {
2349: document.$formname.page.value ++;
2350: }
2351: document.$formname.submit();
2352: return;
2353: }
2354: </script>
2355: ENDSCRIPT
2356: }
2357: } else {
2358: $r->print(&mt('There are no records to display.'));
2359: }
2360: $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
2361: '<input type="hidden" name="slotname" value="'.$env{'form.slotname'}.'" />'.
2362: '<input type="hidden" name="command" value="slotlog" /></form>'.
2363: '<p><a href="/adm/slotrequest?command=showslots">'.
2364: &mt('Return to slot list').'</a></p>');
2365: return;
2366: }
2367:
2368: sub get_resource_title {
2369: my ($symb,$titles,$maptitles) = @_;
2370: my $title;
2371: if ((ref($titles) eq 'HASH') && (ref($maptitles) eq 'HASH')) {
2372: if (defined($titles->{$symb})) {
2373: $title = $titles->{$symb};
2374: } else {
2375: $title = &Apache::lonnet::gettitle($symb);
2376: my $maptitle;
2377: my ($mapurl) = &Apache::lonnet::decode_symb($symb);
2378: if (defined($maptitles->{$mapurl})) {
2379: $maptitle = $maptitles->{$mapurl};
2380: } else {
2381: if ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'}) {
2382: $maptitle=&mt('Main Content');
2383: } else {
2384: $maptitle=&Apache::lonnet::gettitle($mapurl);
2385: }
2386: $maptitles->{$mapurl} = $maptitle;
2387: }
2388: if ($maptitle ne '') {
2389: $title .= ' '.&mt('(in [_1])',$maptitle);
2390: }
2391: $titles->{$symb} = $title;
2392: }
2393: } else {
2394: $title = $symb;
2395: }
2396: return $title;
2397: }
2398:
2399: sub reservationlog_contexts {
2400: my ($crstype) = @_;
2401: my %lt = &Apache::lonlocal::texthash (
2402: any => 'Any',
2403: user => 'By student',
2404: manage => 'Via Slot Manager',
2405: parameter => 'Via Parameter Manager',
2406: reserve => 'Made reservation',
2407: release => 'Dropped reservation',
2408: usermanage => 'By student',
2409: );
2410: if ($crstype eq 'Community') {
2411: $lt{'user'} = &mt('By member');
2412: $lt{'usermanage'} = $lt{'user'};
2413: }
2414: return %lt;
2415: }
2416:
2417: sub display_filter {
2418: my ($formname,$cdom,$cnum,$curr,$version,$allsymbs) = @_;
2419: my $nolink = 1;
2420: my (%titles,%maptitles);
2421: my $output = '<br /><table><tr><td valign="top">'.
2422: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b><br />'.
2423: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
2424: (&mt('all'),5,10,20,50,100,1000,10000)).
2425: '</td><td> </td>';
2426: my $startform =
2427: &Apache::lonhtmlcommon::date_setter($formname,'log_start_date',
2428: $curr->{'log_start_date'},undef,
2429: undef,undef,undef,undef,undef,undef,$nolink);
2430: my $endform =
2431: &Apache::lonhtmlcommon::date_setter($formname,'log_end_date',
2432: $curr->{'log_end_date'},undef,
2433: undef,undef,undef,undef,undef,undef,$nolink);
2434: my $crstype = &Apache::loncommon::course_type();
2435: my %lt = &reservationlog_contexts($crstype);
2436: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').
2437: '</b><br /><table><tr><td>'.&mt('After:').
2438: '</td><td>'.$startform.'</td></tr><tr><td>'.&mt('Before:').'</td><td>'.
2439: $endform.'</td></tr></table></td><td> </td>';
2440: if (ref($allsymbs) eq 'ARRAY') {
2441: $output .= '<td valign="top"><b>'.&mt('Resource').'</b><br />'.
2442: '<select name="resource"><option value="any"';
2443: if ($curr->{'resource'} eq 'any') {
2444: $output .= ' selected="selected"';
2445: }
2446: $output .= '>'.&mt('Any').'</option>'."\n";
2447: foreach my $symb (@{$allsymbs}) {
2448: my $title = &get_resource_title($symb,\%titles,\%maptitles);
2449: my $selstr = '';
2450: if ($curr->{'resource'} eq $symb) {
2451: $selstr = ' selected="selected"';
2452: }
2453: $output .= ' <option value="'.$symb.'"'.$selstr.'>'.$title.'</option>';
2454: }
2455: $output .= '</select></td><td> </td><td valign="top"><b>'.
2456: &mt('Context:').'</b><br /><select name="chgcontext">';
2457: foreach my $chgtype ('any','user','manage','parameter') {
2458: my $selstr = '';
2459: if ($curr->{'chgcontext'} eq $chgtype) {
2460: $output .= $selstr = ' selected="selected"';
2461: }
2462: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
2463: }
2464: $output .= '</select></td>';
2465: } else {
2466: $output .= '<td valign="top"><b>'.&mt('Action').'</b><br />'.
2467: '<select name="action"><option value="any"';
2468: if ($curr->{'action'} eq 'any') {
2469: $output .= ' selected="selected"';
2470: }
2471: $output .= '>'.&mt('Any').'</option>'."\n";
2472: foreach my $actiontype ('reserve','release') {
2473: my $selstr = '';
2474: if ($curr->{'action'} eq $actiontype) {
2475: $output .= $selstr = ' selected="selected"';
2476: }
2477: $output .= '<option value="'.$actiontype.'"'.$selstr.'>'.$lt{$actiontype}.'</option>'."\n";
2478: }
2479: $output .= '</select></td>';
2480: }
2481: $output .= '<td> </td></tr></table>'.
2482: '<p><input type="submit" value="'.
2483: &mt('Update Display').'" /></p>'.
2484: '<p class="LC_info">'.
2485: &mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
2486: ,'2.9.0');
2487: if ($version) {
2488: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
2489: }
2490: $output .= '</p><hr /><br />';
2491: return $output;
2492: }
2493:
2494: sub slot_change_messaging {
2495: my ($setting,$subject,$msg,$action) = @_;
2496: my $user = $env{'user.name'};
2497: my $domain = $env{'user.domain'};
2498: my ($message_status,$comment_status);
2499: if ($setting eq 'only_student'
2500: || $setting eq 'student_and_user_notes_screen') {
2501: $message_status =
2502: &Apache::lonmsg::user_normal_msg($user,$domain,$subject,$msg);
2503: $message_status = '<li>'.&mt('Sent to you: [_1]',
2504: $message_status).' </li>';
2505: }
2506: if ($setting eq 'student_and_user_notes_screen') {
2507: $comment_status =
2508: &Apache::lonmsg::store_instructor_comment($subject.'<br />'.
2509: $msg,$user,$domain);
2510: $comment_status = '<li>'.&mt('Entry added to course record (viewable by instructor): [_1]',
2511: $comment_status).'</li>';
2512: }
2513: if ($message_status || $comment_status) {
2514: my $msgtitle;
2515: if ($action eq 'reserve') {
2516: $msgtitle = &mt('Status of messages about saved reservation');
2517: } elsif ($action eq 'release') {
2518: $msgtitle = &mt('Status of messages about dropped reservation');
2519: } elsif ($action eq 'nochange') {
2520: $msgtitle = &mt('Status of messages about unchanged existing reservation');
2521: }
2522: return '<span class="LC_info">'.$msgtitle.'</span>'
2523: .'<ul>'
2524: .$message_status
2525: .$comment_status
2526: .'</ul><hr />';
2527: }
2528: }
2529:
2530: sub upload_start {
2531: my ($r)=@_;
2532: $r->print(
2533: &Apache::grades::checkforfile_js()
2534: .'<h2>'.&mt('Upload a file containing the slot definitions').'</h2>'
2535: .'<form method="post" enctype="multipart/form-data"'
2536: .' action="/adm/slotrequest" name="slotupload">'
2537: .'<input type="hidden" name="command" value="csvuploadmap" />'
2538: .&Apache::lonhtmlcommon::start_pick_box()
2539: .&Apache::lonhtmlcommon::row_title(&mt('File'))
2540: .&Apache::loncommon::upfile_select_html()
2541: .&Apache::lonhtmlcommon::row_closure()
2542: .&Apache::lonhtmlcommon::row_title(
2543: '<label for="noFirstLine">'
2544: .&mt('Ignore First Line')
2545: .'</label>')
2546: .'<input type="checkbox" name="noFirstLine" id="noFirstLine" />'
2547: .&Apache::lonhtmlcommon::row_closure(1)
2548: .&Apache::lonhtmlcommon::end_pick_box()
2549: .'<p>'
2550: .'<input type="button" onclick="javascript:checkUpload(this.form);"'
2551: .' value="'.&mt('Next').'" />'
2552: .'</p>'
2553: .'</form>'
2554: );
2555: }
2556:
2557: sub csvuploadmap_header {
2558: my ($r,$datatoken,$distotal)= @_;
2559: my $javascript;
2560: if ($env{'form.upfile_associate'} eq 'reverse') {
2561: $javascript=&csvupload_javascript_reverse_associate();
2562: } else {
2563: $javascript=&csvupload_javascript_forward_associate();
2564: }
2565:
2566: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
2567: my $ignore=&mt('Ignore First Line');
2568: my $buttontext = &mt('Reverse Association');
2569:
2570: $r->print(
2571: '<form method="post" enctype="multipart/form-data" action="/adm/slotrequest" name="slotupload">'
2572: .'<h2>'.&mt('Identify fields in uploaded list').'</h2>'
2573: .'<div class="LC_columnSection">'
2574: .&Apache::loncommon::help_open_topic(
2575: 'Slot About',&mt('Help on slots'))
2576: .' '.&Apache::loncommon::help_open_topic(
2577: 'Slot SelectingField',&mt('Help on selecting Fields'))
2578: ."</div>\n"
2579: .'<p class="LC_info">'
2580: .&mt('Total number of records found in file: [_1]','<b>'.$distotal.'</b>')
2581: ."</p>\n"
2582: );
2583: if ($distotal == 0) {
2584: $r->print('<p class="LC_warning">'.&mt('None found').'</p>');
2585: }
2586: $r->print(
2587: '<p>'
2588: .&mt('Enter as many fields as you can.').'<br />'
2589: .&mt('The system will inform you and bring you back to this page,[_1]if the data selected is insufficient to create the slots.','<br />')
2590: .'</p>'
2591: );
2592: $r->print(
2593: '<div class="LC_left_float">'
2594: .'<fieldset><legend>'.&mt('Functions').'</legend>'
2595: .'<label><input type="checkbox" name="noFirstLine"'.$checked.' />'.$ignore.'</label>'
2596: .' <input type="button" value="'.$buttontext
2597: .'" onclick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />'
2598: .'</fieldset></div><br clear="all" />'
2599: );
2600:
2601: $r->print(<<ENDPICK);
2602: <input type="hidden" name="associate" value="" />
2603: <input type="hidden" name="datatoken" value="$datatoken" />
2604: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
2605: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
2606: <input type="hidden" name="upfile_associate"
2607: value="$env{'form.upfile_associate'}" />
2608: <input type="hidden" name="command" value="csvuploadassign" />
2609: <script type="text/javascript" language="Javascript">
2610: // <![CDATA[
2611: $javascript
2612: // ]]>
2613: </script>
2614: ENDPICK
2615: return '';
2616:
2617: }
2618:
2619: sub csvuploadmap_footer {
2620: my ($request,$i,$keyfields) =@_;
2621: my $buttontext = &mt('Create Slots');
2622: $request->print(<<ENDPICK);
2623: <input type="hidden" name="nfields" value="$i" />
2624: <input type="hidden" name="keyfields" value="$keyfields" />
2625: <input type="button" onclick="javascript:verify(this.form)" value="$buttontext" /><br />
2626: </form>
2627: ENDPICK
2628: }
2629:
2630: sub csvupload_javascript_reverse_associate {
2631: my $error1=&mt('You need to specify the name, start time, end time and a type.');
2632: return(<<ENDPICK);
2633: function verify(vf) {
2634: var foundstart=0;
2635: var foundend=0;
2636: var foundname=0;
2637: var foundtype=0;
2638: for (i=0;i<=vf.nfields.value;i++) {
2639: tw=eval('vf.f'+i+'.selectedIndex');
2640: if (i==0 && tw!=0) { foundname=1; }
2641: if (i==1 && tw!=0) { foundtype=1; }
2642: if (i==2 && tw!=0) { foundstat=1; }
2643: if (i==3 && tw!=0) { foundend=1; }
2644: }
2645: if (foundstart==0 && foundend==0 && foundtype==0 && foundname==0) {
2646: alert('$error1');
2647: return;
2648: }
2649: vf.submit();
2650: }
2651: function flip(vf,tf) {
2652: }
2653: ENDPICK
2654: }
2655:
2656: sub csvupload_javascript_forward_associate {
2657: my $error1=&mt('You need to specify the name, start time, end time and a type.');
2658: return(<<ENDPICK);
2659: function verify(vf) {
2660: var foundstart=0;
2661: var foundend=0;
2662: var foundname=0;
2663: var foundtype=0;
2664: for (i=0;i<=vf.nfields.value;i++) {
2665: tw=eval('vf.f'+i+'.selectedIndex');
2666: if (tw==1) { foundname=1; }
2667: if (tw==2) { foundtype=1; }
2668: if (tw==3) { foundstat=1; }
2669: if (tw==4) { foundend=1; }
2670: }
2671: if (foundstart==0 && foundend==0 && foundtype==0 && foundname==0) {
2672: alert('$error1');
2673: return;
2674: }
2675: vf.submit();
2676: }
2677: function flip(vf,tf) {
2678: }
2679: ENDPICK
2680: }
2681:
2682: sub csv_upload_map {
2683: my ($r)= @_;
2684:
2685: my $datatoken;
2686: if (!$env{'form.datatoken'}) {
2687: $datatoken=&Apache::loncommon::upfile_store($r);
2688: } else {
2689: $datatoken=&Apache::loncommon::valid_datatoken($env{'form.datatoken'});
2690: if ($datatoken ne '') {
2691: &Apache::loncommon::load_tmp_file($r,$datatoken);
2692: }
2693: }
2694: my @records=&Apache::loncommon::upfile_record_sep();
2695: if ($env{'form.noFirstLine'}) { shift(@records); }
2696: &csvuploadmap_header($r,$datatoken,$#records+1);
2697: my ($i,$keyfields);
2698: if (@records) {
2699: my @fields=&csvupload_fields();
2700:
2701: if ($env{'form.upfile_associate'} eq 'reverse') {
2702: &Apache::loncommon::csv_print_samples($r,\@records);
2703: $i=&Apache::loncommon::csv_print_select_table($r,\@records,
2704: \@fields);
2705: foreach (@fields) { $keyfields.=$_->[0].','; }
2706: chop($keyfields);
2707: } else {
2708: unshift(@fields,['none','']);
2709: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
2710: \@fields);
2711: my %sone=&Apache::loncommon::record_sep($records[0]);
2712: $keyfields=join(',',sort(keys(%sone)));
2713: }
2714: }
2715: &csvuploadmap_footer($r,$i,$keyfields);
2716:
2717: return '';
2718: }
2719:
2720: sub csvupload_fields {
2721: return (['name','Slot name'],
2722: ['type','Type of slot'],
2723: ['starttime','Start Time of slot'],
2724: ['endtime','End Time of slot'],
2725: ['startreserve','Reservation Start Time'],
2726: ['endreserve','Reservation End Time'],
2727: ['reservationmsg','Message when reservation changed'],
2728: ['ip','IP or DNS restriction'],
2729: ['proctor','List of proctor ids'],
2730: ['description','Slot Description'],
2731: ['maxspace','Maximum number of reservations'],
2732: ['symb','Resource Restriction'],
2733: ['uniqueperiod','Date range of slot exclusion'],
2734: ['secret','Secret word proctor uses to validate'],
2735: ['allowedsections','Sections slot is restricted to'],
2736: ['allowedusers','Users slot is restricted to'],
2737: );
2738: }
2739:
2740: sub csv_upload_assign {
2741: my ($r,$mgr)= @_;
2742: my $datatoken = &Apache::loncommon::valid_datatoken($env{'form.datatoken'});
2743: if ($datatoken ne '') {
2744: &Apache::loncommon::load_tmp_file($r,$datatoken);
2745: }
2746: my @slotdata = &Apache::loncommon::upfile_record_sep();
2747: if ($env{'form.noFirstLine'}) { shift(@slotdata); }
2748: my %fields=&Apache::grades::get_fields();
2749: $r->print('<h3>'.&mt('Creating Slots').'</h3>');
2750: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
2751: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2752: my $countdone=0;
2753: my @errors;
2754: foreach my $slot (@slotdata) {
2755: my %slot;
2756: my %entries=&Apache::loncommon::record_sep($slot);
2757: my $domain;
2758: my $name=$entries{$fields{'name'}};
2759: if ($name=~/^\s*$/) {
2760: push(@errors,"Did not create slot with no name");
2761: next;
2762: }
2763: if ($name=~/\s/) {
2764: push(@errors,"$name not created -- Name must not contain spaces");
2765: next;
2766: }
2767: if ($name=~/\W/) {
2768: push(@errors,"$name not created -- Name must contain only letters, numbers and _");
2769: next;
2770: }
2771: if ($entries{$fields{'type'}}) {
2772: $slot{'type'}=$entries{$fields{'type'}};
2773: } else {
2774: $slot{'type'}='preassigned';
2775: }
2776: if ($slot{'type'} ne 'preassigned' &&
2777: $slot{'type'} ne 'schedulable_student') {
2778: push(@errors,"$name not created -- invalid type ($slot{'type'}) must be either preassigned or schedulable_student");
2779: next;
2780: }
2781: if ($entries{$fields{'starttime'}}) {
2782: $slot{'starttime'}=&UnixDate($entries{$fields{'starttime'}},"%s");
2783: }
2784: if ($entries{$fields{'endtime'}}) {
2785: $slot{'endtime'}=&UnixDate($entries{$fields{'endtime'}},"%s");
2786: }
2787:
2788: # start/endtime must be defined and greater than zero
2789: if (!$slot{'starttime'}) {
2790: push(@errors,"$name not created -- Invalid start time");
2791: next;
2792: }
2793: if (!$slot{'endtime'}) {
2794: push(@errors,"$name not created -- Invalid end time");
2795: next;
2796: }
2797: if ($slot{'starttime'} > $slot{'endtime'}) {
2798: push(@errors,"$name not created -- Slot starts after it ends");
2799: next;
2800: }
2801:
2802: if ($entries{$fields{'startreserve'}}) {
2803: my $date = &UnixDate($entries{$fields{'startreserve'}},"%s");
2804: if ($date eq '') {
2805: push(@errors,"$name -- No reservation start time set for slot -- value provided had invalid format");
2806: } else {
2807: $slot{'startreserve'} = $date;
2808: }
2809: }
2810: if (defined($slot{'startreserve'})
2811: && $slot{'startreserve'} > $slot{'starttime'}) {
2812: push(@errors,"$name not created -- Slot's reservation start time is after the slot's start time.");
2813: next;
2814: }
2815:
2816: if ($entries{$fields{'endreserve'}}) {
2817: my $date = &UnixDate($entries{$fields{'endreserve'}},"%s");
2818: if ($date eq '') {
2819: push(@errors,"$name -- No reservation end time set for slot -- value provided had invalid format");
2820: } else {
2821: $slot{'endreserve'} = $date;
2822: }
2823: }
2824: if (defined($slot{'endreserve'})
2825: && $slot{'endreserve'} > $slot{'starttime'}) {
2826: push(@errors,"$name not created -- Slot's reservation end time is after the slot's start time.");
2827: next;
2828: }
2829:
2830: if ($slot{'type'} eq 'schedulable_student') {
2831: if ($entries{$fields{'reservationmsg'}}) {
2832: if (($entries{$fields{'reservationmsg'}} eq 'only_student') ||
2833: ($entries{$fields{'reservationmsg'}} eq 'student_and_user_notes_screen')) {
2834: $slot{'reservationmsg'}=$entries{$fields{'reservationmsg'}};
2835: } else {
2836: unless (($entries{$fields{'reservationmsg'}} eq 'none') ||
2837: ($entries{$fields{'reservationmsg'}} eq '')) {
2838: push(@errors,"$name -- Slot's reservationmsg setting ignored - not one of: 'only_student', 'student_and_user_notes_screen', 'none' or ''");
2839: }
2840: }
2841: }
2842: }
2843:
2844: foreach my $key ('ip','proctor','description','maxspace',
2845: 'secret','symb') {
2846: if ($entries{$fields{$key}}) {
2847: $slot{$key}=$entries{$fields{$key}};
2848: }
2849: }
2850: if ($entries{$fields{'allowedusers'}}) {
2851: $entries{$fields{'allowedusers'}} =~ s/^\s+//;
2852: $entries{$fields{'allowedusers'}} =~ s/\s+$//;
2853: my @allowedusers;
2854: foreach my $poss (split(/\s*,\s*/,$entries{$fields{'allowedusers'}})) {
2855: my ($possuname,$possudom) = split(/:/,$poss);
2856: if (($possuname =~ /^$match_username$/) && ($possudom =~ /^$match_domain$/)) {
2857: unless (grep(/^\Q$poss\E$/,@allowedusers)) {
2858: push(@allowedusers,$poss);
2859: }
2860: }
2861: }
2862: if (@allowedusers > 0) {
2863: $slot{'allowedusers'} = join(',',@allowedusers);
2864: }
2865: }
2866: if ($entries{$fields{'allowedsections'}}) {
2867: $entries{$fields{'allowedsections'}} =~ s/^\s+//;
2868: $entries{$fields{'allowedsections'}} =~ s/\s+$//;
2869: my @allowedsections;
2870: foreach my $poss (split(/\s*,\s*/,$entries{$fields{'allowedsections'}})) {
2871: if (($poss !~ /\W/) && ($poss ne 'none')) {
2872: unless (grep(/^\Q$poss\E$/,@allowedsections)) {
2873: push(@allowedsections,$poss);
2874: }
2875: }
2876: }
2877: if (@allowedsections > 0) {
2878: $slot{'allowedsections'} = join(',',@allowedsections);
2879: }
2880: }
2881: if ($entries{$fields{'uniqueperiod'}}) {
2882: my ($start,$end)= map { &UnixDate($_,"%s"); } split(',',$entries{$fields{'uniqueperiod'}});
2883: if (($start ne '') && ($end ne '')) {
2884: $slot{'uniqueperiod'}=[$start,$end];
2885: } else {
2886: push(@errors,"$name -- Slot's unique period ignored -- one or both of the comma separated values for start and end had an invalid format");
2887: }
2888: }
2889: if (ref($slot{'uniqueperiod'}) eq 'ARRAY'
2890: && $slot{'uniqueperiod'}[0] > $slot{'uniqueperiod'}[1]) {
2891: push(@errors,"$name not created -- Slot's unique period start time is later than the unique period's end time.");
2892: next;
2893: }
2894:
2895: &Apache::lonnet::cput('slots',{$name=>\%slot},$cdom,$cname);
2896: $r->print('.');
2897: $r->rflush();
2898: $countdone++;
2899: }
2900: if ($countdone) {
2901: &Apache::lonnet::devalidate_slots_cache($cname,$cdom);
2902: }
2903: $r->print('<p>'.&mt('Created [quant,_1,slot]',$countdone)."\n".'</p>');
2904: foreach my $error (@errors) {
2905: $r->print('<p><span class="LC_warning">'.$error.'</span></p>'."\n");
2906: }
2907: &show_table($r,$mgr);
2908: return '';
2909: }
2910:
2911: sub slot_command_titles {
2912: my %titles = (
2913: slotlog => 'Reservation Logs',
2914: showslots => 'Manage Slots',
2915: showresv => 'Reservation History',
2916: manageresv => 'Manage Reservations',
2917: uploadstart => 'Upload Slots File',
2918: csvuploadmap => 'Upload Slots File',
2919: csvuploadassign => 'Upload Slots File',
2920: delete => 'Slot Deletion',
2921: release => 'Reservation Result',
2922: remove_reservation => 'Remove Registration',
2923: get_reservation => 'Request Reservation',
2924: );
2925: return %titles;
2926: }
2927:
2928: sub slot_reservationmsg_options {
2929: my %options = &Apache::lonlocal::texthash (
2930: only_student => 'Sent to student',
2931: student_and_user_notes_screen => 'Sent to student and added to user notes',
2932: none => 'None sent and no record in user notes',
2933: );
2934: return %options;
2935: }
2936:
2937: sub handler {
2938: my $r=shift;
2939:
2940: &Apache::loncommon::content_type($r,'text/html');
2941: &Apache::loncommon::no_cache($r);
2942: if ($r->header_only()) {
2943: $r->send_http_header();
2944: return OK;
2945: }
2946:
2947: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
2948:
2949: my %crumb_titles = &slot_command_titles();
2950: my $brcrum;
2951:
2952: my $vgr=&Apache::lonnet::allowed('vgr',$env{'request.course.id'});
2953: my $mgr=&Apache::lonnet::allowed('mgr',$env{'request.course.id'});
2954: my (%slots,$consumed_uniqueperiods);
2955: if ($env{'form.command'} eq 'showslots') {
2956: if (($vgr ne 'F') && ($mgr ne 'F')) {
2957: $env{'form.command'} = 'manageresv';
2958: }
2959: } elsif ($env{'form.command'} eq 'manageresv') {
2960: if (($vgr eq 'F') || ($mgr eq 'F')) {
2961: $env{'form.command'} = 'showslots';
2962: }
2963: }
2964: my $title='Requesting Another Worktime';
2965: if ($env{'form.command'} eq 'showresv') {
2966: $title = 'Reservation History';
2967: if ($env{'form.origin'} eq 'aboutme') {
2968: $brcrum =[{href=>"/adm/$env{'form.udom'}/$env{'form.uname'}/aboutme",text=>'Personal Information Page'}];
2969: } else {
2970: $brcrum =[{href=>"/adm/slotrequest?command=manageresv",text=>'Manage Reservations'}];
2971: }
2972: if (ref($brcrum) eq 'ARRAY') {
2973: push(@{$brcrum},{href=>"/adm/slotrequest?command=showresv",text=>$title});
2974: }
2975: } elsif (($env{'form.requestattempt'}) || ($env{'form.command'} eq 'manageresv')) {
2976: if ($env{'form.command'} eq 'manageresv') {
2977: $title = 'Manage Reservations';
2978: $brcrum =[{href=>"/adm/slotrequest?command=manageresv",text=>$title}];
2979: }
2980: my ($cnum,$cdom)=&get_course();
2981: %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
2982: $consumed_uniqueperiods = &get_consumed_uniqueperiods(\%slots);
2983: } elsif ($vgr eq 'F') {
2984: if ($env{'form.command'} =~ /^(slotlog|showslots|uploadstart|csvuploadmap|csvuploadassign|delete|release|remove_registration)$/) {
2985: $brcrum =[{href=>"/adm/slotrequest?command=showslots",
2986: text=>$crumb_titles{'showslots'}}];
2987: $title = 'Managing Slots';
2988: unless ($env{'form.command'} eq 'showslots') {
2989: if (ref($brcrum) eq 'ARRAY') {
2990: push(@{$brcrum},{href=>"/adm/slotrequest?command=$env{'form.command'}",text=>$crumb_titles{$env{'form.command'}}});
2991: }
2992: }
2993: }
2994: } elsif ($env{'form.command'} eq 'release') {
2995: if ($env{'form.context'} eq 'usermanage') {
2996: $brcrum =[{href=>"/adm/slotrequest?command=manageresv",
2997: text=>$crumb_titles{'showslots'}}];
2998: $title = 'Manage Reservations';
2999: if (ref($brcrum) eq 'ARRAY') {
3000: push(@{$brcrum},{href=>"/adm/slotrequest?command=$env{'form.command'}",text=>$crumb_titles{$env{'form.command'}}});
3001: }
3002: }
3003: } else {
3004: $brcrum =[];
3005: }
3006: my ($symb,$js,$available,$allavailable,$got_slots);
3007: $available = [];
3008: if ($env{'form.requestattempt'}) {
3009: $symb=&unescape($env{'form.symb'});
3010: @{$got_slots}=&check_for_reservation($symb,'allslots');
3011: }
3012: if (($env{'form.requestattempt'}) || ($env{'form.command'} eq 'manageresv')) {
3013: $js = &reservation_js(\%slots,$consumed_uniqueperiods,$available,$got_slots,$symb);
3014: }
3015: &start_page($r,$title,$brcrum,$js);
3016:
3017: if ($env{'form.command'} eq 'manageresv') {
3018: $allavailable = $available;
3019: undef($available);
3020: undef($got_slots);
3021: my $crstype = &Apache::loncommon::course_type();
3022: &manage_reservations($r,$crstype,\%slots,$consumed_uniqueperiods,$allavailable);
3023: } elsif ($env{'form.command'} eq 'showresv') {
3024: &show_reservations($r,$env{'form.uname'},$env{'form.udom'});
3025: } elsif ($env{'form.command'} eq 'showslots' && $vgr eq 'F') {
3026: &show_table($r,$mgr);
3027: } elsif ($env{'form.command'} eq 'remove_registration' && $mgr eq 'F') {
3028: &remove_registration($r);
3029: } elsif ($env{'form.command'} eq 'release' && $mgr eq 'F') {
3030: if ($env{'form.entry'} eq 'remove all') {
3031: &release_all_slot($r,$mgr);
3032: } else {
3033: &release_slot($r,undef,undef,undef,$mgr);
3034: }
3035: } elsif ($env{'form.command'} eq 'delete' && $mgr eq 'F') {
3036: &delete_slot($r);
3037: } elsif ($env{'form.command'} eq 'uploadstart' && $mgr eq 'F') {
3038: &upload_start($r);
3039: } elsif ($env{'form.command'} eq 'csvuploadmap' && $mgr eq 'F') {
3040: &csv_upload_map($r);
3041: } elsif ($env{'form.command'} eq 'csvuploadassign' && $mgr eq 'F') {
3042: if ($env{'form.associate'} ne 'Reverse Association') {
3043: &csv_upload_assign($r,$mgr);
3044: } else {
3045: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
3046: $env{'form.upfile_associate'} = 'reverse';
3047: } else {
3048: $env{'form.upfile_associate'} = 'forward';
3049: }
3050: &csv_upload_map($r);
3051: }
3052: } elsif (($env{'form.command'} eq 'slotlog') && ($vgr eq 'F')) {
3053: &show_reservations_log($r);
3054: } else {
3055: my $symb=&unescape($env{'form.symb'});
3056: if (!defined($symb)) {
3057: &fail($r,'not_valid');
3058: return OK;
3059: }
3060: my (undef,undef,$res)=&Apache::lonnet::decode_symb($symb);
3061: my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb);
3062: if ($useslots ne 'resource'
3063: && $useslots ne 'map'
3064: && $useslots ne 'map_map') {
3065: &fail($r,'not_available');
3066: return OK;
3067: }
3068: $env{'request.symb'}=$symb;
3069: my $type = ($res =~ /\.task$/) ? 'Task'
3070: : 'problem';
3071: my ($status) = &Apache::lonhomework::check_slot_access('0',$type);
3072: if ($status eq 'CAN_ANSWER' ||
3073: $status eq 'NEEDS_CHECKIN' ||
3074: $status eq 'WAITING_FOR_GRADE') {
3075: &fail($r,'not_allowed');
3076: return OK;
3077: }
3078: if ($env{'form.requestattempt'}) {
3079: $r->print('<div class="LC_left_float">');
3080: &show_choices($r,$symb,undef,undef,\%slots,$consumed_uniqueperiods,$available,$got_slots);
3081: $r->print('</div><div style="padding:0;clear:both;margin:0;border:0"></div>');
3082: } elsif ($env{'form.command'} eq 'release') {
3083: &release_slot($r,$symb);
3084: } elsif ($env{'form.command'} eq 'get') {
3085: &get_slot($r,$symb);
3086: } elsif ($env{'form.command'} eq 'change') {
3087: if ($env{'form.nochange'}) {
3088: my $slot_name = $env{'form.releaseslot'};
3089: my @slots = &check_for_reservation($symb,'allslots');
3090: my $msg;
3091: if (($slot_name ne '') && (grep(/^\Q$slot_name\E/,@slots))) {
3092: my %slot=&Apache::lonnet::get_slot($env{'form.releaseslot'});
3093: my $description=&get_description($slot_name,\%slot);
3094: $msg = '<span style="font-weight: bold;">'.
3095: &mt('Unchanged reservation: [_1]',$description).'</span><br /><br />';
3096: my $person =
3097: &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
3098: my $subject = &mt('Reservation unchanged: [_1]',$description);
3099: my $msgbody = &mt('No change to existing registration by [_1] for [_2].',$person,$description);
3100: $msg .= &slot_change_messaging($slot{'reservationmsg'},$subject,$msgbody,'nochange');
3101: } else {
3102: $msg = '<span class="LC_warning">'.&mt('Reservation no longer reported as available.').'</span>';
3103: }
3104: $r->print($msg);
3105: &return_link($r);
3106: } elsif (&get_slot($r,$symb,$env{'form.releaseslot'},1)) {
3107: &release_slot($r,$symb,$env{'form.releaseslot'});
3108: }
3109: } else {
3110: $r->print('<p>'.&mt('Unknown command: [_1]',$env{'form.command'}).'</p>');
3111: }
3112: }
3113: &end_page($r);
3114: return OK;
3115: }
3116:
3117: 1;
3118: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>