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