2 # NOTE: 4-character tabs
4 #script to administer the categories table
5 #written 20/02/2002 by paul.poulain@free.fr
6 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
9 # this script use an $op to know what to do.
10 # if $op is empty or none of the above values,
11 # - the default screen is build (with all records, or filtered datas).
12 # - the user can clic on add, modify or delete record.
14 # - if primkey exists, this is a modification,so we read the $primkey record
15 # - builds the add/modify form
17 # - the user has just send datas, so we create/modify the record
19 # - we show the record having primkey=$primkey and ask for deletion validation form
20 # if $op=delete_confirm
21 # - we delete the record having primkey=$primkey
24 # Copyright 2000-2002 Katipo Communications
26 # This file is part of Koha.
28 # Koha is free software; you can redistribute it and/or modify it under the
29 # terms of the GNU General Public License as published by the Free Software
30 # Foundation; either version 2 of the License, or (at your option) any later
33 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
34 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
35 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
37 # You should have received a copy of the GNU General Public License along with
38 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
39 # Suite 330, Boston, MA 02111-1307 USA
47 use C4::Interface::CGI::Output;
51 my ($env,$searchstring,$type)=@_;
52 my $dbh = C4::Context->dbh;
53 $searchstring=~ s/\'/\\\'/g;
54 my @data=split(' ',$searchstring);
56 my $sth=$dbh->prepare("Select * from itemtypes where (description like ?) order by itemtype");
57 $sth->execute("$data[0]%");
59 while (my $data=$sth->fetchrow_hashref){
64 return (scalar(@results),\@results);
68 my $searchfield=$input->param('description');
69 my $offset=$input->param('offset');
70 my $script_name="/cgi-bin/koha/admin/itemtypes.pl";
71 my $itemtype=$input->param('itemtype');
73 my $op = $input->param('op');
74 $searchfield=~ s/\,//g;
75 my ($template, $borrowernumber, $cookie)
76 = get_template_and_user({template_name => "parameters/itemtypes.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 ################## ADD_FORM ##################################
92 # called by default. Used to create form to add or modify a record
93 if ($op eq 'add_form') {
94 #start the page and read in includes
95 #---- if primkey exists, it's a modify action, so read values to modify...
98 my $dbh = C4::Context->dbh;
99 my $sth=$dbh->prepare("select itemtype,description,renewalsallowed,rentalcharge,notforloan from itemtypes where itemtype=?");
100 $sth->execute($itemtype);
101 $data=$sth->fetchrow_hashref;
104 $template->param(itemtype => $itemtype,
105 description => $data->{'description'},
106 renewalsallowed => $data->{'renewalsallowed'},
107 rentalcharge => $data->{'rentalcharge'},
108 notforloan => $data->{'notforloan'}
111 # END $OP eq ADD_FORM
112 ################## ADD_VALIDATE ##################################
113 # called by add_form, used to insert/modify data in DB
114 } elsif ($op eq 'add_validate') {
115 my $dbh = C4::Context->dbh;
116 my $sth=$dbh->prepare("replace itemtypes (itemtype,description,renewalsallowed,rentalcharge,notforloan) values (?,?,?,?,?)");
118 $input->param('itemtype'),$input->param('description'),
119 $input->param('renewalsallowed'),$input->param('rentalcharge'),
120 $input->param('notforloan')?1:0);
122 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=itemtypes.pl\"></html>";
124 # END $OP eq ADD_VALIDATE
125 ################## DELETE_CONFIRM ##################################
126 # called by default form, used to confirm deletion of data in DB
127 } elsif ($op eq 'delete_confirm') {
128 #start the page and read in includes
129 my $dbh = C4::Context->dbh;
131 # Check both categoryitem and biblioitems, see Bug 199
133 for my $table ('issuingrules', 'biblioitems') {
134 my $sth=$dbh->prepare("select count(*) as total from $table where itemtype=?");
135 $sth->execute($itemtype);
136 $total += $sth->fetchrow_hashref->{total};
140 my $sth=$dbh->prepare("select itemtype,description,renewalsallowed,rentalcharge from itemtypes where itemtype=?");
141 $sth->execute($itemtype);
142 my $data=$sth->fetchrow_hashref;
145 $template->param(itemtype => $itemtype,
146 description => $data->{'description'},
147 renewalsallowed => $data->{'renewalsallowed'},
148 rentalcharge => $data->{'rentalcharge'},
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 #start the page and read in includes
155 my $dbh = C4::Context->dbh;
156 my $itemtype=uc($input->param('itemtype'));
157 my $sth=$dbh->prepare("delete from itemtypes where itemtype=?");
158 $sth->execute($itemtype);
160 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=itemtypes.pl\"></html>";
162 # END $OP eq DELETE_CONFIRMED
163 ################## DEFAULT ##################################
166 my ($count,$results)=StringSearch($env,$searchfield,'web');
169 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
171 if ($toggle eq 'white'){
172 $row_data{toggle}="#ffffcc";
174 $row_data{toggle}="white";
176 $row_data{itemtype} = $results->[$i]{'itemtype'};
177 $row_data{description} = $results->[$i]{'description'};
178 $row_data{renewalsallowed} = $results->[$i]{'renewalsallowed'};
179 $row_data{rentalcharge} = $results->[$i]{'rentalcharge'};
180 push(@loop_data, \%row_data);
182 $template->param(loop => \@loop_data);
184 my $prevpage = $offset-$pagesize;
185 $template->param(previous => "$script_name?offset=".$prevpage);
187 if ($offset+$pagesize<$count) {
188 my $nextpage =$offset+$pagesize;
189 $template->param(next => "$script_name?offset=".$nextpage);
191 } #---- END $OP eq DEFAULT
192 output_html_with_http_headers $input, $cookie, $template->output;