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

(-)a/C4/Biblio.pm (+66 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 $template = $params->{template}; # Only used for ISBD
3769
    my ( @records_data, $records_file );
3770
3771
    # CSV
3772
    if ($format eq 'csv' ) {
3773
3774
        # FIXME should be used at the beginning of this module
3775
        # But compilation explodes...
3776
        require C4::Record;
3777
        $records_file = C4::Record::marc2csv($biblionumbers, $params->{csv_profile_id});
3778
3779
    # Other formats
3780
    } else {
3781
        # retrieve biblios from shelf
3782
        my $marcflavour = C4::Context->preference('marcflavour');
3783
        foreach my $biblionumber (@$biblionumbers) {
3784
            my $dat              = GetBiblioData($biblionumber);
3785
            next unless $dat;
3786
            my $record           = GetMarcBiblio($biblionumber, 1);
3787
            my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
3788
            my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
3789
            my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
3790
            my $fw               = GetFrameworkCode($biblionumber);
3791
            my $subtitle         = GetRecordValue( 'subtitle', $record, $fw );
3792
3793
            my @items = C4::Items::GetItemsInfo( $biblionumber );
3794
3795
            my $hasauthors = 0;
3796
            if($dat->{'author'} || @$marcauthorsarray) {
3797
              $hasauthors = 1;
3798
            }
3799
3800
            $dat->{MARCNOTES}      = $marcnotesarray;
3801
            $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
3802
            $dat->{MARCAUTHORS}    = $marcauthorsarray;
3803
            $dat->{HASAUTHORS}     = $hasauthors;
3804
            $dat->{biblionumber}   = $biblionumber;
3805
            $dat->{ITEM_RESULTS}   = \@items;
3806
            $dat->{subtitle}       = $subtitle;
3807
3808
            if ($format eq 'iso2709') {
3809
                $records_file .= $record->as_usmarc();
3810
            }
3811
            elsif ($format eq 'ris') {
3812
                $records_file .= C4::Ris::marc2ris($record);
3813
            }
3814
            elsif ($format eq 'bibtex') {
3815
                $records_file .= C4::Record::marc2bibtex($record, $biblionumber);
3816
            }
3817
            elsif ( $format eq 'isbd' ) {
3818
                # Only called from the OPAC at the moment
3819
                $records_file   .= C4::Biblio::GetISBDView($biblionumber, $template);
3820
            }
3821
3822
            push( @records_data, $dat );
3823
        }
3824
    }
3825
3826
    return { records_file => $records_file, records_data => \@records_data };
3827
}
3828
3763
1;
3829
1;
3764
3830
3765
3831
(-)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 (-88 / +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-162 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
        next unless $dat;
76
        my $record           = GetMarcBiblio($biblionumber, 1);
77
        my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
78
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
79
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
80
81
        my @items = GetItemsInfo( $biblionumber );
82
83
        my $hasauthors = 0;
84
        if($dat->{'author'} || @$marcauthorsarray) {
85
          $hasauthors = 1;
86
        }
87
	
88
89
        $dat->{MARCNOTES}      = $marcnotesarray;
90
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
91
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
92
        $dat->{HASAUTHORS}     = $hasauthors;
93
        $dat->{'biblionumber'} = $biblionumber;
94
        $dat->{ITEM_RESULTS}   = \@items;
95
96
        $iso2709 .= $record->as_usmarc();
97
98
        push( @results, $dat );
99
    }
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};
100
80
101
    my $resultsarray = \@results;
102
    $template2->param(
81
    $template2->param(
103
        BIBLIO_RESULTS => $resultsarray,
82
        BIBLIO_RESULTS => $records_data,
104
        email_sender   => $email_sender,
83
        email_sender   => $email_sender,
105
        comment        => $comment
84
        comment        => $comment
106
    );
85
    );
107
86
108
    # Getting template result
87
    # Getting template result
109
    my $template_res = $template2->output();
88
    my $template_res = $template2->output();
110
    my $body;
111
112
    # Analysing information and getting mail properties
113
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
114
        $mail{subject} = $1;
115
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
116
        $mail{subject} = Encode::encode("UTF-8", $mail{subject});
117
    }
118
    else { $mail{'subject'} = "no subject"; }
119
89
120
    my $email_header = "";
