4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
27 use C4::Interface::CGI::Output;
34 my $searchfield=$input->param('searchfield');
35 $searchfield="" unless $searchfield;
36 my $id=$input->param('id');
37 my $offset=$input->param('offset');
38 $offset=0 unless $offset;
39 my $op = $input->param('op');
40 my $dspchoice = $input->param('select_display');
43 my $script_name="/cgi-bin/koha/admin/koha_attr.pl";
45 my $dbh = C4::Context->dbh;
48 my ($template, $loggedinuser, $cookie)
49 = get_template_and_user({template_name => "admin/koha_attr.tmpl",
53 flagsrequired => {parameters => 1},
59 $template->param(script_name => $script_name,
60 $op => 1); # we show only the TMPL_VAR names $op
62 $template->param(script_name => $script_name,
63 else => 1); # we show only the TMPL_VAR names $op
67 ################## ADD_FORM ##################################
68 # called by default. Used to create form to add or modify a record
69 if ($op eq 'add_form') {
70 #---- if primkey exists, it's a modify action, so read values to modify...
73 $sth=$dbh->prepare("select id,marctokoha,attr,liblibrarian,sorts,recordtype,tagfield,tagsubfield,opacshow,intrashow from koha_attr where id=? ");
75 $data=$sth->fetchrow_hashref;
78 my $sth = $dbh->prepare("select authorised_value from authorised_values where category='recordtype'");
80 my @authorised_values;
81 #push @authorised_values,"";
82 while ((my $category) = $sth->fetchrow_array) {
83 push @authorised_values, $category;
85 my $recordlist = CGI::scrolling_list(-name=>'recordtype',
86 -values=> \@authorised_values,
89 -default => $data->{'recordtype'},
91 my $sth = $dbh->prepare("select authorised_value from authorised_values where category='mfield' order by lib");
93 my @authorised_values;
94 #push @authorised_values,"";
95 while ((my $category) = $sth->fetchrow_array) {
96 push @authorised_values, $category;
98 my $taglist = CGI::scrolling_list(-name=>'tagfield',
99 -values=> \@authorised_values,
102 -default => $data->{'tagfield'},
104 my $sth = $dbh->prepare("select authorised_value from authorised_values where category='subfield' order by lib ");
106 my @authorised_values;
107 #push @authorised_values,"";
108 while ((my $category) = $sth->fetchrow_array) {
109 push @authorised_values, $category;
111 my $tagsublist = CGI::scrolling_list(-name=>'tagsubfield',
112 -values=> \@authorised_values,
115 -default => $data->{'tagsubfield'},
119 $template->param(action => "Modify tag",id=>$id ,searchfield => "<input type=\"hidden\" name=\"marctokoha\" value=\"$searchfield\" />$searchfield");
120 $template->param('heading-modify-tag-p' => 1);
122 $template->param(action => "Add tag",
123 searchfield => "<input type=\"text\" name=\"marctokoha\" size=\"40\" maxlength=\"80\" />");
124 $template->param('heading-add-tag-p' => 1);
126 $template->param('use-heading-flags-p' => 1);
127 $template->param(liblibrarian => $data->{'liblibrarian'},
128 attr=> $data->{'attr'},
129 recordtype=>$recordlist,
131 tagsubfield=>$tagsublist,
132 sorts => CGI::checkbox(-name=>'sorts',
133 -checked=> $data->{'sorts'}?'checked':'',
137 opacshow => CGI::checkbox(-name=>'opacshow',
138 -checked=> $data->{'opacshow'}?'checked':'',
142 intrashow => CGI::checkbox(-name=>'intrashow',
143 -checked=> $data->{'intrashow'}?'checked':'',
150 # END $OP eq ADD_FORM
151 ################## ADD_VALIDATE ##################################
152 # called by add_form, used to insert/modify data in DB
153 } elsif ($op eq 'add_validate') {
154 my $id =$input->param('id');
156 $sth=$dbh->prepare("replace koha_attr set id=?,marctokoha=?,attr=?,liblibrarian=?,sorts=?,recordtype=?,tagfield=?,tagsubfield=? ,opacshow=?,intrashow=? ");
159 my $marctokoha =$input->param('marctokoha');
160 my $attr =$input->param('attr');
161 my $liblibrarian = $input->param('liblibrarian');
162 my $sorts =$input->param('sorts');
163 my $opacshow =$input->param('opacshow');
164 my $intrashow =$input->param('intrashow');
165 my $recordtype =$input->param('recordtype');
166 my $tagfield =$input->param('tagfield');
167 my $tagsubfield =$input->param('tagsubfield');
168 unless (C4::Context->config('demo') eq 1) {
169 $sth->execute( $id,$marctokoha,$attr,$liblibrarian,$sorts?1:0,$recordtype,$tagfield,$tagsubfield,$opacshow?1:0,$intrashow?1:0);
172 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=koha_attr.pl?searchfield=$marctokoha\"></html>";
175 # END $OP eq ADD_VALIDATE
176 ################## DELETE_CONFIRM ##################################
177 # called by default form, used to confirm deletion of data in DB
178 } elsif ($op eq 'delete_confirm') {
179 $sth=$dbh->prepare("select id,marctokoha,liblibrarian,recordtype from koha_attr where id=? ");
181 my $data=$sth->fetchrow_hashref;
183 $template->param(liblibrarian => $data->{'liblibrarian'}."/". $data->{'recordtype'},id=>$data->{'id'},
184 searchfield => $searchfield,
186 # END $OP eq DELETE_CONFIRM
187 ################## DELETE_CONFIRMED ##################################
188 # called by delete_confirm, used to effectively confirm deletion of data in DB
189 } elsif ($op eq 'delete_confirmed') {
191 unless (C4::Context->config('demo') eq 1) {
192 $dbh->do("delete from koha_attr where id=$id ");
194 # END $OP eq DELETE_CONFIRMED
196 ################## DEFAULT ##################################
198 # here, $op can be unset or set
199 if ($searchfield ne '') {
200 $template->param(searchfield => $searchfield);
204 #here, user only wants used tags/subfields displayed
205 my $sth=$dbh->prepare("Select * from koha_attr where tagfield <>'' and marctokoha >= ? ");
206 #could be ordoned by tab
207 $sth->execute($searchfield);
209 while (my $data=$sth->fetchrow_hashref){
210 push(@results,$data);
220 while ($i < ($offset+$pagesize<$cnt?$offset+$pagesize:$cnt)) {
226 my %row_data; # get a fresh hash for the row data
227 $row_data{id} = $results[$i]->{'id'};
228 $row_data{marctokoha} = $results[$i]->{'marctokoha'};
229 $row_data{liblibrarian} = $results[$i]->{'liblibrarian'};
230 $row_data{sorts} = $results[$i]->{'sorts'};
231 $row_data{attr} = $results[$i]->{'attr'};
232 $row_data{recordtype} = $results[$i]->{'recordtype'};
233 $row_data{tagfield} = $results[$i]->{'tagfield'};
234 $row_data{tagsubfield} = $results[$i]->{'tagsubfield'};
235 $row_data{opacshow} = $results[$i]->{'opacshow'};
236 $row_data{intrashow} = $results[$i]->{'intrashow'};
237 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results[$i]->{'marctokoha'}."&id=".$results[$i]->{'id'};
238 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results[$i]->{'marctokoha'}."&id=".$results[$i]->{'id'};
239 $row_data{toggle} = $toggle;
240 push(@loop_data, \%row_data);
243 $template->param(select_display => "True",
244 loop => \@loop_data);
247 #here, normal old style : display every tags
248 my ($count,@results)=StringSearch($dbh,$searchfield);
252 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
258 my %row_data; # get a fresh hash for the row data
259 $row_data{id} = $results[$i]->{'id'};
260 $row_data{marctokoha} = $results[$i]->{marctokoha};
261 $row_data{liblibrarian} = $results[$i]->{liblibrarian};
262 $row_data{sorts} = $results[$i]->{sorts};
263 $row_data{opacshow} = $results[$i]->{'opacshow'};
264 $row_data{intrashow} = $results[$i]->{'intrashow'};
265 $row_data{attr} = $results[$i]->{attr};
266 $row_data{recordtype} = $results[$i]->{'recordtype'};
267 $row_data{tagfield} = $results[$i]->{'tagfield'};
268 $row_data{tagsubfield} = $results[$i]->{'tagsubfield'};
269 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results[$i]->{marctokoha}."&id=".$results[$i]->{'id'};
270 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results[$i]->{marctokoha}."&id=".$results[$i]->{'id'};
271 $row_data{toggle} = $toggle;
272 push(@loop_data, \%row_data);
274 $template->param(loop => \@loop_data);
277 my $prevpage = $offset-$pagesize;
278 $template->param(isprevpage => $offset,
279 prevpage=> $prevpage,
280 searchfield => $searchfield,
281 script_name => $script_name,
285 if ($offset+$pagesize<$cnt) {
286 my $nextpage =$offset+$pagesize;
287 $template->param(nextpage =>$nextpage,
288 searchfield => $searchfield,
289 script_name => $script_name,
293 } #---- END $OP eq DEFAULT
295 $template->param(loggeninuser => $loggedinuser,
296 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
297 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
298 IntranetNav => C4::Context->preference("IntranetNav"),
300 output_html_with_http_headers $input, $cookie, $template->output;
304 # the sub used for searches
307 my ($dbh,$searchstring)=@_;
308 my $sth=$dbh->prepare("Select * from koha_attr where marctokoha >=? order by marctokoha");
309 $sth->execute($searchstring);
311 while (my $data=$sth->fetchrow_hashref){
312 push(@dataresults,$data);
317 return (scalar(@dataresults),@dataresults);