add("
");
try
{
if ($sOperation == 'search_form')
{
$sOQL = "SELECT $sOQLClass $sOQLClause";
$oFilter = DBObjectSearch::FromOQL($sOQL);
}
else
{
// Second part: advanced search form:
if (!empty($sFilter))
{
$oFilter = CMDBSearchFilter::unserialize($sFilter);
}
else if (!empty($sClassName))
{
$oFilter = new CMDBSearchFilter($sClassName);
}
}
}
catch (CoreException $e)
{
$oFilter = new CMDBSearchFilter($sClassName);
$oP->P("Error:");
$oP->P($e->getHtmlDesc());
}
if ($oFilter != null)
{
$oSet = new CMDBObjectSet($oFilter);
$oBlock = new DisplayBlock($oFilter, 'search', false);
$aExtraParams = $oAppContext->GetAsHash();
$aExtraParams['open'] = true;
$aExtraParams['oql_class'] = $sOQLClass;
//$aExtraParams['class'] = $sClassName;
$oBlock->Display($oP, 0, $aExtraParams);
// Search results
$oResultBlock = new DisplayBlock($oFilter, 'list', false);
$oResultBlock->Display($oP, 1);
// Menu node
$sFilter = $oFilter->ToOQL();
$sMenuNodeContent = <<
$sFilter
EOF;
if ($sOperation == "add_menu")
{
$oMenuNode = MetaModel::NewObject('menuNode');
$sClass = utils::ReadPostedParam('class', '');
$sLabel = utils::ReadPostedParam('label', '');
$sDescription = utils::ReadPostedParam('description', '');
$iPreviousNodeId = utils::ReadPostedParam('previous_node_id', 1);
$bChildItem = utils::ReadPostedParam('child_item', false);
$oMenuNode->Set('label', $sDescription);
$oMenuNode->Set('name', $sLabel);
$oMenuNode->Set('icon_path', '../images/std_view.gif');
$oMenuNode->Set('template', $sMenuNodeContent);
$oMenuNode->Set('hyperlink', 'UI.php');
$oMenuNode->Set('type', 'user');
$oMenuNode->Set('user_id', UserRights::GetUserId());
$oPreviousNode = MetaModel::GetObject('menuNode', $iPreviousNodeId);
if ($bChildItem)
{
// Insert the new item as a child of the previous one
$oMenuNode->Set('parent_id', $iPreviousNodeId);
$oMenuNode->Set('rank', 1); // A new child item is the first one, so let's start the numbering at 1
// If there are already child nodes, shift their rank by one
// to make room for the newly inserted child node
$oNextNodeSet = $oPreviousNode->GetChildNodesSet(null); // null => don't limit ourselves to the user context
// since we need to update all children in order to keep
// the database consistent
while($oNextNode = $oNextNodeSet->Fetch())
{
$oNextNode->Set('rank', 1 + $oNextNode->Get('rank'));
$oNextNode->DBUpdate();
}
}
else
{
// Insert the new item as the next sibling of the previous one
$oMenuNode->Set('parent_id', $oPreviousNode->Get('parent_id'));
$oMenuNode->Set('rank', 1 + $oPreviousNode->Get('rank')); // the new item comes immediatly after the selected one
// Add 1 to the rank of all the nodes currently following the 'selected' one
// to make room for the newly inserted node
$oNextNodeSet = $oPreviousNode->GetNextNodesSet(null); // null => don't limit ourselves to the user context
// since we need to update all children in order to keep
// the database consistent
while($oNextNode = $oNextNodeSet->Fetch())
{
$oNextNode->Set('rank', 1 + $oNextNode->Get('rank'));
$oNextNode->DBUpdate();
}
}
list($bRes, $aIssues) = $oMenuNode->CheckToInsert();
if ($bRes)
{
$oMenuNode->DBInsert();
$oP->add("