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

(-)a/C4/Biblio.pm (+66 lines)
Lines 37-42 use C4::ClassSource; Link Here
37
use C4::Charset;
37
use C4::Charset;
38
use C4::Linker;
38
use C4::Linker;
39
use C4::OAI::Sets;
39
use C4::OAI::Sets;
40
use C4::Ris;
40
41
41
use Koha::Cache;
42
use Koha::Cache;
42
use Koha::Authority::Types;
43
use Koha::Authority::Types;
Lines 3808-3813 sub RemoveAllNsb { Link Here
3808
    return $record;
3809
    return $record;
3809
}
3810
}
3810
3811
3812
sub BuildBiblioDataForExport {
3813
    my ( $params ) = @_;
3814
    my $biblionumbers = $params->{biblionumbers};
3815
    my $format = $params->{format};
3816
    my $template = $params->{template}; # Only used for ISBD
3817
    my ( @records_data, $records_file );
3818
3819
    # CSV
3820
    if ($format eq 'csv' ) {
3821
3822
        # FIXME should be used at the beginning of this module
3823
        # But compilation explodes...
3824
        require C4::Record;
3825
        $records_file = C4::Record::marc2csv($biblionumbers, $params->{csv_profile_id});
3826
3827
    # Other formats
3828
    } else {
3829
        # retrieve biblios from shelf
3830
        my $marcflavour = C4::Context->preference('marcflavour');
3831
        foreach my $biblionumber (@$biblionumbers) {
3832
            my $dat              = GetBiblioData($biblionumber);
3833
            next unless $dat;
3834
            my $record           = GetMarcBiblio($biblionumber, 1);
3835
            my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
3836
            my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
3837
            my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
3838
            my $fw               = GetFrameworkCode($biblionumber);
3839
            my $subtitle         = GetRecordValue( 'subtitle', $record, $fw );
3840
3841
            my @items = C4::Items::GetItemsInfo( $biblionumber );
3842
3843
            my $hasauthors = 0;
3844
            if($dat->{'author'} || @$marcauthorsarray) {
3845
              $hasauthors = 1;
3846
            }
3847
3848
            $dat->{MARCNOTES}      = $marcnotesarray;
3849
            $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
3850
            $dat->{MARCAUTHORS}    = $marcauthorsarray;
3851
            $dat->{HASAUTHORS}     = $hasauthors;
3852
            $dat->{biblionumber}   = $biblionumber;
3853
            $dat->{ITEM_RESULTS}   = \@items;
3854
            $dat->{subtitle}       = $subtitle;
3855
3856
            if ($format eq 'iso2709') {
3857
                $records_file .= $record->as_usmarc();
3858
            }
3859
            elsif ($format eq 'ris') {
3860
                $records_file .= C4::Ris::marc2ris($record);
3861
            }
3862
            elsif ($format eq 'bibtex') {
3863
                $records_file .= C4::Record::marc2bibtex($record, $biblionumber);
3864
            }
3865
            elsif ( $format eq 'isbd' ) {
3866
                # Only called from the OPAC at the moment
3867
                $records_file   .= C4::Biblio::GetISBDView($biblionumber, $template);
3868
            }
3869
3870
            push( @records_data, $dat );
3871
        }
3872
    }
3873
3874
    return { records_file => $records_file, records_data => \@records_data };
3875
}
3876
3811
1;
3877
1;
3812
3878
3813
3879
(-)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
# 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
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
# 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
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 46-51 my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( Link Here
46
43
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');
46
my $format       = $query->param('format') || 'iso2709';
49
47
50
my $dbh          = C4::Context->dbh;
48
my $dbh          = C4::Context->dbh;
51
49
Lines 63-160 if ( $email_add ) { Link Here
63
        }
61
        }
64
    );
62
    );
