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 .= "
\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("
\n"); $this->m_oPage->add("\n"); $this->m_oPage->P("Final step: confirmation"); @@ -126,6 +127,7 @@ $sJSHandlerCode $this->m_oPage->add("\n"); $this->m_oPage->add("
\n"); $this->m_oPage->add("
\n"); + $this->m_oPage->add($oAppContext->GetForForm()); $this->m_oPage->add("m_sClass)."\" />\n"); $this->m_oPage->add("
\n"); $this->m_oPage->add("\n"); diff --git a/pages/UI.php b/pages/UI.php index ba8dc8969..7478805d3 100644 --- a/pages/UI.php +++ b/pages/UI.php @@ -350,6 +350,8 @@ switch($operation) $oP->add_linked_script("../js/linkswidget.js"); $oP->add_linked_script("../js/jquery.blockUI.js"); $oWizard = new UIWizard($oP, $sClass, $sStateCode); + $oContext = new UserContext(); + $aArgs = array_merge($oAppContext->GetAsHash(), utils::ReadParam('default', array())); $sStateCode = $oWizard->GetTargetState(); // Will computes the default state if none was supplied $sClassLabel = MetaModel::GetName($sClass); $oP->add("

Creation of a new $sClassLabel

"); @@ -367,21 +369,19 @@ switch($operation) foreach($aWizardSteps['mandatory'] as $aSteps) { $oP->SetCurrentTab("Step $iStepIndex *"); - $oWizard->DisplayWizardStep($aSteps, $iStepIndex, $iMaxInputId, $aFieldsMap); + $oWizard->DisplayWizardStep($aSteps, $iStepIndex, $iMaxInputId, $aFieldsMap, false /* no finish button */, $aArgs); //$oP->add("\n"); $iStepIndex++; } foreach($aWizardSteps['optional'] as $aSteps) { $oP->SetCurrentTab("Step $iStepIndex *"); - $oWizard->DisplayWizardStep($aSteps, $iStepIndex, $iMaxInputId, $aFieldsMap, true); // true means enable the finish button + $oWizard->DisplayWizardStep($aSteps, $iStepIndex, $iMaxInputId, $aFieldsMap, true, $aArgs); // true means enable the finish button //$oP->add("\n"); $iStepIndex++; } $oWizard->DisplayFinalStep($iStepIndex, $aFieldsMap); - $oAppContext = new ApplicationContext(); - $oContext = new UserContext(); $oObj = null; if (!empty($id)) {