Commit 7df8ef5f9b6e57a3a6f13b70b71ccf855306ecc3

Authored by michael
1 parent 832b7be8

added support for active news items


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1847 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/dashboard/DashboardNews.inc
@@ -5,7 +5,7 @@ require_once("$default->fileSystemRoot/lib/documentmanagement/PhysicalDocumentMa @@ -5,7 +5,7 @@ require_once("$default->fileSystemRoot/lib/documentmanagement/PhysicalDocumentMa
5 /** 5 /**
6 * $Id$ 6 * $Id$
7 * 7 *
8 - * Represents a dahsboard news item. 8 + * Represents a dashboard news item.
9 * 9 *
10 * Licensed under the GNU GPL. For full terms see the file COPYING. 10 * Licensed under the GNU GPL. For full terms see the file COPYING.
11 * 11 *
@@ -52,6 +52,10 @@ class DashboardNews { @@ -52,6 +52,10 @@ class DashboardNews {
52 * The maximum allowable height of an image 52 * The maximum allowable height of an image
53 */ 53 */
54 var $iMaxImageHeight = 40; 54 var $iMaxImageHeight = 40;
  55 + /**
  56 + * Is this news item active
  57 + */
  58 + var $bActive;
55 59
56 /** 60 /**
57 * Constructs a news item 61 * Constructs a news item
@@ -199,6 +203,22 @@ class DashboardNews { @@ -199,6 +203,22 @@ class DashboardNews {
199 } 203 }
200 204
201 /** 205 /**
  206 + * Retrieve the active status
  207 + */
  208 + function getActive() {
  209 + return $this->bActive;
  210 + }
  211 +
  212 + /**
  213 + * Set the active status
  214 + *
  215 + * @param boolean new active status
  216 + */
  217 + function setActive($bNewActive) {
  218 + $this->bActive = $bNewActive;
  219 + }
  220 +
  221 + /**
202 * Retrieve the maximum image width 222 * Retrieve the maximum image width
203 */ 223 */
204 function getMaxImageWidth() { 224 function getMaxImageWidth() {
@@ -274,9 +294,9 @@ class DashboardNews { @@ -274,9 +294,9 @@ class DashboardNews {
274 //if the id >= 0, then the object has already been created 294 //if the id >= 0, then the object has already been created
275 if ($this->iId < 0) { 295 if ($this->iId < 0) {
276 $sql = $default->db; 296 $sql = $default->db;
277 - $result = $sql->query("INSERT INTO $default->owl_news_table (synopsis, body, rank, image, image_size, image_mime_type_id) " . 297 + $result = $sql->query("INSERT INTO $default->owl_news_table (synopsis, body, rank, image, image_size, image_mime_type_id, active) " .
278 "VALUES ('" . addslashes($this->sSynopsis) . "', '" . addslashes($this->sBody) . "', $this->iRank, " . 298 "VALUES ('" . addslashes($this->sSynopsis) . "', '" . addslashes($this->sBody) . "', $this->iRank, " .
279 - "'" . addslashes($this->sImage) . "', $this->iImageSize, $this->iImageMimeTypeID)"); 299 + "'" . addslashes($this->sImage) . "', $this->iImageSize, $this->iImageMimeTypeID, " . ($this->bActive ? "1" : "0") . ")");
280 if ($result) { 300 if ($result) {
281 //set the current news item primary key 301 //set the current news item primary key
282 $this->iId = $sql->insert_id(); 302 $this->iId = $sql->insert_id();
@@ -302,11 +322,21 @@ class DashboardNews { @@ -302,11 +322,21 @@ class DashboardNews {
302 "rank = $this->iRank, " . 322 "rank = $this->iRank, " .
303 "image = '" . addslashes($this->sImage) . "', " . 323 "image = '" . addslashes($this->sImage) . "', " .
304 "image_size = $this->iImageSize " . 324 "image_size = $this->iImageSize " .
305 - ($this->iImageMimeTypeID ? ", image_mime_type_id = $this->iImageMimeTypeID " : "") . 325 + ($this->iImageMimeTypeID ? ", image_mime_type_id = $this->iImageMimeTypeID " : " ") .
306 "WHERE id = $this->iId"; 326 "WHERE id = $this->iId";
  327 +
307 $result = $sql->query($sQuery); 328 $result = $sql->query($sQuery);
308 if ($result) { 329 if ($result) {
309 - return true; 330 + if ($this->bActive) {
  331 + // we're setting this entry to active, so set all the others to inactive
  332 + $sql->query("UPDATE $default->owl_news_table SET active=0");
  333 + // now set our entry to active
  334 + $sql->query("UPDATE $default->owl_news_table SET active=1 where id=$this->iId");
  335 + } else {
  336 + // set this to inactive
  337 + $sql->query("UPDATE $default->owl_news_table SET active=0 where id=$this->iId");
  338 + }
  339 + return true;
310 } 340 }
311 return false; 341 return false;
312 } 342 }
@@ -350,6 +380,7 @@ class DashboardNews { @@ -350,6 +380,7 @@ class DashboardNews {
350 "mimetypeid" => $sql->f("image_mime_type_id") ); 380 "mimetypeid" => $sql->f("image_mime_type_id") );
351 $oDashboardNews = & new DashboardNews(stripslashes($sql->f("synopsis")), stripslashes($sql->f("body")), $sql->f("rank"), $aImage); 381 $oDashboardNews = & new DashboardNews(stripslashes($sql->f("synopsis")), stripslashes($sql->f("body")), $sql->f("rank"), $aImage);
352 $oDashboardNews->iId = $iNewsID; 382 $oDashboardNews->iId = $iNewsID;
  383 + $oDashboardNews->setActive($sql->f("active"));
353 return $oDashboardNews; 384 return $oDashboardNews;
354 } 385 }
355 return false; 386 return false;
presentation/lookAndFeel/knowledgeTree/administration/news/addNewsBL.php
@@ -29,6 +29,7 @@ if (checkSession()) { @@ -29,6 +29,7 @@ if (checkSession()) {
29 if ($fStore) { 29 if ($fStore) {
30 // construct the news object 30 // construct the news object
31 $oDashboardNews = new DashboardNews($fSynopsis, $fBody, $fRank); 31 $oDashboardNews = new DashboardNews($fSynopsis, $fBody, $fRank);
  32 + $oDashboardNews->setActive($fActive);
32 33
33 if (isset($fSynopsis) && isset($fBody) && isset($fRank)) { 34 if (isset($fSynopsis) && isset($fBody) && isset($fRank)) {
34 // if we have a new image 35 // if we have a new image
presentation/lookAndFeel/knowledgeTree/administration/news/editNewsBL.php
@@ -41,6 +41,7 @@ if (checkSession()) { @@ -41,6 +41,7 @@ if (checkSession()) {
41 if ($oDashboardNews->getRank() <> $fRank) { 41 if ($oDashboardNews->getRank() <> $fRank) {
42 $oDashboardNews->setRank($fRank); 42 $oDashboardNews->setRank($fRank);
43 } 43 }
  44 + $oDashboardNews->setActive($fActive);
44 // if we have a new image 45 // if we have a new image
45 if (strlen($_FILES['fImage']['name']) > 0) { 46 if (strlen($_FILES['fImage']['name']) > 0) {
46 // return the size of the image 47 // return the size of the image
presentation/lookAndFeel/knowledgeTree/administration/news/newsUI.inc
@@ -30,16 +30,16 @@ function renderErrorMessage($sErrorMessage) { @@ -30,16 +30,16 @@ function renderErrorMessage($sErrorMessage) {
30 */ 30 */
31 function renderNewsTable() { 31 function renderNewsTable() {
32 global $default; 32 global $default;
33 - $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 " . 33 + $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 " .
34 "FROM $default->owl_news_table ORDER BY rank ASC"; 34 "FROM $default->owl_news_table ORDER BY rank ASC";
35 - $aColumns = array("synopsis", "body", "rank", "image", "edit", "preview", "del");  
36 - $aColumnHeaders = array("Synopsis", "Body", "Rank", "Image");  
37 - $aColumnTypes = array(1,1,1,1,3,3,3); 35 + $aColumns = array("synopsis", "body", "rank", "image", "active", "edit", "preview", "del");
  36 + $aColumnHeaders = array("Synopsis", "Body", "Rank", "Image", "Active");
  37 + $aColumnTypes = array(1,1,1,1,2,3,3,3);
38 $aDBColumnArray = array("id"); 38 $aDBColumnArray = array("id");
39 $aQueryStringVariableNames = array("fNewsID"); 39 $aQueryStringVariableNames = array("fNewsID");
40 - $aLinkURLs = array(4=> "$default->rootUrl/control.php?action=editNews",  
41 - 5=> "$default->rootUrl/control.php?action=previewNews",  
42 - 6=> "$default->rootUrl/control.php?action=removeNews"); 40 + $aLinkURLs = array(5=> "$default->rootUrl/control.php?action=editNews",
  41 + 6=> "$default->rootUrl/control.php?action=previewNews",
  42 + 7=> "$default->rootUrl/control.php?action=removeNews");
43 43
44 $oPatternTableSqlQuery = & new PatternTableSqlQuery($sQuery, $aColumns, $aColumnTypes, $aColumnHeaders, "100%", $aLinkURLs,$aDBColumnArray,$aQueryStringVariableNames); 44 $oPatternTableSqlQuery = & new PatternTableSqlQuery($sQuery, $aColumns, $aColumnTypes, $aColumnHeaders, "100%", $aLinkURLs,$aDBColumnArray,$aQueryStringVariableNames);
45 $oPatternTableSqlQuery->setTableHeading("Dashboard News"); 45 $oPatternTableSqlQuery->setTableHeading("Dashboard News");
@@ -77,6 +77,7 @@ function renderEditAddNewsForm($oDashboardNews, $bUpdate) { @@ -77,6 +77,7 @@ function renderEditAddNewsForm($oDashboardNews, $bUpdate) {
77 $sToRender .= "<tr><td>Body:</td><td><textarea name=\"fBody\" cols=\"35\" rows=\"10\">" . ($oDashboardNews ? $oDashboardNews->getBody() : "") . "</textarea></td></tr>"; 77 $sToRender .= "<tr><td>Body:</td><td><textarea name=\"fBody\" cols=\"35\" rows=\"10\">" . ($oDashboardNews ? $oDashboardNews->getBody() : "") . "</textarea></td></tr>";
78 $sToRender .= "<tr><td>Rank:</td><td><input type=\"text\" name=\"fRank\" value=\"" . ($oDashboardNews ? $oDashboardNews->getRank() : "") . "\"></td></tr>"; 78 $sToRender .= "<tr><td>Rank:</td><td><input type=\"text\" name=\"fRank\" value=\"" . ($oDashboardNews ? $oDashboardNews->getRank() : "") . "\"></td></tr>";
79 $sToRender .= "<tr><td>Image:</td><td><input type=\"file\" name=\"fImage\"></td></tr>"; 79 $sToRender .= "<tr><td>Image:</td><td><input type=\"file\" name=\"fImage\"></td></tr>";
  80 + $sToRender .= "<tr><td>Active:</td><td><input type=\"checkbox\" name=\"fActive\" " . ($oDashboardNews ? ($oDashboardNews->getActive() ? "checked" : "") : "") . "\"></td></tr>";
80 81
81 if ($bUpdate) { 82 if ($bUpdate) {
82 $sToRender .= "<input type=\"hidden\" name=\"fNewsID\" value=\"" . $oDashboardNews->getID() . "\">"; 83 $sToRender .= "<input type=\"hidden\" name=\"fNewsID\" value=\"" . $oDashboardNews->getID() . "\">";
presentation/lookAndFeel/knowledgeTree/dashboardUI.inc
@@ -150,7 +150,7 @@ function renderDashboardNews() { @@ -150,7 +150,7 @@ function renderDashboardNews() {
150 global $default; 150 global $default;
151 151
152 // retrieve all news items 152 // retrieve all news items
153 - $aDashboardNews = DashboardNews::getList(); 153 + $aDashboardNews = DashboardNews::getList("active=1");
154 154
155 $sToRender .= "\t\t\t<table border=\"0\" width=\"100%\">\n"; 155 $sToRender .= "\t\t\t<table border=\"0\" width=\"100%\">\n";
156 // the main news item 156 // the main news item
sql/tables.sql
@@ -250,7 +250,8 @@ body TEXT, @@ -250,7 +250,8 @@ body TEXT,
250 rank INTEGER, 250 rank INTEGER,
251 image TEXT, 251 image TEXT,
252 image_size INTEGER, 252 image_size INTEGER,
253 -image_mime_type_id INTEGER 253 +image_mime_type_id INTEGER,
  254 +active BIT
254 ) TYPE = InnoDB; 255 ) TYPE = InnoDB;
255 256
256 CREATE TABLE organisations_lookup ( 257 CREATE TABLE organisations_lookup (