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

(-)a/C4/Letters.pm (-8 / +2 lines)
Lines 806-819 sub _send_message_by_email ($;$$$) { Link Here
806
                                   status     => 'failed' } );
806
                                   status     => 'failed' } );
807
            return;
807
            return;
808
        }
808
        }
809
        my $which_address = C4::Context->preference('AutoEmailPrimaryAddress');
809
        $to_address = GetPreferredEmailAddress($message->{'borrowernumber'});
810
        # If the system preference is set to 'first valid' (value == OFF), look up email address
810
        unless ($to_address) {
811
        if ($which_address eq 'OFF') {
812
            $to_address = GetFirstValidEmailAddress( $message->{'borrowernumber'} );
813
        } else {
814
            $to_address = $member->{$which_address};
815
        }
816
        unless ($to_address) {  
817
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
811
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
818
            # warning too verbose for this more common case?
812
            # warning too verbose for this more common case?
819
            _set_message_status( { message_id => $message->{'message_id'},
813
            _set_message_status( { message_id => $message->{'message_id'},
(-)a/C4/Members.pm (-1 / +48 lines)
Lines 59-65 BEGIN { Link Here
59
		&getzipnamecity 
59
		&getzipnamecity 
60
		&getidcity
60
		&getidcity
61
61
62
                &GetFirstValidEmailAddress
62
        GetFirstValidEmailAddress
63
        GetPreferredEmailAddress
63
64
64
		&GetAge 
65
		&GetAge 
65
		&GetCities 
66
		&GetCities 
Lines 1367-1372 sub GetFirstValidEmailAddress { Link Here
1367
    }
1368
    }
1368
}
1369
}
1369
1370
1371
1372
=head2 GetPreferredEmailAddress
1373
1374
  $email = GetPreferredEmailAddress($user);
1375
1376
Returns the email address that should be used to send people things, as
1377
determined by the AutoEmailPrimaryAddress system preference.
1378
1379
=head3 OPTIONS
1380
1381
=over 4
1382
1383
=item C<$user>: this is either a hashref of the sort returned by GetMember, or
1384
a number, in which case it'll be assumed to be a user number.
1385
1386
=back
1387
1388
=head3 RETURNS
1389
1390
Returns the email address value if it's available, or C<undef> if it's not.
1391
1392
=cut
1393
1394
sub GetPreferredEmailAddress {
1395
    my ($user) = @_;
1396
1397
    if ( !ref($user) ) {
1398
1399
        # Assume it's a user number
1400
        $user = GetMember( borrowernumber => $user );
1401
    }
1402
1403
    # Least surprise
1404
    return undef if !defined $user;
1405
    my $which_address = C4::Context->preference('AutoEmailPrimaryAddress');
1406
1407
    # If the system preference is set to 'first valid' (value == OFF),
1408
    # look up email address
1409
    if ( $which_address eq 'OFF' ) {
1410
        return $user->{email} || $user->{emailpro} || $user->{B_email};
1411
    }
1412
    else {
1413
        return $user->{$which_address};
1414
    }
1415
}
1416
1370
=head2 GetExpiryDate 
1417
=head2 GetExpiryDate 
1371
1418
1372
  $expirydate = GetExpiryDate($categorycode, $dateenrolled);
1419
  $expirydate = GetExpiryDate($categorycode, $dateenrolled);
(-)a/C4/Reserves.pm (-9 / +1 lines)
Lines 1679-1693 sub _koha_notify_reserve { Link Here
1679
    my $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber);
1679
    my $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber);
1680
    
1680
    
1681
    # Try to get the borrower's email address
1681
    # Try to get the borrower's email address
1682
    my $to_address;
1682
    my $to_address = GetPreferredEmailAddress($borrowernumber);
1683
    my $which_address = C4::Context->preference('AutoEmailPrimaryAddress');
1684
    # If the system preference is set to 'first valid' (value == OFF), look up email address
1685
    if ($which_address eq 'OFF') {
1686
        $to_address = C4::Members::GetFirstValidEmailAddress( $borrowernumber );
1687
    } else {
1688
        $to_address = $borrower->{$which_address};
1689
    }
1690
    
1691
    my $letter_code;
1683
    my $letter_code;
1692
    my $print_mode = 0;
1684
    my $print_mode = 0;
1693
    my $messagingprefs;
1685
    my $messagingprefs;
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 318-320 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ( Link Here
318
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('BasketConfirmations', '1', 'When closing or reopening a basket,', 'always ask for confirmation.|do not ask for confirmation.', 'Choice');
318
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('BasketConfirmations', '1', 'When closing or reopening a basket,', 'always ask for confirmation.|do not ask for confirmation.', 'Choice');
319
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('MARCAuthorityControlField008', '|| aca||aabn           | a|a     d', NULL, NULL, 'Textarea');
319
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('MARCAuthorityControlField008', '|| aca||aabn           | a|a     d', NULL, NULL, 'Textarea');
320
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpenLibraryCovers',0,'If ON Openlibrary book covers will be show',NULL,'YesNo');
320
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpenLibraryCovers',0,'If ON Openlibrary book covers will be show',NULL,'YesNo');
321
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacSendReplyTo',0,'Decides whether to use the patron\'s email address as the reply-to when they\'re sending carts and lists',NULL,'YesNo');
(-)a/installer/data/mysql/updatedatabase.pl (+6 lines)
Lines 4446-4451 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
4446
    SetVersion($DBversion);
4446
    SetVersion($DBversion);
4447
}
4447
}
4448
4448
4449
$DBversion = 'XXX';
4450
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4451
    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacSendReplyTo',0,'Decides whether to use the patron\\'s email address as the reply-to when they\\'re sending carts and lists',NULL,'YesNo');");
4452
    print "Upgrade to $DBversion done (add OpacSendReplyTo syspref (enh 6973))\n";
4453
    SetVersion($DBversion);
4454
}
4449
4455
4450
=head1 FUNCTIONS
4456
=head1 FUNCTIONS
4451
4457
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref (+7 lines)
Lines 233-238 OPAC: Link Here
233
                  no: "Don't allow"
