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