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
31 my ($env,$searchstring,$type)=@_;
32 my $dbh = C4::Context->dbh;
33 $searchstring=~ s/\'/\\\'/g;
34 my @data=split(' ',$searchstring);
36 my $query="Select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where (tagfield >= $data[0]) order by tagfield";
37 my $sth=$dbh->prepare($query);
41 while (my $data=$sth->fetchrow_hashref){
47 return ($cnt,\@results);
51 my $searchfield=$input->param('searchfield');
52 $searchfield=0 unless $searchfield;
53 my $pkfield="tagfield";
54 my $reqsel="select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where $pkfield='$searchfield'";
55 my $offset=$input->param('offset');
56 my $script_name="/cgi-bin/koha/admin/marctagstructure.pl";
58 my $dbh = C4::Context->dbh;
60 my ($template, $loggedinuser, $cookie)
61 = get_template_and_user({template_name => "parameters/marctagstructure.tmpl",
65 flagsrequired => {parameters => 1},
69 my $op = $input->param('op');
70 $searchfield=~ s/\,//g;
73 $template->param(script_name => $script_name,
74 $op => 1); # we show only the TMPL_VAR names $op
76 $template->param(script_name => $script_name,
77 else => 1); # we show only the TMPL_VAR names $op
80 ################## ADD_FORM ##################################
81 # called by default. Used to create form to add or modify a record
82 if ($op eq 'add_form') {
83 #---- if primkey exists, it's a modify action, so read values to modify...
86 my $sth=$dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where $pkfield='$searchfield'");
88 $data=$sth->fetchrow_hashref;
91 my $sth = $dbh->prepare("select distinct category from authorised_values");
93 my @authorised_values;
94 push @authorised_values,"";
95 while ((my $category) = $sth->fetchrow_array) {
96 push @authorised_values, $category;
98 my $authorised_value = CGI::scrolling_list(-name=>'authorised_value',
99 -values=> \@authorised_values,
102 -default => $data->{'authorised_value'},
106 $template->param(action => "Modify tag",
107 searchfield => "<input type=hidden name=tagfield value='$searchfield'>$searchfield");
109 $template->param(action => "Add tag",
110 searchfield => "<input type=text name=tagfield size=5 maxlength=3>");
112 $template->param(liblibrarian => $data->{'liblibrarian'},
113 libopac => $data->{'libopac'},
114 repeatable => CGI::checkbox('repeatable',$data->{'repeatable'}?'checked':'',1,''),
115 mandatory => CGI::checkbox('mandatory',$data->{'mandatory'}?'checked':'',1,''),
116 authorised_value => $authorised_value,
118 # END $OP eq ADD_FORM
119 ################## ADD_VALIDATE ##################################
120 # called by add_form, used to insert/modify data in DB
121 } elsif ($op eq 'add_validate') {
122 my $dbh = C4::Context->dbh;
123 my $sth=$dbh->prepare("replace marc_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value) values (?,?,?,?,?,?)");
124 my $tagfield =$input->param('tagfield');
125 my $liblibrarian = $input->param('liblibrarian');
126 my $libopac =$input->param('libopac');
127 my $repeatable =$input->param('repeatable');
128 my $mandatory =$input->param('mandatory');
129 my $authorised_value =$input->param('authorised_value');
130 $sth->execute($tagfield,
138 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marctagstructure.pl?tagfield=$tagfield\"></html>";
140 # END $OP eq ADD_VALIDATE
141 ################## DELETE_CONFIRM ##################################
142 # called by default form, used to confirm deletion of data in DB
143 } elsif ($op eq 'delete_confirm') {
144 my $dbh = C4::Context->dbh;
145 my $sth=$dbh->prepare($reqsel);
147 my $data=$sth->fetchrow_hashref;
149 $template->param(liblibrarian => $data->{'liblibrarian'},
150 searchfield => $searchfield,
152 # END $OP eq DELETE_CONFIRM
153 ################## DELETE_CONFIRMED ##################################
154 # called by delete_confirm, used to effectively confirm deletion of data in DB
155 } elsif ($op eq 'delete_confirmed') {
156 my $dbh = C4::Context->dbh;
157 $dbh->do("delete from marc_tag_structure where $pkfield='$searchfield'");
158 $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 => "You Searched for <b>$searchfield<b><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(previous => "<a href=$script_name?offset=".$prevpage.'><< Prev</a>');
192 if ($offset+$pagesize<$count) {
193 my $nextpage =$offset+$pagesize;
194 $template->param(next => "<a href=$script_name?offset=".$nextpage.'>Next >></a>');
196 } #---- END $OP eq DEFAULT
198 $template->param(loggeninuser => $loggedinuser);
199 print $input->header(-cookie => $cookie), $template->output;