--- loncom/homework/edit.pm	2003/09/08 21:22:15	1.63
+++ loncom/homework/edit.pm	2003/10/30 20:52:54	1.70
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # edit mode helpers
 #
-# $Id: edit.pm,v 1.63 2003/09/08 21:22:15 albertel Exp $
+# $Id: edit.pm,v 1.70 2003/10/30 20:52:54 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -67,7 +67,7 @@ sub tag_start {
 #<td>". 
 #  &movebuttons($target,$token).
 #    "</tr><tr><td colspan=\"3\">\n";
-	my @help;# = Apache::lonxml::helpinfo($token);
+	my @help = Apache::lonxml::helpinfo($token);
 	if ($help[0]) {
 	    $result .= '<td align="right" valign="top">' .
 		Apache::loncommon::help_open_topic(@help) .
@@ -273,6 +273,11 @@ sub handle_insertafter {
     return $result;
 }
 
+sub insert_img {
+    return '
+    <img />';
+}
+
 sub insert_responseparam {
     return '
     <responseparam />';
@@ -283,6 +288,8 @@ sub insert_formularesponse {
 <formularesponse answer="" samples="">
     <textline />
     <hintgroup>
+    <startouttext/>
+    <endouttext />
     </hintgroup>
 </formularesponse>';
 }
@@ -292,6 +299,8 @@ sub insert_numericalresponse {
 <numericalresponse answer="">
     <textline />
     <hintgroup>
+    <startouttext/>
+    <endouttext />
     </hintgroup>
 </numericalresponse>';
 }
@@ -301,6 +310,8 @@ sub insert_stringresponse {
 <stringresponse answer="" type="">
     <textline />
     <hintgroup>
+    <startouttext/>
+    <endouttext />
     </hintgroup>
 </stringresponse>';
 }
@@ -318,6 +329,8 @@ sub insert_imageresponse {
     <foilgroup>
     </foilgroup>
     <hintgroup>
+    <startouttext/>
+    <endouttext />
     </hintgroup>
 </imageresponse>';
 }
@@ -328,6 +341,8 @@ sub insert_optionresponse {
     <foilgroup options="">
     </foilgroup>
     <hintgroup>
+    <startouttext/>
+    <endouttext />
     </hintgroup>
 </optionresponse>';
 }
@@ -338,6 +353,8 @@ sub insert_radiobuttonresponse {
     <foilgroup>
     </foilgroup>
     <hintgroup>
+    <startouttext/>
+    <endouttext />
     </hintgroup>
 </radiobuttonresponse>';
 }
@@ -348,6 +365,8 @@ sub insert_rankresponse {
     <foilgroup options="">
     </foilgroup>
     <hintgroup>
+    <startouttext/>
+    <endouttext />
     </hintgroup>
 </rankresponse>';
 }
@@ -360,6 +379,8 @@ sub insert_matchresponse {
       </itemgroup>
     </foilgroup>
     <hintgroup>
+    <startouttext/>
+    <endouttext />
     </hintgroup>
 </matchresponse>';
 }
@@ -374,6 +395,14 @@ sub insert_hintpart {
 </hintpart>';
 }
 
+sub insert_hintgroup {
+  return '
+<hintgroup>
+    <startouttext/>
+    <endouttext />
+</hintgroup>';
+}
+
 sub insert_numericalhint {
     return '
 <numericalhint>
@@ -453,7 +482,7 @@ sub editfield {
 }
 
 sub modifiedfield {
-    my ($token) = @_;
+    my ($endtag,$parser) = @_;
     my $result;
 #  foreach my $envkey (sort keys %ENV) {
 #    &Apache::lonxml::debug("$envkey ---- $ENV{$envkey}");
@@ -461,6 +490,9 @@ sub modifiedfield {
 #  &Apache::lonxml::debug("I want homework_edit_$Apache::lonxml::curdepth");
 #  &Apache::lonxml::debug($ENV{"form.homework_edit_$Apache::lonxml::curdepth"});
     $result=$ENV{"form.homework_edit_$Apache::lonxml::curdepth"};
+    my $bodytext=&Apache::lonxml::get_all_text($endtag,$parser);
+    # textareas throw away intial \n 
+    if ($bodytext=~/^\n/) { $result="\n".$result; }
     return $result;
 }
 
@@ -569,17 +601,19 @@ sub select_arg {
     my $optionlist="";
     my $selected=$token->[2]{$name};
     foreach my $option (@$list) {
-	my $value;
+	my ($text,$value);
 	if ( ref($option) eq 'ARRAY') {
 	    $value='value="'.$$option[0].'"';
-	    $option=$$option[1];
+	    $text=$$option[1];
+	    $option=$$option[0];
 	} else {
+	    $text=$option;
 	    $value='value="'.$option.'"';
 	}
 	if ( $selected eq $option ) {
-	    $optionlist.="<option $value selected=\"on\">$option</option>\n";
+	    $optionlist.="<option $value selected=\"on\">$text</option>\n";
 	} else {
-	    $optionlist.="<option $value >$option</option>\n";
+	    $optionlist.="<option $value >$text</option>\n";
 	}
     }
     $result.='<nobr>'.$description.'&nbsp;<select name="'.
@@ -596,18 +630,20 @@ sub select_or_text_arg {
     my $found=0;
     my $selected=$token->[2]{$name};
     foreach my $option (@$list) {
-	my $value;
+	my ($text,$value);
 	if ( ref($option) eq 'ARRAY') {
 	    $value='value="'.$$option[0].'"';
-	    $option=$$option[1];
+	    $text=$$option[1];
+	    $option=$$option[0];
 	} else {
+	    $text=$option;
 	    $value='value="'.$option.'"';
 	}
 	if ( $selected eq $option ) {
-	    $optionlist.="<option $value selected=\"on\">$option</option>\n";
+	    $optionlist.="<option $value selected=\"on\">$text</option>\n";
 	    $found=1;
 	} else {
-	    $optionlist.="<option $value>$option</option>\n";
+	    $optionlist.="<option $value>$text</option>\n";
 	}
     }
     $optionlist.="<option value=\"TYPEDINVALUE\"".
@@ -703,17 +739,21 @@ ENDBUTTON
 #----------------------------------------------------- browse
 sub browse {
     # insert a link to call up the filesystem browser (lonindexer)
-    my ($id, $mode) = @_;
+    my ($id, $mode, $titleid) = @_;
     my $form    = 'lonhomework';
     my $element;
     if (! defined($mode) || $mode eq 'attribute') {
         $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
     } elsif ($mode eq 'textnode') {  # for data between <tag> ... </tag>
         $element = &Apache::lonnet::escape('homework_edit_'.
-                                           $Apache::lonxml::curdepth);
+                                           $Apache::lonxml::curdepth);	
+    }
+    my $titleelement;
+    if ($titleid) {
+	$titleelement=",'','','".&Apache::lonnet::escape("$titleid\_$Apache::lonxml::curdepth")."'";
     }
     my $result = <<"ENDBUTTON";
-<a href=\"javascript:openbrowser('$form','$element')\"\>Select</a>
+<a href=\"javascript:openbrowser('$form','$element'$titleelement)\"\>Select</a>
 ENDBUTTON
     return $result;
 }
@@ -721,7 +761,7 @@ ENDBUTTON
 #----------------------------------------------------- browse
 sub search {
     # insert a link to call up the filesystem browser (lonindexer)
-    my ($id, $mode) = @_;
+    my ($id, $mode, $titleid) = @_;
     my $form    = 'lonhomework';
     my $element;
     if (! defined($mode) || $mode eq 'attribute') {
@@ -730,8 +770,12 @@ sub search {
         $element = &Apache::lonnet::escape('homework_edit_'.
                                            $Apache::lonxml::curdepth);
     }
+    my $titleelement;
+    if ($titleid) {
+	$titleelement=",'".&Apache::lonnet::escape("$titleid\_$Apache::lonxml::curdepth")."'";
+    }
     my $result = <<"ENDBUTTON";
-<a href=\"javascript:opensearcher('$form','$element')\"\>Search</a>
+<a href=\"javascript:opensearcher('$form','$element'$titleelement)\"\>Search</a>
 ENDBUTTON
     return $result;
 }