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' },
51 $template->param(script_name => $script_name,
53 authtypecode => $authtypecode,
54 $op => 1); # we show only the TMPL_VAR names $op
56 $template->param(script_name => $script_name,
58 authtypecode => $authtypecode,
59 else => 1); # we show only the TMPL_VAR names $op
62 my $dbh = C4::Context->dbh;
63 ################## ADD_FORM ##################################
64 # called by default. Used to create form to add or modify a record
65 if ($op eq 'add_form') {
66 # builds kohafield tables
69 my $sth2=$dbh->prepare("SHOW COLUMNS from auth_header");
71 while ((my $field) = $sth2->fetchrow_array) {
72 push @kohafields, "auth_header.".$field;
75 # build authorised value category list
76 my @authorised_value_categories = Koha::AuthorisedValues->new->categories;
77 unshift @authorised_value_categories, '';
78 push @authorised_value_categories, 'branches';
79 push @authorised_value_categories, 'itemtypes';
81 # build thesaurus categories list
82 my @authtypes = uniq( "", map { $_->authtypecode } Koha::Authority::Types->search );
84 # build value_builder list
85 my @value_builder=('');
87 # read value_builder directory.
88 # 2 cases here : on CVS install, $cgidir does not need a /cgi-bin
89 # on a standard install, /cgi-bin need to be added.
90 # test one, then the other
91 my $cgidir = C4::Context->config('intranetdir') ."/cgi-bin";
92 unless (opendir(DIR, "$cgidir/cataloguing/value_builder")) {
93 $cgidir = C4::Context->config('intranetdir');
94 opendir(DIR, "$cgidir/cataloguing/value_builder") || die "can't opendir $cgidir/value_builder: $!";
96 while (my $line = readdir(DIR)) {
97 if ( $line =~ /\.pl$/ &&
98 $line !~ /EXAMPLE\.pl$/ ) { # documentation purposes
99 push (@value_builder,$line);
102 @value_builder= sort {$a cmp $b} @value_builder;
106 my $asses = Koha::Authority::Subfields->search({ tagfield => $tagfield, authtypecode => $authtypecode}, {order_by => 'display_order'})->unblessed;
108 for my $ass ( @$asses ) {
109 my %row_data = %$ass;
110 $row_data{kohafields} = \@kohafields;
111 $row_data{authorised_values} = \@authorised_value_categories;
112 $row_data{frameworkcodes} = \@authtypes;
113 $row_data{value_builders} = \@value_builder;
114 $row_data{row} = $i++;
115 push( @loop_data, \%row_data );
118 # Add a new row for the "New" tab
119 my %row_data; # get a fresh hash for the row data
120 $row_data{'new_subfield'} = 1;
121 $row_data{tab} = -1; # ignore
122 $row_data{ohidden} = 0; # show all
123 $row_data{tagsubfield} = "";
124 $row_data{liblibrarian} = "";
125 $row_data{libopac} = "";
126 $row_data{seealso} = "";
127 $row_data{hidden} = "000";
128 $row_data{repeatable} = 0;
129 $row_data{mandatory} = 0;
130 $row_data{isurl} = 0;
131 $row_data{kohafields} = \@kohafields,
132 $row_data{authorised_values} = \@authorised_value_categories;
133 $row_data{frameworkcodes} = \@authtypes;
134 $row_data{value_builders} = \@value_builder;
136 push( @loop_data, \%row_data );
138 $template->param('use_heading_flags_p' => 1);
139 $template->param('heading_edit_subfields_p' => 1);
140 $template->param(action => "Edit subfields",
141 tagfield => $tagfield,
142 tagfieldinput => "<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\" />",
144 more_tag => $tagfield);
146 # END $OP eq ADD_FORM
147 ################## ADD_VALIDATE ##################################
148 # called by add_form, used to insert/modify data in DB
149 } elsif ($op eq 'add_validate') {
150 $template->param(tagfield => "$input->param('tagfield')");
151 my @tagsubfield = $input->multi_param('tagsubfield');
152 my @liblibrarian = $input->multi_param('liblibrarian');
153 my @libopac = $input->multi_param('libopac');
154 my @kohafield = ''.$input->param('kohafield');
155 my @tab = $input->multi_param('tab');
156 my @seealso = $input->multi_param('seealso');
157 my @ohidden = $input->multi_param('ohidden');
158 my @authorised_value_categories = $input->multi_param('authorised_value');
159 my $authtypecode = $input->param('authtypecode');
160 my @frameworkcodes = $input->multi_param('frameworkcode');
161 my @value_builder =$input->multi_param('value_builder');
162 my @defaultvalue = $input->multi_param('defaultvalue');
165 for (my $i=0; $i<= $#tagsubfield ; $i++) {
166 my $tagfield =$input->param('tagfield');
167 my $tagsubfield =$tagsubfield[$i];
168 $tagsubfield="@" unless $tagsubfield ne '';
169 my $liblibrarian =$liblibrarian[$i];
170 my $libopac =$libopac[$i];
171 my $repeatable =$input->param("repeatable$i")?1:0;
172 my $mandatory =$input->param("mandatory$i")?1:0;
173 my $kohafield =$kohafield[$i];
175 my $seealso =$seealso[$i];
176 my $authorised_value = $authorised_value_categories[$i];
177 my $frameworkcode =$frameworkcodes[$i];
178 my $value_builder=$value_builder[$i];
179 my $defaultvalue = $defaultvalue[$i];
180 my $hidden = $ohidden[$i]; #collate from 3 hiddens;
181 my $isurl = $input->param("isurl$i")?1:0;
183 my $ass = Koha::Authority::Subfields->find(
185 authtypecode => $authtypecode,
186 tagfield => $tagfield,
187 tagsubfield => $tagsubfield
191 liblibrarian => $liblibrarian,
193 repeatable => $repeatable,
194 mandatory => $mandatory,
195 kohafield => $kohafield,
198 authorised_value => $authorised_value,
199 frameworkcode => $frameworkcode,
200 value_builder => $value_builder,
203 defaultvalue => $defaultvalue,
204 display_order => $display_order->{$tagfield} || 0,
208 $ass->update($attributes);
211 Koha::Authority::Subfield->new(
213 authtypecode => $authtypecode,
214 tagfield => $tagfield,
215 tagsubfield => $tagsubfield,
220 $display_order->{$tagfield}++;
223 print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode");
226 # END $OP eq ADD_VALIDATE
227 ################## DELETE_CONFIRM ##################################
228 # called by default form, used to confirm deletion of data in DB
230 elsif ( $op eq 'delete_confirm' ) {
231 my $ass = Koha::Authority::Subfields->find(
233 authtypecode => $authtypecode,
234 tagfield => $tagfield,
235 tagsubfield => $tagsubfield
240 delete_link => $script_name,
243 elsif ( $op eq 'delete_confirmed' ) {
244 Koha::Authority::Subfields->find(
246 authtypecode => $authtypecode,
247 tagfield => $tagfield,
248 tagsubfield => $tagsubfield
251 print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode");
255 my $ass = Koha::Authority::Subfields->search(
257 tagfield => { -like => "$tagfield%" },
258 authtypecode => $authtypecode,
260 { order_by => [ 'tagfield', 'display_order' ] }
263 $template->param( loop => $ass );
265 edit_tagfield => $tagfield,
266 edit_authtypecode => $authtypecode,
269 } #---- END $OP eq DEFAULT
270 output_html_with_http_headers $input, $cookie, $template->output;