Annotation of loncom/interface/slotrequest.pm, revision 1.80
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # Handler for requesting to have slots added to a students record
3: #
1.80 ! albertel 4: # $Id: slotrequest.pm,v 1.79 2007/04/11 21:49:02 albertel 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.28 albertel 59: my ($r,$title)=@_;
1.52 albertel 60: $r->print(&Apache::loncommon::start_page($title));
1.1 albertel 61: }
62:
63: sub end_page {
64: my ($r)=@_;
1.52 albertel 65: $r->print(&Apache::loncommon::end_page());
1.1 albertel 66: }
67:
1.2 albertel 68: =pod
69:
70: slot_reservations db
71: - keys are
72: - slotname\0id -> value is an hashref of
73: name -> user@domain of holder
74: timestamp -> timestamp of reservation
75: symb -> symb of resource that it is reserved for
76:
77: =cut
78:
79: sub get_course {
1.69 albertel 80: (undef,my $courseid)=&Apache::lonnet::whichuser();
1.2 albertel 81: my $cdom=$env{'course.'.$courseid.'.domain'};
82: my $cnum=$env{'course.'.$courseid.'.num'};
83: return ($cnum,$cdom);
84: }
85:
86: sub get_reservation_ids {
87: my ($slot_name)=@_;
88:
89: my ($cnum,$cdom)=&get_course();
90:
91: my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
92: "^$slot_name\0");
1.67 albertel 93: if (&Apache::lonnet::error(%consumed)) {
1.40 albertel 94: return 'error: Unable to determine current status';
95: }
1.2 albertel 96: my ($tmp)=%consumed;
97: if ($tmp=~/^error: 2 / ) {
98: return 0;
99: }
100: return keys(%consumed);
101: }
102:
103: sub space_available {
104: my ($slot_name,$slot)=@_;
105: my $max=$slot->{'maxspace'};
106:
107: if (!defined($max)) { return 1; }
108:
109: my $consumed=scalar(&get_reservation_ids($slot_name));
110: if ($consumed < $max) {
111: return 1
112: }
113: return 0;
114: }
1.3 albertel 115:
1.4 albertel 116: sub check_for_reservation {
1.43 albertel 117: my ($symb,$mode)=@_;
1.4 albertel 118: my $student = &Apache::lonnet::EXT("resource.0.availablestudent", $symb,
119: $env{'user.domain'}, $env{'user.name'});
120:
121: my $course = &Apache::lonnet::EXT("resource.0.available", $symb,
122: $env{'user.domain'}, $env{'user.name'});
123: my @slots = (split(/:/,$student), split(/:/, $course));
124:
125: &Apache::lonxml::debug(" slot list is ".join(':',@slots));
126:
127: my ($cnum,$cdom)=&get_course();
128: my %slots=&Apache::lonnet::get('slots', [@slots], $cdom, $cnum);
129:
1.67 albertel 130: if (&Apache::lonnet::error($student)
131: || &Apache::lonnet::error($course)
132: || &Apache::lonnet::error(%slots)) {
1.41 albertel 133: return 'error: Unable to determine current status';
134: }
1.43 albertel 135: my @got;
136: foreach my $slot_name (sort {
137: if (ref($slots{$a}) && ref($slots{$b})) {
138: return $slots{$a}{'starttime'} <=> $slots{$b}{'starttime'}
139: }
140: if (ref($slots{$a})) { return -1;}
141: if (ref($slots{$b})) { return 1;}
142: return 0;
143: } @slots) {
1.4 albertel 144: next if (!defined($slots{$slot_name}) ||
145: !ref($slots{$slot_name}));
146: &Apache::lonxml::debug(time." $slot_name ".
147: $slots{$slot_name}->{'starttime'}." -- ".
148: $slots{$slot_name}->{'startreserve'});
1.7 albertel 149: if ($slots{$slot_name}->{'endtime'} > time &&
1.4 albertel 150: $slots{$slot_name}->{'startreserve'} < time) {
1.7 albertel 151: # between start of reservation times and end of slot
1.43 albertel 152: if ($mode eq 'allslots') {
153: push(@got,$slot_name);
154: } else {
155: return($slot_name, $slots{$slot_name});
156: }
1.4 albertel 157: }
158: }
1.43 albertel 159: if ($mode eq 'allslots' && @got) {
160: return @got;
161: }
1.4 albertel 162: return (undef,undef);
163: }
164:
1.48 albertel 165: sub get_consumed_uniqueperiods {
166: my ($slots) = @_;
167: my $navmap=Apache::lonnavmaps::navmap->new;
168: my @problems = $navmap->retrieveResources(undef,
169: sub { $_[0]->is_problem() },1,0);
170: my %used_slots;
171: foreach my $problem (@problems) {
172: my $symb = $problem->symb();
173: my $student = &Apache::lonnet::EXT("resource.0.availablestudent",
174: $symb, $env{'user.domain'},
175: $env{'user.name'});
176: my $course = &Apache::lonnet::EXT("resource.0.available",
177: $symb, $env{'user.domain'},
178: $env{'user.name'});
1.67 albertel 179: if (&Apache::lonnet::error($student)
180: || &Apache::lonnet::error($course)) {
1.48 albertel 181: return 'error: Unable to determine current status';
182: }
183: foreach my $slot (split(/:/,$student), split(/:/, $course)) {
184: $used_slots{$slot}=1;
185: }
186: }
1.43 albertel 187:
188: if (!ref($slots)) {
1.48 albertel 189: my ($cnum,$cdom)=&get_course();
190: my %slots=&Apache::lonnet::get('slots', [keys(%used_slots)], $cdom, $cnum);
1.67 albertel 191: if (&Apache::lonnet::error(%slots)) {
1.48 albertel 192: return 'error: Unable to determine current status';
193: }
1.43 albertel 194: $slots = \%slots;
195: }
1.41 albertel 196:
1.48 albertel 197: my %consumed_uniqueperiods;
198: foreach my $slot_name (keys(%used_slots)) {
1.43 albertel 199: next if (!defined($slots->{$slot_name}) ||
200: !ref($slots->{$slot_name}));
1.48 albertel 201:
1.43 albertel 202: next if (!defined($slots->{$slot_name}{'uniqueperiod'}) ||
203: !ref($slots->{$slot_name}{'uniqueperiod'}));
1.48 albertel 204: $consumed_uniqueperiods{$slot_name} =
205: $slots->{$slot_name}{'uniqueperiod'};
206: }
207: return \%consumed_uniqueperiods;
208: }
209:
210: sub check_for_conflict {
211: my ($symb,$new_slot_name,$new_slot,$slots,$consumed_uniqueperiods)=@_;
212:
213: if (!defined($new_slot->{'uniqueperiod'})) { return undef; }
214:
215: if (!ref($consumed_uniqueperiods)) {
216: $consumed_uniqueperiods = &get_consumed_uniqueperiods($slots);
1.67 albertel 217: if (&Apache::lonnet::error(%$consumed_uniqueperiods)) {
1.48 albertel 218: return 'error: Unable to determine current status';
219: }
220: }
221:
222: my ($new_uniq_start,$new_uniq_end) = @{$new_slot->{'uniqueperiod'}};
223: foreach my $slot_name (keys(%$consumed_uniqueperiods)) {
224: my ($start,$end)=@{$consumed_uniqueperiods->{$slot_name}};
1.43 albertel 225: if (!
226: ($start < $new_uniq_start && $end < $new_uniq_start) ||
227: ($start > $new_uniq_end && $end > $new_uniq_end )) {
1.5 albertel 228: return $slot_name;
229: }
230: }
231: return undef;
232:
233: }
234:
1.2 albertel 235: sub make_reservation {
236: my ($slot_name,$slot,$symb)=@_;
1.3 albertel 237:
238: my ($cnum,$cdom)=&get_course();
239:
240: my $value=&Apache::lonnet::EXT("resource.0.availablestudent",$symb,
241: $env{'user.domain'},$env{'user.name'});
242: &Apache::lonxml::debug("value is $value<br />");
1.59 albertel 243:
1.80 ! albertel 244: my $use_slots = &Apache::lonnet::EXT("resource.0.useslots",$symb,
! 245: $env{'user.domain'},$env{'user.name'});
1.59 albertel 246: &Apache::lonxml::debug("use_slots is $use_slots<br />");
247:
1.67 albertel 248: if (&Apache::lonnet::error($value)
249: || &Apache::lonnet::error($use_slots)) {
1.40 albertel 250: return 'error: Unable to determine current status';
251: }
252:
1.59 albertel 253: my $parm_symb = $symb;
254: my $parm_level = 1;
1.66 albertel 255: if ($use_slots eq 'map' || $use_slots eq 'map_map') {
1.59 albertel 256: my ($map) = &Apache::lonnet::decode_symb($symb);
257: $parm_symb = &Apache::lonnet::symbread($map);
258: $parm_level = 2;
259: }
260:
1.3 albertel 261: foreach my $other_slot (split(/:/, $value)) {
262: if ($other_slot eq $slot_name) {
263: my %consumed=&Apache::lonnet::dump('slot_reservations', $cdom,
264: $cnum, "^$slot_name\0");
1.67 albertel 265: if (&Apache::lonnet::error($value)) {
1.40 albertel 266: return 'error: Unable to determine current status';
267: }
1.57 albertel 268: my $me=$env{'user.name'}.':'.$env{'user.domain'};
1.3 albertel 269: foreach my $key (keys(%consumed)) {
270: if ($consumed{$key}->{'name'} eq $me) {
271: my $num=(split('\0',$key))[1];
272: return -$num;
273: }
274: }
275: }
276: }
277:
1.2 albertel 278: my $max=$slot->{'maxspace'};
1.3 albertel 279: if (!defined($max)) { $max=99999; }
1.2 albertel 280:
281: my (@ids)=&get_reservation_ids($slot_name);
1.67 albertel 282: if (&Apache::lonnet::error(@ids)) {
1.40 albertel 283: return 'error: Unable to determine current status';
284: }
1.2 albertel 285: my $last=0;
286: foreach my $id (@ids) {
287: my $num=(split('\0',$id))[1];
288: if ($num > $last) { $last=$num; }
289: }
290:
291: my $wanted=$last+1;
1.3 albertel 292: &Apache::lonxml::debug("wanted $wanted<br />");
1.7 albertel 293: if (scalar(@ids) >= $max) {
1.2 albertel 294: # full up
1.7 albertel 295: return undef;
1.2 albertel 296: }
297:
1.57 albertel 298: my %reservation=('name' => $env{'user.name'}.':'.$env{'user.domain'},
1.2 albertel 299: 'timestamp' => time,
1.59 albertel 300: 'symb' => $parm_symb);
1.2 albertel 301:
302: my $success=&Apache::lonnet::newput('slot_reservations',
303: {"$slot_name\0$wanted" =>
304: \%reservation},
1.3 albertel 305: $cdom, $cnum);
306:
1.2 albertel 307: if ($success eq 'ok') {
1.3 albertel 308: my $new_value=$slot_name;
309: if ($value) {
310: $new_value=$value.':'.$new_value;
311: }
312: my $result=&Apache::lonparmset::storeparm_by_symb($symb,
313: '0_availablestudent',
1.59 albertel 314: $parm_level, $new_value,
315: 'string',
1.3 albertel 316: $env{'user.name'},
317: $env{'user.domain'});
318: &Apache::lonxml::debug("hrrm $result");
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.33 albertel 326: sub remove_registration {
327: my ($r) = @_;
1.55 albertel 328: if ($env{'form.entry'} ne 'remove all') {
329: return &remove_registration_user($r);
330: }
331: my $slot_name = $env{'form.slotname'};
332: my %slot=&Apache::lonnet::get_slot($slot_name);
333:
334: my ($cnum,$cdom)=&get_course();
335: my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
336: "^$slot_name\0");
1.67 albertel 337: if (&Apache::lonnet::error(%consumed)) {
1.78 albertel 338: $r->print("<p><span class=\"LC_error\">".&mt('A network error has occured.').'</span></p>');
1.55 albertel 339: return;
340: }
341: if (!%consumed) {
342: $r->print("<p>".&mt('Slot <tt>[_1]</tt> has no reservations.',
343: $slot_name)."</p>");
344: return;
345: }
346:
347: my @names = map { $consumed{$_}{'name'} } (sort(keys(%consumed)));
348: my $names = join(' ',@names);
349:
350: my $msg = &mt('Remove all of [_1] from slot [_2]?',$names,$slot_name);
351: &remove_registration_confirmation($r,$msg,['entry','slotname']);
352: }
353:
354: sub remove_registration_user {
355: my ($r) = @_;
356:
357: my $slot_name = $env{'form.slotname'};
358:
1.33 albertel 359: my $name = &Apache::loncommon::plainname($env{'form.uname'},
360: $env{'form.udom'});
361:
362: my $title = &Apache::lonnet::gettitle($env{'form.symb'});
363:
1.55 albertel 364: my $msg = &mt('Remove [_1] from slot [_2] for [_3]',
365: $name,$slot_name,$title);
366:
367: &remove_registration_confirmation($r,$msg,['uname','udom','slotname',
368: 'entry','symb']);
369: }
370:
371: sub remove_registration_confirmation {
372: my ($r,$msg,$inputs) =@_;
373:
1.33 albertel 374: my $hidden_input;
1.55 albertel 375: foreach my $parm (@{$inputs}) {
1.33 albertel 376: $hidden_input .=
377: '<input type="hidden" name="'.$parm.'" value="'
378: .&HTML::Entities::encode($env{'form.'.$parm},'"<>&\'').'" />'."\n";
379: }
1.55 albertel 380: my %lt = &Apache::lonlocal::texthash('yes' => 'Yes',
381: 'no' => 'No',);
1.33 albertel 382: $r->print(<<"END_CONFIRM");
1.55 albertel 383: <p> $msg </p>
1.64 albertel 384: <form action="/adm/slotrequest" method="post">
1.33 albertel 385: <input type="hidden" name="command" value="release" />
1.55 albertel 386: <input type="hidden" name="button" value="yes" />
1.33 albertel 387: $hidden_input
1.55 albertel 388: <input type="submit" value="$lt{'yes'}" />
1.33 albertel 389: </form>
1.64 albertel 390: <form action="/adm/slotrequest" method="post">
1.33 albertel 391: <input type="hidden" name="command" value="showslots" />
1.55 albertel 392: <input type="submit" value="$lt{'no'}" />
1.33 albertel 393: </form>
394: END_CONFIRM
395:
396: }
397:
1.55 albertel 398: sub release_all_slot {
399: my ($r,$mgr)=@_;
400:
401: my $slot_name = $env{'form.slotname'};
402:
403: my ($cnum,$cdom)=&get_course();
404:
405: my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
406: "^$slot_name\0");
407:
408: $r->print('<p>'.&mt('Releasing reservations').'</p>');
409:
410: foreach my $entry (sort { $consumed{$a}{'name'} cmp
411: $consumed{$b}{'name'} } (keys(%consumed))) {
1.57 albertel 412: my ($uname,$udom) = split(':',$consumed{$entry}{'name'});
1.55 albertel 413: my ($result,$msg) =
414: &release_reservation($slot_name,$uname,$udom,
415: $consumed{$entry}{'symb'},$mgr);
416: $r->print("<p>$msg</p>");
417: $r->rflush();
418: }
419: $r->print('<p><a href="/adm/slotrequest?command=showslots">'.
420: &mt('Return to slot list').'</a></p>');
421: &return_link($r);
422: }
423:
1.5 albertel 424: sub release_slot {
1.33 albertel 425: my ($r,$symb,$slot_name,$inhibit_return_link,$mgr)=@_;
1.6 albertel 426:
427: if ($slot_name eq '') { $slot_name=$env{'form.slotname'}; }
428:
1.33 albertel 429: my ($uname,$udom) = ($env{'user.name'}, $env{'user.domain'});
430: if ($mgr eq 'F'
431: && defined($env{'form.uname'}) && defined($env{'form.udom'})) {
432: ($uname,$udom) = ($env{'form.uname'}, $env{'form.udom'});
433: }
434:
435: if ($mgr eq 'F'
436: && defined($env{'form.symb'})) {
1.71 albertel 437: $symb = &unescape($env{'form.symb'});
1.33 albertel 438: }
1.55 albertel 439:
440: my ($result,$msg) =
441: &release_reservation($slot_name,$uname,$udom,$symb,$mgr);
442: $r->print("<p>$msg</p>");
443:
444: if ($mgr eq 'F') {
445: $r->print('<p><a href="/adm/slotrequest?command=showslots">'.
446: &mt('Return to slot list').'</a></p>');
447: }
448:
449: if (!$inhibit_return_link) { &return_link($r); }
450: return $result;
451: }
452:
453: sub release_reservation {
454: my ($slot_name,$uname,$udom,$symb,$mgr) = @_;
1.39 albertel 455: my %slot=&Apache::lonnet::get_slot($slot_name);
1.55 albertel 456: my $description=&get_description($slot_name,\%slot);
1.33 albertel 457:
1.39 albertel 458: if ($mgr ne 'F') {
1.43 albertel 459: if ($slot{'starttime'} < time) {
1.55 albertel 460: return (0,&mt('Not allowed to release Reservation: [_1], as it has already ended.',$description));
1.39 albertel 461: }
462: }
1.80 ! albertel 463:
! 464: # if the reservation symb is for a map get a resource in that map
! 465: # to check slot parameters on
! 466: my $navmap=Apache::lonnavmaps::navmap->new;
! 467: my $passed_resource = $navmap->getBySymb($symb);
! 468: if ($passed_resource->is_map()) {
! 469: my ($a_resource) =
! 470: $navmap->retrieveResources($passed_resource,
! 471: sub {$_[0]->is_problem()},0,1);
! 472: $symb = $a_resource->symb();
! 473: }
! 474:
1.5 albertel 475: # get parameter string, check for existance, rebuild string with the slot
1.6 albertel 476: my @slots = split(/:/,&Apache::lonnet::EXT("resource.0.availablestudent",
1.33 albertel 477: $symb,$udom,$uname));
478:
1.6 albertel 479: my @new_slots;
480: foreach my $exist_slot (@slots) {
481: if ($exist_slot eq $slot_name) { next; }
482: push(@new_slots,$exist_slot);
483: }
484: my $new_param = join(':',@new_slots);
1.5 albertel 485:
1.55 albertel 486: my ($cnum,$cdom)=&get_course();
487:
1.5 albertel 488: # get slot reservations, check if user has one, if so remove reservation
1.6 albertel 489: my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
490: "^$slot_name\0");
491: foreach my $entry (keys(%consumed)) {
1.57 albertel 492: if ( $consumed{$entry}->{'name'} eq ($uname.':'.$udom) ) {
1.6 albertel 493: &Apache::lonnet::del('slot_reservations',[$entry],
494: $cdom,$cnum);
495: }
496: }
1.33 albertel 497:
1.80 ! albertel 498: my $use_slots = &Apache::lonnet::EXT("resource.0.useslots",
! 499: $symb,$udom,$uname);
1.59 albertel 500: &Apache::lonxml::debug("use_slots is $use_slots<br />");
501:
1.67 albertel 502: if (&Apache::lonnet::error($use_slots)) {
1.59 albertel 503: return (0,'error: Unable to determine current status');
504: }
505:
506: my $parm_level = 1;
1.66 albertel 507: if ($use_slots eq 'map' || $use_slots eq 'map_map') {
1.59 albertel 508: $parm_level = 2;
509: }
1.5 albertel 510: # store new parameter string
1.6 albertel 511: my $result=&Apache::lonparmset::storeparm_by_symb($symb,
512: '0_availablestudent',
1.59 albertel 513: $parm_level, $new_param,
514: 'string', $uname, $udom);
1.55 albertel 515:
516: my $msg;
1.33 albertel 517: if ($mgr eq 'F') {
1.55 albertel 518: $msg = &mt('Released Reservation for user: [_1]',"$uname:$udom");
519: } else {
520: $msg = &mt('Released Reservation: [_1]',$description);
1.33 albertel 521: }
1.55 albertel 522: return (1,$msg);
1.5 albertel 523: }
524:
1.34 albertel 525: sub delete_slot {
526: my ($r)=@_;
527:
528: my $slot_name = $env{'form.slotname'};
529: my %slot=&Apache::lonnet::get_slot($slot_name);
530:
531: my ($cnum,$cdom)=&get_course();
532: my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
533: "^$slot_name\0");
1.38 albertel 534: my ($tmp) = %consumed;
535: if ($tmp =~ /error: 2/) { undef(%consumed); }
1.34 albertel 536:
537: if (%slot && !%consumed) {
538: $slot{'type'} = 'deleted';
539: my $ret = &Apache::lonnet::cput('slots', {$slot_name => \%slot},
540: $cdom, $cnum);
541: if ($ret eq 'ok') {
542: $r->print("<p>Slot <tt>$slot_name</tt> marked as deleted.</p>");
543: } else {
1.78 albertel 544: $r->print("<p><span class=\"LC_error\"> An error ($ret) occurse when attempting to delete Slot <tt>$slot_name</tt>.</span></p>");
1.34 albertel 545: }
546: } else {
547: if (%consumed) {
548: $r->print("<p>Slot <tt>$slot_name</tt> has active reservations.</p>");
549: } else {
550: $r->print("<p>Slot <tt>$slot_name</tt> does not exist.</p>");
551: }
552: }
553: $r->print('<p><a href="/adm/slotrequest?command=showslots">'.
554: &mt('Return to slot list').'</a></p>');
1.42 albertel 555: &return_link($r);
1.34 albertel 556: }
557:
1.40 albertel 558: sub return_link {
559: my ($r) = @_;
560: $r->print('<p><a href="/adm/flip?postdata=return:">'.
561: &mt('Return to last resource').'</a></p>');
562: }
563:
1.3 albertel 564: sub get_slot {
1.75 albertel 565: my ($r,$symb,$conflictable_slot,$inhibit_return_link)=@_;
1.3 albertel 566:
1.43 albertel 567: my %slot=&Apache::lonnet::get_slot($env{'form.slotname'});
568: my $slot_name=&check_for_conflict($symb,$env{'form.slotname'},\%slot);
1.40 albertel 569:
570: if ($slot_name =~ /^error: (.*)/) {
1.78 albertel 571: $r->print("<p><span class=\"LC_error\">An error occured while attempting to make a reservation. ($1)</span></p>");
1.40 albertel 572: &return_link($r);
1.75 albertel 573: return 0;
1.40 albertel 574: }
1.75 albertel 575: if ($slot_name && $slot_name ne $conflictable_slot) {
1.5 albertel 576: my %slot=&Apache::lonnet::get_slot($slot_name);
1.6 albertel 577: my $description1=&get_description($slot_name,\%slot);
578: %slot=&Apache::lonnet::get_slot($env{'form.slotname'});
579: my $description2=&get_description($env{'form.slotname'},\%slot);
580: $r->print("<p>Already have a reservation: $description1</p>");
1.7 albertel 581: if ($slot_name ne $env{'form.slotname'}) {
582: $r->print(<<STUFF);
1.64 albertel 583: <form method="post" action="/adm/slotrequest">
1.6 albertel 584: <input type="hidden" name="symb" value="$env{'form.symb'}" />
585: <input type="hidden" name="slotname" value="$env{'form.slotname'}" />
586: <input type="hidden" name="releaseslot" value="$slot_name" />
587: <input type="hidden" name="command" value="change" />
588: STUFF
1.7 albertel 589: $r->print("<p>You can either ");
590: $r->print(<<STUFF);
1.6 albertel 591: <input type="submit" name="change" value="Change" />
592: STUFF
1.7 albertel 593: $r->print(' your reservation from <b>'.$description1.'</b> to <b>'.
594: $description2.
1.40 albertel 595: '</b> <br />or </p>');
596: &return_link($r);
1.7 albertel 597: $r->print(<<STUFF);
1.6 albertel 598: </form>
599: STUFF
1.7 albertel 600: } else {
1.40 albertel 601: &return_link($r);
1.7 albertel 602: }
1.75 albertel 603: return 0;
1.5 albertel 604: }
1.45 albertel 605:
1.3 albertel 606: my $reserved=&make_reservation($env{'form.slotname'},
607: \%slot,$symb);
608: my $description=&get_description($env{'form.slotname'},\%slot);
1.7 albertel 609: if (defined($reserved)) {
1.75 albertel 610: my $retvalue = 0;
1.40 albertel 611: if ($slot_name =~ /^error: (.*)/) {
1.78 albertel 612: $r->print("<p><span class=\"LC_error\">An error occured while attempting to make a reservation. ($1)</span></p>");
1.40 albertel 613: } elsif ($reserved > -1) {
1.7 albertel 614: $r->print("<p>Success: $description</p>");
1.75 albertel 615: $retvalue = 1;
1.7 albertel 616: } elsif ($reserved < 0) {
617: $r->print("<p>Already reserved: $description</p>");
618: }
1.75 albertel 619: if (!$inhibit_return_link) { &return_link($r); }
620: return 1;
1.3 albertel 621: }
622:
1.7 albertel 623: my %lt=('request'=>"Availibility list",
1.3 albertel 624: 'try' =>'Try again');
625: %lt=&Apache::lonlocal::texthash(%lt);
626:
1.75 albertel 627: my $extra_input;
628: if ($conflictable_slot) {
629: $extra_input='<input type="hidden" name="releaseslot" value="'.$env{'form.slotname'}.'" />';
630: }
631:
1.3 albertel 632: $r->print(<<STUFF);
1.78 albertel 633: <p> <span class="LC_warning">Failed</span> to reserve a spot for $description. </p>
1.3 albertel 634: <p>
1.64 albertel 635: <form method="post" action="/adm/slotrequest">
1.3 albertel 636: <input type="submit" name="Try Again" value="$lt{'try'}" />
637: <input type="hidden" name="symb" value="$env{'form.symb'}" />
638: <input type="hidden" name="slotname" value="$env{'form.slotname'}" />
1.75 albertel 639: <input type="hidden" name="command" value="$env{'form.command'}" />
640: $extra_input
1.3 albertel 641: </form>
642: ?
643: </p>
644: <p>
645: or
1.64 albertel 646: <form method="post" action="/adm/slotrequest">
1.3 albertel 647: <input type="hidden" name="symb" value="$env{'form.symb'}" />
648: <input type="submit" name="requestattempt" value="$lt{'request'}" />
649: </form>
650: </p>
651: or
652: STUFF
1.42 albertel 653:
1.75 albertel 654: if (!$inhibit_return_link) { &return_link($r); }
655: return 0;
1.3 albertel 656: }
657:
658: sub allowed_slot {
1.48 albertel 659: my ($slot_name,$slot,$symb,$slots,$consumed_uniqueperiods)=@_;
1.49 albertel 660:
1.3 albertel 661: #already started
662: if ($slot->{'starttime'} < time) {
1.76 albertel 663: return 0;
1.3 albertel 664: }
1.5 albertel 665: &Apache::lonxml::debug("$slot_name starttime good");
1.49 albertel 666:
1.3 albertel 667: #already ended
668: if ($slot->{'endtime'} < time) {
669: return 0;
670: }
1.5 albertel 671: &Apache::lonxml::debug("$slot_name endtime good");
1.49 albertel 672:
1.3 albertel 673: # not allowed to pick this one
674: if (defined($slot->{'type'})
675: && $slot->{'type'} ne 'schedulable_student') {
676: return 0;
677: }
1.5 albertel 678: &Apache::lonxml::debug("$slot_name type good");
1.49 albertel 679:
1.53 albertel 680: # reserve time not yet started
681: if ($slot->{'startreserve'} > time) {
682: return 0;
683: }
684: &Apache::lonxml::debug("$slot_name reserve good");
685:
1.50 albertel 686: my $userallowed=0;
1.49 albertel 687: # its for a different set of users
1.50 albertel 688: if (defined($slot->{'allowedsections'})) {
689: if (!defined($env{'request.role.sec'})
690: && grep(/^No section assigned$/,
691: split(',',$slot->{'allowedsections'}))) {
692: $userallowed=1;
693: }
694: if (defined($env{'request.role.sec'})
695: && grep(/^\Q$env{'request.role.sec'}\E$/,
696: split(',',$slot->{'allowedsections'}))) {
697: $userallowed=1;
698: }
1.68 albertel 699: if (defined($env{'request.course.groups'})) {
700: my @groups = split(/:/,$env{'request.course.groups'});
701: my @allowed_sec = split(',',$slot->{'allowedsections'});
702: foreach my $group (@groups) {
703: if (grep {$_ eq $group} (@allowed_sec)) {
704: $userallowed=1;
705: last;
706: }
707: }
708: }
1.49 albertel 709: }
1.50 albertel 710: &Apache::lonxml::debug("$slot_name sections is $userallowed");
1.49 albertel 711:
712: # its for a different set of users
1.50 albertel 713: if (defined($slot->{'allowedusers'})
714: && grep(/^\Q$env{'user.name'}:$env{'user.domain'}\E$/,
715: split(',',$slot->{'allowedusers'}))) {
716: $userallowed=1;
1.49 albertel 717: }
1.51 albertel 718:
719: if (!defined($slot->{'allowedusers'})
720: && !defined($slot->{'allowedsections'})) {
721: $userallowed=1;
722: }
723:
1.50 albertel 724: &Apache::lonxml::debug("$slot_name user is $userallowed");
725: return 0 if (!$userallowed);
1.49 albertel 726:
1.3 albertel 727: # not allowed for this resource
728: if (defined($slot->{'symb'})
729: && $slot->{'symb'} ne $symb) {
730: return 0;
731: }
1.50 albertel 732:
1.48 albertel 733: my $conflict = &check_for_conflict($symb,$slot_name,$slot,$slots,
734: $consumed_uniqueperiods);
1.44 albertel 735: if ($conflict) {
736: if ($slots->{$conflict}{'starttime'} < time) {
737: return 0;
738: }
739: }
1.5 albertel 740: &Apache::lonxml::debug("$slot_name symb good");
1.3 albertel 741: return 1;
1.2 albertel 742: }
743:
1.3 albertel 744: sub get_description {
745: my ($slot_name,$slot)=@_;
746: my $description=$slot->{'description'};
747: if (!defined($description)) {
1.4 albertel 748: $description=&mt('[_1] From [_2] to [_3]',$slot_name,
1.3 albertel 749: &Apache::lonlocal::locallocaltime($slot->{'starttime'}),
750: &Apache::lonlocal::locallocaltime($slot->{'endtime'}));
751: }
752: return $description;
753: }
1.2 albertel 754:
755: sub show_choices {
756: my ($r,$symb)=@_;
757:
758: my ($cnum,$cdom)=&get_course();
759: my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
1.48 albertel 760: my $consumed_uniqueperiods = &get_consumed_uniqueperiods(\%slots);
1.3 albertel 761: my $available;
1.2 albertel 762: $r->print('<table border="1">');
1.5 albertel 763: &Apache::lonxml::debug("Checking Slots");
1.43 albertel 764: my @got_slots=&check_for_reservation($symb,'allslots');
1.2 albertel 765: foreach my $slot (sort
766: { return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'} }
767: (keys(%slots))) {
1.5 albertel 768:
769: &Apache::lonxml::debug("Checking Slot $slot");
1.48 albertel 770: next if (!&allowed_slot($slot,$slots{$slot},undef,\%slots,
771: $consumed_uniqueperiods));
1.3 albertel 772:
773: $available++;
774:
775: my $description=&get_description($slot,$slots{$slot});
1.2 albertel 776:
777: my $form=&mt('Unavailable');
1.43 albertel 778: if ((grep(/^\Q$slot\E$/,@got_slots)) ||
1.7 albertel 779: &space_available($slot,$slots{$slot},$symb)) {
1.5 albertel 780: my $text=&mt('Select');
781: my $command='get';
1.43 albertel 782: if (grep(/^\Q$slot\E$/,@got_slots)) {
1.70 albertel 783: $text=&mt('Drop Reservation');
1.5 albertel 784: $command='release';
1.43 albertel 785: } else {
786: my $conflict = &check_for_conflict($symb,$slot,$slots{$slot},
1.48 albertel 787: \%slots,
788: $consumed_uniqueperiods);
1.43 albertel 789: if ($conflict) {
790: $text=&mt('Change Reservation');
791: $command='get';
792: }
1.5 albertel 793: }
1.63 www 794: my $escsymb=&escape($symb);
1.2 albertel 795: $form=<<STUFF;
1.64 albertel 796: <form method="post" action="/adm/slotrequest">
1.5 albertel 797: <input type="submit" name="Select" value="$text" />
1.3 albertel 798: <input type="hidden" name="symb" value="$escsymb" />
799: <input type="hidden" name="slotname" value="$slot" />
1.5 albertel 800: <input type="hidden" name="command" value="$command" />
1.2 albertel 801: </form>
802: STUFF
803: }
804: $r->print(<<STUFF);
805: <tr>
806: <td>$form</td>
807: <td>$description</td>
808: </tr>
809: STUFF
810: }
1.3 albertel 811:
812: if (!$available) {
1.5 albertel 813: $r->print('<tr><td>No available times. <a href="/adm/flip?postdata=return:">'.
1.3 albertel 814: &mt('Return to last resource').'</a></td></tr>');
815: }
1.2 albertel 816: $r->print('</table>');
817: }
818:
1.30 albertel 819: sub to_show {
1.54 albertel 820: my ($slotname,$slot,$when,$deleted,$name) = @_;
1.30 albertel 821: my $time=time;
822: my $week=60*60*24*7;
1.54 albertel 823:
1.35 albertel 824: if ($deleted eq 'hide' && $slot->{'type'} eq 'deleted') {
825: return 0;
826: }
1.54 albertel 827:
828: if ($name && $name->{'value'} =~ /\w/) {
829: if ($name->{'type'} eq 'substring') {
830: if ($slotname !~ /\Q$name->{'value'}\E/) {
831: return 0;
832: }
833: }
834: if ($name->{'type'} eq 'exact') {
835: if ($slotname eq $name->{'value'}) {
836: return 0;
837: }
838: }
839: }
840:
1.35 albertel 841: if ($when eq 'any') {
842: return 1;
843: } elsif ($when eq 'now') {
1.30 albertel 844: if ($time > $slot->{'starttime'} &&
845: $time < $slot->{'endtime'}) {
846: return 1;
847: }
848: return 0;
849: } elsif ($when eq 'nextweek') {
850: if ( ($time < $slot->{'starttime'} &&
851: ($time+$week) > $slot->{'starttime'})
852: ||
853: ($time < $slot->{'endtime'} &&
854: ($time+$week) > $slot->{'endtime'}) ) {
855: return 1;
856: }
857: return 0;
858: } elsif ($when eq 'lastweek') {
859: if ( ($time > $slot->{'starttime'} &&
860: ($time-$week) < $slot->{'starttime'})
861: ||
862: ($time > $slot->{'endtime'} &&
863: ($time-$week) < $slot->{'endtime'}) ) {
864: return 1;
865: }
866: return 0;
867: } elsif ($when eq 'willopen') {
868: if ($time < $slot->{'starttime'}) {
869: return 1;
870: }
871: return 0;
872: } elsif ($when eq 'wereopen') {
873: if ($time > $slot->{'endtime'}) {
874: return 1;
875: }
876: return 0;
877: }
878:
879: return 1;
880: }
881:
1.33 albertel 882: sub remove_link {
883: my ($slotname,$entry,$uname,$udom,$symb) = @_;
884:
1.55 albertel 885: my $remove = &mt('Remove');
886:
887: if ($entry eq 'remove all') {
888: $remove = &mt('Remove All');
889: undef($uname);
890: undef($udom);
891: }
892:
1.63 www 893: $slotname = &escape($slotname);
894: $entry = &escape($entry);
895: $uname = &escape($uname);
896: $udom = &escape($udom);
897: $symb = &escape($symb);
1.33 albertel 898:
899: return <<"END_LINK";
1.64 albertel 900: <a href="/adm/slotrequest?command=remove_registration&slotname=$slotname&entry=$entry&uname=$uname&udom=$udom&symb=$symb"
1.33 albertel 901: >($remove)</a>
902: END_LINK
903:
904: }
905:
1.5 albertel 906: sub show_table {
1.19 albertel 907: my ($r,$mgr)=@_;
1.5 albertel 908:
909: my ($cnum,$cdom)=&get_course();
910: my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
1.19 albertel 911: if ( (keys(%slots))[0] =~ /^error: 2 /) {
912: undef(%slots);
913: }
1.5 albertel 914: my $available;
1.14 albertel 915: if ($mgr eq 'F') {
1.72 rezaferr 916: # FIXME: This line should be deleted once Slots uses breadcrumbs
1.73 albertel 917: $r->print(&Apache::loncommon::help_open_topic('Slot About', 'Help on slots'));
1.72 rezaferr 918:
1.30 albertel 919: $r->print('<div>');
1.64 albertel 920: $r->print('<form method="post" action="/adm/slotrequest">
1.14 albertel 921: <input type="hidden" name="command" value="uploadstart" />
922: <input type="submit" name="start" value="'.&mt('Upload Slot List').'" />
923: </form>');
1.72 rezaferr 924: $r->print(&Apache::loncommon::help_open_topic('Slot CommaDelimited'));
1.64 albertel 925: $r->print('<form method="post" action="/adm/helper/newslot.helper">
1.28 albertel 926: <input type="submit" name="newslot" value="'.&mt('Create a New Slot').'" />
927: </form>');
1.72 rezaferr 928: $r->print(&Apache::loncommon::help_open_topic('Slot AddInterface'));
1.30 albertel 929: $r->print('</div>');
1.14 albertel 930: }
1.29 albertel 931:
1.54 albertel 932: my %Saveable_Parameters = ('show' => 'array',
933: 'when' => 'scalar',
934: 'order' => 'scalar',
935: 'deleted' => 'scalar',
936: 'name_filter_type' => 'scalar',
937: 'name_filter_value' => 'scalar',
1.35 albertel 938: );
1.46 albertel 939: &Apache::loncommon::store_course_settings('slotrequest',
940: \%Saveable_Parameters);
941: &Apache::loncommon::restore_course_settings('slotrequest',
942: \%Saveable_Parameters);
943: &Apache::grades::init_perm();
944: my ($classlist,$section,$fullname)=&Apache::grades::getclasslist('all');
945: &Apache::grades::reset_perm();
1.29 albertel 946:
1.54 albertel 947: # what to display filtering
1.30 albertel 948: my %show_fields=&Apache::lonlocal::texthash(
1.49 albertel 949: 'name' => 'Slot Name',
950: 'description' => 'Description',
951: 'type' => 'Type',
952: 'starttime' => 'Start time',
953: 'endtime' => 'End Time',
954: 'startreserve' => 'Time students can start reserving',
955: 'secret' => 'Secret Word',
1.74 albertel 956: 'space' => '# of students/max',
1.49 albertel 957: 'ip' => 'IP or DNS restrictions',
958: 'symb' => 'Resource slot is restricted to.',
959: 'allowedsections' => 'Sections slot is restricted to.',
960: 'allowedusers' => 'Users slot is restricted to.',
961: 'uniqueperiod' => 'Period of time slot is unique',
962: 'scheduled' => 'Scheduled Students',
963: 'proctor' => 'List of proctors');
1.30 albertel 964: my @show_order=('name','description','type','starttime','endtime',
1.74 albertel 965: 'startreserve','secret','space','ip','symb',
1.49 albertel 966: 'allowedsections','allowedusers','uniqueperiod',
967: 'scheduled','proctor');
1.30 albertel 968: my @show =
1.29 albertel 969: (exists($env{'form.show'})) ? &Apache::loncommon::get_env_multiple('form.show')
1.30 albertel 970: : keys(%show_fields);
971: my %show = map { $_ => 1 } (@show);
972:
1.54 albertel 973: #when filtering setup
1.30 albertel 974: my %when_fields=&Apache::lonlocal::texthash(
1.35 albertel 975: 'now' => 'Open now',
1.30 albertel 976: 'nextweek' => 'Open within the next week',
977: 'lastweek' => 'Were open last week',
978: 'willopen' => 'Will open later',
1.35 albertel 979: 'wereopen' => 'Were open',
980: 'any' => 'Anytime',
981: );
982: my @when_order=('any','now','nextweek','lastweek','willopen','wereopen');
1.30 albertel 983: $when_fields{'select_form_order'} = \@when_order;
984: my $when = (exists($env{'form.when'})) ? $env{'form.when'}
985: : 'now';
1.29 albertel 986:
1.54 albertel 987: #display of students setup
1.46 albertel 988: my %stu_display_fields=
989: &Apache::lonlocal::texthash('username' => 'User name',
990: 'fullname' => 'Full name',
991: );
992: my @stu_display_order=('fullname','username');
993: my @stu_display =
994: (exists($env{'form.studisplay'})) ? &Apache::loncommon::get_env_multiple('form.studisplay')
995: : keys(%stu_display_fields);
996: my %stu_display = map { $_ => 1 } (@stu_display);
997:
1.54 albertel 998: #name filtering setup
999: my %name_filter_type_fields=
1000: &Apache::lonlocal::texthash('substring' => 'Substring',
1001: 'exact' => 'Exact',
1002: #'reg' => 'Regular Expression',
1003: );
1004: my @name_filter_type_order=('substring','exact');
1005:
1006: $name_filter_type_fields{'select_form_order'} = \@name_filter_type_order;
1007: my $name_filter_type =
1008: (exists($env{'form.name_filter_type'})) ? $env{'form.name_filter_type'}
1009: : 'substring';
1010: my $name_filter = {'type' => $name_filter_type,
1011: 'value' => $env{'form.name_filter_value'},};
1012:
1.64 albertel 1013:
1.54 albertel 1014: #deleted slot filtering
1.64 albertel 1015: #default to hide if no value
1016: $env{'form.deleted'} ||= 'hide';
1.35 albertel 1017: my $hide_radio =
1018: &Apache::lonhtmlcommon::radio('deleted',$env{'form.deleted'},'hide');
1019: my $show_radio =
1020: &Apache::lonhtmlcommon::radio('deleted',$env{'form.deleted'},'show');
1021:
1.64 albertel 1022: $r->print('<form method="post" action="/adm/slotrequest">
1.30 albertel 1023: <input type="hidden" name="command" value="showslots" />');
1024: $r->print('<div>');
1.35 albertel 1025: $r->print('<table class="inline">
1026: <tr><th>'.&mt('Show').'</th>
1.46 albertel 1027: <th>'.&mt('Student Display').'</th>
1.35 albertel 1028: <th>'.&mt('Open').'</th>
1.54 albertel 1029: <th>'.&mt('Slot Name Filter').'</th>
1.35 albertel 1030: <th>'.&mt('Options').'</th>
1031: </tr>
1032: <tr><td>'.&Apache::loncommon::multiple_select_form('show',\@show,6,\%show_fields,\@show_order).
1033: '</td>
1.46 albertel 1034: <td>
1035: '.&Apache::loncommon::multiple_select_form('studisplay',\@stu_display,
1036: 6,\%stu_display_fields,
1037: \@stu_display_order).'
1038: </td>
1.35 albertel 1039: <td>'.&Apache::loncommon::select_form($when,'when',%when_fields).
1040: '</td>
1.54 albertel 1041: <td>'.&Apache::loncommon::select_form($name_filter_type,
1042: 'name_filter_type',
1043: %name_filter_type_fields).
1044: '<br />'.
1045: &Apache::lonhtmlcommon::textbox('name_filter_value',
1046: $env{'form.name_filter_value'},
1047: 15).
1048: '</td>
1.35 albertel 1049: <td>
1050: <table>
1051: <tr>
1052: <td rowspan="2">Deleted slots:</td>
1053: <td><label>'.$show_radio.'Show</label></td>
1054: </tr>
1055: <tr>
1056: <td><label>'.$hide_radio.'Hide</label></td>
1057: </tr>
1058: </table>
1059: </td>
1060: </tr>
1061: </table>');
1.30 albertel 1062: $r->print('</div>');
1063: $r->print('<p><input type="submit" name="start" value="'.&mt('Update Display').'" /></p>');
1.21 albertel 1064: my $linkstart='<a href="/adm/slotrequest?command=showslots&order=';
1.65 albertel 1065: $r->print(&Apache::loncommon::start_data_table().
1066: &Apache::loncommon::start_data_table_header_row().'
1067: <th></th>');
1.30 albertel 1068: foreach my $which (@show_order) {
1069: if ($which ne 'proctor' && exists($show{$which})) {
1070: $r->print('<th>'.$linkstart.$which.'">'.$show_fields{$which}.'</a></th>');
1.29 albertel 1071: }
1072: }
1.65 albertel 1073: $r->print(&Apache::loncommon::end_data_table_header_row());
1.29 albertel 1074:
1.21 albertel 1075: my %name_cache;
1076: my $slotsort = sub {
1.74 albertel 1077: if ($env{'form.order'}=~/^(type|description|endtime|startreserve|ip|symb|allowedsections|allowedusers)$/) {
1.21 albertel 1078: if (lc($slots{$a}->{$env{'form.order'}})
1079: ne lc($slots{$b}->{$env{'form.order'}})) {
1080: return (lc($slots{$a}->{$env{'form.order'}})
1081: cmp lc($slots{$b}->{$env{'form.order'}}));
1082: }
1.74 albertel 1083: } elsif ($env{'form.order'} eq 'space') {
1084: if ($slots{$a}{'maxspace'} ne $slots{$b}{'maxspace'}) {
1085: return ($slots{$a}{'maxspace'} cmp $slots{$b}{'maxspace'});
1086: }
1.23 albertel 1087: } elsif ($env{'form.order'} eq 'name') {
1088: if (lc($a) cmp lc($b)) {
1089: return lc($a) cmp lc($b);
1090: }
1.29 albertel 1091: } elsif ($env{'form.order'} eq 'uniqueperiod') {
1.21 albertel 1092:
1093: if ($slots{$a}->{'uniqueperiod'}[0]
1094: ne $slots{$b}->{'uniqueperiod'}[0]) {
1095: return ($slots{$a}->{'uniqueperiod'}[0]
1096: cmp $slots{$b}->{'uniqueperiod'}[0]);
1097: }
1098: if ($slots{$a}->{'uniqueperiod'}[1]
1099: ne $slots{$b}->{'uniqueperiod'}[1]) {
1100: return ($slots{$a}->{'uniqueperiod'}[1]
1101: cmp $slots{$b}->{'uniqueperiod'}[1]);
1102: }
1103: }
1104: return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'};
1105: };
1.74 albertel 1106:
1107: my %consumed;
1108: if (exists($show{'scheduled'}) || exists($show{'space'}) ) {
1109: %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum);
1110: my ($tmp)=%consumed;
1111: if ($tmp =~ /^error: /) { undef(%consumed); }
1112: }
1113:
1.21 albertel 1114: foreach my $slot (sort $slotsort (keys(%slots))) {
1.54 albertel 1115: if (!&to_show($slot,$slots{$slot},$when,
1116: $env{'form.deleted'},$name_filter)) { next; }
1.5 albertel 1117: if (defined($slots{$slot}->{'type'})
1118: && $slots{$slot}->{'type'} ne 'schedulable_student') {
1.13 albertel 1119: #next;
1.5 albertel 1120: }
1121: my $description=&get_description($slot,$slots{$slot});
1.74 albertel 1122: my ($id_count,$ids);
1123:
1124: if (exists($show{'scheduled'}) || exists($show{'space'}) ) {
1.79 albertel 1125: my $re_str = "$slot\0";
1126: my @this_slot = grep(/^\Q$re_str\E/,keys(%consumed));
1.74 albertel 1127: $id_count = scalar(@this_slot);
1128: if (exists($show{'scheduled'})) {
1.54 albertel 1129: foreach my $entry (sort { $consumed{$a}{name} cmp
1130: $consumed{$b}{name} }
1.79 albertel 1131: (@this_slot)) {
1.47 albertel 1132: my (undef,$id)=split("\0",$entry);
1.57 albertel 1133: my ($uname,$udom) = split(':',$consumed{$entry}{'name'});
1.47 albertel 1134: $ids.= '<nobr>';
1135: foreach my $item (@stu_display_order) {
1136: if ($stu_display{$item}) {
1137: if ($item eq 'fullname') {
1138: $ids.=$fullname->{"$uname:$udom"}.' ';
1139: } elsif ($item eq 'username') {
1.57 albertel 1140: $ids.="<tt>$uname:$udom</tt> ";
1.47 albertel 1141: }
1.46 albertel 1142: }
1143: }
1.47 albertel 1144: $ids.=&remove_link($slot,$entry,$uname,$udom,
1145: $consumed{$entry}{'symb'}).'</nobr><br />';
1.46 albertel 1146: }
1.38 albertel 1147: }
1.5 albertel 1148: }
1.33 albertel 1149:
1.24 albertel 1150: my $start=($slots{$slot}->{'starttime'}?
1151: &Apache::lonlocal::locallocaltime($slots{$slot}->{'starttime'}):'');
1152: my $end=($slots{$slot}->{'endtime'}?
1153: &Apache::lonlocal::locallocaltime($slots{$slot}->{'endtime'}):'');
1.28 albertel 1154: my $start_reserve=($slots{$slot}->{'startreserve'}?
1.24 albertel 1155: &Apache::lonlocal::locallocaltime($slots{$slot}->{'startreserve'}):'');
1156:
1.14 albertel 1157: my $unique;
1158: if (ref($slots{$slot}{'uniqueperiod'})) {
1.64 albertel 1159: $unique=localtime($slots{$slot}{'uniqueperiod'}[0]).', '.
1.14 albertel 1160: localtime($slots{$slot}{'uniqueperiod'}[1]);
1161: }
1.33 albertel 1162:
1.29 albertel 1163: my $title;
1164: if (exists($slots{$slot}{'symb'})) {
1165: my (undef,undef,$res)=
1166: &Apache::lonnet::decode_symb($slots{$slot}{'symb'});
1167: $res = &Apache::lonnet::clutter($res);
1168: $title = &Apache::lonnet::gettitle($slots{$slot}{'symb'});
1169: $title='<a href="'.$res.'?symb='.$slots{$slot}{'symb'}.'">'.$title.'</a>';
1170: }
1.33 albertel 1171:
1.49 albertel 1172: my $allowedsections;
1173: if (exists($show{'allowedsections'})) {
1174: $allowedsections =
1175: join(', ',sort(split(/\s*,\s*/,
1176: $slots{$slot}->{'allowedsections'})));
1177: }
1178:
1179: my @allowedusers;
1180: if (exists($show{'allowedusers'})) {
1181: @allowedusers= map {
1182: my ($uname,$udom)=split(/:/,$_);
1183: my $fullname=$name_cache{$_};
1184: if (!defined($fullname)) {
1185: $fullname = &Apache::loncommon::plainname($uname,$udom);
1186: $fullname =~s/\s/ /g;
1187: $name_cache{$_} = $fullname;
1188: }
1189: &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
1190: } (sort(split(/\s*,\s*/,$slots{$slot}->{'allowedusers'})));
1191: }
1192: my $allowedusers=join(', ',@allowedusers);
1193:
1.29 albertel 1194: my @proctors;
1195: my $rowspan=1;
1196: my $colspan=1;
1.30 albertel 1197: if (exists($show{'proctor'})) {
1.29 albertel 1198: $rowspan=2;
1199: @proctors= map {
1.62 albertel 1200: my ($uname,$udom)=split(/:/,$_);
1.29 albertel 1201: my $fullname=$name_cache{$_};
1202: if (!defined($fullname)) {
1203: $fullname = &Apache::loncommon::plainname($uname,$udom);
1204: $fullname =~s/\s/ /g;
1205: $name_cache{$_} = $fullname;
1206: }
1207: &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
1208: } (sort(split(/\s*,\s*/,$slots{$slot}->{'proctor'})));
1209: }
1.20 albertel 1210: my $proctors=join(', ',@proctors);
1.14 albertel 1211:
1.34 albertel 1212: my $edit=(<<"EDITLINK");
1.31 albertel 1213: <a href="/adm/helper/newslot.helper?name=$slot">Edit</a>
1214: EDITLINK
1.34 albertel 1215:
1216: my $delete=(<<"DELETELINK");
1.64 albertel 1217: <a href="/adm/slotrequest?command=delete&slotname=$slot">Delete</a>
1.34 albertel 1218: DELETELINK
1.55 albertel 1219:
1.56 albertel 1220: my $remove_all=&remove_link($slot,'remove all').'<br />';
1.55 albertel 1221:
1.34 albertel 1222: if ($ids ne '') { undef($delete); }
1.56 albertel 1223: if ($slots{$slot}{'type'} ne 'schedulable_student'
1224: || $ids eq '') {
1.55 albertel 1225: undef($remove_all);
1226: }
1.34 albertel 1227:
1.65 albertel 1228: my $row_start=&Apache::loncommon::start_data_table_row();
1229: my $row_end=&Apache::loncommon::end_data_table_row();
1230: $r->print($row_start.
1231: "\n<td rowspan=\"$rowspan\">$edit $delete</td>\n");
1.30 albertel 1232: if (exists($show{'name'})) {
1.29 albertel 1233: $colspan++;$r->print("<td>$slot</td>");
1234: }
1.33 albertel 1235: if (exists($show{'description'})) {
1236: $colspan++;$r->print("<td>$description</td>\n");
1237: }
1.30 albertel 1238: if (exists($show{'type'})) {
1.29 albertel 1239: $colspan++;$r->print("<td>$slots{$slot}->{'type'}</td>\n");
1240: }
1.30 albertel 1241: if (exists($show{'starttime'})) {
1.29 albertel 1242: $colspan++;$r->print("<td>$start</td>\n");
1243: }
1.30 albertel 1244: if (exists($show{'endtime'})) {
1.29 albertel 1245: $colspan++;$r->print("<td>$end</td>\n");
1246: }
1.30 albertel 1247: if (exists($show{'startreserve'})) {
1.29 albertel 1248: $colspan++;$r->print("<td>$start_reserve</td>\n");
1249: }
1.30 albertel 1250: if (exists($show{'secret'})) {
1.29 albertel 1251: $colspan++;$r->print("<td>$slots{$slot}{'secret'}</td>\n");
1252: }
1.74 albertel 1253: if (exists($show{'space'})) {
1254: my $display = $id_count;
1255: if ($slots{$slot}{'maxspace'}>0) {
1256: $display.='/'.$slots{$slot}{'maxspace'};
1257: if ($slots{$slot}{'maxspace'} <= $id_count) {
1258: $display = '<strong>'.$display.' (full) </strong>';
1259: }
1260: }
1261: $colspan++;$r->print("<td>$display</td>\n");
1.29 albertel 1262: }
1.30 albertel 1263: if (exists($show{'ip'})) {
1.29 albertel 1264: $colspan++;$r->print("<td>$slots{$slot}{'ip'}</td>\n");
1265: }
1.30 albertel 1266: if (exists($show{'symb'})) {
1.29 albertel 1267: $colspan++;$r->print("<td>$title</td>\n");
1268: }
1.49 albertel 1269: if (exists($show{'allowedsections'})) {
1270: $colspan++;$r->print("<td>$allowedsections</td>\n");
1271: }
1272: if (exists($show{'allowedusers'})) {
1273: $colspan++;$r->print("<td>$allowedusers</td>\n");
1.29 albertel 1274: }
1.64 albertel 1275: if (exists($show{'uniqueperiod'})) {
1276: $colspan++;$r->print("<td>$unique</td>\n");
1277: }
1.47 albertel 1278: if (exists($show{'scheduled'})) {
1.64 albertel 1279: $colspan++;$r->print("<td>$remove_all $ids</td>\n");
1.47 albertel 1280: }
1.65 albertel 1281: $r->print("$row_end\n");
1.30 albertel 1282: if (exists($show{'proctor'})) {
1.29 albertel 1283: $r->print(<<STUFF);
1.65 albertel 1284: $row_start
1.29 albertel 1285: <td colspan="$colspan">$proctors</td>
1.65 albertel 1286: $row_end
1.5 albertel 1287: STUFF
1.29 albertel 1288: }
1.5 albertel 1289: }
1.64 albertel 1290: $r->print('</table></form>');
1.5 albertel 1291: }
1292:
1.14 albertel 1293: sub upload_start {
1.19 albertel 1294: my ($r)=@_;
1.14 albertel 1295: $r->print(&Apache::grades::checkforfile_js());
1296: my $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
1297: $result.=' <b>'.
1298: &mt('Specify a file containing the slot definitions.').
1299: '</b></td></tr>'."\n";
1300: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1301: my $upfile_select=&Apache::loncommon::upfile_select_html();
1302: my $ignore=&mt('Ignore First Line');
1303: $result.=<<ENDUPFORM;
1304: <form method="post" enctype="multipart/form-data" action="/adm/slotrequest" name="slotupload">
1305: <input type="hidden" name="command" value="csvuploadmap" />
1306: $upfile_select
1307: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Data" />
1308: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1309: </form>
1310: ENDUPFORM
1311: $result.='</td></tr></table>'."\n";
1312: $result.='</td></tr></table>'."\n";
1313: $r->print($result);
1314: }
1315:
1316: sub csvuploadmap_header {
1.19 albertel 1317: my ($r,$datatoken,$distotal)= @_;
1.14 albertel 1318: my $javascript;
1319: if ($env{'form.upfile_associate'} eq 'reverse') {
1320: $javascript=&csvupload_javascript_reverse_associate();
1321: } else {
1322: $javascript=&csvupload_javascript_forward_associate();
1323: }
1324:
1325: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1326: my $ignore=&mt('Ignore First Line');
1.72 rezaferr 1327: my $help_field = &Apache::loncommon::help_open_topic('Slot SelectingField');
1328:
1.14 albertel 1329: $r->print(<<ENDPICK);
1330: <form method="post" enctype="multipart/form-data" action="/adm/slotrequest" name="slotupload">
1.72 rezaferr 1331: <h3>Identify fields $help_field</h3>
1.14 albertel 1332: Total number of records found in file: $distotal <hr />
1333: Enter as many fields as you can. The system will inform you and bring you back
1334: to this page if the data selected is insufficient to create the slots.<hr />
1335: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1336: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1337: <input type="hidden" name="associate" value="" />
1338: <input type="hidden" name="datatoken" value="$datatoken" />
1339: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
1340: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1341: <input type="hidden" name="upfile_associate"
1342: value="$env{'form.upfile_associate'}" />
1343: <input type="hidden" name="command" value="csvuploadassign" />
1344: <hr />
1345: <script type="text/javascript" language="Javascript">
1346: $javascript
1347: </script>
1348: ENDPICK
1349: return '';
1350:
1351: }
1352:
1353: sub csvuploadmap_footer {
1354: my ($request,$i,$keyfields) =@_;
1355: $request->print(<<ENDPICK);
1356: </table>
1357: <input type="hidden" name="nfields" value="$i" />
1358: <input type="hidden" name="keyfields" value="$keyfields" />
1359: <input type="button" onClick="javascript:verify(this.form)" value="Create Slots" /><br />
1360: </form>
1361: ENDPICK
1362: }
1363:
1364: sub csvupload_javascript_reverse_associate {
1365: my $error1=&mt('You need to specify the name, starttime, endtime and a type');
1366: return(<<ENDPICK);
1367: function verify(vf) {
1368: var foundstart=0;
1369: var foundend=0;
1370: var foundname=0;
1371: var foundtype=0;
1372: for (i=0;i<=vf.nfields.value;i++) {
1373: tw=eval('vf.f'+i+'.selectedIndex');
1374: if (i==0 && tw!=0) { foundname=1; }
1375: if (i==1 && tw!=0) { foundtype=1; }
1376: if (i==2 && tw!=0) { foundstat=1; }
1377: if (i==3 && tw!=0) { foundend=1; }
1378: }
1379: if (foundstart==0 && foundend==0 && foundtype==0 && foundname==0) {
1380: alert('$error1');
1381: return;
1382: }
1383: vf.submit();
1384: }
1385: function flip(vf,tf) {
1386: }
1387: ENDPICK
1388: }
1389:
1390: sub csvupload_javascript_forward_associate {
1391: my $error1=&mt('You need to specify the name, starttime, endtime and a type');
1392: return(<<ENDPICK);
1393: function verify(vf) {
1394: var foundstart=0;
1395: var foundend=0;
1396: var foundname=0;
1397: var foundtype=0;
1398: for (i=0;i<=vf.nfields.value;i++) {
1399: tw=eval('vf.f'+i+'.selectedIndex');
1400: if (tw==1) { foundname=1; }
1401: if (tw==2) { foundtype=1; }
1402: if (tw==3) { foundstat=1; }
1403: if (tw==4) { foundend=1; }
1404: }
1405: if (foundstart==0 && foundend==0 && foundtype==0 && foundname==0) {
1406: alert('$error1');
1407: return;
1408: }
1409: vf.submit();
1410: }
1411: function flip(vf,tf) {
1412: }
1413: ENDPICK
1414: }
1415:
1416: sub csv_upload_map {
1.19 albertel 1417: my ($r)= @_;
1.14 albertel 1418:
1419: my $datatoken;
1420: if (!$env{'form.datatoken'}) {
1421: $datatoken=&Apache::loncommon::upfile_store($r);
1422: } else {
1423: $datatoken=$env{'form.datatoken'};
1424: &Apache::loncommon::load_tmp_file($r);
1425: }
1426: my @records=&Apache::loncommon::upfile_record_sep();
1427: if ($env{'form.noFirstLine'}) { shift(@records); }
1.19 albertel 1428: &csvuploadmap_header($r,$datatoken,$#records+1);
1.14 albertel 1429: my ($i,$keyfields);
1430: if (@records) {
1431: my @fields=&csvupload_fields();
1432:
1433: if ($env{'form.upfile_associate'} eq 'reverse') {
1434: &Apache::loncommon::csv_print_samples($r,\@records);
1435: $i=&Apache::loncommon::csv_print_select_table($r,\@records,
1436: \@fields);
1437: foreach (@fields) { $keyfields.=$_->[0].','; }
1438: chop($keyfields);
1439: } else {
1440: unshift(@fields,['none','']);
1441: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
1442: \@fields);
1443: my %sone=&Apache::loncommon::record_sep($records[0]);
1444: $keyfields=join(',',sort(keys(%sone)));
1445: }
1446: }
1447: &csvuploadmap_footer($r,$i,$keyfields);
1448:
1449: return '';
1450: }
1451:
1452: sub csvupload_fields {
1453: return (['name','Slot name'],
1454: ['type','Type of slot'],
1455: ['starttime','Start Time of slot'],
1456: ['endtime','End Time of slot'],
1.15 albertel 1457: ['startreserve','Reservation Start Time'],
1.14 albertel 1458: ['ip','IP or DNS restriction'],
1459: ['proctor','List of proctor ids'],
1460: ['description','Slot Description'],
1461: ['maxspace','Maximum number of reservations'],
1462: ['symb','Resource Restriction'],
1463: ['uniqueperiod','Date range of slot exclusion'],
1.49 albertel 1464: ['secret','Secret word proctor uses to validate'],
1465: ['allowedsections','Sections slot is restricted to'],
1466: ['allowedusers','Users slot is restricted to'],
1467: );
1.14 albertel 1468: }
1469:
1470: sub csv_upload_assign {
1.19 albertel 1471: my ($r,$mgr)= @_;
1.14 albertel 1472: &Apache::loncommon::load_tmp_file($r);
1473: my @slotdata = &Apache::loncommon::upfile_record_sep();
1474: if ($env{'form.noFirstLine'}) { shift(@slotdata); }
1475: my %fields=&Apache::grades::get_fields();
1476: $r->print('<h3>Creating Slots</h3>');
1477: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1478: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1479: my $countdone=0;
1.31 albertel 1480: my @errors;
1.14 albertel 1481: foreach my $slot (@slotdata) {
1482: my %slot;
1483: my %entries=&Apache::loncommon::record_sep($slot);
1484: my $domain;
1485: my $name=$entries{$fields{'name'}};
1.31 albertel 1486: if ($name=~/^\s*$/) {
1487: push(@errors,"Did not create slot with no name");
1488: next;
1489: }
1490: if ($name=~/\s/) {
1491: push(@errors,"$name not created -- Name must not contain spaces");
1492: next;
1493: }
1494: if ($name=~/\W/) {
1495: push(@errors,"$name not created -- Name must contain only letters, numbers and _");
1496: next;
1497: }
1.14 albertel 1498: if ($entries{$fields{'type'}}) {
1499: $slot{'type'}=$entries{$fields{'type'}};
1500: } else {
1501: $slot{'type'}='preassigned';
1502: }
1.31 albertel 1503: if ($slot{'type'} ne 'preassigned' &&
1504: $slot{'type'} ne 'schedulable_student') {
1505: push(@errors,"$name not created -- invalid type ($slot{'type'}) must be either preassigned or schedulable_student");
1506: next;
1507: }
1.14 albertel 1508: if ($entries{$fields{'starttime'}}) {
1509: $slot{'starttime'}=&UnixDate($entries{$fields{'starttime'}},"%s");
1510: }
1511: if ($entries{$fields{'endtime'}}) {
1.16 albertel 1512: $slot{'endtime'}=&UnixDate($entries{$fields{'endtime'}},"%s");
1.14 albertel 1513: }
1.58 albertel 1514:
1515: # start/endtime must be defined and greater than zero
1516: if (!$slot{'starttime'}) {
1517: push(@errors,"$name not created -- Invalid start time");
1518: next;
1519: }
1520: if (!$slot{'endtime'}) {
1521: push(@errors,"$name not created -- Invalid end time");
1522: next;
1523: }
1524: if ($slot{'starttime'} > $slot{'endtime'}) {
1525: push(@errors,"$name not created -- Slot starts after it ends");
1526: next;
1527: }
1528:
1.23 albertel 1529: if ($entries{$fields{'startreserve'}}) {
1530: $slot{'startreserve'}=
1531: &UnixDate($entries{$fields{'startreserve'}},"%s");
1532: }
1.58 albertel 1533: if (defined($slot{'startreserve'})
1534: && $slot{'startreserve'} > $slot{'starttime'}) {
1535: push(@errors,"$name not created -- Slot's reservation start time is after the slot's start time.");
1536: next;
1537: }
1538:
1.14 albertel 1539: foreach my $key ('ip','proctor','description','maxspace',
1540: 'secret','symb') {
1541: if ($entries{$fields{$key}}) {
1542: $slot{$key}=$entries{$fields{$key}};
1543: }
1544: }
1.58 albertel 1545:
1.14 albertel 1546: if ($entries{$fields{'uniqueperiod'}}) {
1547: my ($start,$end)=split(',',$entries{$fields{'uniqueperiod'}});
1548: my @times=(&UnixDate($start,"%s"),
1549: &UnixDate($end,"%s"));
1550: $slot{'uniqueperiod'}=\@times;
1551: }
1.58 albertel 1552: if (defined($slot{'uniqueperiod'})
1553: && $slot{'uniqueperiod'}[0] > $slot{'uniqueperiod'}[1]) {
1554: push(@errors,"$name not created -- Slot's unique period start time is later than the unique period's end time.");
1555: next;
1556: }
1.14 albertel 1557:
1558: &Apache::lonnet::cput('slots',{$name=>\%slot},$cdom,$cname);
1559: $r->print('.');
1560: $r->rflush();
1561: $countdone++;
1562: }
1.31 albertel 1563: $r->print("<p>Created $countdone slots\n</p>");
1564: foreach my $error (@errors) {
1.78 albertel 1565: $r->print("<p><span class=\"LC_warning\">$error</span></p>\n");
1.31 albertel 1566: }
1.19 albertel 1567: &show_table($r,$mgr);
1.14 albertel 1568: return '';
1569: }
1570:
1.1 albertel 1571: sub handler {
1572: my $r=shift;
1573:
1.30 albertel 1574: &Apache::loncommon::content_type($r,'text/html');
1575: &Apache::loncommon::no_cache($r);
1576: if ($r->header_only()) {
1577: $r->send_http_header();
1578: return OK;
1579: }
1580:
1.8 albertel 1581: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.28 albertel 1582:
1.12 albertel 1583: my $vgr=&Apache::lonnet::allowed('vgr',$env{'request.course.id'});
1.14 albertel 1584: my $mgr=&Apache::lonnet::allowed('mgr',$env{'request.course.id'});
1.28 albertel 1585: my $title='Requesting Another Worktime';
1586: if ($env{'form.command'} =~ /^(showslots|uploadstart|csvuploadmap|csvuploadassign)$/ && $vgr eq 'F') {
1587: $title = 'Managing Slots';
1588: }
1589: &start_page($r,$title);
1590:
1.8 albertel 1591: if ($env{'form.command'} eq 'showslots' && $vgr eq 'F') {
1.19 albertel 1592: &show_table($r,$mgr);
1.33 albertel 1593: } elsif ($env{'form.command'} eq 'remove_registration' && $mgr eq 'F') {
1594: &remove_registration($r);
1595: } elsif ($env{'form.command'} eq 'release' && $mgr eq 'F') {
1.55 albertel 1596: if ($env{'form.entry'} eq 'remove all') {
1597: &release_all_slot($r,$mgr);
1598: } else {
1599: &release_slot($r,undef,undef,undef,$mgr);
1600: }
1.34 albertel 1601: } elsif ($env{'form.command'} eq 'delete' && $mgr eq 'F') {
1602: &delete_slot($r);
1.14 albertel 1603: } elsif ($env{'form.command'} eq 'uploadstart' && $mgr eq 'F') {
1.19 albertel 1604: &upload_start($r);
1.14 albertel 1605: } elsif ($env{'form.command'} eq 'csvuploadmap' && $mgr eq 'F') {
1.19 albertel 1606: &csv_upload_map($r);
1.14 albertel 1607: } elsif ($env{'form.command'} eq 'csvuploadassign' && $mgr eq 'F') {
1608: if ($env{'form.associate'} ne 'Reverse Association') {
1.19 albertel 1609: &csv_upload_assign($r,$mgr);
1.14 albertel 1610: } else {
1611: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
1612: $env{'form.upfile_associate'} = 'reverse';
1613: } else {
1614: $env{'form.upfile_associate'} = 'forward';
1615: }
1.19 albertel 1616: &csv_upload_map($r);
1.14 albertel 1617: }
1.8 albertel 1618: } else {
1.63 www 1619: my $symb=&unescape($env{'form.symb'});
1.61 albertel 1620: if (!defined($symb)) {
1621: &fail($r,'not_valid');
1622: return OK;
1623: }
1.19 albertel 1624: my (undef,undef,$res)=&Apache::lonnet::decode_symb($symb);
1.36 albertel 1625: my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb);
1.66 albertel 1626: if ($useslots ne 'resource'
1627: && $useslots ne 'map'
1628: && $useslots ne 'map_map') {
1.61 albertel 1629: &fail($r,'not_available');
1.19 albertel 1630: return OK;
1631: }
1632: $env{'request.symb'}=$symb;
1.36 albertel 1633: my $type = ($res =~ /\.task$/) ? 'Task'
1634: : 'problem';
1635: my ($status) = &Apache::lonhomework::check_slot_access('0',$type);
1.11 albertel 1636: if ($status eq 'CAN_ANSWER' ||
1637: $status eq 'NEEDS_CHECKIN' ||
1638: $status eq 'WAITING_FOR_GRADE') {
1639: &fail($r,'not_allowed');
1640: return OK;
1641: }
1642: if ($env{'form.requestattempt'}) {
1643: &show_choices($r,$symb);
1644: } elsif ($env{'form.command'} eq 'release') {
1645: &release_slot($r,$symb);
1646: } elsif ($env{'form.command'} eq 'get') {
1647: &get_slot($r,$symb);
1648: } elsif ($env{'form.command'} eq 'change') {
1.75 albertel 1649: if (&get_slot($r,$symb,$env{'form.releaseslot'},1)) {
1650: &release_slot($r,$symb,$env{'form.releaseslot'});
1.39 albertel 1651: }
1.11 albertel 1652: } else {
1653: $r->print("<p>Unknown command: ".$env{'form.command'}."</p>");
1654: }
1.2 albertel 1655: }
1.1 albertel 1656: &end_page($r);
1657: return OK;
1658: }
1.3 albertel 1659:
1660: 1;
1661: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>