Bug 11742: FIX the code parameter was not take into account
[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         [% IF copy_form %]
57           if ( new_lettercode == '[% code %]' ) {
58             alert( _("Please change the code.") );
59             return false;
60           }
61         [% END %]
62
63         [% IF ( add_form and code ) # IF edit %]
64           if ( new_lettercode != '[% code %]' ) {
65         [% END %]
66           $.ajax({
67             data: { code: new_lettercode },
68             type: 'GET',
69             url: '/cgi-bin/koha/svc/letters/',
70             success: function (data) {
71               if ( data.letters.length > 0 ) {
72                 alert( _("This letter code is already used for another letter.") );
73                 return false;
74               } else {
75                 $("#add_notice").submit();
76               }
77             },
78           });
79         [% IF ( add_form and code ) %]
80           } else {
81             $("#add_notice").submit();
82           }
83         [% END %]
84     });
85
86     var sms_limit = 160;
87     $("#content_sms").on("keyup", function(){
88         var length = $(this).val().length;
89         $("#sms_counter").html(length + "/" + sms_limit + _(" characters"));
90         if ( length  > sms_limit ) {
91             $("#sms_counter").css("color", "red");
92         } else {
93             $("#sms_counter").css("color", "black");
94         }
95     });
96 }); 
97 [% IF add_form or copy_form %]
98         
99     function cancel(f) {
100         $('#op').val("");
101         f.method = "get";
102         f.submit();
103     }
104
105                 function isNotNull(f,noalert) {
106                         if (f.value.length ==0) {
107         return false;
108                         }
109                         return true;
110                 }
111
112                 function isNum(v,maybenull) {
113                 var n = new Number(v.value);
114                 if (isNaN(n)) {
115                         return false;
116                         }
117                 if (maybenull==0 && v.value=='') {
118                         return false;
119                 }
120                 return true;
121                 }
122         function insertValueQuery(mtt_id) {
123             var fieldset = $("#" + mtt_id);
124             var myQuery = $(fieldset).find('textarea[name="content"]');
125             var myListBox = $(fieldset).find('select[name="SQLfieldname"]');
126
127             if($(myListBox).find('option').length > 0) {
128                 var chaineAj = "";
129                 var NbSelect = 0;
130                 $(myListBox).find('option').each( function (){
131                     if ( $(this).attr('selected') ) {
132                         NbSelect++;
133                         if (NbSelect > 1)
134                             chaineAj += ", ";
135                         chaineAj += $(this).val();
136                     }
137                 } );
138                 $(myQuery).insertAtCaret("<<" + chaineAj + ">>");
139             }
140         }
141         [% END %]
142                 //]]>
143                 </script>
144 </head>
145 <body id="tools_letter" class="tools">
146 [% INCLUDE 'header.inc' %]
147 [% INCLUDE 'letters-search.inc' %]
148
149 <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>
150
151 [% IF add_form or copy_form %]<div id="doc" class="yui-t7">[% ELSE %]<div id="doc3" class="yui-t2">[% END %]
152    
153    <div id="bd">
154         <div id="yui-main">
155         <div class="yui-b">
156
157 [% IF ( no_op_set ) %]
158     <h1>Notices and Slips</h1>
159     <form method="get" action="/cgi-bin/koha/tools/letter.pl" id="selectlibrary">
160       <input type="hidden" name="searchfield" value="[% searchfield %]" />
161     [% UNLESS independant_branch %]
162       <p>
163         Select a library :
164             <select name="branchcode" id="branch" style="width:20em;">
165                 <option value="">All libraries</option>
166             [% FOREACH branchloo IN branchloop %]
167                 [% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]
168             [% END %]
169             </select>
170       </p>
171     [% END %]
172       <div id="toolbar" class="btn-toolbar">
173           <button type="submit" class="btn btn-small" id="newnotice"><i class="icon-plus"></i> New notice</button>
174         <input type="hidden" id="op" name="op" />
175       </div>
176     </form>
177
178                 [% IF ( search ) %]
179         <p>You searched for <b>[% searchfield %]</b></p>
180                 [% END %]
181                 [% IF ( letter && !independant_branch) %]
182             [% select_for_copy = BLOCK %]
183             <select name="branchcode">
184                 [% FOREACH branchloo IN branchloop %]
185                 <option value="[% branchloo.value %]">Copy to [% branchloo.branchname %]</option>
186                 [% END %]
187             </select>
188             [% END %]
189         [% END %]
190         [% IF letter %]
191           <table id="lettert">
192             <thead>
193               <tr>
194                 <th>Library</th>
195                 <th>Module</th>
196                 <th>Code</th>
197                 <th>Name</th>
198                 <th>Copy notice</th>
199                 <th>&nbsp;</th>
200                 <th>&nbsp;</th>
201               </tr>
202             </thead>
203             <tbody>
204               [% FOREACH lette IN letter %]
205                 [% can_edit = lette.branchcode || !independant_branch %]
206                 <tr>
207                   <td>[% IF lette.branchname %][% lette.branchname %][% ELSE %](All libraries)[% END %]</td>
208                   <td>[% lette.module %]</td>
209                   <td>[% lette.code %]</td>
210                   <td>[% lette.name %]</td>
211                   <td style="white-space: nowrap">
212                     [% IF !independant_branch || !lette.branchcode %]
213                       <form method="post" action="/cgi-bin/koha/tools/letter.pl">
214                         <input type="hidden" name="op" value="copy_form" />
215                         <input type="hidden" name="oldbranchcode" value="[% lette.branchcode %]" />
216                         <input type="hidden" name="module" value="[% lette.module %]" />
217                         <input type="hidden" name="code" value="[% lette.code %]" />
218                         [% IF independant_branch %]
219                           <input type="hidden" name="branchcode" value="[% independant_branch %]" />
220                         [% ELSE %]
221                           [% select_for_copy %]
222                         [% END %]
223                         <input type="submit" value="Copy" />
224                       </form>
225                     [% END %]
226                   </td>
227                   <td>
228                     [% IF can_edit %]
229                       <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>
230                     [% END %]
231                   </td>
232                   <td>
233                     [% IF !lette.protected && can_edit %]
234                       <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>
235                     [% END %]
236                   </td>
237                 </tr>
238               [% END %]
239             </tbody>
240           </table>
241         [% ELSE %]
242           <div class="dialog message">
243           [% IF ( branchcode ) %]
244              <p>There are no notices for this library.</p>
245           [% ELSE %]
246               <p>There are no notices.</p>
247           [% END %]
248           </div>
249         [% END %]
250 [% END %]
251
252         
253 [% IF add_form or copy_form %]
254 <h1>[% IF ( modify ) %]Modify notice[% ELSE %]Add notice[% END %]</h1>
255         <form id="add_notice" name="Aform" method="post" enctype="multipart/form-data" class="validate">
256         [% IF add_form %]
257           <input type="hidden" name="op" id="op" value="add_validate" />
258         [% ELSE %]
259           <input type="hidden" name="op" id="op" value="copy_validate" />
260         [% END %]
261
262                 <input type="hidden" name="checked" value="0" />
263                 [% IF ( modify ) %]
264                 <input type="hidden" name="add" value="0" />
265                 [% ELSE %]
266                 <input type="hidden" name="add" value="1" />
267                 [% END %]
268                 <fieldset class="rows">
269             <input type="hidden" name="oldbranchcode" value="[% oldbranchcode %]" />
270             [% IF independant_branch %]
271                 <input type="hidden" name="branchcode" value="[% independant_branch %]" />
272             [% ELSE %]
273                 <ol>
274                         <li>
275                                 <label for="branch">Library:</label>
276                 <select name="branchcode" id="branch" style="width:20em;">
277                     <option value="">All libraries</option>
278                 [% FOREACH branchloo IN branchloop %]
279                     [% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]
280                 [% END %]
281                 </select>
282                         </li>
283             [% END %]
284                         <li>
285                                 <label for="module">Koha module:</label>
286                                 <input type="hidden" name="oldmodule" value="[% module %]" />
287                 [% IF adding  %]
288                   <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;">
289                 [% ELSE %]
290                   <select name="module" id="module">
291                 [% END %]
292                                     [% IF ( module == "catalogue" ) %]
293                                       <option value="catalogue" selected="selected">Catalog</option>
294                                     [% ELSE %]
295                                       <option value="catalogue" >Catalog</option>
296                                     [% END %]
297                                     [% IF ( module == "circulation" ) %]
298                                       <option value="circulation" selected="selected">Circulation</option>
299                                     [% ELSE %]
300                                       <option value="circulation">Circulation</option>
301                                     [% END %]
302                                     [% IF ( module == "claimacquisition" ) %]
303                                       <option value="claimacquisition" selected="selected">Claim acquisition</option>
304                                     [% ELSE %]
305                                       <option value="claimacquisition">Claim acquisition</option>
306                                     [% END %]
307                                     [% IF ( module == "claimissues" ) %]
308                                       <option value="claimissues" selected="selected">Claim serial issue</option>
309                                     [% ELSE %]
310                                       <option value="claimissues">Claim serial issue</option>
311                                     [% END %]
312                                     [% IF ( module == "reserves" ) %]
313                                       <option value="reserves" selected="selected">Holds</option>
314                                     [% ELSE %]
315                                       <option value="reserves">Holds</option>
316                                     [% END %]
317                                     [% IF ( module == "members" ) %]
318                                       <option value="members" selected="selected">Members</option>
319                                     [% ELSE %]
320                                       <option value="members">Members</option>
321                                     [% END %]
322                                     [% IF ( module == "serial" ) %]
323                                       <option value="serial" selected="selected">Serials (routing list)</option>
324                                     [% ELSE %]
325                                       <option value="serial">Serials (routing list)</option>
326                                     [% END %]
327                                     [% IF ( module == "suggestions" ) %]
328                                       <option value="suggestions" selected="selected">Suggestions</option>
329                                     [% ELSE %]
330                                       <option value="suggestions">Suggestions</option>
331                                     [% END %]
332                 </select>
333             </li>
334             <li>
335               <label for="code" class="required">Code:</label>
336               <input type="text" id="code" name="code" size="20" maxlength="20" value="[% code %]" required="required"/>
337               <span class="required">Required</span>
338               [% IF copying %]
339                 You must change this code to reflect the copy.
340               [% END %]
341               <input type="hidden" id="code" name="oldcode" value="[% oldcode %]" />
342             </li>
343             <li>
344               <label for="name" class="required">Name:</label>
345               <input type="text" id="name" name="name" size="60" value="[% letter_name %]" required="required" />
346               <span class="required">Required</span>
347           </li>
348
349         [% FOREACH letter IN letters %]
350           <li>
351             [% IF letter.message_transport_type == "sms" and not Koha.Preference("SMSSendDriver") %]
352               <fieldset class="rows mtt" id="[% letter.message_transport_type %]" disabled="disabled">
353                 <div class="dialog message">You should enable the SMSSendDriver preference to use the SMS templates.</div>
354             [% ELSIF letter.message_transport_type == "phone" and not Koha.Preference("TalkingTechItivaPhoneNotification") %]
355               <fieldset class="rows mtt" id="[% letter.message_transport_type %]" disabled="disabled">
356                 <div class="dialog message">You should enable the TalkingTechItivaPhoneNotification preference to use the phone templates.</div>
357             [% ELSE %]
358               <fieldset class="rows mtt" id="[% letter.message_transport_type %]">
359             [% END %]
360               <legend>
361                 [% SWITCH letter.message_transport_type %]
362                 [% CASE 'email' %]
363                   Email
364                 [% CASE 'print' %]
365                   Print
366                 [% CASE 'sms' %]
367                   SMS
368                 [% CASE 'feed' %]
369                   Feed
370                 [% CASE 'phone' %]
371                   Phone
372                 [% CASE %]
373                   [% letter.message_transport_type %]
374                 [% END %]
375               </legend>
376               <ol>
377                 <li>
378                   <input type="hidden" name="message_transport_type" value="[% letter.message_transport_type %]" />
379                   <label for="is_html_[% letter.message_transport_type %]">HTML message:</label>
380                   [% IF letter.is_html %]
381                     <input type="checkbox" name="is_html_[% letter.message_transport_type %]" id="is_html_[% letter.message_transport_type %]" value="1" checked="checked" />
382                   [% ELSE %]
383                     <input type="checkbox" name="is_html_[% letter.message_transport_type %]" id="is_html_[% letter.message_transport_type %]" value="1" />
384                   [% END %]
385                 </li>
386                 <li>
387                   <label for="title">Message subject:</label><input type="text" id="title" name="title" size="60" value="[% letter.title %]" />
388                 </li>
389                 <li>
390                   <label for="SQLfieldname">Message body:</label>
391                   [% IF letter.message_transport_type == 'sms' %]
392                     <span id="sms_counter">[% IF letter.content.length > 0 %][% letter.content.length %][% ELSE %]0[% END %]/160 characters</span>
393                   [% END %]
394                   <table>
395                     <tr>
396                       <td>
397                         <select name="SQLfieldname" multiple="multiple" size="9">
398                           [% FOREACH SQLfieldnam IN SQLfieldname %]
399                             <option value="[% SQLfieldnam.value %]">[% SQLfieldnam.text %]</option>
400                           [% END %]
401                         </select>
402                       </td>
403                       <td><input type="button" name="insert" value="&gt;&gt;" onclick="insertValueQuery('[% letter.message_transport_type %]')" title="Insert" /></td>
404                       <td><textarea name="content" id="content_[% letter.message_transport_type %]" cols="80" rows="15">[% letter.content %]</textarea></td>
405                     </tr>
406                   </table>
407                 </li>
408               </ol>
409             </fieldset>
410           </li>
411         [% END %]
412         </ol>
413
414         [% 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 %]
415         </fieldset>
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="hidden" name="message_transport_type" value="*" />
452                 <input type="submit" value="Yes, delete" class="approve" />
453                                 </form>
454
455                                 <form action="[% action %]" method="get">
456                     <input type="submit" value="No, do not delete" class="deny" />
457                                 </form>
458                 </div>
459
460 [% END %]
461         
462 [% IF ( delete_confirmed ) %]
463         Data deleted
464         <form action="[% action %]" method="post">
465         <input type="submit" value="OK" />
466         </form>
467 [% END %]
468
469 </div>
470 </div>
471 [% UNLESS add_form or copy_form %]
472     <div class="yui-b noprint">
473         [% INCLUDE 'tools-menu.inc' %]
474     </div>
475 [% END %]
476 </div>
477 [% INCLUDE 'intranet-bottom.inc' %]