From 094bb6e33423738cdbb4737d1025dad8361ae32a Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 29 May 2019 14:36:08 +0200 Subject: [news] Use date/time selection for expiry, not duration in hrs --- modules-available/news/config.json | 3 +- modules-available/news/page.inc.php | 35 ++++++++++++--------- modules-available/news/templates/page-news.html | 41 ++++++++++++++++++++++--- 3 files changed, 60 insertions(+), 19 deletions(-) diff --git a/modules-available/news/config.json b/modules-available/news/config.json index 23cd1443..2e090c1c 100644 --- a/modules-available/news/config.json +++ b/modules-available/news/config.json @@ -1,6 +1,7 @@ { "category": "main.content", "dependencies": [ - "js_stupidtable" + "js_stupidtable", + "bootstrap_datepicker" ] } \ No newline at end of file diff --git a/modules-available/news/page.inc.php b/modules-available/news/page.inc.php index 8e2b4e7e..7a09d437 100644 --- a/modules-available/news/page.inc.php +++ b/modules-available/news/page.inc.php @@ -121,24 +121,24 @@ class Page_News extends Page $lines = array(); $res = Database::simpleQuery("SELECT newsid, dateline, expires, title, content FROM vmchooser_pages WHERE type = :type ORDER BY dateline DESC LIMIT 20", ['type' => $this->pageType]); + $foundActive = false; while ($row = $res->fetch(PDO::FETCH_ASSOC)) { $row['dateline_s'] = Util::prettyTime($row['dateline']); $row['expires_s'] = $this->formatExpires($row['expires']); + if ($row['newsid'] == $this->newsId) { + $row['active'] = true; + } if ($row['expires'] < $NOW) { $row['muted'] = 'text-muted'; + } elseif (!$foundActive) { + $row['live'] = 'active'; + $foundActive = true; } - if ($row['newsid'] == $this->newsId) { - $row['active'] = 'active'; - } $row['content'] = substr(strip_tags(str_replace('>', '> ', $row['content'])), 0, 160); $lines[] = $row; } - $validity = ceil(($this->newsExpires - $NOW) / 3600); - if ($this->newsExpires === false || $validity > 24 * 365 * 5) { - $validity = ''; - } $data = array( 'withTitle' => self::TYPES[$this->pageType]['headline'], 'newsTypeName' => Dictionary::translate('type_' . $this->pageType, true), @@ -147,10 +147,16 @@ class Page_News extends Page 'currentContent' => $this->newsContent, 'currentTitle' => $this->newsTitle, 'type' => $this->pageType, - 'validity' => $validity, 'list' => $lines, 'hasSummernote' => $this->hasSummernote, ); + $validity = ceil(($this->newsExpires - $NOW) / 3600); + if ($this->newsExpires === false || $validity > 24 * 365 * 5) { + $data['infinite_checked'] = 'checked'; + $this->newsExpires = strtotime('+7 days 00:00:00'); + } + $data['enddate'] = date('Y-m-d', $this->newsExpires); + $data['endtime'] = date('H:i', $this->newsExpires); if (!User::hasPermission($this->pageType . '.save')) { $data['save'] = [ 'readonly' => 'readonly', @@ -221,11 +227,12 @@ class Page_News extends Page // check if news content were set by the user $newsTitle = Request::post('news-title', '', 'string'); $newsContent = Request::post('news-content', false, 'string'); - $validity = Request::post('validity', false, 'string'); - if ($validity === false || $validity === '') { - $validity = 86400 * 3650; // 10 Years + $infinite = (Request::post('infinite', '', 'string') !== ''); + if ($infinite) { + $expires = strtotime('+10 years 0:00'); } else { - $validity *= 3600; // Hours to seconds + $expires = strtotime(Request::post('enddate', 'today', 'string') . ' ' + . Request::post('endtime', '23:59', 'string')); } if (!empty($newsContent)) { // we got title and content, save it to DB @@ -240,7 +247,7 @@ class Page_News extends Page WHERE newsid = :newsid LIMIT 1', [ 'newsid' => $row['newsid'], 'dateline' => time(), - 'expires' => time() + $validity, + 'expires' => $expires, 'title' => $newsTitle, ]); return true; @@ -249,7 +256,7 @@ class Page_News extends Page Database::exec("INSERT INTO vmchooser_pages (dateline, expires, title, content, type) VALUES (:dateline, :expires, :title, :content, :type)", array( 'dateline' => time(), - 'expires' => time() + $validity, + 'expires' => $expires, 'title' => $newsTitle, 'content' => $newsContent, 'type' => $pageType, diff --git a/modules-available/news/templates/page-news.html b/modules-available/news/templates/page-news.html index 0543a414..1c944cb8 100644 --- a/modules-available/news/templates/page-news.html +++ b/modules-available/news/templates/page-news.html @@ -14,9 +14,30 @@ {{/withTitle}} -
- ({{lang_leaveEmptyInfinite}}) - +
+
+ +
+ + +
+
+
+
+ + + + +
+
+
+
+ + + + +
+
@@ -49,6 +70,7 @@ + @@ -59,7 +81,8 @@ {{#list}} - + + @@ -96,5 +119,15 @@ document.addEventListener("DOMContentLoaded", function () { {{#hasSummernote}} $('.summernote[readonly]').each(function() { $(this).summernote('disable'); }); {{/hasSummernote}} + var dateSettings = { + format: 'yyyy-mm-dd', + todayHighlight: true, + }; + $('.datepicker').datepicker(dateSettings); + var chf = function() { + $('#enddate, #endtime').prop('disabled', $('#infinite-checkbox').is(':checked')); + }; + $('#infinite-checkbox').change(chf); + chf(); }, false); // --> \ No newline at end of file -- cgit v1.2.3-55-g7522
{{lang_created}} {{lang_expires}} {{lang_title}}
{{#active}}{{/active}} {{dateline_s}} {{expires_s}}
{{title}}