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 => "admin/authorised_values.tmpl",
62 flagsrequired => {parameters => 1, management => 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 $template->param('heading-modify-authorized-value-p' => 1);
91 } elsif ( ! $data->{'category'} ) {
92 $template->param(action => "Add new category");
93 $template->param('heading-add-new-category-p' => 1);
95 $template->param(action => "Add authorised value");
96 $template->param('heading-add-authorized-value-p' => 1);
98 $template->param('use-heading-flags-p' => 1);
99 $template->param(category => $data->{'category'},
100 authorised_value => $data->{'authorised_value'},
101 lib => $data->{'lib'},
104 if ($data->{'category'}) {
105 $template->param(category => "<input type=\"hidden\" name=\"category\" value='$data->{'category'}'>$data->{'category'}");
107 $template->param(category => "<input type=text name=\"category\" size=8 maxlength=8>");
109 ################## ADD_VALIDATE ##################################
110 # called by add_form, used to insert/modify data in DB
111 } elsif ($op eq 'add_validate') {
112 my $dbh = C4::Context->dbh;
113 my $sth=$dbh->prepare("replace authorised_values (id,category,authorised_value,lib) values (?,?,?,?)");
114 my $lib = $input->param('lib');
115 undef $lib if ($lib eq ""); # to insert NULL instead of a blank string
117 $sth->execute($input->param('id'), $input->param('category'), $input->param('authorised_value'), $lib);
119 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$input->param('category')."\"></html>";
121 ################## DELETE_CONFIRM ##################################
122 # called by default form, used to confirm deletion of data in DB
123 } elsif ($op eq 'delete_confirm') {
124 my $dbh = C4::Context->dbh;
125 my $sth=$dbh->prepare("select category,authorised_value,lib from authorised_values where id=?");
127 my $data=$sth->fetchrow_hashref;
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 $sth=$dbh->prepare("delete from authorised_values where id=?");
142 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=$searchfield\"></html>";
145 # END $OP eq DELETE_CONFIRMED
146 ################## DEFAULT ##################################
148 # build categories list
149 my $sth = $dbh->prepare("select distinct category from authorised_values");
152 while ( my ($category) = $sth->fetchrow_array) {
153 push(@category_list,$category);
155 # push koha system categories
156 my $tab_list = CGI::scrolling_list(-name=>'searchfield',
157 -values=> \@category_list,
164 $searchfield=$category_list[0];
167 my ($count,$results)=StringSearch($env,$searchfield,'web');
171 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
172 if ($toggle eq 'white'){
177 my %row_data; # get a fresh hash for the row data
178 $row_data{category} = $results->[$i]{'category'};
179 $row_data{authorised_value} = $results->[$i]{'authorised_value'};
180 $row_data{lib} = $results->[$i]{'lib'};
181 $row_data{edit} = "$script_name?op=add_form&id=".$results->[$i]{'id'};
182 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=$searchfield&id=".$results->[$i]{'id'};
183 push(@loop_data, \%row_data);
186 $template->param(loop => \@loop_data,
187 tab_list => $tab_list,
188 category => $searchfield);
191 my $prevpage = $offset-$pagesize;
192 $template->param(isprevpage => $offset,
193 prevpage=> $prevpage,
194 searchfield => $searchfield,
195 script_name => $script_name,
198 if ($offset+$pagesize<$count) {
199 my $nextpage =$offset+$pagesize;
200 $template->param(nextpage =>$nextpage,
201 searchfield => $searchfield,
202 script_name => $script_name,
205 } #---- END $OP eq DEFAULT
206 $template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
207 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
208 IntranetNav => C4::Context->preference("IntranetNav"),
210 output_html_with_http_headers $input, $cookie, $template->output;