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