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

(-)a/C4/Members.pm (-1 / +1 lines)
Lines 2425-2431 sub IssueSlip { Link Here
2425
            'news' => [ map {
2425
            'news' => [ map {
2426
                $_->{'timestamp'} = $_->{'newdate'};
2426
                $_->{'timestamp'} = $_->{'newdate'};
2427
                { opac_news => $_ }
2427
                { opac_news => $_ }
2428
            } @{ GetNewsToDisplay("slip") } ],
2428
            } @{ GetNewsToDisplay("slip",$branch) } ],
2429
        );
2429
        );
2430
    }
2430
    }
2431
2431
(-)a/C4/NewsChannels.pm (-58 / +114 lines)
Lines 1-37 Link Here
1
package C4::NewsChannels;
1
package C4::NewsChannels;
2
2
3
# Copyright 2000-2002 Katipo Communications
4
#
5
# This file is part of Koha.
3
# This file is part of Koha.
6
#
4
#
7
# Koha is free software; you can redistribute it and/or modify it under the
5
# Copyright (C) 2000  Katipo Communications
8
# terms of the GNU General Public License as published by the Free Software
6
# Copyright (C) 2013  Mark Tompsett
9
# Foundation; either version 2 of the License, or (at your option) any later
7
#
10
# version.
8
# Koha is free software; you can redistribute it and/or modify it
9
# under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 3 of the License, or
11
# (at your option) any later version.
11
#
12
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# Koha is distributed in the hope that it will be useful, but
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
15
#
17
#
16
# You should have received a copy of the GNU General Public License along
18
# You should have received a copy of the GNU General Public License
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
20
use strict;
21
use warnings;
22
21
22
use Modern::Perl;
23
use C4::Context;
23
use C4::Context;
24
use C4::Dates qw(format_date);
24
use C4::Dates qw(format_date);
25
25
26
use vars qw($VERSION @ISA @EXPORT);
26
use vars qw($VERSION @ISA @EXPORT);
27
27
28
BEGIN { 
28
BEGIN { 
29
    $VERSION = 3.07.00.049;	# set the version for version checking
29
    $VERSION = 3.07.00.049;        # set the version for version checking
30
	@ISA = qw(Exporter);
30
        @ISA = qw(Exporter);
31
	@EXPORT = qw(
31
        @EXPORT = qw(
32
		&GetNewsToDisplay
32
                     &add_opac_new
33
		&add_opac_new &upd_opac_new &del_opac_new &get_opac_new &get_opac_news
33
                     &upd_opac_new
34
	);
34
                     &del_opac_new
35
                     &get_opac_new
36
                     &get_opac_news
37
                     &GetNewsToDisplay
38
                    );
35
}
39
}
36
40
37
=head1 NAME
41
=head1 NAME
Lines 47-76 This module provides the functions needed to mange OPAC and intranet news. Link Here
47
=cut
51
=cut
48
52
49
sub add_opac_new {
53
sub add_opac_new {
50
    my ($title, $new, $lang, $expirationdate, $timestamp, $number) = @_;
54
    my ($href_entry) = @_;
51
    my $dbh = C4::Context->dbh;
55
    my $retval=0;
52
    my $sth = $dbh->prepare("INSERT INTO opac_news (title, new, lang, expirationdate, timestamp, number) VALUES (?,?,?,?,?,?)");
56
53
    $sth->execute($title, $new, $lang, $expirationdate, $timestamp, $number);
57
    if ($href_entry) {
54
    $sth->finish;
58
        my @fields = keys %{$href_entry};
55
    return 1;
59
        my @values = values %{$href_entry};
60
        my $field_string = join ",",@fields;
61
        $field_string = $field_string // q{};
62
        my $values_string = "?," x ($#fields) . "?";
63
64
        my $dbh = C4::Context->dbh;
65
        my $sth = $dbh->prepare("INSERT INTO opac_news ( $field_string ) VALUES ( $values_string );");
66
        $sth->execute(@values);
67
        $retval = 1;
68
    }
69
    return $retval;
56
}
70
}
57
71
58
sub upd_opac_new {
72
sub upd_opac_new {
59
    my ($idnew, $title, $new, $lang, $expirationdate, $timestamp,$number) = @_;
73
    my ($href_entry) = @_;
60
    my $dbh = C4::Context->dbh;
74
    my $retval = 0;
61
    my $sth = $dbh->prepare("
75
62
        UPDATE opac_news SET 
76
    if ($href_entry) {
63
            title = ?,
77
        # take the keys of hash entry and make a list, but...
64
            new = ?,
78
        my @fields = keys %{$href_entry};
65
            lang = ?,
79
        my @values;
66
            expirationdate = ?,
80
        $#values = -1;
67
            timestamp = ?,
81
        my $field_string = q{};
68
            number = ?
82
        foreach my $field_name (@fields) {
69
        WHERE idnew = ?
83
            # exclude idnew
70
    ");
84
            if ( $field_name ne 'idnew' ) {
71
    $sth->execute($title, $new, $lang, $expirationdate, $timestamp,$number,$idnew);
85
                $field_string = $field_string . "$field_name = ?,";
72
    $sth->finish;
86
                push @values,$href_entry->{$field_name};
73
    return 1;
87
            }
88
        }
89
        # put idnew at the end, so we know which record to update
90
        push @values,$href_entry->{'idnew'};
91
        chop $field_string; # remove that excess ,
92
93
        my $dbh = C4::Context->dbh;
94
        my $sth = $dbh->prepare("UPDATE opac_news SET $field_string WHERE idnew = ?;");
95
        $sth->execute(@values);
96
        $retval = 1;
97
    }
98
    return $retval;
74
}
99
}
75
100
76
sub del_opac_new {
101
sub del_opac_new {
Lines 79-85 sub del_opac_new { Link Here
79
        my $dbh = C4::Context->dbh;
104
        my $dbh = C4::Context->dbh;
80
        my $sth = $dbh->prepare("DELETE FROM opac_news WHERE idnew IN ($ids)");
105
        my $sth = $dbh->prepare("DELETE FROM opac_news WHERE idnew IN ($ids)");
81
        $sth->execute();
106
        $sth->execute();
82
        $sth->finish;
83
        return 1;
107
        return 1;
84
    } else {
108
    } else {
85
        return 0;
109
        return 0;
Lines 89-123 sub del_opac_new { Link Here
89
sub get_opac_new {
113
sub get_opac_new {
90
    my ($idnew) = @_;
114
    my ($idnew) = @_;
91
    my $dbh = C4::Context->dbh;
115
    my $dbh = C4::Context->dbh;
92
    my $sth = $dbh->prepare("SELECT * FROM opac_news WHERE idnew = ?");
116
    my $query = q{
117
                  SELECT opac_news.*,branches.branchname,timestamp AS newdate
118
                  FROM opac_news LEFT JOIN branches ON opac_news.branchcode=branches.branchcode
119
                  WHERE opac_news.idnew = ?;
120
                };
121
    my $sth = $dbh->prepare($query);
93
    $sth->execute($idnew);
122
    $sth->execute($idnew);
94
    my $data = $sth->fetchrow_hashref;
123
    my $data = $sth->fetchrow_hashref;
95
    $data->{$data->{'lang'}} = 1 if defined $data->{lang};
124
    $data->{$data->{'lang'}} = 1 if defined $data->{lang};
96
    $data->{expirationdate} = format_date($data->{expirationdate});
125
    $data->{expirationdate} = format_date($data->{expirationdate});
97
    $data->{timestamp}      = format_date($data->{timestamp});
126
    $data->{timestamp}      = format_date($data->{timestamp});
98
    $sth->finish;
127
    if (!defined($data->{branchcode}) || $data->{branchcode} eq '') {
128
        $data->{branchname}     = "All Branches";
129
    }
99
    return $data;
130
    return $data;
100
}
131
}
101
132
102
sub get_opac_news {
133
sub get_opac_news {
103
    my ($limit, $lang) = @_;
134
    my ($limit, $lang, $branchcode) = @_;
135
    my @values;
104
    my $dbh = C4::Context->dbh;
136
    my $dbh = C4::Context->dbh;
105
    my $query = "SELECT *, timestamp AS newdate FROM opac_news";
137
    my $query = q{
106
    if ($lang) {
138
                  SELECT opac_news.*,branches.branchname,timestamp AS newdate
107
        $query.= " WHERE lang = '" .$lang ."' ";
139
                  FROM opac_news LEFT JOIN branches ON opac_news.branchcode=branches.branchcode
140
                };
141
    if ($lang && $branchcode) {
142
        $query.= " WHERE (opac_news.lang='' OR opac_news.lang=?)";
143
        $query .= " AND  (opac_news.branchcode IS NULL OR opac_news.branchcode=?)";
144
        push @values,$lang;
145
        push @values,$branchcode;
146
    }
147
    elsif ($lang) {
148
        $query.= " WHERE (opac_news.lang='' OR opac_news.lang=?)";
149
        push @values,$lang;
150
    }
151
    elsif ($branchcode) {
152
        $query .= " WHERE (opac_news.branchcode IS NULL OR opac_news.branchcode=?)";
153
        push @values,$branchcode;
154
    }
155
    else {
156
       # nothing
108
    }
157
    }
109
    $query.= " ORDER BY timestamp DESC ";
158
    $query.= " ORDER BY timestamp DESC ";
110
    #if ($limit) {
159
    #if ($limit) {
111
    #    $query.= "LIMIT 0, " . $limit;
160
    #    $query.= "LIMIT 0, " . $limit;
112
    #}
161
    #}
113
    my $sth = $dbh->prepare($query);
162
    my $sth = $dbh->prepare($query);
114
    $sth->execute();
163
    $sth->execute(@values);
115
    my @opac_news;
164
    my @opac_news;
116
    my $count = 0;
165
    my $count = 0;
117
    while (my $row = $sth->fetchrow_hashref) {
166
    while (my $row = $sth->fetchrow_hashref) {
118
        if ((($limit) && ($count < $limit)) || (!$limit)) {
167
        if ((($limit) && ($count < $limit)) || (!$limit)) {
119
            $row->{'newdate'} = format_date($row->{'newdate'});
168
            $row->{'newdate'} = format_date($row->{'newdate'});
120
            $row->{'expirationdate'} = format_date($row->{'expirationdate'});
169
            $row->{'expirationdate'} = format_date($row->{'expirationdate'});
170
            $row->{'branchname'}     = "All Branches" if !$row->{'branchcode'};
121
            push @opac_news, $row;
171
            push @opac_news, $row;
122
        }
172
        }
123
        $count++;
173
        $count++;
Lines 127-143 sub get_opac_news { Link Here
127
177
128
=head2 GetNewsToDisplay
178
=head2 GetNewsToDisplay
129
179
130
    $news = &GetNewsToDisplay($lang);
180
    $news = &GetNewsToDisplay($lang,$branch);
131
    C<$news> is a ref to an array which containts
181
    C<$news> is a ref to an array which containts
132
    all news with expirationdate > today or expirationdate is null.
182
    all news with expirationdate > today or expirationdate is null
183
    that is applicable for a given branch.
133
184
134
=cut
185
=cut
135
186
136
sub GetNewsToDisplay {
187
sub GetNewsToDisplay {
137
    my $lang = shift;
188
    my ($lang,$branch) = @_;
138
    my $dbh = C4::Context->dbh;
189
    my $dbh = C4::Context->dbh;
139
    # SELECT *,DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate
190
    # SELECT *,DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate
140
    my $query = "
191
    my $query = q{
141
     SELECT *,timestamp AS newdate
192
     SELECT *,timestamp AS newdate
142
     FROM   opac_news
193
     FROM   opac_news
143
     WHERE   (
194
     WHERE   (
Lines 145-159 sub GetNewsToDisplay { Link Here
145
        OR    expirationdate IS NULL
196
        OR    expirationdate IS NULL
146
        OR    expirationdate = '00-00-0000'
197
        OR    expirationdate = '00-00-0000'
147
      )
198
      )
148
      AND   `timestamp` <= CURRENT_DATE()
199
      AND   `timestamp` < CURRENT_DATE()+1
149
      AND   lang = ?
200
      AND   (lang = '' OR lang = ?)
201
      AND   (branchcode IS NULL OR branchcode = ?)
150
      ORDER BY number
202
      ORDER BY number
151
    ";				# expirationdate field is NOT in ISO format?
203
    }; # expirationdate field is NOT in ISO format?
204
       # timestamp has HH:mm:ss, CURRENT_DATE() generates 00:00:00
205
       #           by adding 1, that captures today correctly.
152
    my $sth = $dbh->prepare($query);
206
    my $sth = $dbh->prepare($query);
153
    $sth->execute($lang);
207
    $lang = $lang // '';
208
    $branch = $branch // '';
209
    $sth->execute($lang,$branch);
154
    my @results;
210
    my @results;
155
    while ( my $row = $sth->fetchrow_hashref ){
211
    while ( my $row = $sth->fetchrow_hashref ){
156
		$row->{newdate} = format_date($row->{newdate});
212
        $row->{newdate} = format_date($row->{newdate});
157
        push @results, $row;
213
        push @results, $row;
158
    }
214
    }
159
    return \@results;
215
    return \@results;
(-)a/installer/data/mysql/en/optional/sample_news.sql (-2 / +6 lines)
Lines 1-2 Link Here
1
INSERT INTO `opac_news` VALUES (1,'Welcome to Koha','Welcome to Koha. Koha is a full-featured open-source ILS. Developed initially in New Zealand by Katipo Communications Ltd and first deployed in January of 2000 for Horowhenua Library Trust, Koha is currently maintained by a team of software providers and library technology staff from around the globe.','koha','2007-10-29 05:25:58','2099-01-10',1),
1
INSERT INTO `opac_news` ( title,             new,
2
(2,'What\'s Next?','Now that you\'ve installed Koha, what\'s next? Here are some suggestions:\r\n<ul>\r\n<li><a href=\"http://koha-community.org/documentation/\">Read Koha Documentation</a></li>\r\n<li><a href=\"http://wiki.koha-community.org\">Read/Write to the Koha Wiki</a></li>\r\n<li><a href=\"http://koha-community.org/support/\">Read and Contribute to Discussions</a></li>\r\n<li><a href=\"http://bugs.koha-community.org\">Report Koha Bugs</a></li>\r\n<li><a href=\"http://wiki.koha-community.org/wiki/Version_Control_Using_Git\">Submit Patches to Koha using Git (Version Control System)</a></li>\r\n<li><a href=\"http://koha-community.org/support/\">Chat with Koha users and developers</a></li>\r\n</ul>\r\n','koha','2007-10-29 05:34:45','2099-01-10',2);
2
                          lang,   timestamp,            expirationdate, number, branchcode )
3
                 VALUES ( 'Welcome to Koha', 'Welcome to Koha. Koha is a full-featured open-source ILS. Developed initially in New Zealand by Katipo Communications Ltd and first deployed in January of 2000 for Horowhenua Library Trust, Koha is currently maintained by a team of software providers and library technology staff from around the globe.',
4
                          'koha', '2007-10-29 05:25:58','2099-01-10',   1,      NULL),
5
                        ( 'What\'s Next?',   'Now that you\'ve installed Koha, what\'s next? Here are some suggestions:\r\n<ul>\r\n<li><a href=\"http://koha-community.org/documentation/\">Read Koha Documentation</a></li>\r\n<li><a href=\"http://wiki.koha-community.org\">Read/Write to the Koha Wiki</a></li>\r\n<li><a href=\"http://koha-community.org/support/\">Read and Contribute to Discussions</a></li>\r\n<li><a href=\"http://bugs.koha-community.org\">Report Koha Bugs</a></li>\r\n<li><a href=\"http://wiki.koha-community.org/wiki/Version_Control_Using_Git\">Submit Patches to Koha using Git (Version Control System)</a></li>\r\n<li><a href=\"http://koha-community.org/support/\">Chat with Koha users and developers</a></li>\r\n</ul>\r\n',
6
                          'koha', '2007-10-29 05:34:45','2099-01-10',   2,      NULL);
(-)a/installer/data/mysql/kohastructure.sql (-1 / +4 lines)
Lines 1636-1648 CREATE TABLE `old_reserves` ( -- this table holds all holds/reserves that have b Link Here
1636
DROP TABLE IF EXISTS `opac_news`;
1636
DROP TABLE IF EXISTS `opac_news`;
1637
CREATE TABLE `opac_news` ( -- data from the news tool
1637
CREATE TABLE `opac_news` ( -- data from the news tool
1638
  `idnew` int(10) unsigned NOT NULL auto_increment, -- unique identifier for the news article
1638
  `idnew` int(10) unsigned NOT NULL auto_increment, -- unique identifier for the news article
1639
  `branchcode` varchar(10) NULL default NULL, -- branch code used to create branch specific news, NULL is every branch.
1639
  `title` varchar(250) NOT NULL default '', -- title of the news article
1640
  `title` varchar(250) NOT NULL default '', -- title of the news article
1640
  `new` text NOT NULL, -- the body of your news article
1641
  `new` text NOT NULL, -- the body of your news article
1641
  `lang` varchar(25) NOT NULL default '', -- location for the article (koha is the staff client, slip is the circulation receipt and language codes are for the opac)
1642
  `lang` varchar(25) NOT NULL default '', -- location for the article (koha is the staff client, slip is the circulation receipt and language codes are for the opac)
1642
  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP, -- pulibcation date and time
1643
  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP, -- pulibcation date and time
1643
  `expirationdate` date default NULL, -- date the article is set to expire or no longer be visible
1644
  `expirationdate` date default NULL, -- date the article is set to expire or no longer be visible
1644
  `number` int(11) default NULL, -- the order in which this article appears in that specific location
1645
  `number` int(11) default NULL, -- the order in which this article appears in that specific location
1645
  PRIMARY KEY  (`idnew`)
1646
  PRIMARY KEY  (`idnew`),
1647
  CONSTRAINT opac_news_branchcode_ibfk FOREIGN KEY (branchcode) REFERENCES branches (branchcode)
1648
    ON DELETE CASCADE ON UPDATE CASCADE
1646
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1649
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1647
1650
1648
--
1651
--
(-)a/installer/data/mysql/updatedatabase.pl (+13 lines)
Lines 7824-7829 if ( CheckVersion($DBversion) ) { Link Here
7824
    SetVersion($DBversion);
7824
    SetVersion($DBversion);
7825
}
7825
}
7826
7826
7827
$DBversion = "3.15.00.XXX";
7828
if ( CheckVersion($DBversion) ) {
7829
    $dbh->do(q{
7830
        ALTER TABLE opac_news ADD branchcode varchar(10) NULL DEFAULT NULL,
7831
                              ADD CONSTRAINT opac_news_branchcode_ibfk
7832
                                  FOREIGN KEY (branchcode)
7833
                                  REFERENCES branches (branchcode)
7834
                                  ON DELETE CASCADE ON UPDATE CASCADE;
7835
    });
7836
    print "Upgrade to $DBversion done (Bug 7567: Add branchcode to opac_news)\n";
7837
    SetVersion($DBversion);
7838
}
7839
7827
7840
7828
=head1 FUNCTIONS
7841
=head1 FUNCTIONS
7829
7842
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt (-32 / +102 lines)
Lines 56-63 Edit News Item[% ELSE %]Add News Item[% END %][% ELSE %]News[% END %]</div> Link Here
56
56
57
[% IF ( add_form ) %]<div id="doc" class="yui-t7">[% ELSE %]<div id="doc3" class="yui-t2">[% END %]
57
[% IF ( add_form ) %]<div id="doc" class="yui-t7">[% ELSE %]<div id="doc3" class="yui-t2">[% END %]
58
   <div id="bd">
58
   <div id="bd">
59
	<div id="yui-main">
59
        <div id="yui-main">
60
	<div class="yui-b">
60
        <div class="yui-b">
61
61
62
[% UNLESS ( add_form ) %]
62
[% UNLESS ( add_form ) %]
63
<div id="toolbar" class="btn-toolbar">
63
<div id="toolbar" class="btn-toolbar">
Lines 69-99 Edit News Item[% ELSE %]Add News Item[% END %][% ELSE %]News[% END %]</div> Link Here
69
        <form name="add_form" method="post" action="/cgi-bin/koha/tools/koha-news.pl" >
69
        <form name="add_form" method="post" action="/cgi-bin/koha/tools/koha-news.pl" >
70
            <input type="hidden" name="op" value="[% op %]" />
70
            <input type="hidden" name="op" value="[% op %]" />
71
            <input type="hidden" name="id" value="[% id %]" />
71
            <input type="hidden" name="id" value="[% id %]" />
72
			<fieldset class="rows">
72
                        <fieldset class="rows">
73
            <legend>OPAC and Koha news</legend>
73
            <legend>OPAC and Koha news</legend>
74
           <ol> <li>
74
           <ol> <li>
75
            <label for="lang">Display location</label>
75
            <label for="lang">Display location</label>
76
            <select id="lang" name="lang">
76
            <select id="lang" name="lang">
77
                <option value="koha">Librarian interface</option>
77
            [% IF ( new_detail.lang == ""     ) %]
78
                [% IF ( slip ) %]<option value="slip" selected="selected">Slip</option>[% ELSE %]<option value="slip">Slip</option>[% END %]
78
                <option value="" selected>All</option>
79
                [% FOREACH lang_lis IN lang_list %]
79
            [% ELSE %]
80
                    [% IF ( lang_lis.selected ) %]<option value="[% lang_lis.language %]" selected="selected">OPAC ([% lang_lis.language %])</option>[% ELSE %]<option value="[% lang_lis.language %]">OPAC ([% lang_lis.language %])</option>[% END %]
80
                <option value=""         >All</option>
81
                [% END %]
81
            [% END %]
82
            [% IF ( new_detail.lang == "koha"     ) %]
83
                <option value="koha" selected>Librarian interface</option>
84
            [% ELSE %]
85
                <option value="koha"         >Librarian interface</option>
86
            [% END %]
87
            [% IF ( new_detail.lang == "slip"     ) %]
88
                <option value="slip" selected>Slip</option>
89
            [% ELSE %]
90
                <option value="slip"         >Slip</option>
91
            [% END %]
92
            [% FOREACH lang_lis IN lang_list %]
93
            [% IF ( lang_lis.language == new_detail.lang ) %]
94
                <option value="[% lang_lis.language %]" selected>OPAC ([% lang_lis.language %])</option>
95
            [% ELSE %]
96
                <option value="[% lang_lis.language %]"         >OPAC ([% lang_lis.language %])</option>
97
            [% END %]
98
            [% END %]
82
            </select>
99
            </select>
83
            </li>
100
            </li>
84
            <li>
101
            <li>
102
                <label for="branch">Branch: </label>
103
                <select id="branch" name="branch">
104
                [% IF ( new_detail.branchcode == "" ) %]
105
                    <option value="" selected>All Branches</option>
106
                [% ELSE %]
107
                    <option value=""         >All Branches</option>
108
                [% END %]
109
                [% FOREACH branch_item IN branch_list %]
110
                [% IF ( branch_item.value.branchcode ==
111
                        new_detail.branchcode ) %]
112
                    <option value="[% branch_item.value.branchcode %]"
113
                            selected>[% branch_item.value.branchname %]
114
                    </option>
115
                [% ELSE %]
116
                    <option value="[% branch_item.value.branchcode %]"
117
                                    >[% branch_item.value.branchname %]
118
                    </option>
119
                [% END %]
120
                [% END %]
121
                </select>
122
            </li>
123
            <li>
85
                <label for="title">Title: </label>
124
                <label for="title">Title: </label>
86
                <input id="title" size="30" type="text" name="title" value="[% new_detail.title %]" />
125
                <input id="title" size="30" type="text" name="title" value="[% new_detail.title %]" />
87
            </li>
126
            </li>
88
            <li>
127
            <li>
89
                <label for="from">Publication date: </label>
128
                <label for="from">Publication date: </label>
90
                <input id="from" type="text" name="timestamp" size="15" value="[% new_detail.timestamp %]" class="datepickerfrom" />
129
                <input id="from" type="text" name="timestamp" size="15" value="[% new_detail.timestamp %]" class="datepickerfrom" />
91
				<div class="hint">[% INCLUDE 'date-format.inc' %]</div>
130
                                <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
92
            </li>
131
            </li>
93
            <li>
132
            <li>
94
                <label for="to">Expiration date: </label>
133
                <label for="to">Expiration date: </label>
95
                <input id="to" type="text" name="expirationdate" size="15" value="[% new_detail.expirationdate %]" class="datepickerto" />
134
                <input id="to" type="text" name="expirationdate" size="15" value="[% new_detail.expirationdate %]" class="datepickerto" />
96
				<div class="hint">[% INCLUDE 'date-format.inc' %]</div>
135
                                <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
97
            </li>
136
            </li>
98
            <li>
137
            <li>
99
                <label for="number">Appear in position: </label>
138
                <label for="number">Appear in position: </label>
Lines 106-112 Edit News Item[% ELSE %]Add News Item[% END %][% ELSE %]News[% END %]</div> Link Here
106
            <li><label for="new">News: </label>
145
            <li><label for="new">News: </label>
107
            <textarea name="new" id="new"  cols="75" rows="10">[% new_detail.new %]</textarea></li>
146
            <textarea name="new" id="new"  cols="75" rows="10">[% new_detail.new %]</textarea></li>
108
            </ol>
147
            </ol>
109
			</fieldset>
148
                        </fieldset>
110
  
149
  
111
                <fieldset class="action"><input class="button" type="submit" value="Submit" /> <a class="cancel" href="/cgi-bin/koha/tools/koha-news.pl">Cancel</a></fieldset>
150
                <fieldset class="action"><input class="button" type="submit" value="Submit" /> <a class="cancel" href="/cgi-bin/koha/tools/koha-news.pl">Cancel</a></fieldset>
112
        </form>
151
        </form>
Lines 115-131 Edit News Item[% ELSE %]Add News Item[% END %][% ELSE %]News[% END %]</div> Link Here
115
        <form name="add_form" method="post" action="/cgi-bin/koha/tools/koha-news.pl" >
154
        <form name="add_form" method="post" action="/cgi-bin/koha/tools/koha-news.pl" >
116
            <label for="lang">Display location:</label>
155
            <label for="lang">Display location:</label>
117
            <select name="lang" id="lang">
156
            <select name="lang" id="lang">
118
            <option value="">All</option>
157
            [% IF ( lang == ""     ) %]
119
            <option value="koha">Librarian interface</option>
158
                <option value="" selected>All</option>
120
	    <option value="slip">Slip</option>
159
            [% ELSE %]
121
                [% FOREACH lang_lis IN lang_list %]
160
                <option value=""         >All</option>
122
                    [% IF ( lang_lis.selected ) %]
161
            [% END %]
123
                        <option value="[% lang_lis.language %]" selected="selected">
162
            [% IF ( lang == "koha"     ) %]
124
                    [% ELSE %]
163
                <option value="koha" selected>Librarian interface</option>
125
                        <option value="[% lang_lis.language %]">
164
            [% ELSE %]
126
                    [% END %]
165
                <option value="koha"         >Librarian interface</option>
127
                        OPAC ([% lang_lis.language %])
166
            [% END %]
167
            [% IF ( lang == "slip"     ) %]
168
                <option value="slip" selected>Slip</option>
169
            [% ELSE %]
170
                <option value="slip"         >Slip</option>
171
            [% END %]
172
            [% FOREACH lang_lis IN lang_list %]
173
            [% IF ( lang_lis.language == lang ) %]
174
                <option value="[% lang_lis.language %]" selected>OPAC ([% lang_lis.language %])</option>
175
            [% ELSE %]
176
                <option value="[% lang_lis.language %]"         >OPAC ([% lang_lis.language %])</option>
177
            [% END %]
178
            [% END %]
179
            </select>
180
            <label for="branch">Branch: </label>
181
            <select id="branch" name="branch">
182
                [% IF ( branchcode == "" ) %]
183
                    <option value="" selected>All Branches</option>
184
                [% ELSE %]
185
                    <option value=""         >All Branches</option>
186
                [% END %]
187
                [% FOREACH branch_item IN branch_list %]
188
                [% IF ( branch_item.value.branchcode == branchcode ) %]
189
                    <option value="[% branch_item.value.branchcode %]"
190
                            selected>[% branch_item.value.branchname %]
128
                    </option>
191
                    </option>
192
                [% ELSE %]
193
                    <option value="[% branch_item.value.branchcode %]"
194
                                    >[% branch_item.value.branchname %]
195
                    </option>
196
                [% END %]
129
                [% END %]
197
                [% END %]
130
            </select>
198
            </select>
131
            <input type="submit" class="button" value="Filter" />
199
            <input type="submit" class="button" value="Filter" />
Lines 137-142 Edit News Item[% ELSE %]Add News Item[% END %][% ELSE %]News[% END %]</div> Link Here
137
                   <thead> <tr>
205
                   <thead> <tr>
138
                        <th>&nbsp;</th>
206
                        <th>&nbsp;</th>
139
                        <th>Location</th>
207
                        <th>Location</th>
208
                        <th>Branch</th>
140
                        <th>Number</th>
209
                        <th>Number</th>
141
                        <th>Creation date</th>
210
                        <th>Creation date</th>
142
                        <th>Expiration date</th>
211
                        <th>Expiration date</th>
Lines 153-169 Edit News Item[% ELSE %]Add News Item[% END %][% ELSE %]News[% END %]</div> Link Here
153
                            <td>
222
                            <td>
154
                                <input type="checkbox" name="ids" value="[% opac_new.idnew %]" />
223
                                <input type="checkbox" name="ids" value="[% opac_new.idnew %]" />
155
                            </td>
224
                            </td>
156
                            <td>[% IF ( opac_new.lang == 'koha' ) %]
225
                            <td>[% SWITCH opac_new.lang %]
157
			            Librarian interface
226
                                [%   CASE 'koha' %]
158
                                 [% ELSE %]
227
                                    Librarian interface
159
                                    [% IF ( opac_new.lang == 'slip' ) %]
228
                                [%   CASE 'slip' %]
160
				        Slip
229
                                    Slip
161
                                    [% ELSE %]
230
                                [%   CASE '' %]
162
                                        OPAC
231
                                    All
163
				    [% END %]
232
                                [%   CASE %]
164
				 [% END %]
233
                                    OPAC ([% opac_new.lang %])
165
                             </td>
234
                                [% END %]
166
235
                            </td>
236
                            <td>[% opac_new.branchname %]</td>
167
                            <td>[% opac_new.number %]</td>
237
                            <td>[% opac_new.number %]</td>
168
                            <td>[% opac_new.newdate %]</td>
238
                            <td>[% opac_new.newdate %]</td>
169
                            <td>[% opac_new.expirationdate %] [% IF ( opac_new.expired ) %](<span class="expired">expired</span>)[% END %]</td>
239
                            <td>[% opac_new.expirationdate %] [% IF ( opac_new.expired ) %](<span class="expired">expired</span>)[% END %]</td>
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-main.tt (-4 / +4 lines)
Lines 19-28 Link Here
19
         [% END %]
19
         [% END %]
20
     [% ELSE %]
20
     [% ELSE %]
21
        <div id="notloggedin" class="yui-ge">
21
        <div id="notloggedin" class="yui-ge">
22
    [% END %]
22
     [% END %]
23
        <div class="yui-u first">
23
        <div class="yui-u first">
24
        <div id="news" class="container">
24
	[% IF ( koha_news_count ) %]
25
	[% IF ( koha_news_count ) %]
25
<div id="news" class="container">
26
    <table>
26
    <table>
27
    [% FOREACH koha_new IN koha_news %]
27
    [% FOREACH koha_new IN koha_news %]
28
    <tr><th>[% koha_new.title %]</th></tr>
28
    <tr><th>[% koha_new.title %]</th></tr>
Lines 30-37 Link Here
30
                <p class="newsfooter"><i>(published on [% koha_new.newdate %])</i></p></td></tr>
30
                <p class="newsfooter"><i>(published on [% koha_new.newdate %])</i></p></td></tr>
31
    [% END %]
31
    [% END %]
32
    </table>
32
    </table>
33
</div>
33
        [% END %]
34
[% END %]
34
        </div>
35
35
36
      [% IF ( display_daily_quote && daily_quote ) %]
36
      [% IF ( display_daily_quote && daily_quote ) %]
37
    <div id="daily-quote" class="container"><h1>Quote of the Day</h1><div><span id="daily-quote-text">[% daily_quote.text %]</span><span id="daily-quote-sep"> ~ </span><span id="daily-quote-source">[% daily_quote.source %]</span></div></div>
37
    <div id="daily-quote" class="container"><h1>Quote of the Day</h1><div><span id="daily-quote-text">[% daily_quote.text %]</span><span id="daily-quote-sep"> ~ </span><span id="daily-quote-source">[% daily_quote.source %]</span></div></div>
(-)a/mainpage.pl (-1 / +5 lines)
Lines 42-48 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( Link Here
42
    }
42
    }
43
);
43
);
44
44
45
my $all_koha_news   = &GetNewsToDisplay("koha");
45
my $homebranch;
46
if (C4::Context->userenv) {
47
    $homebranch = C4::Context->userenv->{'branch'};
48
}
49
my $all_koha_news   = &GetNewsToDisplay("koha",$homebranch);
46
my $koha_news_count = scalar @$all_koha_news;
50
my $koha_news_count = scalar @$all_koha_news;
47
51
48
$template->param(
52
$template->param(
(-)a/opac/opac-main.pl (-4 / +7 lines)
Lines 16-27 Link Here
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
17
18
18
19
use strict;
19
use Modern::Perl;
20
use warnings;
21
use CGI;
20
use CGI;
22
use C4::Auth;    # get_template_and_user
21
use C4::Auth;    # get_template_and_user
23
use C4::Output;
22
use C4::Output;
24
use C4::NewsChannels;    # get_opac_news
23
use C4::NewsChannels;    # GetNewsToDisplay
25
use C4::Languages qw(getTranslatedLanguages accept_language);
24
use C4::Languages qw(getTranslatedLanguages accept_language);
26
use C4::Koha qw( GetDailyQuote );
25
use C4::Koha qw( GetDailyQuote );
27
26
Lines 48-54 $template->param( Link Here
48
# use cookie setting for language, bug default to syspref if it's not set
47
# use cookie setting for language, bug default to syspref if it's not set
49
my ($theme, $news_lang, $availablethemes) = C4::Templates::themelanguage(C4::Context->config('opachtdocs'),'opac-main.tt','opac',$input);
48
my ($theme, $news_lang, $availablethemes) = C4::Templates::themelanguage(C4::Context->config('opachtdocs'),'opac-main.tt','opac',$input);
50
49
51
my $all_koha_news   = &GetNewsToDisplay($news_lang);
50
my $homebranch;
51
if (C4::Context->userenv) {
52
    $homebranch = C4::Context->userenv->{'branch'} // '';
53
}
54
my $all_koha_news   = &GetNewsToDisplay($news_lang,$homebranch);
52
my $koha_news_count = scalar @$all_koha_news;
55
my $koha_news_count = scalar @$all_koha_news;
53
56
54
my $quote = GetDailyQuote();   # other options are to pass in an exact quote id or select a random quote each pass... see perldoc C4::Koha
57
my $quote = GetDailyQuote();   # other options are to pass in an exact quote id or select a random quote each pass... see perldoc C4::Koha
(-)a/t/NewsChannels.t (-14 lines)
Lines 1-14 Link Here
1
#!/usr/bin/perl
2
#
3
# This Koha test module is a stub!  
4
# Add more tests here!!!
5
6
use strict;
7
use warnings;
8
9
use Test::More tests => 1;
10
11
BEGIN {
12
        use_ok('C4::NewsChannels');
13
}
14
(-)a/t/db_dependent/NewsChannels.t (+120 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
#
3
# This Koha test module is a stub!
4
# Add more tests here!!!
5
6
use Modern::Perl;
7
use C4::Dates qw(format_date);
8
use C4::Branch qw(GetBranchName);
9
use Test::More tests => 8;
10
11
BEGIN {
12
        use_ok('C4::NewsChannels');
13
}
14
15
16
my $dbh = C4::Context->dbh;
17
18
# Start transaction
19
$dbh->{AutoCommit} = 0;
20
$dbh->{RaiseError} = 1;
21
22
# Add LIB1, if it doesn't exist.
23
my $addbra = 'LIB1';
24
$dbh->do(q{
25
    INSERT INTO branches (branchcode,branchname) VALUES (?,?)
26
          }, undef,      ($addbra,   "$addbra branch")
27
        ) unless GetBranchName($addbra);
28
29
# Test add_opac_new
30
my $timestamp = '2000-01-01';
31
my $hashref_entry1 = {
32
  'title'          => 'News Title',
33
  'new'            => '<p>We have some exciting news!</p>',
34
  'lang'           => '',
35
  'timestamp'      => $timestamp,
36
  'expirationdate' => '2999-12-30',
37
  'number'         => 1,
38
  'branchcode'     => 'LIB1',
39
                  };
40
my $rv = add_opac_new( $hashref_entry1 );
41
ok($rv==1,"Successfully added the first dummy news item!");
42
43
my $hashref_entry2 = {
44
  "title"          => 'News Title2',
45
  "new"            => '<p>We have some exciting news!</p>',
46
  "lang"           => '',
47
  "timestamp"      => $timestamp,
48
  "expirationdate" => '2999-12-31',
49
  "number"         => 1,
50
  "branchcode"     => 'LIB1',
51
                     };
52
$rv = add_opac_new( $hashref_entry2 );
53
ok($rv==1,"Successfully added the second dummy news item!");
54
55
# We need to determine the idnew in a non-MySQLism way.
56
# This should be good enough.
57
my $sth = $dbh->prepare(q{
58
  SELECT idnew from opac_news
59
  WHERE timestamp='2000-01-01' AND
60
        expirationdate='2999-12-30' AND
61
        branchcode='LIB1';
62
                        });
63
$sth->execute();
64
my $idnew1 = $sth->fetchrow;
65
$sth = $dbh->prepare(q{
66
  SELECT idnew from opac_news
67
  WHERE timestamp='2000-01-01' AND
68
        expirationdate='2999-12-31' AND
69
        branchcode='LIB1';
70
                        });
71
$sth->execute();
72
my $idnew2 = $sth->fetchrow;
73
74
# Test upd_opac_new
75
$hashref_entry2->{new} = '<p>Update! There is no news!</p>';
76
$hashref_entry2->{idnew} = $idnew2;
77
$rv = upd_opac_new($hashref_entry2);
78
ok($rv==1,"Successfully updated second dummy news item!");
79
80
# Test get_opac_new (single news item)
81
$hashref_entry1->{timestamp} =
82
  format_date( $hashref_entry1->{timestamp} );
83
$hashref_entry1->{expirationdate} =
84
  format_date( $hashref_entry1->{expirationdate} );
85
$hashref_entry2->{timestamp} =
86
  format_date( $hashref_entry2->{timestamp} );
87
$hashref_entry2->{expirationdate} =
88
  format_date( $hashref_entry2->{expirationdate} );
89
my $hashref_check = get_opac_new($idnew1);
90
my $failure = 0;
91
foreach my $key (keys %{$hashref_entry1}) {
92
    if ($hashref_entry1->{$key} ne $hashref_check->{$key}) {
93
        $failure = 1;
94
        print STDERR "\nKey mismatch: " . $hashref_entry1->{$key} . " vs ";
95
        print STDERR $hashref_check->{$key} . "\n";
96
    }
97
}
98
ok($failure==0,"Successfully tested get_opac_new id1!");
99
100
# Test get_opac_new (single news item)
101
$hashref_check = get_opac_new($idnew2);
102
$failure = 0;
103
foreach my $key (keys %{$hashref_entry2}) {
104
    if ($hashref_entry2->{$key} ne $hashref_check->{$key}) {
105
        $failure = 1;
106
        print STDERR "\nKey mismatch: " . $hashref_entry1->{$key} . " vs ";
107
        print STDERR $hashref_check->{$key} . "\n";
108
    }
109
}
110
ok($failure==0,"Successfully tested get_opac_new id2!");
111
112
# Test get_opac_news (multiple news items)
113
my ($opac_news_count, $arrayref_opac_news) = get_opac_news(0,'','LIB1');
114
ok($opac_news_count>=2,"Successfully tested get_opac_news for LIB1!");
115
116
# Test GetNewsToDisplay
117
($opac_news_count, $arrayref_opac_news) = GetNewsToDisplay('','LIB1');
118
ok($opac_news_count>=2,"Successfully tested GetNewsToDisplay for LIB1!");
119
120
$dbh->rollback;
(-)a/tools/koha-news.pl (-7 / +35 lines)
Lines 32-37 use C4::Output; Link Here
32
use C4::NewsChannels;
32
use C4::NewsChannels;
33
use C4::Languages qw(getTranslatedLanguages);
33
use C4::Languages qw(getTranslatedLanguages);
34
use Date::Calc qw/Date_to_Days Today/;
34
use Date::Calc qw/Date_to_Days Today/;
35
use C4::Branch qw/GetBranches/;
35
36
36
my $cgi = new CGI;
37
my $cgi = new CGI;
37
38
Lines 42-47 my $expirationdate = format_date_in_iso($cgi->param('expirationdate')); Link Here
42
my $timestamp      = format_date_in_iso($cgi->param('timestamp'));
43
my $timestamp      = format_date_in_iso($cgi->param('timestamp'));
43
my $number         = $cgi->param('number');
44
my $number         = $cgi->param('number');
44
my $lang           = $cgi->param('lang');
45
my $lang           = $cgi->param('lang');
46
my $branchcode     = $cgi->param('branch');
47
# Foreign Key constraints work with NULL, not ''
48
# NULL = All branches.
49
$branchcode = undef if (defined($branchcode) && $branchcode eq '');
50
my $hashref_entry;
45
51
46
my $new_detail = get_opac_new($id);
52
my $new_detail = get_opac_new($id);
47
53
Lines 67-75 foreach my $language ( @$tlangs ) { Link Here
67
      };
73
      };
68
}
74
}
69
75
70
$template->param( lang_list => \@lang_list );
76
my $branches = GetBranches;
71
77
72
my $op = $cgi->param('op');
78
$template->param( lang_list   => \@lang_list,
79
                  branch_list => $branches,
80
                  branchcode => $branchcode );
81
82
my $op = $cgi->param('op') // '';
73
83
74
if ( $op eq 'add_form' ) {
84
if ( $op eq 'add_form' ) {
75
    $template->param( add_form => 1 );
85
    $template->param( add_form => 1 );
Lines 86-96 if ( $op eq 'add_form' ) { Link Here
86
    }
96
    }
87
}
97
}
88
elsif ( $op eq 'add' ) {
98
elsif ( $op eq 'add' ) {
89
    add_opac_new( $title, $new, $lang, $expirationdate, $timestamp, $number );
99
    $hashref_entry = {
100
                    "title"          => $title,
101
                    "new"            => $new,
102
                    "lang"           => $lang,
103
                    "timestamp"      => $timestamp,
104
                    "expirationdate" => $expirationdate,
105
                    "number"         => $number,
106
                    "branchcode"     => $branchcode,
107
                  };
108
    add_opac_new( $hashref_entry );
90
    print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
109
    print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
91
}
110
}
92
elsif ( $op eq 'edit' ) {
111
elsif ( $op eq 'edit' ) {
93
    upd_opac_new( $id, $title, $new, $lang, $expirationdate, $timestamp ,$number );
112
    $hashref_entry = {
113
                    "idnew"          => $id,
114
                    "title"          => $title,
115
                    "new"            => $new,
116
                    "lang"           => $lang,
117
                    "timestamp"      => $timestamp,
118
                    "expirationdate" => $expirationdate,
119
                    "number"         => $number,
120
                    "branchcode"     => $branchcode,
121
                  };
122
    upd_opac_new( $hashref_entry );
94
    print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
123
    print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
95
}
124
}
96
elsif ( $op eq 'del' ) {
125
elsif ( $op eq 'del' ) {
Lines 101-107 elsif ( $op eq 'del' ) { Link Here
101
130
102
else {
131
else {
103
132
104
    my ( $opac_news_count, $opac_news ) = &get_opac_news( undef, $lang );
133
    my ( $opac_news_count, $opac_news ) = &get_opac_news( 0, $lang, $branchcode );
105
    
134
    
106
    foreach my $new ( @$opac_news ) {
135
    foreach my $new ( @$opac_news ) {
107
        next unless $new->{'expirationdate'};
136
        next unless $new->{'expirationdate'};
Lines 113-121 else { Link Here
113
    }
142
    }
114
    
143
    
115
    $template->param(
144
    $template->param(
116
        $lang           => 1,
117
        opac_news       => $opac_news,
145
        opac_news       => $opac_news,
118
        opac_news_count => $opac_news_count,
146
        opac_news_count => $opac_news_count,
119
		);
147
		);
148
    $template->param( lang => $lang );
120
}
149
}
121
output_html_with_http_headers $cgi, $cookie, $template->output;
150
output_html_with_http_headers $cgi, $cookie, $template->output;
122
- 

Return to bug 7567