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