Annotation of loncom/homework/edit.pm, revision 1.56

1.1       albertel    1: # The LearningOnline Network with CAPA 
                      2: # edit mode helpers
1.25      albertel    3: #
1.56    ! www         4: # $Id: edit.pm,v 1.55 2003/06/10 18:39:08 albertel Exp $
1.25      albertel    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: #
1.1       albertel   28: # 3/20 Guy
1.27      matthew    29: # 01/10/02 Matthew
1.29      matthew    30: # 03/06/02 Matthew
1.1       albertel   31: package Apache::edit; 
                     32: 
                     33: use strict;
1.32      albertel   34: use Apache::lonnet();
                     35: use HTML::Entities();
1.1       albertel   36: 
1.10      albertel   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;
1.38      www        42: @Apache::edit::inserttag=();
1.49      www        43: # image-type responses: active background image and curdepth at definition
                     44: $Apache::edit::bgimgsrc='';
                     45: $Apache::edit::bgimgsrccurdepth='';
1.10      albertel   46: 
                     47: sub initialize_edit {
                     48:   $Apache::edit::colordepth=0;
1.38      www        49:   @Apache::edit::inserttag=();
1.10      albertel   50: }
                     51: 
1.1       albertel   52: sub tag_start {
1.9       albertel   53:   my ($target,$token,$description) = @_;
1.1       albertel   54:   my $result='';
1.5       albertel   55:   if ($target eq "edit") {
1.4       albertel   56:     my $tag=$token->[1];
1.22      albertel   57:     if (!$description) {
                     58:       $description=&Apache::lonxml::description($token);
                     59:       if (!$description) { $description="<$tag>"; }
                     60:     }
1.10      albertel   61:     $result.= &start_table($token)."<tr><td>$description</td>
1.14      albertel   62: <td>Delete".
1.8       albertel   63:   &deletelist($target,$token)
                     64:   ."</td>
1.4       albertel   65: <td>".
1.27      matthew    66:     &insertlist($target,$token).&end_row().&start_spanning_row();
                     67: #<td>". 
1.22      albertel   68: #  &movebuttons($target,$token).
                     69: #    "</tr><tr><td colspan=\"3\">\n";
1.4       albertel   70:   }
1.1       albertel   71:   return $result;
                     72: }
                     73: 
                     74: sub tag_end {
1.9       albertel   75:   my ($target,$token,$description) = @_;
1.1       albertel   76:   my $result='';
1.4       albertel   77:   if ($target eq 'edit') {
1.55      albertel   78:     $result.="</td></tr>".&end_table()."\n";
1.4       albertel   79:   }
                     80:   return $result;
                     81: }
