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

(-)a/C4/Biblio.pm (+60 lines)
Lines 38-43 use C4::ClassSource; Link Here
38
use C4::Charset;
38
use C4::Charset;
39
use C4::Linker;
39
use C4::Linker;
40
use C4::OAI::Sets;
40
use C4::OAI::Sets;
41
use C4::Ris;
41
42
42
use Koha::Cache;
43
use Koha::Cache;
43
44
Lines 3760-3765 sub RemoveAllNsb { Link Here
3760
    return $record;
3761
    return $record;
3761
}
3762
}
3762
3763
3764
sub BuildBiblioDataForExport {
3765
    my ( $params ) = @_;
3766
    my $biblionumbers = $params->{biblionumbers};
3767
    my $format = $params->{format};
3768
    my ( @records_data, $records_file );
3769
3770
    # CSV
3771
    if ($format eq 'csv' ) {
3772
3773
        # FIXME should be used at the beginning of this module
3774
        # But compilation explodes...
3775
        require C4::Record;
3776
        $records_file = C4::Record::marc2csv($biblionumbers, $params->{csv_profile_id});
3777
3778
    # Other formats
3779
    } else {
3780
        # retrieve biblios from shelf
3781
        my $marcflavour = C4::Context->preference('marcflavour');
3782
        foreach my $biblionumber (@$biblionumbers) {
3783
            my $dat              = GetBiblioData($biblionumber);
3784
            my $record           = GetMarcBiblio($biblionumber, 1);
3785
            my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
3786
            my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
3787
            my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
3788
            my $fw               = GetFrameworkCode($biblionumber);
3789
            my $subtitle         = GetRecordValue( 'subtitle', $record, $fw );
3790
3791
            my @items = C4::Items::GetItemsInfo( $biblionumber );
3792
3793
            my $hasauthors = 0;
3794
            if($dat->{'author'} || @$marcauthorsarray) {
3795
              $hasauthors = 1;
3796
            }
3797
3798
            $dat->{MARCNOTES}      = $marcnotesarray;
3799
            $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
3800
            $dat->{MARCAUTHORS}    = $marcauthorsarray;
3801
            $dat->{HASAUTHORS}     = $hasauthors;
3802
            $dat->{biblionumber}   = $biblionumber;
3803
            $dat->{ITEM_RESULTS}   = \@items;
3804
            $dat->{subtitle}       = $subtitle;
3805
3806
            if ($format eq 'iso2709') {
3807
                $records_file .= $record->as_usmarc();
3808
            }
3809
            elsif ($format eq 'ris') {
3810
                $records_file .= C4::Ris::marc2ris($record);
3811
            }
3812
            elsif ($format eq 'bibtex') {
3813
                $records_file .= C4::Record::marc2bibtex($record, $biblionumber);
3814
            }
3815
3816
            push( @records_data, $dat );
3817
        }
3818
    }
3819
3820
    return { records_file => $records_file, records_data => \@records_data };
3821
}
3822
3763
1;
3823
1;
3764
3824
3765
3825
(-)a/Koha/Email.pm (+75 lines)
Lines 18-23 Link Here
18
package Koha::Email;
18
package Koha::Email;
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Encode qw( encode );
22
use MIME::QuotedPrint;
23
use MIME::Base64;
21
24
22
use base qw(Class::Accessor);
25
use base qw(Class::Accessor);
23
use C4::Context;
26
use C4::Context;
Lines 60-65 sub create_message_headers { Link Here
60
    $mail{'Message'}      = $params->{message}     if $params->{message};
63
    $mail{'Message'}      = $params->{message}     if $params->{message};
61
    $mail{'Subject'}      = $params->{subject}     if $params->{subject};
64
    $mail{'Subject'}      = $params->{subject}     if $params->{subject};
62
    $mail{'Content-Type'} = $params->{contenttype} if $params->{contenttype};
65
    $mail{'Content-Type'} = $params->{contenttype} if $params->{contenttype};
66
    $self->{mail} = \%mail;
63
    return %mail;
67
    return %mail;
64
}
68
}
69
70
sub fill_body_for_sending {
71
    my ( $self, $params ) = @_;
72
    my $template          = $params->{template};
73
    my $default_filename  = $params->{default_filename};
74
    my $attachment        = $params->{attachment};
75
76
    my %mail = %{ $self->{mail} };
77
78
    # Analysing information and getting mail properties
79
    if ( $template =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
80
        $mail{Subject} = $1;
81
        $mail{Subject} =~ s|\n?(.*)\n?|$1|;
82
        $mail{Subject} = Encode::encode("UTF-8", $mail{Subject});
83
    }
84
    else { $mail{Subject} = "no subject"; }
85
86
    my $email_header = "";
87
    if ( $template =~ /<HEADER>(.*)<END_HEADER>/s ) {
88
        $email_header = $1;
89
        $email_header =~ s|\n?(.*)\n?|$1|;
90
        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
91
    }
92
93
    if ( $template =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
94
        $default_filename = $1;
95
        $default_filename =~ s|\n?(.*)\n?|$1|;
96
    }
97
98
    my $body;
99
    if ( $template =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
100
        $body = $1;
101
        $body =~ s|\n?(.*)\n?|$1|;
102
        $body = encode_qp(Encode::encode("UTF-8", $body));
103
    }
104
105
    my $boundary = "====" . time() . "====";
106
107
    # We set and put the multipart content
108
    $mail{'Content-Type'} = qq|multipart/mixed; boundary="$boundary"|;
109
110
    # If the attachement is a csv file, it's already encoded
111
    # See C4::Record::marc2csv which calls C4::Record::marcrecord2csv
112
    unless ( $default_filename =~ m|.csv$| ) {
113
        $attachment = Encode::encode( "UTF-8", $attachment )
114
    }
115
    my $file = encode_base64( $attachment );
116
    $boundary = '--' . $boundary;
117
118
    $mail{body} = <<END_OF_BODY;
119
$boundary
120
MIME-Version: 1.0
121
Content-Type: text/plain; charset="utf-8"
122
Content-Transfer-Encoding: quoted-printable
123
124
$email_header
125
$body
126
$boundary
127
Content-Type: application/octet-stream; name="$default_filename"
128
Content-Transfer-Encoding: base64
129
Content-Disposition: attachment; filename="$default_filename"
130
131
$file
132
$boundary--
133
END_OF_BODY
134
135
    $self->{mail} = \%mail;
136
137
    return %mail;
138
}
139
65
1;
140
1;
(-)a/basket/basket.pl (-4 / +2 lines)
Lines 15-30 Link Here
15
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
15
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16
# Suite 330, Boston, MA  02111-1307 USA
16
# Suite 330, Boston, MA  02111-1307 USA
17
17
18
18
use Modern::Perl;
19
use strict;
20
use warnings;
21
use CGI qw ( -utf8 );
19
use CGI qw ( -utf8 );
22
use C4::Koha;
20
use C4::Koha;
23
use C4::Biblio;
21
use C4::Biblio;
24
use C4::Items;
22
use C4::Items;
25
use C4::Auth;
23
use C4::Auth;
26
use C4::Output;
24
use C4::Output;
27
use C4::Csv;
25
use C4::Csv qw( GetCsvProfilesLoop );
28
26
29
my $query = new CGI;
27
my $query = new CGI;
30
28
(-)a/basket/downloadcart.pl (-1 lines)
Lines 21-27 use strict; Link Here
21
use warnings;
21
use warnings;
22
22
23
use CGI qw ( -utf8 );
23
use CGI qw ( -utf8 );
24
use Encode qw(encode);
25
24
26
use C4::Auth;
25
use C4::Auth;
27
use C4::Biblio;
26
use C4::Biblio;
(-)a/basket/sendbasket.pl (-87 / +26 lines)
Lines 15-35 Link Here
15
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
15
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16
# Suite 330, Boston, MA  02111-1307 USA
16
# Suite 330, Boston, MA  02111-1307 USA
17
17
18
use strict;
18
use Modern::Perl;
19
use warnings;
20
19
21
use CGI qw ( -utf8 );
20
use CGI qw ( -utf8 );
22
use Encode qw(encode);
23
use Carp;
21
use Carp;
24
22
25
use Mail::Sendmail;
23
use Mail::Sendmail;
26
use MIME::QuotedPrint;
27
use MIME::Base64;
28
use C4::Biblio;
24
use C4::Biblio;
29
use C4::Items;
25
use C4::Items;
30
use C4::Auth;
26
use C4::Auth;
31
use C4::Output;
27
use C4::Output;
32
use C4::Biblio;
28
use C4::Biblio;
29
use C4::Csv qw( GetCsvProfilesLoop );
33
use Koha::Email;
30
use Koha::Email;
34
31
35
my $query = new CGI;
32
my $query = new CGI;
Lines 47-52 my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( Link Here
47
my $bib_list     = $query->param('bib_list');
44
my $bib_list     = $query->param('bib_list');
48
my $email_add    = $query->param('email_add');
45
my $email_add    = $query->param('email_add');
49
my $email_sender = $query->param('email_sender');
46
my $email_sender = $query->param('email_sender');
47
my $format       = $query->param('format') || 'iso2709';
50
48
51
my $dbh          = C4::Context->dbh;
49
my $dbh          = C4::Context->dbh;
52
50
Lines 64-161 if ( $email_add ) { Link Here
64
        }
62
        }
