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
26 use C4::Interface::CGI::Output;
32 my ($env,$searchstring,$type)=@_;
33 my $dbh = C4::Context->dbh;
34 $searchstring=~ s/\'/\\\'/g;
35 my @data=split(' ',$searchstring);
37 my $sth=$dbh->prepare("Select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where (tagfield >= ?) order by tagfield");
38 $sth->execute($data[0]);
40 while (my $data=$sth->fetchrow_hashref){
45 return (scalar(@results),\@results);
49 my $searchfield=$input->param('searchfield');
50 $searchfield=0 unless $searchfield;
51 my $offset=$input->param('offset');
52 my $script_name="/cgi-bin/koha/admin/marctagstructure.pl";
54 my $dbh = C4::Context->dbh;
56 my ($template, $loggedinuser, $cookie)
57 = get_template_and_user({template_name => "parameters/marctagstructure.tmpl",
61 flagsrequired => {parameters => 1},
65 my $op = $input->param('op');
66 $searchfield=~ s/\,//g;
69 $template->param(script_name => $script_name,
70 $op => 1); # we show only the TMPL_VAR names $op
72 $template->param(script_name => $script_name,
73 else => 1); # we show only the TMPL_VAR names $op
76 ################## ADD_FORM ##################################
77 # called by default. Used to create form to add or modify a record
78 if ($op eq 'add_form') {
79 #---- if primkey exists, it's a modify action, so read values to modify...
82 my $sth=$dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where tagfield=?");
83 $sth->execute($searchfield);
84 $data=$sth->fetchrow_hashref;
87 my $sth = $dbh->prepare("select distinct category from authorised_values");
89 my @authorised_values;
90 push @authorised_values,"";
91 while ((my $category) = $sth->fetchrow_array) {
92 push @authorised_values, $category;
94 my $authorised_value = CGI::scrolling_list(-name=>'authorised_value',
95 -values=> \@authorised_values,
98 -default => $data->{'authorised_value'},
102 $template->param(action => "Modify tag",
103 searchfield => "<input type=\"hidden\" name=\"tagfield\" value=\"$searchfield\" />$searchfield");
105 $template->param(action => "Add tag",
106 searchfield => "<input type=\"text\" name=\"tagfield\" size=\"5\" maxlength=\"3\" />");
108 $template->param(liblibrarian => $data->{'liblibrarian'},
109 libopac => $data->{'libopac'},
110 repeatable => CGI::checkbox('repeatable',$data->{'repeatable'}?'checked':'',1,''),
111 mandatory => CGI::checkbox('mandatory',$data->{'mandatory'}?'checked':'',1,''),
112 authorised_value => $authorised_value,
114 # END $OP eq ADD_FORM
115 ################## ADD_VALIDATE ##################################
116 # called by add_form, used to insert/modify data in DB
117 } elsif ($op eq 'add_validate') {
118 my $dbh = C4::Context->dbh;
119 my $sth=$dbh->prepare("replace marc_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value) values (?,?,?,?,?,?)");
120 my $tagfield =$input->param('tagfield');
121 my $liblibrarian = $input->param('liblibrarian');
122 my $libopac =$input->param('libopac');
123 my $repeatable =$input->param('repeatable');
124 my $mandatory =$input->param('mandatory');
125 my $authorised_value =$input->param('authorised_value');
126 unless (C4::Context->config('demo') eq 1) {
127 $sth->execute($tagfield,
136 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marctagstructure.pl?tagfield=$tagfield\"></html>";
138 # END $OP eq ADD_VALIDATE
139 ################## DELETE_CONFIRM ##################################
140 # called by default form, used to confirm deletion of data in DB
141 } elsif ($op eq 'delete_confirm') {
142 my $dbh = C4::Context->dbh;
143 my $sth=$dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where tagfield=?");
144 $sth->execute($searchfield);
145 my $data=$sth->fetchrow_hashref;
147 $template->param(liblibrarian => $data->{'liblibrarian'},
148 searchfield => $searchfield,
150 # END $OP eq DELETE_CONFIRM
151 ################## DELETE_CONFIRMED ##################################
152 # called by delete_confirm, used to effectively confirm deletion of data in DB
153 } elsif ($op eq 'delete_confirmed') {
154 my $dbh = C4::Context->dbh;
155 unless (C4::Context->config('demo') eq 1) {
156 $dbh->do("delete from marc_tag_structure where tagfield='$searchfield'");
157 $dbh->do("delete from marc_subfield_structure where tagfield='$searchfield'");
159 # END $OP eq DELETE_CONFIRMED
160 ################## DEFAULT ##################################
162 if ($searchfield ne '') {
163 $template->param(searchfield => "<p>You Searched for <strong>$searchfield<strong></p>");
166 my ($count,$results)=StringSearch($env,$searchfield,'web');
169 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
170 if ($toggle eq 'white'){
175 my %row_data; # get a fresh hash for the row data
176 $row_data{tagfield} = $results->[$i]{'tagfield'};
177 $row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
178 $row_data{repeatable} = $results->[$i]{'repeatable'};
179 $row_data{mandatory} = $results->[$i]{'mandatory'};
180 $row_data{authorised_value} = $results->[$i]{'authorised_value'};
181 $row_data{subfield_link} ="marc_subfields_structure.pl?tagfield=".$results->[$i]{'tagfield'};
182 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'tagfield'};
183 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'tagfield'};
184 $row_data{bgcolor} = $toggle;
185 push(@loop_data, \%row_data);
187 $template->param(loop => \@loop_data);
189 my $prevpage = $offset-$pagesize;
190 $template->param(isprevpage => $offset,
191 prevpage=> $prevpage,
192 searchfield => $searchfield,
193 script_name => $script_name,
196 if ($offset+$pagesize<$count) {
197 my $nextpage =$offset+$pagesize;
198 $template->param(nextpage =>$nextpage,
199 searchfield => $searchfield,
200 script_name => $script_name,
203 } #---- END $OP eq DEFAULT
205 $template->param(loggeninuser => $loggedinuser);
206 output_html_with_http_headers $input, $cookie, $template->output;