2 # NOTE: 4-character tabs
4 #script to administer the itemtype subcategories 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
50 my ($searchstring,$type)=@_;
51 my $dbh = C4
::Context
->dbh;
52 $searchstring=~ s/\'/\\\'/g;
53 my @data=split(' ',$searchstring);
55 my $sth=$dbh->prepare("Select * from subcategorytable where (description like ?) order by subcategorycode");
56 $sth->execute("$data[0]%");
58 while (my $data=$sth->fetchrow_hashref){
63 return (scalar(@results),\
@results);
67 my $searchfield=$input->param('description');
68 my $offset=$input->param('offset');
69 my $script_name="/cgi-bin/koha/admin/itemtypesubcategory.pl";
70 my $subcategorycode=$input->param('subcategorycode');
72 my $op = $input->param('op');
73 $searchfield=~ s/\,//g;
74 my ($template, $borrowernumber, $cookie)
75 = get_template_and_user
({template_name
=> "admin/itemtypesubcategory.tmpl",
79 flagsrequired
=> {parameters
=> 1},
84 $template->param(script_name
=> $script_name,
85 $op => 1); # we show only the TMPL_VAR names $op
87 $template->param(script_name
=> $script_name,
88 else => 1); # we show only the TMPL_VAR names $op
90 ################## ADD_FORM ##################################
91 # called by default. Used to create form to add or modify a record
92 if ($op eq 'add_form') {
93 #start the page and read in includes
94 #---- if primkey exists, it's a modify action, so read values to modify...
97 my $dbh = C4
::Context
->dbh;
98 my @itemtypesselected;
99 if ($subcategorycode) {
100 my $sth=$dbh->prepare("select subcategorycode,description,itemtypecodes from subcategorytable where subcategorycode=?");
101 $sth->execute($subcategorycode);
102 $data=$sth->fetchrow_hashref;
104 @itemtypesselected = split ( /\|/, $data->{'itemtypecodes'} );
107 my $sth=$dbh->prepare("select description,itemtype from itemtypes order by description");
109 while (my ($description,$itemtype) = $sth->fetchrow) {
110 $itemtypes .='<td><input type="checkbox" name="itemtypecodes" value="'.$itemtype.'"';
111 if(grep /$itemtype/,@itemtypesselected){
112 $itemtypes .=' checked';
114 $itemtypes .='>'.$description.'</td>';
117 $template->param(subcategorycode
=> $subcategorycode,
118 description
=> $data->{'description'},
119 itemtypes
=> $itemtypes
122 # END $OP eq ADD_FORM
123 ################## ADD_VALIDATE ##################################
124 # called by add_form, used to insert/modify data in DB
125 } elsif ($op eq 'add_validate') {
126 my $dbh = C4
::Context
->dbh;
127 my @itemtypecodesarray = $input->param('itemtypecodes');
128 my $itemtypecodes=join('|',@itemtypecodesarray);
129 my $sth=$dbh->prepare("replace subcategorytable (subcategorycode,description,itemtypecodes) values (?,?,?)");
131 $input->param('subcategorycode'),$input->param('description'),
135 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=itemtypesubcategory.pl\"></html>";
137 # END $OP eq ADD_VALIDATE
138 ################## DELETE_CONFIRM ##################################
139 # called by default form, used to confirm deletion of data in DB
140 } elsif ($op eq 'delete_confirm') {
141 #start the page and read in includes
142 my $dbh = C4
::Context
->dbh;
143 my $sth=$dbh->prepare("select subcategorycode,description,itemtypecodes from subcategorytable where subcategorycode=?");
144 $sth->execute($subcategorycode);
145 my $data=$sth->fetchrow_hashref;
148 $template->param(subcategorycode
=> $subcategorycode,
149 description
=> $data->{'description'},
150 itemtypecodes
=> $data->{'itemtypecodes'});
151 # END $OP eq DELETE_CONFIRM
152 ################## DELETE_CONFIRMED ##################################
153 # called by delete_confirm, used to effectively confirm deletion of data in DB
154 } elsif ($op eq 'delete_confirmed') {
155 #start the page and read in includes
156 my $dbh = C4
::Context
->dbh;
157 my $subcategorycode=uc($input->param('subcategorycode'));
158 my $sth=$dbh->prepare("delete from subcategorytable where subcategorycode=?");
159 $sth->execute($subcategorycode);
161 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=itemtypesubcategory.pl\"></html>";
163 # END $OP eq DELETE_CONFIRMED
164 ################## DEFAULT ##################################
166 my ($count,$results)=StringSearch
($searchfield,'web');
169 for (my $i=$offset; $i < ($offset+$pagesize<$count?
$offset+$pagesize:$count); $i++){
176 $row_data{toggle
} = $toggle;
177 $row_data{subcategorycode
} = $results->[$i]{subcategorycode
};
178 $row_data{description
} = $results->[$i]{description
};
179 $row_data{itemtypecodes
} = $results->[$i]{itemtypecodes
};
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;