|
Lines 30-35
use C4::Auth qw( get_template_and_user );
Link Here
|
| 30 |
use C4::Output qw( output_html_with_http_headers ); |
30 |
use C4::Output qw( output_html_with_http_headers ); |
| 31 |
use Koha::Database; |
31 |
use Koha::Database; |
| 32 |
use Koha::Z3950Servers; |
32 |
use Koha::Z3950Servers; |
|
|
33 |
use Try::Tiny qw( catch try ); |
| 33 |
|
34 |
|
| 34 |
# Initialize CGI, template, database |
35 |
# Initialize CGI, template, database |
| 35 |
|
36 |
|
|
Lines 67-84
if ( $op eq 'cud-delete_confirmed' && $id ) {
Link Here
|
| 67 |
recordtype checked servername servertype sru_options sru_fields attributes |
68 |
recordtype checked servername servertype sru_options sru_fields attributes |
| 68 |
add_xslt/; |
69 |
add_xslt/; |
| 69 |
my $formdata = _form_data_hashref( $input, \@fields ); |
70 |
my $formdata = _form_data_hashref( $input, \@fields ); |
|
|
71 |
my @branches = grep { $_ ne q{} } $input->multi_param('branches'); |
| 72 |
|
| 70 |
if ($id) { |
73 |
if ($id) { |
| 71 |
my $server = Koha::Z3950Servers->find($id); |
74 |
my $server = Koha::Z3950Servers->find($id); |
| 72 |
if ($server) { |
75 |
if ($server) { |
| 73 |
$server->set($formdata)->store; |
76 |
try { |
| 74 |
$template->param( msg_updated => 1, msg_add => $formdata->{servername} ); |
77 |
$server->set($formdata)->store; |
|
|
78 |
$server->replace_library_limits( \@branches ); |
| 79 |
$template->param( msg_updated => 1, msg_add => $formdata->{servername} ); |
| 80 |
} catch { |
| 81 |
$template->param( msg_error => 1, msg_add => $formdata->{servername} ); |
| 82 |
}; |
| 75 |
} else { |
83 |
} else { |
| 76 |
$template->param( msg_notfound => 1, msg_add => $id ); |
84 |
$template->param( msg_notfound => 1, msg_add => $id ); |
| 77 |
} |
85 |
} |
| 78 |
$id = 0; |
86 |
$id = 0; |
| 79 |
} else { |
87 |
} else { |
| 80 |
Koha::Z3950Server->new($formdata)->store; |
88 |
try { |
| 81 |
$template->param( msg_added => 1, msg_add => $formdata->{servername} ); |
89 |
my $server = Koha::Z3950Server->new($formdata)->store; |
|
|
90 |
$server->replace_library_limits( \@branches ); |
| 91 |
$template->param( msg_added => 1, msg_add => $formdata->{servername} ); |
| 92 |
} catch { |
| 93 |
$template->param( msg_error => 1, msg_add => $formdata->{servername} ); |
| 94 |
}; |
| 82 |
} |
95 |
} |
| 83 |
} elsif ( $op eq 'search' ) { |
96 |
} elsif ( $op eq 'search' ) { |
| 84 |
|
97 |
|
|
Lines 91-105
if ( $op eq 'cud-delete_confirmed' && $id ) {
Link Here
|
| 91 |
my $data = []; |
104 |
my $data = []; |
| 92 |
if ( $op eq 'add' || $op eq 'edit' ) { |
105 |
if ( $op eq 'add' || $op eq 'edit' ) { |
| 93 |
$data = ServerSearch( $schema, $id, $searchfield ) if $searchfield || $id; |
106 |
$data = ServerSearch( $schema, $id, $searchfield ) if $searchfield || $id; |
| 94 |
delete $data->[0]->{id} if @$data && $op eq 'add'; #cloning record |
107 |
my $server = $data ? $data->next : undef; |
|
|
108 |
if ( $server && $op eq 'add' ) { |
| 109 |
|
| 110 |
# Cloning record - remove id |
| 111 |
$server = $server->unblessed; |
| 112 |
delete $server->{id}; |
| 113 |
} |
| 95 |
$template->param( |
114 |
$template->param( |
| 96 |
add_form => 1, server => @$data ? $data->[0] : undef, |
115 |
add_form => 1, server => $server, |
| 97 |
op => $op, type => $op eq 'add' ? lc $type : '' |
116 |
op => $op, type => $op eq 'add' ? lc $type : '' |
| 98 |
); |
117 |
); |
| 99 |
} else { |
118 |
} else { |
| 100 |
$data = ServerSearch( $schema, $id, $searchfield ); |
119 |
$data = ServerSearch( $schema, $id, $searchfield ); |
| 101 |
$template->param( |
120 |
$template->param( |
| 102 |
loop => \@$data, searchfield => $searchfield, id => $id, |
121 |
loop => $data, searchfield => $searchfield, id => $id, |
| 103 |
op => 'list' |
122 |
op => 'list' |
| 104 |
); |
123 |
); |
| 105 |
} |
124 |
} |
|
Lines 112-118
sub ServerSearch { #find server(s) by id or name
Link Here
|
| 112 |
|
131 |
|
| 113 |
return Koha::Z3950Servers->search( |
132 |
return Koha::Z3950Servers->search( |
| 114 |
$id ? { id => $id } : { servername => { like => $searchstring . '%' } }, |
133 |
$id ? { id => $id } : { servername => { like => $searchstring . '%' } }, |
| 115 |
)->unblessed; |
134 |
); |
| 116 |
} |
135 |
} |
| 117 |
|
136 |
|
| 118 |
sub _form_data_hashref { |
137 |
sub _form_data_hashref { |