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

raeburn raeburn at source.lon-capa.org
Sat Oct 1 11:55:51 EDT 2011


raeburn		Sat Oct  1 15:55:51 2011 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  - Handback of multiple files to one student.
    - Streamline process (one message for all returned files for a problem).
    - Localize message text according to recipient's language.
    - More robust if multiple file uploads by student for a single response:
      - Handback files will be uploaded and message sent for each and all
        files returned by the instructor. 
  
  
-------------- next part --------------
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.653 loncom/homework/grades.pm:1.654
--- loncom/homework/grades.pm:1.653	Sat Oct  1 15:48:18 2011
+++ loncom/homework/grades.pm	Sat Oct  1 15:55:51 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.653 2011/10/01 15:48:18 raeburn Exp $
+# $Id: grades.pm,v 1.654 2011/10/01 15:55:51 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1775,9 +1775,10 @@
 	my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
 	my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
 	next if (!@$files);
-	my $file_counter = 1;
+	my $file_counter = 0;
 	foreach my $file (@$files) {
 	    if ($file =~ /\/portfolio\//) {
+                $file_counter++;
     	        my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
     	        my ($name,$version,$ext) = &file_name_version_ext($file_disp);
     	        $file_disp = "$name.$ext";
@@ -1785,11 +1786,14 @@
     	        $result.=&mt('Return commented version of [_1] to student.',
     			 '<span class="LC_filename">'.$file_disp.'</span>');
     	        $result.='<input type="file"   name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
-    	        $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />';
-    	        $result.='('.&mt('File will be uploaded when you click on Save & Next below.').')<br />';
-    	        $file_counter++;
+    	        $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />'."\n";
 	    }
 	}
+        if ($file_counter) {
+            $result .= '<input type="hidden" name="'.$prefix.'countreturndoc" value="'.$file_counter.'" />'."\n".
+                       '<span class="LC_info">'.
+                       '('.&mt('File(s) will be uploaded when you click on Save & Next below.',$file_counter).')</span><br /><br />';
+        }
     }
     return $result;    
 }
@@ -2880,18 +2884,19 @@
         $request->print('<br />'.&navmap_errormsg().'<br />');
         return;
     }
+    my @handedback;
+    my $file_msg;
     my @part_response_id = &flatten_responseType($responseType);
     foreach my $part_response_id (@part_response_id) {
     	my ($part_id,$resp_id) = @{ $part_response_id };
 	my $part_resp = join('_',@{ $part_response_id });
-            if (($env{'form.'.$newflg.'_'.$part_resp.'_returndoc1'}) && ($new_part eq $part_id)) {
-                # if multiple files are uploaded names will be 'returndoc2','returndoc3'
-                my $file_counter = 1;
-		my $file_msg;
-                while ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter}) {
-                    my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'.filename'};
+        if (($env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'} =~ /^\d+$/) & ($new_part eq $part_id)) {
+            for (my $counter=1; $counter<=$env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'}; $counter++) {
+                # if multiple files are uploaded names will be 'returndoc2','returndoc3' 
+                if ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter}) {
+                    my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter.'.filename'};
                     my ($directory,$answer_file) = 
-                        ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter} =~ /^(.*?)([^\/]*)$/);
+                        ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$counter} =~ /^(.*?)([^\/]*)$/);
                     my ($answer_name,$answer_ver,$answer_ext) =
 		        &file_name_version_ext($answer_file);
 		    my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
@@ -2901,42 +2906,55 @@
                     # fix file name
                     my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
                     my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
-            	                                $newflg.'_'.$part_resp.'_returndoc'.$file_counter,
+            	                                $newflg.'_'.$part_resp.'_returndoc'.$counter,
             	                                $save_file_name);
                     if ($result !~ m|^/uploaded/|) {
                         $request->print('<br /><span class="LC_error">'.
                             &mt('An error occurred ([_1]) while trying to upload [_2].',
-                                $result,$newflg.'_'.$part_resp.'_returndoc'.$file_counter).
+                                $result,$newflg.'_'.$part_resp.'_returndoc'.$counter).
                                         '</span>');
                     } else {
                         # mark the file as read only
-                        my @files = ($save_file_name);
-                        my @what = ($symb,$env{'request.course.id'},'handback');
-                        &Apache::lonnet::mark_as_readonly($domain,$stuname,\@files,\@what);
+                        push(@handedback,$save_file_name);
 			if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
 			    $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
 			}
                         $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
-			$file_msg.= "\n".'<br /><span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span><br />";
-
+			$file_msg.= '<span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span> <br />";
                     }
-                    $request->print('<br />'.&mt('[_1] will be the uploaded file name [_2]','<span class="LC_info">'.$fname.'</span>','<span class="LC_filename">'.$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter}.'</span>'));
-                    $file_counter++;
+                    $request->print('<br />'.&mt('[_1] will be the uploaded file name [_2]','<span class="LC_info">'.$fname.'</span>','<span class="LC_filename">'.$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$counter}.'</span>'));
                 }
-		my $subject = "File Handed Back by Instructor ";
-		my $message = "A file has been returned that was originally submitted in reponse to: <br />";
-		$message .= "<strong>".&Apache::lonnet::gettitle($symb)."</strong><br />";
-		$message .= ' The returned file(s) are named: '. $file_msg;
-		$message .= " and can be found in your portfolio space.";
-		my ($feedurl,$showsymb) = 
-		    &get_feedurl_and_symb($symb,$domain,$stuname);
-                my $restitle = &Apache::lonnet::gettitle($symb);
-		my $msgstatus = 
-                   &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject.
-			 ' (File Returned) ['.$restitle.']',$message,undef,
-                         $feedurl,undef,undef,undef,$showsymb,$restitle);
             }
         }
+    }
+    if (@handedback > 0) {
+        $request->print('<br />');
+        my @what = ($symb,$env{'request.course.id'},'handback');
+        &Apache::lonnet::mark_as_readonly($domain,$stuname,\@handedback,\@what);
+        my $user_lh = &Apache::loncommon::user_lang($stuname,$domain,$env{'request.course.id'});    
+        my ($subject,$message);
+        if (scalar(@handedback) == 1) {
+            $subject = &mt_user($user_lh,'File Handed Back by Instructor');
+            $message = &mt_user($user_lh,'A file has been returned that was originally submitted in response to: ');
+        } else {
+            $subject = &mt_user($user_lh,'Files Handed Back by Instructor');
+            $message = &mt_user($user_lh,'Files have been returned that were originally submitted in response to: ');
+        }
+        $message .= "<p><strong>".&Apache::lonnet::gettitle($symb)." </strong></p>";
+        $message .= &mt_user($user_lh,'The returned file(s) are named: [_1]',"<br />$file_msg <br />").
+                    &mt_user($user_lh,'The file(s) can be found in your [_1]portfolio[_2].','<a href="/adm/portfolio">','</a>');
+        my ($feedurl,$showsymb) =
+            &get_feedurl_and_symb($symb,$domain,$stuname);
+        my $restitle = &Apache::lonnet::gettitle($symb);
+        $subject .= ' '.&mt_user($user_lh,'(File Returned)').' ['.$restitle.']';
+        my $msgstatus =
+             &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject,
+                 $message,undef,$feedurl,undef,undef,undef,$showsymb,
+                 $restitle);
+        if ($msgstatus) {
+            $request->print(&mt('Notification message status: [_1]','<span class="LC_info">'.$msgstatus.'</span>').'<br />');
+        }
+    }
     return;
 }
 


More information about the LON-CAPA-cvs mailing list