File:  [LON-CAPA] / loncom / homework / edit.pm
Revision 1.57.2.4: download - view: text, annotated - select for diffs
Thu Oct 16 18:36:22 2003 UTC (20 years, 6 months ago) by albertel
Branches: version_1_0_2
CVS tags: version_1_0_3
Diff to branchpoint 1.57: preferred, unified
- This pisses me off

    1: # The LearningOnline Network with CAPA 
    2: # edit mode helpers
    3: #
    4: # $Id: edit.pm,v 1.57.2.4 2003/10/16 18:36:22 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:     $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: 	if (ref($newvalue) eq 'ARRAY') {
  471: 	    $token->[2]->{$arg}=join(',',@$newvalue);
  472: 	} else {
  473: 	    $token->[2]->{$arg}=$newvalue;
  474: 	}
  475: 	$rebuild=1;
  476:     }
  477:   }
  478:   return $rebuild;
  479: }
  480: 
  481: # looks for /> on start tags
  482: sub rebuild_tag {
  483:   my ($token) = @_;
  484:   my $result;
  485:   if ($token->[0] eq 'S') {
  486:     $result = '<'.$token->[1];
  487:     while (my ($key,$val)= each(%{$token->[2]})) {
  488:       $val=~s:^\s+|\s+$::g;
  489:       $val=~s:"::g; #"
  490:       &Apache::lonxml::debug("setting :$key: to  :$val:");
  491:       $result.=' '.$key.'="'.$val.'"';
  492:     }
  493:     if ($token->[4] =~ m:/>$:) {
  494:       $result.=' />';
  495:     } else {
  496:       $result.='>';
  497:     }
  498:   } elsif ( $token->[0] eq 'E' ) {
  499:     $result = '</'.$token->[1].'>';
  500:   }
  501:   return $result;
  502: }
  503: 
  504: sub html_element_name {
  505:     my ($name) = @_;
  506:     return $name.'_'.$Apache::lonxml::curdepth;
  507: }
  508: 
  509: sub hidden_arg {
  510:     my ($name,$token) = @_;
  511:     my $result;
  512:     my $arg=$token->[2]{$name};
  513:     $result='<input name="'.&html_element_name($name).
  514: 	'" type="hidden" value="'.$arg.'" />';
  515:     return $result;
  516: }
  517: 
  518: sub checked_arg {
  519:     my ($description,$name,$list,$token) = @_;
  520:     my $result;
  521:     my $optionlist="";
  522:     my $allselected=$token->[2]{$name};
  523:     $result=$description;
  524:     foreach my $option (@$list) {
  525: 	my ($value,$text);
  526: 	if ( ref($option) eq 'ARRAY') {
  527: 	    $value='value="'.$$option[0].'"';
  528: 	    $text=$$option[1];
  529: 	    $option=$$option[0];
  530: 	} else {
  531: 	    $text=$option;
  532: 	    $value='value="'.$option.'"';
  533: 	}
  534: 	$result.="<nobr><input type='checkbox' $value name='".
  535: 	    &html_element_name($name)."'";
  536: 	foreach my $selected (split(/,/,$allselected)) {
  537: 	    if ( $selected eq $option ) {
  538: 		$result.=" checked='on' ";
  539: 		last;
  540: 	    }
  541: 	}
  542: 	$result.=" />$text</nobr>\n";
  543:     }
  544:     return $result;
  545: }
  546: 
  547: sub text_arg {
  548:   my ($description,$name,$token,$size) = @_;
  549:   my $result;
  550:   if (!defined $size) { $size=20; }
  551:   my $arg=$token->[2]{$name};
  552:   $result=$description.'&nbsp;<input name="'.&html_element_name($name).
  553:     '" type="text" value="'.$arg.'" size="'.$size.'" />';
  554:   return '<nobr>'.$result.'</nobr>';
  555: }
  556: 
  557: sub select_arg {
  558:     my ($description,$name,$list,$token) = @_;
  559:     my $result;
  560:     my $optionlist="";
  561:     my $selected=$token->[2]{$name};
  562:     foreach my $option (@$list) {
  563: 	my ($text,$value);
  564: 	if ( ref($option) eq 'ARRAY') {
  565: 	    $value='value="'.$$option[0].'"';
  566: 	    $text=$$option[1];
  567: 	    $option=$$option[0];
  568: 	} else {
  569: 	    $text=$option;
  570: 	    $value='value="'.$option.'"';
  571: 	}
  572: 	if ( $selected eq $option ) {
  573: 	    $optionlist.="<option $value selected=\"on\">$text</option>\n";
  574: 	} else {
  575: 	    $optionlist.="<option $value >$text</option>\n";
  576: 	}
  577:     }
  578:     $result.='<nobr>'.$description.'&nbsp;<select name="'.
  579: 	&html_element_name($name).'">
  580:        '.$optionlist.'
  581:       </select></nobr>';
  582:     return $result;
  583: }
  584: 
  585: sub select_or_text_arg {
  586:     my ($description,$name,$list,$token,$size) = @_;
  587:     my $result;
  588:     my $optionlist="";
  589:     my $found=0;
  590:     my $selected=$token->[2]{$name};
  591:     foreach my $option (@$list) {
  592: 	my ($text,$value);
  593: 	if ( ref($option) eq 'ARRAY') {
  594: 	    $value='value="'.$$option[0].'"';
  595: 	    $text=$$option[1];
  596: 	    $option=$$option[0];
  597: 	} else {
  598: 	    $text=$option;
  599: 	    $value='value="'.$option.'"';
  600: 	}
  601: 	if ( $selected eq $option ) {
  602: 	    $optionlist.="<option $value selected=\"on\">$text</option>\n";
  603: 	    $found=1;
  604: 	} else {
  605: 	    $optionlist.="<option $value>$text</option>\n";
  606: 	}
  607:     }
  608:     $optionlist.="<option value=\"TYPEDINVALUE\">Type in value</option>\n";
  609:     if (($found) || (!$selected)) {
  610: 	$result.=$description.'&nbsp;<select name="'.&html_element_name($name)
  611:             .'">
  612:        '.$optionlist.'
  613:       </select>';
  614:     } else {
  615: 	$result.=&text_arg($description,$name,$token,$size);
  616:     }
  617:     return '<nobr>'.$result.'</nobr>';
  618: }
  619: 
  620: #----------------------------------------------------- image coordinates
  621: # single image coordinates, x, y 
  622: sub entercoords {
  623:     my ($idx,,$idy,$mode,$width,$height) = @_;
  624:     unless ($Apache::edit::bgimgsrc) { return ''; }
  625:     if ($idx) { $idx.='_'; }
  626:     if ($idy) { $idy.='_'; }
  627:     my $bgfile=&Apache::lonnet::escape($Apache::edit::bgimgsrc);
  628:     my $form    = 'lonhomework';
  629:     my $element;
  630:     if (! defined($mode) || $mode eq 'attribute') {
  631:         $element = &Apache::lonnet::escape("$Apache::lonxml::curdepth");
  632:     } elsif ($mode eq 'textnode') {  # for data between <tag> ... </tag>
  633:         $element = &Apache::lonnet::escape('homework_edit_'.
  634:                                            $Apache::lonxml::curdepth);
  635:     }
  636:     my $formheight='';
  637:     if ($height) {
  638: 	$formheight='&formheight='.$height.'_'.$Apache::edit::bgimgsrccurdepth;
  639:     }
  640:     my $formwidth='';
  641:     if ($width) {
  642: 	$formwidth='&formwidth='.$width.'_'.$Apache::edit::bgimgsrccurdepth;
  643:     }
  644:     my $result = <<"ENDBUTTON";
  645: <a href="/cgi-bin/imagechoice.pl?formname=$form&file=$bgfile&formx=$idx$element&formy=$idy$element$formheight$formwidth"
  646: target="imagechoice">Click Coordinates</a>
  647: ENDBUTTON
  648:     return $result;
  649: }
  650: 
  651: # coordinate pair (x1,y1)-(x2,y2)
  652: sub entercoordpair {
  653:     my ($id,$mode,$width,$height) = @_;
  654:     unless ($Apache::edit::bgimgsrc) { return ''; }
  655:     my $bgfile=&Apache::lonnet::escape($Apache::edit::bgimgsrc);
  656:     my $form    = 'lonhomework';
  657:     my $element;
  658:     if (! defined($mode) || $mode eq 'attribute') {
  659:         $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
  660:     } elsif ($mode eq 'textnode') {  # for data between <tag> ... </tag>
  661:         $element = &Apache::lonnet::escape('homework_edit_'.
  662:                                            $Apache::lonxml::curdepth);
  663:     }
  664:     my $formheight='';
  665:     if ($height) {
  666: 	$formheight='&formheight='.$height.'_'.$Apache::edit::bgimgsrccurdepth;
  667:     }
  668:     my $formwidth='';
  669:     if ($width) {
  670: 	$formwidth='&formwidth='.$width.'_'.$Apache::edit::bgimgsrccurdepth;
  671:     }
  672:     my $result = <<"ENDBUTTON";
  673: <a href="/cgi-bin/imagechoice.pl?mode=pair&formname=$form&file=$bgfile$formheight$formwidth&formcoord=$element"
  674: target="imagechoice">Click Coordinate Pair</a>
  675: ENDBUTTON
  676:     return $result;
  677: }
  678: #----------------------------------------------------- browse
  679: sub browse {
  680:     # insert a link to call up the filesystem browser (lonindexer)
  681:     my ($id, $mode) = @_;
  682:     my $form    = 'lonhomework';
  683:     my $element;
  684:     if (! defined($mode) || $mode eq 'attribute') {
  685:         $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
  686:     } elsif ($mode eq 'textnode') {  # for data between <tag> ... </tag>
  687:         $element = &Apache::lonnet::escape('homework_edit_'.
  688:                                            $Apache::lonxml::curdepth);
  689:     }
  690:     my $result = <<"ENDBUTTON";
  691: <a href=\"javascript:openbrowser('$form','$element')\"\>Select</a>
  692: ENDBUTTON
  693:     return $result;
  694: }
  695: 
  696: #----------------------------------------------------- browse
  697: sub search {
  698:     # insert a link to call up the filesystem browser (lonindexer)
  699:     my ($id, $mode) = @_;
  700:     my $form    = 'lonhomework';
  701:     my $element;
  702:     if (! defined($mode) || $mode eq 'attribute') {
  703:         $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
  704:     } elsif ($mode eq 'textnode') {  # for data between <tag> ... </tag>
  705:         $element = &Apache::lonnet::escape('homework_edit_'.
  706:                                            $Apache::lonxml::curdepth);
  707:     }
  708:     my $result = <<"ENDBUTTON";
  709: <a href=\"javascript:opensearcher('$form','$element')\"\>Search</a>
  710: ENDBUTTON
  711:     return $result;
  712: }
  713: 
  714: 
  715: 1;
  716: __END__
  717: 
  718: =head1 NAME
  719: 
  720: Apache::edit - edit mode helpers
  721: 
  722: =head1 SYNOPSIS
  723: 
  724: Invoked by many homework and xml related modules.
  725: 
  726:  &Apache::edit::SUBROUTINENAME(ARGUMENTS);
  727: 
  728: =head1 INTRODUCTION
  729: 
  730: This module outputs HTML syntax helpful for the rendering of edit
  731: mode interfaces.
  732: 
  733: This is part of the LearningOnline Network with CAPA project
  734: described at http://www.lon-capa.org.
  735: 
  736: =head1 HANDLER SUBROUTINE
  737: 
  738: There is no handler subroutine.
  739: 
  740: =head1 OTHER SUBROUTINES
  741: 
  742: =over 4
  743: 
  744: =item *
  745: 
  746: initialize_edit() : initialize edit (set colordepth to zero)
  747: 
  748: =item *
  749: 
  750: tag_start($target,$token,$description) : provide deletion and insertion lists
  751: for the manipulation of a start tag; return a scalar string
  752: 
  753: =item *
  754: 
  755: tag_end($target,$token,$description) : ending syntax corresponding to
  756: &tag_start. return a scalar string.
  757: 
  758: =item *
  759: 
  760: start_table($token) : start table; update colordepth; return scalar string.
  761: 
  762: =item *
  763: 
  764: end_table() : reduce color depth; end table; return scalar string
  765: 
  766: =item *
  767: 
  768: start_spanning_row() : start a new table row spanning the 'edit' environment.
  769: 
  770: =item *
  771: 
  772: start_row() : start a new table row and element. 
  773: 
  774: =item *
  775: 
  776: end_row() : end current table element and row.
  777: 
  778: =item *
  779: 
  780: movebuttons($target,$token) : move-up and move-down buttons; return scalar
  781: string
  782: 
  783: =item *
  784: 
  785: deletelist($target,$token) : provide a yes option in an HTML select element;
  786: return scalar string
  787: 
  788: =item *
  789: 
  790: handle_delete($space,$target,$token,$tagstack,$parstack,$parser,$safeeval,
  791: $style) : respond to a user delete request by passing relevant stack
  792: and array information to various rendering functions; return a scalar string
  793: 
  794: =item *
  795: 
  796: get_insert_list($token) : provide an insertion list based on possibilities
  797: from lonxml; return a scalar string
  798: 
  799: =item *
  800: 
  801: insertlist($target,$token) : api that uses get_insert_list;
  802: return a scalar string
  803: 
  804: =item *
  805: 
  806: handleinsert($token) : provide an insertion list based on possibilities
  807: from lonxml; return a scalar string
  808: 
  809: =item *
  810: 
  811: get_insert_list($token) : provide an insertion list based on possibilities
  812: from lonxml; return a scalar string
  813: 
  814: =item *
  815: browse($elementname) : provide a link which will open up the filesystem
  816: browser (lonindexer) and, once a file is selected, place the result in
  817: the form element $elementname.
  818: 
  819: =item *
  820: search($elementname) : provide a link which will open up the filesystem
  821: searcher (lonsearchcat) and, once a file is selected, place the result in
  822: the form element $elementname.
  823: 
  824: =item *
  825: editline(tag,data,description,size): Provide a <input type="text" ../> for
  826: single-line text entry.  This is to be used for text enclosed by tags, not
  827: arguements/parameters associated with a tag.
  828: 
  829: =back
  830: 
  831: incomplete...
  832: 
  833: =cut

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