65
63
66
    my @bibs = split( /\//, $bib_list );
64
    my $csv_profile_id;
67
    my @results;
65
    if ( $format =~ m|^\d+$| ) {
68
    my $iso2709;
66
        $csv_profile_id = $format;
69
    my $marcflavour = C4::Context->preference('marcflavour');
67
        $format         = 'csv';
70
    foreach my $biblionumber (@bibs) {
71
        $template2->param( biblionumber => $biblionumber );
72
73
        my $dat              = GetBiblioData($biblionumber);
74
        next unless $dat;
75
        my $record           = GetMarcBiblio($biblionumber, 1);
76
        my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
77
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
78
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
79
80
        my @items = GetItemsInfo( $biblionumber );
81
82
        my $hasauthors = 0;
83
        if($dat->{'author'} || @$marcauthorsarray) {
84
          $hasauthors = 1;
85
        }
86
	
87
88
        $dat->{MARCNOTES}      = $marcnotesarray;
89
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
90
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
91
        $dat->{HASAUTHORS}     = $hasauthors;
92
        $dat->{'biblionumber'} = $biblionumber;
93
        $dat->{ITEM_RESULTS}   = \@items;
94
95
        $iso2709 .= $record->as_usmarc();
96
97
        push( @results, $dat );
98
    }
68
    }
69
    my @biblionumbers = split( /\//, $bib_list );
70
    my $data = C4::Biblio::BuildBiblioDataForExport(
71
        {
72
            biblionumbers  => \@biblionumbers,
73
            format         => $format,
74
            csv_profile_id => $csv_profile_id
75
        }
76
    );
77
    my $records_file = $data->{records_file};
78
    my $records_data = $data->{records_data};
99
79
100
    my $resultsarray = \@results;
101
    $template2->param(
80
    $template2->param(
102
        BIBLIO_RESULTS => $resultsarray,
81
        BIBLIO_RESULTS => $records_data,
103
        comment        => $comment
82
        comment        => $comment
104
    );
83
    );
105
84
106
    # Getting template result
85
    # Getting template result
107
    my $template_res = $template2->output();
86
    my $template_res = $template2->output();
108
    my $body;
109
110
    # Analysing information and getting mail properties
111
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
112
        $mail{subject} = $1;
113
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
114
        $mail{subject} = Encode::encode("UTF-8", $mail{subject});
115
    }
116
    else { $mail{'subject'} = "no subject"; }
117
87
118
    my $email_header = "";
88
    %mail = $email->fill_body_for_sending(
119
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
89
        {
120
        $email_header = $1;
90
            template => $template_res,
121
        $email_header =~ s|\n?(.*)\n?|$1|;
91
            default_filename => "basket.$format",
122
        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
92
            attachment => $records_file,
123
    }
93
        }
124
94
    );
125
    my $email_file = "basket.txt";
126
    if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
127
        $email_file = $1;
128
        $email_file =~ s|\n?(.*)\n?|$1|;
129
    }
130
131
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
132
        $body = $1;
133
        $body =~ s|\n?(.*)\n?|$1|;
134
        $body = encode_qp(Encode::encode("UTF-8", $body));
135
    }
136
137
    my $boundary = "====" . time() . "====";
138
139
    # Writing mail
140
    $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
141
    my $isofile = encode_base64(encode("UTF-8", $iso2709));
142
    $boundary = '--' . $boundary;
143
    $mail{body} = <<END_OF_BODY;
144
$boundary
145
Content-Type: text/plain; charset="utf-8"
146
Content-Transfer-Encoding: quoted-printable
147
148
$email_header
149
$body
150
$boundary
151
Content-Type: application/octet-stream; name="basket.iso2709"
152
Content-Transfer-Encoding: base64
153
Content-Disposition: attachment; filename="basket.iso2709"
154
155
$isofile
156
$boundary--
157
END_OF_BODY
158
95
159
    # Sending mail
96
    # Sending mail
160
    if ( sendmail %mail ) {
97
    if ( sendmail %mail ) {
Lines 175-180 else { Link Here
175
        url            => "/cgi-bin/koha/basket/sendbasket.pl",
112
        url            => "/cgi-bin/koha/basket/sendbasket.pl",
176
        suggestion     => C4::Context->preference("suggestion"),
113
        suggestion     => C4::Context->preference("suggestion"),
177
        virtualshelves => C4::Context->preference("virtualshelves"),
114
        virtualshelves => C4::Context->preference("virtualshelves"),
115
        csv_profiles => GetCsvProfilesLoop('marc'),
178
    );
116
    );
179
    output_html_with_http_headers $query, $cookie, $template->output;
117
    output_html_with_http_headers $query, $cookie, $template->output;
180
}
118
}
(-)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 30-36 Your cart Link Here
30
        <li>
