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
29 my ($env,$searchstring,$type)=@_;
30 my $dbh = C4::Context->dbh;
31 $searchstring=~ s/\'/\\\'/g;
32 my @data=split(' ',$searchstring);
34 my $query="Select tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab, authorised_value from marc_subfield_structure where (tagfield like \"$searchstring%\") order by tagfield";
35 my $sth=$dbh->prepare($query);
39 while (my $data=$sth->fetchrow_hashref){
46 return ($cnt,\@results);
50 my $tagfield=$input->param('tagfield');
51 my $tagsubfield=$input->param('tagsubfield');
52 my $pkfield="tagfield";
53 my $reqsel="select tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,authorised_value from marc_subfield_structure where tagfield='$tagfield'";
54 my $reqdel="delete from marc_subfield_structure where tagfield='$tagfield' and tagsubfield='$tagsubfield'";
55 my $offset=$input->param('offset');
56 my $script_name="/cgi-bin/koha/admin/marc_subfields_structure.pl";
58 my $template = gettemplate("parameters/marc_subfields_structure.tmpl",0);
60 my $op = $input->param('op');
64 $template->param(script_name => $script_name,
66 $op => 1); # we show only the TMPL_VAR names $op
68 $template->param(script_name => $script_name,
70 else => 1); # we show only the TMPL_VAR names $op
73 ################## ADD_FORM ##################################
74 # called by default. Used to create form to add or modify a record
75 if ($op eq 'add_form') {
77 my $dbh = C4::Context->dbh;
78 my $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,authorised_value from marc_subfield_structure where tagfield='$tagfield'"); # and tagsubfield='$tagsubfield'");
80 # builds kohafield tables
83 my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
85 while ((my $field) = $sth2->fetchrow_array) {
86 push @kohafields, "biblio.".$field;
88 my $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
90 while ((my $field) = $sth2->fetchrow_array) {
91 push @kohafields, "biblioitems.".$field;
93 my $sth2=$dbh->prepare("SHOW COLUMNS from items");
95 while ((my $field) = $sth2->fetchrow_array) {
96 push @kohafields, "items.".$field;
98 # buiild authorised value list
100 $sth2 = $dbh->prepare("select distinct category from authorised_values");
102 my @authorised_values;
103 push @authorised_values,"";
104 while ((my $category) = $sth2->fetchrow_array) {
105 push @authorised_values, $category;
107 $template->param(action => "Edit subfields",
108 tagfield => "<input type=hidden name=tagfield value='$tagfield'>$tagfield",
113 while ($data =$sth->fetchrow_hashref) {
114 my %row_data; # get a fresh hash for the row data
115 if ($toggle eq 'white'){
120 $row_data{tab} = CGI::scrolling_list(-name=>'tab',
121 -values=>['-1','0','1','2','3','4','5','6','7','8','9','10'],
122 -labels => {'-1' =>'ignore','0'=>'0','1'=>'1',
123 '2' =>'2','3'=>'3','4'=>'4',
124 '5' =>'5','6'=>'6','7'=>'7',
125 '8' =>'8','9'=>'9','10'=>'items (10)',
127 -default=>$data->{'tab'},
131 $row_data{tagsubfield} =$data->{'tagsubfield'}."<input type='hidden' name='tagsubfield' value='".$data->{'tagsubfield'}."'>";
132 $row_data{liblibrarian} = $data->{'liblibrarian'};
133 $row_data{libopac} = $data->{'libopac'};
134 $row_data{kohafield}= CGI::scrolling_list( -name=>"kohafield",
135 -values=> \@kohafields,
136 -default=> "$data->{'kohafield'}",
140 $row_data{authorised_value} = CGI::scrolling_list(-name=>'authorised_value',
141 -values=> \@authorised_values,
142 -default=>$data->{'authorised_value'},
146 # $row_data{kohafield} = $data->{'kohafield'};
147 $row_data{repeatable} = CGI::checkbox("repeatable$i",$data->{'repeatable'}?'checked':'',1,'');
148 $row_data{mandatory} = CGI::checkbox("mandatory$i",$data->{'mandatory'}?'checked':'',1,'');
149 $row_data{bgcolor} = $toggle;
150 push(@loop_data, \%row_data);
153 # add an empty line for add if needed
154 my %row_data; # get a fresh hash for the row data
155 $row_data{tab} = CGI::scrolling_list(-name=>'tab',
156 -values=>['-1','0','1','2','3','4','5','6','7','8','9','10'],
157 -labels => {'-1' =>'ignore','0'=>'0','1'=>'1',
158 '2' =>'2','3'=>'3','4'=>'4',
159 '5' =>'5','6'=>'6','7'=>'7',
160 '8' =>'8','9'=>'9','10'=>'items (10)',
166 $row_data{tagsubfield} = "<input type='text' name='tagsubfield' value='".$data->{'tagsubfield'}."' size=3 maxlength=1>";
167 $row_data{liblibrarian} = "";
168 $row_data{libopac} = "";
169 $row_data{repeatable} = CGI::checkbox('repeatable','',1,'');
170 $row_data{mandatory} = CGI::checkbox('mandatory','',1,'');
171 $row_data{kohafield}= CGI::scrolling_list( -name=>'kohafield',
172 -values=> \@kohafields,
177 $row_data{authorised_value} = CGI::scrolling_list(-name=>'authorised_value',
178 -values=> \@authorised_values,
182 $row_data{bgcolor} = $toggle;
183 push(@loop_data, \%row_data);
185 $template->param(loop => \@loop_data);
187 # END $OP eq ADD_FORM
188 ################## ADD_VALIDATE ##################################
189 # called by add_form, used to insert/modify data in DB
190 } elsif ($op eq 'add_validate') {
191 my $dbh = C4::Context->dbh;
192 $template->param(tagfield => "$input->param('tagfield')");
193 my $sth=$dbh->prepare("replace marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,authorised_value)
194 values (?,?,?,?,?,?,?,?,?)");
195 my @tagsubfield = $input->param('tagsubfield');
196 my @liblibrarian = $input->param('liblibrarian');
197 my @libopac = $input->param('libopac');
198 my @kohafield = $input->param('kohafield');
199 my @tab = $input->param('tab');
200 my @authorised_values = $input->param('authorised_value');
201 for (my $i=0; $i<= $#tagsubfield ; $i++) {
202 my $tagfield =$input->param('tagfield');
203 my $tagsubfield =$tagsubfield[$i];
204 my $liblibrarian =$liblibrarian[$i];
205 my $libopac =$libopac[$i];
206 my $repeatable =$input->param("repeatable$i")?1:0;
207 my $mandatory =$input->param("mandatory$i")?1:0;
208 my $kohafield =$kohafield[$i];
210 my $authorised_value =$authorised_values[$i];
212 $sth->execute ($tagfield,
224 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marc_subfields_structure.pl?tagfield=$tagfield\"></html>";
227 # END $OP eq ADD_VALIDATE
228 ################## DELETE_CONFIRM ##################################
229 # called by default form, used to confirm deletion of data in DB
230 } elsif ($op eq 'delete_confirm') {
231 my $dbh = C4::Context->dbh;
232 my $sth=$dbh->prepare($reqsel);
234 my $data=$sth->fetchrow_hashref;
236 $template->param(liblibrarian => $data->{'liblibrarian'},
237 tagsubfield => $tagsubfield,
238 delete_link => $script_name,
239 tagfield =>$tagfield,
240 tagsubfield => $tagsubfield,
242 # END $OP eq DELETE_CONFIRM
243 ################## DELETE_CONFIRMED ##################################
244 # called by delete_confirm, used to effectively confirm deletion of data in DB
245 } elsif ($op eq 'delete_confirmed') {
246 my $dbh = C4::Context->dbh;
247 my $sth=$dbh->prepare($reqdel);
250 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marc_subfields_structure.pl?tagfield=$tagfield\"></html>";
252 $template->param(tagfield => $tagfield);
253 # END $OP eq DELETE_CONFIRMED
254 ################## DEFAULT ##################################
257 my ($count,$results)=StringSearch($env,$tagfield,'web');
260 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
261 if ($toggle eq 'white'){
266 my %row_data; # get a fresh hash for the row data
267 $row_data{tagfield} = $results->[$i]{'tagfield'};
268 $row_data{tagsubfield} = $results->[$i]{'tagsubfield'};
269 $row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
270 $row_data{kohafield} = $results->[$i]{'kohafield'};
271 $row_data{repeatable} = $results->[$i]{'repeatable'};
272 $row_data{mandatory} = $results->[$i]{'mandatory'};
273 $row_data{tab} = $results->[$i]{'tab'};
274 $row_data{authorised_value} = $results->[$i]{'authorised_value'};
275 $row_data{delete} = "$script_name?op=delete_confirm&tagfield=$tagfield&tagsubfield=".$results->[$i]{'tagsubfield'};
276 $row_data{bgcolor} = $toggle;
277 push(@loop_data, \%row_data);
279 $template->param(loop => \@loop_data);
280 $template->param(edit => "<a href='$script_name?op=add_form&tagfield=$tagfield'>Edit</a>");
282 my $prevpage = $offset-$pagesize;
283 $template->param(prev =>"<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
285 if ($offset+$pagesize<$count) {
286 my $nextpage =$offset+$pagesize;
287 $template->param(next => "<a href=$script_name?offset=".$nextpage.'Next >></a>');
289 } #---- END $OP eq DEFAULT
291 print "Content-Type: text/html\n\n", $template->output;