[LON-CAPA-cvs] cvs: loncom /debugging_tools make_slots.pl /homework bridgetask.pm /interface slotrequest.pm

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 09 Aug 2005 07:34:53 -0000


This is a MIME encoded message

--albertel1123572893
Content-Type: text/plain

albertel		Tue Aug  9 03:34:53 2005 EDT

  Modified files:              
    /loncom/homework	bridgetask.pm 
    /loncom/interface	slotrequest.pm 
    /loncom/debugging_tools	make_slots.pl 
  Log:
  - adding uniqueperiod - time period in which a another slot of an overlapping unique period can't be scheduled
  - instructors can also see the full reservation table
  
  
  
--albertel1123572893
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20050809033453.txt"

Index: loncom/homework/bridgetask.pm
diff -u loncom/homework/bridgetask.pm:1.37 loncom/homework/bridgetask.pm:1.38
--- loncom/homework/bridgetask.pm:1.37	Sat Jun  4 04:17:06 2005
+++ loncom/homework/bridgetask.pm	Tue Aug  9 03:34:51 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: bridgetask.pm,v 1.37 2005/06/04 08:17:06 albertel Exp $
+# $Id: bridgetask.pm,v 1.38 2005/08/09 07:34:51 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -165,25 +165,30 @@
 }
 
 sub add_request_another_attempt_button {
+    my ($text)=@_;
+    if (!$text) { $text="Request another attempt"; }
     my $result;
     my $symb=&Apache::lonnet::symbread();
     my ($slot_name,$slot)=&Apache::slotrequest::check_for_reservation($symb);
+    my $action='get_reservation';
     if ($slot_name) {
+	$text="Change reservation.";
+	$action='change_reservation';
 	my $description=&Apache::slotrequest::get_description($slot_name,
 							      $slot);
 	$result.=(<<STUFF);
 <p> Will be next available: $description </p>
 STUFF
-
-    } else {
-	if ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); }
-	$symb=&Apache::lonnet::escape($symb);
-	$result.='<form method="POST" action="/adm/slotrequest">'.
-	    '<input type="hidden" name="symb" value="'.$symb.'" />'.
-	    '<input type="submit" name="requestattempt" value="'.
-	    &mt("Request another attempt").'" />'.
-	    '</form>';
     }
+    
+    if ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); }
+    $symb=&Apache::lonnet::escape($symb);
+    $result.='<form method="POST" action="/adm/slotrequest">'.
+	'<input type="hidden" name="symb" value="'.$symb.'" />'.
+	'<input type="hidden" name="command" value="'.$action.'" />'.
+	'<input type="submit" name="requestattempt" value="'.
+	&mt($text).'" />'.
+	'</form>';
     return $result;
 }
 
@@ -219,6 +224,14 @@
 	    my $uri=$env{'request.uri'};
 	    if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
 	    $body_tag_start.=$uri.'">'.&add_grading_button()."</form>";
+	    my $symb=&Apache::lonnet::symbread();
+	    $body_tag_start.='<form method="POST" action="/adm/slotrequest">'.
+		'<input type="hidden" name="symb" value="'.$symb.'" />'.
+		'<input type="hidden" name="command" value="showslots" />'.
+		'<input type="submit" name="requestattempt" value="'.
+		&mt('Show Slot list').'" />'.
+		'</form>';
+
 	}
     }
     if ($target eq 'web' || ($target eq 'grade' && !$env{'form.webgrade'}) || $target eq 'answer' ||
@@ -249,6 +262,7 @@
 		    $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
 		} elsif ($status eq 'NOT_IN_A_SLOT') {
 		    $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
+		    $msg.=&add_request_another_attempt_button("Sign up for time to work.");
 		} elsif ($status eq 'NEEDS_CHECKIN') {
 		    $msg.='<h1>'.&mt('You need the Proctor to validate you.').
 			'</h1>'.&proctor_validation_screen($slot);
Index: loncom/interface/slotrequest.pm
diff -u loncom/interface/slotrequest.pm:1.4 loncom/interface/slotrequest.pm:1.5
--- loncom/interface/slotrequest.pm:1.4	Sat Jun  4 04:17:06 2005
+++ loncom/interface/slotrequest.pm	Tue Aug  9 03:34:51 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler for requesting to have slots added to a students record
 #
-# $Id: slotrequest.pm,v 1.4 2005/06/04 08:17:06 albertel Exp $
+# $Id: slotrequest.pm,v 1.5 2005/08/09 07:34:51 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -134,8 +134,32 @@
     return (undef,undef);
 }
 
