File:  [LON-CAPA] / loncom / homework / edit.pm
Revision 1.56: download - view: text, annotated - select for diffs
Mon Jun 16 15:09:23 2003 UTC (20 years, 10 months ago) by www
Branches: MAIN
CVS tags: version_0_99_3, HEAD
Bug #1689: Browse becomes Select

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

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