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
29 my ($env,$searchstring,$type)=@_;
30 my $dbh = C4::Context->dbh;
31 $searchstring=~ s/\'/\\\'/g;
32 my @data=split(' ',$searchstring);
34 my $query="Select tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,authorised_value,thesaurus_category,value_builder from marc_subfield_structure where (tagfield like \"$searchstring%\") order by tagfield";
35 my $sth=$dbh->prepare($query);
39 while (my $data=$sth->fetchrow_hashref){
46 return ($cnt,\@results);
50 my $tagfield=$input->param('tagfield');
51 my $tagsubfield=$input->param('tagsubfield');
52 my $pkfield="tagfield";
53 my $reqsel="select tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,authorised_value,thesaurus_category,value_builder from marc_subfield_structure where tagfield='$tagfield'";
54 my $reqdel="delete from marc_subfield_structure where tagfield='$tagfield' and tagsubfield='$tagsubfield'";
55 my $offset=$input->param('offset');
56 my $script_name="/cgi-bin/koha/admin/marc_subfields_structure.pl";
58 my $template = gettemplate("parameters/marc_subfields_structure.tmpl",0);
60 my $op = $input->param('op');
64 $template->param(script_name => $script_name,
66 $op => 1); # we show only the TMPL_VAR names $op
68 $template->param(script_name => $script_name,
70 else => 1); # we show only the TMPL_VAR names $op
73 ################## ADD_FORM ##################################
74 # called by default. Used to create form to add or modify a record
75 if ($op eq 'add_form') {
77 my $dbh = C4::Context->dbh;
78 my $more_subfields = $input->param("more_subfields")+1;
79 # builds kohafield tables
82 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
84 while ((my $field) = $sth2->fetchrow_array) {
85 push @kohafields, "biblio.".$field;
87 my $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
89 while ((my $field) = $sth2->fetchrow_array) {
90 push @kohafields, "biblioitems.".$field;
92 my $sth2=$dbh->prepare("SHOW COLUMNS from items");
94 while ((my $field) = $sth2->fetchrow_array) {
95 push @kohafields, "items.".$field;
97 # build authorised value list
99 $sth2 = $dbh->prepare("select distinct category from authorised_values");
101 my @authorised_values;
102 push @authorised_values,"";
103 while ((my $category) = $sth2->fetchrow_array) {
104 push @authorised_values, $category;
106 # build thesaurus categories list
108 $sth2 = $dbh->prepare("select distinct category from bibliothesaurus");
110 my @thesaurus_category;
111 push @thesaurus_category,"";
112 while ((my $category) = $sth2->fetchrow_array) {
113 push @thesaurus_category, $category;
115 # build value_builder list
116 my @value_builder=('');
117 opendir(DIR, "../value_builder") || die "can't opendir ../value_builder: $!";
118 while (my $line = readdir(DIR)) {
119 if ($line =~ /\.pl$/) {
120 push (@value_builder,$line);
125 warn "$value_builder[0] ยง $value_builder[1]";
127 my $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,authorised_value,thesaurus_category,value_builder from marc_subfield_structure where tagfield='$tagfield'"); # and tagsubfield='$tagsubfield'");
132 while ($data =$sth->fetchrow_hashref) {
133 my %row_data; # get a fresh hash for the row data
134 if ($toggle eq 'white'){
139 $row_data{tab} = CGI::scrolling_list(-name=>'tab',
140 -values=>['-1','0','1','2','3','4','5','6','7','8','9','10'],
141 -labels => {'-1' =>'ignore','0'=>'0','1'=>'1',
142 '2' =>'2','3'=>'3','4'=>'4',
143 '5' =>'5','6'=>'6','7'=>'7',
144 '8' =>'8','9'=>'9','10'=>'items (10)',
146 -default=>$data->{'tab'},
150 $row_data{tagsubfield} =$data->{'tagsubfield'}."<input type='hidden' name='tagsubfield' value='".$data->{'tagsubfield'}."'>";
151 $row_data{liblibrarian} = CGI::escapeHTML($data->{'liblibrarian'});
152 $row_data{libopac} = CGI::escapeHTML($data->{'libopac'});
153 $row_data{kohafield}= CGI::scrolling_list( -name=>"kohafield",
154 -values=> \@kohafields,
155 -default=> "$data->{'kohafield'}",
159 $row_data{authorised_value} = CGI::scrolling_list(-name=>'authorised_value',
160 -values=> \@authorised_values,
161 -default=>$data->{'authorised_value'},
165 $row_data{value_builder} = CGI::scrolling_list(-name=>'value_builder',
166 -values=> \@value_builder,
167 -default=>$data->{'thesaurus_category'},
171 $row_data{thesaurus_category} = CGI::scrolling_list(-name=>'thesaurus_category',
172 -values=> \@thesaurus_category,
173 -default=>$data->{'thesaurus_category'},
177 # $row_data{kohafield} = $data->{'kohafield'};
178 $row_data{repeatable} = CGI::checkbox("repeatable$i",$data->{'repeatable'}?'checked':'',1,'');
179 $row_data{mandatory} = CGI::checkbox("mandatory$i",$data->{'mandatory'}?'checked':'',1,'');
180 $row_data{bgcolor} = $toggle;
181 push(@loop_data, \%row_data);
184 # add more_subfields empty lines for add if needed
185 for (my $i=1;$i<=$more_subfields;$i++) {
186 my %row_data; # get a fresh hash for the row data
187 $row_data{tab} = CGI::scrolling_list(-name=>'tab',
188 -values=>['-1','0','1','2','3','4','5','6','7','8','9','10'],
189 -labels => {'-1' =>'ignore','0'=>'0','1'=>'1',
190 '2' =>'2','3'=>'3','4'=>'4',
191 '5' =>'5','6'=>'6','7'=>'7',
192 '8' =>'8','9'=>'9','10'=>'items (10)',
198 $row_data{tagsubfield} = "<input type='text' name='tagsubfield' value='".$data->{'tagsubfield'}."' size=3 maxlength=1>";
199 $row_data{liblibrarian} = "";
200 $row_data{libopac} = "";
201 $row_data{repeatable} = CGI::checkbox('repeatable','',1,'');
202 $row_data{mandatory} = CGI::checkbox('mandatory','',1,'');
203 $row_data{kohafield}= CGI::scrolling_list( -name=>'kohafield',
204 -values=> \@kohafields,
209 $row_data{authorised_value} = CGI::scrolling_list(-name=>'authorised_value',
210 -values=> \@authorised_values,
214 $row_data{thesaurus_category} = CGI::scrolling_list(-name=>'thesaurus_category',
215 -values=> \@thesaurus_category,
219 $row_data{bgcolor} = $toggle;
220 push(@loop_data, \%row_data);
222 $template->param(action => "Edit subfields",
223 tagfield => "<input type=hidden name=tagfield value='$tagfield'>$tagfield",
225 more_subfields => $more_subfields,
226 more_tag => $tagfield);
228 # END $OP eq ADD_FORM
229 ################## ADD_VALIDATE ##################################
230 # called by add_form, used to insert/modify data in DB
231 } elsif ($op eq 'add_validate') {
232 my $dbh = C4::Context->dbh;
233 $template->param(tagfield => "$input->param('tagfield')");
234 my $sth=$dbh->prepare("replace marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,authorised_value,thesaurus_category,value_builder)
235 values (?,?,?,?,?,?,?,?,?,?,?)");
236 my @tagsubfield = $input->param('tagsubfield');
237 my @liblibrarian = $input->param('liblibrarian');
238 my @libopac = $input->param('libopac');
239 my @kohafield = $input->param('kohafield');
240 my @tab = $input->param('tab');
241 my @authorised_values = $input->param('authorised_value');
242 my @thesaurus_category = $input->param('thesaurus_category');
243 my @value_builder =$input->param('value_builder');
244 for (my $i=0; $i<= $#tagsubfield ; $i++) {
245 my $tagfield =$input->param('tagfield');
246 my $tagsubfield =$tagsubfield[$i];
247 my $liblibrarian =$liblibrarian[$i];
248 my $libopac =$libopac[$i];
249 my $repeatable =$input->param("repeatable$i")?1:0;
250 my $mandatory =$input->param("mandatory$i")?1:0;
251 my $kohafield =$kohafield[$i];
253 my $authorised_value =$authorised_values[$i];
254 my $thesaurus_category =$thesaurus_category[$i];
255 my $value_builder=$value_builder[$i];
257 $sth->execute ($tagfield,
271 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marc_subfields_structure.pl?tagfield=$tagfield\"></html>";
274 # END $OP eq ADD_VALIDATE
275 ################## DELETE_CONFIRM ##################################
276 # called by default form, used to confirm deletion of data in DB
277 } elsif ($op eq 'delete_confirm') {
278 my $dbh = C4::Context->dbh;
279 my $sth=$dbh->prepare($reqsel);
281 my $data=$sth->fetchrow_hashref;
283 $template->param(liblibrarian => $data->{'liblibrarian'},
284 tagsubfield => $tagsubfield,
285 delete_link => $script_name,
286 tagfield =>$tagfield,
287 tagsubfield => $tagsubfield,
289 # END $OP eq DELETE_CONFIRM
290 ################## DELETE_CONFIRMED ##################################
291 # called by delete_confirm, used to effectively confirm deletion of data in DB
292 } elsif ($op eq 'delete_confirmed') {
293 my $dbh = C4::Context->dbh;
294 my $sth=$dbh->prepare($reqdel);
297 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marc_subfields_structure.pl?tagfield=$tagfield\"></html>";
299 $template->param(tagfield => $tagfield);
300 # END $OP eq DELETE_CONFIRMED
301 ################## DEFAULT ##################################
304 my ($count,$results)=StringSearch($env,$tagfield,'web');
307 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
308 if ($toggle eq 'white'){
313 my %row_data; # get a fresh hash for the row data
314 $row_data{tagfield} = $results->[$i]{'tagfield'};
315 $row_data{tagsubfield} = $results->[$i]{'tagsubfield'};
316 $row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
317 $row_data{kohafield} = $results->[$i]{'kohafield'};
318 $row_data{repeatable} = $results->[$i]{'repeatable'};
319 $row_data{mandatory} = $results->[$i]{'mandatory'};
320 $row_data{tab} = $results->[$i]{'tab'};
321 $row_data{authorised_value} = $results->[$i]{'authorised_value'};
322 $row_data{thesaurus_category} = $results->[$i]{'thesaurus_category'};
323 $row_data{value_builder} = $results->[$i]{'value_builder'};
324 $row_data{delete} = "$script_name?op=delete_confirm&tagfield=$tagfield&tagsubfield=".$results->[$i]{'tagsubfield'};
325 $row_data{bgcolor} = $toggle;
326 push(@loop_data, \%row_data);
328 $template->param(loop => \@loop_data);
329 $template->param(edit => "<a href='$script_name?op=add_form&tagfield=$tagfield'>Edit</a>");
331 my $prevpage = $offset-$pagesize;
332 $template->param(prev =>"<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
334 if ($offset+$pagesize<$count) {
335 my $nextpage =$offset+$pagesize;
336 $template->param(next => "<a href=$script_name?offset=".$nextpage.'Next >></a>');
338 } #---- END $OP eq DEFAULT
340 print "Content-Type: text/html\n\n", $template->output;