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 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
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.
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.
22 #use warnings; FIXME - Bug 2505
29 use vars qw( $tagslib);
30 use vars qw( $authorised_values_sth);
31 use vars qw( $is_a_modif );
36 plugin_parameters : other parameters added when the plugin is called by the dopop function
40 sub plugin_parameters {
41 my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
45 sub plugin_javascript {
46 my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
47 my $function_name= "macles".(int(rand(100000))+1);
49 <script type=\"text/javascript\">
52 function Focus$function_name(subfield_managed) {
56 function Blur$function_name(subfield_managed) {
60 function Clic$function_name(i) {
61 newin=window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=macles.pl&index=\"+i,\"MACLES\",',toolbar=false,scrollbars=yes');
68 return ($function_name,$res);
75 # my $input = new CGI;
76 my $index= $input->param('index');
79 my $dbh = C4::Context->dbh;
80 my $rq=$dbh->prepare("SELECT authorised_value, lib from authorised_values where category=\"MACLES\" order by authorised_value DESC");
85 my (%numbers,%cells,@colhdr,@rowhdr,@multiplelines,@lists,$table);
86 while (my $tab = $rq->fetchrow_hashref){
87 my $number=substr($tab->{authorised_value},0,1);
88 if ($tab->{authorised_value}=~/[0-9]XX/){
89 $numbers{$number}->{'hdr_tab'}=$tab->{lib};
90 $numbers{$number}->{'Table'}=($number=~/[1-7]/);
91 } elsif ($tab->{authorised_value}=~/.X./){
92 $tab->{authorised_value}=~s/X/\./;
94 unshift @{$numbers{$number}->{"col_hdr"}},{"colvalue"=>$tab->{authorised_value},"collib"=>$tab->{lib}};
95 } elsif ($tab->{authorised_value}=~/..X/){
96 $tab->{authorised_value}=~s/X/\./;
97 unshift @{$numbers{$number}->{"row_hdr"}},{"rowvalue"=>$tab->{authorised_value},"rowlib"=>$tab->{lib}}
98 } elsif ($tab->{'authorised_value'}=~/,/){
99 my @listval=split /,/,$tab->{'authorised_value'};
100 # $tab->{authorised_value}=~s/,/","/g;
101 # $tab->{authorised_value}="(".$tab->{authorised_value}.")";
103 foreach my $val (@listval){
104 unshift @{$numbers{$number}->{$val}},$tab->{'lib'};
105 my $mulrow=substr($val,0,2);
108 foreach my $mulrow (sort keys %mulrows){
109 unshift @{$numbers{$number}->{$mulrow}},{'listlib' => $tab->{'lib'},'listvalue' => $tab->{'authorised_value'}};
112 unshift @{$numbers{$number}->{$tab->{'authorised_value'}}},$tab->{'lib'};
114 # use Data::Dumper;warn "BIGLOOP IN".Dumper(@BIGLOOP);
116 foreach my $num ( sort keys %numbers ) {
119 @tmpcolhdr = @{ $numbers{$num}->{'col_hdr'} }
120 if ( $numbers{$num}->{'col_hdr'} );
121 @tmprowhdr = @{ $numbers{$num}->{"row_hdr"} }
122 if ( $numbers{$num}->{'row_hdr'} );
126 foreach my $row (@tmprowhdr) {
127 my $tmprowvalue = $row->{rowvalue};
129 $rowcode = $1 if $tmprowvalue =~ /[0-9]([0-9])\./;
131 if ( scalar(@tmpcolhdr) > 0 ) {
133 #cas du tableau bidim
134 foreach my $col (@tmpcolhdr) {
135 my $tmpcolvalue = $col->{colvalue};
137 $colcode = $1 if $tmpcolvalue =~ /[0-9]\.([0-9])/;
139 $cell{celvalue} = $num . $rowcode . $colcode;
140 $cell{rowvalue} = $tmprowvalue;
141 $cell{colvalue} = $tmpcolvalue;
142 if ( $numbers{$num}->{ $num . $rowcode . $colcode } ) {
145 @{ $numbers{$num}->{ $num . $rowcode . $colcode } }
148 push @{ $cell{libs} }, { 'lib' => $_ };
152 push @{ $cell{libs} },
153 { 'lib' => $num . $rowcode . $colcode };
157 if ( $numbers{$num}->{ $num . $rowcode } ) {
158 my @tmpliblist = @{ $numbers{$num}->{ $num . $rowcode } };
160 { 'lib' => $row->{rowlib}, 'liblist' => \@tmpliblist };
165 #Cas de la liste simple
166 foreach my $key ( sort keys %{ $numbers{$num} } ) {
168 if ( $key =~ /$num$rowcode[0-9]/ ) {
169 $cell{celvalue} = $key;
170 foreach my $lib ( @{ $numbers{$num}->{$key} } ) {
171 push @{ $cell{'libs'} }, { 'lib' => $lib };
180 'rowvalue' => $row->{rowvalue},
181 'rowlib' => $row->{rowlib}
184 $BIGLOOPcell{'Lists'} = \@lists if ( scalar(@lists) > 0 );
185 $BIGLOOPcell{'lines'} = \@lines if ( scalar(@lines) > 0 );
186 $BIGLOOPcell{'col_hdr'} = \@tmpcolhdr if ( scalar(@tmpcolhdr) > 0 );
187 $BIGLOOPcell{'Table'} = $numbers{$num}->{'Table'};
188 $BIGLOOPcell{'hdr_tab'} = $numbers{$num}->{'hdr_tab'};
189 $BIGLOOPcell{'number'} = $num;
190 push @BIGLOOP, \%BIGLOOPcell;
192 # warn "BIGLOOP OUT".Dumper(@BIGLOOP);
193 my ($template, $loggedinuser, $cookie)
194 = get_template_and_user({template_name => "cataloguing/value_builder/macles.tt",
197 authnotrequired => 0,
198 flagsrequired => {editcatalogue => '*'},
201 $template->param(BIGLOOP=>\@BIGLOOP);
202 $template->param("index"=>$index);
203 output_html_with_http_headers $input, $cookie, $template->output;