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
30 my ($env,$searchstring,$type)=@_;
31 my $dbh = C4::Context->dbh;
32 $searchstring=~ s/\'/\\\'/g;
33 my @data=split(' ',$searchstring);
35 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";
36 my $sth=$dbh->prepare($query);
40 while (my $data=$sth->fetchrow_hashref){
47 return ($cnt,\@results);
51 my $tagfield=$input->param('tagfield');
52 my $tagsubfield=$input->param('tagsubfield');
53 my $pkfield="tagfield";
54 my $reqsel="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'";
55 my $reqdel="delete from marc_subfield_structure where tagfield='$tagfield' and tagsubfield='$tagsubfield'";
56 my $offset=$input->param('offset');
57 my $script_name="/cgi-bin/koha/admin/marc_subfields_structure.pl";
59 my ($template, $borrowernumber, $cookie)
60 = get_template_and_user({template_name => "parameters/marc_subfields_structure.tmpl",
64 flagsrequired => {parameters => 1},
68 my $op = $input->param('op');
72 $template->param(script_name => $script_name,
74 $op => 1); # we show only the TMPL_VAR names $op
76 $template->param(script_name => $script_name,
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;
87 # builds kohafield tables
90 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
92 while ((my $field) = $sth2->fetchrow_array) {
93 push @kohafields, "biblio.".$field;
95 my $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
97 while ((my $field) = $sth2->fetchrow_array) {
98 push @kohafields, "biblioitems.".$field;
100 my $sth2=$dbh->prepare("SHOW COLUMNS from items");
102 while ((my $field) = $sth2->fetchrow_array) {
103 push @kohafields, "items.".$field;
105 # build authorised value list
107 $sth2 = $dbh->prepare("select distinct category from authorised_values");
109 my @authorised_values;
110 push @authorised_values,"";
111 while ((my $category) = $sth2->fetchrow_array) {
112 push @authorised_values, $category;
114 push (@authorised_values,"branches");
115 push (@authorised_values,"itemtypes");
116 # build thesaurus categories list
118 $sth2 = $dbh->prepare("select distinct category from bibliothesaurus");
120 my @thesaurus_category;
121 push @thesaurus_category,"";
122 while ((my $category) = $sth2->fetchrow_array) {
123 push @thesaurus_category, $category;
125 # build value_builder list
126 my @value_builder=('');
127 opendir(DIR, "../value_builder") || die "can't opendir ../value_builder: $!";
128 while (my $line = readdir(DIR)) {
129 if ($line =~ /\.pl$/) {
130 push (@value_builder,$line);
136 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'");
141 while ($data =$sth->fetchrow_hashref) {
142 my %row_data; # get a fresh hash for the row data
143 if ($toggle eq 'white'){
148 $row_data{tab} = CGI::scrolling_list(-name=>'tab',
149 -values=>['-1','0','1','2','3','4','5','6','7','8','9','10'],
150 -labels => {'-1' =>'ignore','0'=>'0','1'=>'1',
151 '2' =>'2','3'=>'3','4'=>'4',
152 '5' =>'5','6'=>'6','7'=>'7',
153 '8' =>'8','9'=>'9','10'=>'items (10)',
155 -default=>$data->{'tab'},
159 $row_data{tagsubfield} =$data->{'tagsubfield'}."<input type='hidden' name='tagsubfield' value='".$data->{'tagsubfield'}."'>";
160 $row_data{liblibrarian} = CGI::escapeHTML($data->{'liblibrarian'});
161 $row_data{libopac} = CGI::escapeHTML($data->{'libopac'});
162 $row_data{kohafield}= CGI::scrolling_list( -name=>"kohafield",
163 -values=> \@kohafields,
164 -default=> "$data->{'kohafield'}",
168 $row_data{authorised_value} = CGI::scrolling_list(-name=>'authorised_value',
169 -values=> \@authorised_values,
170 -default=>$data->{'authorised_value'},
174 $row_data{value_builder} = CGI::scrolling_list(-name=>'value_builder',
175 -values=> \@value_builder,
176 -default=>$data->{'value_builder'},
180 $row_data{thesaurus_category} = CGI::scrolling_list(-name=>'thesaurus_category',
181 -values=> \@thesaurus_category,
182 -default=>$data->{'thesaurus_category'},
186 # $row_data{kohafield} = $data->{'kohafield'};
187 $row_data{repeatable} = CGI::checkbox("repeatable$i",$data->{'repeatable'}?'checked':'',1,'');
188 $row_data{mandatory} = CGI::checkbox("mandatory$i",$data->{'mandatory'}?'checked':'',1,'');
189 $row_data{bgcolor} = $toggle;
190 push(@loop_data, \%row_data);
193 # add more_subfields empty lines for add if needed
194 for (my $i=1;$i<=$more_subfields;$i++) {
195 my %row_data; # get a fresh hash for the row data
196 $row_data{tab} = CGI::scrolling_list(-name=>'tab',
197 -values=>['-1','0','1','2','3','4','5','6','7','8','9','10'],
198 -labels => {'-1' =>'ignore','0'=>'0','1'=>'1',
199 '2' =>'2','3'=>'3','4'=>'4',
200 '5' =>'5','6'=>'6','7'=>'7',
201 '8' =>'8','9'=>'9','10'=>'items (10)',
207 $row_data{tagsubfield} = "<input type='text' name='tagsubfield' value='".$data->{'tagsubfield'}."' size=3 maxlength=1>";
208 $row_data{liblibrarian} = "";
209 $row_data{libopac} = "";
210 $row_data{repeatable} = CGI::checkbox('repeatable','',1,'');
211 $row_data{mandatory} = CGI::checkbox('mandatory','',1,'');
212 $row_data{kohafield}= CGI::scrolling_list( -name=>'kohafield',
213 -values=> \@kohafields,
218 $row_data{authorised_value} = CGI::scrolling_list(-name=>'authorised_value',
219 -values=> \@authorised_values,
223 $row_data{thesaurus_category} = CGI::scrolling_list(-name=>'thesaurus_category',
224 -values=> \@thesaurus_category,
228 $row_data{bgcolor} = $toggle;
229 push(@loop_data, \%row_data);
231 $template->param(action => "Edit subfields",
232 tagfield => "<input type=hidden name=tagfield value='$tagfield'>$tagfield",
234 more_subfields => $more_subfields,
235 more_tag => $tagfield);
237 # END $OP eq ADD_FORM
238 ################## ADD_VALIDATE ##################################
239 # called by add_form, used to insert/modify data in DB
240 } elsif ($op eq 'add_validate') {
241 my $dbh = C4::Context->dbh;
242 $template->param(tagfield => "$input->param('tagfield')");
243 my $sth=$dbh->prepare("replace marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,authorised_value,thesaurus_category,value_builder)
244 values (?,?,?,?,?,?,?,?,?,?,?)");
245 my @tagsubfield = $input->param('tagsubfield');
246 my @liblibrarian = $input->param('liblibrarian');
247 my @libopac = $input->param('libopac');
248 my @kohafield = $input->param('kohafield');
249 my @tab = $input->param('tab');
250 my @authorised_values = $input->param('authorised_value');
251 my @thesaurus_category = $input->param('thesaurus_category');
252 my @value_builder =$input->param('value_builder');
253 for (my $i=0; $i<= $#tagsubfield ; $i++) {
254 my $tagfield =$input->param('tagfield');
255 my $tagsubfield =$tagsubfield[$i];
256 my $liblibrarian =$liblibrarian[$i];
257 my $libopac =$libopac[$i];
258 my $repeatable =$input->param("repeatable$i")?1:0;
259 my $mandatory =$input->param("mandatory$i")?1:0;
260 my $kohafield =$kohafield[$i];
262 my $authorised_value =$authorised_values[$i];
263 my $thesaurus_category =$thesaurus_category[$i];
264 my $value_builder=$value_builder[$i];
266 $sth->execute ($tagfield,
280 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marc_subfields_structure.pl?tagfield=$tagfield\"></html>";
283 # END $OP eq ADD_VALIDATE
284 ################## DELETE_CONFIRM ##################################
285 # called by default form, used to confirm deletion of data in DB
286 } elsif ($op eq 'delete_confirm') {
287 my $dbh = C4::Context->dbh;
288 my $sth=$dbh->prepare($reqsel);
290 my $data=$sth->fetchrow_hashref;
292 $template->param(liblibrarian => $data->{'liblibrarian'},
293 tagsubfield => $data->{'tagsubfield'},
294 delete_link => $script_name,
295 tagfield =>$tagfield,
296 tagsubfield => $tagsubfield,
298 # END $OP eq DELETE_CONFIRM
299 ################## DELETE_CONFIRMED ##################################
300 # called by delete_confirm, used to effectively confirm deletion of data in DB
301 } elsif ($op eq 'delete_confirmed') {
302 my $dbh = C4::Context->dbh;
303 my $sth=$dbh->prepare($reqdel);
306 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marc_subfields_structure.pl?tagfield=$tagfield\"></html>";
308 $template->param(tagfield => $tagfield);
309 # END $OP eq DELETE_CONFIRMED
310 ################## DEFAULT ##################################
313 my ($count,$results)=StringSearch($env,$tagfield,'web');
316 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
317 if ($toggle eq 'white'){
322 my %row_data; # get a fresh hash for the row data
323 $row_data{tagfield} = $results->[$i]{'tagfield'};
324 $row_data{tagsubfield} = $results->[$i]{'tagsubfield'};
325 $row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
326 $row_data{kohafield} = $results->[$i]{'kohafield'};
327 $row_data{repeatable} = $results->[$i]{'repeatable'};
328 $row_data{mandatory} = $results->[$i]{'mandatory'};
329 $row_data{tab} = $results->[$i]{'tab'};
330 $row_data{authorised_value} = $results->[$i]{'authorised_value'};
331 $row_data{thesaurus_category} = $results->[$i]{'thesaurus_category'};
332 $row_data{value_builder} = $results->[$i]{'value_builder'};
333 $row_data{delete} = "$script_name?op=delete_confirm&tagfield=$tagfield&tagsubfield=".$results->[$i]{'tagsubfield'};
334 $row_data{bgcolor} = $toggle;
335 push(@loop_data, \%row_data);
337 $template->param(loop => \@loop_data);
338 $template->param(edit => "<a href='$script_name?op=add_form&tagfield=$tagfield'>Edit</a>");
340 my $prevpage = $offset-$pagesize;
341 $template->param(prev =>"<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
343 if ($offset+$pagesize<$count) {
344 my $nextpage =$offset+$pagesize;
345 $template->param(next => "<a href=$script_name?offset=".$nextpage.'Next >></a>');
347 } #---- END $OP eq DEFAULT
349 print $input->header(-cookie => $cookie), $template->output;