30
        <li>
31
            <span>
31
            <span>
32
                [% BIBLIO_RESULT.title %]
32
                [% BIBLIO_RESULT.title %]
33
                [% IF ( BIBLIO_RESULT.subtitle ) %] [% BIBLIO_RESULT.subtitle %][% END %]
33
                [% IF ( BIBLIO_RESULT.subtitle.size ) %]
34
                  [% FOREACH subtitle IN BIBLIO_RESULT.subtitle %]
35
                    [% subtitle.subfield %]
36
                  [% END %]
37
                [% END %]
34
            </span>
38
            </span>
35
39
36
            <p>
40
            <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="/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
    <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 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 %]</i></h1>
50
                                <h1>Download list <i>[% shelf.shelfname %]</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 30-36 Your cart Link Here
30
        <li>
30
        <li>
31
            <span>
31
            <span>
32
                [% BIBLIO_RESULT.title %]
32
                [% BIBLIO_RESULT.title %]
33
                [% IF ( BIBLIO_RESULT.subtitle ) %] [% BIBLIO_RESULT.subtitle %][% END %]
33
                [% IF ( BIBLIO_RESULT.subtitle.size ) %]
34
                  [% FOREACH subtitle IN BIBLIO_RESULT.subtitle %]
35
                    [% subtitle.subfield %]
36
                  [% END %]
37
                [% END %]
34
            </span>
38
            </span>
35
39
36
            <p>
40
            <p>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasketform.tt (+2 lines)
Lines 34-39 Link Here
34
                                    <label for="comment">Comment:</label>
34
                                    <label for="comment">Comment:</label>
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
                                    <label for="format">Format:</label>
38
                                    [% INCLUDE 'download-export-available-formats.inc' %]
37
                                </fieldset>
39
                                </fieldset>
38
                                <fieldset class="action">
40
                                <fieldset class="action">
39
                                    <input type="submit" class="btn" value="Send" />
41
                                    <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 21-27 use strict; Link Here
