|
Lines 19-34
Link Here
|
| 19 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 20 |
|
20 |
|
| 21 |
use Modern::Perl; |
21 |
use Modern::Perl; |
|
|
22 |
|
| 22 |
use CGI qw ( -utf8 ); |
23 |
use CGI qw ( -utf8 ); |
|
|
24 |
use Try::Tiny; |
| 25 |
|
| 23 |
use C4::Auth; |
26 |
use C4::Auth; |
| 24 |
use C4::Context; |
27 |
use C4::Context; |
| 25 |
use C4::Output; |
28 |
use C4::Output; |
| 26 |
use C4::Koha; |
29 |
use C4::Koha; |
|
|
30 |
|
| 31 |
use Koha::Database; |
| 27 |
use Koha::Patrons; |
32 |
use Koha::Patrons; |
| 28 |
use Koha::Items; |
33 |
use Koha::Items; |
| 29 |
use Koha::Libraries; |
34 |
use Koha::Libraries; |
|
|
35 |
use Koha::SMTP::Servers; |
| 30 |
|
36 |
|
| 31 |
my $input = new CGI; |
37 |
my $input = CGI->new; |
| 32 |
my $branchcode = $input->param('branchcode'); |
38 |
my $branchcode = $input->param('branchcode'); |
| 33 |
my $categorycode = $input->param('categorycode'); |
39 |
my $categorycode = $input->param('categorycode'); |
| 34 |
my $op = $input->param('op') || 'list'; |
40 |
my $op = $input->param('op') || 'list'; |
|
Lines 48-57
if ( $op eq 'add_form' ) {
Link Here
|
| 48 |
my $library; |
54 |
my $library; |
| 49 |
if ($branchcode) { |
55 |
if ($branchcode) { |
| 50 |
$library = Koha::Libraries->find($branchcode); |
56 |
$library = Koha::Libraries->find($branchcode); |
|
|
57 |
$template->param( selected_smtp_server => $library->smtp_server ); |
| 51 |
} |
58 |
} |
| 52 |
|
59 |
|
|
|
60 |
my @smtp_servers = Koha::SMTP::Servers->search; |
| 61 |
|
| 53 |
$template->param( |
62 |
$template->param( |
| 54 |
library => $library, |
63 |
library => $library, |
|
|
64 |
smtp_servers => \@smtp_servers |
| 55 |
); |
65 |
); |
| 56 |
} elsif ( $op eq 'add_validate' ) { |
66 |
} elsif ( $op eq 'add_validate' ) { |
| 57 |
my @fields = qw( |
67 |
my @fields = qw( |
|
Lines 83-93
if ( $op eq 'add_form' ) {
Link Here
|
| 83 |
for my $field (@fields) { |
93 |
for my $field (@fields) { |
| 84 |
$library->$field( scalar $input->param($field) ); |
94 |
$library->$field( scalar $input->param($field) ); |
| 85 |
} |
95 |
} |
| 86 |
eval { $library->store; }; |
96 |
|
| 87 |
if ($@) { |
97 |
try { |
|
|
98 |
Koha::Database->new->schema->txn_do( |
| 99 |
sub { |
| 100 |
$library->store->discard_changes; |
| 101 |
# Deal with SMTP server |
| 102 |
my $smtp_server_id = $input->param('smtp_server'); |
| 103 |
|
| 104 |
if ( $smtp_server_id ) { |
| 105 |
if ( $smtp_server_id eq '*' ) { |
| 106 |
$library->smtp_server({ smtp_server => undef }); |
| 107 |
} |
| 108 |
else { |
| 109 |
my $smtp_server = Koha::SMTP::Servers->find( $smtp_server_id ); |
| 110 |
Koha::Exceptions::BadParameter->throw( parameter => 'smtp_server' ) |
| 111 |
unless $smtp_server; |
| 112 |
$library->smtp_server({ smtp_server => $smtp_server }); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
push @messages, { type => 'message', code => 'success_on_update' }; |
| 117 |
} |
| 118 |
); |
| 119 |
} |
| 120 |
catch { |
| 88 |
push @messages, { type => 'alert', code => 'error_on_update' }; |
121 |
push @messages, { type => 'alert', code => 'error_on_update' }; |
| 89 |
} else { |
|
|
| 90 |
push @messages, { type => 'message', code => 'success_on_update' }; |
| 91 |
} |
122 |
} |
| 92 |
} else { |
123 |
} else { |
| 93 |
$branchcode =~ s|\s||g; |
124 |
$branchcode =~ s|\s||g; |
|
Lines 96-107
if ( $op eq 'add_form' ) {
Link Here
|
| 96 |
( map { $_ => scalar $input->param($_) || undef } @fields ) |
127 |
( map { $_ => scalar $input->param($_) || undef } @fields ) |
| 97 |
} |
128 |
} |
| 98 |
); |
129 |
); |
| 99 |
eval { $library->store; }; |
130 |
|
| 100 |
if ($@) { |
131 |
try { |
| 101 |
push @messages, { type => 'alert', code => 'error_on_insert' }; |
132 |
Koha::Database->new->schema->txn_do( |
| 102 |
} else { |
133 |
sub { |
| 103 |
push @messages, { type => 'message', code => 'success_on_insert' }; |
134 |
$library->store->discard_changes; |
|
|
135 |
|
| 136 |
my $smtp_server_id = $input->param('smtp_server'); |
| 137 |
|
| 138 |
if ( $smtp_server_id ) { |
| 139 |
if ( $smtp_server_id ne '*' ) { |
| 140 |
my $smtp_server = Koha::SMTP::Servers->find( $smtp_server_id ); |
| 141 |
Koha::Exceptions::BadParameter->throw( parameter => 'smtp_server' ) |
| 142 |
unless $smtp_server; |
| 143 |
$library->smtp_server({ smtp_server => $smtp_server }); |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
push @messages, { type => 'message', code => 'success_on_insert' }; |
| 148 |
} |
| 149 |
); |
| 104 |
} |
150 |
} |
|
|
151 |
catch { |
| 152 |
push @messages, { type => 'alert', code => 'error_on_insert' }; |
| 153 |
}; |
| 105 |
} |
154 |
} |
| 106 |
$op = 'list'; |
155 |
$op = 'list'; |
| 107 |
} elsif ( $op eq 'delete_confirm' ) { |
156 |
} elsif ( $op eq 'delete_confirm' ) { |