mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
Fixed Trac #258: cleanup of application context parameters.
SVN:trunk[908]
This commit is contained in:
@@ -57,9 +57,10 @@ class ApplicationContext
|
||||
if (empty(self::$aDefaultValues))
|
||||
{
|
||||
self::$aDefaultValues = array();
|
||||
$aContext = utils::ReadParam('c', array());
|
||||
foreach($this->aNames as $sName)
|
||||
{
|
||||
$sValue = utils::ReadParam($sName, '');
|
||||
$sValue = isset($aContext[$sName]) ? $aContext[$sName] : '';
|
||||
// TO DO: check if some of the context parameters are mandatory (or have default values)
|
||||
if (!empty($sValue))
|
||||
{
|
||||
@@ -70,6 +71,20 @@ class ApplicationContext
|
||||
$this->aValues = self::$aDefaultValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current value for the given parameter
|
||||
* @param string $sParamName Name of the parameter to read
|
||||
* @return mixed The value for this parameter
|
||||
*/
|
||||
public function GetCurrentValue($sParamName, $defaultValue = '')
|
||||
{
|
||||
if (isset($this->aValues[$sParamName]))
|
||||
{
|
||||
return $this->aValues[$sParamName];
|
||||
}
|
||||
return $defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the context as string with the format name1=value1&name2=value2....
|
||||
* return string The context as a string to be appended to an href property
|
||||
@@ -79,7 +94,7 @@ class ApplicationContext
|
||||
$aParams = array();
|
||||
foreach($this->aValues as $sName => $sValue)
|
||||
{
|
||||
$aParams[] = $sName.'='.urlencode($sValue);
|
||||
$aParams[] = "c[$sName]".'='.urlencode($sValue);
|
||||
}
|
||||
return implode("&", $aParams);
|
||||
}
|
||||
@@ -93,7 +108,7 @@ class ApplicationContext
|
||||
$sContext = "";
|
||||
foreach($this->aValues as $sName => $sValue)
|
||||
{
|
||||
$sContext .= "<input type=\"hidden\" name=\"$sName\" value=\"$sValue\" />\n";
|
||||
$sContext .= "<input type=\"hidden\" name=\"c[$sName]\" value=\"$sValue\" />\n";
|
||||
}
|
||||
return $sContext;
|
||||
}
|
||||
@@ -104,7 +119,12 @@ class ApplicationContext
|
||||
*/
|
||||
public function GetAsHash()
|
||||
{
|
||||
return $this->aValues;
|
||||
$aReturn = array();
|
||||
foreach($this->aValues as $sName => $sValue)
|
||||
{
|
||||
$aReturn["c[$sName]"] = $sValue;
|
||||
}
|
||||
return $aReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -899,7 +899,8 @@ EOF
|
||||
}
|
||||
$aOptions[MetaModel::GetName($sClassName)] = "<option selected value=\"$sClassName\">".MetaModel::GetName($sClassName)."</options>\n";
|
||||
ksort($aOptions);
|
||||
$sClassesCombo = "<select name=\"class\" onChange=\"ReloadSearchForm('$sSearchFormId', this.value, '$sRootClass')\">\n".implode('', $aOptions)."</select>\n";
|
||||
$sContext = $oAppContext->GetForLink();
|
||||
$sClassesCombo = "<select name=\"class\" onChange=\"ReloadSearchForm('$sSearchFormId', this.value, '$sRootClass', '$sContext')\">\n".implode('', $aOptions)."</select>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -919,7 +920,7 @@ EOF
|
||||
$aList = MetaModel::GetZListItems($sClassName, 'standard_search');
|
||||
foreach($aList as $sFilterCode)
|
||||
{
|
||||
$oAppContext->Reset($sFilterCode); // Make sure the same parameter will not be passed twice
|
||||
//$oAppContext->Reset($sFilterCode); // Make sure the same parameter will not be passed twice
|
||||
$sHtml .= '<span style="white-space: nowrap;padding:5px;display:inline-block;">';
|
||||
$sFilterValue = '';
|
||||
$sFilterValue = utils::ReadParam($sFilterCode, '');
|
||||
@@ -1607,5 +1608,15 @@ EOF
|
||||
}
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps the given context parameter name to the appropriate filter/search code for this class
|
||||
* @param string $sContextParam Name of the context parameter, i.e. 'org_id'
|
||||
* @return string Filter code, i.e. 'customer_id'
|
||||
*/
|
||||
public static function MapContextParam($sContextParam)
|
||||
{
|
||||
return $sContextParam;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -320,17 +320,29 @@ class DisplayBlock
|
||||
}
|
||||
if ($this->m_sStyle != 'links')
|
||||
{
|
||||
$aFilterCodes = array_keys(MetaModel::GetClassFilterDefs($this->m_oFilter->GetClass()));
|
||||
$oAppContext = new ApplicationContext();
|
||||
$sClass = $this->m_oFilter->GetClass();
|
||||
$aFilterCodes = array_keys(MetaModel::GetClassFilterDefs($sClass));
|
||||
foreach($oAppContext->GetNames() as $sContextParam)
|
||||
{
|
||||
eval("\$sParamCode = $sClass::MapContextParam('$sFilterCode');"); //Map context parameter to the value/filter code depending on the class
|
||||
}
|
||||
foreach($aFilterCodes as $sFilterCode)
|
||||
{
|
||||
$sExternalFilterValue = utils::ReadParam($sFilterCode, '');
|
||||
if (isset($aExtraParams[$sFilterCode]))
|
||||
{
|
||||
$this->m_oFilter->AddCondition($sFilterCode, trim($aExtraParams[$sFilterCode])); // Use the default 'loose' operator
|
||||
$condition = $aExtraParams[$sFilterCode];
|
||||
}
|
||||
else if ($bDoSearch && $sExternalFilterValue != "")
|
||||
{
|
||||
$this->m_oFilter->AddCondition($sFilterCode, trim($sExternalFilterValue)); // Use the default 'loose' operator
|
||||
// Search takes precedence over context params...
|
||||
$condition = trim($sExternalFilterValue);
|
||||
}
|
||||
|
||||
if (!is_null($condition))
|
||||
{
|
||||
$this->m_oFilter->AddCondition($sFilterCode, $condition); // Use the default 'loose' operator
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -582,7 +594,7 @@ class DisplayBlock
|
||||
$aFilterCodes = array_keys(MetaModel::GetClassFilterDefs($this->m_oFilter->GetClass()));
|
||||
foreach($oAppContext->GetNames() as $sFilterCode)
|
||||
{
|
||||
$sContextParamValue = trim(utils::ReadParam($sFilterCode, null));
|
||||
$sContextParamValue = $oAppContext->GetCurrentValue($sFilterCode, null);
|
||||
if (!is_null($sContextParamValue) && ! empty($sContextParamValue) && MetaModel::IsValidFilterCode($sClass, $sFilterCode))
|
||||
{
|
||||
$this->m_oFilter->AddCondition($sFilterCode, $sContextParamValue); // Use the default 'loose' operator
|
||||
@@ -596,7 +608,7 @@ class DisplayBlock
|
||||
$this->m_oSet = new CMDBObjectSet($this->m_oFilter, array(), $aQueryParams);
|
||||
}
|
||||
$iCount = $this->m_oSet->Count();
|
||||
$sHyperlink = '../pages/UI.php?operation=search&filter='.$this->m_oFilter->serialize();
|
||||
$sHyperlink = '../pages/UI.php?operation=search&'.$oAppContext->GetForLink().'&filter='.$this->m_oFilter->serialize();
|
||||
$sHtml .= '<p><a class="actions" href="'.$sHyperlink.'">';
|
||||
$sHtml .= MetaModel::GetClassIcon($sClass, true, 'float;left;margin-right:10px;');
|
||||
$sHtml .= MetaModel::GetName($sClass).': '.$iCount.'</a></p>';
|
||||
@@ -624,7 +636,7 @@ class DisplayBlock
|
||||
$aFilterCodes = array_keys(MetaModel::GetClassFilterDefs($this->m_oFilter->GetClass()));
|
||||
foreach($oAppContext->GetNames() as $sFilterCode)
|
||||
{
|
||||
$sContextParamValue = trim(utils::ReadParam($sFilterCode, null));
|
||||
$sContextParamValue = $oAppContext->GetCurrentValue($sFilterCode, null);
|
||||
if (!is_null($sContextParamValue) && ! empty($sContextParamValue) && MetaModel::IsValidFilterCode($sClass, $sFilterCode))
|
||||
{
|
||||
$this->m_oFilter->AddCondition($sFilterCode, $sContextParamValue); // Use the default 'loose' operator
|
||||
@@ -657,7 +669,7 @@ class DisplayBlock
|
||||
}
|
||||
else
|
||||
{
|
||||
$sHyperlink = '../pages/UI.php?operation=search&filter='.$oFilter->serialize();
|
||||
$sHyperlink = '../pages/UI.php?operation=search&'.$oAppContext->GetForLink().'&filter='.$oFilter->serialize();
|
||||
$aCounts[$sStateValue] = "<a href=\"$sHyperlink\">{$aCounts[$sStateValue]}</a>";
|
||||
}
|
||||
}
|
||||
@@ -666,7 +678,7 @@ class DisplayBlock
|
||||
$sHtml .= '<tr><td>'.implode('</td><td>', $aCounts).'</td></tr></table></div>';
|
||||
// Title & summary
|
||||
$iCount = $this->m_oSet->Count();
|
||||
$sHyperlink = '../pages/UI.php?operation=search&filter='.$this->m_oFilter->serialize();
|
||||
$sHyperlink = '../pages/UI.php?operation=search&'.$oAppContext->GetForLink().'&filter='.$this->m_oFilter->serialize();
|
||||
$sHtml .= '<h1>'.Dict::S(str_replace('_', ':', $sTitle)).'</h1>';
|
||||
$sHtml .= '<a class="summary" href="'.$sHyperlink.'">'.Dict::Format(str_replace('_', ':', $sLabel), $iCount).'</a>';
|
||||
break;
|
||||
|
||||
@@ -32,12 +32,12 @@ require_once("../application/user.preferences.class.inc.php");
|
||||
class iTopWebPage extends NiceWebPage
|
||||
{
|
||||
private $m_sMenu;
|
||||
private $m_currentOrganization;
|
||||
// private $m_currentOrganization;
|
||||
private $m_aTabs;
|
||||
private $m_sCurrentTabContainer;
|
||||
private $m_sCurrentTab;
|
||||
|
||||
public function __construct($sTitle, $currentOrganization)
|
||||
public function __construct($sTitle)
|
||||
{
|
||||
parent::__construct($sTitle);
|
||||
$this->m_sCurrentTabContainer = '';
|
||||
@@ -46,7 +46,7 @@ class iTopWebPage extends NiceWebPage
|
||||
$this->m_sMenu = "";
|
||||
$oAppContext = new ApplicationContext();
|
||||
$sExtraParams = $oAppContext->GetForLink();
|
||||
$this->m_currentOrganization = $currentOrganization;
|
||||
// $this->m_currentOrganization = $currentOrganization;
|
||||
$this->add_header("Content-type: text/html; charset=utf-8");
|
||||
$this->add_header("Cache-control: no-cache");
|
||||
$this->add_linked_stylesheet("../css/jquery.treeview.css");
|
||||
@@ -478,15 +478,17 @@ EOF
|
||||
break;
|
||||
|
||||
default:
|
||||
$oAppContext = new ApplicationContext();
|
||||
$iCurrentOrganization = $oAppContext->GetCurrentValue('org_id');
|
||||
$sHtml = '<div id="SiloSelection">';
|
||||
$sHtml .= '<form style="display:inline" action="'.$_SERVER['PHP_SELF'].'"><select style="width:150px;font-size:x-small" name="org_id" title="Pick an organization" onChange="this.form.submit();">';
|
||||
$sSelected = ($this->m_currentOrganization == '') ? ' selected' : '';
|
||||
$sHtml .= '<form style="display:inline" action="'.$_SERVER['PHP_SELF'].'"><select style="width:150px;font-size:x-small" name="c[org_id]" title="Pick an organization" onChange="this.form.submit();">';
|
||||
$sSelected = ($iCurrentOrganization == '') ? ' selected' : '';
|
||||
$sHtml .= '<option value=""'.$sSelected.'>'.Dict::S('UI:AllOrganizations').'</option>';
|
||||
while($oOrg = $oSet->Fetch())
|
||||
{
|
||||
if ($this->m_currentOrganization == $oOrg->GetKey())
|
||||
if ($iCurrentOrganization == $oOrg->GetKey())
|
||||
{
|
||||
$oCurrentOrganization = $oOrg;
|
||||
// $oCurrentOrganization = $oOrg;
|
||||
$sSelected = " selected";
|
||||
|
||||
}
|
||||
@@ -498,8 +500,8 @@ EOF
|
||||
}
|
||||
$sHtml .= '</select>';
|
||||
// Add other dimensions/context information to this form
|
||||
$oAppContext = new ApplicationContext();
|
||||
$oAppContext->Reset('org_id'); // Org id is handled above and we want to be able to change it here !
|
||||
// $oAppContext = new ApplicationContext();
|
||||
$oAppContext->Reset('org_id'); // org_id is handled above and we want to be able to change it here !
|
||||
$sHtml .= $oAppContext->GetForForm();
|
||||
$sHtml .= '</form>';
|
||||
$sHtml .= '</div>';
|
||||
@@ -511,10 +513,9 @@ EOF
|
||||
{
|
||||
// Display the menu
|
||||
$oAppContext = new ApplicationContext();
|
||||
$iActiveNodeId = ApplicationMenu::GetActiveNodeId();
|
||||
$iAccordionIndex = 0;
|
||||
|
||||
ApplicationMenu::DisplayMenu($this, $oAppContext->GetAsHash(), $iActiveNodeId);
|
||||
ApplicationMenu::DisplayMenu($this, $oAppContext->GetAsHash());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -218,7 +218,8 @@ class ApplicationMenu
|
||||
*/
|
||||
static public function GetActiveNodeId()
|
||||
{
|
||||
$iMenuIndex = utils::ReadParam('menu', -1);
|
||||
$oAppContext = new ApplicationContext();
|
||||
$iMenuIndex = $oAppContext->GetCurrentValue('menu', -1);
|
||||
|
||||
if ($iMenuIndex == -1)
|
||||
{
|
||||
@@ -319,7 +320,7 @@ abstract class MenuNode
|
||||
|
||||
public function GetHyperlink($aExtraParams)
|
||||
{
|
||||
$aExtraParams['menu'] = $this->GetIndex();
|
||||
$aExtraParams['c[menu]'] = $this->GetIndex();
|
||||
return $this->AddParams('../pages/UI.php', $aExtraParams);
|
||||
}
|
||||
|
||||
@@ -593,7 +594,7 @@ class WebPageMenuNode extends MenuNode
|
||||
|
||||
public function GetHyperlink($aExtraParams)
|
||||
{
|
||||
$aExtraParams['menu'] = $this->GetIndex();
|
||||
$aExtraParams['c[menu]'] = $this->GetIndex();
|
||||
return $this->AddParams( $this->sHyperlink, $aExtraParams);
|
||||
}
|
||||
|
||||
@@ -631,7 +632,7 @@ class NewObjectMenuNode extends MenuNode
|
||||
public function GetHyperlink($aExtraParams)
|
||||
{
|
||||
$sHyperlink = '../pages/UI.php?operation=new&class='.$this->sClass;
|
||||
$aExtraParams['menu'] = $this->GetIndex();
|
||||
$aExtraParams['c[menu]'] = $this->GetIndex();
|
||||
return $this->AddParams($sHyperlink, $aExtraParams);
|
||||
}
|
||||
|
||||
|
||||
@@ -240,7 +240,7 @@ class DisplayTemplate
|
||||
</itoptab>
|
||||
</itoptabs>';
|
||||
|
||||
$oPage = new iTopWebPage('Unit Test', 3);
|
||||
$oPage = new iTopWebPage('Unit Test');
|
||||
//$oPage->add("Template content: <pre>".htmlentities($sTemplate)."</pre>\n");
|
||||
$oTemplate = new DisplayTemplate($sTemplate);
|
||||
$oTemplate->Render($oPage, array('class'=>'Network device','pkey'=> 271, 'name' => 'deliversw01.mecanorama.fr', 'org_id' => 3));
|
||||
|
||||
@@ -99,7 +99,7 @@ function UpdateFileName(id, sNewFileName)
|
||||
/**
|
||||
* Reload a search form for the specified class
|
||||
*/
|
||||
function ReloadSearchForm(divId, sClassName, sBaseClass)
|
||||
function ReloadSearchForm(divId, sClassName, sBaseClass, sContext)
|
||||
{
|
||||
var oDiv = $('#'+divId);
|
||||
oDiv.block();
|
||||
@@ -112,7 +112,7 @@ function ReloadSearchForm(divId, sClassName, sBaseClass)
|
||||
aSubmit = oFormEvents.submit;
|
||||
}
|
||||
|
||||
$.post('ajax.render.php',
|
||||
$.post('ajax.render.php?'+sContext,
|
||||
{ operation: 'search_form', className: sClassName, baseClass: sBaseClass, currentId: divId },
|
||||
function(data) {
|
||||
oDiv.empty();
|
||||
|
||||
14
pages/UI.php
14
pages/UI.php
@@ -501,7 +501,6 @@ try
|
||||
|
||||
require_once('../application/startup.inc.php');
|
||||
$oAppContext = new ApplicationContext();
|
||||
$currentOrganization = utils::ReadParam('org_id', '');
|
||||
$operation = utils::ReadParam('operation', '');
|
||||
|
||||
$oKPI = new ExecutionKPI();
|
||||
@@ -511,7 +510,7 @@ try
|
||||
|
||||
$oKPI->ComputeAndReport('User login');
|
||||
|
||||
$oP = new iTopWebPage(Dict::S('UI:WelcomeToITop'), $currentOrganization);
|
||||
$oP = new iTopWebPage(Dict::S('UI:WelcomeToITop'));
|
||||
|
||||
switch($operation)
|
||||
{
|
||||
@@ -781,7 +780,12 @@ try
|
||||
$oP->add_linked_script("../js/linkswidget.js");
|
||||
$oP->add_linked_script("../js/jquery.blockUI.js");
|
||||
|
||||
$aArgs = array_merge($oAppContext->GetAsHash(), utils::ReadParam('default', array()));
|
||||
$aArgs = utils::ReadParam('default', array());
|
||||
$aContext = $oAppContext->GetAsHash();
|
||||
foreach( $oAppContext->GetNames() as $key)
|
||||
{
|
||||
$aArgs[$key] = $oAppContext->GetCurrentValue($key);
|
||||
}
|
||||
|
||||
// If the specified class has subclasses, ask the user an instance of which class to create
|
||||
$aSubClasses = MetaModel::EnumChildClasses($sClass, ENUM_CHILD_CLASSES_ALL); // Including the specified class itself
|
||||
@@ -818,9 +822,9 @@ try
|
||||
$oP->add("<div class=\"wizContainer\">\n");
|
||||
$aDefaults = utils::ReadParam('default', array());
|
||||
$aContext = $oAppContext->GetAsHash();
|
||||
foreach($aContext as $key => $value)
|
||||
foreach( $oAppContext->GetNames() as $key)
|
||||
{
|
||||
$aDefaults[$key] = $value;
|
||||
$aDefaults[$key] = $oAppContext->GetCurrentValue($key);
|
||||
}
|
||||
// Set all the default values in an object and clone this "default" object
|
||||
$oObjToClone = MetaModel::NewObject($sRealClass);
|
||||
|
||||
@@ -33,10 +33,8 @@ require_once('../application/loginwebpage.class.inc.php');
|
||||
LoginWebPage::DoLogin(true); // Check user rights and prompt if needed (must be admin)
|
||||
|
||||
$oAppContext = new ApplicationContext();
|
||||
$iActiveNodeId = utils::ReadParam('menu', -1);
|
||||
$currentOrganization = utils::ReadParam('org_id', '');
|
||||
|
||||
$oP = new iTopWebPage(Dict::S('UI:UniversalSearchTitle'), $currentOrganization);
|
||||
$oP = new iTopWebPage(Dict::S('UI:UniversalSearchTitle'));
|
||||
|
||||
// From now on the context is limited to the the selected organization ??
|
||||
|
||||
|
||||
@@ -28,14 +28,13 @@ try
|
||||
require_once('../application/itopwebpage.class.inc.php');
|
||||
|
||||
require_once('../application/startup.inc.php');
|
||||
$currentOrganization = utils::ReadParam('org_id', '');
|
||||
$operation = utils::ReadParam('operation', '');
|
||||
$oAppContext = new ApplicationContext();
|
||||
|
||||
require_once('../application/loginwebpage.class.inc.php');
|
||||
LoginWebPage::DoLogin(); // Check user rights and prompt if needed
|
||||
|
||||
$oP = new iTopWebPage(Dict::S('UI:Audit:Title'), $currentOrganization);
|
||||
$oP = new iTopWebPage(Dict::S('UI:Audit:Title'));
|
||||
|
||||
function GetRuleResultSet($iRuleId, $oDefinitionFilter)
|
||||
{
|
||||
|
||||
@@ -35,10 +35,9 @@ try
|
||||
LoginWebPage::DoLogin(); // Check user rights and prompt if needed
|
||||
|
||||
$oAppContext = new ApplicationContext();
|
||||
$currentOrganization = utils::ReadParam('org_id', 1);
|
||||
$iStep = utils::ReadParam('step', 1);
|
||||
|
||||
$oPage = new iTopWebPage(Dict::S('UI:Title:BulkImport'), $currentOrganization);
|
||||
$oPage = new iTopWebPage(Dict::S('UI:Title:BulkImport'));
|
||||
|
||||
/**
|
||||
* Helper function to build a select from the list of valid classes for a given action
|
||||
|
||||
@@ -27,10 +27,8 @@ LoginWebPage::DoLogin(); // Check user rights and prompt if needed
|
||||
|
||||
$sOperation = utils::ReadParam('operation', 'menu');
|
||||
$oAppContext = new ApplicationContext();
|
||||
$iActiveNodeId = utils::ReadParam('menu', -1);
|
||||
$currentOrganization = utils::ReadParam('org_id', '');
|
||||
|
||||
$oP = new iTopWebPage("iTop - Navigator", $currentOrganization);
|
||||
$oP = new iTopWebPage("iTop - Navigator");
|
||||
|
||||
// Main program
|
||||
$sClass = utils::ReadParam('class', '');
|
||||
|
||||
@@ -91,10 +91,8 @@ function ShowExamples($oP, $sExpression)
|
||||
|
||||
$sOperation = utils::ReadParam('operation', 'menu');
|
||||
$oAppContext = new ApplicationContext();
|
||||
$iActiveNodeId = utils::ReadParam('menu', -1);
|
||||
$currentOrganization = utils::ReadParam('org_id', '');
|
||||
|
||||
$oP = new iTopWebPage(Dict::S('UI:RunQuery:Title'), $currentOrganization);
|
||||
$oP = new iTopWebPage(Dict::S('UI:RunQuery:Title'));
|
||||
|
||||
// Main program
|
||||
$sExpression = utils::ReadParam('expression', '');
|
||||
|
||||
@@ -507,11 +507,9 @@ function DisplayRelationDetails($oPage, $sRelCode)
|
||||
|
||||
// Display the menu on the left
|
||||
$oAppContext = new ApplicationContext();
|
||||
$iActiveNodeId = utils::ReadParam('menu', -1);
|
||||
$currentOrganization = utils::ReadParam('org_id', 1);
|
||||
$operation = utils::ReadParam('operation', '');
|
||||
|
||||
$oPage = new iTopWebPage(Dict::S('UI:Schema:Title'), $currentOrganization);
|
||||
$oPage = new iTopWebPage(Dict::S('UI:Schema:Title'));
|
||||
$oPage->no_cache();
|
||||
|
||||
$operation = utils::ReadParam('operation', '');
|
||||
|
||||
Reference in New Issue
Block a user