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");
104 $template->param('heading-modify-tag-p' => 1);
106 $template->param(action => "Add tag",
107 searchfield => "<input type=\"text\" name=\"tagfield\" size=\"5\" maxlength=\"3\" />");
108 $template->param('heading-add-tag-p' => 1);
110 $template->param('use-heading-flags-p' => 1);
111 $template->param(liblibrarian => $data->{'liblibrarian'},
112 libopac => $data->{'libopac'},
113 repeatable => CGI::checkbox('repeatable',$data->{'repeatable'}?'checked':'',1,''),
114 mandatory => CGI::checkbox('mandatory',$data->{'mandatory'}?'checked':'',1,''),
115 authorised_value => $authorised_value,
117 # END $OP eq ADD_FORM
118 ################## ADD_VALIDATE ##################################
119 # called by add_form, used to insert/modify data in DB
120 } elsif ($op eq 'add_validate') {
121 my $dbh = C4::Context->dbh;
122 my $sth=$dbh->prepare("replace marc_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value) values (?,?,?,?,?,?)");
123 my $tagfield =$input->param('tagfield');
124 my $liblibrarian = $input->param('liblibrarian');
125 my $libopac =$input->param('libopac');
126 my $repeatable =$input->param('repeatable');
127 my $mandatory =$input->param('mandatory');
128 my $authorised_value =$input->param('authorised_value');
129 unless (C4::Context->config('demo') eq 1) {
130 $sth->execute($tagfield,
139 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marctagstructure.pl?tagfield=$tagfield\"></html>";
141 # END $OP eq ADD_VALIDATE
142 ################## DELETE_CONFIRM ##################################
143 # called by default form, used to confirm deletion of data in DB
144 } elsif ($op eq 'delete_confirm') {
145 my $dbh = C4::Context->dbh;
146 my $sth=$dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where tagfield=?");
147 $sth->execute($searchfield);
148 my $data=$sth->fetchrow_hashref;
150 $template->param(liblibrarian => $data->{'liblibrarian'},
151 searchfield => $searchfield,
153 # END $OP eq DELETE_CONFIRM
154 ################## DELETE_CONFIRMED ##################################
155 # called by delete_confirm, used to effectively confirm deletion of data in DB
156 } elsif ($op eq 'delete_confirmed') {
157 my $dbh = C4::Context->dbh;
158 unless (C4::Context->config('demo') eq 1) {
159 $dbh->do("delete from marc_tag_structure where tagfield='$searchfield'");
160 $dbh->do("delete from marc_subfield_structure where tagfield='$searchfield'");
162 # END $OP eq DELETE_CONFIRMED
163 ################## DEFAULT ##################################
165 if ($searchfield ne '') {
166 $template->param(searchfield => "<p>You Searched for <strong>$searchfield<strong></p>");
169 my ($count,$results)=StringSearch($env,$searchfield,'web');
172 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
173 if ($toggle eq 'white'){
178 my %row_data; # get a fresh hash for the row data
179 $row_data{tagfield} = $results->[$i]{'tagfield'};
180 $row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
181 $row_data{repeatable} = $results->[$i]{'repeatable'};
182 $row_data{mandatory} = $results->[$i]{'mandatory'};
183 $row_data{authorised_value} = $results->[$i]{'authorised_value'};
184 $row_data{subfield_link} ="marc_subfields_structure.pl?tagfield=".$results->[$i]{'tagfield'};
185 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'tagfield'};
186 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'tagfield'};
187 $row_data{bgcolor} = $toggle;
188 push(@loop_data, \%row_data);
190 $template->param(loop => \@loop_data);
192 my $prevpage = $offset-$pagesize;
193 $template->param(isprevpage => $offset,
194 prevpage=> $prevpage,
195 searchfield => $searchfield,
196 script_name => $script_name,
199 if ($offset+$pagesize<$count) {
200 my $nextpage =$offset+$pagesize;
201 $template->param(nextpage =>$nextpage,
202 searchfield => $searchfield,
203 script_name => $script_name,
206 } #---- END $OP eq DEFAULT
208 $template->param(loggeninuser => $loggedinuser);
209 output_html_with_http_headers $input, $cookie, $template->output;