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
30 my ($searchstring,$type)=@_;
31 my $dbh = C4::Context->dbh;
32 $searchstring=~ s/\'/\\\'/g;
33 my @data=split(' ',$searchstring);
35 my $sth=$dbh->prepare("Select id,category,authorised_value,lib from authorised_values where (category like ?) order by category,authorised_value");
36 $sth->execute("$data[0]%");
39 while (my $data=$sth->fetchrow_hashref){
44 return ($cnt,\@results);
48 my $searchfield=$input->param('searchfield');
49 $searchfield=~ s/\,//g;
50 my $id = $input->param('id');
51 my $offset=$input->param('offset');
52 my $script_name="/cgi-bin/koha/admin/authorised_values.pl";
53 my $dbh = C4::Context->dbh;
55 my ($template, $borrowernumber, $cookie)
56 = get_template_and_user({template_name => "admin/authorised_values.tmpl",
60 flagsrequired => {parameters => 1},
64 my $op = $input->param('op');
67 $template->param(script_name => $script_name,
68 $op => 1); # we show only the TMPL_VAR names $op
70 $template->param(script_name => $script_name,
71 else => 1); # we show only the TMPL_VAR names $op
73 ################## ADD_FORM ##################################
74 # called by default. Used to create form to add or modify a record
75 if ($op eq 'add_form') {
78 my $dbh = C4::Context->dbh;
79 my $sth=$dbh->prepare("select id,category,authorised_value,lib from authorised_values where id=?");
81 $data=$sth->fetchrow_hashref;
84 $data->{'category'} = $input->param('category');
87 $template->param(action_modify => 1);
88 $template->param('heading-modify-authorized-value-p' => 1);
89 } elsif ( ! $data->{'category'} ) {
90 $template->param(action_add_category => 1);
91 $template->param('heading-add-new-category-p' => 1);
93 $template->param(action_add_value => 1);
94 $template->param('heading-add-authorized-value-p' => 1);
96 $template->param('use-heading-flags-p' => 1);
97 $template->param(category => $data->{'category'},
98 authorised_value => $data->{'authorised_value'},
99 lib => $data->{'lib'},
102 if ($data->{'category'}) {
103 $template->param(category => "<input type=\"hidden\" name=\"category\" value='$data->{'category'}'>$data->{'category'}");
105 $template->param(category => "<input type=text name=\"category\" size=8 maxlength=8>");
107 ################## ADD_VALIDATE ##################################
108 # called by add_form, used to insert/modify data in DB
109 } elsif ($op eq 'add_validate') {
110 my $dbh = C4::Context->dbh;
111 my $sth=$dbh->prepare("replace authorised_values (id,category,authorised_value,lib) values (?,?,?,?)");
112 my $lib = $input->param('lib');
113 undef $lib if ($lib eq ""); # to insert NULL instead of a blank string
115 $sth->execute($input->param('id'), $input->param('category'), $input->param('authorised_value'), $lib);
117 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$input->param('category')."\"></html>";
119 ################## DELETE_CONFIRM ##################################
120 # called by default form, used to confirm deletion of data in DB
121 } elsif ($op eq 'delete_confirm') {
122 my $dbh = C4::Context->dbh;
123 my $sth=$dbh->prepare("select category,authorised_value,lib from authorised_values where id=?");
125 my $data=$sth->fetchrow_hashref;
127 $id = $input->param('id') unless $id;
128 $template->param(searchfield => $searchfield,
129 Tvalue => $data->{'authorised_value'},
133 # END $OP eq DELETE_CONFIRM
134 ################## DELETE_CONFIRMED ##################################
135 # called by delete_confirm, used to effectively confirm deletion of data in DB
136 } elsif ($op eq 'delete_confirmed') {
137 my $dbh = C4::Context->dbh;
138 my $id = $input->param('id');
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];
166 my ($count,$results)=StringSearch($searchfield,'web');
170 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
171 if ($toggle eq 'white'){
176 my %row_data; # get a fresh hash for the row data
177 $row_data{category} = $results->[$i]{'category'};
178 $row_data{authorised_value} = $results->[$i]{'authorised_value'};
179 $row_data{lib} = $results->[$i]{'lib'};
180 $row_data{edit} = "$script_name?op=add_form&id=".$results->[$i]{'id'};
181 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=$searchfield&id=".$results->[$i]{'id'};
182 push(@loop_data, \%row_data);
185 $template->param(loop => \@loop_data,
186 tab_list => $tab_list,
187 category => $searchfield);
190 my $prevpage = $offset-$pagesize;
191 $template->param(isprevpage => $offset,
192 prevpage=> $prevpage,
193 searchfield => $searchfield,
194 script_name => $script_name,
197 if ($offset+$pagesize<$count) {
198 my $nextpage =$offset+$pagesize;
199 $template->param(nextpage =>$nextpage,
200 searchfield => $searchfield,
201 script_name => $script_name,
204 } #---- END $OP eq DEFAULT
205 $template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
206 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
207 IntranetNav => C4::Context->preference("IntranetNav"),
209 output_html_with_http_headers $input, $cookie, $template->output;