View | Details | Raw Unified | Return to bug 9016
Collapse All | Expand All

(-)a/C4/Letters.pm (-18 / +45 lines)
Lines 42-48 BEGIN { Link Here
42
    $VERSION = 3.07.00.049;
42
    $VERSION = 3.07.00.049;
43
	@ISA = qw(Exporter);
43
	@ISA = qw(Exporter);
44
	@EXPORT = qw(
44
	@EXPORT = qw(
45
	&GetLetters &GetPreparedLetter &GetWrappedLetter &addalert &getalert &delalert &findrelatedto &SendAlerts &GetPrintMessages
45
	&GetLetters &GetPreparedLetter &GetWrappedLetter &addalert &getalert &delalert &findrelatedto &SendAlerts &GetPrintMessages &GetMessageTransportTypes
46
	);
46
	);
47
}
47
}
48
48
Lines 97-116 $template->param(LETTERLOOP => \@letterloop); Link Here
97
sub GetLetters {
97
sub GetLetters {
98
98
99
    # returns a reference to a hash of references to ALL letters...
99
    # returns a reference to a hash of references to ALL letters...
100
    my $cat = shift;
100
    my ( $cat, $message_transport_type ) = @_;
101
    $message_transport_type ||= 'email';
101
    my %letters;
102
    my %letters;
102
    my $dbh = C4::Context->dbh;
103
    my $dbh = C4::Context->dbh;
103
    my $sth;
104
    my $sth;
104
    if (defined $cat) {
105
    my $query = q{
105
        my $query = "SELECT * FROM letter WHERE module = ? ORDER BY name";
106
        SELECT * FROM letter WHERE
106
        $sth = $dbh->prepare($query);
107
    };
107
        $sth->execute($cat);
108
    $query .= q{ module = ? AND } if defined $cat;
108
    }
109
    $query .= q{ message_transport_type = ? ORDER BY name};
109
    else {
110
    $sth = $dbh->prepare($query);
110
        my $query = "SELECT * FROM letter ORDER BY name";
111
    $sth->execute((defined $cat ? $cat : ()), $message_transport_type);
111
        $sth = $dbh->prepare($query);
112
112
        $sth->execute;
113
    }
114
    while ( my $letter = $sth->fetchrow_hashref ) {
113
    while ( my $letter = $sth->fetchrow_hashref ) {
115
        $letters{ $letter->{'code'} } = $letter->{'name'};
114
        $letters{ $letter->{'code'} } = $letter->{'name'};
116
    }
115
    }
Lines 124-130 sub GetLetters { Link Here
124
#        short-term fix, our will work.
123
#        short-term fix, our will work.
125
our %letter;
124
our %letter;
126
sub getletter {
125
sub getletter {
127
    my ( $module, $code, $branchcode ) = @_;
126
    my ( $module, $code, $branchcode, $message_transport_type ) = @_;
127
    $message_transport_type ||= 'email';
128
128
129
    $branchcode ||= '';
129
    $branchcode ||= '';
130
130
Lines 135-151 sub getletter { Link Here
135
        $branchcode = C4::Context->userenv->{'branch'};
135
        $branchcode = C4::Context->userenv->{'branch'};
136
    }
136
    }
137
137
138
    if ( my $l = $letter{$module}{$code}{$branchcode} ) {
138
    if ( my $l = $letter{$module}{$code}{$branchcode}{$message_transport_type} ) {
139
        return { %$l }; # deep copy
139
        return { %$l }; # deep copy
140
    }
140
    }
141
141
142
    my $dbh = C4::Context->dbh;
142
    my $dbh = C4::Context->dbh;
143
    my $sth = $dbh->prepare("select * from letter where module=? and code=? and (branchcode = ? or branchcode = '') order by branchcode desc limit 1");
143
    my $sth = $dbh->prepare(q{
144
    $sth->execute( $module, $code, $branchcode );
144
        SELECT *
145
        FROM letter
146
        WHERE module=? AND code=? AND (branchcode = ? OR branchcode = '') AND message_transport_type = ?
147
        ORDER BY branchcode DESC LIMIT 1
148
    });
149
    $sth->execute( $module, $code, $branchcode, $message_transport_type );
145
    my $line = $sth->fetchrow_hashref
150
    my $line = $sth->fetchrow_hashref
146
      or return;
151
      or return;
147
    $line->{'content-type'} = 'text/html; charset="UTF-8"' if $line->{is_html};
152
    $line->{'content-type'} = 'text/html; charset="UTF-8"' if $line->{is_html};
148
    $letter{$module}{$code}{$branchcode} = $line;
153
    $letter{$module}{$code}{$branchcode}{$message_transport_type} = $line;
149
    return { %$line };
154
    return { %$line };
150
}
155
}
151
156
Lines 447-453 sub GetPreparedLetter { Link Here
447
    my $letter_code = $params{letter_code} or croak "No letter_code";
452
    my $letter_code = $params{letter_code} or croak "No letter_code";
448
    my $branchcode  = $params{branchcode} || '';
453
    my $branchcode  = $params{branchcode} || '';
449
454
450
    my $letter = getletter( $module, $letter_code, $branchcode )
455
    my $letter = getletter( $module, $letter_code, $branchcode, $params{message_transport_type} )
451
        or warn( "No $module $letter_code letter"),
456
        or warn( "No $module $letter_code letter"),
452
            return;
457
            return;
453
458
Lines 836-841 ENDSQL Link Here
836
    return $sth->fetchall_arrayref({});
841
    return $sth->fetchall_arrayref({});
837
}
842
}
838
843
844
=head2 GetMessageTransportTypes
845
846
  my @mtt = GetMessageTransportTypes();
847
848
  returns a list of hashes
849
850
=cut
851
852
sub GetMessageTransportTypes {
853
    my $dbh = C4::Context->dbh();
854
    my $sth = $dbh->prepare("
855
        SELECT message_transport_type
856
        FROM message_transport_types
857
        ORDER BY message_transport_type
858
    ");
859
    $sth->execute;
860
    my @mtts = map{
861
        $_->[0]
862
    } @{ $sth->fetchall_arrayref() };
863
    return \@mtts;
864
}
865
839
=head2 _add_attachements
866
=head2 _add_attachements
840
867
841
named parameters:
868
named parameters:
(-)a/koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.insertatcaret.js (+46 lines)
Line 0 Link Here
1
/*!
2
 * jQuery insertAtCaret
3
 * Allows inserting text where the caret is in a textarea
4
 * Copyright (c) 2003-2010 phpMyAdmin devel team
5
 * Version: 1.0
6
 * Developed by the phpMyAdmin devel team. Modified by Alex King and variaas
7
 * http://alexking.org/blog/2003/06/02/inserting-at-the-cursor-using-javascript
8
 * http://www.mail-archive.com/jquery-en@googlegroups.com/msg08708.html
9
 * Licensed under the GPL license:
10
 * http://www.gnu.org/licenses/gpl.html
11
 */
12
;(function($) {
13
14
$.fn.insertAtCaret = function (myValue) {
15
16
    return this.each(function() {
17
18
        //IE support
19
        if (document.selection) {
20
21
            this.focus();
22
            sel = document.selection.createRange();
23
            sel.text = myValue;
24
            this.focus();
25
26
        } else if (this.selectionStart || this.selectionStart == '0') {
27
28
            //MOZILLA / NETSCAPE support
29
            var startPos = this.selectionStart;
30
            var endPos = this.selectionEnd;
31
            var scrollTop = this.scrollTop;
32
            this.value = this.value.substring(0, startPos)+ myValue+ this.value.substring(endPos,this.value.length);
33
            this.focus();
34
            this.selectionStart = startPos + myValue.length;
35
            this.selectionEnd = startPos + myValue.length;
36
            this.scrollTop = scrollTop;
37
38
        } else {
39
40
            this.value += myValue;
41
            this.focus();
42
        }
43
    });
44
};
45
46
})(jQuery);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt (-161 / +169 lines)
Lines 1-10 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Tools &rsaquo; Notices[% IF ( add_form ) %][% IF ( modify ) %] &rsaquo; Modify notice[% ELSE %] &rsaquo; Add notice[% END %][% END %][% IF ( add_validate ) %] &rsaquo; Notice added[% END %][% IF ( delete_confirm ) %] &rsaquo; Confirm deletion[% END %]</title>
2
<title>Koha &rsaquo; Tools &rsaquo; Notices[% IF ( add_form ) %][% IF ( modify ) %] &rsaquo; Modify notice[% ELSE %] &rsaquo; Add notice[% END %][% END %][% IF ( add_validate ) %] &rsaquo; Notice added[% END %][% IF ( delete_confirm ) %] &rsaquo; Confirm deletion[% END %]</title>
3
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
3
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'doc-head-close.inc' %]
4
<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/en/css/datatables.css" />
5
<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/en/css/datatables.css" />
5
<script type="text/javascript" src="[% interface %]/[% theme %]/en/lib/jquery/plugins/jquery.dataTables.min.js"></script>
6
<script type="text/javascript" src="[% interface %]/[% theme %]/en/lib/jquery/plugins/jquery.dataTables.min.js"></script>
6
[% INCLUDE 'datatables-strings.inc' %]
7
[% INCLUDE 'datatables-strings.inc' %]
7
<script type="text/javascript" src="[% interface %]/[% theme %]/en/js/datatables.js"></script>
8
<script type="text/javascript" src="[% interface %]/[% theme %]/en/js/datatables.js"></script>
9
<script type="text/javascript" src="[% interface %]/[% theme %]/en/lib/jquery/plugins/jquery.insertatcaret.js"></script>
8
<script type="text/javascript">
10
<script type="text/javascript">
9
//<![CDATA[
11
//<![CDATA[
10
$(document).ready(function() {
12
$(document).ready(function() {
Lines 25-30 $(document).ready(function() { Link Here
25
            return true;
27
            return true;
26
      });
28
      });
27
    [% END %]
29
    [% END %]
30
31
    $("#submit").click( function(event) {
32
        $("fieldset.mtt").each( function(){
33
            var title = $(this).find('input[name="title"]').val();
34
            var content = $(this).find('textarea[name="content"]').val();
35
            if (
36
                    ( title.length == 0 && content.length > 0 )
37
                 || ( title.length > 0 && content.length == 0 )
38
            ) {
39
                var mtt = $(this).find('input[name="message_transport_type"]').val();
40
                alert("You must specify a title and a content for " + mtt);
41
                event.preventDefault();
42
            }
43
        } );
44
        return true;
45
    });
46
47
    var sms_limit = 160;
48
    $("#content_sms").on("keyup", function(){
49
        var length = $(this).val().length;
50
        $("#sms_counter").html(length + "/" + sms_limit);
51
        if ( length  > sms_limit ) {
52
            $("#sms_counter").css("color", "red");
53
        } else {
54
            $("#sms_counter").css("color", "black");
55
        }
56
    });
28
}); 
57
}); 
29
[% IF ( add_form ) %]
58
[% IF ( add_form ) %]
30
	
