View | Details | Raw Unified | Return to bug 15451
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/csv-profiles.tt (-371 / +239 lines)
Lines 2-396 Link Here
2
<script type="text/javascript">
2
<script type="text/javascript">
3
//<![CDATA[
3
//<![CDATA[
4
function reloadPage(p) {
4
function reloadPage(p) {
5
	var id = p.value;
5
    var id = p.value;
6
	if (id != 0) { document.location = "/cgi-bin/koha/tools/csv-profiles.pl?id=" + id; }
6
    if (id != 0) { document.location = "/cgi-bin/koha/tools/csv-profiles.pl?op=add_form&amp;export_format_id=" + id; }
7
}
7
}
8
     $(document).ready(function() {
8
     $(document).ready(function() {
9
        $('#csvexporttabs').tabs();
9
        $("#type").change(function(){
10
11
        $("#profile_type").find("option:first").attr("selected", "selected");
12
        $("#csvnew").find("li.marc_specific").show();
13
        $("#csvnew").find("li.sql_specific").hide();
14
15
        $("#profile_type").change(function(){
16
            if ( $(this).find("option:selected").val() == "marc" ) {
17
                $("#csvnew li.marc_specific").show();
18
                $("#new_profile_marc_content").attr("required", "required");
19
                $("#csvnew li.sql_specific").hide();
20
                $("#new_profile_sql_content").removeAttr("required");
21
            } else {
22
                $("#csvnew li.marc_specific").hide();
23
                $("#new_profile_marc_content").removeAttr("required");
24
                $("#csvnew li.sql_specific").show();
25
                $("#new_profile_sql_content").attr("required", "required");
26
            }
27
        });
28
        $("#modify_profile_type").change(function(){
29
            if ( $(this).find("option:selected").val() == "marc" ) {
10
            if ( $(this).find("option:selected").val() == "marc" ) {
30
                $("#csvedit li.marc_specific").show();
11
                $("li.marc_specific").show();
31
                $("#modify_profile_marc_content").attr("required", "required");
12
                $("#marc_content").attr("required", "required");
32
                $("#csvedit li.sql_specific").hide();
13
                $("li.sql_specific").hide();
33
                $("#modify_profile_sql_content").removeAttr("required");
14
                $("#sql_content").removeAttr("required");
34
            } else {
15
            } else {
35
                $("#csvedit li.marc_specific").hide();
16
                $("li.marc_specific").hide();
36
                $("#modify_profile_marc_content").removeAttr("required");
17
                $("#marc_content").removeAttr("required");
37
                $("#csvedit li.sql_specific").show();
18
                $("li.sql_specific").show();
38
                $("#modify_profile_sql_content").attr("required", "required");
19
                $("#sql_content").attr("required", "required");
39
            }
20
            }
40
        });
21
        });
41
        $("#profile_type").change();
22
        $("#type").change();
42
        $("#modify_profile_type").change();
43
     });
23
     });
44
//]]>
24
//]]>
45
</script>
25
</script>
46
</head>
26
</head>
47
27
48
<body id="tools_csv-profiles" class="tools">
28
<body id="tools_csv-profiles" class="tools">
49
	[% INCLUDE 'header.inc' %]
29
[% INCLUDE 'header.inc' %]
50
	[% INCLUDE 'cat-search.inc' %]
30
[% INCLUDE 'cat-search.inc' %]
51
31
52
	<div id="breadcrumbs">
32
<div id="breadcrumbs">
53
		<a href="/cgi-bin/koha/mainpage.pl">Home</a>
33
    <a href="/cgi-bin/koha/mainpage.pl">Home</a>
54
		&rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
34
    &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
55
		&rsaquo; CSV export profiles
35
    &rsaquo; CSV export profiles
56
	</div>
36
</div>
57
37
58
	<div id="doc3" class="yui-t2">
38
<div id="doc3" class="yui-t2">
59
		<div id="bd">
39
   <div id="bd">
60
			<div id="yui-main">
40
    <div id="yui-main">
61
				<div class="yui-b">
41
    <div class="yui-b">
62
				    [% IF ( success || error ) %]
42
63
					    [% IF ( success ) %]
43
[% FOR m IN messages %]
64
        [% IF ( action == 'create' ) %]<div class="dialog message">The new CSV profile "[% profile_name %]" has been successfully created.</div>[% END %]
44
    <div class="dialog [% m.type %]">
65
        [% IF ( action == 'edit' ) %]<div class="dialog message">The CSV profile has been successfully modified.</div>[% END %]
45
        [% SWITCH m.code %]
66
        [% IF ( action == 'delete' ) %]<div class="dialog message">The CSV profile has been successfully deleted.</div>[% END %]
46
        [% CASE 'error_on_update' %]
47
            An error occurred when updating this CSV profile. Perhaps it already exists.
