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

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

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