233
                  no: "Don't allow"
234
            - patrons to store items in a temporary "Cart" on the OPAC.
234
            - patrons to store items in a temporary "Cart" on the OPAC.
235
        -
235
        -
236
            - Use
237
            - pref: OpacSendReplyTo
238
              choices:
239
                  yes: "sender's email"
240
                  no: "library admin email"
241
            - as the reply-to address when sending carts and lists.
242
        -
236
            - pref: OpacTopissue
243
            - pref: OpacTopissue
237
              choices:
244
              choices:
238
                  yes: Allow
245
                  yes: Allow
(-)a/opac/opac-sendbasket.pl (-10 / +11 lines)
Lines 46-61 my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( Link Here
46
46
47
my $bib_list     = $query->param('bib_list');
47
my $bib_list     = $query->param('bib_list');
48
my $email_add    = $query->param('email_add');
48
my $email_add    = $query->param('email_add');
49
my $email_sender = $query->param('email_sender');
50
49
51
my $dbh          = C4::Context->dbh;
50
my $dbh          = C4::Context->dbh;
52
51
53
if ( $email_add ) {
52
if ( $email_add ) {
54
    my $email_from = C4::Context->preference('KohaAdminEmailAddress');
53
    my $email_from = C4::Context->preference('KohaAdminEmailAddress');
55
    my $comment    = $query->param('comment');
54
    my $user = GetMember( borrowernumber => $borrowernumber );
56
    my %mail = (
55
    my $sender_email
57
        To   => $email_add,
56
        = C4::Context->preference('OpacSendReplyTo')
58
        From => $email_from
57
        ? GetPreferredEmailAddress($user) || $email_from
58
        : $email_from;
59
    my $comment = $query->param('comment');
60
    my %mail    = (
61
        To         => $email_add,
62
        From       => $email_from,
63
        'Reply-To' => $sender_email,
59
    );
64
    );
60
65
61
    my ( $template2, $borrowernumber, $cookie ) = get_template_and_user(
66
    my ( $template2, $borrowernumber, $cookie ) = get_template_and_user(
Lines 87-93 if ( $email_add ) { Link Here
87
        if($dat->{'author'} || @$marcauthorsarray) {
92
        if($dat->{'author'} || @$marcauthorsarray) {
88
          $hasauthors = 1;
93
          $hasauthors = 1;
89
        }
94
        }
90
	
91
95
92
        $dat->{MARCNOTES}      = $marcnotesarray;
96
        $dat->{MARCNOTES}      = $marcnotesarray;
93
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
97
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
Lines 102-113 if ( $email_add ) { Link Here
102
    }
106
    }
103
107
104
    my $resultsarray = \@results;
108
    my $resultsarray = \@results;
105
    
109
106
    my $user = GetMember(borrowernumber => $borrowernumber); 
107
    
108
    $template2->param(
110
    $template2->param(
109
        BIBLIO_RESULTS => $resultsarray,
111
        BIBLIO_RESULTS => $resultsarray,
110
        email_sender   => $email_sender,
111
        comment        => $comment,
112
        comment        => $comment,
112
        firstname      => $user->{firstname},
113
        firstname      => $user->{firstname},
113
        surname        => $user->{surname},
114
        surname        => $user->{surname},
(-)a/opac/opac-sendshelf.pl (-5 / +9 lines)
Lines 55-65 if ( ShelfPossibleAction( (defined($borrowernumber) ? $borrowernumber : -1), $sh Link Here
55
55
56
if ( $email ) {
56
if ( $email ) {
57
    my $email_from = C4::Context->preference('KohaAdminEmailAddress');
57
    my $email_from = C4::Context->preference('KohaAdminEmailAddress');
58
    my $comment    = $query->param('comment');
58
    my $sender_email
59
        = C4::Context->preference('OpacSendReplyTo')
60
        ? GetPreferredEmailAddress($user) || $email_from
61
        : $email_from;
62
    my $comment = $query->param('comment');
59
63
60
    my %mail = (
64
    my %mail = (
61
        To   => $email,
65
        To         => $email,
62
        From => $email_from
66
        From       => $email_from,
67
        'Reply-To' => $sender_email,
63
    );
68
    );
64
69
65
    my ( $template2, $borrowernumber, $cookie ) = get_template_and_user(
70
    my ( $template2, $borrowernumber, $cookie ) = get_template_and_user(
Lines 185-188 END_OF_BODY Link Here
185
                      url     => "/cgi-bin/koha/opac-sendshelf.pl",
190
                      url     => "/cgi-bin/koha/opac-sendshelf.pl",
186
    );
191
    );
187
    output_html_with_http_headers $query, $cookie, $template->output;
192
    output_html_with_http_headers $query, $cookie, $template->output;
188
}
193
}
189
- 

Return to bug 6973