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
51 my ($env,$searchstring,$type)=@_;
52 my $dbh = C4::Context->dbh;
53 $searchstring=~ s/\'/\\\'/g;
54 my @data=split(' ',$searchstring);
56 my $query="Select variable,value,explanation from systempreferences where (variable like \"$data[0]%\") order by variable";
57 my $sth=$dbh->prepare($query);
61 while (my $data=$sth->fetchrow_hashref){
66 return ($cnt,\@results);
70 my $searchfield=$input->param('searchfield');
71 my $pkfield="variable";
72 my $reqsel="select variable,value,explanation from systempreferences where $pkfield='$searchfield'";
73 my $reqdel="delete from systempreferences where $pkfield='$searchfield'";
74 my $offset=$input->param('offset');
75 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
77 my ($template, $borrowernumber, $cookie)
78 = get_template_and_user({template_name => "parameters/systempreferences.tmpl",
82 flagsrequired => {parameters => 1},
86 my $op = $input->param('op');
87 $searchfield=~ s/\,//g;
90 $template->param(script_name => $script_name,
91 $op => 1); # we show only the TMPL_VAR names $op
93 $template->param(script_name => $script_name,
94 else => 1); # we show only the TMPL_VAR names $op
96 ################## ADD_FORM ##################################
97 # called by default. Used to create form to add or modify a record
98 if ($op eq 'add_form') {
99 #---- if primkey exists, it's a modify action, so read values to modify...
102 my $dbh = C4::Context->dbh;
103 my $sth=$dbh->prepare("select variable,value,explanation from systempreferences where variable='$searchfield'");
105 $data=$sth->fetchrow_hashref;
109 $template->param(action => "Modify pref");
111 $template->param(action => "Add pref");
113 $template->param(explanation => $data->{'explanation'},
114 value => $data->{'value'},
117 $template->param(searchfield => "<input type=hidden name=variable value='$searchfield'>$searchfield");
119 $template->param(searchfield => "<input type=text name=variable size=80 maxlength=80>");
121 ################## ADD_VALIDATE ##################################
122 # called by add_form, used to insert/modify data in DB
123 } elsif ($op eq 'add_validate') {
124 my $dbh = C4::Context->dbh;
125 my $query = "replace systempreferences (variable,value,explanation) values (";
126 $query.= $dbh->quote($input->param('variable')).",";
127 $query.= $dbh->quote($input->param('value')).",";
128 $query.= $dbh->quote($input->param('explanation')).")";
129 my $sth=$dbh->prepare($query);
132 ################## DELETE_CONFIRM ##################################
133 # called by default form, used to confirm deletion of data in DB
134 } elsif ($op eq 'delete_confirm') {
135 my $dbh = C4::Context->dbh;
136 my $sth=$dbh->prepare($reqsel);
138 my $data=$sth->fetchrow_hashref;
140 $template->param(searchfield => $searchfield,
141 Tvalue => $data->{'value'},
144 # END $OP eq DELETE_CONFIRM
145 ################## DELETE_CONFIRMED ##################################
146 # called by delete_confirm, used to effectively confirm deletion of data in DB
147 } elsif ($op eq 'delete_confirmed') {
148 my $dbh = C4::Context->dbh;
149 my $sth=$dbh->prepare($reqdel);
152 # END $OP eq DELETE_CONFIRMED
153 ################## DEFAULT ##################################
155 if ($searchfield ne '') {
156 $template->param(searchfield => "You Searched for <b>$searchfield<b><p>");
159 my ($count,$results)=StringSearch($env,$searchfield,'web');
162 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
163 if ($toggle eq 'white'){
168 my %row_data; # get a fresh hash for the row data
169 $row_data{variable} = $results->[$i]{'variable'};
170 $row_data{value} = $results->[$i]{'value'};
171 $row_data{explanation} = $results->[$i]{'explanation'};
172 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
173 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
174 push(@loop_data, \%row_data);
176 $template->param(loop => \@loop_data);
178 my $prevpage = $offset-$pagesize;
179 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
181 if ($offset+$pagesize<$count) {
182 my $nextpage =$offset+$pagesize;
183 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
185 } #---- END $OP eq DEFAULT
187 print $input->header(-cookie => $cookie), $template->output;