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