* Add enclair_db option to UserDB.pm. Allows logging of enclair password
[interchange.git] / code / UI_Tag / rotate_table.coretag
1 # Copyright 2002-2007 Interchange Development Group and others
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.  See the LICENSE file for details.
7
8 # $Id: rotate_table.coretag,v 1.4 2007-03-30 23:40:54 pajamian Exp $
9
10 UserTag rotate-table Order        rotate
11 UserTag rotate-table PosNumber    1
12 UserTag rotate-table Interpolate  1
13 UserTag rotate-table HasEndTag    1
14 UserTag rotate-table Version      $Revision: 1.4 $
15 UserTag rotate-table Routine      <<EOR
16 sub {
17         my ($rotate, $text) = @_;
18         return $text unless $rotate;
19         my $rotated = '';
20         $text =~ s/(.*<TABLE.*?>)//si;
21         my $out = $1 || '';
22         $text =~ s:(.*?)</table\s*>:</TABLE>:si;
23         my $table = $1;
24
25         my @cols;
26
27         while ($table =~ m:<TR.*?>(.*?)</TR>:sig) {
28                 push @cols, $1;
29         }
30         
31         my $i = 0;
32         my @rows;
33         my @meta;
34         my $rows = 0;
35         my @r; my @c; my @m;
36         my ($r,$c);
37
38         for (@cols) {
39                 while(m:<T([HD])(.*?)>(.*?)</T\1>:sig) {
40                         my $meta = $1 . $2;
41                         push @r, $3;
42                         if($meta =~ /SPAN/i) {
43                                 $meta =~ s/\bcolspan\s*=/ROWMETASPAN=/ig;
44                                 $meta =~ s/\browspan\s*=/COLMETASPAN=/ig;
45                                 $meta =~ s/(ROW|COL)META/$1/g;
46                         }
47                         push @m, $meta;
48                 }
49                 $meta[$i] = [@m];
50                 $rows[$i] = [@r];
51                 $i++;
52                 $rows = $rows < $#r ? $#r : $rows;
53                 undef @m;
54                 undef @r;
55         }
56         foreach $r (0 .. $rows) {
57                 $rotated .= "<TR>\n";
58                 foreach $c (0 .. $#cols) {
59                         $rotated .= "<T" . $meta[$c]->[$r] . ">";
60                         $rotated .= "$rows[$c]->[$r]";
61                         $rotated .= "</TD>\n"
62                 }
63                 $rotated .= "</TR>\n";
64         }
65         return $out . $rotated . $text;
66 }
67 EOR