Bugzilla – Attachment 148188 Details for
Bug 29393
Ability to send emails from patron details page
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29393: Ability to send emails from patron details page
Bug-29393-Ability-to-send-emails-from-patron-detai.patch (text/plain), 11.51 KB, created by
Fridolin Somers
on 2023-03-14 20:43:25 UTC
(
hide
)
Description:
Bug 29393: Ability to send emails from patron details page
Filename:
MIME Type:
Creator:
Fridolin Somers
Created:
2023-03-14 20:43:25 UTC
Size:
11.51 KB
patch
obsolete
>From 7d682da0bc2c83443210edcac18106f09f350dd7 Mon Sep 17 00:00:00 2001 >From: Alex Arnaud <alex.arnaud@biblibre.com> >Date: Tue, 2 Nov 2021 16:16:29 +0100 >Subject: [PATCH] Bug 29393: Ability to send emails from patron details page > >Test plan > - apply Bug 12802 > - go to a patron's details page > - click on "Add message" in tools bar > - choose "Email" in "Add a message for" > - Select a notice (module members) or manualy fill the message > - Save > - Check the message is saved in message_queue table >--- > Koha/Template/Plugin/NoticeTemplates.pm | 55 ++++++++++++++ > circ/add_message.pl | 44 ++++++++++-- > .../prog/en/includes/members-toolbar.inc | 29 +++++++- > .../intranet-tmpl/prog/js/members-menu.js | 33 +++++++++ > .../Template/Plugin/NoticeTemplates.t | 71 +++++++++++++++++++ > 5 files changed, 224 insertions(+), 8 deletions(-) > create mode 100644 Koha/Template/Plugin/NoticeTemplates.pm > create mode 100644 t/db_dependent/Template/Plugin/NoticeTemplates.t > >diff --git a/Koha/Template/Plugin/NoticeTemplates.pm b/Koha/Template/Plugin/NoticeTemplates.pm >new file mode 100644 >index 0000000000..fe6ed61214 >--- /dev/null >+++ b/Koha/Template/Plugin/NoticeTemplates.pm >@@ -0,0 +1,55 @@ >+package Koha::Template::Plugin::NoticeTemplates; >+ >+# Copyright 2021 BibLibre >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Template::Plugin; >+use base qw( Template::Plugin ); >+ >+use Koha::Notice::Templates; >+ >+sub GetByModule { >+ my ( $self, $module ) = @_; >+ >+ return Koha::Notice::Templates->search({ module => $module }); >+} >+ >+=head1 NAME >+ >+Koha::Template::Plugin::NoticeTemplates - TT Plugin for notice templates >+ >+=head1 SYNOPSIS >+ >+[% USE NoticeTemplates %] >+ >+[% NoticeTemplates.GetByModule('members') %] >+ >+=head1 ROUTINES >+ >+=head2 GetByModule >+ >+In a template, you can get notice templates by module with >+[% letters = NoticeTemplates.GetByModule( 'members' ) %] >+ >+=head1 AUTHOR >+ >+Alex Arnaud <alex.arnaud@biblibre.com> >+ >+=cut >+1; >diff --git a/circ/add_message.pl b/circ/add_message.pl >index ee90af3522..7dbbc7aa13 100755 >--- a/circ/add_message.pl >+++ b/circ/add_message.pl >@@ -23,6 +23,7 @@ use CGI qw ( -utf8 ); > > use C4::Auth qw( get_template_and_user ); > use C4::Output; >+use C4::Letters; > use Koha::Patron::Message; > > my $input = CGI->new; >@@ -39,16 +40,45 @@ my $borrowernumber = $input->param('borrowernumber'); > my $branchcode = $input->param('branchcode'); > my $message_type = $input->param('message_type'); > my $borrower_message = $input->param('borrower_message'); >+my $borrower_subject = $input->param('borrower_subject'); >+my $letter_code = $input->param('select_patron_notice'); > my $batch = $input->param('batch'); > >-Koha::Patron::Message->new( >- { >- borrowernumber => $borrowernumber, >- branchcode => $branchcode, >- message_type => $message_type, >- message => $borrower_message, >+if ( $message_type eq 'L' or $message_type eq 'B' ) { >+ Koha::Patron::Message->new( >+ { >+ borrowernumber => $borrowernumber, >+ branchcode => $branchcode, >+ message_type => $message_type, >+ message => $borrower_message, >+ } >+ )->store; >+} >+ >+if ( $message_type eq 'E' ) { >+ my $letter = { >+ title => $borrower_subject, >+ content => $borrower_message >+ }; >+ >+ if ( $letter_code ) { >+ $letter = C4::Letters::GetPreparedLetter( >+ module => 'members', >+ letter_code => $letter_code, >+ tables => { >+ 'borrowers' => $borrowernumber >+ }, >+ ); > } >-)->store; >+ >+ C4::Letters::EnqueueLetter( >+ { >+ letter => $letter, >+ borrowernumber => $borrowernumber, >+ message_transport_type => 'email', >+ } >+ ) or warn "can't enqueue letter"; >+} > > my $url = $input->referer; > if ( $url ) { >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc >index 311044ad71..d4e4eee990 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc >@@ -3,6 +3,7 @@ > [% USE Branches %] > [% USE Categories %] > [% USE AuthorisedValues %] >+[% USE NoticeTemplates %] > [% USE scalar %] > <div id="toolbar" class="btn-toolbar"> > [% IF CAN_user_borrowers_edit_borrowers %] >@@ -121,6 +122,7 @@ > <select name="message_type" id="message_type"> > <option value="L">Staff - Internal note</option> > <option value="B">OPAC - [% patron.firstname | html %] [% patron.surname | html %]</option> >+ <option value="E">Email - email addresses of patron</option> > </select> > </div> > [% bor_notes = AuthorisedValues.Get( 'BOR_NOTES' ) %] >@@ -135,8 +137,33 @@ > </select> > </div> > [% END %] >+ >+ [% patron_letters = NoticeTemplates.GetByModule( 'members' ) %] >+ [% IF patron_letters %] >+ <div class="form-group"> >+ <label for="select_patron_notice" style="display:none;">Patron notice: </label> >+ <select name="select_patron_notice" id="select_patron_notice" style="display:none;"> >+ <option value="">Select notice</option> >+ [% FOREACH letter IN patron_letters %] >+ <option value="[% letter.code | html %]">[% letter.name | html %]</option> >+ [% END %] >+ </select> >+ </div> >+ [% END %] >+ > <div class="form-group"> >- <textarea rows="3" class="modal-textarea" name="borrower_message" id="borrower_message" ></textarea> >+ <fieldset class="rows"> >+ <ol> >+ <li id="subject_form" style="display: none;"> >+ <label for="borrower_subject">Subject:</label> >+ <input type="text" size="60" name="borrower_subject" id="borrower_subject"/> >+ </li> >+ <li> >+ <label for="borrower_message" style="display: none;">Body:</label> >+ <textarea cols="65" rows="5" name="borrower_message" id="borrower_message" ></textarea> >+ </li> >+ </ol> >+ </fieldset> > </div> > <input type="hidden" name="borrowernumber" value="[% patron.borrowernumber | html %]" /> > <input type="hidden" name="batch" value="[% batch | html %]" /> >diff --git a/koha-tmpl/intranet-tmpl/prog/js/members-menu.js b/koha-tmpl/intranet-tmpl/prog/js/members-menu.js >index b020966e58..8be196ed84 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/members-menu.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/members-menu.js >@@ -86,6 +86,39 @@ $(document).ready(function(){ > startup(); > }); > >+ $("#message_type").on("change",function(){ >+ if ($(this).val() == 'E') { >+ $("label[for='borrower_message']").show(); >+ $('#subject_form').show(); >+ $("label[for='select_patron_notice']").show(); >+ $('#select_patron_notice').show(); >+ $("label[for='select_patron_messages']").hide(); >+ $('#select_patron_messages').hide(); >+ $('#borrower_message').val(''); >+ $('#select_patron_notice').val(''); >+ } else { >+ $('#subject_form').hide(); >+ $("label[for='borrower_message']").hide(); >+ $("label[for='select_patron_notice']").hide(); >+ $('#select_patron_notice').hide(); >+ $("label[for='select_patron_messages']").show(); >+ $('#select_patron_messages').show(); >+ $('#borrower_subject').prop( "disabled", false ); >+ $('#borrower_message').prop( "disabled", false ); >+ $('#select_patron_messages').val(''); >+ } >+ }); >+ >+ $("#select_patron_notice").on("change",function(){ >+ if ($(this).val()) { >+ $('#borrower_subject').prop( "disabled", true ); >+ $('#borrower_message').prop( "disabled", true ); >+ } else { >+ $('#borrower_subject').prop( "disabled", false ); >+ $('#borrower_message').prop( "disabled", false ); >+ } >+ }); >+ > $(".edit-patronimage").on("click", function(e){ > e.preventDefault(); > var borrowernumber = $(this).data("borrowernumber"); >diff --git a/t/db_dependent/Template/Plugin/NoticeTemplates.t b/t/db_dependent/Template/Plugin/NoticeTemplates.t >new file mode 100644 >index 0000000000..84e38578d6 >--- /dev/null >+++ b/t/db_dependent/Template/Plugin/NoticeTemplates.t >@@ -0,0 +1,71 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 4; >+ >+use Koha::Database; >+use Koha::Notice::Templates; >+ >+use t::lib::TestBuilder; >+ >+BEGIN { >+ use_ok('Koha::Template::Plugin::NoticeTemplates'); >+} >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+$schema->storage->txn_begin; >+ >+Koha::Notice::Templates->delete(); >+ >+my $notice_templates = Koha::Notice::Templates->search({ module => 'members'}); >+ >+$builder->build({ >+ source => 'Letter', >+ value => { >+ name => 'Hold cancellation', >+ module => 'reserves' >+ } >+}); >+ >+$builder->build({ >+ source => 'Letter', >+ value => { >+ name => 'Account expiration', >+ module => 'members' >+ } >+}); >+ >+$builder->build({ >+ source => 'Letter', >+ value => { >+ name => 'Discharge', >+ module => 'members' >+ } >+}); >+ >+my $plugin = Koha::Template::Plugin::NoticeTemplates->new(); >+ok($plugin, "initialized notice templates plugin"); >+ >+my $notices = $plugin->GetByModule('members'); >+is( $notices->count, 2, 'returns 2 defined members letters' ); >+ >+$notices = $plugin->GetByModule('reserves'); >+is( $notices->count, 1, 'returns 2 defined reserves letters' ); >+ >+$schema->storage->txn_rollback; >-- >2.39.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29393
:
127237
|
127238
|
127452
|
127506
|
127511
|
127847
|
128215
|
128216
|
128217
|
128218
|
128219
|
128363
|
148187
|
148188
|
148189
|
148190
|
148191
|
148192
|
148193
|
148194
|
149812
|
160107
|
160108
|
160109
|
160110
|
160111
|
160112
|
160113
|
160114
|
160633
|
160638
|
160639
|
165498
|
165499
|
165500
|
165501
|
165502
|
165503
|
165504
|
165505
|
165511
|
165512
|
165513
|
165514
|
165515
|
165516
|
165517
|
165518
|
165519
|
165520
|
165521
|
165522
|
165942