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 $query="Select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where (tagfield >= $data[0]) order by tagfield";
38 my $sth=$dbh->prepare($query);
42 while (my $data=$sth->fetchrow_hashref){
48 return ($cnt,\@results);
52 my $searchfield=$input->param('searchfield');
53 $searchfield=0 unless $searchfield;
54 my $pkfield="tagfield";
55 my $reqsel="select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where $pkfield='$searchfield'";
56 my $offset=$input->param('offset');
57 my $script_name="/cgi-bin/koha/admin/marctagstructure.pl";
59 my $dbh = C4::Context->dbh;
61 my ($template, $loggedinuser, $cookie)
62 = get_template_and_user({template_name => "parameters/marctagstructure.tmpl",
66 flagsrequired => {parameters => 1},
70 my $op = $input->param('op');
71 $searchfield=~ s/\,//g;
74 $template->param(script_name => $script_name,
75 $op => 1); # we show only the TMPL_VAR names $op
77 $template->param(script_name => $script_name,
78 else => 1); # we show only the TMPL_VAR names $op
81 ################## ADD_FORM ##################################
82 # called by default. Used to create form to add or modify a record
83 if ($op eq 'add_form') {
84 #---- if primkey exists, it's a modify action, so read values to modify...
87 my $sth=$dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where $pkfield='$searchfield'");
89 $data=$sth->fetchrow_hashref;
92 my $sth = $dbh->prepare("select distinct category from authorised_values");
94 my @authorised_values;
95 push @authorised_values,"";
96 while ((my $category) = $sth->fetchrow_array) {
97 push @authorised_values, $category;
99 my $authorised_value = CGI::scrolling_list(-name=>'authorised_value',
100 -values=> \@authorised_values,
103 -default => $data->{'authorised_value'},
107 $template->param(action => "Modify tag",
108 searchfield => "<input type=hidden name=tagfield value='$searchfield'>$searchfield");
110 $template->param(action => "Add tag",
111 searchfield => "<input type=text name=tagfield size=5 maxlength=3>");
113 $template->param(liblibrarian => $data->{'liblibrarian'},
114 libopac => $data->{'libopac'},
115 repeatable => CGI::checkbox('repeatable',$data->{'repeatable'}?'checked':'',1,''),
116 mandatory => CGI::checkbox('mandatory',$data->{'mandatory'}?'checked':'',1,''),
117 authorised_value => $authorised_value,
119 # END $OP eq ADD_FORM
120 ################## ADD_VALIDATE ##################################
121 # called by add_form, used to insert/modify data in DB
122 } elsif ($op eq 'add_validate') {
123 my $dbh = C4::Context->dbh;
124 my $sth=$dbh->prepare("replace marc_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value) values (?,?,?,?,?,?)");
125 my $tagfield =$input->param('tagfield');
126 my $liblibrarian = $input->param('liblibrarian');
127 my $libopac =$input->param('libopac');
128 my $repeatable =$input->param('repeatable');
129 my $mandatory =$input->param('mandatory');
130 my $authorised_value =$input->param('authorised_value');
131 $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($reqsel);
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 $dbh->do("delete from marc_tag_structure where $pkfield='$searchfield'");
159 $dbh->do("delete from marc_subfield_structure where tagfield='$searchfield'");
160 # END $OP eq DELETE_CONFIRMED
161 ################## DEFAULT ##################################
163 if ($searchfield ne '') {
164 $template->param(searchfield => "You Searched for <b>$searchfield<b><p>");
167 my ($count,$results)=StringSearch($env,$searchfield,'web');
170 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
171 if ($toggle eq 'white'){
176 my %row_data; # get a fresh hash for the row data
177 $row_data{tagfield} = $results->[$i]{'tagfield'};
178 $row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
179 $row_data{repeatable} = $results->[$i]{'repeatable'};
180 $row_data{mandatory} = $results->[$i]{'mandatory'};
181 $row_data{authorised_value} = $results->[$i]{'authorised_value'};
182 $row_data{subfield_link} ="marc_subfields_structure.pl?tagfield=".$results->[$i]{'tagfield'};
183 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'tagfield'};
184 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'tagfield'};
185 $row_data{bgcolor} = $toggle;
186 push(@loop_data, \%row_data);
188 $template->param(loop => \@loop_data);
190 my $prevpage = $offset-$pagesize;
191 $template->param(previous => "<a href=\"$script_name?offset=".$prevpage.'">');
193 if ($offset+$pagesize<$count) {
194 my $nextpage =$offset+$pagesize;
195 $template->param(next => "<a href=\"$script_name?offset=".$nextpage.'">');
197 } #---- END $OP eq DEFAULT
199 $template->param(loggeninuser => $loggedinuser);
200 output_html_with_http_headers $input, $cookie, $template->output;