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'});
124 # END $OP eq ADD_FORM
125 ################## ADD_VALIDATE ##################################
126 # called by add_form, used to insert/modify data in DB
127 } elsif ($op eq 'add_validate') {
128 my $dbh = C4
::Context
->dbh;
129 my $bookfundid=uc($input->param('bookfundid'));
130 my $query = "delete from aqbookfund where bookfundid ='$bookfundid'";
131 my $sth=$dbh->prepare($query);
134 $query = "replace aqbookfund (bookfundid,bookfundname) values (";
135 $query.= $dbh->quote($input->param('bookfundid')).",";
136 $query.= $dbh->quote($input->param('bookfundname')).")";
137 my $sth=$dbh->prepare($query);
140 # END $OP eq ADD_VALIDATE
141 ################## DELETE_CONFIRM ##################################
142 # called by default form, used to confirm deletion of data in DB
143 } elsif ($op eq 'delete_confirm') {
144 my $dbh = C4
::Context
->dbh;
145 # my $sth=$dbh->prepare("select count(*) as total from categoryitem where itemtype='$itemtype'");
147 # my $total = $sth->fetchrow_hashref;
149 my $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup from aqbookfund where bookfundid='$bookfundid'");
151 my $data=$sth->fetchrow_hashref;
153 $template->param(bookfundid
=> $bookfundid);
154 $template->param(bookfundname
=> $data->{'bookfundname'});
155 # END $OP eq DELETE_CONFIRM
156 ################## DELETE_CONFIRMED ##################################
157 # called by delete_confirm, used to effectively confirm deletion of data in DB
158 } elsif ($op eq 'delete_confirmed') {
159 my $dbh = C4
::Context
->dbh;
160 my $bookfundid=uc($input->param('bookfundid'));
161 my $query = "delete from aqbookfund where bookfundid='$bookfundid'";
162 my $sth=$dbh->prepare($query);
164 $dbh->do("delete from aqbudget where bookfundid='$bookfundid'");
166 # END $OP eq DELETE_CONFIRMED
167 ################## DEFAULT ##################################
169 $template->param(scriptname
=> $script_name);
170 if ($searchfield ne '') {
171 $template->param(search
=> 1);
172 $template->param(searchfield
=> $searchfield);
175 my ($count,$results)=StringSearch
($env,$searchfield,'web');
178 my $dbh = C4
::Context
->dbh;
179 my $sth2 = $dbh->prepare("Select aqbudgetid,startdate,enddate,budgetamount from aqbudget where bookfundid = ? order by bookfundid");
180 for (my $i=$offset; $i < ($offset+$pagesize<$count?
$offset+$pagesize:$count); $i++){
182 $row_data{bookfundid
} =$results->[$i]{'bookfundid'};
183 $row_data{bookfundname
} = $results->[$i]{'bookfundname'};
184 $sth2->execute($row_data{bookfundid
});
186 while (my ($aqbudgetid,$startdate,$enddate,$budgetamount) = $sth2->fetchrow) {
188 $budgetrow_data{aqbudgetid
} = $aqbudgetid;
189 $budgetrow_data{startdate
} = $startdate;
190 $budgetrow_data{enddate
} = $enddate;
191 $budgetrow_data{budgetamount
} = $budgetamount;
192 push @budget_loop,\
%budgetrow_data;
194 $row_data{budget
} = \
@budget_loop;
195 push @loop_data,\
%row_data;
197 $template->param(bookfund
=> \
@loop_data);
198 } #---- END $OP eq DEFAULT
200 output_html_with_http_headers
$input, $cookie, $template->output;