21
use warnings;
21
use warnings;
22
22
23
use CGI qw ( -utf8 );
23
use CGI qw ( -utf8 );
24
use Encode qw(encode);
25
24
26
use C4::Auth;
25
use C4::Auth;
27
use C4::Biblio;
26
use C4::Biblio;
Lines 55-66 if ($bib_list && $format) { Link Here
55
    my $extension;
54
    my $extension;
56
    my $type;
55
    my $type;
57
56
58
    # CSV   
57
    # CSV
59
    if ($format =~ /^\d+$/) {
58
    if ($format =~ /^\d+$/) {
60
59
61
        $output = marc2csv(\@bibs, $format);
60
        $output = marc2csv(\@bibs, $format);
61
        $format = 'csv';
62
62
63
        # Other formats
63
    # Other formats
64
    } else {
64
    } else {
65
        foreach my $biblio (@bibs) {
65
        foreach my $biblio (@bibs) {
66
66
Lines 84-92 if ($bib_list && $format) { Link Here
84
        }
84
        }
85
    }
85
    }
86
86
87
    # If it was a CSV export we change the format after the export so the file extension is fine
88
    $format = "csv" if ($format =~ m/^\d+$/);
89
90
    print $query->header(
87
    print $query->header(
91
                               -type => ($type) ? $type : 'application/octet-stream',
88
                               -type => ($type) ? $type : 'application/octet-stream',
92
        -'Content-Transfer-Encoding' => 'binary',
89
        -'Content-Transfer-Encoding' => 'binary',
(-)a/opac/opac-downloadshelf.pl (-4 / +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 69-74 if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { Link Here
69
                push @biblios, $content->biblionumber->biblionumber;
68
                push @biblios, $content->biblionumber->biblionumber;
70
            }
69
            }
71
            $output = marc2csv(\@biblios, $format);
70
            $output = marc2csv(\@biblios, $format);
71
72
            $format = 'csv';
73
72
        # Other formats
74
        # Other formats
73
        } else {
75
        } else {
74
            while ( my $content = $contents->next ) {
76
            while ( my $content = $contents->next ) {
Lines 94-102 if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { Link Here
94
            }
96
            }
95
        }
97
        }
96
98
97
        # If it was a CSV export we change the format after the export so the file extension is fine
98
        $format = "csv" if ($format =~ m/^\d+$/);
99
100
        print $query->header(
99
        print $query->header(
101
                                   -type => ($type) ? $type : 'application/octet-stream',
100
                                   -type => ($type) ? $type : 'application/octet-stream',
102
            -'Content-Transfer-Encoding' => 'binary',
101
            -'Content-Transfer-Encoding' => 'binary',
(-)a/opac/opac-sendbasket.pl (-94 / +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::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 48-53 my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( Link Here
48
45
49
my $bib_list     = $query->param('bib_list');
46
my $bib_list     = $query->param('bib_list');
50
my $email_add    = $query->param('email_add');
47
my $email_add    = $query->param('email_add');
48
my $format       = $query->param('format') || 'iso2709';
51
49
52
my $dbh          = C4::Context->dbh;
50
my $dbh          = C4::Context->dbh;
53
51
Lines 76-119 if ( $email_add ) { Link Here
76
        }
74
        }
77
    );
75
    );
78
76
79
    my @bibs = split( /\//, $bib_list );
77
    my $csv_profile_id;
80
    my @results;
78
    if ( $format =~ m|^\d+$| ) {
81
    my $iso2709;
79
        $csv_profile_id = $format;
82
    my $marcflavour = C4::Context->preference('marcflavour');
80
        $format         = 'csv';
83
    foreach my $biblionumber (@bibs) {
84
        $template2->param( biblionumber => $biblionumber );
85
86
        my $dat              = GetBiblioData($biblionumber);
87
        next unless $dat;
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
93
        my @items = GetItemsInfo( $biblionumber );
94
95
        my $hasauthors = 0;
96
        if($dat->{'author'} || @$marcauthorsarray) {
97
          $hasauthors = 1;
98
        }
99
	
100
101
        $dat->{MARCNOTES}      = $marcnotesarray;
102
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
103
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
104
        $dat->{HASAUTHORS}     = $hasauthors;
105
        $dat->{'biblionumber'} = $biblionumber;
106
        $dat->{ITEM_RESULTS}   = \@items;
107
108
        $iso2709 .= $record->as_usmarc();
109
110
        push( @results, $dat );
111
    }
81
    }
82
    my @biblionumbers = split( /\//, $bib_list );
83
    my $data = C4::Biblio::BuildBiblioDataForExport(
84
        {
85
            biblionumbers  => \@biblionumbers,
86
            format         => $format,
87
            csv_profile_id => $csv_profile_id,
88
            template       => 'opac',
89
        }
90
    );
91
    my $records_file = $data->{records_file};
92
    my $records_data = $data->{records_data};
112
93
113
    my $resultsarray = \@results;
114
    
115
    $template2->param(
94
    $template2->param(
116
        BIBLIO_RESULTS => $resultsarray,
95
        BIBLIO_RESULTS => $records_data,
117
        comment        => $comment,
96
        comment        => $comment,
118
        firstname      => $user->{firstname},
97
        firstname      => $user->{firstname},
119
        surname        => $user->{surname},
98
        surname        => $user->{surname},
Lines 121-188 if ( $email_add ) { Link Here
121
100
122
    # Getting template result
101
    # Getting template result
123
    my $template_res = $template2->output();
102
    my $template_res = $template2->output();
124
    my $body;
125
126
    # Analysing information and getting mail properties
127
128
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
129
        $mail{subject} = $1;
130
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
131
        $mail{subject} = Encode::encode("UTF-8", $mail{subject});
132
    }
133
    else { $mail{'subject'} = "no subject"; }
134
135
    my $email_header = "";
136
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
137
        $email_header = $1;
138
        $email_header =~ s|\n?(.*)\n?|$1|;
139
        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
140
    }
141
103
142
    my $email_file = "basket.txt";
104
    %mail = $email->fill_body_for_sending(
143
    if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
105
        {
144
        $email_file = $1;
106
            template => $template_res,
145
        $email_file =~ s|\n?(.*)\n?|$1|;
107
            default_filename => "basket.$format",
146
    }
108
            attachment => $records_file,
147
109
        }
148
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
110
    );
149
        $body = $1;
150
        $body =~ s|\n?(.*)\n?|$1|;
151
        $body = encode_qp(Encode::encode("UTF-8", $body));
152
    }
153
154
    $mail{body} = $body;
155
156
    my $boundary = "====" . time() . "====";
157
158
    $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
159
    my $isofile = encode_base64(encode("UTF-8", $iso2709));
160
    $boundary = '--' . $boundary;
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="basket.iso2709"
171
Content-Transfer-Encoding: base64
172
Content-Disposition: attachment; filename="basket.iso2709"
173
174
$isofile
175
$boundary--
176
END_OF_BODY
177
111
178
    # Sending mail (if not empty basket)
112
    # Sending mail (if not empty basket)
179
    if ( defined($iso2709) && sendmail %mail ) {
113
    if ( defined($records_file) && sendmail %mail ) {
180
    # do something if it works....
114
    # do something if it works....
181
        $template->param( SENT      => "1" );
115
        $template->param( SENT      => "1" );
182
    }
116
    }
183
    else {
117
    else {
184
        # do something if it doesnt work....
118
        # do something if it doesnt work....
185
    carp "Error sending mail: empty basket" if !defined($iso2709);
119
    carp "Error sending mail: empty basket" unless defined($records_file);
186
        carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error;
120
        carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error;
187
        $template->param( error => 1 );
121
        $template->param( error => 1 );
188
    }
122
    }
Lines 195-200 else { Link Here
195
        url            => "/cgi-bin/koha/opac-sendbasket.pl",
129
        url            => "/cgi-bin/koha/opac-sendbasket.pl",
196
        suggestion     => C4::Context->preference("suggestion"),
130
        suggestion     => C4::Context->preference("suggestion"),
197
        virtualshelves => C4::Context->preference("virtualshelves"),
131
        virtualshelves => C4::Context->preference("virtualshelves"),
132
        csv_profiles   => GetCsvProfilesLoop('marc'),
198
    );
133
    );
199
    output_html_with_http_headers $query, $cookie, $template->output;
134
    output_html_with_http_headers $query, $cookie, $template->output;
200
}
135
}
(-)a/opac/opac-sendshelf.pl (-87 / +30 lines)
Lines 17-37 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 C4::Members;
30
use C4::Members;
31
use C4::Csv qw( GetCsvProfilesLoop );
35
use Koha::Email;
32
use Koha::Email;
36
use Koha::Virtualshelves;
33
use Koha::Virtualshelves;
37
34
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 73-114 if ( $email ) { Link Here
73
        }
71
        }
74
    );
