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
29 my ($searchstring,$type)=@_;
30 my $dbh = C4
::Context
->dbh;
31 $searchstring=~ s/\'/\\\'/g;
32 my @data=split(' ',$searchstring);
34 my $sth=$dbh->prepare("Select host,port,db,userid,password,name,id,checked,rank,syntax,encoding from z3950servers where (name like ?) order by rank,name");
35 $sth->execute("$data[0]\%");
37 while (my $data=$sth->fetchrow_hashref) {
43 return (scalar(@results),\
@results);
47 my $searchfield=$input->param('searchfield');
48 my $offset=$input->param('offset');
49 my $script_name="/cgi-bin/koha/admin/z3950servers.pl";
52 my $op = $input->param('op');
54 my ($template, $loggedinuser, $cookie)
55 = get_template_and_user
({template_name
=> "admin/z3950servers.tmpl",
59 flagsrequired
=> {parameters
=> 1},
64 $template->param(script_name
=> $script_name,
65 searchfield
=> $searchfield);
68 ################## ADD_FORM ##################################
69 # called by default. Used to create form to add or modify a record
70 if ($op eq 'add_form') {
71 $template->param(add_form
=> 1);
72 #---- if primkey exists, it's a modify action, so read values to modify...
75 my $dbh = C4
::Context
->dbh;
76 my $sth=$dbh->prepare("select host,port,db,userid,password,name,id,checked,rank,syntax,encoding from z3950servers where (name = ?) order by rank,name");
77 $sth->execute($searchfield);
78 $data=$sth->fetchrow_hashref;
81 $template->param( $_ => $data->{$_} )
82 for ( qw( host port db userid password checked rank ) );
83 $template->param( $_ . $data->{$_} => 1)
84 for ( qw( syntax encoding ) );
86 ################## ADD_VALIDATE ##################################
87 # called by add_form, used to insert/modify data in DB
88 } elsif ($op eq 'add_validate') {
89 $template->param(add_validate
=> 1);
90 my $dbh=C4
::Context
->dbh;
91 my $sth=$dbh->prepare("select * from z3950servers where name=?");
92 $sth->execute($input->param('searchfield'));
94 $sth=$dbh->prepare("update z3950servers set host=?, port=?, db=?, userid=?, password=?, name=?, checked=?, rank=?,syntax=?,encoding=? where name=?");
95 $sth->execute($input->param('host'),
96 $input->param('port'),
98 $input->param('userid'),
99 $input->param('password'),
100 $input->param('searchfield'),
101 $input->param('checked'),
102 $input->param('rank'),
103 $input->param('syntax'),
104 $input->param('encoding'),
105 $input->param('searchfield'),
110 "INSERT INTO z3950servers " .
111 "(host,port,db,userid,password,name,checked,rank,syntax,encoding) " .
112 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" );
114 $input->param( 'host' ),
115 $input->param( 'port' ),
116 $input->param( 'db' ),
117 $input->param( 'userid' ),
118 $input->param( 'password' ),
119 $input->param( 'searchfield' ),
120 $input->param( 'checked' ),
121 $input->param( 'rank' ),
122 $input->param( 'syntax' ),
123 $input->param( 'encoding' ) );
126 # END $OP eq ADD_VALIDATE
127 ################## DELETE_CONFIRM ##################################
128 # called by default form, used to confirm deletion of data in DB
129 } elsif ($op eq 'delete_confirm') {
130 $template->param(delete_confirm
=> 1);
131 my $dbh = C4
::Context
->dbh;
133 my $sth2=$dbh->prepare("select host,port,db,userid,password,name,id,checked,rank,syntax,encoding from z3950servers where (name = ?) order by rank,name");
134 $sth2->execute($searchfield);
135 my $data=$sth2->fetchrow_hashref;
138 $template->param(host
=> $data->{'host'},
139 port
=> $data->{'port'},
141 userid
=> $data->{'userid'},
142 password
=> $data->{'password'},
143 checked
=> $data->{'checked'},
144 rank
=> $data->{'rank'},
145 syntax
=> $data->{'syntax'},
146 encoding
=> $data->{'encoding'} );
148 # END $OP eq DELETE_CONFIRM
149 ################## DELETE_CONFIRMED ##################################
150 # called by delete_confirm, used to effectively confirm deletion of data in DB
151 } elsif ($op eq 'delete_confirmed') {
152 $template->param(delete_confirmed
=> 1);
153 my $dbh=C4
::Context
->dbh;
154 my $sth=$dbh->prepare("delete from z3950servers where name=?");
155 $sth->execute($searchfield);
157 # END $OP eq DELETE_CONFIRMED
158 ################## DEFAULT ##################################
160 $template->param(else => 1);
161 my ($count,$results)=StringSearch
($searchfield,'web');
164 for (my $i=$offset; $i < ($offset+$pagesize<$count?
$offset+$pagesize:$count); $i++){
166 my $urlsearchfield=$results->[$i]{name
};
167 $urlsearchfield=~s/ /%20/g;
168 my %row = ( name
=> $results->[$i]{'name'},
169 host
=> $results->[$i]{'host'},
170 port
=> $results->[$i]{'port'},
171 db
=> $results->[$i]{'db'},
172 userid
=>$results->[$i]{'userid'},
173 password
=> ($results->[$i]{'password'}) ?
('#######') : (' '),
174 checked
=> $results->[$i]{'checked'},
175 rank
=> $results->[$i]{'rank'},
176 syntax
=> $results->[$i]{'syntax'},
177 encoding
=> $results->[$i]{'encoding'},
191 $template->param(loop => \
@loop);
193 $template->param(offsetgtzero
=> 1,
194 prevpage
=> $offset-$pagesize);
196 if ($offset+$pagesize<$count) {
197 $template->param(ltcount
=> 1,
198 nextpage
=> $offset+$pagesize);
200 } #---- END $OP eq DEFAULT
201 output_html_with_http_headers
$input, $cookie, $template->output;