3 # Copyright 2011,2014 Mark Gavillet & PTFS Europe Ltd
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 our $input = CGI->new();
28 our $schema = Koha::Database->new()->schema();
30 our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
32 template_name => 'admin/edi_accounts.tt',
36 flagsrequired => { acquisition => 'edi_manage' },
40 my $op = $input->param('op');
43 if ( $op eq 'acct_form' ) {
45 $template->param( acct_form => 1 );
46 my @vendors = $schema->resultset('Aqbookseller')->search(
49 columns => [ 'name', 'id' ],
50 order_by => { -asc => 'name' }
53 $template->param( vendors => \@vendors );
55 my $plugins_enabled = C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins");
56 $template->param( plugins_enabled => $plugins_enabled );
58 if ( $plugins_enabled ) {
59 my @plugins = Koha::Plugins->new()->GetPlugins({
62 $template->param( plugins => \@plugins );
65 elsif ( $op eq 'delete_confirm' ) {
67 $template->param( delete_confirm => 1 );
70 if ( $op eq 'save' ) {
73 my $id = $input->param('id');
75 description => scalar $input->param('description'),
76 host => scalar $input->param('host'),
77 username => scalar $input->param('username'),
78 password => scalar $input->param('password'),
79 vendor_id => scalar $input->param('vendor_id'),
80 upload_directory => scalar $input->param('upload_directory'),
81 download_directory => scalar $input->param('download_directory'),
82 san => scalar $input->param('san'),
83 transport => scalar $input->param('transport'),
84 id_code_qualifier => scalar $input->param('id_code_qualifier'),
85 plugin => scalar $input->param('plugin'),
87 # ensure all capability fields set to binary 0 or 1
88 foreach my $capability
89 (qw( quotes_enabled invoices_enabled orders_enabled responses_enabled auto_orders)) {
90 $fields->{$capability} = defined $input->param($capability);
91 if ($fields->{$capability} != 1) {
92 $fields->{$capability} = 0;
97 $schema->resultset('VendorEdiAccount')->search(
101 )->update_all($fields);
104 $schema->resultset('VendorEdiAccount')->create($fields);
107 elsif ( $op eq 'delete_confirmed' ) {
109 $schema->resultset('VendorEdiAccount')
110 ->search( { id => scalar $input->param('id'), } )->delete_all;
113 # we do a default dispaly after deletes and saves
114 # as well as when thats all you want
115 $template->param( display => 1 );
116 my @ediaccounts = $schema->resultset('VendorEdiAccount')->search(
122 $template->param( ediaccounts => \@ediaccounts );
129 description => 'EAN International',
133 description => 'US SAN Agency',
137 description => 'Assigned by supplier',
141 description => 'Assigned by buyer',
146 output_html_with_http_headers( $input, $cookie, $template->output );
151 my $account = $schema->resultset('VendorEdiAccount')->find($id);
156 # passing undef will default to add
161 my $acct_id = $input->param('id');
163 my $acct = $schema->resultset('VendorEdiAccount')->find($acct_id);
165 $template->param( account => $acct );