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
31 my $search_category=$input->param('search_category');
32 $search_category=$input->param('category') unless $search_category;
33 #my $toponly = $input->param('toponly');
34 my $branch = $input->param('branch');
35 my $searchstring = $input->param('searchstring');
36 $searchstring=~ s/\,//g;
37 my $id = $input->param('id');
38 my $offset=$input->param('offset');
39 my $father=$input->param('father');
41 my $reqsel="select category,stdlib,freelib from bibliothesaurus where id='$id'";
42 my $reqdel="delete from bibliothesaurus where id='$id'";
43 my $script_name="/cgi-bin/koha/admin/thesaurus.pl";
44 my $dbh = C4::Context->dbh;
45 my $authoritysep = C4::Context->preference("authoritysep");
47 my ($template, $borrowernumber, $cookie)
48 = get_template_and_user({template_name => "parameters/thesaurus.tmpl",
52 flagsrequired => {parameters => 1},
58 my $prevpage = $offset-$pagesize;
59 my $nextpage =$offset+$pagesize;
61 my $op = $input->param('op');
64 $template->param(script_name => $script_name,
65 $op => 1); # we show only the TMPL_VAR names $op
67 $template->param(script_name => $script_name,
68 else => 1); # we show only the TMPL_VAR names $op
70 ################## ADD_FORM ##################################
71 # called by default. Used to create form to add or modify a record
72 if ($op eq 'add_form') {
75 my $dbh = C4::Context->dbh;
76 my $sth=$dbh->prepare("select id,category,freelib,stdlib from bibliothesaurus where id='$id'");
78 $data=$sth->fetchrow_hashref;
81 $data->{'category'} = $input->param('category');
82 $data->{'stdlib'} = $input->param('stdlib');
84 if ($search_category) {
85 $template->param(action => "Modify thesaurus");
87 $template->param(action => "Add thesaurus");
89 $template->param(category => $data->{'category'},
90 stdlib => $data->{'stdlib'},
91 freelib => $data->{'freelib'},
94 # toponly => $toponly,
95 search_category => $search_category,
96 searchstring => $searchstring,
100 if ($data->{'category'}) {
101 $template->param(category => "<input type=\"hidden\" name=\"category\" value='$data->{'category'}'>$data->{'category'}");
103 $template->param(category => "<input type=text name=\"category\" size=8 maxlength=8>");
105 ################## ADD_VALIDATE ##################################
106 # called by add_form, used to insert/modify data in DB
107 } elsif ($op eq 'add_validate') {
108 my $dbh = C4::Context->dbh;
109 my $freelib = $input->param('freelib');
110 $freelib = $input->param('stdlib') unless ($input->param('freelib'));
111 newauthority($dbh,$input->param('category'),$input->param('father')." ".$input->param('stdlib'), $freelib,'',1,'');
112 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>";
114 ################## DELETE_CONFIRM ##################################
115 # called by default form, used to confirm deletion of data in DB
116 } elsif ($op eq 'delete_confirm') {
117 my $dbh = C4::Context->dbh;
118 my $sth=$dbh->prepare($reqsel);
120 my $data=$sth->fetchrow_hashref;
122 $template->param(search_category => $search_category,
123 Tvalue => $data->{'stdlib'},
127 # END $OP eq DELETE_CONFIRM
128 ################## DELETE_CONFIRMED ##################################
129 # called by delete_confirm, used to effectively confirm deletion of data in DB
130 } elsif ($op eq 'delete_confirmed') {
132 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=thesaurus.pl?search_category=$search_category&searchstring=$searchstring\"></html>";
134 # END $OP eq DELETE_CONFIRMED
135 ################## DETAIL_FORM ##################################
136 } elsif ($op eq 'detail_form') {
137 # build categories list
138 my $sth = $dbh->prepare("select distinct category from bibliothesaurus");
141 while ( my ($category) = $sth->fetchrow_array) {
142 push(@category_list,$category);
144 my $tab_list = CGI::scrolling_list(-name=>'search_category',
145 -values=> \@category_list,
146 -default=>"$search_category",
150 if (!$search_category) {
151 $search_category=$category_list[0];
154 my $sth = $dbh->prepare("select father,stdlib,category,hierarchy from bibliothesaurus where id=?");
156 my ($father,$stdlib,$category,$suphierarchy) = $sth->fetchrow_array;
158 $sth= $dbh->prepare("select id,freelib from bibliothesaurus where father=? and stdlib=?");
159 $sth->execute($father,$stdlib);
163 while ( my ($id,$freelib) = $sth->fetchrow_array) {
164 if ($toggle eq 'white'){
169 my %row_data; # get a fresh hash for the row data
170 $row_data{freelib} = $freelib;
171 $row_data{edit} = "$script_name?op=add_form&id=$id";
172 $row_data{delete} = "$script_name?op=delete_confirm&search_category=$search_category&id=$id";
173 push(@loop_data, \%row_data);
176 $template->param(loop => \@loop_data,
177 tab_list => $tab_list,
178 category => $search_category,
179 # toponly => $toponly,
180 searchstring => $searchstring,
182 category => $category);
183 ################## DEFAULT ##################################
185 # build categories list
186 my $sth = $dbh->prepare("select distinct category from bibliothesaurus");
189 while ( my ($category) = $sth->fetchrow_array) {
190 push(@category_list,$category);
192 my $tab_list = CGI::scrolling_list(-name=>'search_category',
193 -values=> \@category_list,
194 -default=>"$search_category",
198 if (!$search_category) {
199 $search_category=$category_list[0];
202 my ($count,$results)=searchauthority($env,$search_category,$branch,$searchstring,$offset,$pagesize);
206 for (my $i=0; $i < $pagesize; $i++){
207 if ($results->[$i]{'stdlib'}) {
208 if ($toggle eq 'white'){
213 my %row_data; # get a fresh hash for the row data
214 $row_data{category} = $results->[$i]{'category'};
215 # $row_data{stdlib} = (" " x $results->[$i]{'level'}).$results->[$i]{'stdlib'};
216 $row_data{stdlib} = $results->[$i]{'stdlib'};
217 $row_data{freelib} = $results->[$i]{'freelib'};
218 $row_data{freelib} =~ s/($searchstring)/<b>$1<\/b>/gi;
219 $row_data{father} = $results->[$i]{'father'};
220 $row_data{dig} ="<a href=thesaurus.pl?branch=$results->[$i]{'hierarchy'}$results->[$i]{'id'}|&search_category=$search_category>";
221 $row_data{related} ="<a href=thesaurus.pl?id=$results->[$i]{'id'}&search_category=$search_category&op=detail_form>";
222 $row_data{edit} = "$script_name?op=add_form&branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$offset&id=".$results->[$i]{'id'};
223 $row_data{delete} = "$script_name?op=delete_confirm&search_category=$search_category&id=".$results->[$i]{'id'};
224 push(@loop_data, \%row_data);
227 # rebuild complete hierarchy
228 my $sth = $dbh->prepare("select stdlib from bibliothesaurus where id=?");
229 my @hierarchy = split(/\|/,$branch);
233 for (my $xi=0;$xi<=$#hierarchy;$xi++) {
235 $sth->execute($hierarchy[$xi]);
236 my ($t) = $sth->fetchrow_array;
237 $x.=$hierarchy[$xi]."|";
240 push (@hierarchy_loop, \%link);
241 $father .= $t." $authoritysep ";
243 $template->param(loop => \@loop_data,
244 tab_list => $tab_list,
245 category => $search_category,
246 # toponly => $toponly,
247 searchstring => $searchstring,
248 hierarchy_loop => \@hierarchy_loop,
252 $template->param(previous => "<a href=$script_name?branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$prevpage><< Prev</a>");
254 if ($pagesize<$count) {
255 $template->param(next => "<a href=$script_name?branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$nextpage>Next >></a>");
257 } #---- END $OP eq DEFAULT
259 print $input->header(
260 -type => guesstype($template->output),
262 ), $template->output;