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