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
23 use C4::Interface::CGI::Output;
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');
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 => "admin/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=?");
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 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 ################## MOD_VALIDATE ##################################
115 # called by add_form, used to modify data in DB
116 } elsif ($op eq 'mod_validate') {
117 my $dbh = C4::Context->dbh;
118 my $freelib = $input->param('freelib');
119 modauthority($dbh,$id,$freelib);
120 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=thesaurus.pl?branch=$branch&search_category=$search_category&offset=$offset&searchstring=".CGI::escapeHTML($searchstring)."\"></html>";
122 ################## DELETE_CONFIRM ##################################
123 # called by default form, used to confirm deletion of data in DB
124 } elsif ($op eq 'delete_confirm') {
125 my $dbh = C4::Context->dbh;
126 my $sth=$dbh->prepare("select category,stdlib,freelib from bibliothesaurus where id=?");
128 my $data=$sth->fetchrow_hashref;
130 $template->param(search_category => $search_category,
131 Tvalue => $data->{'stdlib'},
135 # END $OP eq DELETE_CONFIRM
136 ################## DELETE_CONFIRMED ##################################
137 # called by delete_confirm, used to effectively confirm deletion of data in DB
138 } elsif ($op eq 'delete_confirmed') {
140 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=thesaurus.pl?search_category=$search_category&searchstring=$searchstring\"></html>";
142 # END $OP eq DELETE_CONFIRMED
143 ################## DETAIL_FORM ##################################
144 } elsif ($op eq 'detail_form') {
145 # build categories list
146 my $sth = $dbh->prepare("select distinct category from bibliothesaurus");
149 while ( my ($category) = $sth->fetchrow_array) {
150 push(@category_list,$category);
152 my $tab_list = CGI::scrolling_list(-name=>'search_category',
153 -values=> \@category_list,
154 -default=>"$search_category",
159 if (!$search_category) {
160 $search_category=$category_list[0];
163 my $sth = $dbh->prepare("select father,stdlib,category,hierarchy from bibliothesaurus where id=?");
165 my ($father,$stdlib,$category,$suphierarchy) = $sth->fetchrow_array;
167 $sth= $dbh->prepare("select id,freelib from bibliothesaurus where father=? and stdlib=?");
168 $sth->execute($father,$stdlib);
172 while ( my ($id,$freelib) = $sth->fetchrow_array) {
173 if ($toggle eq 'white'){
178 my %row_data; # get a fresh hash for the row data
179 $row_data{freelib} = $freelib;
180 $row_data{edit} = "$script_name?op=add_form&id=$id";
181 $row_data{delete} = "$script_name?op=delete_confirm&search_category=$search_category&id=$id";
182 push(@loop_data, \%row_data);
185 $template->param(loop => \@loop_data,
186 tab_list => $tab_list,
187 category => $search_category,
188 # toponly => $toponly,
189 searchstring => $searchstring,
191 category => $category);
192 ################## DEFAULT ##################################
194 # build categories list
195 my $sth = $dbh->prepare("select distinct category from bibliothesaurus");
198 while ( my ($category) = $sth->fetchrow_array) {
199 push(@category_list,$category);
201 my $tab_list = CGI::scrolling_list(-name=>'search_category',
202 -values=> \@category_list,
203 -default=>"$search_category",
208 if (!$search_category) {
209 $search_category=$category_list[0];
212 my ($count,$results)=searchauthority($env,$search_category,$branch,$searchstring,$offset,$pagesize);
216 for (my $i=0; $i < $pagesize; $i++){
217 if ($results->[$i]{'stdlib'}) {
218 if ($toggle eq 'white'){
223 my %row_data; # get a fresh hash for the row data
224 $row_data{category} = $results->[$i]{'category'};
225 # $row_data{stdlib} = (" " x $results->[$i]{'level'}).$results->[$i]{'stdlib'};
226 $row_data{stdlib} = $results->[$i]{'stdlib'};
227 $row_data{freelib} = $results->[$i]{'freelib'};
228 $row_data{freelib} =~ s/($searchstring)/<b>$1<\/b>/gi;
229 $row_data{father} = $results->[$i]{'father'};
230 $row_data{dig} ="<a href=thesaurus.pl?branch=$results->[$i]{'hierarchy'}$results->[$i]{'id'}|&search_category=$search_category>";
231 $row_data{related} ="<a href=thesaurus.pl?id=$results->[$i]{'id'}&search_category=$search_category&op=detail_form>";
232 $row_data{edit} = "$script_name?op=add_form&branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$offset&id=".$results->[$i]{'id'};
233 $row_data{delete} = "$script_name?op=delete_confirm&search_category=$search_category&id=".$results->[$i]{'id'};
234 push(@loop_data, \%row_data);
237 # rebuild complete hierarchy
238 my $sth = $dbh->prepare("select stdlib from bibliothesaurus where id=?");
239 my @hierarchy = split(/\|/,$branch);
243 for (my $xi=0;$xi<=$#hierarchy;$xi++) {
245 $sth->execute($hierarchy[$xi]);
246 my ($t) = $sth->fetchrow_array;
247 $x.=$hierarchy[$xi]."|";
250 push (@hierarchy_loop, \%link);
251 $father .= $t." $authoritysep ";
253 $template->param(loop => \@loop_data,
254 tab_list => $tab_list,
255 category => $search_category,
256 # toponly => $toponly,
257 searchstring => $searchstring,
258 hierarchy_loop => \@hierarchy_loop,
262 $template->param(previous => "$script_name?branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$prevpage");
264 if ($pagesize<$count) {
265 $template->param(next => "$script_name?branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$nextpage");
267 } #---- END $OP eq DEFAULT
268 $template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
269 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
270 IntranetNav => C4::Context->preference("IntranetNav"),
272 output_html_with_http_headers $input, $cookie, $template->output;