Bug 17702: Add UI to manage account credit types
[koha.git] / cataloguing / value_builder / macles.pl
blobbed0c88f667abdf7d53d90d8d5ef6a6e582616be
1 #!/usr/bin/perl
3 # Converted to new plugin style (Bug 13437)
5 # Copyright 2000-2002 Katipo Communications
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use Modern::Perl;
23 use CGI qw ( -utf8 );
25 use C4::Context;
26 use C4::Output;
27 use C4::Auth;
29 my $builder = sub {
30 my ( $params ) = @_;
31 my $function_name = $params->{id};
32 my $res="
33 <script type=\"text/javascript\">
34 //<![CDATA[
35 function Click$function_name(i) {
36 newin=window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=macles.pl&index=\"+i,\"MACLES\",',toolbar=false,scrollbars=yes');
38 //]]>
39 </script>
41 return $res;
44 my $launcher = sub {
45 my ( $params ) = @_;
46 my $input = $params->{cgi};
47 my $index= $input->param('index');
49 my $dbh = C4::Context->dbh;
50 my $rq=$dbh->prepare("SELECT authorised_value, lib from authorised_values where category=\"MACLES\" order by authorised_value DESC");
51 #tabs
52 $rq->execute;
53 my @BIGLOOP;
54 my (%numbers,@lists,$table);
55 while (my $tab = $rq->fetchrow_hashref){
56 my $number=substr($tab->{authorised_value},0,1);
57 if ($tab->{authorised_value}=~/[0-9]XX/){
58 $numbers{$number}->{'hdr_tab'}=$tab->{lib};
59 $numbers{$number}->{'Table'}=($number=~/[1-7]/);
60 } elsif ($tab->{authorised_value}=~/.X./){
61 $tab->{authorised_value}=~s/X/\./;
62 $table=1;
63 unshift @{$numbers{$number}->{"col_hdr"}},{"colvalue"=>$tab->{authorised_value},"collib"=>$tab->{lib}};
64 } elsif ($tab->{authorised_value}=~/..X/){
65 $tab->{authorised_value}=~s/X/\./;
66 unshift @{$numbers{$number}->{"row_hdr"}},{"rowvalue"=>$tab->{authorised_value},"rowlib"=>$tab->{lib}}
67 } elsif ($tab->{'authorised_value'}=~/,/){
68 my @listval=split /,/,$tab->{'authorised_value'};
69 # $tab->{authorised_value}=~s/,/","/g;
70 # $tab->{authorised_value}="(".$tab->{authorised_value}.")";
71 my %mulrows;
72 foreach my $val (@listval){
73 unshift @{$numbers{$number}->{$val}},$tab->{'lib'};
74 my $mulrow=substr($val,0,2);
75 $mulrows{$mulrow}=1;
77 foreach my $mulrow (sort keys %mulrows){
78 unshift @{$numbers{$number}->{$mulrow}},{'listlib' => $tab->{'lib'},'listvalue' => $tab->{'authorised_value'}};
80 } else {
81 unshift @{$numbers{$number}->{$tab->{'authorised_value'}}},$tab->{'lib'};
84 foreach my $num ( sort keys %numbers ) {
85 my @tmpcolhdr;
86 my @tmprowhdr;
87 @tmpcolhdr = @{ $numbers{$num}->{'col_hdr'} }
88 if ( $numbers{$num}->{'col_hdr'} );
89 @tmprowhdr = @{ $numbers{$num}->{"row_hdr"} }
90 if ( $numbers{$num}->{'row_hdr'} );
91 my @lines;
92 my @lists;
93 my %BIGLOOPcell;
94 foreach my $row (@tmprowhdr) {
95 my $tmprowvalue = $row->{rowvalue};
96 my $rowcode;
97 $rowcode = $1 if $tmprowvalue =~ /[0-9]([0-9])\./;
98 my @cells;
99 if ( scalar(@tmpcolhdr) > 0 ) {
101 #cas du tableau bidim
102 foreach my $col (@tmpcolhdr) {
103 my $tmpcolvalue = $col->{colvalue};
104 my $colcode;
105 $colcode = $1 if $tmpcolvalue =~ /[0-9]\.([0-9])/;
106 my %cell;
107 $cell{celvalue} = $num . $rowcode . $colcode;
108 $cell{rowvalue} = $tmprowvalue;
109 $cell{colvalue} = $tmpcolvalue;
110 if ( $numbers{$num}->{ $num . $rowcode . $colcode } ) {
112 foreach (
113 @{ $numbers{$num}->{ $num . $rowcode . $colcode } }
116 push @{ $cell{libs} }, { 'lib' => $_ };
119 else {
120 push @{ $cell{libs} },
121 { 'lib' => $num . $rowcode . $colcode };
123 push @cells, \%cell;
125 if ( $numbers{$num}->{ $num . $rowcode } ) {
126 my @tmpliblist = @{ $numbers{$num}->{ $num . $rowcode } };
127 push @lists,
128 { 'lib' => $row->{rowlib}, 'liblist' => \@tmpliblist };
131 else {
133 #Cas de la liste simple
134 foreach my $key ( sort keys %{ $numbers{$num} } ) {
135 my %cell;
136 if ( $key =~ /$num$rowcode[0-9]/ ) {
137 $cell{celvalue} = $key;
138 foreach my $lib ( @{ $numbers{$num}->{$key} } ) {
139 push @{ $cell{'libs'} }, { 'lib' => $lib };
141 push @cells, \%cell;
145 push @lines,
147 'cells' => \@cells,
148 'rowvalue' => $row->{rowvalue},
149 'rowlib' => $row->{rowlib}
152 $BIGLOOPcell{'Lists'} = \@lists if ( scalar(@lists) > 0 );
153 $BIGLOOPcell{'lines'} = \@lines if ( scalar(@lines) > 0 );
154 $BIGLOOPcell{'col_hdr'} = \@tmpcolhdr if ( scalar(@tmpcolhdr) > 0 );
155 $BIGLOOPcell{'Table'} = $numbers{$num}->{'Table'};
156 $BIGLOOPcell{'hdr_tab'} = $numbers{$num}->{'hdr_tab'};
157 $BIGLOOPcell{'number'} = $num;
158 push @BIGLOOP, \%BIGLOOPcell;
161 my ($template, $loggedinuser, $cookie)
162 = get_template_and_user({template_name => "cataloguing/value_builder/macles.tt",
163 query => $input,
164 type => "intranet",
165 authnotrequired => 0,
166 flagsrequired => {editcatalogue => '*'},
167 debug => 1,
169 $template->param(BIGLOOP=>\@BIGLOOP);
170 $template->param("index"=>$index);
171 output_html_with_http_headers $input, $cookie, $template->output;
174 return { builder => $builder, launcher => $launcher };