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

1.1       albertel    1: # The LearningOnline Network with CAPA 
                      2: # edit mode helpers
1.25      albertel    3: #
1.153   ! golterma    4: # $Id: edit.pm,v 1.152 2014/11/28 18:23:03 raeburn 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.82      www        28: 
1.125     raeburn    29: =pod
                     30: 
1.117     jms        31: =head1 NAME
                     32: 
                     33: Apache::edit - edit mode helpers
                     34: 
                     35: =head1 SYNOPSIS
                     36: 
                     37: Invoked by many homework and xml related modules.
                     38: 
                     39:  &Apache::edit::SUBROUTINENAME(ARGUMENTS);
                     40: 
                     41: =head1 INTRODUCTION
                     42: 
                     43: This module outputs HTML syntax helpful for the rendering of edit
                     44: mode interfaces.
                     45: 
                     46: This is part of the LearningOnline Network with CAPA project
                     47: described at http://www.lon-capa.org.
                     48: 
1.118     jms        49: =head1 SUBROUTINES
1.117     jms        50: 
                     51: =over 4
                     52: 
1.118     jms        53: =item initialize_edit() 
1.117     jms        54: 
1.118     jms        55: initialize edit (set colordepth to zero)
1.117     jms        56: 
1.118     jms        57: =item tag_start($target,$token,$description)
1.117     jms        58: 
1.118     jms        59: provide deletion and insertion lists
1.117     jms        60: for the manipulation of a start tag; return a scalar string
                     61: 
1.118     jms        62: =item tag_end($target,$token,$description)
1.117     jms        63: 
1.118     jms        64: ending syntax corresponding to
1.117     jms        65: &tag_start. return a scalar string.
                     66: 
1.118     jms        67: =item  start_table($token)
1.117     jms        68: 
1.118     jms        69: start table; update colordepth; return scalar string.
1.117     jms        70: 
1.118     jms        71: =item end_table()
1.117     jms        72: 
1.118     jms        73: reduce color depth; end table; return scalar string
1.117     jms        74: 
1.118     jms        75: =item start_spanning_row()
1.117     jms        76: 
1.118     jms        77: start a new table row spanning the 'edit' environment.
1.117     jms        78: 
1.118     jms        79: =item start_row()
1.117     jms        80: 
1.118     jms        81: start a new table row and element. 
1.117     jms        82: 
1.118     jms        83: =item end_row() 
1.117     jms        84: 
1.118     jms        85: end current table element and row.
1.117     jms        86: 
1.118     jms        87: =item movebuttons($target,$token)
1.117     jms        88: 
1.118     jms        89: move-up and move-down buttons; return scalar string
1.117     jms        90: 
1.118     jms        91: =item deletelist($target,$token)
1.117     jms        92: 
1.118     jms        93: provide a yes option in an HTML select element; return scalar string
1.117     jms        94: 
1.118     jms        95: =item handle_delete($space,$target,$token,$tagstack,$parstack,$parser,$safeeval,
                     96: $style)
1.117     jms        97: 
1.118     jms        98: respond to a user delete request by passing relevant stack
1.117     jms        99: and array information to various rendering functions; return a scalar string
                    100: 
1.118     jms       101: =item get_insert_list($token)
                    102: 
                    103: provide an insertion list based on possibilities from lonxml; return a scalar string
1.117     jms       104: 
1.118     jms       105: =item insertlist($target,$token)
1.117     jms       106: 
1.118     jms       107: api that uses get_insert_list; return a scalar string
1.117     jms       108: 
1.118     jms       109: =item handleinsert($token)
1.117     jms       110: 
1.118     jms       111: provide an insertion list based on possibilities from lonxml; return a scalar string
1.117     jms       112: 
1.118     jms       113: =item get_insert_list($token)
1.117     jms       114: 
1.118     jms       115: provide an insertion list based on possibilities from lonxml; return a scalar string
1.117     jms       116: 
1.118     jms       117: =item browse($elementname)
1.117     jms       118: 
1.118     jms       119: provide a link which will open up the filesystem browser (lonindexer) and, once a file is selected, place the result in the form element $elementname.
1.117     jms       120: 
1.118     jms       121: =item search($elementname)
1.117     jms       122: 
1.118     jms       123: provide a link which will open up the filesystem searcher (lonsearchcat) and, once a file is selected, place the result in the form element $elementname.
                    124: 
                    125: =item editline(tag,data,description,size)
                    126: 
                    127: Provide a <input type="text" ../> for single-line text entry.  This is to be used for text enclosed by tags, not arguements/parameters associated with a tag.
1.117     jms       128: 
                    129: =back
                    130: 
                    131: =cut
                    132: 
1.1       albertel  133: package Apache::edit; 
                    134: 
                    135: use strict;
1.92      albertel  136: use Apache::lonnet;
1.32      albertel  137: use HTML::Entities();
1.71      www       138: use Apache::lonlocal;
1.102     www       139: use lib '/home/httpd/lib/perl/';
                    140: use LONCAPA;
                    141:  
1.1       albertel  142: 
1.10      albertel  143: # Global Vars
                    144: # default list of colors to use in editing
                    145: @Apache::edit::colorlist=('#ffffff','#ff0000','#00ff00','#0000ff','#0ff000','#000ff0','#f0000f');
                    146: # depth of nesting of edit
                    147: $Apache::edit::colordepth=0;
1.38      www       148: @Apache::edit::inserttag=();
1.49      www       149: # image-type responses: active background image and curdepth at definition
                    150: $Apache::edit::bgimgsrc='';
                    151: $Apache::edit::bgimgsrccurdepth='';
1.10      albertel  152: 
                    153: sub initialize_edit {
1.63      albertel  154:     $Apache::edit::colordepth=0;
                    155:     @Apache::edit::inserttag=();
1.10      albertel  156: }
                    157: 