59
	
Lines 65-124 $(document).ready(function() { Link Here
65
			}
94
			}
66
		}
95
		}
67
	
96
	
68
		function Check(f) {
97
        function insertValueQuery(mtt_id) {
69
			var ok=1;
98
            var fieldset = $("#" + mtt_id);
70
			var _alertString="";
99
            var myQuery = $(fieldset).find('textarea[name="content"]');
71
			var alertString2;
100
            var myListBox = $(fieldset).find('select[name="SQLfieldname"]');
72
/*			if (!(isNotNull(window.document.Aform.code))) {
101
73
				_alertString += "\n- " + _("Code missing");
102
            if($(myListBox).find('option').length > 0) {
74
			}*/
103
                var chaineAj = "";
75
/*			if (!(isNotNull(window.document.Aform.name))) {
104
                var NbSelect = 0;
76
				_alertString += "\n- " + _("Name missing");
105
                $(myListBox).find('option').each( function (){
77
			}*/
106
                    if ( $(this).attr('selected') ) {
78
			if (_alertString.length==0) {
107
                        NbSelect++;
79
				document.Aform.submit();
108
                        if (NbSelect > 1)
80
			} else {
109
                            chaineAj += ", ";
81
				alertString2  = _("Form not submitted because of the following problem(s)");
110
                        chaineAj += $(this).val();
82
				alertString2 += "\n------------------------------------------------------------------------------------\n";
111
                    }
83
				alertString2 += _alertString;
112
                } );
84
				alert(alertString2);
113
                $(myQuery).insertAtCaret(chaineAj);
85
			}