90
    %mail = $email->fill_body_for_sending(
121
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
91
        {
122
        $email_header = $1;
92
            template => $template_res,
123
        $email_header =~ s|\n?(.*)\n?|$1|;
93
            default_filename => "basket.$format",
124
        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
94
            attachment => $records_file,
125
    }
95
        }
126
96
    );
127
    my $email_file = "basket.txt";
128
    if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
129
        $email_file = $1;
130
        $email_file =~ s|\n?(.*)\n?|$1|;
131
    }
132
133
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
134
        $body = $1;
135
        $body =~ s|\n?(.*)\n?|$1|;
136
        $body = encode_qp(Encode::encode("UTF-8", $body));
137
    }
138
139
    my $boundary = "====" . time() . "====";
140
141
    # Writing mail
142
    $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
143
    my $isofile = encode_base64(encode("UTF-8", $iso2709));
144
    $boundary = '--' . $boundary;
145
    $mail{body} = <<END_OF_BODY;
146
$boundary
147
Content-Type: text/plain; charset="utf-8"
148
Content-Transfer-Encoding: quoted-printable
149
150
$email_header
151
$body
152
$boundary
153
Content-Type: application/octet-stream; name="basket.iso2709"
154
Content-Transfer-Encoding: base64
155
Content-Disposition: attachment; filename="basket.iso2709"
156
157
$isofile
158
$boundary--
159
END_OF_BODY
160
97
161
    # Sending mail
98
    # Sending mail
