--- loncom/homework/grades.pm	2006/03/07 02:50:15	1.328
+++ loncom/homework/grades.pm	2006/03/11 00:08:48	1.332
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.328 2006/03/07 02:50:15 banghart Exp $
+# $Id: grades.pm,v 1.332 2006/03/11 00:08:48 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1497,6 +1497,7 @@ sub handback_box {
 sub show_problem {
     my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode) = @_;
     my $rendered;
+    &Apache::lonxml::remember_problem_counter();
     if ($mode eq 'both' or $mode eq 'text') {
 	$rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
 					     $env{'request.course.id'});
@@ -1508,6 +1509,7 @@ sub show_problem {
     }
     my $companswer;
     if ($mode eq 'both' or $mode eq 'answer') {
+	&Apache::lonxml::restore_problem_counter();
 	$companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
 						    $env{'request.course.id'});
     }
@@ -1594,6 +1596,7 @@ sub submission {
 	    } elsif ($env{'form.vAns'} eq 'yes') {
 		$mode='answer';
 	    }
+	    &Apache::lonxml::clear_problem_counter();
 	    $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
 	}
 	
@@ -1692,6 +1695,7 @@ KEYWORDS
 	} elsif ($env{'form.vAns'} eq 'all') {
 	    $mode='answer';
 	}
+	&Apache::lonxml::clear_problem_counter();
 	$request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode));
     }
 
