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
31 my ($env,$searchstring,$type)=@_;
32 my $dbh = C4::Context->dbh;
33 $searchstring=~ s/\'/\\\'/g;
34 my @data=split(' ',$searchstring);
36 my $query="Select id,category,authorised_value,lib from authorised_values where (category like \"$data[0]%\") order by category,authorised_value";
37 my $sth=$dbh->prepare($query);
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 $reqsel="select category,authorised_value,lib from authorised_values where id='$id'";
54 my $reqdel="delete from authorised_values where id='$id'";
55 my $offset=$input->param('offset');
56 my $script_name="/cgi-bin/koha/admin/authorised_values.pl";
57 my $dbh = C4::Context->dbh;
59 my ($template, $borrowernumber, $cookie)
60 = get_template_and_user({template_name => "parameters/authorised_values.tmpl",
64 flagsrequired => {parameters => 1},
68 my $op = $input->param('op');
71 $template->param(script_name => $script_name,
72 $op => 1); # we show only the TMPL_VAR names $op
74 $template->param(script_name => $script_name,
75 else => 1); # we show only the TMPL_VAR names $op
77 ################## ADD_FORM ##################################
78 # called by default. Used to create form to add or modify a record
79 if ($op eq 'add_form') {
82 my $dbh = C4::Context->dbh;
83 my $sth=$dbh->prepare("select id,category,authorised_value,lib from authorised_values where id='$id'");
85 $data=$sth->fetchrow_hashref;
88 $data->{'category'} = $input->param('category');
91 $template->param(action => "Modify authorised value");
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 $sth->execute($input->param('id'), $input->param('category'), $input->param('authorised_value'),$input->param('lib'));
112 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$input->param('category')."\"></html>";
114 ################## DELETE_CONFIRM ##################################
115 # called by default form, used to confirm deletion of data in DB
116 } elsif ($op eq 'delete_confirm') {
117 my $dbh = C4::Context->dbh;
118 my $sth=$dbh->prepare($reqsel);
120 my $data=$sth->fetchrow_hashref;
122 $template->param(searchfield => $searchfield,
123 Tvalue => $data->{'authorised_value'},
127 # END $OP eq DELETE_CONFIRM
128 ################## DELETE_CONFIRMED ##################################
129 # called by delete_confirm, used to effectively confirm deletion of data in DB
130 } elsif ($op eq 'delete_confirmed') {
131 my $dbh = C4::Context->dbh;
132 my $sth=$dbh->prepare($reqdel);
135 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=$searchfield\"></html>";
138 # END $OP eq DELETE_CONFIRMED
139 ################## DEFAULT ##################################
141 # build categories list
142 my $sth = $dbh->prepare("select distinct category from authorised_values");
145 while ( my ($category) = $sth->fetchrow_array) {
146 push(@category_list,$category);
148 # push koha system categories
149 my $tab_list = CGI::scrolling_list(-name=>'searchfield',
150 -values=> \@category_list,
156 $searchfield=$category_list[0];
159 my ($count,$results)=StringSearch($env,$searchfield,'web');
163 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
164 if ($toggle eq 'white'){
169 my %row_data; # get a fresh hash for the row data
170 $row_data{category} = $results->[$i]{'category'};
171 $row_data{authorised_value} = $results->[$i]{'authorised_value'};
172 $row_data{lib} = $results->[$i]{'lib'};
173 $row_data{edit} = "$script_name?op=add_form&id=".$results->[$i]{'id'};
174 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=$searchfield&id=".$results->[$i]{'id'};
175 push(@loop_data, \%row_data);
178 $template->param(loop => \@loop_data,
179 tab_list => $tab_list,
180 category => $searchfield);
182 my $prevpage = $offset-$pagesize;
183 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
185 if ($offset+$pagesize<$count) {
186 my $nextpage =$offset+$pagesize;
187 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
189 } #---- END $OP eq DEFAULT
191 print $input->header(-cookie => $cookie), $template->output;