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>.
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 );
34 sub plugin_javascript {
35 my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
36 my $function_name= "macles".(int(rand(100000))+1);
38 <script type=\"text/javascript\">
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');
49 return ($function_name,$res);
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");
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/\./;
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}.")";
84 foreach my $val (@listval){
85 unshift @{$numbers{$number}->{$val}},$tab->{'lib'};
86 my $mulrow=substr($val,0,2);
89 foreach my $mulrow (sort keys %mulrows){
90 unshift @{$numbers{$number}->{$mulrow}},{'listlib' => $tab->{'lib'},'listvalue' => $tab->{'authorised_value'}};
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 ) {
100 @tmpcolhdr = @{ $numbers{$num}->{'col_hdr'} }
101 if ( $numbers{$num}->{'col_hdr'} );
102 @tmprowhdr = @{ $numbers{$num}->{"row_hdr"} }
103 if ( $numbers{$num}->{'row_hdr'} );
107 foreach my $row (@tmprowhdr) {
108 my $tmprowvalue = $row->{rowvalue};
110 $rowcode = $1 if $tmprowvalue =~ /[0-9]([0-9])\./;
112 if ( scalar(@tmpcolhdr) > 0 ) {
114 #cas du tableau bidim
115 foreach my $col (@tmpcolhdr) {
116 my $tmpcolvalue = $col->{colvalue};
118 $colcode = $1 if $tmpcolvalue =~ /[0-9]\.([0-9])/;
120 $cell{celvalue} = $num . $rowcode . $colcode;
121 $cell{rowvalue} = $tmprowvalue;
122 $cell{colvalue} = $tmpcolvalue;
123 if ( $numbers{$num}->{ $num . $rowcode . $colcode } ) {
126 @{ $numbers{$num}->{ $num . $rowcode . $colcode } }
129 push @{ $cell{libs} }, { 'lib' => $_ };
133 push @{ $cell{libs} },
134 { 'lib' => $num . $rowcode . $colcode };
138 if ( $numbers{$num}->{ $num . $rowcode } ) {
139 my @tmpliblist = @{ $numbers{$num}->{ $num . $rowcode } };
141 { 'lib' => $row->{rowlib}, 'liblist' => \@tmpliblist };
146 #Cas de la liste simple
147 foreach my $key ( sort keys %{ $numbers{$num} } ) {
149 if ( $key =~ /$num$rowcode[0-9]/ ) {
150 $cell{celvalue} = $key;
151 foreach my $lib ( @{ $numbers{$num}->{$key} } ) {
152 push @{ $cell{'libs'} }, { 'lib' => $lib };
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",
178 authnotrequired => 0,
179 flagsrequired => {editcatalogue => '*'},
182 $template->param(BIGLOOP=>\@BIGLOOP);
183 $template->param("index"=>$index);
184 output_html_with_http_headers $input, $cookie, $template->output;