@@ -3755,6 +3759,7 @@ sub displayPage {
 	'<td align="center"><b>&nbsp;Prob.&nbsp;</b></td>'.
 	'<td><b>&nbsp;'.($env{'form.vProb'} eq 'no' ? 'Title' : 'Problem Text').'/Grade</b></td></tr>';
 
+    &Apache::lonxml::clear_problem_counter();
     my ($depth,$question,$prob) = (1,1,1);
     $iterator->next(); # skip the first BEGIN_MAP
     my $curRes = $iterator->next(); # for "current resource"
@@ -4199,7 +4204,8 @@ sub scantron_selectphase {
 	    <td> Options: </td>
             <td>
 	       <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> Do only previously skipped records</label> <br />
-               <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> Remove all exisiting corrections</label>
+               <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> Remove all exisiting corrections</label> <br />
+               <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> Skip hidden resources when grading</label>
 	    </td>
           </tr>
           <tr bgcolor="#ffffe6">
@@ -4528,8 +4534,15 @@ sub scantron_find_student {
 
 sub scantron_filter {
     my ($curres)=@_;
-                        # randomout is dysfunctional at best for this purpose
-    if (ref($curres) && $curres->is_problem()) { #&& !$curres->randomout) {
+
+    if (ref($curres) && $curres->is_problem()) {
+	# if the user has asked to not have either hidden
+	# or 'randomout' controlled resources to be graded
+	# don't include them
+	if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
+	    && $curres->randomout) {
+	    return 0;
+	}
 	return 1;
     }
     return 0;
@@ -4712,6 +4725,7 @@ sub scantron_form_start {
   <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
   <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
   <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
+  <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
 SCANTRONFORM
     return $result;
 }
@@ -4746,7 +4760,7 @@ sub scantron_validate_file {
     $r->print("<p>Gathering neccessary info.</p>");$r->rflush();
     #get the student pick code ready
     $r->print(&Apache::loncommon::studentbrowser_javascript());
-    my $max_bubble=&scantron_get_maxbubble($r);
+    my $max_bubble=&scantron_get_maxbubble();
     my $result=&scantron_form_start($max_bubble).$default_form_data;
     $r->print($result);
     
@@ -5070,8 +5084,10 @@ ENDSCRIPT
 	   "&scantron_CODElist=".&Apache::lonnet::escape($env{'form.scantron_CODElist'}).
 	   "&curCODE=".&Apache::lonnet::escape($$scan_record{'scantron.CODE'}).
 	   "&scantron_selectfile=".&Apache::lonnet::escape($env{'form.scantron_selectfile'});
-	$r->print("<label><input type='radio' name='scantron_CODE_resolution' value='use_found' /> <a target='_blank' href='$href'>Select</a> a CODE from the list of all CODEs and use it.</label> Selected CODE is <input readonly='true' type='text' size='8' name='scantron_CODE_selectedvalue' onfocus=\"javascript:change_radio('use_found')\" onchange=\"javascript:change_radio('use_found')\" />");
-	$r->print("\n<br />");
+	if ($env{'form.scantron_CODElist'} =~ /\S/) { 
+	    $r->print("<label><input type='radio' name='scantron_CODE_resolution' value='use_found' /> <a target='_blank' href='$href'>Select</a> a CODE from the list of all CODEs and use it.</label> Selected CODE is <input readonly='true' type='text' size='8' name='scantron_CODE_selectedvalue' onfocus=\"javascript:change_radio('use_found')\" onchange=\"javascript:change_radio('use_found')\" />");
+	    $r->print("\n<br />");
+	}
 	$r->print("<label><input type='radio' name='scantron_CODE_resolution' value='use_typed' /> Use </label><input type='text' size='8' name='scantron_CODE_newvalue' onfocus=\"javascript:change_radio('use_typed')\" onkeypress=\"javascript:change_radio('use_typed')\" /> as the CODE.");
 	$r->print("\n<br /><br />");
     } elsif ($error eq 'doublebubble') {
@@ -5245,28 +5261,29 @@ sub scantron_validate_doublebubble {
     return (0,$currentphase+1);
 }
 
-sub scantron_get_maxbubble {
-    my ($r)=@_;
+sub scantron_get_maxbubble {    
     if (defined($env{'form.scantron_maxbubble'}) &&
 	$env{'form.scantron_maxbubble'}) {
 	return $env{'form.scantron_maxbubble'};
     }
+
     my $navmap=Apache::lonnavmaps::navmap->new();
     my (undef,undef,$sequence)=
 	&Apache::lonnet::decode_symb($env{'form.selectpage'});
+
     my $map=$navmap->getResourceByUrl($sequence);
     my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
-    &Apache::lonnet::delenv('form.counter');
+
+    &Apache::lonxml::clear_problem_counter();
+
     foreach my $resource (@resources) {
-	my $result=&Apache::lonnet::ssi($resource->src().'?symb='.&Apache::lonnet::escape($resource->symb()));
+	my $result=&Apache::lonnet::ssi($resource->src(),
+					('symb' => $resource->symb()));
     }
     &Apache::lonnet::delenv('scantron\.');
-    my $envfile=$env{'user.environment'};
-    $envfile=~/\/([^\/]+)\.id$/;
-    $envfile=$1;
-    &Apache::lonnet::transfer_profile_to_env($r->dir_config('lonIDsDir'),
-					     $envfile);
-    $env{'form.scantron_maxbubble'}=$env{'form.counter'}-1;
+    $env{'form.scantron_maxbubble'} =
+	&Apache::lonxml::get_problem_counter()-1;
+
     return $env{'form.scantron_maxbubble'};
 }
 
@@ -5360,7 +5377,8 @@ SCANTRONFORM
  	    next;
  	}
   	($uname,$udom)=split(/:/,$uname);
-  	&Apache::lonnet::delenv('form.counter');
+
+	&Apache::lonxml::clear_problem_counter();
   	&Apache::lonnet::appenv(%$scan_record);
 	
 	my $i=0;
@@ -5388,7 +5406,7 @@ SCANTRONFORM
 	$completedstudents{$uname}={'line'=>$line};
 	if (&Apache::loncommon::connection_aborted($r)) { last; }
     } continue {
-	&Apache::lonnet::delenv('form.counter');
+	&Apache::lonxml::clear_problem_counter();
 	&Apache::lonnet::delenv('scantron\.');
     }
     &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);