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,$frameworkcode)=@_;
32 my $dbh = C4::Context->dbh;
33 $searchstring=~ s/\'/\\\'/g;
34 my @data=split(' ',$searchstring);
36 my $sth=$dbh->prepare("Select * from marc_subfield_structure where (tagfield like ? and frameworkcode=?) order by tagfield");
37 $sth->execute("$searchstring%",$frameworkcode);
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 $frameworkcode=$input->param('frameworkcode');
53 my $pkfield="tagfield";
54 my $offset=$input->param('offset');
55 my $script_name="/cgi-bin/koha/admin/marc_subfields_structure.pl";
57 my ($template, $borrowernumber, $cookie)
58 = get_template_and_user({template_name => "parameters/marc_subfields_structure.tmpl",
62 flagsrequired => {parameters => 1},
66 my $op = $input->param('op');
70 $template->param(script_name => $script_name,
72 frameworkcode => $frameworkcode,
73 $op => 1); # we show only the TMPL_VAR names $op
75 $template->param(script_name => $script_name,
77 frameworkcode => $frameworkcode,
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 if ($field eq 'notes') { $field = 'bnotes'; }
99 push @kohafields, "biblioitems.".$field;
101 my $sth2=$dbh->prepare("SHOW COLUMNS from items");
103 while ((my $field) = $sth2->fetchrow_array) {
104 push @kohafields, "items.".$field;
108 push @kohafields, "additionalauthors.author";
109 push @kohafields, "bibliosubject.subject";
110 push @kohafields, "bibliosubtitle.title";
111 # build authorised value list
113 $sth2 = $dbh->prepare("select distinct category from authorised_values");
115 my @authorised_values;
116 push @authorised_values,"";
117 while ((my $category) = $sth2->fetchrow_array) {
118 push @authorised_values, $category;
120 push (@authorised_values,"branches");
121 push (@authorised_values,"itemtypes");
122 # build thesaurus categories list
124 $sth2 = $dbh->prepare("select distinct category from bibliothesaurus");
126 my @thesaurus_category;
127 push @thesaurus_category,"";
128 while ((my $category) = $sth2->fetchrow_array) {
129 push @thesaurus_category, $category;
131 # build value_builder list
132 my @value_builder=('');
133 opendir(DIR, "../value_builder") || die "can't opendir ../value_builder: $!";
134 while (my $line = readdir(DIR)) {
135 if ($line =~ /\.pl$/) {
136 push (@value_builder,$line);
142 my $sth=$dbh->prepare("select * from marc_subfield_structure where tagfield=? and frameworkcode=?"); # and tagsubfield='$tagsubfield'");
143 $sth->execute($tagfield,$frameworkcode);
147 while ($data =$sth->fetchrow_hashref) {
148 my %row_data; # get a fresh hash for the row data
149 if ($toggle eq 'white'){
154 $row_data{tab} = CGI::scrolling_list(-name=>'tab',
155 -values=>['-1','0','1','2','3','4','5','6','7','8','9','10'],
156 -labels => {'-1' =>'ignore','0'=>'0','1'=>'1',
157 '2' =>'2','3'=>'3','4'=>'4',
158 '5' =>'5','6'=>'6','7'=>'7',
159 '8' =>'8','9'=>'9','10'=>'items (10)',
161 -default=>$data->{'tab'},
165 $row_data{tagsubfield} =$data->{'tagsubfield'}."<input type='hidden' name='tagsubfield' value='".$data->{'tagsubfield'}."'>";
166 $row_data{liblibrarian} = CGI::escapeHTML($data->{'liblibrarian'});
167 $row_data{libopac} = CGI::escapeHTML($data->{'libopac'});
168 $row_data{seealso} = CGI::escapeHTML($data->{'seealso'});
169 $row_data{kohafield}= CGI::scrolling_list( -name=>"kohafield",
170 -values=> \@kohafields,
171 -default=> "$data->{'kohafield'}",
175 $row_data{authorised_value} = CGI::scrolling_list(-name=>'authorised_value',
176 -values=> \@authorised_values,
177 -default=>$data->{'authorised_value'},
181 $row_data{value_builder} = CGI::scrolling_list(-name=>'value_builder',
182 -values=> \@value_builder,
183 -default=>$data->{'value_builder'},
187 $row_data{thesaurus_category} = CGI::scrolling_list(-name=>'thesaurus_category',
188 -values=> \@thesaurus_category,
189 -default=>$data->{'thesaurus_category'},
193 $row_data{repeatable} = CGI::checkbox("repeatable$i",$data->{'repeatable'}?'checked':'',1,'');
194 $row_data{mandatory} = CGI::checkbox("mandatory$i",$data->{'mandatory'}?'checked':'',1,'');
195 $row_data{hidden} = CGI::checkbox("hidden$i",$data->{'hidden'}?'checked':'',1,'');
196 $row_data{isurl} = CGI::checkbox("isurl$i",$data->{'isurl'}?'checked':'',1,'');
197 $row_data{bgcolor} = $toggle;
198 push(@loop_data, \%row_data);
201 # add more_subfields empty lines for add if needed
202 for (my $i=1;$i<=$more_subfields;$i++) {
203 my %row_data; # get a fresh hash for the row data
204 $row_data{tab} = CGI::scrolling_list(-name=>'tab',
205 -values=>['-1','0','1','2','3','4','5','6','7','8','9','10'],
206 -labels => {'-1' =>'ignore','0'=>'0','1'=>'1',
207 '2' =>'2','3'=>'3','4'=>'4',
208 '5' =>'5','6'=>'6','7'=>'7',
209 '8' =>'8','9'=>'9','10'=>'items (10)',
215 $row_data{tagsubfield} = "<input type=\"text\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" size=\"3\" maxlength=\"1\">";
216 $row_data{liblibrarian} = "";
217 $row_data{libopac} = "";
218 $row_data{seealso} = "";
219 $row_data{repeatable} = CGI::checkbox('repeatable','',1,'');
220 $row_data{mandatory} = CGI::checkbox('mandatory','',1,'');
221 $row_data{hidden} = CGI::checkbox('hidden','',1,'');
222 $row_data{isurl} = CGI::checkbox('isurl','',1,'');
223 $row_data{kohafield}= CGI::scrolling_list( -name=>'kohafield',
224 -values=> \@kohafields,
229 $row_data{authorised_value} = CGI::scrolling_list(-name=>'authorised_value',
230 -values=> \@authorised_values,
234 $row_data{thesaurus_category} = CGI::scrolling_list(-name=>'thesaurus_category',
235 -values=> \@thesaurus_category,
239 $row_data{bgcolor} = $toggle;
240 push(@loop_data, \%row_data);
242 $template->param('use-heading-flags-p' => 1);
243 $template->param('heading-edit-subfields-p' => 1);
244 $template->param(action => "Edit subfields",
245 tagfield => "<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\">$tagfield",
247 more_subfields => $more_subfields,
248 more_tag => $tagfield);
250 # END $OP eq ADD_FORM
251 ################## ADD_VALIDATE ##################################
252 # called by add_form, used to insert/modify data in DB
253 } elsif ($op eq 'add_validate') {
254 my $dbh = C4::Context->dbh;
255 $template->param(tagfield => "$input->param('tagfield')");
256 my $sth=$dbh->prepare("replace marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,thesaurus_category,value_builder,hidden,isurl,frameworkcode)
257 values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
258 my @tagsubfield = $input->param('tagsubfield');
259 my @liblibrarian = $input->param('liblibrarian');
260 my @libopac = $input->param('libopac');
261 my @kohafield = $input->param('kohafield');
262 my @tab = $input->param('tab');
263 my @seealso = $input->param('seealso');
264 my @authorised_values = $input->param('authorised_value');
265 my @thesaurus_category = $input->param('thesaurus_category');
266 my @value_builder =$input->param('value_builder');
267 for (my $i=0; $i<= $#tagsubfield ; $i++) {
268 my $tagfield =$input->param('tagfield');
269 my $tagsubfield =$tagsubfield[$i];
270 $tagsubfield="@" unless $tagsubfield;
271 my $liblibrarian =$liblibrarian[$i];
272 my $libopac =$libopac[$i];
273 my $repeatable =$input->param("repeatable$i")?1:0;
274 my $mandatory =$input->param("mandatory$i")?1:0;
275 my $kohafield =$kohafield[$i];
277 my $seealso =$seealso[$i];
278 my $authorised_value =$authorised_values[$i];
279 my $thesaurus_category =$thesaurus_category[$i];
280 my $value_builder=$value_builder[$i];
281 my $hidden = $input->param("hidden$i")?1:0;
282 my $isurl = $input->param("isurl$i")?1:0;
284 unless (C4::Context->config('demo') eq 1) {
285 $sth->execute ($tagfield,
305 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marc_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode\"></html>";
308 # END $OP eq ADD_VALIDATE
309 ################## DELETE_CONFIRM ##################################
310 # called by default form, used to confirm deletion of data in DB
311 } elsif ($op eq 'delete_confirm') {
312 my $dbh = C4::Context->dbh;
313 my $sth=$dbh->prepare("select * from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?");
314 $sth->execute($tagfield,$tagsubfield);
315 my $data=$sth->fetchrow_hashref;
317 $template->param(liblibrarian => $data->{'liblibrarian'},
318 tagsubfield => $data->{'tagsubfield'},
319 delete_link => $script_name,
320 tagfield =>$tagfield,
321 tagsubfield => $tagsubfield,
322 frameworkcode => $frameworkcode,
324 # END $OP eq DELETE_CONFIRM
325 ################## DELETE_CONFIRMED ##################################
326 # called by delete_confirm, used to effectively confirm deletion of data in DB
327 } elsif ($op eq 'delete_confirmed') {
328 my $dbh = C4::Context->dbh;
329 unless (C4::Context->config('demo') eq 1) {
330 my $sth=$dbh->prepare("delete from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?");
331 $sth->execute($tagfield,$tagsubfield,$frameworkcode);
334 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marc_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode\"></html>";
336 $template->param(tagfield => $tagfield);
337 # END $OP eq DELETE_CONFIRMED
338 ################## DEFAULT ##################################
341 my ($count,$results)=StringSearch($env,$tagfield,$frameworkcode);
344 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
345 if ($toggle eq 'white'){
350 my %row_data; # get a fresh hash for the row data
351 $row_data{tagfield} = $results->[$i]{'tagfield'};
352 $row_data{tagsubfield} = $results->[$i]{'tagsubfield'};
353 $row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
354 $row_data{kohafield} = $results->[$i]{'kohafield'};
355 $row_data{repeatable} = $results->[$i]{'repeatable'};
356 $row_data{mandatory} = $results->[$i]{'mandatory'};
357 $row_data{tab} = $results->[$i]{'tab'};
358 $row_data{seealso} = $results->[$i]{'seealso'};
359 $row_data{authorised_value} = $results->[$i]{'authorised_value'};
360 $row_data{thesaurus_category} = $results->[$i]{'thesaurus_category'};
361 $row_data{value_builder} = $results->[$i]{'value_builder'};
362 $row_data{hidden} = $results->[$i]{'hidden'};
363 $row_data{isurl} = $results->[$i]{'isurl'};
364 $row_data{delete} = "$script_name?op=delete_confirm&tagfield=$tagfield&tagsubfield=".$results->[$i]{'tagsubfield'}."&frameworkcode=$frameworkcode";
365 $row_data{bgcolor} = $toggle;
366 if ($row_data{tab} eq -1) {
367 $row_data{subfield_ignored} = 1;
370 push(@loop_data, \%row_data);
372 $template->param(loop => \@loop_data);
373 $template->param(edit => "<a href=\"$script_name?op=add_form&tagfield=$tagfield&frameworkcode=$frameworkcode\">");
375 my $prevpage = $offset-$pagesize;
376 $template->param(prev =>"<a href=\"$script_name?offset=$prevpage\">");
378 if ($offset+$pagesize<$count) {
379 my $nextpage =$offset+$pagesize;
380 $template->param(next => "<a href=\"$script_name?offset=$nextpage\">");
382 } #---- END $OP eq DEFAULT
384 output_html_with_http_headers $input, $cookie, $template->output;