Bugzilla – Attachment 21165 Details for
Bug 9016
Multi transport types for notices
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 9016: Create a message for each transport type.
Bug-9016-Create-a-message-for-each-transport-type.patch (text/plain), 37.93 KB, created by
Jonathan Druart
on 2013-09-18 11:38:47 UTC
(
hide
)
Description:
Bug 9016: Create a message for each transport type.
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2013-09-18 11:38:47 UTC
Size:
37.93 KB
patch
obsolete
>From cd1787163902118085f5c2ba496d494a480082bb Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Fri, 6 Sep 2013 10:27:04 +0200 >Subject: [PATCH] Bug 9016: Create a message for each transport type. > >This patch adds: >- a new jquery plugin : insertatcaret. >- the ability to define a notice template for each transport type. >- a new routine C4::Letters::GetMessageTransportTypes. > >Test plan: >- Go on tools/letter.pl and check that all existing notices are still > there. >- Modify one. A new empty message is present for sms, print, etc. The > email message is filled with the existant value. >- Add a message for sms for example (don't forget the subject) and save. >- edit again and verify the sms message has been saved. >--- > C4/Letters.pm | 63 ++-- > .../en/lib/jquery/plugins/jquery.insertatcaret.js | 46 +++ > .../intranet-tmpl/prog/en/modules/tools/letter.tt | 330 ++++++++++---------- > t/db_dependent/Letters.t | 23 ++ > tools/letter.pl | 163 ++++++---- > 5 files changed, 391 insertions(+), 234 deletions(-) > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.insertatcaret.js > create mode 100644 t/db_dependent/Letters.t > >diff --git a/C4/Letters.pm b/C4/Letters.pm >index 93bc34d..5a8c6cd 100644 >--- a/C4/Letters.pm >+++ b/C4/Letters.pm >@@ -42,7 +42,7 @@ BEGIN { > $VERSION = 3.07.00.049; > @ISA = qw(Exporter); > @EXPORT = qw( >- &GetLetters &GetPreparedLetter &GetWrappedLetter &addalert &getalert &delalert &findrelatedto &SendAlerts &GetPrintMessages >+ &GetLetters &GetPreparedLetter &GetWrappedLetter &addalert &getalert &delalert &findrelatedto &SendAlerts &GetPrintMessages &GetMessageTransportTypes > ); > } > >@@ -97,20 +97,19 @@ $template->param(LETTERLOOP => \@letterloop); > sub GetLetters { > > # returns a reference to a hash of references to ALL letters... >- my $cat = shift; >+ my ( $cat, $message_transport_type ) = @_; >+ $message_transport_type ||= 'email'; > my %letters; > my $dbh = C4::Context->dbh; > my $sth; >- if (defined $cat) { >- my $query = "SELECT * FROM letter WHERE module = ? ORDER BY name"; >- $sth = $dbh->prepare($query); >- $sth->execute($cat); >- } >- else { >- my $query = "SELECT * FROM letter ORDER BY name"; >- $sth = $dbh->prepare($query); >- $sth->execute; >- } >+ my $query = q{ >+ SELECT * FROM letter WHERE >+ }; >+ $query .= q{ module = ? AND } if defined $cat; >+ $query .= q{ message_transport_type = ? ORDER BY name}; >+ $sth = $dbh->prepare($query); >+ $sth->execute((defined $cat ? $cat : ()), $message_transport_type); >+ > while ( my $letter = $sth->fetchrow_hashref ) { > $letters{ $letter->{'code'} } = $letter->{'name'}; > } >@@ -124,7 +123,8 @@ sub GetLetters { > # short-term fix, our will work. > our %letter; > sub getletter { >- my ( $module, $code, $branchcode ) = @_; >+ my ( $module, $code, $branchcode, $message_transport_type ) = @_; >+ $message_transport_type ||= 'email'; > > $branchcode ||= ''; > >@@ -135,17 +135,22 @@ sub getletter { > $branchcode = C4::Context->userenv->{'branch'}; > } > >- if ( my $l = $letter{$module}{$code}{$branchcode} ) { >+ if ( my $l = $letter{$module}{$code}{$branchcode}{$message_transport_type} ) { > return { %$l }; # deep copy > } > > my $dbh = C4::Context->dbh; >- my $sth = $dbh->prepare("select * from letter where module=? and code=? and (branchcode = ? or branchcode = '') order by branchcode desc limit 1"); >- $sth->execute( $module, $code, $branchcode ); >+ my $sth = $dbh->prepare(q{ >+ SELECT * >+ FROM letter >+ WHERE module=? AND code=? AND (branchcode = ? OR branchcode = '') AND message_transport_type = ? >+ ORDER BY branchcode DESC LIMIT 1 >+ }); >+ $sth->execute( $module, $code, $branchcode, $message_transport_type ); > my $line = $sth->fetchrow_hashref > or return; > $line->{'content-type'} = 'text/html; charset="UTF-8"' if $line->{is_html}; >- $letter{$module}{$code}{$branchcode} = $line; >+ $letter{$module}{$code}{$branchcode}{$message_transport_type} = $line; > return { %$line }; > } > >@@ -447,7 +452,7 @@ sub GetPreparedLetter { > my $letter_code = $params{letter_code} or croak "No letter_code"; > my $branchcode = $params{branchcode} || ''; > >- my $letter = getletter( $module, $letter_code, $branchcode ) >+ my $letter = getletter( $module, $letter_code, $branchcode, $params{message_transport_type} ) > or warn( "No $module $letter_code letter"), > return; > >@@ -836,6 +841,28 @@ ENDSQL > return $sth->fetchall_arrayref({}); > } > >+=head2 GetMessageTransportTypes >+ >+ my @mtt = GetMessageTransportTypes(); >+ >+ returns a list of hashes >+ >+=cut >+ >+sub GetMessageTransportTypes { >+ my $dbh = C4::Context->dbh(); >+ my $sth = $dbh->prepare(" >+ SELECT message_transport_type >+ FROM message_transport_types >+ ORDER BY message_transport_type >+ "); >+ $sth->execute; >+ my @mtts = map{ >+ $_->[0] >+ } @{ $sth->fetchall_arrayref() }; >+ return \@mtts; >+} >+ > =head2 _add_attachements > > named parameters: >diff --git a/koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.insertatcaret.js b/koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.insertatcaret.js >new file mode 100644 >index 0000000..408eb5d >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.insertatcaret.js >@@ -0,0 +1,46 @@ >+/*! >+ * jQuery insertAtCaret >+ * Allows inserting text where the caret is in a textarea >+ * Copyright (c) 2003-2010 phpMyAdmin devel team >+ * Version: 1.0 >+ * Developed by the phpMyAdmin devel team. Modified by Alex King and variaas >+ * http://alexking.org/blog/2003/06/02/inserting-at-the-cursor-using-javascript >+ * http://www.mail-archive.com/jquery-en@googlegroups.com/msg08708.html >+ * Licensed under the GPL license: >+ * http://www.gnu.org/licenses/gpl.html >+ */ >+;(function($) { >+ >+$.fn.insertAtCaret = function (myValue) { >+ >+ return this.each(function() { >+ >+ //IE support >+ if (document.selection) { >+ >+ this.focus(); >+ sel = document.selection.createRange(); >+ sel.text = myValue; >+ this.focus(); >+ >+ } else if (this.selectionStart || this.selectionStart == '0') { >+ >+ //MOZILLA / NETSCAPE support >+ var startPos = this.selectionStart; >+ var endPos = this.selectionEnd; >+ var scrollTop = this.scrollTop; >+ this.value = this.value.substring(0, startPos)+ myValue+ this.value.substring(endPos,this.value.length); >+ this.focus(); >+ this.selectionStart = startPos + myValue.length; >+ this.selectionEnd = startPos + myValue.length; >+ this.scrollTop = scrollTop; >+ >+ } else { >+ >+ this.value += myValue; >+ this.focus(); >+ } >+ }); >+}; >+ >+})(jQuery); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt >index 52e2b83..6a69caf 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt >@@ -1,10 +1,12 @@ > [% INCLUDE 'doc-head-open.inc' %] > <title>Koha › Tools › Notices[% IF ( add_form ) %][% IF ( modify ) %] › Modify notice[% ELSE %] › Add notice[% END %][% END %][% IF ( add_validate ) %] › Notice added[% END %][% IF ( delete_confirm ) %] › Confirm deletion[% END %]</title> >+<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" /> > [% INCLUDE 'doc-head-close.inc' %] > <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/en/css/datatables.css" /> > <script type="text/javascript" src="[% interface %]/[% theme %]/en/lib/jquery/plugins/jquery.dataTables.min.js"></script> > [% INCLUDE 'datatables-strings.inc' %] > <script type="text/javascript" src="[% interface %]/[% theme %]/en/js/datatables.js"></script> >+<script type="text/javascript" src="[% interface %]/[% theme %]/en/lib/jquery/plugins/jquery.insertatcaret.js"></script> > <script type="text/javascript"> > //<![CDATA[ > $(document).ready(function() { >@@ -25,6 +27,33 @@ $(document).ready(function() { > return true; > }); > [% END %] >+ >+ $("#submit").click( function(event) { >+ $("fieldset.mtt").each( function(){ >+ var title = $(this).find('input[name="title"]').val(); >+ var content = $(this).find('textarea[name="content"]').val(); >+ if ( >+ ( title.length == 0 && content.length > 0 ) >+ || ( title.length > 0 && content.length == 0 ) >+ ) { >+ var mtt = $(this).find('input[name="message_transport_type"]').val(); >+ alert("You must specify a title and a content for " + mtt); >+ event.preventDefault(); >+ } >+ } ); >+ return true; >+ }); >+ >+ var sms_limit = 160; >+ $("#content_sms").on("keyup", function(){ >+ var length = $(this).val().length; >+ $("#sms_counter").html(length + "/" + sms_limit); >+ if ( length > sms_limit ) { >+ $("#sms_counter").css("color", "red"); >+ } else { >+ $("#sms_counter").css("color", "black"); >+ } >+ }); > }); > [% IF ( add_form ) %] > >@@ -65,60 +94,25 @@ $(document).ready(function() { > } > } > >- function Check(f) { >- var ok=1; >- var _alertString=""; >- var alertString2; >-/* if (!(isNotNull(window.document.Aform.code))) { >- _alertString += "\n- " + _("Code missing"); >- }*/ >-/* if (!(isNotNull(window.document.Aform.name))) { >- _alertString += "\n- " + _("Name missing"); >- }*/ >- if (_alertString.length==0) { >- document.Aform.submit(); >- } else { >- alertString2 = _("Form not submitted because of the following problem(s)"); >- alertString2 += "\n------------------------------------------------------------------------------------\n"; >- alertString2 += _alertString; >- alert(alertString2); >- } >- } >- // GPL code coming from PhpMyAdmin >- function insertValueQuery() { >- var myQuery = document.Aform.content; >- var myListBox = document.Aform.SQLfieldname; >- >- if(myListBox.options.length > 0) { >- var chaineAj = ""; >- var NbSelect = 0; >- for(var i=0; i<myListBox.options.length; i++) { >- if (myListBox.options[i].selected){ >- NbSelect++; >- if (NbSelect > 1) >- chaineAj += ", "; >- chaineAj += myListBox.options[i].value; >- } >- } >- >- //IE support >- if (document.selection) { >- myQuery.focus(); >- sel = document.selection.createRange(); >- sel.text = chaineAj; >- document.Aform.insert.focus(); >- } >- //MOZILLA/NETSCAPE support >- else if (document.Aform.content.selectionStart || document.Aform.content.selectionStart == "0") { >- var startPos = document.Aform.content.selectionStart; >- var endPos = document.Aform.content.selectionEnd; >- var chaineSql = document.Aform.content.value; >- myQuery.value = chaineSql.substring(0, startPos) +'<<'+ chaineAj+'>>' + chaineSql.substring(endPos, chaineSql.length); >- } else { >- myQuery.value += chaineAj; >- } >- } >- } >+ function insertValueQuery(mtt_id) { >+ var fieldset = $("#" + mtt_id); >+ var myQuery = $(fieldset).find('textarea[name="content"]'); >+ var myListBox = $(fieldset).find('select[name="SQLfieldname"]'); >+ >+ if($(myListBox).find('option').length > 0) { >+ var chaineAj = ""; >+ var NbSelect = 0; >+ $(myListBox).find('option').each( function (){ >+ if ( $(this).attr('selected') ) { >+ NbSelect++; >+ if (NbSelect > 1) >+ chaineAj += ", "; >+ chaineAj += $(this).val(); >+ } >+ } ); >+ $(myQuery).insertAtCaret(chaineAj); >+ } >+ } > [% END %] > //]]> > </script> >@@ -168,75 +162,72 @@ $(document).ready(function() { > </select> > [% END %] > [% END %] >- >-[% IF ( letter ) %] >- <table id="lettert"> >- <thead><tr> >- <th>Library</th> >- <th>Module</th> >- <th>Code</th> >- <th>Name</th> >- <th>Copy notice</th> >- <th> </th> >- <th> </th> >- </tr></thead> >- <tbody> >- [% FOREACH lette IN letter %] >- [% can_edit = lette.branchcode || !independant_branch %] >- [% UNLESS ( loop.odd ) %] >- <tr class="highlight"> >- [% ELSE %] >- <tr> >- [% END %] >- <td>[% lette.branchname || "(All libraries)" %]</td> >- <td>[% lette.module %]</td> >- <td>[% lette.code %]</td> >- <td>[% lette.name %]</td> >- <td style="white-space: nowrap"> >- [% IF !independant_branch || !lette.branchcode %] >- <form method="post" action="/cgi-bin/koha/tools/letter.pl"> >+ [% IF letter %] >+ <table id="lettert"> >+ <thead> >+ <tr> >+ <th>Library</th> >+ <th>Module</th> >+ <th>Code</th> >+ <th>Name</th> >+ <th>Copy notice</th> >+ <th> </th> >+ <th> </th> >+ </tr> >+ </thead> >+ <tbody> >+ [% FOREACH lette IN letter %] >+ [% can_edit = lette.branchcode || !independant_branch %] >+ <tr> >+ <td>[% lette.branchname || "(All libraries)" %]</td> >+ <td>[% lette.module %]</td> >+ <td>[% lette.code %]</td> >+ <td>[% lette.name %]</td> >+ <td style="white-space: nowrap"> >+ [% IF !independant_branch || !lette.branchcode %] >+ <form method="post" action="/cgi-bin/koha/tools/letter.pl"> > <input type="hidden" name="op" value="copy" /> >- <input type="hidden" name="oldbranchcode" value="[% lette.branchcode %]" /> >+ <input type="hidden" name="oldbranchcode" value="[% lette.branchcode %]" /> > <input type="hidden" name="module" value="[% lette.module %]" /> > <input type="hidden" name="code" value="[% lette.code %]" /> >- [% IF independant_branch %] >- <input type="hidden" name="branchcode" value="[% independant_branch %]" /> >- [% ELSE %] >- [% select_for_copy %] >- [% END %] >+ [% IF independant_branch %] >+ <input type="hidden" name="branchcode" value="[% independant_branch %]" /> >+ [% ELSE %] >+ [% select_for_copy %] >+ [% END %] > <input type="submit" value="Copy" /> >- </form> >- [% END %] >- </td> >- <td> >- [% IF can_edit %] >- <a href="/cgi-bin/koha/tools/letter.pl?op=add_form&branchcode=[% lette.branchcode %]&module=[% lette.module %]&code=[% lette.code %]">Edit</a> >- [% END %] >- </td> >- <td> >- [% IF !lette.protected && can_edit %] >- <a href="/cgi-bin/koha/tools/letter.pl?op=delete_confirm&branchcode=[%lette.branchcode %]&module=[% lette.module %]&code=[% lette.code %]">Delete</a> >- [% END %] >- </td> >- </tr> >- [% END %] >- </tbody> >- </table> >-[% ELSE %] >- <div class="dialog message"> >- [% IF ( branchcode ) %] >- <p>There are no notices for this library.</p> >+ </form> >+ [% END %] >+ </td> >+ <td> >+ [% IF can_edit %] >+ <a href="/cgi-bin/koha/tools/letter.pl?op=add_form&branchcode=[% lette.branchcode %]&module=[% lette.module %]&code=[% lette.code %]">Edit</a> >+ [% END %] >+ </td> >+ <td> >+ [% IF !lette.protected && can_edit %] >+ <a href="/cgi-bin/koha/tools/letter.pl?op=delete_confirm&branchcode=[%lette.branchcode %]&module=[% lette.module %]&code=[% lette.code %]">Delete</a> >+ [% END %] >+ </td> >+ </tr> >+ [% END %] >+ </tbody> >+ </table> > [% ELSE %] >- <p>There are no notices.</p> >+ <div class="dialog message"> >+ [% IF ( branchcode ) %] >+ <p>There are no notices for this library.</p> >+ [% ELSE %] >+ <p>There are no notices.</p> >+ [% END %] >+ </div> > [% END %] >- </div> >-[% END %] > [% END %] > > > [% IF ( add_form ) %] > <h1>[% IF ( modify ) %]Modify notice[% ELSE %]Add notice[% END %]</h1> >- <form action="?" name="Aform" method="post"> >+ <form name="Aform" method="post" enctype="multipart/form-data"> > <input type="hidden" name="op" id="op" value="add_validate" /> > <input type="hidden" name="checked" value="0" /> > [% IF ( modify ) %] >@@ -264,45 +255,45 @@ $(document).ready(function() { > <label for="module">Koha module:</label> > <input type="hidden" name="oldmodule" value="[% module %]" /> > [% IF ( modify ) %]<select name="module" id="module">[% END %] [% IF ( adding ) %] <select name="module" id="module" onchange="javascript:window.location.href = unescape(window.location.pathname)+'?op=add_form&module='+this.value+'&content='+window.document.forms['Aform'].elements['content'].value;">[% END %] >- [% IF ( catalogue ) %] >- <option value="catalogue" selected="selected">Catalog</option> >+ [% IF ( module == "catalogue" ) %] >+ <option value="catalogue" selected="selected">Catalog</option> > [% ELSE %] >- <option value="catalogue" >Catalog</option> >+ <option value="catalogue" >Catalog</option> > [% END %] >- [% IF ( circulation ) %] >- <option value="circulation" selected="selected">Circulation</option> >+ [% IF ( module == "circulation" ) %] >+ <option value="circulation" selected="selected">Circulation</option> > [% ELSE %] >- <option value="circulation">Circulation</option> >+ <option value="circulation">Circulation</option> > [% END %] >- [% IF ( claimacquisition ) %] >- <option value="claimacquisition" selected="selected">Claim acquisition</option> >+ [% IF ( module == "claimacquisition" ) %] >+ <option value="claimacquisition" selected="selected">Claim acquisition</option> > [% ELSE %] >- <option value="claimacquisition">Claim acquisition</option> >+ <option value="claimacquisition">Claim acquisition</option> > [% END %] >- [% IF ( claimissues ) %] >- <option value="claimissues" selected="selected">Claim serial issue</option> >+ [% IF ( module == "claimissues" ) %] >+ <option value="claimissues" selected="selected">Claim serial issue</option> > [% ELSE %] >- <option value="claimissues">Claim serial issue</option> >+ <option value="claimissues">Claim serial issue</option> > [% END %] >- [% IF ( reserves ) %] >- <option value="reserves" selected="selected">Holds</option> >+ [% IF ( module == "reserves" ) %] >+ <option value="reserves" selected="selected">Holds</option> > [% ELSE %] >- <option value="reserves">Holds</option> >+ <option value="reserves">Holds</option> > [% END %] >- [% IF ( members ) %] >- <option value="members" selected="selected">Members</option> >+ [% IF ( module == "members" ) %] >+ <option value="members" selected="selected">Members</option> > [% ELSE %] >- <option value="members">Members</option> >+ <option value="members">Members</option> > [% END %] >- [% IF ( serial ) %] >- <option value="serial" selected="selected">Serials (routing list)</option> >+ [% IF ( module == "serial" ) %] >+ <option value="serial" selected="selected">Serials (routing list)</option> > [% ELSE %] >- <option value="serial">Serials (routing list)</option> >+ <option value="serial">Serials (routing list)</option> > [% END %] >- [% IF ( suggestions ) %] >- <option value="suggestions" selected="selected">Suggestions</option> >+ [% IF ( module == "suggestions" ) %] >+ <option value="suggestions" selected="selected">Suggestions</option> > [% ELSE %] >- <option value="suggestions">Suggestions</option> >+ <option value="suggestions">Suggestions</option> > [% END %] > </select> > </li> >@@ -312,33 +303,49 @@ $(document).ready(function() { > <li> > <label for="name">Name:</label><input type="text" id="name" name="name" size="60" value="[% name %]" /> > </li> >- <li> >- <label for="is_html">HTML message:</label> >- [% IF is_html %] >- <input type="checkbox" id="is_html" name="is_html" value="1" checked /> >- [% ELSE %] >- <input type="checkbox" id="is_html" name="is_html" value="1" /> >- [% END %] >- </li> >- <li> >- <label for="title">Message subject:</label><input type="text" id="title" name="title" size="60" value="[% title %]" /> >- </li> >- <li> >- <label for="SQLfieldname">Message body:</label> >- </li> >- <li> >- <table> >- <tr><td><select name="SQLfieldname" id="SQLfieldname" size="9"> >- [% FOREACH SQLfieldnam IN SQLfieldname %] >- <option value="[% SQLfieldnam.value %]">[% SQLfieldnam.text %]</option> >- [% END %] >- </select></td><td><input type="button" name="insert" value=">>" onclick="insertValueQuery()" title="Insert" /></td><td><textarea name="content" cols="80" rows="15">[% content %]</textarea></td></tr></table> > >- </li> >- </ol> >- [% IF code.search('DGST') %] <span class="overdue">Warning, this is a template for a Digest, as such, any references to branch data ( e.g. branches.branchname ) will refer to the borrower's home branch.</span> [% END %] >+ [% FOREACH letter IN letters %] >+ <li> >+ <fieldset class="rows mtt" id="[% letter.message_transport_type %]"> >+ <legend>[% letter.message_transport_type %]</legend> >+ <ol> >+ <li> >+ <input type="hidden" name="message_transport_type" value="[% letter.message_transport_type %]" /> >+ <label for="is_html_[% letter.message_transport_type %]">HTML message:</label> >+ [% IF letter.is_html %] >+ <input type="checkbox" name="is_html_[% letter.message_transport_type %]" id="is_html_[% letter.message_transport_type %]" value="1" checked="checked" /> >+ [% ELSE %] >+ <input type="checkbox" name="is_html_[% letter.message_transport_type %]" id="is_html_[% letter.message_transport_type %]" value="1" /> >+ [% END %] >+ </li> >+ <li> >+ <label for="title">Message subject:</label><input type="text" id="title" name="title" size="60" value="[% letter.title %]" /> >+ </li> >+ <li> >+ <label for="SQLfieldname">Message body: [% IF letter.message_transport_type == 'sms' %]<span id="sms_counter">[% letter.content.length %]/160</span>[% END %]</label> >+ <table> >+ <tr> >+ <td> >+ <select name="SQLfieldname" multiple="multiple" size="9"> >+ [% FOREACH SQLfieldnam IN SQLfieldname %] >+ <option value="[% SQLfieldnam.value %]">[% SQLfieldnam.text %]</option> >+ [% END %] >+ </select> >+ </td> >+ <td><input type="button" name="insert" value=">>" onclick="insertValueQuery('[% letter.message_transport_type %]')" title="Insert" /></td> >+ <td><textarea name="content" id="content_[% letter.message_transport_type %]" cols="80" rows="15">[% letter.content %]</textarea></td> >+ </tr> >+ </table> >+ </li> >+ </ol> >+ </fieldset> >+ </li> >+ [% END %] >+ </ol> >+ >+ [% IF code.search('DGST') %] <span class="overdue">Warning, this is a template for a Digest, as such, any references to branch data ( e.g. branches.branchname ) will refer to the borrower's home branch.</span> [% END %] > </fieldset> >- <fieldset class="action"><input type="button" value="Submit" onclick="Check(this.form)" class="button" /> <a class="cancel" href="/cgi-bin/koha/tools/letter.pl">Cancel</a></fieldset> >+ <fieldset class="action"><input type="submit" id="submit" value="Submit" class="button" /> <a class="cancel" href="/cgi-bin/koha/tools/letter.pl">Cancel</a></fieldset> > <input type="hidden" name="searchfield" value="[% searchfield %]" /> > </form> > [% END %] >@@ -373,6 +380,7 @@ $(document).ready(function() { > <input type="hidden" name="branchcode" value="[% branchcode %]" /> > <input type="hidden" name="code" value="[% code %]" /> > <input type="hidden" name="module" value="[% module %]" /> >+ <input type="hidden" name="message_transport_type" value="*" /> > <input type="submit" value="Yes, delete" class="approve" /> > </form> > >diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t >new file mode 100644 >index 0000000..1f93510 >--- /dev/null >+++ b/t/db_dependent/Letters.t >@@ -0,0 +1,23 @@ >+#!/usr/bin/perl; >+ >+use Modern::Perl; >+use Test::More tests => 3; >+ >+use C4::Context; >+use_ok('C4::Letters'); >+can_ok('C4::Letters', 'GetMessageTransportTypes'); >+ >+my $dbh = C4::Context->dbh; >+$dbh->{AutoCommit} = 0; >+$dbh->{RaiseError} = 1; >+ >+$dbh->do(q|DELETE FROM letter|); >+$dbh->do(q|DELETE FROM message_queue|); >+$dbh->do(q|DELETE FROM message_transport_types|); >+ >+$dbh->do(q| >+ INSERT INTO message_transport_types( message_transport_type ) VALUES ('email'), ('phone'), ('print'), ('sms') >+|); >+ >+my $mtts = C4::Letters::GetMessageTransportTypes(); >+is_deeply( $mtts, ['email', 'phone', 'print', 'sms'], 'GetMessageTransportTypes returns all values' ); >diff --git a/tools/letter.pl b/tools/letter.pl >index 7582e66..0f242f3 100755 >--- a/tools/letter.pl >+++ b/tools/letter.pl >@@ -47,14 +47,16 @@ use C4::Auth; > use C4::Context; > use C4::Output; > use C4::Branch; # GetBranches >+use C4::Letters; > use C4::Members::Attributes; > >-# _letter_from_where($branchcode,$module, $code) >+# _letter_from_where($branchcode,$module, $code, $mtt) > # - return FROM WHERE clause and bind args for a letter > sub _letter_from_where { >- my ($branchcode, $module, $code) = @_; >+ my ($branchcode, $module, $code, $mtt) = @_; > my $sql = q{FROM letter WHERE branchcode = ? AND module = ? AND code = ?}; >- my @args = ($branchcode || '', $module, $code); >+ $sql .= q{ AND message_transport_type = ?} if $mtt ne '*'; >+ my @args = ( $branchcode || '', $module, $code, ($mtt ne '*' ? $mtt : ()) ); > # Mysql is retarded. cause branchcode is part of the primary key it cannot be null. How does that > # work with foreign key constraint I wonder... > >@@ -68,12 +70,12 @@ sub _letter_from_where { > return ($sql, \@args); > } > >-# letter_exists($branchcode,$module, $code) >-# - return true if a letter with the given $branchcode, $module and $code exists >-sub letter_exists { >+# get_letters($branchcode,$module, $code, $mtt) >+# - return letters with the given $branchcode, $module, $code and $mtt exists >+sub get_letters { > my ($sql, $args) = _letter_from_where(@_); > my $dbh = C4::Context->dbh; >- my $letter = $dbh->selectrow_hashref("SELECT * $sql", undef, @$args); >+ my $letter = $dbh->selectall_hashref("SELECT * $sql", 'message_transport_type', undef, @$args); > return $letter; > } > >@@ -90,7 +92,7 @@ my $searchfield = $input->param('searchfield'); > my $script_name = '/cgi-bin/koha/tools/letter.pl'; > our $branchcode = $input->param('branchcode'); > my $code = $input->param('code'); >-my $module = $input->param('module'); >+my $module = $input->param('module') || ''; > my $content = $input->param('content'); > my $op = $input->param('op') || ''; > my $dbh = C4::Context->dbh; >@@ -135,7 +137,8 @@ elsif ( $op eq 'delete_confirm' ) { > delete_confirm($branchcode, $module, $code); > } > elsif ( $op eq 'delete_confirmed' ) { >- delete_confirmed($branchcode, $module, $code); >+ my $mtt = $input->param('message_transport_type'); >+ delete_confirmed($branchcode, $module, $code, $mtt); > $op = q{}; # next operation is to return to default screen > } > else { >@@ -152,25 +155,55 @@ if ($op) { > output_html_with_http_headers $input, $cookie, $template->output; > > sub add_form { >- my ($branchcode,$module, $code ) = @_; >+ my ( $branchcode,$module, $code ) = @_; > >- my $letter; >+ my $letters; > # if code has been passed we can identify letter and its an update action > if ($code) { >- $letter = letter_exists($branchcode,$module, $code); >+ $letters = get_letters($branchcode,$module, $code, '*'); > } >- if ($letter) { >- $template->param( modify => 1 ); >- $template->param( code => $letter->{code} ); >+ >+ my $message_transport_types = GetMessageTransportTypes(); >+ my @letter_loop; >+ if ($letters) { >+ my $first_flag = 1; >+ for my $mtt ( @$message_transport_types ) { >+ if ( $first_flag ) { >+ $template->param( >+ modify => 1, >+ code => $code, >+ branchcode => $branchcode, >+ name => $letters->{$mtt}{name}, >+ ); >+ $first_flag = 0; >+ } >+ >+ push @letter_loop, { >+ message_transport_type => $mtt, >+ is_html => $letters->{$mtt}{is_html}, >+ title => $letters->{$mtt}{title}, >+ content => $letters->{$mtt}{content}, >+ }; >+ } > } > else { # initialize the new fields >- $letter = { >+ for my $mtt ( @$message_transport_types ) { >+ $mtt = $mtt->{message_transport_type}; >+ push @letter_loop, { >+ message_transport_type => $mtt, >+ } >+ } >+ $template->param( > branchcode => $branchcode, > module => $module, >- }; >+ ); > $template->param( adding => 1 ); > } > >+ $template->param( >+ letters => \@letter_loop, >+ ); >+ > my $field_selection; > push @{$field_selection}, add_fields('branches'); > if ($module eq 'reserves') { >@@ -212,13 +245,7 @@ sub add_form { > } > > $template->param( >- branchcode => $letter->{branchcode}, >- name => $letter->{name}, >- is_html => $letter->{is_html}, >- title => $letter->{title}, >- content => $letter->{content}, > module => $module, >- $module => 1, > branchloop => _branchloop($branchcode), > SQLfieldname => $field_selection, > ); >@@ -233,22 +260,36 @@ sub add_validate { > my $oldmodule = $input->param('oldmodule'); > my $code = $input->param('code'); > my $name = $input->param('name'); >- my $is_html = $input->param('is_html'); >- my $title = $input->param('title'); >- my $content = $input->param('content'); >- if (letter_exists($oldbranchcode,$oldmodule, $code)) { >- $dbh->do( >- q{UPDATE letter SET branchcode = ?, module = ?, name = ?, is_html = ?, title = ?, content = ? WHERE branchcode = ? AND module = ? AND code = ?}, >- undef, >- $branchcode, $module, $name, $is_html || 0, $title, $content, >- $oldbranchcode, $oldmodule, $code >- ); >- } else { >- $dbh->do( >- q{INSERT INTO letter (branchcode,module,code,name,is_html,title,content) VALUES (?,?,?,?,?,?,?)}, >- undef, >- $branchcode, $module, $code, $name, $is_html || 0, $title, $content >- ); >+ my @mtt = $input->param('message_transport_type'); >+ my @title = $input->param('title'); >+ my @content = $input->param('content'); >+ for my $mtt ( @mtt ) { >+ my $is_html = $input->param("is_html_$mtt"); >+ my $title = shift @title; >+ my $content = shift @content; >+ my $letter = get_letters($oldbranchcode,$oldmodule, $code, $mtt); >+ unless ( $title and $content ) { >+ delete_confirmed( $oldbranchcode, $oldmodule, $code, $mtt ); >+ next; >+ } >+ if ( exists $letter->{$mtt} ) { >+ $dbh->do( >+ q{ >+ UPDATE letter >+ SET branchcode = ?, module = ?, name = ?, is_html = ?, title = ?, content = ? >+ WHERE branchcode = ? AND module = ? AND code = ? AND message_transport_type = ? >+ }, >+ undef, >+ $branchcode, $module, $name, $is_html || 0, $title, $content, >+ $oldbranchcode, $oldmodule, $code, $mtt >+ ); >+ } else { >+ $dbh->do( >+ q{INSERT INTO letter (branchcode,module,code,name,is_html,title,content,message_transport_type) VALUES (?,?,?,?,?,?,?,?)}, >+ undef, >+ $branchcode, $module, $code, $name, $is_html || 0, $title, $content, $mtt >+ ); >+ } > } > # set up default display > default_display($branchcode); >@@ -261,31 +302,41 @@ sub add_copy { > my $module = $input->param('module'); > my $code = $input->param('code'); > >- return if letter_exists($branchcode,$module, $code); >+ return if keys %{ get_letters($branchcode,$module, $code, '*') }; > >- my $old_letter = letter_exists($oldbranchcode,$module, $code); >+ my $old_letters = get_letters($oldbranchcode,$module, $code, '*'); > >- $dbh->do( >- q{INSERT INTO letter (branchcode,module,code,name,is_html,title,content) VALUES (?,?,?,?,?,?,?)}, >- undef, >- $branchcode, $module, $code, $old_letter->{name}, $old_letter->{is_html}, $old_letter->{title}, $old_letter->{content} >- ); >+ my $message_transport_types = GetMessageTransportTypes(); >+ for my $mtt ( @$message_transport_types ) { >+ next unless exists $old_letters->{$mtt}; >+ my $old_letter = $old_letters->{$mtt}; >+ >+ $dbh->do( >+ q{INSERT INTO letter (branchcode,module,code,name,is_html,title,content,message_transport_type) VALUES (?,?,?,?,?,?,?,?)}, >+ undef, >+ $branchcode, $module, $code, $old_letter->{name}, $old_letter->{is_html}, $old_letter->{title}, $old_letter->{content}, $mtt >+ ); >+ } > } > > sub delete_confirm { > my ($branchcode, $module, $code) = @_; > my $dbh = C4::Context->dbh; >- my $letter = letter_exists($branchcode, $module, $code); >- $template->param( branchcode => $branchcode, branchname => GetBranchName($branchcode) ); >- $template->param( code => $code ); >- $template->param( module => $module); >- $template->param( name => $letter->{name}); >+ my $letter = get_letters($branchcode, $module, $code, '*'); >+ my @values = values %$letter; >+ $template->param( >+ branchcode => $branchcode, >+ branchname => GetBranchName($branchcode), >+ code => $code, >+ module => $module, >+ name => $values[0]->{name}, >+ ); > return; > } > > sub delete_confirmed { >- my ($branchcode, $module, $code) = @_; >- my ($sql, $args) = _letter_from_where($branchcode, $module, $code); >+ my ($branchcode, $module, $code, $mtt) = @_; >+ my ($sql, $args) = _letter_from_where($branchcode, $module, $code, $mtt); > my $dbh = C4::Context->dbh; > $dbh->do("DELETE $sql", undef, @$args); > # setup default display for screen >@@ -302,7 +353,8 @@ sub retrieve_letters { > my ($sql, @where, @args); > $sql = "SELECT branchcode, module, code, name, branchname > FROM letter >- LEFT OUTER JOIN branches USING (branchcode)"; >+ LEFT OUTER JOIN branches USING (branchcode) >+ "; > if ($searchstring && $searchstring=~m/(\S+)/) { > $searchstring = $1 . q{%}; > push @where, 'code LIKE ?'; >@@ -318,8 +370,9 @@ sub retrieve_letters { > } > > $sql .= " WHERE ".join(" AND ", @where) if @where; >+ $sql .= " GROUP BY branchcode,module,code"; > $sql .= " ORDER BY module, code, branchcode"; >-# use Data::Dumper; die Dumper($sql, \@args); >+ > return $dbh->selectall_arrayref($sql, { Slice => {} }, @args); > } > >-- >1.7.10.4
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 9016
:
13276
|
20814
|
20815
|
20816
|
20916
|
21164
|
21165
|
21166
|
21167
|
21636
|
21637
|
21638
|
21639
|
22814
|
23272
|
23273
|
23289
|
23290
|
23291
|
23292
|
23293
|
23562
|
23955
|
23956
|
23957
|
23958
|
23959
|
23960
|
24571
|
24572
|
24573
|
24574
|
24575
|
24576
|
25006
|
25123
|
25124
|
25125
|
25126
|
25127
|
25128
|
25129
|
25130
|
25415
|
25416
|
25417
|
25418
|
25419
|
25420
|
25421
|
25422
|
25606
|
25899
|
26182
|
26209
|
26210
|
26211
|
26216
|
26226
|
26233
|
26648
|
26649
|
26650
|
26656
|
26657
|
26658
|
26659
|
26660
|
26661
|
26662
|
26663
|
26664
|
26665
|
26666
|
26667
|
26668
|
26670
|
26672
|
26673
|
27794
|
27795
|
27796
|
27797
|
27798
|
27799
|
27800
|
27801
|
27802
|
27803
|
27804
|
27805
|
27806
|
27807
|
27808
|
27809