diff --git a/application/applicationcontext.class.inc.php b/application/applicationcontext.class.inc.php
index e3422e02e..e23ddd390 100644
--- a/application/applicationcontext.class.inc.php
+++ b/application/applicationcontext.class.inc.php
@@ -14,6 +14,7 @@ class ApplicationContext
{
protected $aNames;
protected $aValues;
+ protected static $aDefaultValues; // Cache shared among all instances
public function __construct()
{
@@ -29,16 +30,20 @@ class ApplicationContext
*/
protected function ReadContext()
{
- $this->aValues = array();
- foreach($this->aNames as $sName)
+ if (empty(self::$aDefaultValues))
{
- $sValue = utils::ReadParam($sName, '');
- // TO DO: check if some of the context parameters are mandatory (or have default values)
- if (!empty($sValue))
+ self::$aDefaultValues = array();
+ foreach($this->aNames as $sName)
{
- $this->aValues[$sName] = $sValue;
+ $sValue = utils::ReadParam($sName, '');
+ // TO DO: check if some of the context parameters are mandatory (or have default values)
+ if (!empty($sValue))
+ {
+ self::$aDefaultValues[$sName] = $sValue;
+ }
}
}
+ $this->aValues = self::$aDefaultValues;
}
/**
@@ -77,5 +82,18 @@ class ApplicationContext
{
return $this->aValues;
}
+ /**
+ * Removes the specified parameter from the context, for example when the same parameter
+ * is already a search parameter
+ * @param string $sParamName Name of the parameter to remove
+ * @return none
+ */
+ public function Reset($sParamName)
+ {
+ if (isset($this->aValues[$sParamName]))
+ {
+ unset($this->aValues[$sParamName]);
+ }
+ }
}
?>
diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php
index ccd5c9e55..dd4782afc 100644
--- a/application/cmdbabstract.class.inc.php
+++ b/application/cmdbabstract.class.inc.php
@@ -507,12 +507,13 @@ abstract class cmdbAbstractObject extends CMDBObject
public static function GetSearchForm(web_page $oPage, CMDBObjectSet $oSet, $aExtraParams = array())
{
static $iSearchFormId = 0;
+ $oAppContext = new ApplicationContext();
$sHtml = '';
$numCols=4;
$iSearchFormId++;
$sClassName = $oSet->GetFilter()->GetClass();
- // Romain: temporariy removed the tab "OQL query" because it was not finalized
+ // Romain: temporarily removed the tab "OQL query" because it was not finalized
// (especially when used to add a link)
/*
$sHtml .= "
@@ -536,6 +537,7 @@ abstract class cmdbAbstractObject extends CMDBObject
$aList = MetaModel::GetZListItems($sClassName, 'standard_search');
foreach($aList as $sFilterCode)
{
+ $oAppContext->Reset($sFilterCode); // Make sure the same parameter will not be passed twice
if (($index % $numCols) == 0)
{
if ($index != 0)
@@ -608,6 +610,7 @@ abstract class cmdbAbstractObject extends CMDBObject
$sHtml .= "\n";
$sHtml .= "\n";
$sHtml .= "\n";
+ $sHtml .= $oAppContext->GetForForm();
$sHtml .= "\n";
$sHtml .= "
\n";
@@ -634,6 +637,7 @@ abstract class cmdbAbstractObject extends CMDBObject
$sHtml .= "\n";
}
$sHtml .= "\n";
+ $sHtml .= $oAppContext->GetForForm();
$sHtml .= "\n";
$sHtml .= "\n";
return $sHtml;
@@ -642,6 +646,12 @@ abstract class cmdbAbstractObject extends CMDBObject
public static function GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $value = '', $sDisplayValue = '', $iId = '', $sNameSuffix = '', $iFlags = 0, $aArgs = array())
{
static $iInputId = 0;
+ if (isset($aArgs[$sAttCode]) && empty($value))
+ {
+ // default value passed by the context (either the app context of the operation)
+ $value = $aArgs[$sAttCode];
+ }
+
if (!empty($iId))
{
$iInputId = $iId;
@@ -797,7 +807,7 @@ abstract class cmdbAbstractObject extends CMDBObject
$oPage->add("\n");
}
- public static function DisplayCreationForm(web_page $oPage, $sClass, $oObjectToClone = null)
+ public static function DisplayCreationForm(web_page $oPage, $sClass, $oObjectToClone = null, $aArgs = array())
{
static $iCreationFormId = 0;
@@ -835,7 +845,7 @@ abstract class cmdbAbstractObject extends CMDBObject
$sDisplayValue = ($oObjectToClone == null) ? '' : $oObjectToClone->GetDisplayValue($sAttCode);
$iOptions = isset($aStates[$sTargetState]['attribute_list'][$sAttCode]) ? $aStates[$sTargetState]['attribute_list'][$sAttCode] : 0;
- $sHTMLValue = self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, '', '', $iOptions);
+ $sHTMLValue = self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, '', '', $iOptions, $aArgs);
$aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sHTMLValue);
}
}
diff --git a/application/displayblock.class.inc.php b/application/displayblock.class.inc.php
index c006bd91a..f744cf6c4 100644
--- a/application/displayblock.class.inc.php
+++ b/application/displayblock.class.inc.php
@@ -257,10 +257,12 @@ class DisplayBlock
}
$sFilter = urlencode($this->m_oFilter->serialize());
$aData = array();
+ $oAppContext = new ApplicationContext();
+ $sParams = $oAppContext->GetForLink();
foreach($aGroupBy as $sValue => $iCount)
{
$aData[] = array ( 'group' => $sValue,
- 'value' => "$iCount"); // TO DO: add the context information
+ 'value' => "$iCount"); // TO DO: add the context information
}
$sHtml .= $oPage->GetTable(array('group' => array('label' => MetaModel::GetLabel($this->m_oFilter->GetClass(), $sGroupByField), 'description' => ''), 'value' => array('label'=>'Count', 'description' => 'Number of elements')), $aData);
}
@@ -287,7 +289,9 @@ class DisplayBlock
{
if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES)
{
- $sHtml .= $oPage->GetP("Click here to create a new ".Metamodel::GetName($sClass)."\n");
+ $oAppContext = new ApplicationContext();
+ $sParams = $oAppContext->GetForLink();
+ $sHtml .= $oPage->GetP("Click here to create a new ".Metamodel::GetName($sClass)."\n");
}
}
}
@@ -312,7 +316,9 @@ class DisplayBlock
{
if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES)
{
- $sHtml .= $oPage->GetP("Click here to add new ".Metamodel::GetName($sTargetClass)."s\n");
+ $oAppContext = new ApplicationContext();
+ $sParams = $oAppContext->GetForLink();
+ $sHtml .= $oPage->GetP("Click here to add new ".Metamodel::GetName($sTargetClass)."s\n");
}
}
}
diff --git a/application/uiwizard.class.inc.php b/application/uiwizard.class.inc.php
index 1ae24cabe..9ee6c1d83 100644
--- a/application/uiwizard.class.inc.php
+++ b/application/uiwizard.class.inc.php
@@ -25,7 +25,7 @@ class UIWizard
/**
* Displays one step of the wizard
*/
- public function DisplayWizardStep($aStep, $iStepIndex, &$iMaxInputId, &$aFieldsMap, $bFinishEnabled = false)
+ public function DisplayWizardStep($aStep, $iStepIndex, &$iMaxInputId, &$aFieldsMap, $bFinishEnabled = false, $aArgs = array())
{
if ($iStepIndex == 1) // one big form that contains everything, to make sure that the uploaded files are posted too
{
@@ -60,7 +60,7 @@ class UIWizard
$sFieldFlag = ($iOptions & (OPT_ATT_MANDATORY | OPT_ATT_MUSTCHANGE)) ? ' *' : '';
$oDefaultValuesSet = $oAttDef->GetDefaultValue(); // @@@ TO DO: get the object's current value if the object exists
- $sHTMLValue = cmdbAbstractObject::GetFormElementForField($this->m_oPage, $this->m_sClass, $sAttCode, $oAttDef, $oDefaultValuesSet, '', "att_$iMaxInputId", '', $iOptions);
+ $sHTMLValue = cmdbAbstractObject::GetFormElementForField($this->m_oPage, $this->m_sClass, $sAttCode, $oAttDef, $oDefaultValuesSet, '', "att_$iMaxInputId", '', $iOptions, $aArgs);
$aFieldsMap[$iMaxInputId] = $sAttCode;
$aDetails[] = array('label' => $oAttDef->GetLabel().$sFieldFlag, 'value' => "
$sHTMLValue
");
if ($oAttDef->GetValuesDef() != null)
@@ -108,6 +108,7 @@ $sJSHandlerCode
*/
public function DisplayFinalStep($iStepIndex, $aFieldsMap)
{
+ $oAppContext = new ApplicationContext();
$this->m_oPage->add("