65
    );
63
    );
66
64
67
    my @bibs = split( /\//, $bib_list );
65
    my $csv_profile_id;
68
    my @results;
66
    if ( $format =~ m|^\d+$| ) {
69
    my $iso2709;
67
        $csv_profile_id = $format;
70
    my $marcflavour = C4::Context->preference('marcflavour');
68
        $format         = 'csv';
71
    foreach my $biblionumber (@bibs) {
72
        $template2->param( biblionumber => $biblionumber );
73
74
        my $dat              = GetBiblioData($biblionumber);
75
        my $record           = GetMarcBiblio($biblionumber, 1);
76
        my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
77
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
78
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
79
80
        my @items = GetItemsInfo( $biblionumber );
81
82
        my $hasauthors = 0;
83
        if($dat->{'author'} || @$marcauthorsarray) {
84
          $hasauthors = 1;
85
        }
86
	
87
88
        $dat->{MARCNOTES}      = $marcnotesarray;
89
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
90
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
91
        $dat->{HASAUTHORS}     = $hasauthors;
92
        $dat->{'biblionumber'} = $biblionumber;
93
        $dat->{ITEM_RESULTS}   = \@items;
94
95
        $iso2709 .= $record->as_usmarc();
96
97
        push( @results, $dat );
98
    }
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};
99
80
100
    my $resultsarray = \@results;
101
    $template2->param(
81
    $template2->param(
102
        BIBLIO_RESULTS => $resultsarray,
82
        BIBLIO_RESULTS => $records_data,
103
        email_sender   => $email_sender,
83
        email_sender   => $email_sender,
104
        comment        => $comment
84
        comment        => $comment
105
    );
85
    );
106
86
107
    # Getting template result
87
    # Getting template result
108
    my $template_res = $template2->output();
88
    my $template_res = $template2->output();
109
    my $body;
110
111
    # Analysing information and getting mail properties
112
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
113
        $mail{subject} = $1;
114
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
115
        $mail{subject} = Encode::encode("UTF-8", $mail{subject});
116
    }
117
    else { $mail{'subject'} = "no subject"; }
118
89
119
    my $email_header = "";
90
    %mail = $email->fill_body_for_sending(
120
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
91
        {
121
        $email_header = $1;
92
            template => $template_res,
122
        $email_header =~ s|\n?(.*)\n?|$1|;
93
            default_filename => "basket.$format",
123
        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
94
            attachment => $records_file,
124
    }
95
        }
125
96
    );
126
    my $email_file = "basket.txt";
127
    if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
128
        $email_file = $1;
129
        $email_file =~ s|\n?(.*)\n?|$1|;
130
    }
131
132
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
133
        $body = $1;
134
        $body =~ s|\n?(.*)\n?|$1|;
135
        $body = encode_qp(Encode::encode("UTF-8", $body));
136
    }
137
138
    my $boundary = "====" . time() . "====";
139
140
    # Writing mail
141
    $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
142
    my $isofile = encode_base64(encode("UTF-8", $iso2709));
143
    $boundary = '--' . $boundary;
144
    $mail{body} = <<END_OF_BODY;
145
$boundary
146
Content-Type: text/plain; charset="utf-8"
147
Content-Transfer-Encoding: quoted-printable
148
149
$email_header
150
$body
151
$boundary
152
Content-Type: application/octet-stream; name="basket.iso2709"
153
Content-Transfer-Encoding: base64
154
Content-Disposition: attachment; filename="basket.iso2709"
155
156
$isofile
157
$boundary--
158
END_OF_BODY
159
97
160
    # Sending mail
98
    # Sending mail
161
    if ( sendmail %mail ) {
99
    if ( sendmail %mail ) {
Lines 176-181 else { Link Here
176
        url            => "/cgi-bin/koha/basket/sendbasket.pl",
114
        url            => "/cgi-bin/koha/basket/sendbasket.pl",
177
        suggestion     => C4::Context->preference("suggestion"),
115
        suggestion     => C4::Context->preference("suggestion"),
178
        virtualshelves => C4::Context->preference("virtualshelves"),
116
        virtualshelves => C4::Context->preference("virtualshelves"),
117
        csv_profiles => GetCsvProfilesLoop('marc'),
179
    );
118
    );
180
    output_html_with_http_headers $query, $cookie, $template->output;
119
    output_html_with_http_headers $query, $cookie, $template->output;
181
}
120
}
(-)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 %]">CSV - [% csv_profile.profile %]</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">iso2709</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 %]">CSV - [% csv_profile.profile %]</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 %]
34
                [% BIBLIO_RESULT.title %]
35
                [% IF ( BIBLIO_RESULT.subtitle ) %] [% BIBLIO_RESULT.subtitle %][% END %]
35
                [% IF ( BIBLIO_RESULT.subtitle.size ) %]
36
                  [% FOREACH subtitle IN BIBLIO_RESULT.subtitle %]
37
                    [% subtitle.subfield %]
38
                  [% END %]
39
                [% END %]
36
            </span>
40
            </span>
37
41
38
            <p>
42
            <p>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasketform.tt (-14 / +20 lines)
Lines 17-37 Link Here
17
[% ELSE %]
17
[% ELSE %]
18
18
19
<form action="[% url %]" method="post">
19
<form action="[% url %]" method="post">
20
20
    <fieldset class="rows">
