Annotation of loncom/interface/slotrequest.pm, revision 1.39
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # Handler for requesting to have slots added to a students record
3: #
1.39 ! albertel 4: # $Id: slotrequest.pm,v 1.38 2006/01/24 06:41:16 albertel Exp $
1.1 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###
29:
30: package Apache::slotrequest;
31:
32: use strict;
33: use Apache::Constants qw(:common :http :methods);
34: use Apache::loncommon();
35: use Apache::lonlocal;
36: use Apache::lonnet;
1.27 albertel 37: use Date::Manip;
1.1 albertel 38:
39: sub fail {
40: my ($r,$code)=@_;
1.2 albertel 41: if ($code eq 'not_valid') {
1.8 albertel 42: $r->print('<p>'.&mt('Unable to understand what resource you wanted to sign up for.').'</p>');
1.2 albertel 43:
1.8 albertel 44: } elsif ($code eq 'not_allowed') {
45: $r->print('<p>'.&mt('Not allowed to sign up or change reservations at this time.').'</p>');
46: } else {
47: $r->print('<p>'.&mt('Failed.').'</p>');
1.2 albertel 48: }
1.8 albertel 49:
1.2 albertel 50: $r->print('<p><a href="/adm/flip?postdata=return:">'.
51: &mt('Return to last resource').'</a></p>');
1.1 albertel 52: &end_page($r);
53: }
54:
55: sub start_page {
1.28 albertel 56: my ($r,$title)=@_;
1.1 albertel 57: my $html=&Apache::lonxml::xmlbegin();
1.28 albertel 58: $r->print($html.'<head><title>'.&mt($title).'</title></head>');
59: $r->print(&Apache::loncommon::bodytag($title));
1.1 albertel 60: }
61:
62: sub end_page {
63: my ($r)=@_;
64: $r->print(&Apache::loncommon::endbodytag().'</html>');
65: }
66:
1.2 albertel 67: =pod
68:
69: slot_reservations db
70: - keys are
71: - slotname\0id -> value is an hashref of
72: name -> user@domain of holder
73: timestamp -> timestamp of reservation
74: symb -> symb of resource that it is reserved for
75:
76: =cut
77:
78: sub get_course {
79: (undef,my $courseid)=&Apache::lonxml::whichuser();
80: my $cdom=$env{'course.'.$courseid.'.domain'};
81: my $cnum=$env{'course.'.$courseid.'.num'};
82: return ($cnum,$cdom);
83: }
84:
85: sub get_reservation_ids {
86: my ($slot_name)=@_;
87:
88: my ($cnum,$cdom)=&get_course();
89:
90: my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
91: "^$slot_name\0");
92:
93: my ($tmp)=%consumed;
94: if ($tmp=~/^error: 2 / ) {
95: return 0;
96: }
97: return keys(%consumed);
98: }
99:
100: sub space_available {
101: my ($slot_name,$slot)=@_;
102: my $max=$slot->{'maxspace'};
103:
104: if (!defined($max)) { return 1; }
105:
106: my $consumed=scalar(&get_reservation_ids($slot_name));
107: if ($consumed < $max) {
108: return 1
109: }
110: return 0;
111: }
1.3 albertel 112:
1.4 albertel 113: sub check_for_reservation {
114: my ($symb)=@_;
115: my $student = &Apache::lonnet::EXT("resource.0.availablestudent", $symb,
116: $env{'user.domain'}, $env{'user.name'});
117:
118: my $course = &Apache::lonnet::EXT("resource.0.available", $symb,
119: $env{'user.domain'}, $env{'user.name'});
120: my @slots = (split(/:/,$student), split(/:/, $course));
121:
122: &Apache::lonxml::debug(" slot list is ".join(':',@slots));
123:
124: my ($cnum,$cdom)=&get_course();
125: my %slots=&Apache::lonnet::get('slots', [@slots], $cdom, $cnum);
126:
127: foreach my $slot_name (@slots) {
128: next if (!defined($slots{$slot_name}) ||
129: !ref($slots{$slot_name}));
130: &Apache::lonxml::debug(time." $slot_name ".
131: $slots{$slot_name}->{'starttime'}." -- ".
132: $slots{$slot_name}->{'startreserve'});
1.7 albertel 133: if ($slots{$slot_name}->{'endtime'} > time &&
1.4 albertel 134: $slots{$slot_name}->{'startreserve'} < time) {
1.7 albertel 135: # between start of reservation times and end of slot
1.4 albertel 136: return($slot_name, $slots{$slot_name});
137: }
138: }
139: return (undef,undef);
140: }
141:
1.5 albertel 142: sub check_for_conflict {
143: my ($symb,$new_slot_name)=@_;
144: my $student = &Apache::lonnet::EXT("resource.0.availablestudent", $symb,
145: $env{'user.domain'}, $env{'user.name'});
146: my $course = &Apache::lonnet::EXT("resource.0.available", $symb,
147: $env{'user.domain'}, $env{'user.name'});
148: my @slots = (split(/:/,$student), split(/:/, $course));
149: my ($cnum,$cdom)=&get_course();
150: my %slots=&Apache::lonnet::get('slots', [@slots], $cdom, $cnum);
151: foreach my $slot_name (@slots) {
152: next if (!defined($slots{$slot_name}) ||
153: !ref($slots{$slot_name}));
154:
155: next if (!defined($slots{$slot_name}->{'uniqueperiod'}) ||
156: !ref($slots{$slot_name}->{'uniqueperiod'}));
157: my ($start,$end)=@{$slots{$slot_name}->{'uniqueperiod'}};
158: if ($start<time && time < $end) {
159: return $slot_name;
160: }
161: }
162: return undef;
163:
164: }
165:
1.2 albertel 166: sub make_reservation {
167: my ($slot_name,$slot,$symb)=@_;
1.3 albertel 168:
169: my ($cnum,$cdom)=&get_course();
170:
171: my $value=&Apache::lonnet::EXT("resource.0.availablestudent",$symb,
172: $env{'user.domain'},$env{'user.name'});
173: &Apache::lonxml::debug("value is $value<br />");
174: foreach my $other_slot (split(/:/, $value)) {
175: if ($other_slot eq $slot_name) {
176: my %consumed=&Apache::lonnet::dump('slot_reservations', $cdom,
177: $cnum, "^$slot_name\0");
178:
179: my $me=$env{'user.name'}.'@'.$env{'user.domain'};
180: foreach my $key (keys(%consumed)) {
181: if ($consumed{$key}->{'name'} eq $me) {
182: my $num=(split('\0',$key))[1];
183: return -$num;
184: }
185: }
186: }
187: }
188:
1.2 albertel 189: my $max=$slot->{'maxspace'};
1.3 albertel 190: if (!defined($max)) { $max=99999; }
1.2 albertel 191:
192: my (@ids)=&get_reservation_ids($slot_name);
193:
194: my $last=0;
195: foreach my $id (@ids) {
196: my $num=(split('\0',$id))[1];
197: if ($num > $last) { $last=$num; }
198: }
199:
200: my $wanted=$last+1;
1.3 albertel 201: &Apache::lonxml::debug("wanted $wanted<br />");
1.7 albertel 202: if (scalar(@ids) >= $max) {
1.2 albertel 203: # full up
1.7 albertel 204: return undef;
1.2 albertel 205: }
206:
207: my %reservation=('name' => $env{'user.name'}.'@'.$env{'user.domain'},
208: 'timestamp' => time,
209: 'symb' => $symb);
210:
211: my $success=&Apache::lonnet::newput('slot_reservations',
212: {"$slot_name\0$wanted" =>
213: \%reservation},
1.3 albertel 214: $cdom, $cnum);
215:
1.2 albertel 216: if ($success eq 'ok') {
1.3 albertel 217: my $new_value=$slot_name;
218: if ($value) {
219: $new_value=$value.':'.$new_value;
220: }
221: my $result=&Apache::lonparmset::storeparm_by_symb($symb,
222: '0_availablestudent',
223: 1, $new_value, 'string',
224: $env{'user.name'},
225: $env{'user.domain'});
226: &Apache::lonxml::debug("hrrm $result");
1.2 albertel 227: return $wanted;
228: }
1.3 albertel 229:
1.2 albertel 230: # someone else got it
1.3 albertel 231: return undef;
232: }
233:
1.33 albertel 234: sub remove_registration {
235: my ($r) = @_;
236: my $name = &Apache::loncommon::plainname($env{'form.uname'},
237: $env{'form.udom'});
238:
239: my $title = &Apache::lonnet::gettitle($env{'form.symb'});
240:
241: my $hidden_input;
242: foreach my $parm ('uname','udom','slotname','entry','symb') {
243: $hidden_input .=
244: '<input type="hidden" name="'.$parm.'" value="'
245: .&HTML::Entities::encode($env{'form.'.$parm},'"<>&\'').'" />'."\n";
246: }
247: $r->print(<<"END_CONFIRM");
248: <p> Remove $name from slot $env{'form.slotname'} for $title</p>
249: <form action="/adm/slotrequest" method="POST">
250: <input type="hidden" name="command" value="release" />
251: $hidden_input
252: <input type="submit" name="Yes" value="yes" />
253: </form>
254: <form action="/adm/slotrequest" method="POST">
255: <input type="hidden" name="command" value="showslots" />
256: <input type="submit" name="No" value="no" />
257: </form>
258: END_CONFIRM
259:
260: }
261:
1.5 albertel 262: sub release_slot {
1.33 albertel 263: my ($r,$symb,$slot_name,$inhibit_return_link,$mgr)=@_;
1.6 albertel 264:
265: if ($slot_name eq '') { $slot_name=$env{'form.slotname'}; }
266: my ($cnum,$cdom)=&get_course();
267:
1.33 albertel 268: my ($uname,$udom) = ($env{'user.name'}, $env{'user.domain'});
269: if ($mgr eq 'F'
270: && defined($env{'form.uname'}) && defined($env{'form.udom'})) {
271: ($uname,$udom) = ($env{'form.uname'}, $env{'form.udom'});
272: }
273:
274: if ($mgr eq 'F'
275: && defined($env{'form.symb'})) {
276: $symb = $env{'form.symb'};
277: }
1.39 ! albertel 278: my %slot=&Apache::lonnet::get_slot($slot_name);
! 279: my $description=&get_description($env{'form.slotname'},\%slot);
1.33 albertel 280:
1.39 ! albertel 281: if ($mgr ne 'F') {
! 282: if ($slot{$slot_name}{'starttime'} < time) {
! 283: $r->print("<p>Not allowed to release Reservation: $description, as it has already ended.</p>");
! 284: $r->print('<p><a href="/adm/flip?postdata=return:">'.
! 285: &mt('Return to last resource').'</a></p>');
! 286: return 0;
! 287: }
! 288: }
1.5 albertel 289: # get parameter string, check for existance, rebuild string with the slot
1.6 albertel 290: my @slots = split(/:/,&Apache::lonnet::EXT("resource.0.availablestudent",
1.33 albertel 291: $symb,$udom,$uname));
292:
1.6 albertel 293: my @new_slots;
294: foreach my $exist_slot (@slots) {
295: if ($exist_slot eq $slot_name) { next; }
296: push(@new_slots,$exist_slot);
297: }
298: my $new_param = join(':',@new_slots);
1.5 albertel 299:
300: # get slot reservations, check if user has one, if so remove reservation
1.6 albertel 301: my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
302: "^$slot_name\0");
303: foreach my $entry (keys(%consumed)) {
1.33 albertel 304: if ( $consumed{$entry}->{'name'} eq ($uname.'@'.$udom) ) {
1.6 albertel 305: &Apache::lonnet::del('slot_reservations',[$entry],
306: $cdom,$cnum);
307: }
308: }
1.33 albertel 309:
1.5 albertel 310: # store new parameter string
1.6 albertel 311: my $result=&Apache::lonparmset::storeparm_by_symb($symb,
312: '0_availablestudent',
313: 1, $new_param, 'string',
1.33 albertel 314: $uname,$udom);
1.6 albertel 315: my $description=&get_description($env{'form.slotname'},\%slot);
316: $r->print("<p>Released Reservation: $description</p>");
1.33 albertel 317: if ($mgr eq 'F') {
318: $r->print('<p><a href="/adm/slotrequest?command=showslots">'.
319: &mt('Return to slot list').'</a></p>');
320: }
1.7 albertel 321: if (!$inhibit_return_link) {
1.6 albertel 322: $r->print('<p><a href="/adm/flip?postdata=return:">'.
323: &mt('Return to last resource').'</a></p>');
324: }
325: return 1;
1.5 albertel 326: }
327:
1.34 albertel 328: sub delete_slot {
329: my ($r)=@_;
330:
331: my $slot_name = $env{'form.slotname'};
332: my %slot=&Apache::lonnet::get_slot($slot_name);
333:
334: my ($cnum,$cdom)=&get_course();
335: my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
336: "^$slot_name\0");
1.38 albertel 337: my ($tmp) = %consumed;
338: if ($tmp =~ /error: 2/) { undef(%consumed); }
1.34 albertel 339:
340: if (%slot && !%consumed) {
341: $slot{'type'} = 'deleted';
342: my $ret = &Apache::lonnet::cput('slots', {$slot_name => \%slot},
343: $cdom, $cnum);
344: if ($ret eq 'ok') {
345: $r->print("<p>Slot <tt>$slot_name</tt> marked as deleted.</p>");
346: } else {
347: $r->print("<p> An error ($ret) occurse when attempting to delete Slot <tt>$slot_name</tt>.</p>");
348: }
349: } else {
350: if (%consumed) {
351: $r->print("<p>Slot <tt>$slot_name</tt> has active reservations.</p>");
352: } else {
353: $r->print("<p>Slot <tt>$slot_name</tt> does not exist.</p>");
354: }
355: }
356: $r->print('<p><a href="/adm/slotrequest?command=showslots">'.
357: &mt('Return to slot list').'</a></p>');
358: $r->print('<p><a href="/adm/flip?postdata=return:">'.
359: &mt('Return to last resource').'</a></p>');
360: }
361:
1.3 albertel 362: sub get_slot {
363: my ($r,$symb)=@_;
364:
1.5 albertel 365: my $slot_name=&check_for_conflict($symb,$env{'form.slotname'});
366: if ($slot_name) {
367: my %slot=&Apache::lonnet::get_slot($slot_name);
1.6 albertel 368: my $description1=&get_description($slot_name,\%slot);
369: %slot=&Apache::lonnet::get_slot($env{'form.slotname'});
370: my $description2=&get_description($env{'form.slotname'},\%slot);
371: $r->print("<p>Already have a reservation: $description1</p>");
1.7 albertel 372: if ($slot_name ne $env{'form.slotname'}) {
373: $r->print(<<STUFF);
1.6 albertel 374: <form method="POST" action="/adm/slotrequest">
375: <input type="hidden" name="symb" value="$env{'form.symb'}" />
376: <input type="hidden" name="slotname" value="$env{'form.slotname'}" />
377: <input type="hidden" name="releaseslot" value="$slot_name" />
378: <input type="hidden" name="command" value="change" />
379: STUFF
1.7 albertel 380: $r->print("<p>You can either ");
381: $r->print(<<STUFF);
1.6 albertel 382: <input type="submit" name="change" value="Change" />
383: STUFF
1.7 albertel 384: $r->print(' your reservation from <b>'.$description1.'</b> to <b>'.
385: $description2.
386: '</b> <br />or <a href="/adm/flip?postdata=return:">'.
387: &mt('Return to last resource').'</a></p>');
388: $r->print(<<STUFF);
1.6 albertel 389: </form>
390: STUFF
1.7 albertel 391: } else {
392: $r->print('<p><a href="/adm/flip?postdata=return:">'.
393: &mt('Return to last resource').'</a></p>');
394: }
1.5 albertel 395: return;
396: }
1.3 albertel 397: my %slot=&Apache::lonnet::get_slot($env{'form.slotname'});
398: my $reserved=&make_reservation($env{'form.slotname'},
399: \%slot,$symb);
400: my $description=&get_description($env{'form.slotname'},\%slot);
1.7 albertel 401: if (defined($reserved)) {
402: if ($reserved > -1) {
403: $r->print("<p>Success: $description</p>");
404: $r->print('<p><a href="/adm/flip?postdata=return:">'.
405: &mt('Return to last resource').'</a></p>');
406: return;
407: } elsif ($reserved < 0) {
408: $r->print("<p>Already reserved: $description</p>");
409: $r->print('<p><a href="/adm/flip?postdata=return:">'.
410: &mt('Return to last resource').'</a></p>');
411: return;
412: }
1.3 albertel 413: }
414:
1.7 albertel 415: my %lt=('request'=>"Availibility list",
1.3 albertel 416: 'try' =>'Try again');
417: %lt=&Apache::lonlocal::texthash(%lt);
418:
419: $r->print(<<STUFF);
420: <p> <font color="red">Failed</font> to reserve a spot for $description. </p>
421: <p>
422: <form method="POST" action="/adm/slotrequest">
423: <input type="submit" name="Try Again" value="$lt{'try'}" />
424: <input type="hidden" name="symb" value="$env{'form.symb'}" />
425: <input type="hidden" name="slotname" value="$env{'form.slotname'}" />
426: <input type="hidden" name="command" value="get" />
427: </form>
428: ?
429: </p>
430: <p>
431: or
432: <form method="POST" action="/adm/slotrequest">
433: <input type="hidden" name="symb" value="$env{'form.symb'}" />
434: <input type="submit" name="requestattempt" value="$lt{'request'}" />
435: </form>
436: </p>
437: or
438: STUFF
439: $r->print('<p><a href="/adm/flip?postdata=return:">'.
440: &mt('Return to last resource').'</a></p>');
441: return;
442: }
443:
444: sub allowed_slot {
445: my ($slot_name,$slot,$symb)=@_;
446: #already started
447: if ($slot->{'starttime'} < time) {
1.5 albertel 448: # all open slot to be schedulable
449: #return 0;
1.3 albertel 450: }
1.5 albertel 451: &Apache::lonxml::debug("$slot_name starttime good");
1.3 albertel 452: #already ended
453: if ($slot->{'endtime'} < time) {
454: return 0;
455: }
1.5 albertel 456: &Apache::lonxml::debug("$slot_name endtime good");
1.3 albertel 457: # not allowed to pick this one
458: if (defined($slot->{'type'})
459: && $slot->{'type'} ne 'schedulable_student') {
460: return 0;
461: }
1.5 albertel 462: &Apache::lonxml::debug("$slot_name type good");
1.3 albertel 463: # not allowed for this resource
464: if (defined($slot->{'symb'})
465: && $slot->{'symb'} ne $symb) {
466: return 0;
467: }
1.5 albertel 468: &Apache::lonxml::debug("$slot_name symb good");
1.3 albertel 469: return 1;
1.2 albertel 470: }
471:
1.3 albertel 472: sub get_description {
473: my ($slot_name,$slot)=@_;
474: my $description=$slot->{'description'};
475: if (!defined($description)) {
1.4 albertel 476: $description=&mt('[_1] From [_2] to [_3]',$slot_name,
1.3 albertel 477: &Apache::lonlocal::locallocaltime($slot->{'starttime'}),
478: &Apache::lonlocal::locallocaltime($slot->{'endtime'}));
479: }
480: return $description;
481: }
1.2 albertel 482:
483: sub show_choices {
484: my ($r,$symb)=@_;
485:
486: my ($cnum,$cdom)=&get_course();
487: my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
1.3 albertel 488: my $available;
1.2 albertel 489: $r->print('<table border="1">');
1.5 albertel 490: &Apache::lonxml::debug("Checking Slots");
491: my ($got_slot)=&check_for_reservation($symb);
1.2 albertel 492: foreach my $slot (sort
493: { return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'} }
494: (keys(%slots))) {
1.5 albertel 495:
496: &Apache::lonxml::debug("Checking Slot $slot");
1.3 albertel 497: next if (!&allowed_slot($slot,$slots{$slot}));
498:
499: $available++;
500:
501: my $description=&get_description($slot,$slots{$slot});
1.2 albertel 502:
503: my $form=&mt('Unavailable');
1.7 albertel 504: if (($slot eq $got_slot) ||
505: &space_available($slot,$slots{$slot},$symb)) {
1.5 albertel 506: my $text=&mt('Select');
507: my $command='get';
508: if ($slot eq $got_slot) {
509: $text=&mt('Free Reservation');
510: $command='release';
511: }
1.3 albertel 512: my $escsymb=&Apache::lonnet::escape($symb);
1.2 albertel 513: $form=<<STUFF;
1.3 albertel 514: <form method="POST" action="/adm/slotrequest">
1.5 albertel 515: <input type="submit" name="Select" value="$text" />
1.3 albertel 516: <input type="hidden" name="symb" value="$escsymb" />
517: <input type="hidden" name="slotname" value="$slot" />
1.5 albertel 518: <input type="hidden" name="command" value="$command" />
1.2 albertel 519: </form>
520: STUFF
521: }
522: $r->print(<<STUFF);
523: <tr>
524: <td>$form</td>
525: <td>$description</td>
526: </tr>
527: STUFF
528: }
1.3 albertel 529:
530: if (!$available) {
1.5 albertel 531: $r->print('<tr><td>No available times. <a href="/adm/flip?postdata=return:">'.
1.3 albertel 532: &mt('Return to last resource').'</a></td></tr>');
533: }
1.2 albertel 534: $r->print('</table>');
535: }
536:
1.30 albertel 537: sub to_show {
1.35 albertel 538: my ($slot,$when,$deleted) = @_;
1.30 albertel 539: my $time=time;
540: my $week=60*60*24*7;
1.35 albertel 541: if ($deleted eq 'hide' && $slot->{'type'} eq 'deleted') {
542: return 0;
543: }
544: if ($when eq 'any') {
545: return 1;
546: } elsif ($when eq 'now') {
1.30 albertel 547: if ($time > $slot->{'starttime'} &&
548: $time < $slot->{'endtime'}) {
549: return 1;
550: }
551: return 0;
552: } elsif ($when eq 'nextweek') {
553: if ( ($time < $slot->{'starttime'} &&
554: ($time+$week) > $slot->{'starttime'})
555: ||
556: ($time < $slot->{'endtime'} &&
557: ($time+$week) > $slot->{'endtime'}) ) {
558: return 1;
559: }
560: return 0;
561: } elsif ($when eq 'lastweek') {
562: if ( ($time > $slot->{'starttime'} &&
563: ($time-$week) < $slot->{'starttime'})
564: ||
565: ($time > $slot->{'endtime'} &&
566: ($time-$week) < $slot->{'endtime'}) ) {
567: return 1;
568: }
569: return 0;
570: } elsif ($when eq 'willopen') {
571: if ($time < $slot->{'starttime'}) {
572: return 1;
573: }
574: return 0;
575: } elsif ($when eq 'wereopen') {
576: if ($time > $slot->{'endtime'}) {
577: return 1;
578: }
579: return 0;
580: }
581:
582: return 1;
583: }
584:
1.33 albertel 585: sub remove_link {
586: my ($slotname,$entry,$uname,$udom,$symb) = @_;
587:
588: $slotname = &Apache::lonnet::escape($slotname);
589: $entry = &Apache::lonnet::escape($entry);
590: $uname = &Apache::lonnet::escape($uname);
591: $udom = &Apache::lonnet::escape($udom);
592: $symb = &Apache::lonnet::escape($symb);
593:
594: my $remove= &mt('Remove');
595:
596: return <<"END_LINK";
597: <a href="/adm/slotrequest?command=remove_registration&slotname=$slotname&entry=$entry&uname=$uname&udom=$udom&symb=$symb"
598: >($remove)</a>
599: END_LINK
600:
601: }
602:
1.5 albertel 603: sub show_table {
1.19 albertel 604: my ($r,$mgr)=@_;
1.5 albertel 605:
606: my ($cnum,$cdom)=&get_course();
607: my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
1.19 albertel 608: if ( (keys(%slots))[0] =~ /^error: 2 /) {
609: undef(%slots);
610: }
1.5 albertel 611: my $available;
1.14 albertel 612: if ($mgr eq 'F') {
1.30 albertel 613: $r->print('<div>');
1.14 albertel 614: $r->print('<form method="POST" action="/adm/slotrequest">
615: <input type="hidden" name="command" value="uploadstart" />
616: <input type="submit" name="start" value="'.&mt('Upload Slot List').'" />
617: </form>');
1.28 albertel 618: $r->print('<form method="POST" action="/adm/helper/newslot.helper">
619: <input type="submit" name="newslot" value="'.&mt('Create a New Slot').'" />
620: </form>');
1.30 albertel 621: $r->print('</div>');
1.14 albertel 622: }
1.29 albertel 623:
1.35 albertel 624: my %Saveable_Parameters = ('show' => 'array',
625: 'when' => 'scalar',
626: 'order' => 'scalar',
627: 'deleted' => 'scalar',
628: );
1.30 albertel 629: &Apache::loncommon::store_course_settings('slotrequest',\%Saveable_Parameters);
630: &Apache::loncommon::restore_course_settings('slotrequest',\%Saveable_Parameters);
1.29 albertel 631:
1.30 albertel 632: my %show_fields=&Apache::lonlocal::texthash(
1.29 albertel 633: 'name' => 'Slot Name',
634: 'description' => 'Description',
635: 'type' => 'Type',
636: 'starttime' => 'Start time',
637: 'endtime' => 'End Time',
638: 'startreserve' => 'Time students can start reserving',
639: 'secret' => 'Secret Word',
1.37 raeburn 640: 'maxspace' => 'Maximum # of students',
1.29 albertel 641: 'ip' => 'IP or DNS restrictions',
642: 'symb' => 'Resource slot is restricted to.',
643: 'uniqueperiod' => 'Period of time slot is unique',
644: 'proctor' => 'List of proctors');
1.30 albertel 645: my @show_order=('name','description','type','starttime','endtime',
1.29 albertel 646: 'startreserve','secret','maxspace','ip','symb',
647: 'uniqueperiod','proctor');
1.30 albertel 648: my @show =
1.29 albertel 649: (exists($env{'form.show'})) ? &Apache::loncommon::get_env_multiple('form.show')
1.30 albertel 650: : keys(%show_fields);
651: my %show = map { $_ => 1 } (@show);
652:
653: my %when_fields=&Apache::lonlocal::texthash(
1.35 albertel 654: 'now' => 'Open now',
1.30 albertel 655: 'nextweek' => 'Open within the next week',
656: 'lastweek' => 'Were open last week',
657: 'willopen' => 'Will open later',
1.35 albertel 658: 'wereopen' => 'Were open',
659: 'any' => 'Anytime',
660: );
661: my @when_order=('any','now','nextweek','lastweek','willopen','wereopen');
1.30 albertel 662: $when_fields{'select_form_order'} = \@when_order;
663: my $when = (exists($env{'form.when'})) ? $env{'form.when'}
664: : 'now';
1.29 albertel 665:
1.35 albertel 666: my $hide_radio =
667: &Apache::lonhtmlcommon::radio('deleted',$env{'form.deleted'},'hide');
668: my $show_radio =
669: &Apache::lonhtmlcommon::radio('deleted',$env{'form.deleted'},'show');
670:
1.29 albertel 671: $r->print('<form method="POST" action="/adm/slotrequest">
1.30 albertel 672: <input type="hidden" name="command" value="showslots" />');
673: $r->print('<div>');
1.35 albertel 674: $r->print('<table class="inline">
675: <tr><th>'.&mt('Show').'</th>
676: <th>'.&mt('Open').'</th>
677: <th>'.&mt('Options').'</th>
678: </tr>
679: <tr><td>'.&Apache::loncommon::multiple_select_form('show',\@show,6,\%show_fields,\@show_order).
680: '</td>
681: <td>'.&Apache::loncommon::select_form($when,'when',%when_fields).
682: '</td>
683: <td>
684: <table>
685: <tr>
686: <td rowspan="2">Deleted slots:</td>
687: <td><label>'.$show_radio.'Show</label></td>
688: </tr>
689: <tr>
690: <td><label>'.$hide_radio.'Hide</label></td>
691: </tr>
692: </table>
693: </td>
694: </tr>
695: </table>');
1.30 albertel 696: $r->print('</div>');
697: $r->print('<p><input type="submit" name="start" value="'.&mt('Update Display').'" /></p>');
1.21 albertel 698: my $linkstart='<a href="/adm/slotrequest?command=showslots&order=';
1.30 albertel 699: $r->print('<table class="thinborder">
1.10 albertel 700: <tr>
1.29 albertel 701: <th></th>');
1.30 albertel 702: foreach my $which (@show_order) {
703: if ($which ne 'proctor' && exists($show{$which})) {
704: $r->print('<th>'.$linkstart.$which.'">'.$show_fields{$which}.'</a></th>');
1.29 albertel 705: }
706: }
707: $r->print('<th>Scheduled Students</th></tr>');
708:
1.21 albertel 709: my %name_cache;
710: my $slotsort = sub {
1.29 albertel 711: if ($env{'form.order'}=~/^(type|description|endtime|startreserve|maxspace|ip|symb)$/) {
1.21 albertel 712: if (lc($slots{$a}->{$env{'form.order'}})
713: ne lc($slots{$b}->{$env{'form.order'}})) {
714: return (lc($slots{$a}->{$env{'form.order'}})
715: cmp lc($slots{$b}->{$env{'form.order'}}));
716: }
1.23 albertel 717: } elsif ($env{'form.order'} eq 'name') {
718: if (lc($a) cmp lc($b)) {
719: return lc($a) cmp lc($b);
720: }
1.29 albertel 721: } elsif ($env{'form.order'} eq 'uniqueperiod') {
1.21 albertel 722:
723: if ($slots{$a}->{'uniqueperiod'}[0]
724: ne $slots{$b}->{'uniqueperiod'}[0]) {
725: return ($slots{$a}->{'uniqueperiod'}[0]
726: cmp $slots{$b}->{'uniqueperiod'}[0]);
727: }
728: if ($slots{$a}->{'uniqueperiod'}[1]
729: ne $slots{$b}->{'uniqueperiod'}[1]) {
730: return ($slots{$a}->{'uniqueperiod'}[1]
731: cmp $slots{$b}->{'uniqueperiod'}[1]);
732: }
733: }
734: return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'};
735: };
736: foreach my $slot (sort $slotsort (keys(%slots))) {
1.35 albertel 737: if (!&to_show($slots{$slot},$when,$env{'form.deleted'})) { next; }
1.5 albertel 738: if (defined($slots{$slot}->{'type'})
739: && $slots{$slot}->{'type'} ne 'schedulable_student') {
1.13 albertel 740: #next;
1.5 albertel 741: }
742: my $description=&get_description($slot,$slots{$slot});
743: my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
744: "^$slot\0");
745: my $ids;
1.38 albertel 746:
747: my ($tmp)=%consumed;
748: if ($tmp !~ /^error: /) {
749: foreach my $entry (sort(keys(%consumed))) {
750: my (undef,$id)=split("\0",$entry);
751: my ($uname,$udom) = split('@',$consumed{$entry}{'name'});
752: my $name = &Apache::loncommon::plainname($uname,$udom);
753: $ids.= '<nobr>'.$name.&remove_link($slot,$entry,$uname,$udom,
754: $consumed{$entry}{'symb'})
755: .'</nobr><br />';
756: }
1.5 albertel 757: }
1.33 albertel 758:
1.24 albertel 759: my $start=($slots{$slot}->{'starttime'}?
760: &Apache::lonlocal::locallocaltime($slots{$slot}->{'starttime'}):'');
761: my $end=($slots{$slot}->{'endtime'}?
762: &Apache::lonlocal::locallocaltime($slots{$slot}->{'endtime'}):'');
1.28 albertel 763: my $start_reserve=($slots{$slot}->{'startreserve'}?
1.24 albertel 764: &Apache::lonlocal::locallocaltime($slots{$slot}->{'startreserve'}):'');
765:
1.14 albertel 766: my $unique;
767: if (ref($slots{$slot}{'uniqueperiod'})) {
768: $unique=localtime($slots{$slot}{'uniqueperiod'}[0]).','.
769: localtime($slots{$slot}{'uniqueperiod'}[1]);
770: }
1.33 albertel 771:
1.29 albertel 772: my $title;
773: if (exists($slots{$slot}{'symb'})) {
774: my (undef,undef,$res)=
775: &Apache::lonnet::decode_symb($slots{$slot}{'symb'});
776: $res = &Apache::lonnet::clutter($res);
777: $title = &Apache::lonnet::gettitle($slots{$slot}{'symb'});
778: $title='<a href="'.$res.'?symb='.$slots{$slot}{'symb'}.'">'.$title.'</a>';
779: }
1.33 albertel 780:
1.29 albertel 781: my @proctors;
782: my $rowspan=1;
783: my $colspan=1;
1.30 albertel 784: if (exists($show{'proctor'})) {
1.29 albertel 785: $rowspan=2;
786: @proctors= map {
787: my ($uname,$udom)=split(/@/,$_);
788: my $fullname=$name_cache{$_};
789: if (!defined($fullname)) {
790: &Apache::lonnet::logthis("Gettign $uname $udom");
791: $fullname = &Apache::loncommon::plainname($uname,$udom);
792: $fullname =~s/\s/ /g;
793: $name_cache{$_} = $fullname;
794: }
795: &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
796: } (sort(split(/\s*,\s*/,$slots{$slot}->{'proctor'})));
797: }
1.20 albertel 798: my $proctors=join(', ',@proctors);
1.14 albertel 799:
1.34 albertel 800: my $edit=(<<"EDITLINK");
1.31 albertel 801: <a href="/adm/helper/newslot.helper?name=$slot">Edit</a>
802: EDITLINK
1.34 albertel 803:
804: my $delete=(<<"DELETELINK");
805: <a href="/adm/slotrequest?command=delete&slotname=$slot">Delete</a>
806: DELETELINK
807: if ($ids ne '') { undef($delete); }
808:
809: $r->print("<tr>\n<td rowspan=\"$rowspan\">$edit $delete</td>\n");
1.30 albertel 810: if (exists($show{'name'})) {
1.29 albertel 811: $colspan++;$r->print("<td>$slot</td>");
812: }
1.33 albertel 813: if (exists($show{'description'})) {
814: $colspan++;$r->print("<td>$description</td>\n");
815: }
1.30 albertel 816: if (exists($show{'type'})) {
1.29 albertel 817: $colspan++;$r->print("<td>$slots{$slot}->{'type'}</td>\n");
818: }
1.30 albertel 819: if (exists($show{'starttime'})) {
1.29 albertel 820: $colspan++;$r->print("<td>$start</td>\n");
821: }
1.30 albertel 822: if (exists($show{'endtime'})) {
1.29 albertel 823: $colspan++;$r->print("<td>$end</td>\n");
824: }
1.30 albertel 825: if (exists($show{'startreserve'})) {
1.29 albertel 826: $colspan++;$r->print("<td>$start_reserve</td>\n");
827: }
1.30 albertel 828: if (exists($show{'secret'})) {
1.29 albertel 829: $colspan++;$r->print("<td>$slots{$slot}{'secret'}</td>\n");
830: }
1.30 albertel 831: if (exists($show{'maxspace'})) {
1.29 albertel 832: $colspan++;$r->print("<td>$slots{$slot}{'maxspace'}</td>\n");
833: }
1.30 albertel 834: if (exists($show{'ip'})) {
1.29 albertel 835: $colspan++;$r->print("<td>$slots{$slot}{'ip'}</td>\n");
836: }
1.30 albertel 837: if (exists($show{'symb'})) {
1.29 albertel 838: $colspan++;$r->print("<td>$title</td>\n");
839: }
1.30 albertel 840: if (exists($show{'uniqueperiod'})) {
1.29 albertel 841: $colspan++;$r->print("<td>$unique</td>\n");
842: }
843: $colspan++;$r->print("<td>$ids</td>\n</tr>\n");
1.30 albertel 844: if (exists($show{'proctor'})) {
1.29 albertel 845: $r->print(<<STUFF);
1.21 albertel 846: <tr>
1.29 albertel 847: <td colspan="$colspan">$proctors</td>
1.21 albertel 848: </tr>
1.5 albertel 849: STUFF
1.29 albertel 850: }
1.5 albertel 851: }
852: $r->print('</table>');
853: }
854:
1.14 albertel 855: sub upload_start {
1.19 albertel 856: my ($r)=@_;
1.14 albertel 857: $r->print(&Apache::grades::checkforfile_js());
858: my $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
859: $result.=' <b>'.
860: &mt('Specify a file containing the slot definitions.').
861: '</b></td></tr>'."\n";
862: $result.='<tr bgcolor=#ffffe6><td>'."\n";
863: my $upfile_select=&Apache::loncommon::upfile_select_html();
864: my $ignore=&mt('Ignore First Line');
865: $result.=<<ENDUPFORM;
866: <form method="post" enctype="multipart/form-data" action="/adm/slotrequest" name="slotupload">
867: <input type="hidden" name="command" value="csvuploadmap" />
868: $upfile_select
869: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Data" />
870: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
871: </form>
872: ENDUPFORM
873: $result.='</td></tr></table>'."\n";
874: $result.='</td></tr></table>'."\n";
875: $r->print($result);
876: }
877:
878: sub csvuploadmap_header {
1.19 albertel 879: my ($r,$datatoken,$distotal)= @_;
1.14 albertel 880: my $javascript;
881: if ($env{'form.upfile_associate'} eq 'reverse') {
882: $javascript=&csvupload_javascript_reverse_associate();
883: } else {
884: $javascript=&csvupload_javascript_forward_associate();
885: }
886:
887: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
888: my $ignore=&mt('Ignore First Line');
889: $r->print(<<ENDPICK);
890: <form method="post" enctype="multipart/form-data" action="/adm/slotrequest" name="slotupload">
891: <h3>Identify fields</h3>
892: Total number of records found in file: $distotal <hr />
893: Enter as many fields as you can. The system will inform you and bring you back
894: to this page if the data selected is insufficient to create the slots.<hr />
895: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
896: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
897: <input type="hidden" name="associate" value="" />
898: <input type="hidden" name="datatoken" value="$datatoken" />
899: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
900: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
901: <input type="hidden" name="upfile_associate"
902: value="$env{'form.upfile_associate'}" />
903: <input type="hidden" name="command" value="csvuploadassign" />
904: <hr />
905: <script type="text/javascript" language="Javascript">
906: $javascript
907: </script>
908: ENDPICK
909: return '';
910:
911: }
912:
913: sub csvuploadmap_footer {
914: my ($request,$i,$keyfields) =@_;
915: $request->print(<<ENDPICK);
916: </table>
917: <input type="hidden" name="nfields" value="$i" />
918: <input type="hidden" name="keyfields" value="$keyfields" />
919: <input type="button" onClick="javascript:verify(this.form)" value="Create Slots" /><br />
920: </form>
921: ENDPICK
922: }
923:
924: sub csvupload_javascript_reverse_associate {
925: my $error1=&mt('You need to specify the name, starttime, endtime and a type');
926: return(<<ENDPICK);
927: function verify(vf) {
928: var foundstart=0;
929: var foundend=0;
930: var foundname=0;
931: var foundtype=0;
932: for (i=0;i<=vf.nfields.value;i++) {
933: tw=eval('vf.f'+i+'.selectedIndex');
934: if (i==0 && tw!=0) { foundname=1; }
935: if (i==1 && tw!=0) { foundtype=1; }
936: if (i==2 && tw!=0) { foundstat=1; }
937: if (i==3 && tw!=0) { foundend=1; }
938: }
939: if (foundstart==0 && foundend==0 && foundtype==0 && foundname==0) {
940: alert('$error1');
941: return;
942: }
943: vf.submit();
944: }
945: function flip(vf,tf) {
946: }
947: ENDPICK
948: }
949:
950: sub csvupload_javascript_forward_associate {
951: my $error1=&mt('You need to specify the name, starttime, endtime and a type');
952: return(<<ENDPICK);
953: function verify(vf) {
954: var foundstart=0;
955: var foundend=0;
956: var foundname=0;
957: var foundtype=0;
958: for (i=0;i<=vf.nfields.value;i++) {
959: tw=eval('vf.f'+i+'.selectedIndex');
960: if (tw==1) { foundname=1; }
961: if (tw==2) { foundtype=1; }
962: if (tw==3) { foundstat=1; }
963: if (tw==4) { foundend=1; }
964: }
965: if (foundstart==0 && foundend==0 && foundtype==0 && foundname==0) {
966: alert('$error1');
967: return;
968: }
969: vf.submit();
970: }
971: function flip(vf,tf) {
972: }
973: ENDPICK
974: }
975:
976: sub csv_upload_map {
1.19 albertel 977: my ($r)= @_;
1.14 albertel 978:
979: my $datatoken;
980: if (!$env{'form.datatoken'}) {
981: $datatoken=&Apache::loncommon::upfile_store($r);
982: } else {
983: $datatoken=$env{'form.datatoken'};
984: &Apache::loncommon::load_tmp_file($r);
985: }
986: my @records=&Apache::loncommon::upfile_record_sep();
987: if ($env{'form.noFirstLine'}) { shift(@records); }
1.19 albertel 988: &csvuploadmap_header($r,$datatoken,$#records+1);
1.14 albertel 989: my ($i,$keyfields);
990: if (@records) {
991: my @fields=&csvupload_fields();
992:
993: if ($env{'form.upfile_associate'} eq 'reverse') {
994: &Apache::loncommon::csv_print_samples($r,\@records);
995: $i=&Apache::loncommon::csv_print_select_table($r,\@records,
996: \@fields);
997: foreach (@fields) { $keyfields.=$_->[0].','; }
998: chop($keyfields);
999: } else {
1000: unshift(@fields,['none','']);
1001: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
1002: \@fields);
1003: my %sone=&Apache::loncommon::record_sep($records[0]);
1004: $keyfields=join(',',sort(keys(%sone)));
1005: }
1006: }
1007: &csvuploadmap_footer($r,$i,$keyfields);
1008:
1009: return '';
1010: }
1011:
1012: sub csvupload_fields {
1013: return (['name','Slot name'],
1014: ['type','Type of slot'],
1015: ['starttime','Start Time of slot'],
1016: ['endtime','End Time of slot'],
1.15 albertel 1017: ['startreserve','Reservation Start Time'],
1.14 albertel 1018: ['ip','IP or DNS restriction'],
1019: ['proctor','List of proctor ids'],
1020: ['description','Slot Description'],
1021: ['maxspace','Maximum number of reservations'],
1022: ['symb','Resource Restriction'],
1023: ['uniqueperiod','Date range of slot exclusion'],
1024: ['secret','Secret word proctor uses to validate']);
1025: }
1026:
1027: sub csv_upload_assign {
1.19 albertel 1028: my ($r,$mgr)= @_;
1.14 albertel 1029: &Apache::loncommon::load_tmp_file($r);
1030: my @slotdata = &Apache::loncommon::upfile_record_sep();
1031: if ($env{'form.noFirstLine'}) { shift(@slotdata); }
1032: my %fields=&Apache::grades::get_fields();
1033: $r->print('<h3>Creating Slots</h3>');
1034: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1035: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1036: my $countdone=0;
1.31 albertel 1037: my @errors;
1.14 albertel 1038: foreach my $slot (@slotdata) {
1039: my %slot;
1040: my %entries=&Apache::loncommon::record_sep($slot);
1041: my $domain;
1042: my $name=$entries{$fields{'name'}};
1.31 albertel 1043: if ($name=~/^\s*$/) {
1044: push(@errors,"Did not create slot with no name");
1045: next;
1046: }
1047: if ($name=~/\s/) {
1048: push(@errors,"$name not created -- Name must not contain spaces");
1049: next;
1050: }
1051: if ($name=~/\W/) {
1052: push(@errors,"$name not created -- Name must contain only letters, numbers and _");
1053: next;
1054: }
1.14 albertel 1055: if ($entries{$fields{'type'}}) {
1056: $slot{'type'}=$entries{$fields{'type'}};
1057: } else {
1058: $slot{'type'}='preassigned';
1059: }
1.31 albertel 1060: if ($slot{'type'} ne 'preassigned' &&
1061: $slot{'type'} ne 'schedulable_student') {
1062: push(@errors,"$name not created -- invalid type ($slot{'type'}) must be either preassigned or schedulable_student");
1063: next;
1064: }
1.14 albertel 1065: if ($entries{$fields{'starttime'}}) {
1066: $slot{'starttime'}=&UnixDate($entries{$fields{'starttime'}},"%s");
1067: }
1068: if ($entries{$fields{'endtime'}}) {
1.16 albertel 1069: $slot{'endtime'}=&UnixDate($entries{$fields{'endtime'}},"%s");
1.14 albertel 1070: }
1.23 albertel 1071: if ($entries{$fields{'startreserve'}}) {
1072: $slot{'startreserve'}=
1073: &UnixDate($entries{$fields{'startreserve'}},"%s");
1074: }
1.14 albertel 1075: foreach my $key ('ip','proctor','description','maxspace',
1076: 'secret','symb') {
1077: if ($entries{$fields{$key}}) {
1078: $slot{$key}=$entries{$fields{$key}};
1079: }
1080: }
1081: if ($entries{$fields{'uniqueperiod'}}) {
1082: my ($start,$end)=split(',',$entries{$fields{'uniqueperiod'}});
1083: my @times=(&UnixDate($start,"%s"),
1084: &UnixDate($end,"%s"));
1085: $slot{'uniqueperiod'}=\@times;
1086: }
1087:
1088: &Apache::lonnet::cput('slots',{$name=>\%slot},$cdom,$cname);
1089: $r->print('.');
1090: $r->rflush();
1091: $countdone++;
1092: }
1.31 albertel 1093: $r->print("<p>Created $countdone slots\n</p>");
1094: foreach my $error (@errors) {
1095: $r->print("<p>$error\n</p>");
1096: }
1.19 albertel 1097: &show_table($r,$mgr);
1.14 albertel 1098: return '';
1099: }
1100:
1.1 albertel 1101: sub handler {
1102: my $r=shift;
1103:
1.30 albertel 1104: &Apache::loncommon::content_type($r,'text/html');
1105: &Apache::loncommon::no_cache($r);
1106: if ($r->header_only()) {
1107: $r->send_http_header();
1108: return OK;
1109: }
1110:
1.8 albertel 1111: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.28 albertel 1112:
1.12 albertel 1113: my $vgr=&Apache::lonnet::allowed('vgr',$env{'request.course.id'});
1.14 albertel 1114: my $mgr=&Apache::lonnet::allowed('mgr',$env{'request.course.id'});
1.28 albertel 1115: my $title='Requesting Another Worktime';
1116: if ($env{'form.command'} =~ /^(showslots|uploadstart|csvuploadmap|csvuploadassign)$/ && $vgr eq 'F') {
1117: $title = 'Managing Slots';
1118: }
1119: &start_page($r,$title);
1120:
1.8 albertel 1121: if ($env{'form.command'} eq 'showslots' && $vgr eq 'F') {
1.19 albertel 1122: &show_table($r,$mgr);
1.33 albertel 1123: } elsif ($env{'form.command'} eq 'remove_registration' && $mgr eq 'F') {
1124: &remove_registration($r);
1125: } elsif ($env{'form.command'} eq 'release' && $mgr eq 'F') {
1126: &release_slot($r,undef,undef,undef,$mgr);
1.34 albertel 1127: } elsif ($env{'form.command'} eq 'delete' && $mgr eq 'F') {
1128: &delete_slot($r);
1.14 albertel 1129: } elsif ($env{'form.command'} eq 'uploadstart' && $mgr eq 'F') {
1.19 albertel 1130: &upload_start($r);
1.14 albertel 1131: } elsif ($env{'form.command'} eq 'csvuploadmap' && $mgr eq 'F') {
1.19 albertel 1132: &csv_upload_map($r);
1.14 albertel 1133: } elsif ($env{'form.command'} eq 'csvuploadassign' && $mgr eq 'F') {
1134: if ($env{'form.associate'} ne 'Reverse Association') {
1.19 albertel 1135: &csv_upload_assign($r,$mgr);
1.14 albertel 1136: } else {
1137: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
1138: $env{'form.upfile_associate'} = 'reverse';
1139: } else {
1140: $env{'form.upfile_associate'} = 'forward';
1141: }
1.19 albertel 1142: &csv_upload_map($r);
1.14 albertel 1143: }
1.8 albertel 1144: } else {
1.19 albertel 1145: my $symb=&Apache::lonnet::unescape($env{'form.symb'});
1146: my (undef,undef,$res)=&Apache::lonnet::decode_symb($symb);
1.36 albertel 1147: my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb);
1148: if ($useslots ne 'resource') {
1.19 albertel 1149: &fail($r,'not_valid');
1150: return OK;
1151: }
1152: $env{'request.symb'}=$symb;
1.36 albertel 1153: my $type = ($res =~ /\.task$/) ? 'Task'
1154: : 'problem';
1155: my ($status) = &Apache::lonhomework::check_slot_access('0',$type);
1.11 albertel 1156: if ($status eq 'CAN_ANSWER' ||
1157: $status eq 'NEEDS_CHECKIN' ||
1158: $status eq 'WAITING_FOR_GRADE') {
1159: &fail($r,'not_allowed');
1160: return OK;
1161: }
1162: if ($env{'form.requestattempt'}) {
1163: &show_choices($r,$symb);
1164: } elsif ($env{'form.command'} eq 'release') {
1165: &release_slot($r,$symb);
1166: } elsif ($env{'form.command'} eq 'get') {
1167: &get_slot($r,$symb);
1168: } elsif ($env{'form.command'} eq 'change') {
1.39 ! albertel 1169: if (&release_slot($r,$symb,$env{'form.releaseslot'},1)) {
! 1170: &get_slot($r,$symb);
! 1171: }
1.11 albertel 1172: } else {
1173: $r->print("<p>Unknown command: ".$env{'form.command'}."</p>");
1174: }
1.2 albertel 1175: }
1.1 albertel 1176: &end_page($r);
1177: return OK;
1178: }
1.3 albertel 1179:
1180: 1;
1181: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>