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
29 use C4::Interface::CGI::Output;
32 my ($searchstring,$type)=@_;
33 my $dbh = C4::Context->dbh;
34 $searchstring=~ s/\'/\\\'/g;
35 my @data=split(' ',$searchstring);
37 my $sth=$dbh->prepare("Select host,port,db,userid,password,name,id,checked,rank,syntax from z3950servers where (name like ?) order by rank,name");
38 $sth->execute("$data[0]\%");
40 while (my $data=$sth->fetchrow_hashref) {
46 return (scalar(@results),\@results);
50 my $searchfield=$input->param('searchfield');
51 my $offset=$input->param('offset');
52 my $script_name="/cgi-bin/koha/admin/z3950servers.pl";
55 my $op = $input->param('op');
57 my ($template, $loggedinuser, $cookie)
58 = get_template_and_user({template_name => "admin/z3950servers.tmpl",
62 flagsrequired => {parameters => 1},
67 $template->param(script_name => $script_name,
68 searchfield => $searchfield);
71 ################## ADD_FORM ##################################
72 # called by default. Used to create form to add or modify a record
73 if ($op eq 'add_form') {
74 $template->param(add_form => 1);
75 #---- if primkey exists, it's a modify action, so read values to modify...
78 my $dbh = C4::Context->dbh;
79 my $sth=$dbh->prepare("select host,port,db,userid,password,name,id,checked,rank,syntax from z3950servers where (name = ?) order by rank,name");
80 $sth->execute($searchfield);
81 $data=$sth->fetchrow_hashref;
85 $template->param(host => $data->{'host'},
86 port => $data->{'port'},
88 userid => $data->{'userid'},
89 password => $data->{'password'},
90 checked => $data->{'checked'},
91 rank => $data->{'rank'});
93 ################## ADD_VALIDATE ##################################
94 # called by add_form, used to insert/modify data in DB
95 } elsif ($op eq 'add_validate') {
96 $template->param(add_validate => 1);
97 my $dbh=C4::Context->dbh;
98 my $sth=$dbh->prepare("select * from z3950servers where name=?");
99 $sth->execute($input->param('searchfield'));
101 $sth=$dbh->prepare("update z3950servers set host=?, port=?, db=?, userid=?, password=?, name=?, checked=?, rank=?,syntax=? where name=?");
102 $sth->execute($input->param('host'),
103 $input->param('port'),
105 $input->param('userid'),
106 $input->param('password'),
107 $input->param('searchfield'),
108 $input->param('checked'),
109 $input->param('rank'),
110 $input->param('syntax'),
111 $input->param('searchfield'),
114 $sth=$dbh->prepare("insert into z3950servers (host,port,db,userid,password,name,checked,rank,syntax) values (?, ?, ?, ?, ?, ?, ?, ?,?)");
115 $sth->execute($input->param('host'),
116 $input->param('port'),
118 $input->param('userid'),
119 $input->param('password'),
120 $input->param('searchfield'),
121 $input->param('checked'),
122 $input->param('rank'),
123 $input->param('syntax'),
127 # END $OP eq ADD_VALIDATE
128 ################## DELETE_CONFIRM ##################################
129 # called by default form, used to confirm deletion of data in DB
130 } elsif ($op eq 'delete_confirm') {
131 $template->param(delete_confirm => 1);
132 my $dbh = C4::Context->dbh;
134 my $sth2=$dbh->prepare("select host,port,db,userid,password,name,id,checked,rank,syntax from z3950servers where (name = ?) order by rank,name");
135 $sth2->execute($searchfield);
136 my $data=$sth2->fetchrow_hashref;
139 $template->param(host => $data->{'host'},
140 port => $data->{'port'},
142 userid => $data->{'userid'},
143 password => $data->{'password'},
144 checked => $data->{'checked'},
145 rank => $data->{'rank'});
147 # END $OP eq DELETE_CONFIRM
148 ################## DELETE_CONFIRMED ##################################
149 # called by delete_confirm, used to effectively confirm deletion of data in DB
150 } elsif ($op eq 'delete_confirmed') {
151 $template->param(delete_confirmed => 1);
152 my $dbh=C4::Context->dbh;
153 my $sth=$dbh->prepare("delete from z3950servers where name=?");
154 $sth->execute($searchfield);
156 # END $OP eq DELETE_CONFIRMED
157 ################## DEFAULT ##################################
159 $template->param(else => 1);
160 my ($count,$results)=StringSearch($searchfield,'web');
163 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
165 my $urlsearchfield=$results->[$i]{name};
166 $urlsearchfield=~s/ /%20/g;
167 my %row = ( name => $results->[$i]{'name'},
168 host => $results->[$i]{'host'},
169 port => $results->[$i]{'port'},
170 db => $results->[$i]{'db'},
171 userid =>$results->[$i]{'userid'},
172 password => ($results->[$i]{'password'}) ? ('#######') : (' '),
173 checked => $results->[$i]{'checked'},
174 rank => $results->[$i]{'rank'},
175 syntax => $results->[$i]{'syntax'},
189 $template->param(loop => \@loop);
191 $template->param(offsetgtzero => 1,
192 prevpage => $offset-$pagesize);
194 if ($offset+$pagesize<$count) {
195 $template->param(ltcount => 1,
196 nextpage => $offset+$pagesize);
198 } #---- END $OP eq DEFAULT
199 $template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
200 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
201 IntranetNav => C4::Context->preference("IntranetNav"),
203 output_html_with_http_headers $input, $cookie, $template->output;