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::Interface::CGI::Output;
32 my ($env,$searchstring,$type)=@_;
33 my $dbh = C4::Context->dbh;
34 $searchstring=~ s/\'/\\\'/g;
35 my @data=split(' ',$searchstring);
37 my $sth=$dbh->prepare("Select id,category,authorised_value,lib from authorised_values where (category like ?) order by category,authorised_value");
38 $sth->execute("$data[0]%");
41 while (my $data=$sth->fetchrow_hashref){
46 return ($cnt,\@results);
50 my $searchfield=$input->param('searchfield');
51 $searchfield=~ s/\,//g;
52 my $id = $input->param('id');
53 my $offset=$input->param('offset');
54 my $script_name="/cgi-bin/koha/admin/authorised_values.pl";
55 my $dbh = C4::Context->dbh;
57 my ($template, $borrowernumber, $cookie)
58 = get_template_and_user({template_name => "parameters/authorised_values.tmpl",
62 flagsrequired => {parameters => 1},
66 my $op = $input->param('op');
69 $template->param(script_name => $script_name,
70 $op => 1); # we show only the TMPL_VAR names $op
72 $template->param(script_name => $script_name,
73 else => 1); # we show only the TMPL_VAR names $op
75 ################## ADD_FORM ##################################
76 # called by default. Used to create form to add or modify a record
77 if ($op eq 'add_form') {
80 my $dbh = C4::Context->dbh;
81 my $sth=$dbh->prepare("select id,category,authorised_value,lib from authorised_values where id=?");
83 $data=$sth->fetchrow_hashref;
86 $data->{'category'} = $input->param('category');
89 $template->param(action => "Modify authorised value");
90 } elsif ( ! $data->{'category'} ) {
91 $template->param(action => "Add new category");
93 $template->param(action => "Add authorised value");
95 $template->param(category => $data->{'category'},
96 authorised_value => $data->{'authorised_value'},
97 lib => $data->{'lib'},
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/modify data in DB
107 } elsif ($op eq 'add_validate') {
108 my $dbh = C4::Context->dbh;
109 my $sth=$dbh->prepare("replace authorised_values (id,category,authorised_value,lib) values (?,?,?,?)");
110 my $lib = $input->param('lib');
111 undef $lib if ($lib eq ""); # to insert NULL instead of a blank string
113 $sth->execute($input->param('id'), $input->param('category'), $input->param('authorised_value'), $lib);
115 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$input->param('category')."\"></html>";
117 ################## DELETE_CONFIRM ##################################
118 # called by default form, used to confirm deletion of data in DB
119 } elsif ($op eq 'delete_confirm') {
120 my $dbh = C4::Context->dbh;
121 my $sth=$dbh->prepare("select category,authorised_value,lib from authorised_values where id=?");
123 my $data=$sth->fetchrow_hashref;
125 $template->param(searchfield => $searchfield,
126 Tvalue => $data->{'authorised_value'},
130 # END $OP eq DELETE_CONFIRM
131 ################## DELETE_CONFIRMED ##################################
132 # called by delete_confirm, used to effectively confirm deletion of data in DB
133 } elsif ($op eq 'delete_confirmed') {
134 my $dbh = C4::Context->dbh;
135 my $sth=$dbh->prepare("delete from authorised_values where id=?");
138 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=$searchfield\"></html>";
141 # END $OP eq DELETE_CONFIRMED
142 ################## DEFAULT ##################################
144 # build categories list
145 my $sth = $dbh->prepare("select distinct category from authorised_values");
148 while ( my ($category) = $sth->fetchrow_array) {
149 push(@category_list,$category);
151 # push koha system categories
152 my $tab_list = CGI::scrolling_list(-name=>'searchfield',
153 -values=> \@category_list,
159 $searchfield=$category_list[0];
162 my ($count,$results)=StringSearch($env,$searchfield,'web');
166 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
167 if ($toggle eq 'white'){
172 my %row_data; # get a fresh hash for the row data
173 $row_data{category} = $results->[$i]{'category'};
174 $row_data{authorised_value} = $results->[$i]{'authorised_value'};
175 $row_data{lib} = $results->[$i]{'lib'};
176 $row_data{edit} = "$script_name?op=add_form&id=".$results->[$i]{'id'};
177 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=$searchfield&id=".$results->[$i]{'id'};
178 push(@loop_data, \%row_data);
181 $template->param(loop => \@loop_data,
182 tab_list => $tab_list,
183 category => $searchfield);
186 my $prevpage = $offset-$pagesize;
187 $template->param(isprevpage => $offset,
188 prevpage=> $prevpage,
189 searchfield => $searchfield,
190 script_name => $script_name,
193 if ($offset+$pagesize<$count) {
194 my $nextpage =$offset+$pagesize;
195 $template->param(nextpage =>$nextpage,
196 searchfield => $searchfield,
197 script_name => $script_name,
200 } #---- END $OP eq DEFAULT
202 output_html_with_http_headers $input, $cookie, $template->output;