[LON-CAPA-cvs] cvs: loncom /interface slotrequest.pm

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 30 Mar 2006 04:35:59 -0000


albertel		Wed Mar 29 23:35:59 2006 EDT

  Modified files:              
    /loncom/interface	slotrequest.pm 
  Log:
  - add ability to remove all student reservations from a slot quickly
  
  
Index: loncom/interface/slotrequest.pm
diff -u loncom/interface/slotrequest.pm:1.54 loncom/interface/slotrequest.pm:1.55
--- loncom/interface/slotrequest.pm:1.54	Wed Mar 29 23:34:32 2006
+++ loncom/interface/slotrequest.pm	Wed Mar 29 23:35:58 2006
@@ -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.54 2006/03/30 04:34:32 albertel Exp $
+# $Id: slotrequest.pm,v 1.55 2006/03/30 04:35:58 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -313,37 +313,106 @@
 
 sub remove_registration {
     my ($r) = @_;
+    if ($env{'form.entry'} ne 'remove all') {
+	return &remove_registration_user($r);
+    }
+    my $slot_name = $env{'form.slotname'};
+    my %slot=&Apache::lonnet::get_slot($slot_name);
+
+    my ($cnum,$cdom)=&get_course();
+    my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
+				       "^$slot_name\0");
+    if (&network_error(%consumed)) {
+	$r->print("<p>".&mt('A network error has occured.').'</p>');
+	return;
+    }
+    if (!%consumed) {
+	$r->print("<p>".&mt('Slot <tt>[_1]</tt> has no reservations.',
+			    $slot_name)."</p>");
+	return;
+    }
+
+    my @names = map { $consumed{$_}{'name'} } (sort(keys(%consumed)));
+    my $names = join(' ',@names);
+
+    my $msg = &mt('Remove all of [_1] from slot [_2]?',$names,$slot_name);
+    &remove_registration_confirmation($r,$msg,['entry','slotname']);
+}
+
+sub remove_registration_user {
+    my ($r) = @_;
+    
+    my $slot_name = $env{'form.slotname'};
+
     my $name = &Apache::loncommon::plainname($env{'form.uname'},
 					     $env{'form.udom'});
 
     my $title = &Apache::lonnet::gettitle($env{'form.symb'});
 
+    my $msg = &mt('Remove [_1] from slot [_2] for [_3]',
+		  $name,$slot_name,$title);
+    
+    &remove_registration_confirmation($r,$msg,['uname','udom','slotname',
+					       'entry','symb']);
+}
+
+sub remove_registration_confirmation {
+    my ($r,$msg,$inputs) =@_;
+
     my $hidden_input;
-    foreach my $parm ('uname','udom','slotname','entry','symb') {
+    foreach my $parm (@{$inputs}) {
 	$hidden_input .=
 	    '<input type="hidden" name="'.$parm.'" value="'
 	    .&HTML::Entities::encode($env{'form.'.$parm},'"<>&\'').'" />'."\n";
     }
+    my %lt = &Apache::lonlocal::texthash('yes' => 'Yes',
+					 'no'  => 'No',);
     $r->print(<<"END_CONFIRM");
-<p> Remove $name from slot $env{'form.slotname'} for $title</p>
+<p> $msg </p>
 <form action="/adm/slotrequest" method="POST">
     <input type="hidden" name="command" value="release" />
+    <input type="hidden" name="button" value="yes" />
     $hidden_input
-    <input type="submit" name="Yes" value="yes" />
+    <input type="submit" value="$lt{'yes'}" />
 </form>
 <form action="/adm/slotrequest" method="POST">
     <input type="hidden" name="command" value="showslots" />
-    <input type="submit" name="No" value="no" />
+    <input type="submit" value="$lt{'no'}" />
 </form>
 END_CONFIRM
 
 }
 
+sub release_all_slot {
+    my ($r,$mgr)=@_;
+    
+    my $slot_name = $env{'form.slotname'};
+
+    my ($cnum,$cdom)=&get_course();
+
+    my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
+				       "^$slot_name\0");
+    
+    $r->print('<p>'.&mt('Releasing reservations').'</p>');
+
+    foreach my $entry (sort { $consumed{$a}{'name'} cmp 
+				  $consumed{$b}{'name'} } (keys(%consumed))) {
+	my ($uname,$udom) = split('@',$consumed{$entry}{'name'});
+	my ($result,$msg) =
+	    &release_reservation($slot_name,$uname,$udom,
+				 $consumed{$entry}{'symb'},$mgr);
+	$r->print("<p>$msg</p>");
+	$r->rflush();
+    }
+    $r->print('<p><a href="/adm/slotrequest?command=showslots">'.
+	      &mt('Return to slot list').'</a></p>');
+    &return_link($r);
+}
+
 sub release_slot {
     my ($r,$symb,$slot_name,$inhibit_return_link,$mgr)=@_;
 
     if ($slot_name eq '') { $slot_name=$env{'form.slotname'}; }
-    my ($cnum,$cdom)=&get_course();
 
     my ($uname,$udom) = ($env{'user.name'}, $env{'user.domain'});
     if ($mgr eq 'F' 
@@ -355,14 +424,28 @@
 	&& defined($env{'form.symb'})) {
 	$symb = $env{'form.symb'};
     }
+
+    my ($result,$msg) =
+	&release_reservation($slot_name,$uname,$udom,$symb,$mgr);
+    $r->print("<p>$msg</p>");
+    
+    if ($mgr eq 'F') {
+	$r->print('<p><a href="/adm/slotrequest?command=showslots">'.
+		  &mt('Return to slot list').'</a></p>');
+    }
+
+    if (!$inhibit_return_link) { &return_link($r);  }
+    return $result;
+}
+
+sub release_reservation {
+    my ($slot_name,$uname,$udom,$symb,$mgr) = @_;
     my %slot=&Apache::lonnet::get_slot($slot_name);
-    my $description=&get_description($env{'form.slotname'},\%slot);
+    my $description=&get_description($slot_name,\%slot);
 
     if ($mgr ne 'F') {
 	if ($slot{'starttime'} < time) {
-	    $r->print("<p>Not allowed to release Reservation: $description, as it has already ended.  </p>");
-	    &return_link($r);
-	    return 0;
+	    return (0,&mt('Not allowed to release Reservation: [_1], as it has already ended.',$description));
 	}
     }
     # get parameter string, check for existance, rebuild string with the slot
@@ -376,6 +459,8 @@
     }
     my $new_param = join(':',@new_slots);
 