114
            }
86
		}
115
        }
87
		// GPL code coming from PhpMyAdmin
88
		function insertValueQuery() {
89
			var myQuery = document.Aform.content;
90
			var myListBox = document.Aform.SQLfieldname;
91
		
92
			if(myListBox.options.length > 0) {
93
				var chaineAj = "";
94
				var NbSelect = 0;
95
				for(var i=0; i<myListBox.options.length; i++) {
96
					if (myListBox.options[i].selected){
97
						NbSelect++;
98
						if (NbSelect > 1)
99
							chaineAj += ", ";
100
						chaineAj += myListBox.options[i].value;
101
					}
102
				}
103
		
104
				//IE support
105
				if (document.selection) {
106
					myQuery.focus();
107
					sel = document.selection.createRange();
108
					sel.text = chaineAj;
109
					document.Aform.insert.focus();
110
				}
111
				//MOZILLA/NETSCAPE support
112
				else if (document.Aform.content.selectionStart || document.Aform.content.selectionStart == "0") {
113
					var startPos = document.Aform.content.selectionStart;
114
					var endPos = document.Aform.content.selectionEnd;
115
					var chaineSql = document.Aform.content.value;
116
					myQuery.value = chaineSql.substring(0, startPos) +'<<'+ chaineAj+'>>' + chaineSql.substring(endPos, chaineSql.length);
117
				} else {
118
					myQuery.value += chaineAj;
119
				}
120
			}
121
		}
122
	[% END %]
116
	[% END %]
123
		//]]>
117
		//]]>
124
		</script>
118
		</script>
