[LON-CAPA-cvs] cvs: loncom /homework grades.pm

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 24 May 2002 21:45:22 -0000


albertel		Fri May 24 17:45:22 2002 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  - javascript works for validating a flipping field assignement
  - grade assignment started
  - BUG#42
  
  
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.26 loncom/homework/grades.pm:1.27
--- loncom/homework/grades.pm:1.26	Mon May 20 22:29:22 2002
+++ loncom/homework/grades.pm	Fri May 24 17:45:22 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.26 2002/05/21 02:29:22 albertel Exp $
+# $Id: grades.pm,v 1.27 2002/05/24 21:45:22 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -386,7 +386,7 @@
 	    '<table border=0><tr><td bgcolor="#999999">'."\n".
 	     '<table border=0>'."\n".
 	      '<tr><td bgcolor='.$headerclr.'>UserId</td><td bgcolor='.$headerclr.'>Domain</td>'."\n";
-  foreach my $part (@parts) {
+  foreach my $part (sort(@parts)) {
      my $display=&Apache::lonnet::metadata($url,$part.'.display');
      if  (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
      $result.='<td bgcolor='.$headerclr.'>'.$display.'</td>'."\n";
@@ -449,16 +449,88 @@
   return $result;
 }
 
+sub csvupload_javascript_reverse_associate {
+  return(<<ENDPICK);
+  function verify(vf) {
+    var foundsomething=0;
+    var founduname=0;
+    var founddomain=0;
+    for (i=0;i<=vf.nfields.value;i++) {
+      tw=eval('vf.f'+i+'.selectedIndex');
+      if (i==0 && tw!=0) { founduname=1; }
+      if (i==1 && tw!=0) { founddomain=1; }
+      if (i!=0 && i!=1 && tw!=0) { foundsomething=1; }
+    }
+    if (founduname==0 || founddomain==0) {
+      alert('You need to specify at both the username and domain');
+      return;
+    }
+    if (foundsomething==0) {
+      alert('You need to specify at least one grading field');
+      return;
+    }
+    vf.submit();
+  }
+  function flip(vf,tf) {
+    var nw=eval('vf.f'+tf+'.selectedIndex');
+    var i;
+    for (i=0;i<=vf.nfields.value;i++) {
+      //can not pick the same destination field for both name and domain
+      if (((i ==0)||(i ==1)) && 
+          ((tf==0)||(tf==1)) && 
+          (i!=tf) &&
+          (eval('vf.f'+i+'.selectedIndex')==nw)) {
+        eval('vf.f'+i+'.selectedIndex=0;')
+      }
+    }
+  }
+ENDPICK
+}
+
+sub csvupload_javascript_forward_associate {
+  return(<<ENDPICK);
+  function verify(vf) {
+    var foundsomething=0;
+    var founduname=0;
+    var founddomain=0;
+    for (i=0;i<=vf.nfields.value;i++) {
+      tw=eval('vf.f'+i+'.selectedIndex');
+      if (tw==1) { founduname=1; }
+      if (tw==2) { founddomain=1; }
+      if (tw>2) { foundsomething=1; }
+    }
+    if (founduname==0 || founddomain==0) {
+      alert('You need to specify at both the username and domain');
+      return;
+    }
+    if (foundsomething==0) {
+      alert('You need to specify at least one grading field');
+      return;
+    }
+    vf.submit();
+  }
+  function flip(vf,tf) {
+    var nw=eval('vf.f'+tf+'.selectedIndex');
+    var i;
+    //can not pick the same destination field twice
+    for (i=0;i<=vf.nfields.value;i++) {
+      if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
+        eval('vf.f'+i+'.selectedIndex=0;')
+      }
+    }
+  }
+ENDPICK
+}
+
 sub csvuploadmap_header {
   my ($request,$symb,$url,$datatoken,$distotal)= @_;
   my $result;
   my $javascript;
   if ($ENV{'form.upfile_associate'} eq 'reverse') {
-#    $javascript=&csv_upload_javascript_reverse_associate();
+    $javascript=&csvupload_javascript_reverse_associate();
   } else {
-#    $javascript=&csv_upload_javascript_forward_associate();
+    $javascript=&csvupload_javascript_forward_associate();
   }
-  my $javascript_validations;#=&javascript_validations($krbdefdom);
   $request->print(<<ENDPICK);
 <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
 <h3>Uploading Class Grades for resource $url</h3>
@@ -481,7 +553,6 @@
 <hr />
 <script type="text/javascript" language="Javascript">
 $javascript
-$javascript_validations
 </script>
 ENDPICK
   return '';
@@ -491,11 +562,11 @@
 sub csvupload_fields {
   my ($url) = @_;
   my (@parts) = &getpartlist($url);
-  my @fields;
-  foreach my $part (@parts) {
+  my @fields=(['username','Student Username'],['domain','Student Domain']);
+  foreach my $part (sort(@parts)) {
     my @datum;
     my $display=&Apache::lonnet::metadata($url,$part.'.display');
-    my $name=&Apache::lonnet::metadata($url,$part.'.name');
+    my $name=$part;
     if  (!$display) { $display = $name; }
     @datum=($name,$display);
     push(@fields,\@datum);
@@ -547,6 +618,43 @@
   }
   &csvuploadmap_footer($request,$i,$keyfields);
   return '';
+}
+
+sub csvuploadassign {
+  my ($request)= @_;
+  my ($symb,$url)=&get_symb_and_url($request);
+  if (!$symb) {return '';}
+  &Apache::loncommon::load_tmp_file($request);
+  my @gradedata=&Apache::loncommon::upfile_record_sep();
+  my @keyfields = split(/\,/,$ENV{'form.keyfields'});
+  my %fields=();
+  for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
+    if ($ENV{'form.upfile_associate'} eq 'reverse') {
+      if ($ENV{'form.f'.$i} ne 'none') {
+	$fields{$keyfields[$i]}=$ENV{'form.f'.$i};
+      }
+    } else {
+      if ($ENV{'form.f'.$i} ne 'none') {
+	$fields{$ENV{'form.f'.$i}}=$keyfields[$i];
+      }
+    }
+  }
+  $request->print('<h3>Assigning Grades</h3>');
+  &Apache::lonhomework::showhash(('1'=>\@keyfields));
+  &Apache::lonhomework::showhash(%fields);
+  my $courseid=$ENV{'request.course.id'};
+  my $cdom=$ENV{"course.$courseid.domain"};
+  my $cnum=$ENV{"course.$courseid.num"};
+  my (%classlist) = &getclasslist($cdom,$cnum,'1');
+  foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
+    my %newhash;
+    foreach my $grade (@gradedata) {
+      my %entries=&Apache::loncommon::record_sep($grade);
+      foreach my $dest (keys(%fields)) {
+	
+      }
+    }
+  }
 }
 
 sub send_header {