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
30 my ($env,$searchstring,$type)=@_;
31 my $dbh = C4::Context->dbh;
32 $searchstring=~ s/\'/\\\'/g;
33 my @data=split(' ',$searchstring);
35 my $query="Select tagfield,liblibrarian,libopac,repeatable,mandatory from marc_tag_structure where (tagfield like \"$data[0]%\") order by tagfield";
36 my $sth=$dbh->prepare($query);
40 while (my $data=$sth->fetchrow_hashref){
46 return ($cnt,\@results);
50 my $searchfield=$input->param('searchfield');
51 my $pkfield="tagfield";
52 my $reqsel="select tagfield,liblibrarian,libopac,repeatable,mandatory from marc_tag_structure where $pkfield='$searchfield'";
53 my $reqdel="delete 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 $template = gettemplate("parameters/marctagstructure.tmpl",0);
59 my $op = $input->param('op');
60 $searchfield=~ s/\,//g;
63 $template->param(script_name => $script_name,
64 $op => 1); # we show only the TMPL_VAR names $op
66 $template->param(script_name => $script_name,
67 else => 1); # we show only the TMPL_VAR names $op
70 ################## ADD_FORM ##################################
71 # called by default. Used to create form to add or modify a record
72 if ($op eq 'add_form') {
73 #---- if primkey exists, it's a modify action, so read values to modify...
76 my $dbh = C4::Context->dbh;
77 my $sth=$dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory from marc_tag_structure where $pkfield='$searchfield'");
79 $data=$sth->fetchrow_hashref;
83 $template->param(action => "Modify tag",
84 searchfield => "<input type=hidden name=tagfield value='$searchfield'>$searchfield");
86 $template->param(action => "Add tag",
87 searchfield => "<input type=text name=tagfield size=5 maxlength=3>");
89 $template->param(liblibrarian => $data->{'liblibrarian'},
90 libopac => $data->{'libopac'},
91 repeatable => $data->{'repeatable'},
92 mandatory => $data->{'mandatory'},
95 ################## ADD_VALIDATE ##################################
96 # called by add_form, used to insert/modify data in DB
97 } elsif ($op eq 'add_validate') {
98 my $dbh = C4::Context->dbh;
99 my $sth=$dbh->prepare("replace marc_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory) values (?,?,?,?,?)");
100 my $tagfield =$input->param('tagfield');
101 my $liblibrarian = $input->param('liblibrarian');
102 my $libopac =$input->param('libopac');
103 my $repeatable =$input->param('repeatable');
104 my $mandatory =$input->param('mandatory');
105 $sth->execute($tagfield,
112 # END $OP eq ADD_VALIDATE
113 ################## DELETE_CONFIRM ##################################
114 # called by default form, used to confirm deletion of data in DB
115 } elsif ($op eq 'delete_confirm') {
116 my $dbh = C4::Context->dbh;
117 my $sth=$dbh->prepare($reqsel);
119 my $data=$sth->fetchrow_hashref;
121 $template->param(liblibrarian => $data->{'liblibrarian'},
122 searchfield => $searchfield,
124 # END $OP eq DELETE_CONFIRM
125 ################## DELETE_CONFIRMED ##################################
126 # called by delete_confirm, used to effectively confirm deletion of data in DB
127 } elsif ($op eq 'delete_confirmed') {
128 my $dbh = C4::Context->dbh;
129 my $sth=$dbh->prepare($reqdel);
132 # END $OP eq DELETE_CONFIRMED
133 ################## DEFAULT ##################################
135 if ($searchfield ne '') {
136 $template->param(searchfield => "You Searched for <b>$searchfield<b><p>");
139 my ($count,$results)=StringSearch($env,$searchfield,'web');
142 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
143 if ($toggle eq 'white'){
148 my %row_data; # get a fresh hash for the row data
149 $row_data{tagfield} = $results->[$i]{'tagfield'};
150 $row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
151 $row_data{subfield_link} ="marc_subfields_structure.pl?tagfield=".$results->[$i]{'tagfield'};
152 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'tagfield'};
153 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'tagfield'};
154 $row_data{bgcolor} = $toggle;
155 push(@loop_data, \%row_data);
157 $template->param(loop => \@loop_data);
159 my $prevpage = $offset-$pagesize;
160 $template->param(previous => "<a href=$script_name?offset=".$prevpage.'><< Prev</a>');
162 if ($offset+$pagesize<$count) {
163 my $nextpage =$offset+$pagesize;
164 $template->param(next => "<a href=$script_name?offset=".$nextpage.'>Next >></a>');
166 } #---- END $OP eq DEFAULT
168 print "Content-Type: text/html\n\n", $template->output;