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
23 use C4::Interface::CGI::Output;
31 my ($env,$searchstring,$authtypecode)=@_;
32 my $dbh = C4::Context->dbh;
33 $searchstring=~ s/\'/\\\'/g;
34 my @data=split(' ',$searchstring);
36 my $sth=$dbh->prepare("Select tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,tab,seealso,authorised_value,value_builder from auth_subfield_structure where (tagfield like ? and authtypecode=?) order by tagfield");
37 $sth->execute("$searchstring%",$authtypecode);
40 while (my $data=$sth->fetchrow_hashref){
46 return ($cnt,\@results);
50 my $tagfield=$input->param('tagfield');
51 my $tagsubfield=$input->param('tagsubfield');
52 my $authtypecode=$input->param('authtypecode');
53 my $pkfield="tagfield";
54 my $offset=$input->param('offset');
55 my $script_name="/cgi-bin/koha/admin/auth_subfields_structure.pl";
57 my ($template, $borrowernumber, $cookie)
58 = get_template_and_user({template_name => "parameters/auth_subfields_structure.tmpl",
62 flagsrequired => {parameters => 1},
66 my $op = $input->param('op');
70 $template->param(script_name => $script_name,
72 authtypecode => $authtypecode,
73 $op => 1); # we show only the TMPL_VAR names $op
75 $template->param(script_name => $script_name,
77 authtypecode => $authtypecode,
78 else => 1); # we show only the TMPL_VAR names $op
81 ################## ADD_FORM ##################################
82 # called by default. Used to create form to add or modify a record
83 if ($op eq 'add_form') {
85 my $dbh = C4::Context->dbh;
86 my $more_subfields = $input->param("more_subfields")+1;
88 # build authorised value list
89 my $sth2 = $dbh->prepare("select distinct category from authorised_values");
91 my @authorised_values;
92 push @authorised_values,"";
93 while ((my $category) = $sth2->fetchrow_array) {
94 push @authorised_values, $category;
96 push (@authorised_values,"branches");
97 push (@authorised_values,"itemtypes");
98 # build value_builder list
99 my @value_builder=('');
100 opendir(DIR, "../value_builder") || die "can't opendir ../value_builder: $!";
101 while (my $line = readdir(DIR)) {
102 if ($line =~ /\.pl$/) {
103 push (@value_builder,$line);
109 my $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,tab,seealso,authorised_value,value_builder from auth_subfield_structure where tagfield=? and authtypecode=?"); # and tagsubfield='$tagsubfield'");
110 $sth->execute($tagfield,$authtypecode);
114 while ($data =$sth->fetchrow_hashref) {
115 my %row_data; # get a fresh hash for the row data
116 if ($toggle eq 'white'){
121 $row_data{tab} = CGI::scrolling_list(-name=>'tab',
122 -values=>['-1','0','1','2','3','4','5','6','7','8','9'],
123 -labels => {'-1' =>'ignore','0'=>'0','1'=>'1',
124 '2' =>'2','3'=>'3','4'=>'4',
125 '5' =>'5','6'=>'6','7'=>'7',
128 -default=>$data->{'tab'},
132 $row_data{tagsubfield} =$data->{'tagsubfield'}."<input type='hidden' name='tagsubfield' value='".$data->{'tagsubfield'}."'>";
133 $row_data{liblibrarian} = CGI::escapeHTML($data->{'liblibrarian'});
134 $row_data{libopac} = CGI::escapeHTML($data->{'libopac'});
135 $row_data{seealso} = CGI::escapeHTML($data->{'seealso'});
136 $row_data{authorised_value} = CGI::scrolling_list(-name=>'authorised_value',
137 -values=> \@authorised_values,
138 -default=>$data->{'authorised_value'},
142 $row_data{value_builder} = CGI::scrolling_list(-name=>'value_builder',
143 -values=> \@value_builder,
144 -default=>$data->{'value_builder'},
148 $row_data{repeatable} = CGI::checkbox("repeatable$i",$data->{'repeatable'}?'checked':'',1,'');
149 $row_data{mandatory} = CGI::checkbox("mandatory$i",$data->{'mandatory'}?'checked':'',1,'');
150 $row_data{bgcolor} = $toggle;
151 push(@loop_data, \%row_data);
154 # add more_subfields empty lines for add if needed
155 for (my $i=1;$i<=$more_subfields;$i++) {
156 my %row_data; # get a fresh hash for the row data
157 $row_data{tab} = CGI::scrolling_list(-name=>'tab',
158 -values=>['-1','0','1','2','3','4','5','6','7','8','9'],
159 -labels => {'-1' =>'ignore','0'=>'0','1'=>'1',
160 '2' =>'2','3'=>'3','4'=>'4',
161 '5' =>'5','6'=>'6','7'=>'7',
168 $row_data{tagsubfield} = "<input type=\"text\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" size=\"3\" maxlength=\"1\">";
169 $row_data{liblibrarian} = "";
170 $row_data{libopac} = "";
171 $row_data{seealso} = "";
172 $row_data{repeatable} = CGI::checkbox('repeatable','',1,'');
173 $row_data{mandatory} = CGI::checkbox('mandatory','',1,'');
174 $row_data{authorised_value} = CGI::scrolling_list(-name=>'authorised_value',
175 -values=> \@authorised_values,
179 $row_data{bgcolor} = $toggle;
180 push(@loop_data, \%row_data);
182 $template->param('use-heading-flags-p' => 1);
183 $template->param('heading-edit-subfields-p' => 1);
184 $template->param(action => "Edit subfields",
185 tagfield => "<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\">$tagfield",
187 more_subfields => $more_subfields,
188 more_tag => $tagfield);
190 # END $OP eq ADD_FORM
191 ################## ADD_VALIDATE ##################################
192 # called by add_form, used to insert/modify data in DB
193 } elsif ($op eq 'add_validate') {
194 my $dbh = C4::Context->dbh;
195 $template->param(tagfield => "$input->param('tagfield')");
196 my $sth=$dbh->prepare("replace auth_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,tab,seealso,authorised_value,value_builder,authtypecode)
197 values (?,?,?,?,?,?,?,?,?,?,?)");
198 my @tagsubfield = $input->param('tagsubfield');
199 my @liblibrarian = $input->param('liblibrarian');
200 my @libopac = $input->param('libopac');
201 my @tab = $input->param('tab');
202 my @seealso = $input->param('seealso');
203 my @authorised_values = $input->param('authorised_value');
204 my @value_builder =$input->param('value_builder');
205 for (my $i=0; $i<= $#tagsubfield ; $i++) {
206 my $tagfield =$input->param('tagfield');
207 my $tagsubfield =$tagsubfield[$i];
208 $tagsubfield="@" unless $tagsubfield;
209 my $liblibrarian =$liblibrarian[$i];
210 my $libopac =$libopac[$i];
211 my $repeatable =$input->param("repeatable$i")?1:0;
212 my $mandatory =$input->param("mandatory$i")?1:0;
214 my $seealso =$seealso[$i];
215 my $authorised_value =$authorised_values[$i];
216 my $value_builder=$value_builder[$i];
218 unless (C4::Context->config('demo') eq 1) {
219 $sth->execute ($tagfield,
228 $value_builder,$authtypecode);
233 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
236 # END $OP eq ADD_VALIDATE
237 ################## DELETE_CONFIRM ##################################
238 # called by default form, used to confirm deletion of data in DB
239 } elsif ($op eq 'delete_confirm') {
240 my $dbh = C4::Context->dbh;
241 my $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,tab,authorised_value,value_builder from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
242 $sth->execute($tagfield,$tagsubfield,$authtypecode);
243 my $data=$sth->fetchrow_hashref;
245 $template->param(liblibrarian => $data->{'liblibrarian'},
246 tagsubfield => $data->{'tagsubfield'},
247 delete_link => $script_name,
248 tagfield =>$tagfield,
249 tagsubfield => $tagsubfield,
250 authtypecode => $authtypecode,
252 # END $OP eq DELETE_CONFIRM
253 ################## DELETE_CONFIRMED ##################################
254 # called by delete_confirm, used to effectively confirm deletion of data in DB
255 } elsif ($op eq 'delete_confirmed') {
256 my $dbh = C4::Context->dbh;
257 unless (C4::Context->config('demo') eq 1) {
258 my $sth=$dbh->prepare("delete from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
259 $sth->execute($tagfield,$tagsubfield,$authtypecode);
260 warn "DEL : $tagfield,$tagsubfield,$authtypecode";
263 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
265 $template->param(tagfield => $tagfield);
266 # END $OP eq DELETE_CONFIRMED
267 ################## DEFAULT ##################################
270 my ($count,$results)=StringSearch($env,$tagfield,$authtypecode);
273 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
274 if ($toggle eq 'white'){
279 my %row_data; # get a fresh hash for the row data
280 $row_data{tagfield} = $results->[$i]{'tagfield'};
281 $row_data{tagsubfield} = $results->[$i]{'tagsubfield'};
282 $row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
283 $row_data{repeatable} = $results->[$i]{'repeatable'};
284 $row_data{mandatory} = $results->[$i]{'mandatory'};
285 $row_data{tab} = $results->[$i]{'tab'};
286 $row_data{seealso} = $results->[$i]{'seealso'};
287 $row_data{authorised_value} = $results->[$i]{'authorised_value'};
288 $row_data{value_builder} = $results->[$i]{'value_builder'};
289 $row_data{delete} = "$script_name?op=delete_confirm&tagfield=$tagfield&tagsubfield=".$results->[$i]{'tagsubfield'}."&authtypecode=$authtypecode";
290 $row_data{bgcolor} = $toggle;
291 if ($row_data{tab} eq -1) {
292 $row_data{subfield_ignored} = 1;
294 push(@loop_data, \%row_data);
296 $template->param(loop => \@loop_data);
297 $template->param(edit => "<a href=\"$script_name?op=add_form&tagfield=$tagfield&authtypecode=$authtypecode\">");
299 my $prevpage = $offset-$pagesize;
300 $template->param(prev =>"<a href=\"$script_name?offset=$prevpage&tagfield=$tagfield&authtypecode=$authtypecode\">");
302 if ($offset+$pagesize<$count) {
303 my $nextpage =$offset+$pagesize;
304 $template->param(next => "<a href=\"$script_name?offset=$nextpage&tagfield=$tagfield&authtypecode=$authtypecode\">");
306 } #---- END $OP eq DEFAULT
308 output_html_with_http_headers $input, $cookie, $template->output;