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

(-)a/C4/Biblio.pm (+65 lines)
Lines 37-42 use C4::Charset; Link Here
37
use C4::Linker;
37
use C4::Linker;
38
use C4::OAI::Sets;
38
use C4::OAI::Sets;
39
use C4::Debug;
39
use C4::Debug;
40
use C4::Ris;
40
41
41
use Koha::Caches;
42
use Koha::Caches;
42
use Koha::Authority::Types;
43
use Koha::Authority::Types;
Lines 3820-3825 sub RemoveAllNsb { Link Here
3820
    return $record;
3821
    return $record;
3821
}
3822
}
3822
3823
3824
sub BuildBiblioDataForExport {
3825
    my ( $params ) = @_;
3826
    my $biblionumbers = $params->{biblionumbers};
3827
    my $format = $params->{format};
3828
    my $template = $params->{template}; # Only used for ISBD
3829
    my ( @records_data, $records_file );
3830
3831
    # CSV
3832
    if ($format eq 'csv' ) {
3833
3834
        # FIXME should be used at the beginning of this module
3835
        # But compilation explodes...
3836
        require C4::Record;
3837
        $records_file = C4::Record::marc2csv($biblionumbers, $params->{csv_profile_id});
3838
3839
    # Other formats
3840
    } else {
3841
        # retrieve biblios from shelf
3842
        my $marcflavour = C4::Context->preference('marcflavour');
3843
        foreach my $biblionumber (@$biblionumbers) {
3844
            my $dat              = GetBiblioData($biblionumber);
3845
            next unless $dat;
3846
            my $record           = GetMarcBiblio($biblionumber, 1);
3847
            my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
3848
            my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
3849
            my $fw               = GetFrameworkCode($biblionumber);
3850
            my $subtitle         = GetRecordValue( 'subtitle', $record, $fw );
3851
3852
            my @items = C4::Items::GetItemsInfo( $biblionumber );
3853
3854
            my $hasauthors = 0;
3855
            if($dat->{'author'} || @$marcauthorsarray) {
3856
              $hasauthors = 1;
3857
            }
3858
3859
            $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
3860
            $dat->{MARCAUTHORS}    = $marcauthorsarray;
3861
            $dat->{HASAUTHORS}     = $hasauthors;
3862
            $dat->{biblionumber}   = $biblionumber;
3863
            $dat->{ITEM_RESULTS}   = \@items;
3864
            $dat->{subtitle}       = $subtitle;
3865
3866
            if ($format eq 'iso2709') {
3867
                $records_file .= $record->as_usmarc();
3868
            }
3869
            elsif ($format eq 'ris') {
3870
                $records_file .= C4::Ris::marc2ris($record);
3871
            }
3872
            elsif ($format eq 'bibtex') {
3873
                require C4::Record;
3874
                $records_file .= C4::Record::marc2bibtex($record, $biblionumber);
3875
            }
3876
            elsif ( $format eq 'isbd' ) {
3877
                # Only called from the OPAC at the moment
3878
                $records_file   .= C4::Biblio::GetISBDView($biblionumber, $template);
3879
            }
3880
3881
            push( @records_data, $dat );
3882
        }
3883
    }
3884
3885
    return { records_file => $records_file, records_data => \@records_data };
3886
}
3887
3823
1;
3888
1;
3824
3889
3825
3890
(-)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 (-1 lines)
Lines 15-21 Link Here
15
# You should have received a copy of the GNU General Public License
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
17
18
19
use Modern::Perl;
18
use Modern::Perl;
20
use CGI qw ( -utf8 );
19
use CGI qw ( -utf8 );
21
use C4::Koha;
20
use C4::Koha;
(-)a/basket/downloadcart.pl (-1 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
23
use Encode qw(encode);
24
23
25
use C4::Auth;
24
use C4::Auth;
26
use C4::Biblio;
25
use C4::Biblio;
(-)a/basket/sendbasket.pl (-84 / +25 lines)
Lines 18-29 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use CGI qw ( -utf8 );
20
use CGI qw ( -utf8 );
21
use Encode qw(encode);
22
use Carp;
21
use Carp;
23
use Digest::MD5 qw(md5_base64);
22
use Digest::MD5 qw(md5_base64);
24
use Mail::Sendmail;
23
use Mail::Sendmail;
25
use MIME::QuotedPrint;
26
use MIME::Base64;
27
24
28
use C4::Biblio;
25
use C4::Biblio;
29
use C4::Items;
26
use C4::Items;
Lines 32-37 use C4::Output; Link Here
32
use C4::Templates ();
29
use C4::Templates ();
33
use Koha::Email;
30
use Koha::Email;
34
use Koha::Token;
31
use Koha::Token;
32
use Koha::CsvProfiles;
35
33
36
my $query = new CGI;
34
my $query = new CGI;
37
35
Lines 47-52 my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( Link Here
47
45
48
my $bib_list     = $query->param('bib_list') || '';
46
my $bib_list     = $query->param('bib_list') || '';
49
my $email_add    = $query->param('email_add');
47
my $email_add    = $query->param('email_add');
48
my $format       = $query->param('format') || 'iso2709';
50
49
51
my $dbh          = C4::Context->dbh;
50
my $dbh          = C4::Context->dbh;
52
51
Lines 66-161 if ( $email_add ) { Link Here
66
        'basket/sendbasket.tt', 'intranet', $query,
65
        'basket/sendbasket.tt', 'intranet', $query,
67
    );
66
    );
68
67
69
    my @bibs = split( /\//, $bib_list );
68
    my $csv_profile_id;
70
    my @results;
69
    if ( $format =~ m|^\d+$| ) {
71
    my $iso2709;
70
        $csv_profile_id = $format;
72
    my $marcflavour = C4::Context->preference('marcflavour');
71
        $format         = 'csv';
73
    foreach my $biblionumber (@bibs) {
74
        $template2->param( biblionumber => $biblionumber );
75
76
        my $dat              = GetBiblioData($biblionumber);
77
        next unless $dat;
78
        my $record           = GetMarcBiblio($biblionumber, 1);
79
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
80
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
81
82
        my @items = GetItemsInfo( $biblionumber );
83
84
        my $hasauthors = 0;
85
        if($dat->{'author'} || @$marcauthorsarray) {
86
          $hasauthors = 1;
87
        }
88
	
89
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
    }
72
    }
73
    my @biblionumbers = split( /\//, $bib_list );
74
    my $data = C4::Biblio::BuildBiblioDataForExport(
75
        {
76
            biblionumbers  => \@biblionumbers,
77
            format         => $format,
78
            csv_profile_id => $csv_profile_id
79
        }
80
    );
81
    my $records_file = $data->{records_file};
82
    my $records_data = $data->{records_data};
100
83
101
    my $resultsarray = \@results;
102
    $template2->param(
84
    $template2->param(
103
        BIBLIO_RESULTS => $resultsarray,
85
        BIBLIO_RESULTS => $records_data,
104
        comment        => $comment
86
        comment        => $comment
105
    );
87
    );
106
88
107
    # Getting template result
89
    # Getting template result
108
    my $template_res = $template2->output();
90
    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
91
119
    my $email_header = "";
92
    %mail = $email->fill_body_for_sending(
120
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
93
        {
121
        $email_header = $1;
94
            template => $template_res,
122
        $email_header =~ s|\n?(.*)\n?|$1|;
95
            default_filename => "basket.$format",
123
        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
96
            attachment => $records_file,
124
    }
97
        }
125
98
    );
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
99
160
    # Sending mail
100
    # Sending mail
161
    if ( sendmail %mail ) {
101
    if ( sendmail %mail ) {
Lines 181-186 else { Link Here
181
                secret => md5_base64( C4::Context->config('pass') ),
121
                secret => md5_base64( C4::Context->config('pass') ),
182
            }
122
            }
183
        ),
123
        ),
124
        csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc' }) ],
184
    );
