|
Lines 27-32
use CGI qw ( -utf8 );
Link Here
|
| 27 |
use C4::Auth qw(get_template_and_user); |
27 |
use C4::Auth qw(get_template_and_user); |
| 28 |
use C4::Koha; |
28 |
use C4::Koha; |
| 29 |
use C4::Context; |
29 |
use C4::Context; |
|
|
30 |
use C4::Log qw( logaction ); |
| 30 |
use C4::Output qw(output_html_with_http_headers); |
31 |
use C4::Output qw(output_html_with_http_headers); |
| 31 |
use C4::Languages qw(getTranslatedLanguages); |
32 |
use C4::Languages qw(getTranslatedLanguages); |
| 32 |
use Koha::DateUtils; |
33 |
use Koha::DateUtils; |
|
Lines 118-128
elsif ( $op eq 'add_validate' ) {
Link Here
|
| 118 |
); |
119 |
); |
| 119 |
# Delete if title or content is empty |
120 |
# Delete if title or content is empty |
| 120 |
unless ( $title and $content ) { |
121 |
unless ( $title and $content ) { |
| 121 |
$additional_content->delete if $additional_content; |
122 |
if ( $additional_content ) { |
|
|
123 |
eval { $additional_content->delete }; |
| 124 |
unless ($@) { |
| 125 |
logaction('NEWS', 'DELETE' , undef, sprintf("%s|%s|%s|%s", $additional_content->code, $additional_content->title, $additional_content->lang, $additional_content->content)); |
| 126 |
} |
| 127 |
} |
| 122 |
next; |
128 |
next; |
| 123 |
} elsif ( $additional_content ) { |
129 |
} elsif ( $additional_content ) { |
|
|
130 |
my $updated; |
| 124 |
eval { |
131 |
eval { |
| 125 |
$additional_content->update( |
132 |
$additional_content->set( |
| 126 |
{ |
133 |
{ |
| 127 |
category => $category, |
134 |
category => $category, |
| 128 |
code => $code, |
135 |
code => $code, |
|
Lines 137-148
elsif ( $op eq 'add_validate' ) {
Link Here
|
| 137 |
borrowernumber => $borrowernumber, |
144 |
borrowernumber => $borrowernumber, |
| 138 |
} |
145 |
} |
| 139 |
); |
146 |
); |
|
|
147 |
$updated = $additional_content->_result->get_dirty_columns; |
| 148 |
$additional_content->store; |
| 140 |
}; |
149 |
}; |
| 141 |
if ($@) { |
150 |
if ($@) { |
| 142 |
$success = 0; |
151 |
$success = 0; |
| 143 |
push @messages, { type => 'error', code => 'error_on_update' }; |
152 |
push @messages, { type => 'error', code => 'error_on_update' }; |
| 144 |
last; |
153 |
last; |
| 145 |
} |
154 |
} |
|
|
155 |
|
| 156 |
logaction('NEWS', 'MODIFY' , undef, sprintf("%s|%s|%s|%s", $code, $title, $lang, $content)) |
| 157 |
if C4::Context->preference("NewsLog") && $updated; |
| 146 |
} |
158 |
} |
| 147 |
else { |
159 |
else { |
| 148 |
my $additional_content = Koha::AdditionalContent->new( |
160 |
my $additional_content = Koha::AdditionalContent->new( |
|
Lines 166-171
elsif ( $op eq 'add_validate' ) {
Link Here
|
| 166 |
push @messages, { type => 'error', code => 'error_on_insert' }; |
178 |
push @messages, { type => 'error', code => 'error_on_insert' }; |
| 167 |
last; |
179 |
last; |
| 168 |
} |
180 |
} |
|
|
181 |
|
| 182 |
logaction('NEWS', 'ADD' , undef, sprintf("%s|%s|%s|%s", $code, $title, $lang, $content)) |
| 183 |
if C4::Context->preference("NewsLog"); |
| 169 |
} |
184 |
} |
| 170 |
|
185 |
|
| 171 |
} |
186 |
} |
|
Lines 173-180
elsif ( $op eq 'add_validate' ) {
Link Here
|
| 173 |
} |
188 |
} |
| 174 |
elsif ( $op eq 'delete_confirmed' ) { |
189 |
elsif ( $op eq 'delete_confirmed' ) { |
| 175 |
my @ids = $cgi->multi_param('ids'); |
190 |
my @ids = $cgi->multi_param('ids'); |
| 176 |
my $deleted = |
191 |
my $deleted = eval { |
| 177 |
eval { Koha::AdditionalContents->search( { idnew => \@ids } )->delete; }; |
192 |
|
|
|
193 |
my $schema = Koha::Database->new->schema; |
| 194 |
$schema->txn_do( |
| 195 |
sub { |
| 196 |
my $contents = |
| 197 |
Koha::AdditionalContents->search( { idnew => \@ids } ); |
| 198 |
|
| 199 |
if ( C4::Context->preference("NewsLog") ) { |
| 200 |
while ( my $c = $contents->next ) { |
| 201 |
logaction('NEWS', 'DELETE' , undef, sprintf("%s|%s|%s|%s", $c->code, $c->title, $c->lang, $c->content)); |
| 202 |
} |
| 203 |
} |
| 204 |
$contents->delete; |
| 205 |
} |
| 206 |
); |
| 207 |
}; |
| 178 |
|
208 |
|
| 179 |
if ( $@ or not $deleted ) { |
209 |
if ( $@ or not $deleted ) { |
| 180 |
push @messages, { type => 'error', code => 'error_on_delete' }; |
210 |
push @messages, { type => 'error', code => 'error_on_delete' }; |
| 181 |
- |
|
|