igor@66: #!/usr/bin/perl igor@66: igor@66: our $change_matix = ''; igor@66: igor@66: our $change_matrix = ' igor@66: um über mit von vom nach zum zur in an auf igor@66: der das des dem den ein einer einem einen eines igor@66: '; igor@66: igor@66: our $change_matrix = ' igor@66: router network ip route igor@66: '; igor@66: igor@66: if (open(FILE, $ARGV[0])) { igor@66: local $/; igor@66: $change_matrix = ; igor@66: } igor@66: shift @ARGV; igor@66: igor@66: my $BaseURL = $ARGV[0]; igor@66: shift; igor@66: igor@66: my $Subdir = $ARGV[0]; igor@66: shift; igor@66: igor@66: my $StateFile = $ARGV[0]; igor@66: shift; igor@66: igor@66: sub load_state() igor@66: { igor@66: my %state; igor@66: my $entries = 0; igor@66: if (open(FILE, "$StateFile")) { igor@66: while() { igor@66: chomp; igor@66: my ($k,$v) = split /\s+/, $_, 2; igor@66: $state{$k} = $v; igor@66: $entries += 1; igor@66: } igor@66: } igor@66: $state{"ENTRIES"} = $entries; igor@66: return \%state; igor@66: } igor@66: igor@66: @colors = qw(ccccff 7aedaa ddeecc ffccee); igor@66: igor@66: our %change_matrix; igor@66: our %color; igor@66: our $dropdown_number = 0; igor@66: igor@66: $i = 0; igor@66: for (split /\n/, $change_matrix){ igor@66: next if /^\s*$/; igor@66: my @words = sort(split /\s+/); igor@66: for my $kw (@words) { igor@66: $change_matrix{$kw} = [ "???", @words ]; igor@66: $color{$kw} = $colors[$i%@colors]; igor@66: } igor@66: # uppercase igor@66: for (@words) { igor@66: s/(.)(.*)/\U$1\E$2/; igor@66: } igor@66: for my $kw (@words) { igor@66: $change_matrix{$kw} = [ "???", @words ]; igor@66: $color{$kw} = $colors[$i%@colors]; igor@66: } igor@66: $i += 1; igor@66: }; igor@66: igor@66: #for (keys(%change_matrix)) { igor@66: # print "$_ => ".join(", ", @{$change_matrix{$_}})."\n"; igor@66: # print "$_ => ".$color{$_}."\n"; igor@66: #} igor@66: our $CorrectAnswers = 0; igor@66: igor@66: sub generate_drop_down($$) igor@66: { igor@66: my $word = $_[0]; igor@66: my %state = %{$_[1]}; igor@66: igor@66: my $name = "dropdown$dropdown_number"; igor@66: my $value = $state{$name}; igor@66: $dropdown_number += 1; igor@66: my @variants = @{$change_matrix{$word}}; igor@66: $options = join("", map {my $selected = ""; $selected='selected="selected"' if $_ eq $value; ""} @variants); igor@66: my $color = $color{$word}; igor@66: if ($word eq $value) { igor@66: $color = "ffffff"; igor@66: $CorrectAnswers += 1; igor@66: } igor@66: if ($color) { igor@66: $color = "background:#$color"; igor@66: } igor@66: my $disabled = ""; igor@66: if ($value eq $word) { igor@66: $disabled = "disabled"; igor@66: } igor@66: my $onchange = "onchange='javascript:myAlert(\"$name\", this.form.$name, \"$word\")'"; igor@66: return "
"; igor@66: } igor@66: sub highlight_word($$$) igor@66: { igor@66: my $tag = $_[0]; igor@66: my $text = $_[1]; igor@66: my $state = $_[2]; igor@66: igor@66: if ($tag=~/^<[aA]/) { igor@66: return $tag.$text; igor@66: } igor@66: my $re = join("|", keys(%change_matrix)); igor@66: $text =~ s@(^|[;> ])($re)(?=([ <]|$))@"$1".generate_drop_down($2, $state)@egms; igor@66: return $tag.$text; igor@66: } igor@66: igor@66: my $state = load_state(); igor@66: #my %a = %{$state}; igor@66: #print join(", ", keys(%a)),"\n"; igor@66: igor@66: $jquery = ""; igor@66: local $/; igor@66: $text = <>; igor@66: $text =~ s@()(.*?)()@$2@g; igor@66: $text =~ s@(.*)(]*>)@$2@ims; igor@66: my $before_body = $1; igor@66: $text =~ s@(]*>)@$1@ims; igor@66: $text =~ s/(<.*?>)([^<]*)(?=<)/highlight_word($1, $2, $state)/egms; igor@66: $text = $before_body.$text; igor@66: igor@66: my $wrong_answers = $$state{"ENTRIES"} - $CorrectAnswers; igor@66: $info_div = " igor@66:
igor@66: $wrong_answers   igor@66: $CorrectAnswers   igor@66: $dropdown_number igor@66:
"; igor@66: igor@66: $text =~ s@(]*>)@$jquery$1$info_div@i; igor@66: $text =~ s@(]*>)@$1@i; igor@66: print $text;