125
    );
185
    output_html_with_http_headers $query, $cookie, $template->output;
126
    output_html_with_http_headers $query, $cookie, $template->output;
186
}
127
}
(-)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 31-37 Your cart Link Here
31
        <li>
31
        <li>
32
            <span>
32
            <span>
33
                [% BIBLIO_RESULT.title %]
33
                [% BIBLIO_RESULT.title %]
34
                [% IF ( BIBLIO_RESULT.subtitle ) %] [% BIBLIO_RESULT.subtitle %][% END %]
34
                [% IF ( BIBLIO_RESULT.subtitle.size ) %]
35
                  [% FOREACH subtitle IN BIBLIO_RESULT.subtitle %]
36
                    [% subtitle.subfield %]
37
                  [% END %]
38
                [% END %]
35
            </span>
39
            </span>
36
40
37
            <p>
41
            <p>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasketform.tt (-15 / +21 lines)
Lines 17-38 Link Here
17
[% ELSE %]
17
[% ELSE %]
18
18
19
<form action="/cgi-bin/koha/basket/sendbasket.pl" method="post">
19
<form action="/cgi-bin/koha/basket/sendbasket.pl" 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
    </ol>
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">
38
        <input type="hidden" name="bib_list" value="[% bib_list %]" />
39
        <input type="hidden" name="csrf_token" value="[% csrf_token %]" />
40
        <input type="submit" value="Send" /> <a class="cancel close" href="#">Cancel</a>
32
    </fieldset>
41
    </fieldset>
33
    <fieldset class="action"> <input type="submit" value="Send" /> <a class="cancel close" href="#">Cancel</a> </fieldset>
