[LON-CAPA-cvs] cvs: loncom(version_2_10_X) /homework lonhomework.pm

raeburn raeburn at source.lon-capa.org
Thu Oct 6 08:32:53 EDT 2011


raeburn		Thu Oct  6 12:32:53 2011 EDT

  Modified files:              (Branch: version_2_10_X)
    /loncom/homework	lonhomework.pm 
  Log:
  - Backport 1.323, 1.324, 1.328.
  
  
-------------- next part --------------
Index: loncom/homework/lonhomework.pm
diff -u loncom/homework/lonhomework.pm:1.317.4.3 loncom/homework/lonhomework.pm:1.317.4.4
--- loncom/homework/lonhomework.pm:1.317.4.3	Thu Jan  6 22:38:11 2011
+++ loncom/homework/lonhomework.pm	Thu Oct  6 12:32:52 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Homework handler
 #
-# $Id: lonhomework.pm,v 1.317.4.3 2011/01/06 22:38:11 raeburn Exp $
+# $Id: lonhomework.pm,v 1.317.4.4 2011/10/06 12:32:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -129,43 +129,46 @@
 	    return ('web');
 	}
     } elsif ($env{'request.state'} eq "construct") {
+#
+# We are in construction space, editing and testing problems
+#
 	if ( defined($env{'form.grade_target'}) ) {
 	    return ($env{'form.grade_target'});
 	}
 	if ( defined($env{'form.preview'})) {
 	    if ( defined($env{'form.submitted'})) {
+#
+# We are doing a problem preview
+#
 		return ('grade', 'web');
 	    } else {
 		return ('web');
 	    }
 	} else {
 	    if ($env{'form.problemstate'} eq 'WEB_GRADE') {
-		#$env{'form.webgrade'} = 'yes';
-		return ('grade','webgrade','answer');
-	    } elsif (($env{'form.problemmode'} eq 'view') ||
-		     ($env{'form.problemmode'} eq 'discard')) {
-		if ( defined($env{'form.submitted'}) &&
-		     (!defined($env{'form.resetdata'})) &&
-		     (!defined($env{'form.newrandomization'}))) {
-		    return ('grade', 'web','answer');
-		} else {
-		    return ('web','answer');
-		}
-	    } elsif ($env{'form.problemmode'} eq 'edit') {
-		if ( $env{'form.submitted'} eq 'edit' ) {
-		    if ( $env{'form.submitbutton'} eq &mt('Save and View') ) {
-			return ('modified','web','answer');
-		    } else {
-			return ('modified','no_output_web','edit');
-		    }
-		} else {
-		    return ('no_output_web','edit');
-		}
-	    } else {
-		return ('web');
-	    }
+                return ('grade','webgrade','answer');
+            } elsif ($env{'form.problemmode'} eq 'view') {
+                return ('grade','web','answer');
+            } elsif ($env{'form.problemmode'} eq 'saveview') {
+                return ('modified','web','answer');
+            } elsif ($env{'form.problemmode'} eq 'discard') {
+                return ('web','answer');
+            } elsif (($env{'form.problemmode'} eq 'saveedit') ||
+                     ($env{'form.problemmode'} eq 'undo')) {
+                return ('modified','no_output_web','edit');
+            } elsif ($env{'form.problemmode'} eq 'edit') {
+                return ('no_output_web','edit');
+            } else {
+                return ('web');
+            }
 	}
+#
+# End of Construction Space
+#
     }
+#
+# Huh? We are nowhere, so do nothing.
+#
     return ();
 }
 
@@ -383,7 +386,7 @@
 	    $date=&mt("can not be accessed from your location.");
 	    return($status,$date);
 	}
