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