34
    <input type="hidden" name="bib_list" value="[% bib_list %]" />
35
    <input type="hidden" name="csrf_token" value="[% csrf_token %]" />
36
</form>
42
</form>
37
43
38
[% END %]</div>
44
[% END %]</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/downloadshelf.tt (-12 / +6 lines)
Lines 26-43 Link Here
26
<form method="post" action="/cgi-bin/koha/virtualshelves/downloadshelf.pl">
26
<form method="post" action="/cgi-bin/koha/virtualshelves/downloadshelf.pl">
27
	<fieldset class="rows">
27
	<fieldset class="rows">
28
    <legend>Download list</legend>
28
    <legend>Download list</legend>
29
	<ol><li>
29
    <ol>
30
    <label for="format">Format: </label>
30
        <li>
31
        <select name="format" id="format">
31
            <label for="format">Format: </label>
32
        <option value="">-- Choose format --</option>
32
            [% INCLUDE 'download-export-available-formats.inc' %]
33
	    <option value="iso2709">iso2709</option>
33
        </li>
34
	    <option value="ris">RIS</option>
34
    </ol>
35
	    <option value="bibtex">BibTex</option>
36
	    [% FOREACH csv_profile IN csv_profiles %]
37
	    <option value="[% csv_profile.export_format_id %]">CSV - [% csv_profile.profile %]</option>
38
	    [% END %]
39
	</select>
40
	</li></ol>
41
	</fieldset>
35
	</fieldset>
42
	<fieldset class="action"><input type="hidden" name="shelfid" value="[% shelfid %]" />
36
	<fieldset class="action"><input type="hidden" name="shelfid" value="[% shelfid %]" />
43
	<input type="submit" name="save" value="Save" />  <a class="cancel close" href="#">Cancel</a>
37
	<input type="submit" name="save" value="Save" />  <a class="cancel close" href="#">Cancel</a>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/sendshelfform.tt (-14 / +20 lines)
Lines 16-36 Link Here
16
[% ELSE %]
16
[% ELSE %]
17
17
18
<form action="/cgi-bin/koha/virtualshelves/sendshelf.pl" method="post">
18
<form action="/cgi-bin/koha/virtualshelves/sendshelf.pl" 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 11-26 Link Here
11
                    <div id="userdownloadcart">
11
                    <div id="userdownloadcart">
12
                        <h1>Download cart</h1>
12
                        <h1>Download cart</h1>
13
                        <form method="post" action="/cgi-bin/koha/opac-downloadcart.pl">
13
                        <form method="post" action="/cgi-bin/koha/opac-downloadcart.pl">
14
                            <select name="format" id="format">
14
                            [% INCLUDE 'download-export-available-formats.inc' %]
15
                                <option value="">-- Choose format --</option>
16
                                <option value="ris">RIS (Zotero, EndNote, others)</option>
17
                                <option value="bibtex">BibTeX</option>
18
                                <option value="isbd">ISBD</option>
19
                                <option value="iso2709">MARC</option>
20
                                [% FOREACH csv_profile IN csv_profiles %]
21
                                    <option value="[% csv_profile.export_format_id %]">CSV - [% csv_profile.profile %]</option>
22
                                [% END %]
23
                            </select>
24
                            <fieldset class="action">
15
                            <fieldset class="action">
25
                                <input type="hidden" name="bib_list" value="[% bib_list | html %]" />
16
                                <input type="hidden" name="bib_list" value="[% bib_list | html %]" />
26
                                <input type="submit" name="save" value="Go" />
17
                                <input type="submit" name="save" value="Go" />
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt (-10 / +1 lines)
Lines 50-65 Link Here
50
                                <h1>Download list <i>[% shelf.shelfname | html %]</i></h1>
50
                                <h1>Download list <i>[% shelf.shelfname | html %]</i></h1>
51
                                <form method="post" action="/cgi-bin/koha/opac-downloadshelf.pl">
51
                                <form method="post" action="/cgi-bin/koha/opac-downloadshelf.pl">
52
                                    <fieldset>
52
                                    <fieldset>
53
                                        <select name="format" id="dlformat" required="required">
53
                                        [% INCLUDE 'download-export-available-formats.inc' %]
54
                                            <option value="">-- Choose format --</option>
55
                                            <option value="ris">RIS (Zotero, EndNote, others)</option>
56
                                            <option value="bibtex">BibTeX</option>
57
                                            <option value="isbd">ISBD</option>
58
                                            <option value="iso2709">MARC</option>
59
                                            [% FOREACH csv_profile IN csv_profiles %]
60
                                            <option value="[% csv_profile.export_format_id |html %]">CSV - [% csv_profile.profile |html %]</option>
61
                                            [% END %]
62
                                        </select>
63
                                        <span class="required">Required</span>
54
                                        <span class="required">Required</span>
64
                                    </fieldset>
