Bug 13215: The same letter code can be used for several libraries
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / letter.tt
1 [% USE Koha %]
2 [% INCLUDE 'doc-head-open.inc' %]
3 <title>Koha &rsaquo; Tools &rsaquo; Notices[% IF ( add_form or copy_form ) %][% IF ( modify ) %] &rsaquo; Modify notice[% ELSE %] &rsaquo; Add notice[% END %][% END %][% IF ( add_validate or copy_validate) %] &rsaquo; Notice added[% END %][% IF ( delete_confirm ) %] &rsaquo; Confirm deletion[% END %]</title>
4 [% INCLUDE 'doc-head-close.inc' %]
5 <link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
6 [% INCLUDE 'datatables.inc' %]
7 <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.insertatcaret.js"></script>
8 <script type="text/javascript">
9 //<![CDATA[
10 $(document).ready(function() {
11     $("#lettert:has(tbody tr)").dataTable($.extend(true, {}, dataTablesDefaults, {
12         "sDom": 't',
13         "aoColumnDefs": [
14             { "aTargets": [ -1,-2, -3 ], "bSortable": false, "bSearchable": false }
15         ],
16         "bPaginate": false
17     }));
18     [% IF no_op_set %]
19       $('#branch').change(function() {
20             $('#op').val("");
21             $('#selectlibrary').submit();
22       });
23       $('#newnotice').click(function() {
24             $('#op').val("add_form");
25             return true;
26       });
27     [% END %]
28
29     $("#submit_form").click( function(event) {
30         event.preventDefault();
31         var at_least_one_exists = 0;
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                 var msg = _("Please specify title and content for %s");
41                 msg = msg.replace( "%s", mtt );
42                 at_least_one_exists = 1;
43                 alert(msg)
44                 return false;
45             } else if ( title.length > 0 && content.length > 0 ) {
46                 at_least_one_exists = 1;
47             }
48         } );
49         if ( ! at_least_one_exists ) {
50             alert( _("Please fill at least one template.") );
51             return false;
52         }
53
54         // Test if code already exists in DB
55         var new_lettercode = $("#code").val();
56         var new_branchcode = $("#branch").val();
57         [% IF ( add_form and code ) # IF edit %]
58           if ( new_lettercode != '[% code %]' ) {
59         [% END %]
60           $.ajax({
61             data: { code: new_lettercode, branchcode: new_branchcode },
62             type: 'GET',
63             url: '/cgi-bin/koha/svc/letters/',
64             success: function (data) {
65               if ( data.letters.length > 0 ) {
66                 if( new_branchcode == '' ) {
67                     alert( _("A default letter with the code '%s' already exists.").format(new_lettercode) );
68                 } else {
69                     alert( _("A letter with the code '%s' already exists for '%s'.").format(new_lettercode, new_branchcode) );
70                 }
71                 return false;
72               } else {
73                 $("#add_notice").submit();
74               }
75             },
76           });
77         [% IF ( add_form and code ) %]
78           } else {
79             $("#add_notice").submit();
80           }
81         [% END %]
82     });
83
84     var sms_limit = 160;
85     $("#content_sms").on("keyup", function(){
86         var length = $(this).val().length;
87         $("#sms_counter").html(length + "/" + sms_limit + _(" characters"));
88         if ( length  > sms_limit ) {
89             $("#sms_counter").css("color", "red");
90         } else {
91             $("#sms_counter").css("color", "black");
92         }
93     });
94     $( "#transport-types" ).accordion({ collapsible: true, active:false, animate: 200 });
95 }); 
96 [% IF add_form or copy_form %]
97         
98     function cancel(f) {
99         $('#op').val("");
100         f.method = "get";
101         f.submit();
102     }
103
104                 function isNotNull(f,noalert) {
105                         if (f.value.length ==0) {
106         return false;
107                         }
108                         return true;
109                 }
110
111                 function isNum(v,maybenull) {
112                 var n = new Number(v.value);
113                 if (isNaN(n)) {
114                         return false;
115                         }
116                 if (maybenull==0 && v.value=='') {
117                         return false;
118                 }
119                 return true;
120                 }
121         function insertValueQuery(mtt_id) {
122             var fieldset = $("#" + mtt_id);
123             var myQuery = $(fieldset).find('textarea[name="content"]');
124             var myListBox = $(fieldset).find('select[name="SQLfieldname"]');
125
126             if($(myListBox).find('option').length > 0) {
127                 var chaineAj = "";
128                 var NbSelect = 0;
129                 $(myListBox).find('option').each( function (){
130                     if ( $(this).attr('selected') ) {
131                         NbSelect++;
132                         if (NbSelect > 1)
133                             chaineAj += ", ";
134                         chaineAj += $(this).val();
135                     }
136                 } );
137                 $(myQuery).insertAtCaret("<<" + chaineAj + ">>");
138             }
139         }
140         [% END %]
141                 //]]>
142                 </script>
143 </head>
144 <body id="tools_letter" class="tools">
145 [% INCLUDE 'header.inc' %]
146 [% INCLUDE 'letters-search.inc' %]
147
148 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; [% IF ( add_form or copy_form) %][% IF ( modify ) %]<a href="/cgi-bin/koha/tools/letter.pl">Notices &amp; Slips</a> &rsaquo; Modify notice[% ELSE %] <a href="/cgi-bin/koha/tools/letter.pl">Notices &amp; Slips</a> &rsaquo; Add notice[% END %][% ELSE %][% IF ( add_validate or copy_validate) %] <a href="/cgi-bin/koha/tools/letter.pl">Notices &amp; Slips</a> &rsaquo; Notice added[% ELSE %][% IF ( delete_confirm ) %] <a href="/cgi-bin/koha/tools/letter.pl">Notices &amp; Slips</a> &rsaquo; Confirm deletion[% ELSE %]Notices &amp; Slips[% END %][% END %][% END %]</div>
149
150 [% IF add_form or copy_form %]<div id="doc" class="yui-t7">[% ELSE %]<div id="doc3" class="yui-t2">[% END %]
151    
152    <div id="bd">
153         <div id="yui-main">
154         <div class="yui-b">
155
156 [% IF ( no_op_set ) %]
157     <h1>Notices and Slips</h1>
158     <form method="get" action="/cgi-bin/koha/tools/letter.pl" id="selectlibrary">
159       <input type="hidden" name="searchfield" value="[% searchfield %]" />
160     [% UNLESS independant_branch %]
161       <p>
162         Select a library :
163             <select name="branchcode" id="branch" style="width:20em;">
164                 <option value="">All libraries</option>
165             [% FOREACH branchloo IN branchloop %]
166                 [% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]
167             [% END %]
168             </select>
169       </p>
170     [% END %]
171       <div id="toolbar" class="btn-toolbar">
172           <button type="submit" class="btn btn-small" id="newnotice"><i class="icon-plus"></i> New notice</button>
173         <input type="hidden" id="op" name="op" />
174       </div>
175     </form>
176
177                 [% IF ( search ) %]
178         <p>You searched for <b>[% searchfield %]</b></p>
179                 [% END %]
180                 [% IF ( letter && !independant_branch) %]
181             [% select_for_copy = BLOCK %]
182             <select name="branchcode">
183                 [% FOREACH branchloo IN branchloop %]
184                 <option value="[% branchloo.value %]">Copy to [% branchloo.branchname %]</option>
185                 [% END %]
186             </select>
187             [% END %]
188         [% END %]
189         [% IF letter %]
190           <table id="lettert">
191             <thead>
192               <tr>
193                 <th>Library</th>
194                 <th>Module</th>
195                 <th>Code</th>
196                 <th>Name</th>
197                 <th>Copy notice</th>
198                 <th>&nbsp;</th>
199                 <th>&nbsp;</th>
200               </tr>
201             </thead>
202             <tbody>
203               [% FOREACH lette IN letter %]
204                 [% can_edit = lette.branchcode || !independant_branch %]
205                 <tr>
206                   <td>[% IF lette.branchname %][% lette.branchname %][% ELSE %](All libraries)[% END %]</td>
207                   <td>[% lette.module %]</td>
208                   <td>[% lette.code %]</td>
209                   <td>[% lette.name %]</td>
210                   <td style="white-space: nowrap">
211                     [% IF !independant_branch || !lette.branchcode %]
212                       <form method="post" action="/cgi-bin/koha/tools/letter.pl">
213                         <input type="hidden" name="op" value="copy_form" />
214                         <input type="hidden" name="oldbranchcode" value="[% lette.branchcode %]" />
215                         <input type="hidden" name="module" value="[% lette.module %]" />
216                         <input type="hidden" name="code" value="[% lette.code %]" />
217                         [% IF independant_branch %]
218                           <input type="hidden" name="branchcode" value="[% independant_branch %]" />
219                         [% ELSE %]
220                           [% select_for_copy %]
221                         [% END %]
222                         <input type="submit" value="Copy" />
223                       </form>
224                     [% END %]
225                   </td>
226                   <td>
227                     [% IF can_edit %]
228                       <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>
229                     [% END %]
230                   </td>
231                   <td>
232                     [% IF !lette.protected && can_edit %]
233                       <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>
234                     [% END %]
235                   </td>
236                 </tr>
237               [% END %]
238             </tbody>
239           </table>
240         [% ELSE %]
241           <div class="dialog message">
242           [% IF ( branchcode ) %]
243              <p>There are no notices for this library.</p>
244           [% ELSE %]
245               <p>There are no notices.</p>
246           [% END %]
247           </div>
248         [% END %]
249 [% END %]
250
251         
252 [% IF add_form or copy_form %]
253 <h1>[% IF ( modify ) %]Modify notice[% ELSE %]Add notice[% END %]</h1>
254         <form id="add_notice" name="Aform" method="post" enctype="multipart/form-data" class="validate">
255         [% IF add_form %]
256           <input type="hidden" name="op" id="op" value="add_validate" />
257         [% ELSE %]
258           <input type="hidden" name="op" id="op" value="copy_validate" />
259         [% END %]
260
261                 <input type="hidden" name="checked" value="0" />
262                 [% IF ( modify ) %]
263                 <input type="hidden" name="add" value="0" />
264                 [% ELSE %]
265                 <input type="hidden" name="add" value="1" />
266                 [% END %]
267                 <fieldset class="rows">
268             <input type="hidden" name="oldbranchcode" value="[% oldbranchcode %]" />
269             [% IF independant_branch %]
270                 <input type="hidden" name="branchcode" value="[% independant_branch %]" />
271             [% ELSE %]
272                 <ol>
273                         <li>
274                                 <label for="branch">Library:</label>
275                 <select name="branchcode" id="branch" style="width:20em;">
276                     <option value="">All libraries</option>
277                 [% FOREACH branchloo IN branchloop %]
278                     [% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]
279                 [% END %]
280                 </select>
281                         </li>
282             [% END %]
283                         <li>
284                                 <label for="module">Koha module:</label>
285                                 <input type="hidden" name="oldmodule" value="[% module %]" />
286                 [% IF adding  %]
287                   <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;">
288                 [% ELSE %]
289                   <select name="module" id="module">
290                 [% END %]
291                                     [% IF ( module == "catalogue" ) %]
292                                       <option value="catalogue" selected="selected">Catalog</option>
293                                     [% ELSE %]
294                                       <option value="catalogue" >Catalog</option>
295                                     [% END %]
296                                     [% IF ( module == "circulation" ) %]
297                                       <option value="circulation" selected="selected">Circulation</option>
298                                     [% ELSE %]
299                                       <option value="circulation">Circulation</option>
300                                     [% END %]
301                                     [% IF ( module == "claimacquisition" ) %]
302                                       <option value="claimacquisition" selected="selected">Claim acquisition</option>
303                                     [% ELSE %]
304                                       <option value="claimacquisition">Claim acquisition</option>
305                                     [% END %]
306                                     [% IF ( module == "claimissues" ) %]
307                                       <option value="claimissues" selected="selected">Claim serial issue</option>
308                                     [% ELSE %]
309                                       <option value="claimissues">Claim serial issue</option>
310                                     [% END %]
311                                     [% IF ( module == "reserves" ) %]
312                                       <option value="reserves" selected="selected">Holds</option>
313                                     [% ELSE %]
314                                       <option value="reserves">Holds</option>
315                                     [% END %]
316                                     [% IF ( module == "members" ) %]
317                                       <option value="members" selected="selected">Members</option>
318                                     [% ELSE %]
319                                       <option value="members">Members</option>
320                                     [% END %]
321                                     [% IF ( module == "serial" ) %]
322                                       <option value="serial" selected="selected">Serials (routing list)</option>
323                                     [% ELSE %]
324                                       <option value="serial">Serials (routing list)</option>
325                                     [% END %]
326                                     [% IF ( module == "suggestions" ) %]
327                                       <option value="suggestions" selected="selected">Suggestions</option>
328                                     [% ELSE %]
329                                       <option value="suggestions">Suggestions</option>
330                                     [% END %]
331                 </select>
332             </li>
333             <li>
334               [% IF adding %]
335                   <label for="code" class="required">Code:</label>
336                   <input type="text" id="code" name="code" size="20" maxlength="20" value="" required="required"/>
337                   <span class="required">Required</span>
338               [% ELSE %]
339                   <label for="code">Code:</label>
340                   <input type="hidden" id="code" name="code" size="20" maxlength="20" value="[% code %]" required="required"/>
341                   [% code %]
342               [% END %]
343             </li>
344             <li>
345               <label for="name" class="required">Name:</label>
346               <input type="text" id="name" name="name" size="60" value="[% letter_name %]" required="required" />
347               <span class="required">Required</span>
348             </li>
349         </ol>
350     </fieldset>
351         <div id="transport-types" style="clear:both">
352         [% FOREACH letter IN letters %]
353             <h3>
354                 [% SWITCH letter.message_transport_type %]
355                 [% CASE 'email' %]
356                   Email
357                 [% CASE 'print' %]
358                   Print
359                 [% CASE 'sms' %]
360                   SMS
361                 [% CASE 'feed' %]
362                   Feed
363                 [% CASE 'phone' %]
364                   Phone
365                 [% CASE %]
366                   [% letter.message_transport_type %]
367                 [% END %]
368             </h3>
369             [% IF letter.message_transport_type == "sms" and not Koha.Preference("SMSSendDriver") %]
370               <fieldset class="rows mtt" id="[% letter.message_transport_type %]" disabled="disabled">
371                 <div class="dialog message">You should enable the SMSSendDriver preference to use the SMS templates.</div>
372             [% ELSIF letter.message_transport_type == "phone" and not Koha.Preference("TalkingTechItivaPhoneNotification") %]
373               <fieldset class="rows mtt" id="[% letter.message_transport_type %]" disabled="disabled">
374                 <div class="dialog message">You should enable the TalkingTechItivaPhoneNotification preference to use the phone templates.</div>
375             [% ELSE %]
376               <fieldset class="rows mtt" id="[% letter.message_transport_type %]">
377             [% END %]
378               <ol>
379                 <li>
380                   <input type="hidden" name="message_transport_type" value="[% letter.message_transport_type %]" />
381                   <label for="is_html_[% letter.message_transport_type %]">HTML message:</label>
382                   [% IF letter.is_html %]
383                     <input type="checkbox" name="is_html_[% letter.message_transport_type %]" id="is_html_[% letter.message_transport_type %]" value="1" checked="checked" />
384                   [% ELSE %]
385                     <input type="checkbox" name="is_html_[% letter.message_transport_type %]" id="is_html_[% letter.message_transport_type %]" value="1" />
386                   [% END %]
387                 </li>
388                 <li>
389                   <label for="title_[% letter.message_transport_type %]">Message subject:</label><input type="text" id="title_[% letter.message_transport_type %]" name="title" size="60" value="[% letter.title %]" />
390                 </li>
391                 <li>
392                   <label for="SQLfieldname_[% letter.message_transport_type %]">Message body:</label>
393                   [% IF letter.message_transport_type == 'sms' %]
394                     <span id="sms_counter">[% IF letter.content.length > 0 %][% letter.content.length %][% ELSE %]0[% END %]/160 characters</span>
395                   [% END %]
396                   <table>
397                     <tr>
398                       <td>
399                         <select name="SQLfieldname" id="SQLfieldname_[% letter.message_transport_type %]" multiple="multiple" size="9">
400                           [% FOREACH SQLfieldnam IN SQLfieldname %]
401                             <option value="[% SQLfieldnam.value %]">[% SQLfieldnam.text %]</option>
402                           [% END %]
403                         </select>
404                       </td>
405                       <td><input type="button" name="insert" value="&gt;&gt;" onclick="insertValueQuery('[% letter.message_transport_type %]')" title="Insert" /></td>
406                       <td><textarea name="content" id="content_[% letter.message_transport_type %]" cols="80" rows="15">[% letter.content %]</textarea></td>
407                     </tr>
408                   </table>
409                 </li>
410               </ol>
411             </fieldset>
412         [% END %]
413         </div> <!-- / #transport-types -->
414
415         [% 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 %]
416         <fieldset class="action"><input type="submit" id="submit_form" value="Submit" class="button" /> <a class="cancel" href="/cgi-bin/koha/tools/letter.pl">Cancel</a></fieldset>
417       <input type="hidden" name="searchfield" value="[% searchfield %]" />
418     </form>
419 [% END %]
420
421 [% IF ( add_validate or copy_validate) %]
422         Data recorded
423         <form action="[% action %]" method="post">
424         <input type="submit" value="OK" />
425         </form>
426 [% END %]
427         
428 [% IF ( delete_confirm ) %]
429     <div class="dialog alert"><h3>Delete notice?</h3>
430         <table>
431         <thead>
432                 <tr>
433                         <th>Library</th>
434                         <th>Module</th>
435                         <th>Code</th>
436                         <th>Name</th>
437                 </tr>
438         </thead>
439                 <tr>
440                         <td>[% branchname %]</td>
441                         <td>[% module %]</td>
442             <td>[% code %]</td>
443                         <td>[% name %]</td>
444                 </tr>
445         </table>
446                 <form action="[% action %]" method="post">
447                 <input type="hidden" name="op" value="delete_confirmed">
448                 <input type="hidden" name="branchcode" value="[% branchcode %]" />
449                 <input type="hidden" name="code" value="[% code %]" />
450                 <input type="hidden" name="module" value="[% module %]" />
451                 <input type="submit" value="Yes, delete" class="approve" />
452                                 </form>
453
454                                 <form action="[% action %]" method="get">
455                     <input type="submit" value="No, do not delete" class="deny" />
456                                 </form>
457                 </div>
458
459 [% END %]
460         
461 [% IF ( delete_confirmed ) %]
462         Data deleted
463         <form action="[% action %]" method="post">
464         <input type="submit" value="OK" />
465         </form>
466 [% END %]
467
468 </div>
469 </div>
470 [% UNLESS add_form or copy_form %]
471     <div class="yui-b noprint">
472         [% INCLUDE 'tools-menu.inc' %]
473     </div>
474 [% END %]
475 </div>
476 [% INCLUDE 'intranet-bottom.inc' %]