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;
27 use C4::AuthoritiesMarc;
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');
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, $borrowernumber, $cookie)
47 = get_template_and_user({template_name => "admin/thesaurus.tmpl",
51 flagsrequired => {parameters => 1},
57 my $prevpage = $offset-$pagesize;
58 my $nextpage =$offset+$pagesize;
60 my $op = $input->param('op');
63 $template->param(script_name => $script_name,
64 $op => 1); # we show only the TMPL_VAR names $op
66 $template->param(script_name => $script_name,
67 else => 1); # we show only the TMPL_VAR names $op
69 ################## ADD_FORM ##################################
70 # called by default. Used to create form to add or modify a record
71 if ($op eq 'add_form') {
74 my $dbh = C4::Context->dbh;
75 my $sth=$dbh->prepare("select id,category,freelib,stdlib from bibliothesaurus where id=?");
77 $data=$sth->fetchrow_hashref;
80 $data->{'category'} = $input->param('category');
81 $data->{'stdlib'} = $input->param('stdlib');
83 if ($search_category) {
84 $template->param(action => "Modify thesaurus");
86 $template->param(action => "Add thesaurus");
88 $template->param(category => $data->{'category'},
89 stdlib => $data->{'stdlib'},
90 freelib => $data->{'freelib'},
93 # toponly => $toponly,
94 search_category => $search_category,
95 searchstring => $searchstring,
99 if ($data->{'category'}) {
100 $template->param(category => "<input type=\"hidden\" name=\"category\" value='$data->{'category'}'>$data->{'category'}");
102 $template->param(category => "<input type=text name=\"category\" size=8 maxlength=8>");
104 ################## ADD_VALIDATE ##################################
105 # called by add_form, used to insert data in DB
106 } elsif ($op eq 'add_validate') {
107 my $dbh = C4::Context->dbh;
108 my $freelib = $input->param('freelib');
109 $freelib = $input->param('stdlib') unless ($input->param('freelib'));
110 newauthority($dbh,$input->param('category'),$input->param('father')." ".$input->param('stdlib'), $freelib,'',1,'');
111 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>";
113 ################## MOD_VALIDATE ##################################
114 # called by add_form, used to modify data in DB
115 } elsif ($op eq 'mod_validate') {
116 my $dbh = C4::Context->dbh;
117 my $freelib = $input->param('freelib');
118 modauthority($dbh,$id,$freelib);
119 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>";
121 ################## DELETE_CONFIRM ##################################
122 # called by default form, used to confirm deletion of data in DB
123 } elsif ($op eq 'delete_confirm') {
124 my $dbh = C4::Context->dbh;
125 my $sth=$dbh->prepare("select category,stdlib,freelib from bibliothesaurus where id=?");
127 my $data=$sth->fetchrow_hashref;
129 $template->param(search_category => $search_category,
130 Tvalue => $data->{'stdlib'},
134 # END $OP eq DELETE_CONFIRM
135 ################## DELETE_CONFIRMED ##################################
136 # called by delete_confirm, used to effectively confirm deletion of data in DB
137 } elsif ($op eq 'delete_confirmed') {
139 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=thesaurus.pl?search_category=$search_category&searchstring=$searchstring\"></html>";
141 # END $OP eq DELETE_CONFIRMED
142 ################## DETAIL_FORM ##################################
143 } elsif ($op eq 'detail_form') {
144 # build categories list
145 my $sth = $dbh->prepare("select distinct category from bibliothesaurus");
148 while ( my ($category) = $sth->fetchrow_array) {
149 push(@category_list,$category);
151 my $tab_list = CGI::scrolling_list(-name=>'search_category',
152 -values=> \@category_list,
153 -default=>"$search_category",
158 if (!$search_category) {
159 $search_category=$category_list[0];
161 my $sth = $dbh->prepare("select father,stdlib,category,hierarchy from bibliothesaurus where id=?");
163 my ($father,$stdlib,$category,$suphierarchy) = $sth->fetchrow_array;
165 $sth= $dbh->prepare("select id,freelib from bibliothesaurus where father=? and stdlib=?");
166 $sth->execute($father,$stdlib);
170 while ( my ($id,$freelib) = $sth->fetchrow_array) {
171 if ($toggle eq 'white'){
176 my %row_data; # get a fresh hash for the row data
177 $row_data{freelib} = $freelib;
178 $row_data{edit} = "$script_name?op=add_form&id=$id";
179 $row_data{delete} = "$script_name?op=delete_confirm&search_category=$search_category&id=$id";
180 push(@loop_data, \%row_data);
183 $template->param(loop => \@loop_data,
184 tab_list => $tab_list,
185 category => $search_category,
186 # toponly => $toponly,
187 searchstring => $searchstring,
189 category => $category);
190 ################## DEFAULT ##################################
192 # build categories list
193 my $sth = $dbh->prepare("select distinct category from bibliothesaurus");
196 while ( my ($category) = $sth->fetchrow_array) {
197 push(@category_list,$category);
199 my $tab_list = CGI::scrolling_list(-name=>'search_category',
200 -values=> \@category_list,
201 -default=>"$search_category",
206 if (!$search_category) {
207 $search_category=$category_list[0];
209 my ($count,$results)=searchauthority($search_category,$branch,$searchstring,$offset,$pagesize);
213 for (my $i=0; $i < $pagesize; $i++){
214 if ($results->[$i]{'stdlib'}) {
215 if ($toggle eq 'white'){
220 my %row_data; # get a fresh hash for the row data
221 $row_data{category} = $results->[$i]{'category'};
222 # $row_data{stdlib} = (" " x $results->[$i]{'level'}).$results->[$i]{'stdlib'};
223 $row_data{stdlib} = $results->[$i]{'stdlib'};
224 $row_data{freelib} = $results->[$i]{'freelib'};
225 $row_data{freelib} =~ s/($searchstring)/<b>$1<\/b>/gi;
226 $row_data{father} = $results->[$i]{'father'};
227 $row_data{dig} ="<a href=thesaurus.pl?branch=$results->[$i]{'hierarchy'}$results->[$i]{'id'}|&search_category=$search_category>";
228 $row_data{related} ="<a href=thesaurus.pl?id=$results->[$i]{'id'}&search_category=$search_category&op=detail_form>";
229 $row_data{edit} = "$script_name?op=add_form&branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$offset&id=".$results->[$i]{'id'};
230 $row_data{delete} = "$script_name?op=delete_confirm&search_category=$search_category&id=".$results->[$i]{'id'};
231 push(@loop_data, \%row_data);
234 # rebuild complete hierarchy
235 my $sth = $dbh->prepare("select stdlib from bibliothesaurus where id=?");
236 my @hierarchy = split(/\|/,$branch);
240 for (my $xi=0;$xi<=$#hierarchy;$xi++) {
242 $sth->execute($hierarchy[$xi]);
243 my ($t) = $sth->fetchrow_array;
244 $x.=$hierarchy[$xi]."|";
247 push (@hierarchy_loop, \%link);
248 $father .= $t." $authoritysep ";
250 $template->param(loop => \@loop_data,
251 tab_list => $tab_list,
252 category => $search_category,
253 # toponly => $toponly,
254 searchstring => $searchstring,
255 hierarchy_loop => \@hierarchy_loop,
259 $template->param(previous => "$script_name?branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$prevpage");
261 if ($pagesize<$count) {
262 $template->param(next => "$script_name?branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$nextpage");
264 } #---- END $OP eq DEFAULT
265 $template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
266 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
267 IntranetNav => C4::Context->preference("IntranetNav"),
269 output_html_with_http_headers $input, $cookie, $template->output;