Bug 25771: Allow the user to sort checkouts by the renew column in the OPAC
[koha-ffzg.git] / tools / letter.pl
index f1a234b..7af71dd 100755 (executable)
@@ -66,7 +66,9 @@ my $code        = $input->param('code');
 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(
@@ -74,7 +76,6 @@ 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,
     }
@@ -90,13 +91,14 @@ $template->param(
        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&section=$section");
         exit;
     } else {
         $op = q{}; # we return to the default screen for the next operation
@@ -188,7 +190,7 @@ sub add_form {
             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 ) {
@@ -205,6 +207,7 @@ sub add_form {
             $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} // '',
             };
@@ -258,12 +261,16 @@ sub add_form {
         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 {/^$code$/} qw( CHECKIN CHECKOUT HOLD_SLIP );
+        $preview_is_available = grep {$_ eq $code } qw( CHECKIN CHECKOUT HOLD_SLIP );
     }
 
     $template->param(
@@ -287,10 +294,10 @@ sub add_validate {
     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
@@ -361,7 +368,7 @@ sub retrieve_letters {
 
     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)
     ";