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