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

raeburn raeburn at source.lon-capa.org
Wed May 2 13:04:19 EDT 2012


raeburn		Wed May  2 17:04:19 2012 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/homework	grades.pm 
  Log:
  - Backport 1.671, 1.607 (part), 1.609 (part).
  
  
-------------- next part --------------
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.596.2.12.2.5 loncom/homework/grades.pm:1.596.2.12.2.6
--- loncom/homework/grades.pm:1.596.2.12.2.5	Wed May  2 15:36:10 2012
+++ loncom/homework/grades.pm	Wed May  2 17:04:19 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.596.2.12.2.5 2012/05/02 15:36:10 raeburn Exp $
+# $Id: grades.pm,v 1.596.2.12.2.6 2012/05/02 17:04:19 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -124,13 +124,16 @@
 # --- Get the symbolic name of a problem and the url
 sub get_symb {
     my ($request,$silent) = @_;
-    (my $url=$env{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
-    my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
-    if ($symb eq '') { 
-	if (!$silent) {
-            $request->print(&mt("Unable to handle ambiguous references: [_1].",$url));
-	    return ();
-	}
+    my $symb=$env{'form.symb'};
+    unless ($symb) {
+        (my $url=$env{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
+        $symb = &Apache::lonnet::symbread($url);
+        if ($symb eq '') { 
+	    if (!$silent) {
+                $request->print(&mt("Unable to handle ambiguous references: [_1].",$url));
+	        return ();
+	    }
+        }
     }
     &Apache::lonenc::check_decrypt(\$symb);
     return ($symb);
@@ -1914,14 +1917,27 @@
 	$companswer=~s|</form>||g;
 	$companswer=~s|name="submit"|name="would_have_been_submit"|g;
     }
+    my $renderheading = &mt('View of the problem');
+    my $answerheading = &mt('Correct answer');
+    if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
+        my $stu_fullname = $env{'form.fullname'};
+        if ($stu_fullname eq '') {
+            $stu_fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
+        }
+        my $forwhom = &nameUserString(undef,$stu_fullname,$uname,$udom);
+        if ($forwhom ne '') {
+            $renderheading = &mt('View of the problem for[_1]',$forwhom);
+            $answerheading = &mt('Correct answer for[_1]',$forwhom);
+        }
+    }
     $rendered=
         '<div class="LC_Box">'
-       .'<h3 class="LC_hcell">'.&mt('View of the problem').'</h3>'
+       .'<h3 class="LC_hcell">'.$renderheading.'</h3>'
        .$rendered
        .'</div>';
     $companswer=
         '<div class="LC_Box">'
-       .'<h3 class="LC_hcell">'.&mt('Correct answer').'</h3>'
+       .'<h3 class="LC_hcell">'.$answerheading.'</h3>'
        .$companswer
        .'</div>';
     my $result;
@@ -1992,7 +2008,7 @@
     $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
     my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
     $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
-    my $symb = &get_symb($request); 
+    my ($symb) = &get_symb($request); 
     if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
 
     if (!&canview($usec)) {
@@ -2596,10 +2612,187 @@
     return $string;
 }
 
+# For Tasks provide a mechanism to display previous version for one specific student
+
+sub show_previous_task_version {
+    my ($request,$symb) = @_;
+    if ($symb eq '') {
+        $request->print("Unable to handle ambiguous references.");
+
+        return '';
+    }
+    my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
+    my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
+    if (!&canview($usec)) {
+        $request->print('<span class="LC_warning">Unable to view previous version for requested student.('.
+                        $uname.':'.$udom.' in section '.$usec.' in course id '.
+                        $env{'request.course.id'}.')</span>');
+        return;
+    }
+    my $mode = 'both';
+    my $isTask = ($symb =~/\.task$/);
+    if ($isTask) {
+        if ($env{'form.previousversion'} =~ /^\d+$/) {
+            if ($env{'form.fullname'} eq '') {
+                $env{'form.fullname'} =
+                    &Apache::loncommon::plainname($uname,$udom,'lastname');
+            }
+            my $probtitle=&Apache::lonnet::gettitle($symb);
+            $request->print("\n\n".
+                            '<div class="LC_grade_show_user">'.
+                            '<h2>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
+                            '</h2>'."\n");
+            &Apache::lonxml::clear_problem_counter();
+            $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,
+                            {'previousversion' => $env{'form.previousversion'} }));
+            $request->print("\n</div>");
+        }
+    }
+    return;
+}
+
+sub choose_task_version_form {
+    my ($symb,$uname,$udom,$nomenu) = @_;
+    my $isTask = ($symb =~/\.task$/);
+    my ($current,$version,$result,$js,$displayed,$rowtitle);
+    if ($isTask) {
+        my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
+                                              $udom,$uname);
+        if (($record{'resource.0.version'} eq '') ||
+            ($record{'resource.0.version'} < 2)) {
+            return ($record{'resource.0.version'},
+                    $record{'resource.0.version'},$result,$js);
+        } else {
+            $current = $record{'resource.0.version'};
+        }
+        if ($env{'form.previousversion'}) {
+            $displayed = $env{'form.previousversion'};
+            $rowtitle = &mt('Choose another version:')
+        } else {
+            $displayed = $current;
+            $rowtitle = &mt('Show earlier version:');
+        }
+        $result = '<div class="LC_left_float">';
+        my $list;
+        my $numversions = 0;
+        for (my $i=1; $i<=$record{'resource.0.version'}; $i++) {
+            if ($i == $current) {
+                if (!$env{'form.previousversion'} || $nomenu) {
+                    next;
+                } else {
+                    $list .= '<option value="'.$i.'">'.&mt('Current').'</option>'."\n";
+                    $numversions ++;
+                }
+            } elsif (defined($record{'resource.'.$i.'.0.status'})) {
+                unless ($i == $env{'form.previousversion'}) {
+                    $numversions ++;
+                }
+                $list .= '<option value="'.$i.'">'.$i.'</option>'."\n";
+            }
+        }
+        if ($numversions) {
+            $symb = &HTML::Entities::encode($symb,'<>"&');
+            $result .=
+                '<form name="getprev" method="post" action=""'.
+                ' onsubmit="return previousVersion('."'$uname','$udom','$symb','$displayed'".');">'.
+                &Apache::loncommon::start_data_table().
+                &Apache::loncommon::start_data_table_row().
+                '<th align="left">'.$rowtitle.'</th>'.
+                '<td><select name="version">'.
+                '<option>'.&mt('Select').'</option>'.
+                $list.
+                '</select></td>'.
+                &Apache::loncommon::end_data_table_row();
+            unless ($nomenu) {
+                $result .= &Apache::loncommon::start_data_table_row().
+                '<th align="left">'.&mt('Open in new window').'</th>'.
+                '<td><span class="LC_nobreak">'.
+                '<label><input type="radio" name="prevwin" value="1" />'.
+                &mt('Yes').'</label>'.
+                '<label><input type="radio" name="prevwin" value="0" checked="checked" />'.&mt('No').'</label>'.
+                '</span></td>'.
+                &Apache::loncommon::end_data_table_row();
+            }
+            $result .=
+                &Apache::loncommon::start_data_table_row().
+                '<th align="left"> </th>'.
+                '<td>'.
+                '<input type="submit" name="prevsub" value="'.&mt('Display').'" />'.
+                '</td>'.
+                &Apache::loncommon::end_data_table_row().
+                &Apache::loncommon::end_data_table().
+                '</form>';
+            $js = &previous_display_javascript($nomenu,$current);
+        } elsif ($displayed && $nomenu) {
+            $result .= '<a href="javascript:window.close()">'.&mt('Close window').'</a>';
+        } else {
+            $result .= &mt('No previous versions to show for this student');
+        }
+        $result .= '</div>';
+    }
+    return ($current,$displayed,$result,$js);
+}
+
+sub previous_display_javascript {
+    my ($nomenu,$current) = @_;
+    my $js = <<"JSONE";
+<script type="text/javascript">
+// <![CDATA[
+function previousVersion(uname,udom,symb) {
+    var current = '$current';
+    var version = document.getprev.version.options[document.getprev.version.selectedIndex].value;
+    var prevstr = new RegExp("^\\\\d+\$");
+    if (!prevstr.test(version)) {
+        return false;
+    }
+    var url = '';
+    if (version == current) {
+        url = '/adm/grades?student='+uname+'&userdom='+udom+'&symb='+symb+'&command=submission';
+    } else {
+        url = '/adm/grades?student='+uname+'&userdom='+udom+'&symb='+symb+'&command=versionsub&previousversion='+version;
+    }
+JSONE
+    if ($nomenu) {
+        $js .= <<"JSTWO";
+    document.location.href = url;
+JSTWO
+    } else {
+        $js .= <<"JSTHREE";
+    var newwin = 0;
+    for (var i=0; i<document.getprev.prevwin.length; i++) {
+        if (document.getprev.prevwin[i].checked == true) {
+            newwin = document.getprev.prevwin[i].value;
+        }
+    }
+    if (newwin == 1) {
+        var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
+        url = url+'&inhibitmenu=yes';
+        if (typeof(previousWin) == 'undefined' || previousWin.closed) {
+            previousWin = window.open(url,'',options,1);
+        } else {
+            previousWin.location.href = url;
+        }
+        previousWin.focus();
+        return false;
+    } else {
+        document.location.href = url;
+        return false;
+    }
+JSTHREE
+    }
+    $js .= <<"ENDJS";
+    return false;
+}
+// ]]>
+</script>
+ENDJS
+
+}
+
 #--- Called from submission routine
 sub processHandGrade {
     my ($request) = shift;
-    my $symb   = &get_symb($request);
+    my ($symb)   = &get_symb($request);
     my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
     my $button = $env{'form.gradeOpt'};
     my $ngrade = $env{'form.NCT'};
@@ -3667,7 +3860,7 @@
 sub editgrades {
     my ($request) = @_;
 
-    my $symb=&get_symb($request);
+    my ($symb)=&get_symb($request);
     my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
     my $title='<h2>'.&mt('Current Grade Status').'</h2>';
     $title.='<h4>'.&mt('<b>Current Resource: </b>[_1]',$env{'form.probTitle'}).'</h4>'."\n";
@@ -4695,6 +4888,7 @@
 	&Apache::loncommon::start_data_table_header_row().
 	'<th>'.&mt('Date/Time').'</th>'.
 	($isCODE?'<th>'.&mt('CODE').'</th>':'').
+        ($isTask?'<th>'.&mt('Version').'</th>':'').
 	'<th>'.&mt('Submission').'</th>'.
 	'<th>'.&mt('Status').'</th>'.
 	&Apache::loncommon::end_data_table_header_row();
@@ -4715,7 +4909,9 @@
 	if (exists($$record{$version.':resource.0.version'})) {
 	    $interaction = $$record{$version.':resource.0.version'};
 	}
-
+        if ($isTask && $env{'form.previousversion'}) {
+            next unless ($interaction == $env{'form.previousversion'});
+        }
 	my $where = ($isTask ? "$version:resource.$interaction"
 		             : "$version:resource");
 	$studentTable.=&Apache::loncommon::start_data_table_row().
@@ -4723,6 +4919,9 @@
 	if ($isCODE) {
 	    $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
 	}
+        if ($isTask) {
+            $studentTable.='<td>'.$interaction.'</td>';
+        }
 	my @versionKeys = split(/\:/,$$record{$version.':keys'});
 	my @displaySub = ();
 	foreach my $partid (@{$parts}) {
@@ -8182,8 +8381,9 @@
 							  'domainid',
 							  'coursename',$dom);
     my $syllabuslink = '<a href="javascript:ToSyllabus();">'.&mt('Syllabus').'</a>'.
-                       ('&nbsp'x2).&mt('(shows course personnel)'); 
-    my $default_form_data=&defaultFormData(&get_symb($r,1));
+                       ('&nbsp'x2).&mt('(shows course personnel)');
+    my ($symb) = &get_symb($r,1);
+    my $default_form_data=&defaultFormData($symb);
     my $nofile_alert = &mt('Please use the browse button to select a file from your local directory.');
     my $nocourseid_alert = &mt("Please use the 'Select Course' link to open a separate window where you can search for a course to which a file can be uploaded.");
     $r->print('
@@ -8388,7 +8588,8 @@
 
 sub scantron_download_scantron_data {
     my ($r)=@_;
-    my $default_form_data=&defaultFormData(&get_symb($r,1));
+    my ($symb) = &get_symb($r,1);
+    my $default_form_data=&defaultFormData($symb);
     my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
     my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
     my $file=$env{'form.scantron_selectfile'};
@@ -8398,7 +8599,7 @@
 	    '.&mt('The requested file name was invalid.').'
         </p>
 ');
-	$r->print(&show_grading_menu_form(&get_symb($r,1)));
+	$r->print(&show_grading_menu_form($symb));
 	return;
     }
     my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
@@ -8421,7 +8622,7 @@
 	      '<a href="'.$skipped.'">','</a>').'
     </p>
 ');
-    $r->print(&show_grading_menu_form(&get_symb($r,1)));
+    $r->print(&show_grading_menu_form($symb));
     return '';
 }
 
@@ -8757,6 +8958,13 @@
     return \%savedState;
 }
 
+#--- Href with symb and command ---
+
+sub href_symb_cmd {
+    my ($symb,$cmd)=@_;
+    return '/adm/grades?symb='.&HTML::Entities::encode(&Apache::lonenc::check_encrypt($symb),'<>&"').'&command='.$cmd;
+}
+
 sub grading_menu {
     my ($request) = @_;
     my ($symb)=&get_symb($request);
@@ -9639,6 +9847,19 @@
            '</div>';
 }
 
+sub startpage {
+    my ($r,$symb,$crumbs,$onlyfolderflag,$nodisplayflag,$stuvcurrent,$stuvdisp,$nomenu,$js) = @_;
+    if ($nomenu) {
+        $r->print(&Apache::loncommon::start_page("Student's Version",$js,{'only_body' => '1'}));
+    } else {
+        $r->print(&Apache::loncommon::start_page('Grading',$js,
+                                                 {'bread_crumbs' => $crumbs}));
+    }
+    unless ($nodisplayflag) {
+       $r->print(&Apache::lonhtmlcommon::resource_info_box($symb,$onlyfolderflag,$stuvcurrent,$stuvdisp));
+    }
+}
+
 sub handler {
     my $request=$_[0];
     &reset_caches();
@@ -9660,7 +9881,7 @@
     $ssi_error = 0;
     my $brcrum = [{href=>"/adm/grades",text=>"Grading"}];
     my $start_page = &Apache::loncommon::start_page('Grading',undef,
-                                          {'bread_crumbs' => $brcrum});
+                                                    {'bread_crumbs' => $brcrum});
     if ($symb eq '' && $command eq '') {
 	if ($env{'user.adv'}) {
             &Apache::loncommon::content_type($request,'text/html');
@@ -9713,9 +9934,33 @@
         }
         &Apache::loncommon::content_type($request,'text/html');
         $request->send_http_header;
-        $request->print($start_page);
+        unless ((($command eq 'submission' || $command eq 'versionsub')) && ($perm{'vgr'})) {
+            $request->print($start_page); 
+        }
 	if ($command eq 'submission' && $perm{'vgr'}) {
+            my ($stuvcurrent,$stuvdisp,$versionform,$js);
+            if (($env{'form.student'} ne '') && ($env{'form.userdom'} ne '')) {
+                ($stuvcurrent,$stuvdisp,$versionform,$js) =
+                    &choose_task_version_form($symb,$env{'form.student'},
+                                              $env{'form.userdom'});
+            }
+            &startpage($request,$symb,[{href=>"", text=>"Student Submissions"}],undef,undef,$stuvcurrent,$stuvdisp,undef,$js);
+            if ($versionform) {
+                $request->print($versionform);
+            }
+            $request->print('<br clear="all" />');
 	    ($env{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
+        } elsif ($command eq 'versionsub' && $perm{'vgr'}) {
+            my ($stuvcurrent,$stuvdisp,$versionform,$js) =
+                &choose_task_version_form($symb,$env{'form.student'},
+                                          $env{'form.userdom'},
+                                          $env{'form.inhibitmenu'});
+            &startpage($request,$symb,[{href=>"", text=>"Previous Student Version"}],undef,undef,$stuvcurrent,$stuvdisp,$env{'form.inhibitmenu'},$js);
+            if ($versionform) {
+                $request->print($versionform);
+            }
+            $request->print('<br clear="all" />');
+            $request->print(&show_previous_task_version($request,$symb));
 	} elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
 	    &pickStudentPage($request);
 	} elsif ($command eq 'displayPage' && $perm{'vgr'}) {


More information about the LON-CAPA-cvs mailing list