[LON-CAPA-cvs] cvs: loncom /homework insertlist.tab structuretags.pm

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 23 Aug 2002 21:17:16 -0000


This is a MIME encoded message

--albertel1030137436
Content-Type: text/plain

albertel		Fri Aug 23 17:17:16 2002 EDT

  Modified files:              
    /loncom/homework	structuretags.pm insertlist.tab 
  Log:
  - fixes BUG#650 <library> tag is edittable
  
  
--albertel1030137436
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20020823171716.txt"

Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.104 loncom/homework/structuretags.pm:1.105
--- loncom/homework/structuretags.pm:1.104	Tue Aug 20 10:42:22 2002
+++ loncom/homework/structuretags.pm	Fri Aug 23 17:17:16 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.104 2002/08/20 14:42:22 sakharuk Exp $
+# $Id: structuretags.pm,v 1.105 2002/08/23 21:17:16 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -101,7 +101,68 @@
     }
     $body_tag_start.='>';
   }
-  return ($result,$head_tag_start,$body_tag_start);
+  my $form_tag_start;
+  if (!defined($found{'form'})) {
+    $form_tag_start='<form name="lonhomework" method="POST" action="'.
+      $ENV{'request.uri'}.'">';
+  }
+  return ($result,$head_tag_start,$body_tag_start,$form_tag_start);
+}
+
+sub get_resource_name {
+  my ($parstack,$safeeval)=@_;
+  my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval);
+  if ($name eq '') { 
+    $name=&Apache::lonnet::EXT('resource.title');
+    if ($name eq 'con_lost') { $name = ''; }
+  }
+  $Apache::lonhomework::name=$name;
+  return $name;
+}
+
+sub setup_rndseed {
+  my ($safeeval)=@_;
+  my $rndseed;
+  if ($ENV{'request.state'} eq "construct") {
+    $rndseed=$ENV{'form.rndseed'};
+    if (!$rndseed) {
+      $rndseed=time;
+      $ENV{'form.rndseed'}=$rndseed;
+    }
+    &Apache::run::run('$external::randomseed='.$rndseed.';',$safeeval);
+  }
+  return $rndseed;
+}
+
+sub problem_edit_header {
+  return '<input type="hidden" name="submitted" value="edit" />
+       <input type="hidden" name="problemmode" value="Edit" />
+       <input type="submit" name="problemmode" value="Discard Edits and View" />
+       <input type="submit" name="problemmode" value="EditXML" />
+       <input type="submit" name="Undo" value="undo" /> <hr />
+       <input type="submit" name="submit" value="Submit Changes" />
+       <input type="submit" name="submit" value="Submit Changes and View" /><br />
+      ';
+}
+
+sub problem_edit_footer {
+  return '<br /><input type="submit" name="submit" value="Submit Changes and Edit" />
+    <input type="submit" name="submit" value="Submit Changes and View" />';
+}
+
+sub problem_web_to_edit_header {
+  my ($rndseed)=@_;
+  my $result.='<input type="hidden" name="problemmode" value="View" />
+             <input type="submit" name="problemmode" value="Edit" />
+             <input type="submit" name="problemmode" value="EditXML" />
+             Random Seed:<input type="text" name="rndseed" width="10" value="'.
+	       $rndseed.'" />
+             <input type="submit" name="changerandseed" value="Change" />
+             <input type="submit" name="resetdata" value="Reset Submissions" />
+             <input type="checkbox" name="showallfoils" ';
+  if (defined($ENV{'form.showallfoils'})) { $result.='checked="on"'; }
+  $result.= ' /> Show All Foils
+             <hr />';
 }
 
 sub initialize_storage {
@@ -200,7 +261,7 @@
   my $accessmsg;
 
   #should get back a <html> or the neccesary stuff to start XML/MathML
-  my ($result,$head_tag_start,$body_tag_start)=
+  my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
     &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
   if ($target eq 'tex' and $ENV{'request.symb'} =~ m/\.page_/) { $result = '';}
 
@@ -216,15 +277,7 @@
     }
 
     #handle rand seed in construction space
