Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
|
3 |
# Copyright 2012 Xercode Media Software S.L. |
4 |
# |
5 |
# This file is part of Koha. |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it under the |
8 |
# terms of the GNU General Public License as published by the Free Software |
9 |
# Foundation; either version 2 of the License, or (at your option) any later |
10 |
# version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
13 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
14 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
15 |
# |
16 |
# You should have received a copy of the GNU General Public License along |
17 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 |
|
20 |
use strict; |
21 |
use warnings; |
22 |
use CGI; |
23 |
use C4::Context; |
24 |
use C4::Output; |
25 |
use C4::Auth; |
26 |
use C4::Koha; |
27 |
use C4::Languages qw(getTranslatedLanguages); |
28 |
use Data::Dumper; |
29 |
|
30 |
my $input = new CGI; |
31 |
our $dbh = C4::Context->dbh; |
32 |
my $ERROR = $input->param('ERROR') || 0; |
33 |
my $query; |
34 |
my $script_name = "/cgi-bin/koha/admin/facets.pl"; |
35 |
|
36 |
my $op = $input->param('op') || ""; |
37 |
my $id = $input->param('idFacet'); |
38 |
|
39 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
40 |
{ template_name => "admin/facets.tt", |
41 |
query => $input, |
42 |
type => "intranet", |
43 |
authnotrequired => 0, |
44 |
flagsrequired => { parameters => 1 }, |
45 |
debug => 1, |
46 |
} |
47 |
); |
48 |
|
49 |
sub getTabListAuthValues { |
50 |
my $selected = shift; |
51 |
|
52 |
my $sth = $dbh->prepare("SELECT DISTINCT category FROM authorised_values"); |
53 |
$sth->execute; |
54 |
my @category_list; |
55 |
my %categories; # a hash, to check that some hardcoded categories exist. |
56 |
push(@category_list,""); |
57 |
while ( my ($category) = $sth->fetchrow_array) { |
58 |
push(@category_list,$category); |
59 |
} |
60 |
|
61 |
#reorder the list |
62 |
@category_list = sort {$a cmp $b} @category_list; |
63 |
my $tab_list = CGI::scrolling_list(-name=>'authorised_value', |
64 |
-id=>'authorised_value', |
65 |
-values => \@category_list, |
66 |
-default => $selected, |
67 |
-size => 1, |
68 |
-multiple=> 0, |
69 |
); |
70 |
|
71 |
return $tab_list; |
72 |
} |
73 |
|
74 |
|
75 |
if ($op eq "add_form"){ |
76 |
my $tabListAuthValues = getTabListAuthValues(''); |
77 |
$template->param('tabListAuthValues', $tabListAuthValues); |
78 |
|
79 |
}elsif ($op eq "save_facet"){ |
80 |
|
81 |
$query = "INSERT INTO facets "; |
82 |
$query.= "(marcflavour, idx, label, authorised_value, tags, position, vlength, expanded, singleBranchMode, active, category, sep) "; |
83 |
$query.= "VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"; |
84 |
my $sth3 = $dbh->prepare($query); |
85 |
|
86 |
$sth3->execute( |
87 |
$input->param('marcflavour'), |
88 |
$input->param('idx'), |
89 |
$input->param('label'), |
90 |
$input->param('authorised_value'), |
91 |
$input->param('tags'), |
92 |
$input->param('position'), |
93 |
$input->param('vlength'), |
94 |
($input->param('expanded')?1:0), |
95 |
($input->param('singleBranchMode')?1:0), |
96 |
($input->param('active')?1:0), |
97 |
$input->param('category'), |
98 |
$input->param('sep') |
99 |
); |
100 |
$sth3->finish; |
101 |
print $input->redirect($script_name); |
102 |
|
103 |
}elsif( $op eq "edit_form" ){ |
104 |
|
105 |
$query = "SELECT * FROM facets WHERE idFacet = ?"; |
106 |
my $sth3 = $dbh->prepare($query); |
107 |
$sth3->execute($id); |
108 |
my $data = $sth3->fetchrow_hashref; |
109 |
$template->param( |
110 |
idFacet => $data->{idFacet}, |
111 |
marcflavour => $data->{marcflavour}, |
112 |
idx => $data->{idx}, |
113 |
label => $data->{label}, |
114 |
authorised_value => $data->{authorised_value}, |
115 |
tags => $data->{tags}, |
116 |
position => $data->{position}, |
117 |
vlength => $data->{vlength}, |
118 |
expanded => $data->{expanded}, |
119 |
singleBranchMode => $data->{singleBranchMode}, |
120 |
active => $data->{active}, |
121 |
category => $data->{category}, |
122 |
sep => $data->{sep} |
123 |
); |
124 |
$sth3->finish; |
125 |
|
126 |
my $tabListAuthValues = getTabListAuthValues($data->{authorised_value}); |
127 |
$template->param('tabListAuthValues', $tabListAuthValues); |
128 |
|
129 |
}elsif( $op eq "update_facet" ){ |
130 |
|
131 |
$query = "UPDATE facets SET "; |
132 |
$query.= "marcflavour = ?, idx = ?, label = ?, authorised_value = ?, tags = ?, "; |
133 |
$query.= "position = ?, vlength = ?, expanded = ?, singleBranchMode = ?, "; |
134 |
$query.= "active = ?, category = ?, sep = ? "; |
135 |
$query.= "WHERE idFacet = ?"; |
136 |
my $sth3 = $dbh->prepare($query); |
137 |
$sth3->execute( |
138 |
$input->param('marcflavour'), |
139 |
$input->param('idx'), |
140 |
$input->param('label'), |
141 |
$input->param('authorised_value'), |
142 |
$input->param('tags'), |
143 |
$input->param('position'), |
144 |
$input->param('vlength'), |
145 |
($input->param('expanded')?1:0), |
146 |
($input->param('singleBranchMode')?1:0), |
147 |
($input->param('active')?1:0), |
148 |
$input->param('category'), |
149 |
$input->param('sep'), |
150 |
$input->param('idFacet') ); |
151 |
$sth3->finish; |
152 |
print $input->redirect($script_name); |
153 |
|
154 |
}elsif( $op eq "delete_confirmed"){ |
155 |
|
156 |
$query = "DELETE FROM facets WHERE idFacet = ?"; |
157 |
my $sth3 = $dbh->prepare($query); |
158 |
$sth3->execute( $id ); |
159 |
$sth3->finish; |
160 |
|
161 |
print $input->redirect($script_name); |
162 |
|
163 |
}elsif( $op eq "delete_confirm"){ |
164 |
|
165 |
$query = "SELECT * FROM facets WHERE idFacet = ?"; |
166 |
my $sth3 = $dbh->prepare($query); |
167 |
$sth3->execute($id); |
168 |
my $data = $sth3->fetchrow_hashref; |
169 |
$template->param( |
170 |
idFacet => $data->{idFacet}, |
171 |
marcflavour => $data->{marcflavour}, |
172 |
label => $data->{label}, |
173 |
tags => $data->{tags} |
174 |
); |
175 |
$sth3->finish; |
176 |
|
177 |
}else{ |
178 |
|
179 |
$query = "SELECT * FROM facets "; |
180 |
my $sth3 = $dbh->prepare($query); |
181 |
$sth3->execute(); |
182 |
my @loop_data; |
183 |
while ( my $r = $sth3->fetchrow_hashref ) { |
184 |
push @loop_data, { |
185 |
idFacet => $r->{idFacet}, |
186 |
marcflavour => $r->{marcflavour}, |
187 |
idx => $r->{idx}, |
188 |
label => $r->{label}, |
189 |
authorised_value => $r->{authorised_value}, |
190 |
tags => $r->{tags}, |
191 |
expanded => $r->{expanded}, |
192 |
singleBranchMode => $r->{singleBranchMode}, |
193 |
active => $r->{active} |
194 |
}; |
195 |
} |
196 |
$template->param( loop => \@loop_data ); |
197 |
$template->param( op => $op ) if ($op ne ""); |
198 |
$template->param( else => 1 ); |
199 |
$sth3->finish; |
200 |
|
201 |
} |
202 |
|
203 |
$template->param( op => $op ) if ($op ne ""); |
204 |
$template->param( id => $id ); |
205 |
$template->param( script_name => $script_name ); |
206 |
|
207 |
my $use_zebra_facets = C4::Context->config('use_zebra_facets'); |
208 |
$template->param( use_zebra_facets => $use_zebra_facets ); |
209 |
|
210 |
output_html_with_http_headers $input, $cookie, $template->output; |
211 |
|