3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
27 use Koha::Authority::Types;
28 use Koha::AuthorisedValues;
29 use Koha::Authority::Subfields;
31 use List::MoreUtils qw( uniq );
34 my $tagfield = $input->param('tagfield');
35 my $tagsubfield = $input->param('tagsubfield');
36 my $authtypecode = $input->param('authtypecode');
37 my $op = $input->param('op') || '';
38 my $script_name = "/cgi-bin/koha/admin/auth_subfields_structure.pl";
40 my ($template, $borrowernumber, $cookie) = get_template_and_user(
41 { template_name => "admin/auth_subfields_structure.tt",
44 flagsrequired => { parameters => 'manage_marc_frameworks' },
52 $template->param(script_name => $script_name,
54 authtypecode => $authtypecode,
55 $op => 1); # we show only the TMPL_VAR names $op
57 $template->param(script_name => $script_name,
59 authtypecode => $authtypecode,
60 else => 1); # we show only the TMPL_VAR names $op
63 my $dbh = C4::Context->dbh;
64 ################## ADD_FORM ##################################
65 # called by default. Used to create form to add or modify a record
66 if ($op eq 'add_form') {
67 # builds kohafield tables
70 my $sth2=$dbh->prepare("SHOW COLUMNS from auth_header");
72 while ((my $field) = $sth2->fetchrow_array) {
73 push @kohafields, "auth_header.".$field;
76 # build authorised value category list
77 my @authorised_value_categories = Koha::AuthorisedValues->new->categories;
78 unshift @authorised_value_categories, '';
79 push @authorised_value_categories, 'branches';
80 push @authorised_value_categories, 'itemtypes';
82 # build thesaurus categories list
83 my @authtypes = uniq( "", map { $_->authtypecode } Koha::Authority::Types->search );
85 # build value_builder list
86 my @value_builder=('');
88 # read value_builder directory.
89 # 2 cases here : on CVS install, $cgidir does not need a /cgi-bin
90 # on a standard install, /cgi-bin need to be added.
91 # test one, then the other
92 my $cgidir = C4::Context->config('intranetdir') ."/cgi-bin";
93 unless (opendir(DIR, "$cgidir/cataloguing/value_builder")) {
94 $cgidir = C4::Context->config('intranetdir');
95 opendir(DIR, "$cgidir/cataloguing/value_builder") || die "can't opendir $cgidir/value_builder: $!";
97 while (my $line = readdir(DIR)) {
98 if ( $line =~ /\.pl$/ &&
99 $line !~ /EXAMPLE\.pl$/ ) { # documentation purposes
100 push (@value_builder,$line);
103 @value_builder= sort {$a cmp $b} @value_builder;
107 my $asses = Koha::Authority::Subfields->search({ tagfield => $tagfield, authtypecode => $authtypecode}, {order_by => 'display_order'})->unblessed;
109 for my $ass ( @$asses ) {
110 my %row_data = %$ass;
111 $row_data{kohafields} = \@kohafields;
112 $row_data{authorised_values} = \@authorised_value_categories;
113 $row_data{frameworkcodes} = \@authtypes;
114 $row_data{value_builders} = \@value_builder;
115 $row_data{row} = $i++;
116 push( @loop_data, \%row_data );
119 # Add a new row for the "New" tab
120 my %row_data; # get a fresh hash for the row data
121 $row_data{'new_subfield'} = 1;
122 $row_data{tab} = -1; # ignore
123 $row_data{ohidden} = 0; # show all
124 $row_data{tagsubfield} = "";
125 $row_data{liblibrarian} = "";
126 $row_data{libopac} = "";
127 $row_data{seealso} = "";
128 $row_data{hidden} = "000";
129 $row_data{repeatable} = 0;
130 $row_data{mandatory} = 0;
131 $row_data{isurl} = 0;
132 $row_data{kohafields} = \@kohafields,
133 $row_data{authorised_values} = \@authorised_value_categories;
134 $row_data{frameworkcodes} = \@authtypes;
135 $row_data{value_builders} = \@value_builder;
137 push( @loop_data, \%row_data );
139 $template->param('use_heading_flags_p' => 1);
140 $template->param('heading_edit_subfields_p' => 1);
141 $template->param(action => "Edit subfields",
142 tagfield => $tagfield,
143 tagfieldinput => "<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\" />",
145 more_tag => $tagfield);
147 # END $OP eq ADD_FORM
148 ################## ADD_VALIDATE ##################################
149 # called by add_form, used to insert/modify data in DB
150 } elsif ($op eq 'add_validate') {
151 $template->param(tagfield => "$input->param('tagfield')");
152 my @tagsubfield = $input->multi_param('tagsubfield');
153 my @liblibrarian = $input->multi_param('liblibrarian');
154 my @libopac = $input->multi_param('libopac');
155 my @kohafield = ''.$input->param('kohafield');
156 my @tab = $input->multi_param('tab');
157 my @seealso = $input->multi_param('seealso');
158 my @ohidden = $input->multi_param('ohidden');
159 my @authorised_value_categories = $input->multi_param('authorised_value');
160 my $authtypecode = $input->param('authtypecode');
161 my @frameworkcodes = $input->multi_param('frameworkcode');
162 my @value_builder =$input->multi_param('value_builder');
163 my @defaultvalue = $input->multi_param('defaultvalue');
166 for (my $i=0; $i<= $#tagsubfield ; $i++) {
167 my $tagfield =$input->param('tagfield');
168 my $tagsubfield =$tagsubfield[$i];
169 $tagsubfield="@" unless $tagsubfield ne '';
170 my $liblibrarian =$liblibrarian[$i];
171 my $libopac =$libopac[$i];
172 my $repeatable =$input->param("repeatable$i")?1:0;
173 my $mandatory =$input->param("mandatory$i")?1:0;
174 my $kohafield =$kohafield[$i];
176 my $seealso =$seealso[$i];
177 my $authorised_value = $authorised_value_categories[$i];
178 my $frameworkcode =$frameworkcodes[$i];
179 my $value_builder=$value_builder[$i];
180 my $defaultvalue = $defaultvalue[$i];
181 my $hidden = $ohidden[$i]; #collate from 3 hiddens;
182 my $isurl = $input->param("isurl$i")?1:0;
184 my $ass = Koha::Authority::Subfields->find(
186 authtypecode => $authtypecode,
187 tagfield => $tagfield,
188 tagsubfield => $tagsubfield
192 liblibrarian => $liblibrarian,
194 repeatable => $repeatable,
195 mandatory => $mandatory,
196 kohafield => $kohafield,
199 authorised_value => $authorised_value,
200 frameworkcode => $frameworkcode,
201 value_builder => $value_builder,
204 defaultvalue => $defaultvalue,
205 display_order => $display_order->{$tagfield} || 0,
209 $ass->update($attributes);
212 Koha::Authority::Subfield->new(
214 authtypecode => $authtypecode,
215 tagfield => $tagfield,
216 tagsubfield => $tagsubfield,
221 $display_order->{$tagfield}++;
224 print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode");
227 # END $OP eq ADD_VALIDATE
228 ################## DELETE_CONFIRM ##################################
229 # called by default form, used to confirm deletion of data in DB
231 elsif ( $op eq 'delete_confirm' ) {
232 my $ass = Koha::Authority::Subfields->find(
234 authtypecode => $authtypecode,
235 tagfield => $tagfield,
236 tagsubfield => $tagsubfield
241 delete_link => $script_name,
244 elsif ( $op eq 'delete_confirmed' ) {
245 Koha::Authority::Subfields->find(
247 authtypecode => $authtypecode,
248 tagfield => $tagfield,
249 tagsubfield => $tagsubfield
252 print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode");
256 my $ass = Koha::Authority::Subfields->search(
258 tagfield => { -like => "$tagfield%" },
259 authtypecode => $authtypecode,
261 { order_by => [ 'tagfield', 'display_order' ] }
264 $template->param( loop => $ass );
266 edit_tagfield => $tagfield,
267 edit_authtypecode => $authtypecode,
270 } #---- END $OP eq DEFAULT
271 output_html_with_http_headers $input, $cookie, $template->output;