21
<fieldset class="rows"> 
21
        <legend>Sending your cart</legend>
22
<legend>Sending your cart</legend>
22
        <ol>
23
<ol>   <li>
23
            <li>
24
        <label for="email_add">Email address:</label>
24
                <label for="email_add">Email address:</label>
25
        <input type="text" id="email_add" name="email_add" size="43" class="focus" />
25
                <input type="text" id="email_add" name="email_add" size="43" class="focus" />
26
    </li>
26
            </li>
27
    <li>
27
            <li>
28
            <label for="comment">Comment:</label>
28
                <label for="comment">Comment:</label>
29
            <textarea id="comment" name="comment" rows="4" cols="40"></textarea>
29
                <textarea id="comment" name="comment" rows="4" cols="40"></textarea>
30
    </li>
30
            </li>
31
    <li>
31
            <li>
32
                <label for="format">Format:</label>
33
                [% INCLUDE 'download-export-available-formats.inc' %]
34
            </li>
35
        </ol>
36
    </fieldset>
37
    <fieldset class="action">
32
        <input type="hidden" name="bib_list" value="[% bib_list %]" />
38
        <input type="hidden" name="bib_list" value="[% bib_list %]" />
33
    </li></ol></fieldset>
39
        <input type="submit" value="Send" /> <a class="cancel close" href="#">Cancel</a>
34
       <fieldset class="action"> <input type="submit" value="Send" /> <a class="cancel close" href="#">Cancel</a> </fieldset>
40
    </fieldset>
35
</form>
41
</form>
36
42
37
[% END %]</div>
43
[% END %]</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/downloadshelf.tt (-12 / +6 lines)
Lines 10-27 Link Here
10
<form method="post" action="/cgi-bin/koha/virtualshelves/downloadshelf.pl">
10
<form method="post" action="/cgi-bin/koha/virtualshelves/downloadshelf.pl">
11
	<fieldset class="rows">
11
	<fieldset class="rows">
12
    <legend>Download list</legend>
12
    <legend>Download list</legend>
13
	<ol><li>
13
    <ol>
14
    <label for="format">Format: </label>
14
        <li>
15
        <select name="format" id="format">
15
            <label for="format">Format: </label>
16
        <option value="">-- Choose format --</option>
16
            [% INCLUDE 'download-export-available-formats.inc' %]
17
	    <option value="iso2709">iso2709</option>
17
        </li>
18
	    <option value="ris">RIS</option>
18
    </ol>
19
	    <option value="bibtex">BibTex</option>
20
	    [% FOREACH csv_profile IN csv_profiles %]
21
	    <option value="[% csv_profile.export_format_id %]">CSV - [% csv_profile.profile %]</option>
22
	    [% END %]
23
	</select>
24
	</li></ol>
25
	</fieldset>
19
	</fieldset>
26
	<fieldset class="action"><input type="hidden" name="shelfid" value="[% shelfid %]" />
20
	<fieldset class="action"><input type="hidden" name="shelfid" value="[% shelfid %]" />
27
	<input type="submit" name="save" value="Save" />  <a class="cancel close" href="#">Cancel</a>
21
	<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 (-14 / +20 lines)
Lines 16-36 Link Here
16
[% ELSE %]
16
[% ELSE %]
17
17
18
<form action="[% url %]" method="post">
18
<form action="[% url %]" method="post">
19
19
    <fieldset class="rows">
20
<fieldset class="rows"> 
20
        <legend>Sending your list</legend>
21
<legend>Sending your list</legend>
21
        <ol>
22
<ol>   <li>
22
            <li>
23
        <label for="email">Email address:</label>
23
                <label for="email">Email address:</label>
24
        <input type="text" id="email" name="email" size="43" class="focus" />
24
                <input type="text" id="email" name="email" size="43" class="focus" />
25
    </li>
25
            </li>
26
    <li>
26
            <li>
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>
30
            <li>
31
                <label for="format">Format:</label>
32
                [% INCLUDE 'download-export-available-formats.inc' %]
33
            </li>
34
        </ol>
35
    </fieldset>
36
    <fieldset class="action">
31
        <input type="hidden" name="shelfid" value="[% shelfid %]" />
37
        <input type="hidden" name="shelfid" value="[% shelfid %]" />
32
    </li></ol></fieldset>
38
        <input type="submit" value="Send" /> <a class="cancel close" href="#">Cancel</a>
33
       <fieldset class="action"> <input type="submit" value="Send" /> <a class="cancel close" href="#">Cancel</a> </fieldset>
39
    </fieldset>
34
</form>
40
</form>
35
41
36
[% END %]</div>
42
[% END %]</div>
(-)a/koha-tmpl/opac-tmpl/bootstrap/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/opac-tmpl/bootstrap/en/modules/opac-downloadcart.tt (-9 / +1 lines)
Lines 10-24 Link Here
10
                    <div id="userdownloadcart">
10
                    <div id="userdownloadcart">
11
                        <h1>Download cart</h1>
11
                        <h1>Download cart</h1>
12
                        <form method="post" action="/cgi-bin/koha/opac-downloadcart.pl">
12
                        <form method="post" action="/cgi-bin/koha/opac-downloadcart.pl">
13
                            <select name="format" id="format">
13
                            [% INCLUDE 'download-export-available-formats.inc' %]
14
                                <option value="">-- Choose format --</option>
15
                                <option value="ris">RIS (Zotero, EndNote, others)</option>
16
                                <option value="bibtex">BibTeX</option>
17
                                <option value="iso2709">MARC</option>
18
                                [% FOREACH csv_profile IN csv_profiles %]
19
                                    <option value="[% csv_profile.export_format_id %]">CSV - [% csv_profile.profile %]</option>
20
                                [% END %]
21
                            </select>
22
                            <fieldset class="action">
14
                            <fieldset class="action">
23
                                <input type="hidden" name="bib_list" value="[% bib_list | html %]" />
15
                                <input type="hidden" name="bib_list" value="[% bib_list | html %]" />
24
                                <input type="submit" name="save" value="Go" />
16
                                <input type="submit" name="save" value="Go" />
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt (-9 / +1 lines)
Lines 49-63 Link Here
49
                                <h1>Download list <i>[% shelfname %]</i></h1>
49
                                <h1>Download list <i>[% shelfname %]</i></h1>
50
                                <form method="post" action="/cgi-bin/koha/opac-downloadshelf.pl">
50
                                <form method="post" action="/cgi-bin/koha/opac-downloadshelf.pl">
51
                                    <fieldset>
51
                                    <fieldset>
52
                                        <select name="format" id="dlformat" required="required">
52
                                        [% INCLUDE 'download-export-available-formats.inc' %]
53
                                            <option value="">-- Choose format --</option>
54
                                            <option value="ris">RIS (Zotero, EndNote, others)</option>
55
                                            <option value="bibtex">BibTeX</option>
56
                                            <option value="iso2709">MARC</option>
57
                                            [% FOREACH csv_profile IN csv_profiles %]
58
                                            <option value="[% csv_profile.export_format_id |html %]">CSV - [% csv_profile.profile |html %]</option>
59
                                            [% END %]
60
                                        </select>
61
                                        <span class="required">Required</span>
