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;
31 my ($env,$searchstring,$type)=@_;
32 my $dbh = C4::Context->dbh;
33 $searchstring=~ s/\'/\\\'/g;
34 my @data=split(' ',$searchstring);
36 my $sth=$dbh->prepare("Select id,category,authorised_value,lib from authorised_values where (category like ?) order by category,authorised_value");
37 $sth->execute("$data[0]%");
40 while (my $data=$sth->fetchrow_hashref){
45 return ($cnt,\@results);
49 my $searchfield=$input->param('searchfield');
50 $searchfield=~ s/\,//g;
51 my $id = $input->param('id');
52 my $offset=$input->param('offset');
53 my $script_name="/cgi-bin/koha/admin/authorised_values.pl";
54 my $dbh = C4::Context->dbh;
56 my ($template, $borrowernumber, $cookie)
57 = get_template_and_user({template_name => "admin/authorised_values.tmpl",
61 flagsrequired => {parameters => 1},
65 my $op = $input->param('op');
68 $template->param(script_name => $script_name,
69 $op => 1); # we show only the TMPL_VAR names $op
71 $template->param(script_name => $script_name,
72 else => 1); # we show only the TMPL_VAR names $op
74 ################## ADD_FORM ##################################
75 # called by default. Used to create form to add or modify a record
76 if ($op eq 'add_form') {
79 my $dbh = C4::Context->dbh;
80 my $sth=$dbh->prepare("select id,category,authorised_value,lib from authorised_values where id=?");
82 $data=$sth->fetchrow_hashref;
85 $data->{'category'} = $input->param('category');
88 $template->param(action_modify => 1);
89 $template->param('heading-modify-authorized-value-p' => 1);
90 } elsif ( ! $data->{'category'} ) {
91 $template->param(action_add_category => 1);
92 $template->param('heading-add-new-category-p' => 1);
94 $template->param(action_add_value => 1);
95 $template->param('heading-add-authorized-value-p' => 1);
97 $template->param('use-heading-flags-p' => 1);
98 $template->param(category => $data->{'category'},
99 authorised_value => $data->{'authorised_value'},
100 lib => $data->{'lib'},
103 if ($data->{'category'}) {
104 $template->param(category => "<input type=\"hidden\" name=\"category\" value='$data->{'category'}'>$data->{'category'}");
106 $template->param(category => "<input type=text name=\"category\" size=8 maxlength=8>");
108 ################## ADD_VALIDATE ##################################
109 # called by add_form, used to insert/modify data in DB
110 } elsif ($op eq 'add_validate') {
111 my $dbh = C4::Context->dbh;
112 my $sth=$dbh->prepare("replace authorised_values (id,category,authorised_value,lib) values (?,?,?,?)");
113 my $lib = $input->param('lib');
114 undef $lib if ($lib eq ""); # to insert NULL instead of a blank string
116 $sth->execute($input->param('id'), $input->param('category'), $input->param('authorised_value'), $lib);
118 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$input->param('category')."\"></html>";
120 ################## DELETE_CONFIRM ##################################
121 # called by default form, used to confirm deletion of data in DB
122 } elsif ($op eq 'delete_confirm') {
123 my $dbh = C4::Context->dbh;
124 my $sth=$dbh->prepare("select category,authorised_value,lib from authorised_values where id=?");
126 my $data=$sth->fetchrow_hashref;
128 $id = $input->param('id') unless $id;
129 $template->param(searchfield => $searchfield,
130 Tvalue => $data->{'authorised_value'},
134 # END $OP eq DELETE_CONFIRM
135 ################## DELETE_CONFIRMED ##################################
136 # called by delete_confirm, used to effectively confirm deletion of data in DB
137 } elsif ($op eq 'delete_confirmed') {
138 my $dbh = C4::Context->dbh;
139 my $id = $input->param('id');
140 my $sth=$dbh->prepare("delete from authorised_values where id=?");
143 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=$searchfield\"></html>";
146 # END $OP eq DELETE_CONFIRMED
147 ################## DEFAULT ##################################
149 # build categories list
150 my $sth = $dbh->prepare("select distinct category from authorised_values");
153 while ( my ($category) = $sth->fetchrow_array) {
154 push(@category_list,$category);
156 # push koha system categories
157 my $tab_list = CGI::scrolling_list(-name=>'searchfield',
158 -values=> \@category_list,
165 $searchfield=$category_list[0];
168 my ($count,$results)=StringSearch($env,$searchfield,'web');
172 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
173 if ($toggle eq 'white'){
178 my %row_data; # get a fresh hash for the row data
179 $row_data{category} = $results->[$i]{'category'};
180 $row_data{authorised_value} = $results->[$i]{'authorised_value'};
181 $row_data{lib} = $results->[$i]{'lib'};
182 $row_data{edit} = "$script_name?op=add_form&id=".$results->[$i]{'id'};
183 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=$searchfield&id=".$results->[$i]{'id'};
184 push(@loop_data, \%row_data);
187 $template->param(loop => \@loop_data,
188 tab_list => $tab_list,
189 category => $searchfield);
192 my $prevpage = $offset-$pagesize;
193 $template->param(isprevpage => $offset,
194 prevpage=> $prevpage,
195 searchfield => $searchfield,
196 script_name => $script_name,
199 if ($offset+$pagesize<$count) {
200 my $nextpage =$offset+$pagesize;
201 $template->param(nextpage =>$nextpage,
202 searchfield => $searchfield,
203 script_name => $script_name,
206 } #---- END $OP eq DEFAULT
207 $template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
208 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
209 IntranetNav => C4::Context->preference("IntranetNav"),
211 output_html_with_http_headers $input, $cookie, $template->output;