File:  [LON-CAPA] / loncom / homework / edit.pm
Revision 1.59: download - view: text, annotated - select for diffs
Mon Aug 4 22:07:29 2003 UTC (20 years, 9 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- Jeremy needs to commit his changes to lonxml

    1: # The LearningOnline Network with CAPA 
    2: # edit mode helpers
    3: #
    4: # $Id: edit.pm,v 1.59 2003/08/04 22:07:29 albertel Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: # 3/20 Guy
   29: # 01/10/02 Matthew
   30: # 03/06/02 Matthew
   31: package Apache::edit; 
   32: 
   33: use strict;
   34: use Apache::lonnet();
   35: use HTML::Entities();
   36: 
   37: # Global Vars
   38: # default list of colors to use in editing
   39: @Apache::edit::colorlist=('#ffffff','#ff0000','#00ff00','#0000ff','#0ff000','#000ff0','#f0000f');
   40: # depth of nesting of edit
   41: $Apache::edit::colordepth=0;
   42: @Apache::edit::inserttag=();
   43: # image-type responses: active background image and curdepth at definition
   44: $Apache::edit::bgimgsrc='';
   45: $Apache::edit::bgimgsrccurdepth='';
   46: 
   47: sub initialize_edit {
   48:   $Apache::edit::colordepth=0;
   49:   @Apache::edit::inserttag=();
   50: }
   51: 
   52: sub tag_start {
   53:   my ($target,$token,$description) = @_;
   54:   my $result='';
   55:   if ($target eq "edit") {
   56:     my $tag=$token->[1];
   57:     if (!$description) {
   58:       $description=&Apache::lonxml::description($token);
   59:       if (!$description) { $description="<$tag>"; }
   60:     }
   61:     $result.= &start_table($token)."<tr><td>$description</td>
   62: <td>Delete".
   63:   &deletelist($target,$token)
   64:   ."</td>
   65: <td>".
   66:     &insertlist($target,$token);
   67: #<td>". 
   68: #  &movebuttons($target,$token).
   69: #    "</tr><tr><td colspan=\"3\">\n";
   70:     my @help;# = Apache::lonxml::helpinfo($token);
   71:     if ($help[0]) {
   72: 	$result .= '<td align="right" valign="top">' .
   73: 	    Apache::loncommon::help_open_topic(@help) .
   74: 	    '</td>';
   75:     } else { $result .= "<td>&nbsp;</td>"; }
   76:     $result .= &end_row().&start_spanning_row();
   77:   }
   78:   return $result;
   79: }
   80: 
   81: sub tag_end {
   82:   my ($target,$token,$description) = @_;
   83:   my $result='';
   84:   if ($target eq 'edit') {
   85:     $result.="</td></tr>".&end_table()."\n";
   86:   }
   87:   return $result;
   88: }
   89: 
   90: sub start_table {
   91:   my ($token)=@_;
   92:   my $tag = $token->[1];
   93:   my $tagnum;
   94:   foreach my $namespace (reverse @Apache::lonxml::namespace) {
   95:     my $testtag=$namespace.'::'.$tag;
   96:     $tagnum=$Apache::lonxml::insertlist{"$testtag.num"};
   97:     if (defined($tagnum)) { last; }
   98:   }
   99:   if (!defined ($tagnum)) { $tagnum=$Apache::lonxml::insertlist{"$tag.num"}; }
  100:   my $color = $Apache::lonxml::insertlist{"$tagnum.color"};
  101:   if (!defined($color)) {
  102:     $color = $Apache::edit::colorlist[$Apache::edit::colordepth];
  103:   }
  104:   $Apache::edit::colordepth++;
  105:   push(@Apache::edit::inserttag,$token->[1]);
  106:   my $result='<div align="right">';
  107:   $result.='<table bgcolor="'.$color.'" width="97%" border="0" cellspacing="5" cellpadding="3">';
  108:   return $result;
  109: }
  110: 
  111: sub end_table {
  112:   $Apache::edit::colordepth--;
  113:   my $result='</table></div>';
  114:   $result.="<table><tr><td>";
  115: 
  116:   my ($tagname,$closingtag);
  117:   if (defined($Apache::edit::inserttag[-2])) {
  118:     $tagname=$Apache::edit::inserttag[-2];
  119:   } else {$tagname='problem';}
  120:   if (defined($Apache::edit::inserttag[-1])) {
  121:     $closingtag=$Apache::edit::inserttag[-1];
  122:   }
  123:   $result.=&innerinsertlist('edit',$tagname,$closingtag).
  124:     "</td></tr></table>";
  125:   pop(@Apache::edit::inserttag);
  126:   return $result;
  127: }
  128: 
  129: sub start_spanning_row { return '<tr><td colspan="4" bgcolor="#DDDDDD">';}
  130: sub start_row          { return '<tr><td bgcolor="#DDDDDD">';            }
  131: sub end_row            { return '</td></tr>';          }
  132: 
  133: sub movebuttons {
  134:   my ($target,$token) = @_;
  135:   my $result='<input type="submit" name="moveup.'.
  136:     $Apache::lonxml::curdepth.'" value="Move Up" />';
  137:   $result.='<input type="submit" name="movedown.'.
  138:     $Apache::lonxml::curdepth.'" value="Move Down" />';
  139:   return $result;
  140: }
  141: 
  142: sub deletelist {
  143:   my ($target,$token) = @_;
  144:   my $result = "<select name=\"delete_$Apache::lonxml::curdepth\">
  145: <option></option>
  146: <option>Yes</option>
  147: </select>";
  148:   return $result;
  149: }
  150: 
  151: sub handle_delete {
  152:   if (!$ENV{"form.delete_$Apache::lonxml::curdepth"}) { return ''; }
  153:   my ($space,$target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  154:   my $result=0;
  155:   if ($space) {
  156:     my $sub1="$space\:\:delete_$token->[1]";
  157:     {
  158:       no strict 'refs';
  159:       if (defined &$sub1) {
  160: 	$result=&$sub1($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
  161:       }
  162:     }
  163:   }
  164:   if (!$result) {
  165:     my $endtag='/'.$token->[1];
  166:     my $bodytext=&Apache::lonxml::get_all_text($endtag,$parser);
  167:     $$parser['-1']->get_token();
  168:     &Apache::lonxml::debug("Deleting :$bodytext: for $token->[1]");
  169:     &Apache::lonxml::end_tag($tagstack,$parstack,$token);
  170:   }
  171:   return 1;
  172: }
  173: 
  174: sub get_insert_list {
  175:   my ($tagname) = @_;
  176:   my $result='';
  177:   my @tagnums= ();
  178:   #&Apache::lonxml::debug("keys ".join("\n",sort(keys(%Apache::lonxml::insertlist))));
  179:   if ($Apache::lonxml::insertlist{"$tagname.which"}) {
  180:     push (@tagnums, @{ $Apache::lonxml::insertlist{"$tagname.which"} });
  181:   }
  182:   foreach my $namespace (@Apache::lonxml::namespace) {
  183:     if ($Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"}) {
  184:       push (@tagnums, @{ $Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"} });
  185:     }
  186:   }
  187:   if (@tagnums) {
  188:     my %options;
  189:     foreach my $tagnum (@tagnums) {
  190:       my $descrip=$Apache::lonxml::insertlist{"$tagnum.description"};
  191:       $options{$descrip} ="<option value=\"$tagnum\">".$descrip."</option>\n";
  192:     }
  193:     foreach my $option (sort(keys(%options))) { $result.=$options{$option}; }
  194:     if ($result) { $result='<option selected="on"></option>'.$result; }
  195:   }
  196:   return $result;
  197: }
  198: 
  199: sub insertlist {
  200:   my ($target,$token) = @_;
  201:   return &innerinsertlist($target,$token->[1]);
  202: }
  203: 
  204: sub innerinsertlist {
  205:   my ($target,$tagname,$closingtag) = @_;
  206:   my $result;
  207:   my $after='';
  208:   if ($closingtag) {
  209:      $after='_after_'.$closingtag; 
  210:   }
  211:   if ($target eq 'edit') {
  212:     my $optionlist= &get_insert_list($tagname);
  213:     if ($optionlist) {
  214:       $result = "Insert:
  215: <select name=\"insert$after\_$Apache::lonxml::curdepth\">
  216: $optionlist
  217: </select>"
  218:     } else {
  219:       $result="&nbsp;";
  220:     }
  221:   }
  222:   return $result;
  223: }
  224: 
  225: sub handle_insert {
  226:   if ($ENV{"form.insert_$Apache::lonxml::curdepth"} eq '') { return ''; }
  227:   my $result;
  228:   my $tagnum = $ENV{"form.insert_$Apache::lonxml::curdepth"};
  229:   my $func=$Apache::lonxml::insertlist{"$tagnum.function"};
  230:   if ($func eq 'default') {
  231:     my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
  232:     my $namespace;
  233:     if ($newtag =~ /::/) { ($namespace,$newtag) = split(/::/,$newtag); }
  234:     $result.="\n<$newtag>\n</$newtag>";
  235:   } else {
  236:     if (defined(&$func)) {
  237:       {
  238: 	no strict 'refs';
  239: 	$result.=&$func();
  240:       }
  241:     } else {
  242:       my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
  243:       &Apache::lonxml::error("Unable to insert tag $newtag, $func was not defined.");
  244:     }
  245:   }
  246:   return $result;
  247: }
  248: 
  249: sub handle_insertafter {
  250:   my $tagname=shift;
  251:   if ($ENV{"form.insert_after_$tagname\_$Apache::lonxml::curdepth"} eq '')
  252:      { return ''; }
  253:   my $result;
  254:   my $tagnum =$ENV{"form.insert_after_$tagname\_$Apache::lonxml::curdepth"};
  255:   my $func=$Apache::lonxml::insertlist{"$tagnum.function"};
  256:   if ($func eq 'default') {
  257:     my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
  258:     my $namespace;
  259:     if ($newtag =~ /::/) { ($namespace,$newtag) = split(/::/,$newtag); }
  260:     $result.="\n<$newtag>\n</$newtag>";
  261:   } else {
  262:     if (defined(&$func)) {
  263:       {
  264: 	no strict 'refs';
  265: 	$result.=&$func();
  266:       }
  267:     } else {
  268:       my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
  269:       &Apache::lonxml::error("Unable to insert (after) tag $newtag, $func was not defined. ($tagname $tagnum)");
  270:     }
  271:   }
  272:   return $result;
  273: }
  274: 
  275: sub insert_responseparam {
  276:   return '
  277:     <responseparam />';
  278: }
  279: 
  280: sub insert_formularesponse {
  281:   return '
  282: <formularesponse answer="" samples="">
  283:     <textline />
  284:     <hintgroup>
  285:     </hintgroup>
  286: </formularesponse>';
  287: }
  288: 
  289: sub insert_numericalresponse {
  290:   return '
  291: <numericalresponse answer="">
  292:     <textline />
  293:     <hintgroup>
  294:     </hintgroup>
  295: </numericalresponse>';
  296: }
  297: 
  298: sub insert_stringresponse {
  299:   return '
  300: <stringresponse answer="" type="">
  301:     <textline />
  302:     <hintgroup>
  303:     </hintgroup>
  304: </stringresponse>';
  305: }
  306: 
  307: sub insert_essayresponse {
  308:   return '
  309: <essayresponse>
  310:     <textfield></textfield>
  311: </essayresponse>';
  312: }
  313: 
  314: sub insert_imageresponse {
  315:   return '
  316: <imageresponse max="1">
  317:     <foilgroup>
  318:     </foilgroup>
  319:     <hintgroup>
  320:     </hintgroup>
  321: </imageresponse>';
  322: }
  323: 
  324: sub insert_optionresponse {
  325:   return '
  326: <optionresponse max="10">
  327:     <foilgroup options="">
  328:     </foilgroup>
  329:     <hintgroup>
  330:     </hintgroup>
  331: </optionresponse>';
  332: }
  333: 
  334: sub insert_radiobuttonresponse {
  335:   return '
  336: <radiobuttonresponse max="10">
  337:     <foilgroup>
  338:     </foilgroup>
  339:     <hintgroup>
  340:     </hintgroup>
  341: </radiobuttonresponse>';
  342: }
  343: 
  344: sub insert_rankresponse {
  345:   return '
  346: <rankresponse max="10">
  347:     <foilgroup options="">
  348:     </foilgroup>
  349:     <hintgroup>
  350:     </hintgroup>
  351: </rankresponse>';
  352: }
  353: 
  354: sub insert_matchresponse {
  355:   return '
  356: <matchresponse max="10">
  357:     <foilgroup options="">
  358:       <itemgroup>
  359:       </itemgroup>
  360:     </foilgroup>
  361:     <hintgroup>
  362:     </hintgroup>
  363: </matchresponse>';
  364: }
  365: 
  366: sub insert_displayduedate { return '<displayduedate />'; }
  367: sub insert_displaytitle   { return '<displaytitle />'; }
  368: sub insert_hintpart {
  369:   return '
  370: <hintpart on="default">
  371:     <startouttext/>
  372:     <endouttext />
  373: </hintpart>';
  374: }
  375: 
  376: sub insert_numericalhint {
  377:   return '
  378: <numericalhint>
  379: </numericalhint>';
  380: }
  381: 
  382: sub insert_stringhint {
  383:   return '
  384: <stringhint>
  385: </stringhint>';
  386: }
  387: 
  388: sub insert_formulahint {
  389:   return '
  390: <formulahint>
  391: </formulahint>';
  392: }
  393: 
  394: sub insert_radiobuttonhint {
  395:   return '
  396: <radiobuttonhint>
  397: </radiobuttonhint>';
  398: }
  399: 
  400: sub insert_optionhint {
  401:   return '
  402: <optionhint>
  403: </optionhint>';
  404: }
  405: 
  406: sub insert_startouttext {
  407:   return "<startouttext />\n<endouttext />";
  408: }
  409: 
  410: sub insert_script {
  411:   return "\n<script type=\"loncapa/perl\">\n</script>";
  412: }
  413: 
  414: sub textarea_sizes {
  415:   my ($data)=@_;
  416:   my $count=0;
  417:   my $maxlength=-1;
  418:   foreach (split ("\n", $$data)) {
  419:       $count+=int(length($_)/79);
  420:       $count++;
  421:       if (length($_) > $maxlength) { $maxlength = length($_); }
  422:   }
  423:   my $rows = $count;
  424:   my $cols = $maxlength;
  425:   return ($rows,$cols);
  426: }
  427: 
  428: sub editline {
  429:     my ($tag,$data,$description,$size)=@_;
  430:     $data=&HTML::Entities::encode($data);
  431:     if ($description) { $description="<br />".$description."<br />"; }
  432:     my $result = <<"END";
  433: $description
  434: <input type="text" name="homework_edit_$Apache::lonxml::curdepth" 
  435:        value="$data" size="$size" />
  436: END
  437:     return $result;
  438: }
  439: 
  440: sub editfield {
  441:   my ($tag,$data,$description,$minwidth,$minheight)=@_;
  442: 
  443:   my ($rows,$cols)=&textarea_sizes(\$data);
  444:   if ($cols > 80) { $cols = 80; }
  445:   if ($cols < $minwidth ) { $cols = $minwidth; }
  446:   if ($rows < $minheight) { $rows = $minheight; }
  447:   if ($description) { $description="<br />".$description."<br />"; }
  448:   return $description."\n".'&nbsp;&nbsp;&nbsp;<textarea rows="'.$rows.
  449:     '" cols="'.$cols.'" name="homework_edit_'.$Apache::lonxml::curdepth.'">'.
  450:       &HTML::Entities::encode($data).'</textarea>'."\n";
  451: }
  452: 
  453: sub modifiedfield {
  454:   my ($token) = @_;
  455:   my $result;
  456: #  foreach my $envkey (sort keys %ENV) {
  457: #    &Apache::lonxml::debug("$envkey ---- $ENV{$envkey}");
  458: #  }
  459: #  &Apache::lonxml::debug("I want homework_edit_$Apache::lonxml::curdepth");
  460: #  &Apache::lonxml::debug($ENV{"form.homework_edit_$Apache::lonxml::curdepth"});
  461:   $result=$ENV{"form.homework_edit_$Apache::lonxml::curdepth"};
  462:   return $result;
  463: }
  464: 
  465: # Returns a 1 if the token has been modified and you should rebuild the tag
  466: # side-effects, will modify the $token if new values are found
  467: sub get_new_args {
  468:   my ($token,$parstack,$safeeval,@args)=@_;
  469:   my $rebuild=0;
  470:   foreach my $arg (@args) {
  471:     #just want the string that it was set to
  472:     my $value=$token->[2]->{$arg};
  473:     my $element=&html_element_name($arg);
  474:     my $newvalue=$ENV{"form.$element"};
  475:     &Apache::lonxml::debug(" for:$arg: cur is :$value: new is :$newvalue:");
  476:     if (defined($newvalue) && $value ne $newvalue) {
  477:       $token->[2]->{$arg}=$newvalue;
  478:       $rebuild=1;
  479:     }
  480:   }
  481:   return $rebuild;
  482: }
  483: 
  484: # looks for /> on start tags
  485: sub rebuild_tag {
  486:   my ($token) = @_;
  487:   my $result;
  488:   if ($token->[0] eq 'S') {
  489:     $result = '<'.$token->[1];
  490:     while (my ($key,$val)= each(%{$token->[2]})) {
  491:       $val=~s:^\s+|\s+$::g;
  492:       $val=~s:"::g; #"
  493:       &Apache::lonxml::debug("setting :$key: to  :$val:");
  494:       $result.=' '.$key.'="'.$val.'"';
  495:     }
  496:     if ($token->[4] =~ m:/>$:) {
  497:       $result.=' />';
  498:     } else {
  499:       $result.='>';
  500:     }
  501:   } elsif ( $token->[0] eq 'E' ) {
  502:     $result = '</'.$token->[1].'>';
  503:   }
  504:   return $result;
  505: }
  506: 
  507: sub html_element_name {
  508:     my ($name) = @_;
  509:     return $name.'_'.$Apache::lonxml::curdepth;
  510: }
  511: 
  512: sub hidden_arg {
  513:     my ($name,$token) = @_;
  514:     my $result;
  515:     my $arg=$token->[2]{$name};
  516:     $result='<input name="'.&html_element_name($name).
  517: 	'" type="hidden" value="'.$arg.'" />';
  518:     return $result;
  519: }
  520: 
  521: sub text_arg {
  522:   my ($description,$name,$token,$size) = @_;
  523:   my $result;
  524:   if (!defined $size) { $size=20; }
  525:   my $arg=$token->[2]{$name};
  526:   $result=$description.'&nbsp;<input name="'.&html_element_name($name).
  527:     '" type="text" value="'.$arg.'" size="'.$size.'" />';
  528:   return '<nobr>'.$result.'</nobr>';
  529: }
  530: 
  531: sub select_arg {
  532:     my ($description,$name,$list,$token) = @_;
  533:     my $result;
  534:     my $optionlist="";
  535:     my $selected=$token->[2]{$name};
  536:     foreach my $option (@$list) {
  537: 	my $value;
  538: 	if ( ref($option) eq 'ARRAY') {
  539: 	    $value='value="'.$$option[0].'"';
  540: 	    $option=$$option[1];
  541: 	} else {
  542: 	    $value='value="'.$option.'"';
  543: 	}
  544: 	if ( $selected eq $option ) {
  545: 	    $optionlist.="<option $value selected=\"on\">$option</option>\n";
  546: 	} else {
  547: 	    $optionlist.="<option $value >$option</option>\n";
  548: 	}
  549:     }
  550:     $result.='<nobr>'.$description.'&nbsp;<select name="'.
  551: 	&html_element_name($name).'">
  552:        '.$optionlist.'
  553:       </select></nobr>';
  554:     return $result;
  555: }
  556: 
  557: sub select_or_text_arg {
  558:     my ($description,$name,$list,$token,$size) = @_;
  559:     my $result;
  560:     my $optionlist="";
  561:     my $found=0;
  562:     my $selected=$token->[2]{$name};
  563:     foreach my $option (@$list) {
  564: 	my $value;
  565: 	if ( ref($option) eq 'ARRAY') {
  566: 	    $value='value="'.$$option[0].'"';
  567: 	    $option=$$option[1];
  568: 	} else {
  569: 	    $value='value="'.$option.'"';
  570: 	}
  571: 	if ( $selected eq $option ) {
  572: 	    $optionlist.="<option $value selected=\"on\">$option</option>\n";
  573: 	    $found=1;
  574: 	} else {
  575: 	    $optionlist.="<option $value>$option</option>\n";
  576: 	}
  577:     }
  578:     $optionlist.="<option value=\"TYPEDINVALUE\">Type in value</option>\n";
  579:     if (($found) || (!$selected)) {
  580: 	$result.=$description.'&nbsp;<select name="'.&html_element_name($name)
  581:             .'">
  582:        '.$optionlist.'
  583:       </select>';
  584:     } else {
  585: 	$result.=&text_arg($description,$name,$token,$size);
  586:     }
  587:     return '<nobr>'.$result.'</nobr>';
  588: }
  589: 
  590: #----------------------------------------------------- image coordinates
  591: # single image coordinates, x, y 
  592: sub entercoords {
  593:     my ($idx,,$idy,$mode,$width,$height) = @_;
  594:     unless ($Apache::edit::bgimgsrc) { return ''; }
  595:     if ($idx) { $idx.='_'; }
  596:     if ($idy) { $idy.='_'; }
  597:     my $bgfile=&Apache::lonnet::escape($Apache::edit::bgimgsrc);
  598:     my $form    = 'lonhomework';
  599:     my $element;
  600:     if (! defined($mode) || $mode eq 'attribute') {
  601:         $element = &Apache::lonnet::escape("$Apache::lonxml::curdepth");
  602:     } elsif ($mode eq 'textnode') {  # for data between <tag> ... </tag>
  603:         $element = &Apache::lonnet::escape('homework_edit_'.
  604:                                            $Apache::lonxml::curdepth);
  605:     }
  606:     my $formheight='';
  607:     if ($height) {
  608: 	$formheight='&formheight='.$height.'_'.$Apache::edit::bgimgsrccurdepth;
  609:     }
  610:     my $formwidth='';
  611:     if ($width) {
  612: 	$formwidth='&formwidth='.$width.'_'.$Apache::edit::bgimgsrccurdepth;
  613:     }
  614:     my $result = <<"ENDBUTTON";
  615: <a href="/cgi-bin/imagechoice.pl?formname=$form&file=$bgfile&formx=$idx$element&formy=$idy$element$formheight$formwidth"
  616: target="imagechoice">Click Coordinates</a>
  617: ENDBUTTON
  618:     return $result;
  619: }
  620: 
  621: # coordinate pair (x1,y1)-(x2,y2)
  622: sub entercoordpair {
  623:     my ($id,$mode,$width,$height) = @_;
  624:     unless ($Apache::edit::bgimgsrc) { return ''; }
  625:     my $bgfile=&Apache::lonnet::escape($Apache::edit::bgimgsrc);
  626:     my $form    = 'lonhomework';
  627:     my $element;
  628:     if (! defined($mode) || $mode eq 'attribute') {
  629:         $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
  630:     } elsif ($mode eq 'textnode') {  # for data between <tag> ... </tag>
  631:         $element = &Apache::lonnet::escape('homework_edit_'.
  632:                                            $Apache::lonxml::curdepth);
  633:     }
  634:     my $formheight='';
  635:     if ($height) {
  636: 	$formheight='&formheight='.$height.'_'.$Apache::edit::bgimgsrccurdepth;
  637:     }
  638:     my $formwidth='';
  639:     if ($width) {
  640: 	$formwidth='&formwidth='.$width.'_'.$Apache::edit::bgimgsrccurdepth;
  641:     }
  642:     my $result = <<"ENDBUTTON";
  643: <a href="/cgi-bin/imagechoice.pl?mode=pair&formname=$form&file=$bgfile$formheight$formwidth&formcoord=$element"
  644: target="imagechoice">Click Coordinate Pair</a>
  645: ENDBUTTON
  646:     return $result;
  647: }
  648: #----------------------------------------------------- browse
  649: sub browse {
  650:     # insert a link to call up the filesystem browser (lonindexer)
  651:     my ($id, $mode) = @_;
  652:     my $form    = 'lonhomework';
  653:     my $element;
  654:     if (! defined($mode) || $mode eq 'attribute') {
  655:         $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
  656:     } elsif ($mode eq 'textnode') {  # for data between <tag> ... </tag>
  657:         $element = &Apache::lonnet::escape('homework_edit_'.
  658:                                            $Apache::lonxml::curdepth);
  659:     }
  660:     my $result = <<"ENDBUTTON";
  661: <a href=\"javascript:openbrowser('$form','$element')\"\>Select</a>
  662: ENDBUTTON
  663:     return $result;
  664: }
  665: 
  666: #----------------------------------------------------- browse
  667: sub search {
  668:     # insert a link to call up the filesystem browser (lonindexer)
  669:     my ($id, $mode) = @_;
  670:     my $form    = 'lonhomework';
  671:     my $element;
  672:     if (! defined($mode) || $mode eq 'attribute') {
  673:         $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
  674:     } elsif ($mode eq 'textnode') {  # for data between <tag> ... </tag>
  675:         $element = &Apache::lonnet::escape('homework_edit_'.
  676:                                            $Apache::lonxml::curdepth);
  677:     }
  678:     my $result = <<"ENDBUTTON";
  679: <a href=\"javascript:opensearcher('$form','$element')\"\>Search</a>
  680: ENDBUTTON
  681:     return $result;
  682: }
  683: 
  684: 
  685: 1;
  686: __END__
  687: 
  688: =head1 NAME
  689: 
  690: Apache::edit - edit mode helpers
  691: 
  692: =head1 SYNOPSIS
  693: 
  694: Invoked by many homework and xml related modules.
  695: 
  696:  &Apache::edit::SUBROUTINENAME(ARGUMENTS);
  697: 
  698: =head1 INTRODUCTION
  699: 
  700: This module outputs HTML syntax helpful for the rendering of edit
  701: mode interfaces.
  702: 
  703: This is part of the LearningOnline Network with CAPA project
  704: described at http://www.lon-capa.org.
  705: 
  706: =head1 HANDLER SUBROUTINE
  707: 
  708: There is no handler subroutine.
  709: 
  710: =head1 OTHER SUBROUTINES
  711: 
  712: =over 4
  713: 
  714: =item *
  715: 
  716: initialize_edit() : initialize edit (set colordepth to zero)
  717: 
  718: =item *
  719: 
  720: tag_start($target,$token,$description) : provide deletion and insertion lists
  721: for the manipulation of a start tag; return a scalar string
  722: 
  723: =item *
  724: 
  725: tag_end($target,$token,$description) : ending syntax corresponding to
  726: &tag_start. return a scalar string.
  727: 
  728: =item *
  729: 
  730: start_table($token) : start table; update colordepth; return scalar string.
  731: 
  732: =item *
  733: 
  734: end_table() : reduce color depth; end table; return scalar string
  735: 
  736: =item *
  737: 
  738: start_spanning_row() : start a new table row spanning the 'edit' environment.
  739: 
  740: =item *
  741: 
  742: start_row() : start a new table row and element. 
  743: 
  744: =item *
  745: 
  746: end_row() : end current table element and row.
  747: 
  748: =item *
  749: 
  750: movebuttons($target,$token) : move-up and move-down buttons; return scalar
  751: string
  752: 
  753: =item *
  754: 
  755: deletelist($target,$token) : provide a yes option in an HTML select element;
  756: return scalar string
  757: 
  758: =item *
  759: 
  760: handle_delete($space,$target,$token,$tagstack,$parstack,$parser,$safeeval,
  761: $style) : respond to a user delete request by passing relevant stack
  762: and array information to various rendering functions; return a scalar string
  763: 
  764: =item *
  765: 
  766: get_insert_list($token) : provide an insertion list based on possibilities
  767: from lonxml; return a scalar string
  768: 
  769: =item *
  770: 
  771: insertlist($target,$token) : api that uses get_insert_list;
  772: return a scalar string
  773: 
  774: =item *
  775: 
  776: handleinsert($token) : provide an insertion list based on possibilities
  777: from lonxml; return a scalar string
  778: 
  779: =item *
  780: 
  781: get_insert_list($token) : provide an insertion list based on possibilities
  782: from lonxml; return a scalar string
  783: 
  784: =item *
  785: browse($elementname) : provide a link which will open up the filesystem
  786: browser (lonindexer) and, once a file is selected, place the result in
  787: the form element $elementname.
  788: 
  789: =item *
  790: search($elementname) : provide a link which will open up the filesystem
  791: searcher (lonsearchcat) and, once a file is selected, place the result in
  792: the form element $elementname.
  793: 
  794: =item *
  795: editline(tag,data,description,size): Provide a <input type="text" ../> for
  796: single-line text entry.  This is to be used for text enclosed by tags, not
  797: arguements/parameters associated with a tag.
  798: 
  799: =back
  800: 
  801: incomplete...
  802: 
  803: =cut

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>