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

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

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