Annotation of loncom/interface/slotrequest.pm, revision 1.88
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # Handler for requesting to have slots added to a students record
3: #
1.88 ! bisitz 4: # $Id: slotrequest.pm,v 1.87 2009/02/02 02:56:12 raeburn Exp $
1.1 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###
29:
30: package Apache::slotrequest;
31:
32: use strict;
33: use Apache::Constants qw(:common :http :methods);
34: use Apache::loncommon();
35: use Apache::lonlocal;
36: use Apache::lonnet;
1.48 albertel 37: use Apache::lonnavmaps();
1.27 albertel 38: use Date::Manip;
1.63 www 39: use lib '/home/httpd/lib/perl/';
40: use LONCAPA;
1.1 albertel 41:
42: sub fail {
43: my ($r,$code)=@_;
1.2 albertel 44: if ($code eq 'not_valid') {
1.8 albertel 45: $r->print('<p>'.&mt('Unable to understand what resource you wanted to sign up for.').'</p>');
1.61 albertel 46: } elsif ($code eq 'not_available') {
47: $r->print('<p>'.&mt('No slots are available.').'</p>');
1.8 albertel 48: } elsif ($code eq 'not_allowed') {
49: $r->print('<p>'.&mt('Not allowed to sign up or change reservations at this time.').'</p>');
50: } else {
51: $r->print('<p>'.&mt('Failed.').'</p>');
1.2 albertel 52: }
1.8 albertel 53:
1.42 albertel 54: &return_link($r);
1.1 albertel 55: &end_page($r);
56: }
57:
58: sub start_page {
1.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) {
676: $r->print(&mt('or').'</p>').&return_link($r);
677: } else {
678: $r->print('</p>');
679: }
1.75 albertel 680: return 0;
1.3 albertel 681: }
682:
683: sub allowed_slot {
1.48 albertel 684: my ($slot_name,$slot,$symb,$slots,$consumed_uniqueperiods)=@_;
1.49 albertel 685:
1.3 albertel 686: #already started
687: if ($slot->{'starttime'} < time) {
1.76 albertel 688: return 0;
1.3 albertel 689: }
1.5 albertel 690: &Apache::lonxml::debug("$slot_name starttime good");
1.49 albertel 691:
1.3 albertel 692: #already ended
693: if ($slot->{'endtime'} < time) {
694: return 0;
695: }
1.5 albertel 696: &Apache::lonxml::debug("$slot_name endtime good");
1.49 albertel 697:
1.3 albertel 698: # not allowed to pick this one
699: if (defined($slot->{'type'})
700: && $slot->{'type'} ne 'schedulable_student') {
701: return 0;
702: }
1.5 albertel 703: &Apache::lonxml::debug("$slot_name type good");
1.49 albertel 704:
1.53 albertel 705: # reserve time not yet started
706: if ($slot->{'startreserve'} > time) {
707: return 0;
708: }
709: &Apache::lonxml::debug("$slot_name reserve good");
710:
1.50 albertel 711: my $userallowed=0;
1.49 albertel 712: # its for a different set of users
1.50 albertel 713: if (defined($slot->{'allowedsections'})) {
714: if (!defined($env{'request.role.sec'})
715: && grep(/^No section assigned$/,
716: split(',',$slot->{'allowedsections'}))) {
717: $userallowed=1;
718: }
719: if (defined($env{'request.role.sec'})
720: && grep(/^\Q$env{'request.role.sec'}\E$/,
721: split(',',$slot->{'allowedsections'}))) {
722: $userallowed=1;
723: }
1.68 albertel 724: if (defined($env{'request.course.groups'})) {
725: my @groups = split(/:/,$env{'request.course.groups'});
726: my @allowed_sec = split(',',$slot->{'allowedsections'});
727: foreach my $group (@groups) {
728: if (grep {$_ eq $group} (@allowed_sec)) {
729: $userallowed=1;
730: last;
731: }
732: }
733: }
1.49 albertel 734: }
1.50 albertel 735: &Apache::lonxml::debug("$slot_name sections is $userallowed");
1.49 albertel 736:
737: # its for a different set of users
1.50 albertel 738: if (defined($slot->{'allowedusers'})
739: && grep(/^\Q$env{'user.name'}:$env{'user.domain'}\E$/,
740: split(',',$slot->{'allowedusers'}))) {
741: $userallowed=1;
1.49 albertel 742: }
1.51 albertel 743:
744: if (!defined($slot->{'allowedusers'})
745: && !defined($slot->{'allowedsections'})) {
746: $userallowed=1;
747: }
748:
1.50 albertel 749: &Apache::lonxml::debug("$slot_name user is $userallowed");
750: return 0 if (!$userallowed);
1.49 albertel 751:
1.3 albertel 752: # not allowed for this resource
753: if (defined($slot->{'symb'})
754: && $slot->{'symb'} ne $symb) {
755: return 0;
756: }
1.50 albertel 757:
1.48 albertel 758: my $conflict = &check_for_conflict($symb,$slot_name,$slot,$slots,
759: $consumed_uniqueperiods);
1.85 raeburn 760: if ($conflict =~ /^error: /) {
761: return 0;
1.86 raeburn 762: } elsif ($conflict ne '') {
1.44 albertel 763: if ($slots->{$conflict}{'starttime'} < time) {
764: return 0;
765: }
766: }
1.5 albertel 767: &Apache::lonxml::debug("$slot_name symb good");
1.3 albertel 768: return 1;
1.2 albertel 769: }
770:
1.3 albertel 771: sub get_description {
772: my ($slot_name,$slot)=@_;
773: my $description=$slot->{'description'};
774: if (!defined($description)) {
1.4 albertel 775: $description=&mt('[_1] From [_2] to [_3]',$slot_name,
1.3 albertel 776: &Apache::lonlocal::locallocaltime($slot->{'starttime'}),
777: &Apache::lonlocal::locallocaltime($slot->{'endtime'}));
778: }
779: return $description;
780: }
1.2 albertel 781:
782: sub show_choices {
783: my ($r,$symb)=@_;
784:
785: my ($cnum,$cdom)=&get_course();
786: my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
1.48 albertel 787: my $consumed_uniqueperiods = &get_consumed_uniqueperiods(\%slots);
1.85 raeburn 788: if (ref($consumed_uniqueperiods) eq 'HASH') {
789: if (&Apache::lonnet::error(%$consumed_uniqueperiods)) {
790: $r->print('<span class="LC_error">'.
791: &mt('An error occurred determining slot availability').
792: '</span>');
793: return;
794: }
795: } elsif ($consumed_uniqueperiods =~ /^error: /) {
796: $r->print('<span class="LC_error">'.
797: &mt('An error occurred determining slot availability').
798: '</span>');
799: return;
800: }
1.3 albertel 801: my $available;
1.5 albertel 802: &Apache::lonxml::debug("Checking Slots");
1.43 albertel 803: my @got_slots=&check_for_reservation($symb,'allslots');
1.85 raeburn 804: if ($got_slots[0] =~ /^error: /) {
805: $r->print('<span class="LC_error">'.
806: &mt('An error occurred determining slot availability').
807: '</span>');
808: return;
809: }
810: $r->print('<table border="1">');
1.2 albertel 811: foreach my $slot (sort
812: { return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'} }
813: (keys(%slots))) {
1.5 albertel 814:
815: &Apache::lonxml::debug("Checking Slot $slot");
1.48 albertel 816: next if (!&allowed_slot($slot,$slots{$slot},undef,\%slots,
817: $consumed_uniqueperiods));
1.3 albertel 818:
819: $available++;
820:
821: my $description=&get_description($slot,$slots{$slot});
1.2 albertel 822:
823: my $form=&mt('Unavailable');
1.43 albertel 824: if ((grep(/^\Q$slot\E$/,@got_slots)) ||
1.7 albertel 825: &space_available($slot,$slots{$slot},$symb)) {
1.5 albertel 826: my $text=&mt('Select');
827: my $command='get';
1.43 albertel 828: if (grep(/^\Q$slot\E$/,@got_slots)) {
1.70 albertel 829: $text=&mt('Drop Reservation');
1.5 albertel 830: $command='release';
1.43 albertel 831: } else {
832: my $conflict = &check_for_conflict($symb,$slot,$slots{$slot},
1.48 albertel 833: \%slots,
834: $consumed_uniqueperiods);
1.85 raeburn 835: if ($conflict) {
836: if ($conflict =~ /^error: /) {
837: $r->print('<tr><td><span class="LC_error" colspan="2">'
838: .&mt('Slot: [_1] has unknown status.',$description)
839: .'</span></td></tr>');
840: } else {
841: $text=&mt('Change Reservation');
842: $command='get';
843: }
844: }
1.5 albertel 845: }
1.63 www 846: my $escsymb=&escape($symb);
1.2 albertel 847: $form=<<STUFF;
1.64 albertel 848: <form method="post" action="/adm/slotrequest">
1.5 albertel 849: <input type="submit" name="Select" value="$text" />
1.3 albertel 850: <input type="hidden" name="symb" value="$escsymb" />
851: <input type="hidden" name="slotname" value="$slot" />
1.5 albertel 852: <input type="hidden" name="command" value="$command" />
1.2 albertel 853: </form>
854: STUFF
855: }
856: $r->print(<<STUFF);
857: <tr>
858: <td>$form</td>
859: <td>$description</td>
860: </tr>
861: STUFF
862: }
1.3 albertel 863:
864: if (!$available) {
1.87 raeburn 865: $r->print('<tr><td>'.&mt('No available times.').
866: ' <a href="/adm/flip?postdata=return:">'.
1.3 albertel 867: &mt('Return to last resource').'</a></td></tr>');
868: }
1.2 albertel 869: $r->print('</table>');
870: }
871:
1.30 albertel 872: sub to_show {
1.54 albertel 873: my ($slotname,$slot,$when,$deleted,$name) = @_;
1.30 albertel 874: my $time=time;
875: my $week=60*60*24*7;
1.54 albertel 876:
1.35 albertel 877: if ($deleted eq 'hide' && $slot->{'type'} eq 'deleted') {
878: return 0;
879: }
1.54 albertel 880:
881: if ($name && $name->{'value'} =~ /\w/) {
882: if ($name->{'type'} eq 'substring') {
883: if ($slotname !~ /\Q$name->{'value'}\E/) {
884: return 0;
885: }
886: }
887: if ($name->{'type'} eq 'exact') {
888: if ($slotname eq $name->{'value'}) {
889: return 0;
890: }
891: }
892: }
893:
1.35 albertel 894: if ($when eq 'any') {
895: return 1;
896: } elsif ($when eq 'now') {
1.30 albertel 897: if ($time > $slot->{'starttime'} &&
898: $time < $slot->{'endtime'}) {
899: return 1;
900: }
901: return 0;
902: } elsif ($when eq 'nextweek') {
903: if ( ($time < $slot->{'starttime'} &&
904: ($time+$week) > $slot->{'starttime'})
905: ||
906: ($time < $slot->{'endtime'} &&
907: ($time+$week) > $slot->{'endtime'}) ) {
908: return 1;
909: }
910: return 0;
911: } elsif ($when eq 'lastweek') {
912: if ( ($time > $slot->{'starttime'} &&
913: ($time-$week) < $slot->{'starttime'})
914: ||
915: ($time > $slot->{'endtime'} &&
916: ($time-$week) < $slot->{'endtime'}) ) {
917: return 1;
918: }
919: return 0;
920: } elsif ($when eq 'willopen') {
921: if ($time < $slot->{'starttime'}) {
922: return 1;
923: }
924: return 0;
925: } elsif ($when eq 'wereopen') {
926: if ($time > $slot->{'endtime'}) {
927: return 1;
928: }
929: return 0;
930: }
931:
932: return 1;
933: }
934:
1.33 albertel 935: sub remove_link {
936: my ($slotname,$entry,$uname,$udom,$symb) = @_;
937:
1.55 albertel 938: my $remove = &mt('Remove');
939:
940: if ($entry eq 'remove all') {
941: $remove = &mt('Remove All');
942: undef($uname);
943: undef($udom);
944: }
945:
1.63 www 946: $slotname = &escape($slotname);
947: $entry = &escape($entry);
948: $uname = &escape($uname);
949: $udom = &escape($udom);
950: $symb = &escape($symb);
1.33 albertel 951:
952: return <<"END_LINK";
1.64 albertel 953: <a href="/adm/slotrequest?command=remove_registration&slotname=$slotname&entry=$entry&uname=$uname&udom=$udom&symb=$symb"
1.33 albertel 954: >($remove)</a>
955: END_LINK
956:
957: }
958:
1.5 albertel 959: sub show_table {
1.19 albertel 960: my ($r,$mgr)=@_;
1.5 albertel 961:
962: my ($cnum,$cdom)=&get_course();
963: my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
1.19 albertel 964: if ( (keys(%slots))[0] =~ /^error: 2 /) {
965: undef(%slots);
966: }
1.5 albertel 967: my $available;
1.14 albertel 968: if ($mgr eq 'F') {
1.72 rezaferr 969: # FIXME: This line should be deleted once Slots uses breadcrumbs
1.73 albertel 970: $r->print(&Apache::loncommon::help_open_topic('Slot About', 'Help on slots'));
1.72 rezaferr 971:
1.30 albertel 972: $r->print('<div>');
1.64 albertel 973: $r->print('<form method="post" action="/adm/slotrequest">
1.14 albertel 974: <input type="hidden" name="command" value="uploadstart" />
975: <input type="submit" name="start" value="'.&mt('Upload Slot List').'" />
976: </form>');
1.72 rezaferr 977: $r->print(&Apache::loncommon::help_open_topic('Slot CommaDelimited'));
1.64 albertel 978: $r->print('<form method="post" action="/adm/helper/newslot.helper">
1.28 albertel 979: <input type="submit" name="newslot" value="'.&mt('Create a New Slot').'" />
980: </form>');
1.72 rezaferr 981: $r->print(&Apache::loncommon::help_open_topic('Slot AddInterface'));
1.30 albertel 982: $r->print('</div>');
1.14 albertel 983: }
1.29 albertel 984:
1.54 albertel 985: my %Saveable_Parameters = ('show' => 'array',
986: 'when' => 'scalar',
987: 'order' => 'scalar',
988: 'deleted' => 'scalar',
989: 'name_filter_type' => 'scalar',
990: 'name_filter_value' => 'scalar',
1.35 albertel 991: );
1.46 albertel 992: &Apache::loncommon::store_course_settings('slotrequest',
993: \%Saveable_Parameters);
994: &Apache::loncommon::restore_course_settings('slotrequest',
995: \%Saveable_Parameters);
996: &Apache::grades::init_perm();
997: my ($classlist,$section,$fullname)=&Apache::grades::getclasslist('all');
998: &Apache::grades::reset_perm();
1.29 albertel 999:
1.54 albertel 1000: # what to display filtering
1.30 albertel 1001: my %show_fields=&Apache::lonlocal::texthash(
1.49 albertel 1002: 'name' => 'Slot Name',
1003: 'description' => 'Description',
1004: 'type' => 'Type',
1005: 'starttime' => 'Start time',
1006: 'endtime' => 'End Time',
1007: 'startreserve' => 'Time students can start reserving',
1008: 'secret' => 'Secret Word',
1.74 albertel 1009: 'space' => '# of students/max',
1.49 albertel 1010: 'ip' => 'IP or DNS restrictions',
1011: 'symb' => 'Resource slot is restricted to.',
1012: 'allowedsections' => 'Sections slot is restricted to.',
1013: 'allowedusers' => 'Users slot is restricted to.',
1014: 'uniqueperiod' => 'Period of time slot is unique',
1015: 'scheduled' => 'Scheduled Students',
1016: 'proctor' => 'List of proctors');
1.30 albertel 1017: my @show_order=('name','description','type','starttime','endtime',
1.74 albertel 1018: 'startreserve','secret','space','ip','symb',
1.49 albertel 1019: 'allowedsections','allowedusers','uniqueperiod',
1020: 'scheduled','proctor');
1.30 albertel 1021: my @show =
1.29 albertel 1022: (exists($env{'form.show'})) ? &Apache::loncommon::get_env_multiple('form.show')
1.30 albertel 1023: : keys(%show_fields);
1024: my %show = map { $_ => 1 } (@show);
1025:
1.54 albertel 1026: #when filtering setup
1.30 albertel 1027: my %when_fields=&Apache::lonlocal::texthash(
1.35 albertel 1028: 'now' => 'Open now',
1.30 albertel 1029: 'nextweek' => 'Open within the next week',
1030: 'lastweek' => 'Were open last week',
1031: 'willopen' => 'Will open later',
1.35 albertel 1032: 'wereopen' => 'Were open',
1033: 'any' => 'Anytime',
1034: );
1035: my @when_order=('any','now','nextweek','lastweek','willopen','wereopen');
1.30 albertel 1036: $when_fields{'select_form_order'} = \@when_order;
1037: my $when = (exists($env{'form.when'})) ? $env{'form.when'}
1038: : 'now';
1.29 albertel 1039:
1.54 albertel 1040: #display of students setup
1.46 albertel 1041: my %stu_display_fields=
1042: &Apache::lonlocal::texthash('username' => 'User name',
1043: 'fullname' => 'Full name',
1044: );
1045: my @stu_display_order=('fullname','username');
1046: my @stu_display =
1047: (exists($env{'form.studisplay'})) ? &Apache::loncommon::get_env_multiple('form.studisplay')
1048: : keys(%stu_display_fields);
1049: my %stu_display = map { $_ => 1 } (@stu_display);
1050:
1.54 albertel 1051: #name filtering setup
1052: my %name_filter_type_fields=
1053: &Apache::lonlocal::texthash('substring' => 'Substring',
1054: 'exact' => 'Exact',
1055: #'reg' => 'Regular Expression',
1056: );
1057: my @name_filter_type_order=('substring','exact');
1058:
1059: $name_filter_type_fields{'select_form_order'} = \@name_filter_type_order;
1060: my $name_filter_type =
1061: (exists($env{'form.name_filter_type'})) ? $env{'form.name_filter_type'}
1062: : 'substring';
1063: my $name_filter = {'type' => $name_filter_type,
1064: 'value' => $env{'form.name_filter_value'},};
1065:
1.64 albertel 1066:
1.54 albertel 1067: #deleted slot filtering
1.64 albertel 1068: #default to hide if no value
1069: $env{'form.deleted'} ||= 'hide';
1.35 albertel 1070: my $hide_radio =
1071: &Apache::lonhtmlcommon::radio('deleted',$env{'form.deleted'},'hide');
1072: my $show_radio =
1073: &Apache::lonhtmlcommon::radio('deleted',$env{'form.deleted'},'show');
1074:
1.64 albertel 1075: $r->print('<form method="post" action="/adm/slotrequest">
1.30 albertel 1076: <input type="hidden" name="command" value="showslots" />');
1077: $r->print('<div>');
1.35 albertel 1078: $r->print('<table class="inline">
1079: <tr><th>'.&mt('Show').'</th>
1.46 albertel 1080: <th>'.&mt('Student Display').'</th>
1.35 albertel 1081: <th>'.&mt('Open').'</th>
1.54 albertel 1082: <th>'.&mt('Slot Name Filter').'</th>
1.35 albertel 1083: <th>'.&mt('Options').'</th>
1084: </tr>
1085: <tr><td>'.&Apache::loncommon::multiple_select_form('show',\@show,6,\%show_fields,\@show_order).
1086: '</td>
1.46 albertel 1087: <td>
1088: '.&Apache::loncommon::multiple_select_form('studisplay',\@stu_display,
1089: 6,\%stu_display_fields,
1090: \@stu_display_order).'
1091: </td>
1.35 albertel 1092: <td>'.&Apache::loncommon::select_form($when,'when',%when_fields).
1093: '</td>
1.54 albertel 1094: <td>'.&Apache::loncommon::select_form($name_filter_type,
1095: 'name_filter_type',
1096: %name_filter_type_fields).
1097: '<br />'.
1098: &Apache::lonhtmlcommon::textbox('name_filter_value',
1099: $env{'form.name_filter_value'},
1100: 15).
1101: '</td>
1.35 albertel 1102: <td>
1103: <table>
1104: <tr>
1105: <td rowspan="2">Deleted slots:</td>
1106: <td><label>'.$show_radio.'Show</label></td>
1107: </tr>
1108: <tr>
1109: <td><label>'.$hide_radio.'Hide</label></td>
1110: </tr>
1111: </table>
1112: </td>
1113: </tr>
1114: </table>');
1.30 albertel 1115: $r->print('</div>');
1116: $r->print('<p><input type="submit" name="start" value="'.&mt('Update Display').'" /></p>');
1.21 albertel 1117: my $linkstart='<a href="/adm/slotrequest?command=showslots&order=';
1.65 albertel 1118: $r->print(&Apache::loncommon::start_data_table().
1119: &Apache::loncommon::start_data_table_header_row().'
1120: <th></th>');
1.30 albertel 1121: foreach my $which (@show_order) {
1122: if ($which ne 'proctor' && exists($show{$which})) {
1123: $r->print('<th>'.$linkstart.$which.'">'.$show_fields{$which}.'</a></th>');
1.29 albertel 1124: }
1125: }
1.65 albertel 1126: $r->print(&Apache::loncommon::end_data_table_header_row());
1.29 albertel 1127:
1.21 albertel 1128: my %name_cache;
1129: my $slotsort = sub {
1.74 albertel 1130: if ($env{'form.order'}=~/^(type|description|endtime|startreserve|ip|symb|allowedsections|allowedusers)$/) {
1.21 albertel 1131: if (lc($slots{$a}->{$env{'form.order'}})
1132: ne lc($slots{$b}->{$env{'form.order'}})) {
1133: return (lc($slots{$a}->{$env{'form.order'}})
1134: cmp lc($slots{$b}->{$env{'form.order'}}));
1135: }
1.74 albertel 1136: } elsif ($env{'form.order'} eq 'space') {
1137: if ($slots{$a}{'maxspace'} ne $slots{$b}{'maxspace'}) {
1138: return ($slots{$a}{'maxspace'} cmp $slots{$b}{'maxspace'});
1139: }
1.23 albertel 1140: } elsif ($env{'form.order'} eq 'name') {
1141: if (lc($a) cmp lc($b)) {
1142: return lc($a) cmp lc($b);
1143: }
1.29 albertel 1144: } elsif ($env{'form.order'} eq 'uniqueperiod') {
1.21 albertel 1145:
1146: if ($slots{$a}->{'uniqueperiod'}[0]
1147: ne $slots{$b}->{'uniqueperiod'}[0]) {
1148: return ($slots{$a}->{'uniqueperiod'}[0]
1149: cmp $slots{$b}->{'uniqueperiod'}[0]);
1150: }
1151: if ($slots{$a}->{'uniqueperiod'}[1]
1152: ne $slots{$b}->{'uniqueperiod'}[1]) {
1153: return ($slots{$a}->{'uniqueperiod'}[1]
1154: cmp $slots{$b}->{'uniqueperiod'}[1]);
1155: }
1156: }
1157: return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'};
1158: };
1.74 albertel 1159:
1160: my %consumed;
1161: if (exists($show{'scheduled'}) || exists($show{'space'}) ) {
1162: %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum);
1163: my ($tmp)=%consumed;
1164: if ($tmp =~ /^error: /) { undef(%consumed); }
1165: }
1166:
1.21 albertel 1167: foreach my $slot (sort $slotsort (keys(%slots))) {
1.54 albertel 1168: if (!&to_show($slot,$slots{$slot},$when,
1169: $env{'form.deleted'},$name_filter)) { next; }
1.5 albertel 1170: if (defined($slots{$slot}->{'type'})
1171: && $slots{$slot}->{'type'} ne 'schedulable_student') {
1.13 albertel 1172: #next;
1.5 albertel 1173: }
1174: my $description=&get_description($slot,$slots{$slot});
1.74 albertel 1175: my ($id_count,$ids);
1176:
1177: if (exists($show{'scheduled'}) || exists($show{'space'}) ) {
1.79 albertel 1178: my $re_str = "$slot\0";
1179: my @this_slot = grep(/^\Q$re_str\E/,keys(%consumed));
1.74 albertel 1180: $id_count = scalar(@this_slot);
1181: if (exists($show{'scheduled'})) {
1.54 albertel 1182: foreach my $entry (sort { $consumed{$a}{name} cmp
1183: $consumed{$b}{name} }
1.79 albertel 1184: (@this_slot)) {
1.47 albertel 1185: my (undef,$id)=split("\0",$entry);
1.57 albertel 1186: my ($uname,$udom) = split(':',$consumed{$entry}{'name'});
1.84 bisitz 1187: $ids.= '<span class="LC_nobreak">';
1.47 albertel 1188: foreach my $item (@stu_display_order) {
1189: if ($stu_display{$item}) {
1190: if ($item eq 'fullname') {
1191: $ids.=$fullname->{"$uname:$udom"}.' ';
1192: } elsif ($item eq 'username') {
1.57 albertel 1193: $ids.="<tt>$uname:$udom</tt> ";
1.47 albertel 1194: }
1.46 albertel 1195: }
1196: }
1.47 albertel 1197: $ids.=&remove_link($slot,$entry,$uname,$udom,
1.84 bisitz 1198: $consumed{$entry}{'symb'}).'</span><br />';
1.46 albertel 1199: }
1.38 albertel 1200: }
1.5 albertel 1201: }
1.33 albertel 1202:
1.24 albertel 1203: my $start=($slots{$slot}->{'starttime'}?
1204: &Apache::lonlocal::locallocaltime($slots{$slot}->{'starttime'}):'');
1205: my $end=($slots{$slot}->{'endtime'}?
1206: &Apache::lonlocal::locallocaltime($slots{$slot}->{'endtime'}):'');
1.28 albertel 1207: my $start_reserve=($slots{$slot}->{'startreserve'}?
1.24 albertel 1208: &Apache::lonlocal::locallocaltime($slots{$slot}->{'startreserve'}):'');
1209:
1.14 albertel 1210: my $unique;
1211: if (ref($slots{$slot}{'uniqueperiod'})) {
1.64 albertel 1212: $unique=localtime($slots{$slot}{'uniqueperiod'}[0]).', '.
1.14 albertel 1213: localtime($slots{$slot}{'uniqueperiod'}[1]);
1214: }
1.33 albertel 1215:
1.29 albertel 1216: my $title;
1217: if (exists($slots{$slot}{'symb'})) {
1218: my (undef,undef,$res)=
1219: &Apache::lonnet::decode_symb($slots{$slot}{'symb'});
1220: $res = &Apache::lonnet::clutter($res);
1221: $title = &Apache::lonnet::gettitle($slots{$slot}{'symb'});
1222: $title='<a href="'.$res.'?symb='.$slots{$slot}{'symb'}.'">'.$title.'</a>';
1223: }
1.33 albertel 1224:
1.49 albertel 1225: my $allowedsections;
1226: if (exists($show{'allowedsections'})) {
1227: $allowedsections =
1228: join(', ',sort(split(/\s*,\s*/,
1229: $slots{$slot}->{'allowedsections'})));
1230: }
1231:
1232: my @allowedusers;
1233: if (exists($show{'allowedusers'})) {
1234: @allowedusers= map {
1235: my ($uname,$udom)=split(/:/,$_);
1236: my $fullname=$name_cache{$_};
1237: if (!defined($fullname)) {
1238: $fullname = &Apache::loncommon::plainname($uname,$udom);
1239: $fullname =~s/\s/ /g;
1240: $name_cache{$_} = $fullname;
1241: }
1242: &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
1243: } (sort(split(/\s*,\s*/,$slots{$slot}->{'allowedusers'})));
1244: }
1245: my $allowedusers=join(', ',@allowedusers);
1246:
1.29 albertel 1247: my @proctors;
1248: my $rowspan=1;
1249: my $colspan=1;
1.30 albertel 1250: if (exists($show{'proctor'})) {
1.29 albertel 1251: $rowspan=2;
1252: @proctors= map {
1.62 albertel 1253: my ($uname,$udom)=split(/:/,$_);
1.29 albertel 1254: my $fullname=$name_cache{$_};
1255: if (!defined($fullname)) {
1256: $fullname = &Apache::loncommon::plainname($uname,$udom);
1257: $fullname =~s/\s/ /g;
1258: $name_cache{$_} = $fullname;
1259: }
1260: &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
1261: } (sort(split(/\s*,\s*/,$slots{$slot}->{'proctor'})));
1262: }
1.20 albertel 1263: my $proctors=join(', ',@proctors);
1.14 albertel 1264:
1.34 albertel 1265: my $edit=(<<"EDITLINK");
1.31 albertel 1266: <a href="/adm/helper/newslot.helper?name=$slot">Edit</a>
1267: EDITLINK
1.34 albertel 1268:
1269: my $delete=(<<"DELETELINK");
1.64 albertel 1270: <a href="/adm/slotrequest?command=delete&slotname=$slot">Delete</a>
1.34 albertel 1271: DELETELINK
1.55 albertel 1272:
1.56 albertel 1273: my $remove_all=&remove_link($slot,'remove all').'<br />';
1.55 albertel 1274:
1.34 albertel 1275: if ($ids ne '') { undef($delete); }
1.56 albertel 1276: if ($slots{$slot}{'type'} ne 'schedulable_student'
1277: || $ids eq '') {
1.55 albertel 1278: undef($remove_all);
1279: }
1.34 albertel 1280:
1.65 albertel 1281: my $row_start=&Apache::loncommon::start_data_table_row();
1282: my $row_end=&Apache::loncommon::end_data_table_row();
1283: $r->print($row_start.
1284: "\n<td rowspan=\"$rowspan\">$edit $delete</td>\n");
1.30 albertel 1285: if (exists($show{'name'})) {
1.29 albertel 1286: $colspan++;$r->print("<td>$slot</td>");
1287: }
1.33 albertel 1288: if (exists($show{'description'})) {
1289: $colspan++;$r->print("<td>$description</td>\n");
1290: }
1.30 albertel 1291: if (exists($show{'type'})) {
1.29 albertel 1292: $colspan++;$r->print("<td>$slots{$slot}->{'type'}</td>\n");
1293: }
1.30 albertel 1294: if (exists($show{'starttime'})) {
1.29 albertel 1295: $colspan++;$r->print("<td>$start</td>\n");
1296: }
1.30 albertel 1297: if (exists($show{'endtime'})) {
1.29 albertel 1298: $colspan++;$r->print("<td>$end</td>\n");
1299: }
1.30 albertel 1300: if (exists($show{'startreserve'})) {
1.29 albertel 1301: $colspan++;$r->print("<td>$start_reserve</td>\n");
1302: }
1.30 albertel 1303: if (exists($show{'secret'})) {
1.29 albertel 1304: $colspan++;$r->print("<td>$slots{$slot}{'secret'}</td>\n");
1305: }
1.74 albertel 1306: if (exists($show{'space'})) {
1307: my $display = $id_count;
1308: if ($slots{$slot}{'maxspace'}>0) {
1309: $display.='/'.$slots{$slot}{'maxspace'};
1310: if ($slots{$slot}{'maxspace'} <= $id_count) {
1311: $display = '<strong>'.$display.' (full) </strong>';
1312: }
1313: }
1314: $colspan++;$r->print("<td>$display</td>\n");
1.29 albertel 1315: }
1.30 albertel 1316: if (exists($show{'ip'})) {
1.29 albertel 1317: $colspan++;$r->print("<td>$slots{$slot}{'ip'}</td>\n");
1318: }
1.30 albertel 1319: if (exists($show{'symb'})) {
1.29 albertel 1320: $colspan++;$r->print("<td>$title</td>\n");
1321: }
1.49 albertel 1322: if (exists($show{'allowedsections'})) {
1323: $colspan++;$r->print("<td>$allowedsections</td>\n");
1324: }
1325: if (exists($show{'allowedusers'})) {
1326: $colspan++;$r->print("<td>$allowedusers</td>\n");
1.29 albertel 1327: }
1.64 albertel 1328: if (exists($show{'uniqueperiod'})) {
1329: $colspan++;$r->print("<td>$unique</td>\n");
1330: }
1.47 albertel 1331: if (exists($show{'scheduled'})) {
1.64 albertel 1332: $colspan++;$r->print("<td>$remove_all $ids</td>\n");
1.47 albertel 1333: }
1.65 albertel 1334: $r->print("$row_end\n");
1.30 albertel 1335: if (exists($show{'proctor'})) {
1.29 albertel 1336: $r->print(<<STUFF);
1.65 albertel 1337: $row_start
1.29 albertel 1338: <td colspan="$colspan">$proctors</td>
1.65 albertel 1339: $row_end
1.5 albertel 1340: STUFF
1.29 albertel 1341: }
1.5 albertel 1342: }
1.64 albertel 1343: $r->print('</table></form>');
1.5 albertel 1344: }
1345:
1.14 albertel 1346: sub upload_start {
1.19 albertel 1347: my ($r)=@_;
1.14 albertel 1348: $r->print(&Apache::grades::checkforfile_js());
1349: my $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
1350: $result.=' <b>'.
1351: &mt('Specify a file containing the slot definitions.').
1352: '</b></td></tr>'."\n";
1.87 raeburn 1353: $result.='<tr bgcolor="#ffffe6"><td>'."\n";
1.14 albertel 1354: my $upfile_select=&Apache::loncommon::upfile_select_html();
1355: my $ignore=&mt('Ignore First Line');
1356: $result.=<<ENDUPFORM;
1357: <form method="post" enctype="multipart/form-data" action="/adm/slotrequest" name="slotupload">
1358: <input type="hidden" name="command" value="csvuploadmap" />
1359: $upfile_select
1360: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Data" />
1361: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1362: </form>
1363: ENDUPFORM
1364: $result.='</td></tr></table>'."\n";
1365: $result.='</td></tr></table>'."\n";
1366: $r->print($result);
1367: }
1368:
1369: sub csvuploadmap_header {
1.19 albertel 1370: my ($r,$datatoken,$distotal)= @_;
1.14 albertel 1371: my $javascript;
1372: if ($env{'form.upfile_associate'} eq 'reverse') {
1373: $javascript=&csvupload_javascript_reverse_associate();
1374: } else {
1375: $javascript=&csvupload_javascript_forward_associate();
1376: }
1377:
1378: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1379: my $ignore=&mt('Ignore First Line');
1.72 rezaferr 1380: my $help_field = &Apache::loncommon::help_open_topic('Slot SelectingField');
1381:
1.14 albertel 1382: $r->print(<<ENDPICK);
1383: <form method="post" enctype="multipart/form-data" action="/adm/slotrequest" name="slotupload">
1.72 rezaferr 1384: <h3>Identify fields $help_field</h3>
1.14 albertel 1385: Total number of records found in file: $distotal <hr />
1386: Enter as many fields as you can. The system will inform you and bring you back
1387: to this page if the data selected is insufficient to create the slots.<hr />
1388: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1389: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1390: <input type="hidden" name="associate" value="" />
1391: <input type="hidden" name="datatoken" value="$datatoken" />
1392: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
1393: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1394: <input type="hidden" name="upfile_associate"
1395: value="$env{'form.upfile_associate'}" />
1396: <input type="hidden" name="command" value="csvuploadassign" />
1397: <hr />
1398: <script type="text/javascript" language="Javascript">
1399: $javascript
1400: </script>
1401: ENDPICK
1402: return '';
1403:
1404: }
1405:
1406: sub csvuploadmap_footer {
1407: my ($request,$i,$keyfields) =@_;
1.87 raeburn 1408: my $buttontext = &mt('Create Slots');
1.14 albertel 1409: $request->print(<<ENDPICK);
1410: </table>
1411: <input type="hidden" name="nfields" value="$i" />
1412: <input type="hidden" name="keyfields" value="$keyfields" />
1.87 raeburn 1413: <input type="button" onClick="javascript:verify(this.form)" value="$buttontext" /><br />
1.14 albertel 1414: </form>
1415: ENDPICK
1416: }
1417:
1418: sub csvupload_javascript_reverse_associate {
1419: my $error1=&mt('You need to specify the name, starttime, endtime and a type');
1420: return(<<ENDPICK);
1421: function verify(vf) {
1422: var foundstart=0;
1423: var foundend=0;
1424: var foundname=0;
1425: var foundtype=0;
1426: for (i=0;i<=vf.nfields.value;i++) {
1427: tw=eval('vf.f'+i+'.selectedIndex');
1428: if (i==0 && tw!=0) { foundname=1; }
1429: if (i==1 && tw!=0) { foundtype=1; }
1430: if (i==2 && tw!=0) { foundstat=1; }
1431: if (i==3 && tw!=0) { foundend=1; }
1432: }
1433: if (foundstart==0 && foundend==0 && foundtype==0 && foundname==0) {
1434: alert('$error1');
1435: return;
1436: }
1437: vf.submit();
1438: }
1439: function flip(vf,tf) {
1440: }
1441: ENDPICK
1442: }
1443:
1444: sub csvupload_javascript_forward_associate {
1445: my $error1=&mt('You need to specify the name, starttime, endtime and a type');
1446: return(<<ENDPICK);
1447: function verify(vf) {
1448: var foundstart=0;
1449: var foundend=0;
1450: var foundname=0;
1451: var foundtype=0;
1452: for (i=0;i<=vf.nfields.value;i++) {
1453: tw=eval('vf.f'+i+'.selectedIndex');
1454: if (tw==1) { foundname=1; }
1455: if (tw==2) { foundtype=1; }
1456: if (tw==3) { foundstat=1; }
1457: if (tw==4) { foundend=1; }
1458: }
1459: if (foundstart==0 && foundend==0 && foundtype==0 && foundname==0) {
1460: alert('$error1');
1461: return;
1462: }
1463: vf.submit();
1464: }
1465: function flip(vf,tf) {
1466: }
1467: ENDPICK
1468: }
1469:
1470: sub csv_upload_map {
1.19 albertel 1471: my ($r)= @_;
1.14 albertel 1472:
1473: my $datatoken;
1474: if (!$env{'form.datatoken'}) {
1475: $datatoken=&Apache::loncommon::upfile_store($r);
1476: } else {
1477: $datatoken=$env{'form.datatoken'};
1478: &Apache::loncommon::load_tmp_file($r);
1479: }
1480: my @records=&Apache::loncommon::upfile_record_sep();
1481: if ($env{'form.noFirstLine'}) { shift(@records); }
1.19 albertel 1482: &csvuploadmap_header($r,$datatoken,$#records+1);
1.14 albertel 1483: my ($i,$keyfields);
1484: if (@records) {
1485: my @fields=&csvupload_fields();
1486:
1487: if ($env{'form.upfile_associate'} eq 'reverse') {
1488: &Apache::loncommon::csv_print_samples($r,\@records);
1489: $i=&Apache::loncommon::csv_print_select_table($r,\@records,
1490: \@fields);
1491: foreach (@fields) { $keyfields.=$_->[0].','; }
1492: chop($keyfields);
1493: } else {
1494: unshift(@fields,['none','']);
1495: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
1496: \@fields);
1497: my %sone=&Apache::loncommon::record_sep($records[0]);
1498: $keyfields=join(',',sort(keys(%sone)));
1499: }
1500: }
1501: &csvuploadmap_footer($r,$i,$keyfields);
1502:
1503: return '';
1504: }
1505:
1506: sub csvupload_fields {
1507: return (['name','Slot name'],
1508: ['type','Type of slot'],
1509: ['starttime','Start Time of slot'],
1510: ['endtime','End Time of slot'],
1.15 albertel 1511: ['startreserve','Reservation Start Time'],
1.14 albertel 1512: ['ip','IP or DNS restriction'],
1513: ['proctor','List of proctor ids'],
1514: ['description','Slot Description'],
1515: ['maxspace','Maximum number of reservations'],
1516: ['symb','Resource Restriction'],
1517: ['uniqueperiod','Date range of slot exclusion'],
1.49 albertel 1518: ['secret','Secret word proctor uses to validate'],
1519: ['allowedsections','Sections slot is restricted to'],
1520: ['allowedusers','Users slot is restricted to'],
1521: );
1.14 albertel 1522: }
1523:
1524: sub csv_upload_assign {
1.19 albertel 1525: my ($r,$mgr)= @_;
1.14 albertel 1526: &Apache::loncommon::load_tmp_file($r);
1527: my @slotdata = &Apache::loncommon::upfile_record_sep();
1528: if ($env{'form.noFirstLine'}) { shift(@slotdata); }
1529: my %fields=&Apache::grades::get_fields();
1.87 raeburn 1530: $r->print('<h3>'.&mt('Creating Slots').'</h3>');
1.14 albertel 1531: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1532: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1533: my $countdone=0;
1.31 albertel 1534: my @errors;
1.14 albertel 1535: foreach my $slot (@slotdata) {
1536: my %slot;
1537: my %entries=&Apache::loncommon::record_sep($slot);
1538: my $domain;
1539: my $name=$entries{$fields{'name'}};
1.31 albertel 1540: if ($name=~/^\s*$/) {
1541: push(@errors,"Did not create slot with no name");
1542: next;
1543: }
1544: if ($name=~/\s/) {
1545: push(@errors,"$name not created -- Name must not contain spaces");
1546: next;
1547: }
1548: if ($name=~/\W/) {
1549: push(@errors,"$name not created -- Name must contain only letters, numbers and _");
1550: next;
1551: }
1.14 albertel 1552: if ($entries{$fields{'type'}}) {
1553: $slot{'type'}=$entries{$fields{'type'}};
1554: } else {
1555: $slot{'type'}='preassigned';
1556: }
1.31 albertel 1557: if ($slot{'type'} ne 'preassigned' &&
1558: $slot{'type'} ne 'schedulable_student') {
1559: push(@errors,"$name not created -- invalid type ($slot{'type'}) must be either preassigned or schedulable_student");
1560: next;
1561: }
1.14 albertel 1562: if ($entries{$fields{'starttime'}}) {
1563: $slot{'starttime'}=&UnixDate($entries{$fields{'starttime'}},"%s");
1564: }
1565: if ($entries{$fields{'endtime'}}) {
1.16 albertel 1566: $slot{'endtime'}=&UnixDate($entries{$fields{'endtime'}},"%s");
1.14 albertel 1567: }
1.58 albertel 1568:
1569: # start/endtime must be defined and greater than zero
1570: if (!$slot{'starttime'}) {
1571: push(@errors,"$name not created -- Invalid start time");
1572: next;
1573: }
1574: if (!$slot{'endtime'}) {
1575: push(@errors,"$name not created -- Invalid end time");
1576: next;
1577: }
1578: if ($slot{'starttime'} > $slot{'endtime'}) {
1579: push(@errors,"$name not created -- Slot starts after it ends");
1580: next;
1581: }
1582:
1.23 albertel 1583: if ($entries{$fields{'startreserve'}}) {
1584: $slot{'startreserve'}=
1585: &UnixDate($entries{$fields{'startreserve'}},"%s");
1586: }
1.58 albertel 1587: if (defined($slot{'startreserve'})
1588: && $slot{'startreserve'} > $slot{'starttime'}) {
1589: push(@errors,"$name not created -- Slot's reservation start time is after the slot's start time.");
1590: next;
1591: }
1592:
1.14 albertel 1593: foreach my $key ('ip','proctor','description','maxspace',
1594: 'secret','symb') {
1595: if ($entries{$fields{$key}}) {
1596: $slot{$key}=$entries{$fields{$key}};
1597: }
1598: }
1.58 albertel 1599:
1.14 albertel 1600: if ($entries{$fields{'uniqueperiod'}}) {
1601: my ($start,$end)=split(',',$entries{$fields{'uniqueperiod'}});
1602: my @times=(&UnixDate($start,"%s"),
1603: &UnixDate($end,"%s"));
1604: $slot{'uniqueperiod'}=\@times;
1605: }
1.58 albertel 1606: if (defined($slot{'uniqueperiod'})
1607: && $slot{'uniqueperiod'}[0] > $slot{'uniqueperiod'}[1]) {
1608: push(@errors,"$name not created -- Slot's unique period start time is later than the unique period's end time.");
1609: next;
1610: }
1.14 albertel 1611:
1612: &Apache::lonnet::cput('slots',{$name=>\%slot},$cdom,$cname);
1613: $r->print('.');
1614: $r->rflush();
1615: $countdone++;
1616: }
1.87 raeburn 1617: $r->print('<p>'.&mt('Created [quant,_1,slot]',$countdone)."\n".'</p>');
1.31 albertel 1618: foreach my $error (@errors) {
1.87 raeburn 1619: $r->print('<p><span class="LC_warning">'.$error.'</span></p>'."\n");
1.31 albertel 1620: }
1.19 albertel 1621: &show_table($r,$mgr);
1.14 albertel 1622: return '';
1623: }
1624:
1.1 albertel 1625: sub handler {
1626: my $r=shift;
1627:
1.30 albertel 1628: &Apache::loncommon::content_type($r,'text/html');
1629: &Apache::loncommon::no_cache($r);
1630: if ($r->header_only()) {
1631: $r->send_http_header();
1632: return OK;
1633: }
1634:
1.8 albertel 1635: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.28 albertel 1636:
1.12 albertel 1637: my $vgr=&Apache::lonnet::allowed('vgr',$env{'request.course.id'});
1.14 albertel 1638: my $mgr=&Apache::lonnet::allowed('mgr',$env{'request.course.id'});
1.28 albertel 1639: my $title='Requesting Another Worktime';
1640: if ($env{'form.command'} =~ /^(showslots|uploadstart|csvuploadmap|csvuploadassign)$/ && $vgr eq 'F') {
1641: $title = 'Managing Slots';
1642: }
1643: &start_page($r,$title);
1644:
1.8 albertel 1645: if ($env{'form.command'} eq 'showslots' && $vgr eq 'F') {
1.19 albertel 1646: &show_table($r,$mgr);
1.33 albertel 1647: } elsif ($env{'form.command'} eq 'remove_registration' && $mgr eq 'F') {
1648: &remove_registration($r);
1649: } elsif ($env{'form.command'} eq 'release' && $mgr eq 'F') {
1.55 albertel 1650: if ($env{'form.entry'} eq 'remove all') {
1651: &release_all_slot($r,$mgr);
1652: } else {
1653: &release_slot($r,undef,undef,undef,$mgr);
1654: }
1.34 albertel 1655: } elsif ($env{'form.command'} eq 'delete' && $mgr eq 'F') {
1656: &delete_slot($r);
1.14 albertel 1657: } elsif ($env{'form.command'} eq 'uploadstart' && $mgr eq 'F') {
1.19 albertel 1658: &upload_start($r);
1.14 albertel 1659: } elsif ($env{'form.command'} eq 'csvuploadmap' && $mgr eq 'F') {
1.19 albertel 1660: &csv_upload_map($r);
1.14 albertel 1661: } elsif ($env{'form.command'} eq 'csvuploadassign' && $mgr eq 'F') {
1662: if ($env{'form.associate'} ne 'Reverse Association') {
1.19 albertel 1663: &csv_upload_assign($r,$mgr);
1.14 albertel 1664: } else {
1665: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
1666: $env{'form.upfile_associate'} = 'reverse';
1667: } else {
1668: $env{'form.upfile_associate'} = 'forward';
1669: }
1.19 albertel 1670: &csv_upload_map($r);
1.14 albertel 1671: }
1.8 albertel 1672: } else {
1.63 www 1673: my $symb=&unescape($env{'form.symb'});
1.61 albertel 1674: if (!defined($symb)) {
1675: &fail($r,'not_valid');
1676: return OK;
1677: }
1.19 albertel 1678: my (undef,undef,$res)=&Apache::lonnet::decode_symb($symb);
1.36 albertel 1679: my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb);
1.66 albertel 1680: if ($useslots ne 'resource'
1681: && $useslots ne 'map'
1682: && $useslots ne 'map_map') {
1.61 albertel 1683: &fail($r,'not_available');
1.19 albertel 1684: return OK;
1685: }
1686: $env{'request.symb'}=$symb;
1.36 albertel 1687: my $type = ($res =~ /\.task$/) ? 'Task'
1688: : 'problem';
1689: my ($status) = &Apache::lonhomework::check_slot_access('0',$type);
1.11 albertel 1690: if ($status eq 'CAN_ANSWER' ||
1691: $status eq 'NEEDS_CHECKIN' ||
1692: $status eq 'WAITING_FOR_GRADE') {
1693: &fail($r,'not_allowed');
1694: return OK;
1695: }
1696: if ($env{'form.requestattempt'}) {
1697: &show_choices($r,$symb);
1698: } elsif ($env{'form.command'} eq 'release') {
1699: &release_slot($r,$symb);
1700: } elsif ($env{'form.command'} eq 'get') {
1701: &get_slot($r,$symb);
1702: } elsif ($env{'form.command'} eq 'change') {
1.75 albertel 1703: if (&get_slot($r,$symb,$env{'form.releaseslot'},1)) {
1704: &release_slot($r,$symb,$env{'form.releaseslot'});
1.39 albertel 1705: }
1.11 albertel 1706: } else {
1.87 raeburn 1707: $r->print('<p>'.&mt('Unknown command: [_1]',$env{'form.command'}).'</p>');
1.11 albertel 1708: }
1.2 albertel 1709: }
1.1 albertel 1710: &end_page($r);
1711: return OK;
1712: }
1.3 albertel 1713:
1714: 1;
1715: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>