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
48 my ($env,$searchstring,$type)=@_;
49 my $dbh = C4::Context->dbh;
50 $searchstring=~ s/\'/\\\'/g;
51 my @data=split(' ',$searchstring);
53 my $query="select bookfundid,bookfundname,bookfundgroup from aqbookfund where bookfundid and (bookfundid like \"$data[0]%\") order by bookfundid";
54 my $sth=$dbh->prepare($query);
58 while (my $data=$sth->fetchrow_hashref){
64 return ($cnt,\@results);
68 my $searchfield=$input->param('searchfield');
69 my $offset=$input->param('offset');
70 my $script_name="/cgi-bin/koha/admin/aqbookfund.pl";
71 my $bookfundid=$input->param('bookfundid');
73 my $op = $input->param('op');
74 $searchfield=~ s/\,//g;
76 my $template = gettemplate("parameters/aqbookfund.tmpl",0);
78 $template->param(script_name => $script_name,
79 $op => 1); # we show only the TMPL_VAR names $op
81 $template->param(script_name => $script_name,
82 else => 1); # we show only the TMPL_VAR names $op
84 $template->param(action => $script_name);
87 ################## ADD_FORM ##################################
88 # called by default. Used to create form to add or modify a record
89 if ($op eq 'add_form') {
90 #---- if primkey exists, it's a modify action, so read values to modify...
94 my $dbh = C4::Context->dbh;
95 my $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup from aqbookfund where bookfundid='$bookfundid'");
97 $data=$sth->fetchrow_hashref;
101 $header = "Modify book fund";
103 $header = "Add book fund";
105 $template->param(header => $header);
110 $template->param(add_or_modify => $add_or_modify);
111 $template->param(bookfundid =>$bookfundid);
112 $template->param(bookfundname =>$data->{'bookfundname'});
113 $template->param(bookfundgroup =>$data->{'bookfundgroup'});
115 # END $OP eq ADD_FORM
116 ################## ADD_VALIDATE ##################################
117 # called by add_form, used to insert/modify data in DB
118 } elsif ($op eq 'add_validate') {
119 my $dbh = C4::Context->dbh;
120 my $bookfundid=uc($input->param('bookfundid'));
121 my $query = "delete from aqbookfund where bookfundid ='$bookfundid'";
122 my $sth=$dbh->prepare($query);
125 $query = "replace aqbookfund (bookfundid,bookfundname,bookfundgroup) values (";
126 $query.= $dbh->quote($input->param('bookfundid')).",";
127 $query.= $dbh->quote($input->param('bookfundname')).",";
128 $query.= $dbh->quote($input->param('bookfundgroup')).")";
129 my $sth=$dbh->prepare($query);
132 # END $OP eq ADD_VALIDATE
133 ################## DELETE_CONFIRM ##################################
134 # called by default form, used to confirm deletion of data in DB
135 } elsif ($op eq 'delete_confirm') {
136 my $dbh = C4::Context->dbh;
137 # my $sth=$dbh->prepare("select count(*) as total from categoryitem where itemtype='$itemtype'");
139 # my $total = $sth->fetchrow_hashref;
141 my $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup from aqbookfund where bookfundid='$bookfundid'");
143 my $data=$sth->fetchrow_hashref;
145 $template->param(bookfundid => $bookfundid);
146 $template->param(bookfundname => $data->{'bookfundname'});
147 $template->param(bookfundgroup => $data->{'bookfundgroup'});
148 # END $OP eq DELETE_CONFIRM
149 ################## DELETE_CONFIRMED ##################################
150 # called by delete_confirm, used to effectively confirm deletion of data in DB
151 } elsif ($op eq 'delete_confirmed') {
152 my $dbh = C4::Context->dbh;
153 my $bookfundid=uc($input->param('bookfundid'));
154 my $query = "delete from aqbookfund where bookfundid='$bookfundid'";
155 my $sth=$dbh->prepare($query);
158 # END $OP eq DELETE_CONFIRMED
159 ################## DEFAULT ##################################
161 $template->param(scriptname => $script_name);
162 if ($searchfield ne '') {
163 $template->param(search => 1);
164 $template->param(searchfield => $searchfield);
167 my ($count,$results)=StringSearch($env,$searchfield,'web');
170 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
172 # my ($od,$issue,$fines)=categdata2($env,$results->[$i]{'borrowernumber'});
176 my @bookfundname = ();
177 my @bookfundgroup = ();
178 push(@toggle,$toggle);
179 push(@bookfundid,$results->[$i]{'bookfundid'});
180 push(@bookfundname,$results->[$i]{'bookfundname'});
181 push(@bookfundgroup,$results->[$i]{'bookfundgroup'});
182 if ($toggle eq 'white'){
187 while (@toggle and @bookfundid and @bookfundname and @bookfundgroup) {
189 $row_data{toggle} = shift @toggle;
190 $row_data{bookfundid} = shift @bookfundid;
191 $row_data{bookfundname} = shift @bookfundname;
192 $row_data{bookfundgroup} = shift @bookfundgroup;
193 push(@loop_data, \%row_data);
196 $template->param(bookfund => \@loop_data);
197 } #---- END $OP eq DEFAULT
201 print "Content-Type: text/html\n\n", $template->output;