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 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 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 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 $template->param(action => "Edit subfields",
99 tagfield => "<input type=hidden name=tagfield value='$tagfield'>$tagfield",
103 while ($data =$sth->fetchrow_hashref) {
104 my %row_data; # get a fresh hash for the row data
105 if ($toggle eq 'white'){
110 $row_data{tab} = CGI::scrolling_list(-name=>'tab[]',
111 -values=>['','0','1','2','3','4','5','6','7','8','9','10'],
112 -labels => {'' =>'','0'=>'0','1'=>'1',
113 '2' =>'2','3'=>'3','4'=>'4',
114 '5' =>'5','6'=>'6','7'=>'7',
115 '8' =>'8','9'=>'9','10'=>'items (10)',
117 -default=>$data->{'tab'},
121 $row_data{tagsubfield} =$data->{'tagsubfield'}."<input type='hidden' name='tagsubfield[]' value='".$data->{'tagsubfield'}."'>";
122 $row_data{liblibrarian} = $data->{'liblibrarian'};
123 $row_data{libopac} = $data->{'libopac'};
124 $row_data{kohafield}= CGI::scrolling_list( -name=>'kohafield[]',
125 -values=> \@kohafields,
126 -default=> "$data->{'kohafield'}",
130 # $row_data{kohafield} = $data->{'kohafield'};
131 $row_data{repeatable} = CGI::checkbox('repeatable[]',$data->{'repeatable'}?'checked':'',1,'');
132 $row_data{mandatory} = CGI::checkbox('mandatory[]',$data->{'mandatory'}?'checked':'',1,'');
133 $row_data{bgcolor} = $toggle;
134 push(@loop_data, \%row_data);
136 # add an empty line for add if needed
137 my %row_data; # get a fresh hash for the row data
138 $row_data{tab} = CGI::scrolling_list(-name=>'tab[]',
139 -values=>['','0','1','2','3','4','5','6','7','8','9','items (10)'],
144 $row_data{tagsubfield} = "<input type='text' name='tagsubfield[]' value='".$data->{'tagsubfield'}."' size=3 maxlength=1>";
145 $row_data{liblibrarian} = "";
146 $row_data{libopac} = "";
147 $row_data{repeatable} = CGI::checkbox('repeatable[]','',1,'');
148 $row_data{mandatory} = CGI::checkbox('mandatory[]','',1,'');
149 $row_data{kohafield}= CGI::scrolling_list( -name=>'kohafield[]',
150 -values=> \@kohafields,
155 $row_data{bgcolor} = $toggle;
156 push(@loop_data, \%row_data);
158 $template->param(loop => \@loop_data);
160 # END $OP eq ADD_FORM
161 ################## ADD_VALIDATE ##################################
162 # called by add_form, used to insert/modify data in DB
163 } elsif ($op eq 'add_validate') {
164 my $dbh = C4::Context->dbh;
165 $template->param(tagfield => "$input->param('tagfield')");
166 my $sth=$dbh->prepare("replace marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab)
167 values (?,?,?,?,?,?,?,?)");
168 my @tagsubfield = $input->param('tagsubfield[]');
169 my @liblibrarian = $input->param('liblibrarian[]');
170 my @libopac = $input->param('libopac[]');
171 my @repeatable = $input->param('repeatable[]');
172 my @mandatory = $input->param('mandatory[]');
173 my @kohafield = $input->param('kohafield[]');
174 my @tab = $input->param('tab[]');
175 for (my $i=0; $i<= $#tagsubfield ; $i++) {
176 my $tagfield =$input->param('tagfield');
177 my $tagsubfield =$tagsubfield[$i];
178 my $liblibrarian =$liblibrarian[$i];
179 my $libopac =$libopac[$i];
180 my $repeatable =$repeatable[$i]?1:0;
181 my $mandatory =$mandatory[$i]?1:0;
182 my $kohafield =$kohafield[$i];
185 $sth->execute ($tagfield,
196 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marc_subfields_structure.pl?tagfield=$tagfield\"></html>";
199 # END $OP eq ADD_VALIDATE
200 ################## DELETE_CONFIRM ##################################
201 # called by default form, used to confirm deletion of data in DB
202 } elsif ($op eq 'delete_confirm') {
203 my $dbh = C4::Context->dbh;
204 my $sth=$dbh->prepare($reqsel);
206 my $data=$sth->fetchrow_hashref;
208 $template->param(liblibrarian => $data->{'liblibrarian'},
209 tagsubfield => $tagsubfield,
210 delete_link => $script_name,
211 tagfield =>$tagfield,
212 tagsubfield => $tagsubfield,
214 # END $OP eq DELETE_CONFIRM
215 ################## DELETE_CONFIRMED ##################################
216 # called by delete_confirm, used to effectively confirm deletion of data in DB
217 } elsif ($op eq 'delete_confirmed') {
218 my $dbh = C4::Context->dbh;
219 my $sth=$dbh->prepare($reqdel);
222 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marc_subfields_structure.pl?tagfield=$tagfield\"></html>";
224 $template->param(tagfield => $tagfield);
225 # END $OP eq DELETE_CONFIRMED
226 ################## DEFAULT ##################################
229 my ($count,$results)=StringSearch($env,$tagfield,'web');
232 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
233 if ($toggle eq 'white'){
238 my %row_data; # get a fresh hash for the row data
239 $row_data{tagfield} = $results->[$i]{'tagfield'};
240 $row_data{tagsubfield} = $results->[$i]{'tagsubfield'};
241 $row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
242 $row_data{kohafield} = $results->[$i]{'kohafield'};
243 $row_data{repeatable} = $results->[$i]{'repeatable'};
244 $row_data{mandatory} = $results->[$i]{'mandatory'};
245 $row_data{tab} = $results->[$i]{'tab'};
246 $row_data{delete} = "$script_name?op=delete_confirm&tagfield=$tagfield&tagsubfield=".$results->[$i]{'tagsubfield'};
247 $row_data{bgcolor} = $toggle;
248 push(@loop_data, \%row_data);
250 $template->param(loop => \@loop_data);
251 $template->param(edit => "<a href='$script_name?op=add_form&tagfield=$tagfield'>Edit</a>");
253 my $prevpage = $offset-$pagesize;
254 $template->param(prev =>"<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
256 if ($offset+$pagesize<$count) {
257 my $nextpage =$offset+$pagesize;
258 $template->param(next => "<a href=$script_name?offset=".$nextpage.'Next >></a>');
260 } #---- END $OP eq DEFAULT
262 print "Content-Type: text/html\n\n", $template->output;