Annotation of loncom/homework/randomlabel.pm, revision 1.1
1.1 ! tsai 1: # The LearningOnline Network with CAPA
! 2: # random labelling tool
! 3: # 7/20/2001 Isaac Tsai
! 4: # 8/10/2001 Isaac Tsai
! 5: # SYNTAX:
! 6: # <randomlabel bgimg=URL code=JAVACLASS codebase=URL width=12 height=45>
! 7: # <labelgroup name=GroupOne type=img>
! 8: # <location x=123 y=456 />
! 9: # <location x=321 y=654 />
! 10: # <location x=213 y=546 />
! 11: # <label>IMG-URL</label>
! 12: # <label>IMG-URL</label>
! 13: # <label>IMG-URL</label>
! 14: # </labelgroup>
! 15: # <labelgroup name=GroupTwo type=text>
! 16: # <location x=12 y=45 />
! 17: # <location x=32 y=65 />
! 18: # <location x=21 y=54 />
! 19: # <label>TEXT</label>
! 20: # <label>TEXT</label>
! 21: # <label>TEXT</label>
! 22: # </labelgroup>
! 23: # </randomlabel>
! 24: # ===========================================
! 25: # location (123,456): $GroupOne[1] = ...
! 26: # (321,654): $GroupOne[2] = ...
! 27: # (213,546): $GroupOne[3] = ...
! 28: # location (12,45) : $GroupOne[1] = ...
! 29: # (321,654): $GroupOne[2] = ...
! 30: # (213,546): $GroupOne[3] = ...
! 31: # ===========================================
! 32: package Apache::randomlabel;
! 33: use strict;
! 34:
! 35: sub BEGIN {
! 36: &Apache::lonxml::register('Apache::randomlabel',('randomlabel','labelgroup','location','label'));
! 37: }
! 38:
! 39: sub start_randomlabel {
! 40: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
! 41: my $result='';
! 42: my $bgimg= &Apache::lonxml::get_param('bgimg',$parstack,$safeeval);
! 43: my $code = &Apache::lonxml::get_param('code',$parstack,$safeeval);
! 44: my $codebase = &Apache::lonxml::get_param('codebase',$parstack,$safeeval);
! 45: my $w= &Apache::lonxml::get_param('width',$parstack,$safeeval);
! 46: my $h= &Apache::lonxml::get_param('height',$parstack,$safeeval);
! 47:
! 48: $result.="<applet code=$code codebase=$codebase width=\"$w\" height=\"$h\">";
! 49: $result.="<param name=\"bgimg\" value=\"$bgimg\">";
! 50: if ($target eq 'edit') {
! 51: }
! 52: if ($target eq 'modified') {
! 53: }
! 54: return $result;
! 55: }
! 56:
! 57: sub end_randomlabel {
! 58: return '</applet><BR />';
! 59: }
! 60:
! 61: sub start_labelgroup {
! 62: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
! 63: my $result='';
! 64: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
! 65: my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
! 66: $Apache::randomlabel::groupname=$name;
! 67: @Apache::randomlabel::xcoord = ();
! 68: @Apache::randomlabel::ycoord = ();
! 69: @Apache::randomlabel::label_arr = ();
! 70: return '';
! 71: }
! 72:
! 73: # begin to assign labels to locations
! 74: sub end_labelgroup {
! 75: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
! 76: my $gname = $Apache::randomlabel::groupname;
! 77: my $count = $#Apache::randomlabel::label_arr + 1;
! 78: my $code;
! 79: my $out;
! 80: my $label;
! 81: my $x;
! 82: my $y;
! 83: my $text= "<param name=\"count\" value=\"$count\">";
! 84:
! 85: my @idx_arr = (0 .. $#Apache::randomlabel::label_arr);
! 86: &Apache::structuretags::shuffle(\@idx_arr);
! 87: for(0 .. $#Apache::randomlabel::label_arr) {
! 88: $label = "$Apache::randomlabel::label_arr[ $idx_arr[$_] ]";
! 89: $x = pop @Apache::randomlabel::xcoord;
! 90: $y = pop @Apache::randomlabel::ycoord;
! 91: $text .= "<param name=\"LB". $_ . "\" value=\"$label\">";
! 92: $text .= "<param name=\"X" . $_ . "\" value=\"$x\"> ";
! 93: $text .= "<param name=\"Y" . $_ . "\" value=\"$y\">";
! 94: $code = "push(\@$gname, $label);" ;
! 95: # print("CODE=$code");
! 96: # $out=Apache::run::run($code,$safeeval,$$parstack[$#$parstack]);
! 97: $out=Apache::run::run($code,$safeeval);
! 98: }
! 99:
! 100: return $text;
! 101: }
! 102:
! 103: sub start_location {
! 104: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
! 105: my $x= &Apache::lonxml::get_param('x',$parstack,$safeeval);
! 106: my $y= &Apache::lonxml::get_param('y',$parstack,$safeeval);
! 107:
! 108: push(@Apache::randomlabel::xcoord,$x);
! 109: push(@Apache::randomlabel::ycoord,$y);
! 110: return '';
! 111: }
! 112:
! 113: sub end_location {
! 114: return '';
! 115: }
! 116:
! 117: sub start_label {
! 118: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
! 119: my $ltext=&Apache::lonxml::get_all_text("/label",$$parser[$#$parser]);
! 120:
! 121: push(@Apache::randomlabel::label_arr,$ltext);
! 122: return '';
! 123: }
! 124:
! 125: sub end_label {
! 126: return '';
! 127: }
! 128:
! 129:
! 130:
! 131: 1;
! 132: __END__
! 133:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>