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
49 my ($env,$searchstring,$type)=@_;
50 my $dbh = C4::Context->dbh;
51 $searchstring=~ s/\'/\\\'/g;
52 my @data=split(' ',$searchstring);
54 my $query="select bookfundid,bookfundname,bookfundgroup from aqbookfund where bookfundid and (bookfundid like \"$data[0]%\") order by bookfundid";
55 my $sth=$dbh->prepare($query);
59 while (my $data=$sth->fetchrow_hashref){
65 return ($cnt,\@results);
69 my $searchfield=$input->param('searchfield');
70 my $offset=$input->param('offset');
71 my $script_name="/cgi-bin/koha/admin/aqbookfund.pl";
72 my $bookfundid=$input->param('bookfundid');
74 my $op = $input->param('op');
75 $searchfield=~ s/\,//g;
77 my ($template, $borrowernumber, $cookie)
78 = get_template_and_user({template_name => "parameters/aqbookfund.tmpl",
82 flagsrequired => {parameters => 1},
87 $template->param(script_name => $script_name,
88 $op => 1); # we show only the TMPL_VAR names $op
90 $template->param(script_name => $script_name,
91 else => 1); # we show only the TMPL_VAR names $op
93 $template->param(action => $script_name);
96 ################## ADD_FORM ##################################
97 # called by default. Used to create form to add or modify a record
98 if ($op eq 'add_form') {
99 #---- if primkey exists, it's a modify action, so read values to modify...
103 my $dbh = C4::Context->dbh;
104 my $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup from aqbookfund where bookfundid='$bookfundid'");
106 $data=$sth->fetchrow_hashref;
110 $header = "Modify book fund";
112 $header = "Add book fund";
114 $template->param(header => $header);
119 $template->param(add_or_modify => $add_or_modify);
120 $template->param(bookfundid =>$bookfundid);
121 $template->param(bookfundname =>$data->{'bookfundname'});
122 $template->param(bookfundgroup =>$data->{'bookfundgroup'});
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,bookfundgroup) values (";
135 $query.= $dbh->quote($input->param('bookfundid')).",";
136 $query.= $dbh->quote($input->param('bookfundname')).",";
137 $query.= $dbh->quote($input->param('bookfundgroup')).")";
138 my $sth=$dbh->prepare($query);
141 # END $OP eq ADD_VALIDATE
142 ################## DELETE_CONFIRM ##################################
143 # called by default form, used to confirm deletion of data in DB
144 } elsif ($op eq 'delete_confirm') {
145 my $dbh = C4::Context->dbh;
146 # my $sth=$dbh->prepare("select count(*) as total from categoryitem where itemtype='$itemtype'");
148 # my $total = $sth->fetchrow_hashref;
150 my $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup from aqbookfund where bookfundid='$bookfundid'");
152 my $data=$sth->fetchrow_hashref;
154 $template->param(bookfundid => $bookfundid);
155 $template->param(bookfundname => $data->{'bookfundname'});
156 $template->param(bookfundgroup => $data->{'bookfundgroup'});
157 # END $OP eq DELETE_CONFIRM
158 ################## DELETE_CONFIRMED ##################################
159 # called by delete_confirm, used to effectively confirm deletion of data in DB
160 } elsif ($op eq 'delete_confirmed') {
161 my $dbh = C4::Context->dbh;
162 my $bookfundid=uc($input->param('bookfundid'));
163 my $query = "delete from aqbookfund where bookfundid='$bookfundid'";
164 my $sth=$dbh->prepare($query);
167 # END $OP eq DELETE_CONFIRMED
168 ################## DEFAULT ##################################
170 $template->param(scriptname => $script_name);
171 if ($searchfield ne '') {
172 $template->param(search => 1);
173 $template->param(searchfield => $searchfield);
176 my ($count,$results)=StringSearch($env,$searchfield,'web');
179 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
181 # my ($od,$issue,$fines)=categdata2($env,$results->[$i]{'borrowernumber'});
185 my @bookfundname = ();
186 my @bookfundgroup = ();
187 push(@toggle,$toggle);
188 push(@bookfundid,$results->[$i]{'bookfundid'});
189 push(@bookfundname,$results->[$i]{'bookfundname'});
190 push(@bookfundgroup,$results->[$i]{'bookfundgroup'});
191 if ($toggle eq 'white'){
196 while (@toggle and @bookfundid and @bookfundname and @bookfundgroup) {
198 $row_data{toggle} = shift @toggle;
199 $row_data{bookfundid} = shift @bookfundid;
200 $row_data{bookfundname} = shift @bookfundname;
201 $row_data{bookfundgroup} = shift @bookfundgroup;
202 push(@loop_data, \%row_data);
205 $template->param(bookfund => \@loop_data);
206 } #---- END $OP eq DEFAULT
208 print $input->header(-cookie => $cookie), $template->output;