1.1       albertel  158: sub tag_start {
1.63      albertel  159:     my ($target,$token,$description) = @_;
                    160:     my $result='';
                    161:     if ($target eq "edit") {
                    162: 	my $tag=$token->[1];
                    163: 	if (!$description) {
1.149     bisitz    164: 	    $description=&mt(&Apache::lonxml::description($token));
1.63      albertel  165: 	    if (!$description) { $description="&lt;$tag&gt;"; }
                    166: 	}
1.153   ! golterma  167:     $result.= &start_table($token)."<tr><td>".&Apache::loncommon::insert_folding_button().
        !           168:         " $description</td><td>".&mt('Delete?')." ".&deletelist($target,$token).
        !           169:         "</td><td>".&insertlist($target,$token);
1.27      matthew   170: #<td>". 
1.22      albertel  171: #  &movebuttons($target,$token).
                    172: #    "</tr><tr><td colspan=\"3\">\n";
1.66      matthew   173: 	my @help = Apache::lonxml::helpinfo($token);
1.63      albertel  174: 	if ($help[0]) {
1.148     golterma  175: 	    $result .= '</td><td class="LC_edit_problem_latexhelper">'.
1.88      albertel  176: 		Apache::loncommon::help_open_topic(@help);
                    177: 	} else { $result .= "</td><td>&nbsp;"; }
1.63      albertel  178: 	$result .= &end_row().&start_spanning_row();
                    179:     }
                    180:     return $result;
1.1       albertel  181: }
                    182: 
                    183: sub tag_end {
1.63      albertel  184:     my ($target,$token,$description) = @_;
                    185:     my $result='';
                    186:     if ($target eq 'edit') {
                    187: 	$result.="</td></tr>".&end_table()."\n";
                    188:     }
                    189:     return $result;
1.4       albertel  190: }
1.1       albertel  191: 
1.10      albertel  192: sub start_table {
1.63      albertel  193:     my ($token)=@_;
1.104     albertel  194:     my $tag = &Apache::lonxml::get_tag($token);
                    195:     
                    196:     my $color = $Apache::lonxml::insertlist{"$tag.color"};
                    197:     &Apache::lonxml::debug(" $tag -- $color");
1.63      albertel  198:     if (!defined($color)) {
                    199: 	$color = $Apache::edit::colorlist[$Apache::edit::colordepth];
                    200:     }
                    201:     $Apache::edit::colordepth++;
                    202:     push(@Apache::edit::inserttag,$token->[1]);
1.148     golterma  203:     my $result='<div>';
1.124     bisitz    204:     $result.='<table bgcolor="'.$color.'" width="97%" border="0" cellspacing="3" cellpadding="2">';
1.63      albertel  205:     return $result;
1.10      albertel  206: }
                    207: 
                    208: sub end_table {
1.63      albertel  209:     $Apache::edit::colordepth--;
                    210:     my $result='</table></div>';
1.148     golterma  211:     $result.='<div><table><tr><td>';
1.63      albertel  212: 
                    213:     my ($tagname,$closingtag);
                    214:     if (defined($Apache::edit::inserttag[-2])) {
                    215: 	$tagname=$Apache::edit::inserttag[-2];
1.105     albertel  216:     } else {
                    217: 	if ($Apache::lonhomework::parsing_a_task) {
                    218: 	    $tagname='Task';
                    219: 	} else {
                    220: 	    $tagname='problem';
                    221: 	}
                    222:     }
1.63      albertel  223:     if (defined($Apache::edit::inserttag[-1])) {
                    224: 	$closingtag=$Apache::edit::inserttag[-1];
                    225:     }
                    226:     $result.=&innerinsertlist('edit',$tagname,$closingtag).
1.94      albertel  227: 	"</td></tr></table></div>";
1.105     albertel  228:     my $last = pop(@Apache::edit::inserttag);
1.63      albertel  229:     return $result;
1.10      albertel  230: }
                    231: 
1.153   ! golterma  232: sub start_spanning_row {
        !           233:     return '<tr name="foldblock_'.$Apache::lonxml::curdepth.
        !           234:     '" style="visibility: \'\'"><td colspan="5" bgcolor="#F0F0F0">';
        !           235: }
1.41      www       236: sub start_row          { return '<tr><td bgcolor="#DDDDDD">';            }
1.27      matthew   237: sub end_row            { return '</td></tr>';          }
                    238: 
1.22      albertel  239: sub movebuttons {
1.63      albertel  240:     my ($target,$token) = @_;
                    241:     my $result='<input type="submit" name="moveup.'.
                    242: 	$Apache::lonxml::curdepth.'" value="Move Up" />';
                    243:     $result.='<input type="submit" name="movedown.'.
                    244: 	$Apache::lonxml::curdepth.'" value="Move Down" />';
                    245:     return $result;
1.22      albertel  246: }
                    247: 
1.8       albertel  248: sub deletelist {
1.63      albertel  249:     my ($target,$token) = @_;
                    250:     my $result = "<select name=\"delete_$Apache::lonxml::curdepth\">
1.14      albertel  251: <option></option>
1.116     bisitz    252: <option>".&mt('yes')."</option>
1.8       albertel  253: </select>";
1.63      albertel  254:     return $result;
1.8       albertel  255: }
                    256: 
