From 7df8ef5f9b6e57a3a6f13b70b71ccf855306ecc3 Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 14 May 2003 13:31:23 +0000 Subject: [PATCH] added support for active news items --- lib/dashboard/DashboardNews.inc | 41 ++++++++++++++++++++++++++++++++++++----- presentation/lookAndFeel/knowledgeTree/administration/news/addNewsBL.php | 1 + presentation/lookAndFeel/knowledgeTree/administration/news/editNewsBL.php | 1 + presentation/lookAndFeel/knowledgeTree/administration/news/newsUI.inc | 15 ++++++++------- presentation/lookAndFeel/knowledgeTree/dashboardUI.inc | 2 +- sql/tables.sql | 3 ++- 6 files changed, 49 insertions(+), 14 deletions(-) diff --git a/lib/dashboard/DashboardNews.inc b/lib/dashboard/DashboardNews.inc index 26fd676..4784ead 100644 --- a/lib/dashboard/DashboardNews.inc +++ b/lib/dashboard/DashboardNews.inc @@ -5,7 +5,7 @@ require_once("$default->fileSystemRoot/lib/documentmanagement/PhysicalDocumentMa /** * $Id$ * - * Represents a dahsboard news item. + * Represents a dashboard news item. * * Licensed under the GNU GPL. For full terms see the file COPYING. * @@ -52,6 +52,10 @@ class DashboardNews { * The maximum allowable height of an image */ var $iMaxImageHeight = 40; + /** + * Is this news item active + */ + var $bActive; /** * Constructs a news item @@ -199,6 +203,22 @@ class DashboardNews { } /** + * Retrieve the active status + */ + function getActive() { + return $this->bActive; + } + + /** + * Set the active status + * + * @param boolean new active status + */ + function setActive($bNewActive) { + $this->bActive = $bNewActive; + } + + /** * Retrieve the maximum image width */ function getMaxImageWidth() { @@ -274,9 +294,9 @@ class DashboardNews { //if the id >= 0, then the object has already been created if ($this->iId < 0) { $sql = $default->db; - $result = $sql->query("INSERT INTO $default->owl_news_table (synopsis, body, rank, image, image_size, image_mime_type_id) " . + $result = $sql->query("INSERT INTO $default->owl_news_table (synopsis, body, rank, image, image_size, image_mime_type_id, active) " . "VALUES ('" . addslashes($this->sSynopsis) . "', '" . addslashes($this->sBody) . "', $this->iRank, " . - "'" . addslashes($this->sImage) . "', $this->iImageSize, $this->iImageMimeTypeID)"); + "'" . addslashes($this->sImage) . "', $this->iImageSize, $this->iImageMimeTypeID, " . ($this->bActive ? "1" : "0") . ")"); if ($result) { //set the current news item primary key $this->iId = $sql->insert_id(); @@ -302,11 +322,21 @@ class DashboardNews { "rank = $this->iRank, " . "image = '" . addslashes($this->sImage) . "', " . "image_size = $this->iImageSize " . - ($this->iImageMimeTypeID ? ", image_mime_type_id = $this->iImageMimeTypeID " : "") . + ($this->iImageMimeTypeID ? ", image_mime_type_id = $this->iImageMimeTypeID " : " ") . "WHERE id = $this->iId"; + $result = $sql->query($sQuery); if ($result) { - return true; + if ($this->bActive) { + // we're setting this entry to active, so set all the others to inactive + $sql->query("UPDATE $default->owl_news_table SET active=0"); + // now set our entry to active + $sql->query("UPDATE $default->owl_news_table SET active=1 where id=$this->iId"); + } else { + // set this to inactive + $sql->query("UPDATE $default->owl_news_table SET active=0 where id=$this->iId"); + } + return true; } return false; } @@ -350,6 +380,7 @@ class DashboardNews { "mimetypeid" => $sql->f("image_mime_type_id") ); $oDashboardNews = & new DashboardNews(stripslashes($sql->f("synopsis")), stripslashes($sql->f("body")), $sql->f("rank"), $aImage); $oDashboardNews->iId = $iNewsID; + $oDashboardNews->setActive($sql->f("active")); return $oDashboardNews; } return false; diff --git a/presentation/lookAndFeel/knowledgeTree/administration/news/addNewsBL.php b/presentation/lookAndFeel/knowledgeTree/administration/news/addNewsBL.php index b60f4ad..7b2d150 100644 --- a/presentation/lookAndFeel/knowledgeTree/administration/news/addNewsBL.php +++ b/presentation/lookAndFeel/knowledgeTree/administration/news/addNewsBL.php @@ -29,6 +29,7 @@ if (checkSession()) { if ($fStore) { // construct the news object $oDashboardNews = new DashboardNews($fSynopsis, $fBody, $fRank); + $oDashboardNews->setActive($fActive); if (isset($fSynopsis) && isset($fBody) && isset($fRank)) { // if we have a new image diff --git a/presentation/lookAndFeel/knowledgeTree/administration/news/editNewsBL.php b/presentation/lookAndFeel/knowledgeTree/administration/news/editNewsBL.php index e54a328..8b364b5 100644 --- a/presentation/lookAndFeel/knowledgeTree/administration/news/editNewsBL.php +++ b/presentation/lookAndFeel/knowledgeTree/administration/news/editNewsBL.php @@ -41,6 +41,7 @@ if (checkSession()) { if ($oDashboardNews->getRank() <> $fRank) { $oDashboardNews->setRank($fRank); } + $oDashboardNews->setActive($fActive); // if we have a new image if (strlen($_FILES['fImage']['name']) > 0) { // return the size of the image diff --git a/presentation/lookAndFeel/knowledgeTree/administration/news/newsUI.inc b/presentation/lookAndFeel/knowledgeTree/administration/news/newsUI.inc index bd91ac6..53cc01f 100644 --- a/presentation/lookAndFeel/knowledgeTree/administration/news/newsUI.inc +++ b/presentation/lookAndFeel/knowledgeTree/administration/news/newsUI.inc @@ -30,16 +30,16 @@ function renderErrorMessage($sErrorMessage) { */ function renderNewsTable() { global $default; - $sQuery = "SELECT id, synopsis, IF(LENGTH(body) > 25, CONCAT(LEFT(body,25),'...'), body) AS body, rank, IF(LENGTH(image)>0, 'yes', 'no') as image, 'Edit' AS edit, 'Preview' AS preview, 'Delete' AS del " . + $sQuery = "SELECT id, synopsis, IF(LENGTH(body) > 25, CONCAT(LEFT(body,25),'...'), body) AS body, rank, IF(LENGTH(image)>0, 'yes', 'no') as image, active, 'Edit' AS edit, 'Preview' AS preview, 'Delete' AS del " . "FROM $default->owl_news_table ORDER BY rank ASC"; - $aColumns = array("synopsis", "body", "rank", "image", "edit", "preview", "del"); - $aColumnHeaders = array("Synopsis", "Body", "Rank", "Image"); - $aColumnTypes = array(1,1,1,1,3,3,3); + $aColumns = array("synopsis", "body", "rank", "image", "active", "edit", "preview", "del"); + $aColumnHeaders = array("Synopsis", "Body", "Rank", "Image", "Active"); + $aColumnTypes = array(1,1,1,1,2,3,3,3); $aDBColumnArray = array("id"); $aQueryStringVariableNames = array("fNewsID"); - $aLinkURLs = array(4=> "$default->rootUrl/control.php?action=editNews", - 5=> "$default->rootUrl/control.php?action=previewNews", - 6=> "$default->rootUrl/control.php?action=removeNews"); + $aLinkURLs = array(5=> "$default->rootUrl/control.php?action=editNews", + 6=> "$default->rootUrl/control.php?action=previewNews", + 7=> "$default->rootUrl/control.php?action=removeNews"); $oPatternTableSqlQuery = & new PatternTableSqlQuery($sQuery, $aColumns, $aColumnTypes, $aColumnHeaders, "100%", $aLinkURLs,$aDBColumnArray,$aQueryStringVariableNames); $oPatternTableSqlQuery->setTableHeading("Dashboard News"); @@ -77,6 +77,7 @@ function renderEditAddNewsForm($oDashboardNews, $bUpdate) { $sToRender .= "Body:"; $sToRender .= "Rank:getRank() : "") . "\">"; $sToRender .= "Image:"; + $sToRender .= "Active:getActive() ? "checked" : "") : "") . "\">"; if ($bUpdate) { $sToRender .= "getID() . "\">"; diff --git a/presentation/lookAndFeel/knowledgeTree/dashboardUI.inc b/presentation/lookAndFeel/knowledgeTree/dashboardUI.inc index 921fb86..3cd0a22 100644 --- a/presentation/lookAndFeel/knowledgeTree/dashboardUI.inc +++ b/presentation/lookAndFeel/knowledgeTree/dashboardUI.inc @@ -150,7 +150,7 @@ function renderDashboardNews() { global $default; // retrieve all news items - $aDashboardNews = DashboardNews::getList(); + $aDashboardNews = DashboardNews::getList("active=1"); $sToRender .= "\t\t\t\n"; // the main news item diff --git a/sql/tables.sql b/sql/tables.sql index 102f024..941d912 100644 --- a/sql/tables.sql +++ b/sql/tables.sql @@ -250,7 +250,8 @@ body TEXT, rank INTEGER, image TEXT, image_size INTEGER, -image_mime_type_id INTEGER +image_mime_type_id INTEGER, +active BIT ) TYPE = InnoDB; CREATE TABLE organisations_lookup ( -- libgit2 0.21.4