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