File:  [LON-CAPA] / loncom / homework / edit.pm
Revision 1.54: download - view: text, annotated - select for diffs
Mon Jun 9 22:42:49 2003 UTC (21 years ago) by albertel
Branches: MAIN
CVS tags: HEAD
- takes care of BUG#1676, image click fully editable now

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

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