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

(-)a/basket/sendbasket.pl (-37 / +41 lines)
Lines 23-29 use Carp qw( carp ); Link Here
23
use Try::Tiny qw( catch try );
23
use Try::Tiny qw( catch try );
24
24
25
use C4::Biblio qw(
25
use C4::Biblio qw(
26
    GetMarcSubjects
26
  GetMarcSubjects
27
);
27
);
28
use C4::Auth qw( get_template_and_user );
28
use C4::Auth qw( get_template_and_user );
29
use C4::Output qw( output_and_exit output_html_with_http_headers );
29
use C4::Output qw( output_and_exit output_html_with_http_headers );
Lines 34-45 use Koha::Token; Link Here
34
34
35
my $query = CGI->new;
35
my $query = CGI->new;
36
36
37
my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
37
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
38
    {
38
    {
39
        template_name   => "basket/sendbasketform.tt",
39
        template_name => "basket/sendbasketform.tt",
40
        query           => $query,
40
        query         => $query,
41
        type            => "intranet",
41
        type          => "intranet",
42
        flagsrequired   => { catalogue => 1 },
42
        flagsrequired => { catalogue => 1 },
43
    }
43
    }
44
);
44
);
45
45
Lines 48-61 my $email_add = $query->param('email_add'); Link Here
48
48
49
my $dbh = C4::Context->dbh;
49
my $dbh = C4::Context->dbh;
50
50
51
if ( $email_add ) {
51
if ($email_add) {
52
    output_and_exit( $query, $cookie, $template, 'wrong_csrf_token' )
52
    output_and_exit( $query, $cookie, $template, 'wrong_csrf_token' )
53
        unless Koha::Token->new->check_csrf({
53
      unless Koha::Token->new->check_csrf(
54
        {
54
            session_id => scalar $query->cookie('CGISESSID'),
55
            session_id => scalar $query->cookie('CGISESSID'),
55
            token  => scalar $query->param('csrf_token'),
56
            token      => scalar $query->param('csrf_token'),
56
        });
57
        }
58
      );
57
59
58
    my $patron = Koha::Patrons->find( $borrowernumber );
60
    my $patron     = Koha::Patrons->find($borrowernumber);
59
    my $user_email = $patron->first_valid_email_address;
61
    my $user_email = $patron->first_valid_email_address;
60
62
61
    my $comment = $query->param('comment');
63
    my $comment = $query->param('comment');
Lines 63-115 if ( $email_add ) { Link Here
63
    my @bibs = split( /\//, $bib_list );
65
    my @bibs = split( /\//, $bib_list );
64
    my $iso2709;
66
    my $iso2709;
65
67
66
    foreach my $bib ( @bibs ) {
68
    foreach my $bib (@bibs) {
67
        my $biblio = Koha::Biblios->find( $bib ) or next;
69
        my $biblio = Koha::Biblios->find($bib) or next;
68
        $iso2709 .= $biblio->metadata->record->as_usmarc();
70
        $iso2709 .= $biblio->metadata->record->as_usmarc();
69
    }
71
    }
70
72
71
    if ( !defined $iso2709 ) {
73
    if ( !defined $iso2709 ) {
72
        carp "Error sending mail: empty basket";
74
        carp "Error sending mail: empty basket";
73
        $template->param( error => 1 );
75
        $template->param( error => 1 );
74
    } elsif ( !defined $user_email or $user_email eq '' ) {
76
    }
77
    elsif ( !defined $user_email or $user_email eq '' ) {
75
        carp "Error sending mail: sender's email address is invalid";
78
        carp "Error sending mail: sender's email address is invalid";
76
        $template->param( error => 1 );
79
        $template->param( error => 1 );
77
    } else {
80
    }
78
        my %loops = (
81
    else {
79
            biblio => \@bibs,
82
        my %loops = ( biblio => \@bibs, );
80
        );
81
83
82
        my %substitute = (
84
        my %substitute = ( comment => $comment, );
83
            comment => $comment,
84
        );
85
85
86
        my $letter = C4::Letters::GetPreparedLetter(
86
        my $letter = C4::Letters::GetPreparedLetter(
87
            module => 'catalogue',
87
            module      => 'catalogue',
88
            letter_code => 'CART',
88
            letter_code => 'CART',
89
            lang => $patron->lang,
89
            lang        => $patron->lang,
90
            tables => {
90
            tables      => {
91
                borrowers => $borrowernumber,
91
                borrowers => $borrowernumber,
92
            },
92
            },
93
            message_transport_type => 'email',
93
            message_transport_type => 'email',
94
            loops => \%loops,
94
            loops                  => \%loops,
95
            substitute => \%substitute,
95
            substitute             => \%substitute,
96
        );
96
        );
97
97
98
        my $attachment = {
98
        my $attachment = {
99
            filename => 'basket.iso2709',
99
            filename => 'basket.iso2709',
100
            type => 'application/octet-stream',
100
            type     => 'application/octet-stream',
101
            content => Encode::encode("UTF-8", $iso2709),
101
            content  => Encode::encode( "UTF-8", $iso2709 ),
102
        };
102
        };
103
103
104
        my $message_id = C4::Letters::EnqueueLetter({
104
        my $message_id = C4::Letters::EnqueueLetter(
105
            letter => $letter,
105
            {
106
            message_transport_type => 'email',
106
                letter                 => $letter,
107
            to_address => $email_add,
107
                message_transport_type => 'email',
108
            reply_address => $user_email,
108
                to_address             => $email_add,
109
            attachments => [$attachment],
109
                reply_address          => $user_email,
110
        });
110
                attachments            => [$attachment],
111
            }
112
        );
111
113
112
        C4::Letters::SendQueuedMessages({ message_id => $message_id });
114
        C4::Letters::SendQueuedMessages( { message_id => $message_id } );
113
115
114
        $template->param( SENT => 1 );
116
        $template->param( SENT => 1 );
115
    }
117
    }
Lines 122-128 else { Link Here
122
        url            => "/cgi-bin/koha/basket/sendbasket.pl",
124
        url            => "/cgi-bin/koha/basket/sendbasket.pl",
123
        suggestion     => C4::Context->preference("suggestion"),
125
        suggestion     => C4::Context->preference("suggestion"),
124
        virtualshelves => C4::Context->preference("virtualshelves"),
126
        virtualshelves => C4::Context->preference("virtualshelves"),
125
        csrf_token     => Koha::Token->new->generate_csrf({ session_id => scalar $query->cookie('CGISESSID'), }),
127
        csrf_token     => Koha::Token->new->generate_csrf(
128
            { session_id => scalar $query->cookie('CGISESSID'), }
129
        ),
126
    );
130
    );
127
    output_html_with_http_headers $query, $cookie, $template->output;
131
    output_html_with_http_headers $query, $cookie, $template->output;
128
}
132
}
(-)a/opac/opac-sendbasket.pl (-44 / +49 lines)
Lines 25-31 use Carp qw( carp ); Link Here
25
use Try::Tiny qw( catch try );
25
use Try::Tiny qw( catch try );
26
26
27
use C4::Biblio qw(
27
use C4::Biblio qw(
28
    GetMarcSubjects
28
  GetMarcSubjects
29
);
29
);
30
use C4::Auth qw( get_template_and_user );
30
use C4::Auth qw( get_template_and_user );
31
use C4::Output qw( output_html_with_http_headers );
31
use C4::Output qw( output_html_with_http_headers );
Lines 37-119 use Koha::Token; Link Here
37
37
38
my $query = CGI->new;
38
my $query = CGI->new;
39
39
40
my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
40
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
41
    {
41
    {
42
        template_name   => "opac-sendbasketform.tt",
42
        template_name => "opac-sendbasketform.tt",
43
        query           => $query,
43
        query         => $query,
44
        type            => "opac",
44
        type          => "opac",
45
    }
45
    }
46
);
46
);
47
47
48
my $bib_list     = $query->param('bib_list') || '';
48
my $bib_list  = $query->param('bib_list') || '';
49
my $email_add    = $query->param('email_add');
49
my $email_add = $query->param('email_add');
50
50
51
if ( $email_add ) {
51
if ($email_add) {
52
    die "Wrong CSRF token" unless Koha::Token->new->check_csrf({
52
    die "Wrong CSRF token"
53
        session_id => scalar $query->cookie('CGISESSID'),
53
      unless Koha::Token->new->check_csrf(
54
        token  => scalar $query->param('csrf_token'),
54
        {
55
    });
55
            session_id => scalar $query->cookie('CGISESSID'),
56
            token      => scalar $query->param('csrf_token'),
57
        }
58
      );
56
59
57
    my $patron = Koha::Patrons->find( $borrowernumber );
60
    my $patron     = Koha::Patrons->find($borrowernumber);
58
    my $user_email = $patron->first_valid_email_address;
61
    my $user_email = $patron->first_valid_email_address;
59
62
60
    my $comment    = $query->param('comment');
63
    my $comment = $query->param('comment');
61
64
62
    my @bibs = split( /\//, $bib_list );
65
    my @bibs = split( /\//, $bib_list );
63
    my $iso2709;
66
    my $iso2709;
64
    foreach my $bib ( @bibs ) {
67
    foreach my $bib (@bibs) {
65
        my $biblio = Koha::Biblios->find( $bib ) or next;
68
        my $biblio = Koha::Biblios->find($bib) or next;
66
        $iso2709 .= $biblio->metadata->record->as_usmarc();
69
        $iso2709 .= $biblio->metadata->record->as_usmarc();
67
    };
70
    }
68
71
69
    if ( !defined $iso2709 ) {
72
    if ( !defined $iso2709 ) {
70
        carp "Error sending mail: empty basket";
73
        carp "Error sending mail: empty basket";
71
        $template->param( error => 1 );
74
        $template->param( error => 1 );
72
    } elsif ( !defined $user_email or $user_email eq '' ) {
75
    }
76
    elsif ( !defined $user_email or $user_email eq '' ) {
73
        carp "Error sending mail: sender's email address is invalid";
77
        carp "Error sending mail: sender's email address is invalid";
74
        $template->param( error => 1 );
78
        $template->param( error => 1 );
75
    } else {
79
    }
76
        my %loops = (
80
    else {
77
            biblio => \@bibs,
81
        my %loops = ( biblio => \@bibs, );
78
        );
79
82
80
        my %substitute = (
83
        my %substitute = ( comment => $comment, );
81
            comment => $comment,
82
        );
83
84
84
        my $letter = C4::Letters::GetPreparedLetter(
85
        my $letter = C4::Letters::GetPreparedLetter(
85
            module => 'catalogue',
86
            module      => 'catalogue',
86
            letter_code => 'CART',
87
            letter_code => 'CART',
87
            lang => $patron->lang,
88
            lang        => $patron->lang,
88
            tables => {
89
            tables      => {
89
                borrowers => $borrowernumber,
90
                borrowers => $borrowernumber,
90
            },
91
            },
91
            message_transport_type => 'email',
92
            message_transport_type => 'email',
92
            loops => \%loops,
93
            loops                  => \%loops,
93
            substitute => \%substitute,
94
            substitute             => \%substitute,
94
        );
95
        );
95
96
96
        my $attachment = {
97
        my $attachment = {
97
            filename => 'basket.iso2709',
98
            filename => 'basket.iso2709',
98
            type => 'application/octet-stream',
99
            type     => 'application/octet-stream',
99
            content => Encode::encode("UTF-8", $iso2709),
100
            content  => Encode::encode( "UTF-8", $iso2709 ),
100
        };
101
        };
101
102
102
        my $message_id = C4::Letters::EnqueueLetter({
103
        my $message_id = C4::Letters::EnqueueLetter(
103
            letter => $letter,
104
            {
104
            message_transport_type => 'email',
105
                letter                 => $letter,
105
            to_address => $email_add,
106
                message_transport_type => 'email',
106
            reply_address => $user_email,
107
                to_address             => $email_add,
107
            attachments => [$attachment],
108
                reply_address          => $user_email,
108
        });
109
                attachments            => [$attachment],
110
            }
111
        );
109
112
110
        C4::Letters::SendQueuedMessages({ message_id => $message_id });
113
        C4::Letters::SendQueuedMessages( { message_id => $message_id } );
111
114
112
        $template->param( SENT => 1 );
115
        $template->param( SENT => 1 );
113
    }
116
    }
114
117
115
    $template->param( email_add => $email_add );
118
    $template->param( email_add => $email_add );
116
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
119
    output_html_with_http_headers $query, $cookie, $template->output, undef,
120
      { force_no_caching => 1 };
117
}
121
}
118
else {
122
else {
119
    my $new_session_id = $query->cookie('CGISESSID');
123
    my $new_session_id = $query->cookie('CGISESSID');
Lines 122-129 else { Link Here
122
        url            => "/cgi-bin/koha/opac-sendbasket.pl",
126
        url            => "/cgi-bin/koha/opac-sendbasket.pl",
123
        suggestion     => C4::Context->preference("suggestion"),
127
        suggestion     => C4::Context->preference("suggestion"),
124
        virtualshelves => C4::Context->preference("virtualshelves"),
128
        virtualshelves => C4::Context->preference("virtualshelves"),
125
        csrf_token => Koha::Token->new->generate_csrf(
129
        csrf_token =>
126
            { session_id => $new_session_id, } ),
130
          Koha::Token->new->generate_csrf( { session_id => $new_session_id, } ),
127
    );
131
    );
128
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
132
    output_html_with_http_headers $query, $cookie, $template->output, undef,
133
      { force_no_caching => 1 };
129
}
134
}
(-)a/opac/opac-sendshelf.pl (-86 / +95 lines)
Lines 26-34 use Try::Tiny qw( catch try ); Link Here
26
26
27
use C4::Auth qw( get_template_and_user );
27
use C4::Auth qw( get_template_and_user );
28
use C4::Biblio qw(
28
use C4::Biblio qw(
29
    GetFrameworkCode
29
  GetFrameworkCode
30
    GetMarcISBN
30
  GetMarcISBN
31
    GetMarcSubjects
31
  GetMarcSubjects
32
);
32
);
33
use C4::Output qw( output_html_with_http_headers );
33
use C4::Output qw( output_html_with_http_headers );
34
use Koha::Biblios;
34
use Koha::Biblios;
Lines 39-141 use Koha::Virtualshelves; Link Here
39
my $query = CGI->new;
39
my $query = CGI->new;
40
40
41
# if virtualshelves is disabled, leave immediately
41
# if virtualshelves is disabled, leave immediately
42
if ( ! C4::Context->preference('virtualshelves') ) {
42
if ( !C4::Context->preference('virtualshelves') ) {
43
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
43
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
44
    exit;
44
    exit;
45
}
45
}
46
46
47
my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
47
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
48
    {
48
    {
49
        template_name   => "opac-sendshelfform.tt",
49
        template_name => "opac-sendshelfform.tt",
50
        query           => $query,
50
        query         => $query,
51
        type            => "opac",
51
        type          => "opac",
52
    }
52
    }
53
);
53
);
54
54
55
my $shelfid = $query->param('shelfid');
55
my $shelfid = $query->param('shelfid');
56
my $email   = $query->param('email');
56
my $email   = $query->param('email');
57
57
58
my $shelf = Koha::Virtualshelves->find( $shelfid );
58
my $shelf = Koha::Virtualshelves->find($shelfid);
59
if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) {
59
if ( $shelf and $shelf->can_be_viewed($borrowernumber) ) {
60
  if ( $email ) {
60
    if ($email) {
61
    my $comment    = $query->param('comment');
61
        my $comment = $query->param('comment');
62
62
63
    my $patron = Koha::Patrons->find( $borrowernumber );
63
        my $patron     = Koha::Patrons->find($borrowernumber);
64
    my $user_email = $patron->first_valid_email_address;
64
        my $user_email = $patron->first_valid_email_address;
65
    my $shelf = Koha::Virtualshelves->find( $shelfid );
65
        my $shelf      = Koha::Virtualshelves->find($shelfid);
66
    my $contents = $shelf->get_contents;
66
        my $contents   = $shelf->get_contents;
67
    my $iso2709;
67
        my $iso2709;
68
68
69
    my @biblionumbers;
69
        my @biblionumbers;
70
    while ( my $content = $contents->next ) {
70
        while ( my $content = $contents->next ) {
71
        push @biblionumbers, $content->biblionumber;
71
            push @biblionumbers, $content->biblionumber;
72
        my $biblio = Koha::Biblios->find($content->biblionumber);
72
            my $biblio = Koha::Biblios->find( $content->biblionumber );
73
        $iso2709 .= $biblio->metadata->record->as_usmarc();
73
            $iso2709 .= $biblio->metadata->record->as_usmarc();
74
    };
74
        }
75
75
76
    if ( !defined $iso2709 ) {
76
        if ( !defined $iso2709 ) {
77
        carp "Error sending mail: empty list";
77
            carp "Error sending mail: empty list";
78
        $template->param( error => 1 );
78
            $template->param( error => 1 );
79
    } elsif ( !defined $user_email or $user_email eq '' ) {
79
        }
80
        carp "Error sending mail: sender's email address is invalid";
80
        elsif ( !defined $user_email or $user_email eq '' ) {
81
        $template->param( error => 1 );
81
            carp "Error sending mail: sender's email address is invalid";
82
    } else {
82
            $template->param( error => 1 );
83
         my %loops = (
83
        }
84
             biblio => \@biblionumbers,
84
        else {
85
         );
85
            my %loops = ( biblio => \@biblionumbers, );
86
86
87
         my %substitute = (
87
            my %substitute = (
88
             comment => $comment,
88
                comment  => $comment,
89
             listname => $shelf->shelfname,
89
                listname => $shelf->shelfname,
90
         );
90
            );
91
91
92
        my $letter = C4::Letters::GetPreparedLetter(
92
            my $letter = C4::Letters::GetPreparedLetter(
93
            module => 'catalogue',
93
                module      => 'catalogue',
94
            letter_code => 'LIST',
94
                letter_code => 'LIST',
95
            lang => $patron->lang,
95
                lang        => $patron->lang,
96
            tables => {
96
                tables      => {
97
                borrowers => $borrowernumber,
97
                    borrowers => $borrowernumber,
98
            },
98
                },
99
            message_transport_type => 'email',
99
                message_transport_type => 'email',
100
            loops => \%loops,
100
                loops                  => \%loops,
101
            substitute => \%substitute,
101
                substitute             => \%substitute,
102
            );
103
104
            my $attachment = {
105
                filename => 'list.iso2709',
106
                type     => 'application/octet-stream',
107
                content  => Encode::encode( "UTF-8", $iso2709 ),
108
            };
109
110
            my $message_id = C4::Letters::EnqueueLetter(
111
                {
112
                    letter                 => $letter,
113
                    message_transport_type => 'email',
114
                    borrowernumber         => $patron->borrowernumber,
115
                    to_address             => $email,
116
                    reply_address          => $user_email,
117
                    attachments            => [$attachment],
118
                }
119
            );
120
121
            C4::Letters::SendQueuedMessages( { message_id => $message_id } );
122
123
            $template->param( SENT => 1 );
124
        }
125
126
        $template->param(
127
            shelfid => $shelfid,
128
            email   => $email,
102
        );
129
        );
130
        output_html_with_http_headers $query, $cookie, $template->output,
131
          undef, { force_no_caching => 1 };
103
132
104
        my $attachment = {
105
            filename => 'list.iso2709',
106
            type => 'application/octet-stream',
107
            content => Encode::encode("UTF-8", $iso2709),
108
        };
109
110
        my $message_id = C4::Letters::EnqueueLetter({
111
            letter => $letter,
112
            message_transport_type => 'email',
113
            borrowernumber => $patron->borrowernumber,
114
            to_address => $email,
115
            reply_address => $user_email,
116
            attachments => [$attachment],
117
        });
118
119
        C4::Letters::SendQueuedMessages({ message_id => $message_id });
120
121
        $template->param( SENT => 1 );
122
    }
133
    }
123
134
    else {
135
        $template->param(
136
            shelfid => $shelfid,
137
            url     => "/cgi-bin/koha/opac-sendshelf.pl",
138
        );
139
        output_html_with_http_headers $query, $cookie, $template->output,
140
          undef, { force_no_caching => 1 };
141
    }
142
}
143
else {
124
    $template->param(
144
    $template->param(
125
        shelfid => $shelfid,
145
        invalidlist => 1,
126
        email   => $email,
146
        url         => "/cgi-bin/koha/opac-sendshelf.pl",
127
    );
128
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
129
130
  } else {
131
    $template->param( shelfid => $shelfid,
132
                      url     => "/cgi-bin/koha/opac-sendshelf.pl",
133
                    );
134
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
135
  }
136
} else {
137
    $template->param( invalidlist => 1,
138
                      url     => "/cgi-bin/koha/opac-sendshelf.pl",
139
    );
147
    );
140
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
148
    output_html_with_http_headers $query, $cookie, $template->output, undef,
149
      { force_no_caching => 1 };
141
}
150
}
(-)a/virtualshelves/sendshelf.pl (-37 / +38 lines)
Lines 26-37 use Try::Tiny qw( catch try ); Link Here
26
26
27
use C4::Auth qw( get_template_and_user );
27
use C4::Auth qw( get_template_and_user );
28
use C4::Biblio qw(
28
use C4::Biblio qw(
29
    GetMarcISBN
29
  GetMarcISBN
30
    GetMarcSubjects
30
  GetMarcSubjects
31
);
31
);
32
use C4::Output qw(
32
use C4::Output qw(
33
    output_html_with_http_headers
33
  output_html_with_http_headers
34
    output_and_exit
34
  output_and_exit
35
);
35
);
36
36
37
use Koha::Biblios;
37
use Koha::Biblios;
Lines 42-121 my $query = CGI->new; Link Here
42
42
43
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
43
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
44
    {
44
    {
45
        template_name   => "virtualshelves/sendshelfform.tt",
45
        template_name => "virtualshelves/sendshelfform.tt",
46
        query           => $query,
46
        query         => $query,
47
        type            => "intranet",
47
        type          => "intranet",
48
        flagsrequired   => { catalogue => 1 },
48
        flagsrequired => { catalogue => 1 },
49
    }
49
    }
