Ver Fonte

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

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@58 a333f486-631f-4898-b8df-5754b55c2be0

dflaven há 16 anos atrás
pai
commit
0f04f30236

+ 23 - 0
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', '<p></p><p></p><p style="text-align:center; font-family:Georgia, Times, serif; font-size:32px;">My bookmarks</p><p style="text-align:center; font-family:Georgia, Times, serif; font-size:14px;"><i>This section contains my most favorite search results</i></p>');
+			$oMenu->Set('user_id', $iUserId);
+			$oMenu->DBInsert();
+		}
 	}
 
 

+ 19 - 10
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;

+ 3 - 3
pages/UniversalSearch.php

@@ -58,14 +58,14 @@ if ($oFilter != null)
 	$oResultBlock->RenderContent($oP);
 	
 	// Menu node
-	$sFilter = $oFilter->ToSibusQL();
+	$sFilter = $oFilter->ToOQL();
 	$sMenuNodeContent = <<<EOF
 <div id="TopPane">
-<itopblock BlockClass="DisplayBlock" objectclass="bizContact" type="search" asynchronous="false" encoding="text/sibusql">$sFilter</itopblock>
+<itopblock BlockClass="DisplayBlock" type="search" asynchronous="false" encoding="text/oql">$sFilter</itopblock>
 </div>
 <div id="BottomPane">
 <p></p>
-<itopblock BlockClass="DisplayBlock" objectclass="bizContact" type="list" asynchronous="false" encoding="text/sibusql">$sFilter</itopblock>
+<itopblock BlockClass="DisplayBlock" type="list" asynchronous="false" encoding="text/oql">$sFilter</itopblock>
 </div>
 EOF;
 

+ 10 - 2
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 "<p>No session information</p>\n";
 }
 
 $oPage = new ajax_page("");