diff --git a/admin/z3950servers.pl b/admin/z3950servers.pl index 7993f66089..7d013907cf 100755 --- a/admin/z3950servers.pl +++ b/admin/z3950servers.pl @@ -24,16 +24,17 @@ use C4::Output; use CGI; use C4::Search; use C4::Database; +use C4::Context; sub StringSearch { my ($env,$searchstring,$type)=@_; - my $dbh = &C4Connect; + my $dbh = C4::Context->dbh; $searchstring=~ s/\'/\\\'/g; my @data=split(' ',$searchstring); my $count=@data; - my $query="Select host,port,db,userid,password,name,id,checked,rank from z3950servers where (name like \"$data[0]\%\") order by rank,name"; - my $sth=$dbh->prepare($query); - $sth->execute; + my $query="Select host,port,db,userid,password,name,id,checked,rank from +z3950servers where (name like \"$data[0]\%\") order by rank,name"; my +$sth=$dbh->prepare($query); $sth->execute; my @results; my $cnt=0; while (my $data=$sth->fetchrow_hashref) { @@ -48,11 +49,11 @@ sub StringSearch { my $input = new CGI; my $searchfield=$input->param('searchfield'); -my $reqsel="select host,port,db,userid,password,name,id,checked,rank from z3950servers where (name = '$searchfield') order by rank,name"; -my $reqdel="delete from z3950servers where name='$searchfield'"; -my $offset=$input->param('offset'); -my $script_name="/cgi-bin/koha/admin/z3950servers.pl"; - +my $reqsel="select host,port,db,userid,password,name,id,checked,rank from +z3950servers where (name = '$searchfield') order by rank,name";my +$reqdel="delete from z3950servers where name='$searchfield'";my +$offset=$input->param('offset');my +$script_name="/cgi-bin/koha/admin/z3950servers.pl"; my $pagesize=20; my $op = $input->param('op'); $searchfield=~ s/\,//g; @@ -68,29 +69,29 @@ if ($op eq 'add_form') { #---- if primkey exists, it's a modify action, so read values to modify... my $data; if ($searchfield) { - my $dbh = &C4Connect; - my $sth=$dbh->prepare("select host,port,db,userid,password,name,id,checked,rank from z3950servers where (name = '$searchfield') order by rank,name"); - $sth->execute; - $data=$sth->fetchrow_hashref; - $sth->finish; + my $dbh = C4::Context->dbh; + my $sth=$dbh->prepare("select +host,port,db,userid,password,name,id,checked,rank from z3950servers where (name += '$searchfield') order by rank,name"); $sth->execute; +$data=$sth->fetchrow_hashref; $sth->finish; } print < - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// - function isNotNull(f,noalert) { + /////////////////////////////////////////////////////////////////////////////// +////////////////////////////////// function isNotNull(f,noalert) { if (f.value.length ==0) { return false; } return true; } - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// - function toUC(f) { + /////////////////////////////////////////////////////////////////////////////// +////////////////////////////////// function toUC(f) { var x=f.value.toUpperCase(); f.value=x; return true; } - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// - function isNum(v,maybenull) { + /////////////////////////////////////////////////////////////////////////////// +////////////////////////////////// function isNum(v,maybenull) { var n = new Number(v.value); if (isNaN(n)) { return false; @@ -100,15 +101,15 @@ if ($op eq 'add_form') { } return true; } - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// - function isDate(f) { + /////////////////////////////////////////////////////////////////////////////// +////////////////////////////////// function isDate(f) { var t = Date.parse(f.value); if (isNaN(t)) { return false; } } - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// - function Check(f) { + /////////////////////////////////////////////////////////////////////////////// +////////////////////////////////// function Check(f) { var ok=1; var _alertString=""; var alertString2; @@ -137,9 +138,9 @@ if ($op eq 'add_form') { document.Aform.submit(); } else { alertString2 = "Form not submitted because of the following problem(s)\\n"; - alertString2 += "------------------------------------------------------------------------------------\\n\\n"; - alertString2 += _alertString; - alert(alertString2); + alertString2 += +"------------------------------------------------------------------------------- +-----\\n\\n"; alertString2 += _alertString; alert(alertString2); } } @@ -154,32 +155,32 @@ printend print ""; print ""; if ($searchfield) { - print "\n"; - } else { - print "\n"; - } - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print ""; - print ""; - print ""; - print "
Z39.50 Server$searchfield
Z39.50 Server
Hostname
Port
Database
Userid
Password
Checked (searched by default)
Rank (display order)
 
"; - print ""; -; - # END $OP eq ADD_FORM -################## ADD_VALIDATE ################################## -# called by add_form, used to insert/modify data in DB -} elsif ($op eq 'add_validate') { - my $dbh=C4Connect; - my $sth=$dbh->prepare("select * from z3950servers where name=?"); - $sth->execute($input->param('searchfield')); - if ($sth->rows) { - $sth=$dbh->prepare("update z3950servers set host=?, port=?, db=?, userid=?, password=?, name=?, checked=?, rank=? where name=?"); - $sth->execute($input->param('host'), - $input->param('port'), + print "Z39.50 Server$searchfield\n"; } else { + print "Z39.50 Server\n"; } + print "Hostname\n"; print "Port\n"; print "Database\n"; print +"Userid\n"; print "Password\n"; print +"Checked (searched by default)"; print +"Rank (display order)"; print +" "; print ""; print "";; + # END $OP eq ADD_FORM################## ADD_VALIDATE +################################### called by add_form, used to insert/modify +data in DB} elsif ($op eq 'add_validate') { my $dbh=C4::Context->dbh; my +$sth=$dbh->prepare("select * from z3950servers where name=?"); +$sth->execute($input->param('searchfield')); if ($sth->rows) { + $sth=$dbh->prepare("update z3950servers set host=?, port=?, db=?, userid=?, +password=?, name=?, checked=?, rank=? where name=?"); +$sth->execute($input->param('host'), $input->param('port'), $input->param('db'), $input->param('userid'), $input->param('password'), @@ -189,9 +190,9 @@ printend $input->param('searchfield') ); } else { - $sth=$dbh->prepare("insert into z3950servers (host,port,db,userid,password,name,checked,rank) values (?, ?, ?, ?, ?, ?, ?, ?)"); - $sth->execute($input->param('host'), - $input->param('port'), + $sth=$dbh->prepare("insert into z3950servers +(host,port,db,userid,password,name,checked,rank) values (?, ?, ?, ?, ?, ?, ?, +?)"); $sth->execute($input->param('host'), $input->param('port'), $input->param('db'), $input->param('userid'), $input->param('password'), @@ -209,9 +210,9 @@ printend ################## DELETE_CONFIRM ################################## # called by default form, used to confirm deletion of data in DB } elsif ($op eq 'delete_confirm') { - my $dbh = &C4Connect; - my $sth=$dbh->prepare("select count(*) as total from borrowers where branchcode='$searchfield'"); - $sth->execute; + my $dbh = C4::Context->dbh; + my $sth=$dbh->prepare("select count(*) as total from borrowers where +branchcode='$searchfield'"); $sth->execute; my $total = $sth->fetchrow_hashref; $sth->finish; print "$reqsel"; @@ -220,32 +221,32 @@ printend my $data=$sth->fetchrow_hashref; $sth->finish; print mktablehdr; - print mktablerow(2,'#99cc33',bold('Branch code'),bold("$searchfield"),'/images/background-mem.gif'); - print "
"; - print "Branch code$data->{'branchcode'}"; - print "  name$data->{'branchname'}"; - print "  adress$data->{'branchaddress1'}"; - print " $data->{'branchaddress2'}"; - print " $data->{'branchaddress3'}"; - print " phone$data->{'branchphone'}"; - print "  fax$data->{'branchfax'}"; - print "  e-mail$data->{'branchemail'}"; - print "  issuing$data->{'issuing'}"; - if ($total->{'total'} >0) { - print "This record is used $total->{'total'} times. Deletion not possible"; - print "
"; - } else { - print "CONFIRM DELETION"; - print "
"; - } - # END $OP eq DELETE_CONFIRM -################## DELETE_CONFIRMED ################################## -# called by delete_confirm, used to effectively confirm deletion of data in DB -} elsif ($op eq 'delete_confirmed') { - my $dbh=C4Connect; -# my $searchfield=$input->param('branchcode'); - my $sth=$dbh->prepare($reqdel); - $sth->execute; + print mktablerow(2,'#99cc33',bold('Branch +code'),bold("$searchfield"),'/images/background-mem.gif'); print "
"; print "Branch +code$data->{'branchcode'}"; print "  +name$data->{'branchname'}"; print "  +adress$data->{'branchaddress1'}"; print +" $data->{'branchaddress2'}"; print +" $data->{'branchaddress3'}"; print +" phone$data->{'branchphone'}"; print +"  fax$data->{'branchfax'}"; print +"  e-mail$data->{'branchemail'}"; print +"  issuing$data->{'issuing'}"; if +($total->{'total'} >0) { print "This record +is used $total->{'total'} times. Deletion not possible"; print +"
"; } else { print "CONFIRM DELETION"; print "
"; } # END $OP eq +DELETE_CONFIRM################## DELETE_CONFIRMED +################################### called by delete_confirm, used to +effectively confirm deletion of data in DB} elsif ($op eq 'delete_confirmed') { +my $dbh=C4::Context->dbh;# my $searchfield=$input->param('branchcode'); my +$sth=$dbh->prepare($reqdel); $sth->execute; $sth->finish; print "data deleted"; print "
"; @@ -272,8 +273,8 @@ printend my $env; my ($count,$results)=StringSearch($env,$searchfield,'web'); my $toggle="white"; - for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){ - if ($toggle eq 'white'){ + for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); +$i++){ if ($toggle eq 'white'){ $toggle="#ffffcc"; } else { $toggle="white"; @@ -291,9 +292,9 @@ printend $results->[$i]{'checked'}, $results->[$i]{'rank'}, mklink("$script_name?op=add_form&searchfield=$urlsearchfield".'','Edit'), - mklink("$script_name?op=delete_confirm&searchfield=$urlsearchfield",'Delete')); - } - print mktableft; + +mklink("$script_name?op=delete_confirm&searchfield=$urlsearchfield",'Delete')); +} print mktableft; print ""; print ""; if ($offset>0) { @@ -305,8 +306,8 @@ printend my $nextpage =$offset+$pagesize; print mklink("$script_name?offset=".$nextpage,'Next >>'); } - print "

"; - print "
"; + print "

"; print ""; } #---- END $OP eq DEFAULT print endmenu('admin'); print endpage();