Bug 30093: Rename patron-search.inc to patron-search-header.inc
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / members / merge-patrons.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Branches %]
4 [% USE Categories %]
5 [% USE KohaDates %]
6 [% SET footerjs = 1 %]
7 [% INCLUDE 'doc-head-open.inc' %]
8 <title>Merge patron records &rsaquo; Patrons &rsaquo; Koha</title>
9 [% INCLUDE 'doc-head-close.inc' %]
10 [% FILTER collapse %]
11     <style>
12         ins {
13             background-color: #e6ffe6;
14         }
15         del {
16             background-color: #ffe6e6;
17         }
18         .col0,
19         .col1 {
20             display: none;
21         }
22         .col3 ins,
23         .col2 del {
24             display: none;
25         }
26         #col-label,
27         .col2,
28         .col3 {
29             border-right: 1px solid #EEE;
30             flex-grow: 1;
31             margin-right:1em;
32         }
33         #col-label {
34             font-family: monospace;
35         }
36         #col-label div {
37             white-space: none;
38         }
39         .compare {
40             display: flex;
41         }
42         .modal-lg {
43             width: 90%;
44         }
45     </style>
46 [% END %]
47 </head>
48 <body id="pat_merge" class="pat">
49 [% INCLUDE 'header.inc' %]
50 [% INCLUDE 'patron-search-header.inc' %]
51
52 [% BLOCK display_names %]
53     [% SWITCH rs %]
54         [% CASE 'Accountline'           %]account lines
55         [% CASE 'ArticleRequest'        %]article requests
56         [% CASE 'BorrowerAttribute'     %]extended patron attributes
57         [% CASE 'BorrowerDebarment'     %]patron restrictions
58         [% CASE 'BorrowerFile'          %]patrons files
59         [% CASE 'BorrowerModification'  %]patron modification requests
60         [% CASE 'ClubEnrollment'        %]club enrollments
61         [% CASE 'Issue'                 %]checkouts
62         [% CASE 'ItemsLastBorrower'     %]marks as last borrower of item
63         [% CASE 'Linktracker'           %]tracked link clicks
64         [% CASE 'Message'               %]patron messages
65         [% CASE 'MessageQueue'          %]patron notices
66         [% CASE 'OldIssue'              %]previous checkouts
67         [% CASE 'OldReserve'            %]filled holds
68         [% CASE 'Rating'                %]ratings
69         [% CASE 'Reserve'               %]current holds
70         [% CASE 'Review'                %]reviews
71         [% CASE 'Statistic'             %]statistics
72         [% CASE 'SearchHistory'         %]historical searches
73         [% CASE 'Suggestion'            %]purchase suggestions
74         [% CASE 'TagAll'                %]tags
75         [% CASE 'Virtualshelfcontent'   %]list items
76         [% CASE 'Virtualshelfshare'     %]list shares
77         [% CASE 'Virtualshelve'         %]lists
78         [% CASE %][% rs | html %]
79     [% END %]
80 [% END %]
81
82 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
83     <ol>
84         <li>
85             <a href="/cgi-bin/koha/mainpage.pl">Home</a>
86         </li>
87         <li>
88             <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>
89         </li>
90         <li>
91             <a href="#" aria-current="page">Merge patron records</a>
92         </li>
93     </ol>
94 </nav>
95
96 <div class="main container-fluid">
97     <div class="row">
98         <div class="col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2">
99             <h3>Merge patron records</h3>
100
101             [% IF action == 'show' %]
102                 [% IF patrons.count > 1 %]
103                     [% IF ( patrons.count == 2 ) %]
104                         <div id="toolbar" class="btn-toolbar">
105                             <div class="btn-group">
106                                 <button class="btn btn-default" id="compare_patrons">
107                                     <i class="fa fa-arrows-h"></i> Compare patrons
108                                 </button>
109                             </div>
110                         </div>
111                     [% END %]
112
113                     <p>Select patron to keep. Data from the other patrons will be transferred to this patron record and the remaining patron records will be deleted.</p>
114
115                     <form type="post" action="merge-patrons.pl" id="patron-merge-form">
116                         <table id="patron-merge-table" class="datatable">
117                             <thead>
118                                 <tr>
119                                     <th>&nbsp;</th>
120                                     <th>Card</th>
121                                     <th>Name</th>
122                                     <th>Date of birth</th>
123                                     <th>Category</th>
124                                     <th>Library</th>
125                                     <th>Expires on</th>
126                                 </tr>
127                             </thead>
128
129                             <tbody>
130                                 [% FOREACH p IN patrons %]
131                                     <tr>
132                                         <td><input class="keeper" type="radio" name="keeper" value="[% p.id | html %]" data-borrowernumber="[% p.id | html %]" id="keeper_[% p.id | html %]" /></td>
133                                         <td>
134                                             <label for="keeper_[% p.id | html %]">
135                                                 <strong>[% p.cardnumber | html %]</strong>
136                                             </label>
137                                         </td>
138                                         <td>
139                                             <a target="_blank" href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% p.borrowernumber | uri %]">
140                                                 [% INCLUDE 'patron-title.inc' patron = p %]
141                                                 <i class="fa fa-window-restore"></i>
142                                             </a>
143                                         </td>
144                                         <td>[% p.dateofbirth | $KohaDates %]</td>
145                                         <td>[% Categories.GetName( p.categorycode ) | html %] ([% p.categorycode | html %])</td>
146                                         <td>[% Branches.GetName( p.branchcode ) | html %]</td>
147                                         <td>[% p.dateexpiry | $KohaDates %]</td>
148                                 [% END %]
149                             </tbody>
150                         </table>
151
152                         <fieldset class="action">
153                             [% FOREACH p IN patrons %]
154                                 <input type="hidden" name="id" value="[% p.id | html %]" />
155                             [% END %]
156                             <input type="hidden" name="action" value="merge" />
157                             <input id="merge-patrons" type="submit" value="Merge patrons" />
158                         </fieldset>
159
160                     [% ELSE %]
161                         <div class="dialog alert">Error: Two or more patrons need to be selected for merging</div>
162                     [% END %]
163                 </form>
164             [% ELSIF action == 'merge' %]
165                 <h4>Results</h4>
166                 [% IF error %]
167                     [% IF error == 'INVALID_KEEPER' %]
168                         <div class="dialog alert">Merge failed! The patron to keep was invalid.</div>
169                     [% ELSE %]
170                         <div class="dialog alert">Merge failed! The following error was reported: [% error | html %].</div>
171                     [% END %]
172                 [% ELSIF !results.merged.keys.size %]
173                     <div class="dialog alert">No valid patrons to merge were found.</div>
174                 [% ELSE %]
175                     <p>
176                         Patron records merged into <a href="moremember.pl?borrowernumber=[% keeper.id | uri %]">[% INCLUDE 'patron-title.inc' patron = keeper %]</a>
177                     </p>
178
179                     [% FOREACH pair IN results.merged.pairs %]
180                         [% SET patron = pair.value.patron %]
181
182                         <h5>[% INCLUDE 'patron-title.inc' %]</h5>
183
184                         [% FOREACH r IN pair.value.updated.pairs %]
185                             [% SET name = r.key %]
186                             [% SET count = r.value %]
187                             [% IF count %]
188                                 <p>
189                                     <span>[% count | html %] [% PROCESS display_names rs = name %] transferred.</span>
190                                     [% IF name == 'Reserve' %]
191                                         <strong>It is advisable to check for and resolve duplicate holds due to merging.</strong>
192                                     [% END %]
193                                 </p>
194                             [% END %]
195                         [% END %]
196                     [% END %]
197                 [% END %]
198
199                 [% UNLESS error %]
200                     <a class="btn btn-default" href="moremember.pl?borrowernumber=[% keeper.id | html %]">View patron record</a>
201                 [% END %]
202             [% END %]
203         </div>
204     </div>
205
206     <!-- Modal -->
207     <div class="modal" id="compareModal" tabindex="-1" role="dialog" aria-labelledby="compareModalLabel">
208         <div class="modal-dialog modal-lg" role="document">
209             <div class="modal-content">
210                 <div class="modal-header">
211                     <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
212                     <h4 class="modal-title" id="compareModalLabel">Compare patrons for merging</h4>
213                 </div>
214                 <div class="modal-body">
215                     <div class="compare">
216                         <div id="col-label">
217                             <div><strong>Name:</strong></div>
218                             <div><strong>Initials:</strong></div>
219                             <div><strong>Other name:</strong></div>
220                             <div><strong>Library:</strong></div>
221                             <div><strong>Card number:</strong></div>
222                             <div><strong>Category:</strong></div>
223                             <br />
224                             <div><strong>Address line 1:</strong></div>
225                             <div><strong>Address line 2:</strong></div>
226                             <div><strong>City:</strong></div>
227                             <div><strong>State:</strong></div>
228                             <div><strong>ZIP/Postal code:</strong></div>
229                             <div><strong>Country:</strong></div>
230                             <br />
231                             <div><strong>Registration date:</strong></div>
232                             <div><strong>Renewal date:</strong></div>
233                             <div><strong>Expiration date:</strong></div>
234                             <div><strong>Date of birth:</strong></div>
235                             <div><strong>Restricted:</strong></div>
236                             <div><strong>Primary email:</strong></div>
237                             <div><strong>Secondary email:</strong></div>
238                             <div><strong>Primary phone:</strong></div>
239                             <div><strong>Secondary phone:</strong></div>
240                             <div><strong>Other phone:</strong></div>
241                             <div><strong>Gender:</strong></div>
242                             <div><strong>Updated on:</strong></div>
243                             <div><strong>Username:</strong></div>
244                         </div>
245
246                         [% FOREACH p IN patrons %]
247                             <div id="col-[% p.borrowernumber | html %]-orig"class="col[% loop.index | html %]">
248 <!-- <pre> block is unindented to avoid unwanted whitespace -->
249 <pre>
250 [% IF ( p.surname ) %][% p.surname | html %], [% p.firstname | html %][% ELSE %]-[% END %]
251 [% IF ( p.initials ) %][% p.initials | html %][% ELSE %]-[% END %]
252 [% IF ( p.othernames ) %][% p.othernames | html %][% ELSE %]-[% END %]
253 [% IF ( p.branchcode ) %][% p.branchcode | html %][% ELSE %]-[% END %]
254 [% IF ( p.cardnumber ) %][% p.cardnumber | html %][% ELSE %]-[% END %]
255 [% IF ( p.categorycode ) %][% p.categorycode | html %][% ELSE %]-[% END %]
256
257 [% IF ( p.address ) %][% p.address | html %][% ELSE %]-[% END %]
258 [% IF ( p.address2 ) %][% p.address2 | html %][% ELSE %]-[% END %]
259 [% IF ( p.city ) %][% p.city | html %][% ELSE %]-[% END %]
260 [% IF ( p.state ) %][% p.state | html %][% ELSE %]-[% END %]
261 [% IF ( p.zipcode ) %][% p.zipcode | html %][% ELSE %]-[% END %]
262 [% IF ( p.country ) %][% p.country | html %][% ELSE %]-[% END %]
263
264 [% IF ( p.dateenrolled ) %][% p.dateenrolled | html %][% ELSE %]-[% END %]
265 [% IF ( p.date_renewed ) %][% p.date_renewed | html %][% ELSE %]-[% END %]
266 [% IF ( p.dateexpiry ) %][% p.dateexpiry | html %][% ELSE %]-[% END %]
267 [% IF ( p.dateofbirth ) %][% p.dateofbirth | html %][% ELSE %]-[% END %]
268 [% IF ( p.debarred ) %][% p.debarred | html %][% ELSE %]-[% END %]
269 [% IF ( p.email ) %][% p.email | html %][% ELSE %]-[% END %]
270 [% IF ( p.emailpro ) %][% p.emailpro | html %][% ELSE %]-[% END %]
271 [% IF ( p.phone ) %][% p.phone | html %][% ELSE %]-[% END %]
272 [% IF ( p.phonepro ) %][% p.phonepro | html %][% ELSE %]-[% END %]
273 [% IF ( p.mobile ) %][% p.mobile | html %][% ELSE %]-[% END %]
274 [% IF ( p.sex ) %][% p.sex | html %][% ELSE %]-[% END %]
275 [% IF ( p.updated_on ) %][% p.updated_on | html %][% ELSE %]-[% END %]
276 [% IF ( p.userid ) %][% p.userid | html %][% ELSE %]-[% END %]
277 </pre>
278                             </div>
279                         [% END %]
280                         [% FOREACH p IN patrons %]
281                             <div id="col-[% p.borrowernumber | html %]-diff" class="col[% ( loop.index + 2 ) | html %]"><pre></pre></div>
282                         [% END %]
283                     </div>
284                 </div>
285                 <div class="modal-footer">
286                     <button type="button" class="btn btn-default" id="submit-merge-form"><i class="fa fa-compress" aria-hidden="true"></i> Merge patrons</button>
287                     <button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-remove" aria-hidden="true"></i> Close</button>
288                 </div>
289             </div> <!-- /.modal-content -->
290         </div> <!-- /.modal-dialog -->
291     </div> <!-- /#compareModal -->
292
293 [% MACRO jsinclude BLOCK %]
294     [% INCLUDE 'str/members-menu.inc' %]
295     [% Asset.js("js/members-menu.js") | $raw %]
296     [% Asset.js("lib/jsdiff/jsdiff.min.js") | $raw %]
297     <script>
298     $(document).ready(function() {
299         var controls = $("#merge-patrons, #compare_patrons");
300         controls.prop('disabled', true);
301         $('#patron-merge-table').on('change', 'input', function() {
302             if ( $('.keeper:checked').length > 0 ) {
303                 controls.prop('disabled', false);
304             } else {
305                 controls.prop('disabled', true);
306             }
307         });
308
309         $("#compare_patrons").on("click", function(e){
310             e.preventDefault();
311             $("#compareModal").modal("show");
312         });
313
314         $("#compareModal").on("shown.bs.modal", function(){
315             /* Find which column is the basis for merging */
316             var col0 = $(".keeper:checked").data("borrowernumber");
317             var col1 = $(".keeper:not(:checked)").data("borrowernumber");
318             /* Get the original patron data for comparison */
319             var diff1 = $("#col-" + col0 + "-orig pre").text();
320             var diff2 = $("#col-" + col1 + "-orig pre").text();
321
322             var diffs = diffString(diff2, diff1);
323             /* Load the diff HTML in the empty columns */
324             $(".col2 pre, .col3 pre").html(diffs);
325         });
326
327         $("#submit-merge-form").on("click", function(){
328             $("#patron-merge-form").submit();
329         });
330     });
331
332     </script>
333 [% END %]
334
335 [% INCLUDE 'intranet-bottom.inc' %]