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