1.14      albertel  257: sub handle_delete {
1.92      albertel  258:     if (!$env{"form.delete_$Apache::lonxml::curdepth"}) { return ''; }
1.63      albertel  259:     my ($space,$target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    260:     my $result=0;
                    261:     if ($space) {
                    262: 	my $sub1="$space\:\:delete_$token->[1]";
                    263: 	{
                    264: 	    no strict 'refs';
                    265: 	    if (defined &$sub1) {
                    266: 		$result=&$sub1($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
                    267: 	    }
                    268: 	}
                    269:     }
                    270:     if (!$result) {
                    271: 	my $endtag='/'.$token->[1];
1.97      albertel  272: 	my $bodytext=&Apache::lonxml::get_all_text($endtag,$parser,$style);
1.63      albertel  273: 	$$parser['-1']->get_token();
                    274: 	&Apache::lonxml::debug("Deleting :$bodytext: for $token->[1]");
                    275: 	&Apache::lonxml::end_tag($tagstack,$parstack,$token);
                    276:     }
                    277:     return 1;
1.14      albertel  278: }
                    279: 
1.7       albertel  280: sub get_insert_list {
1.63      albertel  281:     my ($tagname) = @_;
                    282:     my $result='';
1.104     albertel  283:     my @tags= ();
1.63      albertel  284:     #&Apache::lonxml::debug("keys ".join("\n",sort(keys(%Apache::lonxml::insertlist))));
                    285:     if ($Apache::lonxml::insertlist{"$tagname.which"}) {
1.104     albertel  286: 	push (@tags, @{ $Apache::lonxml::insertlist{"$tagname.which"} });
1.63      albertel  287:     }
                    288:     foreach my $namespace (@Apache::lonxml::namespace) {
                    289: 	if ($Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"}) {
1.104     albertel  290: 	    push (@tags, @{ $Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"} });
1.63      albertel  291: 	}
                    292:     }
1.104     albertel  293:     if (@tags) {
1.63      albertel  294: 	my %options;
1.104     albertel  295: 	foreach my $tag (@tags) {
                    296: 	    my $descrip=$Apache::lonxml::insertlist{"$tag.description"};
                    297: 	    my $tagnum =$Apache::lonxml::insertlist{"$tag.num"};
1.63      albertel  298: 	    $options{$descrip} ="<option value=\"$tagnum\">".
1.151     bisitz    299: 		&mt($descrip)."</option>\n";
1.63      albertel  300: 	}
                    301: 	foreach my $option (sort(keys(%options))) {$result.=$options{$option};}
1.88      albertel  302: 	if ($result) { $result='<option selected="selected"></option>'.$result; }
1.63      albertel  303:     }
                    304:     return $result;
1.5       albertel  305: }
                    306: 
1.4       albertel  307: sub insertlist {
1.63      albertel  308:     my ($target,$token) = @_;
                    309:     return &innerinsertlist($target,$token->[1]);
1.38      www       310: }
                    311: 
                    312: sub innerinsertlist {
1.63      albertel  313:     my ($target,$tagname,$closingtag) = @_;
                    314:     my $result;
                    315:     my $after='';
                    316:     if ($closingtag) {
                    317: 	$after='_after_'.$closingtag; 
                    318:     }
                    319:     if ($target eq 'edit') {
                    320: 	my $optionlist= &get_insert_list($tagname);
                    321: 	if ($optionlist) {
1.116     bisitz    322: 	    $result = &mt('Insert:')."
1.63      albertel  323:             <select name=\"insert$after\_$Apache::lonxml::curdepth\">
                    324:                   $optionlist
                    325:             </select>"
                    326: 	} else {
                    327: 	    $result="&nbsp;";
                    328: 	}
1.6       albertel  329:     }
1.63      albertel  330:     return $result;
1.6       albertel  331: }
                    332: 
1.7       albertel  333: sub handle_insert {
1.92      albertel  334:     if ($env{"form.insert_$Apache::lonxml::curdepth"} eq '') { return ''; }
                    335:     my $tagnum = $env{"form.insert_$Apache::lonxml::curdepth"};
1.104     albertel  336:     return &do_insert($tagnum);
1.38      www       337: }
                    338: 
                    339: sub handle_insertafter {
1.63      albertel  340:     my $tagname=shift;
1.104     albertel  341:     if ($env{"form.insert_after_$tagname\_$Apache::lonxml::curdepth"} eq '') {
                    342: 	return '';
                    343:     }
                    344:     my $tagnum =$env{"form.insert_after_$tagname\_$Apache::lonxml::curdepth"};
1.105     albertel  345:     return &do_insert($tagnum,1);
1.104     albertel  346: }
                    347: 
                    348: sub do_insert {
1.105     albertel  349:     my ($tagnum,$after) = @_;
1.63      albertel  350:     my $result;
1.104     albertel  351: 
                    352:     my $newtag = $Apache::lonxml::insertlist{"$tagnum.tag"};
                    353:     my $func   = $Apache::lonxml::insertlist{"$newtag.function"};
1.63      albertel  354:     if ($func eq 'default') {
                    355: 	my $namespace;
                    356: 	if ($newtag =~ /::/) { ($namespace,$newtag) = split(/::/,$newtag); }
1.105     albertel  357: 	my $depth = scalar(@Apache::lonxml::depthcounter);
                    358: 	$depth -- if ($after);
                    359: 	my $inset = "\t"x$depth;
1.126     www       360: 	$result.="\n$inset<$newtag></$newtag>";
1.38      www       361:     } else {
1.63      albertel  362: 	if (defined(&$func)) {
                    363: 	    {
                    364: 		no strict 'refs';
                    365: 		$result.=&$func();
                    366: 	    }
                    367: 	} else {
1.104     albertel  368: 	    &Apache::lonxml::error("Unable to insert tag $newtag, $func was not defined. ($tagnum)");
1.63      albertel  369: 	}
1.5       albertel  370:     }
1.63      albertel  371:     return $result;
1.69      albertel  372: }
                    373: 
                    374: sub insert_img {
                    375:     return '
                    376:     <img />';
1.16      albertel  377: }
                    378: 
                    379: sub insert_responseparam {
1.63      albertel  380:     return '
1.16      albertel  381:     <responseparam />';
1.5       albertel  382: }
                    383: 
1.87      albertel  384: sub insert_parameter {
                    385:     return '
                    386:     <parameter />';
                    387: }
                    388: 
1.24      albertel  389: sub insert_formularesponse {
1.63      albertel  390:     return '
1.24      albertel  391: <formularesponse answer="" samples="">
1.86      albertel  392:     <responseparam description="Numerical Tolerance" type="tolerance" default="0.00001" name="tol" />
                    393:     <textline size="25"/>
1.24      albertel  394:     <hintgroup>
1.78      www       395:     <startouttext /><endouttext />
1.24      albertel  396:     </hintgroup>
                    397: </formularesponse>';
                    398: }
                    399: 
1.129     www       400: sub insert_functionplotresponse {
                    401:     return '
                    402: <functionplotresponse>
1.133     www       403: <functionplotelements>
                    404: </functionplotelements>
                    405: <functionplotruleset>
                    406: </functionplotruleset>
1.129     www       407: </functionplotresponse>';
                    408: }
                    409: 
1.131     www       410: sub insert_spline {
                    411:     return '
                    412: <spline />';
                    413: }
                    414: 
                    415: sub insert_backgroundplot {
                    416:     return '
                    417: <backgroundplot />';
                    418: }
                    419: 
1.136     www       420: sub insert_plotobject {
                    421:     return '
                    422: <plotobject />';
                    423: }
                    424: 
                    425: sub insert_plotvector {
                    426:     return '
                    427: <plotvector />';
                    428: }
                    429: 
1.141     www       430: sub insert_drawvectorsum {
                    431:     return '
                    432: <drawvectorsum />';
                    433: }
                    434: 
                    435: 
1.132     www       436: sub insert_functionplotrule {
1.131     www       437:     return '
1.132     www       438: <functionplotrule />';
1.131     www       439: }
                    440: 
1.137     www       441: sub insert_functionplotvectorrule {
                    442:     return '
                    443: <functionplotvectorrule />';
                    444: }
                    445: 
                    446: sub insert_functionplotvectorsumrule {
                    447:     return '
                    448: <functionplotvectorsumrule />';
                    449: }
                    450: 
1.138     www       451: sub insert_functionplotcustomrule {
                    452:     return '
                    453: <functionplotcustomrule>
                    454: <answer type="loncapa/perl">
                    455: # &fpr_val("label"), &fpr_f($x), &fpr_dfdx($x), &fpr_d2fdx2($x)
                    456: # ($xs,$xe,$ys,$ye)=&fpr_vectorcoords("Name"), ($x,$y)=&fpr_objectcoords("Name")
                    457: # &fpr_vectorlength("Name"), &fpr_vectorangle("Name")
                    458:  
                    459: # Return 0 or 1
                    460: return 1;
                    461: </answer>
                    462: </functionplotcustomrule>';
                    463: }
                    464: 
1.133     www       465: sub insert_functionplotruleset {
                    466:     return '
                    467: <functionplotruleset>
                    468: <functionplotrule />
                    469: </functionplotruleset>';
                    470: }
1.131     www       471: 
1.133     www       472: sub insert_functionplotelements {
                    473:     return '
                    474: <functionplotelements>
                    475: <spline />
                    476: </functionplotelements>';
                    477: }
1.131     www       478: 
1.15      albertel  479: sub insert_numericalresponse {
1.63      albertel  480:     return '
1.15      albertel  481: <numericalresponse answer="">
1.90      www       482: <responseparam type="tolerance" default="5%" name="tol" description="Numerical Tolerance" />
                    483: <responseparam name="sig" type="int_range,0-16" default="0,15" description="Significant Figures" />
1.15      albertel  484:     <textline />
                    485:     <hintgroup>
1.78      www       486:     <startouttext /><endouttext />
1.15      albertel  487:     </hintgroup>
                    488: </numericalresponse>';
                    489: }
                    490: 
1.145     kruse     491: sub insert_externalresponse {
                    492:     return '
                    493: <externalresponse url="" answer="" answerdisplay="" form="">
                    494:     <textfield spellcheck="none" />
                    495: </externalresponse>';
                    496: }
                    497: 
1.96      albertel  498: sub insert_customresponse {
1.95      albertel  499:     return '
1.96      albertel  500: <customresponse>
1.95      albertel  501:     <answer type="loncapa/perl">
                    502:     </answer>
                    503:     <textline />
                    504:     <hintgroup>
                    505:     <startouttext /><endouttext />
                    506:     </hintgroup>
1.96      albertel  507: </customresponse>';
1.95      albertel  508: }
                    509: 
1.96      albertel  510: sub insert_customresponse_answer {
1.95      albertel  511:     return '
                    512:     <answer type="loncapa/perl">
                    513:     </answer>
                    514: ';
                    515: }
                    516: 
1.106     albertel  517: sub insert_customhint {
                    518:     return '
                    519:         <customhint>
                    520:             <answer type="loncapa/perl">
                    521:             </answer>
                    522:         </customhint>';
                    523: }
                    524: 
                    525: sub insert_customhint_answer {
                    526:     return '
                    527:             <answer type="loncapa/perl">
                    528:             </answer>
                    529: ';
                    530: }
                    531: 
                    532: sub insert_mathresponse {
                    533:     return '
                    534: <mathresponse>
                    535:     <answer>
                    536:     </answer>
                    537:     <textline />
                    538:     <hintgroup>
                    539:         <startouttext />
                    540:         <endouttext />
                    541:     </hintgroup>
                    542: </mathresponse>';
                    543: }
                    544: 
                    545: sub insert_mathresponse_answer {
                    546:     return '
                    547:     <answer>
                    548:     </answer>
                    549: ';
                    550: }
                    551: 
                    552: sub insert_mathhint {
                    553:     return '
                    554:         <mathhint>
                    555:             <answer>
                    556:             </answer>
                    557:         </mathhint>';
                    558: }
                    559: 
                    560: sub insert_mathhint_answer {
                    561:     return '
                    562:             <answer>
                    563:             </answer>
                    564: ';
                    565: }
                    566: 
1.18      albertel  567: sub insert_stringresponse {
1.63      albertel  568:     return '
1.18      albertel  569: <stringresponse answer="" type="">
                    570:     <textline />
                    571:     <hintgroup>
1.78      www       572:     <startouttext /><endouttext />
1.18      albertel  573:     </hintgroup>
                    574: </stringresponse>';
1.36      albertel  575: }
                    576: 
                    577: sub insert_essayresponse {
1.63      albertel  578:     return '
1.36      albertel  579: <essayresponse>
                    580:     <textfield></textfield>
                    581: </essayresponse>';
1.54      albertel  582: }
                    583: 
                    584: sub insert_imageresponse {
1.63      albertel  585:     return '
1.54      albertel  586: <imageresponse max="1">
                    587:     <foilgroup>
1.89      albertel  588:       <foil>
                    589:       </foil>
1.54      albertel  590:     </foilgroup>
                    591:     <hintgroup>
1.78      www       592:     <startouttext /><endouttext />
1.54      albertel  593:     </hintgroup>
                    594: </imageresponse>';
1.18      albertel  595: }
                    596: 
1.7       albertel  597: sub insert_optionresponse {
1.63      albertel  598:     return '
1.7       albertel  599: <optionresponse max="10">
                    600:     <foilgroup options="">
1.89      albertel  601:       <foil>
                    602:          <startouttext /><endouttext />
                    603:       </foil>
1.7       albertel  604:     </foilgroup>
1.14      albertel  605:     <hintgroup>
1.78      www       606:     <startouttext /><endouttext />
1.14      albertel  607:     </hintgroup>
1.7       albertel  608: </optionresponse>';
1.1       albertel  609: }
                    610: 
1.72      albertel  611: sub insert_organicresponse {
                    612:     return '
                    613: <organicresponse>
                    614:     <textline />
                    615:     <hintgroup>
1.78      www       616:     <startouttext /><endouttext />
1.72      albertel  617:     </hintgroup>
                    618: </organicresponse>';
                    619: }
                    620: 
                    621: sub insert_organicstructure {
                    622:     return '
                    623: <organicstructure />
                    624: ';
                    625: }
                    626: 
1.23      albertel  627: sub insert_radiobuttonresponse {
1.63      albertel  628:     return '
1.23      albertel  629: <radiobuttonresponse max="10">
                    630:     <foilgroup>
1.89      albertel  631:       <foil>
                    632:          <startouttext /><endouttext />
                    633:       </foil>
1.23      albertel  634:     </foilgroup>
                    635:     <hintgroup>
1.78      www       636:     <startouttext /><endouttext />
1.23      albertel  637:     </hintgroup>
                    638: </radiobuttonresponse>';
1.72      albertel  639: }
                    640: 
                    641: sub insert_reactionresponse {
                    642:     return '
                    643: <reactionresponse>
                    644:     <textline />
                    645:     <hintgroup>
1.78      www       646:     <startouttext /><endouttext />
1.72      albertel  647:     </hintgroup>
                    648: </reactionresponse>';
1.43      albertel  649: }
                    650: 
                    651: sub insert_rankresponse {
1.63      albertel  652:     return '
1.43      albertel  653: <rankresponse max="10">
                    654:     <foilgroup options="">
1.89      albertel  655:       <foil>
                    656:          <startouttext /><endouttext />
                    657:       </foil>
1.43      albertel  658:     </foilgroup>
                    659:     <hintgroup>
1.78      www       660:     <startouttext /><endouttext />
1.43      albertel  661:     </hintgroup>
                    662: </rankresponse>';
1.23      albertel  663: }
                    664: 
1.44      albertel  665: sub insert_matchresponse {
1.63      albertel  666:     return '
1.44      albertel  667: <matchresponse max="10">
                    668:     <foilgroup options="">
                    669:       <itemgroup>
1.146     bisitz    670:         <item>
                    671:           <startouttext /><endouttext />
                    672:         </item>
1.44      albertel  673:       </itemgroup>
1.89      albertel  674:       <foil>
                    675:          <startouttext /><endouttext />
                    676:       </foil>
1.44      albertel  677:     </foilgroup>
                    678:     <hintgroup>
1.78      www       679:     <startouttext /><endouttext />
1.44      albertel  680:     </hintgroup>
                    681: </matchresponse>';
                    682: }
                    683: 
1.127     www       684: sub insert_startpartmarker { return '<startpartmarker />'; }
                    685: sub insert_endpartmarker { return '<endpartmarker />'; }
                    686: 
1.21      albertel  687: sub insert_displayduedate { return '<displayduedate />'; }
                    688: sub insert_displaytitle   { return '<displaytitle />'; }
1.22      albertel  689: sub insert_hintpart {
1.63      albertel  690:     return '
1.22      albertel  691: <hintpart on="default">
1.90      www       692:     <startouttext/><endouttext />
1.22      albertel  693: </hintpart>';
1.67      albertel  694: }
                    695: 
                    696: sub insert_hintgroup {
                    697:   return '
                    698: <hintgroup>
1.78      www       699:     <startouttext /><endouttext />
1.67      albertel  700: </hintgroup>';
1.22      albertel  701: }
                    702: 
                    703: sub insert_numericalhint {
1.63      albertel  704:     return '
1.22      albertel  705: <numericalhint>
                    706: </numericalhint>';
1.46      albertel  707: }
                    708: 
1.123     www       709: sub insert_reactionhint {
                    710:     return '
                    711: <reactionhint>
                    712: </reactionhint>';
                    713: }
                    714: 
                    715: sub insert_organichint {
                    716:     return '
                    717: <organichint>
                    718: </organichint>';
                    719: }
                    720: 
1.46      albertel  721: sub insert_stringhint {
1.63      albertel  722:     return '
1.46      albertel  723: <stringhint>
                    724: </stringhint>';
                    725: }
                    726: 
                    727: sub insert_formulahint {
1.63      albertel  728:     return '
1.46      albertel  729: <formulahint>
                    730: </formulahint>';
1.37      albertel  731: }
                    732: 
                    733: sub insert_radiobuttonhint {
1.63      albertel  734:     return '
1.37      albertel  735: <radiobuttonhint>
                    736: </radiobuttonhint>';
1.50      albertel  737: }
                    738: 
                    739: sub insert_optionhint {
1.63      albertel  740:     return '
1.50      albertel  741: <optionhint>
                    742: </optionhint>';
1.22      albertel  743: }
1.21      albertel  744: 
1.23      albertel  745: sub insert_startouttext {
1.78      www       746:     return "<startouttext /><endouttext />";
1.23      albertel  747: }
                    748: 
                    749: sub insert_script {
1.78      www       750:     return "\n<script type=\"loncapa/perl\"></script>";
1.23      albertel  751: }
                    752: 
1.98      albertel  753: sub js_change_detection {
                    754:     my $unsaved=&mt("There are unsaved changes");
                    755:     return (<<SCRIPT);
                    756: <script type="text/javascript">
1.142     raeburn   757: // <![CDATA[
1.98      albertel  758: var clean = true;
                    759: var is_submit = false;
1.99      albertel  760: var still_ask = false;
1.98      albertel  761: function compareForm(event_) {
                    762:         if (!event_ && window.event) {
                    763:           event_ = window.event;
                    764:         }
1.99      albertel  765: 	if ((!is_submit || (is_submit && still_ask)) && !clean) {
                    766: 	    still_ask = false;
                    767: 	    is_submit = false;
1.98      albertel  768:             event_.returnValue = "$unsaved";
                    769:             return "$unsaved";
                    770:         }
                    771: }
                    772: function unClean() {
                    773:      clean=false;
                    774: }
                    775: window.onbeforeunload = compareForm;
1.142     raeburn   776: // ]]>
1.98      albertel  777: </script>
                    778: SCRIPT
                    779: }
                    780: 
                    781: sub form_change_detection {
                    782:     return ' onsubmit="is_submit=true;" ';
                    783: }
                    784: 
                    785: sub element_change_detection {
                    786:     return ' onchange="unClean();" ';
                    787: }
                    788: 
1.99      albertel  789: sub submit_ask_anyway {
1.113     raeburn   790:     my ($extra_action) = @_;
1.153   ! golterma  791:     my $resource = $env{'request.ambiguous'};
        !           792:     return ' onclick="saveScrollPosition(\''.$resource.'\');still_ask=true;'.$extra_action.';" ';
1.99      albertel  793: }
                    794: 
1.134     www       795: sub submit_dont_ask {
                    796:     my ($extra_action) = @_;
1.153   ! golterma  797:     my $resource = $env{'request.ambiguous'};
        !           798:     return ' onclick="saveScrollPosition(\''.$resource.'\');is_submit=true;'.$extra_action.';" ';
1.134     www       799: }
                    800: 
1.152     raeburn   801: sub js_update_linknum {
                    802:     return (<<SCRIPT);
                    803: <script type="text/javascript">
                    804: // <![CDATA[
                    805: function updateNumber(name,index,caller,textprompt) {
                    806:     var pickitem = document.getElementById(name+'_'+index);
                    807:     var picknumtext = document.getElementById(name+'_numtext_'+index);
                    808:     if (pickitem.checked) {
                    809:         var showval = '';
                    810:         if (pickitem.value != 'nochoice') {
                    811:             showval = pickitem.value;
                    812:         } 
                    813:         var picknum=prompt(textprompt,showval);
                    814:         if (picknum == '' || picknum == null) {
                    815:             if (caller == 'check') {
                    816:                 pickitem.checked=false;
                    817:                 pickitem.value='nochoice';
                    818:             }
                    819:         } else {
                    820:             picknum.toString();
                    821:             var regexdigit=/^\\d+\$/;
                    822:             if (regexdigit.test(picknum)) {
                    823:                 pickitem.value = picknum;
                    824:                 picknumtext.innerHTML = '&nbsp;<a href="javascript:updateNumber(\\''+name+'\\',\\''+index+'\\',\\'link\\',\\''+textprompt+'\\');">'+picknum+'</a>';
                    825:             } else {
                    826:                 if (caller == 'check') {
                    827:                     pickitem.checked=false;
                    828:                     pickitem.value='nochoice';
                    829:                 }
                    830:                 return;
                    831:             }
                    832:         }
                    833:     } else {
                    834:         pickitem.value = '';
                    835:         picknumtext.innerHTML = '';
                    836:     }
                    837: }
                    838: 
                    839: // ]]>
                    840: </script>
                    841: SCRIPT
                    842: 
                    843: }
1.134     www       844: 
1.25      albertel  845: sub textarea_sizes {
1.63      albertel  846:     my ($data)=@_;
                    847:     my $count=0;
                    848:     my $maxlength=-1;
                    849:     foreach (split ("\n", $$data)) {
                    850: 	$count+=int(length($_)/79);
                    851: 	$count++;
                    852: 	if (length($_) > $maxlength) { $maxlength = length($_); }
                    853:     }
                    854:     my $rows = $count;
                    855:     my $cols = $maxlength;
                    856:     return ($rows,$cols);
1.25      albertel  857: }
                    858: 
1.32      albertel  859: sub editline {
1.31      matthew   860:     my ($tag,$data,$description,$size)=@_;
1.81      albertel  861:     $data=&HTML::Entities::encode($data,'<>&"');
1.112     albertel  862:     if ($description) { $description=$description."<br />"; }
1.98      albertel  863:     my $change_code = &element_change_detection();
1.31      matthew   864:     my $result = <<"END";
                    865: $description
                    866: <input type="text" name="homework_edit_$Apache::lonxml::curdepth" 
1.98      albertel  867:        value="$data" size="$size" $change_code />
1.31      matthew   868: END
                    869:     return $result;
                    870: }
                    871: 
1.2       albertel  872: sub editfield {
1.82      www       873:     my ($tag,$data,$description,$minwidth,$minheight,$usehtmlarea)=@_;
1.22      albertel  874: 
1.63      albertel  875:     my ($rows,$cols)=&textarea_sizes(\$data);
1.128     raeburn   876:     my $textareaclass;
                    877:  
                    878:     if (&Apache::lonhtmlcommon::htmlareabrowser() && $usehtmlarea) { 
1.84      www       879: 	$rows+=7;      # make room for HTMLarea
                    880: 	$minheight+=7; # make room for HTMLarea
1.128     raeburn   881:         $textareaclass = ' class="LC_richDefaultOff"';
1.84      www       882:     }
1.63      albertel  883:     if ($cols > 80) { $cols = 80; }
                    884:     if ($cols < $minwidth ) { $cols = $minwidth; }
                    885:     if ($rows < $minheight) { $rows = $minheight; }
1.144     bisitz    886:     if ($description) { $description='<br />'.&mt($description).'<br />'; }
1.128     raeburn   887: 
1.105     albertel  888:     # remove typesetting whitespace from between data and the end tag
                    889:     # to make the edit look prettier
                    890:     $data =~ s/\n?[ \t]*$//;
                    891: 
1.135     bisitz    892:     return $description."\n".'<textarea style="width:99%" rows="'.$rows.
1.63      albertel  893: 	'" cols="'.$cols.'" name="homework_edit_'.
1.82      www       894: 	$Apache::lonxml::curdepth.'" id="homework_edit_'.
1.128     raeburn   895: 	$Apache::lonxml::curdepth.'" '.&element_change_detection().
                    896:         $textareaclass.'>'.
1.85      www       897: 	&HTML::Entities::encode($data,'<>&"').'</textarea>'.
1.144     bisitz    898:         ($usehtmlarea?'<br />'.&Apache::lonhtmlcommon::spelllink('lonhomework',
                    899:                                    'homework_edit_'.$Apache::lonxml::curdepth):'')."\n";
1.2       albertel  900: }
                    901: 
                    902: sub modifiedfield {
1.70      albertel  903:     my ($endtag,$parser) = @_;
1.63      albertel  904:     my $result;
1.92      albertel  905:     $result=$env{"form.homework_edit_$Apache::lonxml::curdepth"};
1.70      albertel  906:     my $bodytext=&Apache::lonxml::get_all_text($endtag,$parser);
                    907:     # textareas throw away intial \n 
1.105     albertel  908:     if ($bodytext=~/^\n/) {
                    909: 	$result="\n".$result;
                    910:     }
                    911:     # if there is typesetting whitespace from between the data and the end tag
                    912:     # restore to keep the source looking pretty
                    913:     if ($bodytext =~ /(\n?[ \t]*)$/) {
                    914: 	$result .= $1;
                    915:     }
1.63      albertel  916:     return $result;
1.2       albertel  917: }
                    918: 
1.15      albertel  919: # Returns a 1 if the token has been modified and you should rebuild the tag
1.12      albertel  920: # side-effects, will modify the $token if new values are found
                    921: sub get_new_args {
1.61      albertel  922:     my ($token,$parstack,$safeeval,@args)=@_;
                    923:     my $rebuild=0;
                    924:     foreach my $arg (@args) {
1.63      albertel  925: 	#just want the string that it was set to
                    926: 	my $value=$token->[2]->{$arg};
                    927: 	my $element=&html_element_name($arg);
1.92      albertel  928: 	my $newvalue=$env{"form.$element"};
1.63      albertel  929: 	&Apache::lonxml::debug("for:$arg: cur is :$value: new is :$newvalue:");
                    930: 	if (defined($newvalue) && $value ne $newvalue) {
                    931: 	    if (ref($newvalue) eq 'ARRAY') {
                    932: 		$token->[2]->{$arg}=join(',',@$newvalue);
                    933: 	    } else {
                    934: 		$token->[2]->{$arg}=$newvalue;
                    935: 	    }
1.79      albertel  936: 	    $rebuild=1;
1.111     albertel  937: 	    # add new attributes to the of the attribute seq
                    938: 	    if (!grep { $arg eq $_ } (@{ $token->[3] })) {
                    939: 		push(@{ $token->[3] },$arg);
                    940: 	    }
1.79      albertel  941: 	} elsif (!defined($newvalue) && defined($value)) {
                    942: 	    delete($token->[2]->{$arg});
1.63      albertel  943: 	    $rebuild=1;
1.61      albertel  944: 	}
1.12      albertel  945:     }
1.63      albertel  946:     return $rebuild;
1.12      albertel  947: }
                    948: 
1.15      albertel  949: # looks for /> on start tags
1.12      albertel  950: sub rebuild_tag {
1.63      albertel  951:     my ($token) = @_;
                    952:     my $result;
                    953:     if ($token->[0] eq 'S') {
                    954: 	$result = '<'.$token->[1];
1.109     albertel  955: 	foreach my $attribute (@{ $token->[3] }) {
                    956: 	    my $value = $token->[2]{$attribute};
1.111     albertel  957: 	    next if ($value eq '');
1.109     albertel  958: 	    $value =~s/^\s+|\s+$//g;
                    959: 	    $value =~s/\"//g;
                    960: 	    &Apache::lonxml::debug("setting :$attribute: to  :$value:");
                    961: 	    $result.=' '.$attribute.'="'.$value.'"';
1.63      albertel  962: 	}
                    963: 	if ($token->[4] =~ m:/>$:) {
                    964: 	    $result.=' />';
                    965: 	} else {
                    966: 	    $result.='>';
                    967: 	}
                    968:     } elsif ( $token->[0] eq 'E' ) {
                    969: 	$result = '</'.$token->[1].'>';
1.12      albertel  970:     }
1.63      albertel  971:     return $result;
1.12      albertel  972: }
1.13      albertel  973: 
1.47      matthew   974: sub html_element_name {
                    975:     my ($name) = @_;
1.48      albertel  976:     return $name.'_'.$Apache::lonxml::curdepth;
                    977: }
                    978: 
                    979: sub hidden_arg {
                    980:     my ($name,$token) = @_;
                    981:     my $result;
                    982:     my $arg=$token->[2]{$name};
                    983:     $result='<input name="'.&html_element_name($name).
                    984: 	'" type="hidden" value="'.$arg.'" />';
1.61      albertel  985:     return $result;
                    986: }
                    987: 
                    988: sub checked_arg {
1.152     raeburn   989:     my ($description,$name,$list,$token,$onclick,$useid) = @_;
1.61      albertel  990:     my $result;
                    991:     my $optionlist="";
                    992:     my $allselected=$token->[2]{$name};
1.71      www       993:     $result=&mt($description);
1.61      albertel  994:     foreach my $option (@$list) {
                    995: 	my ($value,$text);
                    996: 	if ( ref($option) eq 'ARRAY') {
                    997: 	    $value='value="'.$$option[0].'"';
1.150     bisitz    998: 	    $text=&mt($$option[1]);
1.61      albertel  999: 	    $option=$$option[0];
                   1000: 	} else {
1.150     bisitz   1001: 	    $text=&mt($option);
1.61      albertel 1002: 	    $value='value="'.$option.'"';
                   1003: 	}
1.143     bisitz   1004:         $result.=' <span class="LC_edit_opt"><label><input type="checkbox" '.$value.' name="'.
1.119     raeburn  1005: 	    &html_element_name($name).'"';
1.61      albertel 1006: 	foreach my $selected (split(/,/,$allselected)) {
                   1007: 	    if ( $selected eq $option ) {
1.119     raeburn  1008: 		$result.=' checked="checked" ';
1.61      albertel 1009: 		last;
                   1010: 	    }
                   1011: 	}
1.152     raeburn  1012:         if ($useid) {
                   1013:             $result .= ' id="'.&html_element_name($name).'" ';
                   1014:         }
                   1015: 	$result.=&element_change_detection().$onclick.' />'.$text.'</label></span>'."\n";
1.61      albertel 1016:     }
1.48      albertel 1017:     return $result;
1.47      matthew  1018: }
                   1019: 
1.13      albertel 1020: sub text_arg {
1.140     foxr     1021:     my ($description,$name,$token,$size, $class) = @_;
1.63      albertel 1022:     my $result;
                   1023:     if (!defined $size) { $size=20; }
                   1024:     my $arg=$token->[2]{$name};
1.71      www      1025:     $result=&mt($description).'&nbsp;<input name="'.&html_element_name($name).
1.140     foxr     1026: 	'" type="text" value="'.$arg.'" size="'.$size.'" ';
                   1027:     if (defined $class) {
                   1028: 	$result .= 'class="' . $class . '" ';
                   1029:     }
                   1030:     $result .=	&element_change_detection().'/>';
1.143     bisitz   1031:     return ' <span class="LC_edit_opt">'.$result.'</span>';
1.13      albertel 1032: }
                   1033: 
                   1034: sub select_arg {
1.39      albertel 1035:     my ($description,$name,$list,$token) = @_;
                   1036:     my $result;
                   1037:     my $optionlist="";
                   1038:     my $selected=$token->[2]{$name};
1.121     raeburn  1039:     if (ref($list) eq 'ARRAY') {
                   1040:         foreach my $option (@{$list}) {
                   1041: 	    my ($text,$value);
                   1042: 	    if (ref($option) eq 'ARRAY') {
                   1043: 	        $value='value="'.&HTML::Entities::encode($option->[0]).'"';
                   1044: 	        $text=$option->[1];
                   1045: 	        $option=$option->[0];
                   1046: 	    } else {
                   1047: 	        $text=$option;
                   1048: 	        $value='value="'.&HTML::Entities::encode($option,'\'"&<>').'"';
                   1049: 	    }
                   1050: 	    if ( $selected eq $option ) {
                   1051: 	        $optionlist.="<option $value selected=\"selected\">".&mt($text)."</option>\n";
                   1052: 	    } else {
                   1053: 	        $optionlist.="<option $value >".&mt($text)."</option>\n";
                   1054: 	    }
                   1055:         }
1.13      albertel 1056:     }
1.143     bisitz   1057:     $result.=' <span class="LC_edit_opt">'.&mt($description).'&nbsp;<select name="'.
1.98      albertel 1058: 	&html_element_name($name).'" '.&element_change_detection().' >
1.13      albertel 1059:        '.$optionlist.'
1.119     raeburn  1060:       </select></span>';
1.39      albertel 1061:     return $result;
1.13      albertel 1062: }
                   1063: 
1.19      albertel 1064: sub select_or_text_arg {
1.39      albertel 1065:     my ($description,$name,$list,$token,$size) = @_;
                   1066:     my $result;
                   1067:     my $optionlist="";
                   1068:     my $found=0;
                   1069:     my $selected=$token->[2]{$name};
1.121     raeburn  1070:     if (ref($list) eq 'ARRAY') {
                   1071:         foreach my $option (@{$list}) {
                   1072: 	    my ($text,$value);
                   1073: 	    if (ref($option) eq 'ARRAY') {
                   1074: 	        $value='value="'.&HTML::Entities::encode($option->[0]).'"';
                   1075: 	        $text=$option->[1];
                   1076: 	        $option=$option->[0];
                   1077: 	    } else {
                   1078: 	        $text=$option;
                   1079: 	        $value='value="'.&HTML::Entities::encode($option,'\'"&<>').'"';
                   1080: 	    }
                   1081: 	    if ( $selected eq $option ) {
                   1082: 	        $optionlist.="<option $value selected=\"selected\">$text</option>\n";
                   1083: 	        $found=1;
                   1084: 	    } else {
                   1085: 	        $optionlist.="<option $value>$text</option>\n";
                   1086: 	    }
                   1087:         }
1.39      albertel 1088:     }
1.60      www      1089:     $optionlist.="<option value=\"TYPEDINVALUE\"".
1.88      albertel 1090:  	((!$found)?' selected="selected"':'').
1.73      www      1091:  	">".&mt('Type-in value')."</option>\n";
1.60      www      1092: #
1.98      albertel 1093:     my $change_code=&element_change_detection();
1.60      www      1094:     my $element=&html_element_name($name);
                   1095:     my $selectelement='select_list_'.$element;
                   1096:     my $typeinelement='type_in_'.$element;
                   1097:     my $typeinvalue=($found?'':$selected);
                   1098: #
                   1099:     my $hiddenvalue='this.form.'.$element.'.value';
                   1100:     my $selectedindex='this.form.'.$selectelement.'.selectedIndex';
                   1101:     my $selectedvalue='this.form.'.$selectelement.
                   1102: 	     '.options['.$selectedindex.'].value';
                   1103:     my $typedinvalue='this.form.'.$typeinelement.'.value';
                   1104:     my $selecttypeinindex='this.form.'.$selectelement.'.options.length';
1.71      www      1105:     $description=&mt($description);
1.60      www      1106: #
                   1107:     return (<<ENDSELECTORTYPE);
1.143     bisitz   1108:  <span class="LC_edit_opt">
1.60      www      1109: $description
                   1110: &nbsp;<select name="$selectelement"
1.147     bisitz   1111: onchange="if ($selectedvalue!='TYPEDINVALUE') { $hiddenvalue=$selectedvalue; $typedinvalue=''; }" >
1.60      www      1112: $optionlist
                   1113: </select>
                   1114: <input type="text" size="$size" name="$typeinelement"
                   1115:        value="$typeinvalue" 
1.147     bisitz   1116: onchange="$hiddenvalue=$typedinvalue;"
                   1117: onfocus="$selectedindex=$selecttypeinindex-1;" />
1.98      albertel 1118: <input type="hidden" name="$element" value="$selected" $change_code />
1.119     raeburn  1119: </span>
1.60      www      1120: ENDSELECTORTYPE
1.19      albertel 1121: }
1.29      matthew  1122: 
1.49      www      1123: #----------------------------------------------------- image coordinates
                   1124: # single image coordinates, x, y 
                   1125: sub entercoords {
1.80      albertel 1126:     my ($idx,$idy,$mode,$width,$height) = @_;
1.49      www      1127:     unless ($Apache::edit::bgimgsrc) { return ''; }
                   1128:     if ($idx) { $idx.='_'; }
                   1129:     if ($idy) { $idy.='_'; }
1.102     www      1130:     my $bgfile=&escape(&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$Apache::edit::bgimgsrc));
1.49      www      1131:     my $form    = 'lonhomework';
                   1132:     my $element;
                   1133:     if (! defined($mode) || $mode eq 'attribute') {
1.102     www      1134:         $element = &escape("$Apache::lonxml::curdepth");
1.49      www      1135:     } elsif ($mode eq 'textnode') {  # for data between <tag> ... </tag>
1.102     www      1136:         $element = &escape('homework_edit_'.
1.49      www      1137:                                            $Apache::lonxml::curdepth);
                   1138:     }
1.80      albertel 1139:     my $id=$Apache::lonxml::curdepth;
                   1140:     my %data=("imagechoice.$id.type"      =>'point',
                   1141: 	      "imagechoice.$id.formname"  =>$form,
                   1142: 	      "imagechoice.$id.formx"     =>"$idx$element",
                   1143: 	      "imagechoice.$id.formy"     =>"$idy$element",
                   1144: 	      "imagechoice.$id.file"      =>$bgfile,
                   1145: 	      "imagechoice.$id.formcoord" =>$element);
1.49      www      1146:     if ($height) {
1.80      albertel 1147: 	$data{"imagechoice.$id.formheight"}=$height.'_'.
                   1148: 	    $Apache::edit::bgimgsrccurdepth;
1.49      www      1149:     }
                   1150:     if ($width) {
1.80      albertel 1151: 	$data{"imagechoice.$id.formwidth"}=$width.'_'.
                   1152: 	    $Apache::edit::bgimgsrccurdepth;
1.49      www      1153:     }
1.114     raeburn  1154:     &Apache::lonnet::appenv(\%data);
1.80      albertel 1155:     my $text="Click Coordinates";
                   1156:     my $result='<a href="/adm/imagechoice?token='.$id.'" target="imagechoice">'.$text.'</a>';
1.49      www      1157:     return $result;
                   1158: }
                   1159: 
1.77      albertel 1160: # coordinates (x1,y1)-(x2,y2)...
                   1161: # mode can be either box, or polygon
                   1162: sub entercoord {
                   1163:     my ($idx,$mode,$width,$height,$type) = @_;
1.49      www      1164:     unless ($Apache::edit::bgimgsrc) { return ''; }
1.102     www      1165:     my $bgfile=&escape(&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$Apache::edit::bgimgsrc));
1.75      albertel 1166:     my $form    = 'lonhomework';
                   1167:     my $element;
                   1168:     if (! defined($mode) || $mode eq 'attribute') {
1.102     www      1169:         $element = &escape("$idx\_$Apache::lonxml::curdepth");
1.75      albertel 1170:     } elsif ($mode eq 'textnode') {  # for data between <tag> ... </tag>
1.102     www      1171:         $element = &escape('homework_edit_'.
1.75      albertel 1172:                                            $Apache::lonxml::curdepth);
                   1173:     }
1.76      albertel 1174:     my $id=$Apache::lonxml::curdepth;
1.77      albertel 1175:     my %data=("imagechoice.$id.type"      =>$type,
1.76      albertel 1176: 	      "imagechoice.$id.formname"  =>$form,
                   1177: 	      "imagechoice.$id.file"      =>$bgfile,
                   1178: 	      "imagechoice.$id.formcoord" =>$element);
1.75      albertel 1179:     if ($height) {
1.76      albertel 1180: 	$data{"imagechoice.$id.formheight"}=$height.'_'.
                   1181: 	    $Apache::edit::bgimgsrccurdepth;
1.75      albertel 1182:     }
                   1183:     if ($width) {
1.76      albertel 1184: 	$data{"imagechoice.$id.formwidth"}=$width.'_'.
                   1185: 	    $Apache::edit::bgimgsrccurdepth;
1.75      albertel 1186:     }
1.114     raeburn  1187:     &Apache::lonnet::appenv(\%data);
1.77      albertel 1188:     my $text="Enter Coordinates";
                   1189:     if ($type eq 'polygon') { $text='Create Polygon Data'; }
                   1190:     my $result='<a href="/adm/imagechoice?token='.$id.'" target="imagechoice">'.$text.'</a>';
1.49      www      1191:     return $result;
                   1192: }
1.76      albertel 1193: 
                   1194: sub deletecoorddata {
1.122     raeburn  1195:     &Apache::lonnet::delenv('imagechoice.');
1.76      albertel 1196: }
                   1197: 
1.29      matthew  1198: #----------------------------------------------------- browse
                   1199: sub browse {
                   1200:     # insert a link to call up the filesystem browser (lonindexer)
1.107     banghart 1201:     my ($id, $mode, $titleid, $only) = @_;
1.29      matthew  1202:     my $form    = 'lonhomework';
1.42      matthew  1203:     my $element;
                   1204:     if (! defined($mode) || $mode eq 'attribute') {
1.102     www      1205:         $element = &escape("$id\_$Apache::lonxml::curdepth");
1.42      matthew  1206:     } elsif ($mode eq 'textnode') {  # for data between <tag> ... </tag>
1.102     www      1207:         $element = &escape('homework_edit_'.
1.68      albertel 1208:                                            $Apache::lonxml::curdepth);	
                   1209:     }
                   1210:     my $titleelement;
                   1211:     if ($titleid) {
1.107     banghart 1212: 	$titleelement=",'$only','','".&escape("$titleid\_$Apache::lonxml::curdepth")."'";
1.108     banghart 1213:     } else {
                   1214:         $titleelement=",'$only'";
1.42      matthew  1215:     }
1.29      matthew  1216:     my $result = <<"ENDBUTTON";
1.68      albertel 1217: <a href=\"javascript:openbrowser('$form','$element'$titleelement)\"\>Select</a>
1.29      matthew  1218: ENDBUTTON
                   1219:     return $result;
                   1220: }
                   1221: 
1.30      matthew  1222: #----------------------------------------------------- browse
                   1223: sub search {
                   1224:     # insert a link to call up the filesystem browser (lonindexer)
1.68      albertel 1225:     my ($id, $mode, $titleid) = @_;
1.30      matthew  1226:     my $form    = 'lonhomework';
1.49      www      1227:     my $element;
                   1228:     if (! defined($mode) || $mode eq 'attribute') {
1.102     www      1229:         $element = &escape("$id\_$Apache::lonxml::curdepth");
1.49      www      1230:     } elsif ($mode eq 'textnode') {  # for data between <tag> ... </tag>
1.102     www      1231:         $element = &escape('homework_edit_'.
1.49      www      1232:                                            $Apache::lonxml::curdepth);
                   1233:     }
1.68      albertel 1234:     my $titleelement;
                   1235:     if ($titleid) {
1.102     www      1236: 	$titleelement=",'".&escape("$titleid\_$Apache::lonxml::curdepth")."'";
1.68      albertel 1237:     }
1.30      matthew  1238:     my $result = <<"ENDBUTTON";
1.68      albertel 1239: <a href=\"javascript:opensearcher('$form','$element'$titleelement)\"\>Search</a>
1.30      matthew  1240: ENDBUTTON
                   1241:     return $result;
                   1242: }
                   1243: 
                   1244: 
1.1       albertel 1245: 1;
                   1246: __END__
1.26      harris41 1247: 
                   1248: 

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