+    my ($cnum,$cdom)=&get_course();
+
     # get slot reservations, check if user has one, if so remove reservation
     my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
 				       "^$slot_name\0");
@@ -391,13 +476,14 @@
 						      '0_availablestudent',
 						      1, $new_param, 'string',
 						      $uname,$udom);
-    $r->print("<p>Released Reservation: $description</p>");
+
+    my $msg;
     if ($mgr eq 'F') {
-	$r->print('<p><a href="/adm/slotrequest?command=showslots">'.
-		  &mt('Return to slot list').'</a></p>');
+	$msg = &mt('Released Reservation for user: [_1]',"$uname:$udom");
+    } else {
+	$msg = &mt('Released Reservation: [_1]',$description);
     }
-    if (!$inhibit_return_link) { &return_link($r);  }
-    return 1;
+    return (1,$msg);
 }
 
 sub delete_slot {
@@ -743,14 +829,20 @@
 sub remove_link {
     my ($slotname,$entry,$uname,$udom,$symb) = @_;
 
+    my $remove = &mt('Remove');
+
+    if ($entry eq 'remove all') {
+	$remove = &mt('Remove All');
+	undef($uname);
+	undef($udom);
+    }
+
     $slotname  = &Apache::lonnet::escape($slotname);
     $entry     = &Apache::lonnet::escape($entry);
     $uname     = &Apache::lonnet::escape($uname);
     $udom      = &Apache::lonnet::escape($udom);
     $symb      = &Apache::lonnet::escape($symb);
 
-    my $remove= &mt('Remove');
-
     return <<"END_LINK";
  <a href="/adm/slotrequest?command=remove_registration&slotname=$slotname&entry=$entry&uname=$uname&udom=$udom&symb=$symb"
    >($remove)</a>
@@ -1049,9 +1141,15 @@
 	my $delete=(<<"DELETELINK");
 <a href="/adm/slotrequest?command=delete&slotname=$slot">Delete</a>
 DELETELINK
+
+        my $remove_all=&remove_link($slot,'remove all');
+
         if ($ids ne '') { undef($delete); }
+	if ($slots{$slot}{'type'} ne 'schedulable_student') { 
+	    undef($remove_all);
+	}
 
-        $r->print("<tr>\n<td rowspan=\"$rowspan\">$edit $delete</td>\n");
+        $r->print("<tr>\n<td rowspan=\"$rowspan\">$edit $delete $remove_all</td>\n");
 	if (exists($show{'name'})) {
 	    $colspan++;$r->print("<td>$slot</td>");
 	}
@@ -1376,7 +1474,11 @@
     } elsif ($env{'form.command'} eq 'remove_registration' && $mgr eq 'F') {
 	&remove_registration($r);
     } elsif ($env{'form.command'} eq 'release' && $mgr eq 'F') {
-	&release_slot($r,undef,undef,undef,$mgr);
+	if ($env{'form.entry'} eq 'remove all') {
+	    &release_all_slot($r,$mgr);
+	} else {
+	    &release_slot($r,undef,undef,undef,$mgr);
+	}
     } elsif ($env{'form.command'} eq 'delete' && $mgr eq 'F') {
 	&delete_slot($r);
     } elsif ($env{'form.command'} eq 'uploadstart' && $mgr eq 'F') {