Bug 2505 - Add commented use warnings where missing in the cataloguing/ directory
[koha.git] / cataloguing / value_builder / macles.pl
1 #!/usr/bin/perl 
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 use strict;
22 #use warnings; FIXME - Bug 2505
23 use CGI;
24 use C4::Context;
25 use C4::Output;
26 use C4::Auth;
27
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;
33
34 =head1
35
36 plugin_parameters : other parameters added when the plugin is called by the dopop function
37
38 =cut
39 sub plugin_parameters {
40 my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
41 return "";
42 }
43
44 sub plugin_javascript {
45 my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
46 my $function_name= "macles".(int(rand(100000))+1);
47 my $res="
48 <script type=\"text/javascript\">
49 //<![CDATA[
50
51 function Focus$function_name(subfield_managed) {
52 return 1;
53 }
54
55 function Blur$function_name(subfield_managed) {
56         return 1;
57 }
58
59 function Clic$function_name(i) {
60         newin=window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=macles.pl&index=\"+i,\"MACLES\",',toolbar=false,scrollbars=yes');
61
62 }
63 //]]>
64 </script>
65 ";
66
67 return ($function_name,$res);
68 }
69
70 sub plugin {
71 my ($input) = @_;
72         my %env;
73
74 #       my $input = new CGI;
75         my $index= $input->param('index');
76
77
78         my $dbh = C4::Context->dbh;
79     my $rq=$dbh->prepare("SELECT authorised_value, lib from authorised_values where category=\"MACLES\" order by authorised_value DESC");
80     #tabs
81     $rq->execute;
82     my @BIGLOOP;
83     my @innerloop;
84     my (%numbers,%cells,@colhdr,@rowhdr,@multiplelines,@lists,$table);
85     while (my $tab = $rq->fetchrow_hashref){
86 #       if (! utf8::is_utf8($tab->{lib})) {
87 #         utf8::decode($tab->{lib});
88 #       }
89 #       warn $tab->{lib};
90       my $number=substr($tab->{authorised_value},0,1);
91       if ($tab->{authorised_value}=~/[0-9]XX/){
92         $numbers{$number}->{'hdr_tab'}=$tab->{lib};
93         $numbers{$number}->{'Table'}=($number=~/[1-7]/);
94       } elsif ($tab->{authorised_value}=~/.X./){
95         $tab->{authorised_value}=~s/X/\./;
96         $table=1;
97         unshift @{$numbers{$number}->{"col_hdr"}},{"colvalue"=>$tab->{authorised_value},"collib"=>$tab->{lib}};
98       } elsif ($tab->{authorised_value}=~/..X/){
99         $tab->{authorised_value}=~s/X/\./;
100         unshift @{$numbers{$number}->{"row_hdr"}},{"rowvalue"=>$tab->{authorised_value},"rowlib"=>$tab->{lib}}
101       } elsif ($tab->{'authorised_value'}=~/,/){
102         my @listval=split /,/,$tab->{'authorised_value'};
103 #          $tab->{authorised_value}=~s/,/","/g;
104 #         $tab->{authorised_value}="(".$tab->{authorised_value}.")";
105         my %mulrows;
106         foreach my $val (@listval){
107           unshift @{$numbers{$number}->{$val}},$tab->{'lib'};
108           my $mulrow=substr($val,0,2);
109           $mulrows{$mulrow}=1;
110         }
111         foreach my $mulrow (sort keys %mulrows){
112           unshift @{$numbers{$number}->{$mulrow}},{'listlib' => $tab->{'lib'},'listvalue' => $tab->{'authorised_value'}};
113         }
114       } else {
115         unshift @{$numbers{$number}->{$tab->{'authorised_value'}}},$tab->{'lib'};
116       }
117 #        use Data::Dumper;warn "BIGLOOP IN".Dumper(@BIGLOOP);
118     }
119     foreach my $num (sort keys %numbers){
120       my @tmpcolhdr = @{$numbers{$num}->{'col_hdr'}} if ($numbers{$num}->{'col_hdr'});
121       my @tmprowhdr = @{$numbers{$num}->{"row_hdr"}} if ($numbers{$num}->{'row_hdr'});
122       my @lines;
123       my @lists;
124       my %BIGLOOPcell;
125       foreach my $row (@tmprowhdr){
126         my $tmprowvalue=$row->{rowvalue};
127         my $rowcode=$1 if $tmprowvalue=~/[0-9]([0-9])\./;
128         my @cells;
129         if (scalar(@tmpcolhdr)>0){
130         #cas du tableau bidim
131           foreach my $col (@tmpcolhdr){
132             my $tmpcolvalue=$col->{colvalue};
133             my $colcode=$1 if $tmpcolvalue=~/[0-9]\.([0-9])/;
134             my %cell;
135             $cell{celvalue}=$num.$rowcode.$colcode;
136             $cell{rowvalue}=$tmprowvalue;
137             $cell{colvalue}=$tmpcolvalue;
138             if ($numbers{$num}->{$num.$rowcode.$colcode}){
139               foreach (@{$numbers{$num}->{$num.$rowcode.$colcode}}){
140                 push @{$cell{libs}},{'lib'=>$_};
141               }
142             }else {
143               push @{$cell{libs}},{'lib'=>$num.$rowcode.$colcode};
144             }
145             push @cells,\%cell;
146           }
147           if ($numbers{$num}->{$num.$rowcode}){
148             my @tmpliblist=@{$numbers{$num}->{$num.$rowcode}};
149             push @lists,{'lib'=>$row->{rowlib},'liblist'=>\@tmpliblist};
150           }
151         } else {
152         #Cas de la liste simple
153           foreach my $key (sort keys %{$numbers{$num}}){
154             my %cell;
155             if ($key=~/$num$rowcode[0-9]/){
156               $cell{celvalue}=$key;
157               foreach my $lib (@{$numbers{$num}->{$key}}){
158                 push @{$cell{'libs'}},{'lib'=>$lib};
159               }
160               push @cells,\%cell;
161             }
162           }
163         }
164         push @lines,{'cells'=>\@cells,'rowvalue'=>$row->{rowvalue},'rowlib'=>$row->{rowlib}};
165       }
166       $BIGLOOPcell{'Lists'}=\@lists if (scalar(@lists)>0);
167       $BIGLOOPcell{'lines'}=\@lines if (scalar(@lines)>0);
168       $BIGLOOPcell{'col_hdr'}=\@tmpcolhdr if (scalar(@tmpcolhdr)>0);
169       $BIGLOOPcell{'Table'}=$numbers{$num}->{'Table'};
170       $BIGLOOPcell{'hdr_tab'}=$numbers{$num}->{'hdr_tab'};
171       $BIGLOOPcell{'number'}=$num;
172       push @BIGLOOP,\%BIGLOOPcell;
173     }
174 #     warn "BIGLOOP OUT".Dumper(@BIGLOOP);
175     my ($template, $loggedinuser, $cookie)
176         = get_template_and_user({template_name => "cataloguing/value_builder/macles.tmpl",
177                     query => $input,
178                     type => "intranet",
179                     authnotrequired => 0,
180                     flagsrequired => {editcatalogue => '*'},
181                     debug => 1,
182                     });
183     $template->param(BIGLOOP=>\@BIGLOOP);
184         $template->param("index"=>$index);
185         output_html_with_http_headers $input, $cookie, $template->output;
186 }
187 1;
188
189