|
Lines 38-51
use Koha::AdditionalContents;
Link Here
|
| 38 |
|
38 |
|
| 39 |
my $cgi = CGI->new; |
39 |
my $cgi = CGI->new; |
| 40 |
|
40 |
|
| 41 |
my $op = $cgi->param('op') || 'list'; |
41 |
my $op = $cgi->param('op') || 'list'; |
| 42 |
my $id = $cgi->param('id'); |
42 |
my $id = $cgi->param('id'); |
| 43 |
my $category = $cgi->param('category') || 'news'; |
43 |
my $category = $cgi->param('category') || 'news'; |
| 44 |
my $wysiwyg; |
44 |
my $wysiwyg; |
| 45 |
my $redirect = $cgi->param('redirect'); |
45 |
my $redirect = $cgi->param('redirect'); |
| 46 |
my $editmode; |
46 |
my $editmode; |
| 47 |
|
47 |
|
| 48 |
if( $cgi->param('editmode') ){ |
48 |
if ( $cgi->param('editmode') ) { |
| 49 |
$wysiwyg = $cgi->param('editmode') eq "wysiwyg" ? 1 : 0; |
49 |
$wysiwyg = $cgi->param('editmode') eq "wysiwyg" ? 1 : 0; |
| 50 |
} else { |
50 |
} else { |
| 51 |
$wysiwyg = C4::Context->preference("AdditionalContentsEditor") eq "tinymce" ? 1 : 0; |
51 |
$wysiwyg = C4::Context->preference("AdditionalContentsEditor") eq "tinymce" ? 1 : 0; |
|
Lines 55-68
$editmode = $wysiwyg eq 1 ? "wysiwyg" : "text";
Link Here
|
| 55 |
|
55 |
|
| 56 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
56 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
| 57 |
{ |
57 |
{ |
| 58 |
template_name => "tools/additional-contents.tt", |
58 |
template_name => "tools/additional-contents.tt", |
| 59 |
query => $cgi, |
59 |
query => $cgi, |
| 60 |
type => "intranet", |
60 |
type => "intranet", |
| 61 |
flagsrequired => { tools => 'edit_additional_contents' }, |
61 |
flagsrequired => { tools => 'edit_additional_contents' }, |
| 62 |
} |
62 |
} |
| 63 |
); |
63 |
); |
| 64 |
|
64 |
|
| 65 |
my @messages; |
65 |
my @messages; |
|
|
66 |
my $my_branch = |
| 67 |
C4::Context->preference("IndependentBranches") |
| 68 |
&& !C4::Context->IsSuperLibrarian() |
| 69 |
? C4::Context->userenv()->{'branch'} |
| 70 |
: undef; |
| 66 |
if ( $op eq 'add_form' ) { |
71 |
if ( $op eq 'add_form' ) { |
| 67 |
|
72 |
|
| 68 |
my $additional_content = Koha::AdditionalContents->find($id); |
73 |
my $additional_content = Koha::AdditionalContents->find($id); |
|
Lines 72-92
if ( $op eq 'add_form' ) {
Link Here
|
| 72 |
$category = $additional_content->category; |
77 |
$category = $additional_content->category; |
| 73 |
} |
78 |
} |
| 74 |
$template->param( |
79 |
$template->param( |
| 75 |
additional_content => $additional_content, |
80 |
my_branch => $my_branch, |
|
|
81 |
additional_content => $additional_content, |
| 76 |
translated_contents => $translated_contents, |
82 |
translated_contents => $translated_contents, |
| 77 |
); |
83 |
); |
| 78 |
} |
84 |
} elsif ( $op eq 'cud-add_validate' ) { |
| 79 |
elsif ( $op eq 'cud-add_validate' ) { |
|
|
| 80 |
output_and_exit_if_error( $cgi, $cookie, $template, { check => 'csrf_token' } ); |
85 |
output_and_exit_if_error( $cgi, $cookie, $template, { check => 'csrf_token' } ); |
| 81 |
my $location = $cgi->param('location'); |
86 |
my $location = $cgi->param('location'); |
| 82 |
my $code = $cgi->param('code'); |
87 |
my $code = $cgi->param('code'); |
| 83 |
my $branchcode = $cgi->param('branchcode') || undef; |
88 |
my $branchcode = $my_branch ? $my_branch : $cgi->param('branchcode') || undef; |
|
|
89 |
my $idnew = $cgi->param('idnew'); |
| 84 |
|
90 |
|
| 85 |
my @lang = $cgi->multi_param('lang'); |
91 |
my @lang = $cgi->multi_param('lang'); |
| 86 |
|
92 |
|
| 87 |
my $expirationdate = $cgi->param('expirationdate'); |
93 |
my $expirationdate = $cgi->param('expirationdate'); |
| 88 |
my $published_on = $cgi->param('published_on'); |
94 |
my $published_on = $cgi->param('published_on'); |
| 89 |
my $number = $cgi->param('number'); |
95 |
my $number = $cgi->param('number'); |
| 90 |
|
96 |
|
| 91 |
try { |
97 |
try { |
| 92 |
Koha::Database->new->schema->txn_do( |
98 |
Koha::Database->new->schema->txn_do( |
|
Lines 181-208
elsif ( $op eq 'cud-add_validate' ) {
Link Here
|
| 181 |
} |
187 |
} |
| 182 |
}; |
188 |
}; |
| 183 |
|
189 |
|
| 184 |
if( $redirect eq "just_save" ){ |
190 |
if ( $redirect eq "just_save" ) { |
| 185 |
print $cgi->redirect("/cgi-bin/koha/tools/additional-contents.pl?op=add_form&id=$id&category=$category&editmode=$editmode&redirect=done"); |
191 |
print $cgi->redirect( |
|
|
192 |
"/cgi-bin/koha/tools/additional-contents.pl?op=add_form&id=$id&category=$category&editmode=$editmode&redirect=done" |
| 193 |
); |
| 186 |
exit; |
194 |
exit; |
| 187 |
} else { |
195 |
} else { |
| 188 |
$op = 'list'; |
196 |
$op = 'list'; |
| 189 |
} |
197 |
} |
| 190 |
} |
198 |
} elsif ( $op eq 'cud-delete_confirmed' ) { |
| 191 |
elsif ( $op eq 'cud-delete_confirmed' ) { |
199 |
output_and_exit_if_error( $cgi, $cookie, $template, { check => 'csrf_token' } ); |
| 192 |
output_and_exit_if_error($cgi, $cookie, $template, { check => 'csrf_token' }); |
|
|
| 193 |
my @ids = $cgi->multi_param('ids'); |
200 |
my @ids = $cgi->multi_param('ids'); |
| 194 |
|
201 |
|
| 195 |
try { |
202 |
try { |
| 196 |
Koha::Database->new->schema->txn_do( |
203 |
Koha::Database->new->schema->txn_do( |
| 197 |
sub { |
204 |
sub { |
| 198 |
my $contents = |
205 |
my $contents = Koha::AdditionalContents->search( { id => \@ids } ); |
| 199 |
Koha::AdditionalContents->search( { id => \@ids } ); |
|
|
| 200 |
|
206 |
|
| 201 |
if ( C4::Context->preference("NewsLog") ) { |
207 |
if ( C4::Context->preference("NewsLog") ) { |
| 202 |
while ( my $c = $contents->next ) { |
208 |
while ( my $c = $contents->next ) { |
| 203 |
my $translated_contents = $c->translated_contents; |
209 |
my $translated_contents = $c->translated_contents; |
| 204 |
while ( my $translated_content = $translated_contents->next ) { |
210 |
while ( my $translated_content = $translated_contents->next ) { |
| 205 |
logaction('NEWS', 'DELETE' , undef, sprintf("%s|%s|%s|%s", $c->code, $translated_content->lang, $translated_content->content)); |
211 |
logaction( |
|
|
212 |
'NEWS', 'DELETE', undef, |
| 213 |
sprintf( |
| 214 |
"%s|%s|%s|%s", $c->code, $translated_content->lang, $translated_content->content |
| 215 |
) |
| 216 |
); |
| 206 |
} |
217 |
} |
| 207 |
} |
218 |
} |
| 208 |
} |
219 |
} |
|
Lines 220-229
elsif ( $op eq 'cud-delete_confirmed' ) {
Link Here
|
| 220 |
|
231 |
|
| 221 |
if ( $op eq 'list' ) { |
232 |
if ( $op eq 'list' ) { |
| 222 |
my $additional_contents = Koha::AdditionalContents->search( |
233 |
my $additional_contents = Koha::AdditionalContents->search( |
| 223 |
{ category => $category, 'additional_contents_localizations.lang' => 'default' }, |
234 |
{ category => $category, 'additional_contents_localizations.lang' => 'default' }, |
| 224 |
{ order_by => { -desc => 'published_on' }, join => 'additional_contents_localizations' } |
235 |
{ order_by => { -desc => 'published_on' }, join => 'additional_contents_localizations' } |
| 225 |
); |
236 |
); |
| 226 |
$template->param( additional_contents => $additional_contents ); |
237 |
$template->param( additional_contents => $additional_contents, my_branch => $my_branch ); |
| 227 |
} |
238 |
} |
| 228 |
|
239 |
|
| 229 |
my $translated_languages = C4::Languages::getTranslatedLanguages; |
240 |
my $translated_languages = C4::Languages::getTranslatedLanguages; |
|
Lines 232-255
for my $language (@$translated_languages) {
Link Here
|
| 232 |
for my $sublanguage ( @{ $language->{sublanguages_loop} } ) { |
243 |
for my $sublanguage ( @{ $language->{sublanguages_loop} } ) { |
| 233 |
if ( $language->{plural} ) { |
244 |
if ( $language->{plural} ) { |
| 234 |
push @languages, |
245 |
push @languages, |
| 235 |
{ |
246 |
{ |
| 236 |
lang => $sublanguage->{rfc4646_subtag}, |
247 |
lang => $sublanguage->{rfc4646_subtag}, |
| 237 |
description => $sublanguage->{native_description} . ' ' |
248 |
description => $sublanguage->{native_description} . ' ' |
| 238 |
. $sublanguage->{region_description} . ' (' |
249 |
. $sublanguage->{region_description} . ' (' |
| 239 |
. $sublanguage->{rfc4646_subtag} . ')', |
250 |
. $sublanguage->{rfc4646_subtag} . ')', |
| 240 |
}; |
251 |
}; |
| 241 |
} |
252 |
} else { |
| 242 |
else { |
|
|
| 243 |
push @languages, |
253 |
push @languages, |
| 244 |
{ |
254 |
{ |
| 245 |
lang => $sublanguage->{rfc4646_subtag}, |
255 |
lang => $sublanguage->{rfc4646_subtag}, |
| 246 |
description => $sublanguage->{native_description} . ' (' |
256 |
description => $sublanguage->{native_description} . ' (' . $sublanguage->{rfc4646_subtag} . ')', |
| 247 |
. $sublanguage->{rfc4646_subtag} . ')', |
257 |
}; |
| 248 |
}; |
|
|
| 249 |
} |
258 |
} |
| 250 |
} |
259 |
} |
| 251 |
} |
260 |
} |
| 252 |
unshift @languages, {lang => 'default'} if @languages; |
261 |
unshift @languages, { lang => 'default' } if @languages; |
| 253 |
|
262 |
|
| 254 |
$template->param( |
263 |
$template->param( |
| 255 |
op => $op, |
264 |
op => $op, |
| 256 |
- |
|
|