55
                                    </fieldset>
65
56
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasket.tt (-1 / +5 lines)
Lines 31-37 Your cart Link Here
31
        <li>
31
        <li>
32
            <span>
32
            <span>
33
                [% BIBLIO_RESULT.title %]
33
                [% BIBLIO_RESULT.title %]
34
                [% IF ( BIBLIO_RESULT.subtitle ) %] [% BIBLIO_RESULT.subtitle %][% END %]
34
                [% IF ( BIBLIO_RESULT.subtitle.size ) %]
35
                  [% FOREACH subtitle IN BIBLIO_RESULT.subtitle %]
36
                    [% subtitle.subfield %]
37
                  [% END %]
38
                [% END %]
35
            </span>
39
            </span>
36
40
37
            <p>
41
            <p>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasketform.tt (+2 lines)
Lines 35-40 Link Here
35
                                    <textarea id="comment" name="comment" rows="4" cols="40"></textarea>
35
                                    <textarea id="comment" name="comment" rows="4" cols="40"></textarea>
36
                                    <input type="hidden" name="bib_list" value="[% bib_list %]" />
36
                                    <input type="hidden" name="bib_list" value="[% bib_list %]" />
37
                                    <input type="hidden" name="csrf_token" value="[% csrf_token %]" />
37
                                    <input type="hidden" name="csrf_token" value="[% csrf_token %]" />
38
                                    <label for="format">Format:</label>
39
                                    [% INCLUDE 'download-export-available-formats.inc' %]
38
                                </fieldset>
40
                                </fieldset>
39
                                <fieldset class="action">
41
                                <fieldset class="action">
40
                                    <input type="submit" class="btn" value="Send" />
42
                                    <input type="submit" class="btn" value="Send" />
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendshelfform.tt (-1 / +4 lines)
Lines 38-44 Link Here
38
                                        <label for="comment">Comment:</label>
38
                                        <label for="comment">Comment:</label>
39
                                        <textarea id="comment" name="comment" rows="4" cols="40"></textarea>
39
                                        <textarea id="comment" name="comment" rows="4" cols="40"></textarea>
40
40
41
                                        <input type="hidden" name="shelfid" value="[% shelfid %]" />
41
                                        <label for="format">Format:</label>
42
                                        [% INCLUDE 'download-export-available-formats.inc' %]
43
44
                                    <input type="hidden" name="shelfid" value="[% shelfid %]" />
42
                                    </fieldset>
45
                                    </fieldset>
43
                                    <fieldset class="action">
46
                                    <fieldset class="action">
44
                                        <input type="submit" value="Send" class="btn" />
47
                                        <input type="submit" value="Send" class="btn" />
