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','items'],
112 -default=>$data->{'tab'},
116 $row_data{tagsubfield} =$data->{'tagsubfield'}."<input type='hidden' name='tagsubfield[]' value='".$data->{'tagsubfield'}."'>";
117 $row_data{liblibrarian} = $data->{'liblibrarian'};
118 $row_data{libopac} = $data->{'libopac'};
119 $row_data{kohafield}= CGI::scrolling_list( -name=>'kohafield[]',
120 -values=> \@kohafields,
121 -default=> "$data->{'kohafield'}",
125 # $row_data{kohafield} = $data->{'kohafield'};
126 $row_data{repeatable} = CGI::checkbox('repeatable[]',$data->{'repeatable'}?'checked':'',1,'');
127 $row_data{mandatory} = CGI::checkbox('mandatory[]',$data->{'mandatory'}?'checked':'',1,'');
128 $row_data{bgcolor} = $toggle;
129 push(@loop_data, \%row_data);
131 # add an empty line for add if needed
132 my %row_data; # get a fresh hash for the row data
133 $row_data{tab} = CGI::scrolling_list(-name=>'tab[]',
134 -values=>['','0','1','2','3','4','5','6','7','8','9','items'],
139 $row_data{tagsubfield} = "<input type='text' name='tagsubfield[]' value='".$data->{'tagsubfield'}."' size=3 maxlength=1>";
140 $row_data{liblibrarian} = "";
141 $row_data{libopac} = "";
142 $row_data{repeatable} = CGI::checkbox('repeatable[]','',1,'');
143 $row_data{mandatory} = CGI::checkbox('mandatory[]','',1,'');
144 $row_data{kohafield} = '';
145 $row_data{bgcolor} = $toggle;
146 push(@loop_data, \%row_data);
148 $template->param(loop => \@loop_data);
150 # END $OP eq ADD_FORM
151 ################## ADD_VALIDATE ##################################
152 # called by add_form, used to insert/modify data in DB
153 } elsif ($op eq 'add_validate') {
154 my $dbh = C4::Context->dbh;
155 $template->param(tagfield => "$input->param('tagfield')");
156 my $sth=$dbh->prepare("replace marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab)
157 values (?,?,?,?,?,?,?,?)");
158 my @tagsubfield = $input->param('tagsubfield[]');
159 my @liblibrarian = $input->param('liblibrarian[]');
160 my @libopac = $input->param('libopac[]');
161 my @repeatable = $input->param('repeatable[]');
162 my @mandatory = $input->param('mandatory[]');
163 my @kohafield = $input->param('kohafield[]');
164 my @tab = $input->param('tab[]');
165 warn "taille : $#tagsubfield";
166 for (my $i=0; $i<= $#tagsubfield ; $i++) {
167 my $tagfield =$input->param('tagfield');
168 my $tagsubfield =$tagsubfield[$i];
169 my $liblibrarian =$liblibrarian[$i];
170 my $libopac =$libopac[$i];
171 my $repeatable =$repeatable[$i]?1:0;
172 my $mandatory =$mandatory[$i]?1:0;
173 my $kohafield =$kohafield[$i];
176 $sth->execute ($tagfield,
187 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marctagstructure.pl\"></html>";
190 # END $OP eq ADD_VALIDATE
191 ################## DELETE_CONFIRM ##################################
192 # called by default form, used to confirm deletion of data in DB
193 } elsif ($op eq 'delete_confirm') {
194 my $dbh = C4::Context->dbh;
195 my $sth=$dbh->prepare($reqsel);
197 my $data=$sth->fetchrow_hashref;
199 $template->param(liblibrarian => $data->{'liblibrarian'},
200 tagsubfield => $tagsubfield,
202 # END $OP eq DELETE_CONFIRM
203 ################## DELETE_CONFIRMED ##################################
204 # called by delete_confirm, used to effectively confirm deletion of data in DB
205 } elsif ($op eq 'delete_confirmed') {
206 my $dbh = C4::Context->dbh;
207 my $sth=$dbh->prepare($reqdel);
210 # END $OP eq DELETE_CONFIRMED
211 ################## DEFAULT ##################################
214 my ($count,$results)=StringSearch($env,$tagfield,'web');
217 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
218 if ($toggle eq 'white'){
223 my %row_data; # get a fresh hash for the row data
224 $row_data{tagfield} = $results->[$i]{'tagfield'};
225 $row_data{tagsubfield} = $results->[$i]{'tagsubfield'};
226 $row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
227 $row_data{kohafield} = $results->[$i]{'kohafield'};
228 $row_data{repeatable} = $results->[$i]{'repeatable'};
229 $row_data{mandatory} = $results->[$i]{'mandatory'};
230 $row_data{tab} = $results->[$i]{'tab'};
231 $row_data{delete} = "$script_name?op=delete_confirm&tagfield=$tagfield&tagsubfield=".$results->[$i]{'tagfield'};
232 $row_data{bgcolor} = $toggle;
233 push(@loop_data, \%row_data);
235 $template->param(loop => \@loop_data);
236 $template->param(edit => "<a href='$script_name?op=add_form&tagfield=$tagfield'>Edit</a>");
238 my $prevpage = $offset-$pagesize;
239 $template->param(prev =>"<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
241 if ($offset+$pagesize<$count) {
242 my $nextpage =$offset+$pagesize;
243 $template->param(next => "a href=$script_name?offset=".$nextpage.'Next >></a>');
245 } #---- END $OP eq DEFAULT
247 print "Content-Type: text/html\n\n", $template->output;