162
    if ( sendmail %mail ) {
99
    if ( sendmail %mail ) {
Lines 177-182 else { Link Here
177
        url            => "/cgi-bin/koha/basket/sendbasket.pl",
114
        url            => "/cgi-bin/koha/basket/sendbasket.pl",
178
        suggestion     => C4::Context->preference("suggestion"),
115
        suggestion     => C4::Context->preference("suggestion"),
179
        virtualshelves => C4::Context->preference("virtualshelves"),
116
        virtualshelves => C4::Context->preference("virtualshelves"),
117
        csv_profiles => GetCsvProfilesLoop('marc'),
180
    );
118
    );
181
    output_html_with_http_headers $query, $cookie, $template->output;
119
    output_html_with_http_headers $query, $cookie, $template->output;
182
}
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 (+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 10-25 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="isbd">ISBD</option>
18
                                <option value="iso2709">MARC</option>
19
                                [% FOREACH csv_profile IN csv_profiles %]
20
                                    <option value="[% csv_profile.export_format_id %]">CSV - [% csv_profile.profile %]</option>
21
                                [% END %]
22
                            </select>
23
                            <fieldset class="action">
14
                            <fieldset class="action">
24
                                <input type="hidden" name="bib_list" value="[% bib_list | html %]" />
15
                                <input type="hidden" name="bib_list" value="[% bib_list | html %]" />
25
                                <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 (-10 / +1 lines)
Lines 49-64 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="isbd">ISBD</option>
57
                                            <option value="iso2709">MARC</option>
58
                                            [% FOREACH csv_profile IN csv_profiles %]
59
                                            <option value="[% csv_profile.export_format_id |html %]">CSV - [% csv_profile.profile |html %]</option>
60
                                            [% END %]
61
                                        </select>
62
                                        <span class="required">Required</span>
53
                                        <span class="required">Required</span>
63
                                    </fieldset>
54
                                    </fieldset>
64
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 57-68 if ($bib_list && $format) { Link Here
57
    my $extension;
56
    my $extension;
58
    my $type;
57
    my $type;
59
58
60
    # CSV   
59
    # CSV
61
    if ($format =~ /^\d+$/) {
60
    if ($format =~ /^\d+$/) {
62
61
63
        $output = marc2csv(\@bibs, $format);
62
        $output = marc2csv(\@bibs, $format);
63
        $format = 'csv';
64
64
65
        # Other formats
65
    # Other formats
66
    } else {
66
    } else {
67
        foreach my $biblio (@bibs) {
67
        foreach my $biblio (@bibs) {
68
68
Lines 86-94 if ($bib_list && $format) { Link Here
86
        }
86
        }
87
    }
87
    }
88
88
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(
89
    print $query->header(
93
                               -type => ($type) ? $type : 'application/octet-stream',
90
                               -type => ($type) ? $type : 'application/octet-stream',
94
        -'Content-Transfer-Encoding' => 'binary',
91
        -'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 67-73 if ( ShelfPossibleAction( (defined($borrowernumber) ? $borrowernumber : -1), $sh Link Here
67
                push @biblios, $_->{biblionumber};
66
                push @biblios, $_->{biblionumber};
68
            }
67
            }
69
            $output = marc2csv(\@biblios, $format);
68
            $output = marc2csv(\@biblios, $format);
70
                
69
70
            $format = 'csv';
71
71
        # Other formats
72
        # Other formats
72
        } else {
73
        } else {
73
            foreach my $biblio (@$items) {
74
            foreach my $biblio (@$items) {
Lines 93-101 if ( ShelfPossibleAction( (defined($borrowernumber) ? $borrowernumber : -1), $sh Link Here
93
            }
94
            }
94
        }
95
        }
95
96
96
        # If it was a CSV export we change the format after the export so the file extension is fine
97
        $format = "csv" if ($format =~ m/^\d+$/);
98
99
        print $query->header(
97
        print $query->header(
100
                                   -type => ($type) ? $type : 'application/octet-stream',
98
                                   -type => ($type) ? $type : 'application/octet-stream',
101
            -'Content-Transfer-Encoding' => 'binary',
99
            -'Content-Transfer-Encoding' => 'binary',
(-)a/opac/opac-sendbasket.pl (-94 / +29 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-122 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
        next unless $dat;
91
        my $record           = GetMarcBiblio($biblionumber, 1);
92
        my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
93
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
94
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
95
96
        my @items = GetItemsInfo( $biblionumber );
97
98
        my $hasauthors = 0;
99
        if($dat->{'author'} || @$marcauthorsarray) {
100
          $hasauthors = 1;
101
        }
102
	
103
104
        $dat->{MARCNOTES}      = $marcnotesarray;
105
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
106
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
107
        $dat->{HASAUTHORS}     = $hasauthors;
108
        $dat->{'biblionumber'} = $biblionumber;
109
        $dat->{ITEM_RESULTS}   = \@items;
110
111
        $iso2709 .= $record->as_usmarc();
112
113
        push( @results, $dat );
114
    }
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
            template       => 'opac',
92
        }
93
    );
94
    my $records_file = $data->{records_file};
95
    my $records_data = $data->{records_data};
115
96
116
    my $resultsarray = \@results;
117
    
118
    $template2->param(
97
    $template2->param(
119
        BIBLIO_RESULTS => $resultsarray,
98
        BIBLIO_RESULTS => $records_data,
120
        email_sender   => $email_sender,
99
        email_sender   => $email_sender,
121
        comment        => $comment,
100
        comment        => $comment,
122
        firstname      => $user->{firstname},
101
        firstname      => $user->{firstname},
Lines 125-192 if ( $email_add ) { Link Here
125
104
126
    # Getting template result
105
    # Getting template result
127
    my $template_res = $template2->output();
106
    my $template_res = $template2->output();
128
    my $body;
129
130
    # Analysing information and getting mail properties
131
132
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
133
        $mail{subject} = $1;
134
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
135
        $mail{subject} = Encode::encode("UTF-8", $mail{subject});
136
    }
137
    else { $mail{'subject'} = "no subject"; }
138
139
    my $email_header = "";
140
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
141
        $email_header = $1;
142
        $email_header =~ s|\n?(.*)\n?|$1|;
143
        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
144
    }
145
107
146
    my $email_file = "basket.txt";
108
    %mail = $email->fill_body_for_sending(
147
    if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
109
        {
148
        $email_file = $1;
110
            template => $template_res,
149
        $email_file =~ s|\n?(.*)\n?|$1|;
111
            default_filename => "basket.$format",
150
    }
112
            attachment => $records_file,
151
113
        }
152
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
114
    );
153
        $body = $1;
154
        $body =~ s|\n?(.*)\n?|$1|;
155
        $body = encode_qp(Encode::encode("UTF-8", $body));
156
    }
157
158
    $mail{body} = $body;
159
160
    my $boundary = "====" . time() . "====";
161
162
    $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
163
    my $isofile = encode_base64(encode("UTF-8", $iso2709));
164
    $boundary = '--' . $boundary;
165
    $mail{body} = <<END_OF_BODY;
166
$boundary
167
MIME-Version: 1.0
168
Content-Type: text/plain; charset="UTF-8"
169
Content-Transfer-Encoding: quoted-printable
170
171
$email_header
172
$body
173
$boundary
174
Content-Type: application/octet-stream; name="basket.iso2709"
175
Content-Transfer-Encoding: base64
176
Content-Disposition: attachment; filename="basket.iso2709"
177
178
$isofile
179
$boundary--
180
END_OF_BODY
181
115
182
    # Sending mail (if not empty basket)
116
    # Sending mail (if not empty basket)
183
    if ( defined($iso2709) && sendmail %mail ) {
117
    if ( defined($records_file) && sendmail %mail ) {
184
    # do something if it works....
118
    # do something if it works....
185
        $template->param( SENT      => "1" );
119
        $template->param( SENT      => "1" );
186
    }
120
    }
187
    else {
121
    else {
188
        # do something if it doesnt work....
122
        # do something if it doesnt work....
189
    carp "Error sending mail: empty basket" if !defined($iso2709);
123
    carp "Error sending mail: empty basket" unless defined($records_file);
190
        carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error;
124
        carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error;
191
        $template->param( error => 1 );
125
        $template->param( error => 1 );
192
    }
126
    }
Lines 199-204 else { Link Here
199
        url            => "/cgi-bin/koha/opac-sendbasket.pl",
133
        url            => "/cgi-bin/koha/opac-sendbasket.pl",
200
        suggestion     => C4::Context->preference("suggestion"),
134
        suggestion     => C4::Context->preference("suggestion"),
201
        virtualshelves => C4::Context->preference("virtualshelves"),
135
        virtualshelves => C4::Context->preference("virtualshelves"),
136
        csv_profiles   => GetCsvProfilesLoop('marc'),
202
    );
137
    );
203
    output_html_with_http_headers $query, $cookie, $template->output;
138
    output_html_with_http_headers $query, $cookie, $template->output;
204
}
139
}
(-)a/opac/opac-sendshelf.pl (-86 / +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::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
            template       => 'opac',
90
        }
