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

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 25 Nov 2003 21:44:45 -0000


albertel		Tue Nov 25 16:44:45 2003 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  - allow CC to upload scantron data
  - fix a typo 
  
  
  
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.161 loncom/homework/grades.pm:1.162
--- loncom/homework/grades.pm:1.161	Fri Nov 21 17:59:42 2003
+++ loncom/homework/grades.pm	Tue Nov 25 16:44:45 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.161 2003/11/21 22:59:42 albertel Exp $
+# $Id: grades.pm,v 1.162 2003/11/25 21:44:45 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3379,7 +3379,7 @@
     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::locommon::propath($cdom,$cname));
+				    &Apache::loncommon::propath($cdom,$cname));
     foreach my $filename (@files) {
 	($filename)=split(/&/,$filename);
 	if ($filename!~/^scantron_orig_/) { next ; }
@@ -3416,12 +3416,12 @@
     #FIXME allow instructor to be able to download the scantron file
     # and to upload it,
     $result.= <<SCANTRONFORM;
-<form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantro_process">
-  <input type="hidden" name="command" value="scantron_validate" />
-  $default_form_data
-  <table width="100%" border="0">
+    <table width="100%" border="0">
     <tr>
       <td bgcolor="#777777">
+       <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantro_process">
+       <input type="hidden" name="command" value="scantron_validate" />
+        $default_form_data
         <table width="100%" border="0">
           <tr bgcolor="#e6ffff">
             <td>
@@ -3450,16 +3450,52 @@
                 <input type="text" name="scantron_maxbubble" />
 	    </td>
           </tr>
+          <tr bgcolor="#ffffe6">
+            <td>
+              <input type="submit" value="Validate Scantron Records" />
+            </td>
+          </tr>
+        </table>
+       </form>
+      </td>
+    </tr>
+SCANTRONFORM
+   
+    $r->print($result);
+
+    if (&Apache::lonnet::allowed('usc',$ENV{'request.role.domain'}) ||
+        &Apache::lonnet::allowed('usc',$ENV{'request.course.id'})) {
+
+        $r->print(<<SCANTRONFORM);
+    <tr>
+      <td bgcolor="#777777">
+        <table width="100%" border="0">
+          <tr bgcolor="#e6ffff">
+            <td>
+              Specify a Scantron data file to upload.
+            </td>
+          </tr>
+          <tr bgcolor="#ffffe6">
+            <td>
+SCANTRONFORM
+        &scantron_upload_scantron_data($r);
+
+        $r->print(<<SCANTRONFORM);
+            </td>
+          </tr>
         </table>
       </td>
     </tr>
+SCANTRONFORM
+    }
+
+    $r->print(<<SCANTRONFORM);
   </table>
-  <input type="submit" value="Validate Scantron Records" />
 </form>
 $grading_menu_button
 SCANTRONFORM
 
-    return $result;
+    return
 }
 
 sub get_scantron_config {
@@ -4112,6 +4148,7 @@
 							  'domainid');
     my $domsel=&Apache::loncommon::select_dom_form($ENV{'request.role.domain'},
 						   'domainid');
+    my $default_form_data=&defaultFormData(&get_symb_and_url($r));
     $r->print(<<UPLOAD);
 <script type="text/javascript" language="javascript">
     function checkUpload(formname) {
@@ -4124,6 +4161,7 @@
 </script>
 
 <form enctype='multipart/form-data' action='/adm/grades' name='rules' method='post'>
+$default_form_data
 Course: <input name='courseid' type='text' />
 Domain: $domsel $select_link
 <br />
@@ -4138,7 +4176,14 @@
 
 sub scantron_upload_scantron_data_save {
     my($r)=@_;
-    $r->print("Doing upload to ".$ENV{'form.courseid'});
+    if (!&Apache::lonnet::allowed('usc',$ENV{'form.domainid'}) &&
+	!&Apache::lonnet::allowed('usc',
+			    $ENV{'form.domainid'}.'_'.$ENV{'form.courseid'})) {
+	$r->print("You are not allowed to upload Scantron data to the requested course.<br />");
+	$r->print(&show_grading_menu_form(&get_symb_and_url($r)));
+	return '';
+    }
+    $r->print("Doing upload to ".$ENV{'form.courseid'}." <br />");
     my $home=&Apache::lonnet::homeserver($ENV{'form.courseid'},
 					 $ENV{'form.domainid'});
     my $fname=$ENV{'form.upfile.filename'};
@@ -4156,10 +4201,10 @@
     # See if there is anything left
     unless ($fname) { return 'error: no uploaded file'; }
     $fname='scantron_orig_'.$fname;
-    &Apache::lonnet::logthis("fname is $fname");
     $r->print(&Apache::lonnet::finishuserfileupload($ENV{'form.courseid'},
 						    $ENV{'form.domainid'},
 						    $home,'upfile',$fname));
+    $r->print(&show_grading_menu_form(&get_symb_and_url($r)));
     return '';
 }
 
@@ -4446,12 +4491,16 @@
 	} 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'})) {
- 	    $request->print(&scantron_upload_scantron_data($request));
- 
+ 		 (&Apache::lonnet::allowed('usc',$ENV{'request.role.domain'})||
+		  &Apache::lonnet::allowed('usc',$ENV{'request.course.id'}))) {
+ 	    $request->print(&scantron_upload_scantron_data($request)); 
  	} elsif ($command eq 'scantronupload_save' &&
- 		 &Apache::lonnet::allowed('usc',$ENV{'request.role.domain'})) {
+ 		 (&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' &&
+		 &Apache::lonnet::allowed('usc',$ENV{'request.course.id'})) {
+ 	    $request->print(&scantron_download_scantron_data($request));
 	} elsif ($command) {
 	    $request->print("Access Denied ($command)");
 	}