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 $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup from aqbookfund where (bookfundname like ?) order by bookfundid");
56 $sth->execute("%$data[0]%");
58 while (my $data=$sth->fetchrow_hashref){
63 return (scalar(@results),\@results);
67 my $searchfield=$input->param('searchfield');
68 my $offset=$input->param('offset');
69 my $script_name="/cgi-bin/koha/admin/aqbookfund.pl";
70 my $bookfundid=$input->param('bookfundid');
72 my $op = $input->param('op');
73 $searchfield=~ s/\,//g;
75 my ($template, $borrowernumber, $cookie)
76 = get_template_and_user({template_name => "parameters/aqbookfund.tmpl",
80 flagsrequired => {parameters => 1},
85 $template->param(script_name => $script_name,
86 $op => 1); # we show only the TMPL_VAR names $op
88 $template->param(script_name => $script_name,
89 else => 1); # we show only the TMPL_VAR names $op
91 $template->param(action => $script_name);
94 ################## ADD_FORM ##################################
95 # called by default. Used to create form to add or modify a record
96 if ($op eq 'add_form') {
97 #---- if primkey exists, it's a modify action, so read values to modify...
101 my $dbh = C4::Context->dbh;
102 my $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup from aqbookfund where bookfundid=?");
103 $sth->execute($bookfundid);
104 $data=$sth->fetchrow_hashref;
108 $header = "Modify book fund";
109 $template->param('header-is-modify-p' => 1);
111 $header = "Add book fund";
112 $template->param('header-is-add-p' => 1);
114 $template->param('use-header-flags-p' => 1);
115 $template->param(header => $header); # NOTE deprecated
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 $sth=$dbh->prepare("delete from aqbookfund where bookfundid =?");
131 $sth->execute($bookfundid);
133 my $sth=$dbh->prepare("replace aqbookfund (bookfundid,bookfundname) values (?,?)");
134 $sth->execute($input->param('bookfundid'),$input->param('bookfundname'));
136 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=aqbookfund.pl\"></html>";
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 bookfundid,bookfundname,bookfundgroup from aqbookfund where bookfundid=?");
145 $sth->execute($bookfundid);
146 my $data=$sth->fetchrow_hashref;
148 $template->param(bookfundid => $bookfundid);
149 $template->param(bookfundname => $data->{'bookfundname'});
150 # END $OP eq DELETE_CONFIRM
151 ################## DELETE_CONFIRMED ##################################
152 # called by delete_confirm, used to effectively confirm deletion of data in DB
153 } elsif ($op eq 'delete_confirmed') {
154 my $dbh = C4::Context->dbh;
155 my $bookfundid=uc($input->param('bookfundid'));
156 my $sth=$dbh->prepare("delete from aqbookfund where bookfundid=?");
157 $sth->execute($bookfundid);
159 $sth=$dbh->prepare("delete from aqbudget where bookfundid=?");
160 $sth->execute($bookfundid);
162 # END $OP eq DELETE_CONFIRMED
163 ################## DEFAULT ##################################
165 $template->param(scriptname => $script_name);
166 if ($searchfield ne '') {
167 $template->param(search => 1);
168 $template->param(searchfield => $searchfield);
171 my ($count,$results)=StringSearch($env,$searchfield,'web');
174 my $dbh = C4::Context->dbh;
175 my $sth2 = $dbh->prepare("Select aqbudgetid,startdate,enddate,budgetamount from aqbudget where bookfundid = ? order by bookfundid");
176 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
178 $row_data{bookfundid} =$results->[$i]{'bookfundid'};
179 $row_data{bookfundname} = $results->[$i]{'bookfundname'};
180 $sth2->execute($row_data{bookfundid});
182 while (my ($aqbudgetid,$startdate,$enddate,$budgetamount) = $sth2->fetchrow) {
184 $budgetrow_data{aqbudgetid} = $aqbudgetid;
185 $budgetrow_data{startdate} = $startdate;
186 $budgetrow_data{enddate} = $enddate;
187 $budgetrow_data{budgetamount} = $budgetamount;
188 push @budget_loop,\%budgetrow_data;
190 $row_data{budget} = \@budget_loop;
191 push @loop_data,\%row_data;
193 $template->param(bookfund => \@loop_data);
194 } #---- END $OP eq DEFAULT
196 output_html_with_http_headers $input, $cookie, $template->output;