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

(-)a/C4/NewsChannels.pm (-13 / +34 lines)
Lines 126-140 sub get_opac_new { Link Here
126
    my ($idnew) = @_;
126
    my ($idnew) = @_;
127
    my $dbh = C4::Context->dbh;
127
    my $dbh = C4::Context->dbh;
128
    my $query = q{
128
    my $query = q{
129
                  SELECT opac_news.*,branches.branchname
129
                  SELECT opac_news.*,branches.branchname,
130
                         timestamp AS newdate,
131
                         borrowers.title AS author_title,
132
                         borrowers.firstname AS author_firstname,
133
                         borrowers.surname AS author_surname
130
                  FROM opac_news LEFT JOIN branches
134
                  FROM opac_news LEFT JOIN branches
131
                      ON opac_news.branchcode=branches.branchcode
135
                      ON opac_news.branchcode=branches.branchcode
136
                  LEFT JOIN borrowers on borrowers.borrowernumber = opac_news.borrowernumber
132
                  WHERE opac_news.idnew = ?;
137
                  WHERE opac_news.idnew = ?;
133
                };
138
                };
134
    my $sth = $dbh->prepare($query);
139
    my $sth = $dbh->prepare($query);
135
    $sth->execute($idnew);
140
    $sth->execute($idnew);
136
    my $data = $sth->fetchrow_hashref;
141
    my $data = $sth->fetchrow_hashref;
137
    $data->{$data->{'lang'}} = 1 if defined $data->{lang};
142
    $data->{$data->{'lang'}} = 1 if defined $data->{lang};
143
    $data->{newdate}        = output_pref({ dt => dt_from_string( $data->{newdate} ), dateonly => 1 });
138
    $data->{expirationdate} = output_pref({ dt => dt_from_string( $data->{expirationdate} ), dateonly => 1 });
144
    $data->{expirationdate} = output_pref({ dt => dt_from_string( $data->{expirationdate} ), dateonly => 1 });
139
    $data->{timestamp}      = output_pref({ dt => dt_from_string( $data->{timestamp} ), dateonly => 1 }) ;
145
    $data->{timestamp}      = output_pref({ dt => dt_from_string( $data->{timestamp} ), dateonly => 1 }) ;
140
    return $data;
146
    return $data;
Lines 190-210 sub get_opac_news { Link Here
190
=cut
196
=cut
191
197
192
sub GetNewsToDisplay {
198
sub GetNewsToDisplay {
193
    my ($lang,$branch) = @_;
199
    my ($lang,$branch,$time,$id) = @_;
194
    my $dbh = C4::Context->dbh;
200
    my $dbh = C4::Context->dbh;
195
    # SELECT *,DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate
201
    # SELECT *,DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate
202
    my @values;
196
    my $query = q{
203
    my $query = q{
197
     SELECT opac_news.*,timestamp AS newdate,
204
     SELECT opac_news.*,timestamp AS newdate,
198
     borrowers.title AS author_title,
205
     borrowers.title     AS author_title,
199
     borrowers.firstname AS author_firstname,
206
     borrowers.firstname AS author_firstname,
200
     borrowers.surname AS author_surname
207
     borrowers.surname   AS author_surname
201
     FROM   opac_news
208
     FROM opac_news
202
     LEFT JOIN borrowers on borrowers.borrowernumber = opac_news.borrowernumber
209
     LEFT JOIN borrowers on borrowers.borrowernumber =
203
     WHERE   (
210
         opac_news.borrowernumber
204
        expirationdate >= CURRENT_DATE()
211
     WHERE (};
205
        OR    expirationdate IS NULL
212
206
        OR    expirationdate = '00-00-0000'
213
    if ( defined $id ) {
207
     )
214
        $query .= q{ opac_news.idnew = ? } if defined $id;
215
        push( @values, $id );
216
    }
217
218
    unless ( defined $time ) {
219
        $query .= q{ AND } if defined $id;
220
        $query .= q{
221
            expirationdate >= CURRENT_DATE()
222
            OR    expirationdate IS NULL
223
            OR    expirationdate = '00-00-0000'
224
         } unless( defined $time and $time eq 'all' );
225
    }
226
227
    $query .= q{ )
208
     AND   DATE(timestamp) < DATE_ADD(CURDATE(), INTERVAL 1 DAY)
228
     AND   DATE(timestamp) < DATE_ADD(CURDATE(), INTERVAL 1 DAY)
209
     AND   (lang = '' OR lang = ?)
229
     AND   (lang = '' OR lang = ?)
210
     AND   (opac_news.branchcode IS NULL OR opac_news.branchcode = ?)
230
     AND   (opac_news.branchcode IS NULL OR opac_news.branchcode = ?)
Lines 214-220 sub GetNewsToDisplay { Link Here
214
       #           by adding 1, that captures today correctly.
234
       #           by adding 1, that captures today correctly.
215
    my $sth = $dbh->prepare($query);
235
    my $sth = $dbh->prepare($query);
216
    $lang = $lang // q{};
236
    $lang = $lang // q{};
217
    $sth->execute($lang,$branch);
237
    push( @values, $lang );
238
    push( @values, $branch );
239
    $sth->execute(@values);
218
    my @results;
240
    my @results;
219
    while ( my $row = $sth->fetchrow_hashref ){
241
    while ( my $row = $sth->fetchrow_hashref ){
220
        $row->{newdate} = output_pref({ dt => dt_from_string( $row->{newdate} ), dateonly => 1 });
242
        $row->{newdate} = output_pref({ dt => dt_from_string( $row->{newdate} ), dateonly => 1 });
221
- 

Return to bug 14272