Bug 17322 - Translation breaks opac-ics.tt
[koha.git] / cataloguing / value_builder / macles.pl
blobc37b6a06a0d32bba4c58a8ca7cbb6e1b19051904
1 #!/usr/bin/perl
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use strict;
22 #use warnings; FIXME - Bug 2505
23 use CGI qw ( -utf8 );
24 use C4::Context;
25 use C4::Output;
26 use C4::Auth;
28 # use Data::Dumper;
29 use vars qw( $tagslib);
30 use vars qw( $authorised_values_sth);
31 use vars qw( $is_a_modif );
32 use utf8;
34 sub plugin_javascript {
35 my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
36 my $function_name= "macles".(int(rand(100000))+1);
37 my $res="
38 <script type=\"text/javascript\">
39 //<![CDATA[
41 function Clic$function_name(i) {
42 newin=window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=macles.pl&index=\"+i,\"MACLES\",',toolbar=false,scrollbars=yes');
45 //]]>
46 </script>
49 return ($function_name,$res);
52 sub plugin {
53 my ($input) = @_;
55 # my $input = new CGI;
56 my $index= $input->param('index');
59 my $dbh = C4::Context->dbh;
60 my $rq=$dbh->prepare("SELECT authorised_value, lib from authorised_values where category=\"MACLES\" order by authorised_value DESC");
61 #tabs
62 $rq->execute;
63 my @BIGLOOP;
64 my (%numbers,@lists,$table);
65 while (my $tab = $rq->fetchrow_hashref){
66 my $number=substr($tab->{authorised_value},0,1);
67 if ($tab->{authorised_value}=~/[0-9]XX/){
68 $numbers{$number}->{'hdr_tab'}=$tab->{lib};
69 $numbers{$number}->{'Table'}=($number=~/[1-7]/);
70 } elsif ($tab->{authorised_value}=~/.X./){
71 $tab->{authorised_value}=~s/X/\./;
72 $table=1;
73 unshift @{$numbers{$number}->{"col_hdr"}},{"colvalue"=>$tab->{authorised_value},"collib"=>$tab->{lib}};
74 } elsif ($tab->{authorised_value}=~/..X/){
75 $tab->{authorised_value}=~s/X/\./;
76 unshift @{$numbers{$number}->{"row_hdr"}},{"rowvalue"=>$tab->{authorised_value},"rowlib"=>$tab->{lib}}
77 } elsif ($tab->{'authorised_value'}=~/,/){
78 my @listval=split /,/,$tab->{'authorised_value'};
79 # $tab->{authorised_value}=~s/,/","/g;
80 # $tab->{authorised_value}="(".$tab->{authorised_value}.")";
81 my %mulrows;
82 foreach my $val (@listval){
83 unshift @{$numbers{$number}->{$val}},$tab->{'lib'};
84 my $mulrow=substr($val,0,2);
85 $mulrows{$mulrow}=1;
87 foreach my $mulrow (sort keys %mulrows){
88 unshift @{$numbers{$number}->{$mulrow}},{'listlib' => $tab->{'lib'},'listvalue' => $tab->{'authorised_value'}};
90 } else {
91 unshift @{$numbers{$number}->{$tab->{'authorised_value'}}},$tab->{'lib'};
93 # use Data::Dumper;warn "BIGLOOP IN".Dumper(@BIGLOOP);
95 foreach my $num ( sort keys %numbers ) {
96 my @tmpcolhdr;
97 my @tmprowhdr;
98 @tmpcolhdr = @{ $numbers{$num}->{'col_hdr'} }
99 if ( $numbers{$num}->{'col_hdr'} );
100 @tmprowhdr = @{ $numbers{$num}->{"row_hdr"} }
101 if ( $numbers{$num}->{'row_hdr'} );
102 my @lines;
103 my @lists;
104 my %BIGLOOPcell;
105 foreach my $row (@tmprowhdr) {
106 my $tmprowvalue = $row->{rowvalue};
107 my $rowcode;
108 $rowcode = $1 if $tmprowvalue =~ /[0-9]([0-9])\./;
109 my @cells;
110 if ( scalar(@tmpcolhdr) > 0 ) {
112 #cas du tableau bidim
113 foreach my $col (@tmpcolhdr) {
114 my $tmpcolvalue = $col->{colvalue};
115 my $colcode;
116 $colcode = $1 if $tmpcolvalue =~ /[0-9]\.([0-9])/;
117 my %cell;
118 $cell{celvalue} = $num . $rowcode . $colcode;
119 $cell{rowvalue} = $tmprowvalue;
120 $cell{colvalue} = $tmpcolvalue;
121 if ( $numbers{$num}->{ $num . $rowcode . $colcode } ) {
123 foreach (
124 @{ $numbers{$num}->{ $num . $rowcode . $colcode } }
127 push @{ $cell{libs} }, { 'lib' => $_ };
130 else {
131 push @{ $cell{libs} },
132 { 'lib' => $num . $rowcode . $colcode };
134 push @cells, \%cell;
136 if ( $numbers{$num}->{ $num . $rowcode } ) {
137 my @tmpliblist = @{ $numbers{$num}->{ $num . $rowcode } };
138 push @lists,
139 { 'lib' => $row->{rowlib}, 'liblist' => \@tmpliblist };
142 else {
144 #Cas de la liste simple
145 foreach my $key ( sort keys %{ $numbers{$num} } ) {
146 my %cell;
147 if ( $key =~ /$num$rowcode[0-9]/ ) {
148 $cell{celvalue} = $key;
149 foreach my $lib ( @{ $numbers{$num}->{$key} } ) {
150 push @{ $cell{'libs'} }, { 'lib' => $lib };
152 push @cells, \%cell;
156 push @lines,
158 'cells' => \@cells,
159 'rowvalue' => $row->{rowvalue},
160 'rowlib' => $row->{rowlib}
163 $BIGLOOPcell{'Lists'} = \@lists if ( scalar(@lists) > 0 );
164 $BIGLOOPcell{'lines'} = \@lines if ( scalar(@lines) > 0 );
165 $BIGLOOPcell{'col_hdr'} = \@tmpcolhdr if ( scalar(@tmpcolhdr) > 0 );
166 $BIGLOOPcell{'Table'} = $numbers{$num}->{'Table'};
167 $BIGLOOPcell{'hdr_tab'} = $numbers{$num}->{'hdr_tab'};
168 $BIGLOOPcell{'number'} = $num;
169 push @BIGLOOP, \%BIGLOOPcell;
171 # warn "BIGLOOP OUT".Dumper(@BIGLOOP);
172 my ($template, $loggedinuser, $cookie)
173 = get_template_and_user({template_name => "cataloguing/value_builder/macles.tt",
174 query => $input,
175 type => "intranet",
176 authnotrequired => 0,
177 flagsrequired => {editcatalogue => '*'},
178 debug => 1,
180 $template->param(BIGLOOP=>\@BIGLOOP);
181 $template->param("index"=>$index);
182 output_html_with_http_headers $input, $cookie, $template->output;