Bug 35650: (follow-up) Other cases found
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / csv-profiles.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% PROCESS 'i18n.inc' %]
4 [% SET footerjs = 1 %]
5 [% INCLUDE 'doc-head-open.inc' %]
6 <title>[% FILTER collapse %]
7     [% IF op == 'add_form' %]
8         [% IF csv_profile %]
9             [% tx("Modify CSV profile '{csv_profile_name}'", {csv_profile_name = csv_profile.profile }) | html %] &rsaquo;
10         [% ELSE %]
11             [% t("New CSV profile") | html %] &rsaquo;
12         [% END %]
13     [% ELSIF ( op == 'delete_confirm' ) %]
14         [% tx("Confirm deletion of CSV profile '{csv_profile_name}'", {csv_profile_name = csv_profile.profile }) | html %] &rsaquo;
15     [% END %]
16     [% t("CSV profiles") | html %] &rsaquo;
17     [% t("Tools") | html %] &rsaquo;
18     [% t("Koha") | html %]
19 [% END %]</title>
20 [% INCLUDE 'doc-head-close.inc' %]
21 </head>
22
23 <body id="tools_csv-profiles" class="tools">
24 [% WRAPPER 'header.inc' %]
25     [% INCLUDE 'cat-search.inc' %]
26 [% END %]
27
28 [% WRAPPER 'sub-header.inc' %]
29     [% WRAPPER breadcrumbs %]
30         [% WRAPPER breadcrumb_item %]
31             <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
32         [% END %]
33         [% IF op == 'add_form' || op == 'delete_confirm' %]
34             [% WRAPPER breadcrumb_item %]
35                 <a href="/cgi-bin/koha/tools/csv-profiles.pl">CSV profiles</a>
36             [% END %]
37         [% END %]
38         [% IF op == 'add_form' %]
39             [% IF csv_profile %]
40                 [% WRAPPER breadcrumb_item bc_active= 1 %]
41                     [% tx("Modify CSV profile '{csv_profile_name}'", {csv_profile_name = csv_profile.profile }) | html %]
42                 [% END %]
43             [% ELSE %]
44                 [% WRAPPER breadcrumb_item bc_active= 1 %]
45                     <span>New CSV profile</span>
46                 [% END %]
47             [% END %]
48         [% ELSIF ( op == 'delete_confirm') %]
49             [% WRAPPER breadcrumb_item bc_active= 1 %]
50                 [% tx("Confirm deletion of CSV profile '{csv_profile_name}'", {csv_profile_name = csv_profile.profile }) | html %]
51             [% END %]
52         [% ELSE %]
53             [% WRAPPER breadcrumb_item bc_active= 1 %]
54                 <span>CSV profiles</span>
55             [% END %]
56         [% END %]
57     [% END #/ WRAPPER breadcrumbs %]
58 [% END #/ WRAPPER sub-header.inc %]
59
60 <div class="main container-fluid">
61     <div class="row">
62         <div class="col-sm-10 col-sm-push-2">
63             <main>
64
65 [% FOR m IN messages %]
66     <div class="dialog [% m.type | html %]">
67         [% SWITCH m.code %]
68         [% CASE 'error_on_update' %]
69             <span>An error occurred when updating this CSV profile. Perhaps it already exists.</span>
70         [% CASE 'error_on_insert' %]
71             <span>An error occurred when adding this CSV profile.</span>
72         [% CASE 'error_on_delete' %]
73             <span>An error occurred when deleting this CSV profile. Check the logs for details.</span>
74         [% CASE 'success_on_update' %]
75             <span>CSV profile updated successfully.</span>
76         [% CASE 'success_on_insert' %]
77             <span>CSV profile added successfully.</span>
78         [% CASE 'success_on_delete' %]
79             <span>CSV profile deleted successfully.</span>
80         [% CASE 'already_exists' %]
81             <span>This CSV profile already exists.</span>
82         [% CASE %]
83             <span>[% m.code | html %]</span>
84         [% END %]
85     </div>
86 [% END %]
87
88 [% BLOCK list_separator_options %]
89     [% IF selected_separator == ',' %]
90         <option value="," selected="selected">Comma (,)</option>
91     [% ELSE %]
92         <option value=",">Comma (,)</option>
93     [% END %]
94     [% IF selected_separator == '|' %]
95         <option value="|" selected="selected">Pipe (|)</option>
96     [% ELSE %]
97         <option value="|">Pipe (|)</option>
98     [% END %]
99     [% IF selected_separator == ';' %]
100         <option value=";" selected="selected">Semi-colon (;)</option>
101     [% ELSE %]
102         <option value=";">Semi-colon (;)</option>
103     [% END %]
104     [% IF selected_separator == '#' %]
105         <option value="#" selected="selected">Sharp (#)</option>
106     [% ELSE %]
107         <option value="#">Sharp (#)</option>
108     [% END %]
109     [% IF selected_separator == ' ' %]
110         <option value=" " selected="selected">Space ( )</option>
111     [% ELSE %]
112         <option value=" ">Space ( )</option>
113     [% END %]
114     [% tab_char = '\t' %]
115     [% IF selected_separator == '\t' %]
116         <option value="\t" selected="selected">Tabulation ([% tab_char | html %])</option>
117     [% ELSE %]
118         <option value="\t">Tabulation ([% tab_char | html %])</option>
119     [% END %]
120     [% new_line_char = '\n' %]
121     [% IF selected_separator == '\n' %]
122         <option value="\n" selected="selected">New line ([% new_line_char | html %])</option>
123     [% ELSE %]
124         <option value="\n">New line ([% new_line_char | html %])</option>
125     [% END %]
126 [% END %]
127
128 [% BLOCK type_description %]
129     [% IF type_code == 'marc' %] <span>MARC</span>
130     [% ELSIF type_code == 'sql' %] <span>SQL</span>
131     [% ELSE %] <span>Unknown type</span>
132     [% END %]
133 [% END %]
134
135 [% BLOCK used_for_description %]
136     [% IF used_for_code == 'export_records' %] <span>Export records</span>
137     [% ELSIF used_for_code == 'late_issues' %] <span>Late serial issues claims</span>
138     [% ELSIF used_for_code == 'late_orders' %] <span>Export late orders</span>
139     [% ELSIF used_for_code == 'export_basket' %] <span>Basket export in acquisition</span>
140     [% ELSIF used_for_code == 'export_lost_items' %] <span>Export lost items in report</span>
141     [% ELSE %] <span>Unknown usage</span>
142     [% END %]
143 [% END %]
144
145 [% IF op == 'add_form' %]
146     [% IF csv_profile %]
147         <h1>[% tx("Modify CSV profile '{csv_profile_name}'", {csv_profile_name = csv_profile.profile }) | html %]</h1>
148     [% ELSE %]
149         <h1>New CSV profile</h1>
150     [% END %]
151
152     <form action="/cgi-bin/koha/tools/csv-profiles.pl" class="validated" method="post">
153         <input type="hidden" name="op" value="add_validate" />
154         <input type="hidden" name="export_format_id" value="[% csv_profile.export_format_id | html %]" />
155         <fieldset class="rows">
156             <ol>
157                 [% IF csv_profile %]
158                     <li><span class="label">Profile ID: </span>[% csv_profile.export_format_id | html %]</li>
159                 [% END %]
160                 <li>
161                     <label for="profile" class="required">Profile name: </label>
162                     <input type="text" name="profile" id="profile" value="[% csv_profile.profile | html %]" class="required">
163                     <span class="required">Required</span>
164                 </li>
165                 <li>
166                     <label for="type" class="required">Profile type: </label>
167                     <select id="type" name="type">
168                         [% FOREACH type IN [ 'marc' 'sql'] %]
169                         [% IF csv_profile.type == type %]
170                             <option value="[% type | html %]" selected="selected">[% PROCESS type_description type_code = type %]</option>
171                         [% ELSE %]
172                             <option value="[% type | html %]">[% PROCESS type_description type_code = type %]</option>
173                         [% END %]
174                         [% END %]
175                     </select>
176                     <span class="required">Required</span>
177                 </li>
178                 <li class="sql_specific">
179                     <label for="used_for_sql">Usage: </label>
180                     <select id="used_for_sql" name="used_for_sql">
181                         [% FOREACH used_for IN [ 'late_issues' 'late_orders', 'export_basket' 'export_lost_items' ] %]
182                         [% IF csv_profile.used_for == used_for %]
183                             <option value="[% used_for | html %]" selected="selected">[% PROCESS used_for_description used_for_code = used_for %]</option>
184                         [% ELSE %]
185                             <option value="[% used_for | html %]">[% PROCESS used_for_description used_for_code = used_for %]</option>
186                         [% END %]
187                         [% END %]
188                     </select>
189                 </li>
190                 <li class="marc_specific">
191                     <label for="used_for_marc">Usage: </label>
192                     <select id="used_for_marc" name="used_for_marc">
193                         [% FOREACH used_for IN [ 'export_records' ] %]
194                         [% IF csv_profile.used_for == used_for %]
195                             <option value="[% used_for | html %]" selected="selected">[% PROCESS used_for_description used_for_code = used_for %]</option>
196                         [% ELSE %]
197                             <option value="[% used_for | html %]">[% PROCESS used_for_description used_for_code = used_for %]</option>
198                         [% END %]
199                         [% END %]
200                     </select>
201                 </li>
202                 <li>
203                     <label for="description">Profile description: </label>
204                     <textarea cols="50" rows="2" name="description" id="description">[% csv_profile.description | html %]</textarea>
205                 </li>
206                 <li>
207                     <label for="csv_separator">CSV separator: </label>
208                     <select name="csv_separator" id="csv_separator">
209                         [% PROCESS list_separator_options selected_separator=csv_profile.csv_separator || ',' %]
210                     </select>
211                 </li>
212
213                 <li class="marc_specific">
214                     <label for="field_separator">Field separator: </label>
215                     <select name="field_separator" id="field_separator">
216                         [% PROCESS list_separator_options selected_separator=csv_profile.field_separator || '#' %]
217                     </select>
218                 </li>
219
220                 <li class="marc_specific"><label for="subfield_separator">Subfield separator: </label>
221                     <select name="subfield_separator" id="subfield_separator">
222                         [% PROCESS list_separator_options selected_separator=csv_profile.subfield_separator || '|'%]
223                     </select>
224                 </li>
225
226                 <li class="marc_specific"><label for="encoding">Encoding: </label>
227                     <select name="encoding" id="encoding">
228                         [% FOREACH encoding IN encodings %]
229                             [% IF csv_profile.encoding == encoding OR NOT csv_profile AND encoding == 'utf8' %]
230                                 <option selected="selected">[% encoding | html %]</option>
231                             [% ELSE %]
232                                 <option>[% encoding | html %]</option>
233                             [% END %]
234                         [% END %]
235                     </select>
236                 </li>
237
238                 <li class="marc_specific">
239                     <label for="staff_only">Only available on the staff interface: </label>
240                     [% IF csv_profile.staff_only %]
241                         <input type="checkbox" name="staff_only" id="staff_only" value="1" checked="checked">
242                     [% ELSE %]
243                         <input type="checkbox" name="staff_only" id="staff_only" value="1">
244                     [% END %]
245                 </li>
246
247                 <li class="marc_specific">
248                     <label for="marc_content" class="required">Profile MARC fields: </label>
249                     <textarea cols="50" rows="2" name="marc_content" id="marc_content">[% csv_profile.content | html %]</textarea>
250                     <span class="required">Required</span>
251                     <p>You have to define which fields or subfields you want to export, separated by pipes.</p>
252                     <p>You can also use your own headers (instead of the ones from Koha) by prefixing the field number with an header, followed by the equal sign.</p>
253                     <p>Example: Personal name=200|Entry element=210$a|300|009</p>
254                     <p>You can use Template Toolkit tags too. See the help page for more information.</p>
255                 </li>
256
257                 <li class="sql_specific">
258                     <label for="sql_content" class="required">Profile SQL fields: </label>
259                     <textarea cols="50" rows="2" name="sql_content" id="sql_content">[% csv_profile.content | html %]</textarea>
260                     <p>You have to define which fields you want to export, separated by pipes.</p>
261                     <p>You can also use your own headers (instead of the ones from Koha) by prefixing the field name with an header, followed by the equal sign.</p>
262                     <p>Example: Name=subscription.name|Title=subscription.title|Issue number=serial.serialseq</p>
263                     <p>For late issues claims you can use data from following tables: serial, subscription, biblio, biblioitems and aqbookseller.</p>
264                     <p>For basket exports you can use data from following tables: biblio, biblioitems, aqorders, aqbudgets and aqbasket.</p>
265                     <p>For exporting late orders you must provide a profile in Template Toolkit syntax to generate the CSV file.</p>
266                 </li>
267             </ol>
268         </fieldset>
269         <fieldset class="action">
270             <input type="submit" class="btn btn-primary" value="Submit" />
271             <a class="cancel" href="/cgi-bin/koha/tools/csv-profiles.pl">Cancel</a>
272         </fieldset>
273     </form>
274 [% END %]
275
276 [% IF op == 'delete_confirm' %]
277     <div class="dialog alert">
278         [% IF csv_profile %]
279             <h1>[% tx("Delete CSV profile '{csv_profile_name}'?", {csv_profile_name = csv_profile.profile }) | html %]</h1>
280             <form action="/cgi-bin/koha/tools/csv-profiles.pl" method="post">
281                 <input type="hidden" name="op" value="delete_confirmed" />
282                 <input type="hidden" name="export_format_id" value="[% csv_profile.export_format_id | html %]" />
283                 <button type="submit" class="approve"><i class="fa fa-check" aria-hidden="true"></i> Yes, delete</button>
284             </form>
285             <form action="/cgi-bin/koha/tools/csv-profiles.pl" method="get">
286                 <button type="submit" class="deny"><i class="fa fa-remove" aria-hidden="true"></i> No, do not delete</button>
287             </form>
288         [% ELSE %]
289             This CSV Profile does not exist.
290         [% END %]
291     </div>
292 [% END %]
293
294 [% IF op == 'list' %]
295
296     <div id="toolbar" class="btn-toolbar">
297         <a class="btn btn-default" id="newcsvprofile" href="/cgi-bin/koha/tools/csv-profiles.pl?op=add_form"><i class="fa fa-plus"></i> New CSV profile</a>
298     </div>
299
300     <h1>CSV profiles</h1>
301
302     [% IF csv_profiles %]
303     <div class="page-section">
304         <table id="table_csv_profiles">
305             <thead>
306                 <th>CSV profile ID</th>
307                 <th>Name</th>
308                 <th>Description</th>
309                 <th>Content</th>
310                 <th>CSV separator</th>
311                 <th>CSV type</th>
312                 <th>Usage</th>
313                 <th class="noExport">Actions</th>
314             </thead>
315             <tbody>
316                 [% FOREACH csv_profile IN csv_profiles %]
317                 <tr>
318                     <td>[% csv_profile.export_format_id | html %]</td>
319                     <td>[% csv_profile.profile | html %]</td>
320                     <td>[% csv_profile.description | html %]</td>
321                     <td>[% csv_profile.content | html | html_line_break %]</td>
322                     <td>[% csv_profile.csv_separator | html %]</td>
323                     <td>[% PROCESS type_description type_code = csv_profile.type %]</td>
324                     <td>[% PROCESS used_for_description used_for_code = csv_profile.used_for %]</td>
325                     <td class="actions">
326                         <a href="/cgi-bin/koha/tools/csv-profiles.pl?op=add_form&amp;export_format_id=[% csv_profile.export_format_id | uri %]" class="btn btn-default btn-xs"><i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit</a>
327                         <a href="/cgi-bin/koha/tools/csv-profiles.pl?op=delete_confirm&amp;export_format_id=[% csv_profile.export_format_id | uri %]" class="btn btn-default btn-xs"><i class="fa fa-trash-can"></i> Delete</a>
328                     </td>
329                 </tr>
330                 [% END %]
331             </tbody>
332         </table>
333     </div>
334     [% ELSE %]
335         There is no CSV profile defined. <a href="/cgi-bin/koha/tools/csv-profiles.pl?op=add_form">Create a new CSV profile</a>.
336     [% END %]
337 [% END %]
338
339             </main>
340         </div> <!-- /.col-sm-10.col-sm-push-2 -->
341
342         <div class="col-sm-2 col-sm-pull-10">
343             <aside>
344                 [% INCLUDE 'tools-menu.inc' %]
345             </aside>
346         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
347      </div> <!-- /.row -->
348
349 [% MACRO jsinclude BLOCK %]
350     [% Asset.js("js/tools-menu.js") | $raw %]
351     <script>
352         function reloadPage(p) {
353             var id = p.value;
354             if (id != 0) { document.location = "/cgi-bin/koha/tools/csv-profiles.pl?op=add_form&amp;export_format_id=" + id; }
355         }
356         $(document).ready(function() {
357             $("#type").change(function(){
358                 if ( $(this).find("option:selected").val() == "marc" ) {
359                     $("li.marc_specific").show();
360                     $("#marc_content").attr("required", "required");
361                     $("li.sql_specific").hide();
362                     $("#sql_content").removeAttr("required");
363                 } else {
364                     $("li.marc_specific").hide();
365                     $("#marc_content").removeAttr("required");
366                     $("li.sql_specific").show();
367                     $("#sql_content").attr("required", "required");
368                 }
369             });
370             $("#type").change();
371         });
372     </script>
373 [% END %]
374
375 [% INCLUDE 'intranet-bottom.inc' %]