50
);
50
);
51
51
52
my $shelfid    = $query->param('shelfid');
52
my $shelfid    = $query->param('shelfid');
53
my $to_address = $query->param('email');
53
my $to_address = $query->param('email');
54
54
55
my $shelf = Koha::Virtualshelves->find( $shelfid );
55
my $shelf = Koha::Virtualshelves->find($shelfid);
56
56
57
output_and_exit( $query, $cookie, $template, 'insufficient_permission' )
57
output_and_exit( $query, $cookie, $template, 'insufficient_permission' )
58
    if $shelf && !$shelf->can_be_viewed( $borrowernumber );
58
  if $shelf && !$shelf->can_be_viewed($borrowernumber);
59
59
60
if ($to_address) {
60
if ($to_address) {
61
    my $comment = $query->param('comment');
61
    my $comment = $query->param('comment');
62
62
63
    my $patron = Koha::Patrons->find( $borrowernumber );
63
    my $patron     = Koha::Patrons->find($borrowernumber);
64
    my $user_email = $patron->first_valid_email_address;
64
    my $user_email = $patron->first_valid_email_address;
65
    my $contents = $shelf->get_contents;
65
    my $contents   = $shelf->get_contents;
66
    my @biblionumbers;
66
    my @biblionumbers;
67
    my $iso2709;
67
    my $iso2709;
68
68
69
    while ( my $content = $contents->next ) {
69
    while ( my $content = $contents->next ) {
70
        push @biblionumbers, $content->biblionumber;
70
        push @biblionumbers, $content->biblionumber;
71
        my $biblio = Koha::Biblios->find($content->biblionumber);
71
        my $biblio = Koha::Biblios->find( $content->biblionumber );
72
        $iso2709 .= $biblio->metadata->record->as_usmarc();
72
        $iso2709 .= $biblio->metadata->record->as_usmarc();
73
    };
73
    }
74
74
75
    if ( !defined $iso2709 ) {
75
    if ( !defined $iso2709 ) {
76
        carp "Error sending mail: empty basket";
76
        carp "Error sending mail: empty basket";
77
        $template->param( error => 1 );
77
        $template->param( error => 1 );
78
    } elsif ( !defined $user_email or $user_email eq '' ) {
78
    }
79
    elsif ( !defined $user_email or $user_email eq '' ) {
79
        carp "Error sending mail: sender's email address is invalid";
80
        carp "Error sending mail: sender's email address is invalid";
80
        $template->param( error => 1 );
81
        $template->param( error => 1 );
81
    } else {
82
    }
82
        my %loops = (
83
    else {
83
            biblio => \@biblionumbers,
84
        my %loops = ( biblio => \@biblionumbers, );
84
        );
85
85
86
        my %substitute = (
86
        my %substitute = (
87
            comment => $comment,
87
            comment  => $comment,
88
            listname => $shelf->shelfname,
88
            listname => $shelf->shelfname,
89
        );
89
        );
90
90
91
        my $letter = C4::Letters::GetPreparedLetter(
91
        my $letter = C4::Letters::GetPreparedLetter(
92
            module => 'catalogue',
92
            module      => 'catalogue',
93
            letter_code => 'LIST',
93
            letter_code => 'LIST',
94
            lang => $patron->lang,
94
            lang        => $patron->lang,
95
            tables => {
95
            tables      => {
96
                borrowers => $borrowernumber,
96
                borrowers => $borrowernumber,
97
            },
97
            },
98
            message_transport_type => 'email',
98
            message_transport_type => 'email',
99
            loops => \%loops,
99
            loops                  => \%loops,
100
            substitute => \%substitute,
100
            substitute             => \%substitute,
101
        );
101
        );
102
102
103
        my $attachment = {
103
        my $attachment = {
104
            filename => 'shelf.iso2709',
104
            filename => 'shelf.iso2709',
105
            type => 'application/octet-stream',
105
            type     => 'application/octet-stream',
106
            content => Encode::encode("UTF-8", $iso2709),
106
            content  => Encode::encode( "UTF-8", $iso2709 ),
107
        };
107
        };
108
108
109
        my $message_id = C4::Letters::EnqueueLetter({
109
        my $message_id = C4::Letters::EnqueueLetter(
110
            letter => $letter,
110
            {
111
            message_transport_type => 'email',
111
                letter                 => $letter,
112
            borrowernumber => $patron->borrowernumber,
112
                message_transport_type => 'email',
113
            to_address => $to_address,
113
                borrowernumber         => $patron->borrowernumber,
114
            reply_address => $user_email,
114
                to_address             => $to_address,
115
            attachments => [$attachment],
115
                reply_address          => $user_email,
116
        });
116
                attachments            => [$attachment],
117
            }
118
        );
117
119
118
        C4::Letters::SendQueuedMessages({ message_id => $message_id });
120
        C4::Letters::SendQueuedMessages( { message_id => $message_id } );
119
121
120
        $template->param( SENT => 1 );
122
        $template->param( SENT => 1 );
121
    }
123
    }
122
- 

Return to bug 3150