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
32 my ($env,$searchstring,$type)=@_;
33 my $dbh = C4::Context->dbh;
34 $searchstring=~ s/\'/\\\'/g;
35 my @data=split(' ',$searchstring);
37 my $query="Select id,category,authorised_value,lib from authorised_values where (category like \"$data[0]%\") order by category,authorised_value";
38 my $sth=$dbh->prepare($query);
42 while (my $data=$sth->fetchrow_hashref){
47 return ($cnt,\@results);
51 my $searchfield=$input->param('searchfield');
52 $searchfield=~ s/\,//g;
53 my $id = $input->param('id');
54 my $reqsel="select category,authorised_value,lib from authorised_values where id='$id'";
55 my $reqdel="delete from authorised_values where id='$id'";
56 my $offset=$input->param('offset');
57 my $script_name="/cgi-bin/koha/admin/authorised_values.pl";
58 my $dbh = C4::Context->dbh;
60 my ($template, $borrowernumber, $cookie)
61 = get_template_and_user({template_name => "parameters/authorised_values.tmpl",
65 flagsrequired => {parameters => 1},
69 my $op = $input->param('op');
72 $template->param(script_name => $script_name,
73 $op => 1); # we show only the TMPL_VAR names $op
75 $template->param(script_name => $script_name,
76 else => 1); # we show only the TMPL_VAR names $op
78 ################## ADD_FORM ##################################
79 # called by default. Used to create form to add or modify a record
80 if ($op eq 'add_form') {
83 my $dbh = C4::Context->dbh;
84 my $sth=$dbh->prepare("select id,category,authorised_value,lib from authorised_values where id='$id'");
86 $data=$sth->fetchrow_hashref;
89 $data->{'category'} = $input->param('category');
92 $template->param(action => "Modify authorised value");
94 $template->param(action => "Add authorised value");
96 $template->param(category => $data->{'category'},
97 authorised_value => $data->{'authorised_value'},
98 lib => $data->{'lib'},
101 if ($data->{'category'}) {
102 $template->param(category => "<input type=\"hidden\" name=\"category\" value='$data->{'category'}'>$data->{'category'}");
104 $template->param(category => "<input type=text name=\"category\" size=8 maxlength=8>");
106 ################## ADD_VALIDATE ##################################
107 # called by add_form, used to insert/modify data in DB
108 } elsif ($op eq 'add_validate') {
109 my $dbh = C4::Context->dbh;
110 my $sth=$dbh->prepare("replace authorised_values (id,category,authorised_value,lib) values (?,?,?,?)");
111 $sth->execute($input->param('id'), $input->param('category'), $input->param('authorised_value'),$input->param('lib'));
113 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$input->param('category')."\"></html>";
115 ################## DELETE_CONFIRM ##################################
116 # called by default form, used to confirm deletion of data in DB
117 } elsif ($op eq 'delete_confirm') {
118 my $dbh = C4::Context->dbh;
119 my $sth=$dbh->prepare($reqsel);
121 my $data=$sth->fetchrow_hashref;
123 $template->param(searchfield => $searchfield,
124 Tvalue => $data->{'authorised_value'},
128 # END $OP eq DELETE_CONFIRM
129 ################## DELETE_CONFIRMED ##################################
130 # called by delete_confirm, used to effectively confirm deletion of data in DB
131 } elsif ($op eq 'delete_confirmed') {
132 my $dbh = C4::Context->dbh;
133 my $sth=$dbh->prepare($reqdel);
136 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=$searchfield\"></html>";
139 # END $OP eq DELETE_CONFIRMED
140 ################## DEFAULT ##################################
142 # build categories list
143 my $sth = $dbh->prepare("select distinct category from authorised_values");
146 while ( my ($category) = $sth->fetchrow_array) {
147 push(@category_list,$category);
149 # push koha system categories
150 my $tab_list = CGI::scrolling_list(-name=>'searchfield',
151 -values=> \@category_list,
157 $searchfield=$category_list[0];
160 my ($count,$results)=StringSearch($env,$searchfield,'web');
164 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
165 if ($toggle eq 'white'){
170 my %row_data; # get a fresh hash for the row data
171 $row_data{category} = $results->[$i]{'category'};
172 $row_data{authorised_value} = $results->[$i]{'authorised_value'};
173 $row_data{lib} = $results->[$i]{'lib'};
174 $row_data{edit} = "$script_name?op=add_form&id=".$results->[$i]{'id'};
175 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=$searchfield&id=".$results->[$i]{'id'};
176 push(@loop_data, \%row_data);
179 $template->param(loop => \@loop_data,
180 tab_list => $tab_list,
181 category => $searchfield);
183 my $prevpage = $offset-$pagesize;
184 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
186 if ($offset+$pagesize<$count) {
187 my $nextpage =$offset+$pagesize;
188 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
190 } #---- END $OP eq DEFAULT
192 print $input->header(
193 -type => guesstype($template->output),
195 ), $template->output;