72
    );
75
73
76
    my $shelf = Koha::Virtualshelves->find( $shelfid );
74
    my @shelf               = GetShelf($shelfid);
77
    my $contents = $shelf->get_contents;
75
    my ($items, $totitems)  = GetShelfContents($shelfid);
78
    my $marcflavour         = C4::Context->preference('marcflavour');
76
79
    my $iso2709;
77
    my $csv_profile_id;
80
    my @results;
78
    if ( $format =~ m|^\d+$| ) {
81
79
        $csv_profile_id = $format;
82
    while ( my $content = $contents->next ) {
80
        $format         = 'csv';
83
        my $biblionumber = $content->biblionumber->biblionumber;
84
        my $fw               = GetFrameworkCode($biblionumber);
85
        my $dat              = GetBiblioData($biblionumber);
86
        my $record           = GetMarcBiblio($biblionumber, 1);
87
        my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
88
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
89
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
90
        my $subtitle         = GetRecordValue('subtitle', $record, $fw);
91
92
        my @items = GetItemsInfo( $biblionumber );
93
94
        $dat->{ISBN}           = GetMarcISBN($record, $marcflavour);
95
        $dat->{MARCNOTES}      = $marcnotesarray;
96
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
97
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
98
        $dat->{'biblionumber'} = $biblionumber;
99
        $dat->{ITEM_RESULTS}   = \@items;
100
        $dat->{subtitle}       = $subtitle;
101
        $dat->{HASAUTHORS}     = $dat->{'author'} || @$marcauthorsarray;
102
103
        $iso2709 .= $record->as_usmarc();
104
105
        push( @results, $dat );
106
    }
81
    }
