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 thesaurus");
78 $template->param(action => "Add thesaurus");
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 my $freelib = $input->param('freelib');
101 $freelib = $input->param('stdlib') unless ($input->param('freelib'));
102 newauthority($dbh,$input->param('category'),$input->param('father')." ".$input->param('stdlib'), $freelib,'',1,'');
103 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>";
105 ################## DELETE_CONFIRM ##################################
106 # called by default form, used to confirm deletion of data in DB
107 } elsif ($op eq 'delete_confirm') {
108 my $dbh = C4::Context->dbh;
109 my $sth=$dbh->prepare($reqsel);
111 my $data=$sth->fetchrow_hashref;
113 $template->param(search_category => $search_category,
114 Tvalue => $data->{'stdlib'},
118 # END $OP eq DELETE_CONFIRM
119 ################## DELETE_CONFIRMED ##################################
120 # called by delete_confirm, used to effectively confirm deletion of data in DB
121 } elsif ($op eq 'delete_confirmed') {
123 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=thesaurus.pl?search_category=$search_category&searchstring=$searchstring\"></html>";
125 # END $OP eq DELETE_CONFIRMED
126 ################## DETAIL_FORM ##################################
127 } elsif ($op eq 'detail_form') {
128 # build categories list
129 my $sth = $dbh->prepare("select distinct category from bibliothesaurus");
132 while ( my ($category) = $sth->fetchrow_array) {
133 push(@category_list,$category);
135 my $tab_list = CGI::scrolling_list(-name=>'search_category',
136 -values=> \@category_list,
137 -default=>"$search_category",
141 if (!$search_category) {
142 $search_category=$category_list[0];
145 my $sth = $dbh->prepare("select father,stdlib,category,hierarchy from bibliothesaurus where id=?");
147 my ($father,$stdlib,$category,$suphierarchy) = $sth->fetchrow_array;
149 $sth= $dbh->prepare("select id,freelib from bibliothesaurus where father=? and stdlib=?");
150 $sth->execute($father,$stdlib);
154 while ( my ($id,$freelib) = $sth->fetchrow_array) {
155 if ($toggle eq 'white'){
160 my %row_data; # get a fresh hash for the row data
161 $row_data{freelib} = $freelib;
162 $row_data{edit} = "$script_name?op=add_form&id=$id";
163 $row_data{delete} = "$script_name?op=delete_confirm&search_category=$search_category&id=$id";
164 push(@loop_data, \%row_data);
167 $template->param(loop => \@loop_data,
168 tab_list => $tab_list,
169 category => $search_category,
170 # toponly => $toponly,
171 searchstring => $searchstring,
173 category => $category);
174 ################## DEFAULT ##################################
176 # build categories list
177 my $sth = $dbh->prepare("select distinct category from bibliothesaurus");
180 while ( my ($category) = $sth->fetchrow_array) {
181 push(@category_list,$category);
183 my $tab_list = CGI::scrolling_list(-name=>'search_category',
184 -values=> \@category_list,
185 -default=>"$search_category",
189 if (!$search_category) {
190 $search_category=$category_list[0];
193 my ($count,$results)=searchauthority($env,$search_category,$branch,$searchstring,$offset,$pagesize);
197 for (my $i=0; $i < $pagesize; $i++){
198 if ($results->[$i]{'stdlib'}) {
199 if ($toggle eq 'white'){
204 my %row_data; # get a fresh hash for the row data
205 $row_data{category} = $results->[$i]{'category'};
206 # $row_data{stdlib} = (" " x $results->[$i]{'level'}).$results->[$i]{'stdlib'};
207 $row_data{stdlib} = $results->[$i]{'stdlib'};
208 $row_data{freelib} = $results->[$i]{'freelib'};
209 $row_data{freelib} =~ s/($searchstring)/<b>$1<\/b>/gi;
210 $row_data{father} = $results->[$i]{'father'};
211 $row_data{dig} ="<a href=thesaurus.pl?branch=$results->[$i]{'hierarchy'}$results->[$i]{'id'}|&search_category=$search_category>";
212 $row_data{related} ="<a href=thesaurus.pl?id=$results->[$i]{'id'}&search_category=$search_category&op=detail_form>";
213 $row_data{edit} = "$script_name?op=add_form&branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$offset&id=".$results->[$i]{'id'};
214 $row_data{delete} = "$script_name?op=delete_confirm&search_category=$search_category&id=".$results->[$i]{'id'};
215 push(@loop_data, \%row_data);
218 # rebuild complete hierarchy
219 my $sth = $dbh->prepare("select stdlib from bibliothesaurus where id=?");
220 my @hierarchy = split(/\|/,$branch);
224 for (my $xi=0;$xi<=$#hierarchy;$xi++) {
226 $sth->execute($hierarchy[$xi]);
227 my ($t) = $sth->fetchrow_array;
228 $x.=$hierarchy[$xi]."|";
231 push (@hierarchy_loop, \%link);
232 $father .= $t." $authoritysep ";
234 $template->param(loop => \@loop_data,
235 tab_list => $tab_list,
236 category => $search_category,
237 # toponly => $toponly,
238 searchstring => $searchstring,
239 hierarchy_loop => \@hierarchy_loop,
243 $template->param(previous => "<a href=$script_name?branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$prevpage><< Prev</a>");
245 if ($pagesize<$count) {
246 $template->param(next => "<a href=$script_name?branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$nextpage>Next >></a>");
248 } #---- END $OP eq DEFAULT
250 print "Content-Type: text/html\n\n", $template->output;