91
    );
92
    my $records_file = $data->{records_file};
93
    my $records_data = $data->{records_data};
109
94
110
    my $user = GetMember(borrowernumber => $borrowernumber);
95
    my $user = GetMember(borrowernumber => $borrowernumber);
111
96
112
    $template2->param(
97
    $template2->param(
113
        BIBLIO_RESULTS => \@results,
98
        BIBLIO_RESULTS => $records_data,
114
        email_sender   => $mail{'from'},
99
        email_sender   => $mail{'from'},
115
        comment        => $comment,
100
        comment        => $comment,
116
        shelfname      => $shelf[1],
101
        shelfname      => $shelf[1],
Lines 122-178 if ( $email ) { Link Here
122
    my $template_res = $template2->output();
107
    my $template_res = $template2->output();
123
    my $body;
108
    my $body;
124
109
125
    # Analysing information and getting mail properties
110
    %mail = $message->fill_body_for_sending(
126
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
111
        {
127
        $mail{subject} = $1;
112
            template => $template_res,
128
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
113
            default_filename => "list.$format",
129
    }
114
            attachment => $records_file,
130
    else { $mail{'subject'} = "no subject"; }
115
        }
131
    $mail{subject} = Encode::encode("UTF-8", $mail{subject});
116
    );
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
117
177
    # Sending mail
118
    # Sending mail
178
    if ( sendmail %mail ) {
119
    if ( sendmail %mail ) {
Lines 192-197 END_OF_BODY Link Here
192
}else{
133
}else{
193
    $template->param( shelfid => $shelfid,
134
    $template->param( shelfid => $shelfid,
194
                      url     => "/cgi-bin/koha/opac-sendshelf.pl",
135
                      url     => "/cgi-bin/koha/opac-sendshelf.pl",
136
                      csv_profiles   => GetCsvProfilesLoop('marc'),
195
                    );
137
                    );
196
    output_html_with_http_headers $query, $cookie, $template->output;
138
    output_html_with_http_headers $query, $cookie, $template->output;
197
}
139
}
(-)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