+sub check_for_conflict {
+    my ($symb,$new_slot_name)=@_;
+    my $student = &Apache::lonnet::EXT("resource.0.availablestudent", $symb,
+				       $env{'user.domain'}, $env{'user.name'});
+    my $course = &Apache::lonnet::EXT("resource.0.available", $symb,
+				      $env{'user.domain'}, $env{'user.name'});
+    my @slots = (split(/:/,$student), split(/:/, $course));
+    my ($cnum,$cdom)=&get_course();
+    my %slots=&Apache::lonnet::get('slots', [@slots], $cdom, $cnum);
+    foreach my $slot_name (@slots) {
+	next if (!defined($slots{$slot_name}) ||
+		 !ref($slots{$slot_name}));
+
+        next if (!defined($slots{$slot_name}->{'uniqueperiod'}) ||
+		 !ref($slots{$slot_name}->{'uniqueperiod'}));
+	my ($start,$end)=@{$slots{$slot_name}->{'uniqueperiod'}};
+	if ($start<time && time < $end) {
+	    return $slot_name;
+	}
+    }
+    return undef;
+
+}
+
 # FIXME - depends on the parameter for the resource to be correct
-#         tho prevent multiple reservations
+#         to prevent multiple reservations
 
 sub make_reservation {
     my ($slot_name,$slot,$symb)=@_;
@@ -207,9 +231,28 @@
     return undef;
 }
 
+sub release_slot {
+    my ($r,$symb)=@_;
+    # get parameter string, check for existance, rebuild string with the slot
+
+    # get slot reservations, check if user has one, if so remove reservation
+
+    # store new parameter string
+}
+
 sub get_slot {
     my ($r,$symb)=@_;
 
+    my $slot_name=&check_for_conflict($symb,$env{'form.slotname'});
+    if ($slot_name) {
+	my %slot=&Apache::lonnet::get_slot($slot_name);
+	my $description=&get_description($env{'form.slotname'},\%slot);
+	$r->print("<p>Already have a reservation: $description</p>");
+	$r->print('<p><a href="/adm/flip?postdata=return:">'.
+		  &mt('Return to last resource').'</a></p>');
+	# FIXME add button to free current reservation adn get new one
+	return;
+    }
     my %slot=&Apache::lonnet::get_slot($env{'form.slotname'});
     my $reserved=&make_reservation($env{'form.slotname'},
 				   \%slot,$symb);
@@ -259,26 +302,27 @@
     my ($slot_name,$slot,$symb)=@_;
     #already started
     if ($slot->{'starttime'} < time) {
-	return 0;
+	# all open slot to be schedulable
+	#return 0;
     }
-
+    &Apache::lonxml::debug("$slot_name starttime good");
     #already ended
     if ($slot->{'endtime'} < time) {
 	return 0;
     }
-
+    &Apache::lonxml::debug("$slot_name endtime good");
     # not allowed to pick this one
     if (defined($slot->{'type'})
 	&& $slot->{'type'} ne 'schedulable_student') {
 	return 0;
     }
-
+    &Apache::lonxml::debug("$slot_name type good");
     # not allowed for this resource
     if (defined($slot->{'symb'})
 	&& $slot->{'symb'} ne $symb) {
 	return 0;
     }
-
+    &Apache::lonxml::debug("$slot_name symb good");
     return 1;
 }
 
@@ -300,10 +344,13 @@
     my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
     my $available;
     $r->print('<table border="1">');
