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

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


This is a MIME encoded message

--albertel1143693443
Content-Type: text/plain

albertel		Wed Mar 29 23:37:23 2006 EDT

  Modified files:              (Branch: version_2_1_X)
    /loncom/interface	slotrequest.pm 
  Log:
  - backport 1.54 1.55
  
  
--albertel1143693443
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20060329233723.txt"

Index: loncom/interface/slotrequest.pm
diff -u loncom/interface/slotrequest.pm:1.48.2.1 loncom/interface/slotrequest.pm:1.48.2.2
--- loncom/interface/slotrequest.pm:1.48.2.1	Tue Mar 21 11:05:57 2006
+++ loncom/interface/slotrequest.pm	Wed Mar 29 23:37:22 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.48.2.1 2006/03/21 16:05:57 albertel Exp $
+# $Id: slotrequest.pm,v 1.48.2.2 2006/03/30 04:37:22 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -315,37 +315,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' 
@@ -357,14 +426,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
@@ -378,6 +461,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");
@@ -393,13 +478,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 {
@@ -644,12 +730,27 @@
 }
 
 sub to_show {
-    my ($slot,$when,$deleted) = @_;
+    my ($slotname,$slot,$when,$deleted,$name) = @_;
     my $time=time;
     my $week=60*60*24*7;
+
     if ($deleted eq 'hide' && $slot->{'type'} eq 'deleted') {
 	return 0;
     }
+
+    if ($name && $name->{'value'} =~ /\w/) {
+	if ($name->{'type'} eq 'substring') {
+	    if ($slotname !~ /\Q$name->{'value'}\E/) {
+		return 0;
+	    }
+	}
+	if ($name->{'type'} eq 'exact') {
+	    if ($slotname eq $name->{'value'}) {
+		return 0;
+	    }
+	}
+    }
+
     if ($when eq 'any') {
 	return 1;
     } elsif ($when eq 'now') {
@@ -694,14 +795,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>
@@ -730,10 +837,12 @@
 	$r->print('</div>');
     }
     
-    my %Saveable_Parameters = ('show'    => 'array',
-			       'when'    => 'scalar',
-			       'order'   => 'scalar',
-			       'deleted' => 'scalar',
+    my %Saveable_Parameters = ('show'              => 'array',
+			       'when'              => 'scalar',
+			       'order'             => 'scalar',
+			       'deleted'           => 'scalar',
+			       'name_filter_type'  => 'scalar',
+			       'name_filter_value' => 'scalar',
 			       );
     &Apache::loncommon::store_course_settings('slotrequest',
 					      \%Saveable_Parameters);
@@ -743,6 +852,7 @@
     my ($classlist,$section,$fullname)=&Apache::grades::getclasslist('all');
     &Apache::grades::reset_perm();
 
+    # what to display filtering
     my %show_fields=&Apache::lonlocal::texthash(
 	     'name'         => 'Slot Name',
 	     'description'  => 'Description',
@@ -765,6 +875,7 @@
 	                            : keys(%show_fields);
     my %show =  map { $_ => 1 } (@show);
 
+    #when filtering setup
     my %when_fields=&Apache::lonlocal::texthash(
 	     'now'      => 'Open now',
 	     'nextweek' => 'Open within the next week',
@@ -778,6 +889,7 @@
     my $when = 	(exists($env{'form.when'})) ? $env{'form.when'}
                                             : 'now';
 
+    #display of students setup
     my %stu_display_fields=
 	&Apache::lonlocal::texthash('username' => 'User name',
 				    'fullname' => 'Full name',
@@ -788,6 +900,22 @@
 	                                  : keys(%stu_display_fields);
     my %stu_display =  map { $_ => 1 } (@stu_display);
 
+    #name filtering setup
+    my %name_filter_type_fields=
+	&Apache::lonlocal::texthash('substring' => 'Substring',
+				    'exact'     => 'Exact',
+				    #'reg'       => 'Regular Expression',
+				    );
+    my @name_filter_type_order=('substring','exact');
+
+    $name_filter_type_fields{'select_form_order'} = \@name_filter_type_order;
+    my $name_filter_type = 
+	(exists($env{'form.name_filter_type'})) ? $env{'form.name_filter_type'}
+                                                : 'substring';
+    my $name_filter = {'type'  => $name_filter_type,
+		       'value' => $env{'form.name_filter_value'},};
+
+    #deleted slot filtering
     my $hide_radio = 
 	&Apache::lonhtmlcommon::radio('deleted',$env{'form.deleted'},'hide');
     my $show_radio = 
@@ -800,6 +928,7 @@
       <tr><th>'.&mt('Show').'</th>
           <th>'.&mt('Student Display').'</th>
           <th>'.&mt('Open').'</th>
+          <th>'.&mt('Slot Name Filter').'</th>
           <th>'.&mt('Options').'</th>
       </tr>
       <tr><td>'.&Apache::loncommon::multiple_select_form('show',\@show,6,\%show_fields,\@show_order).
@@ -811,6 +940,14 @@
            </td>
            <td>'.&Apache::loncommon::select_form($when,'when',%when_fields).
           '</td>
+           <td>'.&Apache::loncommon::select_form($name_filter_type,
+						 'name_filter_type',
+						 %name_filter_type_fields).
+	      '<br />'.
+	      &Apache::lonhtmlcommon::textbox('name_filter_value',
+					      $env{'form.name_filter_value'},
+					      15).
+          '</td>
            <td>
             <table>
               <tr>
@@ -864,7 +1001,8 @@
 	return $slots{$a}->{'starttime'} <=> $slots{$b}->{'starttime'};
     };
     foreach my $slot (sort $slotsort (keys(%slots)))  {
-	if (!&to_show($slots{$slot},$when,$env{'form.deleted'})) { next; }
+	if (!&to_show($slot,$slots{$slot},$when,
+		      $env{'form.deleted'},$name_filter)) { next; }
 	if (defined($slots{$slot}->{'type'})
 	    && $slots{$slot}->{'type'} ne 'schedulable_student') {
 	    #next;
@@ -876,7 +1014,9 @@
 					       "^$slot\0");
 	    my ($tmp)=%consumed;
 	    if ($tmp !~ /^error: /) {
-		foreach my $entry (sort(keys(%consumed))) {
+		foreach my $entry (sort { $consumed{$a}{name} cmp 
+					      $consumed{$b}{name} }
+				   (keys(%consumed))) {
 		    my (undef,$id)=split("\0",$entry);
 		    my ($uname,$udom) = split('@',$consumed{$entry}{'name'});
 		    $ids.= '<nobr>';
@@ -943,9 +1083,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>");
 	}
@@ -1264,7 +1410,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') {

--albertel1143693443--