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

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 18 Nov 2005 16:26:57 -0000


albertel		Fri Nov 18 11:26:57 2005 EDT

  Modified files:              
    /loncom/interface	slotrequest.pm 
    /loncom/html/adm/helper	newslot.helper 
  Log:
  - don't allow user to create bad slots
  
  
Index: loncom/interface/slotrequest.pm
diff -u loncom/interface/slotrequest.pm:1.30 loncom/interface/slotrequest.pm:1.31
--- loncom/interface/slotrequest.pm:1.30	Mon Nov 14 18:21:55 2005
+++ loncom/interface/slotrequest.pm	Fri Nov 18 11:26:47 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.30 2005/11/14 23:21:55 albertel Exp $
+# $Id: slotrequest.pm,v 1.31 2005/11/18 16:26:47 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -658,6 +658,9 @@
   <input type="submit" name="Edit" value="Edit" />
 </form>
 EDITFORM
+	my $edit=(<<EDITLINK);
+<a href="/adm/helper/newslot.helper?name=$slot">Edit</a>
+EDITLINK
  
         $r->print("<tr>\n<td rowspan=\"$rowspan\">$edit</td>\n");
 	if (exists($show{'name'})) {
@@ -887,16 +890,34 @@
     my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
     my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
     my $countdone=0;
+    my @errors;
     foreach my $slot (@slotdata) {
 	my %slot;
 	my %entries=&Apache::loncommon::record_sep($slot);
 	my $domain;
 	my $name=$entries{$fields{'name'}};
+	if ($name=~/^\s*$/) {
+	    push(@errors,"Did not create slot with no name");
+	    next;
+	}
+	if ($name=~/\s/) { 
+	    push(@errors,"$name not created -- Name must not contain spaces");
+	    next;
+	}
+	if ($name=~/\W/) { 
+	    push(@errors,"$name not created -- Name must contain only letters, numbers and _");
+	    next;
+	}
 	if ($entries{$fields{'type'}}) {
 	    $slot{'type'}=$entries{$fields{'type'}};
 	} else {
 	    $slot{'type'}='preassigned';
 	}
+	if ($slot{'type'} ne 'preassigned' &&
+	    $slot{'type'} ne 'schedulable_student') {
+	    push(@errors,"$name not created -- invalid type ($slot{'type'}) must be either preassigned or schedulable_student");
+	    next;
+	}
 	if ($entries{$fields{'starttime'}}) {
 	    $slot{'starttime'}=&UnixDate($entries{$fields{'starttime'}},"%s");
 	}
@@ -925,8 +946,10 @@
 	$r->rflush();
 	$countdone++;
     }
-    $r->print("<br />Created $countdone slots\n");
-    $r->print("<br />\n");
+    $r->print("<p>Created $countdone slots\n</p>");
+    foreach my $error (@errors) {
+	$r->print("<p>$error\n</p>");
+    }
     &show_table($r,$mgr);
     return '';
 }
Index: loncom/html/adm/helper/newslot.helper
diff -u loncom/html/adm/helper/newslot.helper:1.8 loncom/html/adm/helper/newslot.helper:1.9
--- loncom/html/adm/helper/newslot.helper:1.8	Wed Nov  2 17:14:53 2005
+++ loncom/html/adm/helper/newslot.helper	Fri Nov 18 11:26:57 2005
@@ -32,7 +32,8 @@
     <string variable="name" size="30">
       <validator>
           if ($val=~/^\s*$/) { return 'Must specify a name'; }
-          if ($val=~/\s$/) { return 'Must not contain spaces'; }
+          if ($val=~/\s/) { return 'Must not contain spaces'; }
+          if ($val=~/\W/) { return 'Must contain only letters, numbers and _'; }
           return undef;
       </validator>
       <defaultvalue>