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
25 use C4::AuthoritiesMarc;
28 my $search_category=$input->param('search_category');
29 # $search_category=$input->param('category') unless $search_category;
30 #my $toponly = $input->param('toponly');
31 my $branch = $input->param('branch');
32 my $searchstring = $input->param('searchstring');
33 # $searchstring=~ s/\,//g;
34 my $id = $input->param('id');
35 my $offset=$input->param('offset');
36 my $father=$input->param('father');
39 my $reqdel="delete from bibliothesaurus where id='$id'";
40 my $script_name="/cgi-bin/koha/admin/thesaurus.pl";
41 my $dbh = C4::Context->dbh;
42 my $authoritysep = C4::Context->preference("authoritysep");
44 my ($template, $borrowernumber, $cookie)
45 = get_template_and_user({template_name => "admin/thesaurus.tmpl",
49 flagsrequired => {parameters => 1},
55 my $prevpage = $offset-$pagesize;
56 my $nextpage =$offset+$pagesize;
58 my $op = $input->param('op');
61 $template->param(script_name => $script_name,
62 $op => 1); # we show only the TMPL_VAR names $op
64 $template->param(script_name => $script_name,
65 else => 1); # we show only the TMPL_VAR names $op
67 ################## ADD_FORM ##################################
68 # called by default. Used to create form to add or modify a record
69 if ($op eq 'add_form') {
72 my $dbh = C4::Context->dbh;
73 my $sth=$dbh->prepare("select id,category,freelib,stdlib from bibliothesaurus where id=?");
75 $data=$sth->fetchrow_hashref;
78 $data->{'category'} = $input->param('category');
79 $data->{'stdlib'} = $input->param('stdlib');
81 if ($search_category) {
82 $template->param(action => "Modify thesaurus");
84 $template->param(action => "Add thesaurus");
86 $template->param(category => $data->{'category'},
87 stdlib => $data->{'stdlib'},
88 freelib => $data->{'freelib'},
91 # toponly => $toponly,
92 search_category => $search_category,
93 searchstring => $searchstring,
97 if ($data->{'category'}) {
98 $template->param(category => "<input type=\"hidden\" name=\"category\" value='$data->{'category'}'>$data->{'category'}");
100 $template->param(category => "<input type=text name=\"category\" size=8 maxlength=8>");
102 ################## ADD_VALIDATE ##################################
103 # called by add_form, used to insert data in DB
104 } elsif ($op eq 'add_validate') {
105 my $dbh = C4::Context->dbh;
106 my $freelib = $input->param('freelib');
107 $freelib = $input->param('stdlib') unless ($input->param('freelib'));
108 newauthority($dbh,$input->param('category'),$input->param('father')." ".$input->param('stdlib'), $freelib,'',1,'');
109 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>";
111 ################## MOD_VALIDATE ##################################
112 # called by add_form, used to modify data in DB
113 } elsif ($op eq 'mod_validate') {
114 my $dbh = C4::Context->dbh;
115 my $freelib = $input->param('freelib');
116 modauthority($dbh,$id,$freelib);
117 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>";
119 ################## DELETE_CONFIRM ##################################
120 # called by default form, used to confirm deletion of data in DB
121 } elsif ($op eq 'delete_confirm') {
122 my $dbh = C4::Context->dbh;
123 my $sth=$dbh->prepare("select category,stdlib,freelib from bibliothesaurus where id=?");
125 my $data=$sth->fetchrow_hashref;
127 $template->param(search_category => $search_category,
128 Tvalue => $data->{'stdlib'},
132 # END $OP eq DELETE_CONFIRM
133 ################## DELETE_CONFIRMED ##################################
134 # called by delete_confirm, used to effectively confirm deletion of data in DB
135 } elsif ($op eq 'delete_confirmed') {
137 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=thesaurus.pl?search_category=$search_category&searchstring=$searchstring\"></html>";
139 # END $OP eq DELETE_CONFIRMED
140 ################## DETAIL_FORM ##################################
141 } elsif ($op eq 'detail_form') {
142 # build categories list
143 my $sth = $dbh->prepare("select distinct category from bibliothesaurus");
146 while ( my ($category) = $sth->fetchrow_array) {
147 push(@category_list,$category);
149 my $tab_list = CGI::scrolling_list(-name=>'search_category',
150 -values=> \@category_list,
151 -default=>"$search_category",
156 if (!$search_category) {
157 $search_category=$category_list[0];
159 my $sth = $dbh->prepare("select father,stdlib,category,hierarchy from bibliothesaurus where id=?");
161 my ($father,$stdlib,$category,$suphierarchy) = $sth->fetchrow_array;
163 $sth= $dbh->prepare("select id,freelib from bibliothesaurus where father=? and stdlib=?");
164 $sth->execute($father,$stdlib);
168 while ( my ($id,$freelib) = $sth->fetchrow_array) {
169 if ($toggle eq 'white'){
174 my %row_data; # get a fresh hash for the row data
175 $row_data{freelib} = $freelib;
176 $row_data{edit} = "$script_name?op=add_form&id=$id";
177 $row_data{delete} = "$script_name?op=delete_confirm&search_category=$search_category&id=$id";
178 push(@loop_data, \%row_data);
181 $template->param(loop => \@loop_data,
182 tab_list => $tab_list,
183 category => $search_category,
184 # toponly => $toponly,
185 searchstring => $searchstring,
187 category => $category);
188 ################## DEFAULT ##################################
190 # build categories list
191 my $sth = $dbh->prepare("select distinct category from bibliothesaurus");
194 while ( my ($category) = $sth->fetchrow_array) {
195 push(@category_list,$category);
197 my $tab_list = CGI::scrolling_list(-name=>'search_category',
198 -values=> \@category_list,
199 -default=>"$search_category",
204 if (!$search_category) {
205 $search_category=$category_list[0];
207 my ($count,$results)=searchauthority($search_category,$branch,$searchstring,$offset,$pagesize);
211 for (my $i=0; $i < $pagesize; $i++){
212 if ($results->[$i]{'stdlib'}) {
213 if ($toggle eq 'white'){
218 my %row_data; # get a fresh hash for the row data
219 $row_data{category} = $results->[$i]{'category'};
220 # $row_data{stdlib} = (" " x $results->[$i]{'level'}).$results->[$i]{'stdlib'};
221 $row_data{stdlib} = $results->[$i]{'stdlib'};
222 $row_data{freelib} = $results->[$i]{'freelib'};
223 $row_data{freelib} =~ s/($searchstring)/<b>$1<\/b>/gi;
224 $row_data{father} = $results->[$i]{'father'};
225 $row_data{dig} ="<a href=thesaurus.pl?branch=$results->[$i]{'hierarchy'}$results->[$i]{'id'}|&search_category=$search_category>";
226 $row_data{related} ="<a href=thesaurus.pl?id=$results->[$i]{'id'}&search_category=$search_category&op=detail_form>";
227 $row_data{edit} = "$script_name?op=add_form&branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$offset&id=".$results->[$i]{'id'};
228 $row_data{delete} = "$script_name?op=delete_confirm&search_category=$search_category&id=".$results->[$i]{'id'};
229 push(@loop_data, \%row_data);
232 # rebuild complete hierarchy
233 my $sth = $dbh->prepare("select stdlib from bibliothesaurus where id=?");
234 my @hierarchy = split(/\|/,$branch);
238 for (my $xi=0;$xi<=$#hierarchy;$xi++) {
240 $sth->execute($hierarchy[$xi]);
241 my ($t) = $sth->fetchrow_array;
242 $x.=$hierarchy[$xi]."|";
245 push (@hierarchy_loop, \%link);
246 $father .= $t." $authoritysep ";
248 $template->param(loop => \@loop_data,
249 tab_list => $tab_list,
250 category => $search_category,
251 # toponly => $toponly,
252 searchstring => $searchstring,
253 hierarchy_loop => \@hierarchy_loop,
257 $template->param(previous => "$script_name?branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$prevpage");
259 if ($pagesize<$count) {
260 $template->param(next => "$script_name?branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$nextpage");
262 } #---- END $OP eq DEFAULT
263 $template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
264 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
265 IntranetNav => C4::Context->preference("IntranetNav"),
267 output_html_with_http_headers $input, $cookie, $template->output;