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

(-)a/C4/Csv.pm (-3 / +7 lines)
Lines 43-53 $VERSION = 3.07.00.049; Link Here
43
43
44
# Returns all informations about csv profiles
44
# Returns all informations about csv profiles
45
sub GetCsvProfiles {
45
sub GetCsvProfiles {
46
    my ( $type ) = @_;
46
    my $dbh = C4::Context->dbh;
47
    my $dbh = C4::Context->dbh;
47
    my $query = "SELECT * FROM export_format";
48
    my $query = "SELECT * FROM export_format";
49
    if ( $type ) {
50
        $query .= " WHERE type = ?";
51
    }
48
52
49
    $sth = $dbh->prepare($query);
53
    $sth = $dbh->prepare($query);
50
    $sth->execute;
54
    $sth->execute( $type ? $type : () );
51
55
52
    $sth->fetchall_arrayref({});
56
    $sth->fetchall_arrayref({});
53
57
Lines 82-93 sub GetMarcFieldsForCsv { Link Here
82
86
83
    my ($id) = @_;
87
    my ($id) = @_;
84
    my $dbh = C4::Context->dbh;
88
    my $dbh = C4::Context->dbh;
85
    my $query = "SELECT marcfields FROM export_format WHERE export_format_id=?";
89
    my $query = "SELECT content FROM export_format WHERE export_format_id=?";
86
90
87
    $sth = $dbh->prepare($query);
91
    $sth = $dbh->prepare($query);
88
    $sth->execute($id);
92
    $sth->execute($id);
89
93
90
    return ($sth->fetchrow_hashref)->{marcfields};
94
    return ($sth->fetchrow_hashref)->{content};
91
    
95
    
92
 
96
 
93
}
97
}
(-)a/C4/Record.pm (-1 / +1 lines)
Lines 461-467 sub marcrecord2csv { Link Here
461
    $csv->sep_char($csvseparator);
461
    $csv->sep_char($csvseparator);
462
462
463
    # Getting the marcfields
463
    # Getting the marcfields
464
    my $marcfieldslist = $profile->{marcfields};
464
    my $marcfieldslist = $profile->{content};
465
465
466
    # Getting the marcfields as an array
466
    # Getting the marcfields as an array
467
    my @marcfieldsarray = split('\|', $marcfieldslist);
467
    my @marcfieldsarray = split('\|', $marcfieldslist);
(-)a/installer/data/mysql/kohastructure.sql (-1 / +2 lines)
Lines 921-931 CREATE TABLE `export_format` ( Link Here
921
  `export_format_id` int(11) NOT NULL auto_increment,
921
  `export_format_id` int(11) NOT NULL auto_increment,
922
  `profile` varchar(255) NOT NULL,
922
  `profile` varchar(255) NOT NULL,
923
  `description` mediumtext NOT NULL,
923
  `description` mediumtext NOT NULL,
924
  `marcfields` mediumtext NOT NULL,
924
  `content` mediumtext NOT NULL,
925
  `csv_separator` varchar(2) NOT NULL,
925
  `csv_separator` varchar(2) NOT NULL,
926
  `field_separator` varchar(2) NOT NULL,
926
  `field_separator` varchar(2) NOT NULL,
927
  `subfield_separator` varchar(2) NOT NULL,
927
  `subfield_separator` varchar(2) NOT NULL,
928
  `encoding` varchar(255) NOT NULL,
928
  `encoding` varchar(255) NOT NULL,
929
  `type` varchar(255) DEFAULT 'marc',
929
  PRIMARY KEY  (`export_format_id`)
930
  PRIMARY KEY  (`export_format_id`)
930
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Used for CSV export';
931
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Used for CSV export';
931
932
(-)a/installer/data/mysql/updatedatabase.pl (+18 lines)
Lines 7139-7144 if ( CheckVersion($DBversion) ) { Link Here
7139
    SetVersion ($DBversion);
7139
    SetVersion ($DBversion);
7140
}
7140
}
7141
7141
7142
7143
7144
7145
7146
7147
7148
$DBversion = "3.13.00.XXX";
7149
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
7150
    $dbh->do(q{
7151
        ALTER TABLE export_format ADD type VARCHAR(255) DEFAULT 'marc' AFTER encoding
7152
    });
7153
    $dbh->do(q{
7154
        ALTER TABLE export_format CHANGE marcfields content mediumtext NOT NULL
7155
    });
7156
    print "Upgrade to $DBversion done (Bug 10853: Add new field export_format.type and rename export_format.marcfields with export_format.content)\n";
7157
    SetVersion($DBversion);
7158
}
7159
7142
=head1 FUNCTIONS
7160
=head1 FUNCTIONS
7143
7161
7144
=head2 TableExists($table)
7162
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/csv-profiles.tt (-12 / +71 lines)
Lines 7-12 function reloadPage(p) { Link Here
7
}
7
}
8
     $(document).ready(function() {
8
     $(document).ready(function() {
9
        $('#csvexporttabs').tabs();
9
        $('#csvexporttabs').tabs();
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
                $("#csvnew li.sql_specific").hide();
19
            } else {
20
                $("#csvnew li.marc_specific").hide();
21
                $("#csvnew li.sql_specific").show();
22
            }
23
        });
24
        $("#modify_profile_type").change(function(){
25
            if ( $(this).find("option:selected").val() == "marc" ) {
26
                $("#csvedit li.marc_specific").show();
27
                $("#csvedit li.sql_specific").hide();
28
            } else {
29
                $("#csvedit li.marc_specific").hide();
30
                $("#csvedit li.sql_specific").show();
31
            }
32
        });
33
        $("#modify_profile_type").change();
10
     });
