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

(-)a/C4/Biblio.pm (+83 lines)
Lines 93-98 use C4::Charset; Link Here
93
use C4::Linker;
93
use C4::Linker;
94
use C4::OAI::Sets;
94
use C4::OAI::Sets;
95
use C4::Debug;
95
use C4::Debug;
96
use C4::Ris;
96
97
97
use Koha::Caches;
98
use Koha::Caches;
98
use Koha::Authority::Types;
99
use Koha::Authority::Types;
Lines 3216-3221 sub RemoveAllNsb { Link Here
3216
    return $record;
3217
    return $record;
3217
}
3218
}
3218
3219
3220
=head2 BuildBiblioDataForExport
3221
3222
    my $data = BuildBiblioDataForExport({
3223
        biblionumbers => \@biblionumbers,
3224
        format => $format,
3225
        template => $template, # Only used for ISBD format
3226
        csv_profile_id => $csv_profile_id, # Only used for CSV format
3227
3228
Returns a hashref with the following keys:
3229
3230
=over
3231
3232
=item * records_file  A string containing the export file contents
3233
3234
=item * records_data  An array of hashrefs for all biblio records
3235
3236
=back
3237
3238
=cut
3239
3240
sub BuildBiblioDataForExport {
3241
    my ( $params ) = @_;
3242
    my $biblionumbers = $params->{biblionumbers};
3243
    my $format = $params->{format};
3244
    my $template = $params->{template}; # Only used for ISBD
3245
    my ( @records_data, $records_file );
3246
3247
    # CSV
3248
    if ($format eq 'csv' ) {
3249
3250
        # FIXME should be used at the beginning of this module
3251
        # But compilation explodes...
3252
        require C4::Record;
3253
        $records_file = C4::Record::marc2csv($biblionumbers, $params->{csv_profile_id});
3254
3255
    # Other formats
3256
    } else {
3257
        # retrieve biblios from shelf
3258
        my $marcflavour = C4::Context->preference('marcflavour');
3259
        foreach my $biblionumber (@$biblionumbers) {
3260
            my $dat              = GetBiblioData($biblionumber);
3261
            next unless $dat;
3262
            my $record           = GetMarcBiblio({ biblionumber => $biblionumber, embed_items => 1 });
3263
            my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
3264
            my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
3265
            my $fw               = GetFrameworkCode($biblionumber);
3266
3267
            my @items = C4::Items::GetItemsInfo( $biblionumber );
3268
3269
            my $hasauthors = 0;
3270
            if($dat->{'author'} || @$marcauthorsarray) {
3271
              $hasauthors = 1;
3272
            }
3273
3274
            $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
3275
            $dat->{MARCAUTHORS}    = $marcauthorsarray;
3276
            $dat->{HASAUTHORS}     = $hasauthors;
3277
            $dat->{biblionumber}   = $biblionumber;
3278
            $dat->{ITEM_RESULTS}   = \@items;
3279
3280
            if ($format eq 'iso2709') {
3281
                $records_file .= $record->as_usmarc();
3282
            }
3283
            elsif ($format eq 'ris') {
3284
                $records_file .= C4::Ris::marc2ris($record);
3285
            }
3286
            elsif ($format eq 'bibtex') {
3287
                require C4::Record;
3288
                $records_file .= C4::Record::marc2bibtex($record, $biblionumber);
3289
            }
3290
            elsif ( $format eq 'isbd' ) {
3291
                # Only called from the OPAC at the moment
3292
                $records_file   .= C4::Biblio::GetISBDView($biblionumber, $template);
3293
            }
3294
3295
            push( @records_data, $dat );
3296
        }
3297
    }
3298
3299
    return { records_file => $records_file, records_data => \@records_data };
3300
}
3301
3219
1;
3302
1;
3220
3303
3221
3304
(-)a/C4/Ris.pm (-1 / +3 lines)
Lines 439-444 sub print_typetag { Link Here
439
sub normalize_author {
439
sub normalize_author {
440
    my($rawauthora, $rawauthorb, $rawauthorc, $nametype) = @_;
440
    my($rawauthora, $rawauthorb, $rawauthorc, $nametype) = @_;
441
441
442
    $nametype //= 0;
443
442
    if ($nametype == 0) {
444
    if ($nametype == 0) {
443
	# ToDo: convert every input to Last[,(F.|First)[ (M.|Middle)[,Suffix]]]
445
	# ToDo: convert every input to Last[,(F.|First)[ (M.|Middle)[,Suffix]]]
444
	warn("name >>$rawauthora<< in direct order - leave as is") if $marcprint;
446
	warn("name >>$rawauthora<< in direct order - leave as is") if $marcprint;
Lines 831-837 sub get_keywords { Link Here
831
833
832
    ## loop over all 6XX fields
834
    ## loop over all 6XX fields
833
    foreach my $kwfield (@keywords) {
835
    foreach my $kwfield (@keywords) {
834
        if ($kwfield != undef) {
836
        if (defined $kwfield) {
835
            ## authornames get special treatment
837
            ## authornames get special treatment
836
            if ($fieldname eq "600") {
838
            if ($fieldname eq "600") {
837
                my $val = normalize_author($kwfield->subfield('a'), $kwfield->subfield('b'), $kwfield->subfield('c'), $kwfield->indicator('1'));
839
                my $val = normalize_author($kwfield->subfield('a'), $kwfield->subfield('b'), $kwfield->subfield('c'), $kwfield->indicator('1'));
(-)a/basket/sendbasket.pl (-36 / +20 lines)
Lines 29-34 use C4::Output; Link Here
29
use C4::Templates ();
29
use C4::Templates ();
30
use Koha::Email;
30
use Koha::Email;
31
use Koha::Token;
31
use Koha::Token;
32
use Koha::CsvProfiles;
32
33
33
my $query = CGI->new;
34
my $query = CGI->new;
34
35
Lines 43-48 my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( Link Here
43
44
44
my $bib_list  = $query->param('bib_list') || '';
45
my $bib_list  = $query->param('bib_list') || '';
45
my $email_add = $query->param('email_add');
46
my $email_add = $query->param('email_add');
47
my $format    = $query->param('format') || 'iso2709';
46
48
47
my $dbh = C4::Context->dbh;
49
my $dbh = C4::Context->dbh;
48
50
Lines 60-102 if ( $email_add ) { Link Here
60
        'basket/sendbasket.tt', 'intranet', $query,
62
        'basket/sendbasket.tt', 'intranet', $query,
61
    );
63
    );
62
64
63
    my @bibs = split( /\//, $bib_list );
65
    my $csv_profile_id;
64
    my @results;
66
    if ( $format =~ m|^\d+$| ) {
65
    my $iso2709;
67
        $csv_profile_id = $format;
66
    my $marcflavour = C4::Context->preference('marcflavour');
68
        $format         = 'csv';
67
    foreach my $biblionumber (@bibs) {
68
        $template2->param( biblionumber => $biblionumber );
69
70
        my $dat              = GetBiblioData($biblionumber);
71
        next unless $dat;
72
        my $record           = GetMarcBiblio({
73
            biblionumber => $biblionumber,
74
            embed_items => 1 });
75
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
76
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
77
78
        my @items = GetItemsInfo( $biblionumber );
79
80
        my $hasauthors = 0;
81
        if($dat->{'author'} || @$marcauthorsarray) {
82
          $hasauthors = 1;
83
        }
84
	
85
86
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
87
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
88
        $dat->{HASAUTHORS}     = $hasauthors;
89
        $dat->{'biblionumber'} = $biblionumber;
90
        $dat->{ITEM_RESULTS}   = \@items;
91
92
        $iso2709 .= $record->as_usmarc();
93
94
        push( @results, $dat );
95
    }
69
    }
70
    my @biblionumbers = split( /\//, $bib_list );
71
    my $data = C4::Biblio::BuildBiblioDataForExport(
72
        {
73
            biblionumbers  => \@biblionumbers,
74
            format         => $format,
75
            csv_profile_id => $csv_profile_id
76
        }
77
    );
78
    my $records_file = $data->{records_file};
79
    my $records_data = $data->{records_data};
96
80
97
    my $resultsarray = \@results;
98
    $template2->param(
81
    $template2->param(
99
        BIBLIO_RESULTS => $resultsarray,
82
        BIBLIO_RESULTS => $records_data,
100
        comment        => $comment
83
        comment        => $comment
101
    );
84
    );
102
85
Lines 141-149 END_OF_BODY Link Here
141
124
142
        $email->text_body( $THE_body );
125
        $email->text_body( $THE_body );
143
        $email->attach(
126
        $email->attach(
144
            Encode::encode( "UTF-8", $iso2709 ),
127
            Encode::encode( "UTF-8", $records_file ),
145
            content_type => 'application/octet-stream',
128
            content_type => 'application/octet-stream',
146
            name         => 'basket.iso2709',
129
            name         => "basket.$format",
147
            disposition  => 'attachment',
130
            disposition  => 'attachment',
148
        );
131
        );
149
132
Lines 166-171 else { Link Here
166
        suggestion     => C4::Context->preference("suggestion"),
149
        suggestion     => C4::Context->preference("suggestion"),
167
        virtualshelves => C4::Context->preference("virtualshelves"),
150
        virtualshelves => C4::Context->preference("virtualshelves"),
168
        csrf_token     => Koha::Token->new->generate_csrf({ session_id => scalar $query->cookie('CGISESSID'), }),
151
        csrf_token     => Koha::Token->new->generate_csrf({ session_id => scalar $query->cookie('CGISESSID'), }),
152
        csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc' }) ],
169
    );
153
    );
170
    output_html_with_http_headers $query, $cookie, $template->output;
154
    output_html_with_http_headers $query, $cookie, $template->output;
171
}
155
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/download-export-available-formats.inc (+9 lines)
Line 0 Link Here
1
<select name="format" id="dlformat">
2
    <option value="">-- Choose format --</option>
3
    <option value="ris">RIS (Zotero, EndNote, others)</option>
4
    <option value="bibtex">BibTeX</option>
5
    <option value="iso2709">MARC</option>
6
    [% FOREACH csv_profile IN csv_profiles %]
7
        <option value="[% csv_profile.export_format_id | html %]">CSV - [% csv_profile.profile | html %]</option>
8
    [% END %]
9
</select>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/downloadcart.tt (-12 / +5 lines)
Lines 9-26 Link Here
9
<form method="post" action="/cgi-bin/koha/basket/downloadcart.pl">
9
<form method="post" action="/cgi-bin/koha/basket/downloadcart.pl">
10
<fieldset class="rows">
10
<fieldset class="rows">
11
	<legend>Download cart</legend>
11
	<legend>Download cart</legend>
12
	<ol><li>
12
    <ol>
13
	<label for="format">Format:</label>
13
        <li>
14
        <select name="format" id="format">
14
            <label for="format">Format:</label>
15
        <option value="">-- Choose format --</option>
15
            [% INCLUDE 'download-export-available-formats.inc' %]
16
        <option value="iso2709">MARC</option>
16
        </li>
17
	    <option value="ris">RIS</option>
18
	    <option value="bibtex">BibTex</option>
19
	    [% FOREACH csv_profile IN csv_profiles %]
20
	    <option value="[% csv_profile.export_format_id | html %]">CSV - [% csv_profile.profile | html %]</option>
21
	    [% END %]
22
23
	</select></li>
24
	</ol>
17
	</ol>
25
	</fieldset>
18
	</fieldset>
26
	<fieldset class="action">
19
	<fieldset class="action">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasket.tt (-1 / +5 lines)
Lines 32-38 Your cart Link Here
32
        <li>
32
        <li>
33
            <span>
33
            <span>
34
                [% BIBLIO_RESULT.title | $raw %]
34
                [% BIBLIO_RESULT.title | $raw %]
35
                [% IF ( BIBLIO_RESULT.subtitle ) %] [% BIBLIO_RESULT.subtitle | $raw %][% END %]
35
                [% IF ( BIBLIO_RESULT.subtitle.size ) %]
36
                  [% FOREACH subtitle IN BIBLIO_RESULT.subtitle %]
37
                    [% subtitle.subfield | $raw %]
38
                  [% END %]
39
                [% END %]
36
                [% BIBLIO_RESULT.part_number | $raw %] [% BIBLIO_RESULT.part_name | $raw %]
40
                [% BIBLIO_RESULT.part_number | $raw %] [% BIBLIO_RESULT.part_name | $raw %]
37
            </span>
41
            </span>
38
42
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasketform.tt (-12 / +16 lines)
Lines 18-35 Link Here
18
18
19
[% INCLUDE 'blocking_errors.inc' %]
19
[% INCLUDE 'blocking_errors.inc' %]
20
<form action="/cgi-bin/koha/basket/sendbasket.pl" method="post">
20
<form action="/cgi-bin/koha/basket/sendbasket.pl" method="post">
21
21
    <fieldset class="rows">
22
<fieldset class="rows"> 
22
        <legend>Sending your cart</legend>
23
<legend>Sending your cart</legend>
23
        <ol>
24
<ol>   <li>
24
            <li>
25
        <label for="email_add">Email address:</label>
25
                <label for="email_add">Email address:</label>
26
        <input type="text" id="email_add" name="email_add" size="43" class="focus" />
26
                <input type="text" id="email_add" name="email_add" size="43" class="focus" />
27
    </li>
27
            </li>
28
    <li>
28
            <li>
29
            <label for="comment">Comment:</label>
29
                <label for="comment">Comment:</label>
30
            <textarea id="comment" name="comment" rows="4" cols="40"></textarea>
30
                <textarea id="comment" name="comment" rows="4" cols="40"></textarea>
31
    </li>
31
            </li>
32
    </ol>
32
            <li>
33
                <label for="format">Format:</label>
34
                [% INCLUDE 'download-export-available-formats.inc' %]
35
            </li>
36
        </ol>
33
    </fieldset>
37
    </fieldset>
34
    <fieldset class="action"> <input type="submit" value="Send" /> <a class="cancel close" href="#">Cancel</a> </fieldset>
38
    <fieldset class="action"> <input type="submit" value="Send" /> <a class="cancel close" href="#">Cancel</a> </fieldset>
35
    <input type="hidden" name="bib_list" value="[% bib_list | html %]" />
39
    <input type="hidden" name="bib_list" value="[% bib_list | html %]" />
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/downloadshelf.tt (-12 / +6 lines)
Lines 26-43 Link Here
26
<form method="post" action="/cgi-bin/koha/virtualshelves/downloadshelf.pl">
26
<form method="post" action="/cgi-bin/koha/virtualshelves/downloadshelf.pl">
27
	<fieldset class="rows">
27
	<fieldset class="rows">
28
    <legend>Download list</legend>
28
    <legend>Download list</legend>
29
	<ol><li>
29
    <ol>
30
    <label for="format">Format: </label>
30
        <li>
31
        <select name="format" id="format">
31
            <label for="format">Format: </label>
32
        <option value="">-- Choose format --</option>
32
            [% INCLUDE 'download-export-available-formats.inc' %]
33
        <option value="iso2709">MARC</option>
33
        </li>
34
	    <option value="ris">RIS</option>
34
    </ol>
35
	    <option value="bibtex">BibTex</option>
36
	    [% FOREACH csv_profile IN csv_profiles %]
37
	    <option value="[% csv_profile.export_format_id | html %]">CSV - [% csv_profile.profile | html %]</option>
38
	    [% END %]
39
	</select>
40
	</li></ol>
41
	</fieldset>
35
	</fieldset>
42
	<fieldset class="action"><input type="hidden" name="shelfid" value="[% shelfid | html %]" />
36
	<fieldset class="action"><input type="hidden" name="shelfid" value="[% shelfid | html %]" />
43
	<input type="submit" name="save" value="Save" />  <a class="cancel close" href="#">Cancel</a>
37
	<input type="submit" name="save" value="Save" />  <a class="cancel close" href="#">Cancel</a>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/sendshelfform.tt (+4 lines)
Lines 27-32 Link Here
27
            <label for="comment">Comment:</label>
27
            <label for="comment">Comment:</label>
28
            <textarea id="comment" name="comment" rows="4" cols="40"></textarea>
28
            <textarea id="comment" name="comment" rows="4" cols="40"></textarea>
29
    </li>
29
    </li>
30
    <li>
31
            <label for="comment">Format:</label>
32
            [% INCLUDE 'download-export-available-formats.inc' %]
33
    </li>
30
    <li>
34
    <li>
31
        <input type="hidden" name="shelfid" value="[% shelfid | html %]" />
35
        <input type="hidden" name="shelfid" value="[% shelfid | html %]" />
32
    </li></ol></fieldset>
36
    </li></ol></fieldset>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/download-export-available-formats.inc (+10 lines)
Line 0 Link Here
1
<select name="format" id="dlformat">
2
    <option value="">-- Choose format --</option>
3
    <option value="ris">RIS (Zotero, EndNote, others)</option>
4
    <option value="bibtex">BibTeX</option>
5
    <option value="isbd">ISBD</option>
6
    <option value="iso2709">MARC</option>
7
    [% FOREACH csv_profile IN csv_profiles %]
8
        <option value="[% csv_profile.export_format_id | html %]">CSV - [% csv_profile.profile | html %]</option>
9
    [% END %]
10
</select>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadcart.tt (-10 / +1 lines)
Lines 11-26 Link Here
11
                    <div id="userdownloadcart" class="maincontent">
11
                    <div id="userdownloadcart" class="maincontent">
12
                        <h1>Download cart</h1>
12
                        <h1>Download cart</h1>
13
                        <form method="post" action="/cgi-bin/koha/opac-downloadcart.pl">
13
                        <form method="post" action="/cgi-bin/koha/opac-downloadcart.pl">
14
                            <select name="format" id="format">
14
                            [% INCLUDE 'download-export-available-formats.inc' %]
15
                                <option value="">-- Choose format --</option>
16
                                <option value="ris">RIS (Zotero, EndNote, others)</option>
17
                                <option value="bibtex">BibTeX</option>
18
                                <option value="isbd">ISBD</option>
19
                                <option value="iso2709">MARC</option>
20
                                [% FOREACH csv_profile IN csv_profiles %]
21
                                    <option value="[% csv_profile.export_format_id | html %]">CSV - [% csv_profile.profile | html %]</option>
22
                                [% END %]
23
                            </select>
24
                            <fieldset class="action">
15
                            <fieldset class="action">
25
                                <input type="hidden" name="bib_list" value="[% bib_list | html %]" />
16
                                <input type="hidden" name="bib_list" value="[% bib_list | html %]" />
26
                                <input type="submit" name="save" value="Go" />
17
                                <input type="submit" name="save" value="Go" />
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt (-10 / +1 lines)
Lines 56-71 Link Here
56
                                <h1>Download list <em>[% shelf.shelfname | html %]</em></h1>
56
                                <h1>Download list <em>[% shelf.shelfname | html %]</em></h1>
57
                                <form method="post" action="/cgi-bin/koha/opac-downloadshelf.pl">
57
                                <form method="post" action="/cgi-bin/koha/opac-downloadshelf.pl">
58
                                    <fieldset>
58
                                    <fieldset>
59
                                        <select name="format" id="dlformat" required="required">
59
                                        [% INCLUDE 'download-export-available-formats.inc' %]
60
                                            <option value="">-- Choose format --</option>
61
                                            <option value="ris">RIS (Zotero, EndNote, others)</option>
62
                                            <option value="bibtex">BibTeX</option>
63
                                            <option value="isbd">ISBD</option>
64
                                            <option value="iso2709">MARC</option>
65
                                            [% FOREACH csv_profile IN csv_profiles %]
66
                                            <option value="[% csv_profile.export_format_id | html %]">CSV - [% csv_profile.profile | html %]</option>
67
                                            [% END %]
68
                                        </select>
69
                                        <span class="required">Required</span>
60
                                        <span class="required">Required</span>
70
                                    </fieldset>
61
                                    </fieldset>
71
62
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasketform.tt (+2 lines)
Lines 36-41 Link Here
36
                                    <textarea id="comment" name="comment" rows="4" cols="40"></textarea>
36
                                    <textarea id="comment" name="comment" rows="4" cols="40"></textarea>
37
                                    <input type="hidden" name="bib_list" value="[% bib_list | html %]" />
37
                                    <input type="hidden" name="bib_list" value="[% bib_list | html %]" />
38
                                    <input type="hidden" name="csrf_token" value="[% csrf_token | html %]" />
38
                                    <input type="hidden" name="csrf_token" value="[% csrf_token | html %]" />
39
                                    <label for="format">Format:</label>
40
                                    [% INCLUDE 'download-export-available-formats.inc' %]
39
                                </fieldset>
41
                                </fieldset>
40
                                [% IF Koha.Preference('RequestOnOpac') || Koha.Preference('OpacRenewalAllowed') %]<p id="donotrequestbymail">Please do not use this mail to request or renew books.</p>[% END %]
42
                                [% IF Koha.Preference('RequestOnOpac') || Koha.Preference('OpacRenewalAllowed') %]<p id="donotrequestbymail">Please do not use this mail to request or renew books.</p>[% END %]
41
                                <fieldset class="action">
43
                                <fieldset class="action">
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendshelfform.tt (+3 lines)
Lines 39-44 Link Here
39
                                        <label for="comment">Comment:</label>
39
                                        <label for="comment">Comment:</label>
40
                                        <textarea id="comment" name="comment" rows="4" cols="40"></textarea>
40
                                        <textarea id="comment" name="comment" rows="4" cols="40"></textarea>
41
41
42
                                        <label for="format">Format:</label>
43
                                        [% INCLUDE 'download-export-available-formats.inc' %]
44
42
                                        <input type="hidden" name="shelfid" value="[% shelfid | html %]" />
45
                                        <input type="hidden" name="shelfid" value="[% shelfid | html %]" />
43
                                    </fieldset>
46
                                    </fieldset>
44
                                    [% IF Koha.Preference('RequestOnOpac') || Koha.Preference('OpacRenewalAllowed') %]<p id="donotrequestbymail">Please do not use this mail to request or renew books.</p>[% END %]
47
                                    [% IF Koha.Preference('RequestOnOpac') || Koha.Preference('OpacRenewalAllowed') %]<p id="donotrequestbymail">Please do not use this mail to request or renew books.</p>[% END %]
(-)a/opac/opac-downloadcart.pl (-5 / +3 lines)
Lines 63-69 if ($bib_list && $format) { Link Here
63
    my $extension;
63
    my $extension;
64
    my $type;
64
    my $type;
65
65
66
    # CSV   
66
    # CSV
67
    if ($format =~ /^\d+$/) {
67
    if ($format =~ /^\d+$/) {
68
68
69
        my $csv_profile = Koha::CsvProfiles->find($format);
69
        my $csv_profile = Koha::CsvProfiles->find($format);
Lines 73-80 if ($bib_list && $format) { Link Here
73
        }
73
        }
74
74
75
        $output = marc2csv(\@bibs, $format);
75
        $output = marc2csv(\@bibs, $format);
76
        $format = 'csv';
76
77
77
        # Other formats
78
    # Other formats
78
    } else {
79
    } else {
79
        my $record_processor = Koha::RecordProcessor->new({
80
        my $record_processor = Koha::RecordProcessor->new({
80
            filters => 'ViewPolicy'
81
            filters => 'ViewPolicy'
Lines 119-127 if ($bib_list && $format) { Link Here
119
        }
120
        }
120
    }
121
    }
121
122
122
    # If it was a CSV export we change the format after the export so the file extension is fine
123
    $format = "csv" if ($format =~ m/^\d+$/);
124
125
    print $query->header(
123
    print $query->header(
126
                               -type => ($type) ? $type : 'application/octet-stream',
124
                               -type => ($type) ? $type : 'application/octet-stream',
127
        -'Content-Transfer-Encoding' => 'binary',
125
        -'Content-Transfer-Encoding' => 'binary',
(-)a/opac/opac-downloadshelf.pl (-3 / +3 lines)
Lines 87-92 if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { Link Here
87
                push @biblios, $content->biblionumber;
87
                push @biblios, $content->biblionumber;
88
            }
88
            }
89
            $output = marc2csv(\@biblios, $format);
89
            $output = marc2csv(\@biblios, $format);
90
91
            $format = 'csv';
92
90
        # Other formats
93
        # Other formats
91
        } else {
94
        } else {
92
            my $record_processor = Koha::RecordProcessor->new({
95
            my $record_processor = Koha::RecordProcessor->new({
Lines 129-137 if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { Link Here
129
            }
132
            }
130
        }
133
        }
131
134
132
        # If it was a CSV export we change the format after the export so the file extension is fine
133
        $format = "csv" if ($format =~ m/^\d+$/);
134
135
        print $query->header(
135
        print $query->header(
136
                                   -type => ($type) ? $type : 'application/octet-stream',
136
                                   -type => ($type) ? $type : 'application/octet-stream',
137
            -'Content-Transfer-Encoding' => 'binary',
137
            -'Content-Transfer-Encoding' => 'binary',
(-)a/opac/opac-sendbasket.pl (-40 / +22 lines)
Lines 33-38 use C4::Templates (); Link Here
33
use Koha::Email;
33
use Koha::Email;
34
use Koha::Patrons;
34
use Koha::Patrons;
35
use Koha::Token;
35
use Koha::Token;
36
use Koha::CsvProfiles;
36
37
37
my $query = CGI->new;
38
my $query = CGI->new;
38
39
Lines 46-51 my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( Link Here
46
47
47
my $bib_list     = $query->param('bib_list') || '';
48
my $bib_list     = $query->param('bib_list') || '';
48
my $email_add    = $query->param('email_add');
49
my $email_add    = $query->param('email_add');
50
my $format       = $query->param('format') || 'iso2709';
49
51
50
my $dbh          = C4::Context->dbh;
52
my $dbh          = C4::Context->dbh;
51
53
Lines 68-113 if ( $email_add ) { Link Here
68
        'opac-sendbasket.tt', 'opac', $query,
70
        'opac-sendbasket.tt', 'opac', $query,
69
    );
71
    );
70
72
71
    my @bibs = split( /\//, $bib_list );
73
    my $csv_profile_id;
72
    my @results;
74
    if ( $format =~ m|^\d+$| ) {
73
    my $iso2709;
75
        $csv_profile_id = $format;
74
    my $marcflavour = C4::Context->preference('marcflavour');
76
        $format         = 'csv';
75
    foreach my $biblionumber (@bibs) {
76
        $template2->param( biblionumber => $biblionumber );
77
78
        my $dat              = GetBiblioData($biblionumber);
79
        next unless $dat;
80
        my $record           = GetMarcBiblio({
81
            biblionumber => $biblionumber,
82
            embed_items  => 1,
83
            opac         => 1,
84
            borcat       => $borcat });
85
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
86
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
87
88
        my @items = GetItemsInfo( $biblionumber );
89
90
        my $hasauthors = 0;
91
        if($dat->{'author'} || @$marcauthorsarray) {
92
          $hasauthors = 1;
93
        }
94
	
95
96
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
97
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
98
        $dat->{HASAUTHORS}     = $hasauthors;
99
        $dat->{'biblionumber'} = $biblionumber;
100
        $dat->{ITEM_RESULTS}   = \@items;
101
102
        $iso2709 .= $record->as_usmarc();
103
104
        push( @results, $dat );
105
    }
77
    }
78
    my @biblionumbers = split( /\//, $bib_list );
79
    my $data = C4::Biblio::BuildBiblioDataForExport(
80
        {
81
            biblionumbers  => \@biblionumbers,
82
            format         => $format,
83
            csv_profile_id => $csv_profile_id,
84
            template       => 'opac',
85
        }
86
    );
87
    my $records_file = $data->{records_file};
88
    my $records_data = $data->{records_data};
106
89
107
    my $resultsarray = \@results;
108
    
109
    $template2->param(
90
    $template2->param(
110
        BIBLIO_RESULTS => $resultsarray,
91
        BIBLIO_RESULTS => $records_data,
111
        comment        => $comment,
92
        comment        => $comment,
112
        firstname      => $patron->firstname,
93
        firstname      => $patron->firstname,
113
        surname        => $patron->surname,
94
        surname        => $patron->surname,
Lines 143-149 $email_header Link Here
143
$body
124
$body
144
END_OF_BODY
125
END_OF_BODY
145
126
146
    if ( !defined $iso2709 ) {
127
    if ( !defined $records_file ) {
147
        carp "Error sending mail: empty basket";
128
        carp "Error sending mail: empty basket";
148
        $template->param( error => 1 );
129
        $template->param( error => 1 );
149
    }
130
    }
Lines 158-166 END_OF_BODY Link Here
158
            $email->header( 'X-Abuse-Report' => C4::Context->preference('KohaAdminEmailAddress') );
139
            $email->header( 'X-Abuse-Report' => C4::Context->preference('KohaAdminEmailAddress') );
159
            $email->text_body( $THE_body );
140
            $email->text_body( $THE_body );
160
            $email->attach(
141
            $email->attach(
161
                Encode::encode( "UTF-8", $iso2709 ),
142
                Encode::encode( "UTF-8", $records_file ),
162
                content_type => 'application/octet-stream',
143
                content_type => 'application/octet-stream',
163
                name         => 'basket.iso2709',
144
                name         => "basket.$format",
164
                disposition  => 'attachment',
145
                disposition  => 'attachment',
165
            );
146
            );
166
            my $library = $patron->library;
147
            my $library = $patron->library;
Lines 186-191 else { Link Here
186
        virtualshelves => C4::Context->preference("virtualshelves"),
167
        virtualshelves => C4::Context->preference("virtualshelves"),
187
        csrf_token => Koha::Token->new->generate_csrf(
168
        csrf_token => Koha::Token->new->generate_csrf(
188
            { session_id => $new_session_id, } ),
169
            { session_id => $new_session_id, } ),
170
        csv_profiles   => [ Koha::CsvProfiles->search({ type => 'marc' }) ],
189
    );
171
    );
190
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
172
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
191
}
173
}
(-)a/opac/opac-sendshelf.pl (-30 / +24 lines)
Lines 32-37 use C4::Members; Link Here
32
use Koha::Email;
32
use Koha::Email;
33
use Koha::Patrons;
33
use Koha::Patrons;
34
use Koha::Virtualshelves;
34
use Koha::Virtualshelves;
35
use Koha::CsvProfiles;
35
36
36
my $query = CGI->new;
37
my $query = CGI->new;
37
38
Lines 51-56 my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( Link Here
51
52
52
my $shelfid = $query->param('shelfid');
53
my $shelfid = $query->param('shelfid');
53
my $email   = $query->param('email');
54
my $email   = $query->param('email');
55
my $format  = $query->param('format') || 'iso2709';
54
56
55
my $dbh          = C4::Context->dbh;
57
my $dbh          = C4::Context->dbh;
56
58
Lines 74-113 if ( $email ) { Link Here
74
76
75
    my $shelf = Koha::Virtualshelves->find( $shelfid );
77
    my $shelf = Koha::Virtualshelves->find( $shelfid );
76
    my $contents = $shelf->get_contents;
78
    my $contents = $shelf->get_contents;
77
    my $marcflavour         = C4::Context->preference('marcflavour');
78
    my $iso2709;
79
    my @results;
80
79
80
    my @biblionumbers;
81
    while ( my $content = $contents->next ) {
81
    while ( my $content = $contents->next ) {
82
        my $biblionumber = $content->biblionumber;
82
        my $biblionumber = $content->biblionumber;
83
        my $record           = GetMarcBiblio({
83
        push @biblionumbers, $biblionumber;
84
            biblionumber => $biblionumber,
85
            embed_items  => 1,
86
            opac         => 1,
87
            borcat       => $borcat });
88
        next unless $record;
89
        my $fw               = GetFrameworkCode($biblionumber);
90
        my $dat              = GetBiblioData($biblionumber);
91
92
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
93
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
94
95
        my @items = GetItemsInfo( $biblionumber );
96
97
        $dat->{ISBN}           = GetMarcISBN($record, $marcflavour);
98
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
99
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
100
        $dat->{'biblionumber'} = $biblionumber;
101
        $dat->{ITEM_RESULTS}   = \@items;
102
        $dat->{HASAUTHORS}     = $dat->{'author'} || @$marcauthorsarray;
103
104
        $iso2709 .= $record->as_usmarc();
105
106
        push( @results, $dat );
107
    }
84
    }
108
85
86
    my $csv_profile_id;
87
    if ( $format =~ m|^\d+$| ) {
88
        $csv_profile_id = $format;
89
        $format         = 'csv';
90
    }
91
    my $data = C4::Biblio::BuildBiblioDataForExport(
92
        {
93
            biblionumbers  => \@biblionumbers,
94
            format         => $format,
95
            csv_profile_id => $csv_profile_id,
96
            template       => 'opac',
97
        }
98
    );
99
    my $records_file = $data->{records_file};
100
    my $records_data = $data->{records_data};
101
109
    $template2->param(
102
    $template2->param(
110
        BIBLIO_RESULTS => \@results,
103
        BIBLIO_RESULTS => $records_data,
111
        comment        => $comment,
104
        comment        => $comment,
112
        shelfname      => $shelf->shelfname,
105
        shelfname      => $shelf->shelfname,
113
        firstname      => $patron->firstname,
106
        firstname      => $patron->firstname,
Lines 153-161 END_OF_BODY Link Here
153
        );
146
        );
154
        $email->text_body( $THE_body );
147
        $email->text_body( $THE_body );
155
        $email->attach(
148
        $email->attach(
156
            Encode::encode( "UTF-8", $iso2709 ),
149
            Encode::encode( "UTF-8", $records_file ),
157
            content_type => 'application/octet-stream',
150
            content_type => 'application/octet-stream',
158
            name         => 'list.iso2709',
151
            name         => "list.$format",
159
            disposition  => 'attachment',
152
            disposition  => 'attachment',
160
        );
153
        );
161
        my $library = Koha::Patrons->find( $borrowernumber )->library;
154
        my $library = Koha::Patrons->find( $borrowernumber )->library;
Lines 178-183 END_OF_BODY Link Here
178
}else{
171
}else{
179
    $template->param( shelfid => $shelfid,
172
    $template->param( shelfid => $shelfid,
180
                      url     => "/cgi-bin/koha/opac-sendshelf.pl",
173
                      url     => "/cgi-bin/koha/opac-sendshelf.pl",
174
                      csv_profiles   => [ Koha::CsvProfiles->search({ type => 'marc' }) ],
181
                    );
175
                    );
182
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
176
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
183
}
177
}
(-)a/t/db_dependent/Biblio/BuildBiblioDataForExport.t (+120 lines)
Line 0 Link Here
1
use Modern::Perl;
2
use Test::More tests => 4;
3
4
use Test::MockModule;
5
use MARC::Record;
6
use MARC::Field;
7
8
use C4::Biblio;
9
use C4::Context;
10
use C4::Items;
11
use C4::Record;
12
use Koha::DateUtils;
13
use Koha::Item;
14
15
use t::lib::TestBuilder;
16
17
my $schema = Koha::Database->new()->schema();
18
$schema->storage->txn_begin();
19
20
my $builder = t::lib::TestBuilder->new();
21
22
my $title = q|The art of computer programming|;
23
my $author = 'Knuth, Donald Ervin';
24
my $biblio = $builder->build_sample_biblio({ title => $title, author => $author });
25
my $record = $biblio->metadata->record;
26
if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
27
    $record->append_fields(
28
        MARC::Field->new(200, ' ', ' ', a => 'The art of another title', f => 'Donald E. Knuth. II'),
29
        MARC::Field->new(700, '0', '0', a => 'Knuth,Donald Ervin'),
30
    );
31
} else {
32
    $record->field(245)->update(c => $author);
33
    $record->append_fields(
34
        MARC::Field->new(245, ' ', ' ', a => 'The art of another title', f => 'Donald E. Knuth. II'),
35
    );
36
}
37
$record->append_fields(
38
    MARC::Field->new(
39
        600, ' ', '1',
40
        a => 'Computer programming.',
41
        9 => '462',
42
    ),
43
    MARC::Field->new(
44
        600, ' ', '0',
45
        a => 'Computer algorithms.',
46
        9 => '499',
47
    ),
48
);
49
$biblio->metadata->update({ metadata => $record->as_xml() });
50
my $biblionumber = $biblio->biblionumber;
51
my $item = $builder->build_sample_item({ biblionumber => $biblionumber, library => 'CPL', itype => 'CANNOT', barcode => 'my new barcode' });
52
53
subtest 'csv' => sub {
54
    plan tests => 1;
55
    my $csv_content = C4::Context->preference('marcflavour') eq 'UNIMARC'
56
      ? 'Title=200$a|Subject=600$a'
57
      : 'Title=245$a|Subject=600$a';
58
    my $csv_profile_id = insert_csv_profile({ csv_content => $csv_content });
59
60
    my $csv_data = C4::Biblio::BuildBiblioDataForExport({
61
        biblionumbers => [ $biblionumber ],
62
        format => 'csv',
63
        csv_profile_id => $csv_profile_id,
64
    });
65
66
    is_deeply( $csv_data, { records_data => [], records_file => qq{Title|Subject
67
"$title,The art of another title"|"Computer programming.,Computer algorithms."
68
}}, 'BuildBiblioDataForExport should return correct values in csv' );
69
};
70
71
subtest 'iso2709' => sub {
72
    plan tests => 7;
73
    my $iso2709_data = C4::Biblio::BuildBiblioDataForExport({
74
        biblionumbers => [ $biblionumber ],
75
        format => 'iso2709',
76
    });
77
78
    my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1});
79
80
    like( $iso2709_data->{records_file}, qr{00467nam a2200121 a \d+140211b xxu||||| |||| 00| 0 eng d1 aKnuth, Donald Ervind193814a$titlecDonald E. Knuth.9014aThe art of another titlecDonald E. Knuth. II91 1aComputer programming.9462 0aComputer algorithms.9499  c57d57  00104070910aCPLbCPLd$todaypmy new barcoder$todayw$todayyCANNOT}, 'BuildBiblioDataForExport should return a correct records file in iso2709' );
81
82
    my $first_biblio_data = @{ $iso2709_data->{records_data} }[0];
83
    is( $first_biblio_data->{HASAUTHORS}, 1 );
84
    is( scalar( @{ $first_biblio_data->{MARCSUBJCTS} } ), 2, '499 and 462' );
85
    is( $first_biblio_data->{title}, $title );
86
    is( scalar( @{ $first_biblio_data->{ITEM_RESULTS} } ), 1, '1 item' );
87
    is( scalar( @{ $first_biblio_data->{MARCAUTHORS} } ), 1, '1 author' );
88
    is( $first_biblio_data->{biblionumber}, $biblionumber, 'bibionumber is correct' );
89
};
90
91
subtest 'ris' => sub {
92
    plan tests => 1;
93
    my $ris_data = C4::Biblio::BuildBiblioDataForExport({
94
        biblionumbers => [ $biblionumber ],
95
        format => 'ris',
96
    });
97
    is( $ris_data->{records_file}, qq|TY  - GEN\r\nAU  - Knuth,Donald Ervin\r\nTI  - $title\r\nKW  - Computer programming.\r\nKW  - Computer algorithms.\r\nER  - \r\n|,);
98
};
99
100
subtest 'bibtex' => sub {
101
    plan tests => 1;
102
    my $bibtex_data = C4::Biblio::BuildBiblioDataForExport({
103
        biblionumbers => [ $biblionumber ],
104
        format => 'bibtex',
105
    });
106
    my $expected = qq|\@book{$biblionumber,\n\tauthor = {Knuth,Donald Ervin},\n\ttitle = {The art of computer programming}\n}\n|;
107
    is( $bibtex_data->{records_file}, $expected);
108
};
109
110
sub insert_csv_profile {
111
    my ( $params ) = @_;
112
    my $dbh = C4::Context->dbh;
113
    $dbh->do(q|
114
        INSERT INTO export_format(profile, description, content, csv_separator, field_separator, subfield_separator, encoding, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
115
        |, {}, ("TEST_PROFILE4", "my desc", $params->{csv_content}, '|', ';', ',', 'utf8', 'marc')
116
    );
117
    return $dbh->last_insert_id( undef, undef, 'export_format', undef );
118
}
119
120
$schema->storage->txn_rollback();
(-)a/virtualshelves/sendshelf.pl (-25 / +22 lines)
Lines 30-35 use C4::Items; Link Here
30
use C4::Output;
30
use C4::Output;
31
use Koha::Email;
31
use Koha::Email;
32
use Koha::Virtualshelves;
32
use Koha::Virtualshelves;
33
use Koha::CsvProfiles;
33
34
34
my $query = CGI->new;
35
my $query = CGI->new;
35
36
Lines 44-49 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
44
45
45
my $shelfid    = $query->param('shelfid');
46
my $shelfid    = $query->param('shelfid');
46
my $to_address = $query->param('email');
47
my $to_address = $query->param('email');
48
my $format     = $query->param('format') || 'iso2709';
47
49
48
my $dbh = C4::Context->dbh;
50
my $dbh = C4::Context->dbh;
49
51
Lines 61-95 if ($to_address) { Link Here
61
63
62
    my $shelf = Koha::Virtualshelves->find( $shelfid );
64
    my $shelf = Koha::Virtualshelves->find( $shelfid );
63
    my $contents = $shelf->get_contents;
65
    my $contents = $shelf->get_contents;
64
    my $marcflavour = C4::Context->preference('marcflavour');
65
    my $iso2709;
66
    my @results;
67
66
67
    my @biblionumbers;
68
    while ( my $content = $contents->next ) {
68
    while ( my $content = $contents->next ) {
69
        my $biblionumber     = $content->biblionumber;
69
        my $biblionumber     = $content->biblionumber;
70
        my $dat              = GetBiblioData($biblionumber);
70
        push @biblionumbers, $biblionumber;
71
        my $record           = GetMarcBiblio({
71
    }
72
            biblionumber => $biblionumber,
73
            embed_items  => 1 });
74
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
75
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
76
77
        my @items = GetItemsInfo($biblionumber);
78
79
        $dat->{ISBN}           = GetMarcISBN($record, $marcflavour);
80
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
81
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
82
        $dat->{'biblionumber'} = $biblionumber;
83
        $dat->{ITEM_RESULTS}   = \@items;
84
        $dat->{HASAUTHORS}     = $dat->{'author'} || @$marcauthorsarray;
85
86
        $iso2709 .= $record->as_usmarc();
87
72
88
        push( @results, $dat );
73
    my $csv_profile_id;
74
    if ( $format =~ m|^\d+$| ) {
75
        $csv_profile_id = $format;
76
        $format         = 'csv';
89
    }
77
    }
78
    my $data = C4::Biblio::BuildBiblioDataForExport(
79
        {
80
            biblionumbers  => \@biblionumbers,
81
            format         => $format,
82
            csv_profile_id => $csv_profile_id
83
        }
84
    );
85
    my $records_file = $data->{records_file};
86
    my $records_data = $data->{records_data};
90
87
91
    $template2->param(
88
    $template2->param(
92
        BIBLIO_RESULTS => \@results,
89
        BIBLIO_RESULTS => $records_data,
93
        comment        => $comment,
90
        comment        => $comment,
94
        shelfname      => $shelf->shelfname,
91
        shelfname      => $shelf->shelfname,
95
    );
92
    );
Lines 133-141 END_OF_BODY Link Here
133
        );
130
        );
134
        $email->text_body( $THE_body );
131
        $email->text_body( $THE_body );
135
        $email->attach(
132
        $email->attach(
136
            Encode::encode("UTF-8", $iso2709),
133
            Encode::encode("UTF-8", $records_file),
137
            content_type => 'application/octet-stream',
134
            content_type => 'application/octet-stream',
138
            name         => 'shelf.iso2709',
135
            name         => "shelf.$format",
139
            disposition  => 'attachment',
136
            disposition  => 'attachment',
140
        );
137
        );
141
138
Lines 156-161 else { Link Here
156
    $template->param(
153
    $template->param(
157
        shelfid => $shelfid,
154
        shelfid => $shelfid,
158
        url     => "/cgi-bin/koha/virtualshelves/sendshelf.pl",
155
        url     => "/cgi-bin/koha/virtualshelves/sendshelf.pl",
156
        csv_profiles   => [ Koha::CsvProfiles->search({ type => 'marc' }) ],
159
    );
157
    );
160
    output_html_with_http_headers $query, $cookie, $template->output;
158
    output_html_with_http_headers $query, $cookie, $template->output;
161
}
159
}
162
- 

Return to bug 13345