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

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 14 Oct 2003 00:05:17 -0000


albertel		Mon Oct 13 20:05:17 2003 EDT

  Modified files:              (Branch: version_1_0_2_scantron)
    /loncom/homework	grades.pm 
  Log:
  - Scantron Operator exists and is fully functional
  - starting the grading process now looks for uploaded scantron datafiles in the course directory
  
  
  
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.130.2.1.2.8 loncom/homework/grades.pm:1.130.2.1.2.9
--- loncom/homework/grades.pm:1.130.2.1.2.8	Mon Oct 13 18:36:59 2003
+++ loncom/homework/grades.pm	Mon Oct 13 20:05:16 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.130.2.1.2.8 2003/10/13 22:36:59 albertel Exp $
+# $Id: grades.pm,v 1.130.2.1.2.9 2003/10/14 00:05:16 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3146,17 +3146,18 @@
 }
 
 sub scantron_uploads {
-    #FIXME need to support scantron files put in another location,
-    # maybe the course directory? a scantron dir in the course directory?
     if (!-e $Apache::lonnet::perlvar{'lonScansDir'}) { return ''};
     my $result=	'<select name="scantron_selectfile">';
-    opendir(DIR,$Apache::lonnet::perlvar{'lonScansDir'});
-    my @files=sort(readdir(DIR));
+    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::loncreatecourse::propath($cdom,$cname));
     foreach my $filename (@files) {
-	if ($filename eq '.' or $filename eq '..') { next; }
+	($filename)=split(/&/,$filename);
+	if ($filename!~/^scantron_orig_/) { next ; }
+	$filename=~s/^scantron_orig_//;
 	$result.="<option>$filename</option>\n";
     }
-    closedir(DIR);
     $result.="</select>";
     return $result;
 }
@@ -3921,14 +3922,47 @@
 sub scantron_upload_scantron_data {
     my ($r)=@_;
     $r->print(&Apache::loncommon::coursebrowser_javascript($ENV{'request.role.domain'}));
-    $r->print(&Apache::loncommon::selectcourse_link('rules',
-			  'courseid','domain'));
-    $r->print("Course: <input name='courseid' type='text'/>");
-    $r->print("Domain: <input name='domain' type='text'/>");
+    my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
+							  'domainid');
+    my $domsel=&Apache::loncommon::select_dom_form($ENV{'request.role.domain'},
+						   'domainid');
+    $r->print(<<UPLOAD);
+<script type="text/javascript" language="javascript">
+    function checkUpload(formname) {
+	if (formname.upfile.value == "") {
+	    alert("Please use the browse button to select a file from your local directory.");
+	    return false;
+	}
+	formname.submit();
+    }
+</script>
 
+<form enctype='multipart/form-data' action='/adm/grades' name='rules' method='post'>
+Course: <input name='courseid' type='text' />
+Domain: $domsel $select_link
+<br />
+<input name='command' value='scantronupload_save' type='hidden' />
+File to upload:<input type="file" name="upfile" size="50" />
+<br />
+<input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scantron Data" />
+</form>
+UPLOAD
     return '';
+}
 
+sub scantron_upload_scantron_data_save {
+    my($r)=@_;
+    $r->print("Doing upload to ".$ENV{'form.courseid'});
+    my $home=&Apache::lonnet::homeserver($ENV{'form.courseid'},
+					 $ENV{'form.domainid'});
+    my $fname='scantron_orig_'.$ENV{'form.upfile.filename'};
+    $r->print(&Apache::lonnet::finishuserfileupload($ENV{'form.courseid'},
+						    $ENV{'form.domainid'},
+						    $home,'upfile',$fname));
+    return '';
 }
+
+
 #-------- end of section for handling grading scantron forms -------
 #
 #-------------------------------------------------------------------
@@ -4115,7 +4149,7 @@
 	$url = $ENV{'form.url'};
     }
     &send_header($request);
-    if ($url eq '' && $symb eq '') {
+    if ($url eq '' && $symb eq '' && $command eq '') {
 	if ($ENV{'user.adv'}) {
 	    if (($ENV{'form.codeone'}) && ($ENV{'form.codetwo'}) &&
 		($ENV{'form.codethree'})) {
@@ -4199,8 +4233,13 @@
 	    $request->print(&scantron_validate_file($request));
 	} elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
 	    $request->print(&scantron_process_students($request));
-	} elsif ($command eq 'scantronupload' && &Apache::lonnet::allowed('usc',$ENV{'request.role.domain'})) {
+	} elsif ($command eq 'scantronupload' && 
+		 &Apache::lonnet::allowed('usc',$ENV{'request.role.domain'})) {
 	    $request->print(&scantron_upload_scantron_data($request));
+
+	} elsif ($command eq 'scantronupload_save' &&
+		 &Apache::lonnet::allowed('usc',$ENV{'request.role.domain'})) {
+	    $request->print(&scantron_upload_scantron_data_save($request));
 	} elsif ($command) {
 	    $request->print("Access Denied");
 	}