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