48
        [% CASE 'error_on_insert' %]
49
            An error occurred when adding this CSV profile.
50
        [% CASE 'error_on_delete' %]
51
            An error occurred when deleting this CSV profile. Check the logs.
52
        [% CASE 'success_on_update' %]
53
            CSV profile updated successfully.
54
        [% CASE 'success_on_insert' %]
55
            CSV profile added successfully.
56
        [% CASE 'success_on_delete' %]
57
            CSV profile deleted successfully.
58
        [% CASE 'already_exists' %]
59
            This CSV profile already exists.
60
        [% CASE %]
61
            [% m.code %]
62
        [% END %]
63
    </div>
64
[% END %]
65
66
[% BLOCK list_separator_options %]
67
    [% IF selected_separator == ',' %]
68
        <option value="," selected="selected">Comma (,)</option>
69
    [% ELSE %]
70
        <option value=",">Comma (,)</option>
71
    [% END %]
72
    [% IF selected_separator == '|' %]
73
        <option value="|" selected="selected">Pipe (|)</option>
74
    [% ELSE %]
75
        <option value="|">Pipe (|)</option>
76
    [% END %]
77
    [% IF selected_separator == ';' %]
78
        <option value=";" selected="selected">Semi-colon (;)</option>
79
    [% ELSE %]
80
        <option value=";">Semi-colon (;)</option>
81
    [% END %]
82
    [% IF selected_separator == '#' %]
