1: # The LearningOnline Network with CAPA
2: # edit mode helpers
3: #
4: # $Id: edit.pm,v 1.95 2005/11/10 22:19:27 albertel Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::edit;
30:
31: use strict;
32: use Apache::lonnet;
33: use HTML::Entities();
34: use Apache::lonlocal;
35:
36: # Global Vars
37: # default list of colors to use in editing
38: @Apache::edit::colorlist=('#ffffff','#ff0000','#00ff00','#0000ff','#0ff000','#000ff0','#f0000f');
39: # depth of nesting of edit
40: $Apache::edit::colordepth=0;
41: @Apache::edit::inserttag=();
42: # image-type responses: active background image and curdepth at definition
43: $Apache::edit::bgimgsrc='';
44: $Apache::edit::bgimgsrccurdepth='';
45:
46: sub initialize_edit {
47: $Apache::edit::colordepth=0;
48: @Apache::edit::inserttag=();
49: }
50:
51: sub tag_start {
52: my ($target,$token,$description) = @_;
53: my $result='';
54: if ($target eq "edit") {
55: my $tag=$token->[1];
56: if (!$description) {
57: $description=&Apache::lonxml::description($token);
58: if (!$description) { $description="<$tag>"; }
59: }
60: $result.= &start_table($token)."<tr><td>$description</td>
61: <td>Delete".
62: &deletelist($target,$token)
63: ."</td>
64: <td>".
65: &insertlist($target,$token);
66: #<td>".
67: # &movebuttons($target,$token).
68: # "</tr><tr><td colspan=\"3\">\n";
69: my @help = Apache::lonxml::helpinfo($token);
70: if ($help[0]) {
71: $result .= '</td><td align="right" valign="top">' .
72: Apache::loncommon::help_open_topic(@help);
73: } else { $result .= "</td><td> "; }
74: $result .= &end_row().&start_spanning_row();
75: }
76: return $result;
77: }
78:
79: sub tag_end {
80: my ($target,$token,$description) = @_;
81: my $result='';
82: if ($target eq 'edit') {
83: $result.="</td></tr>".&end_table()."\n";
84: }
85: return $result;
86: }
87:
88: sub start_table {
89: my ($token)=@_;
90: my $tag = $token->[1];
91: my $tagnum;
92: foreach my $namespace (reverse @Apache::lonxml::namespace) {
93: my $testtag=$namespace.'::'.$tag;
94: $tagnum=$Apache::lonxml::insertlist{"$testtag.num"};
95: &Apache::lonxml::debug(" $testtag ");
96: if (defined($tagnum)) { last; }
97: }
98: if (!defined ($tagnum)) {$tagnum=$Apache::lonxml::insertlist{"$tag.num"};}
99: my $color = $Apache::lonxml::insertlist{"$tagnum.color"};
100: &Apache::lonxml::debug(" $tagnum -- $color");
101: if (!defined($color)) {
102: $color = $Apache::edit::colorlist[$Apache::edit::colordepth];
103: }
104: $Apache::edit::colordepth++;
105: push(@Apache::edit::inserttag,$token->[1]);
106: my $result='<div align="right">';
107: $result.='<table bgcolor="'.$color.'" width="97%" border="0" cellspacing="5" cellpadding="3">';
108: return $result;
109: }
110:
111: sub end_table {
112: $Apache::edit::colordepth--;
113: my $result='</table></div>';
114: $result.='<div align="left"><table><tr><td>';
115:
116: my ($tagname,$closingtag);
117: if (defined($Apache::edit::inserttag[-2])) {
118: $tagname=$Apache::edit::inserttag[-2];
119: } else {$tagname='problem';}
120: if (defined($Apache::edit::inserttag[-1])) {
121: $closingtag=$Apache::edit::inserttag[-1];
122: }
123: $result.=&innerinsertlist('edit',$tagname,$closingtag).
124: "</td></tr></table></div>";
125: pop(@Apache::edit::inserttag);
126: return $result;
127: }
128:
129: sub start_spanning_row { return '<tr><td colspan="4" bgcolor="#DDDDDD">';}
130: sub start_row { return '<tr><td bgcolor="#DDDDDD">'; }
131: sub end_row { return '</td></tr>'; }
132:
133: sub movebuttons {
134: my ($target,$token) = @_;
135: my $result='<input type="submit" name="moveup.'.
136: $Apache::lonxml::curdepth.'" value="Move Up" />';
137: $result.='<input type="submit" name="movedown.'.
138: $Apache::lonxml::curdepth.'" value="Move Down" />';
139: return $result;
140: }
141:
142: sub deletelist {
143: my ($target,$token) = @_;
144: my $result = "<select name=\"delete_$Apache::lonxml::curdepth\">
145: <option></option>
146: <option>Yes</option>
147: </select>";
148: return $result;
149: }
150:
151: sub handle_delete {
152: if (!$env{"form.delete_$Apache::lonxml::curdepth"}) { return ''; }
153: my ($space,$target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
154: my $result=0;
155: if ($space) {
156: my $sub1="$space\:\:delete_$token->[1]";
157: {
158: no strict 'refs';
159: if (defined &$sub1) {
160: $result=&$sub1($target,$token,$tagstack,$parstack,$parser,$safeeval,$style);
161: }
162: }
163: }
164: if (!$result) {
165: my $endtag='/'.$token->[1];
166: my $bodytext=&Apache::lonxml::get_all_text($endtag,$parser);
167: $$parser['-1']->get_token();
168: &Apache::lonxml::debug("Deleting :$bodytext: for $token->[1]");
169: &Apache::lonxml::end_tag($tagstack,$parstack,$token);
170: }
171: return 1;
172: }
173:
174: sub get_insert_list {
175: my ($tagname) = @_;
176: my $result='';
177: my @tagnums= ();
178: #&Apache::lonxml::debug("keys ".join("\n",sort(keys(%Apache::lonxml::insertlist))));
179: if ($Apache::lonxml::insertlist{"$tagname.which"}) {
180: push (@tagnums, @{ $Apache::lonxml::insertlist{"$tagname.which"} });
181: }
182: foreach my $namespace (@Apache::lonxml::namespace) {
183: if ($Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"}) {
184: push (@tagnums, @{ $Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"} });
185: }
186: }
187: if (@tagnums) {
188: my %options;
189: foreach my $tagnum (@tagnums) {
190: my $descrip=$Apache::lonxml::insertlist{"$tagnum.description"};
191: $options{$descrip} ="<option value=\"$tagnum\">".
192: $descrip."</option>\n";
193: }
194: foreach my $option (sort(keys(%options))) {$result.=$options{$option};}
195: if ($result) { $result='<option selected="selected"></option>'.$result; }
196: }
197: return $result;
198: }
199:
200: sub insertlist {
201: my ($target,$token) = @_;
202: return &innerinsertlist($target,$token->[1]);
203: }
204:
205: sub innerinsertlist {
206: my ($target,$tagname,$closingtag) = @_;
207: my $result;
208: my $after='';
209: if ($closingtag) {
210: $after='_after_'.$closingtag;
211: }
212: if ($target eq 'edit') {
213: my $optionlist= &get_insert_list($tagname);
214: if ($optionlist) {
215: $result = "Insert:
216: <select name=\"insert$after\_$Apache::lonxml::curdepth\">
217: $optionlist
218: </select>"
219: } else {
220: $result=" ";
221: }
222: }
223: return $result;
224: }
225:
226: sub handle_insert {
227: if ($env{"form.insert_$Apache::lonxml::curdepth"} eq '') { return ''; }
228: my $result;
229: my $tagnum = $env{"form.insert_$Apache::lonxml::curdepth"};
230: my $func=$Apache::lonxml::insertlist{"$tagnum.function"};
231: if ($func eq 'default') {
232: my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
233: my $namespace;
234: if ($newtag =~ /::/) { ($namespace,$newtag) = split(/::/,$newtag); }
235: $result.="\n<$newtag>\n</$newtag>";
236: } else {
237: if (defined(&$func)) {
238: {
239: no strict 'refs';
240: $result.=&$func();
241: }
242: } else {
243: my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
244: &Apache::lonxml::error("Unable to insert tag ".$Apache::lonxml::curdepth." ($tagnum) $newtag, func was not defined.");
245: }
246: }
247: return $result;
248: }
249:
250: sub handle_insertafter {
251: my $tagname=shift;
252: if ($env{"form.insert_after_$tagname\_$Apache::lonxml::curdepth"} eq '')
253: { return ''; }
254: my $result;
255: my $tagnum =$env{"form.insert_after_$tagname\_$Apache::lonxml::curdepth"};
256: my $func=$Apache::lonxml::insertlist{"$tagnum.function"};
257: if ($func eq 'default') {
258: my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
259: my $namespace;
260: if ($newtag =~ /::/) { ($namespace,$newtag) = split(/::/,$newtag); }
261: $result.="\n<$newtag>\n</$newtag>";
262: } else {
263: if (defined(&$func)) {
264: {
265: no strict 'refs';
266: $result.=&$func();
267: }
268: } else {
269: my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
270: &Apache::lonxml::error("Unable to insert (after) tag $newtag, $func was not defined. ($tagname $tagnum)");
271: }
272: }
273: return $result;
274: }
275:
276: sub insert_img {
277: return '
278: <img />';
279: }
280:
281: sub insert_responseparam {
282: return '
283: <responseparam />';
284: }
285:
286: sub insert_parameter {
287: return '
288: <parameter />';
289: }
290:
291: sub insert_formularesponse {
292: return '
293: <formularesponse answer="" samples="">
294: <responseparam description="Numerical Tolerance" type="tolerance" default="0.00001" name="tol" />
295: <textline size="25"/>
296: <hintgroup>
297: <startouttext /><endouttext />
298: </hintgroup>
299: </formularesponse>';
300: }
301:
302: sub insert_numericalresponse {
303: return '
304: <numericalresponse answer="">
305: <responseparam type="tolerance" default="5%" name="tol" description="Numerical Tolerance" />
306: <responseparam name="sig" type="int_range,0-16" default="0,15" description="Significant Figures" />
307: <textline />
308: <hintgroup>
309: <startouttext /><endouttext />
310: </hintgroup>
311: </numericalresponse>';
312: }
313:
314: sub insert_algorithmicresponse {
315: return '
316: <algorithmicresponse>
317: <answer type="loncapa/perl">
318: </answer>
319: <textline />
320: <hintgroup>
321: <startouttext /><endouttext />
322: </hintgroup>
323: </algorithmicresponse>';
324: }
325:
326: sub insert_algorithmicresponse_answer {
327: return '
328: <answer type="loncapa/perl">
329: </answer>
330: ';
331: }
332:
333: sub insert_stringresponse {
334: return '
335: <stringresponse answer="" type="">
336: <textline />
337: <hintgroup>
338: <startouttext /><endouttext />
339: </hintgroup>
340: </stringresponse>';
341: }
342:
343: sub insert_essayresponse {
344: return '
345: <essayresponse>
346: <textfield></textfield>
347: </essayresponse>';
348: }
349:
350: sub insert_imageresponse {
351: return '
352: <imageresponse max="1">
353: <foilgroup>
354: <foil>
355: </foil>
356: </foilgroup>
357: <hintgroup>
358: <startouttext /><endouttext />
359: </hintgroup>
360: </imageresponse>';
361: }
362:
363: sub insert_optionresponse {
364: return '
365: <optionresponse max="10">
366: <foilgroup options="">
367: <foil>
368: <startouttext /><endouttext />
369: </foil>
370: </foilgroup>
371: <hintgroup>
372: <startouttext /><endouttext />
373: </hintgroup>
374: </optionresponse>';
375: }
376:
377: sub insert_organicresponse {
378: return '
379: <organicresponse>
380: <textline />
381: <hintgroup>
382: <startouttext /><endouttext />
383: </hintgroup>
384: </organicresponse>';
385: }
386:
387: sub insert_organicstructure {
388: return '
389: <organicstructure />
390: ';
391: }
392:
393: sub insert_radiobuttonresponse {
394: return '
395: <radiobuttonresponse max="10">
396: <foilgroup>
397: <foil>
398: <startouttext /><endouttext />
399: </foil>
400: </foilgroup>
401: <hintgroup>
402: <startouttext /><endouttext />
403: </hintgroup>
404: </radiobuttonresponse>';
405: }
406:
407: sub insert_reactionresponse {
408: return '
409: <reactionresponse>
410: <textline />
411: <hintgroup>
412: <startouttext /><endouttext />
413: </hintgroup>
414: </reactionresponse>';
415: }
416:
417: sub insert_rankresponse {
418: return '
419: <rankresponse max="10">
420: <foilgroup options="">
421: <foil>
422: <startouttext /><endouttext />
423: </foil>
424: </foilgroup>
425: <hintgroup>
426: <startouttext /><endouttext />
427: </hintgroup>
428: </rankresponse>';
429: }
430:
431: sub insert_matchresponse {
432: return '
433: <matchresponse max="10">
434: <foilgroup options="">
435: <itemgroup>
436: </itemgroup>
437: <foil>
438: <startouttext /><endouttext />
439: </foil>
440: </foilgroup>
441: <hintgroup>
442: <startouttext /><endouttext />
443: </hintgroup>
444: </matchresponse>';
445: }
446:
447: sub insert_displayduedate { return '<displayduedate />'; }
448: sub insert_displaytitle { return '<displaytitle />'; }
449: sub insert_hintpart {
450: return '
451: <hintpart on="default">
452: <startouttext/><endouttext />
453: </hintpart>';
454: }
455:
456: sub insert_hintgroup {
457: return '
458: <hintgroup>
459: <startouttext /><endouttext />
460: </hintgroup>';
461: }
462:
463: sub insert_numericalhint {
464: return '
465: <numericalhint>
466: </numericalhint>';
467: }
468:
469: sub insert_stringhint {
470: return '
471: <stringhint>
472: </stringhint>';
473: }
474:
475: sub insert_formulahint {
476: return '
477: <formulahint>
478: </formulahint>';
479: }
480:
481: sub insert_radiobuttonhint {
482: return '
483: <radiobuttonhint>
484: </radiobuttonhint>';
485: }
486:
487: sub insert_optionhint {
488: return '
489: <optionhint>
490: </optionhint>';
491: }
492:
493: sub insert_startouttext {
494: return "<startouttext /><endouttext />";
495: }
496:
497: sub insert_script {
498: return "\n<script type=\"loncapa/perl\"></script>";
499: }
500:
501: sub textarea_sizes {
502: my ($data)=@_;
503: my $count=0;
504: my $maxlength=-1;
505: foreach (split ("\n", $$data)) {
506: $count+=int(length($_)/79);
507: $count++;
508: if (length($_) > $maxlength) { $maxlength = length($_); }
509: }
510: my $rows = $count;
511: my $cols = $maxlength;
512: return ($rows,$cols);
513: }
514:
515: sub editline {
516: my ($tag,$data,$description,$size)=@_;
517: $data=&HTML::Entities::encode($data,'<>&"');
518: if ($description) { $description="<br />".$description."<br />"; }
519: my $result = <<"END";
520: $description
521: <input type="text" name="homework_edit_$Apache::lonxml::curdepth"
522: value="$data" size="$size" />
523: END
524: return $result;
525: }
526:
527: sub editfield {
528: my ($tag,$data,$description,$minwidth,$minheight,$usehtmlarea)=@_;
529:
530: my ($rows,$cols)=&textarea_sizes(\$data);
531: if (&Apache::lonhtmlcommon::htmlareabrowser() &&
532: !&Apache::lonhtmlcommon::htmlareablocked()) {
533: $rows+=7; # make room for HTMLarea
534: $minheight+=7; # make room for HTMLarea
535: }
536: if ($cols > 80) { $cols = 80; }
537: if ($cols < $minwidth ) { $cols = $minwidth; }
538: if ($rows < $minheight) { $rows = $minheight; }
539: if ($description) { $description="<br />".$description."<br />"; }
540: if ($usehtmlarea) {
541: push @Apache::lonxml::htmlareafields,'homework_edit_'.
542: $Apache::lonxml::curdepth;
543: }
544: return $description."\n".' <textarea style="width:100%" rows="'.$rows.
545: '" cols="'.$cols.'" name="homework_edit_'.
546: $Apache::lonxml::curdepth.'" id="homework_edit_'.
547: $Apache::lonxml::curdepth.'">'.
548: &HTML::Entities::encode($data,'<>&"').'</textarea>'.
549: ($usehtmlarea?&Apache::lonhtmlcommon::spelllink('lonhomework',
550: 'homework_edit_'.$Apache::lonxml::curdepth):'')."\n";
551: }
552:
553: sub modifiedfield {
554: my ($endtag,$parser) = @_;
555: my $result;
556: # foreach my $envkey (sort keys %env) {
557: # &Apache::lonxml::debug("$envkey ---- $env{$envkey}");
558: # }
559: # &Apache::lonxml::debug("I want homework_edit_$Apache::lonxml::curdepth");
560: # &Apache::lonxml::debug($env{"form.homework_edit_$Apache::lonxml::curdepth"});
561: $result=$env{"form.homework_edit_$Apache::lonxml::curdepth"};
562: my $bodytext=&Apache::lonxml::get_all_text($endtag,$parser);
563: # textareas throw away intial \n
564: if ($bodytext=~/^\n/) { $result="\n".$result; }
565: return $result;
566: }
567:
568: # Returns a 1 if the token has been modified and you should rebuild the tag
569: # side-effects, will modify the $token if new values are found
570: sub get_new_args {
571: my ($token,$parstack,$safeeval,@args)=@_;
572: my $rebuild=0;
573: foreach my $arg (@args) {
574: #just want the string that it was set to
575: my $value=$token->[2]->{$arg};
576: my $element=&html_element_name($arg);
577: my $newvalue=$env{"form.$element"};
578: &Apache::lonxml::debug("for:$arg: cur is :$value: new is :$newvalue:");
579: if (defined($newvalue) && $value ne $newvalue) {
580: if (ref($newvalue) eq 'ARRAY') {
581: $token->[2]->{$arg}=join(',',@$newvalue);
582: } else {
583: $token->[2]->{$arg}=$newvalue;
584: }
585: $rebuild=1;
586: } elsif (!defined($newvalue) && defined($value)) {
587: delete($token->[2]->{$arg});
588: $rebuild=1;
589: }
590: }
591: return $rebuild;
592: }
593:
594: # looks for /> on start tags
595: sub rebuild_tag {
596: my ($token) = @_;
597: my $result;
598: if ($token->[0] eq 'S') {
599: $result = '<'.$token->[1];
600: while (my ($key,$val)= each(%{$token->[2]})) {
601: $val=~s:^\s+|\s+$::g;
602: $val=~s:"::g; #"
603: &Apache::lonxml::debug("setting :$key: to :$val:");
604: $result.=' '.$key.'="'.$val.'"';
605: }
606: if ($token->[4] =~ m:/>$:) {
607: $result.=' />';
608: } else {
609: $result.='>';
610: }
611: } elsif ( $token->[0] eq 'E' ) {
612: $result = '</'.$token->[1].'>';
613: }
614: return $result;
615: }
616:
617: sub html_element_name {
618: my ($name) = @_;
619: return $name.'_'.$Apache::lonxml::curdepth;
620: }
621:
622: sub hidden_arg {
623: my ($name,$token) = @_;
624: my $result;
625: my $arg=$token->[2]{$name};
626: $result='<input name="'.&html_element_name($name).
627: '" type="hidden" value="'.$arg.'" />';
628: return $result;
629: }
630:
631: sub checked_arg {
632: my ($description,$name,$list,$token) = @_;
633: my $result;
634: my $optionlist="";
635: my $allselected=$token->[2]{$name};
636: $result=&mt($description);
637: foreach my $option (@$list) {
638: my ($value,$text);
639: if ( ref($option) eq 'ARRAY') {
640: $value='value="'.$$option[0].'"';
641: $text=$$option[1];
642: $option=$$option[0];
643: } else {
644: $text=$option;
645: $value='value="'.$option.'"';
646: }
647: $result.="<nobr><input type='checkbox' $value name='".
648: &html_element_name($name)."'";
649: foreach my $selected (split(/,/,$allselected)) {
650: if ( $selected eq $option ) {
651: $result.=" checked='checked' ";
652: last;
653: }
654: }
655: $result.=" />$text</nobr>\n";
656: }
657: return $result;
658: }
659:
660: sub text_arg {
661: my ($description,$name,$token,$size) = @_;
662: my $result;
663: if (!defined $size) { $size=20; }
664: my $arg=$token->[2]{$name};
665: $result=&mt($description).' <input name="'.&html_element_name($name).
666: '" type="text" value="'.$arg.'" size="'.$size.'" />';
667: return '<nobr>'.$result.'</nobr>';
668: }
669:
670: sub select_arg {
671: my ($description,$name,$list,$token) = @_;
672: my $result;
673: my $optionlist="";
674: my $selected=$token->[2]{$name};
675: foreach my $option (@$list) {
676: my ($text,$value);
677: if ( ref($option) eq 'ARRAY') {
678: $value='value="'.&HTML::Entities::encode($$option[0]).'"';
679: $text=$$option[1];
680: $option=$$option[0];
681: } else {
682: $text=$option;
683: $value='value="'.&HTML::Entities::encode($option,'\'"&<>').'"';
684: }
685: if ( $selected eq $option ) {
686: $optionlist.="<option $value selected=\"selected\">$text</option>\n";
687: } else {
688: $optionlist.="<option $value >$text</option>\n";
689: }
690: }
691: $result.='<nobr>'.$description.' <select name="'.
692: &html_element_name($name).'">
693: '.$optionlist.'
694: </select></nobr>';
695: return $result;
696: }
697:
698: sub select_or_text_arg {
699: my ($description,$name,$list,$token,$size) = @_;
700: my $result;
701: my $optionlist="";
702: my $found=0;
703: my $selected=$token->[2]{$name};
704: foreach my $option (@$list) {
705: my ($text,$value);
706: if ( ref($option) eq 'ARRAY') {
707: $value='value="'.&HTML::Entities::encode($$option[0]).'"';
708: $text=$$option[1];
709: $option=$$option[0];
710: } else {
711: $text=$option;
712: $value='value="'.&HTML::Entities::encode($option,'\'"&<>').'"';
713: }
714: if ( $selected eq $option ) {
715: $optionlist.="<option $value selected=\"selected\">$text</option>\n";
716: $found=1;
717: } else {
718: $optionlist.="<option $value>$text</option>\n";
719: }
720: }
721: $optionlist.="<option value=\"TYPEDINVALUE\"".
722: ((!$found)?' selected="selected"':'').
723: ">".&mt('Type-in value')."</option>\n";
724: #
725: my $element=&html_element_name($name);
726: my $selectelement='select_list_'.$element;
727: my $typeinelement='type_in_'.$element;
728: my $typeinvalue=($found?'':$selected);
729: #
730: my $hiddenvalue='this.form.'.$element.'.value';
731: my $selectedindex='this.form.'.$selectelement.'.selectedIndex';
732: my $selectedvalue='this.form.'.$selectelement.
733: '.options['.$selectedindex.'].value';
734: my $typedinvalue='this.form.'.$typeinelement.'.value';
735: my $selecttypeinindex='this.form.'.$selectelement.'.options.length';
736: $description=&mt($description);
737: #
738: return (<<ENDSELECTORTYPE);
739: <nobr>
740: $description
741: <select name="$selectelement"
742: onChange="if ($selectedvalue!='TYPEDINVALUE') { $hiddenvalue=$selectedvalue; $typedinvalue=''; }" >
743: $optionlist
744: </select>
745: <input type="text" size="$size" name="$typeinelement"
746: value="$typeinvalue"
747: onChange="$hiddenvalue=$typedinvalue;"
748: onFocus="$selectedindex=$selecttypeinindex-1;" />
749: <input type="hidden" name="$element" value="$selected" />
750: </nobr>
751: ENDSELECTORTYPE
752: }
753:
754: #----------------------------------------------------- image coordinates
755: # single image coordinates, x, y
756: sub entercoords {
757: my ($idx,$idy,$mode,$width,$height) = @_;
758: unless ($Apache::edit::bgimgsrc) { return ''; }
759: if ($idx) { $idx.='_'; }
760: if ($idy) { $idy.='_'; }
761: my $bgfile=&Apache::lonnet::escape(&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$Apache::edit::bgimgsrc));
762: my $form = 'lonhomework';
763: my $element;
764: if (! defined($mode) || $mode eq 'attribute') {
765: $element = &Apache::lonnet::escape("$Apache::lonxml::curdepth");
766: } elsif ($mode eq 'textnode') { # for data between <tag> ... </tag>
767: $element = &Apache::lonnet::escape('homework_edit_'.
768: $Apache::lonxml::curdepth);
769: }
770: my $id=$Apache::lonxml::curdepth;
771: my %data=("imagechoice.$id.type" =>'point',
772: "imagechoice.$id.formname" =>$form,
773: "imagechoice.$id.formx" =>"$idx$element",
774: "imagechoice.$id.formy" =>"$idy$element",
775: "imagechoice.$id.file" =>$bgfile,
776: "imagechoice.$id.formcoord" =>$element);
777: if ($height) {
778: $data{"imagechoice.$id.formheight"}=$height.'_'.
779: $Apache::edit::bgimgsrccurdepth;
780: }
781: if ($width) {
782: $data{"imagechoice.$id.formwidth"}=$width.'_'.
783: $Apache::edit::bgimgsrccurdepth;
784: }
785: &Apache::lonnet::appenv(%data);
786: my $text="Click Coordinates";
787: my $result='<a href="/adm/imagechoice?token='.$id.'" target="imagechoice">'.$text.'</a>';
788: return $result;
789: }
790:
791: # coordinates (x1,y1)-(x2,y2)...
792: # mode can be either box, or polygon
793: sub entercoord {
794: my ($idx,$mode,$width,$height,$type) = @_;
795: unless ($Apache::edit::bgimgsrc) { return ''; }
796: my $bgfile=&Apache::lonnet::escape(&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$Apache::edit::bgimgsrc));
797: my $form = 'lonhomework';
798: my $element;
799: if (! defined($mode) || $mode eq 'attribute') {
800: $element = &Apache::lonnet::escape("$idx\_$Apache::lonxml::curdepth");
801: } elsif ($mode eq 'textnode') { # for data between <tag> ... </tag>
802: $element = &Apache::lonnet::escape('homework_edit_'.
803: $Apache::lonxml::curdepth);
804: }
805: my $id=$Apache::lonxml::curdepth;
806: my %data=("imagechoice.$id.type" =>$type,
807: "imagechoice.$id.formname" =>$form,
808: "imagechoice.$id.file" =>$bgfile,
809: "imagechoice.$id.formcoord" =>$element);
810: if ($height) {
811: $data{"imagechoice.$id.formheight"}=$height.'_'.
812: $Apache::edit::bgimgsrccurdepth;
813: }
814: if ($width) {
815: $data{"imagechoice.$id.formwidth"}=$width.'_'.
816: $Apache::edit::bgimgsrccurdepth;
817: }
818: &Apache::lonnet::appenv(%data);
819: my $text="Enter Coordinates";
820: if ($type eq 'polygon') { $text='Create Polygon Data'; }
821: my $result='<a href="/adm/imagechoice?token='.$id.'" target="imagechoice">'.$text.'</a>';
822: return $result;
823: }
824:
825: sub deletecoorddata {
826: &Apache::lonnet::delenv("imagechoice\\.");
827: }
828:
829: #----------------------------------------------------- browse
830: sub browse {
831: # insert a link to call up the filesystem browser (lonindexer)
832: my ($id, $mode, $titleid) = @_;
833: my $form = 'lonhomework';
834: my $element;
835: if (! defined($mode) || $mode eq 'attribute') {
836: $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
837: } elsif ($mode eq 'textnode') { # for data between <tag> ... </tag>
838: $element = &Apache::lonnet::escape('homework_edit_'.
839: $Apache::lonxml::curdepth);
840: }
841: my $titleelement;
842: if ($titleid) {
843: $titleelement=",'','','".&Apache::lonnet::escape("$titleid\_$Apache::lonxml::curdepth")."'";
844: }
845: my $result = <<"ENDBUTTON";
846: <a href=\"javascript:openbrowser('$form','$element'$titleelement)\"\>Select</a>
847: ENDBUTTON
848: return $result;
849: }
850:
851: #----------------------------------------------------- browse
852: sub search {
853: # insert a link to call up the filesystem browser (lonindexer)
854: my ($id, $mode, $titleid) = @_;
855: my $form = 'lonhomework';
856: my $element;
857: if (! defined($mode) || $mode eq 'attribute') {
858: $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
859: } elsif ($mode eq 'textnode') { # for data between <tag> ... </tag>
860: $element = &Apache::lonnet::escape('homework_edit_'.
861: $Apache::lonxml::curdepth);
862: }
863: my $titleelement;
864: if ($titleid) {
865: $titleelement=",'".&Apache::lonnet::escape("$titleid\_$Apache::lonxml::curdepth")."'";
866: }
867: my $result = <<"ENDBUTTON";
868: <a href=\"javascript:opensearcher('$form','$element'$titleelement)\"\>Search</a>
869: ENDBUTTON
870: return $result;
871: }
872:
873:
874: 1;
875: __END__
876:
877: =head1 NAME
878:
879: Apache::edit - edit mode helpers
880:
881: =head1 SYNOPSIS
882:
883: Invoked by many homework and xml related modules.
884:
885: &Apache::edit::SUBROUTINENAME(ARGUMENTS);
886:
887: =head1 INTRODUCTION
888:
889: This module outputs HTML syntax helpful for the rendering of edit
890: mode interfaces.
891:
892: This is part of the LearningOnline Network with CAPA project
893: described at http://www.lon-capa.org.
894:
895: =head1 HANDLER SUBROUTINE
896:
897: There is no handler subroutine.
898:
899: =head1 OTHER SUBROUTINES
900:
901: =over 4
902:
903: =item *
904:
905: initialize_edit() : initialize edit (set colordepth to zero)
906:
907: =item *
908:
909: tag_start($target,$token,$description) : provide deletion and insertion lists
910: for the manipulation of a start tag; return a scalar string
911:
912: =item *
913:
914: tag_end($target,$token,$description) : ending syntax corresponding to
915: &tag_start. return a scalar string.
916:
917: =item *
918:
919: start_table($token) : start table; update colordepth; return scalar string.
920:
921: =item *
922:
923: end_table() : reduce color depth; end table; return scalar string
924:
925: =item *
926:
927: start_spanning_row() : start a new table row spanning the 'edit' environment.
928:
929: =item *
930:
931: start_row() : start a new table row and element.
932:
933: =item *
934:
935: end_row() : end current table element and row.
936:
937: =item *
938:
939: movebuttons($target,$token) : move-up and move-down buttons; return scalar
940: string
941:
942: =item *
943:
944: deletelist($target,$token) : provide a yes option in an HTML select element;
945: return scalar string
946:
947: =item *
948:
949: handle_delete($space,$target,$token,$tagstack,$parstack,$parser,$safeeval,
950: $style) : respond to a user delete request by passing relevant stack
951: and array information to various rendering functions; return a scalar string
952:
953: =item *
954:
955: get_insert_list($token) : provide an insertion list based on possibilities
956: from lonxml; return a scalar string
957:
958: =item *
959:
960: insertlist($target,$token) : api that uses get_insert_list;
961: return a scalar string
962:
963: =item *
964:
965: handleinsert($token) : provide an insertion list based on possibilities
966: from lonxml; return a scalar string
967:
968: =item *
969:
970: get_insert_list($token) : provide an insertion list based on possibilities
971: from lonxml; return a scalar string
972:
973: =item *
974: browse($elementname) : provide a link which will open up the filesystem
975: browser (lonindexer) and, once a file is selected, place the result in
976: the form element $elementname.
977:
978: =item *
979: search($elementname) : provide a link which will open up the filesystem
980: searcher (lonsearchcat) and, once a file is selected, place the result in
981: the form element $elementname.
982:
983: =item *
984: editline(tag,data,description,size): Provide a <input type="text" ../> for
985: single-line text entry. This is to be used for text enclosed by tags, not
986: arguements/parameters associated with a tag.
987:
988: =back
989:
990: incomplete...
991:
992: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>