-    my $rndseed;
-    if ($ENV{'request.state'} eq "construct") {
-      $rndseed=$ENV{'form.rndseed'};
-      if (!$rndseed) {
-	$rndseed=time;
-	$ENV{'form.rndseed'}=$rndseed;
-      }
-      &Apache::run::run('$external::randomseed='.$rndseed.';',$safeeval);
-    }
+    my $rndseed=&setup_rndseed($safeeval);
     ($status,$accessmsg) = &Apache::lonhomework::check_access('0');
     push (@Apache::inputtags::status,$status);
     my $expression='$external::datestatus="'.$status.'";';
@@ -246,31 +299,14 @@
 	$result.=$msg.'<br />';
       }
     } elsif ($target eq 'web') {
-      my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
-      if ($name eq '') { 
-	$name=&Apache::lonnet::EXT('resource.title');
-	if ($name eq 'con_lost') { $name = ''; }
-      }
-      $Apache::lonhomework::name=$name;
+      my $name= &get_resource_name($parstack,$safeeval);
       if ($status eq 'CAN_ANSWER') {
 	# create a page header and exit
-	$result.="$head_tag_start<title>$name</title></head>\n
-              $body_tag_start\n
-              <form name=\"lonhomework\" method=\"POST\" action=\"".$ENV{'request.uri'}."\">".
+	$result.="$head_tag_start<title>$name</title></head>
+              $body_tag_start \n $form_tag_start".	
 		'<input type="hidden" name="submitted" value="yes" />';
 	if ($ENV{'request.state'} eq "construct") {
-	  $result.=
-	    '<input type="hidden" name="problemmode" value="View" />
-             <input type="submit" name="problemmode" value="Edit" />
-             <input type="submit" name="problemmode" value="EditXML" />
-             Random Seed:<input type="text" name="rndseed" width="10" value="'.
-	       $rndseed.'" />
-             <input type="submit" name="changerandseed" value="Change" />
-             <input type="submit" name="resetdata" value="Reset Submissions" />
-             <input type="checkbox" name="showallfoils" ';
-	  if (defined($ENV{'form.showallfoils'})) { $result.='checked="on"'; }
-	  $result.= ' /> Show All Foils
-             <hr />';
+	  $result.= &problem_web_to_edit_header($rndseed);
 	}
 	# if we are viewing someone else preserve that info
 	if (defined $ENV{'form.grade_symb'}) {
@@ -325,17 +361,8 @@
 	}
     }
   } elsif ($target eq 'edit') {
-    $result.=$head_tag_start."</head>".$body_tag_start.
-      '<form name="lonhomework" method="POST" action="'.
-	$ENV{'request.uri'}.'">
-       <input type="hidden" name="submitted" value="edit" />
-       <input type="hidden" name="problemmode" value="Edit" />
-       <input type="submit" name="problemmode" value="Discard Edits and View" />
-       <input type="submit" name="problemmode" value="EditXML" />
-       <input type="submit" name="Undo" value="undo" /> <hr />
-       <input type="submit" name="submit" value="Submit Changes" />
-       <input type="submit" name="submit" value="Submit Changes and View" /><br />
-      ';
+    $result.=$head_tag_start."</head>".$body_tag_start.$form_tag_start.
+      &problem_edit_header();
     my $temp=&Apache::edit::insertlist($target,$token);
     $result.=$temp;
   } elsif ($target eq 'modified') {
@@ -384,8 +411,7 @@
     }
   } elsif ($target eq 'edit') {
     &Apache::lonxml::debug("in end_problem with $target, edit");
-    $result ='<br /><input type="submit" name="submit" value="Submit Changes and Edit" />';
-    $result.='<input type="submit" name="submit" value="Submit Changes and View" />';
+    $result = &problem_edit_footer();
   } elsif ($target eq 'tex') {
       $result .= '\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}';
       if (not $ENV{'request.symb'} =~ m/\.page_/) {
@@ -399,33 +425,34 @@
 
 sub start_library {
   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
-  my ($result,$head_tag_start,$body_tag_start)=
+  my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
     &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
   if ($target eq 'edit') {
-    $result.=$head_tag_start."</head>".$body_tag_start.
-      '<form name="lonhomework" method="POST" action="'.$ENV{'request.uri'}.'">
-       <input type="hidden" name="submitted" value="edit" />
-       <input type="hidden" name="problemmode" value="Edit" />
-       <input type="submit" name="problemmode" value="View" />
-       <input type="submit" name="Undo" value="undo" /> <hr />
-      ';
+    $result.=$head_tag_start."</head>".$body_tag_start.$form_tag_start.
+      &problem_edit_header();
     my $temp=&Apache::edit::insertlist($target,$token);
     $result.=$temp;
-    return $result;
-  }
-  if ($target eq 'modified') {
+  } elsif ($target eq 'modified') {
     $result=$token->[4];
     $result.=&Apache::edit::handle_insert();
-    return $result;
+  } elsif ($target eq 'web' && $ENV{'request.state'} eq "construct" ) {
+    my $name=&get_resource_name($parstack,$safeeval);
+    my $rndseed=&setup_rndseed($safeeval);
+    $result.="$head_tag_start<title>$name</title></head>
+              $body_tag_start \n $form_tag_start".	
+		'<input type="hidden" name="submitted" value="yes" />';
+    $result.=&problem_web_to_edit_header($rndseed);
   }
-  return '';
+  return $result;
 }
 
 sub end_library {
   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   my $result='';
   if ($target eq 'edit') {
-    $result='<br /><input type="submit" name="submit" value="Submit Changes" />';
+    $result=&problem_edit_footer();
+  } elsif ($target eq 'web' && $ENV{'request.state'} eq "construct") {
+    $result.='</form></body>'.&Apache::lonxml::xmlend();
   }
   return $result;
 }
Index: loncom/homework/insertlist.tab
diff -u loncom/homework/insertlist.tab:1.28 loncom/homework/insertlist.tab:1.29
--- loncom/homework/insertlist.tab:1.28	Wed Aug  7 12:23:05 2002
+++ loncom/homework/insertlist.tab	Fri Aug 23 17:17:16 2002
@@ -103,7 +103,7 @@
 scriptlib            . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
 window               . . . . . . . . . . . . . . . . . . . . . Y Y . . . . . Y Y . Y . Y Y . Y . Y Y . Y . . . Y Y Y Y Y Y Y . . . . . . . . . . . .
 block                Y Y Y Y . . . . . . . Y . . . . . . . . Y Y Y . . . Y . Y Y Y Y Y Y Y . Y . Y Y . Y . . . Y Y Y Y Y Y Y . . . . . . . . . . . .
-library              . . . . . . . . . . . . . . . . . . . . . Y Y . . . . . . . Y Y Y Y . . . . . . . Y . . . . . Y . . . Y . . . . . . . . . . . .
+library              Y Y Y Y . . . . . . . Y . . . . . . . . Y Y Y . . . Y . Y Y Y Y Y Y . . Y Y Y Y . Y . . . Y Y Y Y Y Y Y . . . . . . . . . . . .
 notsolved            Y Y Y Y . . . . . . . Y . . . . . . . . Y Y Y . . . Y . Y Y Y Y Y Y Y . . . Y Y . Y . . . Y . Y Y Y Y Y . . . . . . . . . . . .
 part                 Y Y Y Y . . . . . . . Y . . . . . . . . Y Y Y . . . Y . Y Y Y Y Y Y Y . Y . Y Y . Y . . . Y Y Y Y . Y Y . . . . . . . . . . . .
 postanswerdate       . . . . . . . . . . . . . . . . . . . . . Y Y . . . . . Y Y Y Y Y Y Y . Y . . . . Y . . . Y Y Y Y . Y Y . . . . . . . . . . . .

--albertel1030137436--