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);
41 while (my $data=$sth->fetchrow_hashref){
48 return ($cnt,\@results);
52 my $tagfield=$input->param('tagfield');
53 my $tagsubfield=$input->param('tagsubfield');
54 my $frameworkcode=$input->param('frameworkcode');
55 my $pkfield="tagfield";
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 frameworkcode => $frameworkcode,
75 $op => 1); # we show only the TMPL_VAR names $op
77 $template->param(script_name => $script_name,
79 frameworkcode => $frameworkcode,
80 else => 1); # we show only the TMPL_VAR names $op
83 ################## ADD_FORM ##################################
84 # called by default. Used to create form to add or modify a record
85 if ($op eq 'add_form') {
87 my $dbh = C4::Context->dbh;
88 my $more_subfields = $input->param("more_subfields")+1;
89 # builds kohafield tables
92 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
94 while ((my $field) = $sth2->fetchrow_array) {
95 push @kohafields, "biblio.".$field;
97 my $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
99 while ((my $field) = $sth2->fetchrow_array) {
100 if ($field eq 'notes') { $field = 'bnotes'; }
101 push @kohafields, "biblioitems.".$field;
103 my $sth2=$dbh->prepare("SHOW COLUMNS from items");
105 while ((my $field) = $sth2->fetchrow_array) {
106 push @kohafields, "items.".$field;
110 push @kohafields, "additionalauthors.author";
111 push @kohafields, "bibliosubject.subject";
112 push @kohafields, "bibliosubtitle.title";
113 # build authorised value list
115 $sth2 = $dbh->prepare("select distinct category from authorised_values");
117 my @authorised_values;
118 push @authorised_values,"";
119 while ((my $category) = $sth2->fetchrow_array) {
120 push @authorised_values, $category;
122 push (@authorised_values,"branches");
123 push (@authorised_values,"itemtypes");
124 # build thesaurus categories list
126 $sth2 = $dbh->prepare("select authtypecode from auth_types");
130 while ((my $authtypecode) = $sth2->fetchrow_array) {
131 push @authtypes, $authtypecode;
133 # build value_builder list
134 my @value_builder=('');
135 opendir(DIR, "../value_builder") || die "can't opendir ../value_builder: $!";
136 while (my $line = readdir(DIR)) {
137 if ($line =~ /\.pl$/) {
138 push (@value_builder,$line);
144 my $sth=$dbh->prepare("select * from marc_subfield_structure where tagfield=? and frameworkcode=?"); # and tagsubfield='$tagsubfield'");
145 $sth->execute($tagfield,$frameworkcode);
149 while ($data =$sth->fetchrow_hashref) {
150 my %row_data; # get a fresh hash for the row data
151 if ($toggle eq 'white'){
156 $row_data{tab} = CGI::scrolling_list(-name=>'tab',
157 -values=>['-1','0','1','2','3','4','5','6','7','8','9','10'],
158 -labels => {'-1' =>'ignore','0'=>'0','1'=>'1',
159 '2' =>'2','3'=>'3','4'=>'4',
160 '5' =>'5','6'=>'6','7'=>'7',
161 '8' =>'8','9'=>'9','10'=>'items (10)',
163 -default=>$data->{'tab'},
167 warn "ATTENTION ---+--- $data->{'link'}";
168 $row_data{tagsubfield} =$data->{'tagsubfield'}."<input type='hidden' name='tagsubfield' value='".$data->{'tagsubfield'}."'>";
169 $row_data{liblibrarian} = CGI::escapeHTML($data->{'liblibrarian'});
170 $row_data{libopac} = CGI::escapeHTML($data->{'libopac'});
171 $row_data{seealso} = CGI::escapeHTML($data->{'seealso'});
172 $row_data{kohafield}= CGI::scrolling_list( -name=>"kohafield",
173 -values=> \@kohafields,
174 -default=> "$data->{'kohafield'}",
178 $row_data{authorised_value} = CGI::scrolling_list(-name=>'authorised_value',
179 -values=> \@authorised_values,
180 -default=>$data->{'authorised_value'},
184 $row_data{value_builder} = CGI::scrolling_list(-name=>'value_builder',
185 -values=> \@value_builder,
186 -default=>$data->{'value_builder'},
190 $row_data{authtypes} = CGI::scrolling_list(-name=>'authtypecode',
191 -values=> \@authtypes,
192 -default=>$data->{'authtypecode'},
196 $row_data{repeatable} = CGI::checkbox("repeatable$i",$data->{'repeatable'}?'checked':'',1,'');
197 $row_data{mandatory} = CGI::checkbox("mandatory$i",$data->{'mandatory'}?'checked':'',1,'');
198 $row_data{hidden} = CGI::checkbox("hidden$i",$data->{'hidden'}?'checked':'',1,'');
199 $row_data{isurl} = CGI::checkbox("isurl$i",$data->{'isurl'}?'checked':'',1,'');
200 $row_data{bgcolor} = $toggle;
201 $row_data{link} = CGI::escapeHTML($data->{'link'});
202 push(@loop_data, \%row_data);
205 # add more_subfields empty lines for add if needed
206 for (my $i=1;$i<=$more_subfields;$i++) {
207 my %row_data; # get a fresh hash for the row data
208 $row_data{tab} = CGI::scrolling_list(-name=>'tab',
209 -values=>['-1','0','1','2','3','4','5','6','7','8','9','10'],
210 -labels => {'-1' =>'ignore','0'=>'0','1'=>'1',
211 '2' =>'2','3'=>'3','4'=>'4',
212 '5' =>'5','6'=>'6','7'=>'7',
213 '8' =>'8','9'=>'9','10'=>'items (10)',
219 $row_data{tagsubfield} = "<input type=\"text\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" size=\"3\" maxlength=\"1\">";
220 $row_data{liblibrarian} = "";
221 $row_data{libopac} = "";
222 $row_data{seealso} = "";
223 $row_data{repeatable} = CGI::checkbox('repeatable','',1,'');
224 $row_data{mandatory} = CGI::checkbox('mandatory','',1,'');
225 $row_data{hidden} = CGI::checkbox('hidden','',1,'');
226 $row_data{isurl} = CGI::checkbox('isurl','',1,'');
227 $row_data{kohafield}= CGI::scrolling_list( -name=>'kohafield',
228 -values=> \@kohafields,
233 $row_data{authorised_value} = CGI::scrolling_list(-name=>'authorised_value',
234 -values=> \@authorised_values,
238 $row_data{authtypes} = CGI::scrolling_list(-name=>'authtypecode',
239 -values=> \@authtypes,
243 $row_data{link} = CGI::escapeHTML($data->{'link'});
244 $row_data{bgcolor} = $toggle;
245 push(@loop_data, \%row_data);
247 $template->param('use-heading-flags-p' => 1);
248 $template->param('heading-edit-subfields-p' => 1);
249 $template->param(action => "Edit subfields",
250 tagfield => "<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\">$tagfield",
252 more_subfields => $more_subfields,
253 more_tag => $tagfield);
255 # END $OP eq ADD_FORM
256 ################## ADD_VALIDATE ##################################
257 # called by add_form, used to insert/modify data in DB
258 } elsif ($op eq 'add_validate') {
259 my $dbh = C4::Context->dbh;
260 $template->param(tagfield => "$input->param('tagfield')");
261 my $sth=$dbh->prepare("replace marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,authtypecode,value_builder,hidden,isurl,frameworkcode, link)
262 values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
263 my @tagsubfield = $input->param('tagsubfield');
264 my @liblibrarian = $input->param('liblibrarian');
265 my @libopac = $input->param('libopac');
266 my @kohafield = $input->param('kohafield');
267 my @tab = $input->param('tab');
268 my @seealso = $input->param('seealso');
269 my @authorised_values = $input->param('authorised_value');
270 my @authtypecodes = $input->param('authtypecode');
271 my @value_builder =$input->param('value_builder');
272 my @link =$input->param('link');
273 for (my $i=0; $i<= $#tagsubfield ; $i++) {
274 my $tagfield =$input->param('tagfield');
275 my $tagsubfield =$tagsubfield[$i];
276 $tagsubfield="@" unless $tagsubfield;
277 my $liblibrarian =$liblibrarian[$i];
278 my $libopac =$libopac[$i];
279 my $repeatable =$input->param("repeatable$i")?1:0;
280 my $mandatory =$input->param("mandatory$i")?1:0;
281 my $kohafield =$kohafield[$i];
283 my $seealso =$seealso[$i];
284 my $authorised_value =$authorised_values[$i];
285 my $authtypecode =$authtypecodes[$i];
286 my $value_builder=$value_builder[$i];
287 my $hidden = $input->param("hidden$i")?1:0;
288 my $isurl = $input->param("isurl$i")?1:0;
289 my $link = $link[$i];
291 unless (C4::Context->config('demo') eq 1) {
292 $sth->execute ($tagfield,
314 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marc_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode\"></html>";
317 # END $OP eq ADD_VALIDATE
318 ################## DELETE_CONFIRM ##################################
319 # called by default form, used to confirm deletion of data in DB
320 } elsif ($op eq 'delete_confirm') {
321 my $dbh = C4::Context->dbh;
322 my $sth=$dbh->prepare("select * from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?");
323 $sth->execute($tagfield,$tagsubfield);
324 my $data=$sth->fetchrow_hashref;
326 $template->param(liblibrarian => $data->{'liblibrarian'},
327 tagsubfield => $data->{'tagsubfield'},
328 delete_link => $script_name,
329 tagfield =>$tagfield,
330 tagsubfield => $tagsubfield,
331 frameworkcode => $frameworkcode,
333 # END $OP eq DELETE_CONFIRM
334 ################## DELETE_CONFIRMED ##################################
335 # called by delete_confirm, used to effectively confirm deletion of data in DB
336 } elsif ($op eq 'delete_confirmed') {
337 my $dbh = C4::Context->dbh;
338 unless (C4::Context->config('demo') eq 1) {
339 my $sth=$dbh->prepare("delete from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?");
340 $sth->execute($tagfield,$tagsubfield,$frameworkcode);
343 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marc_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode\"></html>";
345 $template->param(tagfield => $tagfield);
346 # END $OP eq DELETE_CONFIRMED
347 ################## DEFAULT ##################################
350 my ($count,$results)=StringSearch($env,$tagfield,$frameworkcode);
353 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
354 if ($toggle eq 'white'){
359 my %row_data; # get a fresh hash for the row data
360 $row_data{tagfield} = $results->[$i]{'tagfield'};
361 $row_data{tagsubfield} = $results->[$i]{'tagsubfield'};
362 $row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
363 $row_data{kohafield} = $results->[$i]{'kohafield'};
364 $row_data{repeatable} = $results->[$i]{'repeatable'};
365 $row_data{mandatory} = $results->[$i]{'mandatory'};
366 $row_data{tab} = $results->[$i]{'tab'};
367 $row_data{seealso} = $results->[$i]{'seealso'};
368 $row_data{authorised_value} = $results->[$i]{'authorised_value'};
369 $row_data{authtypecode} = $results->[$i]{'authtypecode'};
370 $row_data{value_builder} = $results->[$i]{'value_builder'};
371 $row_data{hidden} = $results->[$i]{'hidden'};
372 $row_data{isurl} = $results->[$i]{'isurl'};
373 $row_data{delete} = "$script_name?op=delete_confirm&tagfield=$tagfield&tagsubfield=".$results->[$i]{'tagsubfield'}."&frameworkcode=$frameworkcode";
374 $row_data{bgcolor} = $toggle;
375 if ($row_data{tab} eq -1) {
376 $row_data{subfield_ignored} = 1;
379 push(@loop_data, \%row_data);
381 $template->param(loop => \@loop_data);
382 $template->param(edit => "<a href=\"$script_name?op=add_form&tagfield=$tagfield&frameworkcode=$frameworkcode\">");
384 my $prevpage = $offset-$pagesize;
385 $template->param(prev =>"<a href=\"$script_name?offset=$prevpage\">");
387 if ($offset+$pagesize<$count) {
388 my $nextpage =$offset+$pagesize;
389 $template->param(next => "<a href=\"$script_name?offset=$nextpage\">");
391 } #---- END $OP eq DEFAULT
393 output_html_with_http_headers $input, $cookie, $template->output;