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