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 my $toponly = $input->param('toponly');
32 my $branch = $input->param('branch');
33 my $searchstring = $input->param('searchstring');
34 $searchstring=~ s/\,//g;
35 my $id = $input->param('id');
36 my $offset=$input->param('offset');
37 my $father=$input->param('father');
39 my $reqsel="select category,stdlib,freelib from authorised_values where id='$id'";
40 my $reqdel="delete from authorised_values where id='$id'";
41 my $script_name="/cgi-bin/koha/admin/thesaurus.pl";
42 my $dbh = C4::Context->dbh;
43 my $authoritysep = C4::Context->preference("authoritysep");
44 warn "authority : $authoritysep";
46 my $template = gettemplate("parameters/thesaurus.tmpl",0);
48 my $op = $input->param('op');
51 $template->param(script_name => $script_name,
52 $op => 1); # we show only the TMPL_VAR names $op
54 $template->param(script_name => $script_name,
55 else => 1); # we show only the TMPL_VAR names $op
57 ################## ADD_FORM ##################################
58 # called by default. Used to create form to add or modify a record
59 if ($op eq 'add_form') {
63 my $dbh = C4::Context->dbh;
64 my $sth=$dbh->prepare("select id,category,freelib,stdlib from bibliothesaurus where id='$id'");
66 $data=$sth->fetchrow_hashref;
69 $data->{'category'} = $input->param('category');
70 $data->{'stdlib'} = $input->param('stdlib');
72 if ($search_category) {
73 $template->param(action => "Modify authorised value");
75 $template->param(action => "Add authorised value");
77 $template->param(category => $data->{'category'},
78 stdlib => $data->{'stdlib'},
79 freelib => $data->{'freelib'},
83 search_category => $search_category,
84 searchstring => $searchstring,
88 if ($data->{'category'}) {
89 $template->param(category => "<input type=\"hidden\" name=\"category\" value='$data->{'category'}'>$data->{'category'}");
91 $template->param(category => "<input type=text name=\"category\" size=8 maxlength=8>");
93 ################## ADD_VALIDATE ##################################
94 # called by add_form, used to insert/modify data in DB
95 } elsif ($op eq 'add_validate') {
96 my $dbh = C4::Context->dbh;
97 my $sth=$dbh->prepare("replace bibliothesaurus (id,category,stdlib,freelib,father,hierarchy) values (?,?,?,?,?)");
98 $sth->execute($input->param('id'), $input->param('category'), $input->param('stdlib'), $input->param('freelib'),$father);
100 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=thesaurus.pl?branch=$branch&toponly=$toponly&search_category=$search_category&searchstring=$searchstring&offset=$offset\"></html>";
102 ################## DELETE_CONFIRM ##################################
103 # called by default form, used to confirm deletion of data in DB
104 } elsif ($op eq 'delete_confirm') {
105 my $dbh = C4::Context->dbh;
106 my $sth=$dbh->prepare($reqsel);
108 my $data=$sth->fetchrow_hashref;
110 $template->param(search_category => $search_category,
111 Tvalue => $data->{'stdlib'},
115 # END $OP eq DELETE_CONFIRM
116 ################## DELETE_CONFIRMED ##################################
117 # called by delete_confirm, used to effectively confirm deletion of data in DB
118 } elsif ($op eq 'delete_confirmed') {
119 my $dbh = C4::Context->dbh;
120 my $sth=$dbh->prepare($reqdel);
123 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=thesaurus.pl?search_category=$search_category\"></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 stdlib,category from bibliothesaurus where id=?");
147 my ($stdlib,$category) = $sth->fetchrow_array;
149 $sth= $dbh->prepare("select id,freelib from bibliothesaurus where stdlib=?");
150 $sth->execute($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,
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,$toponly,$branch,$searchstring);
197 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
198 if ($toggle eq 'white'){
203 my %row_data; # get a fresh hash for the row data
204 $row_data{category} = $results->[$i]{'category'};
205 $row_data{stdlib} = (" " x $results->[$i]{'level'}).$results->[$i]{'stdlib'};
206 $row_data{stdlib} = $results->[$i]{'stdlib'};
207 $row_data{dig} ="<a href=thesaurus.pl?branch=$results->[$i]{'hierarchy'}".($results->[$i]{'hierarchy'}?"|":"")."$results->[$i]{'id'}&toponly=$toponly&search_category=$search_category>";
208 $row_data{related} ="<a href=thesaurus.pl?id=$results->[$i]{'id'}&search_category=$search_category&op=detail_form>";
209 $row_data{edit} = "$script_name?op=add_form&branch=$branch&toponly=$toponly&search_category=$search_category&searchstring=$searchstring&offset=$offset&id=".$results->[$i]{'id'};
210 $row_data{delete} = "$script_name?op=delete_confirm&search_category=$search_category&id=".$results->[$i]{'id'};
211 push(@loop_data, \%row_data);
213 # rebuild complete hierarchy
214 my $sth = $dbh->prepare("select stdlib from bibliothesaurus where id=?");
215 my @hierarchy = split(/\|/,$branch);
219 for (my $xi=0;$xi<=$#hierarchy;$xi++) {
221 $sth->execute($hierarchy[$xi]);
222 my ($t) = $sth->fetchrow_array;
226 push (@hierarchy_loop, \%link);
228 $father = $t." $authoritysep ";
230 $template->param(loop => \@loop_data,
231 tab_list => $tab_list,
232 category => $search_category,
234 searchstring => $searchstring,
235 hierarchy_loop => \@hierarchy_loop,
239 my $prevpage = $offset-$pagesize;
240 $template->param(previous => "<a href=$script_name?branch=$branch&toponly=$toponly&search_category=$search_category&searchstring=$searchstring&offset=$prevpage><< Prev</a>");
242 if ($offset+$pagesize<$count) {
243 my $nextpage =$offset+$pagesize;
244 $template->param(next => "<a href=$script_name?branch=$branch&toponly=$toponly&search_category=$search_category&searchstring=$searchstring&offset=$nextpage>Next >></a>");
246 } #---- END $OP eq DEFAULT
248 print "Content-Type: text/html\n\n", $template->output;