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 => "admin/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',
123 -labels => {'-1' =>'No (ignore)','0'=>'yes'
125 -default=>$data->{'tab'},
129 $row_data{tagsubfield} =$data->{'tagsubfield'}."<input type='hidden' name='tagsubfield' value='".$data->{'tagsubfield'}."'>";
130 $row_data{liblibrarian} = CGI::escapeHTML($data->{'liblibrarian'});
131 $row_data{libopac} = CGI::escapeHTML($data->{'libopac'});
132 $row_data{seealso} = CGI::escapeHTML($data->{'seealso'});
133 $row_data{authorised_value} = CGI::scrolling_list(-name=>'authorised_value',
134 -values=> \@authorised_values,
135 -default=>$data->{'authorised_value'},
139 $row_data{value_builder} = CGI::scrolling_list(-name=>'value_builder',
140 -values=> \@value_builder,
141 -default=>$data->{'value_builder'},
145 $row_data{repeatable} = CGI::checkbox("repeatable$i",$data->{'repeatable'}?'checked':'',1,'');
146 $row_data{mandatory} = CGI::checkbox("mandatory$i",$data->{'mandatory'}?'checked':'',1,'');
147 $row_data{bgcolor} = $toggle;
148 push(@loop_data, \%row_data);
151 # add more_subfields empty lines for add if needed
152 for (my $i=1;$i<=$more_subfields;$i++) {
153 my %row_data; # get a fresh hash for the row data
154 $row_data{tab} = CGI::scrolling_list(-name=>'tab',
156 -labels => {'-1' =>'no (ignore)','0'=>'yes',
162 $row_data{tagsubfield} = "<input type=\"text\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" size=\"3\" maxlength=\"1\">";
163 $row_data{liblibrarian} = "";
164 $row_data{libopac} = "";
165 $row_data{seealso} = "";
166 $row_data{repeatable} = CGI::checkbox('repeatable','',1,'');
167 $row_data{mandatory} = CGI::checkbox('mandatory','',1,'');
168 $row_data{authorised_value} = CGI::scrolling_list(-name=>'authorised_value',
169 -values=> \@authorised_values,
173 $row_data{bgcolor} = $toggle;
174 push(@loop_data, \%row_data);
176 $template->param('use-heading-flags-p' => 1);
177 $template->param('heading-edit-subfields-p' => 1);
178 $template->param(action => "Edit subfields",
179 tagfield => "<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\">$tagfield",
181 more_subfields => $more_subfields,
182 more_tag => $tagfield);
184 # END $OP eq ADD_FORM
185 ################## ADD_VALIDATE ##################################
186 # called by add_form, used to insert/modify data in DB
187 } elsif ($op eq 'add_validate') {
188 my $dbh = C4::Context->dbh;
189 $template->param(tagfield => "$input->param('tagfield')");
190 my $sth=$dbh->prepare("replace auth_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,tab,seealso,authorised_value,value_builder,authtypecode)
191 values (?,?,?,?,?,?,?,?,?,?,?)");
192 my @tagsubfield = $input->param('tagsubfield');
193 my @liblibrarian = $input->param('liblibrarian');
194 my @libopac = $input->param('libopac');
195 my @tab = $input->param('tab');
196 my @seealso = $input->param('seealso');
197 my @authorised_values = $input->param('authorised_value');
198 my @value_builder =$input->param('value_builder');
199 for (my $i=0; $i<= $#tagsubfield ; $i++) {
200 my $tagfield =$input->param('tagfield');
201 my $tagsubfield =$tagsubfield[$i];
202 $tagsubfield="@" unless $tagsubfield ne '';
203 my $liblibrarian =$liblibrarian[$i];
204 my $libopac =$libopac[$i];
205 my $repeatable =$input->param("repeatable$i")?1:0;
206 my $mandatory =$input->param("mandatory$i")?1:0;
208 my $seealso =$seealso[$i];
209 my $authorised_value =$authorised_values[$i];
210 my $value_builder=$value_builder[$i];
212 unless (C4::Context->config('demo') eq 1) {
213 $sth->execute ($tagfield,
222 $value_builder,$authtypecode);
227 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
230 # END $OP eq ADD_VALIDATE
231 ################## DELETE_CONFIRM ##################################
232 # called by default form, used to confirm deletion of data in DB
233 } elsif ($op eq 'delete_confirm') {
234 my $dbh = C4::Context->dbh;
235 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=?");
236 $sth->execute($tagfield,$tagsubfield,$authtypecode);
237 my $data=$sth->fetchrow_hashref;
239 $template->param(liblibrarian => $data->{'liblibrarian'},
240 tagsubfield => $data->{'tagsubfield'},
241 delete_link => $script_name,
242 tagfield =>$tagfield,
243 tagsubfield => $tagsubfield,
244 authtypecode => $authtypecode,
246 # END $OP eq DELETE_CONFIRM
247 ################## DELETE_CONFIRMED ##################################
248 # called by delete_confirm, used to effectively confirm deletion of data in DB
249 } elsif ($op eq 'delete_confirmed') {
250 my $dbh = C4::Context->dbh;
251 unless (C4::Context->config('demo') eq 1) {
252 my $sth=$dbh->prepare("delete from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
253 $sth->execute($tagfield,$tagsubfield,$authtypecode);
254 warn "DEL : $tagfield,$tagsubfield,$authtypecode";
257 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
259 $template->param(tagfield => $tagfield);
260 # END $OP eq DELETE_CONFIRMED
261 ################## DEFAULT ##################################
264 my ($count,$results)=StringSearch($env,$tagfield,$authtypecode);
267 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
268 if ($toggle eq 'white'){
273 my %row_data; # get a fresh hash for the row data
274 $row_data{tagfield} = $results->[$i]{'tagfield'};
275 $row_data{tagsubfield} = $results->[$i]{'tagsubfield'};
276 $row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
277 $row_data{repeatable} = $results->[$i]{'repeatable'};
278 $row_data{mandatory} = $results->[$i]{'mandatory'};
279 $row_data{tab} = $results->[$i]{'tab'};
280 $row_data{seealso} = $results->[$i]{'seealso'};
281 $row_data{authorised_value} = $results->[$i]{'authorised_value'};
282 $row_data{value_builder} = $results->[$i]{'value_builder'};
283 $row_data{delete} = "$script_name?op=delete_confirm&tagfield=$tagfield&tagsubfield=".$results->[$i]{'tagsubfield'}."&authtypecode=$authtypecode";
284 $row_data{bgcolor} = $toggle;
285 if ($row_data{tab} eq -1) {
286 $row_data{subfield_ignored} = 1;
288 push(@loop_data, \%row_data);
290 $template->param(loop => \@loop_data);
291 $template->param(edit => "<a href=\"$script_name?op=add_form&tagfield=$tagfield&authtypecode=$authtypecode\">");
293 my $prevpage = $offset-$pagesize;
294 $template->param(prev =>"<a href=\"$script_name?offset=$prevpage&tagfield=$tagfield&authtypecode=$authtypecode\">");
296 if ($offset+$pagesize<$count) {
297 my $nextpage =$offset+$pagesize;
298 $template->param(next => "<a href=\"$script_name?offset=$nextpage&tagfield=$tagfield&authtypecode=$authtypecode\">");
300 } #---- END $OP eq DEFAULT
302 output_html_with_http_headers $input, $cookie, $template->output;