[LON-CAPA-cvs] cvs: loncom /html/adm/helper newslot.helper /interface slotrequest.pm

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 07 Mar 2006 16:15:59 -0000


This is a MIME encoded message

--albertel1141748159
Content-Type: text/plain

albertel		Tue Mar  7 11:15:59 2006 EDT

  Modified files:              
    /loncom/interface	slotrequest.pm 
    /loncom/html/adm/helper	newslot.helper 
  Log:
  - adding allowedsections and allowed users restrictions to slot specifications
  
  
--albertel1141748159
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20060307111559.txt"

Index: loncom/interface/slotrequest.pm
diff -u loncom/interface/slotrequest.pm:1.48 loncom/interface/slotrequest.pm:1.49
--- loncom/interface/slotrequest.pm:1.48	Sun Feb 26 14:40:14 2006
+++ loncom/interface/slotrequest.pm	Tue Mar  7 11:15:48 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 2006/02/26 19:40:14 albertel Exp $
+# $Id: slotrequest.pm,v 1.49 2006/03/07 16:15:48 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -529,23 +529,41 @@
 
 sub allowed_slot {
     my ($slot_name,$slot,$symb,$slots,$consumed_uniqueperiods)=@_;
+
     #already started
     if ($slot->{'starttime'} < time) {
 	# 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");
+
+    # its for a different set of users
+    if (defined($slot->{'allowedsection'})) {
+	
+	return 0;
+    }
+    &Apache::lonxml::debug("$slot_name type good");
+
+    # its for a different set of users
+    if (defined($slot->{'allowedusers'})) {
+	
+	return 0;
+    }
+    &Apache::lonxml::debug("$slot_name type good");
+
     # not allowed for this resource
     if (defined($slot->{'symb'})
 	&& $slot->{'symb'} ne $symb) {
@@ -738,22 +756,25 @@
     &Apache::grades::reset_perm();
 
     my %show_fields=&Apache::lonlocal::texthash(
-	     'name'         => 'Slot Name',
-	     'description'  => 'Description',
-	     'type'         => 'Type',
-	     'starttime'    => 'Start time',
-	     'endtime'      => 'End Time',
-             'startreserve' => 'Time students can start reserving',
-	     'secret'       => 'Secret Word',
-	     'maxspace'     => 'Maximum # of students',
-	     'ip'           => 'IP or DNS restrictions',
-	     'symb'         => 'Resource slot is restricted to.',
-	     'uniqueperiod' => 'Period of time slot is unique',
-	     'scheduled'    => 'Scheduled Students',
-	     'proctor'      => 'List of proctors');
+	     'name'            => 'Slot Name',
+	     'description'     => 'Description',
+	     'type'            => 'Type',
+	     'starttime'       => 'Start time',
+	     'endtime'         => 'End Time',
+             'startreserve'    => 'Time students can start reserving',
+	     'secret'          => 'Secret Word',
+	     'maxspace'        => 'Maximum # of students',
+	     'ip'              => 'IP or DNS restrictions',
+	     'symb'            => 'Resource slot is restricted to.',
+	     'allowedsections' => 'Sections slot is restricted to.',
+	     'allowedusers'    => 'Users slot is restricted to.',
+	     'uniqueperiod'    => 'Period of time slot is unique',
+	     'scheduled'       => 'Scheduled Students',
+	     'proctor'         => 'List of proctors');
     my @show_order=('name','description','type','starttime','endtime',
-	       'startreserve','secret','maxspace','ip','symb',
-	       'uniqueperiod','scheduled','proctor');
+		    'startreserve','secret','maxspace','ip','symb',
+		    'allowedsections','allowedusers','uniqueperiod',
+		    'scheduled','proctor');
     my @show = 
 	(exists($env{'form.show'})) ? &Apache::loncommon::get_env_multiple('form.show')
 	                            : keys(%show_fields);
@@ -832,7 +853,7 @@
 
     my %name_cache;
     my $slotsort = sub {
-	if ($env{'form.order'}=~/^(type|description|endtime|startreserve|maxspace|ip|symb)$/) {
+	if ($env{'form.order'}=~/^(type|description|endtime|startreserve|maxspace|ip|symb|allowedsections|allowedusers)$/) {
 	    if (lc($slots{$a}->{$env{'form.order'}})
 		ne lc($slots{$b}->{$env{'form.order'}})) {
 		return (lc($slots{$a}->{$env{'form.order'}}) 
@@ -911,6 +932,28 @@
 	    $title='<a href="'.$res.'?symb='.$slots{$slot}{'symb'}.'">'.$title.'</a>';
 	}
 
+	my $allowedsections;
+	if (exists($show{'allowedsections'})) {
+	    $allowedsections = 
+		join(', ',sort(split(/\s*,\s*/,
+				     $slots{$slot}->{'allowedsections'})));
+	}
+
+	my @allowedusers;
+	if (exists($show{'allowedusers'})) {
+	    @allowedusers= map {
+		my ($uname,$udom)=split(/:/,$_);
+		my $fullname=$name_cache{$_};
+		if (!defined($fullname)) {
+		    $fullname = &Apache::loncommon::plainname($uname,$udom);
+		    $fullname =~s/\s/&nbsp;/g;
+		    $name_cache{$_} = $fullname;
+		}
+		&Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
+	    } (sort(split(/\s*,\s*/,$slots{$slot}->{'allowedusers'})));
+	}
+	my $allowedusers=join(', ',@allowedusers);
+	
 	my @proctors;
 	my $rowspan=1;
 	my $colspan=1;
@@ -920,7 +963,6 @@
 		my ($uname,$udom)=split(/@/,$_);
 		my $fullname=$name_cache{$_};
 		if (!defined($fullname)) {
-		    &Apache::lonnet::logthis("Gettign $uname $udom");
 		    $fullname = &Apache::loncommon::plainname($uname,$udom);
 		    $fullname =~s/\s/&nbsp;/g;
 		    $name_cache{$_} = $fullname;
@@ -970,8 +1012,11 @@
 	if (exists($show{'symb'})) {
 	    $colspan++;$r->print("<td>$title</td>\n");
 	}
-	if (exists($show{'uniqueperiod'})) {
-	    $colspan++;$r->print("<td>$unique</td>\n");
+	if (exists($show{'allowedsections'})) {
+	    $colspan++;$r->print("<td>$allowedsections</td>\n");
+	}
+	if (exists($show{'allowedusers'})) {
+	    $colspan++;$r->print("<td>$allowedusers</td>\n");
 	}
 	if (exists($show{'scheduled'})) {
 	    $colspan++;$r->print("<td>$ids</td>\n</tr>\n");
@@ -1156,7 +1201,10 @@
 	    ['maxspace','Maximum number of reservations'],
 	    ['symb','Resource Restriction'],
 	    ['uniqueperiod','Date range of slot exclusion'],
-	    ['secret','Secret word proctor uses to validate']);
+	    ['secret','Secret word proctor uses to validate'],
+	    ['allowedsections','Sections slot is restricted to'],
+	    ['allowedusers','Users slot is restricted to'],
+	    );
 }
 
 sub csv_upload_assign {
Index: loncom/html/adm/helper/newslot.helper
diff -u loncom/html/adm/helper/newslot.helper:1.12 loncom/html/adm/helper/newslot.helper:1.13
--- loncom/html/adm/helper/newslot.helper:1.12	Fri Feb  3 17:40:46 2006
+++ loncom/html/adm/helper/newslot.helper	Tue Mar  7 11:15:55 2006
@@ -1,5 +1,8 @@
 <helper title="Slot Creation" requiredpriv="mgq">
   <state name="START" title="Specify Required Attributes">
+
+    <nextstate>OPTIONAL</nextstate>
+
     <exec>
       if (!exists($helper->{'VARS'}{'name'}) ||
 	  $helper->{'VARS'}{'name'} !~ /\S/) {
@@ -26,7 +29,7 @@
 	  return $slot{$name}{$which};
       }
     </exec>
-    <message nextstate="OPTIONAL">
+    <message>
         Name: <br />&nbsp;&nbsp;&nbsp;
     </message>
     <string variable="name" size="30">
@@ -42,7 +45,7 @@
     </string>
     <condition>
       <clause>$helper->{DATA}{copy}</clause>
-      <message nextstate="OPTIONAL">
+      <message>
 	<p>Changing the Name will create a new slot with the new name, and not rename the existing slot.</p>
       </message>
     </condition>
@@ -74,6 +77,7 @@
     </choices>
   </state>
 
+
   <state name="OPTIONAL" title="Specify Optional Attributes">
     <message>
         <p>Description:<br />&nbsp;&nbsp;&nbsp;
@@ -159,9 +163,7 @@
       </defaultvalue>
     </choices>
     <message>
-       
-	</p><p>IP restrictions:<br />&nbsp;&nbsp;&nbsp;
-      
+	</p><p>IP restrictions:<br />&nbsp;&nbsp;&nbsp;      
     </message>
     <string variable="ip" size="30">
       <validator>
@@ -173,19 +175,33 @@
     </string>
     <message>  </p>  </message>
   </state>
+
+
   <state name="RESOURCESELECT" title="Specify Optional Attributes">
+
+    <nextstate>PROCTOR</nextstate>
+
     <resource variable="symb">
       <filterfunc>return $res->is_problem()</filterfunc>
       <valuefunc>return $res->symb()</valuefunc>
-      <nextstate>PROCTOR</nextstate>
       <defaultvalue>
         return &{$helper->{DATA}{origslot}}('symb');
       </defaultvalue>
     </resource>    
   </state>
+
+
   <state name="PROCTOR" title="Specify Proctors">
+
+    <nextstate>FINISH</nextstate>
+
+    <condition>
+       <clause>$helper->{'VARS'}{'type'} eq 'schedulable_student'</clause>
+       <nextstate>RESTRICTUSER</nextstate>
+    </condition>
+
     <student variable="proctor" multichoice="1" coursepersonnel="1"
-             nextstate="FINISH" activeonly="1" emptyallowed="1">
+             activeonly="1" emptyallowed="1">
       <defaultvalue>
         my @defaults;
         my $default=&{$helper->{DATA}{origslot}}('proctor');
@@ -197,6 +213,35 @@
       </defaultvalue>
     </student>
   </state>
+
+
+  <state name="RESTRICTUSER" title="Restrict slot availability">
+    <nextstate>FINISH</nextstate>
+    <message>
+      <p>Slots are by default available to all users in a course, if you would like this slot to be restricted to a subset of users you can specify restrictions.</p>
+    </message>
+
+    <message>
+      Select sections to limit slot availability to: <br />&nbsp;&nbsp;&nbsp;
+    </message>
+    <section variable="allowedsections" multichoice="1" allowempty="1">
+      <defaultvalue>
+        return join('|||',
+		    split(',',&{$helper->{DATA}{origslot}}('allowedsections')));
+      </defaultvalue>
+    </section>
+    <message>
+      Select users to limit slot availability to: <br />&nbsp;&nbsp;&nbsp;
+    </message>
+    <student variable="allowedusers" multichoice="1" coursepersonnel="1"
+             activeonly="1" emptyallowed="1">
+      <defaultvalue>
+	 return split(',',&{$helper->{DATA}{origslot}}('allowedusers'));
+      </defaultvalue>
+    </student>
+  </state>
+
+
   <state name="FINISH" title="Creating/Modfying Slot">
 	    <message> Created Slot  </message>	
     <final>
@@ -204,23 +249,27 @@
         my $result;
 	if ($helper->{'STATE'} ne 'FINISH') { return; }
 	my %slot;
+
 	foreach my $which ('type','starttime','endtime') {
 	    $slot{$which} = $helper->{'VARS'}{$which};
 	}
-	foreach my $which ('ip','description','maxspace',
-			   'secret','symb') {
+
+	foreach my $which ('ip','description','maxspace','secret','symb') {
 	    if ( $helper->{'VARS'}{$which} =~/\S/ ) {
 		$slot{$which} = $helper->{'VARS'}{$which};
 	    }
 	}
+
 	if ( $helper->{'VARS'}{'startreserve'} > 0) {
 		$slot{'startreserve'} = $helper->{'VARS'}{'startreserve'};
 	}
+
 	if ( $helper->{'VARS'}{'startunique'} > 0 &&
 	     $helper->{'VARS'}{'endunique'} > 0 ) {
 	    $slot{'uniqueperiod'} = [$helper->{'VARS'}{'startunique'},
 				     $helper->{'VARS'}{'endunique'}];
 	}
+
         if ( $helper->{'VARS'}{'proctor'} =~/\S/ ) {
 	    my @names;
 	    foreach my $user (split(/\|\|\|/, $helper->{'VARS'}{'proctor'})) {
@@ -231,6 +280,33 @@
 	    my %proctors = map { ($_,1) } @names;
 	    $slot{'proctor'}=join(',',sort(keys(%proctors)));
 	}
+
+	if ( $helper->{'VARS'}{'allowedsections'} !~/\S/ );
+
+	    my @names;
+	    foreach my $item (split(/\|\|\|/, $helper->{'VARS'}{'allowedsections'})) {
+		my ($uname,$udomain)=split(/:/,$item);
+		push(@names,"$uname:$udomain");
+	    }
+
+	    # make sure the choices are unique
+	    my %proctors = map { ($_,1) } @names;
+	    $slot{'allowedsections'}=join(',',sort(keys(%proctors)));
+	}
+
+        if ( $helper->{'VARS'}{$which} !~/\S/ );
+
+	    my @names;
+	    foreach my $item (split(/\|\|\|/, $helper->{'VARS'}{$which})) {
+		my ($uname,$udomain)=split(/:/,$item);
+		push(@names,"$uname:$udomain");
+	    }
+
+	    # make sure the choices are unique
+	    my %proctors = map { ($_,1) } @names;
+	    $slot{$which}=join(',',sort(keys(%proctors)));
+	}
+
         my $cname = $env{'course.'.$env{'request.course.id'}.'.num'};
         my $cdom  = $env{'course.'.$env{'request.course.id'}.'.domain'};
 
@@ -243,7 +319,8 @@
                  "\n".'<li> Type: '.$slot{'type'}.'</li>';
         my %labels =
              map {($_->[0],$_->[1])} &Apache::slotrequest::csvupload_fields();
-        foreach my $which ('ip','description','maxspace','secret','symb') {
+        foreach my $which ('ip','description','maxspace','secret','symb',
+			   'allowedsections','allowedusers') {
 	    if (exists($slot{$which})) {
 		$result.="\n".'<li> '.$labels{$which}.': '.
 		    &HTML::Entities::encode($slot{$which}).'</li>';

--albertel1141748159--