|
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 47-56
if ( $op eq 'add_form' ) {
Link Here
|
| 47 |
my $library; |
53 |
my $library; |
| 48 |
if ($branchcode) { |
54 |
if ($branchcode) { |
| 49 |
$library = Koha::Libraries->find($branchcode); |
55 |
$library = Koha::Libraries->find($branchcode); |
|
|
56 |
$template->param( selected_smtp_server => $library->smtp_server ); |
| 50 |
} |
57 |
} |
| 51 |
|
58 |
|
|
|
59 |
my @smtp_servers = Koha::SMTP::Servers->search; |
| 60 |
|
| 52 |
$template->param( |
61 |
$template->param( |
| 53 |
library => $library, |
62 |
library => $library, |
|
|
63 |
smtp_servers => \@smtp_servers |
| 54 |
); |
64 |
); |
| 55 |
} elsif ( $op eq 'add_validate' ) { |
65 |
} elsif ( $op eq 'add_validate' ) { |
| 56 |
my @fields = qw( |
66 |
my @fields = qw( |
|
Lines 82-92
if ( $op eq 'add_form' ) {
Link Here
|
| 82 |
for my $field (@fields) { |
92 |
for my $field (@fields) { |
| 83 |
$library->$field( scalar $input->param($field) ); |
93 |
$library->$field( scalar $input->param($field) ); |
| 84 |
} |
94 |
} |
| 85 |
eval { $library->store; }; |
95 |
|
| 86 |
if ($@) { |
96 |
try { |
|
|
97 |
Koha::Database->new->schema->txn_do( |
| 98 |
sub { |
| 99 |
$library->store->discard_changes; |
| 100 |
# Deal with SMTP server |
| 101 |
my $smtp_server_id = $input->param('smtp_server'); |
| 102 |
|
| 103 |
if ( $smtp_server_id ) { |
| 104 |
if ( $smtp_server_id eq '*' ) { |
| 105 |
$library->smtp_server({ smtp_server => undef }); |
| 106 |
} |
| 107 |
else { |
| 108 |
my $smtp_server = Koha::SMTP::Servers->find( $smtp_server_id ); |
| 109 |
Koha::Exceptions::BadParameter->throw( parameter => 'smtp_server' ) |
| 110 |
unless $smtp_server; |
| 111 |
$library->smtp_server({ smtp_server => $smtp_server }); |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
push @messages, { type => 'message', code => 'success_on_update' }; |
| 116 |
} |
| 117 |
); |
| 118 |
} |
| 119 |
catch { |
| 87 |
push @messages, { type => 'alert', code => 'error_on_update' }; |
120 |
push @messages, { type => 'alert', code => 'error_on_update' }; |
| 88 |
} else { |
|
|
| 89 |
push @messages, { type => 'message', code => 'success_on_update' }; |
| 90 |
} |
121 |
} |
| 91 |
} else { |
122 |
} else { |
| 92 |
$branchcode =~ s|\s||g; |
123 |
$branchcode =~ s|\s||g; |
|
Lines 95-106
if ( $op eq 'add_form' ) {
Link Here
|
| 95 |
( map { $_ => scalar $input->param($_) || undef } @fields ) |
126 |
( map { $_ => scalar $input->param($_) || undef } @fields ) |
| 96 |
} |
127 |
} |
| 97 |
); |
128 |
); |
| 98 |
eval { $library->store; }; |
129 |
|
| 99 |
if ($@) { |
130 |
try { |
| 100 |
push @messages, { type => 'alert', code => 'error_on_insert' }; |
131 |
Koha::Database->new->schema->txn_do( |
| 101 |
} else { |
132 |
sub { |
| 102 |
push @messages, { type => 'message', code => 'success_on_insert' }; |
133 |
$library->store->discard_changes; |
|
|
134 |
|
| 135 |
my $smtp_server_id = $input->param('smtp_server'); |
| 136 |
|
| 137 |
if ( $smtp_server_id ) { |
| 138 |
if ( $smtp_server_id ne '*' ) { |
| 139 |
my $smtp_server = Koha::SMTP::Servers->find( $smtp_server_id ); |
| 140 |
Koha::Exceptions::BadParameter->throw( parameter => 'smtp_server' ) |
| 141 |
unless $smtp_server; |
| 142 |
$library->smtp_server({ smtp_server => $smtp_server }); |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
push @messages, { type => 'message', code => 'success_on_insert' }; |
| 147 |
} |
| 148 |
); |
| 103 |
} |
149 |
} |
|
|
150 |
catch { |
| 151 |
push @messages, { type => 'alert', code => 'error_on_insert' }; |
| 152 |
}; |
| 104 |
} |
153 |
} |
| 105 |
$op = 'list'; |
154 |
$op = 'list'; |
| 106 |
} elsif ( $op eq 'delete_confirm' ) { |
155 |
} elsif ( $op eq 'delete_confirm' ) { |