+    &Apache::lonxml::debug("Checking Slots");
+    my ($got_slot)=&check_for_reservation($symb);
     foreach my $slot (sort 
 		      { return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'} }
 		      (keys(%slots)))  {
-	
+
+	&Apache::lonxml::debug("Checking Slot $slot");
 	next if (!&allowed_slot($slot,$slots{$slot}));
 
 	$available++;
@@ -312,13 +359,19 @@
 
 	my $form=&mt('Unavailable');
 	if (&space_available($slot,$slots{$slot},$symb)) {
+	    my $text=&mt('Select');
+	    my $command='get';
+	    if ($slot eq $got_slot) {
+		$text=&mt('Free Reservation');
+		$command='release';
+	    }
 	    my $escsymb=&Apache::lonnet::escape($symb);
 	    $form=<<STUFF;
    <form method="POST" action="/adm/slotrequest">
-     <input type="submit" name="Select" value="Select" />
+     <input type="submit" name="Select" value="$text" />
      <input type="hidden" name="symb" value="$escsymb" />
      <input type="hidden" name="slotname" value="$slot" />
-     <input type="hidden" name="command" value="get" />
+     <input type="hidden" name="command" value="$command" />
    </form>
 STUFF
 	}
@@ -331,12 +384,50 @@
     }
 
     if (!$available) {
-	$r->print('<tr><td>No avaliable times. <a href="/adm/flip?postdata=return:">'.
+	$r->print('<tr><td>No available times. <a href="/adm/flip?postdata=return:">'.
 		  &mt('Return to last resource').'</a></td></tr>');
     }
     $r->print('</table>');
 }
 
+sub show_table {
+    my ($r,$symb)=@_;
+
+    my ($cnum,$cdom)=&get_course();
+    my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
+    my $available;
+    $r->print('<table border="1">');
+    foreach my $slot (sort 
+		      { return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'} }
+		      (keys(%slots)))  {
+	if (defined($slots{$slot}->{'type'})
+	    && $slots{$slot}->{'type'} ne 'schedulable_student') {
+	    next;
+	}
+	my $description=&get_description($slot,$slots{$slot});
+	my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
+					   "^$slot\0");
+	my $ids;
+	foreach my $entry (sort(keys(%consumed))) {
+	    my (undef,$id)=split("\0",$entry);
+	    $ids.= $id.'-> '.$consumed{$entry}->{'name'}.'<br />';
+	}
+	my $start=localtime($slots{$slot}->{'starttime'});
+	my $end=localtime($slots{$slot}->{'endtime'});
+	$r->print(<<STUFF);
+<tr>
+ <td>$slot</td>
+ <td>$description</td>
+ <td>$start</td>
+ <td>$end</td>
+ <td>$slots{$slot}->{'maxspace'}</td>
+ <td>$ids</td>
+</tr>
+STUFF
+    }
+    $r->print('</table>');
+}
+
 sub handler {
     my $r=shift;
 
@@ -347,9 +438,13 @@
 	&fail($r,'not_valid');
 	return OK;
     }
-    
-    if ($env{'form.requestattempt'}) {
+ 
+    if ($env{'form.command'} eq 'showslots') {
+	&show_table($r,$symb);
+    } elsif ($env{'form.requestattempt'}) {
 	&show_choices($r,$symb);
+    } elsif ($env{'form.command'} eq 'release') {
+	&release_slot($r,$symb);
     } elsif ($env{'form.command'} eq 'get') {
 	&get_slot($r,$symb);
     }
Index: loncom/debugging_tools/make_slots.pl
diff -u loncom/debugging_tools/make_slots.pl:1.4 loncom/debugging_tools/make_slots.pl:1.5
--- loncom/debugging_tools/make_slots.pl:1.4	Sat Jun  4 04:17:32 2005
+++ loncom/debugging_tools/make_slots.pl	Tue Aug  9 03:34:52 2005
@@ -30,11 +30,11 @@
   maxspace - integer (number of people that can schedule this space)
              (if unspecfied no limit is used)
   symb - arrayref of symbs that can be scheduled to be done in this slot
-
+  uniqueperiod - if the user has a reservation that has a uniqueperiod
+                 that overlaps this don't allow them to schedule this
+                 slot
 Possibly Need: (but not yet supported)
-  uniqperiod - if the user has a reservation that has a uniqpersion
-               that overlaps this dn't allow them to schedule this
-               reservation
+  secret - arrary ref of words that are the secret for this slot
 
 
 =cut
@@ -65,8 +65,8 @@
 	'starttime' => &UnixDate("Aug 30th 00:00:00 2004","%s"),
 	'endtime'   => &UnixDate("Aug 30th 00:00:00 2006","%s"),
         'endtime'   => &UnixDate("Aug 30th 00:00:00 2004","%s"),
-	'ip'        => "1.2.3.4",
-	'ip'        => "*albertelli.com",
+	#'ip'        => "1.2.3.4",
+	#'ip'        => "*albertelli.com",
 	'proctor'   => 'testuser@annarbor',
     });
 $db{'slot4'}=
