# TODO This script drives the CRUD operations on the letter table
# The DB interaction should be handled by calls to C4/Letters.pm
-use strict;
-use warnings;
+use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Auth;
use C4::Context;
use C4::Output;
use C4::Letters;
-use C4::Members::Attributes;
+
+use Koha::Patron::Attribute::Types;
# $protected_letters = protected_letters()
# - return a hashref of letter_codes representing letters that should never be deleted
my $module = $input->param('module') || '';
my $content = $input->param('content');
my $op = $input->param('op') || '';
-my $redirect = $input->param('redirect');
+my $redirect = $input->param('redirect');
+my $section = $input->param('section');
+
my $dbh = C4::Context->dbh;
our ( $template, $borrowernumber, $cookie, $staffflags ) = get_template_and_user(
template_name => 'tools/letter.tt',
query => $input,
type => 'intranet',
- authnotrequired => 0,
flagsrequired => { tools => 'edit_notices' },
debug => 1,
}
script_name => $script_name,
searchfield => $searchfield,
branchcode => $branchcode,
+ section => $section,
action => $script_name
);
if ( $op eq 'add_validate' or $op eq 'copy_validate' ) {
add_validate();
if( $redirect eq "just_save" ){
- print $input->redirect("/cgi-bin/koha/tools/letter.pl?op=add_form&branchcode=$branchcode&module=$module&code=$code&redirect=done");
+ print $input->redirect("/cgi-bin/koha/tools/letter.pl?op=add_form&branchcode=$branchcode&module=$module&code=$code&redirect=done§ion=$section");
exit;
} else {
$op = q{}; # we return to the default screen for the next operation
code => $code,
);
my $first_flag_name = 1;
- my ( $lang, @templates );
+ my $lang;
# The letter name is contained into each mtt row.
# So we can only sent the first one to the template.
for my $letter ( @$letters ) {
$letters{ $lang }{templates}{$mtt} = {
message_transport_type => $letter->{message_transport_type},
is_html => $letter->{is_html},
+ updated_on => $letter->{updated_on},
title => $letter->{title},
content => $letter->{content} // '',
};
push @{$field_selection}, add_fields('aqbooksellers', 'aqbasket', 'aqorders', 'biblio', 'biblioitems');
}
elsif ($module eq 'claimissues') {
- push @{$field_selection}, add_fields('aqbooksellers', 'serial', 'subscription');
- push @{$field_selection},
- {
- value => q{},
- text => '---BIBLIO---'
- };
- foreach(qw(title author serial)) {
- push @{$field_selection}, {value => "biblio.$_", text => ucfirst $_ };
- }
+ push @{$field_selection}, add_fields('aqbooksellers', 'serial', 'subscription', 'biblio', 'biblioitems');
}
elsif ($module eq 'serial') {
push @{$field_selection}, add_fields('branches', 'biblio', 'biblioitems', 'borrowers', 'subscription', 'serial');
push @{$field_selection}, add_fields('issues');
}
- if ( $module eq 'circulation' and $code =~ /^AR_/ ) {
+ if ( $module eq 'circulation' and $code and $code =~ /^AR_/ ) {
push @{$field_selection}, add_fields('article_requests');
}
+
+ if ( $module eq 'members' and $code and $code eq 'PROBLEM_REPORT' ) {
+ push @{$field_selection}, add_fields('problem_reports');
+ }
+ }
+
+ my $preview_is_available = 0;
+
+ if ($code) {
+ $preview_is_available = grep {$_ eq $code } qw( CHECKIN CHECKOUT HOLD_SLIP );
}
$template->param(
module => $module,
SQLfieldnames => $field_selection,
branchcode => $branchcode,
+ preview_is_available => $preview_is_available,
);
return;
}
my @content = $input->multi_param('content');
my @lang = $input->multi_param('lang');
for my $mtt ( @mtt ) {
- my $is_html = $input->param("is_html_$mtt");
+ my $lang = shift @lang;
+ my $is_html = $input->param("is_html_$mtt\_$lang");
my $title = shift @title;
my $content = shift @content;
- my $lang = shift @lang;
my $letter = C4::Letters::getletter( $oldmodule, $code, $branchcode, $mtt, $lang );
# getletter can return the default letter even if we pass a branchcode
my $dbh = C4::Context->dbh;
my ($sql, @where, @args);
- $sql = "SELECT branchcode, module, code, name, branchname
+ $sql = "SELECT branchcode, module, code, name, branchname, MAX(updated_on) as updated_on
FROM letter
LEFT OUTER JOIN branches USING (branchcode)
";
}
$sql .= " WHERE ".join(" AND ", @where) if @where;
- $sql .= " GROUP BY branchcode,module,code";
+ $sql .= " GROUP BY branchcode,module,code,name,branchname";
+
$sql .= " ORDER BY module, code, branchcode";
return $dbh->selectall_arrayref($sql, { Slice => {} }, @args);
}
}
if ($table eq 'borrowers') {
- if ( my $attributes = C4::Members::Attributes::GetAttributes() ) {
- foreach (@$attributes) {
- push @fields, {
- value => "borrower-attribute:$_",
- text => "attribute:$_",
- }
+ my $attribute_types = Koha::Patron::Attribute::Types->search(
+ {},
+ { order_by => 'code' },
+ );
+ while ( my $at = $attribute_types->next ) {
+ push @fields, {
+ value => "borrower-attribute:" . $at->code,
+ text => "attribute:" . $at->code,
}
}
}