1.1       albertel   82: 
1.10      albertel   83: sub start_table {
                     84:   my ($token)=@_;
                     85:   my $tag = $token->[1];
                     86:   my $tagnum;
                     87:   foreach my $namespace (reverse @Apache::lonxml::namespace) {
1.23      albertel   88:     my $testtag=$namespace.'::'.$tag;
1.10      albertel   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++;
1.38      www        98:   push(@Apache::edit::inserttag,$token->[1]);
1.40      albertel   99:   my $result='<div align="right">';
1.41      www       100:   $result.='<table bgcolor="'.$color.'" width="97%" border="0" cellspacing="5" cellpadding="3">';
1.10      albertel  101:   return $result;
                    102: }
                    103: 
                    104: sub end_table {
                    105:   $Apache::edit::colordepth--;
1.40      albertel  106:   my $result='</table></div>';
1.39      albertel  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>";
1.38      www       118:   pop(@Apache::edit::inserttag);
1.10      albertel  119:   return $result;
                    120: }
                    121: 
1.41      www       122: sub start_spanning_row { return '<tr><td colspan="3" bgcolor="#DDDDDD">';}
                    123: sub start_row          { return '<tr><td bgcolor="#DDDDDD">';            }
1.27      matthew   124: sub end_row            { return '</td></tr>';          }
                    125: 
1.22      albertel  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: 
1.8       albertel  135: sub deletelist {
                    136:   my ($target,$token) = @_;
                    137:   my $result = "<select name=\"delete_$Apache::lonxml::curdepth\">
1.14      albertel  138: <option></option>
                    139: <option>Yes</option>
1.8       albertel  140: </select>";
                    141:   return $result;
                    142: }
                    143: 
1.14      albertel  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];
1.45      albertel  159:     my $bodytext=&Apache::lonxml::get_all_text($endtag,$parser);
1.14      albertel  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: 
1.7       albertel  167: sub get_insert_list {
1.38      www       168:   my ($tagname) = @_;
1.6       albertel  169:   my $result='';
1.7       albertel  170:   my @tagnums= ();
                    171:   #&Apache::lonxml::debug("keys ".join("\n",sort(keys(%Apache::lonxml::insertlist))));
1.38      www       172:   if ($Apache::lonxml::insertlist{"$tagname.which"}) {
                    173:     push (@tagnums, @{ $Apache::lonxml::insertlist{"$tagname.which"} });
1.7       albertel  174:   }
                    175:   foreach my $namespace (@Apache::lonxml::namespace) {
1.38      www       176:     if ($Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"}) {
                    177:       push (@tagnums, @{ $Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"} });
1.6       albertel  178:     }
                    179:   }
1.7       albertel  180:   if (@tagnums) {
1.33      albertel  181:     my %options;
1.7       albertel  182:     foreach my $tagnum (@tagnums) {
1.33      albertel  183:       my $descrip=$Apache::lonxml::insertlist{"$tagnum.description"};
                    184:       $options{$descrip} ="<option value=\"$tagnum\">".$descrip."</option>\n";
1.5       albertel  185:     }
1.33      albertel  186:     foreach my $option (sort(keys(%options))) { $result.=$options{$option}; }
1.5       albertel  187:     if ($result) { $result='<option selected="on"></option>'.$result; }
                    188:   }
                    189:   return $result;
                    190: }
                    191: 
1.4       albertel  192: sub insertlist {
1.8       albertel  193:   my ($target,$token) = @_;
1.38      www       194:   return &innerinsertlist($target,$token->[1]);
                    195: }
                    196: 
                    197: sub innerinsertlist {
                    198:   my ($target,$tagname,$closingtag) = @_;
1.4       albertel  199:   my $result;
1.38      www       200:   my $after='';
                    201:   if ($closingtag) {
                    202:      $after='_after_'.$closingtag; 
                    203:   }
1.4       albertel  204:   if ($target eq 'edit') {
1.38      www       205:     my $optionlist= &get_insert_list($tagname);
1.5       albertel  206:     if ($optionlist) {
                    207:       $result = "Insert:
1.38      www       208: <select name=\"insert$after\_$Apache::lonxml::curdepth\">
1.5       albertel  209: $optionlist
1.4       albertel  210: </select>"
1.11      albertel  211:     } else {
                    212:       $result="&nbsp;";
1.6       albertel  213:     }
                    214:   }
                    215:   return $result;
                    216: }
                    217: 
1.7       albertel  218: sub handle_insert {
1.15      albertel  219:   if ($ENV{"form.insert_$Apache::lonxml::curdepth"} eq '') { return ''; }
1.6       albertel  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"};
1.7       albertel  225:     my $namespace;
                    226:     if ($newtag =~ /::/) { ($namespace,$newtag) = split(/::/,$newtag); }
1.6       albertel  227:     $result.="\n<$newtag>\n</$newtag>";
                    228:   } else {
1.15      albertel  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.");
1.38      www       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)");
1.5       albertel  263:     }
                    264:   }
                    265:   return $result;
1.16      albertel  266: }
                    267: 
                    268: sub insert_responseparam {
                    269:   return '
                    270:     <responseparam />';
1.5       albertel  271: }
                    272: 
1.24      albertel  273: sub insert_formularesponse {
                    274:   return '
                    275: <formularesponse answer="" samples="">
                    276:     <textline />
                    277:     <hintgroup>
                    278:     </hintgroup>
                    279: </formularesponse>';
                    280: }
                    281: 
1.15      albertel  282: sub insert_numericalresponse {
                    283:   return '
                    284: <numericalresponse answer="">
                    285:     <textline />
                    286:     <hintgroup>
                    287:     </hintgroup>
                    288: </numericalresponse>';
                    289: }
                    290: 
1.18      albertel  291: sub insert_stringresponse {
                    292:   return '
                    293: <stringresponse answer="" type="">
                    294:     <textline />
                    295:     <hintgroup>
                    296:     </hintgroup>
                    297: </stringresponse>';
1.36      albertel  298: }
                    299: 
                    300: sub insert_essayresponse {
                    301:   return '
                    302: <essayresponse>
                    303:     <textfield></textfield>
                    304: </essayresponse>';
1.54      albertel  305: }
                    306: 
                    307: sub insert_imageresponse {
                    308:   return '
                    309: <imageresponse max="1">
                    310:     <foilgroup>
                    311:     </foilgroup>
                    312:     <hintgroup>
                    313:     </hintgroup>
                    314: </imageresponse>';
1.18      albertel  315: }
                    316: 