53
                                        <span class="required">Required</span>
62
                                    </fieldset>
54
                                    </fieldset>
63
55
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasket.tt (-1 / +5 lines)
Lines 32-38 Your cart Link Here
32
        <li>
32
        <li>
33
            <span>
33
            <span>
34
                [% BIBLIO_RESULT.title %]
34
                [% BIBLIO_RESULT.title %]
35
                [% IF ( BIBLIO_RESULT.subtitle ) %] [% BIBLIO_RESULT.subtitle %][% END %]
35
                [% IF ( BIBLIO_RESULT.subtitle.size ) %]
36
                  [% FOREACH subtitle IN BIBLIO_RESULT.subtitle %]
37
                    [% subtitle.subfield %]
38
                  [% END %]
39
                [% END %]
36
            </span>
40
            </span>
37
41
38
            <p>
42
            <p>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasketform.tt (+2 lines)
Lines 33-38 Link Here
33
                                    <label for="comment">Comment:</label>
33
                                    <label for="comment">Comment:</label>
34
                                    <textarea id="comment" name="comment" rows="4" cols="40"></textarea>
34
                                    <textarea id="comment" name="comment" rows="4" cols="40"></textarea>
35
                                    <input type="hidden" name="bib_list" value="[% bib_list %]" />
35
                                    <input type="hidden" name="bib_list" value="[% bib_list %]" />
36
                                    <label for="format">Format:</label>
37
                                    [% INCLUDE 'download-export-available-formats.inc' %]
36
                                </fieldset>
38
                                </fieldset>
37
                                <fieldset class="action">
39
                                <fieldset class="action">
38
                                    <input type="submit" class="btn" value="Send" />
40
                                    <input type="submit" class="btn" value="Send" />
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendshelfform.tt (-1 / +4 lines)
Lines 37-43 Link Here
37
                                        <label for="comment">Comment:</label>
37
                                        <label for="comment">Comment:</label>
38
                                        <textarea id="comment" name="comment" rows="4" cols="40"></textarea>
38
                                        <textarea id="comment" name="comment" rows="4" cols="40"></textarea>
39
39
40
                                        <input type="hidden" name="shelfid" value="[% shelfid %]" />
40
                                        <label for="format">Format:</label>
41
                                        [% INCLUDE 'download-export-available-formats.inc' %]
42
43
                                    <input type="hidden" name="shelfid" value="[% shelfid %]" />
41
                                    </fieldset>
44
                                    </fieldset>
42
                                    <fieldset class="action">
45
                                    <fieldset class="action">
43
                                        <input type="submit" value="Send" class="btn" />
46
                                        <input type="submit" value="Send" class="btn" />
