Bug 20518: Don't show "Messages" header and link on patron details if there are no...
authorOwen Leonard <oleonard@myacpl.org>
Wed, 4 Apr 2018 16:33:34 +0000 (16:33 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 11 Apr 2018 19:45:09 +0000 (16:45 -0300)
This patch modifies the patron detail page so that the "Messages" header
is not displayed if there are no messages.

Unrelated: A minor change was made to moremember.pl to quiet an error in
the log, "Use of uninitialized value $print in string eq at
members/moremember.pl line 219."

To test, apply the patch and open the detail page for a patron who has
no messages. There should be no "Messages" header or "add message" link.

Add a message to the patron's account. The message should appear, along
with the "Messages" header and "add message" link.

The error logs should show no errors.

Signed-off-by: Maksim Sen <maksim.sen@inlibro.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt
members/moremember.pl

index 44cdb94..163fb13 100644 (file)
       </ul>
     </div>
     [% END %]
-    <div id="messages" class="circmessage">
-        <h4>Messages:</h4>
-        <ul>
-            [% FOREACH patron_message IN patron_messages %]
-                <li>
-                    [% IF(patron_message.message_type == "L") %]
-                        <span class="circ-hlt">
-                    [% ELSE %]
-                        <span>
-                    [% END %]
-                        [% patron_message.message_date | $KohaDates %]
-                        [% Branches.GetName( patron_message.branchcode ) %]
-                        [% IF patron_message.manager_id %]
-                            ( <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% patron_message.manager_id %]">[% patron_message.get_column('manager_firstname') %] [% patron_message.get_column('manager_surname') %]</a> )
+
+    [% IF ( patron_messages ) %]
+        <div id="messages" class="circmessage">
+            <h4>Messages:</h4>
+            <ul>
+                [% FOREACH patron_message IN patron_messages %]
+                    <li>
+                        [% IF(patron_message.message_type == "L") %]
+                            <span class="circ-hlt">
+                        [% ELSE %]
+                            <span>
                         [% END %]
-                        <i>"[% patron_message.message | html %]"</i>
-                    </span>
-                    [% IF patron_message.branchcode == branchcode OR Koha.Preference('AllowAllMessageDeletion') %]
-                        <a class="btn btn-link btn-sm" href="/cgi-bin/koha/circ/del_message.pl?message_id=[% patron_message.message_id %]&amp;borrowernumber=[% patron_message.borrowernumber %]&amp;from=moremember" onclick="return confirm(MSG_CONFIRM_DELETE_MESSAGE);"><i class="fa fa-trash"></i> Delete</a>
-                    [% END %]
-                </li>
-            [% END %]
-        </ul>
-        <a id="addnewmessageLabel" href="#add_message_form" class="btn btn-link btn-sm" data-toggle="modal"><i class="fa fa-plus"></i> Add a new message</a>
-    </div>
+                            [% patron_message.message_date | $KohaDates %]
+                            [% Branches.GetName( patron_message.branchcode ) %]
+                            [% IF patron_message.manager_id %]
+                                ( <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% patron_message.manager_id %]">[% patron_message.get_column('manager_firstname') %] [% patron_message.get_column('manager_surname') %]</a> )
+                            [% END %]
+                            <i>"[% patron_message.message | html %]"</i>
+                        </span>
+                        [% IF patron_message.branchcode == branchcode OR Koha.Preference('AllowAllMessageDeletion') %]
+                            <a class="btn btn-link btn-sm" href="/cgi-bin/koha/circ/del_message.pl?message_id=[% patron_message.message_id %]&amp;borrowernumber=[% patron_message.borrowernumber %]&amp;from=moremember" onclick="return confirm(MSG_CONFIRM_DELETE_MESSAGE);"><i class="fa fa-trash"></i> Delete</a>
+                        [% END %]
+                    </li>
+                [% END %]
+            </ul>
+            <a id="addnewmessageLabel" href="#add_message_form" class="btn btn-link btn-sm" data-toggle="modal"><i class="fa fa-plus"></i> Add a new message</a>
+        </div>
+    [% END %]
 
     [% IF ( flagged ) %]
     <div id="circmessages" class="circmessage attention">
index 0f7eddd..f898adb 100755 (executable)
@@ -216,7 +216,7 @@ my $library = Koha::Libraries->find( $data->{branchcode})->unblessed;
 @{$data}{keys %$library} = values %$library; # merge in all branch columns # FIXME This is really ugly, we should pass the library instead
 
 # If printing a page, send the account informations to the template
-if ($print eq "page") {
+if (defined $print and $print eq "page") {
     my $accts = Koha::Account::Lines->search(
         { borrowernumber => $patron->borrowernumber, amountoutstanding => { '>' => 0 } },
         { order_by       => { -desc => 'accountlines_id' } }
@@ -328,6 +328,9 @@ my $patron_messages = Koha::Patron::Messages->search(
     }
 );
 
+if( $patron_messages->count > 0 ){
+    $template->param( patron_messages => $patron_messages );
+}
 
 # Display the language description instead of the code
 # Note that this is certainly wrong
@@ -353,7 +356,6 @@ $template->param(
     PatronsPerPage => C4::Context->preference("PatronsPerPage") || 20,
     relatives_issues_count => $relatives_issues_count,
     relatives_borrowernumbers => \@relatives,
-    patron_messages       => $patron_messages,
 );
 
 output_html_with_http_headers $input, $cookie, $template->output;