Lines 168-242 $(document).ready(function() { Link Here
168
            </select>
162
            </select>
169
            [% END %]
163
            [% END %]
170
        [% END %]
164
        [% END %]
171
165
        [% IF letter %]
172
[% IF ( letter ) %]
166
          <table id="lettert">
173
        <table id="lettert">
167
            <thead>
174
		<thead><tr>
168
              <tr>
175
			<th>Library</th>
169
                <th>Library</th>
176
			<th>Module</th>
170
                <th>Module</th>
177
			<th>Code</th>
171
                <th>Code</th>
178
			<th>Name</th>
172
                <th>Name</th>
179
            <th>Copy notice</th>
173
                <th>Copy notice</th>
180
			<th>&nbsp;</th>
174
                <th>&nbsp;</th>
181
			<th>&nbsp;</th>
175
                <th>&nbsp;</th>
182
		</tr></thead>
176
              </tr>
183
		<tbody>
177
            </thead>
184
    [% FOREACH lette IN letter %]
178
            <tbody>
185
        [% can_edit = lette.branchcode || !independant_branch %]
179
              [% FOREACH lette IN letter %]
186
        [% UNLESS ( loop.odd ) %]
180
                [% can_edit = lette.branchcode || !independant_branch %]
187
			<tr class="highlight">
181
                <tr>
188
        [% ELSE %]
182
                  <td>[% lette.branchname || "(All libraries)" %]</td>
189
			<tr>
183
                  <td>[% lette.module %]</td>
190
        [% END %]
184
                  <td>[% lette.code %]</td>
191
				<td>[% lette.branchname || "(All libraries)" %]</td>
185
                  <td>[% lette.name %]</td>
192
				<td>[% lette.module %]</td>
186
                  <td style="white-space: nowrap">
193
				<td>[% lette.code %]</td>
187
                    [% IF !independant_branch || !lette.branchcode %]
194
				<td>[% lette.name %]</td>
188
                      <form method="post" action="/cgi-bin/koha/tools/letter.pl">
195
				<td style="white-space: nowrap">
196
        [% IF !independant_branch || !lette.branchcode %]
197
                    <form method="post" action="/cgi-bin/koha/tools/letter.pl">
198
                        <input type="hidden" name="op" value="copy" />
189
                        <input type="hidden" name="op" value="copy" />
199
				        <input type="hidden" name="oldbranchcode" value="[% lette.branchcode %]" />
190
                        <input type="hidden" name="oldbranchcode" value="[% lette.branchcode %]" />
200
                        <input type="hidden" name="module" value="[% lette.module %]" />
191
                        <input type="hidden" name="module" value="[% lette.module %]" />
201
                        <input type="hidden" name="code" value="[% lette.code %]" />
192
                        <input type="hidden" name="code" value="[% lette.code %]" />
202
            [% IF independant_branch %]
193
                        [% IF independant_branch %]
203
                        <input type="hidden" name="branchcode" value="[% independant_branch %]" />
194
                          <input type="hidden" name="branchcode" value="[% independant_branch %]" />
204
            [% ELSE %]
195
                        [% ELSE %]
205
                        [% select_for_copy %]
196
                          [% select_for_copy %]
206
            [% END %]
197
                        [% END %]
207
                        <input type="submit" value="Copy" />
198
                        <input type="submit" value="Copy" />
208
                    </form>
199
                      </form>
209
        [% END %]
200
                    [% END %]
210
                </td>
201
                  </td>
211
                <td>
202
                  <td>
212
        [% IF can_edit %]
203
                    [% IF can_edit %]
213
                    <a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;branchcode=[% lette.branchcode %]&amp;module=[% lette.module %]&amp;code=[% lette.code %]">Edit</a>
204
                      <a href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;branchcode=[% lette.branchcode %]&amp;module=[% lette.module %]&amp;code=[% lette.code %]">Edit</a>
214
        [% END %]
205
                    [% END %]
215
				</td>
206
                  </td>
216
				<td>
207
                  <td>
217
        [% IF !lette.protected && can_edit %]
208
                    [% IF !lette.protected && can_edit %]
218
					<a href="/cgi-bin/koha/tools/letter.pl?op=delete_confirm&amp;branchcode=[%lette.branchcode %]&amp;module=[% lette.module %]&amp;code=[% lette.code %]">Delete</a>
209
                      <a href="/cgi-bin/koha/tools/letter.pl?op=delete_confirm&amp;branchcode=[%lette.branchcode %]&amp;module=[% lette.module %]&amp;code=[% lette.code %]">Delete</a>
219
        [% END %]
210
                    [% END %]
220
				</td>
211
                  </td>
221
			</tr>
212
                </tr>
222
    [% END %]
213
              [% END %]
223
        </tbody>
214
            </tbody>
224
		</table>
215
          </table>
225
[% ELSE %]
226
    <div class="dialog message">
227
        [% IF ( branchcode ) %]
228
           <p>There are no notices for this library.</p>
229
        [% ELSE %]
216
        [% ELSE %]
230
            <p>There are no notices.</p>
217
          <div class="dialog message">
218
          [% IF ( branchcode ) %]
219
             <p>There are no notices for this library.</p>
220
          [% ELSE %]
221
              <p>There are no notices.</p>
222
          [% END %]
223
          </div>
231
        [% END %]
224
        [% END %]
232
    </div>
233
[% END %]
234
[% END %]
225
[% END %]
235
226
236
	
227
	
237
[% IF ( add_form ) %]
228
[% IF ( add_form ) %]
238
<h1>[% IF ( modify ) %]Modify notice[% ELSE %]Add notice[% END %]</h1>
229
<h1>[% IF ( modify ) %]Modify notice[% ELSE %]Add notice[% END %]</h1>
239
		<form action="?" name="Aform" method="post">
230
		<form name="Aform" method="post" enctype="multipart/form-data">
240
		<input type="hidden" name="op" id="op" value="add_validate" />
231
		<input type="hidden" name="op" id="op" value="add_validate" />
241
		<input type="hidden" name="checked" value="0" />
232
		<input type="hidden" name="checked" value="0" />
242
		[% IF ( modify ) %]
233
		[% IF ( modify ) %]
Lines 264-308 $(document).ready(function() { Link Here
264
				<label for="module">Koha module:</label>
255
				<label for="module">Koha module:</label>
265
				<input type="hidden" name="oldmodule" value="[% module %]" />
256
				<input type="hidden" name="oldmodule" value="[% module %]" />
266
		[% 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&amp;module='+this.value+'&amp;content='+window.document.forms['Aform'].elements['content'].value;">[% END %]
257
		[% 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&amp;module='+this.value+'&amp;content='+window.document.forms['Aform'].elements['content'].value;">[% END %]
267
                                    [% IF ( catalogue ) %]
258
                                    [% IF ( module == "catalogue" ) %]
268
                                    <option value="catalogue" selected="selected">Catalog</option>
259
                                      <option value="catalogue" selected="selected">Catalog</option>
269
                                    [% ELSE %]
260
                                    [% ELSE %]
270
                                    <option value="catalogue" >Catalog</option>
261
                                      <option value="catalogue" >Catalog</option>
271
                                    [% END %]
262
                                    [% END %]
272
                                    [% IF ( circulation ) %]
263
                                    [% IF ( module == "circulation" ) %]
273
                                    <option value="circulation" selected="selected">Circulation</option>
264
                                      <option value="circulation" selected="selected">Circulation</option>
274
                                    [% ELSE %]
265
                                    [% ELSE %]
275
                                    <option value="circulation">Circulation</option>
266
                                      <option value="circulation">Circulation</option>
276
                                    [% END %]
267
                                    [% END %]
277
                                    [% IF ( claimacquisition ) %]
268
                                    [% IF ( module == "claimacquisition" ) %]
278
                                    <option value="claimacquisition" selected="selected">Claim acquisition</option>
269
                                      <option value="claimacquisition" selected="selected">Claim acquisition</option>
279
                                    [% ELSE %]
270
                                    [% ELSE %]
280
                                    <option value="claimacquisition">Claim acquisition</option>
271
                                      <option value="claimacquisition">Claim acquisition</option>
281
                                    [% END %]
272
                                    [% END %]
282
                                    [% IF ( claimissues ) %]
273
                                    [% IF ( module == "claimissues" ) %]
283
                                    <option value="claimissues" selected="selected">Claim serial issue</option>
274
                                      <option value="claimissues" selected="selected">Claim serial issue</option>
284
                                    [% ELSE %]
275
                                    [% ELSE %]
285
                                    <option value="claimissues">Claim serial issue</option>
276
                                      <option value="claimissues">Claim serial issue</option>
286
                                    [% END %]
277
                                    [% END %]
287
                                    [% IF ( reserves ) %]
278
                                    [% IF ( module == "reserves" ) %]
288
                                    <option value="reserves" selected="selected">Holds</option>
279
                                      <option value="reserves" selected="selected">Holds</option>
289
                                    [% ELSE %]
280
                                    [% ELSE %]
290
                                    <option value="reserves">Holds</option>
281
                                      <option value="reserves">Holds</option>
291
                                    [% END %]
282
                                    [% END %]
292
                                    [% IF ( members ) %]
283
                                    [% IF ( module == "members" ) %]
293
                                    <option value="members" selected="selected">Members</option>
284
                                      <option value="members" selected="selected">Members</option>
294
                                    [% ELSE %]
285
                                    [% ELSE %]
295
                                    <option value="members">Members</option>
286
                                      <option value="members">Members</option>
296
                                    [% END %]
287
                                    [% END %]
297
                                    [% IF ( serial ) %]
288
                                    [% IF ( module == "serial" ) %]
298
                                    <option value="serial" selected="selected">Serials (routing list)</option>
289
                                      <option value="serial" selected="selected">Serials (routing list)</option>
299
                                    [% ELSE %]
290
                                    [% ELSE %]
300
                                    <option value="serial">Serials (routing list)</option>
291
                                      <option value="serial">Serials (routing list)</option>
301
                                    [% END %]
292
                                    [% END %]
302
                                    [% IF ( suggestions ) %]
293
                                    [% IF ( module == "suggestions" ) %]
303
                                    <option value="suggestions" selected="selected">Suggestions</option>
294
                                      <option value="suggestions" selected="selected">Suggestions</option>
304
                                    [% ELSE %]
295
                                    [% ELSE %]
305
                                    <option value="suggestions">Suggestions</option>
296
                                      <option value="suggestions">Suggestions</option>
306
                                    [% END %]
297
                                    [% END %]
307
				</select>
298
				</select>
308
			</li>
299
			</li>
Lines 312-344 $(document).ready(function() { Link Here
312
		<li>
303
		<li>
313
			<label for="name">Name:</label><input type="text" id="name" name="name" size="60" value="[% name %]" />
304
			<label for="name">Name:</label><input type="text" id="name" name="name" size="60" value="[% name %]" />
314
		</li>
305
		</li>
315
		<li>
316
            <label for="is_html">HTML message:</label>
317
      [% IF is_html %]
318
      <input type="checkbox" id="is_html" name="is_html" value="1" checked />
319
      [% ELSE %]
320
      <input type="checkbox" id="is_html" name="is_html" value="1" />
321
      [% END %]
322
		</li>
323
		<li>
324
            <label for="title">Message subject:</label><input type="text" id="title" name="title" size="60" value="[% title %]" />
325
		</li>
326
		<li>
327
            <label for="SQLfieldname">Message body:</label>
328
		</li>
329
		<li>
330
		<table>
331
		<tr><td><select name="SQLfieldname" id="SQLfieldname" size="9">
332
			[% FOREACH SQLfieldnam IN SQLfieldname %]
333
				<option value="[% SQLfieldnam.value %]">[% SQLfieldnam.text %]</option>
334
			[% END %]
335
		</select></td><td><input type="button" name="insert" value="&gt;&gt;" onclick="insertValueQuery()" title="Insert" /></td><td><textarea name="content" cols="80" rows="15">[% content %]</textarea></td></tr></table>
336
306
337
		</li>
307
        [% FOREACH letter IN letters %]
338
		</ol>
308
          <li>
339
                [% 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 %]
309
            <fieldset class="rows mtt" id="[% letter.message_transport_type %]">
310
              <legend>[% letter.message_transport_type %]</legend>
311
              <ol>
312
                <li>
313
                  <input type="hidden" name="message_transport_type" value="[% letter.message_transport_type %]" />
314
                  <label for="is_html_[% letter.message_transport_type %]">HTML message:</label>
315
                  [% IF letter.is_html %]
316
                    <input type="checkbox" name="is_html_[% letter.message_transport_type %]" id="is_html_[% letter.message_transport_type %]" value="1" checked="checked" />
317
                  [% ELSE %]
318
                    <input type="checkbox" name="is_html_[% letter.message_transport_type %]" id="is_html_[% letter.message_transport_type %]" value="1" />
319
                  [% END %]
320
                </li>
321
                <li>
322
                  <label for="title">Message subject:</label><input type="text" id="title" name="title" size="60" value="[% letter.title %]" />
323
                </li>
324
                <li>
325
                  <label for="SQLfieldname">Message body: [% IF letter.message_transport_type == 'sms' %]<span id="sms_counter">[% letter.content.length %]/160</span>[% END %]</label>
326
                  <table>
327
                    <tr>
328
                      <td>
329
                        <select name="SQLfieldname" multiple="multiple" size="9">
330
                          [% FOREACH SQLfieldnam IN SQLfieldname %]
331
                            <option value="[% SQLfieldnam.value %]">[% SQLfieldnam.text %]</option>
332
                          [% END %]
333
                        </select>
334
                      </td>
335
                      <td><input type="button" name="insert" value="&gt;&gt;" onclick="insertValueQuery('[% letter.message_transport_type %]')" title="Insert" /></td>
336
                      <td><textarea name="content" id="content_[% letter.message_transport_type %]" cols="80" rows="15">[% letter.content %]</textarea></td>
337
                    </tr>
338
                  </table>
339
                </li>
340
              </ol>
341
            </fieldset>
342
          </li>
343
        [% END %]
344
        </ol>
345
346
        [% 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 %]
340
		</fieldset>
347
		</fieldset>
341
		<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>
348
		<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>
342
      <input type="hidden" name="searchfield" value="[% searchfield %]" />
349
      <input type="hidden" name="searchfield" value="[% searchfield %]" />
343
		</form>
350
		</form>
344
[% END %]
351
[% END %]
Lines 373-378 $(document).ready(function() { Link Here
373
		<input type="hidden" name="branchcode" value="[% branchcode %]" />
380
		<input type="hidden" name="branchcode" value="[% branchcode %]" />
374
		<input type="hidden" name="code" value="[% code %]" />
381
		<input type="hidden" name="code" value="[% code %]" />
375
		<input type="hidden" name="module" value="[% module %]" />
382
		<input type="hidden" name="module" value="[% module %]" />
383
        <input type="hidden" name="message_transport_type" value="*" />
376
                <input type="submit" value="Yes, delete" class="approve" />
384
                <input type="submit" value="Yes, delete" class="approve" />
377
				</form>
385
				</form>
378
386
(-)a/t/db_dependent/Letters.t (+23 lines)
Line 0 Link Here
1
#!/usr/bin/perl;
2
3
use Modern::Perl;
4
use Test::More tests => 3;
5
6
use C4::Context;
7
use_ok('C4::Letters');
8
can_ok('C4::Letters', 'GetMessageTransportTypes');
9
10
my $dbh = C4::Context->dbh;
11
$dbh->{AutoCommit} = 0;
12
$dbh->{RaiseError} = 1;
13
14
$dbh->do(q|DELETE FROM letter|);
15
$dbh->do(q|DELETE FROM message_queue|);
16
$dbh->do(q|DELETE FROM message_transport_types|);
17
18
$dbh->do(q|
19
    INSERT INTO message_transport_types( message_transport_type ) VALUES ('email'), ('phone'), ('print'), ('sms')
20
|);
21
22
my $mtts = C4::Letters::GetMessageTransportTypes();
23
is_deeply( $mtts, ['email', 'phone', 'print', 'sms'], 'GetMessageTransportTypes returns all values' );
(-)a/tools/letter.pl (-56 / +108 lines)
Lines 47-60 use C4::Auth; Link Here
47
use C4::Context;
47
use C4::Context;
48
use C4::Output;
48
use C4::Output;
49
use C4::Branch; # GetBranches
49
use C4::Branch; # GetBranches
50
use C4::Letters;
50
use C4::Members::Attributes;
51
use C4::Members::Attributes;
51
52
52
# _letter_from_where($branchcode,$module, $code)
53
# _letter_from_where($branchcode,$module, $code, $mtt)
53
# - return FROM WHERE clause and bind args for a letter
54
# - return FROM WHERE clause and bind args for a letter
54
sub _letter_from_where {
55
sub _letter_from_where {
55
    my ($branchcode, $module, $code) = @_;
56
    my ($branchcode, $module, $code, $mtt) = @_;
56
    my $sql = q{FROM letter WHERE branchcode = ? AND module = ? AND code = ?};
57
    my $sql = q{FROM letter WHERE branchcode = ? AND module = ? AND code = ?};
57
    my @args = ($branchcode || '', $module, $code);
58
    $sql .= q{ AND message_transport_type = ?} if $mtt ne '*';
59
    my @args = ( $branchcode || '', $module, $code, ($mtt ne '*' ? $mtt : ()) );
58
# Mysql is retarded. cause branchcode is part of the primary key it cannot be null. How does that
60
# Mysql is retarded. cause branchcode is part of the primary key it cannot be null. How does that
59
# work with foreign key constraint I wonder...
61
# work with foreign key constraint I wonder...
60
62
Lines 68-79 sub _letter_from_where { Link Here
68
    return ($sql, \@args);
70
    return ($sql, \@args);
69
}
71
}
70
72
71
# letter_exists($branchcode,$module, $code)
73
# get_letters($branchcode,$module, $code, $mtt)
72
# - return true if a letter with the given $branchcode, $module and $code exists
74
# - return letters with the given $branchcode, $module, $code and $mtt exists
73
sub letter_exists {
75
sub get_letters {
74
    my ($sql, $args) = _letter_from_where(@_);
76
    my ($sql, $args) = _letter_from_where(@_);
75
    my $dbh = C4::Context->dbh;
77
    my $dbh = C4::Context->dbh;
76
    my $letter = $dbh->selectrow_hashref("SELECT * $sql", undef, @$args);
78
    my $letter = $dbh->selectall_hashref("SELECT * $sql", 'message_transport_type', undef, @$args);
77
    return $letter;
79
    return $letter;
78
}
80
}
79
81
Lines 90-96 my $searchfield = $input->param('searchfield'); Link Here
90
my $script_name = '/cgi-bin/koha/tools/letter.pl';
92
my $script_name = '/cgi-bin/koha/tools/letter.pl';
91
our $branchcode  = $input->param('branchcode');
93
our $branchcode  = $input->param('branchcode');
92
my $code        = $input->param('code');
94
my $code        = $input->param('code');
93
my $module      = $input->param('module');
95
my $module      = $input->param('module') || '';
94
my $content     = $input->param('content');
96
my $content     = $input->param('content');
95
my $op          = $input->param('op') || '';
97
my $op          = $input->param('op') || '';
96
my $dbh = C4::Context->dbh;
98
my $dbh = C4::Context->dbh;
Lines 135-141 elsif ( $op eq 'delete_confirm' ) { Link Here
135
    delete_confirm($branchcode, $module, $code);
137
    delete_confirm($branchcode, $module, $code);
136
}
138
}
137
elsif ( $op eq 'delete_confirmed' ) {
139
elsif ( $op eq 'delete_confirmed' ) {
138
    delete_confirmed($branchcode, $module, $code);
140
    my $mtt = $input->param('message_transport_type');
141
    delete_confirmed($branchcode, $module, $code, $mtt);
139
    $op = q{}; # next operation is to return to default screen
142
    $op = q{}; # next operation is to return to default screen
140
}
143
}
141
else {
144
else {
Lines 152-176 if ($op) { Link Here
152
output_html_with_http_headers $input, $cookie, $template->output;
155
output_html_with_http_headers $input, $cookie, $template->output;
153
156
154
sub add_form {
157
sub add_form {
155
    my ($branchcode,$module, $code ) = @_;
158
    my ( $branchcode,$module, $code ) = @_;
156
159
157
    my $letter;
160
    my $letters;
158
    # if code has been passed we can identify letter and its an update action
161
    # if code has been passed we can identify letter and its an update action
159
    if ($code) {
162
    if ($code) {
160
        $letter = letter_exists($branchcode,$module, $code);
163
        $letters = get_letters($branchcode,$module, $code, '*');
161
    }
164
    }
162
    if ($letter) {
165
163
        $template->param( modify => 1 );
166
    my $message_transport_types = GetMessageTransportTypes();
164
        $template->param( code   => $letter->{code} );
167
    my @letter_loop;
168
    if ($letters) {
169
        my $first_flag = 1;
170
        for my $mtt ( @$message_transport_types ) {
171
            if ( $first_flag ) {
172
                $template->param(
173
                    modify     => 1,
174
                    code       => $code,
175
                    branchcode => $branchcode,
176
                    name       => $letters->{$mtt}{name},
177
                );
178
                $first_flag = 0;
179
            }
180
181
            push @letter_loop, {
182
                message_transport_type => $mtt,
183
                is_html    => $letters->{$mtt}{is_html},
184
                title      => $letters->{$mtt}{title},
185
                content    => $letters->{$mtt}{content},
186
            };
187
        }
165
    }
188
    }
166
    else { # initialize the new fields
189
    else { # initialize the new fields
167
        $letter = {
190
        for my $mtt ( @$message_transport_types ) {
191
            $mtt = $mtt->{message_transport_type};
192
            push @letter_loop, {
193
                message_transport_type => $mtt,
194
            }
195
        }
196
        $template->param(
168
            branchcode => $branchcode,
197
            branchcode => $branchcode,
169
            module     => $module,
198
            module     => $module,
170
        };
199
        );
171
        $template->param( adding => 1 );
200
        $template->param( adding => 1 );
172
    }
201
    }
173
202
203
    $template->param(
204
        letters => \@letter_loop,
205
    );
206
174
    my $field_selection;
207
    my $field_selection;
175
    push @{$field_selection}, add_fields('branches');
208
    push @{$field_selection}, add_fields('branches');
176
    if ($module eq 'reserves') {
209
    if ($module eq 'reserves') {
Lines 212-224 sub add_form { Link Here
212
    }
245
    }
213
246
214
    $template->param(
247
    $template->param(
215
        branchcode => $letter->{branchcode},
216
        name       => $letter->{name},
217
        is_html    => $letter->{is_html},
218
        title      => $letter->{title},
219
        content    => $letter->{content},
220
        module     => $module,
248
        module     => $module,
221
        $module    => 1,
222
        branchloop => _branchloop($branchcode),
249
        branchloop => _branchloop($branchcode),
223
        SQLfieldname => $field_selection,
250
        SQLfieldname => $field_selection,
224
    );
251
    );
Lines 233-254 sub add_validate { Link Here
233
    my $oldmodule     = $input->param('oldmodule');
260
    my $oldmodule     = $input->param('oldmodule');
234
    my $code          = $input->param('code');
261
    my $code          = $input->param('code');
235
    my $name          = $input->param('name');
262
    my $name          = $input->param('name');
236
    my $is_html       = $input->param('is_html');
263
    my @mtt           = $input->param('message_transport_type');
237
    my $title         = $input->param('title');
264
    my @title         = $input->param('title');
238
    my $content       = $input->param('content');
265
    my @content       = $input->param('content');
239
    if (letter_exists($oldbranchcode,$oldmodule, $code)) {
266
    for my $mtt ( @mtt ) {
240
        $dbh->do(
267
        my $is_html = $input->param("is_html_$mtt");
241
            q{UPDATE letter SET branchcode = ?, module = ?, name = ?, is_html = ?, title = ?, content = ? WHERE branchcode = ? AND module = ? AND code = ?},
268
        my $title   = shift @title;
242
            undef,
269
        my $content = shift @content;
243
            $branchcode, $module, $name, $is_html || 0, $title, $content,
270
        my $letter = get_letters($oldbranchcode,$oldmodule, $code, $mtt);
244
            $oldbranchcode, $oldmodule, $code
271
        unless ( $title and $content ) {
245
        );
272
            delete_confirmed( $oldbranchcode, $oldmodule, $code, $mtt );
246
    } else {
273
            next;
247
        $dbh->do(
274
        }
248
            q{INSERT INTO letter (branchcode,module,code,name,is_html,title,content) VALUES (?,?,?,?,?,?,?)},
275
        if ( exists $letter->{$mtt} ) {
249
            undef,
276
            $dbh->do(
250
            $branchcode, $module, $code, $name, $is_html || 0, $title, $content
277
                q{
251
        );
278
                    UPDATE letter
279
                    SET branchcode = ?, module = ?, name = ?, is_html = ?, title = ?, content = ?
280
                    WHERE branchcode = ? AND module = ? AND code = ? AND message_transport_type = ?
281
                },
282
                undef,
283
                $branchcode, $module, $name, $is_html || 0, $title, $content,
284
                $oldbranchcode, $oldmodule, $code, $mtt
285
            );
286
        } else {
287
            $dbh->do(
288
                q{INSERT INTO letter (branchcode,module,code,name,is_html,title,content,message_transport_type) VALUES (?,?,?,?,?,?,?,?)},
289
                undef,
290
                $branchcode, $module, $code, $name, $is_html || 0, $title, $content, $mtt
291
            );
292
        }
252
    }
293
    }
253
    # set up default display
294
    # set up default display
254
    default_display($branchcode);
295
    default_display($branchcode);
Lines 261-291 sub add_copy { Link Here
261
    my $module        = $input->param('module');
302
    my $module        = $input->param('module');
262
    my $code          = $input->param('code');
303
    my $code          = $input->param('code');
263
304
264
    return if letter_exists($branchcode,$module, $code);
305
    return if keys %{ get_letters($branchcode,$module, $code, '*') };
265
306
266
    my $old_letter = letter_exists($oldbranchcode,$module, $code);
307
    my $old_letters = get_letters($oldbranchcode,$module, $code, '*');
267
308
268
    $dbh->do(
309
    my $message_transport_types = GetMessageTransportTypes();
269
        q{INSERT INTO letter (branchcode,module,code,name,is_html,title,content) VALUES (?,?,?,?,?,?,?)},
310
    for my $mtt ( @$message_transport_types ) {
270
        undef,
311
        next unless exists $old_letters->{$mtt};
271
        $branchcode, $module, $code, $old_letter->{name}, $old_letter->{is_html}, $old_letter->{title}, $old_letter->{content}
312
        my $old_letter = $old_letters->{$mtt};
272
    );
313
314
        $dbh->do(
315
            q{INSERT INTO letter (branchcode,module,code,name,is_html,title,content,message_transport_type) VALUES (?,?,?,?,?,?,?,?)},
316
            undef,
317
            $branchcode, $module, $code, $old_letter->{name}, $old_letter->{is_html}, $old_letter->{title}, $old_letter->{content}, $mtt
318
        );
319
    }
273
}
320
}
274
321
275
sub delete_confirm {
322
sub delete_confirm {
276
    my ($branchcode, $module, $code) = @_;
323
    my ($branchcode, $module, $code) = @_;
277
    my $dbh = C4::Context->dbh;
324
    my $dbh = C4::Context->dbh;
278
    my $letter = letter_exists($branchcode, $module, $code);
325
    my $letter = get_letters($branchcode, $module, $code, '*');
279
    $template->param( branchcode => $branchcode, branchname => GetBranchName($branchcode) );
326
    my @values = values %$letter;
280
    $template->param( code => $code );
327
    $template->param(
281
    $template->param( module => $module);
328
        branchcode => $branchcode,
282
    $template->param( name => $letter->{name});
329
        branchname => GetBranchName($branchcode),
330
        code => $code,
331
        module => $module,
332
        name => $values[0]->{name},
333
    );
283
    return;
334
    return;
284
}
335
}
285
336
286
sub delete_confirmed {
337
sub delete_confirmed {
287
    my ($branchcode, $module, $code) = @_;
338
    my ($branchcode, $module, $code, $mtt) = @_;
288
    my ($sql, $args) = _letter_from_where($branchcode, $module, $code);
339
    my ($sql, $args) = _letter_from_where($branchcode, $module, $code, $mtt);
289
    my $dbh    = C4::Context->dbh;
340
    my $dbh    = C4::Context->dbh;
290
    $dbh->do("DELETE $sql", undef, @$args);
341
    $dbh->do("DELETE $sql", undef, @$args);
291
    # setup default display for screen
342
    # setup default display for screen
Lines 302-308 sub retrieve_letters { Link Here
302
    my ($sql, @where, @args);
353
    my ($sql, @where, @args);
303
    $sql = "SELECT branchcode, module, code, name, branchname
354
    $sql = "SELECT branchcode, module, code, name, branchname
304
            FROM letter
355
            FROM letter
305
            LEFT OUTER JOIN branches USING (branchcode)";
356
            LEFT OUTER JOIN branches USING (branchcode)
357
    ";
306
    if ($searchstring && $searchstring=~m/(\S+)/) {
358
    if ($searchstring && $searchstring=~m/(\S+)/) {
307
        $searchstring = $1 . q{%};
359
        $searchstring = $1 . q{%};
308
        push @where, 'code LIKE ?';
360
        push @where, 'code LIKE ?';
Lines 318-325 sub retrieve_letters { Link Here
318
    }
370
    }
319
371
320
    $sql .= " WHERE ".join(" AND ", @where) if @where;
372
    $sql .= " WHERE ".join(" AND ", @where) if @where;
373
    $sql .= " GROUP BY branchcode,module,code";
321
    $sql .= " ORDER BY module, code, branchcode";
374
    $sql .= " ORDER BY module, code, branchcode";
322
#   use Data::Dumper; die Dumper($sql, \@args);
375
323
    return $dbh->selectall_arrayref($sql, { Slice => {} }, @args);
376
    return $dbh->selectall_arrayref($sql, { Slice => {} }, @args);
324
}
377
}
325
378
326
- 

Return to bug 9016