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

albertel lon-capa-cvs@mail.lon-capa.org
Mon, 21 Nov 2005 19:50:36 -0000


albertel		Mon Nov 21 14:50:36 2005 EDT

  Modified files:              
    /loncom/interface	slotrequest.pm 
  Log:
  - mark a slot as deleted
  
  
  
Index: loncom/interface/slotrequest.pm
diff -u loncom/interface/slotrequest.pm:1.33 loncom/interface/slotrequest.pm:1.34
--- loncom/interface/slotrequest.pm:1.33	Mon Nov 21 13:55:41 2005
+++ loncom/interface/slotrequest.pm	Mon Nov 21 14:50:36 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.33 2005/11/21 18:55:41 albertel Exp $
+# $Id: slotrequest.pm,v 1.34 2005/11/21 19:50:36 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -316,6 +316,38 @@
     return 1;
 }
 
+sub delete_slot {
+    my ($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 (%slot && !%consumed) {
+	$slot{'type'} = 'deleted';
+	my $ret = &Apache::lonnet::cput('slots', {$slot_name => \%slot},
+					$cdom, $cnum);
+	if ($ret eq 'ok') {
+	    $r->print("<p>Slot <tt>$slot_name</tt> marked as deleted.</p>");
+	} else {
+	    $r->print("<p> An error ($ret) occurse when attempting to delete Slot <tt>$slot_name</tt>.</p>");
+	}
+    } else {
+	if (%consumed) {
+	    $r->print("<p>Slot <tt>$slot_name</tt> has active reservations.</p>");
+	} else {
+	    $r->print("<p>Slot <tt>$slot_name</tt> does not exist.</p>");
+	}
+    }
+    $r->print('<p><a href="/adm/slotrequest?command=showslots">'.
+	      &mt('Return to slot list').'</a></p>');
+    $r->print('<p><a href="/adm/flip?postdata=return:">'.
+	      &mt('Return to last resource').'</a></p>');
+}
+
 sub get_slot {
     my ($r,$symb)=@_;
 
@@ -718,11 +750,16 @@
 	}
 	my $proctors=join(', ',@proctors);
 
-	my $edit=(<<EDITLINK);
+	my $edit=(<<"EDITLINK");
 <a href="/adm/helper/newslot.helper?name=$slot">Edit</a>
 EDITLINK
- 
-        $r->print("<tr>\n<td rowspan=\"$rowspan\">$edit</td>\n");
+
+	my $delete=(<<"DELETELINK");
+<a href="/adm/slotrequest?command=delete&slotname=$slot">Delete</a>
+DELETELINK
+        if ($ids ne '') { undef($delete); }
+
+        $r->print("<tr>\n<td rowspan=\"$rowspan\">$edit $delete</td>\n");
 	if (exists($show{'name'})) {
 	    $colspan++;$r->print("<td>$slot</td>");
 	}
@@ -1040,6 +1077,8 @@
 	&remove_registration($r);
     } elsif ($env{'form.command'} eq 'release' && $mgr eq 'F') {
 	&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') {
 	&upload_start($r);
     } elsif ($env{'form.command'} eq 'csvuploadmap' && $mgr eq 'F') {