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