3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
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
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.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
30 my $search_category=$input->param('search_category');
31 $search_category=$input->param('category') unless $search_category;
32 #my $toponly = $input->param('toponly');
33 my $branch = $input->param('branch');
34 my $searchstring = $input->param('searchstring');
35 $searchstring=~ s/\,//g;
36 my $id = $input->param('id');
37 my $offset=$input->param('offset');
38 my $father=$input->param('father');
40 my $reqsel="select category,stdlib,freelib from bibliothesaurus where id='$id'";
41 my $reqdel="delete from bibliothesaurus where id='$id'";
42 my $script_name="/cgi-bin/koha/admin/thesaurus.pl";
43 my $dbh = C4::Context->dbh;
44 my $authoritysep = C4::Context->preference("authoritysep");
46 my $template = gettemplate("parameters/thesaurus.tmpl",0);
49 my $prevpage = $offset-$pagesize;
50 my $nextpage =$offset+$pagesize;
52 my $op = $input->param('op');
55 $template->param(script_name => $script_name,
56 $op => 1); # we show only the TMPL_VAR names $op
58 $template->param(script_name => $script_name,
59 else => 1); # we show only the TMPL_VAR names $op
61 ################## ADD_FORM ##################################
62 # called by default. Used to create form to add or modify a record
63 if ($op eq 'add_form') {
66 my $dbh = C4::Context->dbh;
67 my $sth=$dbh->prepare("select id,category,freelib,stdlib from bibliothesaurus where id='$id'");
69 $data=$sth->fetchrow_hashref;
72 $data->{'category'} = $input->param('category');
73 $data->{'stdlib'} = $input->param('stdlib');
75 if ($search_category) {
76 $template->param(action => "Modify authorised value");
78 $template->param(action => "Add authorised value");
80 $template->param(category => $data->{'category'},
81 stdlib => $data->{'stdlib'},
82 freelib => $data->{'freelib'},
85 # toponly => $toponly,
86 search_category => $search_category,
87 searchstring => $searchstring,
91 if ($data->{'category'}) {
92 $template->param(category => "<input type=\"hidden\" name=\"category\" value='$data->{'category'}'>$data->{'category'}");
94 $template->param(category => "<input type=text name=\"category\" size=8 maxlength=8>");
96 ################## ADD_VALIDATE ##################################
97 # called by add_form, used to insert/modify data in DB
98 } elsif ($op eq 'add_validate') {
99 my $dbh = C4::Context->dbh;
100 newauthority($dbh,$input->param('category'),$input->param('stdlib'), $input->param('freelib'),'',1,'');
101 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=thesaurus.pl?branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$offset\"></html>";
103 ################## DELETE_CONFIRM ##################################
104 # called by default form, used to confirm deletion of data in DB
105 } elsif ($op eq 'delete_confirm') {
106 my $dbh = C4::Context->dbh;
107 my $sth=$dbh->prepare($reqsel);
109 my $data=$sth->fetchrow_hashref;
111 $template->param(search_category => $search_category,
112 Tvalue => $data->{'stdlib'},
116 # END $OP eq DELETE_CONFIRM
117 ################## DELETE_CONFIRMED ##################################
118 # called by delete_confirm, used to effectively confirm deletion of data in DB
119 } elsif ($op eq 'delete_confirmed') {
120 # my $dbh = C4::Context->dbh;
121 # my $sth=$dbh->prepare($reqdel);
125 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=thesaurus.pl?search_category=$search_category&searchstring=$searchstring\"></html>";
127 # END $OP eq DELETE_CONFIRMED
128 ################## DETAIL_FORM ##################################
129 } elsif ($op eq 'detail_form') {
130 # build categories list
131 my $sth = $dbh->prepare("select distinct category from bibliothesaurus");
134 while ( my ($category) = $sth->fetchrow_array) {
135 push(@category_list,$category);
137 my $tab_list = CGI::scrolling_list(-name=>'search_category',
138 -values=> \@category_list,
139 -default=>"$search_category",
143 if (!$search_category) {
144 $search_category=$category_list[0];
147 my $sth = $dbh->prepare("select father,stdlib,category,hierarchy from bibliothesaurus where id=?");
149 my ($father,$stdlib,$category,$suphierarchy) = $sth->fetchrow_array;
151 $sth= $dbh->prepare("select id,freelib from bibliothesaurus where father=? and stdlib=?");
152 $sth->execute($father,$stdlib);
156 while ( my ($id,$freelib) = $sth->fetchrow_array) {
157 if ($toggle eq 'white'){
162 my %row_data; # get a fresh hash for the row data
163 $row_data{freelib} = $freelib;
164 $row_data{edit} = "$script_name?op=add_form&id=$id";
165 $row_data{delete} = "$script_name?op=delete_confirm&search_category=$search_category&id=$id";
166 push(@loop_data, \%row_data);
169 $template->param(loop => \@loop_data,
170 tab_list => $tab_list,
171 category => $search_category,
172 # toponly => $toponly,
173 searchstring => $searchstring,
175 category => $category);
176 ################## DEFAULT ##################################
178 # build categories list
179 my $sth = $dbh->prepare("select distinct category from bibliothesaurus");
182 while ( my ($category) = $sth->fetchrow_array) {
183 push(@category_list,$category);
185 my $tab_list = CGI::scrolling_list(-name=>'search_category',
186 -values=> \@category_list,
187 -default=>"$search_category",
191 if (!$search_category) {
192 $search_category=$category_list[0];
195 my ($count,$results)=searchauthority($env,$search_category,$branch,$searchstring,$offset,$pagesize);
199 for (my $i=0; $i < $pagesize; $i++){
200 if ($results->[$i]{'stdlib'}) {
201 if ($toggle eq 'white'){
206 my %row_data; # get a fresh hash for the row data
207 $row_data{category} = $results->[$i]{'category'};
208 # $row_data{stdlib} = (" " x $results->[$i]{'level'}).$results->[$i]{'stdlib'};
209 $row_data{stdlib} = $results->[$i]{'stdlib'};
210 $row_data{freelib} = $results->[$i]{'freelib'};
211 $row_data{freelib} =~ s/($searchstring)/<b>$1<\/b>/gi;
212 $row_data{father} = $results->[$i]{'father'};
213 $row_data{dig} ="<a href=thesaurus.pl?branch=$results->[$i]{'hierarchy'}$results->[$i]{'id'}|&search_category=$search_category>";
214 $row_data{related} ="<a href=thesaurus.pl?id=$results->[$i]{'id'}&search_category=$search_category&op=detail_form>";
215 $row_data{edit} = "$script_name?op=add_form&branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$offset&id=".$results->[$i]{'id'};
216 $row_data{delete} = "$script_name?op=delete_confirm&search_category=$search_category&id=".$results->[$i]{'id'};
217 push(@loop_data, \%row_data);
220 # rebuild complete hierarchy
221 my $sth = $dbh->prepare("select stdlib from bibliothesaurus where id=?");
222 my @hierarchy = split(/\|/,$branch);
226 for (my $xi=0;$xi<=$#hierarchy;$xi++) {
228 $sth->execute($hierarchy[$xi]);
229 my ($t) = $sth->fetchrow_array;
230 $x.=$hierarchy[$xi]."|";
233 push (@hierarchy_loop, \%link);
234 $father .= $t." $authoritysep ";
236 $template->param(loop => \@loop_data,
237 tab_list => $tab_list,
238 category => $search_category,
239 # toponly => $toponly,
240 searchstring => $searchstring,
241 hierarchy_loop => \@hierarchy_loop,
245 $template->param(previous => "<a href=$script_name?branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$prevpage><< Prev</a>");
247 if ($pagesize<$count) {
248 $template->param(next => "<a href=$script_name?branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$nextpage>Next >></a>");
250 } #---- END $OP eq DEFAULT
252 print "Content-Type: text/html\n\n", $template->output;