diff --git a/dashboard.php b/dashboard.php
index c12b88e..647c142 100644
--- a/dashboard.php
+++ b/dashboard.php
@@ -3,38 +3,38 @@
* $Id$
*
* Main dashboard page -- This page is presented to the user after login.
- * It contains a high level overview of the users subscriptions, checked out
- * document, pending approval routing documents, etc.
+ * It contains a high level overview of the users subscriptions, checked out
+ * document, pending approval routing documents, etc.
*
* KnowledgeTree Open Source Edition
* Document Management Made Simple
* Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
- *
+ *
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation.
- *
+ *
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
- *
+ *
* You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
* Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
- *
+ *
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
- *
+ *
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
- * KnowledgeTree" logo and retain the original copyright notice. If the display of the
+ * KnowledgeTree" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
- * must display the words "Powered by KnowledgeTree" and retain the original
- * copyright notice.
+ * must display the words "Powered by KnowledgeTree" and retain the original
+ * copyright notice.
* Contributor( s): ______________________________________
*/
@@ -53,9 +53,9 @@ require_once(KT_LIB_DIR . '/dashboard/DashletDisables.inc.php');
$sectionName = 'dashboard';
class DashboardDispatcher extends KTStandardDispatcher {
-
+
var $notifications = array();
- var $sHelpPage = 'ktcore/dashboard.html';
+ var $sHelpPage = 'ktcore/dashboard.html';
function DashboardDispatcher() {
$this->aBreadcrumbs = array(
@@ -67,25 +67,29 @@ class DashboardDispatcher extends KTStandardDispatcher {
$this->oPage->setShowPortlets(false);
// retrieve action items for the user.
// FIXME what is the userid?
-
-
+
+
$oDashletRegistry =& KTDashletRegistry::getSingleton();
$aDashlets = $oDashletRegistry->getDashlets($this->oUser);
-
+
$this->sSection = 'dashboard';
$this->oPage->setBreadcrumbDetails(_kt('Home'));
$this->oPage->title = _kt('Dashboard');
-
+
// simplistic improvement over the standard rendering: float half left
// and half right. +Involves no JS -can leave lots of white-space at the bottom.
$aDashletsLeft = array();
- $aDashletsRight = array();
+ $aDashletsRight = array();
$i = 0;
foreach ($aDashlets as $oDashlet) {
- if ($i == 0) { $aDashletsLeft[] = $oDashlet; }
- else {$aDashletsRight[] = $oDashlet; }
+ if(strpos(strtolower($oDashlet->sTitle), 'welcome to knowledgetree') !== false && !empty($aDashletsLeft)){
+ array_unshift($aDashletsLeft, $oDashlet);
+ }else{
+ if ($i == 0) { $aDashletsLeft[] = $oDashlet; }
+ else {$aDashletsRight[] = $oDashlet; }
+ }
$i += 1;
$i %= 2;
}
@@ -97,10 +101,10 @@ class DashboardDispatcher extends KTStandardDispatcher {
$this->oPage->requireJSResource('thirdpartyjs/yui/dom/dom.js');
$this->oPage->requireJSResource('thirdpartyjs/yui/dragdrop/dragdrop.js');
$this->oPage->requireJSResource('resources/js/DDList.js');
-
+
$this->oUser->refreshDashboadState();
-
+
// dashboard
$sDashboardState = $this->oUser->getDashboardState();
$sDSJS = 'var savedState = ';
@@ -114,7 +118,6 @@ class DashboardDispatcher extends KTStandardDispatcher {
$this->oPage->requireJSStandalone($sDSJS);
$this->oPage->requireJSResource('resources/js/dashboard.js');
-
// render
$oTemplating =& KTTemplating::getSingleton();
$oTemplate = $oTemplating->loadTemplate('kt3/dashboard');
@@ -125,33 +128,33 @@ class DashboardDispatcher extends KTStandardDispatcher {
);
return $oTemplate->render($aTemplateData);
}
-
+
// return some kind of ID for each dashlet
// currently uses the class name
function _getDashletId($oDashlet) {
return get_class($oDashlet);
}
- // disable a dashlet.
+ // disable a dashlet.
// FIXME this very slightly violates the separation of concerns, but its not that flagrant.
function do_disableDashlet() {
$sNamespace = KTUtil::arrayGet($_REQUEST, 'fNamespace');
$iUserId = $this->oUser->getId();
-
+
if (empty($sNamespace)) {
$this->errorRedirectToMain('No dashlet specified.');
exit(0);
}
-
+
// do the "delete"
-
+
$this->startTransaction();
$aParams = array('sNamespace' => $sNamespace, 'iUserId' => $iUserId);
$oDD = KTDashletDisable::createFromArray($aParams);
if (PEAR::isError($oDD)) {
$this->errorRedirectToMain('Failed to disable the dashlet.');
}
-
+
$this->commitTransaction();
$this->successRedirectToMain('Dashlet disabled.');
}
diff --git a/lib/dashboard/dashletregistry.inc.php b/lib/dashboard/dashletregistry.inc.php
index afa1c76..8445ade 100644
--- a/lib/dashboard/dashletregistry.inc.php
+++ b/lib/dashboard/dashletregistry.inc.php
@@ -5,32 +5,32 @@
* KnowledgeTree Open Source Edition
* Document Management Made Simple
* Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
- *
+ *
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation.
- *
+ *
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
- *
+ *
* You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
* Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
- *
+ *
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
- *
+ *
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
- * KnowledgeTree" logo and retain the original copyright notice. If the display of the
+ * KnowledgeTree" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
- * must display the words "Powered by KnowledgeTree" and retain the original
- * copyright notice.
+ * must display the words "Powered by KnowledgeTree" and retain the original
+ * copyright notice.
* Contributor( s): ______________________________________
*
*/
@@ -53,6 +53,55 @@ class KTDashletRegistry {
$this->nsnames[$nsname] = array($name, $filename, $nsname, $sPlugin);
}
+ /**
+ * Get any dashlets added since the user's last login
+ *
+ * @param object $oUser
+ */
+ function getNewDashlets($oUser, $sCurrent) {
+ $new = array();
+ $inactive = array();
+
+ static $sInactive = '';
+ $sIgnore = (!empty($sInactive)) ? $sCurrent.','.$sInactive : $sCurrent;
+
+ // Get all dashlets that haven't already been displayed to the user and are active for the user
+ $query = "SELECT * FROM plugin_helper h
+ INNER JOIN plugins p ON (h.plugin = p.namespace)
+ WHERE p.disabled = 0 AND classtype = 'dashlet'
+ AND h.classname NOT IN ($sIgnore)";
+
+ $res = DBUtil::getResultArray($query);
+
+ // If the query is not empty, get the dashlets and return the new active ones
+ // Add the inactive ones the list.
+ if(!PEAR::isError($res) && !empty($res)){
+ $oRegistry =& KTPluginRegistry::getSingleton();
+ foreach ($res as $item){
+ $name = $item['classname'];
+ $filename = $item['pathname'];
+ $sPluginName = $item['plugin'];
+
+ require_once($filename);
+ $oPlugin =& $oRegistry->getPlugin($sPluginName);
+
+ $oDashlet = new $name;
+ $oDashlet->setPlugin($oPlugin);
+ if ($oDashlet->is_active($oUser)) {
+ $new[] = $name;
+ }else{
+ $inactive[] = "'$name'";
+ }
+ }
+ // Add new inactive dashlets
+ $sNewInactive = implode(',', $inactive);
+ $sInactive = (!empty($sInactive)) ? $sInactive.','.$sNewInactive : $sNewInactive;
+
+ return $new;
+ }
+ return '';
+ }
+
// FIXME we might want to do the pruning now, but I'm unsure how to handle the preconditions.
function getDashlets($oUser) {
$aDashlets = array();
diff --git a/lib/users/User.inc b/lib/users/User.inc
index 4d54a9f..edaeaf2 100644
--- a/lib/users/User.inc
+++ b/lib/users/User.inc
@@ -81,6 +81,12 @@ class User extends KTEntity {
var $dLastLogin = null;
var $bDisabled = false;
+ /**
+ * The dashboard state for the current user
+ * @var string
+ */
+ var $sDashboardState = '';
+
var $_aFieldToSelect = array(
'iId' => 'id',
'sUserName' => 'username',
@@ -176,23 +182,26 @@ class User extends KTEntity {
}
function getDashboardState() {
- return KTUtil::getSystemSetting($this->_getDashboardStateKey());
+ if(empty($this->sDashboardState)){
+ $this->sDashboardState = KTUtil::getSystemSetting($this->_getDashboardStateKey());
+ }
+ return $this->sDashboardState;
}
function setDashboardState($mValue) {
+ $this->sDashboardState = $mValue;
KTUtil::setSystemSetting($this->_getDashboardStateKey(), $mValue);
}
function refreshDashboadState()
{
require_once(KT_DIR . "/thirdparty/pear/JSON.php");
-
$dashletRegistry = & KTDashletRegistry::getSingleton();
- $aDashlets = $dashletRegistry->getDashlets($this);
+ $update = false;
+ $knownlist = array();
$oJSON = new Services_JSON();
-
$state = $this->getDashboardState();
$dashlets = $oJSON->decode($state);
@@ -200,34 +209,59 @@ class User extends KTEntity {
if (!isset($dashlets->right)) $dashlets->right = array();
$mergedlist = kt_array_merge($dashlets->left,$dashlets->right);
-
- $knownlist = array();
foreach($mergedlist as $dashlet)
{
- array_push($knownlist,$dashlet->id);
+ array_push($knownlist,"'".$dashlet->id."'");
}
- $update=false;
- //if (!isset($dashlets->left)) $dashlets->left=array();
- //if (!isset($dashlets->right)) $dashlets->right=array();
+ $sKnownlist = implode(',', $knownlist);
+ $aDashlets = $dashletRegistry->getNewDashlets($this, $sKnownlist);
+
+ if(!empty($aDashlets)){
+ $column=1;
+ foreach($aDashlets as $class)
+ {
+ $column = ($column + 1) %2;
+ $obj = new stdClass();
+ $obj->id=$class;
+ $obj->state=0;
+
+ if ($column == 0)
+ array_push($dashlets->left,$obj);
+ else
+ array_push($dashlets->right,$obj);
+ $update=true;
+ }
+ }
- $column=1;
- foreach($aDashlets as $dashlet)
- {
- $class = get_class($dashlet);
- $column=($column + 1) %2;
- if (!in_array($class,$knownlist))
- {
- $obj = new stdClass();
- $obj->id=$class;
- $obj->state=0;
-
- if ($column == 0)
- array_push($dashlets->left,$obj);
- else
- array_push($dashlets->right,$obj);
- $update=true;
- }
+ // Check if the KT Info dashlet is being displayed
+ // If it's not in the top left corner, move it there.
+ if(!(strpos($sKnownlist, 'KTInfoDashlet') === false) && $knownlist[0] != "'KTInfoDashlet'"){
+ $left = $dashlets->left;
+ $right = $dashlets->right;
+
+ $found = false;
+ $update = true;
+ foreach($left as $key => $item){
+ if($item->id == 'KTInfoDashlet'){
+ // found the dashlet
+ $found = 'true';
+ array_splice($dashlets->left, $key, 1);
+ array_unshift($dashlets->left, $item);
+ continue;
+ }
+ }
+ if(!$found){
+ foreach($right as $key => $item){
+ if($item->id == 'KTInfoDashlet'){
+ // found the dashlet
+ $found = 'true';
+ array_splice($dashlets->right, $key, 1);
+ array_unshift($dashlets->left, $item);
+ continue;
+ }
+ }
+ }
}
if ($update)