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

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 14 May 2004 21:30:27 -0000


albertel		Fri May 14 17:30:27 2004 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  - can now download scantron records
  
  
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.201 loncom/homework/grades.pm:1.202
--- loncom/homework/grades.pm:1.201	Fri May 14 16:26:22 2004
+++ loncom/homework/grades.pm	Fri May 14 17:30:27 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.201 2004/05/14 20:26:22 albertel Exp $
+# $Id: grades.pm,v 1.202 2004/05/14 21:30:27 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3420,18 +3420,25 @@
     return $result;
 }
 
-sub scantron_uploads {
-    if (!-e $Apache::lonnet::perlvar{'lonScansDir'}) { return ''};
-    my $result=	'<select name="scantron_selectfile">';
+sub scantron_filenames {
     my $cdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
     my $cname=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
     my @files=&Apache::lonnet::dirlist('userfiles',$cdom,$cname,
 				    &Apache::loncommon::propath($cdom,$cname));
-    $result.="<option></option>";
+    my @possiblenames;
     foreach my $filename (sort(@files)) {
 	($filename)=split(/&/,$filename);
 	if ($filename!~/^scantron_orig_/) { next ; }
 	$filename=~s/^scantron_orig_//;
+	push(@possiblenames,$filename);
+    }
+    return @possiblenames;
+}
+
+sub scantron_uploads {
+    my $result=	'<select name="scantron_selectfile">';
+    $result.="<option></option>";
+    foreach my $filename (sort(&scantron_filenames())) {
 	$result.="<option>$filename</option>\n";
     }
     $result.="</select>";
@@ -3602,18 +3609,8 @@
               <td> Filename of scoring office file: </td><td> $file_selector </td>
             </tr>
             <tr bgcolor="#ffffe6">
-	      <td>
-                Records to download
-              </td>
-              <td>
-                  <input type="radio" name="scantron_options" value="download_skipped"/> Skipped Records <br />
-                  <input type="radio" name="scantron_options" value="download_corrected"/> Corrected Records <br />
-                  <input checked="on" type="radio" name="scantron_options" value="dowload_orig"/> Original Records
-              </td>
-            </tr>
-            <tr bgcolor="#ffffe6">
               <td colspan="2">
-                <input type="submit" value="Validate Scantron Records" />
+                <input type="submit" value="Show List of Files" />
               </td>
             </tr>
           </table>
@@ -4673,6 +4670,50 @@
     return '';
 }
 
+sub valid_file {
+    my ($requested_file)=@_;
+    foreach my $filename (sort(&scantron_filenames())) {
+	&Apache::lonnet::logthis("$requested_file  $filename");
+	if ($requested_file eq $filename) { return 1; }
+    }
+    return 0;
+}
+
+sub scantron_download_scantron_data {
+    my ($r)=@_;
+    my $default_form_data=&defaultFormData(&get_symb_and_url($r,1));
+    my $cname=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
+    my $cdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
+    my $file=$ENV{'form.scantron_selectfile'};
+    if (! &valid_file($file)) {
+	$r->print(<<ERROR);
+	<p>
+	    The requested file name was invalid.
+        </p>
+ERROR
+	$r->print(&show_grading_menu_form(&get_symb_and_url($r,1)));
+	return;
+    }
+    my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
+    my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
+    my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
+    &Apache::lonnet::allowuploaded('/adm/grades',$orig);
+    &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
+    &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
+    $r->print(<<DOWNLOAD);
+    <p>
+	<a href="$orig">Original</a> file as uploaded by the scantron office.
+    </p>
+    <p>
+	<a href="$corrected">Corrections</a>, a file of corrected records that were used in grading.
+    </p>
+    <p>
+	<a href="$skipped">Skipped</a>, a file of records that were skipped.
+    </p>
+DOWNLOAD
+    $r->print(&show_grading_menu_form(&get_symb_and_url($r,1)));
+    return '';
+}
 
 #-------- end of section for handling grading scantron forms -------
 #
@@ -4964,7 +5005,7 @@
  		 (&Apache::lonnet::allowed('usc',$ENV{'request.role.domain'})||
 		  &Apache::lonnet::allowed('usc',$ENV{'request.course.id'}))) {
  	    $request->print(&scantron_upload_scantron_data_save($request));
- 	} elsif ($command eq 'scantrondownload' &&
+ 	} elsif ($command eq 'scantron_download' &&
 		 &Apache::lonnet::allowed('usc',$ENV{'request.course.id'})) {
  	    $request->print(&scantron_download_scantron_data($request));
 	} elsif ($command) {