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.2 2016/08/08 21:18:31 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: my ($cnum,$cdom)=&get_course();
733:
734: # get slot reservations, check if user has one, if so remove reservation
735: my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
736: "^$slot_name\0");
737: foreach my $entry (keys(%consumed)) {
738: if ( $consumed{$entry}->{'name'} eq ($uname.':'.$udom) ) {
739: &Apache::lonnet::del('slot_reservations',[$entry],
740: $cdom,$cnum);
741: my %storehash = (
742: symb => $symb,
743: slot => $slot_name,
744: action => 'release',
745: context => $env{'form.context'},
746: );
747: &Apache::lonnet::write_log('slotreservationslog',\%storehash,
748: 1,$uname,$udom,$cnum,$cdom);
749: &Apache::lonnet::write_log($cdom.'_'.$cnum.'_slotlog',\%storehash,
750: 1,$uname,$udom,$uname,$udom);
751: }
752: }
753:
754: my $use_slots = &Apache::lonnet::EXT("resource.0.useslots",
755: $symb,$udom,$uname);
756: &Apache::lonxml::debug("use_slots is $use_slots<br />");
757:
758: if (&Apache::lonnet::error($use_slots)) {
759: return (0,'error: Unable to determine current status');
760: }
761:
762: my $parm_level = 1;
763: if ($use_slots eq 'map' || $use_slots eq 'map_map') {
764: $parm_level = 2;
765: }
766: # store new parameter string
767: my $result=&Apache::lonparmset::storeparm_by_symb($symb,
768: '0_availablestudent',
769: $parm_level, $new_param,
770: 'string', $uname, $udom);
771: my $msg;
772: if ($mgr eq 'F') {
773: $msg = &mt('Released Reservation for user: [_1]',"$uname:$udom");
774: } else {
775: $msg = '<span style="font-weight: bold;">'.&mt('Released reservation: [_1]',$description).'</span><br /><br />';
776: my $person = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
777: my $subject = &mt('Reservation change: [_1]',$description);
778: my $msgbody = &mt('Reservation released by [_1] for [_2].',$person,$description);
779: $msg .= &slot_change_messaging($slot{'reservationmsg'},$subject,$msgbody,'release');
780: }
781: return (1,$msg);
782: }
783:
784: sub delete_slot {
785: my ($r)=@_;
786:
787: my $slot_name = $env{'form.slotname'};
788: my %slot=&Apache::lonnet::get_slot($slot_name);
789:
790: my ($cnum,$cdom)=&get_course();
791: my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
792: "^$slot_name\0");
793: my ($tmp) = %consumed;
794: if ($tmp =~ /error: 2/) { undef(%consumed); }
795:
796: if (%slot && !%consumed) {
797: $slot{'type'} = 'deleted';
798: my $ret = &Apache::lonnet::cput('slots', {$slot_name => \%slot},
799: $cdom, $cnum);
800: if ($ret eq 'ok') {
801: $r->print('<p>'.&mt('Slot [_1] marked as deleted.','<tt>'.$slot_name.'</tt>').'</p>');
802: } else {
803: $r->print('<p><span class="LC_error">'.&mt('An error occurred when attempting to delete slot: [_1]','<tt>'.$slot_name.'</tt>')." ($ret)</span></p>");
804: }
805: } else {
806: if (%consumed) {
807: $r->print('<p>'.&mt('Slot [_1] has active reservations.','<tt>'.$slot_name.'</tt>').'</p>');
808: } else {
809: $r->print('<p>'.&mt('Slot [_1] does not exist.','<tt>'.$slot_name.'</tt>').'</p>');
810: }
811: }
812: $r->print('<p><a href="/adm/slotrequest?command=showslots">'.
813: &mt('Return to slot list').'</a></p>');
814: &return_link($r);
815: }
816:
817: sub return_link {
818: my ($r) = @_;
819: if (($env{'form.command'} eq 'manageresv') || ($env{'form.context'} eq 'usermanage')) {
820: $r->print('<p><a href="/adm/slotrequest?command=manageresv">'.
821: &mt('Return to reservations'));
822: } else {
823: $r->print('<p><a href="/adm/flip?postdata=return:">'.
824: &mt('Return to last resource').'</a></p>');
825: }
826: }
827:
828: sub get_slot {
829: my ($r,$symb,$conflictable_slot,$inhibit_return_link)=@_;
830:
831: my %slot=&Apache::lonnet::get_slot($env{'form.slotname'});
832: my $slot_name=&check_for_conflict($symb,$env{'form.slotname'},\%slot);
833:
834: if ($slot_name =~ /^error: (.*)/) {
835: $r->print('<p><span class="LC_error">'
836: .&mt('An error occurred while attempting to make a reservation. ([_1])',$1)
837: .'</span></p>');
838: &return_link($r);
839: return 0;
840: }
841: if ($slot_name && $slot_name ne $conflictable_slot) {
842: my %slot=&Apache::lonnet::get_slot($slot_name);
843: my $description1=&get_description($slot_name,\%slot);
844: %slot=&Apache::lonnet::get_slot($env{'form.slotname'});
845: my $description2=&get_description($env{'form.slotname'},\%slot);
846: if ($slot_name ne $env{'form.slotname'}) {
847: $r->print(<<STUFF);
848: <form method="post" action="/adm/slotrequest">
849: <input type="hidden" name="symb" value="$env{'form.symb'}" />
850: <input type="hidden" name="slotname" value="$env{'form.slotname'}" />
851: <input type="hidden" name="releaseslot" value="$slot_name" />
852: <input type="hidden" name="command" value="change" />
853: STUFF
854: $r->print('<p class="LC_error">'.&mt('Reservation currently unchanged').'</p>');
855: if ($slot_name ne '') {
856: $r->print('<p>'.&mt('To complete the transaction you [_1]must confirm[_2] you want to [_3]process the change[_4] to [_5].'
857: ,'<b>','</b>','<i>','</i>','<b>'.$description2.'</b>')
858: .'<br />'
859: .&mt('Or you can choose to [_1]make no change[_2] and continue[_2] with the reservation you already had: [_3].'
860: ,'<i>','</i>','<b>'.$description1.'</b>')
861: .'</p><p><span class="LC_nobreak">'
862: .'<input type="submit" name="change" value="'.&mt('Process the change').'" />'
863: .(' 'x3)
864: .'<input type="submit" name="nochange" value="'.&mt('Make no change').'" />'
865: .'</span></p>');
866: }
867: $r->print(<<STUFF);
868: </form>
869: STUFF
870: } else {
871: $r->print('<p>'.&mt('Already have a reservation: [_1].',$description1).'</p>');
872: &return_link($r);
873: }
874: return 0;
875: }
876:
877: my ($cnum,$cdom)=&get_course();
878: my $reserved=&make_reservation($env{'form.slotname'},
879: \%slot,$symb,$cnum,$cdom);
880: my $description=&get_description($env{'form.slotname'},\%slot);
881: if (defined($reserved)) {
882: my $retvalue = 0;
883: if ($slot_name =~ /^error: (.*)/) {
884: $r->print('<p><span class="LC_error">'
885: .&mt('An error occurred while attempting to make a reservation. ([_1])',$1)
886: .'</span></p>');
887: } elsif ($reserved > -1) {
888: $r->print('<p style="font-weight: bold;">'.&mt('Successfully signed up: [_1]',$description).'</p>');
889: $retvalue = 1;
890: my $person = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
891: my $subject = &mt('Reservation change: [_1]',$description);
892: my $msgbody = &mt('Successful reservation by [_1] for [_2].',$person,$description);
893: my $msg = &slot_change_messaging($slot{'reservationmsg'},$subject,$msgbody,'reserve');
894: if ($msg) {
895: $r->print($msg);
896: }
897: } elsif ($reserved < 0) {
898: $r->print('<p>'.&mt('Already reserved: [_1]',$description).'</p>');
899: }
900: if (!$inhibit_return_link) { &return_link($r); }
901: return 1;
902: }
903:
904: my %lt = &Apache::lonlocal::texthash(
905: 'request' => 'Availability list',
906: 'try' => 'Try again?',
907: 'or' => 'or',
908: );
909:
910: my $extra_input;
911: if ($conflictable_slot) {
912: $extra_input='<input type="hidden" name="releaseslot" value="'.$env{'form.slotname'}.'" />';
913: }
914:
915: $r->print('<p>'.&mt('[_1]Failed[_2] to reserve a slot for [_3].','<span class="LC_warning">','</span>',$description).'</p>');
916: $r->print(<<STUFF);
917: <p>
918: <form method="post" action="/adm/slotrequest">
919: <input type="submit" name="Try Again" value="$lt{'try'}" />
920: <input type="hidden" name="symb" value="$env{'form.symb'}" />
921: <input type="hidden" name="slotname" value="$env{'form.slotname'}" />
922: <input type="hidden" name="command" value="$env{'form.command'}" />
923: $extra_input
924: </form>
925: </p>
926: <p>
927: $lt{'or'}
928: <form method="post" action="/adm/slotrequest">
929: <input type="hidden" name="symb" value="$env{'form.symb'}" />
930: <input type="submit" name="requestattempt" value="$lt{'request'}" />
931: </form>
932: STUFF
933:
934: if (!$inhibit_return_link) {
935: $r->print(&mt('or').'</p>');
936: &return_link($r);
937: } else {
938: $r->print('</p>');
939: }
940: return 0;
941: }
942:
943: sub allowed_slot {
944: my ($slot_name,$slot,$symb,$slots,$consumed_uniqueperiods,$toskip)=@_;
945:
946: #already started
947: if ($slot->{'starttime'} < time) {
948: return 0;
949: }
950: &Apache::lonxml::debug("$slot_name starttime good");
951:
952: #already ended
953: if ($slot->{'endtime'} < time) {
954: return 0;
955: }
956: &Apache::lonxml::debug("$slot_name endtime good");
957:
958: # not allowed to pick this one
959: if (defined($slot->{'type'})
960: && $slot->{'type'} ne 'schedulable_student') {
961: return 0;
962: }
963: &Apache::lonxml::debug("$slot_name type good");
964:
965: # reserve time not yet started
966: if ($slot->{'startreserve'} > time) {
967: return 0;
968: }
969: # reserve time ended
970: if (($slot->{'endreserve'}) &&
971: ($slot->{'endreserve'} < time)) {
972: return 0;
973: }
974: &Apache::lonxml::debug("$slot_name reserve good");
975:
976: my $userallowed=0;
977: # its for a different set of users
978: if (defined($slot->{'allowedsections'})) {
979: if (!defined($env{'request.role.sec'})
980: && grep(/^No section assigned$/,
981: split(',',$slot->{'allowedsections'}))) {
982: $userallowed=1;
983: }
984: if (defined($env{'request.role.sec'})
985: && grep(/^\Q$env{'request.role.sec'}\E$/,
986: split(',',$slot->{'allowedsections'}))) {
987: $userallowed=1;
988: }
989: if (defined($env{'request.course.groups'})) {
990: my @groups = split(/:/,$env{'request.course.groups'});
991: my @allowed_sec = split(',',$slot->{'allowedsections'});
992: foreach my $group (@groups) {
993: if (grep {$_ eq $group} (@allowed_sec)) {
994: $userallowed=1;
995: last;
996: }
997: }
998: }
999: }
1000: &Apache::lonxml::debug("$slot_name sections is $userallowed");
1001:
1002: # its for a different set of users
1003: if (defined($slot->{'allowedusers'})
1004: && grep(/^\Q$env{'user.name'}:$env{'user.domain'}\E$/,
1005: split(',',$slot->{'allowedusers'}))) {
1006: $userallowed=1;
1007: }
1008:
1009: if (!defined($slot->{'allowedusers'})
1010: && !defined($slot->{'allowedsections'})) {
1011: $userallowed=1;
1012: }
1013:
1014: &Apache::lonxml::debug("$slot_name user is $userallowed");
1015: return 0 if (!$userallowed);
1016:
1017: # not allowed for this resource
1018: if (defined($slot->{'symb'})
1019: && $slot->{'symb'} ne $symb) {
1020: unless ((ref($toskip) eq 'HASH') && ($toskip->{'symb'})) {
1021: return 0;
1022: }
1023: }
1024:
1025: my $conflict = &check_for_conflict($symb,$slot_name,$slot,$slots,
1026: $consumed_uniqueperiods);
1027: if ($conflict =~ /^error: /) {
1028: return 0;
1029: } elsif ($conflict ne '') {
1030: if ($slots->{$conflict}{'starttime'} < time) {
1031: return 0;
1032: }
1033: }
1034: &Apache::lonxml::debug("$slot_name symb good");
1035: return 1;
1036: }
1037:
1038: sub get_description {
1039: my ($slot_name,$slot)=@_;
1040: my $description=$slot->{'description'};
1041: if (!defined($description)) {
1042: $description=&mt('[_1] From [_2] to [_3]',$slot_name,
1043: &Apache::lonlocal::locallocaltime($slot->{'starttime'}),
1044: &Apache::lonlocal::locallocaltime($slot->{'endtime'}));
1045: }
1046: return $description;
1047: }
1048:
1049: sub show_choices {
1050: my ($r,$symb,$formname,$num,$slots,$consumed_uniqueperiods,$available,$got_slots)=@_;
1051: my $output;
1052: &Apache::lonxml::debug("Checking Slots");
1053: if (!ref($available) eq 'ARRAY') {
1054: return;
1055: }
1056: if (!@{$available}) {
1057: $output = '<span class="LC_info">'.&mt('No available times.').'</span>';
1058: if ($env{'form.command'} ne 'manageresv') {
1059: $output .= ' <a href="/adm/flip?postdata=return:">'.
1060: &mt('Return to last resource').'</a>';
1061: }
1062: $r->print($output);
1063: return;
1064: }
1065: if (@{$available} > 1) {
1066: my $numavailable = scalar(@{$available});
1067: my $numreserved = 0;
1068: my $js;
1069: my $j = 0;
1070: foreach my $got (@{$got_slots}) {
1071: unless (($got eq '') || (!defined($got))) {
1072: $numreserved ++;
1073: if ($env{'form.command'} eq 'manageresv') {
1074: $js .= " currslot[$j]='$got';\n";
1075: $j++;
1076: }
1077: }
1078: }
1079: my $showfilter = 'none';
1080: $output .= '<fieldset><legend>'.&mt('Actions').'</legend>'."\n".
1081: '<form method="post" name="reservationdisplay_'.$num.
1082: '" action="" onsubmit="toggleSlotDisplay(this.form,'."'$num'".');">';
1083: my @options = ('all','filter');
1084: if ($numreserved) {
1085: unshift(@options,'show');
1086: }
1087: my %resmenu = &Apache::lonlocal::texthash (
1088: show => 'Show current reservation',
1089: all => 'Show all',
1090: filter => 'Search by date',
1091: );
1092: foreach my $option (@options) {
1093: my $onclick = "toggleSlotDisplay(this.form,'$num');";
1094: if (($option eq 'show') && ($env{'form.command'} eq 'manageresv')) {
1095: $onclick .= "currSlotDisplay$num(this.form,'$num');";
1096: }
1097: $output .= '<span class="LC_nobreak"><label>'.
1098: '<input type="radio" class="LC_slotpick_radio" name="slotpick" value="'.
1099: $option.'" onclick="'.$onclick.'" />'.
1100: $resmenu{$option}.
1101: '</label></span>'.(' ' x3)."\n";
1102: }
1103: $output .= '</form>';
1104: my $chooserform = 'reservationchooser_'.$num;
1105: my $starttime = $slots->{$available->[0]}->{'starttime'};
1106: my $endtime = $slots->{$available->[-1]}->{'starttime'};
1107: if ($env{'form.command'} eq 'manageresv') {
1108: $output .= <<"ENDSCRIPT";
1109:
1110: <script type="text/javascript">
1111: // <![CDATA[
1112: function currSlotDisplay$num() {
1113: var currslot = new Array($numreserved);
1114: $js
1115: for (var j=0; j<$numreserved; j++) {
1116: if (document.getElementById('LC_slotrow_$num\_'+currslot[j])) {
1117: document.getElementById('LC_slotrow_$num\_'+currslot[j]).style.display = '';
1118: }
1119: }
1120: }
1121: // ]]>
1122: </script>
1123:
1124: ENDSCRIPT
1125: }
1126: $output .=
1127: '<div id="LC_slotfilter_'.$num.'" style="display:'.$showfilter.'">'.
1128: '<form method="post" name="'.$chooserform.'" action="">'.
1129: '<table><tr><td>'.&mt('Open after').'</td><td>'.
1130: &Apache::lonhtmlcommon::date_setter($chooserform,'start',$starttime,'','','','','','','',1,1).
1131: '</td></tr><tr><td>'.&mt('Closed before').'</td><td>'.
1132: &Apache::lonhtmlcommon::date_setter($chooserform,'end',$endtime,'','','','','','','',1,1).
1133: '</td></tr></table><br />'.
1134: '<input type="button" name="slotfilter" value="Search for reservable slots" onclick="updateSlotDisplay(this.form,'."'$num'".');" />'.
1135: '</form></div><div id="LC_slotsearch_'.$num.'" style="display:none"><hr />';
1136: }
1137: if ($env{'form.command'} eq 'manageresv') {
1138: $output .= '<table border="0">';
1139: } else {
1140: $output .= &Apache::loncommon::start_data_table();
1141: }
1142: foreach my $slot (@{$available}) {
1143: my $description=&get_description($slot,$slots->{$slot});
1144: my $form;
1145: if ((grep(/^\Q$slot\E$/,@{$got_slots})) ||
1146: &space_available($slot,$slots->{$slot},$symb)) {
1147: my $text=&mt('Select');
1148: my $command='get';
1149: if (grep(/^\Q$slot\E$/,@{$got_slots})) {
1150: $text=&mt('Drop Reservation');
1151: $command='release';
1152: } else {
1153: my $conflict = &check_for_conflict($symb,$slot,$slots->{$slot},
1154: $slots,$consumed_uniqueperiods);
1155: if ($conflict) {
1156: if ($conflict =~ /^error: /) {
1157: $form = '<span class="LC_error">'.
1158: &mt('Slot: [_1] has unknown status.',$description).
1159: '</span>';
1160: } else {
1161: $text=&mt('Change Reservation');
1162: $command='get';
1163: }
1164: }
1165: }
1166: my $escsymb=&escape($symb);
1167: if (!$form) {
1168: my $name;
1169: if ($formname) {
1170: $name = 'name="'.$formname.'"';
1171: }
1172: my $context = 'user';
1173: if ($env{'form.command'} eq 'manageresv') {
1174: $context = 'usermanage';
1175: }
1176: $form=<<STUFF;
1177: <form method="post" action="/adm/slotrequest" $name>
1178: <input type="submit" name="Select" value="$text" />
1179: <input type="hidden" name="symb" value="$escsymb" />
1180: <input type="hidden" name="slotname" value="$slot" />
1181: <input type="hidden" name="command" value="$command" />
1182: <input type="hidden" name="context" value="$context" />
1183: </form>
1184: STUFF
1185: }
1186: } else {
1187: $form = &mt('Unavailable');
1188: }
1189: if ($env{'form.command'} eq 'manageresv') {
1190: $output .= '<tr id="LC_slotrow_'.$num.'_'.$slot.'" >';
1191: } else {
1192: $output .= &Apache::loncommon::start_data_table_row('','LC_slotrow_'.$num.'_'.$slot);
1193: }
1194: $output .= "
1195: <td>$form</td>
1196: <td>$description</td>\n";
1197: if ($env{'form.command'} eq 'manageresv') {
1198: $output .= '</tr>';
1199: } else {
1200: $output .= &Apache::loncommon::end_data_table_row();
1201: }
1202: }
1203: if ($env{'form.command'} eq 'manageresv') {
1204: $output .= '</table>';
1205: } else {
1206: $output .= &Apache::loncommon::end_data_table();
1207: }
1208: if (@{$available} > 1) {
1209: $output .= '</div></fieldset>';
1210: }
1211: $r->print($output);
1212: return;
1213: }
1214:
1215: sub to_show {
1216: my ($slotname,$slot,$when,$deleted,$name) = @_;
1217: my $time=time;
1218: my $week=60*60*24*7;
1219:
1220: if ($deleted eq 'hide' && $slot->{'type'} eq 'deleted') {
1221: return 0;
1222: }
1223:
1224: if ($name && $name->{'value'} =~ /\w/) {
1225: if ($name->{'type'} eq 'substring') {
1226: if ($slotname !~ /\Q$name->{'value'}\E/) {
1227: return 0;
1228: }
1229: }
1230: if ($name->{'type'} eq 'exact') {
1231: if ($slotname eq $name->{'value'}) {
1232: return 0;
1233: }
1234: }
1235: }
1236:
1237: if ($when eq 'any') {
1238: return 1;
1239: } elsif ($when eq 'now') {
1240: if ($time > $slot->{'starttime'} &&
1241: $time < $slot->{'endtime'}) {
1242: return 1;
1243: }
1244: return 0;
1245: } elsif ($when eq 'nextweek') {
1246: if ( ($time < $slot->{'starttime'} &&
1247: ($time+$week) > $slot->{'starttime'})
1248: ||
1249: ($time < $slot->{'endtime'} &&
1250: ($time+$week) > $slot->{'endtime'}) ) {
1251: return 1;
1252: }
1253: return 0;
1254: } elsif ($when eq 'lastweek') {
1255: if ( ($time > $slot->{'starttime'} &&
1256: ($time-$week) < $slot->{'starttime'})
1257: ||
1258: ($time > $slot->{'endtime'} &&
1259: ($time-$week) < $slot->{'endtime'}) ) {
1260: return 1;
1261: }
1262: return 0;
1263: } elsif ($when eq 'willopen') {
1264: if ($time < $slot->{'starttime'}) {
1265: return 1;
1266: }
1267: return 0;
1268: } elsif ($when eq 'wereopen') {
1269: if ($time > $slot->{'endtime'}) {
1270: return 1;
1271: }
1272: return 0;
1273: }
1274:
1275: return 1;
1276: }
1277:
1278: sub remove_link {
1279: my ($slotname,$entry,$uname,$udom,$symb) = @_;
1280:
1281: my $remove = &mt('Remove');
1282:
1283: if ($entry eq 'remove all') {
1284: $remove = &mt('Remove All');
1285: undef($uname);
1286: undef($udom);
1287: }
1288:
1289: $slotname = &escape($slotname);
1290: $entry = &escape($entry);
1291: $uname = &escape($uname);
1292: $udom = &escape($udom);
1293: $symb = &escape($symb);
1294:
1295: return <<"END_LINK";
1296: <a href="/adm/slotrequest?command=remove_registration&slotname=$slotname&entry=$entry&uname=$uname&udom=$udom&symb=$symb&context=manage"
1297: >($remove)</a>
1298: END_LINK
1299:
1300: }
1301:
1302: sub show_table {
1303: my ($r,$mgr)=@_;
1304:
1305: my ($cnum,$cdom)=&get_course();
1306: my $crstype=&Apache::loncommon::course_type($cdom.'_'.$cnum);
1307: my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
1308: if ( (keys(%slots))[0] =~ /^error: 2 /) {
1309: undef(%slots);
1310: }
1311: my $available;
1312: if ($mgr eq 'F') {
1313: # FIXME: This line should be deleted once Slots uses breadcrumbs
1314: $r->print('<br />'.&Apache::loncommon::help_open_topic(
1315: 'Slot About', &mt('Help on slots')));
1316:
1317: $r->print('<div>');
1318: $r->print('<form method="post" action="/adm/slotrequest">
1319: <input type="hidden" name="command" value="uploadstart" />
1320: <input type="submit" name="start" value="'.&mt('Upload Slot List').'" />
1321: </form>');
1322: $r->print(&Apache::loncommon::help_open_topic('Slot CommaDelimited'));
1323: $r->print('<form method="post" action="/adm/helper/newslot.helper">
1324: <input type="submit" name="newslot" value="'.&mt('Create a New Slot').'" />
1325: </form>');
1326: $r->print(&Apache::loncommon::help_open_topic('Slot AddInterface'));
1327: $r->print('</div>');
1328: }
1329:
1330: if (!keys(%slots)) {
1331: $r->print(
1332: '<p class="LC_info">'
1333: .&mt('No slots have been created in this '.lc($crstype).'.')
1334: .'</p>'
1335: );
1336: return;
1337: }
1338:
1339: my %Saveable_Parameters = ('show' => 'array',
1340: 'when' => 'scalar',
1341: 'order' => 'scalar',
1342: 'deleted' => 'scalar',
1343: 'name_filter_type' => 'scalar',
1344: 'name_filter_value' => 'scalar',
1345: );
1346: &Apache::loncommon::store_course_settings('slotrequest',
1347: \%Saveable_Parameters);
1348: &Apache::loncommon::restore_course_settings('slotrequest',
1349: \%Saveable_Parameters);
1350: &Apache::grades::init_perm();
1351: my ($classlist,$section,$fullname)=&Apache::grades::getclasslist('all');
1352: &Apache::grades::reset_perm();
1353:
1354: # what to display filtering
1355: my %show_fields=&Apache::lonlocal::texthash(
1356: 'name' => 'Slot Name',
1357: 'description' => 'Description',
1358: 'type' => 'Type',
1359: 'starttime' => 'Start time',
1360: 'endtime' => 'End Time',
1361: 'startreserve' => 'Time students can start reserving',
1362: 'endreserve' => 'Time students can no longer reserve',
1363: 'reservationmsg' => 'Message triggered by reservation',
1364: 'secret' => 'Secret Word',
1365: 'space' => '# of students/max',
1366: 'ip' => 'IP or DNS restrictions',
1367: 'symb' => 'Resource slot is restricted to.',
1368: 'allowedsections' => 'Sections slot is restricted to.',
1369: 'allowedusers' => 'Users slot is restricted to.',
1370: 'uniqueperiod' => 'Period of time slot is unique',
1371: 'scheduled' => 'Scheduled Students',
1372: 'proctor' => 'List of proctors');
1373: if ($crstype eq 'Community') {
1374: $show_fields{'startreserve'} = &mt('Time members can start reserving');
1375: $show_fields{'endreserve'} = &mt('Time members can no longer reserve');
1376: $show_fields{'scheduled'} = &mt('Scheduled Members');
1377: }
1378: my @show_order=('name','description','type','starttime','endtime',
1379: 'startreserve','endreserve','reservationmsg','secret','space',
1380: 'ip','symb','allowedsections','allowedusers','uniqueperiod',
1381: 'scheduled','proctor');
1382: my @show =
1383: (exists($env{'form.show'})) ? &Apache::loncommon::get_env_multiple('form.show')
1384: : keys(%show_fields);
1385: my %show = map { $_ => 1 } (@show);
1386:
1387: #when filtering setup
1388: my %when_fields=&Apache::lonlocal::texthash(
1389: 'now' => 'Open now',
1390: 'nextweek' => 'Open within the next week',
1391: 'lastweek' => 'Were open last week',
1392: 'willopen' => 'Will open later',
1393: 'wereopen' => 'Were open',
1394: 'any' => 'Anytime',
1395: );
1396: my @when_order=('any','now','nextweek','lastweek','willopen','wereopen');
1397: $when_fields{'select_form_order'} = \@when_order;
1398: my $when = (exists($env{'form.when'})) ? $env{'form.when'}
1399: : 'now';
1400:
1401: #display of students setup
1402: my %stu_display_fields=
1403: &Apache::lonlocal::texthash('username' => 'User name',
1404: 'fullname' => 'Full name',
1405: );
1406: my @stu_display_order=('fullname','username');
1407: my @stu_display =
1408: (exists($env{'form.studisplay'})) ? &Apache::loncommon::get_env_multiple('form.studisplay')
1409: : keys(%stu_display_fields);
1410: my %stu_display = map { $_ => 1 } (@stu_display);
1411:
1412: #name filtering setup
1413: my %name_filter_type_fields=
1414: &Apache::lonlocal::texthash('substring' => 'Substring',
1415: 'exact' => 'Exact',
1416: #'reg' => 'Regular Expression',
1417: );
1418: my @name_filter_type_order=('substring','exact');
1419:
1420: $name_filter_type_fields{'select_form_order'} = \@name_filter_type_order;
1421: my $name_filter_type =
1422: (exists($env{'form.name_filter_type'})) ? $env{'form.name_filter_type'}
1423: : 'substring';
1424: my $name_filter = {'type' => $name_filter_type,
1425: 'value' => $env{'form.name_filter_value'},};
1426:
1427:
1428: #deleted slot filtering
1429: #default to hide if no value
1430: $env{'form.deleted'} ||= 'hide';
1431: my $hide_radio =
1432: &Apache::lonhtmlcommon::radio('deleted',$env{'form.deleted'},'hide');
1433: my $show_radio =
1434: &Apache::lonhtmlcommon::radio('deleted',$env{'form.deleted'},'show');
1435:
1436: $r->print('<form method="post" action="/adm/slotrequest">
1437: <input type="hidden" name="command" value="showslots" />');
1438: $r->print('<div>');
1439: $r->print('<table class="inline">
1440: <tr><th>'.&mt('Show').'</th>
1441: <th>'.&mt('Student Display').'</th>
1442: <th>'.&mt('Open').'</th>
1443: <th>'.&mt('Slot Name Filter').'</th>
1444: <th>'.&mt('Options').'</th>
1445: </tr>
1446: <tr><td valign="top">'.&Apache::loncommon::multiple_select_form('show',\@show,6,\%show_fields,\@show_order).
1447: '</td>
1448: <td valign="top">
1449: '.&Apache::loncommon::multiple_select_form('studisplay',\@stu_display,
1450: 6,\%stu_display_fields,
1451: \@stu_display_order).'
1452: </td>
1453: <td valign="top">'.&Apache::loncommon::select_form($when,'when',\%when_fields).
1454: '</td>
1455: <td valign="top">'.&Apache::loncommon::select_form($name_filter_type,
1456: 'name_filter_type',
1457: \%name_filter_type_fields).
1458: '<br />'.
1459: &Apache::lonhtmlcommon::textbox('name_filter_value',
1460: $env{'form.name_filter_value'},
1461: 15).
1462: '</td>
1463: <td valign="top">
1464: <table>
1465: <tr>
1466: <td rowspan="2">'.&mt('Deleted slots:').'</td>
1467: <td><label>'.$show_radio.&mt('Show').'</label></td>
1468: </tr>
1469: <tr>
1470: <td><label>'.$hide_radio.&mt('Hide').'</label></td>
1471: </tr>
1472: </table>
1473: </td>
1474: </tr>
1475: </table>');
1476: $r->print('</div>');
1477: $r->print('<p><input type="submit" name="start" value="'.&mt('Update Display').'" /></p>');
1478: my $linkstart='<a href="/adm/slotrequest?command=showslots&order=';
1479: $r->print(&Apache::loncommon::start_data_table().
1480: &Apache::loncommon::start_data_table_header_row().'
1481: <th></th>');
1482: foreach my $which (@show_order) {
1483: if ($which ne 'proctor' && exists($show{$which})) {
1484: $r->print('<th>'.$linkstart.$which.'">'.$show_fields{$which}.'</a></th>');
1485: }
1486: }
1487: $r->print(&Apache::loncommon::end_data_table_header_row());
1488:
1489: my %name_cache;
1490: my $slotsort = sub {
1491: if ($env{'form.order'}=~/^(type|description|endtime|startreserve|endreserve|ip|symb|allowedsections|allowedusers|reservationmsg)$/) {
1492: if (lc($slots{$a}->{$env{'form.order'}})
1493: ne lc($slots{$b}->{$env{'form.order'}})) {
1494: return (lc($slots{$a}->{$env{'form.order'}})
1495: cmp lc($slots{$b}->{$env{'form.order'}}));
1496: }
1497: } elsif ($env{'form.order'} eq 'space') {
1498: if ($slots{$a}{'maxspace'} ne $slots{$b}{'maxspace'}) {
1499: return ($slots{$a}{'maxspace'} cmp $slots{$b}{'maxspace'});
1500: }
1501: } elsif ($env{'form.order'} eq 'name') {
1502: if (lc($a) cmp lc($b)) {
1503: return lc($a) cmp lc($b);
1504: }
1505: } elsif ($env{'form.order'} eq 'uniqueperiod') {
1506:
1507: if ($slots{$a}->{'uniqueperiod'}[0]
1508: ne $slots{$b}->{'uniqueperiod'}[0]) {
1509: return ($slots{$a}->{'uniqueperiod'}[0]
1510: cmp $slots{$b}->{'uniqueperiod'}[0]);
1511: }
1512: if ($slots{$a}->{'uniqueperiod'}[1]
1513: ne $slots{$b}->{'uniqueperiod'}[1]) {
1514: return ($slots{$a}->{'uniqueperiod'}[1]
1515: cmp $slots{$b}->{'uniqueperiod'}[1]);
1516: }
1517: }
1518: return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'};
1519: };
1520:
1521: my %consumed;
1522: if (exists($show{'scheduled'}) || exists($show{'space'}) ) {
1523: %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum);
1524: my ($tmp)=%consumed;
1525: if ($tmp =~ /^error: /) { undef(%consumed); }
1526: }
1527:
1528: my %msgops = &slot_reservationmsg_options();
1529:
1530: foreach my $slot (sort $slotsort (keys(%slots))) {
1531: if (!&to_show($slot,$slots{$slot},$when,
1532: $env{'form.deleted'},$name_filter)) { next; }
1533: my $reservemsg;
1534: if (defined($slots{$slot}->{'type'})
1535: && $slots{$slot}->{'type'} eq 'schedulable_student') {
1536: $reservemsg = $msgops{$slots{$slot}->{'reservationmsg'}};
1537: }
1538: my $description=&get_description($slot,$slots{$slot});
1539: my ($id_count,$ids);
1540:
1541: if (exists($show{'scheduled'}) || exists($show{'space'}) ) {
1542: my $re_str = "$slot\0";
1543: my @this_slot = grep(/^\Q$re_str\E/,keys(%consumed));
1544: $id_count = scalar(@this_slot);
1545: if (exists($show{'scheduled'})) {
1546: foreach my $entry (sort { $consumed{$a}{name} cmp
1547: $consumed{$b}{name} }
1548: (@this_slot)) {
1549: my (undef,$id)=split("\0",$entry);
1550: my ($uname,$udom) = split(':',$consumed{$entry}{'name'});
1551: $ids.= '<span class="LC_nobreak">';
1552: foreach my $item (@stu_display_order) {
1553: if ($stu_display{$item}) {
1554: if ($item eq 'fullname') {
1555: $ids.=$fullname->{"$uname:$udom"}.' ';
1556: } elsif ($item eq 'username') {
1557: $ids.="<tt>$uname:$udom</tt> ";
1558: }
1559: }
1560: }
1561: $ids.=&remove_link($slot,$entry,$uname,$udom,
1562: $consumed{$entry}{'symb'}).'</span><br />';
1563: }
1564: }
1565: }
1566:
1567: my $start=($slots{$slot}->{'starttime'}?
1568: &Apache::lonlocal::locallocaltime($slots{$slot}->{'starttime'}):'');
1569: my $end=($slots{$slot}->{'endtime'}?
1570: &Apache::lonlocal::locallocaltime($slots{$slot}->{'endtime'}):'');
1571: my $start_reserve=($slots{$slot}->{'startreserve'}?
1572: &Apache::lonlocal::locallocaltime($slots{$slot}->{'startreserve'}):'');
1573: my $end_reserve=($slots{$slot}->{'endreserve'}?
1574: &Apache::lonlocal::locallocaltime($slots{$slot}->{'endreserve'}):'');
1575:
1576: my $unique;
1577: if (ref($slots{$slot}{'uniqueperiod'})) {
1578: $unique=localtime($slots{$slot}{'uniqueperiod'}[0]).', '.
1579: localtime($slots{$slot}{'uniqueperiod'}[1]);
1580: }
1581:
1582: my $title;
1583: if (exists($slots{$slot}{'symb'})) {
1584: my (undef,undef,$res)=
1585: &Apache::lonnet::decode_symb($slots{$slot}{'symb'});
1586: $res = &Apache::lonnet::clutter($res);
1587: $title = &Apache::lonnet::gettitle($slots{$slot}{'symb'});
1588: $title='<a href="'.$res.'?symb='.$slots{$slot}{'symb'}.'">'.$title.'</a>';
1589: }
1590:
1591: my $allowedsections;
1592: if (exists($show{'allowedsections'})) {
1593: $allowedsections =
1594: join(', ',sort(split(/\s*,\s*/,
1595: $slots{$slot}->{'allowedsections'})));
1596: }
1597:
1598: my @allowedusers;
1599: if (exists($show{'allowedusers'})) {
1600: @allowedusers= map {
1601: my ($uname,$udom)=split(/:/,$_);
1602: my $fullname=$name_cache{$_};
1603: if (!defined($fullname)) {
1604: $fullname = &Apache::loncommon::plainname($uname,$udom);
1605: $fullname =~s/\s/ /g;
1606: $name_cache{$_} = $fullname;
1607: }
1608: &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
1609: } (sort(split(/\s*,\s*/,$slots{$slot}->{'allowedusers'})));
1610: }
1611: my $allowedusers=join(', ',@allowedusers);
1612:
1613: my @proctors;
1614: my $rowspan=1;
1615: my $colspan=1;
1616: if (exists($show{'proctor'})) {
1617: $rowspan=2;
1618: @proctors= map {
1619: my ($uname,$udom)=split(/:/,$_);
1620: my $fullname=$name_cache{$_};
1621: if (!defined($fullname)) {
1622: $fullname = &Apache::loncommon::plainname($uname,$udom);
1623: $fullname =~s/\s/ /g;
1624: $name_cache{$_} = $fullname;
1625: }
1626: &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
1627: } (sort(split(/\s*,\s*/,$slots{$slot}->{'proctor'})));
1628: }
1629: my $proctors=join(', ',@proctors);
1630:
1631: my %lt = &Apache::lonlocal::texthash (
1632: edit => 'Edit',
1633: delete => 'Delete',
1634: slotlog => 'History',
1635: );
1636: my $edit=(<<"EDITLINK");
1637: <a href="/adm/helper/newslot.helper?name=$slot">$lt{'edit'}</a>
1638: EDITLINK
1639:
1640: my $delete=(<<"DELETELINK");
1641: <a href="/adm/slotrequest?command=delete&slotname=$slot">$lt{'delete'}</a>
1642: DELETELINK
1643:
1644: my $showlog=(<<"LOGLINK");
1645: <a href="/adm/slotrequest?command=slotlog&slotname=$slot">$lt{'slotlog'}</a>
1646: LOGLINK
1647:
1648: my $remove_all=&remove_link($slot,'remove all').'<br />';
1649:
1650: if ($ids eq '') {
1651: undef($remove_all);
1652: } else {
1653: undef($delete);
1654: }
1655: if ($slots{$slot}{'type'} ne 'schedulable_student') {
1656: undef($showlog);
1657: undef($remove_all);
1658: }
1659:
1660: my $row_start=&Apache::loncommon::start_data_table_row();
1661: my $row_end=&Apache::loncommon::end_data_table_row();
1662: $r->print($row_start.
1663: "\n<td rowspan=\"$rowspan\">$edit $delete $showlog</td>\n");
1664: if (exists($show{'name'})) {
1665: $colspan++;$r->print("<td>$slot</td>");
1666: }
1667: if (exists($show{'description'})) {
1668: $colspan++;$r->print("<td>$description</td>\n");
1669: }
1670: if (exists($show{'type'})) {
1671: $colspan++;$r->print("<td>$slots{$slot}->{'type'}</td>\n");
1672: }
1673: if (exists($show{'starttime'})) {
1674: $colspan++;$r->print("<td>$start</td>\n");
1675: }
1676: if (exists($show{'endtime'})) {
1677: $colspan++;$r->print("<td>$end</td>\n");
1678: }
1679: if (exists($show{'startreserve'})) {
1680: $colspan++;$r->print("<td>$start_reserve</td>\n");
1681: }
1682: if (exists($show{'endreserve'})) {
1683: $colspan++;$r->print("<td>$end_reserve</td>\n");
1684: }
1685: if (exists($show{'reservationmsg'})) {
1686: $colspan++;$r->print("<td>$reservemsg</td>\n");
1687: }
1688: if (exists($show{'secret'})) {
1689: $colspan++;$r->print("<td>$slots{$slot}{'secret'}</td>\n");
1690: }
1691: if (exists($show{'space'})) {
1692: my $display = $id_count;
1693: if ($slots{$slot}{'maxspace'}>0) {
1694: $display.='/'.$slots{$slot}{'maxspace'};
1695: if ($slots{$slot}{'maxspace'} <= $id_count) {
1696: $display = '<strong>'.$display.' (full) </strong>';
1697: }
1698: }
1699: $colspan++;$r->print("<td>$display</td>\n");
1700: }
1701: if (exists($show{'ip'})) {
1702: $colspan++;$r->print("<td>$slots{$slot}{'ip'}</td>\n");
1703: }
1704: if (exists($show{'symb'})) {
1705: $colspan++;$r->print("<td>$title</td>\n");
1706: }
1707: if (exists($show{'allowedsections'})) {
1708: $colspan++;$r->print("<td>$allowedsections</td>\n");
1709: }
1710: if (exists($show{'allowedusers'})) {
1711: $colspan++;$r->print("<td>$allowedusers</td>\n");
1712: }
1713: if (exists($show{'uniqueperiod'})) {
1714: $colspan++;$r->print("<td>$unique</td>\n");
1715: }
1716: if (exists($show{'scheduled'})) {
1717: $colspan++;$r->print("<td>$remove_all $ids</td>\n");
1718: }
1719: $r->print("$row_end\n");
1720: if (exists($show{'proctor'})) {
1721: $r->print(<<STUFF);
1722: $row_start
1723: <td colspan="$colspan">$proctors</td>
1724: $row_end
1725: STUFF
1726: }
1727: }
1728: $r->print(&Apache::loncommon::end_data_table().'</form>');
1729: return;
1730: }
1731:
1732: sub manage_reservations {
1733: my ($r,$crstype,$slots,$consumed_uniqueperiods,$allavailable) = @_;
1734: my $navmap = Apache::lonnavmaps::navmap->new();
1735: $r->print('<p>'
1736: .&mt('Instructors may use a reservation system to place restrictions on when and where assignments can be worked on.')
1737: .'<br />'
1738: .&mt('One example is for management of laboratory space, which is only available at certain times, and has a limited number of seats.')
1739: .'</p>'
1740: );
1741: if (!defined($navmap)) {
1742: $r->print('<div class="LC_error">');
1743: if ($crstype eq 'Community') {
1744: $r->print(&mt('Unable to retrieve information about community contents'));
1745: } else {
1746: $r->print(&mt('Unable to retrieve information about course contents'));
1747: }
1748: $r->print('</div>');
1749: &Apache::lonnet::logthis('Manage Reservations - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1750: return;
1751: }
1752: if (ref($consumed_uniqueperiods) eq 'HASH') {
1753: if (&Apache::lonnet::error(%$consumed_uniqueperiods)) {
1754: $r->print('<span class="LC_error">'.
1755: &mt('An error occurred determining slot availability.').
1756: '</span>');
1757: return;
1758: }
1759: } elsif ($consumed_uniqueperiods =~ /^error: /) {
1760: $r->print('<span class="LC_error">'.
1761: &mt('An error occurred determining slot availability.').
1762: '</span>');
1763: return;
1764: }
1765: my (%parent,%shownparent,%container,%container_title,%contents);
1766: my ($depth,$count,$reservable,$lastcontainer,$rownum) = (0,0,0,0,0);
1767: my @backgrounds = ("LC_odd_row","LC_even_row");
1768: my $numcolors = scalar(@backgrounds);
1769: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/whitespace_21.gif");
1770: my $slotheader = '<p>'.
1771: &mt('Your reservation status for any such assignments is listed below:').
1772: '</p>'.
1773: '<table class="LC_data_table LC_tableOfContent">'."\n";
1774: my $shownheader = 0;
1775: my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
1776: while (my $resource = $it->next()) {
1777: if ($resource == $it->BEGIN_MAP()) {
1778: $depth++;
1779: $parent{$depth} = $lastcontainer;
1780: }
1781: if ($resource == $it->END_MAP()) {
1782: $depth--;
1783: $lastcontainer = $parent{$depth};
1784: }
1785: if (ref($resource)) {
1786: my $symb = $resource->symb();
1787: my $ressymb = $symb;
1788: $contents{$lastcontainer} ++;
1789: next if (!$resource->is_problem() && !$resource->is_sequence() &&
1790: !$resource->is_page());
1791: $count ++;
1792: if (($resource->is_sequence()) || ($resource->is_page())) {
1793: $lastcontainer = $count;
1794: $container{$lastcontainer} = $resource;
1795: $container_title{$lastcontainer} = $resource->compTitle();
1796: }
1797: if ($resource->is_problem()) {
1798: my ($useslots) = $resource->slot_control();
1799: next if (($useslots eq '') || ($useslots =~ /^\s*no\s*$/i));
1800: my ($msg,$get_choices,$slotdescription);
1801: my $title = $resource->compTitle();
1802: my $status = $resource->simpleStatus('0');
1803: my ($slot_status,$date,$slot_name) = $resource->check_for_slot('0');
1804: if ($slot_name ne '') {
1805: my %slot=&Apache::lonnet::get_slot($slot_name);
1806: $slotdescription=&get_description($slot_name,\%slot);
1807: }
1808: if ($slot_status == $resource->NOT_IN_A_SLOT) {
1809: $msg=&mt('No current reservation.');
1810: $get_choices = 1;
1811: } elsif ($slot_status == $resource->NEEDS_CHECKIN) {
1812: $msg='<span class="LC_nobreak">'.&mt('Reserved:').
1813: ' '.$slotdescription.'</span><br />'.
1814: &mt('Access requires proctor validation.');
1815: } elsif ($slot_status == $resource->WAITING_FOR_GRADE) {
1816: $msg=&mt('Submitted and currently in grading queue.');
1817: } elsif ($slot_status == $resource->CORRECT) {
1818: $msg=&mt('Problem is unavailable.');
1819: } elsif ($slot_status == $resource->RESERVED) {
1820: $msg='<span class="LC_nobreak">'.&mt('Reserved:').
1821: ' '.$slotdescription.'</span><br />'.
1822: &mt('Problem is currently available.');
1823: } elsif ($slot_status == $resource->RESERVED_LOCATION) {
1824: $msg='<span class="LC_nobreak">'.&mt('Reserved:').
1825: ' '.$slotdescription.'</span><br />'.
1826: &mt('Problem is available at a different location.');
1827: $get_choices = 1;
1828: } elsif ($slot_status == $resource->RESERVED_LATER) {
1829: $msg='<span class="LC_nobreak">'.&mt('Reserved:').
1830: ' '.$slotdescription.'</span><br />'.
1831: &mt('Problem will be available later.');
1832: $get_choices = 1;
1833: } elsif ($slot_status == $resource->RESERVABLE) {
1834: $msg=&mt('Reservation needed');
1835: $get_choices = 1;
1836: } elsif ($slot_status == $resource->RESERVABLE_LATER) {
1837: $msg=&mt('Reservation needed: will be reservable later.');
1838: } elsif ($slot_status == $resource->NOTRESERVABLE) {
1839: $msg=&mt('Reservation needed: none available.');
1840: } elsif ($slot_status == $resource->UNKNOWN) {
1841: $msg=&mt('Unable to determine status due to network problems.');
1842: } else {
1843: if ($status != $resource->OPEN) {
1844: $msg = &Apache::lonnavmaps::getDescription($resource,'0');
1845: }
1846: }
1847: $reservable ++;
1848: my $treelevel = $depth;
1849: my $higherup = $lastcontainer;
1850: if ($depth > 1) {
1851: my @maprows;
1852: while ($treelevel > 1) {
1853: if (ref($container{$higherup})) {
1854: my $res = $container{$higherup};
1855: last if (defined($shownparent{$higherup}));
1856: my $maptitle = $res->compTitle();
1857: my $type = 'sequence';
1858: if ($res->is_page()) {
1859: $type = 'page';
1860: }
1861: &show_map_row($treelevel,$location,$type,$maptitle,
1862: \@maprows);
1863: $shownparent{$higherup} = 1;
1864: }
1865: $treelevel --;
1866: $higherup = $parent{$treelevel};
1867: }
1868: foreach my $item (@maprows) {
1869: $rownum ++;
1870: my $bgcolor = $backgrounds[$rownum % $numcolors];
1871: if (!$shownheader) {
1872: $r->print($slotheader);
1873: $shownheader = 1;
1874: }
1875: $r->print('<tr class="'.$bgcolor.'">'.$item.'</tr>'."\n");
1876: }
1877: }
1878: $rownum ++;
1879: my $bgcolor = $backgrounds[$rownum % $numcolors];
1880: if (!$shownheader) {
1881: $r->print($slotheader);
1882: $shownheader = 1;
1883: }
1884: $r->print('<tr class="'.$bgcolor.'"><td>'."\n");
1885: for (my $i=0; $i<$depth; $i++) {
1886: $r->print('<img src="'.$location.'" alt="" />');
1887: }
1888: my $result = '<a href="'.$resource->src().'?symb='.$symb.'">'.
1889: '<img class="LC_contentImage" src="/adm/lonIcons/';
1890: if ($resource->is_task()) {
1891: $result .= 'task.gif" alt="'.&mt('Task');
1892: } else {
1893: $result .= 'problem.gif" alt="'.&mt('Problem');
1894: }
1895: $result .= '" /><b>'.$title.'</b></a>'.(' ' x6).'</td>';
1896: my $hasaction;
1897: if ($status == $resource->OPEN) {
1898: if ($get_choices) {
1899: $hasaction = 1;
1900: }
1901: }
1902: if ($hasaction) {
1903: $result .= '<td valign="top">'.$msg.'</td>'.
1904: '<td valign="top">';
1905: } else {
1906: $result .= '<td colspan="2" valign="middle">'.$msg.'</td>';
1907: }
1908: $r->print($result);
1909: if ($hasaction) {
1910: my @got_slots=&check_for_reservation($symb,'allslots');
1911: if ($got_slots[0] =~ /^error: /) {
1912: $r->print('<span class="LC_error">'.
1913: &mt('An error occurred determining slot availability.').
1914: '</span>');
1915: } else {
1916: my $formname = 'manageres_'.$reservable;
1917: if (ref($allavailable) eq 'ARRAY') {
1918: my @available;
1919: if (ref($slots) eq 'HASH') {
1920: foreach my $slot (@{$allavailable}) {
1921: # not allowed for this resource
1922: if (ref($slots->{$slot}) eq 'HASH') {
1923: if ((defined($slots->{$slot}->{'symb'})) &&
1924: ($slots->{$slot}->{'symb'} ne $symb)) {
1925: next;
1926: }
1927: }
1928: push(@available,$slot);
1929: }
1930: }
1931: &show_choices($r,$symb,$formname,$reservable,$slots,$consumed_uniqueperiods,
1932: \@available,\@got_slots);
1933: }
1934: }
1935: $r->print('</td>');
1936: }
1937: $r->print('</tr>');
1938: }
1939: }
1940: }
1941: if ($shownheader) {
1942: $r->print('</table>');
1943: }
1944: if (!$reservable) {
1945: $r->print('<span class="LC_info">');
1946: if ($crstype eq 'Community') {
1947: $r->print(&mt('No community items currently require a reservation to gain access.'));
1948: } else {
1949: $r->print(&mt('No course items currently require a reservation to gain access.'));
1950: }
1951: $r->print('</span>');
1952: }
1953: $r->print('<p><a href="/adm/slotrequest?command=showresv">'.
1954: &mt('Reservation History').'</a></p>');
1955: }
1956:
1957: sub show_map_row {
1958: my ($depth,$location,$type,$title,$maprows) = @_;
1959: my $output = '<td>';
1960: for (my $i=0; $i<$depth-1; $i++) {
1961: $output .= '<img src="'.$location.'" alt="" />';
1962: }
1963: if ($type eq 'page') {
1964: $output .= '<img src="/adm/lonIcons/navmap.page.open.gif" alt="" /> '."\n";
1965: } else {
1966: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n";
1967: }
1968: $output .= $title.'</td><td colspan="2"> </td>'."\n";
1969: unshift (@{$maprows},$output);
1970: return;
1971: }
1972:
1973: sub show_reservations {
1974: my ($r,$uname,$udom) = @_;
1975: if (!defined($uname)) {
1976: $uname = $env{'user.name'};
1977: }
1978: if (!defined($udom)) {
1979: $udom = $env{'user.domain'};
1980: }
1981: my $formname = 'slotlog';
1982: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1983: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1984: my $crstype = &Apache::loncommon::course_type();
1985: my %log=&Apache::lonnet::dump('nohist_'.$cdom.'_'.$cnum.'_slotlog',$udom,$uname);
1986: if ($env{'form.origin'} eq 'aboutme') {
1987: $r->print('<div class="LC_fontsize_large">');
1988: my $name = &Apache::loncommon::plainname($env{'form.uname'},$env{'form.udom'},
1989: 'firstname');
1990: if ($crstype eq 'Community') {
1991: $r->print(&mt('History of member-reservable slots for: [_1]',
1992: $name));
1993: } else {
1994: $r->print(&mt('History of student-reservable slots for: [_1]',
1995: $name));
1996:
1997: }
1998: $r->print('</div>');
1999: }
2000: $r->print('<form action="/adm/slotrequest" method="post" name="'.$formname.'">');
2001: # set defaults
2002: my $now = time();
2003: my $defstart = $now - (7*24*3600); #7 days ago
2004: my %defaults = (
2005: page => '1',
2006: show => '10',
2007: action => 'any',
2008: log_start_date => $defstart,
2009: log_end_date => $now,
2010: );
2011: my $more_records = 0;
2012:
2013: # set current
2014: my %curr;
2015: foreach my $item ('show','page','action') {
2016: $curr{$item} = $env{'form.'.$item};
2017: }
2018: my ($startdate,$enddate) =
2019: &Apache::lonuserutils::get_dates_from_form('log_start_date',
2020: 'log_end_date');
2021: $curr{'log_start_date'} = $startdate;
2022: $curr{'log_end_date'} = $enddate;
2023: foreach my $key (keys(%defaults)) {
2024: if ($curr{$key} eq '') {
2025: $curr{$key} = $defaults{$key};
2026: }
2027: }
2028: my ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
2029: $r->print(&display_filter($formname,$cdom,$cnum,\%curr,$version));
2030: my $showntablehdr = 0;
2031: my $tablehdr = &Apache::loncommon::start_data_table().
2032: &Apache::loncommon::start_data_table_header_row().
2033: '<th> </th><th>'.&mt('When').'</th><th>'.&mt('Action').'</th>'.
2034: '<th>'.&mt('Description').'</th><th>'.&mt('Start time').'</th>'.
2035: '<th>'.&mt('End time').'</th><th>'.&mt('Resource').'</th>'.
2036: &Apache::loncommon::end_data_table_header_row();
2037: my ($minshown,$maxshown);
2038: $minshown = 1;
2039: my $count = 0;
2040: if ($curr{'show'} ne &mt('all')) {
2041: $maxshown = $curr{'page'} * $curr{'show'};
2042: if ($curr{'page'} > 1) {
2043: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
2044: }
2045: }
2046: my (%titles,%maptitles);
2047: my %lt = &reservationlog_contexts($crstype);
2048: foreach my $id (sort { $log{$b}{'exe_time'}<=>$log{$a}{'exe_time'} } (keys(%log))) {
2049: next if (($log{$id}{'exe_time'} < $curr{'log_start_date'}) ||
2050: ($log{$id}{'exe_time'} > $curr{'log_end_date'}));
2051: if ($curr{'show'} ne &mt('all')) {
2052: if ($count >= $curr{'page'} * $curr{'show'}) {
2053: $more_records = 1;
2054: last;
2055: }
2056: }
2057: if ($curr{'action'} ne 'any') {
2058: next if ($log{$id}{'logentry'}{'action'} ne $curr{'action'});
2059: }
2060: $count ++;
2061: next if ($count < $minshown);
2062: if (!$showntablehdr) {
2063: $r->print($tablehdr);
2064: $showntablehdr = 1;
2065: }
2066: my $symb = $log{$id}{'logentry'}{'symb'};
2067: my $slot_name = $log{$id}{'logentry'}{'slot'};
2068: my %slot=&Apache::lonnet::get_slot($slot_name);
2069: my $description = $slot{'description'};
2070: my $start = ($slot{'starttime'}?
2071: &Apache::lonlocal::locallocaltime($slot{'starttime'}):'');
2072: my $end = ($slot{'endtime'}?
2073: &Apache::lonlocal::locallocaltime($slot{'endtime'}):'');
2074: my $title = &get_resource_title($symb,\%titles,\%maptitles);
2075: my $chgaction = $log{$id}{'logentry'}{'action'};
2076: if ($chgaction ne '' && $lt{$chgaction} ne '') {
2077: $chgaction = $lt{$chgaction};
2078: }
2079: $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");
2080: }
2081: if ($showntablehdr) {
2082: $r->print(&Apache::loncommon::end_data_table().'<br />');
2083: if (($curr{'page'} > 1) || ($more_records)) {
2084: $r->print('<table><tr>');
2085: if ($curr{'page'} > 1) {
2086: $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
2087: }
2088: if ($more_records) {
2089: $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
2090: }
2091: $r->print('</tr></table>');
2092: $r->print(<<"ENDSCRIPT");
2093: <script type="text/javascript">
2094: // <![CDATA[
2095: function chgPage(caller) {
2096: if (caller == 'previous') {
2097: document.$formname.page.value --;
2098: }
2099: if (caller == 'next') {
2100: document.$formname.page.value ++;
2101: }
2102: document.$formname.submit();
2103: return;
2104: }
2105: // ]]>
2106: </script>
2107: ENDSCRIPT
2108: }
2109: } else {
2110: $r->print('<span class="LC_info">'
2111: .&mt('There are no transactions to display.')
2112: .'</span>'
2113: );
2114: }
2115: $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'."\n".
2116: '<input type="hidden" name="command" value="showresv" />'."\n");
2117: if ($env{'form.origin'} eq 'aboutme') {
2118: $r->print('<input type="hidden" name="origin" value="'.$env{'form.origin'}.'" />'."\n".
2119: '<input type="hidden" name="uname" value="'.$env{'form.uname'}.'" />'."\n".
2120: '<input type="hidden" name="udom" value="'.$env{'form.udom'}.'" />'."\n");
2121: }
2122: $r->print('</form>');
2123: return;
2124: }
2125:
2126: sub show_reservations_log {
2127: my ($r) = @_;
2128: my $badslot;
2129: my $crstype = &Apache::loncommon::course_type();
2130: if ($env{'form.slotname'} eq '') {
2131: $r->print('<div class="LC_warning">'.&mt('No slot name provided').'</div>');
2132: $badslot = 1;
2133: } else {
2134: my %slot=&Apache::lonnet::get_slot($env{'form.slotname'});
2135: if (keys(%slot) == 0) {
2136: $r->print('<div class="LC_warning">'.&mt('Invalid slot name: [_1]',$env{'form.slotname'}).'</div>');
2137: $badslot = 1;
2138: } elsif ($slot{type} ne 'schedulable_student') {
2139: my $description = &get_description($env{'form.slotname'},\%slot);
2140: $r->print('<div class="LC_warning">');
2141: if ($crstype eq 'Community') {
2142: $r->print(&mt('Reservation history unavailable for non-member-reservable slot: [_1].',$description));
2143: } else {
2144: $r->print(&mt('Reservation history unavailable for non-student-reservable slot: [_1].',$description));
2145: }
2146: $r->print('</div>');
2147: $badslot = 1;
2148: }
2149: }
2150: if ($badslot) {
2151: $r->print('<p><a href="/adm/slotrequest?command=showslots">'.
2152: &mt('Return to slot list').'</a></p>');
2153: return;
2154: }
2155: my $formname = 'reservationslog';
2156: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2157: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2158: my %slotlog=&Apache::lonnet::dump('nohist_slotreservationslog',$cdom,$cnum);
2159: if ((keys(%slotlog))[0]=~/^error\:/) { undef(%slotlog); }
2160:
2161: my (%log,@allsymbs);
2162: if (keys(%slotlog)) {
2163: foreach my $key (keys(%slotlog)) {
2164: if (ref($slotlog{$key}) eq 'HASH') {
2165: if (ref($slotlog{$key}{'logentry'}) eq 'HASH') {
2166: if ($slotlog{$key}{'logentry'}{'slot'} eq $env{'form.slotname'}) {
2167: $log{$key} = $slotlog{$key};
2168: if ($slotlog{$key}{'logentry'}{'symb'} ne '') {
2169: push(@allsymbs,$slotlog{$key}{'logentry'}{'symb'});
2170: }
2171: }
2172: }
2173: }
2174: }
2175: }
2176:
2177: $r->print('<form action="/adm/slotrequest" method="post" name="'.$formname.'">');
2178: my %saveable_parameters = ('show' => 'scalar',);
2179: &Apache::loncommon::store_course_settings('reservationslog',
2180: \%saveable_parameters);
2181: &Apache::loncommon::restore_course_settings('reservationslog',
2182: \%saveable_parameters);
2183: # set defaults
2184: my $now = time();
2185: my $defstart = $now - (7*24*3600); #7 days ago
2186: my %defaults = (
2187: page => '1',
2188: show => '10',
2189: chgcontext => 'any',
2190: action => 'any',
2191: symb => 'any',
2192: log_start_date => $defstart,
2193: log_end_date => $now,
2194: );
2195: my $more_records = 0;
2196:
2197: # set current
2198: my %curr;
2199: foreach my $item ('show','page','chgcontext','action','symb') {
2200: $curr{$item} = $env{'form.'.$item};
2201: }
2202: my ($startdate,$enddate) =
2203: &Apache::lonuserutils::get_dates_from_form('log_start_date',
2204: 'log_end_date');
2205: $curr{'log_start_date'} = $startdate;
2206: $curr{'log_end_date'} = $enddate;
2207: foreach my $key (keys(%defaults)) {
2208: if ($curr{$key} eq '') {
2209: $curr{$key} = $defaults{$key};
2210: }
2211: }
2212: my (%whodunit,%changed,$version);
2213: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
2214:
2215: my %slot=&Apache::lonnet::get_slot($env{'form.slotname'});
2216: my $description = $slot{'description'};
2217: $r->print('<span class="LC_fontsize_large">');
2218: if ($crstype eq 'Community') {
2219: $r->print(&mt('Reservation changes for member-reservable slot: [_1]',$description));
2220: } else {
2221: $r->print(&mt('Reservation changes for student-reservable slot: [_1]',$description));
2222: }
2223: $r->print('</span><br />');
2224: $r->print(&display_filter($formname,$cdom,$cnum,\%curr,$version,\@allsymbs));
2225: my $showntablehdr = 0;
2226: my $tablehdr = &Apache::loncommon::start_data_table().
2227: &Apache::loncommon::start_data_table_header_row().
2228: '<th> </th><th>'.&mt('When').'</th><th>'.&mt('Who made the change').
2229: '</th><th>'.&mt('Affected User').'</th><th>'.&mt('Action').'</th>'.
2230: '<th>'.&mt('Resource').'</th><th>'.&mt('Context').'</th>'.
2231: &Apache::loncommon::end_data_table_header_row();
2232: my ($minshown,$maxshown);
2233: $minshown = 1;
2234: my $count = 0;
2235: if ($curr{'show'} ne &mt('all')) {
2236: $maxshown = $curr{'page'} * $curr{'show'};
2237: if ($curr{'page'} > 1) {
2238: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
2239: }
2240: }
2241: my %lt = &reservationlog_contexts($crstype);
2242: my (%titles,%maptitles);
2243: foreach my $id (sort { $log{$b}{'exe_time'}<=>$log{$a}{'exe_time'} } (keys(%log))) {
2244: next if (($log{$id}{'exe_time'} < $curr{'log_start_date'}) ||
2245: ($log{$id}{'exe_time'} > $curr{'log_end_date'}));
2246: if ($curr{'show'} ne &mt('all')) {
2247: if ($count >= $curr{'page'} * $curr{'show'}) {
2248: $more_records = 1;
2249: last;
2250: }
2251: }
2252: if ($curr{'chgcontext'} ne 'any') {
2253: if ($curr{'chgcontext'} eq 'user') {
2254: next if (($log{$id}{'logentry'}{'context'} ne 'user') &&
2255: ($log{$id}{'logentry'}{'context'} ne 'usermanage'));
2256: } else {
2257: next if ($log{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
2258: }
2259: }
2260: if ($curr{'action'} ne 'any') {
2261: next if ($log{$id}{'logentry'}{'action'} ne $curr{'action'});
2262: }
2263: if ($curr{'symb'} ne 'any') {
2264: next if ($log{$id}{'logentry'}{'symb'} ne $curr{'symb'});
2265: }
2266: $count ++;
2267: next if ($count < $minshown);
2268: if (!$showntablehdr) {
2269: $r->print($tablehdr);
2270: $showntablehdr = 1;
2271: }
2272: if ($whodunit{$log{$id}{'exe_uname'}.':'.$log{$id}{'exe_udom'}} eq '') {
2273: $whodunit{$log{$id}{'exe_uname'}.':'.$log{$id}{'exe_udom'}} =
2274: &Apache::loncommon::plainname($log{$id}{'exe_uname'},$log{$id}{'exe_udom'});
2275: }
2276: if ($changed{$log{$id}{'uname'}.':'.$log{$id}{'udom'}} eq '') {
2277: $changed{$log{$id}{'uname'}.':'.$log{$id}{'udom'}} =
2278: &Apache::loncommon::plainname($log{$id}{'uname'},$log{$id}{'udom'});
2279: }
2280: my $symb = $log{$id}{'logentry'}{'symb'};
2281: my $title = &get_resource_title($symb,\%titles,\%maptitles);
2282: my $chgcontext = $log{$id}{'logentry'}{'context'};
2283: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
2284: $chgcontext = $lt{$chgcontext};
2285: }
2286: my $chgaction = $log{$id}{'logentry'}{'action'};
2287: if ($chgaction ne '' && $lt{$chgaction} ne '') {
2288: $chgaction = $lt{$chgaction};
2289: }
2290: $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");
2291: }
2292: if ($showntablehdr) {
2293: $r->print(&Apache::loncommon::end_data_table().'<br />');
2294: if (($curr{'page'} > 1) || ($more_records)) {
2295: $r->print('<table><tr>');
2296: if ($curr{'page'} > 1) {
2297: $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
2298: }
2299: if ($more_records) {
2300: $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
2301: }
2302: $r->print('</tr></table>');
2303: $r->print(<<"ENDSCRIPT");
2304: <script type="text/javascript">
2305: function chgPage(caller) {
2306: if (caller == 'previous') {
2307: document.$formname.page.value --;
2308: }
2309: if (caller == 'next') {
2310: document.$formname.page.value ++;
2311: }
2312: document.$formname.submit();
2313: return;
2314: }
2315: </script>
2316: ENDSCRIPT
2317: }
2318: } else {
2319: $r->print(&mt('There are no records to display.'));
2320: }
2321: $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
2322: '<input type="hidden" name="slotname" value="'.$env{'form.slotname'}.'" />'.
2323: '<input type="hidden" name="command" value="slotlog" /></form>'.
2324: '<p><a href="/adm/slotrequest?command=showslots">'.
2325: &mt('Return to slot list').'</a></p>');
2326: return;
2327: }
2328:
2329: sub get_resource_title {
2330: my ($symb,$titles,$maptitles) = @_;
2331: my $title;
2332: if ((ref($titles) eq 'HASH') && (ref($maptitles) eq 'HASH')) {
2333: if (defined($titles->{$symb})) {
2334: $title = $titles->{$symb};
2335: } else {
2336: $title = &Apache::lonnet::gettitle($symb);
2337: my $maptitle;
2338: my ($mapurl) = &Apache::lonnet::decode_symb($symb);
2339: if (defined($maptitles->{$mapurl})) {
2340: $maptitle = $maptitles->{$mapurl};
2341: } else {
2342: if ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'}) {
2343: $maptitle=&mt('Main Content');
2344: } else {
2345: $maptitle=&Apache::lonnet::gettitle($mapurl);
2346: }
2347: $maptitles->{$mapurl} = $maptitle;
2348: }
2349: if ($maptitle ne '') {
2350: $title .= ' '.&mt('(in [_1])',$maptitle);
2351: }
2352: $titles->{$symb} = $title;
2353: }
2354: } else {
2355: $title = $symb;
2356: }
2357: return $title;
2358: }
2359:
2360: sub reservationlog_contexts {
2361: my ($crstype) = @_;
2362: my %lt = &Apache::lonlocal::texthash (
2363: any => 'Any',
2364: user => 'By student',
2365: manage => 'Via Slot Manager',
2366: parameter => 'Via Parameter Manager',
2367: reserve => 'Made reservation',
2368: release => 'Dropped reservation',
2369: usermanage => 'By student',
2370: );
2371: if ($crstype eq 'Community') {
2372: $lt{'user'} = &mt('By member');
2373: $lt{'usermanage'} = $lt{'user'};
2374: }
2375: return %lt;
2376: }
2377:
2378: sub display_filter {
2379: my ($formname,$cdom,$cnum,$curr,$version,$allsymbs) = @_;
2380: my $nolink = 1;
2381: my (%titles,%maptitles);
2382: my $output = '<br /><table><tr><td valign="top">'.
2383: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b><br />'.
2384: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
2385: (&mt('all'),5,10,20,50,100,1000,10000)).
2386: '</td><td> </td>';
2387: my $startform =
2388: &Apache::lonhtmlcommon::date_setter($formname,'log_start_date',
2389: $curr->{'log_start_date'},undef,
2390: undef,undef,undef,undef,undef,undef,$nolink);
2391: my $endform =
2392: &Apache::lonhtmlcommon::date_setter($formname,'log_end_date',
2393: $curr->{'log_end_date'},undef,
2394: undef,undef,undef,undef,undef,undef,$nolink);
2395: my $crstype = &Apache::loncommon::course_type();
2396: my %lt = &reservationlog_contexts($crstype);
2397: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').
2398: '</b><br /><table><tr><td>'.&mt('After:').
2399: '</td><td>'.$startform.'</td></tr><tr><td>'.&mt('Before:').'</td><td>'.
2400: $endform.'</td></tr></table></td><td> </td>';
2401: if (ref($allsymbs) eq 'ARRAY') {
2402: $output .= '<td valign="top"><b>'.&mt('Resource').'</b><br />'.
2403: '<select name="resource"><option value="any"';
2404: if ($curr->{'resource'} eq 'any') {
2405: $output .= ' selected="selected"';
2406: }
2407: $output .= '>'.&mt('Any').'</option>'."\n";
2408: foreach my $symb (@{$allsymbs}) {
2409: my $title = &get_resource_title($symb,\%titles,\%maptitles);
2410: my $selstr = '';
2411: if ($curr->{'resource'} eq $symb) {
2412: $selstr = ' selected="selected"';
2413: }
2414: $output .= ' <option value="'.$symb.'"'.$selstr.'>'.$title.'</option>';
2415: }
2416: $output .= '</select></td><td> </td><td valign="top"><b>'.
2417: &mt('Context:').'</b><br /><select name="chgcontext">';
2418: foreach my $chgtype ('any','user','manage','parameter') {
2419: my $selstr = '';
2420: if ($curr->{'chgcontext'} eq $chgtype) {
2421: $output .= $selstr = ' selected="selected"';
2422: }
2423: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
2424: }
2425: $output .= '</select></td>';
2426: } else {
2427: $output .= '<td valign="top"><b>'.&mt('Action').'</b><br />'.
2428: '<select name="action"><option value="any"';
2429: if ($curr->{'action'} eq 'any') {
2430: $output .= ' selected="selected"';
2431: }
2432: $output .= '>'.&mt('Any').'</option>'."\n";
2433: foreach my $actiontype ('reserve','release') {
2434: my $selstr = '';
2435: if ($curr->{'action'} eq $actiontype) {
2436: $output .= $selstr = ' selected="selected"';
2437: }
2438: $output .= '<option value="'.$actiontype.'"'.$selstr.'>'.$lt{$actiontype}.'</option>'."\n";
2439: }
2440: $output .= '</select></td>';
2441: }
2442: $output .= '<td> </td><td valign="middle"><input type="submit" value="'.
2443: &mt('Update Display').'" /></tr></table>'.
2444: '<p class="LC_info">'.
2445: &mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
2446: ,'2.9.0');
2447: if ($version) {
2448: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
2449: }
2450: $output .= '</p><hr /><br />';
2451: return $output;
2452: }
2453:
2454: sub slot_change_messaging {
2455: my ($setting,$subject,$msg,$action) = @_;
2456: my $user = $env{'user.name'};
2457: my $domain = $env{'user.domain'};
2458: my ($message_status,$comment_status);
2459: if ($setting eq 'only_student'
2460: || $setting eq 'student_and_user_notes_screen') {
2461: $message_status =
2462: &Apache::lonmsg::user_normal_msg($user,$domain,$subject,$msg);
2463: $message_status = '<li>'.&mt('Sent to you: [_1]',
2464: $message_status).' </li>';
2465: }
2466: if ($setting eq 'student_and_user_notes_screen') {
2467: $comment_status =
2468: &Apache::lonmsg::store_instructor_comment($subject.'<br />'.
2469: $msg,$user,$domain);
2470: $comment_status = '<li>'.&mt('Entry added to course record (viewable by instructor): [_1]',
2471: $comment_status).'</li>';
2472: }
2473: if ($message_status || $comment_status) {
2474: my $msgtitle;
2475: if ($action eq 'reserve') {
2476: $msgtitle = &mt('Status of messages about saved reservation');
2477: } elsif ($action eq 'release') {
2478: $msgtitle = &mt('Status of messages about dropped reservation');
2479: } elsif ($action eq 'nochange') {
2480: $msgtitle = &mt('Status of messages about unchanged existing reservation');
2481: }
2482: return '<span class="LC_info">'.$msgtitle.'</span>'
2483: .'<ul>'
2484: .$message_status
2485: .$comment_status
2486: .'</ul><hr />';
2487: }
2488: }
2489:
2490: sub upload_start {
2491: my ($r)=@_;
2492: $r->print(
2493: &Apache::grades::checkforfile_js()
2494: .'<h2>'.&mt('Upload a file containing the slot definitions').'</h2>'
2495: .'<form method="post" enctype="multipart/form-data"'
2496: .' action="/adm/slotrequest" name="slotupload">'
2497: .'<input type="hidden" name="command" value="csvuploadmap" />'
2498: .&Apache::lonhtmlcommon::start_pick_box()
2499: .&Apache::lonhtmlcommon::row_title(&mt('File'))
2500: .&Apache::loncommon::upfile_select_html()
2501: .&Apache::lonhtmlcommon::row_closure()
2502: .&Apache::lonhtmlcommon::row_title(
2503: '<label for="noFirstLine">'
2504: .&mt('Ignore First Line')
2505: .'</label>')
2506: .'<input type="checkbox" name="noFirstLine" id="noFirstLine" />'
2507: .&Apache::lonhtmlcommon::row_closure(1)
2508: .&Apache::lonhtmlcommon::end_pick_box()
2509: .'<p>'
2510: .'<input type="button" onclick="javascript:checkUpload(this.form);"'
2511: .' value="'.&mt('Next').'" />'
2512: .'</p>'
2513: .'</form>'
2514: );
2515: }
2516:
2517: sub csvuploadmap_header {
2518: my ($r,$datatoken,$distotal)= @_;
2519: my $javascript;
2520: if ($env{'form.upfile_associate'} eq 'reverse') {
2521: $javascript=&csvupload_javascript_reverse_associate();
2522: } else {
2523: $javascript=&csvupload_javascript_forward_associate();
2524: }
2525:
2526: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
2527: my $ignore=&mt('Ignore First Line');
2528: my $buttontext = &mt('Reverse Association');
2529:
2530: $r->print(
2531: '<form method="post" enctype="multipart/form-data" action="/adm/slotrequest" name="slotupload">'
2532: .'<h2>'.&mt('Identify fields in uploaded list').'</h2>'
2533: .'<div class="LC_columnSection">'
2534: .&Apache::loncommon::help_open_topic(
2535: 'Slot About',&mt('Help on slots'))
2536: .' '.&Apache::loncommon::help_open_topic(
2537: 'Slot SelectingField',&mt('Help on selecting Fields'))
2538: ."</div>\n"
2539: .'<p class="LC_info">'
2540: .&mt('Total number of records found in file: [_1]','<b>'.$distotal.'</b>')
2541: ."</p>\n"
2542: );
2543: if ($distotal == 0) {
2544: $r->print('<p class="LC_warning">'.&mt('None found').'</p>');
2545: }
2546: $r->print(
2547: '<p>'
2548: .&mt('Enter as many fields as you can.').'<br />'
2549: .&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 />')
2550: .'</p>'
2551: );
2552: $r->print(
2553: '<div class="LC_left_float">'
2554: .'<fieldset><legend>'.&mt('Functions').'</legend>'
2555: .'<label><input type="checkbox" name="noFirstLine"'.$checked.' />'.$ignore.'</label>'
2556: .' <input type="button" value="'.$buttontext
2557: .'" onclick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />'
2558: .'</fieldset></div><br clear="all" />'
2559: );
2560:
2561: $r->print(<<ENDPICK);
2562: <input type="hidden" name="associate" value="" />
2563: <input type="hidden" name="datatoken" value="$datatoken" />
2564: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
2565: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
2566: <input type="hidden" name="upfile_associate"
2567: value="$env{'form.upfile_associate'}" />
2568: <input type="hidden" name="command" value="csvuploadassign" />
2569: <script type="text/javascript" language="Javascript">
2570: // <![CDATA[
2571: $javascript
2572: // ]]>
2573: </script>
2574: ENDPICK
2575: return '';
2576:
2577: }
2578:
2579: sub csvuploadmap_footer {
2580: my ($request,$i,$keyfields) =@_;
2581: my $buttontext = &mt('Create Slots');
2582: $request->print(<<ENDPICK);
2583: <input type="hidden" name="nfields" value="$i" />
2584: <input type="hidden" name="keyfields" value="$keyfields" />
2585: <input type="button" onclick="javascript:verify(this.form)" value="$buttontext" /><br />
2586: </form>
2587: ENDPICK
2588: }
2589:
2590: sub csvupload_javascript_reverse_associate {
2591: my $error1=&mt('You need to specify the name, start time, end time and a type.');
2592: return(<<ENDPICK);
2593: function verify(vf) {
2594: var foundstart=0;
2595: var foundend=0;
2596: var foundname=0;
2597: var foundtype=0;
2598: for (i=0;i<=vf.nfields.value;i++) {
2599: tw=eval('vf.f'+i+'.selectedIndex');
2600: if (i==0 && tw!=0) { foundname=1; }
2601: if (i==1 && tw!=0) { foundtype=1; }
2602: if (i==2 && tw!=0) { foundstat=1; }
2603: if (i==3 && tw!=0) { foundend=1; }
2604: }
2605: if (foundstart==0 && foundend==0 && foundtype==0 && foundname==0) {
2606: alert('$error1');
2607: return;
2608: }
2609: vf.submit();
2610: }
2611: function flip(vf,tf) {
2612: }
2613: ENDPICK
2614: }
2615:
2616: sub csvupload_javascript_forward_associate {
2617: my $error1=&mt('You need to specify the name, start time, end time and a type.');
2618: return(<<ENDPICK);
2619: function verify(vf) {
2620: var foundstart=0;
2621: var foundend=0;
2622: var foundname=0;
2623: var foundtype=0;
2624: for (i=0;i<=vf.nfields.value;i++) {
2625: tw=eval('vf.f'+i+'.selectedIndex');
2626: if (tw==1) { foundname=1; }
2627: if (tw==2) { foundtype=1; }
2628: if (tw==3) { foundstat=1; }
2629: if (tw==4) { foundend=1; }
2630: }
2631: if (foundstart==0 && foundend==0 && foundtype==0 && foundname==0) {
2632: alert('$error1');
2633: return;
2634: }
2635: vf.submit();
2636: }
2637: function flip(vf,tf) {
2638: }
2639: ENDPICK
2640: }
2641:
2642: sub csv_upload_map {
2643: my ($r)= @_;
2644:
2645: my $datatoken;
2646: if (!$env{'form.datatoken'}) {
2647: $datatoken=&Apache::loncommon::upfile_store($r);
2648: } else {
2649: $datatoken=$env{'form.datatoken'};
2650: &Apache::loncommon::load_tmp_file($r);
2651: }
2652: my @records=&Apache::loncommon::upfile_record_sep();
2653: if ($env{'form.noFirstLine'}) { shift(@records); }
2654: &csvuploadmap_header($r,$datatoken,$#records+1);
2655: my ($i,$keyfields);
2656: if (@records) {
2657: my @fields=&csvupload_fields();
2658:
2659: if ($env{'form.upfile_associate'} eq 'reverse') {
2660: &Apache::loncommon::csv_print_samples($r,\@records);
2661: $i=&Apache::loncommon::csv_print_select_table($r,\@records,
2662: \@fields);
2663: foreach (@fields) { $keyfields.=$_->[0].','; }
2664: chop($keyfields);
2665: } else {
2666: unshift(@fields,['none','']);
2667: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
2668: \@fields);
2669: my %sone=&Apache::loncommon::record_sep($records[0]);
2670: $keyfields=join(',',sort(keys(%sone)));
2671: }
2672: }
2673: &csvuploadmap_footer($r,$i,$keyfields);
2674:
2675: return '';
2676: }
2677:
2678: sub csvupload_fields {
2679: return (['name','Slot name'],
2680: ['type','Type of slot'],
2681: ['starttime','Start Time of slot'],
2682: ['endtime','End Time of slot'],
2683: ['startreserve','Reservation Start Time'],
2684: ['endreserve','Reservation End Time'],
2685: ['reservationmsg','Message when reservation changed'],
2686: ['ip','IP or DNS restriction'],
2687: ['proctor','List of proctor ids'],
2688: ['description','Slot Description'],
2689: ['maxspace','Maximum number of reservations'],
2690: ['symb','Resource Restriction'],
2691: ['uniqueperiod','Date range of slot exclusion'],
2692: ['secret','Secret word proctor uses to validate'],
2693: ['allowedsections','Sections slot is restricted to'],
2694: ['allowedusers','Users slot is restricted to'],
2695: );
2696: }
2697:
2698: sub csv_upload_assign {
2699: my ($r,$mgr)= @_;
2700: &Apache::loncommon::load_tmp_file($r);
2701: my @slotdata = &Apache::loncommon::upfile_record_sep();
2702: if ($env{'form.noFirstLine'}) { shift(@slotdata); }
2703: my %fields=&Apache::grades::get_fields();
2704: $r->print('<h3>'.&mt('Creating Slots').'</h3>');
2705: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
2706: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2707: my $countdone=0;
2708: my @errors;
2709: foreach my $slot (@slotdata) {
2710: my %slot;
2711: my %entries=&Apache::loncommon::record_sep($slot);
2712: my $domain;
2713: my $name=$entries{$fields{'name'}};
2714: if ($name=~/^\s*$/) {
2715: push(@errors,"Did not create slot with no name");
2716: next;
2717: }
2718: if ($name=~/\s/) {
2719: push(@errors,"$name not created -- Name must not contain spaces");
2720: next;
2721: }
2722: if ($name=~/\W/) {
2723: push(@errors,"$name not created -- Name must contain only letters, numbers and _");
2724: next;
2725: }
2726: if ($entries{$fields{'type'}}) {
2727: $slot{'type'}=$entries{$fields{'type'}};
2728: } else {
2729: $slot{'type'}='preassigned';
2730: }
2731: if ($slot{'type'} ne 'preassigned' &&
2732: $slot{'type'} ne 'schedulable_student') {
2733: push(@errors,"$name not created -- invalid type ($slot{'type'}) must be either preassigned or schedulable_student");
2734: next;
2735: }
2736: if ($entries{$fields{'starttime'}}) {
2737: $slot{'starttime'}=&UnixDate($entries{$fields{'starttime'}},"%s");
2738: }
2739: if ($entries{$fields{'endtime'}}) {
2740: $slot{'endtime'}=&UnixDate($entries{$fields{'endtime'}},"%s");
2741: }
2742:
2743: # start/endtime must be defined and greater than zero
2744: if (!$slot{'starttime'}) {
2745: push(@errors,"$name not created -- Invalid start time");
2746: next;
2747: }
2748: if (!$slot{'endtime'}) {
2749: push(@errors,"$name not created -- Invalid end time");
2750: next;
2751: }
2752: if ($slot{'starttime'} > $slot{'endtime'}) {
2753: push(@errors,"$name not created -- Slot starts after it ends");
2754: next;
2755: }
2756:
2757: if ($entries{$fields{'startreserve'}}) {
2758: my $date = &UnixDate($entries{$fields{'startreserve'}},"%s");
2759: if ($date eq '') {
2760: push(@errors,"$name -- No reservation start time set for slot -- value provided had invalid format");
2761: } else {
2762: $slot{'startreserve'} = $date;
2763: }
2764: }
2765: if (defined($slot{'startreserve'})
2766: && $slot{'startreserve'} > $slot{'starttime'}) {
2767: push(@errors,"$name not created -- Slot's reservation start time is after the slot's start time.");
2768: next;
2769: }
2770:
2771: if ($entries{$fields{'endreserve'}}) {
2772: my $date = &UnixDate($entries{$fields{'endreserve'}},"%s");
2773: if ($date eq '') {
2774: push(@errors,"$name -- No reservation end time set for slot -- value provided had invalid format");
2775: } else {
2776: $slot{'endreserve'} = $date;
2777: }
2778: }
2779: if (defined($slot{'endreserve'})
2780: && $slot{'endreserve'} > $slot{'starttime'}) {
2781: push(@errors,"$name not created -- Slot's reservation end time is after the slot's start time.");
2782: next;
2783: }
2784:
2785: if ($slot{'type'} eq 'schedulable_student') {
2786: if ($entries{$fields{'reservationmsg'}}) {
2787: if (($entries{$fields{'reservationmsg'}} eq 'only_student') ||
2788: ($entries{$fields{'reservationmsg'}} eq 'student_and_user_notes_screen')) {
2789: $slot{'reservationmsg'}=$entries{$fields{'reservationmsg'}};
2790: } else {
2791: unless (($entries{$fields{'reservationmsg'}} eq 'none') ||
2792: ($entries{$fields{'reservationmsg'}} eq '')) {
2793: push(@errors,"$name -- Slot's reservationmsg setting ignored - not one of: 'only_student', 'student_and_user_notes_screen', 'none' or ''");
2794: }
2795: }
2796: }
2797: }
2798:
2799: foreach my $key ('ip','proctor','description','maxspace',
2800: 'secret','symb') {
2801: if ($entries{$fields{$key}}) {
2802: $slot{$key}=$entries{$fields{$key}};
2803: }
2804: }
2805: if ($entries{$fields{'allowedusers'}}) {
2806: $entries{$fields{'allowedusers'}} =~ s/^\s+//;
2807: $entries{$fields{'allowedusers'}} =~ s/\s+$//;
2808: my @allowedusers;
2809: foreach my $poss (split(/\s*,\s*/,$entries{$fields{'allowedusers'}})) {
2810: my ($possuname,$possudom) = split(/:/,$poss);
2811: if (($possuname =~ /^$match_username$/) && ($possudom =~ /^$match_domain$/)) {
2812: unless (grep(/^\Q$poss\E$/,@allowedusers)) {
2813: push(@allowedusers,$poss);
2814: }
2815: }
2816: }
2817: if (@allowedusers > 0) {
2818: $slot{'allowedusers'} = join(',',@allowedusers);
2819: }
2820: }
2821: if ($entries{$fields{'allowedsections'}}) {
2822: $entries{$fields{'allowedsections'}} =~ s/^\s+//;
2823: $entries{$fields{'allowedsections'}} =~ s/\s+$//;
2824: my @allowedsections;
2825: foreach my $poss (split(/\s*,\s*/,$entries{$fields{'allowedsections'}})) {
2826: if (($poss !~ /\W/) && ($poss ne 'none')) {
2827: unless (grep(/^\Q$poss\E$/,@allowedsections)) {
2828: push(@allowedsections,$poss);
2829: }
2830: }
2831: }
2832: if (@allowedsections > 0) {
2833: $slot{'allowedsections'} = join(',',@allowedsections);
2834: }
2835: }
2836: if ($entries{$fields{'uniqueperiod'}}) {
2837: my ($start,$end)= map { &UnixDate($_,"%s"); } split(',',$entries{$fields{'uniqueperiod'}});
2838: if (($start ne '') && ($end ne '')) {
2839: $slot{'uniqueperiod'}=[$start,$end];
2840: } else {
2841: push(@errors,"$name -- Slot's unique period ignored -- one or both of the comma separated values for start and end had an invalid format");
2842: }
2843: }
2844: if (ref($slot{'uniqueperiod'}) eq 'ARRAY'
2845: && $slot{'uniqueperiod'}[0] > $slot{'uniqueperiod'}[1]) {
2846: push(@errors,"$name not created -- Slot's unique period start time is later than the unique period's end time.");
2847: next;
2848: }
2849:
2850: &Apache::lonnet::cput('slots',{$name=>\%slot},$cdom,$cname);
2851: $r->print('.');
2852: $r->rflush();
2853: $countdone++;
2854: }
2855: if ($countdone) {
2856: &Apache::lonnet::devalidate_slots_cache($cname,$cdom);
2857: }
2858: $r->print('<p>'.&mt('Created [quant,_1,slot]',$countdone)."\n".'</p>');
2859: foreach my $error (@errors) {
2860: $r->print('<p><span class="LC_warning">'.$error.'</span></p>'."\n");
2861: }
2862: &show_table($r,$mgr);
2863: return '';
2864: }
2865:
2866: sub slot_command_titles {
2867: my %titles = (
2868: slotlog => 'Reservation Logs',
2869: showslots => 'Manage Slots',
2870: showresv => 'Reservation History',
2871: manageresv => 'Manage Reservations',
2872: uploadstart => 'Upload Slots File',
2873: csvuploadmap => 'Upload Slots File',
2874: csvuploadassign => 'Upload Slots File',
2875: delete => 'Slot Deletion',
2876: release => 'Reservation Result',
2877: remove_reservation => 'Remove Registration',
2878: get_reservation => 'Request Reservation',
2879: );
2880: return %titles;
2881: }
2882:
2883: sub slot_reservationmsg_options {
2884: my %options = &Apache::lonlocal::texthash (
2885: only_student => 'Sent to student',
2886: student_and_user_notes_screen => 'Sent to student and added to user notes',
2887: none => 'None sent and no record in user notes',
2888: );
2889: return %options;
2890: }
2891:
2892: sub handler {
2893: my $r=shift;
2894:
2895: &Apache::loncommon::content_type($r,'text/html');
2896: &Apache::loncommon::no_cache($r);
2897: if ($r->header_only()) {
2898: $r->send_http_header();
2899: return OK;
2900: }
2901:
2902: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
2903:
2904: my %crumb_titles = &slot_command_titles();
2905: my $brcrum;
2906:
2907: my $vgr=&Apache::lonnet::allowed('vgr',$env{'request.course.id'});
2908: my $mgr=&Apache::lonnet::allowed('mgr',$env{'request.course.id'});
2909: my (%slots,$consumed_uniqueperiods);
2910: if ($env{'form.command'} eq 'showslots') {
2911: if (($vgr ne 'F') && ($mgr ne 'F')) {
2912: $env{'form.command'} = 'manageresv';
2913: }
2914: } elsif ($env{'form.command'} eq 'manageresv') {
2915: if (($vgr eq 'F') || ($mgr eq 'F')) {
2916: $env{'form.command'} = 'showslots';
2917: }
2918: }
2919: my $title='Requesting Another Worktime';
2920: if ($env{'form.command'} eq 'showresv') {
2921: $title = 'Reservation History';
2922: if ($env{'form.origin'} eq 'aboutme') {
2923: $brcrum =[{href=>"/adm/$env{'form.udom'}/$env{'form.uname'}/aboutme",text=>'Personal Information Page'}];
2924: } else {
2925: $brcrum =[{href=>"/adm/slotrequest?command=manageresv",text=>'Manage Reservations'}];
2926: }
2927: if (ref($brcrum) eq 'ARRAY') {
2928: push(@{$brcrum},{href=>"/adm/slotrequest?command=showresv",text=>$title});
2929: }
2930: } elsif (($env{'form.requestattempt'}) || ($env{'form.command'} eq 'manageresv')) {
2931: if ($env{'form.command'} eq 'manageresv') {
2932: $title = 'Manage Reservations';
2933: $brcrum =[{href=>"/adm/slotrequest?command=manageresv",text=>$title}];
2934: }
2935: my ($cnum,$cdom)=&get_course();
2936: %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
2937: $consumed_uniqueperiods = &get_consumed_uniqueperiods(\%slots);
2938: } elsif ($vgr eq 'F') {
2939: if ($env{'form.command'} =~ /^(slotlog|showslots|uploadstart|csvuploadmap|csvuploadassign|delete|release|remove_registration)$/) {
2940: $brcrum =[{href=>"/adm/slotrequest?command=showslots",
2941: text=>$crumb_titles{'showslots'}}];
2942: $title = 'Managing Slots';
2943: unless ($env{'form.command'} eq 'showslots') {
2944: if (ref($brcrum) eq 'ARRAY') {
2945: push(@{$brcrum},{href=>"/adm/slotrequest?command=$env{'form.command'}",text=>$crumb_titles{$env{'form.command'}}});
2946: }
2947: }
2948: }
2949: } elsif ($env{'form.command'} eq 'release') {
2950: if ($env{'form.context'} eq 'usermanage') {
2951: $brcrum =[{href=>"/adm/slotrequest?command=manageresv",
2952: text=>$crumb_titles{'showslots'}}];
2953: $title = 'Manage Reservations';
2954: if (ref($brcrum) eq 'ARRAY') {
2955: push(@{$brcrum},{href=>"/adm/slotrequest?command=$env{'form.command'}",text=>$crumb_titles{$env{'form.command'}}});
2956: }
2957: }
2958: } else {
2959: $brcrum =[];
2960: }
2961: my ($symb,$js,$available,$allavailable,$got_slots);
2962: $available = [];
2963: if ($env{'form.requestattempt'}) {
2964: $symb=&unescape($env{'form.symb'});
2965: @{$got_slots}=&check_for_reservation($symb,'allslots');
2966: }
2967: if (($env{'form.requestattempt'}) || ($env{'form.command'} eq 'manageresv')) {
2968: $js = &reservation_js(\%slots,$consumed_uniqueperiods,$available,$got_slots,$symb);
2969: }
2970: &start_page($r,$title,$brcrum,$js);
2971:
2972: if ($env{'form.command'} eq 'manageresv') {
2973: $allavailable = $available;
2974: undef($available);
2975: undef($got_slots);
2976: my $crstype = &Apache::loncommon::course_type();
2977: &manage_reservations($r,$crstype,\%slots,$consumed_uniqueperiods,$allavailable);
2978: } elsif ($env{'form.command'} eq 'showresv') {
2979: &show_reservations($r,$env{'form.uname'},$env{'form.udom'});
2980: } elsif ($env{'form.command'} eq 'showslots' && $vgr eq 'F') {
2981: &show_table($r,$mgr);
2982: } elsif ($env{'form.command'} eq 'remove_registration' && $mgr eq 'F') {
2983: &remove_registration($r);
2984: } elsif ($env{'form.command'} eq 'release' && $mgr eq 'F') {
2985: if ($env{'form.entry'} eq 'remove all') {
2986: &release_all_slot($r,$mgr);
2987: } else {
2988: &release_slot($r,undef,undef,undef,$mgr);
2989: }
2990: } elsif ($env{'form.command'} eq 'delete' && $mgr eq 'F') {
2991: &delete_slot($r);
2992: } elsif ($env{'form.command'} eq 'uploadstart' && $mgr eq 'F') {
2993: &upload_start($r);
2994: } elsif ($env{'form.command'} eq 'csvuploadmap' && $mgr eq 'F') {
2995: &csv_upload_map($r);
2996: } elsif ($env{'form.command'} eq 'csvuploadassign' && $mgr eq 'F') {
2997: if ($env{'form.associate'} ne 'Reverse Association') {
2998: &csv_upload_assign($r,$mgr);
2999: } else {
3000: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
3001: $env{'form.upfile_associate'} = 'reverse';
3002: } else {
3003: $env{'form.upfile_associate'} = 'forward';
3004: }
3005: &csv_upload_map($r);
3006: }
3007: } elsif ($env{'form.command'} eq 'slotlog' && $mgr eq 'F') {
3008: &show_reservations_log($r);
3009: } else {
3010: my $symb=&unescape($env{'form.symb'});
3011: if (!defined($symb)) {
3012: &fail($r,'not_valid');
3013: return OK;
3014: }
3015: my (undef,undef,$res)=&Apache::lonnet::decode_symb($symb);
3016: my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb);
3017: if ($useslots ne 'resource'
3018: && $useslots ne 'map'
3019: && $useslots ne 'map_map') {
3020: &fail($r,'not_available');
3021: return OK;
3022: }
3023: $env{'request.symb'}=$symb;
3024: my $type = ($res =~ /\.task$/) ? 'Task'
3025: : 'problem';
3026: my ($status) = &Apache::lonhomework::check_slot_access('0',$type);
3027: if ($status eq 'CAN_ANSWER' ||
3028: $status eq 'NEEDS_CHECKIN' ||
3029: $status eq 'WAITING_FOR_GRADE') {
3030: &fail($r,'not_allowed');
3031: return OK;
3032: }
3033: if ($env{'form.requestattempt'}) {
3034: $r->print('<div class="LC_left_float">');
3035: &show_choices($r,$symb,undef,undef,\%slots,$consumed_uniqueperiods,$available,$got_slots);
3036: $r->print('</div><div style="padding:0;clear:both;margin:0;border:0"></div>');
3037: } elsif ($env{'form.command'} eq 'release') {
3038: &release_slot($r,$symb);
3039: } elsif ($env{'form.command'} eq 'get') {
3040: &get_slot($r,$symb);
3041: } elsif ($env{'form.command'} eq 'change') {
3042: if ($env{'form.nochange'}) {
3043: my $slot_name = $env{'form.releaseslot'};
3044: my @slots = &check_for_reservation($symb,'allslots');
3045: my $msg;
3046: if (($slot_name ne '') && (grep(/^\Q$slot_name\E/,@slots))) {
3047: my %slot=&Apache::lonnet::get_slot($env{'form.releaseslot'});
3048: my $description=&get_description($slot_name,\%slot);
3049: $msg = '<span style="font-weight: bold;">'.
3050: &mt('Unchanged reservation: [_1]',$description).'</span><br /><br />';
3051: my $person =
3052: &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
3053: my $subject = &mt('Reservation unchanged: [_1]',$description);
3054: my $msgbody = &mt('No change to existing registration by [_1] for [_2].',$person,$description);
3055: $msg .= &slot_change_messaging($slot{'reservationmsg'},$subject,$msgbody,'nochange');
3056: } else {
3057: $msg = '<span class="LC_warning">'.&mt('Reservation no longer reported as available.').'</span>';
3058: }
3059: $r->print($msg);
3060: &return_link($r);
3061: } elsif (&get_slot($r,$symb,$env{'form.releaseslot'},1)) {
3062: &release_slot($r,$symb,$env{'form.releaseslot'});
3063: }
3064: } else {
3065: $r->print('<p>'.&mt('Unknown command: [_1]',$env{'form.command'}).'</p>');
3066: }
3067: }
3068: &end_page($r);
3069: return OK;
3070: }
3071:
3072: 1;
3073: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>