1.7       albertel  317: sub insert_optionresponse {
                    318:   return '
                    319: <optionresponse max="10">
                    320:     <foilgroup options="">
                    321:     </foilgroup>
1.14      albertel  322:     <hintgroup>
                    323:     </hintgroup>
1.7       albertel  324: </optionresponse>';
1.1       albertel  325: }
                    326: 
1.23      albertel  327: sub insert_radiobuttonresponse {
                    328:   return '
                    329: <radiobuttonresponse max="10">
                    330:     <foilgroup>
                    331:     </foilgroup>
                    332:     <hintgroup>
                    333:     </hintgroup>
                    334: </radiobuttonresponse>';
1.43      albertel  335: }
                    336: 
                    337: sub insert_rankresponse {
                    338:   return '
                    339: <rankresponse max="10">
                    340:     <foilgroup options="">
                    341:     </foilgroup>
                    342:     <hintgroup>
                    343:     </hintgroup>
                    344: </rankresponse>';
1.23      albertel  345: }
                    346: 
1.44      albertel  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: 
1.21      albertel  359: sub insert_displayduedate { return '<displayduedate />'; }
                    360: sub insert_displaytitle   { return '<displaytitle />'; }
1.22      albertel  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>';
1.46      albertel  373: }
                    374: 
                    375: sub insert_stringhint {
                    376:   return '
                    377: <stringhint>
                    378: </stringhint>';
                    379: }
                    380: 
                    381: sub insert_formulahint {
                    382:   return '
                    383: <formulahint>
                    384: </formulahint>';
1.37      albertel  385: }
                    386: 
                    387: sub insert_radiobuttonhint {
                    388:   return '
                    389: <radiobuttonhint>
                    390: </radiobuttonhint>';
1.50      albertel  391: }
                    392: 
                    393: sub insert_optionhint {
                    394:   return '
                    395: <optionhint>
                    396: </optionhint>';
1.22      albertel  397: }
1.21      albertel  398: 
1.23      albertel  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: 
1.25      albertel  407: sub textarea_sizes {
                    408:   my ($data)=@_;
                    409:   my $count=0;
                    410:   my $maxlength=-1;
1.53      albertel  411:   foreach (split ("\n", $$data)) {
                    412:       $count+=int(length($_)/79);
                    413:       $count++;
                    414:       if (length($_) > $maxlength) { $maxlength = length($_); }
                    415:   }
1.25      albertel  416:   my $rows = $count;
                    417:   my $cols = $maxlength;
                    418:   return ($rows,$cols);
                    419: }
                    420: 
1.32      albertel  421: sub editline {
1.31      matthew   422:     my ($tag,$data,$description,$size)=@_;
1.32      albertel  423:     $data=&HTML::Entities::encode($data);
1.31      matthew   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: 
1.2       albertel  433: sub editfield {
1.5       albertel  434:   my ($tag,$data,$description,$minwidth,$minheight)=@_;
1.22      albertel  435: 
1.25      albertel  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 />"; }
1.32      albertel  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";
1.2       albertel  444: }
                    445: 
                    446: sub modifiedfield {
                    447:   my ($token) = @_;
1.3       albertel  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;
1.2       albertel  456: }
                    457: 
1.15      albertel  458: # Returns a 1 if the token has been modified and you should rebuild the tag
1.12      albertel  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) {
1.20      albertel  464:     #just want the string that it was set to
                    465:     my $value=$token->[2]->{$arg};
1.48      albertel  466:     my $element=&html_element_name($arg);
                    467:     my $newvalue=$ENV{"form.$element"};
1.12      albertel  468:     &Apache::lonxml::debug(" for:$arg: cur is :$value: new is :$newvalue:");
1.52      albertel  469:     if (defined($newvalue) && $value ne $newvalue) {
1.12      albertel  470:       $token->[2]->{$arg}=$newvalue;
                    471:       $rebuild=1;
                    472:     }
                    473:   }
                    474:   return $rebuild;
                    475: }
                    476: 
1.15      albertel  477: # looks for /> on start tags
1.12      albertel  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]})) {
1.20      albertel  484:       $val=~s:^\s+|\s+$::g;
1.17      albertel  485:       $val=~s:"::g; #"
1.12      albertel  486:       &Apache::lonxml::debug("setting :$key: to  :$val:");
                    487:       $result.=' '.$key.'="'.$val.'"';
                    488:     }
