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