@@ -76,31 +76,36 @@
 	'starttime' => &UnixDate("Aug 30th 00:00:00 2004","%s"),
 	'endtime'   => &UnixDate("Aug 30th 00:00:00 2006","%s"),
 	'endtime'   => &UnixDate("Aug 30th 00:00:00 2004","%s"),
-	'ip'        => "*albertelli.com",
+	#'ip'        => "*albertelli.com",
 	'proctor'   => 'testuser@annarbor',
     });
 $db{'slot5'}=
     &freeze_escape({
 	'type'      => 'schedulable_student',
-	'description' => undef,#'Aug 30th 4 P.M., Room 123 Kedzie',
+	'description' => 'Aug 30th 4 P.M., Room 123 Kedzie',
 	'startreserve' => &UnixDate("Aug 29th 00:00:00 2004","%s"),
-	#'starttime' => &UnixDate("Aug 30th 00:00:00 2004","%s"),
+	'starttime' => &UnixDate("Aug 30th 00:00:00 2004","%s"),
 	'starttime' => &UnixDate("Aug 30th 00:00:00 2006","%s"),
-	'endtime'   => &UnixDate("Aug 30th 00:00:00 2006","%s"),
+	'endtime' => &UnixDate("Aug 30th 00:00:00 2006","%s"),
+	#'endtime'   => &UnixDate("Aug 30th 00:00:00 2006","%s"),
 	#'endtime'   => &UnixDate("Aug 30th 00:00:00 2004","%s"),
-	'ip'        => "*albertelli.com",
+	#'ip'        => "*albertelli.com,"
 	'proctor'   => 'testuser@annarbor',
+	'uniqueperiod' => [&UnixDate("Aug 30th 00:00:00 2004","%s"),
+			   &UnixDate("Aug 30th 00:00:00 2005","%s")],
     });
 $db{'slot6'}=
     &freeze_escape({
 	'type'      => 'schedulable_student',
 	'description' => 'Aug 31th 4 P.M., Room 222 Computer Center',
 	'startreserve' => &UnixDate("Aug 29th 00:00:00 2004","%s"),
-	'starttime' => &UnixDate("Aug 30th 00:00:00 2004","%s"),
+	'starttime' => &UnixDate("Aug 30th 00:00:00 2006","%s"),
 	'endtime'   => &UnixDate("Aug 30th 00:00:00 2006","%s"),
 	#'endtime'   => &UnixDate("Aug 30th 00:00:00 2004","%s"),
-	'ip'        => "*albertelli.com",
+	#'ip'        => "*albertelli.com",
 	'proctor'   => 'testuser@annarbor',
+	'uniqueperiod' => [&UnixDate("Aug 1st 00:00:00 2005","%s"),
+			   &UnixDate("Aug 30th 00:00:00 2006","%s")],
     });
 
 sub freeze_escape {

--albertel1123572893--