82
    my @biblionumbers = map { $_->{biblionumber} } @$items;
83
    my $data = C4::Biblio::BuildBiblioDataForExport(
84
        {
85
            biblionumbers  => \@biblionumbers,
86
            format         => $format,
87
            csv_profile_id => $csv_profile_id,
88
            template       => 'opac',
89
        }
90
    );
91
    my $records_file = $data->{records_file};
92
    my $records_data = $data->{records_data};
107
93
108
    my $user = GetMember(borrowernumber => $borrowernumber);
94
    my $user = GetMember(borrowernumber => $borrowernumber);
109
95
110
    $template2->param(
96
    $template2->param(
111
        BIBLIO_RESULTS => \@results,
97
        BIBLIO_RESULTS => $records_data,
112
        comment        => $comment,
98
        comment        => $comment,
113
        shelfname      => $shelf->shelfname,
99
        shelfname      => $shelf->shelfname,
114
        firstname      => $user->{firstname},
100
        firstname      => $user->{firstname},
Lines 119-175 if ( $email ) { Link Here
119
    my $template_res = $template2->output();
105
    my $template_res = $template2->output();
120
    my $body;
106
    my $body;
121
107
122
    # Analysing information and getting mail properties
108
    %mail = $message->fill_body_for_sending(
123
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
109
        {
124
        $mail{subject} = $1;
110
            template => $template_res,
125
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
111
            default_filename => "list.$format",
126
    }
112
            attachment => $records_file,
127
    else { $mail{'subject'} = "no subject"; }
113
        }
128
    $mail{subject} = Encode::encode("UTF-8", $mail{subject});
114
    );
129
130
    my $email_header = "";
131
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
132
        $email_header = $1;
133
        $email_header =~ s|\n?(.*)\n?|$1|;
134
        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
135
    }
136
137
    my $email_file = "list.txt";
138
    if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
139
        $email_file = $1;
140
        $email_file =~ s|\n?(.*)\n?|$1|;
141
    }
142
143
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
144
        $body = $1;
145
        $body =~ s|\n?(.*)\n?|$1|;
146
        $body = encode_qp(Encode::encode("UTF-8", $body));
147
    }
148
149
    my $boundary = "====" . time() . "====";
150
151
    # We set and put the multipart content
152
    $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
153
154
    my $isofile = encode_base64(encode("UTF-8", $iso2709));
155
    $boundary = '--' . $boundary;
156
157
    $mail{body} = <<END_OF_BODY;
158
$boundary
159
MIME-Version: 1.0
160
Content-Type: text/plain; charset="utf-8"
161
Content-Transfer-Encoding: quoted-printable
162
163
$email_header
164
$body
165
$boundary
166
Content-Type: application/octet-stream; name="list.iso2709"
167
Content-Transfer-Encoding: base64
168
Content-Disposition: attachment; filename="list.iso2709"
169
170
$isofile
171
$boundary--
172
END_OF_BODY
173
115
174
    # Sending mail
116
    # Sending mail
175
    if ( sendmail %mail ) {
117
    if ( sendmail %mail ) {
Lines 192-197 END_OF_BODY Link Here
192
}else{
134
}else{
193
    $template->param( shelfid => $shelfid,
135
    $template->param( shelfid => $shelfid,
194
                      url     => "/cgi-bin/koha/opac-sendshelf.pl",
136
                      url     => "/cgi-bin/koha/opac-sendshelf.pl",
137
                      csv_profiles   => GetCsvProfilesLoop('marc'),
195
                    );
138
                    );
196
    output_html_with_http_headers $query, $cookie, $template->output;
139
    output_html_with_http_headers $query, $cookie, $template->output;
197
}
140
}
(-)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 (-87 / +29 lines)
Lines 17-36 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;
30
use C4::Csv qw( GetCsvProfilesLoop );
34
use Koha::Email;
31
use Koha::Email;
35
use Koha::Virtualshelves;
32
use Koha::Virtualshelves;
36
33
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 70-166 if ($email) { Link Here
70
        }
