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