3 #script to administer the aqbudget table
4 #written 20/02/2002 by paul.poulain@free.fr
5 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
8 # this script use an $op to know what to do.
9 # if $op is empty or none of the above values,
10 # - the default screen is build (with all records, or filtered datas).
11 # - the user can clic on add, modify or delete record.
13 # - if primkey exists, this is a modification,so we read the $primkey record
14 # - builds the add/modify form
16 # - the user has just send datas, so we create/modify the record
18 # - we show the record having primkey=$primkey and ask for deletion validation form
19 # if $op=delete_confirm
20 # - we delete the record having primkey=$primkey
23 # Copyright 2000-2002 Katipo Communications
25 # This file is part of Koha.
27 # Koha is free software; you can redistribute it and/or modify it under the
28 # terms of the GNU General Public License as published by the Free Software
29 # Foundation; either version 2 of the License, or (at your option) any later
32 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
33 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
34 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
36 # You should have received a copy of the GNU General Public License along with
37 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
38 # Suite 330, Boston, MA 02111-1307 USA
45 use C4::Interface::CGI::Output;
50 my ($env,$searchstring,$type)=@_;
51 my $dbh = C4::Context->dbh;
52 $searchstring=~ s/\'/\\\'/g;
53 my @data=split(' ',$searchstring);
55 my $query="select bookfundid,bookfundname,bookfundgroup from aqbookfund where (bookfundname like \"%$data[0]%\") order by bookfundid";
56 my $sth=$dbh->prepare($query);
60 while (my $data=$sth->fetchrow_hashref){
66 return ($cnt,\@results);
70 my $searchfield=$input->param('searchfield');
71 my $offset=$input->param('offset');
72 my $script_name="/cgi-bin/koha/admin/aqbookfund.pl";
73 my $bookfundid=$input->param('bookfundid');
75 my $op = $input->param('op');
76 $searchfield=~ s/\,//g;
78 my ($template, $borrowernumber, $cookie)
79 = get_template_and_user({template_name => "parameters/aqbookfund.tmpl",
83 flagsrequired => {parameters => 1},
88 $template->param(script_name => $script_name,
89 $op => 1); # we show only the TMPL_VAR names $op
91 $template->param(script_name => $script_name,
92 else => 1); # we show only the TMPL_VAR names $op
94 $template->param(action => $script_name);
97 ################## ADD_FORM ##################################
98 # called by default. Used to create form to add or modify a record
99 if ($op eq 'add_form') {
100 #---- if primkey exists, it's a modify action, so read values to modify...
104 my $dbh = C4::Context->dbh;
105 my $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup from aqbookfund where bookfundid='$bookfundid'");
107 $data=$sth->fetchrow_hashref;
111 $header = "Modify book fund";
113 $header = "Add book fund";
115 $template->param(header => $header);
120 $template->param(add_or_modify => $add_or_modify);
121 $template->param(bookfundid =>$bookfundid);
122 $template->param(bookfundname =>$data->{'bookfundname'});
123 $template->param(bookfundgroup =>$data->{'bookfundgroup'});
125 # END $OP eq ADD_FORM
126 ################## ADD_VALIDATE ##################################
127 # called by add_form, used to insert/modify data in DB
128 } elsif ($op eq 'add_validate') {
129 my $dbh = C4::Context->dbh;
130 my $bookfundid=uc($input->param('bookfundid'));
131 my $query = "delete from aqbookfund where bookfundid ='$bookfundid'";
132 my $sth=$dbh->prepare($query);
135 $query = "replace aqbookfund (bookfundid,bookfundname,bookfundgroup) values (";
136 $query.= $dbh->quote($input->param('bookfundid')).",";
137 $query.= $dbh->quote($input->param('bookfundname')).",";
138 $query.= $dbh->quote($input->param('bookfundgroup')).")";
139 my $sth=$dbh->prepare($query);
142 # END $OP eq ADD_VALIDATE
143 ################## DELETE_CONFIRM ##################################
144 # called by default form, used to confirm deletion of data in DB
145 } elsif ($op eq 'delete_confirm') {
146 my $dbh = C4::Context->dbh;
147 # my $sth=$dbh->prepare("select count(*) as total from categoryitem where itemtype='$itemtype'");
149 # my $total = $sth->fetchrow_hashref;
151 my $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup from aqbookfund where bookfundid='$bookfundid'");
153 my $data=$sth->fetchrow_hashref;
155 $template->param(bookfundid => $bookfundid);
156 $template->param(bookfundname => $data->{'bookfundname'});
157 $template->param(bookfundgroup => $data->{'bookfundgroup'});
158 # END $OP eq DELETE_CONFIRM
159 ################## DELETE_CONFIRMED ##################################
160 # called by delete_confirm, used to effectively confirm deletion of data in DB
161 } elsif ($op eq 'delete_confirmed') {
162 my $dbh = C4::Context->dbh;
163 my $bookfundid=uc($input->param('bookfundid'));
164 my $query = "delete from aqbookfund where bookfundid='$bookfundid'";
165 my $sth=$dbh->prepare($query);
168 # END $OP eq DELETE_CONFIRMED
169 ################## DEFAULT ##################################
171 $template->param(scriptname => $script_name);
172 if ($searchfield ne '') {
173 $template->param(search => 1);
174 $template->param(searchfield => $searchfield);
177 my ($count,$results)=StringSearch($env,$searchfield,'web');
180 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
182 # my ($od,$issue,$fines)=categdata2($env,$results->[$i]{'borrowernumber'});
186 my @bookfundname = ();
187 my @bookfundgroup = ();
188 push(@toggle,$toggle);
189 push(@bookfundid,$results->[$i]{'bookfundid'});
190 push(@bookfundname,$results->[$i]{'bookfundname'});
191 push(@bookfundgroup,$results->[$i]{'bookfundgroup'});
192 if ($toggle eq 'white'){
197 while (@toggle and @bookfundid and @bookfundname and @bookfundgroup) {
199 $row_data{toggle} = shift @toggle;
200 $row_data{bookfundid} = shift @bookfundid;
201 $row_data{bookfundname} = shift @bookfundname;
202 $row_data{bookfundgroup} = shift @bookfundgroup;
203 push(@loop_data, \%row_data);
206 $template->param(bookfund => \@loop_data);
207 } #---- END $OP eq DEFAULT
209 output_html_with_http_headers $input, $cookie, $template->output;