From 0957c555c33dccb82128525412c79af90dbd9db8 Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Tue, 28 Apr 2009 13:24:12 +0000 Subject: [PATCH] Fixed bugs linked to the bookmark creation: - There must be a user specific menu entry in the list of menuNodes - The asynchronous ajax page must use the authentication stored in the session - The query must be stored in OQL instead of sibusQL SVN:trunk[58] --- .../userrights/userrightsmatrix.class.inc.php | 23 +++++++++++++++ application/menunode.class.inc.php | 29 ++++++++++++------- pages/UniversalSearch.php | 6 ++-- pages/ajax.render.php | 12 ++++++-- 4 files changed, 55 insertions(+), 15 deletions(-) diff --git a/addons/userrights/userrightsmatrix.class.inc.php b/addons/userrights/userrightsmatrix.class.inc.php index de90baa47..75becda13 100644 --- a/addons/userrights/userrightsmatrix.class.inc.php +++ b/addons/userrights/userrightsmatrix.class.inc.php @@ -268,6 +268,29 @@ class UserRightsMatrix extends UserRightsAddOnAPI } } } + // Create the "My Bookmarks" menu item (parent_id = 0, rank = 6) + if ($bNewUser) + { + $bAddMenu = true; + } + else + { + $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT menuNode WHERE type = 'user' AND parent_id = 0 AND user_id = $iUserId")); + $bAddMenu = ($oSet->Count() < 1); + } + if ($bAddMenu) + { + $oMenu = MetaModel::NewObject('menuNode'); + $oMenu->Set('type', 'user'); + $oMenu->Set('parent_id', 0); // It's a toplevel entry + $oMenu->Set('rank', 6); // Located just above the Admin Tools section (=7) + $oMenu->Set('name', 'My Bookmarks'); + $oMenu->Set('label', 'My Favorite Items'); + $oMenu->Set('hyperlink', 'UI.php'); + $oMenu->Set('template', '

My bookmarks

This section contains my most favorite search results

'); + $oMenu->Set('user_id', $iUserId); + $oMenu->DBInsert(); + } } diff --git a/application/menunode.class.inc.php b/application/menunode.class.inc.php index f571f40f3..e0b72ec62 100644 --- a/application/menunode.class.inc.php +++ b/application/menunode.class.inc.php @@ -89,14 +89,17 @@ class menuNode extends DBObject return $this->Get('hyperlink')."?".implode("&", $aParams); } - public function GetChildNodesSet($sType) + public function GetChildNodesSet($sType = null) { $oSearchFilter = new DBObjectSearch("menuNode"); $oSearchFilter->AddCondition('parent_id', $this->GetKey(), '='); - $oSearchFilter->AddCondition('type', $sType, '='); - if ($sType == 'user') + if ($sType != null) { - $oSearchFilter->AddCondition('user_id', UserRights::GetUserId(), '='); + $oSearchFilter->AddCondition('type', $sType, '='); + if ($sType == 'user') + { + $oSearchFilter->AddCondition('user_id', UserRights::GetUserId(), '='); + } } $oSet = new CMDBObjectSet($oSearchFilter, array('rank' => true)); return $oSet; @@ -184,10 +187,13 @@ class menuNode extends DBObject { $oSearchFilter = new DbObjectSearch("menuNode"); $oSearchFilter->AddCondition('parent_id', 0, '='); - $oSearchFilter->AddCondition('type', $sType, '='); - if ($sType == 'user') + if ($sType != null) { - $oSearchFilter->AddCondition('user_id', UserRights::GetUserId(), '='); + $oSearchFilter->AddCondition('type', $sType, '='); + if ($sType == 'user') + { + $oSearchFilter->AddCondition('user_id', UserRights::GetUserId(), '='); + } } $oRootSet = new CMDBObjectSet($oSearchFilter, array('rank' => true)); while($oNode = $oRootSet->Fetch()) @@ -207,10 +213,13 @@ class menuNode extends DBObject $oSearchFilter = new DBObjectSearch("menuNode"); $oSearchFilter->AddCondition('parent_id', $this->Get('parent_id')); $oSearchFilter->AddCondition('rank', $this->Get('rank'), '>'); - $oSearchFilter->AddCondition('type', $sType, '='); - if ($sType == 'user') + if ($sType != null) { - $oSearchFilter->AddCondition('user_id', UserRights::GetUserId(), '='); + $oSearchFilter->AddCondition('type', $sType, '='); + if ($sType == 'user') + { + $oSearchFilter->AddCondition('user_id', UserRights::GetUserId(), '='); + } } $oSet = new DBObjectSet($oSearchFilter, array('rank'=> true)); // Order by rank (true means ascending) return $oSet; diff --git a/pages/UniversalSearch.php b/pages/UniversalSearch.php index ebe762fb3..e649f8d2b 100644 --- a/pages/UniversalSearch.php +++ b/pages/UniversalSearch.php @@ -58,14 +58,14 @@ if ($oFilter != null) $oResultBlock->RenderContent($oP); // Menu node - $sFilter = $oFilter->ToSibusQL(); + $sFilter = $oFilter->ToOQL(); $sMenuNodeContent = << -$sFilter +$sFilter

-$sFilter +$sFilter
EOF; diff --git a/pages/ajax.render.php b/pages/ajax.render.php index 176a32128..35af6a858 100644 --- a/pages/ajax.render.php +++ b/pages/ajax.render.php @@ -6,10 +6,18 @@ require_once('../application/wizardhelper.class.inc.php'); require_once('../application/ui.linkswidget.class.inc.php'); require_once('../application/startup.inc.php'); -if (isset($_SERVER['PHP_AUTH_USER'])) +session_start(); +if (isset($_SESSION['auth_user'])) { + $sAuthUser = $_SESSION['auth_user']; + $sAuthPwd = $_SESSION['auth_pwd']; // Attempt to login, fails silently - UserRights::Login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); + UserRights::Login($sAuthUser, $sAuthPwd); +} +else +{ + // No session information + echo "

No session information

\n"; } $oPage = new ajax_page("");