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 ano $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 my ($searchstring,$type)=@_;
31 my $dbh = C4::Context->dbh;
34 if ( defined $searchstring ) {
35 $searchstring =~ s/\'/\\\'/g;
36 @data=split(' ',$searchstring);
43 my $query = "SELECT host,port,db,userid,password,name,id,checked,rank,syntax,encoding,timeout,recordtype";
44 $query .= " FROM z3950servers";
45 if ( $searchstring ne '' ) { $query .= " WHERE (name like ?)" }
46 $query .= " ORDER BY rank,name";
47 my $sth=$dbh->prepare($query);
49 if ( $searchstring ne '' ) {
50 $sth->execute("$data[0]\%");
57 while (my $data=$sth->fetchrow_hashref) {
61 return (scalar(@results),\@results);
65 my $searchfield=$input->param('searchfield');
66 my $offset=$input->param('offset') || 0;
67 my $script_name="/cgi-bin/koha/admin/z3950servers.pl";
70 my $op = $input->param('op') || '';
72 my ($template, $loggedinuser, $cookie)
73 = get_template_and_user({template_name => "admin/z3950servers.tmpl",
77 flagsrequired => {parameters => 'parameters_remaining_permissions'},
82 $template->param(script_name => $script_name,
83 searchfield => $searchfield);
86 ################## ADD_FORM ##################################
87 # called by default. Used to create form to add or modify a record
88 if ( $op eq 'add_form' ) {
89 $template->param( add_form => 1 );
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(
96 "select host,port,db,userid,password,name,id,checked,rank,syntax,encoding,timeout,recordtype from z3950servers where (name = ?) order by rank,name"
98 $sth->execute($searchfield);
99 $data = $sth->fetchrow_hashref;
102 $template->param( $_ => $data->{$_} )
103 for (qw( host port db userid password checked rank timeout encoding ));
104 $template->param( $_ . $data->{$_} => 1 ) for (qw( syntax recordtype ));
106 # END $OP eq ADD_FORM
107 ################## ADD_VALIDATE ##################################
108 # called by add_form, used to insert/modify data in DB
109 } elsif ($op eq 'add_validate') {
110 my $dbh=C4::Context->dbh;
111 my $sth=$dbh->prepare("select * from z3950servers where name=?");
112 $sth->execute($input->param('searchfield'));
113 my $checked = $input->param('checked') ? 1 : 0;
115 $template->param(confirm_update => 1);
116 $sth=$dbh->prepare("update z3950servers set host=?, port=?, db=?, userid=?, password=?, name=?, checked=?, rank=?,syntax=?,encoding=?,timeout=?,recordtype=? where name=?");
117 $sth->execute($input->param('host'),
118 $input->param('port'),
120 $input->param('userid'),
121 $input->param('password'),
122 $input->param('searchfield'),
124 $input->param('rank'),
125 $input->param('syntax'),
126 $input->param('encoding'),
127 $input->param('timeout'),
128 $input->param('recordtype'),
129 $input->param('searchfield'),
133 $template->param(confirm_add => 1);
135 "INSERT INTO z3950servers " .
136 "(host,port,db,userid,password,name,checked,rank,syntax,encoding,timeout,recordtype) " .
137 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" );
139 $input->param('host'), $input->param('port'),
140 $input->param('db'), $input->param('userid'),
141 $input->param('password'), $input->param('searchfield'),
142 $checked, $input->param('rank'),
143 $input->param('syntax'), $input->param('encoding'),
144 $input->param('timeout'), $input->param('recordtype')
149 # END $OP eq ADD_VALIDATE
150 ################## DELETE_CONFIRM ##################################
151 # called by default form, used to confirm deletion of data in DB
152 } elsif ($op eq 'delete_confirm') {
153 $template->param( delete_confirm => 1 );
154 my $dbh = C4::Context->dbh;
156 my $sth2 = $dbh->prepare(
157 "select host,port,db,userid,password,name,id,checked,rank,syntax,encoding,timeout,recordtype from z3950servers where (name = ?) order by rank,name"
159 $sth2->execute($searchfield);
160 my $data = $sth2->fetchrow_hashref;
164 host => $data->{'host'},
165 port => $data->{'port'},
167 userid => $data->{'userid'},
168 password => $data->{'password'},
169 checked => $data->{'checked'},
170 rank => $data->{'rank'},
171 syntax => $data->{'syntax'},
172 timeout => $data->{'timeout'},
173 recordtype => $data->{'recordtype'},
174 encoding => $data->{'encoding'}
177 # END $OP eq DELETE_CONFIRM
178 ################## DELETE_CONFIRMED ##################################
179 # called by delete_confirm, used to effectively confirm deletion of data in DB
180 } elsif ($op eq 'delete_confirmed') {
181 $template->param(delete_confirmed => 1);
182 my $dbh=C4::Context->dbh;
183 my $sth=$dbh->prepare("delete from z3950servers where name=?");
184 $sth->execute($searchfield);
186 # END $OP eq DELETE_CONFIRMED
187 ################## DEFAULT ##################################
189 $template->param(else => 1);
190 my ($count,$results)=StringSearch($searchfield,'web');
193 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
194 my $urlsearchfield=$results->[$i]{name};
195 $urlsearchfield=~s/ /%20/g;
196 my %row = ( name => $results->[$i]{'name'},
197 host => $results->[$i]{'host'},
198 port => $results->[$i]{'port'},
199 db => $results->[$i]{'db'},
200 userid =>$results->[$i]{'userid'},
201 password => ($results->[$i]{'password'}) ? ('#######') : (' '),
202 checked => $results->[$i]{'checked'},
203 rank => $results->[$i]{'rank'},
204 syntax => $results->[$i]{'syntax'},
205 encoding => $results->[$i]{'encoding'},
206 timeout => $results->[$i]{'timeout'},
207 recordtype => $results->[$i]{'recordtype'});
211 $template->param(loop => \@loop);
213 $template->param(offsetgtzero => 1,
214 prevpage => $offset-$pagesize);
216 if ($offset+$pagesize<$count) {
217 $template->param(ltcount => 1,
218 nextpage => $offset+$pagesize);
220 } #---- END $OP eq DEFAULT
221 output_html_with_http_headers $input, $cookie, $template->output;