83
        <option value="#" selected="selected">Sharp (#)</option>
84
    [% ELSE %]
85
        <option value="#">Sharp (#)</option>
86
    [% END %]
87
    [% IF selected_separator == ' ' %]
88
        <option value=" " selected="selected">Space ( )</option>
89
    [% ELSE %]
90
        <option value=" ">Space ( )</option>
91
    [% END %]
92
    [% IF selected_separator == '\t' %]
93
        <option value="\t" selected="selected">Tabulation (\t)</option>
94
    [% ELSE %]
95
        <option value="\t">Tabulation (\t)</option>
96
    [% END %]
97
    [% IF selected_separator == '\n' %]
98
        <option value="\n" selected="selected">New line (\n)</option>
99
    [% ELSE %]
100
        <option value="\n">New line (\n)</option>
101
    [% END %]
102
[% END %]
103
104
[% IF op == 'add_form' %]
105
    [% IF csv_profile %]
106
        <h1>Modify a CSV profile</h1>
107
    [% ELSE %]
108
        <h1>New CSV profile</h1>
109
    [% END %]
110
111
    <form action="/cgi-bin/koha/tools/csv-profiles.pl" class="validated" method="post">
112
        <input type="hidden" name="op" value="add_validate" />
113
        <input type="hidden" name="export_format_id" value="[% csv_profile.export_format_id %]" />
114
        <fieldset class="rows">
115
            <ol>
116
                [% IF csv_profile %]
117
                    <li><span class="label">Profile ID: </span>[% csv_profile.export_format_id %]</li>
118
                [% END %]
119
                <li>
120
                    <label for="profile" class="required">Profile name: </label>
121
                    <input type="text" name="profile" id="profile" value="[% csv_profile.profile %]" class="required">
122
                    <span class="required">Required</span>
123
                </li>
124
                <li>
125
                    <label for="type" class="required">Profile type: </label>
126
                    <select id="type" name="type">
127
                        [% IF csv_profile.type == 'sql' %]
128
                            <option value="marc">MARC</option>
129
                            <option value="sql" selected="selected">SQL</option>
67
                        [% ELSE %]
130
                        [% ELSE %]
68
        [% IF ( action == 'create' ) %]<div class="dialog alert">The new CSV profile "[% profile_name %]" has not been created.</div>[% END %]
131
                            <option value="marc" selected="selected">MARC</option>
69
        [% IF ( action == 'edit' ) %]<div class="dialog alert">The CSV profile has not been modified.</div>[% END %]
132
                            <option value="sql">SQL</option>
70
        [% IF ( action == 'delete' ) %]<div class="dialog alert">The CSV profile has not been deleted.</div>[% END %]
133
                        [% END %]
71
					    [% END %]
134
                    </select>
72
				    [% END %]
135
                    <span class="required">Required</span>
73
<div id="csvexporttabs" class="toptabs">
136
                </li>
74
<ul>
137
                <li>
75
    <li><a href="#csvnew">New profile</a></li>
138
                    <label for="description">Profile description: </label>
76
	[% IF ( existing_profiles ) %]
139
                    <textarea cols="50" rows="2" name="description" id="description">[% csv_profile.description %]</textarea>
77
	[% IF ( selected_profile_id ) %]
140
                </li>
78
    <li class="ui-tabs-active">
141
                <li>
79
	[% ELSE %]
142
                    <label for="csv_separator">CSV separator: </label>
80
	<li>
143
                    <select name="csv_separator" id="csv_separator">
81
	 [% END %]
144
                        [% PROCESS list_separator_options selected_separator=csv_profile.csv_separator || ',' %]
82
    <a href="#csvedit">Edit existing profile</a></li> [% END %]
145
                    </select>
83
</ul>
146
                </li>
84
	<div id="csvnew">
147
85
					<h3>New CSV export profile</h3>
148
                <li class="marc_specific">
86
149
                    <label for="field_separator">Field separator: </label>
87
                        <form action="/cgi-bin/koha/tools/csv-profiles.pl" class="validated" method="post">
150
                    <select name="field_separator" id="field_separator">
88
						<fieldset class="rows">
151
                        [% PROCESS list_separator_options selected_separator=csv_profile.field_separator || '#' %]
89
                          <ol>
152
                    </select>
90
                            <li>
153
                </li>
91
                                <label for="profile_name" class="required">Profile name: </label>
154
92
                                <input type="text" id="profile_name" name="profile_name" required="required" />
155
                <li class="marc_specific"><label for="subfield_separator">Subfield separator: </label>
93
                                <span class="required">Required</span>
156
                    <select name="subfield_separator" id="subfield_separator">
94
                            </li>
157
                        [% PROCESS list_separator_options selected_separator=csv_profile.subfield_separator || '|'%]
95
158
                    </select>
96
                            <li>
159
                </li>
97
                              <label for="profile_type" class="required">Profile type: </label>
160
98
                              <select id="profile_type" name="profile_type">
161
                <li class="marc_specific"><label for="encoding">Encoding: </label>
99
                                <option value="marc" selected="selected">MARC</option>
162
                    <select name="encoding" id="encoding">
100
                                <option value="sql">SQL</option>
163
                        [% FOREACH encoding IN encodings %]
101
                              </select>
164
                            [% IF csv_profile.encoding == encoding
102
                              <span class="required">Required</span>
165
                                OR NOT csv_profile AND encoding == 'utf8' %]
103
                            </li>
166
                                <option selected="selected">[% encoding %]</option>
104
167
                            [% ELSE %]
105
						    <li><label for="profile_description">Profile description: </label>
168
                                <option>[% encoding %]</option>
106
						    <textarea cols="50" rows="2" name="profile_description" id="profile_description"></textarea></li>
169
                            [% END %]
107
170
                        [% END %]
108
						    <li><label for="new_csv_separator">CSV separator: </label>
171
                    </select>
109
						    <select name="csv_separator" id="new_csv_separator">
172
                </li>
110
							<option value=":">Colon (:)</option>
173
111
							<option value="," selected="selected">Comma (,)</option>
174
                <li class="marc_specific">
112
							<option value="|">Pipe (|)</option>
175
                    <label for="marc_content" class="required">Profile MARC fields: </label>
113
							<option value=";">Semi-colon (;)</option>
176
                    <textarea cols="50" rows="2" name="marc_content" id="marc_content">[% csv_profile.content %]</textarea>
114
							<option value="#">Sharp (#)</option>
177
                    <span class="required">Required</span>
115
							<option value=" ">Space ( )</option>
178
                    <p>You have to define which fields or subfields you want to export, separated by pipes.</p>
116
							<option value="\t">Tabulation (\t)</option>
179
                    <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>
117
							<option value="\n">New line (\n)</option>
180
                    <p>Example: Personal name=200|Entry element=210$a|300|009</p>
118
						    </select>
181
                    <p>You can use Template Toolkit tags too. See the help page for more information.</p>
119
                            </li>
182
                </li>
183
184
                <li class="sql_specific">
185
                  <label for="sql_content" class="required">Profile SQL fields: </label>
186
                  <textarea cols="50" rows="2" name="sql_content" id="sql_content">[% csv_profile.content %]</textarea>
187
                  <p>You have to define which fields you want to export, separated by pipes.</p>
188
                  <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>
189
                  <p>Example: Name=subscription.name|Title=subscription.title|Issue number=serial.serialseq</p>
190
                </li>
191
            </ol>
192
        </fieldset>
193
        <fieldset class="action">
194
            <input type="submit" value="Submit" />
195
            <a class="cancel" href="/cgi-bin/koha/tools/csv-profiles.pl">Cancel</a>
196
        </fieldset>
197
    </form>
198
[% END %]
199
200
[% IF op == 'delete_confirm' %]
201
    <div class="dialog alert">
202
        <h3>Delete CSV Profile "[% csv_profile.profile %]?"</h3>
203
        <form action="/cgi-bin/koha/tools/csv-profiles.pl" method="post">
204
            <input type="hidden" name="op" value="delete_confirmed" />
205
            <input type="hidden" name="export_format_id" value="[% csv_profile.export_format_id %]" />
206
            <input type="submit" class="approve" value="Yes, delete" />
207
        </form>
208
        <form action="/cgi-bin/koha/tools/csv-profiles.pl" method="get">
209
            <input type="submit" class="deny" value="No, do not Delete" />
210
        </form>
211
    </div>
212
[% END %]
120
213
121
                            <li class="marc_specific"><label for="new_field_separator">Field separator: </label>
214
[% IF op == 'list' %]
122
						    <select name="field_separator" id="new_field_separator">
123
							<option value=":">Colon (:)</option>
124
							<option value=",">Comma (,)</option>
125
							<option value="|">Pipe (|)</option>
126
							<option value=";">Semi-colon (;)</option>
127
							<option value="#" selected="selected">Sharp (#)</option>
128
							<option value=" ">Space ( )</option>
129
							<option value="\t">Tabulation (\t)</option>
130
							<option value="\n">New line (\n)</option>
131
						    </select>
132
                            </li>
133
215
134
                            <li class="marc_specific"><label for="new_subfield_separator">Subfield separator: </label>
216
    <div id="toolbar" class="btn-toolbar">
135
						    <select name="subfield_separator" id="new_subfield_separator">
217
        <a class="btn btn-small" id="newcsvprofile" href="/cgi-bin/koha/tools/csv-profiles.pl?op=add_form"><i class="fa fa-plus"></i> New CSV profile</a>
136
							<option value=":">Colon (:)</option>
218
    </div>
137
							<option value=",">Comma (,)</option>
138
							<option value="|" selected="selected">Pipe (|)</option>
139
							<option value=";">Semi-colon (;)</option>
140
							<option value="#">Sharp (#)</option>
141
							<option value=" ">Space ( )</option>
142
							<option value="\t">Tabulation (\t)</option>
143
							<option value="\n">New line (\n)</option>
144
						    </select>
145
                            </li>
146
					
147
                            <li class="marc_specific"><label for="new_encoding">Encoding: </label>
148
						    <select name="encoding" id="new_encoding">
149
							[% FOREACH encoding IN encodings %]
150
                                [% IF ( encoding.encoding == 'utf8' ) %]
151
									<option selected="selected">[% encoding.encoding %]</option>
152
								[% ELSE %]
153
									<option>[% encoding.encoding %]</option>
154
								[% END %]
155
							[% END %]
156
						    </select></li>
157
219
220
    <h2>CSV profiles</h2>
221
222
    [% IF csv_profiles%]
223
        <table id="table_csv_profiles">
224
            <thead>
225
                <th>CSV profile ID</th>
226
                <th>Name</th>
227
                <th>Description</th>
228
                <th>Content</th>
229
                <th>CSV separator</th>
230
                <th>CSV type</th>
231
                <th>&nbsp;</th>
232
                <th>&nbsp;</th>
233
            </thead>
234
            <tbody>
235
                [% FOREACH csv_profile IN csv_profiles %]
236
                <tr>
237
                    <td>[% csv_profile.export_format_id %]</td>
238
                    <td>[% csv_profile.profile %]</td>
239
                    <td>[% csv_profile.description %]</td>
240
                    <td>[% csv_profile.content %]</td>
241
                    <td>[% csv_profile.csv_separator %]</td>
242
                    [% IF csv_profile.type == 'sql' %]
243
                        <td>SQL</td>
244
                    [% ELSE %]
245
                        <td>MARC</td>
246
                    [% END %]
247
                    <td><a href="/cgi-bin/koha/tools/csv-profiles.pl?op=add_form&amp;export_format_id=[% csv_profile.export_format_id %]">Edit</a></td>
248
                    <td><a href="/cgi-bin/koha/tools/csv-profiles.pl?op=delete_confirm&amp;export_format_id=[% csv_profile.export_format_id %]">Delete</a></td>
249
                </tr>
250
                [% END %]
251
            </tbody>
252
        </table>
253
    [% ELSE %]
254
        There is no CSV profile defined. <a href="/cgi-bin/koha/tools/csv-profiles.pl?op=add_form">Create a new CSV profile</a>.
255
    [% END %]
256
[% END %]
158
257
159
                            <li class="marc_specific">
160
                                <label for="new_profile_marc_content" class="required">Profile MARC fields: </label>
161
                                <textarea cols="50" rows="2" name="profile_marc_content" id="new_profile_marc_content"></textarea>
162
                                <span class="required">Required</span>
163
						    <p>You have to define which fields or subfields you want to export, separated by pipes.</p>
164
                            <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>
165
						    <p>Example: Personal name=200|Entry element=210$a|300|009</p>
166
                            <p>You can use Template Toolkit tags too. See the help page for more information.</p>
167
						    </li>
168
                            <li class="sql_specific">
169
                              <label for="new_profile_sql_content" class="required">Profile SQL fields: </label>
170
                              <textarea cols="50" rows="2" name="profile_sql_content" id="new_profile_sql_content"></textarea>
171
                              <p>You have to define which fields you want to export, separated by pipes.</p>
172
                              <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>
173
                              <p>Example: Name=subscription.name|Title=subscription.title|Issue number=serial.serialseq</p>
174
                            </li>
175
						    </ol>
176
						</fieldset>
177
						<fieldset class="action"><input type="hidden" name="action" value="create" />
178
						<input type="submit" value="Submit" /></fieldset>
179
					    </form>
180
					    <br style="clear:both;" />
181
</div>
258
</div>
182
					[% IF ( existing_profiles ) %]
183
<div id="csvedit">
184
					<h3>Modify or delete a CSV export profile</h3>
185
186
                        <form action="/cgi-bin/koha/tools/csv-profiles.pl" class="validated" method="post">
187
						<fieldset class="rows">
188
                            <ol>
189
                            <li><label for="modify_profile_name" class="required">Profile name: </label>
190
                                <select id="modify_profile_name" name="profile_name" required="required" class="required" onchange="reloadPage(this)">
191
							<option value="0">-- Choose One --</option>
192
							[% FOREACH existing_profile IN existing_profiles %]
193
							[% IF ( existing_profile.export_format_id == selected_profile_id ) %]
194
							<option value="[% existing_profile.export_format_id %]" selected="selected">[% existing_profile.profile %]</option>
195
							[% ELSE %]
196
							<option value="[% existing_profile.export_format_id %]">[% existing_profile.profile %]</option>
197
							[% END %]
198
							[% END %]
199
                            </select>
200
                            <span class="required">Required</span>
201
                            </li>
202
203
                            <li>
204
                              <label for="modify_profile_type" class="required">Profile type: </label>
205
                              <select id="modify_profile_type" name="profile_type" class="required" required="required">
206
                                <option value="marc">MARC</option>
207
                                [% IF selected_profile_type == "sql" %]
208
                                  <option value="sql" selected="selected">SQL</option>
209
                                [% ELSE %]
210
                                  <option value="sql">SQL</option>
211
                                [% END %]
212
                              </select>
213
                                <span class="required">Required</span>
214
                            </li>
215
216
217
						    <li><label for="modify_profile_description">Profile description: </label>
218
						    <textarea cols="50" rows="2" name="profile_description" id="modify_profile_description">[% selected_profile_description %]</textarea></li>
219
220
						    <li><label for="csv_separator">CSV separator: </label>
221
						    <select name="csv_separator" id="csv_separator">
222
								<option value=":">Colon (:)</option>
223
								[% IF ( selected_csv_separator == ',' ) %]
224
								<option value="," selected="selected">Comma (,)</option>
225
								[% ELSE %]
226
								<option value=",">Comma (,)</option>
227
								[% END %]
228
								[% IF ( selected_csv_separator == '|' ) %]
229
								<option value="|" selected="selected">Pipe (|)</option>
230
								[% ELSE %]
231
								<option value="|">Pipe (|)</option>
232
								[% END %]
233
								[% IF ( selected_csv_separator == ';' ) %]
234
								<option value=";" selected="selected">Semi-colon (;)</option>
235
								[% ELSE %]
236
								<option value=";">Semi-colon (;)</option>
237
								[% END %]
238
								[% IF ( selected_csv_separator == '#' ) %]
239
								<option value="#" selected="selected">Sharp (#)</option>
240
								[% ELSE %]
241
								<option value="#">Sharp (#)</option>
242
								[% END %]
243
								[% IF ( selected_csv_separator == ' ' ) %]
244
								<option value=" " selected="selected">Space ( )</option>
245
								[% ELSE %]
246
								<option value=" ">Space ( )</option>
247
								[% END %]
248
								[% IF ( selected_csv_separator == '\t' ) %]
249
								<option value="\t" selected="selected">Tabulation (\t)</option>
250
								[% ELSE %]
251
								<option value="\t">Tabulation (\t)</option>
252
								[% END %]
253
						    	[% IF ( selected_csv_separator == '\n' ) %]
254
								<option value="\n" selected="selected">New line (\n)</option>
255
								[% ELSE %]
256
								<option value="\n">New line (\n)</option>
257
								[% END %]
258
                            </select></li>
259
260
                            <li class="marc_specific"><label for="field_separator">Field separator: </label>
261
						    <select name="field_separator" id="field_separator">
262
                                <option value=":">Colon (:)</option>
263
264
                                [% IF ( selected_field_separator == ',' ) %]
265
                                <option value="," selected="selected">Comma (,)</option>
266
                                [% ELSE %]
267
                                <option value=",">Comma (,)</option>
268
								[% END %]
269
270
                                [% IF ( selected_field_separator == '|' ) %]
271
                                <option value="|" selected="selected">Pipe (|)</option>
272
                                [% ELSE %]
273
                                <option value="|">Pipe (|)</option>
274
                                [% END %]
275
276
                                [% IF ( selected_field_separator == ';' ) %]
277
                                <option value=";" selected="selected">Semi-colon (;)</option>
278
                                [% ELSE %]
279
                                <option value=";">Semi-colon (;)</option>
280
                                [% END %]
281
282
                                [% IF ( selected_field_separator == '#' ) %]
283
                                <option value="#" selected="selected">Sharp (#)</option>
284
                                [% ELSE %]
285
                                <option value="#">Sharp (#)</option>
286
                                [% END %]
287
288
                                [% IF ( selected_field_separator == ' ' ) %]
289
                                <option value=" " selected="selected">Space ( )</option>
290
                                [% ELSE %]
291
                                <option value=" ">Space ( )</option>
292
                                [% END %]
293
294
                                [% IF ( selected_field_separator == '\t' ) %]
295
                                <option value="\t" selected="selected">Tabulation (\t)</option>
296
                                [% ELSE %]
297
                                <option value="\t">Tabulation (\t)</option>
298
                                [% END %]
299
						    	[% IF ( selected_field_separator == '\n' ) %]
300
								<option value="\n" selected="selected">New line (\n)</option>
301
								[% ELSE %]
302
								<option value="\n">New line (\n)</option>
303
								[% END %]
304
						    </select></li>
305
306
307
                            <li class="marc_specific"><label for="subfield_separator">Subfield separator: </label>
308
						    <select name="subfield_separator" id="subfield_separator">
309
                                <option value=":">Colon (:)</option>
310
311
                                [% IF ( selected_subfield_separator == ',' ) %]
312
                                <option value="," selected="selected">Comma (,)</option>
313
                                [% ELSE %]
314
                                <option value=",">Comma (,)</option>
315
                                [% END %]
316
317
                                [% IF ( selected_subfield_separator == '|' ) %]
318
                                <option value="|" selected="selected">Pipe (|)</option>
319
                                [% ELSE %]
320
                                <option value="|">Pipe (|)</option>
321
                                [% END %]
322
323
								[% IF ( selected_subfield_separator == ';' ) %]
324
                                <option value=";" selected="selected">Semi-colon (;)</option>
325
                                [% ELSE %]
326
                                <option value=";">Semi-colon (;)</option>
327
                                [% END %]
328
329
								[% IF ( selected_subfield_separator == '#' ) %]
330
                                <option value="#" selected="selected">Sharp (#)</option>
331
                                [% ELSE %]
332
                                <option value="#">Sharp (#)</option>
333
                                [% END %]
334
335
								[% IF ( selected_subfield_separator == ' ' ) %]
336
                                <option value=" " selected="selected">Space ( )</option>
337
                                [% ELSE %]
338
                                <option value=" ">Space ( )</option>
339
                                [% END %]
340
341
								[% IF ( selected_subfield_separator == '\t' ) %]
342
                                <option value="\t" selected="selected">Tabulation (\t)</option>
343
                                [% ELSE %]
344
                                <option value="\t">Tabulation (\t)</option>
345
                                [% END %]
346
						    	[% IF ( selected_subfield_separator == '\n' ) %]
347
								<option value="\n" selected="selected">New line (\n)</option>
348
								[% ELSE %]
349
								<option value="\n">New line (\n)</option>
350
                                [% END %]
351
	
352
						    </select></li>
353
354
                            <li class="marc_specific"><label for="encoding">Encoding: </label>
355
						    <select name="encoding" id="encoding">
356
							[% FOREACH encoding IN encodings %]
357
                                [% IF ( selected_encoding == encoding.encoding ) %]
358
							    <option selected="selected">[% encoding.encoding %]</option>
359
							    [% ELSE %]
360
							    <option>[% encoding.encoding %]</option>
361
							    [% END %]
362
							[% END %]
363
						    </select></li>
364
365
                            <li class="marc_specific">
366
                                <label for="modify_profile_marc_content" class="required">Profile MARC fields: </label>
367
                                <textarea cols="50" rows="2" name="profile_marc_content" id="modify_profile_marc_content" class="required" required="required">[% selected_profile_content %]</textarea>
368
                                <span class="required">Required</span>
369
                            </li>
370
371
                            <li class="sql_specific">
372
                              <label for="modify_profile_sql_content" class="required">Profile SQL fields: </label>
373
                              <textarea cols="50" rows="2" name="profile_sql_content" id="modify_profile_sql_content">[% selected_profile_content %]</textarea>
374
                            </li>
375
376
						   <li class="radio"> <label for="delete">Delete selected profile?</label>
377
						    <input type="checkbox" name="delete" id="delete" /></li>
378
						    </ol>
379
380
						</fieldset>
381
382
						<fieldset class="action"><input type="hidden" name="modify_profile_id" value="[% selected_profile_id %]" />
383
						<input type="hidden" name="action" value="edit" />
384
						<input type="submit" value="Submit" /> <a href="/cgi-bin/koha/tools/csv-profiles.pl" class="cancel">Cancel</a></fieldset>
385
					    </form>
386
</div>
259
</div>
387
					[% END %]
260
<div class="yui-b noprint">
388
261
[% INCLUDE 'tools-menu.inc' %]
389
				</div>
262
</div>
390
			</div>
263
</div>
391
			</div>
264
[% INCLUDE 'intranet-bottom.inc' %]
392
		    <div class="yui-b noprint">
393
        [% INCLUDE 'tools-menu.inc' %]
394
    </div>
395
	</div>
396
	[% INCLUDE 'intranet-bottom.inc' %]
(-)a/tools/csv-profiles.pl (-77 / +84 lines)
Lines 1-6 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
# Copyright 2009 BibLibre
3
# Copyright 2009 BibLibre
4
# Copyright 2015 Koha Development Team
4
#
5
#
5
# This file is part of Koha.
6
# This file is part of Koha.
6
#
7
#
Lines 33-41 This script allow the user to define a new profile for CSV export Link Here
33
34
34
=cut
35
=cut
35
36
36
use strict;
37
use Modern::Perl;
37
#use warnings; FIXME - Bug 2505
38
use Data::Dumper;
39
use Encode;
38
use Encode;
40
39
41
use C4::Auth;
40
use C4::Auth;
Lines 43-57 use C4::Context; Link Here
43
use C4::Output;
42
use C4::Output;
44
use CGI qw ( -utf8 );
43
use CGI qw ( -utf8 );
45
use C4::Koha;
44
use C4::Koha;
46
use C4::Csv;
45
use Koha::CsvProfiles;
47
46
48
my $input        = new CGI;
47
my $input            = new CGI;
49
my $dbh          = C4::Context->dbh;
48
my $export_format_id = $input->param('export_format_id');
49
my $op               = $input->param('op') || 'list';
50
my @messages;
50
51
51
# open template
52
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
52
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
53
    {
53
    {   template_name   => "tools/csv-profiles.tt",
54
        template_name   => "tools/csv-profiles.tt",
55
        query           => $input,
54
        query           => $input,
56
        type            => "intranet",
55
        type            => "intranet",
57
        authnotrequired => 0,
56
        authnotrequired => 0,
Lines 61-138 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
61
);
60
);
62
61
63
# Getting available encodings list
62
# Getting available encodings list
64
my @encodings = Encode->encodings();
63
$template->param( encodings => [ Encode->encodings ] );
65
my @encodings_loop = map{{encoding => $_}} @encodings;
66
$template->param(encodings => \@encodings_loop);
67
68
my $profile_name        = $input->param("profile_name");
69
my $profile_description = $input->param("profile_description");
70
my $csv_separator       = $input->param("csv_separator");
71
my $field_separator     = $input->param("field_separator");
72
my $subfield_separator  = $input->param("subfield_separator");
73
my $encoding            = $input->param("encoding");
74
my $type                = $input->param("profile_type");
75
my $action              = $input->param("action");
76
my $delete              = $input->param("delete");
77
my $id                  = $input->param("id");
78
if ($delete) { $action = "delete"; }
79
80
my $profile_content = $type eq "marc"
81
    ? $input->param("profile_marc_content")
82
    : $input->param("profile_sql_content");
83
84
if ($profile_name && $profile_content && $action) {
85
    my $rows;
86
87
    if ($action eq "create") {
88
    my $query = "INSERT INTO export_format(export_format_id, profile, description, content, csv_separator, field_separator, subfield_separator, encoding, type) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?)";
89
	my $sth   = $dbh->prepare($query);
90
    $rows  = $sth->execute($profile_name, $profile_description, $profile_content, $csv_separator, $field_separator, $subfield_separator, $encoding, $type);
91
    
92
    }
93
64
94
    if ($action eq "edit") {
65
if ( $op eq 'add_form' ) {
95
    my $query = "UPDATE export_format SET description=?, content=?, csv_separator=?, field_separator=?, subfield_separator=?, encoding=?, type=? WHERE export_format_id=? LIMIT 1";
66
    my $csv_profile;
96
	my $sth   = $dbh->prepare($query);
67
    if ($export_format_id) {
97
    $rows  = $sth->execute($profile_description, $profile_content, $csv_separator, $field_separator, $subfield_separator, $encoding, $type, $profile_name);
68
        $csv_profile = Koha::CsvProfiles->find($export_format_id);
98
    }
69
    }
99
70
    $template->param( csv_profile => $csv_profile, );
100
    if ($action eq "delete") {
71
} elsif ( $op eq 'add_validate' ) {
101
	my $query = "DELETE FROM export_format WHERE export_format_id=? LIMIT 1";
72
    my $profile     = $input->param("profile");
102
	my $sth   = $dbh->prepare($query);
73
    my $description = $input->param("description");
103
	$rows  = $sth->execute($profile_name);
74
    my $type        = $input->param("type");
104
75
    my $content =
76
        $type eq "marc"
77
      ? $input->param("marc_content")
78
      : $input->param("sql_content");
79
    my $csv_separator      = $input->param("csv_separator");
80
    my $field_separator    = $input->param("field_separator");
81
    my $subfield_separator = $input->param("subfield_separator");
82
    my $encoding           = $input->param("encoding");
83
84
    if ($export_format_id) {
85
        my $csv_profile = Koha::CsvProfiles->find($export_format_id);
86
        $csv_profile->profile($profile);
87
        $csv_profile->description($description);
88
        $csv_profile->content($content);
89
        $csv_profile->csv_separator($csv_separator);
90
        $csv_profile->field_separator($field_separator);
91
        $csv_profile->subfield_separator($subfield_separator);
92
        $csv_profile->encoding($encoding);
93
        $csv_profile->type($type);
94
        eval { $csv_profile->store; };
95
96
        if ($@) {
97
            push @messages, { type => 'error', code => 'error_on_update' };
98
        } else {
99
            push @messages, { type => 'message', code => 'success_on_update' };
100
        }
101
    } else {
102
        my $csv_profile = Koha::CsvProfile->new(
103
            {   profile            => $profile,
104
                description        => $description,
105
                content            => $content,
106
                csv_separator      => $csv_separator,
107
                field_separator    => $field_separator,
108
                subfield_separator => $subfield_separator,
109
                encoding           => $encoding,
110
                type               => $type,
111
            }
112
        );
113
        eval { $csv_profile->store; };
114
        if ($@) {
115
            push @messages, { type => 'error', code => 'error_on_insert' };
116
        } else {
117
            push @messages, { type => 'message', code => 'success_on_insert' };
118
        }
105
    }
119
    }
106
120
    $op = 'list';
107
    $rows ? $template->param(success => 1) : $template->param(error => 1);
121
} elsif ( $op eq 'delete_confirm' ) {
108
    $template->param(profile_name => $profile_name);
122
    my $csv_profile = Koha::CsvProfiles->find($export_format_id);
109
    $template->param(action => $action);
123
    $template->param( csv_profile => $csv_profile, );
110
124
} elsif ( $op eq 'delete_confirmed' ) {
125
    my $csv_profile = Koha::CsvProfiles->find($export_format_id);
126
    my $deleted = eval { $csv_profile->delete; };
127
128
    if ( $@ or not $deleted ) {
129
        push @messages, { type => 'error', code => 'error_on_delete' };
130
    } else {
131
        push @messages, { type => 'message', code => 'success_on_delete' };
132
    }
133
    $op = 'list';
111
}
134
}
112
135
113
    # If a profile has been selected for modification
136
if ( $op eq 'list' ) {
114
    if ($id) {
137
    my $csv_profiles = Koha::CsvProfiles->search;
115
    my $query = "SELECT export_format_id, profile, description, content, csv_separator, field_separator, subfield_separator, encoding, type FROM export_format WHERE export_format_id = ?";
138
    $template->param( csv_profiles => $csv_profiles, );
116
	my $sth;
139
}
117
	$sth = $dbh->prepare($query);
118
119
	$sth->execute($id);
120
	my $selected_profile = $sth->fetchrow_arrayref();
121
	$template->param(
122
	    selected_profile_id          => $selected_profile->[0],
123
	    selected_profile_name        => $selected_profile->[1],
124
	    selected_profile_description => $selected_profile->[2],
125
        selected_profile_content     => $selected_profile->[3],
126
	    selected_csv_separator       => $selected_profile->[4],
127
	    selected_field_separator     => $selected_profile->[5],
128
	    selected_subfield_separator  => $selected_profile->[6],
129
        selected_encoding            => $selected_profile->[7],
130
        selected_profile_type        => $selected_profile->[8]
131
	);
132
133
    }
134
140
135
    # List of existing profiles
141
$template->param(
136
    $template->param(existing_profiles => GetCsvProfilesLoop());
142
    messages => \@messages,
143
    op       => $op,
144
);
137
145
138
output_html_with_http_headers $input, $cookie, $template->output;
146
output_html_with_http_headers $input, $cookie, $template->output;
139
- 

Return to bug 15451