-	
+
 	foreach my $temp ("opendate","duedate","answerdate") {
 	    $lastdate = $date;
 	    if ($temp eq 'duedate') {
@@ -638,11 +641,12 @@
 
 sub handle_save_or_undo {
     my ($request,$problem,$result) = @_;
+
     my $file    = &Apache::lonnet::filelocation("",$request->uri);
     my $filebak =$file.".bak";
     my $filetmp =$file.".tmp";
     my $error=0;
-    if ($env{'form.Undo'} eq &mt('undo')) {
+    if (($env{'form.problemmode'} eq 'undo') || ($env{'form.problemmode'} eq 'undoxml')) {
 	my $error=0;
 	if (!&File::Copy::copy($file,$filetmp)) { $error=1; }
 	if ((!$error) && (!&File::Copy::copy($filebak,$file))) { $error=1; }
@@ -665,6 +669,7 @@
 	}
     } else {
         &Apache::lonnet::correct_line_ends($result);
+
 	my $fs=Apache::File->new(">$filebak");
 	if (defined($fs)) {
 	    print $fs $$problem;
@@ -901,20 +906,22 @@
     my $problem=&Apache::lonnet::getfile($file);
     if ($problem eq -1) {
 	&Apache::lonxml::error(
-            '<b> '
+            '<p class="LC_error">'
            .&mt('Unable to find [_1]',
                 '<span class="LC_filename">'.$file.'</span>')
-           .'</b>');
+           .'</p>');
 
 	$problem='';
     }
-    if (defined($env{'form.editxmltext'}) || defined($env{'form.Undo'})) {
+    if (($env{'form.problemmode'} eq 'saveeditxml') ||
+        ($env{'form.problemmode'} eq 'saveviewxml') ||
+        ($env{'form.problemmode'} eq 'undoxml')) {
 	my $error=&handle_save_or_undo($request,\$problem,
 				       \$env{'form.editxmltext'});
 	if (!$error) { $problem=&Apache::lonnet::getfile($file); }
     }
     &Apache::lonhomework::showhashsubset(\%env,'^form');
-    if ( $env{'form.submitbutton'} eq &mt('Save and View') ) {
+    if ($env{'form.problemmode'} eq 'saveviewxml') {
 	&Apache::lonhomework::showhashsubset(\%env,'^form');
 	$env{'form.problemmode'}='view';
 	&renderpage($request,$file);
@@ -929,8 +936,6 @@
             &Apache::structuretags::setmode_javascript().
             &Apache::lonhtmlcommon::dragmath_js("EditMathPopup");
 	my $only_body =  ($env{'environment.remote'} eq 'off')? 0 : 1;
-	my $dragmath_button = 
-            &Apache::lonhtmlcommon::dragmath_button("LC_editxmltext",1);
 
     # Breadcrumbs
     my $brcrum = [{'href' => &Apache::loncommon::authorspace(),
@@ -947,7 +952,7 @@
 						'onload'   => q[resize_textarea('LC_editxmltext','LC_aftertextarea')],
                                     },
                                                 'bread_crumbs' => $brcrum,
-});
+                                           });
 
     $result=$start_page
            .&Apache::loncommon::head_subbox(
@@ -962,25 +967,13 @@
                 </td><td align="right">
                   '.&Apache::loncommon::helpLatexCheatsheet('Problem_LON-CAPA_Functions','Script Functions').'
                 </td></tr>
-              </table>
-              <div class="LC_edit_problem_discards">
-                <input type="hidden" name="problemmode" value="editxml" />
-
-                <input type="button" name="submitmode" accesskey="d" value="'.&mt('Discard Edits and View').'" '.
-                'onclick="javascript:setmode(this.form,'."'discard'".')" />
-                <input type="button" '.&Apache::edit::submit_ask_anyway('setmode(this.form,'."'edit'".')').'name="submitmode" accesskey="e" value="'.&mt('Edit').'" />
-                <input type="submit" name="Undo" accesskey="u" value="'.&mt('undo').'" />
-                '.$dragmath_button.'
-              </div>
-              <div class="LC_edit_problem_saves">
-                <input type="submit" name="submitbutton" accesskey="s" value="'.&mt('Save').'"  />
-                <input type="submit" name="submitbutton" accesskey="v" value="'.&mt('Save and View').'" />
-              </div>
-              <hr style="clear:both;" />
-	      '.&Apache::lonxml::message_location().'
-            </div>
-            '  . '
-            <textarea '.&Apache::edit::element_change_detection().
+              </table>';
+
+         $result.='<input type="hidden" name="problemmode" value="saveedit" />'.
+                  &Apache::structuretags::problem_edit_buttons('editxml');
+
+         $result.='<hr style="clear:both;" />'.&Apache::lonxml::message_location().'</div>'.
+                  '<textarea '.&Apache::edit::element_change_detection().
 	              ' rows="'.$rows.'" cols="'.$cols.'" style="width:100%" '.
 		      ' name="editxmltext" id="LC_editxmltext">'.
 		      &HTML::Entities::encode($problem,'<>&"').'</textarea>
@@ -1023,9 +1016,10 @@
 	    $problem='';
 	    my $filename=(split('/',$file))[-1];
 	    my $error =
-		"<b> ".&mt('Unable to find [_1]',
+                '<p class="LC_error">'
+                .&mt('Unable to find [_1]',
 			   '<span class="LC_filename">'.$filename.'</span>')
-		."</b>";
+		."</p>";
 	    $result.=
 		&Apache::loncommon::simple_error_page($request,'Not available',
 						      $error);
@@ -1257,8 +1251,11 @@
 		#first visit to problem in construction space
 		$env{'form.problemmode'}= 'view';
 		&renderpage($request,$file);
-	    } elsif ($env{'form.problemmode'} eq 'editxml') {
-		&editxmlmode($request,$file);
+            } elsif (($env{'form.problemmode'} eq 'editxml') ||
+                     ($env{'form.problemmode'} eq 'saveeditxml') ||
+                     ($env{'form.problemmode'} eq 'saveviewxml') ||
+                     ($env{'form.problemmode'} eq 'undoxml')) {
+                &editxmlmode($request,$file);
 	    } elsif ($env{'form.problemmode'} eq 'calcanswers') {
 		&analyze($request,$file);
 	    } else {


More information about the LON-CAPA-cvs mailing list