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

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 21 May 2002 02:29:23 -0000


This is a MIME encoded message

--albertel1021948163
Content-Type: text/plain

albertel		Mon May 20 22:29:23 2002 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  - work on csv upload of grades (BUG#42)
  - BROKEN (can't assign anything yet, needs a a javascript "verify" function)
  
  
--albertel1021948163
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20020520222923.txt"

Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.25 loncom/homework/grades.pm:1.26
--- loncom/homework/grades.pm:1.25	Wed May 15 20:01:09 2002
+++ loncom/homework/grades.pm	Mon May 20 22:29:22 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.25 2002/05/16 00:01:09 albertel Exp $
+# $Id: grades.pm,v 1.26 2002/05/21 02:29:22 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -322,17 +322,49 @@
   return $result;
 }
 
-sub viewgrades {
-  my ($request) = @_;
-  my $result='';
-
-  #get resource reference
+sub get_symb_and_url {
+ my ($request) = @_;
   my $url=$ENV{'form.url'};
   $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
   my $symb=$ENV{'form.symb'};
   if (!$symb) { $symb=&Apache::lonnet::symbread($url); }
   if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
+ return ($symb,$url);
+}
 
+sub gradingmenu {
+  my ($request) = @_;
+  my ($symb,$url)=&get_symb_and_url($request);
+  if (!$symb) {return '';}
+  my $result='<h2>Select a grading method</h2><br />';
+  $result.='<form action="/adm/grades" method="post">'."\n".
+     '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
+      '<input type="hidden" name="url" value="'.$url.'" />'."\n".
+	'<input type="hidden" name="command" value="viewgrades" />'."\n".
+	  '<input type="submit" name="submit" value="View/Edit Entire Class" />'."\n".
+	    '</form>';
+  $result.='<form action="/adm/grades" method="post">'."\n".
+     '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
+      '<input type="hidden" name="url" value="'.$url.'" />'."\n".
+	'<input type="hidden" name="command" value="csvupload" />'."\n".
+	  '<input type="submit" name="submit" value="Upload Scores" />'."\n".
+	    '</form>';
+  $result.='<form action="/adm/grades" method="post">'."\n".
+     '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
+      '<input type="hidden" name="url" value="'.$url.'" />'."\n".
+	'<input type="hidden" name="command" value="submission" />'."\n".
+	  '<input type="submit" name="submit" value="View/Edit Student" />'."\n".
+	    '</form>';
+  return $result;
+}
+
+sub viewgrades {
+  my ($request) = @_;
+  my $result='';
+
+  #get resource reference
+  my ($symb,$url)=&get_symb_and_url($request);
+  if (!$symb) {return '';}
   #get classlist
   my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
   #print "Found $cdom:$cnum<br />";
@@ -398,6 +430,125 @@
   return $result;
 }
 
+sub csvupload {
+  my ($request)= @_;
+  my $result;
+  my ($symb,$url)=&get_symb_and_url($request);
+  if (!$symb) {return '';}
+  my $upfile_select=&Apache::loncommon::upfile_select_html();
+  $result.=<<ENDUPFORM;
+<form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
+<input type="hidden" name="symb" value="$symb" />
+<input type="hidden" name="url" value="$url" />
+<input type="hidden" name="command" value="csvuploadmap" />
+<hr />
+<h3>Specify a file containing the class grades for resource $url</h3>
+$upfile_select
+<p><input type="submit" name="submit" value="Upload Grades" />
+ENDUPFORM
+  return $result;
+}
+
+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();
+  } else {
+#    $javascript=&csv_upload_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>
+<hr>
+<h3>Identify fields</h3>
+Total number of records found in file: $distotal <hr />
+Enter as many fields as you can. The system will inform you and bring you back
+to this page if the data selected is insufficient to run your class.<hr />
+<input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
+<input type="hidden" name="associate"  value="" />
+<input type="hidden" name="phase"      value="three" />
+<input type="hidden" name="datatoken"  value="$datatoken" />
+<input type="hidden" name="fileupload" value="$ENV{'form.fileupload'}" />
+<input type="hidden" name="upfiletype" value="$ENV{'form.upfiletype'}" />
+<input type="hidden" name="upfile_associate" 
+                                       value="$ENV{'form.upfile_associate'}" />
+<input type="hidden" name="symb"       value="$symb" />
+<input type="hidden" name="url"        value="$url" />
+<input type="hidden" name="command"    value="csvuploadassign" />
+<hr />
+<script type="text/javascript" language="Javascript">
+$javascript
+$javascript_validations
+</script>
+ENDPICK
+  return '';
+
+}
+
+sub csvupload_fields {
+  my ($url) = @_;
+  my (@parts) = &getpartlist($url);
+  my @fields;
+  foreach my $part (@parts) {
+    my @datum;
+    my $display=&Apache::lonnet::metadata($url,$part.'.display');
+    my $name=&Apache::lonnet::metadata($url,$part.'.name');
+    if  (!$display) { $display = $name; }
+    @datum=($name,$display);
+    push(@fields,\@datum);
+  }
+  return (@fields);
+}
+
+sub csvuploadmap_footer {
+  my ($request,$i,$keyfields) =@_;
+  $request->print(<<ENDPICK);
+</table>
+<input type="hidden" name="nfields" value="$i" />
+<input type="hidden" name="keyfields" value="$keyfields" />
+<input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
+</form>
+ENDPICK
+}
+
+sub csvuploadmap {
+  my ($request)= @_;
+  my ($symb,$url)=&get_symb_and_url($request);
+  if (!$symb) {return '';}
+  my $datatoken;
+  if (!$ENV{'form.datatoken'}) {
+    $datatoken=&Apache::loncommon::upfile_store($request);
+  } else {
+    $datatoken=$ENV{'form.datatoken'};
+    &Apache::loncommon::load_tmp_file($request);
+  }
+  my @records=&Apache::loncommon::upfile_record_sep();
+  &csvuploadmap_header($request,$symb,$url,$datatoken,$#records+1);
+  my $i;
+  my $keyfields;
+  if (@records) {
+    my @fields=&csvupload_fields($url);
+    if ($ENV{'form.upfile_associate'} eq 'reverse') {	
+      &Apache::loncommon::csv_print_samples($request,\@records);
+      $i=&Apache::loncommon::csv_print_select_table($request,\@records,
+						    \@fields);
+      foreach (@fields) { $keyfields.=$_->[0].','; }
+      chop($keyfields);
+    } else {
+      unshift(@fields,['none','']);
+      $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
+						      \@fields);
+      my %sone=&Apache::loncommon::record_sep($records[0]);
+      $keyfields=join(',',sort(keys(%sone)));
+    }
+  }
+  &csvuploadmap_footer($request,$i,$keyfields);
+  return '';
+}
+
 sub send_header {
   my ($request)= @_;
   $request->print(&Apache::lontexconvert::header());
@@ -465,16 +616,34 @@
          }
      }
   } else {
+    &Apache::lonhomework::showhashsubset(\%ENV,'^form');
     $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
     if ($command eq 'submission') {
       &listStudents($request) if ($ENV{'form.student'} eq '');
       $request->print(&submission($request)) if ($ENV{'form.student'} ne '');
+    } elsif ($command eq 'gradingmenu') {
+      $request->print(&gradingmenu($request));
     } elsif ($command eq 'viewgrades') {
       $request->print(&viewgrades($request));
     } elsif ($command eq 'editgrades') {
       $request->print(&editgrades($request));
     } elsif ($command eq 'verify') {
       $request->print(&verifyreceipt($request));
+    } elsif ($command eq 'csvupload') {
+      $request->print(&csvupload($request));
+    } elsif ($command eq 'csvuploadmap') {
+      $request->print(&csvuploadmap($request));
+    } elsif ($command eq 'csvuploadassign') {
+      if ($ENV{'form.associate'} ne 'Reverse Association') {
+	$request->print(&csvuploadassign($request));
+      } else {
+	if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
+	  $ENV{'form.upfile_associate'} = 'reverse';
+	} else {
+	  $ENV{'form.upfile_associate'} = 'forward';
+	}
+	$request->print(&csvuploadmap($request));
+      }
     } else {
       $request->print("Unknown action: $command:");
     }

--albertel1021948163--