3 #script to administer the systempref table
4 #written 20/02/2002 by paul.poulain@free.fr
5 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
8 # this script use an $op to know what to do.
9 # if $op is empty or none of the above values,
10 # - the default screen is build (with all records, or filtered datas).
11 # - the user can clic on add, modify or delete record.
13 # - if primkey exists, this is a modification,so we read the $primkey record
14 # - builds the add/modify form
16 # - the user has just send datas, so we create/modify the record
18 # - we show the record having primkey=$primkey and ask for deletion validation form
19 # if $op=delete_confirm
20 # - we delete the record having primkey=$primkey
23 # Copyright 2000-2002 Katipo Communications
25 # This file is part of Koha.
27 # Koha is free software; you can redistribute it and/or modify it under the
28 # terms of the GNU General Public License as published by the Free Software
29 # Foundation; either version 2 of the License, or (at your option) any later
32 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
33 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
34 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
36 # You should have received a copy of the GNU General Public License along with
37 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
38 # Suite 330, Boston, MA 02111-1307 USA
50 my ($env,$searchstring,$type)=@_;
51 my $dbh = C4::Context->dbh;
52 $searchstring=~ s/\'/\\\'/g;
53 my @data=split(' ',$searchstring);
55 my $query="Select variable,value,explanation from systempreferences where (variable like \"$data[0]%\") order by variable";
56 my $sth=$dbh->prepare($query);
60 while (my $data=$sth->fetchrow_hashref){
65 return ($cnt,\@results);
69 my $searchfield=$input->param('searchfield');
70 my $pkfield="variable";
71 my $reqsel="select variable,value,explanation from systempreferences where $pkfield='$searchfield'";
72 my $reqdel="delete from systempreferences where $pkfield='$searchfield'";
73 my $offset=$input->param('offset');
74 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
76 my $template = gettemplate("parameters/systempreferences.tmpl",0);
78 my $op = $input->param('op');
79 $searchfield=~ s/\,//g;
82 $template->param(script_name => $script_name,
83 $op => 1); # we show only the TMPL_VAR names $op
85 $template->param(script_name => $script_name,
86 else => 1); # we show only the TMPL_VAR names $op
88 ################## ADD_FORM ##################################
89 # called by default. Used to create form to add or modify a record
90 if ($op eq 'add_form') {
91 #---- if primkey exists, it's a modify action, so read values to modify...
94 my $dbh = C4::Context->dbh;
95 my $sth=$dbh->prepare("select variable,value,explanation from systempreferences where variable='$searchfield'");
97 $data=$sth->fetchrow_hashref;
101 $template->param(action => "Modify pref");
103 $template->param(action => "Add pref");
105 $template->param(explanation => $data->{'explanation'},
106 value => $data->{'value'},
109 $template->param(searchfield => "<input type=hidden name=variable value='$searchfield'>$searchfield");
111 $template->param(searchfield => "<input type=text name=variable size=80 maxlength=80>");
113 ################## ADD_VALIDATE ##################################
114 # called by add_form, used to insert/modify data in DB
115 } elsif ($op eq 'add_validate') {
116 my $dbh = C4::Context->dbh;
117 my $query = "replace systempreferences (variable,value,explanation) values (";
118 $query.= $dbh->quote($input->param('variable')).",";
119 $query.= $dbh->quote($input->param('value')).",";
120 $query.= $dbh->quote($input->param('explanation')).")";
121 my $sth=$dbh->prepare($query);
124 ################## DELETE_CONFIRM ##################################
125 # called by default form, used to confirm deletion of data in DB
126 } elsif ($op eq 'delete_confirm') {
127 my $dbh = C4::Context->dbh;
128 my $sth=$dbh->prepare($reqsel);
130 my $data=$sth->fetchrow_hashref;
132 $template->param(searchfield => $searchfield,
133 Tvalue => $data->{'value'},
136 # END $OP eq DELETE_CONFIRM
137 ################## DELETE_CONFIRMED ##################################
138 # called by delete_confirm, used to effectively confirm deletion of data in DB
139 } elsif ($op eq 'delete_confirmed') {
140 my $dbh = C4::Context->dbh;
141 my $sth=$dbh->prepare($reqdel);
144 # END $OP eq DELETE_CONFIRMED
145 ################## DEFAULT ##################################
147 if ($searchfield ne '') {
148 $template->param(searchfield => "You Searched for <b>$searchfield<b><p>");
151 my ($count,$results)=StringSearch($env,$searchfield,'web');
154 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
155 if ($toggle eq 'white'){
160 my %row_data; # get a fresh hash for the row data
161 $row_data{variable} = $results->[$i]{'variable'};
162 $row_data{value} = $results->[$i]{'value'};
163 $row_data{explanation} = $results->[$i]{'explanation'};
164 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
165 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
166 push(@loop_data, \%row_data);
168 $template->param(loop => \@loop_data);
170 my $prevpage = $offset-$pagesize;
171 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
173 if ($offset+$pagesize<$count) {
174 my $nextpage =$offset+$pagesize;
175 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
177 } #---- END $OP eq DEFAULT
179 print "Content-Type: text/html\n\n", $template->output;