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 like \"$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 my $pkfield="tagfield";
53 my $reqsel="select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where $pkfield='$searchfield'";
54 my $offset=$input->param('offset');
55 my $script_name="/cgi-bin/koha/admin/marctagstructure.pl";
57 my $dbh = C4::Context->dbh;
59 my ($template, $loggedinuser, $cookie)
60 = get_template_and_user({template_name => "parameters/marctagstructure.tmpl",
64 flagsrequired => {parameters => 1},
68 my $op = $input->param('op');
69 $searchfield=~ s/\,//g;
72 $template->param(script_name => $script_name,
73 $op => 1); # we show only the TMPL_VAR names $op
75 $template->param(script_name => $script_name,
76 else => 1); # we show only the TMPL_VAR names $op
79 ################## ADD_FORM ##################################
80 # called by default. Used to create form to add or modify a record
81 if ($op eq 'add_form') {
82 #---- if primkey exists, it's a modify action, so read values to modify...
85 my $sth=$dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where $pkfield='$searchfield'");
87 $data=$sth->fetchrow_hashref;
90 my $sth = $dbh->prepare("select distinct category from authorised_values");
92 my @authorised_values;
93 push @authorised_values,"";
94 while ((my $category) = $sth->fetchrow_array) {
95 push @authorised_values, $category;
97 my $authorised_value = CGI::scrolling_list(-name=>'authorised_value',
98 -values=> \@authorised_values,
101 -default => $data->{'authorised_value'},
105 $template->param(action => "Modify tag",
106 searchfield => "<input type=hidden name=tagfield value='$searchfield'>$searchfield");
108 $template->param(action => "Add tag",
109 searchfield => "<input type=text name=tagfield size=5 maxlength=3>");
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 $sth->execute($tagfield,
137 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marctagstructure.pl\"></html>";
139 # END $OP eq ADD_VALIDATE
140 ################## DELETE_CONFIRM ##################################
141 # called by default form, used to confirm deletion of data in DB
142 } elsif ($op eq 'delete_confirm') {
143 my $dbh = C4::Context->dbh;
144 my $sth=$dbh->prepare($reqsel);
146 my $data=$sth->fetchrow_hashref;
148 $template->param(liblibrarian => $data->{'liblibrarian'},
149 searchfield => $searchfield,
151 # END $OP eq DELETE_CONFIRM
152 ################## DELETE_CONFIRMED ##################################
153 # called by delete_confirm, used to effectively confirm deletion of data in DB
154 } elsif ($op eq 'delete_confirmed') {
155 my $dbh = C4::Context->dbh;
156 $dbh->do("delete from marc_tag_structure where $pkfield='$searchfield'");
157 $dbh->do("delete from marc_subfield_structure where tagfield='$searchfield'");
158 # END $OP eq DELETE_CONFIRMED
159 ################## DEFAULT ##################################
161 if ($searchfield ne '') {
162 $template->param(searchfield => "You Searched for <b>$searchfield<b><p>");
165 my ($count,$results)=StringSearch($env,$searchfield,'web');
168 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
169 if ($toggle eq 'white'){
174 my %row_data; # get a fresh hash for the row data
175 $row_data{tagfield} = $results->[$i]{'tagfield'};
176 $row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
177 $row_data{repeatable} = $results->[$i]{'repeatable'};
178 $row_data{mandatory} = $results->[$i]{'mandatory'};
179 $row_data{authorised_value} = $results->[$i]{'authorised_value'};
180 $row_data{subfield_link} ="marc_subfields_structure.pl?tagfield=".$results->[$i]{'tagfield'};
181 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'tagfield'};
182 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'tagfield'};
183 $row_data{bgcolor} = $toggle;
184 push(@loop_data, \%row_data);
186 $template->param(loop => \@loop_data);
188 my $prevpage = $offset-$pagesize;
189 $template->param(previous => "<a href=$script_name?offset=".$prevpage.'><< Prev</a>');
191 if ($offset+$pagesize<$count) {
192 my $nextpage =$offset+$pagesize;
193 $template->param(next => "<a href=$script_name?offset=".$nextpage.'>Next >></a>');
195 } #---- END $OP eq DEFAULT
197 $template->param(loggeninuser => $loggedinuser);
198 print $input->header(-cookie => $cookie), $template->output;