(-)a/opac/opac-downloadcart.pl (-6 / +3 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
23
use Encode qw(encode);
24
23
25
use C4::Auth;
24
use C4::Auth;
26
use C4::Biblio;
25
use C4::Biblio;
Lines 56-67 if ($bib_list && $format) { Link Here
56
    my $extension;
55
    my $extension;
57
    my $type;
56
    my $type;
58
57
59
    # CSV   
58
    # CSV
60
    if ($format =~ /^\d+$/) {
59
    if ($format =~ /^\d+$/) {
61
60
62
        $output = marc2csv(\@bibs, $format);
61
        $output = marc2csv(\@bibs, $format);
62
        $format = 'csv';
63
63
64
        # Other formats
64
    # Other formats
65
    } else {
65
    } else {
66
        my $record_processor = Koha::RecordProcessor->new({
66
        my $record_processor = Koha::RecordProcessor->new({
67
            filters => 'ViewPolicy'
67
            filters => 'ViewPolicy'
Lines 100-108 if ($bib_list && $format) { Link Here
100
        }
100
        }
101
    }
101
    }
102
102
103
    # If it was a CSV export we change the format after the export so the file extension is fine
104
    $format = "csv" if ($format =~ m/^\d+$/);
105
106
    print $query->header(
103
    print $query->header(
107
                               -type => ($type) ? $type : 'application/octet-stream',
104
                               -type => ($type) ? $type : 'application/octet-stream',
108
        -'Content-Transfer-Encoding' => 'binary',
105
        -'Content-Transfer-Encoding' => 'binary',
(-)a/opac/opac-downloadshelf.pl (-4 / +3 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
23
use Encode qw(encode);
24
23
25
use C4::Auth;
24
use C4::Auth;
26
use C4::Biblio;
25
use C4::Biblio;
Lines 73-78 if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { Link Here
73
                push @biblios, $content->biblionumber->biblionumber;
72
                push @biblios, $content->biblionumber->biblionumber;
74
            }
73
            }
75
            $output = marc2csv(\@biblios, $format);
74
            $output = marc2csv(\@biblios, $format);
75
76
            $format = 'csv';
77
76
        # Other formats
78
        # Other formats
77
        } else {
79
        } else {
78
            my $record_processor = Koha::RecordProcessor->new({
80
            my $record_processor = Koha::RecordProcessor->new({
Lines 111-119 if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { Link Here
111
            }
113
            }
112
        }
114
        }
113
115
114
        # If it was a CSV export we change the format after the export so the file extension is fine
115
        $format = "csv" if ($format =~ m/^\d+$/);
116
117
        print $query->header(
116
        print $query->header(
118
                                   -type => ($type) ? $type : 'application/octet-stream',
117
                                   -type => ($type) ? $type : 'application/octet-stream',
119
            -'Content-Transfer-Encoding' => 'binary',
118
            -'Content-Transfer-Encoding' => 'binary',
(-)a/opac/opac-sendbasket.pl (-90 / +28 lines)
Lines 20-31 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
23
use Encode qw(encode);
24
use Carp;
23
use Carp;
25
use Digest::MD5 qw(md5_base64);
24
use Digest::MD5 qw(md5_base64);
26
use Mail::Sendmail;
25
use Mail::Sendmail;
27
use MIME::QuotedPrint;
28
use MIME::Base64;
29
26
30
use C4::Biblio;
27
use C4::Biblio;
31
use C4::Items;
28
use C4::Items;
Lines 35-40 use C4::Members; Link Here
35
use C4::Templates ();
32
use C4::Templates ();
36
use Koha::Email;
33
use Koha::Email;
37
use Koha::Token;
34
use Koha::Token;
35
use Koha::CsvProfiles;
38
36
39
my $query = new CGI;
37
my $query = new CGI;
40
38
Lines 49-54 my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( Link Here
49
47
50
my $bib_list     = $query->param('bib_list') || '';
48
my $bib_list     = $query->param('bib_list') || '';
51
my $email_add    = $query->param('email_add');
49
my $email_add    = $query->param('email_add');
50
my $format       = $query->param('format') || 'iso2709';
52
51
53
my $dbh          = C4::Context->dbh;
52
my $dbh          = C4::Context->dbh;
54
53
Lines 79-120 if ( $email_add ) { Link Here
79
        'opac-sendbasket.tt', 'opac', $query,
78
        'opac-sendbasket.tt', 'opac', $query,
80
    );
79
    );
81
80
82
    my @bibs = split( /\//, $bib_list );
81
    my $csv_profile_id;
83
    my @results;
82
    if ( $format =~ m|^\d+$| ) {
84
    my $iso2709;
83
        $csv_profile_id = $format;
85
    my $marcflavour = C4::Context->preference('marcflavour');
84
        $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 $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->{MARCSUBJCTS}    = $marcsubjctsarray;
104
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
105
        $dat->{HASAUTHORS}     = $hasauthors;
106
        $dat->{'biblionumber'} = $biblionumber;
107
        $dat->{ITEM_RESULTS}   = \@items;
108
109
        $iso2709 .= $record->as_usmarc();
110
111
        push( @results, $dat );
112
    }
85
    }
86
    my @biblionumbers = split( /\//, $bib_list );
87
    my $data = C4::Biblio::BuildBiblioDataForExport(
88
        {
89
            biblionumbers  => \@biblionumbers,
90
            format         => $format,
91
            csv_profile_id => $csv_profile_id,
92
            template       => 'opac',
93
        }
94
    );
95
    my $records_file = $data->{records_file};
96
    my $records_data = $data->{records_data};
113
97
114
    my $resultsarray = \@results;
115
    
116
    $template2->param(
98
    $template2->param(
117
        BIBLIO_RESULTS => $resultsarray,
99
        BIBLIO_RESULTS => $records_data,
118
        comment        => $comment,
100
        comment        => $comment,
119
        firstname      => $user->{firstname},
101
        firstname      => $user->{firstname},
120
        surname        => $user->{surname},
102
        surname        => $user->{surname},
Lines 122-189 if ( $email_add ) { Link Here
122
104
123
    # Getting template result
105
    # Getting template result
124
    my $template_res = $template2->output();
106
    my $template_res = $template2->output();
125
    my $body;
126
127
    # Analysing information and getting mail properties
128
129
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
130
        $mail{subject} = $1;
131
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
132
        $mail{subject} = Encode::encode("UTF-8", $mail{subject});
133
    }
134
    else { $mail{'subject'} = "no subject"; }
135
107
136
    my $email_header = "";
108
    %mail = $email->fill_body_for_sending(
137
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
109
        {
138
        $email_header = $1;
110
            template => $template_res,
139
        $email_header =~ s|\n?(.*)\n?|$1|;
111
            default_filename => "basket.$format",
140
        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
112
            attachment => $records_file,
141
    }
113
        }
142
114
    );
143
    my $email_file = "basket.txt";
144
    if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
145
        $email_file = $1;
146
        $email_file =~ s|\n?(.*)\n?|$1|;
147
    }
148
149
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
150
        $body = $1;
151
        $body =~ s|\n?(.*)\n?|$1|;
152
        $body = encode_qp(Encode::encode("UTF-8", $body));
153
    }
154
155
    $mail{body} = $body;
156
157
    my $boundary = "====" . time() . "====";
158
159
    $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
160
    my $isofile = encode_base64(encode("UTF-8", $iso2709));
161
    $boundary = '--' . $boundary;
162
    $mail{body} = <<END_OF_BODY;
163
$boundary
164
MIME-Version: 1.0
165
Content-Type: text/plain; charset="UTF-8"
166
Content-Transfer-Encoding: quoted-printable
167
168
$email_header
169
$body
170
$boundary
171
Content-Type: application/octet-stream; name="basket.iso2709"
172
Content-Transfer-Encoding: base64
173
Content-Disposition: attachment; filename="basket.iso2709"
174
175
$isofile
176
$boundary--
177
END_OF_BODY
178
115
179
    # Sending mail (if not empty basket)
116
    # Sending mail (if not empty basket)
180
    if ( defined($iso2709) && sendmail %mail ) {
117
    if ( defined($records_file) && sendmail %mail ) {
181
    # do something if it works....
118
    # do something if it works....
182
        $template->param( SENT      => "1" );
119
        $template->param( SENT      => "1" );
183
    }
120
    }
184
    else {
121
    else {
185
        # do something if it doesnt work....
122
        # do something if it doesnt work....
186
    carp "Error sending mail: empty basket" if !defined($iso2709);
123
    carp "Error sending mail: empty basket" unless defined($records_file);
187
        carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error;
124
        carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error;
188
        $template->param( error => 1 );
125
        $template->param( error => 1 );
189
    }
126
    }
Lines 201-206 else { Link Here
201
                secret => md5_base64( C4::Context->config('pass') ),
138
                secret => md5_base64( C4::Context->config('pass') ),
202
            }
139
            }
203
        ),
140
        ),
141
        csv_profiles   => [ Koha::CsvProfiles->search({ type => 'marc' }) ],
204
    );
142
    );
205
    output_html_with_http_headers $query, $cookie, $template->output;
143
    output_html_with_http_headers $query, $cookie, $template->output;
206
}
144
}
(-)a/opac/opac-sendshelf.pl (-80 / +30 lines)
Lines 17-32 Link Here
17
# You should have received a copy of the GNU General Public License
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
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;
Lines 34-39 use C4::Output; Link Here
34
use C4::Members;
30
use C4::Members;
35
use Koha::Email;
31
use Koha::Email;
36
use Koha::Virtualshelves;
32
use Koha::Virtualshelves;
33
use Koha::CsvProfiles;
37
34
38
my $query = new CGI;
35
my $query = new CGI;
39
36
Lines 54-59 my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( Link Here
54
51
55
my $shelfid = $query->param('shelfid');
52
my $shelfid = $query->param('shelfid');
56
my $email   = $query->param('email');
53
my $email   = $query->param('email');
54
my $format  = $query->param('format') || 'iso2709';
57
55
58
my $dbh          = C4::Context->dbh;
56
my $dbh          = C4::Context->dbh;
59
57
Lines 81-118 if ( $email ) { Link Here
81
79
82
    my $shelf = Koha::Virtualshelves->find( $shelfid );
80
    my $shelf = Koha::Virtualshelves->find( $shelfid );
83
    my $contents = $shelf->get_contents;
81
    my $contents = $shelf->get_contents;
84
    my $marcflavour         = C4::Context->preference('marcflavour');
85
    my $iso2709;
86
    my @results;
87
82
83
    my @biblionumbers;
88
    while ( my $content = $contents->next ) {
84
    while ( my $content = $contents->next ) {
89
        my $biblionumber = $content->biblionumber->biblionumber;
85
        my $biblionumber = $content->biblionumber->biblionumber;
90
        my $fw               = GetFrameworkCode($biblionumber);
86
        push @biblionumbers, $biblionumber;
91
        my $dat              = GetBiblioData($biblionumber);
92
        my $record           = GetMarcBiblio($biblionumber, 1);
93
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
94
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
95
        my $subtitle         = GetRecordValue('subtitle', $record, $fw);
96
97
        my @items = GetItemsInfo( $biblionumber );
98
99
        $dat->{ISBN}           = GetMarcISBN($record, $marcflavour);
100
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
101
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
102
        $dat->{'biblionumber'} = $biblionumber;
103
        $dat->{ITEM_RESULTS}   = \@items;
104
        $dat->{subtitle}       = $subtitle;
105
        $dat->{HASAUTHORS}     = $dat->{'author'} || @$marcauthorsarray;
106
107
        $iso2709 .= $record->as_usmarc();
108
109
        push( @results, $dat );
110
    }
87
    }
111
88
89
    my $csv_profile_id;
90
    if ( $format =~ m|^\d+$| ) {
91
        $csv_profile_id = $format;
92
        $format         = 'csv';
93
    }
94
    my $data = C4::Biblio::BuildBiblioDataForExport(
95
        {
96
            biblionumbers  => \@biblionumbers,
97
            format         => $format,
98
            csv_profile_id => $csv_profile_id,
99
            template       => 'opac',
100
        }
101
    );
102
    my $records_file = $data->{records_file};
103
    my $records_data = $data->{records_data};
104
112
    my $user = GetMember(borrowernumber => $borrowernumber);
105
    my $user = GetMember(borrowernumber => $borrowernumber);
113
106
114
    $template2->param(
107
    $template2->param(
115
        BIBLIO_RESULTS => \@results,
108
        BIBLIO_RESULTS => $records_data,
116
        comment        => $comment,
109
        comment        => $comment,
117
        shelfname      => $shelf->shelfname,
110
        shelfname      => $shelf->shelfname,
118
        firstname      => $user->{firstname},
111
        firstname      => $user->{firstname},
Lines 123-179 if ( $email ) { Link Here
123
    my $template_res = $template2->output();
116
    my $template_res = $template2->output();
124
    my $body;
117
    my $body;
125
118
126
    # Analysing information and getting mail properties
119
    %mail = $message->fill_body_for_sending(
127
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
120
        {
128
        $mail{subject} = $1;
121
            template => $template_res,
129
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
122
            default_filename => "list.$format",
130
    }
123
            attachment => $records_file,
131
    else { $mail{'subject'} = "no subject"; }
124
        }
132
    $mail{subject} = Encode::encode("UTF-8", $mail{subject});
125
    );
133
134
    my $email_header = "";
135
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
136
        $email_header = $1;
137
        $email_header =~ s|\n?(.*)\n?|$1|;
138
        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
139
    }
140
141
    my $email_file = "list.txt";
142
    if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
143
        $email_file = $1;
144
        $email_file =~ s|\n?(.*)\n?|$1|;
145
    }
146
147
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
148
        $body = $1;
149
        $body =~ s|\n?(.*)\n?|$1|;
150
        $body = encode_qp(Encode::encode("UTF-8", $body));
151
    }
152
153
    my $boundary = "====" . time() . "====";
154
155
    # We set and put the multipart content
156
    $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
157
158
    my $isofile = encode_base64(encode("UTF-8", $iso2709));
159
    $boundary = '--' . $boundary;
160
161
    $mail{body} = <<END_OF_BODY;
162
$boundary
163
MIME-Version: 1.0
164
Content-Type: text/plain; charset="utf-8"
165
Content-Transfer-Encoding: quoted-printable
166
167
$email_header
168
$body
169
$boundary
170
Content-Type: application/octet-stream; name="list.iso2709"
171
Content-Transfer-Encoding: base64
172
Content-Disposition: attachment; filename="list.iso2709"
173
174
$isofile
175
$boundary--
176
END_OF_BODY
177
126
178
    # Sending mail
127
    # Sending mail
179
    if ( sendmail %mail ) {
128
    if ( sendmail %mail ) {
Lines 196-201 END_OF_BODY Link Here
196
}else{
145
}else{
197
    $template->param( shelfid => $shelfid,
146
    $template->param( shelfid => $shelfid,
198
                      url     => "/cgi-bin/koha/opac-sendshelf.pl",
147
                      url     => "/cgi-bin/koha/opac-sendshelf.pl",
148
                      csv_profiles   => [ Koha::CsvProfiles->search({ type => 'marc' }) ],
199
                    );
149
                    );
200
    output_html_with_http_headers $query, $cookie, $template->output;
150
    output_html_with_http_headers $query, $cookie, $template->output;
201
}
151
}
(-)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 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
23
use Encode qw(encode);
24
23
25
use C4::Auth;
24
use C4::Auth;
26
use C4::Biblio;
25
use C4::Biblio;
(-)a/virtualshelves/sendshelf.pl (-80 / +29 lines)
Lines 17-38 Link Here
17
# You should have received a copy of the GNU General Public License
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
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 Koha::Email;
30
use Koha::Email;
35
use Koha::Virtualshelves;
31
use Koha::Virtualshelves;
32
use Koha::CsvProfiles;
36
33
37
my $query = new CGI;
34
my $query = new CGI;
38
35
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-164 if ($email) { Link Here
72
70
73
    my $shelf = Koha::Virtualshelves->find( $shelfid );
71
    my $shelf = Koha::Virtualshelves->find( $shelfid );
74
    my $contents = $shelf->get_contents;
72
    my $contents = $shelf->get_contents;
75
    my $marcflavour = C4::Context->preference('marcflavour');
76
    my $iso2709;
77
    my @results;
78
73
74
    my @biblionumbers;
79
    while ( my $content = $contents->next ) {
75
    while ( my $content = $contents->next ) {
80
        my $biblionumber     = $content->biblionumber->biblionumber;
76
        my $biblionumber     = $content->biblionumber->biblionumber;
81
        my $fw               = GetFrameworkCode($biblionumber);
77
        push @biblionumbers, $biblionumber;
82
        my $dat              = GetBiblioData($biblionumber);
83
        my $record           = GetMarcBiblio($biblionumber, 1);
84
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
85
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
86
        my $subtitle         = GetRecordValue( 'subtitle', $record, $fw );
87
88
        my @items = GetItemsInfo($biblionumber);
89
90
        $dat->{ISBN}           = GetMarcISBN($record, $marcflavour);
91
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
92
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
93
        $dat->{'biblionumber'} = $biblionumber;
94
        $dat->{ITEM_RESULTS}   = \@items;
95
        $dat->{subtitle}       = $subtitle;
96
        $dat->{HASAUTHORS}     = $dat->{'author'} || @$marcauthorsarray;
97
98
        $iso2709 .= $record->as_usmarc();
99
100
        push( @results, $dat );
101
    }
78
    }
102
79
80
    my $csv_profile_id;
81
    if ( $format =~ m|^\d+$| ) {
82
        $csv_profile_id = $format;
83
        $format         = 'csv';
84
    }
85
    my $data = C4::Biblio::BuildBiblioDataForExport(
86
        {
87
            biblionumbers  => \@biblionumbers,
88
            format         => $format,
89
            csv_profile_id => $csv_profile_id
90
        }
91
    );
92
    my $records_file = $data->{records_file};
93
    my $records_data = $data->{records_data};
94
103
    $template2->param(
95
    $template2->param(
104
        BIBLIO_RESULTS => \@results,
96
        BIBLIO_RESULTS => $records_data,
105
        comment        => $comment,
97
        comment        => $comment,
106
        shelfname      => $shelf->shelfname,
98
        shelfname      => $shelf->shelfname,
107
    );
99
    );
108
100
109
    # Getting template result
101
    # Getting template result
110
    my $template_res = $template2->output();
102
    my $template_res = $template2->output();
111
    my $body;
112
113
    # Analysing information and getting mail properties
114
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
115
        $mail{'subject'} = Encode::encode("UTF-8", $1);
116
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
117
    }
118
    else { $mail{'subject'} = "no subject"; }
119
120
    my $email_header = "";
121
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
122
        $email_header = $1;
123
        $email_header =~ s|\n?(.*)\n?|$1|;
124
        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
125
    }
126
127
    my $email_file = "list.txt";
128
    if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
129
        $email_file = $1;
130
        $email_file =~ s|\n?(.*)\n?|$1|;
131
    }
132
103
133
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
104
    %mail = $message->fill_body_for_sending(
134
        $body = $1;
105
        {
135
        $body =~ s|\n?(.*)\n?|$1|;
106
            template => $template_res,
136
        $body = encode_qp(Encode::encode("UTF-8", $body));
107
            default_filename => "list.$format",
137
    }
108
            attachment => $records_file,
138
109
        }
139
    my $boundary = "====" . time() . "====";
110
    );
140
141
    # We set and put the multipart content
142
    $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
143
144
    my $isofile = encode_base64( encode( "UTF-8", $iso2709 ) );
145
    $boundary = '--' . $boundary;
146
147
    $mail{body} = <<END_OF_BODY;
148
$boundary
149
Content-Type: text/plain; charset="utf-8"
150
Content-Transfer-Encoding: quoted-printable
151
152
$email_header
153
$body
154
$boundary
155
Content-Type: application/octet-stream; name="shelf.iso2709"
156
Content-Transfer-Encoding: base64
157
Content-Disposition: attachment; filename="shelf.iso2709"
158
159
$isofile
160
$boundary--
161
END_OF_BODY
162
111
163
    # Sending mail
112
    # Sending mail
164
    if ( sendmail %mail ) {
113
    if ( sendmail %mail ) {
Lines 180-185 else { Link Here
180
    $template->param(
129
    $template->param(
181
        shelfid => $shelfid,
130
        shelfid => $shelfid,
182
        url     => "/cgi-bin/koha/virtualshelves/sendshelf.pl",
131
        url     => "/cgi-bin/koha/virtualshelves/sendshelf.pl",
132
        csv_profiles   => [ Koha::CsvProfiles->search({ type => 'marc' }) ],
183
    );
133
    );
184
    output_html_with_http_headers $query, $cookie, $template->output;
134
    output_html_with_http_headers $query, $cookie, $template->output;
185
}
135
}
186
- 

Return to bug 13345