2 # NOTE: 4-character tabs
4 #script to administer the itemtype categories table
5 #modified from the itemtype script written 20/02/2002 by paul.poulain@free.fr
6 #This script written by waylon@robertson.net.nz at 2nd June, 2005
7 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
10 # this script use an $op to know what to do.
11 # if $op is empty or none of the above values,
12 # - the default screen is build (with all records, or filtered datas).
13 # - the user can clic on add, modify or delete record.
15 # - if primkey exists, this is a modification,so we read the $primkey record
16 # - builds the add/modify form
18 # - the user has just send datas, so we create/modify the record
20 # - we show the record having primkey=$primkey and ask for deletion validation form
21 # if $op=delete_confirm
22 # - we delete the record having primkey=$primkey
25 # Copyright 2000-2002 Katipo Communications
27 # This file is part of Koha.
29 # Koha is free software; you can redistribute it and/or modify it under the
30 # terms of the GNU General Public License as published by the Free Software
31 # Foundation; either version 2 of the License, or (at your option) any later
34 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
35 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
36 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
38 # You should have received a copy of the GNU General Public License along with
39 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
40 # Suite 330, Boston, MA 02111-1307 USA
47 use C4::Interface::CGI::Output;
51 my ($searchstring,$type)=@_;
52 my $dbh = C4::Context->dbh;
53 $searchstring=~ s/\'/\\\'/g;
54 my @data=split(' ',$searchstring);
56 my $sth=$dbh->prepare("Select * from categorytable where (description like ?) order by categorycode");
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/itemtypecategory.pl";
71 my $categorycode=$input->param('categorycode');
73 my $op = $input->param('op');
74 $searchfield=~ s/\,//g;
75 my ($template, $borrowernumber, $cookie)
76 = get_template_and_user({template_name => "admin/itemtypecategory.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 @itemtypesselected;
101 my $sth=$dbh->prepare("select categorycode,description,itemtypecodes from categorytable where categorycode=?");
102 $sth->execute($categorycode);
103 $data=$sth->fetchrow_hashref;
105 @itemtypesselected = split ( /\|/, $data->{'itemtypecodes'} );
108 my $sth=$dbh->prepare("select description,itemtype from itemtypes order by description");
110 while (my ($description,$itemtype) = $sth->fetchrow) {
111 $itemtypes .='<td><input type="checkbox" name="itemtypecodes" value="'.$itemtype.'"';
112 if(grep /$itemtype/,@itemtypesselected){
113 $itemtypes .=' checked';
115 $itemtypes .='>'.$description.'</td>';
118 $template->param(categorycode => $categorycode,
119 description => $data->{'description'},
120 itemtypes => $itemtypes
123 # END $OP eq ADD_FORM
124 ################## ADD_VALIDATE ##################################
125 # called by add_form, used to insert/modify data in DB
126 } elsif ($op eq 'add_validate') {
127 my $dbh = C4::Context->dbh;
128 my @itemtypecodesarray = $input->param('itemtypecodes');
129 my $itemtypecodes=join('|',@itemtypecodesarray);
130 my $sth=$dbh->prepare("replace categorytable (categorycode,description,itemtypecodes) values (?,?,?)");
132 $input->param('categorycode'),$input->param('description'),
136 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=itemtypecategory.pl\"></html>";
138 # END $OP eq ADD_VALIDATE
139 ################## DELETE_CONFIRM ##################################
140 # called by default form, used to confirm deletion of data in DB
141 } elsif ($op eq 'delete_confirm') {
142 #start the page and read in includes
143 my $dbh = C4::Context->dbh;
144 my $sth=$dbh->prepare("select categorycode,description,itemtypecodes from categorytable where categorycode=?");
145 $sth->execute($categorycode);
146 my $data=$sth->fetchrow_hashref;
149 $template->param(categorycode => $categorycode,
150 description => $data->{'description'},
151 itemtypecodes => $data->{'itemtypecodes'});
152 # END $OP eq DELETE_CONFIRM
153 ################## DELETE_CONFIRMED ##################################
154 # called by delete_confirm, used to effectively confirm deletion of data in DB
155 } elsif ($op eq 'delete_confirmed') {
156 #start the page and read in includes
157 my $dbh = C4::Context->dbh;
158 my $itemtype=uc($input->param('categorycode'));
159 my $sth=$dbh->prepare("delete from categorytable where categorycode=?");
160 $sth->execute($itemtype);
162 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=itemtypecategory.pl\"></html>";
164 # END $OP eq DELETE_CONFIRMED
165 ################## DEFAULT ##################################
167 my ($count,$results)=StringSearch($searchfield,'web');
170 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
177 $row_data{toggle} = $toggle;
178 $row_data{categorycode} = $results->[$i]{categorycode};
179 $row_data{description} = $results->[$i]{description};
180 $row_data{itemtypecodes} = $results->[$i]{itemtypecodes};
181 push(@loop_data, \%row_data);
183 $template->param(loop => \@loop_data);
185 my $prevpage = $offset-$pagesize;
186 $template->param(previous => "$script_name?offset=".$prevpage);
188 if ($offset+$pagesize<$count) {
189 my $nextpage =$offset+$pagesize;
190 $template->param(next => "$script_name?offset=".$nextpage);
192 } #---- END $OP eq DEFAULT
193 output_html_with_http_headers $input, $cookie, $template->output;