3 #script to administer the branches 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
30 use C4::Interface::CGI::Output;
33 my ($env,$searchstring,$type)=@_;
34 my $dbh = C4::Context->dbh;
35 $searchstring=~ s/\'/\\\'/g;
36 my @data=split(' ',$searchstring);
38 my $query="Select host,port,db,userid,password,name,id,checked,rank,syntax from z3950servers where (name like \"$data[0]\%\") order by rank,name";
39 my $sth=$dbh->prepare($query);
43 while (my $data=$sth->fetchrow_hashref) {
50 return ($cnt,\@results);
54 my $searchfield=$input->param('searchfield');
55 my $reqsel="select host,port,db,userid,password,name,id,checked,rank,syntax from z3950servers where (name = '$searchfield') order by rank,name";
56 my $reqdel="delete from z3950servers where name='$searchfield'";
57 my $offset=$input->param('offset');
58 my $script_name="/cgi-bin/koha/admin/z3950servers.pl";
61 my $op = $input->param('op');
62 $searchfield=~ s/\,//g;
64 my ($template, $loggedinuser, $cookie)
65 = get_template_and_user({template_name => "parameters/z3950servers.tmpl",
69 flagsrequired => {parameters => 1},
74 $template->param(script_name => $script_name,
75 searchfield => $searchfield);
78 ################## ADD_FORM ##################################
79 # called by default. Used to create form to add or modify a record
80 if ($op eq 'add_form') {
81 $template->param(add_form => 1);
82 #---- if primkey exists, it's a modify action, so read values to modify...
85 my $dbh = C4::Context->dbh;
86 my $sth=$dbh->prepare("select host,port,db,userid,password,name,id,checked,rank,syntax from z3950servers where (name = '$searchfield') order by rank,name");
88 $data=$sth->fetchrow_hashref;
92 $template->param(host => $data->{'host'},
93 port => $data->{'port'},
95 userid => $data->{'userid'},
96 password => $data->{'password'},
97 checked => $data->{'checked'},
98 rank => $data->{'rank'});
100 ################## ADD_VALIDATE ##################################
101 # called by add_form, used to insert/modify data in DB
102 } elsif ($op eq 'add_validate') {
103 $template->param(add_validate => 1);
104 my $dbh=C4::Context->dbh;
105 my $sth=$dbh->prepare("select * from z3950servers where name=?");
106 $sth->execute($input->param('searchfield'));
108 $sth=$dbh->prepare("update z3950servers set host=?, port=?, db=?, userid=?, password=?, name=?, checked=?, rank=?,syntax=? where name=?");
109 $sth->execute($input->param('host'),
110 $input->param('port'),
112 $input->param('userid'),
113 $input->param('password'),
114 $input->param('searchfield'),
115 $input->param('checked'),
116 $input->param('rank'),
117 $input->param('syntax'),
118 $input->param('searchfield'),
121 $sth=$dbh->prepare("insert into z3950servers (host,port,db,userid,password,name,checked,rank,syntax) values (?, ?, ?, ?, ?, ?, ?, ?,?)");
122 $sth->execute($input->param('host'),
123 $input->param('port'),
125 $input->param('userid'),
126 $input->param('password'),
127 $input->param('searchfield'),
128 $input->param('checked'),
129 $input->param('rank'),
130 $input->param('syntax'),
134 # END $OP eq ADD_VALIDATE
135 ################## DELETE_CONFIRM ##################################
136 # called by default form, used to confirm deletion of data in DB
137 } elsif ($op eq 'delete_confirm') {
138 $template->param(delete_confirm => 1);
139 my $dbh = C4::Context->dbh;
141 my $sth2=$dbh->prepare($reqsel);
143 my $data=$sth2->fetchrow_hashref;
146 $template->param(host => $data->{'host'},
147 port => $data->{'port'},
149 userid => $data->{'userid'},
150 password => $data->{'password'},
151 checked => $data->{'checked'},
152 rank => $data->{'rank'});
154 # END $OP eq DELETE_CONFIRM
155 ################## DELETE_CONFIRMED ##################################
156 # called by delete_confirm, used to effectively confirm deletion of data in DB
157 } elsif ($op eq 'delete_confirmed') {
158 $template->param(delete_confirmed => 1);
159 my $dbh=C4::Context->dbh;
160 my $sth=$dbh->prepare($reqdel);
163 # END $OP eq DELETE_CONFIRMED
164 ################## DEFAULT ##################################
166 $template->param(else => 1);
169 my ($count,$results)=StringSearch($env,$searchfield,'web');
171 my $toggle = 'white';
172 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
174 my $urlsearchfield=$results->[$i]{name};
175 $urlsearchfield=~s/ /%20/g;
176 my %row = ( name => $results->[$i]{'name'},
177 host => $results->[$i]{'host'},
178 port => $results->[$i]{'port'},
179 db => $results->[$i]{'db'},
180 userid =>$results->[$i]{'userid'},
181 password => ($results->[$i]{'password'}) ? ('#######') : (' '),
182 checked => $results->[$i]{'checked'},
183 rank => $results->[$i]{'rank'},
184 syntax => $results->[$i]{'syntax'},
188 if ( $toggle eq 'white' )
198 $template->param(loop => \@loop);
200 $template->param(offsetgtzero => 1,
201 prevpage => $offset-$pagesize);
203 if ($offset+$pagesize<$count) {
204 $template->param(ltcount => 1,
205 nextpage => $offset+$pagesize);
207 } #---- END $OP eq DEFAULT
209 output_html_with_http_headers $input, $cookie, $template->output;