1.15      albertel  489:     if ($token->[4] =~ m:/>$:) {
                    490:       $result.=' />';
                    491:     } else {
                    492:       $result.='>';
                    493:     }
1.12      albertel  494:   } elsif ( $token->[0] eq 'E' ) {
                    495:     $result = '</'.$token->[1].'>';
                    496:   }
                    497:   return $result;
                    498: }
1.13      albertel  499: 
1.47      matthew   500: sub html_element_name {
                    501:     my ($name) = @_;
1.48      albertel  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;
1.47      matthew   512: }
                    513: 
1.13      albertel  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};
1.47      matthew   519:   $result=$description.'&nbsp;<input name="'.&html_element_name($name).
1.13      albertel  520:     '" type="text" value="'.$arg.'" size="'.$size.'" />';
                    521:   return $result;
                    522: }
                    523: 
                    524: sub select_arg {
1.39      albertel  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: 	}
1.13      albertel  542:     }
1.47      matthew   543:     $result.=$description.'&nbsp;<select name="'.&html_element_name($name).
                    544:         '">
1.13      albertel  545:        '.$optionlist.'
1.27      matthew   546:       </select>';
1.39      albertel  547:     return $result;
1.13      albertel  548: }
                    549: 
1.19      albertel  550: sub select_or_text_arg {
1.39      albertel  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)) {
1.47      matthew   573: 	$result.=$description.'&nbsp;<select name="'.&html_element_name($name)
                    574:             .'">
1.39      albertel  575:        '.$optionlist.'
                    576:       </select>';
1.19      albertel  577:     } else {
1.39      albertel  578: 	$result.=&text_arg($description,$name,$token,$size);
1.19      albertel  579:     }
1.39      albertel  580:     return $result;
1.19      albertel  581: }
1.29      matthew   582: 
1.49      www       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";
1.51      www       636: <a href="/cgi-bin/imagechoice.pl?mode=pair&formname=$form&file=$bgfile$formheight$formwidth&formcoord=$element"
1.49      www       637: target="imagechoice">Click Coordinate Pair</a>
                    638: ENDBUTTON
                    639:     return $result;
                    640: }
1.29      matthew   641: #----------------------------------------------------- browse
                    642: sub browse {
                    643:     # insert a link to call up the filesystem browser (lonindexer)
1.42      matthew   644:     my ($id, $mode) = @_;
1.29      matthew   645:     my $form    = 'lonhomework';
1.42      matthew   646:     my $element;
                    647:     if (! defined($mode) || $mode eq 'attribute') {
1.49      www       648:         $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
1.42      matthew   649:     } elsif ($mode eq 'textnode') {  # for data between <tag> ... </tag>
                    650:         $element = &Apache::lonnet::escape('homework_edit_'.
                    651:                                            $Apache::lonxml::curdepth);
                    652:     }
1.29      matthew   653:     my $result = <<"ENDBUTTON";
1.56    ! www       654: <a href=\"javascript:openbrowser('$form','$element')\"\>Select</a>
1.29      matthew   655: ENDBUTTON
                    656:     return $result;
                    657: }
                    658: 
1.30      matthew   659: #----------------------------------------------------- browse
                    660: sub search {
                    661:     # insert a link to call up the filesystem browser (lonindexer)
1.49      www       662:     my ($id, $mode) = @_;
1.30      matthew   663:     my $form    = 'lonhomework';
1.49      www       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:     }
1.30      matthew   671:     my $result = <<"ENDBUTTON";
                    672: <a href=\"javascript:opensearcher('$form','$element')\"\>Search</a>
                    673: ENDBUTTON
                    674:     return $result;
                    675: }
                    676: 
                    677: 
1.1       albertel  678: 1;
                    679: __END__
1.26      harris41  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
1.27      matthew   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.
1.26      harris41  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
1.29      matthew   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
1.30      matthew   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
1.29      matthew   785: the form element $elementname.
1.31      matthew   786: 
1.34      harris41  787: =item *
1.32      albertel  788: editline(tag,data,description,size): Provide a <input type="text" ../> for
1.31      matthew   789: single-line text entry.  This is to be used for text enclosed by tags, not
                    790: arguements/parameters associated with a tag.
1.26      harris41  791: 
                    792: =back
                    793: 
                    794: incomplete...
                    795: 
                    796: =cut

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