add links to aqbudget.pl
[koha.git] / admin / aqbookfund.pl
1 #!/usr/bin/perl
2
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)
6
7 # ALGO :
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.
12 # if $op=add_form
13 #       - if primkey exists, this is a modification,so we read the $primkey record
14 #       - builds the add/modify form
15 # if $op=add_validate
16 #       - the user has just send datas, so we create/modify the record
17 # if $op=delete_form
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
21
22
23 # Copyright 2000-2002 Katipo Communications
24 #
25 # This file is part of Koha.
26 #
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
30 # version.
31 #
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.
35 #
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
39
40 use strict;
41 use CGI;
42 use C4::Context;
43 use C4::Output;
44 use C4::Search;
45 use HTML::Template;
46
47 sub StringSearch  {
48         my ($env,$searchstring,$type)=@_;
49         my $dbh = C4::Context->dbh;
50         $searchstring=~ s/\'/\\\'/g;
51         my @data=split(' ',$searchstring);
52         my $count=@data;
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);
55         $sth->execute;
56         my @results;
57         my $cnt=0;
58         while (my $data=$sth->fetchrow_hashref){
59         push(@results,$data);
60         $cnt ++;
61         }
62         #  $sth->execute;
63         $sth->finish;
64         return ($cnt,\@results);
65 }
66
67 my $input = new CGI;
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');
72 my $pagesize=20;
73 my $op = $input->param('op');
74 $searchfield=~ s/\,//g;
75
76 my $template = gettemplate("parameters/aqbookfund.tmpl",0);
77 if ($op) {
78 $template->param(script_name => $script_name,
79                                                 $op              => 1); # we show only the TMPL_VAR names $op
80 } else {
81 $template->param(script_name => $script_name,
82                                                 else              => 1); # we show only the TMPL_VAR names $op
83 }
84 $template->param(action => $script_name);
85
86
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...
91         my $data;
92         my $header;
93         if ($bookfundid) {
94                 my $dbh = C4::Context->dbh;
95                 my $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup from aqbookfund where bookfundid='$bookfundid'");
96                 $sth->execute;
97                 $data=$sth->fetchrow_hashref;
98                 $sth->finish;
99             }
100         if ($bookfundid) {
101             $header = "Modify book fund";
102         } else {
103             $header = "Add book fund";
104         }
105         $template->param(header => $header);
106         my $add_or_modify=0;
107         if ($bookfundid) {
108             $add_or_modify=1;
109         }
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'});
114
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);
123         $sth->execute;
124         $sth->finish;
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);
130         $sth->execute;
131         $sth->finish;
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'");
138 #       $sth->execute;
139 #       my $total = $sth->fetchrow_hashref;
140 #       $sth->finish;
141         my $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup from aqbookfund where bookfundid='$bookfundid'");
142         $sth->execute;
143         my $data=$sth->fetchrow_hashref;
144         $sth->finish;
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);
156         $sth->execute;
157         $sth->finish;
158                                                                                                         # END $OP eq DELETE_CONFIRMED
159 ################## DEFAULT ##################################
160 } else { # DEFAULT
161        $template->param(scriptname => $script_name);
162        if  ($searchfield ne '') {
163                 $template->param(search => 1);
164                 $template->param(searchfield => $searchfield);
165         }
166        my $env;
167        my ($count,$results)=StringSearch($env,$searchfield,'web');
168        my $toggle="white";
169        my @loop_data =();
170        for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
171                 #find out stats
172         #       my ($od,$issue,$fines)=categdata2($env,$results->[$i]{'borrowernumber'});
173         #       $fines=$fines+0;
174            my @toggle = ();
175            my @bookfundid = ();
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'){
183                         $toggle="#ffffcc";
184                 } else {
185                         $toggle="white";
186                 }
187         while (@toggle and @bookfundid and @bookfundname and @bookfundgroup) { 
188            my %row_data;
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);
194        }
195        }
196        $template->param(bookfund => \@loop_data);
197 } #---- END $OP eq DEFAULT
198
199
200
201 print "Content-Type: text/html\n\n", $template->output;