34
     });
11
//]]>
35
//]]>
12
</script>
36
</script>
Lines 53-61 function reloadPage(p) { Link Here
53
77
54
					     <form action="/cgi-bin/koha/tools/csv-profiles.pl" method="post">
78
					     <form action="/cgi-bin/koha/tools/csv-profiles.pl" method="post">
55
						<fieldset class="rows">
79
						<fieldset class="rows">
56
						    <ol><li><label for="profile_name" class="required">Profile name: </label>
80
                          <ol>
81
                            <li><label for="profile_name" class="required">Profile name: </label>
57
						    <input type="text" id="profile_name" name="profile_name" /></li>
82
						    <input type="text" id="profile_name" name="profile_name" /></li>
58
83
84
                            <li>
85
                              <label for="profile_type" class="required">Profile type: </label>
86
                              <select id="profile_type" name="profile_type">
87
                                <option value="marc" selected="selected">MARC</option>
88
                                <option value="sql">SQL</option>
89
                              </select>
90
                            </li>
91
59
						    <li><label for="profile_description">Profile description: </label>
92
						    <li><label for="profile_description">Profile description: </label>
60
						    <textarea cols="50" rows="2" name="profile_description" id="profile_description"></textarea></li>
93
						    <textarea cols="50" rows="2" name="profile_description" id="profile_description"></textarea></li>
61
94
Lines 72-78 function reloadPage(p) { Link Here
72
						    </select>
105
						    </select>
73
                            </li>
106
                            </li>
74
107
75
						    <li><label for="new_field_separator">Field separator: </label>
108
                            <li class="marc_specific"><label for="new_field_separator">Field separator: </label>
76
						    <select name="field_separator" id="new_field_separator">
109
						    <select name="field_separator" id="new_field_separator">
77
							<option value=":">Colon (:)</option>
110
							<option value=":">Colon (:)</option>
78
							<option value=",">Comma (,)</option>
111
							<option value=",">Comma (,)</option>
Lines 85-91 function reloadPage(p) { Link Here
85
						    </select>
118
						    </select>
86
                            </li>
119
                            </li>
87
120
88
						    <li><label for="new_subfield_separator">Subfield separator: </label>
121
						    <li class="marc_specific"><label for="new_subfield_separator">Subfield separator: </label>
89
						    <select name="subfield_separator" id="new_subfield_separator">
122
						    <select name="subfield_separator" id="new_subfield_separator">
90
							<option value=":">Colon (:)</option>
123
							<option value=":">Colon (:)</option>
91
							<option value=",">Comma (,)</option>
124
							<option value=",">Comma (,)</option>
Lines 98-104 function reloadPage(p) { Link Here
98
						    </select>
131
						    </select>
99
                            </li>
132
                            </li>
100
					
133
					
101
						    <li><label for="new_encoding">Encoding: </label>
134
						    <li class="marc_specific"><label for="new_encoding">Encoding: </label>
102
						    <select name="encoding" id="new_encoding">
135
						    <select name="encoding" id="new_encoding">
103
							[% FOREACH encoding IN encodings %]
136
							[% FOREACH encoding IN encodings %]
104
                                [% IF ( encoding.encoding == 'utf8' ) %]
137
                                [% IF ( encoding.encoding == 'utf8' ) %]
Lines 110-121 function reloadPage(p) { Link Here
110
						    </select></li>
143
						    </select></li>
111
144
112
145
113
                            <li><label for="new_profile_content">Profile MARC fields: </label>
146
                            <li class="marc_specific"><label for="new_profile_marc_content">Profile MARC fields: </label>
114
						    <textarea cols="50" rows="2" name="profile_content" id="new_profile_content"></textarea>
147
						    <textarea cols="50" rows="2" name="profile_marc_content" id="new_profile_marc_content"></textarea>
115
						    <p>You have to define which fields or subfields you want to export, separated by pipes.</p>
148
						    <p>You have to define which fields or subfields you want to export, separated by pipes.</p>
116
                            <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>
149
                            <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
						    <p>Example: Personal name=200|Entry element=210$a|300|009</p>
150
						    <p>Example: Personal name=200|Entry element=210$a|300|009</p>
118
						    </li>
151
						    </li>
152
                            <li class="sql_specific">
153
                              <label for="new_profile_sql_content">Profile SQL fields: </label>
154
                              <textarea cols="50" rows="2" name="profile_sql_content" id="new_profile_sql_content"></textarea>
155
                              <p>You have to define which fields you want to export, separated by pipes.</p>
156
                              <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>
157
                              <p>Example: Name=subscription.name|Title=subscription.title|Issue number=serial.serialseq</p>
158
                            </li>
119
						    </ol>
159
						    </ol>
120
						</fieldset>
160
						</fieldset>
121
						<fieldset class="action"><input type="hidden" name="action" value="create" />
161
						<fieldset class="action"><input type="hidden" name="action" value="create" />
Lines 129-135 function reloadPage(p) { Link Here
129
169
130
				      	    <form action="/cgi-bin/koha/tools/csv-profiles.pl" method="post">
170
				      	    <form action="/cgi-bin/koha/tools/csv-profiles.pl" method="post">
131
						<fieldset class="rows">
171
						<fieldset class="rows">
132
						    <ol><li><label for="modify_profile_name">Profile name: </label>
172
                            <ol>
173
                            <li><label for="modify_profile_name">Profile name: </label>
133
						    <select id="modify_profile_name" name="profile_name" onchange="javascript:reloadPage(this)">
174
						    <select id="modify_profile_name" name="profile_name" onchange="javascript:reloadPage(this)">
134
							<option value="0">-- Choose One --</option>
175
							<option value="0">-- Choose One --</option>
135
							[% FOREACH existing_profile IN existing_profiles %]
176
							[% FOREACH existing_profile IN existing_profiles %]
Lines 141-146 function reloadPage(p) { Link Here
141
							[% END %]
182
							[% END %]
142
						    </select></li>
183
						    </select></li>
143
184
185
                            <li>
186
                              <label for="modify_profile_type">Profile type: </label>
187
                              <select id="modify_profile_type" name="profile_type">
188
                                <option value="marc">MARC</option>
189
                                [% IF selected_profile_type == "sql" %]
190
                                  <option value="sql" selected="selected">SQL</option>
191
                                [% ELSE %]
192
                                  <option value="sql">SQL</option>
193
                                [% END %]
194
                              </select>
195
                            </li>
196
197
144
						    <li><label for="modify_profile_description">Profile description: </label>
198
						    <li><label for="modify_profile_description">Profile description: </label>
145
						    <textarea cols="50" rows="2" name="profile_description" id="modify_profile_description">[% selected_profile_description %]</textarea></li>
199
						    <textarea cols="50" rows="2" name="profile_description" id="modify_profile_description">[% selected_profile_description %]</textarea></li>
146
200
Lines 184-190 function reloadPage(p) { Link Here
184
								[% END %]
238
								[% END %]
185
                            </select></li>
239
                            </select></li>
186
240
187
						    <li><label for="field_separator">Field separator: </label>
241
						    <li class="marc_specific"><label for="field_separator">Field separator: </label>
188
						    <select name="field_separator" id="field_separator">
242
						    <select name="field_separator" id="field_separator">
189
                                <option value=":">Colon (:)</option>
243
                                <option value=":">Colon (:)</option>
190
244
Lines 231-237 function reloadPage(p) { Link Here
231
						    </select></li>
285
						    </select></li>
232
286
233
287
234
						    <li><label for="subfield_separator">Subfield separator: </label>
288
						    <li class="marc_specific"><label for="subfield_separator">Subfield separator: </label>
235
						    <select name="subfield_separator" id="subfield_separator">
289
						    <select name="subfield_separator" id="subfield_separator">
236
                                <option value=":">Colon (:)</option>
290
                                <option value=":">Colon (:)</option>
237
291
Lines 278-284 function reloadPage(p) { Link Here
278
	
332
	
279
						    </select></li>
333
						    </select></li>
280
334
281
						    <li><label for="encoding">Encoding: </label>
335
						    <li class="marc_specific"><label for="encoding">Encoding: </label>
282
						    <select name="encoding" id="encoding">
336
						    <select name="encoding" id="encoding">
283
							[% FOREACH encoding IN encodings %]
337
							[% FOREACH encoding IN encodings %]
284
                                [% IF ( selected_encoding == encoding.encoding ) %]
338
                                [% IF ( selected_encoding == encoding.encoding ) %]
Lines 289-296 function reloadPage(p) { Link Here
289
							[% END %]
343
							[% END %]
290
						    </select></li>
344
						    </select></li>
291
345
292
                            <li><label for="modify_profile_content">Profile MARC fields: </label>
346
                            <li class="marc_specific"><label for="modify_profile_marc_content">Profile MARC fields: </label>
293
						    <textarea cols="50" rows="2" name="profile_content" id="modify_profile_content">[% selected_profile_marcfields %]</textarea></li>
347
						    <textarea cols="50" rows="2" name="profile_marc_content" id="modify_profile_marc_content">[% selected_profile_content %]</textarea></li>
348
349
                            <li class="sql_specific">
350
                              <label for="modify_profile_sql_content">Profile SQL fields: </label>
351
                              <textarea cols="50" rows="2" name="profile_sql_content" id="modify_profile_sql_content">[% selected_profile_content %]</textarea>
352
                            </li>
294
353
295
						   <li class="radio"> <label for="delete">Delete selected profile ?</label>
354
						   <li class="radio"> <label for="delete">Delete selected profile ?</label>
296
						    <input type="checkbox" name="delete" id="delete" /></li>
355
						    <input type="checkbox" name="delete" id="delete" /></li>
(-)a/tools/csv-profiles.pl (-9 / +13 lines)
Lines 67-96 $template->param(encodings => \@encodings_loop); Link Here
67
67
68
my $profile_name        = $input->param("profile_name");
68
my $profile_name        = $input->param("profile_name");
69
my $profile_description = $input->param("profile_description");
69
my $profile_description = $input->param("profile_description");
70
my $profile_content     = $input->param("profile_content");
71
my $csv_separator       = $input->param("csv_separator");
70
my $csv_separator       = $input->param("csv_separator");
72
my $field_separator     = $input->param("field_separator");
71
my $field_separator     = $input->param("field_separator");
73
my $subfield_separator  = $input->param("subfield_separator");
72
my $subfield_separator  = $input->param("subfield_separator");
74
my $encoding            = $input->param("encoding");
73
my $encoding            = $input->param("encoding");
74
my $type                = $input->param("profile_type");
75
my $action              = $input->param("action");
75
my $action              = $input->param("action");
76
my $delete              = $input->param("delete");
76
my $delete              = $input->param("delete");
77
my $id                  = $input->param("id");
77
my $id                  = $input->param("id");
78
if ($delete) { $action = "delete"; }
78
if ($delete) { $action = "delete"; }
79
79
80
my $profile_content = $type eq "marc"
81
    ? $input->param("profile_marc_content")
82
    : $input->param("profile_sql_content");
83
80
if ($profile_name && $profile_content && $action) {
84
if ($profile_name && $profile_content && $action) {
81
    my $rows;
85
    my $rows;
82
86
83
    if ($action eq "create") {
87
    if ($action eq "create") {
84
	my $query = "INSERT INTO export_format(export_format_id, profile, description, marcfields, csv_separator, field_separator, subfield_separator, encoding) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?)";
88
	my $query = "INSERT INTO export_format(export_format_id, profile, description, content, csv_separator, field_separator, subfield_separator, encoding, type) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?)";
85
	my $sth   = $dbh->prepare($query);
89
	my $sth   = $dbh->prepare($query);
86
	$rows  = $sth->execute($profile_name, $profile_description, $profile_content, $csv_separator, $field_separator, $subfield_separator, $encoding);
90
	$rows  = $sth->execute($profile_name, $profile_description, $profile_content, $csv_separator, $field_separator, $subfield_separator, $encoding, $type);
87
    
91
    
88
    }
92
    }
89
93
90
    if ($action eq "edit") {
94
    if ($action eq "edit") {
91
	my $query = "UPDATE export_format SET description=?, marcfields=?, csv_separator=?, field_separator=?, subfield_separator=?, encoding=? WHERE export_format_id=? LIMIT 1";
95
	my $query = "UPDATE export_format SET description=?, content=?, csv_separator=?, field_separator=?, subfield_separator=?, encoding=?, type=? WHERE export_format_id=? LIMIT 1";
92
	my $sth   = $dbh->prepare($query);
96
	my $sth   = $dbh->prepare($query);
93
	$rows  = $sth->execute($profile_description, $profile_content, $csv_separator, $field_separator, $subfield_separator, $encoding, $profile_name);
97
	$rows  = $sth->execute($profile_description, $profile_content, $csv_separator, $field_separator, $subfield_separator, $encoding, $type, $profile_name);
94
    }
98
    }
95
99
96
    if ($action eq "delete") {
100
    if ($action eq "delete") {
Lines 108-114 if ($profile_name && $profile_content && $action) { Link Here
108
112
109
    # If a profile has been selected for modification
113
    # If a profile has been selected for modification
110
    if ($id) {
114
    if ($id) {
111
	my $query = "SELECT export_format_id, profile, description, marcfields, csv_separator, field_separator, subfield_separator, encoding FROM export_format WHERE export_format_id = ?";
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 = ?";
112
	my $sth;
116
	my $sth;
113
	$sth = $dbh->prepare($query);
117
	$sth = $dbh->prepare($query);
114
118
Lines 118-128 if ($profile_name && $profile_content && $action) { Link Here
118
	    selected_profile_id          => $selected_profile->[0],
122
	    selected_profile_id          => $selected_profile->[0],
119
	    selected_profile_name        => $selected_profile->[1],
123
	    selected_profile_name        => $selected_profile->[1],
120
	    selected_profile_description => $selected_profile->[2],
124
	    selected_profile_description => $selected_profile->[2],
121
	    selected_profile_marcfields  => $selected_profile->[3],
125
	    selected_profile_content     => $selected_profile->[3],
122
	    selected_csv_separator       => $selected_profile->[4],
126
	    selected_csv_separator       => $selected_profile->[4],
123
	    selected_field_separator     => $selected_profile->[5],
127
	    selected_field_separator     => $selected_profile->[5],
124
	    selected_subfield_separator  => $selected_profile->[6],
128
	    selected_subfield_separator  => $selected_profile->[6],
125
	    selected_encoding            => $selected_profile->[7]
129
        selected_encoding            => $selected_profile->[7],
130
        selected_profile_type        => $selected_profile->[8]
126
	);
131
	);
127
132
128
    }
133
    }
129
- 

Return to bug 10853