Add a date field in news edition, and permit to set the "timestamp" field, that is...
authorNahuel Angelinetti <nahuel.angelinetti@biblibre.com>
Fri, 6 Mar 2009 10:38:00 +0000 (11:38 +0100)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Tue, 26 May 2009 18:52:41 +0000 (20:52 +0200)
Signed-off-by: Henri-Damien LAURENT <henridamien.laurent@biblibre.com>
Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
C4/NewsChannels.pm
koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tmpl [changed mode: 0644->0755]
tools/koha-news.pl

index 5edf0f1..136cc5c 100644 (file)
@@ -234,16 +234,16 @@ sub update_channel_category {
 }
 
 sub add_opac_new {
-    my ($title, $new, $lang, $expirationdate, $number) = @_;
+    my ($title, $new, $lang, $expirationdate, $timestamp, $number) = @_;
     my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare("INSERT INTO opac_news (title, new, lang, expirationdate, number) VALUES (?,?,?,?,?)");
-    $sth->execute($title, $new, $lang, $expirationdate, $number);
+    my $sth = $dbh->prepare("INSERT INTO opac_news (title, new, lang, expirationdate, timestamp, number) VALUES (?,?,?,?,?,?)");
+    $sth->execute($title, $new, $lang, $expirationdate, $timestamp, $number);
     $sth->finish;
     return 1;
 }
 
 sub upd_opac_new {
-    my ($idnew, $title, $new, $lang, $expirationdate, $number) = @_;
+    my ($idnew, $title, $new, $lang, $expirationdate, $timestamp,$number) = @_;
     my $dbh = C4::Context->dbh;
     my $sth = $dbh->prepare("
         UPDATE opac_news SET 
@@ -251,10 +251,11 @@ sub upd_opac_new {
             new = ?,
             lang = ?,
             expirationdate = ?,
+            timestamp = ?,
             number = ?
         WHERE idnew = ?
     ");
-    $sth->execute($title, $new, $lang, $expirationdate,$number,$idnew);
+    $sth->execute($title, $new, $lang, $expirationdate, $timestamp,$number,$idnew);
     $sth->finish;
     return 1;
 }
@@ -280,6 +281,7 @@ sub get_opac_new {
     my $data = $sth->fetchrow_hashref;
     $data->{$data->{'lang'}} = 1;
     $data->{expirationdate} = format_date($data->{expirationdate});
+    $data->{timestamp}      = format_date($data->{timestamp});
     $sth->finish;
     return $data;
 }
@@ -330,6 +332,7 @@ sub GetNewsToDisplay {
         OR    expirationdate IS NULL
         OR    expirationdate = '00-00-0000'
       )
+      AND   `timestamp` < CURRENT_DATE()
       AND   lang = ?
       ORDER BY number
     ";                         # expirationdate field is NOT in ISO format?
old mode 100644 (file)
new mode 100755 (executable)
index 6aa4d76..09dca99
@@ -64,14 +64,28 @@ Edit News Item<!-- TMPL_ELSE -->Add News Item<!-- /TMPL_IF --><!-- TMPL_ELSE -->
                 <label for="title">Title</label>
                 <input id="title" size="30" type="text" name="title" value="<!-- TMPL_VAR NAME="title" -->" />
             </li>
+            <li>
+                <label for="timestamp">Publication date</label>
+                <input id="timestamp" type="text" name="timestamp" size="15" value="<!-- TMPL_VAR NAME="timestamp" -->" />
+                <img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" alt="Show Calendar" border="0" id="timestampButton" style="cursor: pointer;" />
+                <script type="text/javascript">
+                    Calendar.setup(
+                    {
+                        button : "timestampButton",
+                        inputField : "timestamp",
+                        ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
+                    }
+                    );
+                </script>
+            </li>
             <li>
                 <label for="expirationdate">Expiration date</label>
                 <input id="expirationdate" type="text" name="expirationdate" size="15" value="<!-- TMPL_VAR NAME="expirationdate" -->" />
-                               <img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" alt="Show Calendar" border="0" id="openCalendar" style="cursor: pointer;" />
+                <img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" alt="Show Calendar" border="0" id="openCalendar" style="cursor: pointer;" />
                 <script type="text/javascript">
                     Calendar.setup(
                     {
-                                               button : "openCalendar",
+                        button : "openCalendar",
                         inputField : "expirationdate",
                         ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                     }
index 3730c10..08b38c8 100755 (executable)
@@ -38,6 +38,7 @@ my $id             = $cgi->param('id');
 my $title          = $cgi->param('title');
 my $new            = $cgi->param('new');
 my $expirationdate = format_date_in_iso($cgi->param('expirationdate'));
+my $timestamp      = format_date_in_iso($cgi->param('timestamp'));
 my $number         = $cgi->param('number');
 my $lang           = $cgi->param('lang');
 
@@ -83,11 +84,11 @@ if ( $op eq 'add_form' ) {
     }
 }
 elsif ( $op eq 'add' ) {
-    add_opac_new( $title, $new, $lang, $expirationdate, $number );
+    add_opac_new( $title, $new, $lang, $expirationdate, $timestamp, $number );
     print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
 }
 elsif ( $op eq 'edit' ) {
-    upd_opac_new( $id, $title, $new, $lang, $expirationdate, $number );
+    upd_opac_new( $id, $title, $new, $lang, $expirationdate, $timestamp ,$number );
     print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
 }
 elsif ( $op eq 'del' ) {