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
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,startdate,enddate,budgetamount from aqbudget where bookfundid and (bookfundid 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/aqbudget.pl";
73 my $bookfundid=$input->param('bookfundid');
75 my $op = $input->param('op');
76 $searchfield=~ s/\,//g;
78 my $template = gettemplate("parameters/aqbudget.tmpl",0);
80 $template->param(script_name => $script_name,
81 $op => 1); # we show only the TMPL_VAR names $op
83 $template->param(script_name => $script_name,
84 else => 1); # we show only the TMPL_VAR names $op
87 $template->param(action => $script_name);
88 ################## ADD_FORM ##################################
89 # called by default. Used to create form to add or modify a record
90 if ($op eq 'add_form') {
91 #---- if primkey exists, it's a modify action, so read values to modify...
95 my $dbh = C4::Context->dbh;
96 my $query="select bookfundid,startdate,enddate,budgetamount from aqbudget where bookfundid='$bookfundid'";
98 my $sth=$dbh->prepare($query);
100 $dataaqbudget=$sth->fetchrow_hashref;
102 my $query="select bookfundid,bookfundname from aqbookfund where bookfundid='$bookfundid'";
104 my $sth=$dbh->prepare($query);
106 $dataaqbookfund=$sth->fetchrow_hashref;
111 $header = "Modify budget";
113 $header = "Add budget";
115 $template->param(header => $header);
117 $template->param(modify => 1);
118 $template->param(bookfundid => $bookfundid);
119 $template->param(bookfundname => $dataaqbookfund->{bookfundname});
121 $template->param(adding => 1);
123 $template->param(startdate => $dataaqbudget->{'startdate'});
124 $template->param(enddate => $dataaqbudget->{'enddate'});
125 $template->param(budgetamount => $dataaqbudget->{'budgetamount'});
126 # END $OP eq ADD_FORM
127 ################## ADD_VALIDATE ##################################
128 # called by add_form, used to insert/modify data in DB
129 } elsif ($op eq 'add_validate') {
130 my $dbh = C4::Context->dbh;
131 my $query = "replace aqbudget (bookfundid,startdate,enddate,budgetamount) values (";
132 $query.= $dbh->quote($input->param('bookfundid')).",";
133 $query.= $dbh->quote($input->param('startdate')).",";
134 $query.= $dbh->quote($input->param('enddate')).",";
135 $query.= $dbh->quote($input->param('budgetamount')).")";
136 my $sth=$dbh->prepare($query);
139 # END $OP eq ADD_VALIDATE
140 ################## DELETE_CONFIRM ##################################
141 # called by default form, used to confirm deletion of data in DB
142 } elsif ($op eq 'delete_confirm') {
143 my $dbh = C4::Context->dbh;
144 # my $sth=$dbh->prepare("select count(*) as total from categoryitem where itemtype='$itemtype'");
146 # my $total = $sth->fetchrow_hashref;
148 my $sth=$dbh->prepare("select bookfundid,startdate,enddate,budgetamount from aqbudget where bookfundid='$bookfundid'");
150 my $data=$sth->fetchrow_hashref;
152 $template->param(bookfundid => $bookfundid);
153 $template->param(startdate => $data->{'startdate'});
154 $template->param(enddate => $data->{'enddate'});
155 $template->param(budgetamount => $data->{'budgetamount'});
156 # END $OP eq DELETE_CONFIRM
157 ################## DELETE_CONFIRMED ##################################
158 # called by delete_confirm, used to effectively confirm deletion of data in DB
159 } elsif ($op eq 'delete_confirmed') {
160 my $dbh = C4::Context->dbh;
161 my $bookfundid=uc($input->param('bookfundid'));
162 my $query = "delete from aqbudget where bookfundid='$bookfundid'";
163 my $sth=$dbh->prepare($query);
166 # END $OP eq DELETE_CONFIRMED
167 ################## DEFAULT ##################################
169 if ($searchfield ne '') {
170 $template->param(search => 1);
171 $template->param(searchfield => $searchfield);
174 my ($count,$results)=StringSearch($env,$searchfield,'web');
177 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
179 # my ($od,$issue,$fines)=categdata2($env,$results->[$i]{'borrowernumber'});
182 my $dbh = C4::Context->dbh;
183 my $query="select bookfundid,bookfundname from aqbookfund where bookfundid=$results->[$i]{'bookfundid'}";
185 my $sth=$dbh->prepare($query);
187 $dataaqbookfund=$sth->fetchrow_hashref;
191 my @bookfundname = ();
194 my @budgetamount = ();
195 push(@toggle,$toggle);
196 push(@bookfundid,$results->[$i]{'bookfundid'});
197 push(@bookfundname,$dataaqbookfund->{'bookfundname'});
198 push(@startdate,$results->[$i]{'startdate'});
199 push(@enddate,$results->[$i]{'enddate'});
200 push(@budgetamount,$results->[$i]{'budgetamount'});
201 if ($toggle eq 'white'){
206 while (@toggle and @bookfundid and @bookfundname and @startdate and @enddate and @budgetamount) {
208 $row_data{toggle} = shift @toggle;
209 $row_data{bookfundid} = shift @bookfundid;
210 $row_data{bookfundname} = shift @bookfundname;
211 $row_data{startdate} = shift @startdate;
212 $row_data{enddate} = shift @enddate;
213 $row_data{budgetamount} = shift @budgetamount;
214 push(@loop_data, \%row_data);
217 $template->param(budget => \@loop_data);
218 } #---- END $OP eq DEFAULT
220 print "Content-Type: text/html\n\n", $template->output;