68
        }
71
    );
69
    );
72
70
73
    my $shelf = Koha::Virtualshelves->find( $shelfid );
71
    my @shelf = GetShelf($shelfid);
74
    my $contents = $shelf->get_contents;
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
    while ( my $content = $contents->next ) {
77
        $format         = 'csv';
80
        my $biblionumber     = $content->biblionumber->biblionumber;
81
        my $fw               = GetFrameworkCode($biblionumber);
82
        my $dat              = GetBiblioData($biblionumber);
83
        my $record           = GetMarcBiblio($biblionumber, 1);
84
        my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
85
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
86
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
87
        my $subtitle         = GetRecordValue( 'subtitle', $record, $fw );
88
89
        my @items = GetItemsInfo($biblionumber);
90
91
        $dat->{ISBN}           = GetMarcISBN($record, $marcflavour);
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
        $dat->{HASAUTHORS}     = $dat->{'author'} || @$marcauthorsarray;
99
100
        $iso2709 .= $record->as_usmarc();
101
102
        push( @results, $dat );
103
    }
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};
104
89
105
    $template2->param(
90
    $template2->param(
106
        BIBLIO_RESULTS => \@results,
91
        BIBLIO_RESULTS => $records_data,
107
        comment        => $comment,
92
        comment        => $comment,
108
        shelfname      => $shelf->shelfname,
93
        shelfname      => $shelf->shelfname,
109
    );
94
    );
110
95
111
    # Getting template result
96
    # Getting template result
112
    my $template_res = $template2->output();
97
    my $template_res = $template2->output();
113
    my $body;
114
115
    # Analysing information and getting mail properties
116
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
117
        $mail{'subject'} = Encode::encode("UTF-8", $1);
118
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
119
    }
120
    else { $mail{'subject'} = "no subject"; }
121
122
    my $email_header = "";
123
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
124
        $email_header = $1;
125
        $email_header =~ s|\n?(.*)\n?|$1|;
126
        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
127
    }
128
129
    my $email_file = "list.txt";
130
    if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
131
        $email_file = $1;
132
        $email_file =~ s|\n?(.*)\n?|$1|;
133
    }
134
98
135
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
99
    %mail = $message->fill_body_for_sending(
136
        $body = $1;
100
        {
137
        $body =~ s|\n?(.*)\n?|$1|;
101
            template => $template_res,
138
        $body = encode_qp(Encode::encode("UTF-8", $body));
102
            default_filename => "list.$format",
139
    }
103
            attachment => $records_file,
140
104
        }
141
    my $boundary = "====" . time() . "====";
105
    );
142
143
    # We set and put the multipart content
144
    $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
145
146
    my $isofile = encode_base64( encode( "UTF-8", $iso2709 ) );
147
    $boundary = '--' . $boundary;
148
149
    $mail{body} = <<END_OF_BODY;
150
$boundary
151
Content-Type: text/plain; charset="utf-8"
152
Content-Transfer-Encoding: quoted-printable
153
154
$email_header
155
$body
156
$boundary
157
Content-Type: application/octet-stream; name="shelf.iso2709"
158
Content-Transfer-Encoding: base64
159
Content-Disposition: attachment; filename="shelf.iso2709"
160
161
$isofile
162
$boundary--
163
END_OF_BODY
164
106
165
    # Sending mail
107
    # Sending mail
166
    if ( sendmail %mail ) {
108
    if ( sendmail %mail ) {
Lines 182-187 else { Link Here
182
    $template->param(
124
    $template->param(
183
        shelfid => $shelfid,
125
        shelfid => $shelfid,
184
        url     => "/cgi-bin/koha/virtualshelves/sendshelf.pl",
126
        url     => "/cgi-bin/koha/virtualshelves/sendshelf.pl",
127
        csv_profiles   => GetCsvProfilesLoop('marc'),
185
    );
128
    );
186
    output_html_with_http_headers $query, $cookie, $template->output;
129
    output_html_with_http_headers $query, $cookie, $template->output;
187
}
130
}
188
- 

Return to bug 13345