Bug 13948: DBRev 3.21.00.016
[koha.git] / cataloguing / value_builder / macles.pl
blobbab687b81ff202882b51b434c934018383a49c34
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) = @_;
54 my %env;
56 # my $input = new CGI;
57 my $index= $input->param('index');
60 my $dbh = C4::Context->dbh;
61 my $rq=$dbh->prepare("SELECT authorised_value, lib from authorised_values where category=\"MACLES\" order by authorised_value DESC");
62 #tabs
63 $rq->execute;
64 my @BIGLOOP;
65 my @innerloop;
66 my (%numbers,%cells,@colhdr,@rowhdr,@multiplelines,@lists,$table);
67 while (my $tab = $rq->fetchrow_hashref){
68 my $number=substr($tab->{authorised_value},0,1);
69 if ($tab->{authorised_value}=~/[0-9]XX/){
70 $numbers{$number}->{'hdr_tab'}=$tab->{lib};
71 $numbers{$number}->{'Table'}=($number=~/[1-7]/);
72 } elsif ($tab->{authorised_value}=~/.X./){
73 $tab->{authorised_value}=~s/X/\./;
74 $table=1;
75 unshift @{$numbers{$number}->{"col_hdr"}},{"colvalue"=>$tab->{authorised_value},"collib"=>$tab->{lib}};
76 } elsif ($tab->{authorised_value}=~/..X/){
77 $tab->{authorised_value}=~s/X/\./;
78 unshift @{$numbers{$number}->{"row_hdr"}},{"rowvalue"=>$tab->{authorised_value},"rowlib"=>$tab->{lib}}
79 } elsif ($tab->{'authorised_value'}=~/,/){
80 my @listval=split /,/,$tab->{'authorised_value'};
81 # $tab->{authorised_value}=~s/,/","/g;
82 # $tab->{authorised_value}="(".$tab->{authorised_value}.")";
83 my %mulrows;
84 foreach my $val (@listval){
85 unshift @{$numbers{$number}->{$val}},$tab->{'lib'};
86 my $mulrow=substr($val,0,2);
87 $mulrows{$mulrow}=1;
89 foreach my $mulrow (sort keys %mulrows){
90 unshift @{$numbers{$number}->{$mulrow}},{'listlib' => $tab->{'lib'},'listvalue' => $tab->{'authorised_value'}};
92 } else {
93 unshift @{$numbers{$number}->{$tab->{'authorised_value'}}},$tab->{'lib'};
95 # use Data::Dumper;warn "BIGLOOP IN".Dumper(@BIGLOOP);
97 foreach my $num ( sort keys %numbers ) {
98 my @tmpcolhdr;
99 my @tmprowhdr;
100 @tmpcolhdr = @{ $numbers{$num}->{'col_hdr'} }
101 if ( $numbers{$num}->{'col_hdr'} );
102 @tmprowhdr = @{ $numbers{$num}->{"row_hdr"} }
103 if ( $numbers{$num}->{'row_hdr'} );
104 my @lines;
105 my @lists;
106 my %BIGLOOPcell;
107 foreach my $row (@tmprowhdr) {
108 my $tmprowvalue = $row->{rowvalue};
109 my $rowcode;
110 $rowcode = $1 if $tmprowvalue =~ /[0-9]([0-9])\./;
111 my @cells;
112 if ( scalar(@tmpcolhdr) > 0 ) {
114 #cas du tableau bidim
115 foreach my $col (@tmpcolhdr) {
116 my $tmpcolvalue = $col->{colvalue};
117 my $colcode;
118 $colcode = $1 if $tmpcolvalue =~ /[0-9]\.([0-9])/;
119 my %cell;
120 $cell{celvalue} = $num . $rowcode . $colcode;
121 $cell{rowvalue} = $tmprowvalue;
122 $cell{colvalue} = $tmpcolvalue;
123 if ( $numbers{$num}->{ $num . $rowcode . $colcode } ) {
125 foreach (
126 @{ $numbers{$num}->{ $num . $rowcode . $colcode } }
129 push @{ $cell{libs} }, { 'lib' => $_ };
132 else {
133 push @{ $cell{libs} },
134 { 'lib' => $num . $rowcode . $colcode };
136 push @cells, \%cell;
138 if ( $numbers{$num}->{ $num . $rowcode } ) {
139 my @tmpliblist = @{ $numbers{$num}->{ $num . $rowcode } };
140 push @lists,
141 { 'lib' => $row->{rowlib}, 'liblist' => \@tmpliblist };
144 else {
146 #Cas de la liste simple
147 foreach my $key ( sort keys %{ $numbers{$num} } ) {
148 my %cell;
149 if ( $key =~ /$num$rowcode[0-9]/ ) {
150 $cell{celvalue} = $key;
151 foreach my $lib ( @{ $numbers{$num}->{$key} } ) {
152 push @{ $cell{'libs'} }, { 'lib' => $lib };
154 push @cells, \%cell;
158 push @lines,
160 'cells' => \@cells,
161 'rowvalue' => $row->{rowvalue},
162 'rowlib' => $row->{rowlib}
165 $BIGLOOPcell{'Lists'} = \@lists if ( scalar(@lists) > 0 );
166 $BIGLOOPcell{'lines'} = \@lines if ( scalar(@lines) > 0 );
167 $BIGLOOPcell{'col_hdr'} = \@tmpcolhdr if ( scalar(@tmpcolhdr) > 0 );
168 $BIGLOOPcell{'Table'} = $numbers{$num}->{'Table'};
169 $BIGLOOPcell{'hdr_tab'} = $numbers{$num}->{'hdr_tab'};
170 $BIGLOOPcell{'number'} = $num;
171 push @BIGLOOP, \%BIGLOOPcell;
173 # warn "BIGLOOP OUT".Dumper(@BIGLOOP);
174 my ($template, $loggedinuser, $cookie)
175 = get_template_and_user({template_name => "cataloguing/value_builder/macles.tt",
176 query => $input,
177 type => "intranet",
178 authnotrequired => 0,
179 flagsrequired => {editcatalogue => '*'},
180 debug => 1,
182 $template->param(BIGLOOP=>\@BIGLOOP);
183 $template->param("index"=>$index);
184 output_html_with_http_headers $input, $cookie, $template->output;