(-)a/opac/opac-downloadcart.pl (-6 / +3 lines)
Lines 21-27 use strict; Link Here
21
use warnings;
21
use warnings;
22
22
23
use CGI qw ( -utf8 );
23
use CGI qw ( -utf8 );
24
use Encode qw(encode);
25
24
26
use C4::Auth;
25
use C4::Auth;
27
use C4::Biblio;
26
use C4::Biblio;
Lines 55-66 if ($bib_list && $format) { Link Here
55
    my $marcflavour         = C4::Context->preference('marcflavour');
54
    my $marcflavour         = C4::Context->preference('marcflavour');
56
    my $output;
55
    my $output;
57
56
58
    # CSV   
57
    # CSV
59
    if ($format =~ /^\d+$/) {
58
    if ($format =~ /^\d+$/) {
60
59
61
        $output = marc2csv(\@bibs, $format);
60
        $output = marc2csv(\@bibs, $format);
61
        $format = 'csv';
62
62
63
        # Other formats
63
    # Other formats
64
    } else {
64
    } else {
65
        foreach my $biblio (@bibs) {
65
        foreach my $biblio (@bibs) {
66
66
Lines 79-87 if ($bib_list && $format) { Link Here
79
        }
79
        }
80
    }
80
    }
81
81
82
    # If it was a CSV export we change the format after the export so the file extension is fine
83
    $format = "csv" if ($format =~ m/^\d+$/);
84
85
    print $query->header(
82
    print $query->header(
86
	-type => 'application/octet-stream',
83
	-type => 'application/octet-stream',
87
	-'Content-Transfer-Encoding' => 'binary',
84
	-'Content-Transfer-Encoding' => 'binary',
(-)a/opac/opac-downloadshelf.pl (-5 / +3 lines)
Lines 21-27 use strict; Link Here
21
use warnings;
21
use warnings;
22
22
23
use CGI qw ( -utf8 );
23
use CGI qw ( -utf8 );
24
use Encode qw(encode);
25
24
26
use C4::Auth;
25
use C4::Auth;
27
use C4::Biblio;
26
use C4::Biblio;
Lines 65-71 if ( ShelfPossibleAction( (defined($borrowernumber) ? $borrowernumber : -1), $sh Link Here
65
                push @biblios, $_->{biblionumber};
64
                push @biblios, $_->{biblionumber};
66
            }
65
            }
67
            $output = marc2csv(\@biblios, $format);
66
            $output = marc2csv(\@biblios, $format);
68
                
67
68
            $format = 'csv';
69
69
        # Other formats
70
        # Other formats
70
        } else {
71
        } else {
71
            foreach my $biblio (@$items) {
72
            foreach my $biblio (@$items) {
Lines 86-94 if ( ShelfPossibleAction( (defined($borrowernumber) ? $borrowernumber : -1), $sh Link Here
86
            }
87
            }
87
        }
88
        }
88
89
89
        # If it was a CSV export we change the format after the export so the file extension is fine
90
        $format = "csv" if ($format =~ m/^\d+$/);
91
92
        print $query->header(
90
        print $query->header(
93
    	-type => 'application/octet-stream',
91
    	-type => 'application/octet-stream',
94
    	-'Content-Transfer-Encoding' => 'binary',
92
    	-'Content-Transfer-Encoding' => 'binary',
(-)a/opac/opac-sendbasket.pl (-93 / +28 lines)
Lines 17-38 Link Here
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
19
20
use strict;
20
use Modern::Perl;
21
use warnings;
22
21
23
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
24
use Encode qw(encode);
25
use Carp;
23
use Carp;
26
24
27
use Mail::Sendmail;
25
use Mail::Sendmail;
28
use MIME::QuotedPrint;
29
use MIME::Base64;
30
use C4::Biblio;
26
use C4::Biblio;
31
use C4::Items;
27
use C4::Items;
32
use C4::Auth;
28
use C4::Auth;
33
use C4::Output;
29
use C4::Output;
34
use C4::Biblio;
30
use C4::Biblio;
35
use C4::Members;
31
use C4::Members;
32
use C4::Csv qw( GetCsvProfilesLoop );
36
use Koha::Email;
33
use Koha::Email;
37
34
38
my $query = new CGI;
35
my $query = new CGI;
Lines 50-55 my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( Link Here
50
my $bib_list     = $query->param('bib_list');
47
my $bib_list     = $query->param('bib_list');
51
my $email_add    = $query->param('email_add');
48
my $email_add    = $query->param('email_add');
52
my $email_sender = $query->param('email_sender');
49
my $email_sender = $query->param('email_sender');
50
my $format       = $query->param('format') || 'iso2709';
53
51
54
my $dbh          = C4::Context->dbh;
52
my $dbh          = C4::Context->dbh;
55
53
Lines 79-121 if ( $email_add ) { Link Here
79
        }
77
        }
80
    );
78
    );
81
79
82
    my @bibs = split( /\//, $bib_list );
80
    my $csv_profile_id;
83
    my @results;
81
    if ( $format =~ m|^\d+$| ) {
84
    my $iso2709;
82
        $csv_profile_id = $format;
85
    my $marcflavour = C4::Context->preference('marcflavour');
83
        $format         = 'csv';
86
    foreach my $biblionumber (@bibs) {
87
        $template2->param( biblionumber => $biblionumber );
88
89
        my $dat              = GetBiblioData($biblionumber);
90
        my $record           = GetMarcBiblio($biblionumber, 1);
91
        my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
92
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
93
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
94
95
        my @items = GetItemsInfo( $biblionumber );
96
97
        my $hasauthors = 0;
98
        if($dat->{'author'} || @$marcauthorsarray) {
99
          $hasauthors = 1;
100
        }
101
	
102
103
        $dat->{MARCNOTES}      = $marcnotesarray;
104
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
105
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
106
        $dat->{HASAUTHORS}     = $hasauthors;
107
        $dat->{'biblionumber'} = $biblionumber;
108
        $dat->{ITEM_RESULTS}   = \@items;
109
110
        $iso2709 .= $record->as_usmarc();
111
112
        push( @results, $dat );
113
    }
84
    }
85
    my @biblionumbers = split( /\//, $bib_list );
86
    my $data = C4::Biblio::BuildBiblioDataForExport(
87
        {
88
            biblionumbers  => \@biblionumbers,
89
            format         => $format,
90
            csv_profile_id => $csv_profile_id
91
        }
92
    );
93
    my $records_file = $data->{records_file};
94
    my $records_data = $data->{records_data};
114
95
115
    my $resultsarray = \@results;
116
    
117
    $template2->param(
96
    $template2->param(
118
        BIBLIO_RESULTS => $resultsarray,
97
        BIBLIO_RESULTS => $records_data,
119
        email_sender   => $email_sender,
98
        email_sender   => $email_sender,
120
        comment        => $comment,
99
        comment        => $comment,
121
        firstname      => $user->{firstname},
100
        firstname      => $user->{firstname},
Lines 124-191 if ( $email_add ) { Link Here
124
103
125
    # Getting template result
104
    # Getting template result
126
    my $template_res = $template2->output();
105
    my $template_res = $template2->output();
127
    my $body;
128
129
    # Analysing information and getting mail properties
130
131
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
132
        $mail{subject} = $1;
133
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
134
        $mail{subject} = Encode::encode("UTF-8", $mail{subject});
135
    }
136
    else { $mail{'subject'} = "no subject"; }
137
106
138
    my $email_header = "";
107
    %mail = $email->fill_body_for_sending(
139
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
108
        {
140
        $email_header = $1;
109
            template => $template_res,
141
        $email_header =~ s|\n?(.*)\n?|$1|;
110
            default_filename => "basket.$format",
142
        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
111
            attachment => $records_file,
143
    }
112
        }
144
113
    );
145
    my $email_file = "basket.txt";
146
    if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
147
        $email_file = $1;
148
        $email_file =~ s|\n?(.*)\n?|$1|;
149
    }
150
151
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
152
        $body = $1;
153
        $body =~ s|\n?(.*)\n?|$1|;
154
        $body = encode_qp(Encode::encode("UTF-8", $body));
155
    }
156
157
    $mail{body} = $body;
158
159
    my $boundary = "====" . time() . "====";
160
161
    $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
162
    my $isofile = encode_base64(encode("UTF-8", $iso2709));
163
    $boundary = '--' . $boundary;
164
    $mail{body} = <<END_OF_BODY;
165
$boundary
166
MIME-Version: 1.0
167
Content-Type: text/plain; charset="UTF-8"
168
Content-Transfer-Encoding: quoted-printable
169
170
$email_header
171
$body
172
$boundary
173
Content-Type: application/octet-stream; name="basket.iso2709"
174
Content-Transfer-Encoding: base64
175
Content-Disposition: attachment; filename="basket.iso2709"
176
177
$isofile
178
$boundary--
179
END_OF_BODY
180
114
181
    # Sending mail (if not empty basket)
115
    # Sending mail (if not empty basket)
182
    if ( defined($iso2709) && sendmail %mail ) {
116
    if ( defined($records_file) && sendmail %mail ) {
183
    # do something if it works....
117
    # do something if it works....
184
        $template->param( SENT      => "1" );
118
        $template->param( SENT      => "1" );
185
    }
119
    }
186
    else {
120
    else {
187
        # do something if it doesnt work....
121
        # do something if it doesnt work....
188
    carp "Error sending mail: empty basket" if !defined($iso2709);
122
    carp "Error sending mail: empty basket" unless defined($records_file);
189
        carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error;
123
        carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error;
190
        $template->param( error => 1 );
124
        $template->param( error => 1 );
191
    }
125
    }
Lines 198-203 else { Link Here
198
        url            => "/cgi-bin/koha/opac-sendbasket.pl",
132
        url            => "/cgi-bin/koha/opac-sendbasket.pl",
199
        suggestion     => C4::Context->preference("suggestion"),
133
        suggestion     => C4::Context->preference("suggestion"),
200
        virtualshelves => C4::Context->preference("virtualshelves"),
134
        virtualshelves => C4::Context->preference("virtualshelves"),
135
        csv_profiles   => GetCsvProfilesLoop('marc'),
201
    );
136
    );
202
    output_html_with_http_headers $query, $cookie, $template->output;
137
    output_html_with_http_headers $query, $cookie, $template->output;
203
}
138
}
(-)a/opac/opac-sendshelf.pl (-86 / +27 lines)
Lines 17-38 Link Here
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
19
20
use strict;
20
use Modern::Perl;
21
use warnings;
22
21
23
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
24
use Encode qw( encode );
25
use Carp;
23
use Carp;
26
24
27
use Mail::Sendmail;
25
use Mail::Sendmail;
28
use MIME::QuotedPrint;
29
use MIME::Base64;
30
use C4::Auth;
26
use C4::Auth;
31
use C4::Biblio;
27
use C4::Biblio;
32
use C4::Items;
28
use C4::Items;
33
use C4::Output;
29
use C4::Output;
34
use C4::VirtualShelves;
30
use C4::VirtualShelves;
35
use C4::Members;
31
use C4::Members;
32
use C4::Csv qw( GetCsvProfilesLoop );
36
use Koha::Email;
33
use Koha::Email;
37
34
38
my $query = new CGI;
35
my $query = new CGI;
Lines 49-54 my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( Link Here
49
46
50
my $shelfid = $query->param('shelfid');
47
my $shelfid = $query->param('shelfid');
51
my $email   = $query->param('email');
48
my $email   = $query->param('email');
49
my $format  = $query->param('format') || 'iso2709';
52
50
53
my $dbh          = C4::Context->dbh;
51
my $dbh          = C4::Context->dbh;
54
52
Lines 76-116 if ( $email ) { Link Here
76
74
77
    my @shelf               = GetShelf($shelfid);
75
    my @shelf               = GetShelf($shelfid);
78
    my ($items, $totitems)  = GetShelfContents($shelfid);
76
    my ($items, $totitems)  = GetShelfContents($shelfid);
79
    my $marcflavour         = C4::Context->preference('marcflavour');
77
80
    my $iso2709;
78
    my $csv_profile_id;
81
    my @results;
79
    if ( $format =~ m|^\d+$| ) {
82
80
        $csv_profile_id = $format;
83
    # retrieve biblios from shelf
81
        $format         = 'csv';
84
    foreach my $biblio (@$items) {
85
        my $biblionumber = $biblio->{biblionumber};
86
        my $fw               = GetFrameworkCode($biblionumber);
87
        my $dat              = GetBiblioData($biblionumber);
88
        my $record           = GetMarcBiblio($biblionumber, 1);
89
        my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
90
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
91
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
92
        my $subtitle         = GetRecordValue('subtitle', $record, $fw);
93
94
        my @items = GetItemsInfo( $biblionumber );
95
96
        $dat->{ISBN}           = GetMarcISBN($record, $marcflavour);
97
        $dat->{MARCNOTES}      = $marcnotesarray;
98
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
99
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
100
        $dat->{'biblionumber'} = $biblionumber;
101
        $dat->{ITEM_RESULTS}   = \@items;
102
        $dat->{subtitle}       = $subtitle;
103
        $dat->{HASAUTHORS}     = $dat->{'author'} || @$marcauthorsarray;
104
105
        $iso2709 .= $record->as_usmarc();
106
107
        push( @results, $dat );
108
    }
82
    }
83
    my @biblionumbers = map { $_->{biblionumber} } @$items;
84
    my $data = C4::Biblio::BuildBiblioDataForExport(
85
        {
86
            biblionumbers  => \@biblionumbers,
87
            format         => $format,
88
            csv_profile_id => $csv_profile_id
89
        }
90
    );
91
    my $records_file = $data->{records_file};
92
    my $records_data = $data->{records_data};
109
93
110
    my $user = GetMember(borrowernumber => $borrowernumber);
94
    my $user = GetMember(borrowernumber => $borrowernumber);
111
95
112
    $template2->param(
96
    $template2->param(
113
        BIBLIO_RESULTS => \@results,
97
        BIBLIO_RESULTS => $records_data,
114
        email_sender   => $mail{'from'},
98
        email_sender   => $mail{'from'},
115
        comment        => $comment,
99
        comment        => $comment,
116
        shelfname      => $shelf[1],
100
        shelfname      => $shelf[1],
Lines 122-178 if ( $email ) { Link Here
122
    my $template_res = $template2->output();
106
    my $template_res = $template2->output();
123
    my $body;
107
    my $body;
124
108
125
    # Analysing information and getting mail properties
109
    %mail = $message->fill_body_for_sending(
126
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
110
        {
127
        $mail{subject} = $1;
111
            template => $template_res,
128
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
112
            default_filename => "list.$format",
129
    }
113
            attachment => $records_file,
130
    else { $mail{'subject'} = "no subject"; }
114
        }
131
    $mail{subject} = Encode::encode("UTF-8", $mail{subject});
115
    );
132
133
    my $email_header = "";
134
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
135
        $email_header = $1;
136
        $email_header =~ s|\n?(.*)\n?|$1|;
137
        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
138
    }
139
140
    my $email_file = "list.txt";
141
    if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
142
        $email_file = $1;
143
        $email_file =~ s|\n?(.*)\n?|$1|;
144
    }
145
146
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
147
        $body = $1;
148
        $body =~ s|\n?(.*)\n?|$1|;
149
        $body = encode_qp(Encode::encode("UTF-8", $body));
150
    }
151
152
    my $boundary = "====" . time() . "====";
153
154
    # We set and put the multipart content
155
    $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
156
157
    my $isofile = encode_base64(encode("UTF-8", $iso2709));
158
    $boundary = '--' . $boundary;
159
160
    $mail{body} = <<END_OF_BODY;
161
$boundary
162
MIME-Version: 1.0
163
Content-Type: text/plain; charset="utf-8"
164
Content-Transfer-Encoding: quoted-printable
165
166
$email_header
167
$body
168
$boundary
169
Content-Type: application/octet-stream; name="list.iso2709"
170
Content-Transfer-Encoding: base64
171
Content-Disposition: attachment; filename="list.iso2709"
172
173
$isofile
174
$boundary--
175
END_OF_BODY
176
116
177
    # Sending mail
117
    # Sending mail
178
    if ( sendmail %mail ) {
118
    if ( sendmail %mail ) {
Lines 192-197 END_OF_BODY Link Here
192
}else{
132
}else{
193
    $template->param( shelfid => $shelfid,
133
    $template->param( shelfid => $shelfid,
194
                      url     => "/cgi-bin/koha/opac-sendshelf.pl",
134
                      url     => "/cgi-bin/koha/opac-sendshelf.pl",
135
                      csv_profiles   => GetCsvProfilesLoop('marc'),
195
                    );
136
                    );
196
    output_html_with_http_headers $query, $cookie, $template->output;
137
    output_html_with_http_headers $query, $cookie, $template->output;
197
}
138
}
(-)a/t/Koha_Email.t (-3 / +74 lines)
Lines 1-7 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
use MIME::QuotedPrint;
4
use MIME::Base64;
5
use Template;
6
3
use t::lib::Mocks;
7
use t::lib::Mocks;
4
use Test::More tests => 4;                      # last test to print
8
use Test::More tests => 6;
9
10
use FindBin qw( $Bin );
5
11
6
use_ok('Koha::Email');
12
use_ok('Koha::Email');
7
13
Lines 9-16 my $from = 'chrisc@catalyst.net.nz'; Link Here
9
t::lib::Mocks::mock_preference('ReplytoDefault', $from);
15
t::lib::Mocks::mock_preference('ReplytoDefault', $from);
10
t::lib::Mocks::mock_preference('ReturnpathDefault', $from);
16
t::lib::Mocks::mock_preference('ReturnpathDefault', $from);
11
17
12
13
14
ok( my $email = Koha::Email->new(), 'Create a Koha::Email Object');
18
ok( my $email = Koha::Email->new(), 'Create a Koha::Email Object');
15
ok( my %mail = $email->create_message_headers({from => $from}),'Set headers');
19
ok( my %mail = $email->create_message_headers({from => $from}),'Set headers');
16
is ($mail{'From'}, $from, 'Set correctly');
20
is ($mail{'From'}, $from, 'Set correctly');
21
22
23
my $subject = q|My subject μΣ会é|;
24
my $header = q|My header μΣ会é|;
25
my $message = q|My Message μΣ会é|;
26
27
my $template_filepath = $Bin . '/data/templates/send_by_email.tt';
28
my $tt = Template->new( ENCODING => 'UTF-8', ABSOLUTE => 1 );
29
30
subtest 'csv' => sub {
31
    plan tests => 5;
32
    my $csv_attachment = q|title
33
    "La Recherche"
34
    "Problèmes politiques et sociaux"
35
    "Sud Provence Côte d'Azur"
36
    "The art of computer programming μΣ会é"
37
    |;
38
    # the csv is generated by C4::Record::marc2csv and is already encoded
39
    $csv_attachment = Encode::encode('UTF-8', $csv_attachment);
40
41
    my $output;
42
    $tt->process( $template_filepath, { test => 'pouet' }, \$output );
43
44
    %mail = $email->fill_body_for_sending(
45
        {
46
            template => $output,
47
            default_filename => 'myfile.csv',
48
            attachment => $csv_attachment,
49
        }
50
    );
51
52
    is ($mail{From}, $from, 'From is still set correctly');
53
    like( $mail{Subject}, qr{$subject}, );
54
55
    my $encoded_header = encode_qp($header);
56
    my $encoded_message = encode_qp($header);
57
    my $encoded_csv_attachment = encode_base64($csv_attachment);
58
    like( $mail{body}, qr{$encoded_header}, );
59
    like( $mail{body}, qr{$encoded_message}, );
60
    like( $mail{body}, qr{$encoded_csv_attachment}, );
61
};
62
63
subtest 'iso2709' => sub {
64
    plan tests => 5;
65
    my $ris_attachment = qq|TY  - BOOK\r\nAU  - Knuth, Donald Ervin\r\nTI  - The art of computer programming μΣ会é\r\nKW  - Computer programming\r\nKW  - Computer algorithms\r\nER  - \r\n|;
66
67
    my $output;
68
    $tt->process( $template_filepath, { test => 'pouet' }, \$output );
69
70
    %mail = $email->fill_body_for_sending(
71
        {
72
            template => $output,
73
            default_filename => 'myfile.ris',
74
            attachment => $ris_attachment,
75
        }
76
    );
77
78
    is ($mail{From}, $from, 'From is still set correctly');
79
    like( $mail{Subject}, qr{$subject}, );
80
81
    my $encoded_header = encode_qp($header);
82
    my $encoded_message = encode_qp($header);
83
    my $encoded_ris_attachment = encode_base64(Encode::encode('UTF-8', $ris_attachment));
84
    like( $mail{body}, qr{$encoded_header}, );
85
    like( $mail{body}, qr{$encoded_message}, );
86
    like( $mail{body}, qr{$encoded_ris_attachment}, );
87
};
(-)a/t/data/templates/send_by_email.tt (+11 lines)
Line 0 Link Here
1
<SUBJECT>
2
My subject μΣ会é
3
<END_SUBJECT>
4
5
<HEADER>
6
My header μΣ会é
7
<END_HEADER>
8
9
<MESSAGE>
10
My Message μΣ会é
11
<END_MESSAGE>
(-)a/t/db_dependent/Biblio/BuildBiblioDataForExport.t (+139 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
14
my $dbh = C4::Context->dbh;
15
$dbh->{AutoCommit} = 0;
16
$dbh->{RaiseError} = 1;
17
18
my $module_biblio = Test::MockModule->new('C4::Biblio');
19
20
#my $title = q|The art of computer programming μΣ会é|;
21
my $title = q|The art of computer programming|;
22
my $record = new_record();
23
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, q|| );
24
AddItem({ homebranch => 'CPL', holdingbranch => 'CPL', itype => 'CANNOT', barcode => 'my new barcode' }, $biblionumber);
25
26
subtest 'csv' => sub {
27
    plan tests => 1;
28
    my $csv_content = q(Title=245$a|Author=245$c|Subject=650$a);
29
    my $csv_profile_id = insert_csv_profile({ csv_content => $csv_content });
30
31
    my $csv_data = C4::Biblio::BuildBiblioDataForExport({
32
        biblionumbers => [ $biblionumber ],
33
        format => 'csv',
34
        csv_profile_id => $csv_profile_id,
35
    });
36
37
    is_deeply( $csv_data, { records_data => [], records_file => qq{Title|Author|Subject
38
"$title,The art of another title"|"Donald E. Knuth.,Donald E. Knuth. II"|"Computer programming.,Computer algorithms."
39
}}, 'BuildBiblioDataForExport should return correct values in csv' );
40
};
41
42
subtest 'iso2709' => sub {
43
    plan tests => 7;
44
    my $iso2709_data = C4::Biblio::BuildBiblioDataForExport({
45
        biblionumbers => [ $biblionumber ],
46
        format => 'iso2709',
47
    });
48
49
    my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1});
50
51
    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' );
52
53
    my $first_biblio_data = @{ $iso2709_data->{records_data} }[0];
54
    is( $first_biblio_data->{HASAUTHORS}, 1 );
55
    is( scalar( @{ $first_biblio_data->{MARCSUBJCTS} } ), 2, '499 and 462' );
56
    is( $first_biblio_data->{title}, qq{$title | The art of another title}, );
57
    is( scalar( @{ $first_biblio_data->{ITEM_RESULTS} } ), 1, '1 item' );
58
    is( scalar( @{ $first_biblio_data->{MARCAUTHORS} } ), 0, '0 author' ); # Could be fixed if needed
59
    is( $first_biblio_data->{biblionumber}, $biblionumber, 'bibionumber is correct' );
60
};
61
62
subtest 'ris' => sub {
63
    plan tests => 1;
64
    my $ris_data = C4::Biblio::BuildBiblioDataForExport({
65
        biblionumbers => [ $biblionumber ],
66
        format => 'ris',
67
    });
68
    is( $ris_data->{records_file}, qq|TY  - BOOK\r\nAU  - Knuth, Donald Ervin\r\nTI  - $title\r\nKW  - Computer programming\r\nKW  - Computer algorithms\r\nER  - \r\n|,);
69
};
70
71
subtest 'bibtex' => sub {
72
    plan tests => 1;
73
    my $bibtex_data = C4::Biblio::BuildBiblioDataForExport({
74
        biblionumbers => [ $biblionumber ],
75
        format => 'bibtex',
76
    });
77
    is( $bibtex_data->{records_file}, qq|\@book{$biblionumber,
78
	author = {Knuth, Donald Ervin},
79
	title = {The art of computer programming}
80
}
81
|);
82
};
83
84
sub insert_csv_profile {
85
    my ( $params ) = @_;
86
    $dbh->do(q|
87
        INSERT INTO export_format(profile, description, content, csv_separator, field_separator, subfield_separator, encoding, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
88
        |, {}, ("TEST_PROFILE4", "my desc", $params->{csv_content}, '|', ';', ',', 'utf8', 'marc')
89
    );
90
    return $dbh->last_insert_id( undef, undef, 'export_format', undef );
91
}
92
93
sub new_record {
94
    my $record = MARC::Record->new;
95
    $record->leader('03174nam a2200445 a 4500');
96
    my @fields = (
97
        MARC::Field->new(
98
            '008', "140211b xxu||||| |||| 00| 0 eng d"
99
        ),
100
        MARC::Field->new(
101
            100, '1', ' ',
102
            a => 'Knuth, Donald Ervin',
103
            d => '1938',
104
        ),
105
        MARC::Field->new(
106
            245, '1', '4',
107
            a => $title,
108
            c => 'Donald E. Knuth.',
109
            9 => '0',
110
        ),
111
        MARC::Field->new(
112
            245, '1', '4',
113
            a => 'The art of another title',
114
            c => 'Donald E. Knuth. II',
115
            9 => '1',
116
        ),
117
        MARC::Field->new(
118
            650, ' ', '1',
119
            a => 'Computer programming.',
120
            9 => '462',
121
        ),
122
        MARC::Field->new(
123
            650, ' ', '0',
124
            a => 'Computer algorithms.',
125
            9 => '499',
126
        ),
127
        MARC::Field->new(
128
            952, ' ', ' ',
129
            p => '3010023917',
130
            y => 'BK',
131
            c => 'GEN',
132
            d => '2001-06-25',
133
        ),
134
    );
135
    $record->append_fields(@fields);
136
    return $record;
137
}
138
139
done_testing;
(-)a/virtualshelves/downloadshelf.pl (-1 lines)
Lines 21-27 use strict; Link Here
21
use warnings;
21
use warnings;
22
22
23
use CGI qw ( -utf8 );
23
use CGI qw ( -utf8 );
24
use Encode qw(encode);
25
24
26
use C4::Auth;
25
use C4::Auth;
27
use C4::Biblio;
26
use C4::Biblio;
(-)a/virtualshelves/sendshelf.pl (-84 / +27 lines)
Lines 17-37 Link Here
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
19
20
use strict;
20
use Modern::Perl;
21
use warnings;
22
21
23
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
24
use Encode qw( encode );
25
use Carp;
23
use Carp;
26
24
27
use Mail::Sendmail;
25
use Mail::Sendmail;
28
use MIME::QuotedPrint;
29
use MIME::Base64;
30
use C4::Auth;
26
use C4::Auth;
31
use C4::Biblio;
27
use C4::Biblio;
32
use C4::Items;
28
use C4::Items;
33
use C4::Output;
29
use C4::Output;
34
use C4::VirtualShelves;
30
use C4::VirtualShelves;
31
use C4::Csv qw( GetCsvProfilesLoop );
35
use Koha::Email;
32
use Koha::Email;
36
33
37
my $query = new CGI;
34
my $query = new CGI;
Lines 48-53 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
48
45
49
my $shelfid = $query->param('shelfid');
46
my $shelfid = $query->param('shelfid');
50
my $email   = $query->param('email');
47
my $email   = $query->param('email');
48
my $format  = $query->param('format') || 'iso2709';
51
49
52
my $dbh = C4::Context->dbh;
50
my $dbh = C4::Context->dbh;
53
51
Lines 72-105 if ($email) { Link Here
72
70
73
    my @shelf = GetShelf($shelfid);
71
    my @shelf = GetShelf($shelfid);
74
    my ( $items, $totitems ) = GetShelfContents($shelfid);
72
    my ( $items, $totitems ) = GetShelfContents($shelfid);
75
    my $marcflavour = C4::Context->preference('marcflavour');
73
76
    my $iso2709;
74
    my $csv_profile_id;
77
    my @results;
75
    if ( $format =~ m|^\d+$| ) {
78
76
        $csv_profile_id = $format;
79
    # retrieve biblios from shelf
77
        $format         = 'csv';
80
    foreach my $biblio (@$items) {
81
        my $biblionumber     = $biblio->{biblionumber};
82
        my $fw               = GetFrameworkCode($biblionumber);
83
        my $dat              = GetBiblioData($biblionumber);
84
        my $record           = GetMarcBiblio($biblionumber, 1);
85
        my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
86
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
87
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
88
        my $subtitle         = GetRecordValue( 'subtitle', $record, $fw );
89
90
        my @items = GetItemsInfo($biblionumber);
91
92
        $dat->{MARCNOTES}      = $marcnotesarray;
93
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
94
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
95
        $dat->{'biblionumber'} = $biblionumber;
96
        $dat->{ITEM_RESULTS}   = \@items;
97
        $dat->{subtitle}       = $subtitle;
98
99
        $iso2709 .= $record->as_usmarc();
100
101
        push( @results, $dat );
102
    }
78
    }
79
    my @biblionumbers = map { $_->{biblionumber} } @$items;
80
    my $data = C4::Biblio::BuildBiblioDataForExport(
81
        {
82
            biblionumbers  => \@biblionumbers,
83
            format         => $format,
84
            csv_profile_id => $csv_profile_id
85
        }
86
    );
87
    my $records_file = $data->{records_file};
88
    my $records_data = $data->{records_data};
103
89
104
    if ( C4::Context->preference('OPACBaseURL') ) {
90
    if ( C4::Context->preference('OPACBaseURL') ) {
105
        $template2->param(
91
        $template2->param(
Lines 107-113 if ($email) { Link Here
107
    }
93
    }
108
94
109
    $template2->param(
95
    $template2->param(
110
        BIBLIO_RESULTS => \@results,
96
        BIBLIO_RESULTS => $records_data,
111
        email_sender   => $mail{'from'},
97
        email_sender   => $mail{'from'},
112
        comment        => $comment,
98
        comment        => $comment,
113
        shelfname      => $shelf[1],
99
        shelfname      => $shelf[1],
Lines 115-171 if ($email) { Link Here
115
101
116
    # Getting template result
102
    # Getting template result
117
    my $template_res = $template2->output();
103
    my $template_res = $template2->output();
118
    my $body;
119
120
    # Analysing information and getting mail properties
121
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
122
        $mail{'subject'} = Encode::encode("UTF-8", $1);
123
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
124
    }
125
    else { $mail{'subject'} = "no subject"; }
126
127
    my $email_header = "";
128
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
129
        $email_header = $1;
130
        $email_header =~ s|\n?(.*)\n?|$1|;
131
        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
132
    }
133
134
    my $email_file = "list.txt";
135
    if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
136
        $email_file = $1;
137
        $email_file =~ s|\n?(.*)\n?|$1|;
138
    }
139
104
140
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
105
    %mail = $message->fill_body_for_sending(
141
        $body = $1;
106
        {
142
        $body =~ s|\n?(.*)\n?|$1|;
107
            template => $template_res,
143
        $body = encode_qp(Encode::encode("UTF-8", $body));
108
            default_filename => "list.$format",
144
    }
109
            attachment => $records_file,
145
110
        }
146
    my $boundary = "====" . time() . "====";
111
    );
147
148
    # We set and put the multipart content
149
    $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
150
151
    my $isofile = encode_base64( encode( "UTF-8", $iso2709 ) );
152
    $boundary = '--' . $boundary;
153
154
    $mail{body} = <<END_OF_BODY;
155
$boundary
156
Content-Type: text/plain; charset="utf-8"
157
Content-Transfer-Encoding: quoted-printable
158
159
$email_header
160
$body
161
$boundary
162
Content-Type: application/octet-stream; name="shelf.iso2709"
163
Content-Transfer-Encoding: base64
164
Content-Disposition: attachment; filename="shelf.iso2709"
165
166
$isofile
167
$boundary--
168
END_OF_BODY
169
112
170
    # Sending mail
113
    # Sending mail
171
    if ( sendmail %mail ) {
114
    if ( sendmail %mail ) {
Lines 187-192 else { Link Here
187
    $template->param(
130
    $template->param(
188
        shelfid => $shelfid,
131
        shelfid => $shelfid,
189
        url     => "/cgi-bin/koha/virtualshelves/sendshelf.pl",
132
        url     => "/cgi-bin/koha/virtualshelves/sendshelf.pl",
133
        csv_profiles   => GetCsvProfilesLoop('marc'),
190
    );
134
    );
191
    output_html_with_http_headers $query, $cookie, $template->output;
135
    output_html_with_http_headers $query, $cookie, $template->output;
192
}
136
}
193
- 

Return to bug 13345