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